blob: 885a01bb5ed9cfd9a8eeaf5e30594c2f7df99538 [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 },
Willy Tarreau4fee4e92007-01-06 21:09:17 +010088 { "httpclose", PR_O_HTTP_CLOSE, PR_CAP_FE | PR_CAP_BE, 0 },
89 { "logasap", PR_O_LOGASAP, PR_CAP_FE, 0 },
90 { "abortonclose", PR_O_ABRT_CLOSE, PR_CAP_BE, 0 },
91 { "checkcache", PR_O_CHK_CACHE, PR_CAP_BE, 0 },
92 { "dontlognull", PR_O_NULLNOLOG, PR_CAP_FE, 0 },
93 { "clitcpka", PR_O_TCP_CLI_KA, PR_CAP_FE, 0 },
94 { "srvtcpka", PR_O_TCP_SRV_KA, PR_CAP_BE, 0 },
95 { "allbackups", PR_O_USE_ALL_BK, PR_CAP_BE, 0 },
96 { "persist", PR_O_PERSIST, PR_CAP_BE, 0 },
97 { "forceclose", PR_O_FORCE_CLO | PR_O_HTTP_CLOSE, PR_CAP_BE, 0 },
Willy Tarreau8f922fc2007-01-06 21:11:49 +010098#ifdef CONFIG_HAP_TCPSPLICE
99 { "tcpsplice", PR_O_TCPSPLICE , PR_CAP_BE|PR_CAP_FE, LSTCHK_TCPSPLICE|LSTCHK_NETADM },
100#endif
101
Willy Tarreau13943ab2006-12-31 00:24:10 +0100102 { NULL, 0, 0 }
103};
104
Willy Tarreaubaaee002006-06-26 02:48:02 +0200105
106static struct proxy defproxy; /* fake proxy used to assign default values on all instances */
107int cfg_maxpconn = DEFAULT_MAXCONN; /* # of simultaneous connections per proxy (-N) */
108int cfg_maxconn = 0; /* # of simultaneous connections, (-n) */
109
110/*
111 * converts <str> to a list of listeners which are dynamically allocated.
112 * The format is "{addr|'*'}:port[-end][,{addr|'*'}:port[-end]]*", where :
113 * - <addr> can be empty or "*" to indicate INADDR_ANY ;
114 * - <port> is a numerical port from 1 to 65535 ;
115 * - <end> indicates to use the range from <port> to <end> instead (inclusive).
116 * This can be repeated as many times as necessary, separated by a coma.
117 * The <tail> argument is a pointer to a current list which should be appended
118 * to the tail of the new list. The pointer to the new list is returned.
119 */
120static struct listener *str2listener(char *str, struct listener *tail)
121{
122 struct listener *l;
123 char *c, *next, *range, *dupstr;
124 int port, end;
125
126 next = dupstr = strdup(str);
127
128 while (next && *next) {
129 struct sockaddr_storage ss;
130
131 str = next;
132 /* 1) look for the end of the first address */
133 if ((next = strrchr(str, ',')) != NULL) {
134 *next++ = 0;
135 }
136
137 /* 2) look for the addr/port delimiter, it's the last colon. */
138 if ((range = strrchr(str, ':')) == NULL) {
139 Alert("Missing port number: '%s'\n", str);
140 goto fail;
141 }
142
143 *range++ = 0;
144
145 if (strrchr(str, ':') != NULL) {
146 /* IPv6 address contains ':' */
147 memset(&ss, 0, sizeof(ss));
148 ss.ss_family = AF_INET6;
149
150 if (!inet_pton(ss.ss_family, str, &((struct sockaddr_in6 *)&ss)->sin6_addr)) {
151 Alert("Invalid server address: '%s'\n", str);
152 goto fail;
153 }
154 }
155 else {
156 memset(&ss, 0, sizeof(ss));
157 ss.ss_family = AF_INET;
158
159 if (*str == '*' || *str == '\0') { /* INADDR_ANY */
160 ((struct sockaddr_in *)&ss)->sin_addr.s_addr = INADDR_ANY;
161 }
162 else if (!inet_pton(ss.ss_family, str, &((struct sockaddr_in *)&ss)->sin_addr)) {
163 struct hostent *he;
164
165 if ((he = gethostbyname(str)) == NULL) {
166 Alert("Invalid server name: '%s'\n", str);
167 goto fail;
168 }
169 else
170 ((struct sockaddr_in *)&ss)->sin_addr =
171 *(struct in_addr *) *(he->h_addr_list);
172 }
173 }
174
175 /* 3) look for the port-end delimiter */
176 if ((c = strchr(range, '-')) != NULL) {
177 *c++ = 0;
178 end = atol(c);
179 }
180 else {
181 end = atol(range);
182 }
183
184 port = atol(range);
185
186 if (port < 1 || port > 65535) {
187 Alert("Invalid port '%d' specified for address '%s'.\n", port, str);
188 goto fail;
189 }
190
191 if (end < 1 || end > 65535) {
192 Alert("Invalid port '%d' specified for address '%s'.\n", end, str);
193 goto fail;
194 }
195
196 for (; port <= end; port++) {
197 l = (struct listener *)calloc(1, sizeof(struct listener));
198 l->next = tail;
199 tail = l;
200
201 l->fd = -1;
202 l->addr = ss;
203 if (ss.ss_family == AF_INET6)
204 ((struct sockaddr_in6 *)(&l->addr))->sin6_port = htons(port);
205 else
206 ((struct sockaddr_in *)(&l->addr))->sin_port = htons(port);
207
208 } /* end for(port) */
209 } /* end while(next) */
210 free(dupstr);
211 return tail;
212 fail:
213 free(dupstr);
214 return NULL;
215}
216
Willy Tarreau977b8e42006-12-29 14:19:17 +0100217/*
218 * Sends a warning if proxy <proxy> does not have at least one of the
219 * capabilities in <cap>. An optionnal <hint> may be added at the end
220 * of the warning to help the user. Returns 1 if a warning was emitted
221 * or 0 if the condition is valid.
222 */
223int warnifnotcap(struct proxy *proxy, int cap, const char *file, int line, char *arg, char *hint)
224{
225 char *msg;
226
227 switch (cap) {
228 case PR_CAP_BE: msg = "no backend"; break;
229 case PR_CAP_FE: msg = "no frontend"; break;
230 case PR_CAP_RS: msg = "no ruleset"; break;
231 case PR_CAP_BE|PR_CAP_FE: msg = "neither frontend nor backend"; break;
232 default: msg = "not enough"; break;
233 }
234
235 if (!(proxy->cap & cap)) {
236 Warning("parsing [%s:%d] : '%s' ignored because %s '%s' has %s capability.%s\n",
Willy Tarreau2b5652f2006-12-31 17:46:05 +0100237 file, line, arg, proxy_type_str(proxy), proxy->id, msg, hint ? hint : "");
Willy Tarreau977b8e42006-12-29 14:19:17 +0100238 return 1;
239 }
240 return 0;
241}
Willy Tarreaubaaee002006-06-26 02:48:02 +0200242
243/*
244 * parse a line in a <global> section. Returns 0 if OK, -1 if error.
245 */
Willy Tarreaub17916e2006-10-15 15:17:57 +0200246int cfg_parse_global(const char *file, int linenum, char **args)
Willy Tarreaubaaee002006-06-26 02:48:02 +0200247{
248
249 if (!strcmp(args[0], "global")) { /* new section */
250 /* no option, nothing special to do */
251 return 0;
252 }
253 else if (!strcmp(args[0], "daemon")) {
254 global.mode |= MODE_DAEMON;
255 }
256 else if (!strcmp(args[0], "debug")) {
257 global.mode |= MODE_DEBUG;
258 }
259 else if (!strcmp(args[0], "noepoll")) {
260 cfg_polling_mechanism &= ~POLL_USE_EPOLL;
261 }
262 else if (!strcmp(args[0], "nopoll")) {
263 cfg_polling_mechanism &= ~POLL_USE_POLL;
264 }
265 else if (!strcmp(args[0], "quiet")) {
266 global.mode |= MODE_QUIET;
267 }
268 else if (!strcmp(args[0], "stats")) {
269 global.mode |= MODE_STATS;
270 }
271 else if (!strcmp(args[0], "uid")) {
272 if (global.uid != 0) {
Willy Tarreau95c20ac2007-03-25 15:39:23 +0200273 Alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum);
Willy Tarreaubaaee002006-06-26 02:48:02 +0200274 return 0;
275 }
276 if (*(args[1]) == 0) {
277 Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
278 return -1;
279 }
280 global.uid = atol(args[1]);
281 }
282 else if (!strcmp(args[0], "gid")) {
283 if (global.gid != 0) {
Willy Tarreau95c20ac2007-03-25 15:39:23 +0200284 Alert("parsing [%s:%d] : group/gid already specified. Continuing.\n", file, linenum);
Willy Tarreaubaaee002006-06-26 02:48:02 +0200285 return 0;
286 }
287 if (*(args[1]) == 0) {
288 Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
289 return -1;
290 }
291 global.gid = atol(args[1]);
292 }
Willy Tarreau95c20ac2007-03-25 15:39:23 +0200293 /* user/group name handling */
294 else if (!strcmp(args[0], "user")) {
295 struct passwd *ha_user;
296 if (global.uid != 0) {
297 Alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum);
298 return 0;
299 }
300 errno = 0;
301 ha_user = getpwnam(args[1]);
302 if (ha_user != NULL) {
303 global.uid = (int)ha_user->pw_uid;
304 }
305 else {
306 Alert("parsing [%s:%d] : cannot find user id for '%s' (%d:%s)\n", file, linenum, args[1], errno, strerror(errno));
307 exit(1);
308 }
309 }
310 else if (!strcmp(args[0], "group")) {
311 struct group *ha_group;
312 if (global.gid != 0) {
313 Alert("parsing [%s:%d] : gid/group was already specified. Continuing.\n", file, linenum, args[0]);
314 return 0;
315 }
316 errno = 0;
317 ha_group = getgrnam(args[1]);
318 if (ha_group != NULL) {
319 global.gid = (int)ha_group->gr_gid;
320 }
321 else {
322 Alert("parsing [%s:%d] : cannot find group id for '%s' (%d:%s)\n", file, linenum, args[1], errno, strerror(errno));
323 exit(1);
324 }
325 }
326 /* end of user/group name handling*/
Willy Tarreaubaaee002006-06-26 02:48:02 +0200327 else if (!strcmp(args[0], "nbproc")) {
328 if (global.nbproc != 0) {
329 Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
330 return 0;
331 }
332 if (*(args[1]) == 0) {
333 Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
334 return -1;
335 }
336 global.nbproc = atol(args[1]);
337 }
338 else if (!strcmp(args[0], "maxconn")) {
339 if (global.maxconn != 0) {
340 Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
341 return 0;
342 }
343 if (*(args[1]) == 0) {
344 Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
345 return -1;
346 }
347 global.maxconn = atol(args[1]);
348#ifdef SYSTEM_MAXCONN
349 if (global.maxconn > DEFAULT_MAXCONN && cfg_maxconn <= DEFAULT_MAXCONN) {
350 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);
351 global.maxconn = DEFAULT_MAXCONN;
352 }
353#endif /* SYSTEM_MAXCONN */
354 }
355 else if (!strcmp(args[0], "ulimit-n")) {
356 if (global.rlimit_nofile != 0) {
357 Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
358 return 0;
359 }
360 if (*(args[1]) == 0) {
361 Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
362 return -1;
363 }
364 global.rlimit_nofile = atol(args[1]);
365 }
366 else if (!strcmp(args[0], "chroot")) {
367 if (global.chroot != NULL) {
368 Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
369 return 0;
370 }
371 if (*(args[1]) == 0) {
372 Alert("parsing [%s:%d] : '%s' expects a directory as an argument.\n", file, linenum, args[0]);
373 return -1;
374 }
375 global.chroot = strdup(args[1]);
376 }
377 else if (!strcmp(args[0], "pidfile")) {
378 if (global.pidfile != NULL) {
379 Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
380 return 0;
381 }
382 if (*(args[1]) == 0) {
383 Alert("parsing [%s:%d] : '%s' expects a file name as an argument.\n", file, linenum, args[0]);
384 return -1;
385 }
386 global.pidfile = strdup(args[1]);
387 }
388 else if (!strcmp(args[0], "log")) { /* syslog server address */
389 struct sockaddr_in *sa;
390 int facility, level;
391
392 if (*(args[1]) == 0 || *(args[2]) == 0) {
393 Alert("parsing [%s:%d] : '%s' expects <address> and <facility> as arguments.\n", file, linenum, args[0]);
394 return -1;
395 }
396
397 facility = get_log_facility(args[2]);
398 if (facility < 0) {
399 Alert("parsing [%s:%d] : unknown log facility '%s'\n", file, linenum, args[2]);
400 exit(1);
401 }
402
403 level = 7; /* max syslog level = debug */
404 if (*(args[3])) {
405 level = get_log_level(args[3]);
406 if (level < 0) {
407 Alert("parsing [%s:%d] : unknown optional log level '%s'\n", file, linenum, args[3]);
408 exit(1);
409 }
410 }
411
412 sa = str2sa(args[1]);
413 if (!sa->sin_port)
414 sa->sin_port = htons(SYSLOG_PORT);
415
416 if (global.logfac1 == -1) {
417 global.logsrv1 = *sa;
418 global.logfac1 = facility;
419 global.loglev1 = level;
420 }
421 else if (global.logfac2 == -1) {
422 global.logsrv2 = *sa;
423 global.logfac2 = facility;
424 global.loglev2 = level;
425 }
426 else {
427 Alert("parsing [%s:%d] : too many syslog servers\n", file, linenum);
428 return -1;
429 }
430
431 }
432 else {
433 Alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], "global");
434 return -1;
435 }
436 return 0;
437}
438
439
440static void init_default_instance()
441{
442 memset(&defproxy, 0, sizeof(defproxy));
443 defproxy.mode = PR_MODE_TCP;
444 defproxy.state = PR_STNEW;
445 defproxy.maxconn = cfg_maxpconn;
446 defproxy.conn_retries = CONN_RETRIES;
447 defproxy.logfac1 = defproxy.logfac2 = -1; /* log disabled */
448}
449
450/*
Willy Tarreau977b8e42006-12-29 14:19:17 +0100451 * Parse a line in a <listen>, <frontend>, <backend> or <ruleset> section.
452 * Returns 0 if OK, -1 if error.
Willy Tarreaubaaee002006-06-26 02:48:02 +0200453 */
Willy Tarreaub17916e2006-10-15 15:17:57 +0200454int cfg_parse_listen(const char *file, int linenum, char **args)
Willy Tarreaubaaee002006-06-26 02:48:02 +0200455{
456 static struct proxy *curproxy = NULL;
457 struct server *newsrv = NULL;
Willy Tarreaub17916e2006-10-15 15:17:57 +0200458 const char *err;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200459 int rc;
460
Willy Tarreau977b8e42006-12-29 14:19:17 +0100461 if (!strcmp(args[0], "listen"))
462 rc = PR_CAP_LISTEN;
463 else if (!strcmp(args[0], "frontend"))
464 rc = PR_CAP_FE | PR_CAP_RS;
465 else if (!strcmp(args[0], "backend"))
466 rc = PR_CAP_BE | PR_CAP_RS;
467 else if (!strcmp(args[0], "ruleset"))
468 rc = PR_CAP_RS;
469 else
470 rc = PR_CAP_NONE;
471
472 if (rc != PR_CAP_NONE) { /* new proxy */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200473 if (!*args[1]) {
474 Alert("parsing [%s:%d] : '%s' expects an <id> argument and\n"
475 " optionnally supports [addr1]:port1[-end1]{,[addr]:port[-end]}...\n",
476 file, linenum, args[0]);
477 return -1;
478 }
479
480 if ((curproxy = (struct proxy *)calloc(1, sizeof(struct proxy))) == NULL) {
481 Alert("parsing [%s:%d] : out of memory.\n", file, linenum);
482 return -1;
483 }
484
485 curproxy->next = proxy;
486 proxy = curproxy;
487 LIST_INIT(&curproxy->pendconns);
488
489 curproxy->id = strdup(args[1]);
Willy Tarreau977b8e42006-12-29 14:19:17 +0100490 curproxy->cap = rc;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200491
492 /* parse the listener address if any */
Willy Tarreau977b8e42006-12-29 14:19:17 +0100493 if ((curproxy->cap & PR_CAP_FE) && *args[2]) {
Willy Tarreaubaaee002006-06-26 02:48:02 +0200494 curproxy->listen = str2listener(args[2], curproxy->listen);
495 if (!curproxy->listen)
496 return -1;
497 global.maxsock++;
498 }
499
500 /* set default values */
501 curproxy->state = defproxy.state;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200502 curproxy->options = defproxy.options;
Willy Tarreau7ac51f62007-03-25 16:00:04 +0200503 curproxy->except_net = defproxy.except_net;
504 curproxy->except_mask = defproxy.except_mask;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200505
Willy Tarreau977b8e42006-12-29 14:19:17 +0100506 if (curproxy->cap & PR_CAP_FE) {
507 curproxy->maxconn = defproxy.maxconn;
508
509 /* initialize error relocations */
510 for (rc = 0; rc < HTTP_ERR_SIZE; rc++) {
511 if (defproxy.errmsg[rc].str)
512 chunk_dup(&curproxy->errmsg[rc], &defproxy.errmsg[rc]);
513 }
514
515 curproxy->to_log = defproxy.to_log & ~LW_COOKIE & ~LW_REQHDR & ~ LW_RSPHDR;
516 }
Willy Tarreaubaaee002006-06-26 02:48:02 +0200517
Willy Tarreau977b8e42006-12-29 14:19:17 +0100518 if (curproxy->cap & PR_CAP_BE) {
519 curproxy->fullconn = defproxy.fullconn;
520 curproxy->conn_retries = defproxy.conn_retries;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200521
Willy Tarreau977b8e42006-12-29 14:19:17 +0100522 if (defproxy.check_req)
523 curproxy->check_req = strdup(defproxy.check_req);
524 curproxy->check_len = defproxy.check_len;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200525
Willy Tarreau977b8e42006-12-29 14:19:17 +0100526 if (defproxy.cookie_name)
527 curproxy->cookie_name = strdup(defproxy.cookie_name);
528 curproxy->cookie_len = defproxy.cookie_len;
529 }
Willy Tarreaubaaee002006-06-26 02:48:02 +0200530
Willy Tarreau977b8e42006-12-29 14:19:17 +0100531 if (curproxy->cap & PR_CAP_RS) {
532 if (defproxy.capture_name)
533 curproxy->capture_name = strdup(defproxy.capture_name);
534 curproxy->capture_namelen = defproxy.capture_namelen;
535 curproxy->capture_len = defproxy.capture_len;
Willy Tarreau0f772532006-12-23 20:51:41 +0100536 }
Willy Tarreaubaaee002006-06-26 02:48:02 +0200537
Willy Tarreau977b8e42006-12-29 14:19:17 +0100538 if (curproxy->cap & PR_CAP_FE) {
539 curproxy->clitimeout = defproxy.clitimeout;
540 curproxy->uri_auth = defproxy.uri_auth;
541 curproxy->mon_net = defproxy.mon_net;
542 curproxy->mon_mask = defproxy.mon_mask;
543 if (defproxy.monitor_uri)
544 curproxy->monitor_uri = strdup(defproxy.monitor_uri);
545 curproxy->monitor_uri_len = defproxy.monitor_uri_len;
Willy Tarreau5fdfb912007-01-01 23:11:07 +0100546 if (defproxy.defbe.name)
547 curproxy->defbe.name = strdup(defproxy.defbe.name);
Willy Tarreau977b8e42006-12-29 14:19:17 +0100548 }
549
550 if (curproxy->cap & PR_CAP_BE) {
551 curproxy->contimeout = defproxy.contimeout;
552 curproxy->srvtimeout = defproxy.srvtimeout;
553 curproxy->source_addr = defproxy.source_addr;
554 }
555
Willy Tarreaubaaee002006-06-26 02:48:02 +0200556 curproxy->mode = defproxy.mode;
557 curproxy->logfac1 = defproxy.logfac1;
558 curproxy->logsrv1 = defproxy.logsrv1;
559 curproxy->loglev1 = defproxy.loglev1;
560 curproxy->logfac2 = defproxy.logfac2;
561 curproxy->logsrv2 = defproxy.logsrv2;
562 curproxy->loglev2 = defproxy.loglev2;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200563 curproxy->grace = defproxy.grace;
Willy Tarreau1c47f852006-07-09 08:22:27 +0200564
Willy Tarreaubaaee002006-06-26 02:48:02 +0200565 return 0;
566 }
567 else if (!strcmp(args[0], "defaults")) { /* use this one to assign default values */
568 /* some variables may have already been initialized earlier */
Willy Tarreau5fdfb912007-01-01 23:11:07 +0100569 /* FIXME-20070101: we should do this too at the end of the
570 * config parsing to free all default values.
571 */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200572 if (defproxy.check_req) free(defproxy.check_req);
573 if (defproxy.cookie_name) free(defproxy.cookie_name);
574 if (defproxy.capture_name) free(defproxy.capture_name);
Willy Tarreau1c47f852006-07-09 08:22:27 +0200575 if (defproxy.monitor_uri) free(defproxy.monitor_uri);
Willy Tarreau5fdfb912007-01-01 23:11:07 +0100576 if (defproxy.defbe.name) free(defproxy.defbe.name);
Willy Tarreau0f772532006-12-23 20:51:41 +0100577
578 for (rc = 0; rc < HTTP_ERR_SIZE; rc++) {
579 if (defproxy.errmsg[rc].len)
580 free(defproxy.errmsg[rc].str);
581 }
582
Willy Tarreaubaaee002006-06-26 02:48:02 +0200583 /* we cannot free uri_auth because it might already be used */
584 init_default_instance();
585 curproxy = &defproxy;
Willy Tarreau977b8e42006-12-29 14:19:17 +0100586 defproxy.cap = PR_CAP_LISTEN; /* all caps for now */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200587 return 0;
588 }
589 else if (curproxy == NULL) {
590 Alert("parsing [%s:%d] : 'listen' or 'defaults' expected.\n", file, linenum);
591 return -1;
592 }
593
Willy Tarreau977b8e42006-12-29 14:19:17 +0100594
595 /* Now let's parse the proxy-specific keywords */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200596 if (!strcmp(args[0], "bind")) { /* new listen addresses */
597 if (curproxy == &defproxy) {
598 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
599 return -1;
600 }
Willy Tarreau977b8e42006-12-29 14:19:17 +0100601 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
602 return 0;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200603
604 if (strchr(args[1], ':') == NULL) {
605 Alert("parsing [%s:%d] : '%s' expects [addr1]:port1[-end1]{,[addr]:port[-end]}... as arguments.\n",
606 file, linenum, args[0]);
607 return -1;
608 }
609 curproxy->listen = str2listener(args[1], curproxy->listen);
610 if (!curproxy->listen)
611 return -1;
612 global.maxsock++;
613 return 0;
614 }
615 else if (!strcmp(args[0], "monitor-net")) { /* set the range of IPs to ignore */
616 if (!*args[1] || !str2net(args[1], &curproxy->mon_net, &curproxy->mon_mask)) {
617 Alert("parsing [%s:%d] : '%s' expects address[/mask].\n",
618 file, linenum, args[0]);
619 return -1;
620 }
Willy Tarreau977b8e42006-12-29 14:19:17 +0100621 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
622 return 0;
623
Willy Tarreaubaaee002006-06-26 02:48:02 +0200624 /* flush useless bits */
625 curproxy->mon_net.s_addr &= curproxy->mon_mask.s_addr;
626 return 0;
627 }
Willy Tarreau1c47f852006-07-09 08:22:27 +0200628 else if (!strcmp(args[0], "monitor-uri")) { /* set the URI to intercept */
Willy Tarreau977b8e42006-12-29 14:19:17 +0100629 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
630 return 0;
631
Willy Tarreau1c47f852006-07-09 08:22:27 +0200632 if (!*args[1]) {
633 Alert("parsing [%s:%d] : '%s' expects an URI.\n",
634 file, linenum, args[0]);
635 return -1;
636 }
637
638 if (curproxy->monitor_uri != NULL)
639 free(curproxy->monitor_uri);
640
Willy Tarreau8d5d7f22007-01-21 19:16:41 +0100641 curproxy->monitor_uri_len = strlen(args[1]);
Willy Tarreau1c47f852006-07-09 08:22:27 +0200642 curproxy->monitor_uri = (char *)calloc(1, curproxy->monitor_uri_len + 1);
Willy Tarreau8d5d7f22007-01-21 19:16:41 +0100643 memcpy(curproxy->monitor_uri, args[1], curproxy->monitor_uri_len);
Willy Tarreau1c47f852006-07-09 08:22:27 +0200644 curproxy->monitor_uri[curproxy->monitor_uri_len] = '\0';
645
646 return 0;
647 }
Willy Tarreaubaaee002006-06-26 02:48:02 +0200648 else if (!strcmp(args[0], "mode")) { /* sets the proxy mode */
649 if (!strcmp(args[1], "http")) curproxy->mode = PR_MODE_HTTP;
650 else if (!strcmp(args[1], "tcp")) curproxy->mode = PR_MODE_TCP;
651 else if (!strcmp(args[1], "health")) curproxy->mode = PR_MODE_HEALTH;
652 else {
653 Alert("parsing [%s:%d] : unknown proxy mode '%s'.\n", file, linenum, args[1]);
654 return -1;
655 }
656 }
657 else if (!strcmp(args[0], "disabled")) { /* disables this proxy */
658 curproxy->state = PR_STSTOPPED;
659 }
660 else if (!strcmp(args[0], "enabled")) { /* enables this proxy (used to revert a disabled default) */
661 curproxy->state = PR_STNEW;
662 }
663 else if (!strcmp(args[0], "cookie")) { /* cookie name */
664 int cur_arg;
665 // if (curproxy == &defproxy) {
666 // Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
667 // return -1;
668 // }
669
Willy Tarreau977b8e42006-12-29 14:19:17 +0100670 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
671 return 0;
672
Willy Tarreaubaaee002006-06-26 02:48:02 +0200673 if (curproxy->cookie_name != NULL) {
674 // Alert("parsing [%s:%d] : cookie name already specified. Continuing.\n",
675 // file, linenum);
676 // return 0;
677 free(curproxy->cookie_name);
678 }
679
680 if (*(args[1]) == 0) {
681 Alert("parsing [%s:%d] : '%s' expects <cookie_name> as argument.\n",
682 file, linenum, args[0]);
683 return -1;
684 }
685 curproxy->cookie_name = strdup(args[1]);
686 curproxy->cookie_len = strlen(curproxy->cookie_name);
687
688 cur_arg = 2;
689 while (*(args[cur_arg])) {
690 if (!strcmp(args[cur_arg], "rewrite")) {
691 curproxy->options |= PR_O_COOK_RW;
692 }
693 else if (!strcmp(args[cur_arg], "indirect")) {
694 curproxy->options |= PR_O_COOK_IND;
695 }
696 else if (!strcmp(args[cur_arg], "insert")) {
697 curproxy->options |= PR_O_COOK_INS;
698 }
699 else if (!strcmp(args[cur_arg], "nocache")) {
700 curproxy->options |= PR_O_COOK_NOC;
701 }
702 else if (!strcmp(args[cur_arg], "postonly")) {
703 curproxy->options |= PR_O_COOK_POST;
704 }
705 else if (!strcmp(args[cur_arg], "prefix")) {
706 curproxy->options |= PR_O_COOK_PFX;
707 }
708 else {
709 Alert("parsing [%s:%d] : '%s' supports 'rewrite', 'insert', 'prefix', 'indirect', 'nocache' and 'postonly' options.\n",
710 file, linenum, args[0]);
711 return -1;
712 }
713 cur_arg++;
714 }
715 if (!POWEROF2(curproxy->options & (PR_O_COOK_RW|PR_O_COOK_IND))) {
716 Alert("parsing [%s:%d] : cookie 'rewrite' and 'indirect' modes are incompatible.\n",
717 file, linenum);
718 return -1;
719 }
720
721 if (!POWEROF2(curproxy->options & (PR_O_COOK_RW|PR_O_COOK_INS|PR_O_COOK_PFX))) {
722 Alert("parsing [%s:%d] : cookie 'rewrite', 'insert' and 'prefix' modes are incompatible.\n",
723 file, linenum);
724 return -1;
725 }
726 }/* end else if (!strcmp(args[0], "cookie")) */
727 else if (!strcmp(args[0], "appsession")) { /* cookie name */
728 // if (curproxy == &defproxy) {
729 // Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
730 // return -1;
731 // }
732
Willy Tarreau977b8e42006-12-29 14:19:17 +0100733 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
734 return 0;
735
Willy Tarreaubaaee002006-06-26 02:48:02 +0200736 if (curproxy->appsession_name != NULL) {
737 // Alert("parsing [%s:%d] : cookie name already specified. Continuing.\n",
738 // file, linenum);
739 // return 0;
740 free(curproxy->appsession_name);
741 }
742
743 if (*(args[5]) == 0) {
744 Alert("parsing [%s:%d] : '%s' expects 'appsession' <cookie_name> 'len' <len> 'timeout' <timeout>.\n",
745 file, linenum, args[0]);
746 return -1;
747 }
748 have_appsession = 1;
749 curproxy->appsession_name = strdup(args[1]);
750 curproxy->appsession_name_len = strlen(curproxy->appsession_name);
751 curproxy->appsession_len = atoi(args[3]);
752 curproxy->appsession_timeout = atoi(args[5]);
753 rc = chtbl_init(&(curproxy->htbl_proxy), TBLSIZ, hashpjw, match_str, destroy);
754 if (rc) {
755 Alert("Error Init Appsession Hashtable.\n");
756 return -1;
757 }
758 } /* Url App Session */
759 else if (!strcmp(args[0], "capture")) {
Willy Tarreau977b8e42006-12-29 14:19:17 +0100760 if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL))
761 return 0;
762
Willy Tarreaubaaee002006-06-26 02:48:02 +0200763 if (!strcmp(args[1], "cookie")) { /* name of a cookie to capture */
764 // if (curproxy == &defproxy) {
765 // Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
766 // return -1;
767 // }
768
769 if (curproxy->capture_name != NULL) {
770 // Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n",
771 // file, linenum, args[0]);
772 // return 0;
773 free(curproxy->capture_name);
774 }
775
776 if (*(args[4]) == 0) {
777 Alert("parsing [%s:%d] : '%s' expects 'cookie' <cookie_name> 'len' <len>.\n",
778 file, linenum, args[0]);
779 return -1;
780 }
781 curproxy->capture_name = strdup(args[2]);
782 curproxy->capture_namelen = strlen(curproxy->capture_name);
783 curproxy->capture_len = atol(args[4]);
784 if (curproxy->capture_len >= CAPTURE_LEN) {
785 Warning("parsing [%s:%d] : truncating capture length to %d bytes.\n",
786 file, linenum, CAPTURE_LEN - 1);
787 curproxy->capture_len = CAPTURE_LEN - 1;
788 }
789 curproxy->to_log |= LW_COOKIE;
790 }
791 else if (!strcmp(args[1], "request") && !strcmp(args[2], "header")) {
792 struct cap_hdr *hdr;
793
794 if (curproxy == &defproxy) {
795 Alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
796 return -1;
797 }
798
799 if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) {
800 Alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n",
801 file, linenum, args[0], args[1]);
802 return -1;
803 }
804
805 hdr = calloc(sizeof(struct cap_hdr), 1);
806 hdr->next = curproxy->req_cap;
807 hdr->name = strdup(args[3]);
808 hdr->namelen = strlen(args[3]);
809 hdr->len = atol(args[5]);
810 hdr->index = curproxy->nb_req_cap++;
811 curproxy->req_cap = hdr;
812 curproxy->to_log |= LW_REQHDR;
813 }
814 else if (!strcmp(args[1], "response") && !strcmp(args[2], "header")) {
815 struct cap_hdr *hdr;
816
817 if (curproxy == &defproxy) {
818 Alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
819 return -1;
820 }
821
822 if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) {
823 Alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n",
824 file, linenum, args[0], args[1]);
825 return -1;
826 }
827 hdr = calloc(sizeof(struct cap_hdr), 1);
828 hdr->next = curproxy->rsp_cap;
829 hdr->name = strdup(args[3]);
830 hdr->namelen = strlen(args[3]);
831 hdr->len = atol(args[5]);
832 hdr->index = curproxy->nb_rsp_cap++;
833 curproxy->rsp_cap = hdr;
834 curproxy->to_log |= LW_RSPHDR;
835 }
836 else {
837 Alert("parsing [%s:%d] : '%s' expects 'cookie' or 'request header' or 'response header'.\n",
838 file, linenum, args[0]);
839 return -1;
840 }
841 }
842 else if (!strcmp(args[0], "contimeout")) { /* connect timeout */
843 if (curproxy->contimeout != defproxy.contimeout) {
844 Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
845 return 0;
846 }
Willy Tarreau977b8e42006-12-29 14:19:17 +0100847 else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
848 return 0;
849
Willy Tarreaubaaee002006-06-26 02:48:02 +0200850 if (*(args[1]) == 0) {
851 Alert("parsing [%s:%d] : '%s' expects an integer <time_in_ms> as argument.\n",
852 file, linenum, args[0]);
853 return -1;
854 }
855 curproxy->contimeout = atol(args[1]);
856 }
857 else if (!strcmp(args[0], "clitimeout")) { /* client timeout */
858 if (curproxy->clitimeout != defproxy.clitimeout) {
859 Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n",
860 file, linenum, args[0]);
861 return 0;
862 }
Willy Tarreau977b8e42006-12-29 14:19:17 +0100863 else if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
864 return 0;
865
Willy Tarreaubaaee002006-06-26 02:48:02 +0200866 if (*(args[1]) == 0) {
867 Alert("parsing [%s:%d] : '%s' expects an integer <time_in_ms> as argument.\n",
868 file, linenum, args[0]);
869 return -1;
870 }
871 curproxy->clitimeout = atol(args[1]);
872 }
873 else if (!strcmp(args[0], "srvtimeout")) { /* server timeout */
874 if (curproxy->srvtimeout != defproxy.srvtimeout) {
875 Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
876 return 0;
877 }
Willy Tarreau977b8e42006-12-29 14:19:17 +0100878 else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
879 return 0;
880
Willy Tarreaubaaee002006-06-26 02:48:02 +0200881 if (*(args[1]) == 0) {
882 Alert("parsing [%s:%d] : '%s' expects an integer <time_in_ms> as argument.\n",
883 file, linenum, args[0]);
884 return -1;
885 }
886 curproxy->srvtimeout = atol(args[1]);
887 }
888 else if (!strcmp(args[0], "retries")) { /* connection retries */
Willy Tarreau977b8e42006-12-29 14:19:17 +0100889 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
890 return 0;
891
Willy Tarreaubaaee002006-06-26 02:48:02 +0200892 if (*(args[1]) == 0) {
893 Alert("parsing [%s:%d] : '%s' expects an integer argument (dispatch counts for one).\n",
894 file, linenum, args[0]);
895 return -1;
896 }
897 curproxy->conn_retries = atol(args[1]);
898 }
899 else if (!strcmp(args[0], "stats")) {
Willy Tarreau977b8e42006-12-29 14:19:17 +0100900 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
901 return 0;
902
Willy Tarreaubaaee002006-06-26 02:48:02 +0200903 if (curproxy != &defproxy && curproxy->uri_auth == defproxy.uri_auth)
904 curproxy->uri_auth = NULL; /* we must detach from the default config */
905
906 if (*(args[1]) == 0) {
907 Alert("parsing [%s:%d] : '%s' expects 'uri', 'realm', 'auth', 'scope' or 'enable'.\n", file, linenum, args[0]);
908 return -1;
909 } else if (!strcmp(args[1], "uri")) {
910 if (*(args[2]) == 0) {
911 Alert("parsing [%s:%d] : 'uri' needs an URI prefix.\n", file, linenum);
912 return -1;
913 } else if (!stats_set_uri(&curproxy->uri_auth, args[2])) {
914 Alert("parsing [%s:%d] : out of memory.\n", file, linenum);
915 return -1;
916 }
917 } else if (!strcmp(args[1], "realm")) {
918 if (*(args[2]) == 0) {
919 Alert("parsing [%s:%d] : 'realm' needs an realm name.\n", file, linenum);
920 return -1;
921 } else if (!stats_set_realm(&curproxy->uri_auth, args[2])) {
922 Alert("parsing [%s:%d] : out of memory.\n", file, linenum);
923 return -1;
924 }
925 } else if (!strcmp(args[1], "auth")) {
926 if (*(args[2]) == 0) {
927 Alert("parsing [%s:%d] : 'auth' needs a user:password account.\n", file, linenum);
928 return -1;
929 } else if (!stats_add_auth(&curproxy->uri_auth, args[2])) {
930 Alert("parsing [%s:%d] : out of memory.\n", file, linenum);
931 return -1;
932 }
933 } else if (!strcmp(args[1], "scope")) {
934 if (*(args[2]) == 0) {
935 Alert("parsing [%s:%d] : 'scope' needs a proxy name.\n", file, linenum);
936 return -1;
937 } else if (!stats_add_scope(&curproxy->uri_auth, args[2])) {
938 Alert("parsing [%s:%d] : out of memory.\n", file, linenum);
939 return -1;
940 }
941 } else if (!strcmp(args[1], "enable")) {
942 if (!stats_check_init_uri_auth(&curproxy->uri_auth)) {
943 Alert("parsing [%s:%d] : out of memory.\n", file, linenum);
944 return -1;
945 }
946 } else {
947 Alert("parsing [%s:%d] : unknown stats parameter '%s' (expects 'uri', 'realm', 'auth' or 'enable').\n",
948 file, linenum, args[0]);
949 return -1;
950 }
951 }
952 else if (!strcmp(args[0], "option")) {
Willy Tarreau13943ab2006-12-31 00:24:10 +0100953 int optnum;
954
Willy Tarreaubaaee002006-06-26 02:48:02 +0200955 if (*(args[1]) == 0) {
956 Alert("parsing [%s:%d] : '%s' expects an option name.\n", file, linenum, args[0]);
957 return -1;
958 }
Willy Tarreau13943ab2006-12-31 00:24:10 +0100959
960 for (optnum = 0; cfg_opts[optnum].name; optnum++) {
961 if (!strcmp(args[1], cfg_opts[optnum].name)) {
962 if (warnifnotcap(curproxy, cfg_opts[optnum].cap, file, linenum, args[1], NULL))
963 return 0;
964 curproxy->options |= cfg_opts[optnum].val;
Willy Tarreau4fee4e92007-01-06 21:09:17 +0100965 global.last_checks |= cfg_opts[optnum].checks;
Willy Tarreau13943ab2006-12-31 00:24:10 +0100966 return 0;
967 }
968 }
969
970 if (!strcmp(args[1], "httplog"))
Willy Tarreaubaaee002006-06-26 02:48:02 +0200971 /* generate a complete HTTP log */
972 curproxy->to_log |= LW_DATE | LW_CLIP | LW_SVID | LW_REQ | LW_PXID | LW_RESP | LW_BYTES;
973 else if (!strcmp(args[1], "tcplog"))
974 /* generate a detailed TCP log */
975 curproxy->to_log |= LW_DATE | LW_CLIP | LW_SVID | LW_PXID | LW_BYTES;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200976 else if (!strcmp(args[1], "tcpka")) {
977 /* enable TCP keep-alives on client and server sessions */
Willy Tarreau13943ab2006-12-31 00:24:10 +0100978 if (warnifnotcap(curproxy, PR_CAP_BE | PR_CAP_FE, file, linenum, args[1], NULL))
979 return 0;
980
981 if (curproxy->cap & PR_CAP_FE)
982 curproxy->options |= PR_O_TCP_CLI_KA;
983 if (curproxy->cap & PR_CAP_BE)
984 curproxy->options |= PR_O_TCP_SRV_KA;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200985 }
986 else if (!strcmp(args[1], "httpchk")) {
Willy Tarreau13943ab2006-12-31 00:24:10 +0100987 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL))
988 return 0;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200989 /* use HTTP request to check servers' health */
990 if (curproxy->check_req != NULL) {
991 free(curproxy->check_req);
992 }
993 curproxy->options |= PR_O_HTTP_CHK;
Willy Tarreauf3c69202006-07-09 16:42:34 +0200994 curproxy->options &= ~PR_O_SSL3_CHK;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200995 if (!*args[2]) { /* no argument */
996 curproxy->check_req = strdup(DEF_CHECK_REQ); /* default request */
997 curproxy->check_len = strlen(DEF_CHECK_REQ);
998 } else if (!*args[3]) { /* one argument : URI */
999 int reqlen = strlen(args[2]) + strlen("OPTIONS / HTTP/1.0\r\n\r\n");
1000 curproxy->check_req = (char *)malloc(reqlen);
1001 curproxy->check_len = snprintf(curproxy->check_req, reqlen,
1002 "OPTIONS %s HTTP/1.0\r\n\r\n", args[2]); /* URI to use */
1003 } else { /* more arguments : METHOD URI [HTTP_VER] */
1004 int reqlen = strlen(args[2]) + strlen(args[3]) + 3 + strlen("\r\n\r\n");
1005 if (*args[4])
1006 reqlen += strlen(args[4]);
1007 else
1008 reqlen += strlen("HTTP/1.0");
1009
1010 curproxy->check_req = (char *)malloc(reqlen);
1011 curproxy->check_len = snprintf(curproxy->check_req, reqlen,
1012 "%s %s %s\r\n\r\n", args[2], args[3], *args[4]?args[4]:"HTTP/1.0");
1013 }
Willy Tarreauf3c69202006-07-09 16:42:34 +02001014 }
1015 else if (!strcmp(args[1], "ssl-hello-chk")) {
1016 /* use SSLv3 CLIENT HELLO to check servers' health */
Willy Tarreau13943ab2006-12-31 00:24:10 +01001017 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL))
1018 return 0;
1019
Willy Tarreauf3c69202006-07-09 16:42:34 +02001020 if (curproxy->check_req != NULL) {
1021 free(curproxy->check_req);
1022 }
1023 curproxy->options &= ~PR_O_HTTP_CHK;
1024 curproxy->options |= PR_O_SSL3_CHK;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001025 }
Willy Tarreau7ac51f62007-03-25 16:00:04 +02001026 else if (!strcmp(args[1], "forwardfor")) {
1027 /* insert x-forwarded-for field, but not for the
1028 * IP address listed as an except.
1029 */
1030 if (*(args[2])) {
1031 if (!strcmp(args[2], "except")) {
1032 if (!*args[3] || !str2net(args[3], &curproxy->except_net, &curproxy->except_mask)) {
1033 Alert("parsing [%s:%d] : '%s' only supports optional 'except' address[/mask].\n",
1034 file, linenum, args[0]);
1035 return -1;
1036 }
1037 /* flush useless bits */
1038 curproxy->except_net.s_addr &= curproxy->except_mask.s_addr;
1039 } else {
1040 Alert("parsing [%s:%d] : '%s' only supports optional 'except' address[/mask].\n",
1041 file, linenum, args[0]);
1042 return -1;
1043 }
1044 }
1045 curproxy->options |= PR_O_FWDFOR;
1046 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02001047 else {
1048 Alert("parsing [%s:%d] : unknown option '%s'.\n", file, linenum, args[1]);
1049 return -1;
1050 }
1051 return 0;
1052 }
Willy Tarreau5fdfb912007-01-01 23:11:07 +01001053 else if (!strcmp(args[0], "default_backend")) {
1054 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1055 return 0;
1056
1057 if (*(args[1]) == 0) {
1058 Alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]);
1059 return -1;
1060 }
1061 if (curproxy->defbe.name)
1062 free(curproxy->defbe.name);
1063 curproxy->defbe.name = strdup(args[1]);
1064 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02001065 else if (!strcmp(args[0], "redispatch") || !strcmp(args[0], "redisp")) {
Willy Tarreau977b8e42006-12-29 14:19:17 +01001066 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1067 return 0;
1068
Willy Tarreaubaaee002006-06-26 02:48:02 +02001069 /* enable reconnections to dispatch */
1070 curproxy->options |= PR_O_REDISP;
1071 }
1072#ifdef TPROXY
1073 else if (!strcmp(args[0], "transparent")) {
1074 /* enable transparent proxy connections */
1075 curproxy->options |= PR_O_TRANSP;
1076 }
1077#endif
1078 else if (!strcmp(args[0], "maxconn")) { /* maxconn */
Willy Tarreau977b8e42006-12-29 14:19:17 +01001079 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], " Maybe you want 'fullconn' instead ?"))
1080 return 0;
1081
Willy Tarreaubaaee002006-06-26 02:48:02 +02001082 if (*(args[1]) == 0) {
1083 Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
1084 return -1;
1085 }
1086 curproxy->maxconn = atol(args[1]);
1087 }
Willy Tarreau86034312006-12-29 00:10:33 +01001088 else if (!strcmp(args[0], "fullconn")) { /* fullconn */
Willy Tarreau977b8e42006-12-29 14:19:17 +01001089 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], " Maybe you want 'maxconn' instead ?"))
1090 return 0;
1091
Willy Tarreau86034312006-12-29 00:10:33 +01001092 if (*(args[1]) == 0) {
1093 Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
1094 return -1;
1095 }
1096 curproxy->fullconn = atol(args[1]);
1097 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02001098 else if (!strcmp(args[0], "grace")) { /* grace time (ms) */
1099 if (*(args[1]) == 0) {
1100 Alert("parsing [%s:%d] : '%s' expects a time in milliseconds.\n", file, linenum, args[0]);
1101 return -1;
1102 }
1103 curproxy->grace = atol(args[1]);
1104 }
1105 else if (!strcmp(args[0], "dispatch")) { /* dispatch address */
1106 if (curproxy == &defproxy) {
1107 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1108 return -1;
1109 }
Willy Tarreau977b8e42006-12-29 14:19:17 +01001110 else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1111 return 0;
1112
Willy Tarreaubaaee002006-06-26 02:48:02 +02001113 if (strchr(args[1], ':') == NULL) {
1114 Alert("parsing [%s:%d] : '%s' expects <addr:port> as argument.\n", file, linenum, args[0]);
1115 return -1;
1116 }
1117 curproxy->dispatch_addr = *str2sa(args[1]);
1118 }
1119 else if (!strcmp(args[0], "balance")) { /* set balancing with optional algorithm */
Willy Tarreau977b8e42006-12-29 14:19:17 +01001120 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1121 return 0;
1122
Willy Tarreaubaaee002006-06-26 02:48:02 +02001123 if (*(args[1])) {
1124 if (!strcmp(args[1], "roundrobin")) {
1125 curproxy->options |= PR_O_BALANCE_RR;
1126 }
1127 else if (!strcmp(args[1], "source")) {
1128 curproxy->options |= PR_O_BALANCE_SH;
1129 }
1130 else {
1131 Alert("parsing [%s:%d] : '%s' only supports 'roundrobin' and 'source' options.\n", file, linenum, args[0]);
1132 return -1;
1133 }
1134 }
1135 else /* if no option is set, use round-robin by default */
1136 curproxy->options |= PR_O_BALANCE_RR;
1137 }
1138 else if (!strcmp(args[0], "server")) { /* server address */
1139 int cur_arg;
1140 char *rport;
1141 char *raddr;
1142 short realport;
1143 int do_check;
1144
1145 if (curproxy == &defproxy) {
1146 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1147 return -1;
1148 }
Willy Tarreau977b8e42006-12-29 14:19:17 +01001149 else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1150 return 0;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001151
1152 if (!*args[2]) {
1153 Alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n",
1154 file, linenum, args[0]);
1155 return -1;
1156 }
1157 if ((newsrv = (struct server *)calloc(1, sizeof(struct server))) == NULL) {
1158 Alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1159 return -1;
1160 }
1161
1162 /* the servers are linked backwards first */
1163 newsrv->next = curproxy->srv;
1164 curproxy->srv = newsrv;
1165 newsrv->proxy = curproxy;
1166
1167 LIST_INIT(&newsrv->pendconns);
1168 do_check = 0;
1169 newsrv->state = SRV_RUNNING; /* early server setup */
1170 newsrv->id = strdup(args[1]);
1171
1172 /* several ways to check the port component :
1173 * - IP => port=+0, relative
1174 * - IP: => port=+0, relative
1175 * - IP:N => port=N, absolute
1176 * - IP:+N => port=+N, relative
1177 * - IP:-N => port=-N, relative
1178 */
1179 raddr = strdup(args[2]);
1180 rport = strchr(raddr, ':');
1181 if (rport) {
1182 *rport++ = 0;
1183 realport = atol(rport);
1184 if (!isdigit((int)*rport))
1185 newsrv->state |= SRV_MAPPORTS;
1186 } else {
1187 realport = 0;
1188 newsrv->state |= SRV_MAPPORTS;
1189 }
1190
1191 newsrv->addr = *str2sa(raddr);
1192 newsrv->addr.sin_port = htons(realport);
1193 free(raddr);
1194
1195 newsrv->curfd = -1; /* no health-check in progress */
1196 newsrv->inter = DEF_CHKINTR;
1197 newsrv->rise = DEF_RISETIME;
1198 newsrv->fall = DEF_FALLTIME;
1199 newsrv->health = newsrv->rise; /* up, but will fall down at first failure */
1200 cur_arg = 3;
1201 while (*args[cur_arg]) {
1202 if (!strcmp(args[cur_arg], "cookie")) {
1203 newsrv->cookie = strdup(args[cur_arg + 1]);
1204 newsrv->cklen = strlen(args[cur_arg + 1]);
1205 cur_arg += 2;
1206 }
1207 else if (!strcmp(args[cur_arg], "rise")) {
1208 newsrv->rise = atol(args[cur_arg + 1]);
1209 newsrv->health = newsrv->rise;
1210 cur_arg += 2;
1211 }
1212 else if (!strcmp(args[cur_arg], "fall")) {
1213 newsrv->fall = atol(args[cur_arg + 1]);
1214 cur_arg += 2;
1215 }
1216 else if (!strcmp(args[cur_arg], "inter")) {
1217 newsrv->inter = atol(args[cur_arg + 1]);
1218 cur_arg += 2;
1219 }
1220 else if (!strcmp(args[cur_arg], "port")) {
1221 newsrv->check_port = atol(args[cur_arg + 1]);
1222 cur_arg += 2;
1223 }
1224 else if (!strcmp(args[cur_arg], "backup")) {
1225 newsrv->state |= SRV_BACKUP;
1226 cur_arg ++;
1227 }
1228 else if (!strcmp(args[cur_arg], "weight")) {
1229 int w;
1230 w = atol(args[cur_arg + 1]);
1231 if (w < 1 || w > 256) {
1232 Alert("parsing [%s:%d] : weight of server %s is not within 1 and 256 (%d).\n",
1233 file, linenum, newsrv->id, w);
1234 return -1;
1235 }
1236 newsrv->uweight = w - 1;
1237 cur_arg += 2;
1238 }
1239 else if (!strcmp(args[cur_arg], "minconn")) {
1240 newsrv->minconn = atol(args[cur_arg + 1]);
1241 cur_arg += 2;
1242 }
1243 else if (!strcmp(args[cur_arg], "maxconn")) {
1244 newsrv->maxconn = atol(args[cur_arg + 1]);
1245 cur_arg += 2;
1246 }
1247 else if (!strcmp(args[cur_arg], "check")) {
1248 global.maxsock++;
1249 do_check = 1;
1250 cur_arg += 1;
1251 }
1252 else if (!strcmp(args[cur_arg], "source")) { /* address to which we bind when connecting */
1253 if (!*args[cur_arg + 1]) {
Willy Tarreau8d9246d2007-03-24 12:47:24 +01001254#ifdef CONFIG_HAP_CTTPROXY
1255 Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optional '%s' <addr> as argument.\n",
1256 file, linenum, "source", "usesrc");
1257#else
Willy Tarreaubaaee002006-06-26 02:48:02 +02001258 Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>] as argument.\n",
1259 file, linenum, "source");
Willy Tarreau8d9246d2007-03-24 12:47:24 +01001260#endif
Willy Tarreaubaaee002006-06-26 02:48:02 +02001261 return -1;
1262 }
1263 newsrv->state |= SRV_BIND_SRC;
1264 newsrv->source_addr = *str2sa(args[cur_arg + 1]);
1265 cur_arg += 2;
Willy Tarreau77074d52006-11-12 23:57:19 +01001266 if (!strcmp(args[cur_arg], "usesrc")) { /* address to use outside */
Willy Tarreau8d9246d2007-03-24 12:47:24 +01001267#ifdef CONFIG_HAP_CTTPROXY
Willy Tarreau77074d52006-11-12 23:57:19 +01001268 if (newsrv->source_addr.sin_addr.s_addr == INADDR_ANY) {
Willy Tarreau8d9246d2007-03-24 12:47:24 +01001269 Alert("parsing [%s:%d] : '%s' requires an explicit '%s' address.\n",
1270 file, linenum, "usesrc", "source");
Willy Tarreau77074d52006-11-12 23:57:19 +01001271 return -1;
1272 }
1273 if (!*args[cur_arg + 1]) {
1274 Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n",
1275 file, linenum, "usesrc");
1276 return -1;
1277 }
1278 if (!strcmp(args[cur_arg + 1], "client")) {
1279 newsrv->state |= SRV_TPROXY_CLI;
1280 } else if (!strcmp(args[cur_arg + 1], "clientip")) {
1281 newsrv->state |= SRV_TPROXY_CIP;
1282 } else {
1283 newsrv->state |= SRV_TPROXY_ADDR;
1284 newsrv->tproxy_addr = *str2sa(args[cur_arg + 1]);
1285 }
1286 global.last_checks |= LSTCHK_CTTPROXY | LSTCHK_NETADM;
1287 cur_arg += 2;
Willy Tarreau8d9246d2007-03-24 12:47:24 +01001288#else /* no CTTPROXY support */
1289 Alert("parsing [%s:%d] : '%s' not allowed here because support for cttproxy was not compiled in.\n",
1290 file, linenum, "usesrc");
1291 return -1;
Willy Tarreau77074d52006-11-12 23:57:19 +01001292#endif
Willy Tarreau8d9246d2007-03-24 12:47:24 +01001293 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02001294 }
Willy Tarreau8d9246d2007-03-24 12:47:24 +01001295#ifdef CONFIG_HAP_CTTPROXY
1296 else if (!strcmp(args[cur_arg], "usesrc")) { /* address to use outside: needs "source" first */
1297 Alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n",
1298 file, linenum, "usesrc", "source");
1299 return -1;
1300 }
1301#endif
Willy Tarreaubaaee002006-06-26 02:48:02 +02001302 else {
1303 Alert("parsing [%s:%d] : server %s only supports options 'backup', 'cookie', 'check', 'inter', 'rise', 'fall', 'port', 'source', 'minconn', 'maxconn' and 'weight'.\n",
1304 file, linenum, newsrv->id);
1305 return -1;
1306 }
1307 }
1308
1309 if (do_check) {
1310 if (!newsrv->check_port && !(newsrv->state & SRV_MAPPORTS))
1311 newsrv->check_port = realport; /* by default */
1312 if (!newsrv->check_port) {
Willy Tarreauef00b502007-01-07 02:40:09 +01001313 /* not yet valid, because no port was set on
1314 * the server either. We'll check if we have
1315 * a known port on the first listener.
1316 */
1317 struct listener *l;
1318 l = curproxy->listen;
1319 if (l) {
1320 int port;
1321 port = (l->addr.ss_family == AF_INET6)
1322 ? ntohs(((struct sockaddr_in6 *)(&l->addr))->sin6_port)
1323 : ntohs(((struct sockaddr_in *)(&l->addr))->sin_port);
1324 newsrv->check_port = port;
1325 }
1326 }
1327 if (!newsrv->check_port) {
Willy Tarreaubaaee002006-06-26 02:48:02 +02001328 Alert("parsing [%s:%d] : server %s has neither service port nor check port. Check has been disabled.\n",
1329 file, linenum, newsrv->id);
1330 return -1;
1331 }
1332 newsrv->state |= SRV_CHECKED;
1333 }
1334
1335 if (newsrv->state & SRV_BACKUP)
1336 curproxy->srv_bck++;
1337 else
1338 curproxy->srv_act++;
1339 }
1340 else if (!strcmp(args[0], "log")) { /* syslog server address */
1341 struct sockaddr_in *sa;
1342 int facility;
1343
1344 if (*(args[1]) && *(args[2]) == 0 && !strcmp(args[1], "global")) {
1345 curproxy->logfac1 = global.logfac1;
1346 curproxy->logsrv1 = global.logsrv1;
1347 curproxy->loglev1 = global.loglev1;
1348 curproxy->logfac2 = global.logfac2;
1349 curproxy->logsrv2 = global.logsrv2;
1350 curproxy->loglev2 = global.loglev2;
1351 }
1352 else if (*(args[1]) && *(args[2])) {
1353 int level;
1354
1355 facility = get_log_facility(args[2]);
1356 if (facility < 0) {
1357 Alert("parsing [%s:%d] : unknown log facility '%s'\n", file, linenum, args[2]);
1358 exit(1);
1359 }
1360
1361 level = 7; /* max syslog level = debug */
1362 if (*(args[3])) {
1363 level = get_log_level(args[3]);
1364 if (level < 0) {
1365 Alert("parsing [%s:%d] : unknown optional log level '%s'\n", file, linenum, args[3]);
1366 exit(1);
1367 }
1368 }
1369
1370 sa = str2sa(args[1]);
1371 if (!sa->sin_port)
1372 sa->sin_port = htons(SYSLOG_PORT);
1373
1374 if (curproxy->logfac1 == -1) {
1375 curproxy->logsrv1 = *sa;
1376 curproxy->logfac1 = facility;
1377 curproxy->loglev1 = level;
1378 }
1379 else if (curproxy->logfac2 == -1) {
1380 curproxy->logsrv2 = *sa;
1381 curproxy->logfac2 = facility;
1382 curproxy->loglev2 = level;
1383 }
1384 else {
1385 Alert("parsing [%s:%d] : too many syslog servers\n", file, linenum);
1386 return -1;
1387 }
1388 }
1389 else {
1390 Alert("parsing [%s:%d] : 'log' expects either <address[:port]> and <facility> or 'global' as arguments.\n",
1391 file, linenum);
1392 return -1;
1393 }
1394 }
1395 else if (!strcmp(args[0], "source")) { /* address to which we bind when connecting */
Willy Tarreau977b8e42006-12-29 14:19:17 +01001396 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1397 return 0;
1398
Willy Tarreaubaaee002006-06-26 02:48:02 +02001399 if (!*args[1]) {
Willy Tarreau8d9246d2007-03-24 12:47:24 +01001400#ifdef CONFIG_HAP_CTTPROXY
1401 Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optional '%s' <addr> as argument.\n",
1402 file, linenum, "source", "usesrc");
1403#else
Willy Tarreaubaaee002006-06-26 02:48:02 +02001404 Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>] as argument.\n",
1405 file, linenum, "source");
Willy Tarreau8d9246d2007-03-24 12:47:24 +01001406#endif
Willy Tarreaubaaee002006-06-26 02:48:02 +02001407 return -1;
1408 }
1409
1410 curproxy->source_addr = *str2sa(args[1]);
1411 curproxy->options |= PR_O_BIND_SRC;
Willy Tarreau77074d52006-11-12 23:57:19 +01001412 if (!strcmp(args[2], "usesrc")) { /* address to use outside */
Willy Tarreau8d9246d2007-03-24 12:47:24 +01001413#ifdef CONFIG_HAP_CTTPROXY
Willy Tarreau77074d52006-11-12 23:57:19 +01001414 if (curproxy->source_addr.sin_addr.s_addr == INADDR_ANY) {
1415 Alert("parsing [%s:%d] : '%s' requires an explicit 'source' address.\n",
1416 file, linenum, "usesrc");
1417 return -1;
1418 }
1419 if (!*args[3]) {
1420 Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n",
1421 file, linenum, "usesrc");
1422 return -1;
1423 }
1424
1425 if (!strcmp(args[3], "client")) {
1426 curproxy->options |= PR_O_TPXY_CLI;
1427 } else if (!strcmp(args[3], "clientip")) {
1428 curproxy->options |= PR_O_TPXY_CIP;
1429 } else {
1430 curproxy->options |= PR_O_TPXY_ADDR;
1431 curproxy->tproxy_addr = *str2sa(args[3]);
1432 }
1433 global.last_checks |= LSTCHK_CTTPROXY | LSTCHK_NETADM;
Willy Tarreau8d9246d2007-03-24 12:47:24 +01001434#else /* no CTTPROXY support */
1435 Alert("parsing [%s:%d] : '%s' not allowed here because support for cttproxy was not compiled in.\n",
1436 file, linenum, "usesrc");
1437 return -1;
Willy Tarreau77074d52006-11-12 23:57:19 +01001438#endif
Willy Tarreau8d9246d2007-03-24 12:47:24 +01001439 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02001440 }
Willy Tarreau8d9246d2007-03-24 12:47:24 +01001441#ifdef CONFIG_HAP_CTTPROXY
1442 else if (!strcmp(args[0], "usesrc")) { /* address to use outside: needs "source" first */
1443 Alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n",
1444 file, linenum, "usesrc", "source");
1445 return -1;
1446 }
1447#endif
Willy Tarreaubaaee002006-06-26 02:48:02 +02001448 else if (!strcmp(args[0], "cliexp") || !strcmp(args[0], "reqrep")) { /* replace request header from a regex */
1449 regex_t *preg;
1450 if (curproxy == &defproxy) {
1451 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1452 return -1;
1453 }
Willy Tarreau977b8e42006-12-29 14:19:17 +01001454 else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL))
1455 return 0;
1456
Willy Tarreaubaaee002006-06-26 02:48:02 +02001457 if (*(args[1]) == 0 || *(args[2]) == 0) {
1458 Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n",
1459 file, linenum, args[0]);
1460 return -1;
1461 }
1462
1463 preg = calloc(1, sizeof(regex_t));
1464 if (regcomp(preg, args[1], REG_EXTENDED) != 0) {
1465 Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]);
1466 return -1;
1467 }
1468
1469 err = chain_regex(&curproxy->req_exp, preg, ACT_REPLACE, strdup(args[2]));
1470 if (err) {
1471 Alert("parsing [%s:%d] : invalid character or unterminated sequence in replacement string near '%c'.\n",
1472 file, linenum, *err);
1473 return -1;
1474 }
1475 }
1476 else if (!strcmp(args[0], "reqdel")) { /* delete request header from a 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_REMOVE, NULL);
1497 }
1498 else if (!strcmp(args[0], "reqdeny")) { /* deny a request if a header matches this regex */
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_DENY, NULL);
1519 }
1520 else if (!strcmp(args[0], "reqpass")) { /* pass this header without allowing or denying the request */
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_PASS, NULL);
1541 }
1542 else if (!strcmp(args[0], "reqallow")) { /* allow 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 Tarreaubaaee002006-06-26 02:48:02 +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_ALLOW, NULL);
1563 }
Willy Tarreaub8750a82006-09-03 09:56:00 +02001564 else if (!strcmp(args[0], "reqtarpit")) { /* tarpit a request if a header matches this regex */
1565 regex_t *preg;
1566 if (curproxy == &defproxy) {
1567 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;
1572
Willy Tarreaub8750a82006-09-03 09:56:00 +02001573 if (*(args[1]) == 0) {
1574 Alert("parsing [%s:%d] : '%s' expects <regex> as an argument.\n", file, linenum, args[0]);
1575 return -1;
1576 }
1577
1578 preg = calloc(1, sizeof(regex_t));
1579 if (regcomp(preg, args[1], REG_EXTENDED) != 0) {
1580 Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]);
1581 return -1;
1582 }
1583
1584 chain_regex(&curproxy->req_exp, preg, ACT_TARPIT, NULL);
1585 }
Willy Tarreaua496b602006-12-17 23:15:24 +01001586 else if (!strcmp(args[0], "reqsetbe")) { /* switch the backend from a regex, respecting 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) != 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 }
1608 else if (!strcmp(args[0], "reqisetbe")) { /* switch the backend from a regex, ignoring case */
1609 regex_t *preg;
Willy Tarreau977b8e42006-12-29 14:19:17 +01001610 if (curproxy == &defproxy) {
Willy Tarreaua496b602006-12-17 23:15:24 +01001611 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;
Willy Tarreaua496b602006-12-17 23:15:24 +01001616
Willy Tarreau977b8e42006-12-29 14:19:17 +01001617 if (*(args[1]) == 0 || *(args[2]) == 0) {
Willy Tarreaua496b602006-12-17 23:15:24 +01001618 Alert("parsing [%s:%d] : '%s' expects <search> and <target> as arguments.\n",
1619 file, linenum, args[0]);
1620 return -1;
1621 }
1622
1623 preg = calloc(1, sizeof(regex_t));
Willy Tarreau977b8e42006-12-29 14:19:17 +01001624 if (regcomp(preg, args[1], REG_EXTENDED | REG_ICASE) != 0) {
Willy Tarreaua496b602006-12-17 23:15:24 +01001625 Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]);
1626 }
1627
1628 chain_regex(&curproxy->req_exp, preg, ACT_SETBE, strdup(args[2]));
1629 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02001630 else if (!strcmp(args[0], "reqirep")) { /* replace request header from a regex, ignoring case */
1631 regex_t *preg;
1632 if (curproxy == &defproxy) {
1633 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1634 return -1;
1635 }
Willy Tarreau977b8e42006-12-29 14:19:17 +01001636 else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL))
1637 return 0;
1638
Willy Tarreaubaaee002006-06-26 02:48:02 +02001639 if (*(args[1]) == 0 || *(args[2]) == 0) {
1640 Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n",
1641 file, linenum, args[0]);
1642 return -1;
1643 }
1644
1645 preg = calloc(1, sizeof(regex_t));
1646 if (regcomp(preg, args[1], REG_EXTENDED | REG_ICASE) != 0) {
1647 Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]);
1648 return -1;
1649 }
1650
1651 err = chain_regex(&curproxy->req_exp, preg, ACT_REPLACE, strdup(args[2]));
1652 if (err) {
1653 Alert("parsing [%s:%d] : invalid character or unterminated sequence in replacement string near '%c'.\n",
1654 file, linenum, *err);
1655 return -1;
1656 }
1657 }
1658 else if (!strcmp(args[0], "reqidel")) { /* delete request header from a 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_REMOVE, NULL);
1679 }
1680 else if (!strcmp(args[0], "reqideny")) { /* deny a request if a header matches this regex ignoring case */
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_DENY, NULL);
1701 }
1702 else if (!strcmp(args[0], "reqipass")) { /* pass this header without allowing or denying the request */
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_PASS, NULL);
1723 }
1724 else if (!strcmp(args[0], "reqiallow")) { /* allow 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 Tarreaubaaee002006-06-26 02:48:02 +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_ALLOW, NULL);
1745 }
Willy Tarreaub8750a82006-09-03 09:56:00 +02001746 else if (!strcmp(args[0], "reqitarpit")) { /* tarpit a request if a header matches this regex ignoring case */
1747 regex_t *preg;
1748 if (curproxy == &defproxy) {
1749 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1750 return -1;
1751 }
Willy Tarreau977b8e42006-12-29 14:19:17 +01001752 else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL))
1753 return 0;
1754
Willy Tarreaub8750a82006-09-03 09:56:00 +02001755 if (*(args[1]) == 0) {
1756 Alert("parsing [%s:%d] : '%s' expects <regex> as an argument.\n", file, linenum, args[0]);
1757 return -1;
1758 }
1759
1760 preg = calloc(1, sizeof(regex_t));
1761 if (regcomp(preg, args[1], REG_EXTENDED | REG_ICASE) != 0) {
1762 Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]);
1763 return -1;
1764 }
1765
1766 chain_regex(&curproxy->req_exp, preg, ACT_TARPIT, NULL);
1767 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02001768 else if (!strcmp(args[0], "reqadd")) { /* add request header */
1769 if (curproxy == &defproxy) {
1770 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1771 return -1;
1772 }
Willy Tarreau977b8e42006-12-29 14:19:17 +01001773 else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL))
1774 return 0;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001775
1776 if (curproxy->nb_reqadd >= MAX_NEWHDR) {
1777 Alert("parsing [%s:%d] : too many '%s'. Continuing.\n", file, linenum, args[0]);
1778 return 0;
1779 }
1780
1781 if (*(args[1]) == 0) {
1782 Alert("parsing [%s:%d] : '%s' expects <header> as an argument.\n", file, linenum, args[0]);
1783 return -1;
1784 }
1785
1786 curproxy->req_add[curproxy->nb_reqadd++] = strdup(args[1]);
1787 }
1788 else if (!strcmp(args[0], "srvexp") || !strcmp(args[0], "rsprep")) { /* replace response header from a regex */
1789 regex_t *preg;
1790
1791 if (*(args[1]) == 0 || *(args[2]) == 0) {
1792 Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n",
1793 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 preg = calloc(1, sizeof(regex_t));
1800 if (regcomp(preg, args[1], REG_EXTENDED) != 0) {
1801 Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]);
1802 return -1;
1803 }
1804
1805 err = chain_regex(&curproxy->rsp_exp, preg, ACT_REPLACE, strdup(args[2]));
1806 if (err) {
1807 Alert("parsing [%s:%d] : invalid character or unterminated sequence in replacement string near '%c'.\n",
1808 file, linenum, *err);
1809 return -1;
1810 }
1811 }
1812 else if (!strcmp(args[0], "rspdel")) { /* delete response header from a regex */
1813 regex_t *preg;
1814 if (curproxy == &defproxy) {
1815 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1816 return -1;
1817 }
Willy Tarreau977b8e42006-12-29 14:19:17 +01001818 else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL))
1819 return 0;
1820
Willy Tarreaubaaee002006-06-26 02:48:02 +02001821 if (*(args[1]) == 0) {
1822 Alert("parsing [%s:%d] : '%s' expects <search> as an argument.\n", file, linenum, args[0]);
1823 return -1;
1824 }
1825
1826 preg = calloc(1, sizeof(regex_t));
1827 if (regcomp(preg, args[1], REG_EXTENDED) != 0) {
1828 Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]);
1829 return -1;
1830 }
1831
1832 err = chain_regex(&curproxy->rsp_exp, preg, ACT_REMOVE, strdup(args[2]));
1833 if (err) {
1834 Alert("parsing [%s:%d] : invalid character or unterminated sequence in replacement string near '%c'.\n",
1835 file, linenum, *err);
1836 return -1;
1837 }
1838 }
1839 else if (!strcmp(args[0], "rspdeny")) { /* block response header from a regex */
1840 regex_t *preg;
1841 if (curproxy == &defproxy) {
1842 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1843 return -1;
1844 }
Willy Tarreau977b8e42006-12-29 14:19:17 +01001845 else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL))
1846 return 0;
1847
Willy Tarreaubaaee002006-06-26 02:48:02 +02001848 if (*(args[1]) == 0) {
1849 Alert("parsing [%s:%d] : '%s' expects <search> as an argument.\n", file, linenum, args[0]);
1850 return -1;
1851 }
1852
1853 preg = calloc(1, sizeof(regex_t));
1854 if (regcomp(preg, args[1], REG_EXTENDED) != 0) {
1855 Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]);
1856 return -1;
1857 }
1858
1859 err = chain_regex(&curproxy->rsp_exp, preg, ACT_DENY, strdup(args[2]));
1860 if (err) {
1861 Alert("parsing [%s:%d] : invalid character or unterminated sequence in replacement string near '%c'.\n",
1862 file, linenum, *err);
1863 return -1;
1864 }
1865 }
1866 else if (!strcmp(args[0], "rspirep")) { /* replace response header from a regex ignoring case */
1867 regex_t *preg;
1868 if (curproxy == &defproxy) {
1869 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1870 return -1;
1871 }
Willy Tarreau977b8e42006-12-29 14:19:17 +01001872 else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL))
1873 return 0;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001874
1875 if (*(args[1]) == 0 || *(args[2]) == 0) {
1876 Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n",
1877 file, linenum, args[0]);
1878 return -1;
1879 }
1880
1881 preg = calloc(1, sizeof(regex_t));
1882 if (regcomp(preg, args[1], REG_EXTENDED | REG_ICASE) != 0) {
1883 Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]);
1884 return -1;
1885 }
1886
1887 err = chain_regex(&curproxy->rsp_exp, preg, ACT_REPLACE, strdup(args[2]));
1888 if (err) {
1889 Alert("parsing [%s:%d] : invalid character or unterminated sequence in replacement string near '%c'.\n",
1890 file, linenum, *err);
1891 return -1;
1892 }
1893 }
1894 else if (!strcmp(args[0], "rspidel")) { /* delete response header from a regex ignoring case */
1895 regex_t *preg;
1896 if (curproxy == &defproxy) {
1897 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1898 return -1;
1899 }
Willy Tarreau977b8e42006-12-29 14:19:17 +01001900 else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL))
1901 return 0;
1902
Willy Tarreaubaaee002006-06-26 02:48:02 +02001903 if (*(args[1]) == 0) {
1904 Alert("parsing [%s:%d] : '%s' expects <search> as an argument.\n", file, linenum, args[0]);
1905 return -1;
1906 }
1907
1908 preg = calloc(1, sizeof(regex_t));
1909 if (regcomp(preg, args[1], REG_EXTENDED | REG_ICASE) != 0) {
1910 Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]);
1911 return -1;
1912 }
1913
1914 err = chain_regex(&curproxy->rsp_exp, preg, ACT_REMOVE, strdup(args[2]));
1915 if (err) {
1916 Alert("parsing [%s:%d] : invalid character or unterminated sequence in replacement string near '%c'.\n",
1917 file, linenum, *err);
1918 return -1;
1919 }
1920 }
1921 else if (!strcmp(args[0], "rspideny")) { /* block response header from a regex ignoring case */
1922 regex_t *preg;
1923 if (curproxy == &defproxy) {
1924 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1925 return -1;
1926 }
Willy Tarreau977b8e42006-12-29 14:19:17 +01001927 else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL))
1928 return 0;
1929
Willy Tarreaubaaee002006-06-26 02:48:02 +02001930 if (*(args[1]) == 0) {
1931 Alert("parsing [%s:%d] : '%s' expects <search> as an argument.\n", file, linenum, args[0]);
1932 return -1;
1933 }
1934
1935 preg = calloc(1, sizeof(regex_t));
1936 if (regcomp(preg, args[1], REG_EXTENDED | REG_ICASE) != 0) {
1937 Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]);
1938 return -1;
1939 }
1940
1941 err = chain_regex(&curproxy->rsp_exp, preg, ACT_DENY, strdup(args[2]));
1942 if (err) {
1943 Alert("parsing [%s:%d] : invalid character or unterminated sequence in replacement string near '%c'.\n",
1944 file, linenum, *err);
1945 return -1;
1946 }
1947 }
1948 else if (!strcmp(args[0], "rspadd")) { /* add response header */
1949 if (curproxy == &defproxy) {
1950 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1951 return -1;
1952 }
Willy Tarreau977b8e42006-12-29 14:19:17 +01001953 else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL))
1954 return 0;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001955
1956 if (curproxy->nb_rspadd >= MAX_NEWHDR) {
1957 Alert("parsing [%s:%d] : too many '%s'. Continuing.\n", file, linenum, args[0]);
1958 return 0;
1959 }
1960
1961 if (*(args[1]) == 0) {
1962 Alert("parsing [%s:%d] : '%s' expects <header> as an argument.\n", file, linenum, args[0]);
1963 return -1;
1964 }
1965
1966 curproxy->rsp_add[curproxy->nb_rspadd++] = strdup(args[1]);
1967 }
1968 else if (!strcmp(args[0], "errorloc") ||
1969 !strcmp(args[0], "errorloc302") ||
1970 !strcmp(args[0], "errorloc303")) { /* error location */
1971 int errnum, errlen;
1972 char *err;
1973
1974 // if (curproxy == &defproxy) {
1975 // Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1976 // return -1;
1977 // }
1978
Willy Tarreau977b8e42006-12-29 14:19:17 +01001979 if (warnifnotcap(curproxy, PR_CAP_FE | PR_CAP_BE, file, linenum, args[0], NULL))
1980 return 0;
1981
Willy Tarreaubaaee002006-06-26 02:48:02 +02001982 if (*(args[2]) == 0) {
Willy Tarreau0f772532006-12-23 20:51:41 +01001983 Alert("parsing [%s:%d] : <%s> expects <status_code> and <url> as arguments.\n", file, linenum);
Willy Tarreaubaaee002006-06-26 02:48:02 +02001984 return -1;
1985 }
1986
1987 errnum = atol(args[1]);
1988 if (!strcmp(args[0], "errorloc303")) {
1989 err = malloc(strlen(HTTP_303) + strlen(args[2]) + 5);
1990 errlen = sprintf(err, "%s%s\r\n\r\n", HTTP_303, args[2]);
1991 } else {
1992 err = malloc(strlen(HTTP_302) + strlen(args[2]) + 5);
1993 errlen = sprintf(err, "%s%s\r\n\r\n", HTTP_302, args[2]);
1994 }
1995
Willy Tarreau0f772532006-12-23 20:51:41 +01001996 for (rc = 0; rc < HTTP_ERR_SIZE; rc++) {
1997 if (http_err_codes[rc] == errnum) {
1998 if (curproxy->errmsg[rc].str)
1999 free(curproxy->errmsg[rc].str);
2000 curproxy->errmsg[rc].str = err;
2001 curproxy->errmsg[rc].len = errlen;
2002 break;
Willy Tarreaubaaee002006-06-26 02:48:02 +02002003 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02002004 }
Willy Tarreau0f772532006-12-23 20:51:41 +01002005
2006 if (rc >= HTTP_ERR_SIZE) {
2007 Warning("parsing [%s:%d] : status code %d not handled, error relocation will be ignored.\n",
2008 file, linenum, errnum);
Willy Tarreaubaaee002006-06-26 02:48:02 +02002009 free(err);
2010 }
2011 }
2012 else {
2013 Alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], "listen");
2014 return -1;
2015 }
2016 return 0;
2017}
2018
2019
2020/*
2021 * This function reads and parses the configuration file given in the argument.
2022 * returns 0 if OK, -1 if error.
2023 */
Willy Tarreaub17916e2006-10-15 15:17:57 +02002024int readcfgfile(const char *file)
Willy Tarreaubaaee002006-06-26 02:48:02 +02002025{
2026 char thisline[256];
2027 char *line;
2028 FILE *f;
2029 int linenum = 0;
2030 char *end;
2031 char *args[MAX_LINE_ARGS];
2032 int arg;
2033 int cfgerr = 0;
Willy Tarreau80587432006-12-24 17:47:20 +01002034 int nbchk, mininter;
Willy Tarreaubaaee002006-06-26 02:48:02 +02002035 int confsect = CFG_NONE;
2036
2037 struct proxy *curproxy = NULL;
2038 struct server *newsrv = NULL;
2039
2040 if ((f=fopen(file,"r")) == NULL)
2041 return -1;
2042
2043 init_default_instance();
2044
2045 while (fgets(line = thisline, sizeof(thisline), f) != NULL) {
2046 linenum++;
2047
2048 end = line + strlen(line);
2049
2050 /* skip leading spaces */
2051 while (isspace((int)*line))
2052 line++;
2053
2054 arg = 0;
2055 args[arg] = line;
2056
2057 while (*line && arg < MAX_LINE_ARGS) {
2058 /* first, we'll replace \\, \<space>, \#, \r, \n, \t, \xXX with their
2059 * C equivalent value. Other combinations left unchanged (eg: \1).
2060 */
2061 if (*line == '\\') {
2062 int skip = 0;
2063 if (line[1] == ' ' || line[1] == '\\' || line[1] == '#') {
2064 *line = line[1];
2065 skip = 1;
2066 }
2067 else if (line[1] == 'r') {
2068 *line = '\r';
2069 skip = 1;
2070 }
2071 else if (line[1] == 'n') {
2072 *line = '\n';
2073 skip = 1;
2074 }
2075 else if (line[1] == 't') {
2076 *line = '\t';
2077 skip = 1;
2078 }
2079 else if (line[1] == 'x') {
2080 if ((line + 3 < end ) && ishex(line[2]) && ishex(line[3])) {
2081 unsigned char hex1, hex2;
2082 hex1 = toupper(line[2]) - '0';
2083 hex2 = toupper(line[3]) - '0';
2084 if (hex1 > 9) hex1 -= 'A' - '9' - 1;
2085 if (hex2 > 9) hex2 -= 'A' - '9' - 1;
2086 *line = (hex1<<4) + hex2;
2087 skip = 3;
2088 }
2089 else {
2090 Alert("parsing [%s:%d] : invalid or incomplete '\\x' sequence in '%s'.\n", file, linenum, args[0]);
2091 return -1;
2092 }
2093 }
2094 if (skip) {
2095 memmove(line + 1, line + 1 + skip, end - (line + skip + 1));
2096 end -= skip;
2097 }
2098 line++;
2099 }
2100 else if (*line == '#' || *line == '\n' || *line == '\r') {
2101 /* end of string, end of loop */
2102 *line = 0;
2103 break;
2104 }
2105 else if (isspace((int)*line)) {
2106 /* a non-escaped space is an argument separator */
2107 *line++ = 0;
2108 while (isspace((int)*line))
2109 line++;
2110 args[++arg] = line;
2111 }
2112 else {
2113 line++;
2114 }
2115 }
2116
2117 /* empty line */
2118 if (!**args)
2119 continue;
2120
2121 /* zero out remaining args */
2122 while (++arg < MAX_LINE_ARGS) {
2123 args[arg] = line;
2124 }
2125
Willy Tarreau977b8e42006-12-29 14:19:17 +01002126 if (!strcmp(args[0], "listen") ||
2127 !strcmp(args[0], "frontend") ||
2128 !strcmp(args[0], "backend") ||
2129 !strcmp(args[0], "ruleset") ||
2130 !strcmp(args[0], "defaults")) /* new proxy */
Willy Tarreaubaaee002006-06-26 02:48:02 +02002131 confsect = CFG_LISTEN;
2132 else if (!strcmp(args[0], "global")) /* global config */
2133 confsect = CFG_GLOBAL;
2134 /* else it's a section keyword */
2135
2136 switch (confsect) {
2137 case CFG_LISTEN:
2138 if (cfg_parse_listen(file, linenum, args) < 0)
2139 return -1;
2140 break;
2141 case CFG_GLOBAL:
2142 if (cfg_parse_global(file, linenum, args) < 0)
2143 return -1;
2144 break;
2145 default:
2146 Alert("parsing [%s:%d] : unknown keyword '%s' out of section.\n", file, linenum, args[0]);
2147 return -1;
2148 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02002149 }
2150 fclose(f);
2151
2152 /*
2153 * Now, check for the integrity of all that we have collected.
2154 */
2155
2156 /* will be needed further to delay some tasks */
2157 tv_now(&now);
2158
2159 if ((curproxy = proxy) == NULL) {
2160 Alert("parsing %s : no <listen> line. Nothing to do !\n",
2161 file);
2162 return -1;
2163 }
2164
2165 while (curproxy != NULL) {
Willy Tarreau97a738f2006-12-17 18:02:30 +01002166 curproxy->fiprm = curproxy->beprm = curproxy;
2167
Willy Tarreaubaaee002006-06-26 02:48:02 +02002168 if (curproxy->state == PR_STSTOPPED) {
2169 curproxy = curproxy->next;
2170 continue;
2171 }
2172
Willy Tarreau977b8e42006-12-29 14:19:17 +01002173 if (curproxy->cap & PR_CAP_FE && curproxy->listen == NULL) {
2174 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 +01002175 file, proxy_type_str(curproxy), curproxy->id);
Willy Tarreaubaaee002006-06-26 02:48:02 +02002176 cfgerr++;
2177 }
Willy Tarreau977b8e42006-12-29 14:19:17 +01002178 else if (curproxy->cap & PR_CAP_BE &&
2179 ((curproxy->mode != PR_MODE_HEALTH) &&
2180 !(curproxy->options & (PR_O_TRANSP | PR_O_BALANCE)) &&
2181 (*(int *)&curproxy->dispatch_addr.sin_addr == 0))) {
2182 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 +01002183 file, proxy_type_str(curproxy), curproxy->id);
Willy Tarreaubaaee002006-06-26 02:48:02 +02002184 cfgerr++;
2185 }
2186 else if ((curproxy->mode != PR_MODE_HEALTH) && (curproxy->options & PR_O_BALANCE)) {
2187 if (curproxy->options & PR_O_TRANSP) {
Willy Tarreau977b8e42006-12-29 14:19:17 +01002188 Alert("parsing %s : %s '%s' cannot use both transparent and balance mode.\n",
Willy Tarreau2b5652f2006-12-31 17:46:05 +01002189 file, proxy_type_str(curproxy), curproxy->id);
Willy Tarreaubaaee002006-06-26 02:48:02 +02002190 cfgerr++;
2191 }
2192#ifdef WE_DONT_SUPPORT_SERVERLESS_LISTENERS
2193 else if (curproxy->srv == NULL) {
Willy Tarreau977b8e42006-12-29 14:19:17 +01002194 Alert("parsing %s : %s '%s' needs at least 1 server in balance mode.\n",
Willy Tarreau2b5652f2006-12-31 17:46:05 +01002195 file, proxy_type_str(curproxy), curproxy->id);
Willy Tarreaubaaee002006-06-26 02:48:02 +02002196 cfgerr++;
2197 }
2198#endif
2199 else if (*(int *)&curproxy->dispatch_addr.sin_addr != 0) {
Willy Tarreau977b8e42006-12-29 14:19:17 +01002200 Warning("parsing %s : dispatch address of %s '%s' will be ignored in balance mode.\n",
Willy Tarreau2b5652f2006-12-31 17:46:05 +01002201 file, proxy_type_str(curproxy), curproxy->id);
Willy Tarreaubaaee002006-06-26 02:48:02 +02002202 }
2203 }
2204 else if (curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HEALTH) { /* TCP PROXY or HEALTH CHECK */
2205 if (curproxy->cookie_name != NULL) {
Willy Tarreau977b8e42006-12-29 14:19:17 +01002206 Warning("parsing %s : cookie will be ignored for %s '%s'.\n",
Willy Tarreau2b5652f2006-12-31 17:46:05 +01002207 file, proxy_type_str(curproxy), curproxy->id);
Willy Tarreaubaaee002006-06-26 02:48:02 +02002208 }
2209 if ((newsrv = curproxy->srv) != NULL) {
Willy Tarreau977b8e42006-12-29 14:19:17 +01002210 Warning("parsing %s : servers will be ignored for %s '%s'.\n",
Willy Tarreau2b5652f2006-12-31 17:46:05 +01002211 file, proxy_type_str(curproxy), curproxy->id);
Willy Tarreaubaaee002006-06-26 02:48:02 +02002212 }
2213 if (curproxy->rsp_exp != NULL) {
Willy Tarreau977b8e42006-12-29 14:19:17 +01002214 Warning("parsing %s : server regular expressions will be ignored for %s '%s'.\n",
Willy Tarreau2b5652f2006-12-31 17:46:05 +01002215 file, proxy_type_str(curproxy), curproxy->id);
Willy Tarreaubaaee002006-06-26 02:48:02 +02002216 }
2217 if (curproxy->req_exp != NULL) {
Willy Tarreau977b8e42006-12-29 14:19:17 +01002218 Warning("parsing %s : client regular expressions will be ignored for %s '%s'.\n",
Willy Tarreau2b5652f2006-12-31 17:46:05 +01002219 file, proxy_type_str(curproxy), curproxy->id);
Willy Tarreaubaaee002006-06-26 02:48:02 +02002220 }
Willy Tarreau1c47f852006-07-09 08:22:27 +02002221 if (curproxy->monitor_uri != NULL) {
Willy Tarreau977b8e42006-12-29 14:19:17 +01002222 Warning("parsing %s : monitor-uri will be ignored for %s '%s'.\n",
Willy Tarreau2b5652f2006-12-31 17:46:05 +01002223 file, proxy_type_str(curproxy), curproxy->id);
Willy Tarreau1c47f852006-07-09 08:22:27 +02002224 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02002225 }
2226 else if (curproxy->mode == PR_MODE_HTTP) { /* HTTP PROXY */
2227 if ((curproxy->cookie_name != NULL) && ((newsrv = curproxy->srv) == NULL)) {
2228 Alert("parsing %s : HTTP proxy %s has a cookie but no server list !\n",
2229 file, curproxy->id);
2230 cfgerr++;
Willy Tarreau5fdfb912007-01-01 23:11:07 +01002231 }
2232 }
2233
2234 /* if a default backend was specified, let's find it */
2235 if (curproxy->defbe.name) {
2236 struct proxy *target;
2237
2238 for (target = proxy; target != NULL; target = target->next) {
2239 if (strcmp(target->id, curproxy->defbe.name) == 0)
2240 break;
2241 }
2242 if (target == NULL) {
2243 Alert("parsing %s : default backend '%s' in HTTP %s '%s' was not found !\n",
2244 file, curproxy->defbe.name, proxy_type_str(curproxy), curproxy->id);
2245 cfgerr++;
2246 } else if (target == curproxy) {
2247 Alert("parsing %s : loop detected for default backend %s !\n", file, curproxy->defbe.name);
2248 cfgerr++;
2249 } else if (!(target->cap & PR_CAP_BE)) {
2250 Alert("parsing %s : default backend '%s' in HTTP %s '%s' has no backend capability !\n",
2251 file, curproxy->defbe.name, proxy_type_str(curproxy), curproxy->id);
2252 cfgerr++;
2253 } else if (target->mode != curproxy->mode) {
2254 Alert("parsing %s : default backend '%s' in HTTP %s '%s' is not of same mode (tcp/http) !\n",
2255 file, curproxy->defbe.name, proxy_type_str(curproxy), curproxy->id);
2256 cfgerr++;
2257 } else {
2258 free(curproxy->defbe.name);
2259 curproxy->defbe.be = target;
Willy Tarreaubaaee002006-06-26 02:48:02 +02002260 }
2261 }
2262
Willy Tarreau5fdfb912007-01-01 23:11:07 +01002263 /* find the target proxy in setbe */
Willy Tarreaua496b602006-12-17 23:15:24 +01002264 if (curproxy->mode == PR_MODE_HTTP && curproxy->req_exp != NULL) {
2265 /* map jump target for ACT_SETBE in req_rep chain */
2266 struct hdr_exp *exp;
2267 struct proxy *target;
2268 for (exp = curproxy->req_exp; exp != NULL; exp = exp->next) {
2269 if (exp->action != ACT_SETBE)
2270 continue;
2271 for (target = proxy; target != NULL; target = target->next) {
2272 if (strcmp(target->id, exp->replace) == 0)
2273 break;
2274 }
2275 if (target == NULL) {
Willy Tarreau977b8e42006-12-29 14:19:17 +01002276 Alert("parsing %s : backend '%s' in HTTP %s '%s' was not found !\n",
Willy Tarreau2b5652f2006-12-31 17:46:05 +01002277 file, exp->replace, proxy_type_str(curproxy), curproxy->id);
Willy Tarreaua496b602006-12-17 23:15:24 +01002278 cfgerr++;
2279 } else if (target == curproxy) {
2280 Alert("parsing %s : loop detected for backend %s !\n", file, exp->replace);
2281 cfgerr++;
Willy Tarreau977b8e42006-12-29 14:19:17 +01002282 } else if (!(target->cap & PR_CAP_BE)) {
2283 Alert("parsing %s : target '%s' in HTTP %s '%s' has no backend capability !\n",
Willy Tarreau2b5652f2006-12-31 17:46:05 +01002284 file, exp->replace, proxy_type_str(curproxy), curproxy->id);
Willy Tarreau977b8e42006-12-29 14:19:17 +01002285 cfgerr++;
2286 } else if (target->mode != PR_MODE_HTTP) {
2287 Alert("parsing %s : backend '%s' in HTTP %s '%s' is not HTTP (use 'mode http') !\n",
Willy Tarreau2b5652f2006-12-31 17:46:05 +01002288 file, exp->replace, proxy_type_str(curproxy), curproxy->id);
Willy Tarreau977b8e42006-12-29 14:19:17 +01002289 cfgerr++;
Willy Tarreaua496b602006-12-17 23:15:24 +01002290 } else {
2291 free((void *)exp->replace);
2292 exp->replace = (const char *)target;
2293 }
2294 }
2295 }
Willy Tarreau2738a142006-07-08 17:28:09 +02002296 if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) &&
Willy Tarreau977b8e42006-12-29 14:19:17 +01002297 (((curproxy->cap & PR_CAP_FE) && !curproxy->clitimeout) ||
2298 ((curproxy->cap & PR_CAP_BE) && (curproxy->srv) && (!curproxy->contimeout || !curproxy->srvtimeout)))) {
2299 Warning("parsing %s : missing timeouts for %s '%s'.\n"
Willy Tarreau2738a142006-07-08 17:28:09 +02002300 " | While not properly invalid, you will certainly encounter various problems\n"
2301 " | with such a configuration. To fix this, please ensure that all following\n"
2302 " | values are set to a non-zero value: clitimeout, contimeout, srvtimeout.\n",
Willy Tarreau2b5652f2006-12-31 17:46:05 +01002303 file, proxy_type_str(curproxy), curproxy->id);
Willy Tarreau2738a142006-07-08 17:28:09 +02002304 }
Willy Tarreauf3c69202006-07-09 16:42:34 +02002305
2306 if (curproxy->options & PR_O_SSL3_CHK) {
2307 curproxy->check_len = sizeof(sslv3_client_hello_pkt);
2308 curproxy->check_req = (char *)malloc(sizeof(sslv3_client_hello_pkt));
2309 memcpy(curproxy->check_req, sslv3_client_hello_pkt, sizeof(sslv3_client_hello_pkt));
2310 }
2311
Willy Tarreau86034312006-12-29 00:10:33 +01002312 /* for backwards compatibility with "listen" instances, if
2313 * fullconn is not set but maxconn is set, then maxconn
2314 * is used.
2315 */
2316 if (!curproxy->fullconn)
2317 curproxy->fullconn = curproxy->maxconn;
2318
Willy Tarreaubaaee002006-06-26 02:48:02 +02002319 /* first, we will invert the servers list order */
2320 newsrv = NULL;
2321 while (curproxy->srv) {
2322 struct server *next;
2323
2324 next = curproxy->srv->next;
2325 curproxy->srv->next = newsrv;
2326 newsrv = curproxy->srv;
2327 if (!next)
2328 break;
2329 curproxy->srv = next;
2330 }
2331
2332 /* now, newsrv == curproxy->srv */
2333 if (newsrv) {
2334 struct server *srv;
2335 int pgcd;
2336 int act, bck;
2337
2338 /* We will factor the weights to reduce the table,
2339 * using Euclide's largest common divisor algorithm
2340 */
2341 pgcd = newsrv->uweight + 1;
2342 for (srv = newsrv->next; srv && pgcd > 1; srv = srv->next) {
2343 int t, w;
2344
2345 w = srv->uweight + 1;
2346 while (w) {
2347 t = pgcd % w;
2348 pgcd = w;
2349 w = t;
2350 }
2351 }
2352
2353 act = bck = 0;
2354 for (srv = newsrv; srv; srv = srv->next) {
2355 srv->eweight = ((srv->uweight + 1) / pgcd) - 1;
2356 if (srv->state & SRV_BACKUP)
2357 bck += srv->eweight + 1;
2358 else
2359 act += srv->eweight + 1;
2360 }
2361
2362 /* this is the largest map we will ever need for this servers list */
2363 if (act < bck)
2364 act = bck;
2365
2366 curproxy->srv_map = (struct server **)calloc(act, sizeof(struct server *));
2367 /* recounts servers and their weights */
2368 recount_servers(curproxy);
2369 recalc_server_map(curproxy);
2370 }
2371
2372 if (curproxy->options & PR_O_LOGASAP)
2373 curproxy->to_log &= ~LW_BYTES;
2374
Willy Tarreaubaaee002006-06-26 02:48:02 +02002375 /*
2376 * If this server supports a maxconn parameter, it needs a dedicated
2377 * tasks to fill the emptied slots when a connection leaves.
2378 */
2379 newsrv = curproxy->srv;
2380 while (newsrv != NULL) {
Willy Tarreau86034312006-12-29 00:10:33 +01002381 if (newsrv->minconn > newsrv->maxconn) {
Willy Tarreaubaaee002006-06-26 02:48:02 +02002382 /* Only 'minconn' was specified, or it was higher than or equal
2383 * to 'maxconn'. Let's turn this into maxconn and clean it, as
2384 * this will avoid further useless expensive computations.
2385 */
2386 newsrv->maxconn = newsrv->minconn;
Willy Tarreau86034312006-12-29 00:10:33 +01002387 } else if (newsrv->maxconn && !newsrv->minconn) {
2388 /* minconn was not specified, so we set it to maxconn */
2389 newsrv->minconn = newsrv->maxconn;
Willy Tarreau977b8e42006-12-29 14:19:17 +01002390 } else if (newsrv->minconn != newsrv->maxconn && !curproxy->fullconn) {
2391 Alert("parsing %s, %s '%s' : fullconn is mandatory when minconn is set on a server.\n",
Willy Tarreau2b5652f2006-12-31 17:46:05 +01002392 file, proxy_type_str(curproxy), curproxy->id, linenum);
Willy Tarreau86034312006-12-29 00:10:33 +01002393 return -1;
Willy Tarreaubaaee002006-06-26 02:48:02 +02002394 }
2395
2396 if (newsrv->maxconn > 0) {
2397 struct task *t;
2398
2399 if ((t = pool_alloc(task)) == NULL) {
2400 Alert("parsing [%s:%d] : out of memory.\n", file, linenum);
2401 return -1;
2402 }
2403
Willy Tarreau964c9362007-01-07 00:38:00 +01002404 t->rqnext = NULL;
2405 t->wq = NULL;
Willy Tarreaubaaee002006-06-26 02:48:02 +02002406 t->state = TASK_IDLE;
2407 t->process = process_srv_queue;
2408 t->context = newsrv;
2409 newsrv->queue_mgt = t;
2410
2411 /* never run it unless specifically woken up */
2412 tv_eternity(&t->expire);
2413 task_queue(t);
2414 }
2415 newsrv = newsrv->next;
2416 }
2417
2418 /* now we'll start this proxy's health checks if any */
2419 /* 1- count the checkers to run simultaneously */
2420 nbchk = 0;
2421 mininter = 0;
2422 newsrv = curproxy->srv;
2423 while (newsrv != NULL) {
2424 if (newsrv->state & SRV_CHECKED) {
2425 if (!mininter || mininter > newsrv->inter)
2426 mininter = newsrv->inter;
2427 nbchk++;
2428 }
2429 newsrv = newsrv->next;
2430 }
2431
2432 /* 2- start them as far as possible from each others while respecting
2433 * their own intervals. For this, we will start them after their own
2434 * interval added to the min interval divided by the number of servers,
2435 * weighted by the server's position in the list.
2436 */
2437 if (nbchk > 0) {
2438 struct task *t;
2439 int srvpos;
2440
2441 newsrv = curproxy->srv;
2442 srvpos = 0;
2443 while (newsrv != NULL) {
2444 /* should this server be checked ? */
2445 if (newsrv->state & SRV_CHECKED) {
2446 if ((t = pool_alloc(task)) == NULL) {
2447 Alert("parsing [%s:%d] : out of memory.\n", file, linenum);
2448 return -1;
2449 }
2450
Willy Tarreau964c9362007-01-07 00:38:00 +01002451 t->wq = NULL;
2452 t->rqnext = NULL;
Willy Tarreaubaaee002006-06-26 02:48:02 +02002453 t->state = TASK_IDLE;
2454 t->process = process_chk;
2455 t->context = newsrv;
2456
2457 /* check this every ms */
2458 tv_delayfrom(&t->expire, &now,
2459 newsrv->inter + mininter * srvpos / nbchk);
2460 task_queue(t);
2461 //task_wakeup(&rq, t);
2462 srvpos++;
2463 }
2464 newsrv = newsrv->next;
2465 }
2466 }
2467
2468 curproxy = curproxy->next;
2469 }
2470 if (cfgerr > 0) {
2471 Alert("Errors found in configuration file, aborting.\n");
2472 return -1;
2473 }
2474 else
2475 return 0;
2476}
2477
2478
2479
2480/*
2481 * Local variables:
2482 * c-indent-level: 8
2483 * c-basic-offset: 8
2484 * End:
2485 */