blob: 95922476125169f5079c9ddf562961d1c89aa92d [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>
18
Willy Tarreau2dd0d472006-06-29 17:53:05 +020019#include <common/cfgparse.h>
20#include <common/config.h>
21#include <common/memory.h>
22#include <common/standard.h>
23#include <common/time.h>
24#include <common/uri_auth.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020025
26#include <types/capture.h>
27#include <types/global.h>
28#include <types/polling.h>
29#include <types/proxy.h>
30#include <types/queue.h>
31
32#include <proto/backend.h>
33#include <proto/checks.h>
34#include <proto/log.h>
35#include <proto/server.h>
36#include <proto/task.h>
37
38
39const char *HTTP_302 =
40 "HTTP/1.0 302 Found\r\n"
41 "Cache-Control: no-cache\r\n"
42 "Connection: close\r\n"
43 "Location: "; /* not terminated since it will be concatenated with the URL */
44
45/* same as 302 except that the browser MUST retry with the GET method */
46const char *HTTP_303 =
47 "HTTP/1.0 303 See Other\r\n"
48 "Cache-Control: no-cache\r\n"
49 "Connection: close\r\n"
50 "Location: "; /* not terminated since it will be concatenated with the URL */
51
52const char *HTTP_400 =
53 "HTTP/1.0 400 Bad request\r\n"
54 "Cache-Control: no-cache\r\n"
55 "Connection: close\r\n"
Willy Tarreau791d66d2006-07-08 16:53:38 +020056 "Content-Type: text/html\r\n"
Willy Tarreaubaaee002006-06-26 02:48:02 +020057 "\r\n"
58 "<html><body><h1>400 Bad request</h1>\nYour browser sent an invalid request.\n</body></html>\n";
59
60const char *HTTP_403 =
61 "HTTP/1.0 403 Forbidden\r\n"
62 "Cache-Control: no-cache\r\n"
63 "Connection: close\r\n"
Willy Tarreau791d66d2006-07-08 16:53:38 +020064 "Content-Type: text/html\r\n"
Willy Tarreaubaaee002006-06-26 02:48:02 +020065 "\r\n"
66 "<html><body><h1>403 Forbidden</h1>\nRequest forbidden by administrative rules.\n</body></html>\n";
67
68const char *HTTP_408 =
69 "HTTP/1.0 408 Request Time-out\r\n"
70 "Cache-Control: no-cache\r\n"
71 "Connection: close\r\n"
Willy Tarreau791d66d2006-07-08 16:53:38 +020072 "Content-Type: text/html\r\n"
Willy Tarreaubaaee002006-06-26 02:48:02 +020073 "\r\n"
74 "<html><body><h1>408 Request Time-out</h1>\nYour browser didn't send a complete request in time.\n</body></html>\n";
75
76const char *HTTP_500 =
77 "HTTP/1.0 500 Server Error\r\n"
78 "Cache-Control: no-cache\r\n"
79 "Connection: close\r\n"
Willy Tarreau791d66d2006-07-08 16:53:38 +020080 "Content-Type: text/html\r\n"
Willy Tarreaubaaee002006-06-26 02:48:02 +020081 "\r\n"
82 "<html><body><h1>500 Server Error</h1>\nAn internal server error occured.\n</body></html>\n";
83
84const char *HTTP_502 =
85 "HTTP/1.0 502 Bad Gateway\r\n"
86 "Cache-Control: no-cache\r\n"
87 "Connection: close\r\n"
Willy Tarreau791d66d2006-07-08 16:53:38 +020088 "Content-Type: text/html\r\n"
Willy Tarreaubaaee002006-06-26 02:48:02 +020089 "\r\n"
90 "<html><body><h1>502 Bad Gateway</h1>\nThe server returned an invalid or incomplete response.\n</body></html>\n";
91
92const char *HTTP_503 =
93 "HTTP/1.0 503 Service Unavailable\r\n"
94 "Cache-Control: no-cache\r\n"
95 "Connection: close\r\n"
Willy Tarreau791d66d2006-07-08 16:53:38 +020096 "Content-Type: text/html\r\n"
Willy Tarreaubaaee002006-06-26 02:48:02 +020097 "\r\n"
98 "<html><body><h1>503 Service Unavailable</h1>\nNo server is available to handle this request.\n</body></html>\n";
99
100const char *HTTP_504 =
101 "HTTP/1.0 504 Gateway Time-out\r\n"
102 "Cache-Control: no-cache\r\n"
103 "Connection: close\r\n"
Willy Tarreau791d66d2006-07-08 16:53:38 +0200104 "Content-Type: text/html\r\n"
Willy Tarreaubaaee002006-06-26 02:48:02 +0200105 "\r\n"
106 "<html><body><h1>504 Gateway Time-out</h1>\nThe server didn't respond in time.\n</body></html>\n";
107
Willy Tarreauf3c69202006-07-09 16:42:34 +0200108/* This is the SSLv3 CLIENT HELLO packet used in conjunction with the
109 * ssl-hello-chk option to ensure that the remote server speaks SSL.
110 *
111 * Check RFC 2246 (TLSv1.0) sections A.3 and A.4 for details.
112 */
113const char sslv3_client_hello_pkt[] = {
114 "\x16" /* ContentType : 0x16 = Hanshake */
115 "\x03\x00" /* ProtocolVersion : 0x0300 = SSLv3 */
116 "\x00\x79" /* ContentLength : 0x79 bytes after this one */
117 "\x01" /* HanshakeType : 0x01 = CLIENT HELLO */
118 "\x00\x00\x75" /* HandshakeLength : 0x75 bytes after this one */
119 "\x03\x00" /* Hello Version : 0x0300 = v3 */
120 "\x00\x00\x00\x00" /* Unix GMT Time (s) : filled with <now> (@0x0B) */
121 "HAPROXYSSLCHK\nHAPROXYSSLCHK\n" /* Random : must be exactly 28 bytes */
122 "\x00" /* Session ID length : empty (no session ID) */
123 "\x00\x4E" /* Cipher Suite Length : 78 bytes after this one */
124 "\x00\x01" "\x00\x02" "\x00\x03" "\x00\x04" /* 39 most common ciphers : */
125 "\x00\x05" "\x00\x06" "\x00\x07" "\x00\x08" /* 0x01...0x1B, 0x2F...0x3A */
126 "\x00\x09" "\x00\x0A" "\x00\x0B" "\x00\x0C" /* This covers RSA/DH, */
127 "\x00\x0D" "\x00\x0E" "\x00\x0F" "\x00\x10" /* various bit lengths, */
128 "\x00\x11" "\x00\x12" "\x00\x13" "\x00\x14" /* SHA1/MD5, DES/3DES/AES... */
129 "\x00\x15" "\x00\x16" "\x00\x17" "\x00\x18"
130 "\x00\x19" "\x00\x1A" "\x00\x1B" "\x00\x2F"
131 "\x00\x30" "\x00\x31" "\x00\x32" "\x00\x33"
132 "\x00\x34" "\x00\x35" "\x00\x36" "\x00\x37"
133 "\x00\x38" "\x00\x39" "\x00\x3A"
134 "\x01" /* Compression Length : 0x01 = 1 byte for types */
135 "\x00" /* Compression Type : 0x00 = NULL compression */
136};
137
Willy Tarreaubaaee002006-06-26 02:48:02 +0200138
139static struct proxy defproxy; /* fake proxy used to assign default values on all instances */
140int cfg_maxpconn = DEFAULT_MAXCONN; /* # of simultaneous connections per proxy (-N) */
141int cfg_maxconn = 0; /* # of simultaneous connections, (-n) */
142
143/*
144 * converts <str> to a list of listeners which are dynamically allocated.
145 * The format is "{addr|'*'}:port[-end][,{addr|'*'}:port[-end]]*", where :
146 * - <addr> can be empty or "*" to indicate INADDR_ANY ;
147 * - <port> is a numerical port from 1 to 65535 ;
148 * - <end> indicates to use the range from <port> to <end> instead (inclusive).
149 * This can be repeated as many times as necessary, separated by a coma.
150 * The <tail> argument is a pointer to a current list which should be appended
151 * to the tail of the new list. The pointer to the new list is returned.
152 */
153static struct listener *str2listener(char *str, struct listener *tail)
154{
155 struct listener *l;
156 char *c, *next, *range, *dupstr;
157 int port, end;
158
159 next = dupstr = strdup(str);
160
161 while (next && *next) {
162 struct sockaddr_storage ss;
163
164 str = next;
165 /* 1) look for the end of the first address */
166 if ((next = strrchr(str, ',')) != NULL) {
167 *next++ = 0;
168 }
169
170 /* 2) look for the addr/port delimiter, it's the last colon. */
171 if ((range = strrchr(str, ':')) == NULL) {
172 Alert("Missing port number: '%s'\n", str);
173 goto fail;
174 }
175
176 *range++ = 0;
177
178 if (strrchr(str, ':') != NULL) {
179 /* IPv6 address contains ':' */
180 memset(&ss, 0, sizeof(ss));
181 ss.ss_family = AF_INET6;
182
183 if (!inet_pton(ss.ss_family, str, &((struct sockaddr_in6 *)&ss)->sin6_addr)) {
184 Alert("Invalid server address: '%s'\n", str);
185 goto fail;
186 }
187 }
188 else {
189 memset(&ss, 0, sizeof(ss));
190 ss.ss_family = AF_INET;
191
192 if (*str == '*' || *str == '\0') { /* INADDR_ANY */
193 ((struct sockaddr_in *)&ss)->sin_addr.s_addr = INADDR_ANY;
194 }
195 else if (!inet_pton(ss.ss_family, str, &((struct sockaddr_in *)&ss)->sin_addr)) {
196 struct hostent *he;
197
198 if ((he = gethostbyname(str)) == NULL) {
199 Alert("Invalid server name: '%s'\n", str);
200 goto fail;
201 }
202 else
203 ((struct sockaddr_in *)&ss)->sin_addr =
204 *(struct in_addr *) *(he->h_addr_list);
205 }
206 }
207
208 /* 3) look for the port-end delimiter */
209 if ((c = strchr(range, '-')) != NULL) {
210 *c++ = 0;
211 end = atol(c);
212 }
213 else {
214 end = atol(range);
215 }
216
217 port = atol(range);
218
219 if (port < 1 || port > 65535) {
220 Alert("Invalid port '%d' specified for address '%s'.\n", port, str);
221 goto fail;
222 }
223
224 if (end < 1 || end > 65535) {
225 Alert("Invalid port '%d' specified for address '%s'.\n", end, str);
226 goto fail;
227 }
228
229 for (; port <= end; port++) {
230 l = (struct listener *)calloc(1, sizeof(struct listener));
231 l->next = tail;
232 tail = l;
233
234 l->fd = -1;
235 l->addr = ss;
236 if (ss.ss_family == AF_INET6)
237 ((struct sockaddr_in6 *)(&l->addr))->sin6_port = htons(port);
238 else
239 ((struct sockaddr_in *)(&l->addr))->sin_port = htons(port);
240
241 } /* end for(port) */
242 } /* end while(next) */
243 free(dupstr);
244 return tail;
245 fail:
246 free(dupstr);
247 return NULL;
248}
249
250
251/*
252 * parse a line in a <global> section. Returns 0 if OK, -1 if error.
253 */
Willy Tarreaub17916e2006-10-15 15:17:57 +0200254int cfg_parse_global(const char *file, int linenum, char **args)
Willy Tarreaubaaee002006-06-26 02:48:02 +0200255{
256
257 if (!strcmp(args[0], "global")) { /* new section */
258 /* no option, nothing special to do */
259 return 0;
260 }
261 else if (!strcmp(args[0], "daemon")) {
262 global.mode |= MODE_DAEMON;
263 }
264 else if (!strcmp(args[0], "debug")) {
265 global.mode |= MODE_DEBUG;
266 }
267 else if (!strcmp(args[0], "noepoll")) {
268 cfg_polling_mechanism &= ~POLL_USE_EPOLL;
269 }
270 else if (!strcmp(args[0], "nopoll")) {
271 cfg_polling_mechanism &= ~POLL_USE_POLL;
272 }
273 else if (!strcmp(args[0], "quiet")) {
274 global.mode |= MODE_QUIET;
275 }
276 else if (!strcmp(args[0], "stats")) {
277 global.mode |= MODE_STATS;
278 }
279 else if (!strcmp(args[0], "uid")) {
280 if (global.uid != 0) {
281 Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
282 return 0;
283 }
284 if (*(args[1]) == 0) {
285 Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
286 return -1;
287 }
288 global.uid = atol(args[1]);
289 }
290 else if (!strcmp(args[0], "gid")) {
291 if (global.gid != 0) {
292 Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
293 return 0;
294 }
295 if (*(args[1]) == 0) {
296 Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
297 return -1;
298 }
299 global.gid = atol(args[1]);
300 }
301 else if (!strcmp(args[0], "nbproc")) {
302 if (global.nbproc != 0) {
303 Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
304 return 0;
305 }
306 if (*(args[1]) == 0) {
307 Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
308 return -1;
309 }
310 global.nbproc = atol(args[1]);
311 }
312 else if (!strcmp(args[0], "maxconn")) {
313 if (global.maxconn != 0) {
314 Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
315 return 0;
316 }
317 if (*(args[1]) == 0) {
318 Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
319 return -1;
320 }
321 global.maxconn = atol(args[1]);
322#ifdef SYSTEM_MAXCONN
323 if (global.maxconn > DEFAULT_MAXCONN && cfg_maxconn <= DEFAULT_MAXCONN) {
324 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);
325 global.maxconn = DEFAULT_MAXCONN;
326 }
327#endif /* SYSTEM_MAXCONN */
328 }
329 else if (!strcmp(args[0], "ulimit-n")) {
330 if (global.rlimit_nofile != 0) {
331 Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
332 return 0;
333 }
334 if (*(args[1]) == 0) {
335 Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
336 return -1;
337 }
338 global.rlimit_nofile = atol(args[1]);
339 }
340 else if (!strcmp(args[0], "chroot")) {
341 if (global.chroot != NULL) {
342 Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
343 return 0;
344 }
345 if (*(args[1]) == 0) {
346 Alert("parsing [%s:%d] : '%s' expects a directory as an argument.\n", file, linenum, args[0]);
347 return -1;
348 }
349 global.chroot = strdup(args[1]);
350 }
351 else if (!strcmp(args[0], "pidfile")) {
352 if (global.pidfile != NULL) {
353 Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
354 return 0;
355 }
356 if (*(args[1]) == 0) {
357 Alert("parsing [%s:%d] : '%s' expects a file name as an argument.\n", file, linenum, args[0]);
358 return -1;
359 }
360 global.pidfile = strdup(args[1]);
361 }
362 else if (!strcmp(args[0], "log")) { /* syslog server address */
363 struct sockaddr_in *sa;
364 int facility, level;
365
366 if (*(args[1]) == 0 || *(args[2]) == 0) {
367 Alert("parsing [%s:%d] : '%s' expects <address> and <facility> as arguments.\n", file, linenum, args[0]);
368 return -1;
369 }
370
371 facility = get_log_facility(args[2]);
372 if (facility < 0) {
373 Alert("parsing [%s:%d] : unknown log facility '%s'\n", file, linenum, args[2]);
374 exit(1);
375 }
376
377 level = 7; /* max syslog level = debug */
378 if (*(args[3])) {
379 level = get_log_level(args[3]);
380 if (level < 0) {
381 Alert("parsing [%s:%d] : unknown optional log level '%s'\n", file, linenum, args[3]);
382 exit(1);
383 }
384 }
385
386 sa = str2sa(args[1]);
387 if (!sa->sin_port)
388 sa->sin_port = htons(SYSLOG_PORT);
389
390 if (global.logfac1 == -1) {
391 global.logsrv1 = *sa;
392 global.logfac1 = facility;
393 global.loglev1 = level;
394 }
395 else if (global.logfac2 == -1) {
396 global.logsrv2 = *sa;
397 global.logfac2 = facility;
398 global.loglev2 = level;
399 }
400 else {
401 Alert("parsing [%s:%d] : too many syslog servers\n", file, linenum);
402 return -1;
403 }
404
405 }
406 else {
407 Alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], "global");
408 return -1;
409 }
410 return 0;
411}
412
413
414static void init_default_instance()
415{
416 memset(&defproxy, 0, sizeof(defproxy));
417 defproxy.mode = PR_MODE_TCP;
418 defproxy.state = PR_STNEW;
419 defproxy.maxconn = cfg_maxpconn;
420 defproxy.conn_retries = CONN_RETRIES;
421 defproxy.logfac1 = defproxy.logfac2 = -1; /* log disabled */
422}
423
424/*
425 * parse a line in a <listen> section. Returns 0 if OK, -1 if error.
426 */
Willy Tarreaub17916e2006-10-15 15:17:57 +0200427int cfg_parse_listen(const char *file, int linenum, char **args)
Willy Tarreaubaaee002006-06-26 02:48:02 +0200428{
429 static struct proxy *curproxy = NULL;
430 struct server *newsrv = NULL;
Willy Tarreaub17916e2006-10-15 15:17:57 +0200431 const char *err;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200432 int rc;
433
434 if (!strcmp(args[0], "listen")) { /* new proxy */
435 if (!*args[1]) {
436 Alert("parsing [%s:%d] : '%s' expects an <id> argument and\n"
437 " optionnally supports [addr1]:port1[-end1]{,[addr]:port[-end]}...\n",
438 file, linenum, args[0]);
439 return -1;
440 }
441
442 if ((curproxy = (struct proxy *)calloc(1, sizeof(struct proxy))) == NULL) {
443 Alert("parsing [%s:%d] : out of memory.\n", file, linenum);
444 return -1;
445 }
446
447 curproxy->next = proxy;
448 proxy = curproxy;
449 LIST_INIT(&curproxy->pendconns);
450
451 curproxy->id = strdup(args[1]);
452
453 /* parse the listener address if any */
454 if (*args[2]) {
455 curproxy->listen = str2listener(args[2], curproxy->listen);
456 if (!curproxy->listen)
457 return -1;
458 global.maxsock++;
459 }
460
461 /* set default values */
462 curproxy->state = defproxy.state;
463 curproxy->maxconn = defproxy.maxconn;
464 curproxy->conn_retries = defproxy.conn_retries;
465 curproxy->options = defproxy.options;
466
467 if (defproxy.check_req)
468 curproxy->check_req = strdup(defproxy.check_req);
469 curproxy->check_len = defproxy.check_len;
470
471 if (defproxy.cookie_name)
472 curproxy->cookie_name = strdup(defproxy.cookie_name);
473 curproxy->cookie_len = defproxy.cookie_len;
474
475 if (defproxy.capture_name)
476 curproxy->capture_name = strdup(defproxy.capture_name);
477 curproxy->capture_namelen = defproxy.capture_namelen;
478 curproxy->capture_len = defproxy.capture_len;
479
480 if (defproxy.errmsg.msg400)
481 curproxy->errmsg.msg400 = strdup(defproxy.errmsg.msg400);
482 curproxy->errmsg.len400 = defproxy.errmsg.len400;
483
484 if (defproxy.errmsg.msg403)
485 curproxy->errmsg.msg403 = strdup(defproxy.errmsg.msg403);
486 curproxy->errmsg.len403 = defproxy.errmsg.len403;
487
488 if (defproxy.errmsg.msg408)
489 curproxy->errmsg.msg408 = strdup(defproxy.errmsg.msg408);
490 curproxy->errmsg.len408 = defproxy.errmsg.len408;
491
492 if (defproxy.errmsg.msg500)
493 curproxy->errmsg.msg500 = strdup(defproxy.errmsg.msg500);
494 curproxy->errmsg.len500 = defproxy.errmsg.len500;
495
496 if (defproxy.errmsg.msg502)
497 curproxy->errmsg.msg502 = strdup(defproxy.errmsg.msg502);
498 curproxy->errmsg.len502 = defproxy.errmsg.len502;
499
500 if (defproxy.errmsg.msg503)
501 curproxy->errmsg.msg503 = strdup(defproxy.errmsg.msg503);
502 curproxy->errmsg.len503 = defproxy.errmsg.len503;
503
504 if (defproxy.errmsg.msg504)
505 curproxy->errmsg.msg504 = strdup(defproxy.errmsg.msg504);
506 curproxy->errmsg.len504 = defproxy.errmsg.len504;
507
508 curproxy->clitimeout = defproxy.clitimeout;
509 curproxy->contimeout = defproxy.contimeout;
510 curproxy->srvtimeout = defproxy.srvtimeout;
511 curproxy->mode = defproxy.mode;
512 curproxy->logfac1 = defproxy.logfac1;
513 curproxy->logsrv1 = defproxy.logsrv1;
514 curproxy->loglev1 = defproxy.loglev1;
515 curproxy->logfac2 = defproxy.logfac2;
516 curproxy->logsrv2 = defproxy.logsrv2;
517 curproxy->loglev2 = defproxy.loglev2;
518 curproxy->to_log = defproxy.to_log & ~LW_COOKIE & ~LW_REQHDR & ~ LW_RSPHDR;
519 curproxy->grace = defproxy.grace;
520 curproxy->uri_auth = defproxy.uri_auth;
521 curproxy->source_addr = defproxy.source_addr;
522 curproxy->mon_net = defproxy.mon_net;
523 curproxy->mon_mask = defproxy.mon_mask;
Willy Tarreau1c47f852006-07-09 08:22:27 +0200524
525 if (defproxy.monitor_uri)
526 curproxy->monitor_uri = strdup(defproxy.monitor_uri);
527 curproxy->monitor_uri_len = defproxy.monitor_uri_len;
528
Willy Tarreaubaaee002006-06-26 02:48:02 +0200529 return 0;
530 }
531 else if (!strcmp(args[0], "defaults")) { /* use this one to assign default values */
532 /* some variables may have already been initialized earlier */
533 if (defproxy.check_req) free(defproxy.check_req);
534 if (defproxy.cookie_name) free(defproxy.cookie_name);
535 if (defproxy.capture_name) free(defproxy.capture_name);
536 if (defproxy.errmsg.msg400) free(defproxy.errmsg.msg400);
537 if (defproxy.errmsg.msg403) free(defproxy.errmsg.msg403);
538 if (defproxy.errmsg.msg408) free(defproxy.errmsg.msg408);
539 if (defproxy.errmsg.msg500) free(defproxy.errmsg.msg500);
540 if (defproxy.errmsg.msg502) free(defproxy.errmsg.msg502);
541 if (defproxy.errmsg.msg503) free(defproxy.errmsg.msg503);
542 if (defproxy.errmsg.msg504) free(defproxy.errmsg.msg504);
Willy Tarreau1c47f852006-07-09 08:22:27 +0200543 if (defproxy.monitor_uri) free(defproxy.monitor_uri);
Willy Tarreaubaaee002006-06-26 02:48:02 +0200544 /* we cannot free uri_auth because it might already be used */
545 init_default_instance();
546 curproxy = &defproxy;
547 return 0;
548 }
549 else if (curproxy == NULL) {
550 Alert("parsing [%s:%d] : 'listen' or 'defaults' expected.\n", file, linenum);
551 return -1;
552 }
553
554 if (!strcmp(args[0], "bind")) { /* new listen addresses */
555 if (curproxy == &defproxy) {
556 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
557 return -1;
558 }
559
560 if (strchr(args[1], ':') == NULL) {
561 Alert("parsing [%s:%d] : '%s' expects [addr1]:port1[-end1]{,[addr]:port[-end]}... as arguments.\n",
562 file, linenum, args[0]);
563 return -1;
564 }
565 curproxy->listen = str2listener(args[1], curproxy->listen);
566 if (!curproxy->listen)
567 return -1;
568 global.maxsock++;
569 return 0;
570 }
571 else if (!strcmp(args[0], "monitor-net")) { /* set the range of IPs to ignore */
572 if (!*args[1] || !str2net(args[1], &curproxy->mon_net, &curproxy->mon_mask)) {
573 Alert("parsing [%s:%d] : '%s' expects address[/mask].\n",
574 file, linenum, args[0]);
575 return -1;
576 }
577 /* flush useless bits */
578 curproxy->mon_net.s_addr &= curproxy->mon_mask.s_addr;
579 return 0;
580 }
Willy Tarreau1c47f852006-07-09 08:22:27 +0200581 else if (!strcmp(args[0], "monitor-uri")) { /* set the URI to intercept */
582 if (!*args[1]) {
583 Alert("parsing [%s:%d] : '%s' expects an URI.\n",
584 file, linenum, args[0]);
585 return -1;
586 }
587
588 if (curproxy->monitor_uri != NULL)
589 free(curproxy->monitor_uri);
590
591 curproxy->monitor_uri_len = strlen(args[1]) + 2; /* include leading and trailing spaces */
592 curproxy->monitor_uri = (char *)calloc(1, curproxy->monitor_uri_len + 1);
593 memcpy(curproxy->monitor_uri + 1, args[1], curproxy->monitor_uri_len - 2);
594 curproxy->monitor_uri[curproxy->monitor_uri_len-1] = curproxy->monitor_uri[0] = ' ';
595 curproxy->monitor_uri[curproxy->monitor_uri_len] = '\0';
596
597 return 0;
598 }
Willy Tarreaubaaee002006-06-26 02:48:02 +0200599 else if (!strcmp(args[0], "mode")) { /* sets the proxy mode */
600 if (!strcmp(args[1], "http")) curproxy->mode = PR_MODE_HTTP;
601 else if (!strcmp(args[1], "tcp")) curproxy->mode = PR_MODE_TCP;
602 else if (!strcmp(args[1], "health")) curproxy->mode = PR_MODE_HEALTH;
603 else {
604 Alert("parsing [%s:%d] : unknown proxy mode '%s'.\n", file, linenum, args[1]);
605 return -1;
606 }
607 }
608 else if (!strcmp(args[0], "disabled")) { /* disables this proxy */
609 curproxy->state = PR_STSTOPPED;
610 }
611 else if (!strcmp(args[0], "enabled")) { /* enables this proxy (used to revert a disabled default) */
612 curproxy->state = PR_STNEW;
613 }
614 else if (!strcmp(args[0], "cookie")) { /* cookie name */
615 int cur_arg;
616 // if (curproxy == &defproxy) {
617 // Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
618 // return -1;
619 // }
620
621 if (curproxy->cookie_name != NULL) {
622 // Alert("parsing [%s:%d] : cookie name already specified. Continuing.\n",
623 // file, linenum);
624 // return 0;
625 free(curproxy->cookie_name);
626 }
627
628 if (*(args[1]) == 0) {
629 Alert("parsing [%s:%d] : '%s' expects <cookie_name> as argument.\n",
630 file, linenum, args[0]);
631 return -1;
632 }
633 curproxy->cookie_name = strdup(args[1]);
634 curproxy->cookie_len = strlen(curproxy->cookie_name);
635
636 cur_arg = 2;
637 while (*(args[cur_arg])) {
638 if (!strcmp(args[cur_arg], "rewrite")) {
639 curproxy->options |= PR_O_COOK_RW;
640 }
641 else if (!strcmp(args[cur_arg], "indirect")) {
642 curproxy->options |= PR_O_COOK_IND;
643 }
644 else if (!strcmp(args[cur_arg], "insert")) {
645 curproxy->options |= PR_O_COOK_INS;
646 }
647 else if (!strcmp(args[cur_arg], "nocache")) {
648 curproxy->options |= PR_O_COOK_NOC;
649 }
650 else if (!strcmp(args[cur_arg], "postonly")) {
651 curproxy->options |= PR_O_COOK_POST;
652 }
653 else if (!strcmp(args[cur_arg], "prefix")) {
654 curproxy->options |= PR_O_COOK_PFX;
655 }
656 else {
657 Alert("parsing [%s:%d] : '%s' supports 'rewrite', 'insert', 'prefix', 'indirect', 'nocache' and 'postonly' options.\n",
658 file, linenum, args[0]);
659 return -1;
660 }
661 cur_arg++;
662 }
663 if (!POWEROF2(curproxy->options & (PR_O_COOK_RW|PR_O_COOK_IND))) {
664 Alert("parsing [%s:%d] : cookie 'rewrite' and 'indirect' modes are incompatible.\n",
665 file, linenum);
666 return -1;
667 }
668
669 if (!POWEROF2(curproxy->options & (PR_O_COOK_RW|PR_O_COOK_INS|PR_O_COOK_PFX))) {
670 Alert("parsing [%s:%d] : cookie 'rewrite', 'insert' and 'prefix' modes are incompatible.\n",
671 file, linenum);
672 return -1;
673 }
674 }/* end else if (!strcmp(args[0], "cookie")) */
675 else if (!strcmp(args[0], "appsession")) { /* cookie name */
676 // if (curproxy == &defproxy) {
677 // Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
678 // return -1;
679 // }
680
681 if (curproxy->appsession_name != NULL) {
682 // Alert("parsing [%s:%d] : cookie name already specified. Continuing.\n",
683 // file, linenum);
684 // return 0;
685 free(curproxy->appsession_name);
686 }
687
688 if (*(args[5]) == 0) {
689 Alert("parsing [%s:%d] : '%s' expects 'appsession' <cookie_name> 'len' <len> 'timeout' <timeout>.\n",
690 file, linenum, args[0]);
691 return -1;
692 }
693 have_appsession = 1;
694 curproxy->appsession_name = strdup(args[1]);
695 curproxy->appsession_name_len = strlen(curproxy->appsession_name);
696 curproxy->appsession_len = atoi(args[3]);
697 curproxy->appsession_timeout = atoi(args[5]);
698 rc = chtbl_init(&(curproxy->htbl_proxy), TBLSIZ, hashpjw, match_str, destroy);
699 if (rc) {
700 Alert("Error Init Appsession Hashtable.\n");
701 return -1;
702 }
703 } /* Url App Session */
704 else if (!strcmp(args[0], "capture")) {
705 if (!strcmp(args[1], "cookie")) { /* name of a cookie to capture */
706 // if (curproxy == &defproxy) {
707 // Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
708 // return -1;
709 // }
710
711 if (curproxy->capture_name != NULL) {
712 // Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n",
713 // file, linenum, args[0]);
714 // return 0;
715 free(curproxy->capture_name);
716 }
717
718 if (*(args[4]) == 0) {
719 Alert("parsing [%s:%d] : '%s' expects 'cookie' <cookie_name> 'len' <len>.\n",
720 file, linenum, args[0]);
721 return -1;
722 }
723 curproxy->capture_name = strdup(args[2]);
724 curproxy->capture_namelen = strlen(curproxy->capture_name);
725 curproxy->capture_len = atol(args[4]);
726 if (curproxy->capture_len >= CAPTURE_LEN) {
727 Warning("parsing [%s:%d] : truncating capture length to %d bytes.\n",
728 file, linenum, CAPTURE_LEN - 1);
729 curproxy->capture_len = CAPTURE_LEN - 1;
730 }
731 curproxy->to_log |= LW_COOKIE;
732 }
733 else if (!strcmp(args[1], "request") && !strcmp(args[2], "header")) {
734 struct cap_hdr *hdr;
735
736 if (curproxy == &defproxy) {
737 Alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
738 return -1;
739 }
740
741 if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) {
742 Alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n",
743 file, linenum, args[0], args[1]);
744 return -1;
745 }
746
747 hdr = calloc(sizeof(struct cap_hdr), 1);
748 hdr->next = curproxy->req_cap;
749 hdr->name = strdup(args[3]);
750 hdr->namelen = strlen(args[3]);
751 hdr->len = atol(args[5]);
752 hdr->index = curproxy->nb_req_cap++;
753 curproxy->req_cap = hdr;
754 curproxy->to_log |= LW_REQHDR;
755 }
756 else if (!strcmp(args[1], "response") && !strcmp(args[2], "header")) {
757 struct cap_hdr *hdr;
758
759 if (curproxy == &defproxy) {
760 Alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
761 return -1;
762 }
763
764 if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) {
765 Alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n",
766 file, linenum, args[0], args[1]);
767 return -1;
768 }
769 hdr = calloc(sizeof(struct cap_hdr), 1);
770 hdr->next = curproxy->rsp_cap;
771 hdr->name = strdup(args[3]);
772 hdr->namelen = strlen(args[3]);
773 hdr->len = atol(args[5]);
774 hdr->index = curproxy->nb_rsp_cap++;
775 curproxy->rsp_cap = hdr;
776 curproxy->to_log |= LW_RSPHDR;
777 }
778 else {
779 Alert("parsing [%s:%d] : '%s' expects 'cookie' or 'request header' or 'response header'.\n",
780 file, linenum, args[0]);
781 return -1;
782 }
783 }
784 else if (!strcmp(args[0], "contimeout")) { /* connect timeout */
785 if (curproxy->contimeout != defproxy.contimeout) {
786 Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
787 return 0;
788 }
789 if (*(args[1]) == 0) {
790 Alert("parsing [%s:%d] : '%s' expects an integer <time_in_ms> as argument.\n",
791 file, linenum, args[0]);
792 return -1;
793 }
794 curproxy->contimeout = atol(args[1]);
795 }
796 else if (!strcmp(args[0], "clitimeout")) { /* client timeout */
797 if (curproxy->clitimeout != defproxy.clitimeout) {
798 Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n",
799 file, linenum, args[0]);
800 return 0;
801 }
802 if (*(args[1]) == 0) {
803 Alert("parsing [%s:%d] : '%s' expects an integer <time_in_ms> as argument.\n",
804 file, linenum, args[0]);
805 return -1;
806 }
807 curproxy->clitimeout = atol(args[1]);
808 }
809 else if (!strcmp(args[0], "srvtimeout")) { /* server timeout */
810 if (curproxy->srvtimeout != defproxy.srvtimeout) {
811 Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
812 return 0;
813 }
814 if (*(args[1]) == 0) {
815 Alert("parsing [%s:%d] : '%s' expects an integer <time_in_ms> as argument.\n",
816 file, linenum, args[0]);
817 return -1;
818 }
819 curproxy->srvtimeout = atol(args[1]);
820 }
821 else if (!strcmp(args[0], "retries")) { /* connection retries */
822 if (*(args[1]) == 0) {
823 Alert("parsing [%s:%d] : '%s' expects an integer argument (dispatch counts for one).\n",
824 file, linenum, args[0]);
825 return -1;
826 }
827 curproxy->conn_retries = atol(args[1]);
828 }
829 else if (!strcmp(args[0], "stats")) {
830 if (curproxy != &defproxy && curproxy->uri_auth == defproxy.uri_auth)
831 curproxy->uri_auth = NULL; /* we must detach from the default config */
832
833 if (*(args[1]) == 0) {
834 Alert("parsing [%s:%d] : '%s' expects 'uri', 'realm', 'auth', 'scope' or 'enable'.\n", file, linenum, args[0]);
835 return -1;
836 } else if (!strcmp(args[1], "uri")) {
837 if (*(args[2]) == 0) {
838 Alert("parsing [%s:%d] : 'uri' needs an URI prefix.\n", file, linenum);
839 return -1;
840 } else if (!stats_set_uri(&curproxy->uri_auth, args[2])) {
841 Alert("parsing [%s:%d] : out of memory.\n", file, linenum);
842 return -1;
843 }
844 } else if (!strcmp(args[1], "realm")) {
845 if (*(args[2]) == 0) {
846 Alert("parsing [%s:%d] : 'realm' needs an realm name.\n", file, linenum);
847 return -1;
848 } else if (!stats_set_realm(&curproxy->uri_auth, args[2])) {
849 Alert("parsing [%s:%d] : out of memory.\n", file, linenum);
850 return -1;
851 }
852 } else if (!strcmp(args[1], "auth")) {
853 if (*(args[2]) == 0) {
854 Alert("parsing [%s:%d] : 'auth' needs a user:password account.\n", file, linenum);
855 return -1;
856 } else if (!stats_add_auth(&curproxy->uri_auth, args[2])) {
857 Alert("parsing [%s:%d] : out of memory.\n", file, linenum);
858 return -1;
859 }
860 } else if (!strcmp(args[1], "scope")) {
861 if (*(args[2]) == 0) {
862 Alert("parsing [%s:%d] : 'scope' needs a proxy name.\n", file, linenum);
863 return -1;
864 } else if (!stats_add_scope(&curproxy->uri_auth, args[2])) {
865 Alert("parsing [%s:%d] : out of memory.\n", file, linenum);
866 return -1;
867 }
868 } else if (!strcmp(args[1], "enable")) {
869 if (!stats_check_init_uri_auth(&curproxy->uri_auth)) {
870 Alert("parsing [%s:%d] : out of memory.\n", file, linenum);
871 return -1;
872 }
873 } else {
874 Alert("parsing [%s:%d] : unknown stats parameter '%s' (expects 'uri', 'realm', 'auth' or 'enable').\n",
875 file, linenum, args[0]);
876 return -1;
877 }
878 }
879 else if (!strcmp(args[0], "option")) {
880 if (*(args[1]) == 0) {
881 Alert("parsing [%s:%d] : '%s' expects an option name.\n", file, linenum, args[0]);
882 return -1;
883 }
884 if (!strcmp(args[1], "redispatch"))
885 /* enable reconnections to dispatch */
886 curproxy->options |= PR_O_REDISP;
887#ifdef TPROXY
888 else if (!strcmp(args[1], "transparent"))
889 /* enable transparent proxy connections */
890 curproxy->options |= PR_O_TRANSP;
891#endif
892 else if (!strcmp(args[1], "keepalive"))
893 /* enable keep-alive */
894 curproxy->options |= PR_O_KEEPALIVE;
895 else if (!strcmp(args[1], "forwardfor"))
896 /* insert x-forwarded-for field */
897 curproxy->options |= PR_O_FWDFOR;
898 else if (!strcmp(args[1], "logasap"))
899 /* log as soon as possible, without waiting for the session to complete */
900 curproxy->options |= PR_O_LOGASAP;
901 else if (!strcmp(args[1], "abortonclose"))
902 /* abort connection if client closes during queue or connect() */
903 curproxy->options |= PR_O_ABRT_CLOSE;
904 else if (!strcmp(args[1], "httpclose"))
905 /* force connection: close in both directions in HTTP mode */
906 curproxy->options |= PR_O_HTTP_CLOSE;
907 else if (!strcmp(args[1], "forceclose"))
908 /* force connection: close in both directions in HTTP mode and enforce end of session */
909 curproxy->options |= PR_O_FORCE_CLO | PR_O_HTTP_CLOSE;
910 else if (!strcmp(args[1], "checkcache"))
911 /* require examination of cacheability of the 'set-cookie' field */
912 curproxy->options |= PR_O_CHK_CACHE;
913 else if (!strcmp(args[1], "httplog"))
914 /* generate a complete HTTP log */
915 curproxy->to_log |= LW_DATE | LW_CLIP | LW_SVID | LW_REQ | LW_PXID | LW_RESP | LW_BYTES;
916 else if (!strcmp(args[1], "tcplog"))
917 /* generate a detailed TCP log */
918 curproxy->to_log |= LW_DATE | LW_CLIP | LW_SVID | LW_PXID | LW_BYTES;
919 else if (!strcmp(args[1], "dontlognull")) {
920 /* don't log empty requests */
921 curproxy->options |= PR_O_NULLNOLOG;
922 }
923 else if (!strcmp(args[1], "tcpka")) {
924 /* enable TCP keep-alives on client and server sessions */
925 curproxy->options |= PR_O_TCP_CLI_KA | PR_O_TCP_SRV_KA;
926 }
927 else if (!strcmp(args[1], "clitcpka")) {
928 /* enable TCP keep-alives on client sessions */
929 curproxy->options |= PR_O_TCP_CLI_KA;
930 }
931 else if (!strcmp(args[1], "srvtcpka")) {
932 /* enable TCP keep-alives on server sessions */
933 curproxy->options |= PR_O_TCP_SRV_KA;
934 }
935 else if (!strcmp(args[1], "allbackups")) {
936 /* Use all backup servers simultaneously */
937 curproxy->options |= PR_O_USE_ALL_BK;
938 }
939 else if (!strcmp(args[1], "httpchk")) {
940 /* use HTTP request to check servers' health */
941 if (curproxy->check_req != NULL) {
942 free(curproxy->check_req);
943 }
944 curproxy->options |= PR_O_HTTP_CHK;
Willy Tarreauf3c69202006-07-09 16:42:34 +0200945 curproxy->options &= ~PR_O_SSL3_CHK;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200946 if (!*args[2]) { /* no argument */
947 curproxy->check_req = strdup(DEF_CHECK_REQ); /* default request */
948 curproxy->check_len = strlen(DEF_CHECK_REQ);
949 } else if (!*args[3]) { /* one argument : URI */
950 int reqlen = strlen(args[2]) + strlen("OPTIONS / HTTP/1.0\r\n\r\n");
951 curproxy->check_req = (char *)malloc(reqlen);
952 curproxy->check_len = snprintf(curproxy->check_req, reqlen,
953 "OPTIONS %s HTTP/1.0\r\n\r\n", args[2]); /* URI to use */
954 } else { /* more arguments : METHOD URI [HTTP_VER] */
955 int reqlen = strlen(args[2]) + strlen(args[3]) + 3 + strlen("\r\n\r\n");
956 if (*args[4])
957 reqlen += strlen(args[4]);
958 else
959 reqlen += strlen("HTTP/1.0");
960
961 curproxy->check_req = (char *)malloc(reqlen);
962 curproxy->check_len = snprintf(curproxy->check_req, reqlen,
963 "%s %s %s\r\n\r\n", args[2], args[3], *args[4]?args[4]:"HTTP/1.0");
964 }
Willy Tarreauf3c69202006-07-09 16:42:34 +0200965 }
966 else if (!strcmp(args[1], "ssl-hello-chk")) {
967 /* use SSLv3 CLIENT HELLO to check servers' health */
968 if (curproxy->check_req != NULL) {
969 free(curproxy->check_req);
970 }
971 curproxy->options &= ~PR_O_HTTP_CHK;
972 curproxy->options |= PR_O_SSL3_CHK;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200973 }
974 else if (!strcmp(args[1], "persist")) {
975 /* persist on using the server specified by the cookie, even when it's down */
976 curproxy->options |= PR_O_PERSIST;
977 }
978 else {
979 Alert("parsing [%s:%d] : unknown option '%s'.\n", file, linenum, args[1]);
980 return -1;
981 }
982 return 0;
983 }
984 else if (!strcmp(args[0], "redispatch") || !strcmp(args[0], "redisp")) {
985 /* enable reconnections to dispatch */
986 curproxy->options |= PR_O_REDISP;
987 }
988#ifdef TPROXY
989 else if (!strcmp(args[0], "transparent")) {
990 /* enable transparent proxy connections */
991 curproxy->options |= PR_O_TRANSP;
992 }
993#endif
994 else if (!strcmp(args[0], "maxconn")) { /* maxconn */
995 if (*(args[1]) == 0) {
996 Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
997 return -1;
998 }
999 curproxy->maxconn = atol(args[1]);
1000 }
1001 else if (!strcmp(args[0], "grace")) { /* grace time (ms) */
1002 if (*(args[1]) == 0) {
1003 Alert("parsing [%s:%d] : '%s' expects a time in milliseconds.\n", file, linenum, args[0]);
1004 return -1;
1005 }
1006 curproxy->grace = atol(args[1]);
1007 }
1008 else if (!strcmp(args[0], "dispatch")) { /* dispatch address */
1009 if (curproxy == &defproxy) {
1010 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1011 return -1;
1012 }
1013 if (strchr(args[1], ':') == NULL) {
1014 Alert("parsing [%s:%d] : '%s' expects <addr:port> as argument.\n", file, linenum, args[0]);
1015 return -1;
1016 }
1017 curproxy->dispatch_addr = *str2sa(args[1]);
1018 }
1019 else if (!strcmp(args[0], "balance")) { /* set balancing with optional algorithm */
1020 if (*(args[1])) {
1021 if (!strcmp(args[1], "roundrobin")) {
1022 curproxy->options |= PR_O_BALANCE_RR;
1023 }
1024 else if (!strcmp(args[1], "source")) {
1025 curproxy->options |= PR_O_BALANCE_SH;
1026 }
1027 else {
1028 Alert("parsing [%s:%d] : '%s' only supports 'roundrobin' and 'source' options.\n", file, linenum, args[0]);
1029 return -1;
1030 }
1031 }
1032 else /* if no option is set, use round-robin by default */
1033 curproxy->options |= PR_O_BALANCE_RR;
1034 }
1035 else if (!strcmp(args[0], "server")) { /* server address */
1036 int cur_arg;
1037 char *rport;
1038 char *raddr;
1039 short realport;
1040 int do_check;
1041
1042 if (curproxy == &defproxy) {
1043 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1044 return -1;
1045 }
1046
1047 if (!*args[2]) {
1048 Alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n",
1049 file, linenum, args[0]);
1050 return -1;
1051 }
1052 if ((newsrv = (struct server *)calloc(1, sizeof(struct server))) == NULL) {
1053 Alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1054 return -1;
1055 }
1056
1057 /* the servers are linked backwards first */
1058 newsrv->next = curproxy->srv;
1059 curproxy->srv = newsrv;
1060 newsrv->proxy = curproxy;
1061
1062 LIST_INIT(&newsrv->pendconns);
1063 do_check = 0;
1064 newsrv->state = SRV_RUNNING; /* early server setup */
1065 newsrv->id = strdup(args[1]);
1066
1067 /* several ways to check the port component :
1068 * - IP => port=+0, relative
1069 * - IP: => port=+0, relative
1070 * - IP:N => port=N, absolute
1071 * - IP:+N => port=+N, relative
1072 * - IP:-N => port=-N, relative
1073 */
1074 raddr = strdup(args[2]);
1075 rport = strchr(raddr, ':');
1076 if (rport) {
1077 *rport++ = 0;
1078 realport = atol(rport);
1079 if (!isdigit((int)*rport))
1080 newsrv->state |= SRV_MAPPORTS;
1081 } else {
1082 realport = 0;
1083 newsrv->state |= SRV_MAPPORTS;
1084 }
1085
1086 newsrv->addr = *str2sa(raddr);
1087 newsrv->addr.sin_port = htons(realport);
1088 free(raddr);
1089
1090 newsrv->curfd = -1; /* no health-check in progress */
1091 newsrv->inter = DEF_CHKINTR;
1092 newsrv->rise = DEF_RISETIME;
1093 newsrv->fall = DEF_FALLTIME;
1094 newsrv->health = newsrv->rise; /* up, but will fall down at first failure */
1095 cur_arg = 3;
1096 while (*args[cur_arg]) {
1097 if (!strcmp(args[cur_arg], "cookie")) {
1098 newsrv->cookie = strdup(args[cur_arg + 1]);
1099 newsrv->cklen = strlen(args[cur_arg + 1]);
1100 cur_arg += 2;
1101 }
1102 else if (!strcmp(args[cur_arg], "rise")) {
1103 newsrv->rise = atol(args[cur_arg + 1]);
1104 newsrv->health = newsrv->rise;
1105 cur_arg += 2;
1106 }
1107 else if (!strcmp(args[cur_arg], "fall")) {
1108 newsrv->fall = atol(args[cur_arg + 1]);
1109 cur_arg += 2;
1110 }
1111 else if (!strcmp(args[cur_arg], "inter")) {
1112 newsrv->inter = atol(args[cur_arg + 1]);
1113 cur_arg += 2;
1114 }
1115 else if (!strcmp(args[cur_arg], "port")) {
1116 newsrv->check_port = atol(args[cur_arg + 1]);
1117 cur_arg += 2;
1118 }
1119 else if (!strcmp(args[cur_arg], "backup")) {
1120 newsrv->state |= SRV_BACKUP;
1121 cur_arg ++;
1122 }
1123 else if (!strcmp(args[cur_arg], "weight")) {
1124 int w;
1125 w = atol(args[cur_arg + 1]);
1126 if (w < 1 || w > 256) {
1127 Alert("parsing [%s:%d] : weight of server %s is not within 1 and 256 (%d).\n",
1128 file, linenum, newsrv->id, w);
1129 return -1;
1130 }
1131 newsrv->uweight = w - 1;
1132 cur_arg += 2;
1133 }
1134 else if (!strcmp(args[cur_arg], "minconn")) {
1135 newsrv->minconn = atol(args[cur_arg + 1]);
1136 cur_arg += 2;
1137 }
1138 else if (!strcmp(args[cur_arg], "maxconn")) {
1139 newsrv->maxconn = atol(args[cur_arg + 1]);
1140 cur_arg += 2;
1141 }
1142 else if (!strcmp(args[cur_arg], "check")) {
1143 global.maxsock++;
1144 do_check = 1;
1145 cur_arg += 1;
1146 }
1147 else if (!strcmp(args[cur_arg], "source")) { /* address to which we bind when connecting */
1148 if (!*args[cur_arg + 1]) {
1149 Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>] as argument.\n",
1150 file, linenum, "source");
1151 return -1;
1152 }
1153 newsrv->state |= SRV_BIND_SRC;
1154 newsrv->source_addr = *str2sa(args[cur_arg + 1]);
1155 cur_arg += 2;
Willy Tarreau77074d52006-11-12 23:57:19 +01001156#ifdef CONFIG_HAP_CTTPROXY
1157 if (!strcmp(args[cur_arg], "usesrc")) { /* address to use outside */
1158 if (newsrv->source_addr.sin_addr.s_addr == INADDR_ANY) {
1159 Alert("parsing [%s:%d] : '%s' requires an explicit 'source' address.\n",
1160 file, linenum, "usesrc");
1161 return -1;
1162 }
1163 if (!*args[cur_arg + 1]) {
1164 Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n",
1165 file, linenum, "usesrc");
1166 return -1;
1167 }
1168 if (!strcmp(args[cur_arg + 1], "client")) {
1169 newsrv->state |= SRV_TPROXY_CLI;
1170 } else if (!strcmp(args[cur_arg + 1], "clientip")) {
1171 newsrv->state |= SRV_TPROXY_CIP;
1172 } else {
1173 newsrv->state |= SRV_TPROXY_ADDR;
1174 newsrv->tproxy_addr = *str2sa(args[cur_arg + 1]);
1175 }
1176 global.last_checks |= LSTCHK_CTTPROXY | LSTCHK_NETADM;
1177 cur_arg += 2;
1178 }
1179#endif
Willy Tarreaubaaee002006-06-26 02:48:02 +02001180 }
1181 else {
1182 Alert("parsing [%s:%d] : server %s only supports options 'backup', 'cookie', 'check', 'inter', 'rise', 'fall', 'port', 'source', 'minconn', 'maxconn' and 'weight'.\n",
1183 file, linenum, newsrv->id);
1184 return -1;
1185 }
1186 }
1187
1188 if (do_check) {
1189 if (!newsrv->check_port && !(newsrv->state & SRV_MAPPORTS))
1190 newsrv->check_port = realport; /* by default */
1191 if (!newsrv->check_port) {
1192 Alert("parsing [%s:%d] : server %s has neither service port nor check port. Check has been disabled.\n",
1193 file, linenum, newsrv->id);
1194 return -1;
1195 }
1196 newsrv->state |= SRV_CHECKED;
1197 }
1198
1199 if (newsrv->state & SRV_BACKUP)
1200 curproxy->srv_bck++;
1201 else
1202 curproxy->srv_act++;
1203 }
1204 else if (!strcmp(args[0], "log")) { /* syslog server address */
1205 struct sockaddr_in *sa;
1206 int facility;
1207
1208 if (*(args[1]) && *(args[2]) == 0 && !strcmp(args[1], "global")) {
1209 curproxy->logfac1 = global.logfac1;
1210 curproxy->logsrv1 = global.logsrv1;
1211 curproxy->loglev1 = global.loglev1;
1212 curproxy->logfac2 = global.logfac2;
1213 curproxy->logsrv2 = global.logsrv2;
1214 curproxy->loglev2 = global.loglev2;
1215 }
1216 else if (*(args[1]) && *(args[2])) {
1217 int level;
1218
1219 facility = get_log_facility(args[2]);
1220 if (facility < 0) {
1221 Alert("parsing [%s:%d] : unknown log facility '%s'\n", file, linenum, args[2]);
1222 exit(1);
1223 }
1224
1225 level = 7; /* max syslog level = debug */
1226 if (*(args[3])) {
1227 level = get_log_level(args[3]);
1228 if (level < 0) {
1229 Alert("parsing [%s:%d] : unknown optional log level '%s'\n", file, linenum, args[3]);
1230 exit(1);
1231 }
1232 }
1233
1234 sa = str2sa(args[1]);
1235 if (!sa->sin_port)
1236 sa->sin_port = htons(SYSLOG_PORT);
1237
1238 if (curproxy->logfac1 == -1) {
1239 curproxy->logsrv1 = *sa;
1240 curproxy->logfac1 = facility;
1241 curproxy->loglev1 = level;
1242 }
1243 else if (curproxy->logfac2 == -1) {
1244 curproxy->logsrv2 = *sa;
1245 curproxy->logfac2 = facility;
1246 curproxy->loglev2 = level;
1247 }
1248 else {
1249 Alert("parsing [%s:%d] : too many syslog servers\n", file, linenum);
1250 return -1;
1251 }
1252 }
1253 else {
1254 Alert("parsing [%s:%d] : 'log' expects either <address[:port]> and <facility> or 'global' as arguments.\n",
1255 file, linenum);
1256 return -1;
1257 }
1258 }
1259 else if (!strcmp(args[0], "source")) { /* address to which we bind when connecting */
1260 if (!*args[1]) {
1261 Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>] as argument.\n",
1262 file, linenum, "source");
1263 return -1;
1264 }
1265
1266 curproxy->source_addr = *str2sa(args[1]);
1267 curproxy->options |= PR_O_BIND_SRC;
Willy Tarreau77074d52006-11-12 23:57:19 +01001268#ifdef CONFIG_HAP_CTTPROXY
1269 if (!strcmp(args[2], "usesrc")) { /* address to use outside */
1270 if (curproxy->source_addr.sin_addr.s_addr == INADDR_ANY) {
1271 Alert("parsing [%s:%d] : '%s' requires an explicit 'source' address.\n",
1272 file, linenum, "usesrc");
1273 return -1;
1274 }
1275 if (!*args[3]) {
1276 Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n",
1277 file, linenum, "usesrc");
1278 return -1;
1279 }
1280
1281 if (!strcmp(args[3], "client")) {
1282 curproxy->options |= PR_O_TPXY_CLI;
1283 } else if (!strcmp(args[3], "clientip")) {
1284 curproxy->options |= PR_O_TPXY_CIP;
1285 } else {
1286 curproxy->options |= PR_O_TPXY_ADDR;
1287 curproxy->tproxy_addr = *str2sa(args[3]);
1288 }
1289 global.last_checks |= LSTCHK_CTTPROXY | LSTCHK_NETADM;
1290 }
1291#endif
Willy Tarreaubaaee002006-06-26 02:48:02 +02001292 }
1293 else if (!strcmp(args[0], "cliexp") || !strcmp(args[0], "reqrep")) { /* replace request header from a regex */
1294 regex_t *preg;
1295 if (curproxy == &defproxy) {
1296 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1297 return -1;
1298 }
1299
1300 if (*(args[1]) == 0 || *(args[2]) == 0) {
1301 Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n",
1302 file, linenum, args[0]);
1303 return -1;
1304 }
1305
1306 preg = calloc(1, sizeof(regex_t));
1307 if (regcomp(preg, args[1], REG_EXTENDED) != 0) {
1308 Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]);
1309 return -1;
1310 }
1311
1312 err = chain_regex(&curproxy->req_exp, preg, ACT_REPLACE, strdup(args[2]));
1313 if (err) {
1314 Alert("parsing [%s:%d] : invalid character or unterminated sequence in replacement string near '%c'.\n",
1315 file, linenum, *err);
1316 return -1;
1317 }
1318 }
1319 else if (!strcmp(args[0], "reqdel")) { /* delete request header from a regex */
1320 regex_t *preg;
1321 if (curproxy == &defproxy) {
1322 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1323 return -1;
1324 }
1325
1326 if (*(args[1]) == 0) {
1327 Alert("parsing [%s:%d] : '%s' expects <regex> as an argument.\n", file, linenum, args[0]);
1328 return -1;
1329 }
1330
1331 preg = calloc(1, sizeof(regex_t));
1332 if (regcomp(preg, args[1], REG_EXTENDED) != 0) {
1333 Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]);
1334 return -1;
1335 }
1336
1337 chain_regex(&curproxy->req_exp, preg, ACT_REMOVE, NULL);
1338 }
1339 else if (!strcmp(args[0], "reqdeny")) { /* deny a request if a header matches this regex */
1340 regex_t *preg;
1341 if (curproxy == &defproxy) {
1342 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1343 return -1;
1344 }
1345
1346 if (*(args[1]) == 0) {
1347 Alert("parsing [%s:%d] : '%s' expects <regex> as an argument.\n", file, linenum, args[0]);
1348 return -1;
1349 }
1350
1351 preg = calloc(1, sizeof(regex_t));
1352 if (regcomp(preg, args[1], REG_EXTENDED) != 0) {
1353 Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]);
1354 return -1;
1355 }
1356
1357 chain_regex(&curproxy->req_exp, preg, ACT_DENY, NULL);
1358 }
1359 else if (!strcmp(args[0], "reqpass")) { /* pass this header without allowing or denying the request */
1360 regex_t *preg;
1361 if (curproxy == &defproxy) {
1362 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1363 return -1;
1364 }
1365
1366 if (*(args[1]) == 0) {
1367 Alert("parsing [%s:%d] : '%s' expects <regex> as an argument.\n", file, linenum, args[0]);
1368 return -1;
1369 }
1370
1371 preg = calloc(1, sizeof(regex_t));
1372 if (regcomp(preg, args[1], REG_EXTENDED) != 0) {
1373 Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]);
1374 return -1;
1375 }
1376
1377 chain_regex(&curproxy->req_exp, preg, ACT_PASS, NULL);
1378 }
1379 else if (!strcmp(args[0], "reqallow")) { /* allow a request if a header matches this regex */
1380 regex_t *preg;
1381 if (curproxy == &defproxy) {
1382 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1383 return -1;
1384 }
1385
1386 if (*(args[1]) == 0) {
1387 Alert("parsing [%s:%d] : '%s' expects <regex> as an argument.\n", file, linenum, args[0]);
1388 return -1;
1389 }
1390
1391 preg = calloc(1, sizeof(regex_t));
1392 if (regcomp(preg, args[1], REG_EXTENDED) != 0) {
1393 Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]);
1394 return -1;
1395 }
1396
1397 chain_regex(&curproxy->req_exp, preg, ACT_ALLOW, NULL);
1398 }
Willy Tarreaub8750a82006-09-03 09:56:00 +02001399 else if (!strcmp(args[0], "reqtarpit")) { /* tarpit a request if a header matches this regex */
1400 regex_t *preg;
1401 if (curproxy == &defproxy) {
1402 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1403 return -1;
1404 }
1405
1406 if (*(args[1]) == 0) {
1407 Alert("parsing [%s:%d] : '%s' expects <regex> as an argument.\n", file, linenum, args[0]);
1408 return -1;
1409 }
1410
1411 preg = calloc(1, sizeof(regex_t));
1412 if (regcomp(preg, args[1], REG_EXTENDED) != 0) {
1413 Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]);
1414 return -1;
1415 }
1416
1417 chain_regex(&curproxy->req_exp, preg, ACT_TARPIT, NULL);
1418 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02001419 else if (!strcmp(args[0], "reqirep")) { /* replace request header from a regex, ignoring case */
1420 regex_t *preg;
1421 if (curproxy == &defproxy) {
1422 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1423 return -1;
1424 }
1425
1426 if (*(args[1]) == 0 || *(args[2]) == 0) {
1427 Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n",
1428 file, linenum, args[0]);
1429 return -1;
1430 }
1431
1432 preg = calloc(1, sizeof(regex_t));
1433 if (regcomp(preg, args[1], REG_EXTENDED | REG_ICASE) != 0) {
1434 Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]);
1435 return -1;
1436 }
1437
1438 err = chain_regex(&curproxy->req_exp, preg, ACT_REPLACE, strdup(args[2]));
1439 if (err) {
1440 Alert("parsing [%s:%d] : invalid character or unterminated sequence in replacement string near '%c'.\n",
1441 file, linenum, *err);
1442 return -1;
1443 }
1444 }
1445 else if (!strcmp(args[0], "reqidel")) { /* delete request header from a regex ignoring case */
1446 regex_t *preg;
1447 if (curproxy == &defproxy) {
1448 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1449 return -1;
1450 }
1451
1452 if (*(args[1]) == 0) {
1453 Alert("parsing [%s:%d] : '%s' expects <regex> as an argument.\n", file, linenum, args[0]);
1454 return -1;
1455 }
1456
1457 preg = calloc(1, sizeof(regex_t));
1458 if (regcomp(preg, args[1], REG_EXTENDED | REG_ICASE) != 0) {
1459 Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]);
1460 return -1;
1461 }
1462
1463 chain_regex(&curproxy->req_exp, preg, ACT_REMOVE, NULL);
1464 }
1465 else if (!strcmp(args[0], "reqideny")) { /* deny a request if a header matches this regex ignoring case */
1466 regex_t *preg;
1467 if (curproxy == &defproxy) {
1468 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1469 return -1;
1470 }
1471
1472 if (*(args[1]) == 0) {
1473 Alert("parsing [%s:%d] : '%s' expects <regex> as an argument.\n", file, linenum, args[0]);
1474 return -1;
1475 }
1476
1477 preg = calloc(1, sizeof(regex_t));
1478 if (regcomp(preg, args[1], REG_EXTENDED | REG_ICASE) != 0) {
1479 Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]);
1480 return -1;
1481 }
1482
1483 chain_regex(&curproxy->req_exp, preg, ACT_DENY, NULL);
1484 }
1485 else if (!strcmp(args[0], "reqipass")) { /* pass this header without allowing or denying the request */
1486 regex_t *preg;
1487 if (curproxy == &defproxy) {
1488 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1489 return -1;
1490 }
1491
1492 if (*(args[1]) == 0) {
1493 Alert("parsing [%s:%d] : '%s' expects <regex> as an argument.\n", file, linenum, args[0]);
1494 return -1;
1495 }
1496
1497 preg = calloc(1, sizeof(regex_t));
1498 if (regcomp(preg, args[1], REG_EXTENDED | REG_ICASE) != 0) {
1499 Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]);
1500 return -1;
1501 }
1502
1503 chain_regex(&curproxy->req_exp, preg, ACT_PASS, NULL);
1504 }
1505 else if (!strcmp(args[0], "reqiallow")) { /* allow a request if a header matches this regex ignoring case */
1506 regex_t *preg;
1507 if (curproxy == &defproxy) {
1508 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1509 return -1;
1510 }
1511
1512 if (*(args[1]) == 0) {
1513 Alert("parsing [%s:%d] : '%s' expects <regex> as an argument.\n", file, linenum, args[0]);
1514 return -1;
1515 }
1516
1517 preg = calloc(1, sizeof(regex_t));
1518 if (regcomp(preg, args[1], REG_EXTENDED | REG_ICASE) != 0) {
1519 Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]);
1520 return -1;
1521 }
1522
1523 chain_regex(&curproxy->req_exp, preg, ACT_ALLOW, NULL);
1524 }
Willy Tarreaub8750a82006-09-03 09:56:00 +02001525 else if (!strcmp(args[0], "reqitarpit")) { /* tarpit a request if a header matches this regex ignoring case */
1526 regex_t *preg;
1527 if (curproxy == &defproxy) {
1528 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1529 return -1;
1530 }
1531
1532 if (*(args[1]) == 0) {
1533 Alert("parsing [%s:%d] : '%s' expects <regex> as an argument.\n", file, linenum, args[0]);
1534 return -1;
1535 }
1536
1537 preg = calloc(1, sizeof(regex_t));
1538 if (regcomp(preg, args[1], REG_EXTENDED | REG_ICASE) != 0) {
1539 Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]);
1540 return -1;
1541 }
1542
1543 chain_regex(&curproxy->req_exp, preg, ACT_TARPIT, NULL);
1544 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02001545 else if (!strcmp(args[0], "reqadd")) { /* add request header */
1546 if (curproxy == &defproxy) {
1547 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1548 return -1;
1549 }
1550
1551 if (curproxy->nb_reqadd >= MAX_NEWHDR) {
1552 Alert("parsing [%s:%d] : too many '%s'. Continuing.\n", file, linenum, args[0]);
1553 return 0;
1554 }
1555
1556 if (*(args[1]) == 0) {
1557 Alert("parsing [%s:%d] : '%s' expects <header> as an argument.\n", file, linenum, args[0]);
1558 return -1;
1559 }
1560
1561 curproxy->req_add[curproxy->nb_reqadd++] = strdup(args[1]);
1562 }
1563 else if (!strcmp(args[0], "srvexp") || !strcmp(args[0], "rsprep")) { /* replace response header from a regex */
1564 regex_t *preg;
1565
1566 if (*(args[1]) == 0 || *(args[2]) == 0) {
1567 Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n",
1568 file, linenum, args[0]);
1569 return -1;
1570 }
1571
1572 preg = calloc(1, sizeof(regex_t));
1573 if (regcomp(preg, args[1], REG_EXTENDED) != 0) {
1574 Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]);
1575 return -1;
1576 }
1577
1578 err = chain_regex(&curproxy->rsp_exp, preg, ACT_REPLACE, strdup(args[2]));
1579 if (err) {
1580 Alert("parsing [%s:%d] : invalid character or unterminated sequence in replacement string near '%c'.\n",
1581 file, linenum, *err);
1582 return -1;
1583 }
1584 }
1585 else if (!strcmp(args[0], "rspdel")) { /* delete response header from a regex */
1586 regex_t *preg;
1587 if (curproxy == &defproxy) {
1588 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1589 return -1;
1590 }
1591
1592 if (*(args[1]) == 0) {
1593 Alert("parsing [%s:%d] : '%s' expects <search> as an argument.\n", file, linenum, args[0]);
1594 return -1;
1595 }
1596
1597 preg = calloc(1, sizeof(regex_t));
1598 if (regcomp(preg, args[1], REG_EXTENDED) != 0) {
1599 Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]);
1600 return -1;
1601 }
1602
1603 err = chain_regex(&curproxy->rsp_exp, preg, ACT_REMOVE, strdup(args[2]));
1604 if (err) {
1605 Alert("parsing [%s:%d] : invalid character or unterminated sequence in replacement string near '%c'.\n",
1606 file, linenum, *err);
1607 return -1;
1608 }
1609 }
1610 else if (!strcmp(args[0], "rspdeny")) { /* block response header from a regex */
1611 regex_t *preg;
1612 if (curproxy == &defproxy) {
1613 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1614 return -1;
1615 }
1616
1617 if (*(args[1]) == 0) {
1618 Alert("parsing [%s:%d] : '%s' expects <search> as an argument.\n", file, linenum, args[0]);
1619 return -1;
1620 }
1621
1622 preg = calloc(1, sizeof(regex_t));
1623 if (regcomp(preg, args[1], REG_EXTENDED) != 0) {
1624 Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]);
1625 return -1;
1626 }
1627
1628 err = chain_regex(&curproxy->rsp_exp, preg, ACT_DENY, strdup(args[2]));
1629 if (err) {
1630 Alert("parsing [%s:%d] : invalid character or unterminated sequence in replacement string near '%c'.\n",
1631 file, linenum, *err);
1632 return -1;
1633 }
1634 }
1635 else if (!strcmp(args[0], "rspirep")) { /* replace response header from a regex ignoring case */
1636 regex_t *preg;
1637 if (curproxy == &defproxy) {
1638 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1639 return -1;
1640 }
1641
1642 if (*(args[1]) == 0 || *(args[2]) == 0) {
1643 Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n",
1644 file, linenum, args[0]);
1645 return -1;
1646 }
1647
1648 preg = calloc(1, sizeof(regex_t));
1649 if (regcomp(preg, args[1], REG_EXTENDED | REG_ICASE) != 0) {
1650 Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]);
1651 return -1;
1652 }
1653
1654 err = chain_regex(&curproxy->rsp_exp, preg, ACT_REPLACE, strdup(args[2]));
1655 if (err) {
1656 Alert("parsing [%s:%d] : invalid character or unterminated sequence in replacement string near '%c'.\n",
1657 file, linenum, *err);
1658 return -1;
1659 }
1660 }
1661 else if (!strcmp(args[0], "rspidel")) { /* delete response header from a regex ignoring case */
1662 regex_t *preg;
1663 if (curproxy == &defproxy) {
1664 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1665 return -1;
1666 }
1667
1668 if (*(args[1]) == 0) {
1669 Alert("parsing [%s:%d] : '%s' expects <search> as an argument.\n", file, linenum, args[0]);
1670 return -1;
1671 }
1672
1673 preg = calloc(1, sizeof(regex_t));
1674 if (regcomp(preg, args[1], REG_EXTENDED | REG_ICASE) != 0) {
1675 Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]);
1676 return -1;
1677 }
1678
1679 err = chain_regex(&curproxy->rsp_exp, preg, ACT_REMOVE, strdup(args[2]));
1680 if (err) {
1681 Alert("parsing [%s:%d] : invalid character or unterminated sequence in replacement string near '%c'.\n",
1682 file, linenum, *err);
1683 return -1;
1684 }
1685 }
1686 else if (!strcmp(args[0], "rspideny")) { /* block response header from a regex ignoring case */
1687 regex_t *preg;
1688 if (curproxy == &defproxy) {
1689 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1690 return -1;
1691 }
1692
1693 if (*(args[1]) == 0) {
1694 Alert("parsing [%s:%d] : '%s' expects <search> as an argument.\n", file, linenum, args[0]);
1695 return -1;
1696 }
1697
1698 preg = calloc(1, sizeof(regex_t));
1699 if (regcomp(preg, args[1], REG_EXTENDED | REG_ICASE) != 0) {
1700 Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]);
1701 return -1;
1702 }
1703
1704 err = chain_regex(&curproxy->rsp_exp, preg, ACT_DENY, strdup(args[2]));
1705 if (err) {
1706 Alert("parsing [%s:%d] : invalid character or unterminated sequence in replacement string near '%c'.\n",
1707 file, linenum, *err);
1708 return -1;
1709 }
1710 }
1711 else if (!strcmp(args[0], "rspadd")) { /* add response header */
1712 if (curproxy == &defproxy) {
1713 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1714 return -1;
1715 }
1716
1717 if (curproxy->nb_rspadd >= MAX_NEWHDR) {
1718 Alert("parsing [%s:%d] : too many '%s'. Continuing.\n", file, linenum, args[0]);
1719 return 0;
1720 }
1721
1722 if (*(args[1]) == 0) {
1723 Alert("parsing [%s:%d] : '%s' expects <header> as an argument.\n", file, linenum, args[0]);
1724 return -1;
1725 }
1726
1727 curproxy->rsp_add[curproxy->nb_rspadd++] = strdup(args[1]);
1728 }
1729 else if (!strcmp(args[0], "errorloc") ||
1730 !strcmp(args[0], "errorloc302") ||
1731 !strcmp(args[0], "errorloc303")) { /* error location */
1732 int errnum, errlen;
1733 char *err;
1734
1735 // if (curproxy == &defproxy) {
1736 // Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1737 // return -1;
1738 // }
1739
1740 if (*(args[2]) == 0) {
1741 Alert("parsing [%s:%d] : <errorloc> expects <error> and <url> as arguments.\n", file, linenum);
1742 return -1;
1743 }
1744
1745 errnum = atol(args[1]);
1746 if (!strcmp(args[0], "errorloc303")) {
1747 err = malloc(strlen(HTTP_303) + strlen(args[2]) + 5);
1748 errlen = sprintf(err, "%s%s\r\n\r\n", HTTP_303, args[2]);
1749 } else {
1750 err = malloc(strlen(HTTP_302) + strlen(args[2]) + 5);
1751 errlen = sprintf(err, "%s%s\r\n\r\n", HTTP_302, args[2]);
1752 }
1753
1754 if (errnum == 400) {
1755 if (curproxy->errmsg.msg400) {
1756 //Warning("parsing [%s:%d] : error %d already defined.\n", file, linenum, errnum);
1757 free(curproxy->errmsg.msg400);
1758 }
1759 curproxy->errmsg.msg400 = err;
1760 curproxy->errmsg.len400 = errlen;
1761 }
1762 else if (errnum == 403) {
1763 if (curproxy->errmsg.msg403) {
1764 //Warning("parsing [%s:%d] : error %d already defined.\n", file, linenum, errnum);
1765 free(curproxy->errmsg.msg403);
1766 }
1767 curproxy->errmsg.msg403 = err;
1768 curproxy->errmsg.len403 = errlen;
1769 }
1770 else if (errnum == 408) {
1771 if (curproxy->errmsg.msg408) {
1772 //Warning("parsing [%s:%d] : error %d already defined.\n", file, linenum, errnum);
1773 free(curproxy->errmsg.msg408);
1774 }
1775 curproxy->errmsg.msg408 = err;
1776 curproxy->errmsg.len408 = errlen;
1777 }
1778 else if (errnum == 500) {
1779 if (curproxy->errmsg.msg500) {
1780 //Warning("parsing [%s:%d] : error %d already defined.\n", file, linenum, errnum);
1781 free(curproxy->errmsg.msg500);
1782 }
1783 curproxy->errmsg.msg500 = err;
1784 curproxy->errmsg.len500 = errlen;
1785 }
1786 else if (errnum == 502) {
1787 if (curproxy->errmsg.msg502) {
1788 //Warning("parsing [%s:%d] : error %d already defined.\n", file, linenum, errnum);
1789 free(curproxy->errmsg.msg502);
1790 }
1791 curproxy->errmsg.msg502 = err;
1792 curproxy->errmsg.len502 = errlen;
1793 }
1794 else if (errnum == 503) {
1795 if (curproxy->errmsg.msg503) {
1796 //Warning("parsing [%s:%d] : error %d already defined.\n", file, linenum, errnum);
1797 free(curproxy->errmsg.msg503);
1798 }
1799 curproxy->errmsg.msg503 = err;
1800 curproxy->errmsg.len503 = errlen;
1801 }
1802 else if (errnum == 504) {
1803 if (curproxy->errmsg.msg504) {
1804 //Warning("parsing [%s:%d] : error %d already defined.\n", file, linenum, errnum);
1805 free(curproxy->errmsg.msg504);
1806 }
1807 curproxy->errmsg.msg504 = err;
1808 curproxy->errmsg.len504 = errlen;
1809 }
1810 else {
1811 Warning("parsing [%s:%d] : error %d relocation will be ignored.\n", file, linenum, errnum);
1812 free(err);
1813 }
1814 }
1815 else {
1816 Alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], "listen");
1817 return -1;
1818 }
1819 return 0;
1820}
1821
1822
1823/*
1824 * This function reads and parses the configuration file given in the argument.
1825 * returns 0 if OK, -1 if error.
1826 */
Willy Tarreaub17916e2006-10-15 15:17:57 +02001827int readcfgfile(const char *file)
Willy Tarreaubaaee002006-06-26 02:48:02 +02001828{
1829 char thisline[256];
1830 char *line;
1831 FILE *f;
1832 int linenum = 0;
1833 char *end;
1834 char *args[MAX_LINE_ARGS];
1835 int arg;
1836 int cfgerr = 0;
1837 int nbchk, mininter;
1838 int confsect = CFG_NONE;
1839
1840 struct proxy *curproxy = NULL;
1841 struct server *newsrv = NULL;
1842
1843 if ((f=fopen(file,"r")) == NULL)
1844 return -1;
1845
1846 init_default_instance();
1847
1848 while (fgets(line = thisline, sizeof(thisline), f) != NULL) {
1849 linenum++;
1850
1851 end = line + strlen(line);
1852
1853 /* skip leading spaces */
1854 while (isspace((int)*line))
1855 line++;
1856
1857 arg = 0;
1858 args[arg] = line;
1859
1860 while (*line && arg < MAX_LINE_ARGS) {
1861 /* first, we'll replace \\, \<space>, \#, \r, \n, \t, \xXX with their
1862 * C equivalent value. Other combinations left unchanged (eg: \1).
1863 */
1864 if (*line == '\\') {
1865 int skip = 0;
1866 if (line[1] == ' ' || line[1] == '\\' || line[1] == '#') {
1867 *line = line[1];
1868 skip = 1;
1869 }
1870 else if (line[1] == 'r') {
1871 *line = '\r';
1872 skip = 1;
1873 }
1874 else if (line[1] == 'n') {
1875 *line = '\n';
1876 skip = 1;
1877 }
1878 else if (line[1] == 't') {
1879 *line = '\t';
1880 skip = 1;
1881 }
1882 else if (line[1] == 'x') {
1883 if ((line + 3 < end ) && ishex(line[2]) && ishex(line[3])) {
1884 unsigned char hex1, hex2;
1885 hex1 = toupper(line[2]) - '0';
1886 hex2 = toupper(line[3]) - '0';
1887 if (hex1 > 9) hex1 -= 'A' - '9' - 1;
1888 if (hex2 > 9) hex2 -= 'A' - '9' - 1;
1889 *line = (hex1<<4) + hex2;
1890 skip = 3;
1891 }
1892 else {
1893 Alert("parsing [%s:%d] : invalid or incomplete '\\x' sequence in '%s'.\n", file, linenum, args[0]);
1894 return -1;
1895 }
1896 }
1897 if (skip) {
1898 memmove(line + 1, line + 1 + skip, end - (line + skip + 1));
1899 end -= skip;
1900 }
1901 line++;
1902 }
1903 else if (*line == '#' || *line == '\n' || *line == '\r') {
1904 /* end of string, end of loop */
1905 *line = 0;
1906 break;
1907 }
1908 else if (isspace((int)*line)) {
1909 /* a non-escaped space is an argument separator */
1910 *line++ = 0;
1911 while (isspace((int)*line))
1912 line++;
1913 args[++arg] = line;
1914 }
1915 else {
1916 line++;
1917 }
1918 }
1919
1920 /* empty line */
1921 if (!**args)
1922 continue;
1923
1924 /* zero out remaining args */
1925 while (++arg < MAX_LINE_ARGS) {
1926 args[arg] = line;
1927 }
1928
1929 if (!strcmp(args[0], "listen") || !strcmp(args[0], "defaults")) /* new proxy */
1930 confsect = CFG_LISTEN;
1931 else if (!strcmp(args[0], "global")) /* global config */
1932 confsect = CFG_GLOBAL;
1933 /* else it's a section keyword */
1934
1935 switch (confsect) {
1936 case CFG_LISTEN:
1937 if (cfg_parse_listen(file, linenum, args) < 0)
1938 return -1;
1939 break;
1940 case CFG_GLOBAL:
1941 if (cfg_parse_global(file, linenum, args) < 0)
1942 return -1;
1943 break;
1944 default:
1945 Alert("parsing [%s:%d] : unknown keyword '%s' out of section.\n", file, linenum, args[0]);
1946 return -1;
1947 }
1948
1949
1950 }
1951 fclose(f);
1952
1953 /*
1954 * Now, check for the integrity of all that we have collected.
1955 */
1956
1957 /* will be needed further to delay some tasks */
1958 tv_now(&now);
1959
1960 if ((curproxy = proxy) == NULL) {
1961 Alert("parsing %s : no <listen> line. Nothing to do !\n",
1962 file);
1963 return -1;
1964 }
1965
1966 while (curproxy != NULL) {
1967 if (curproxy->state == PR_STSTOPPED) {
1968 curproxy = curproxy->next;
1969 continue;
1970 }
1971
1972 if (curproxy->listen == NULL) {
1973 Alert("parsing %s : listener %s has no listen address. Please either specify a valid address on the <listen> line, or use the <bind> keyword.\n", file, curproxy->id);
1974 cfgerr++;
1975 }
1976 else if ((curproxy->mode != PR_MODE_HEALTH) &&
1977 !(curproxy->options & (PR_O_TRANSP | PR_O_BALANCE)) &&
1978 (*(int *)&curproxy->dispatch_addr.sin_addr == 0)) {
1979 Alert("parsing %s : listener %s has no dispatch address and is not in transparent or balance mode.\n",
1980 file, curproxy->id);
1981 cfgerr++;
1982 }
1983 else if ((curproxy->mode != PR_MODE_HEALTH) && (curproxy->options & PR_O_BALANCE)) {
1984 if (curproxy->options & PR_O_TRANSP) {
1985 Alert("parsing %s : listener %s cannot use both transparent and balance mode.\n",
1986 file, curproxy->id);
1987 cfgerr++;
1988 }
1989#ifdef WE_DONT_SUPPORT_SERVERLESS_LISTENERS
1990 else if (curproxy->srv == NULL) {
1991 Alert("parsing %s : listener %s needs at least 1 server in balance mode.\n",
1992 file, curproxy->id);
1993 cfgerr++;
1994 }
1995#endif
1996 else if (*(int *)&curproxy->dispatch_addr.sin_addr != 0) {
1997 Warning("parsing %s : dispatch address of listener %s will be ignored in balance mode.\n",
1998 file, curproxy->id);
1999 }
2000 }
2001 else if (curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HEALTH) { /* TCP PROXY or HEALTH CHECK */
2002 if (curproxy->cookie_name != NULL) {
2003 Warning("parsing %s : cookie will be ignored for listener %s.\n",
2004 file, curproxy->id);
2005 }
2006 if ((newsrv = curproxy->srv) != NULL) {
2007 Warning("parsing %s : servers will be ignored for listener %s.\n",
2008 file, curproxy->id);
2009 }
2010 if (curproxy->rsp_exp != NULL) {
2011 Warning("parsing %s : server regular expressions will be ignored for listener %s.\n",
2012 file, curproxy->id);
2013 }
2014 if (curproxy->req_exp != NULL) {
2015 Warning("parsing %s : client regular expressions will be ignored for listener %s.\n",
2016 file, curproxy->id);
2017 }
Willy Tarreau1c47f852006-07-09 08:22:27 +02002018 if (curproxy->monitor_uri != NULL) {
2019 Warning("parsing %s : monitor-uri will be ignored for listener %s.\n",
2020 file, curproxy->id);
2021 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02002022 }
2023 else if (curproxy->mode == PR_MODE_HTTP) { /* HTTP PROXY */
2024 if ((curproxy->cookie_name != NULL) && ((newsrv = curproxy->srv) == NULL)) {
2025 Alert("parsing %s : HTTP proxy %s has a cookie but no server list !\n",
2026 file, curproxy->id);
2027 cfgerr++;
2028 }
2029 }
2030
Willy Tarreau2738a142006-07-08 17:28:09 +02002031 if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) &&
2032 (!curproxy->clitimeout || !curproxy->contimeout || !curproxy->srvtimeout)) {
2033 Warning("parsing %s : missing timeouts for listener '%s'.\n"
2034 " | While not properly invalid, you will certainly encounter various problems\n"
2035 " | with such a configuration. To fix this, please ensure that all following\n"
2036 " | values are set to a non-zero value: clitimeout, contimeout, srvtimeout.\n",
2037 file, curproxy->id);
2038 }
Willy Tarreauf3c69202006-07-09 16:42:34 +02002039
2040 if (curproxy->options & PR_O_SSL3_CHK) {
2041 curproxy->check_len = sizeof(sslv3_client_hello_pkt);
2042 curproxy->check_req = (char *)malloc(sizeof(sslv3_client_hello_pkt));
2043 memcpy(curproxy->check_req, sslv3_client_hello_pkt, sizeof(sslv3_client_hello_pkt));
2044 }
2045
Willy Tarreaubaaee002006-06-26 02:48:02 +02002046 /* first, we will invert the servers list order */
2047 newsrv = NULL;
2048 while (curproxy->srv) {
2049 struct server *next;
2050
2051 next = curproxy->srv->next;
2052 curproxy->srv->next = newsrv;
2053 newsrv = curproxy->srv;
2054 if (!next)
2055 break;
2056 curproxy->srv = next;
2057 }
2058
2059 /* now, newsrv == curproxy->srv */
2060 if (newsrv) {
2061 struct server *srv;
2062 int pgcd;
2063 int act, bck;
2064
2065 /* We will factor the weights to reduce the table,
2066 * using Euclide's largest common divisor algorithm
2067 */
2068 pgcd = newsrv->uweight + 1;
2069 for (srv = newsrv->next; srv && pgcd > 1; srv = srv->next) {
2070 int t, w;
2071
2072 w = srv->uweight + 1;
2073 while (w) {
2074 t = pgcd % w;
2075 pgcd = w;
2076 w = t;
2077 }
2078 }
2079
2080 act = bck = 0;
2081 for (srv = newsrv; srv; srv = srv->next) {
2082 srv->eweight = ((srv->uweight + 1) / pgcd) - 1;
2083 if (srv->state & SRV_BACKUP)
2084 bck += srv->eweight + 1;
2085 else
2086 act += srv->eweight + 1;
2087 }
2088
2089 /* this is the largest map we will ever need for this servers list */
2090 if (act < bck)
2091 act = bck;
2092
2093 curproxy->srv_map = (struct server **)calloc(act, sizeof(struct server *));
2094 /* recounts servers and their weights */
2095 recount_servers(curproxy);
2096 recalc_server_map(curproxy);
2097 }
2098
2099 if (curproxy->options & PR_O_LOGASAP)
2100 curproxy->to_log &= ~LW_BYTES;
2101
2102 if (curproxy->errmsg.msg400 == NULL) {
2103 curproxy->errmsg.msg400 = (char *)HTTP_400;
2104 curproxy->errmsg.len400 = strlen(HTTP_400);
2105 }
2106 if (curproxy->errmsg.msg403 == NULL) {
2107 curproxy->errmsg.msg403 = (char *)HTTP_403;
2108 curproxy->errmsg.len403 = strlen(HTTP_403);
2109 }
2110 if (curproxy->errmsg.msg408 == NULL) {
2111 curproxy->errmsg.msg408 = (char *)HTTP_408;
2112 curproxy->errmsg.len408 = strlen(HTTP_408);
2113 }
2114 if (curproxy->errmsg.msg500 == NULL) {
2115 curproxy->errmsg.msg500 = (char *)HTTP_500;
2116 curproxy->errmsg.len500 = strlen(HTTP_500);
2117 }
2118 if (curproxy->errmsg.msg502 == NULL) {
2119 curproxy->errmsg.msg502 = (char *)HTTP_502;
2120 curproxy->errmsg.len502 = strlen(HTTP_502);
2121 }
2122 if (curproxy->errmsg.msg503 == NULL) {
2123 curproxy->errmsg.msg503 = (char *)HTTP_503;
2124 curproxy->errmsg.len503 = strlen(HTTP_503);
2125 }
2126 if (curproxy->errmsg.msg504 == NULL) {
2127 curproxy->errmsg.msg504 = (char *)HTTP_504;
2128 curproxy->errmsg.len504 = strlen(HTTP_504);
2129 }
2130
2131 /*
2132 * If this server supports a maxconn parameter, it needs a dedicated
2133 * tasks to fill the emptied slots when a connection leaves.
2134 */
2135 newsrv = curproxy->srv;
2136 while (newsrv != NULL) {
2137 if (newsrv->minconn >= newsrv->maxconn) {
2138 /* Only 'minconn' was specified, or it was higher than or equal
2139 * to 'maxconn'. Let's turn this into maxconn and clean it, as
2140 * this will avoid further useless expensive computations.
2141 */
2142 newsrv->maxconn = newsrv->minconn;
2143 newsrv->minconn = 0;
2144 }
2145
2146 if (newsrv->maxconn > 0) {
2147 struct task *t;
2148
2149 if ((t = pool_alloc(task)) == NULL) {
2150 Alert("parsing [%s:%d] : out of memory.\n", file, linenum);
2151 return -1;
2152 }
2153
2154 t->next = t->prev = t->rqnext = NULL; /* task not in run queue yet */
2155 t->wq = LIST_HEAD(wait_queue[1]); /* already assigned to the eternity queue */
2156 t->state = TASK_IDLE;
2157 t->process = process_srv_queue;
2158 t->context = newsrv;
2159 newsrv->queue_mgt = t;
2160
2161 /* never run it unless specifically woken up */
2162 tv_eternity(&t->expire);
2163 task_queue(t);
2164 }
2165 newsrv = newsrv->next;
2166 }
2167
2168 /* now we'll start this proxy's health checks if any */
2169 /* 1- count the checkers to run simultaneously */
2170 nbchk = 0;
2171 mininter = 0;
2172 newsrv = curproxy->srv;
2173 while (newsrv != NULL) {
2174 if (newsrv->state & SRV_CHECKED) {
2175 if (!mininter || mininter > newsrv->inter)
2176 mininter = newsrv->inter;
2177 nbchk++;
2178 }
2179 newsrv = newsrv->next;
2180 }
2181
2182 /* 2- start them as far as possible from each others while respecting
2183 * their own intervals. For this, we will start them after their own
2184 * interval added to the min interval divided by the number of servers,
2185 * weighted by the server's position in the list.
2186 */
2187 if (nbchk > 0) {
2188 struct task *t;
2189 int srvpos;
2190
2191 newsrv = curproxy->srv;
2192 srvpos = 0;
2193 while (newsrv != NULL) {
2194 /* should this server be checked ? */
2195 if (newsrv->state & SRV_CHECKED) {
2196 if ((t = pool_alloc(task)) == NULL) {
2197 Alert("parsing [%s:%d] : out of memory.\n", file, linenum);
2198 return -1;
2199 }
2200
2201 t->next = t->prev = t->rqnext = NULL; /* task not in run queue yet */
2202 t->wq = LIST_HEAD(wait_queue[0]); /* but already has a wait queue assigned */
2203 t->state = TASK_IDLE;
2204 t->process = process_chk;
2205 t->context = newsrv;
2206
2207 /* check this every ms */
2208 tv_delayfrom(&t->expire, &now,
2209 newsrv->inter + mininter * srvpos / nbchk);
2210 task_queue(t);
2211 //task_wakeup(&rq, t);
2212 srvpos++;
2213 }
2214 newsrv = newsrv->next;
2215 }
2216 }
2217
2218 curproxy = curproxy->next;
2219 }
2220 if (cfgerr > 0) {
2221 Alert("Errors found in configuration file, aborting.\n");
2222 return -1;
2223 }
2224 else
2225 return 0;
2226}
2227
2228
2229
2230/*
2231 * Local variables:
2232 * c-indent-level: 8
2233 * c-basic-offset: 8
2234 * End:
2235 */