Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Configuration parser |
| 3 | * |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 4 | * Copyright 2000-2009 Willy Tarreau <w@1wt.eu> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 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 Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 18 | #include <pwd.h> |
| 19 | #include <grp.h> |
Willy Tarreau | 0b4ed90 | 2007-03-26 00:18:40 +0200 | [diff] [blame] | 20 | #include <errno.h> |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 21 | #include <sys/types.h> |
| 22 | #include <sys/stat.h> |
| 23 | #include <fcntl.h> |
| 24 | #include <unistd.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 25 | |
Willy Tarreau | be1b918 | 2009-06-14 18:48:19 +0200 | [diff] [blame] | 26 | #include <netinet/tcp.h> |
| 27 | |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 28 | #include <common/cfgparse.h> |
| 29 | #include <common/config.h> |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 30 | #include <common/errors.h> |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 31 | #include <common/memory.h> |
| 32 | #include <common/standard.h> |
| 33 | #include <common/time.h> |
| 34 | #include <common/uri_auth.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 35 | |
| 36 | #include <types/capture.h> |
| 37 | #include <types/global.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 38 | |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 39 | #include <proto/acl.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 40 | #include <proto/backend.h> |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 41 | #include <proto/buffers.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 42 | #include <proto/checks.h> |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 43 | #include <proto/dumpstats.h> |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 44 | #include <proto/httperr.h> |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 45 | #include <proto/lb_chash.h> |
Willy Tarreau | f89c187 | 2009-10-01 11:19:37 +0200 | [diff] [blame] | 46 | #include <proto/lb_fwlc.h> |
| 47 | #include <proto/lb_fwrr.h> |
| 48 | #include <proto/lb_map.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 49 | #include <proto/log.h> |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 50 | #include <proto/port_range.h> |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 51 | #include <proto/protocols.h> |
| 52 | #include <proto/proto_tcp.h> |
| 53 | #include <proto/proto_http.h> |
Willy Tarreau | 2b5652f | 2006-12-31 17:46:05 +0100 | [diff] [blame] | 54 | #include <proto/proxy.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 55 | #include <proto/server.h> |
Willy Tarreau | 3bc1377 | 2008-12-07 11:50:35 +0100 | [diff] [blame] | 56 | #include <proto/session.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 57 | #include <proto/task.h> |
| 58 | |
| 59 | |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 60 | /* This is the SSLv3 CLIENT HELLO packet used in conjunction with the |
| 61 | * ssl-hello-chk option to ensure that the remote server speaks SSL. |
| 62 | * |
| 63 | * Check RFC 2246 (TLSv1.0) sections A.3 and A.4 for details. |
| 64 | */ |
| 65 | const char sslv3_client_hello_pkt[] = { |
| 66 | "\x16" /* ContentType : 0x16 = Hanshake */ |
| 67 | "\x03\x00" /* ProtocolVersion : 0x0300 = SSLv3 */ |
| 68 | "\x00\x79" /* ContentLength : 0x79 bytes after this one */ |
| 69 | "\x01" /* HanshakeType : 0x01 = CLIENT HELLO */ |
| 70 | "\x00\x00\x75" /* HandshakeLength : 0x75 bytes after this one */ |
| 71 | "\x03\x00" /* Hello Version : 0x0300 = v3 */ |
| 72 | "\x00\x00\x00\x00" /* Unix GMT Time (s) : filled with <now> (@0x0B) */ |
| 73 | "HAPROXYSSLCHK\nHAPROXYSSLCHK\n" /* Random : must be exactly 28 bytes */ |
| 74 | "\x00" /* Session ID length : empty (no session ID) */ |
| 75 | "\x00\x4E" /* Cipher Suite Length : 78 bytes after this one */ |
| 76 | "\x00\x01" "\x00\x02" "\x00\x03" "\x00\x04" /* 39 most common ciphers : */ |
| 77 | "\x00\x05" "\x00\x06" "\x00\x07" "\x00\x08" /* 0x01...0x1B, 0x2F...0x3A */ |
| 78 | "\x00\x09" "\x00\x0A" "\x00\x0B" "\x00\x0C" /* This covers RSA/DH, */ |
| 79 | "\x00\x0D" "\x00\x0E" "\x00\x0F" "\x00\x10" /* various bit lengths, */ |
| 80 | "\x00\x11" "\x00\x12" "\x00\x13" "\x00\x14" /* SHA1/MD5, DES/3DES/AES... */ |
| 81 | "\x00\x15" "\x00\x16" "\x00\x17" "\x00\x18" |
| 82 | "\x00\x19" "\x00\x1A" "\x00\x1B" "\x00\x2F" |
| 83 | "\x00\x30" "\x00\x31" "\x00\x32" "\x00\x33" |
| 84 | "\x00\x34" "\x00\x35" "\x00\x36" "\x00\x37" |
| 85 | "\x00\x38" "\x00\x39" "\x00\x3A" |
| 86 | "\x01" /* Compression Length : 0x01 = 1 byte for types */ |
| 87 | "\x00" /* Compression Type : 0x00 = NULL compression */ |
| 88 | }; |
| 89 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 90 | /* various keyword modifiers */ |
| 91 | enum kw_mod { |
| 92 | KWM_STD = 0, /* normal */ |
| 93 | KWM_NO, /* "no" prefixed before the keyword */ |
| 94 | KWM_DEF, /* "default" prefixed before the keyword */ |
| 95 | }; |
| 96 | |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 97 | /* some of the most common options which are also the easiest to handle */ |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 98 | struct cfg_opt { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 99 | const char *name; |
| 100 | unsigned int val; |
| 101 | unsigned int cap; |
Willy Tarreau | 4fee4e9 | 2007-01-06 21:09:17 +0100 | [diff] [blame] | 102 | unsigned int checks; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 103 | }; |
| 104 | |
| 105 | /* proxy->options */ |
| 106 | static const struct cfg_opt cfg_opts[] = |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 107 | { |
Willy Tarreau | 4fee4e9 | 2007-01-06 21:09:17 +0100 | [diff] [blame] | 108 | { "abortonclose", PR_O_ABRT_CLOSE, PR_CAP_BE, 0 }, |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 109 | { "allbackups", PR_O_USE_ALL_BK, PR_CAP_BE, 0 }, |
Willy Tarreau | 4fee4e9 | 2007-01-06 21:09:17 +0100 | [diff] [blame] | 110 | { "checkcache", PR_O_CHK_CACHE, PR_CAP_BE, 0 }, |
Willy Tarreau | 4fee4e9 | 2007-01-06 21:09:17 +0100 | [diff] [blame] | 111 | { "clitcpka", PR_O_TCP_CLI_KA, PR_CAP_FE, 0 }, |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 112 | { "contstats", PR_O_CONTSTATS, PR_CAP_FE, 0 }, |
| 113 | { "dontlognull", PR_O_NULLNOLOG, PR_CAP_FE, 0 }, |
Willy Tarreau | a31e5df | 2009-12-30 01:10:35 +0100 | [diff] [blame] | 114 | { "forceclose", PR_O_FORCE_CLO, PR_CAP_FE | PR_CAP_BE, 0 }, |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 115 | { "http_proxy", PR_O_HTTP_PROXY, PR_CAP_FE | PR_CAP_BE, 0 }, |
| 116 | { "httpclose", PR_O_HTTP_CLOSE, PR_CAP_FE | PR_CAP_BE, 0 }, |
| 117 | { "keepalive", PR_O_KEEPALIVE, PR_CAP_NONE, 0 }, |
Willy Tarreau | b608feb | 2010-01-02 22:47:18 +0100 | [diff] [blame] | 118 | { "http-server-close", PR_O_SERVER_CLO, PR_CAP_FE | PR_CAP_BE, 0 }, |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 119 | { "logasap", PR_O_LOGASAP, PR_CAP_FE, 0 }, |
| 120 | { "nolinger", PR_O_TCP_NOLING, PR_CAP_FE | PR_CAP_BE, 0 }, |
Willy Tarreau | 4fee4e9 | 2007-01-06 21:09:17 +0100 | [diff] [blame] | 121 | { "persist", PR_O_PERSIST, PR_CAP_BE, 0 }, |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 122 | { "redispatch", PR_O_REDISP, PR_CAP_BE, 0 }, |
| 123 | { "srvtcpka", PR_O_TCP_SRV_KA, PR_CAP_BE, 0 }, |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 124 | #ifdef TPROXY |
Willy Tarreau | 4b1f859 | 2008-12-23 23:13:55 +0100 | [diff] [blame] | 125 | { "transparent", PR_O_TRANSP, PR_CAP_BE, 0 }, |
Willy Tarreau | 8f922fc | 2007-01-06 21:11:49 +0100 | [diff] [blame] | 126 | #endif |
| 127 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 128 | { NULL, 0, 0, 0 } |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 129 | }; |
| 130 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 131 | /* proxy->options2 */ |
| 132 | static const struct cfg_opt cfg_opts2[] = |
| 133 | { |
| 134 | #ifdef CONFIG_HAP_LINUX_SPLICE |
| 135 | { "splice-request", PR_O2_SPLIC_REQ, PR_CAP_FE|PR_CAP_BE, 0 }, |
| 136 | { "splice-response", PR_O2_SPLIC_RTR, PR_CAP_FE|PR_CAP_BE, 0 }, |
| 137 | { "splice-auto", PR_O2_SPLIC_AUT, PR_CAP_FE|PR_CAP_BE, 0 }, |
| 138 | #endif |
Willy Tarreau | 32a4ec0 | 2009-04-02 11:35:18 +0200 | [diff] [blame] | 139 | { "accept-invalid-http-request", PR_O2_REQBUG_OK, PR_CAP_FE, 0 }, |
| 140 | { "accept-invalid-http-response", PR_O2_RSPBUG_OK, PR_CAP_BE, 0 }, |
Willy Tarreau | c9bd0cc | 2009-05-10 11:57:02 +0200 | [diff] [blame] | 141 | { "dontlog-normal", PR_O2_NOLOGNORM, PR_CAP_FE, 0 }, |
| 142 | { "log-separate-errors", PR_O2_LOGERRORS, PR_CAP_FE, 0 }, |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 143 | { "log-health-checks", PR_O2_LOGHCHKS, PR_CAP_BE, 0 }, |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 144 | { "socket-stats", PR_O2_SOCKSTAT, PR_CAP_FE, 0 }, |
Willy Tarreau | 9ea05a7 | 2009-06-14 12:07:01 +0200 | [diff] [blame] | 145 | { "tcp-smart-accept", PR_O2_SMARTACC, PR_CAP_FE, 0 }, |
Willy Tarreau | d88edf2 | 2009-06-14 15:48:17 +0200 | [diff] [blame] | 146 | { "tcp-smart-connect", PR_O2_SMARTCON, PR_CAP_BE, 0 }, |
Willy Tarreau | f27b5ea | 2009-10-03 22:01:18 +0200 | [diff] [blame] | 147 | { "independant-streams", PR_O2_INDEPSTR, PR_CAP_FE|PR_CAP_BE, 0 }, |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 148 | { NULL, 0, 0, 0 } |
| 149 | }; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 150 | |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 151 | static char *cursection = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 152 | static struct proxy defproxy; /* fake proxy used to assign default values on all instances */ |
| 153 | int cfg_maxpconn = DEFAULT_MAXCONN; /* # of simultaneous connections per proxy (-N) */ |
Willy Tarreau | 5af24ef | 2009-03-15 15:23:16 +0100 | [diff] [blame] | 154 | int cfg_maxconn = 0; /* # of simultaneous connections, (-n) */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 155 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 156 | /* List head of all known configuration keywords */ |
| 157 | static struct cfg_kw_list cfg_keywords = { |
| 158 | .list = LIST_HEAD_INIT(cfg_keywords.list) |
| 159 | }; |
| 160 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 161 | /* |
| 162 | * converts <str> to a list of listeners which are dynamically allocated. |
| 163 | * The format is "{addr|'*'}:port[-end][,{addr|'*'}:port[-end]]*", where : |
| 164 | * - <addr> can be empty or "*" to indicate INADDR_ANY ; |
| 165 | * - <port> is a numerical port from 1 to 65535 ; |
| 166 | * - <end> indicates to use the range from <port> to <end> instead (inclusive). |
| 167 | * This can be repeated as many times as necessary, separated by a coma. |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 168 | * Function returns 1 for success or 0 if error. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 169 | */ |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 170 | static int str2listener(char *str, struct proxy *curproxy) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 171 | { |
| 172 | struct listener *l; |
| 173 | char *c, *next, *range, *dupstr; |
| 174 | int port, end; |
| 175 | |
| 176 | next = dupstr = strdup(str); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 177 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 178 | while (next && *next) { |
| 179 | struct sockaddr_storage ss; |
| 180 | |
| 181 | str = next; |
| 182 | /* 1) look for the end of the first address */ |
Krzysztof Piotr Oledzki | 52d522b | 2009-01-27 16:57:08 +0100 | [diff] [blame] | 183 | if ((next = strchr(str, ',')) != NULL) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 184 | *next++ = 0; |
| 185 | } |
| 186 | |
| 187 | /* 2) look for the addr/port delimiter, it's the last colon. */ |
| 188 | if ((range = strrchr(str, ':')) == NULL) { |
| 189 | Alert("Missing port number: '%s'\n", str); |
| 190 | goto fail; |
| 191 | } |
| 192 | |
| 193 | *range++ = 0; |
| 194 | |
| 195 | if (strrchr(str, ':') != NULL) { |
| 196 | /* IPv6 address contains ':' */ |
| 197 | memset(&ss, 0, sizeof(ss)); |
| 198 | ss.ss_family = AF_INET6; |
| 199 | |
| 200 | if (!inet_pton(ss.ss_family, str, &((struct sockaddr_in6 *)&ss)->sin6_addr)) { |
| 201 | Alert("Invalid server address: '%s'\n", str); |
| 202 | goto fail; |
| 203 | } |
| 204 | } |
| 205 | else { |
| 206 | memset(&ss, 0, sizeof(ss)); |
| 207 | ss.ss_family = AF_INET; |
| 208 | |
| 209 | if (*str == '*' || *str == '\0') { /* INADDR_ANY */ |
| 210 | ((struct sockaddr_in *)&ss)->sin_addr.s_addr = INADDR_ANY; |
| 211 | } |
| 212 | else if (!inet_pton(ss.ss_family, str, &((struct sockaddr_in *)&ss)->sin_addr)) { |
| 213 | struct hostent *he; |
| 214 | |
| 215 | if ((he = gethostbyname(str)) == NULL) { |
| 216 | Alert("Invalid server name: '%s'\n", str); |
| 217 | goto fail; |
| 218 | } |
| 219 | else |
| 220 | ((struct sockaddr_in *)&ss)->sin_addr = |
| 221 | *(struct in_addr *) *(he->h_addr_list); |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | /* 3) look for the port-end delimiter */ |
| 226 | if ((c = strchr(range, '-')) != NULL) { |
| 227 | *c++ = 0; |
| 228 | end = atol(c); |
| 229 | } |
| 230 | else { |
| 231 | end = atol(range); |
| 232 | } |
| 233 | |
| 234 | port = atol(range); |
| 235 | |
| 236 | if (port < 1 || port > 65535) { |
| 237 | Alert("Invalid port '%d' specified for address '%s'.\n", port, str); |
| 238 | goto fail; |
| 239 | } |
| 240 | |
| 241 | if (end < 1 || end > 65535) { |
| 242 | Alert("Invalid port '%d' specified for address '%s'.\n", end, str); |
| 243 | goto fail; |
| 244 | } |
| 245 | |
| 246 | for (; port <= end; port++) { |
| 247 | l = (struct listener *)calloc(1, sizeof(struct listener)); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 248 | l->next = curproxy->listen; |
| 249 | curproxy->listen = l; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 250 | |
| 251 | l->fd = -1; |
| 252 | l->addr = ss; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 253 | l->state = LI_INIT; |
| 254 | |
| 255 | if (ss.ss_family == AF_INET6) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 256 | ((struct sockaddr_in6 *)(&l->addr))->sin6_port = htons(port); |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 257 | tcpv6_add_listener(l); |
| 258 | } else { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 259 | ((struct sockaddr_in *)(&l->addr))->sin_port = htons(port); |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 260 | tcpv4_add_listener(l); |
| 261 | } |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 262 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 263 | listeners++; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 264 | } /* end for(port) */ |
| 265 | } /* end while(next) */ |
| 266 | free(dupstr); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 267 | return 1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 268 | fail: |
| 269 | free(dupstr); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 270 | return 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 271 | } |
| 272 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 273 | /* |
| 274 | * Sends a warning if proxy <proxy> does not have at least one of the |
| 275 | * capabilities in <cap>. An optionnal <hint> may be added at the end |
| 276 | * of the warning to help the user. Returns 1 if a warning was emitted |
| 277 | * or 0 if the condition is valid. |
| 278 | */ |
| 279 | int warnifnotcap(struct proxy *proxy, int cap, const char *file, int line, char *arg, char *hint) |
| 280 | { |
| 281 | char *msg; |
| 282 | |
| 283 | switch (cap) { |
| 284 | case PR_CAP_BE: msg = "no backend"; break; |
| 285 | case PR_CAP_FE: msg = "no frontend"; break; |
| 286 | case PR_CAP_RS: msg = "no ruleset"; break; |
| 287 | case PR_CAP_BE|PR_CAP_FE: msg = "neither frontend nor backend"; break; |
| 288 | default: msg = "not enough"; break; |
| 289 | } |
| 290 | |
| 291 | if (!(proxy->cap & cap)) { |
| 292 | Warning("parsing [%s:%d] : '%s' ignored because %s '%s' has %s capability.%s\n", |
Willy Tarreau | 2b5652f | 2006-12-31 17:46:05 +0100 | [diff] [blame] | 293 | file, line, arg, proxy_type_str(proxy), proxy->id, msg, hint ? hint : ""); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 294 | return 1; |
| 295 | } |
| 296 | return 0; |
| 297 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 298 | |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 299 | /* Report a warning if a rule is placed after a 'block' rule. |
| 300 | * Return 1 if the warning has been emitted, otherwise 0. |
| 301 | */ |
| 302 | int warnif_rule_after_block(struct proxy *proxy, const char *file, int line, char *arg) |
| 303 | { |
| 304 | if (!LIST_ISEMPTY(&proxy->block_cond)) { |
| 305 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'block' rule will still be processed before.\n", |
| 306 | file, line, arg); |
| 307 | return 1; |
| 308 | } |
| 309 | return 0; |
| 310 | } |
| 311 | |
| 312 | /* Report a warning if a rule is placed after a reqrewrite rule. |
| 313 | * Return 1 if the warning has been emitted, otherwise 0. |
| 314 | */ |
| 315 | int warnif_rule_after_reqxxx(struct proxy *proxy, const char *file, int line, char *arg) |
| 316 | { |
| 317 | if (proxy->req_exp) { |
| 318 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'reqxxx' rule will still be processed before.\n", |
| 319 | file, line, arg); |
| 320 | return 1; |
| 321 | } |
| 322 | return 0; |
| 323 | } |
| 324 | |
| 325 | /* Report a warning if a rule is placed after a reqadd rule. |
| 326 | * Return 1 if the warning has been emitted, otherwise 0. |
| 327 | */ |
| 328 | int warnif_rule_after_reqadd(struct proxy *proxy, const char *file, int line, char *arg) |
| 329 | { |
| 330 | if (proxy->nb_reqadd) { |
| 331 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'reqadd' rule will still be processed before.\n", |
| 332 | file, line, arg); |
| 333 | return 1; |
| 334 | } |
| 335 | return 0; |
| 336 | } |
| 337 | |
| 338 | /* Report a warning if a rule is placed after a redirect rule. |
| 339 | * Return 1 if the warning has been emitted, otherwise 0. |
| 340 | */ |
| 341 | int warnif_rule_after_redirect(struct proxy *proxy, const char *file, int line, char *arg) |
| 342 | { |
| 343 | if (!LIST_ISEMPTY(&proxy->redirect_rules)) { |
| 344 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'redirect' rule will still be processed before.\n", |
| 345 | file, line, arg); |
| 346 | return 1; |
| 347 | } |
| 348 | return 0; |
| 349 | } |
| 350 | |
| 351 | /* Report a warning if a rule is placed after a 'use_backend' rule. |
| 352 | * Return 1 if the warning has been emitted, otherwise 0. |
| 353 | */ |
| 354 | int warnif_rule_after_use_backend(struct proxy *proxy, const char *file, int line, char *arg) |
| 355 | { |
| 356 | if (!LIST_ISEMPTY(&proxy->switching_rules)) { |
| 357 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'use_backend' rule will still be processed before.\n", |
| 358 | file, line, arg); |
| 359 | return 1; |
| 360 | } |
| 361 | return 0; |
| 362 | } |
| 363 | |
| 364 | /* report a warning if a block rule is dangerously placed */ |
| 365 | int warnif_misplaced_block(struct proxy *proxy, const char *file, int line, char *arg) |
| 366 | { |
| 367 | return warnif_rule_after_reqxxx(proxy, file, line, arg) || |
| 368 | warnif_rule_after_reqadd(proxy, file, line, arg) || |
| 369 | warnif_rule_after_redirect(proxy, file, line, arg) || |
| 370 | warnif_rule_after_use_backend(proxy, file, line, arg); |
| 371 | } |
| 372 | |
| 373 | /* report a warning if a reqxxx rule is dangerously placed */ |
| 374 | int warnif_misplaced_reqxxx(struct proxy *proxy, const char *file, int line, char *arg) |
| 375 | { |
| 376 | return warnif_rule_after_reqadd(proxy, file, line, arg) || |
| 377 | warnif_rule_after_redirect(proxy, file, line, arg) || |
| 378 | warnif_rule_after_use_backend(proxy, file, line, arg); |
| 379 | } |
| 380 | |
| 381 | /* report a warning if a reqadd rule is dangerously placed */ |
| 382 | int warnif_misplaced_reqadd(struct proxy *proxy, const char *file, int line, char *arg) |
| 383 | { |
| 384 | return warnif_rule_after_redirect(proxy, file, line, arg) || |
| 385 | warnif_rule_after_use_backend(proxy, file, line, arg); |
| 386 | } |
| 387 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 388 | /* |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 389 | * parse a line in a <global> section. Returns the error code, 0 if OK, or |
| 390 | * any combination of : |
| 391 | * - ERR_ABORT: must abort ASAP |
| 392 | * - ERR_FATAL: we can continue parsing but not start the service |
| 393 | * - ERR_WARN: a warning has been emitted |
| 394 | * - ERR_ALERT: an alert has been emitted |
| 395 | * Only the two first ones can stop processing, the two others are just |
| 396 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 397 | */ |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 398 | int cfg_parse_global(const char *file, int linenum, char **args, int kwm) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 399 | { |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 400 | int err_code = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 401 | |
| 402 | if (!strcmp(args[0], "global")) { /* new section */ |
| 403 | /* no option, nothing special to do */ |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 404 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 405 | } |
| 406 | else if (!strcmp(args[0], "daemon")) { |
| 407 | global.mode |= MODE_DAEMON; |
| 408 | } |
| 409 | else if (!strcmp(args[0], "debug")) { |
| 410 | global.mode |= MODE_DEBUG; |
| 411 | } |
| 412 | else if (!strcmp(args[0], "noepoll")) { |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 413 | global.tune.options &= ~GTUNE_USE_EPOLL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 414 | } |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 415 | else if (!strcmp(args[0], "nosepoll")) { |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 416 | global.tune.options &= ~GTUNE_USE_SEPOLL; |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 417 | } |
| 418 | else if (!strcmp(args[0], "nokqueue")) { |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 419 | global.tune.options &= ~GTUNE_USE_KQUEUE; |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 420 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 421 | else if (!strcmp(args[0], "nopoll")) { |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 422 | global.tune.options &= ~GTUNE_USE_POLL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 423 | } |
Willy Tarreau | 3ab68cf | 2009-01-25 16:03:28 +0100 | [diff] [blame] | 424 | else if (!strcmp(args[0], "nosplice")) { |
| 425 | global.tune.options &= ~GTUNE_USE_SPLICE; |
| 426 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 427 | else if (!strcmp(args[0], "quiet")) { |
| 428 | global.mode |= MODE_QUIET; |
| 429 | } |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 430 | else if (!strcmp(args[0], "tune.maxpollevents")) { |
| 431 | if (global.tune.maxpollevents != 0) { |
| 432 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 433 | err_code |= ERR_ALERT; |
| 434 | goto out; |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 435 | } |
| 436 | if (*(args[1]) == 0) { |
| 437 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 438 | err_code |= ERR_ALERT | ERR_FATAL; |
| 439 | goto out; |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 440 | } |
| 441 | global.tune.maxpollevents = atol(args[1]); |
| 442 | } |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 443 | else if (!strcmp(args[0], "tune.maxaccept")) { |
| 444 | if (global.tune.maxaccept != 0) { |
| 445 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 446 | err_code |= ERR_ALERT; |
| 447 | goto out; |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 448 | } |
| 449 | if (*(args[1]) == 0) { |
| 450 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 451 | err_code |= ERR_ALERT | ERR_FATAL; |
| 452 | goto out; |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 453 | } |
| 454 | global.tune.maxaccept = atol(args[1]); |
| 455 | } |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 456 | else if (!strcmp(args[0], "tune.bufsize")) { |
| 457 | if (*(args[1]) == 0) { |
| 458 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 459 | err_code |= ERR_ALERT | ERR_FATAL; |
| 460 | goto out; |
| 461 | } |
| 462 | global.tune.bufsize = atol(args[1]); |
| 463 | if (global.tune.maxrewrite >= global.tune.bufsize / 2) |
| 464 | global.tune.maxrewrite = global.tune.bufsize / 2; |
| 465 | } |
| 466 | else if (!strcmp(args[0], "tune.maxrewrite")) { |
| 467 | if (*(args[1]) == 0) { |
| 468 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 469 | err_code |= ERR_ALERT | ERR_FATAL; |
| 470 | goto out; |
| 471 | } |
| 472 | global.tune.maxrewrite = atol(args[1]); |
| 473 | if (global.tune.maxrewrite >= global.tune.bufsize / 2) |
| 474 | global.tune.maxrewrite = global.tune.bufsize / 2; |
| 475 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 476 | else if (!strcmp(args[0], "uid")) { |
| 477 | if (global.uid != 0) { |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 478 | Alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 479 | err_code |= ERR_ALERT; |
| 480 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 481 | } |
| 482 | if (*(args[1]) == 0) { |
| 483 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 484 | err_code |= ERR_ALERT | ERR_FATAL; |
| 485 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 486 | } |
| 487 | global.uid = atol(args[1]); |
| 488 | } |
| 489 | else if (!strcmp(args[0], "gid")) { |
| 490 | if (global.gid != 0) { |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 491 | Alert("parsing [%s:%d] : group/gid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 492 | err_code |= ERR_ALERT; |
| 493 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 494 | } |
| 495 | if (*(args[1]) == 0) { |
| 496 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 497 | err_code |= ERR_ALERT | ERR_FATAL; |
| 498 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 499 | } |
| 500 | global.gid = atol(args[1]); |
| 501 | } |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 502 | /* user/group name handling */ |
| 503 | else if (!strcmp(args[0], "user")) { |
| 504 | struct passwd *ha_user; |
| 505 | if (global.uid != 0) { |
| 506 | Alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 507 | err_code |= ERR_ALERT; |
| 508 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 509 | } |
| 510 | errno = 0; |
| 511 | ha_user = getpwnam(args[1]); |
| 512 | if (ha_user != NULL) { |
| 513 | global.uid = (int)ha_user->pw_uid; |
| 514 | } |
| 515 | else { |
| 516 | Alert("parsing [%s:%d] : cannot find user id for '%s' (%d:%s)\n", file, linenum, args[1], errno, strerror(errno)); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 517 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 518 | } |
| 519 | } |
| 520 | else if (!strcmp(args[0], "group")) { |
| 521 | struct group *ha_group; |
| 522 | if (global.gid != 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 523 | Alert("parsing [%s:%d] : gid/group was already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 524 | err_code |= ERR_ALERT; |
| 525 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 526 | } |
| 527 | errno = 0; |
| 528 | ha_group = getgrnam(args[1]); |
| 529 | if (ha_group != NULL) { |
| 530 | global.gid = (int)ha_group->gr_gid; |
| 531 | } |
| 532 | else { |
| 533 | Alert("parsing [%s:%d] : cannot find group id for '%s' (%d:%s)\n", file, linenum, args[1], errno, strerror(errno)); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 534 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 535 | } |
| 536 | } |
| 537 | /* end of user/group name handling*/ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 538 | else if (!strcmp(args[0], "nbproc")) { |
| 539 | if (global.nbproc != 0) { |
| 540 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 541 | err_code |= ERR_ALERT; |
| 542 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 543 | } |
| 544 | if (*(args[1]) == 0) { |
| 545 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 546 | err_code |= ERR_ALERT | ERR_FATAL; |
| 547 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 548 | } |
| 549 | global.nbproc = atol(args[1]); |
| 550 | } |
| 551 | else if (!strcmp(args[0], "maxconn")) { |
| 552 | if (global.maxconn != 0) { |
| 553 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 554 | err_code |= ERR_ALERT; |
| 555 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 556 | } |
| 557 | if (*(args[1]) == 0) { |
| 558 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 559 | err_code |= ERR_ALERT | ERR_FATAL; |
| 560 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 561 | } |
| 562 | global.maxconn = atol(args[1]); |
| 563 | #ifdef SYSTEM_MAXCONN |
| 564 | if (global.maxconn > DEFAULT_MAXCONN && cfg_maxconn <= DEFAULT_MAXCONN) { |
| 565 | 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); |
| 566 | global.maxconn = DEFAULT_MAXCONN; |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 567 | err_code |= ERR_ALERT; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 568 | } |
| 569 | #endif /* SYSTEM_MAXCONN */ |
| 570 | } |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 571 | else if (!strcmp(args[0], "maxpipes")) { |
| 572 | if (global.maxpipes != 0) { |
| 573 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 574 | err_code |= ERR_ALERT; |
| 575 | goto out; |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 576 | } |
| 577 | if (*(args[1]) == 0) { |
| 578 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 579 | err_code |= ERR_ALERT | ERR_FATAL; |
| 580 | goto out; |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 581 | } |
| 582 | global.maxpipes = atol(args[1]); |
| 583 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 584 | else if (!strcmp(args[0], "ulimit-n")) { |
| 585 | if (global.rlimit_nofile != 0) { |
| 586 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 587 | err_code |= ERR_ALERT; |
| 588 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 589 | } |
| 590 | if (*(args[1]) == 0) { |
| 591 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 592 | err_code |= ERR_ALERT | ERR_FATAL; |
| 593 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 594 | } |
| 595 | global.rlimit_nofile = atol(args[1]); |
| 596 | } |
| 597 | else if (!strcmp(args[0], "chroot")) { |
| 598 | if (global.chroot != NULL) { |
| 599 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 600 | err_code |= ERR_ALERT; |
| 601 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 602 | } |
| 603 | if (*(args[1]) == 0) { |
| 604 | Alert("parsing [%s:%d] : '%s' expects a directory as an argument.\n", file, linenum, args[0]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 605 | err_code |= ERR_ALERT | ERR_FATAL; |
| 606 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 607 | } |
| 608 | global.chroot = strdup(args[1]); |
| 609 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 610 | else if (!strcmp(args[0], "description")) { |
| 611 | int i, len=0; |
| 612 | char *d; |
| 613 | |
| 614 | if (!*args[1]) { |
| 615 | Alert("parsing [%s:%d]: '%s' expects a string argument.\n", |
| 616 | file, linenum, args[0]); |
| 617 | err_code |= ERR_ALERT | ERR_FATAL; |
| 618 | goto out; |
| 619 | } |
| 620 | |
| 621 | for(i=1; *args[i]; i++) |
| 622 | len += strlen(args[i])+1; |
| 623 | |
| 624 | if (global.desc) |
| 625 | free(global.desc); |
| 626 | |
| 627 | global.desc = d = (char *)calloc(1, len); |
| 628 | |
| 629 | d += sprintf(d, "%s", args[1]); |
| 630 | for(i=2; *args[i]; i++) |
| 631 | d += sprintf(d, " %s", args[i]); |
| 632 | } |
| 633 | else if (!strcmp(args[0], "node")) { |
| 634 | int i; |
| 635 | char c; |
| 636 | |
| 637 | for (i=0; args[1][i]; i++) { |
| 638 | c = args[1][i]; |
| 639 | if (!isupper(c) && !islower(c) && !isdigit(c) && c != '_' && c != '-' && c != '.') |
| 640 | break; |
| 641 | } |
| 642 | |
| 643 | if (!i || args[1][i]) { |
| 644 | Alert("parsing [%s:%d]: '%s' requires valid node name - non-empty string" |
| 645 | " with digits(0-9), letters(A-Z, a-z), dot(.), hyphen(-) or underscode(_).\n", |
| 646 | file, linenum, args[0]); |
| 647 | err_code |= ERR_ALERT | ERR_FATAL; |
| 648 | goto out; |
| 649 | } |
| 650 | |
| 651 | if (global.node) |
| 652 | free(global.node); |
| 653 | |
| 654 | global.node = strdup(args[1]); |
| 655 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 656 | else if (!strcmp(args[0], "pidfile")) { |
| 657 | if (global.pidfile != NULL) { |
| 658 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 659 | err_code |= ERR_ALERT; |
| 660 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 661 | } |
| 662 | if (*(args[1]) == 0) { |
| 663 | Alert("parsing [%s:%d] : '%s' expects a file name as an argument.\n", file, linenum, args[0]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 664 | err_code |= ERR_ALERT | ERR_FATAL; |
| 665 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 666 | } |
| 667 | global.pidfile = strdup(args[1]); |
| 668 | } |
| 669 | else if (!strcmp(args[0], "log")) { /* syslog server address */ |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 670 | struct logsrv logsrv; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 671 | int facility, level, minlvl; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 672 | |
| 673 | if (*(args[1]) == 0 || *(args[2]) == 0) { |
| 674 | Alert("parsing [%s:%d] : '%s' expects <address> and <facility> as arguments.\n", file, linenum, args[0]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 675 | err_code |= ERR_ALERT | ERR_FATAL; |
| 676 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 677 | } |
| 678 | |
| 679 | facility = get_log_facility(args[2]); |
| 680 | if (facility < 0) { |
| 681 | Alert("parsing [%s:%d] : unknown log facility '%s'\n", file, linenum, args[2]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 682 | err_code |= ERR_ALERT | ERR_FATAL; |
| 683 | facility = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 684 | } |
| 685 | |
| 686 | level = 7; /* max syslog level = debug */ |
| 687 | if (*(args[3])) { |
| 688 | level = get_log_level(args[3]); |
| 689 | if (level < 0) { |
| 690 | Alert("parsing [%s:%d] : unknown optional log level '%s'\n", file, linenum, args[3]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 691 | err_code |= ERR_ALERT | ERR_FATAL; |
| 692 | level = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 693 | } |
| 694 | } |
| 695 | |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 696 | minlvl = 0; /* limit syslog level to this level (emerg) */ |
| 697 | if (*(args[4])) { |
| 698 | minlvl = get_log_level(args[4]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 699 | if (minlvl < 0) { |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 700 | Alert("parsing [%s:%d] : unknown optional minimum log level '%s'\n", file, linenum, args[4]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 701 | err_code |= ERR_ALERT | ERR_FATAL; |
| 702 | minlvl = 0; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 703 | } |
| 704 | } |
| 705 | |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 706 | if (args[1][0] == '/') { |
| 707 | logsrv.u.addr.sa_family = AF_UNIX; |
| 708 | logsrv.u.un = *str2sun(args[1]); |
| 709 | } else { |
| 710 | logsrv.u.addr.sa_family = AF_INET; |
| 711 | logsrv.u.in = *str2sa(args[1]); |
| 712 | if (!logsrv.u.in.sin_port) |
| 713 | logsrv.u.in.sin_port = htons(SYSLOG_PORT); |
| 714 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 715 | |
| 716 | if (global.logfac1 == -1) { |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 717 | global.logsrv1 = logsrv; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 718 | global.logfac1 = facility; |
| 719 | global.loglev1 = level; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 720 | global.minlvl1 = minlvl; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 721 | } |
| 722 | else if (global.logfac2 == -1) { |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 723 | global.logsrv2 = logsrv; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 724 | global.logfac2 = facility; |
| 725 | global.loglev2 = level; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 726 | global.minlvl2 = minlvl; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 727 | } |
| 728 | else { |
| 729 | Alert("parsing [%s:%d] : too many syslog servers\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 730 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 731 | } |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 732 | } |
| 733 | else if (!strcmp(args[0], "spread-checks")) { /* random time between checks (0-50) */ |
| 734 | if (global.spread_checks != 0) { |
| 735 | Alert("parsing [%s:%d]: spread-checks already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 736 | err_code |= ERR_ALERT; |
| 737 | goto out; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 738 | } |
| 739 | if (*(args[1]) == 0) { |
| 740 | Alert("parsing [%s:%d]: '%s' expects an integer argument (0..50).\n", file, linenum, args[0]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 741 | err_code |= ERR_ALERT | ERR_FATAL; |
| 742 | goto out; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 743 | } |
| 744 | global.spread_checks = atol(args[1]); |
| 745 | if (global.spread_checks < 0 || global.spread_checks > 50) { |
| 746 | Alert("parsing [%s:%d]: 'spread-checks' needs a positive value in range 0..50.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 747 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 748 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 749 | } |
| 750 | else { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 751 | struct cfg_kw_list *kwl; |
| 752 | int index; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 753 | int rc; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 754 | |
| 755 | list_for_each_entry(kwl, &cfg_keywords.list, list) { |
| 756 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 757 | if (kwl->kw[index].section != CFG_GLOBAL) |
| 758 | continue; |
| 759 | if (strcmp(kwl->kw[index].kw, args[0]) == 0) { |
| 760 | /* prepare error message just in case */ |
| 761 | snprintf(trash, sizeof(trash), |
| 762 | "error near '%s' in '%s' section", args[0], "global"); |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 763 | rc = kwl->kw[index].parse(args, CFG_GLOBAL, NULL, NULL, trash, sizeof(trash)); |
| 764 | if (rc < 0) { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 765 | Alert("parsing [%s:%d] : %s\n", file, linenum, trash); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 766 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 767 | } |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 768 | else if (rc > 0) { |
| 769 | Warning("parsing [%s:%d] : %s\n", file, linenum, trash); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 770 | err_code |= ERR_WARN; |
| 771 | goto out; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 772 | } |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 773 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 774 | } |
| 775 | } |
| 776 | } |
| 777 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 778 | Alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], "global"); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 779 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 780 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 781 | |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 782 | out: |
| 783 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 784 | } |
| 785 | |
| 786 | |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 787 | void init_default_instance() |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 788 | { |
| 789 | memset(&defproxy, 0, sizeof(defproxy)); |
| 790 | defproxy.mode = PR_MODE_TCP; |
| 791 | defproxy.state = PR_STNEW; |
| 792 | defproxy.maxconn = cfg_maxpconn; |
| 793 | defproxy.conn_retries = CONN_RETRIES; |
| 794 | defproxy.logfac1 = defproxy.logfac2 = -1; /* log disabled */ |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 795 | |
| 796 | LIST_INIT(&defproxy.pendconns); |
| 797 | LIST_INIT(&defproxy.acl); |
| 798 | LIST_INIT(&defproxy.block_cond); |
| 799 | LIST_INIT(&defproxy.mon_fail_cond); |
| 800 | LIST_INIT(&defproxy.switching_rules); |
| 801 | |
Willy Tarreau | 3a70f94 | 2008-02-15 11:15:34 +0100 | [diff] [blame] | 802 | proxy_reset_timeouts(&defproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 803 | } |
| 804 | |
| 805 | /* |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 806 | * Parse a line in a <listen>, <frontend>, <backend> or <ruleset> section. |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 807 | * Returns the error code, 0 if OK, or any combination of : |
| 808 | * - ERR_ABORT: must abort ASAP |
| 809 | * - ERR_FATAL: we can continue parsing but not start the service |
| 810 | * - ERR_WARN: a warning has been emitted |
| 811 | * - ERR_ALERT: an alert has been emitted |
| 812 | * Only the two first ones can stop processing, the two others are just |
| 813 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 814 | */ |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 815 | int cfg_parse_listen(const char *file, int linenum, char **args, int kwm) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 816 | { |
| 817 | static struct proxy *curproxy = NULL; |
| 818 | struct server *newsrv = NULL; |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 819 | const char *err; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 820 | int rc; |
| 821 | unsigned val; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 822 | int err_code = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 823 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 824 | if (!strcmp(args[0], "listen")) |
| 825 | rc = PR_CAP_LISTEN; |
| 826 | else if (!strcmp(args[0], "frontend")) |
| 827 | rc = PR_CAP_FE | PR_CAP_RS; |
| 828 | else if (!strcmp(args[0], "backend")) |
| 829 | rc = PR_CAP_BE | PR_CAP_RS; |
| 830 | else if (!strcmp(args[0], "ruleset")) |
| 831 | rc = PR_CAP_RS; |
| 832 | else |
| 833 | rc = PR_CAP_NONE; |
| 834 | |
| 835 | if (rc != PR_CAP_NONE) { /* new proxy */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 836 | if (!*args[1]) { |
| 837 | Alert("parsing [%s:%d] : '%s' expects an <id> argument and\n" |
| 838 | " optionnally supports [addr1]:port1[-end1]{,[addr]:port[-end]}...\n", |
| 839 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 840 | err_code |= ERR_ALERT | ERR_ABORT; |
| 841 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 842 | } |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 843 | |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 844 | err = invalid_char(args[1]); |
| 845 | if (err) { |
| 846 | Alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 847 | file, linenum, *err, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 848 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 849 | } |
| 850 | |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 851 | for (curproxy = proxy; curproxy != NULL; curproxy = curproxy->next) { |
| 852 | /* |
| 853 | * If there are two proxies with the same name only following |
| 854 | * combinations are allowed: |
| 855 | * |
| 856 | * listen backend frontend ruleset |
| 857 | * listen - - - - |
| 858 | * backend - - OK - |
| 859 | * frontend - OK - - |
| 860 | * ruleset - - - - |
| 861 | */ |
| 862 | |
| 863 | if (!strcmp(curproxy->id, args[1]) && |
| 864 | (rc!=(PR_CAP_FE|PR_CAP_RS) || curproxy->cap!=(PR_CAP_BE|PR_CAP_RS)) && |
| 865 | (rc!=(PR_CAP_BE|PR_CAP_RS) || curproxy->cap!=(PR_CAP_FE|PR_CAP_RS))) { |
Willy Tarreau | 092549f | 2009-10-04 21:11:42 +0200 | [diff] [blame] | 866 | Warning("Parsing [%s:%d]: %s '%s' has same name as another %s (declared at %s:%d).\n", |
| 867 | file, linenum, proxy_cap_str(rc), args[1], proxy_type_str(curproxy), |
| 868 | curproxy->conf.file, curproxy->conf.line); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 869 | err_code |= ERR_WARN; |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 870 | } |
| 871 | } |
| 872 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 873 | if ((curproxy = (struct proxy *)calloc(1, sizeof(struct proxy))) == NULL) { |
| 874 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 875 | err_code |= ERR_ALERT | ERR_ABORT; |
| 876 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 877 | } |
Willy Tarreau | 5af24ef | 2009-03-15 15:23:16 +0100 | [diff] [blame] | 878 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 879 | curproxy->next = proxy; |
| 880 | proxy = curproxy; |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 881 | curproxy->conf.file = file; |
| 882 | curproxy->conf.line = linenum; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 883 | LIST_INIT(&curproxy->pendconns); |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 884 | LIST_INIT(&curproxy->acl); |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 885 | LIST_INIT(&curproxy->block_cond); |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 886 | LIST_INIT(&curproxy->redirect_rules); |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 887 | LIST_INIT(&curproxy->mon_fail_cond); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 888 | LIST_INIT(&curproxy->switching_rules); |
Willy Tarreau | b686644 | 2008-07-14 23:54:42 +0200 | [diff] [blame] | 889 | LIST_INIT(&curproxy->tcp_req.inspect_rules); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 890 | |
Willy Tarreau | ee99136 | 2007-05-14 14:37:50 +0200 | [diff] [blame] | 891 | /* Timeouts are defined as -1, so we cannot use the zeroed area |
| 892 | * as a default value. |
| 893 | */ |
Willy Tarreau | 3a70f94 | 2008-02-15 11:15:34 +0100 | [diff] [blame] | 894 | proxy_reset_timeouts(curproxy); |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 895 | |
| 896 | curproxy->last_change = now.tv_sec; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 897 | curproxy->id = strdup(args[1]); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 898 | curproxy->cap = rc; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 899 | |
| 900 | /* parse the listener address if any */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 901 | if ((curproxy->cap & PR_CAP_FE) && *args[2]) { |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 902 | struct listener *new, *last = curproxy->listen; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 903 | if (!str2listener(args[2], curproxy)) { |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 904 | err_code |= ERR_FATAL; |
| 905 | goto out; |
| 906 | } |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 907 | new = curproxy->listen; |
| 908 | while (new != last) { |
| 909 | new->conf.file = file; |
| 910 | new->conf.line = linenum; |
| 911 | new = new->next; |
| 912 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 913 | global.maxsock++; |
| 914 | } |
| 915 | |
| 916 | /* set default values */ |
| 917 | curproxy->state = defproxy.state; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 918 | curproxy->options = defproxy.options; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 919 | curproxy->options2 = defproxy.options2; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 920 | curproxy->no_options = defproxy.no_options; |
| 921 | curproxy->no_options2 = defproxy.no_options2; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 922 | curproxy->bind_proc = defproxy.bind_proc; |
Willy Tarreau | 3168223 | 2007-11-29 15:38:04 +0100 | [diff] [blame] | 923 | curproxy->lbprm.algo = defproxy.lbprm.algo; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 924 | curproxy->except_net = defproxy.except_net; |
| 925 | curproxy->except_mask = defproxy.except_mask; |
Maik Broemme | 36db02e | 2009-05-08 17:02:07 +0200 | [diff] [blame] | 926 | curproxy->except_to = defproxy.except_to; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 927 | curproxy->except_mask_to = defproxy.except_mask_to; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 928 | |
Willy Tarreau | 79f5fe8 | 2008-08-23 08:18:21 +0200 | [diff] [blame] | 929 | if (defproxy.fwdfor_hdr_len) { |
| 930 | curproxy->fwdfor_hdr_len = defproxy.fwdfor_hdr_len; |
| 931 | curproxy->fwdfor_hdr_name = strdup(defproxy.fwdfor_hdr_name); |
| 932 | } |
| 933 | |
Willy Tarreau | b86db34 | 2009-11-30 11:50:16 +0100 | [diff] [blame] | 934 | if (defproxy.orgto_hdr_len) { |
| 935 | curproxy->orgto_hdr_len = defproxy.orgto_hdr_len; |
| 936 | curproxy->orgto_hdr_name = strdup(defproxy.orgto_hdr_name); |
| 937 | } |
| 938 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 939 | if (curproxy->cap & PR_CAP_FE) { |
| 940 | curproxy->maxconn = defproxy.maxconn; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 941 | curproxy->backlog = defproxy.backlog; |
Willy Tarreau | 13a34bd | 2009-05-10 18:52:49 +0200 | [diff] [blame] | 942 | curproxy->fe_sps_lim = defproxy.fe_sps_lim; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 943 | |
| 944 | /* initialize error relocations */ |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 945 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) |
| 946 | chunk_dup(&curproxy->errmsg[rc], &defproxy.errmsg[rc]); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 947 | |
| 948 | curproxy->to_log = defproxy.to_log & ~LW_COOKIE & ~LW_REQHDR & ~ LW_RSPHDR; |
| 949 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 950 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 951 | if (curproxy->cap & PR_CAP_BE) { |
| 952 | curproxy->fullconn = defproxy.fullconn; |
| 953 | curproxy->conn_retries = defproxy.conn_retries; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 954 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 955 | if (defproxy.check_req) |
| 956 | curproxy->check_req = strdup(defproxy.check_req); |
| 957 | curproxy->check_len = defproxy.check_len; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 958 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 959 | if (defproxy.cookie_name) |
| 960 | curproxy->cookie_name = strdup(defproxy.cookie_name); |
| 961 | curproxy->cookie_len = defproxy.cookie_len; |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 962 | if (defproxy.cookie_domain) |
| 963 | curproxy->cookie_domain = strdup(defproxy.cookie_domain); |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 964 | |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 965 | if (defproxy.rdp_cookie_name) |
| 966 | curproxy->rdp_cookie_name = strdup(defproxy.rdp_cookie_name); |
| 967 | curproxy->rdp_cookie_len = defproxy.rdp_cookie_len; |
| 968 | |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 969 | if (defproxy.url_param_name) |
| 970 | curproxy->url_param_name = strdup(defproxy.url_param_name); |
| 971 | curproxy->url_param_len = defproxy.url_param_len; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 972 | |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 973 | if (defproxy.hh_name) |
| 974 | curproxy->hh_name = strdup(defproxy.hh_name); |
| 975 | curproxy->hh_len = defproxy.hh_len; |
| 976 | curproxy->hh_match_domain = defproxy.hh_match_domain; |
| 977 | |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 978 | if (defproxy.iface_name) |
| 979 | curproxy->iface_name = strdup(defproxy.iface_name); |
| 980 | curproxy->iface_len = defproxy.iface_len; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 981 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 982 | |
Willy Tarreau | 3b6b1a9 | 2009-07-23 13:24:23 +0200 | [diff] [blame] | 983 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 984 | if (defproxy.capture_name) |
| 985 | curproxy->capture_name = strdup(defproxy.capture_name); |
| 986 | curproxy->capture_namelen = defproxy.capture_namelen; |
| 987 | curproxy->capture_len = defproxy.capture_len; |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 988 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 989 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 990 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 991 | curproxy->timeout.client = defproxy.timeout.client; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 992 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | 036fae0 | 2008-01-06 13:24:40 +0100 | [diff] [blame] | 993 | curproxy->timeout.httpreq = defproxy.timeout.httpreq; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 994 | curproxy->uri_auth = defproxy.uri_auth; |
| 995 | curproxy->mon_net = defproxy.mon_net; |
| 996 | curproxy->mon_mask = defproxy.mon_mask; |
| 997 | if (defproxy.monitor_uri) |
| 998 | curproxy->monitor_uri = strdup(defproxy.monitor_uri); |
| 999 | curproxy->monitor_uri_len = defproxy.monitor_uri_len; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 1000 | if (defproxy.defbe.name) |
| 1001 | curproxy->defbe.name = strdup(defproxy.defbe.name); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1002 | } |
| 1003 | |
| 1004 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 1005 | curproxy->timeout.connect = defproxy.timeout.connect; |
| 1006 | curproxy->timeout.server = defproxy.timeout.server; |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 1007 | curproxy->timeout.check = defproxy.timeout.check; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 1008 | curproxy->timeout.queue = defproxy.timeout.queue; |
Willy Tarreau | 51c9bde | 2008-01-06 13:40:03 +0100 | [diff] [blame] | 1009 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | cd7afc0 | 2009-07-12 10:03:17 +0200 | [diff] [blame] | 1010 | curproxy->timeout.httpreq = defproxy.timeout.httpreq; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1011 | curproxy->source_addr = defproxy.source_addr; |
| 1012 | } |
| 1013 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1014 | curproxy->mode = defproxy.mode; |
| 1015 | curproxy->logfac1 = defproxy.logfac1; |
| 1016 | curproxy->logsrv1 = defproxy.logsrv1; |
| 1017 | curproxy->loglev1 = defproxy.loglev1; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 1018 | curproxy->minlvl1 = defproxy.minlvl1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1019 | curproxy->logfac2 = defproxy.logfac2; |
| 1020 | curproxy->logsrv2 = defproxy.logsrv2; |
| 1021 | curproxy->loglev2 = defproxy.loglev2; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 1022 | curproxy->minlvl2 = defproxy.minlvl2; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1023 | curproxy->grace = defproxy.grace; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1024 | curproxy->conf.used_listener_id = EB_ROOT; |
| 1025 | curproxy->conf.used_server_id = EB_ROOT; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 1026 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1027 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1028 | } |
| 1029 | else if (!strcmp(args[0], "defaults")) { /* use this one to assign default values */ |
| 1030 | /* some variables may have already been initialized earlier */ |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 1031 | /* FIXME-20070101: we should do this too at the end of the |
| 1032 | * config parsing to free all default values. |
| 1033 | */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1034 | free(defproxy.check_req); |
| 1035 | free(defproxy.cookie_name); |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 1036 | free(defproxy.rdp_cookie_name); |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 1037 | free(defproxy.cookie_domain); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1038 | free(defproxy.url_param_name); |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 1039 | free(defproxy.hh_name); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1040 | free(defproxy.capture_name); |
| 1041 | free(defproxy.monitor_uri); |
| 1042 | free(defproxy.defbe.name); |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 1043 | free(defproxy.iface_name); |
Willy Tarreau | 79f5fe8 | 2008-08-23 08:18:21 +0200 | [diff] [blame] | 1044 | free(defproxy.fwdfor_hdr_name); |
| 1045 | defproxy.fwdfor_hdr_len = 0; |
Willy Tarreau | b86db34 | 2009-11-30 11:50:16 +0100 | [diff] [blame] | 1046 | free(defproxy.orgto_hdr_name); |
| 1047 | defproxy.orgto_hdr_len = 0; |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 1048 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1049 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1050 | chunk_destroy(&defproxy.errmsg[rc]); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 1051 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1052 | /* we cannot free uri_auth because it might already be used */ |
| 1053 | init_default_instance(); |
| 1054 | curproxy = &defproxy; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1055 | defproxy.cap = PR_CAP_LISTEN; /* all caps for now */ |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1056 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1057 | } |
| 1058 | else if (curproxy == NULL) { |
| 1059 | Alert("parsing [%s:%d] : 'listen' or 'defaults' expected.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1060 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1061 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1062 | } |
| 1063 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1064 | |
| 1065 | /* Now let's parse the proxy-specific keywords */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1066 | if (!strcmp(args[0], "bind")) { /* new listen addresses */ |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 1067 | struct listener *new_listen, *last_listen; |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1068 | int cur_arg; |
| 1069 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1070 | if (curproxy == &defproxy) { |
| 1071 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1072 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1073 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1074 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1075 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1076 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1077 | |
| 1078 | if (strchr(args[1], ':') == NULL) { |
| 1079 | Alert("parsing [%s:%d] : '%s' expects [addr1]:port1[-end1]{,[addr]:port[-end]}... as arguments.\n", |
| 1080 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1081 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1082 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1083 | } |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 1084 | |
| 1085 | last_listen = curproxy->listen; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1086 | if (!str2listener(args[1], curproxy)) { |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1087 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1088 | goto out; |
| 1089 | } |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1090 | |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 1091 | new_listen = curproxy->listen; |
| 1092 | while (new_listen != last_listen) { |
| 1093 | new_listen->conf.file = file; |
| 1094 | new_listen->conf.line = linenum; |
| 1095 | new_listen = new_listen->next; |
| 1096 | } |
| 1097 | |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1098 | cur_arg = 2; |
| 1099 | while (*(args[cur_arg])) { |
| 1100 | if (!strcmp(args[cur_arg], "interface")) { /* specifically bind to this interface */ |
| 1101 | #ifdef SO_BINDTODEVICE |
| 1102 | struct listener *l; |
| 1103 | |
| 1104 | if (!*args[cur_arg + 1]) { |
| 1105 | Alert("parsing [%s:%d] : '%s' : missing interface name.\n", |
| 1106 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1107 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1108 | goto out; |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1109 | } |
| 1110 | |
| 1111 | for (l = curproxy->listen; l != last_listen; l = l->next) |
| 1112 | l->interface = strdup(args[cur_arg + 1]); |
| 1113 | |
| 1114 | global.last_checks |= LSTCHK_NETADM; |
| 1115 | |
| 1116 | cur_arg += 2; |
| 1117 | continue; |
| 1118 | #else |
| 1119 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 1120 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1121 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1122 | goto out; |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1123 | #endif |
| 1124 | } |
Willy Tarreau | be1b918 | 2009-06-14 18:48:19 +0200 | [diff] [blame] | 1125 | if (!strcmp(args[cur_arg], "mss")) { /* set MSS of listening socket */ |
| 1126 | #ifdef TCP_MAXSEG |
| 1127 | struct listener *l; |
| 1128 | int mss; |
| 1129 | |
| 1130 | if (!*args[cur_arg + 1]) { |
| 1131 | Alert("parsing [%s:%d] : '%s' : missing MSS value.\n", |
| 1132 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1133 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1134 | goto out; |
Willy Tarreau | be1b918 | 2009-06-14 18:48:19 +0200 | [diff] [blame] | 1135 | } |
| 1136 | |
| 1137 | mss = str2uic(args[cur_arg + 1]); |
| 1138 | if (mss < 1 || mss > 65535) { |
| 1139 | Alert("parsing [%s:%d]: %s expects an MSS value between 1 and 65535.\n", |
| 1140 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1141 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1142 | goto out; |
Willy Tarreau | be1b918 | 2009-06-14 18:48:19 +0200 | [diff] [blame] | 1143 | } |
| 1144 | |
| 1145 | for (l = curproxy->listen; l != last_listen; l = l->next) |
| 1146 | l->maxseg = mss; |
| 1147 | |
| 1148 | cur_arg += 2; |
| 1149 | continue; |
| 1150 | #else |
| 1151 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 1152 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1153 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1154 | goto out; |
Willy Tarreau | be1b918 | 2009-06-14 18:48:19 +0200 | [diff] [blame] | 1155 | #endif |
| 1156 | } |
Willy Tarreau | cb6cd43 | 2009-10-13 07:34:14 +0200 | [diff] [blame] | 1157 | |
| 1158 | if (!strcmp(args[cur_arg], "defer-accept")) { /* wait for some data for 1 second max before doing accept */ |
| 1159 | #ifdef TCP_DEFER_ACCEPT |
| 1160 | struct listener *l; |
| 1161 | |
| 1162 | for (l = curproxy->listen; l != last_listen; l = l->next) |
| 1163 | l->options |= LI_O_DEF_ACCEPT; |
| 1164 | |
| 1165 | cur_arg ++; |
| 1166 | continue; |
| 1167 | #else |
| 1168 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 1169 | file, linenum, args[0], args[cur_arg]); |
| 1170 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1171 | goto out; |
| 1172 | #endif |
| 1173 | } |
| 1174 | |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1175 | if (!strcmp(args[cur_arg], "transparent")) { /* transparently bind to these addresses */ |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 1176 | #ifdef CONFIG_HAP_LINUX_TPROXY |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 1177 | struct listener *l; |
| 1178 | |
| 1179 | for (l = curproxy->listen; l != last_listen; l = l->next) |
| 1180 | l->options |= LI_O_FOREIGN; |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1181 | |
| 1182 | cur_arg ++; |
| 1183 | continue; |
| 1184 | #else |
| 1185 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 1186 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1187 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1188 | goto out; |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1189 | #endif |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 1190 | } |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1191 | |
| 1192 | if (!strcmp(args[cur_arg], "name")) { |
| 1193 | struct listener *l; |
| 1194 | |
| 1195 | for (l = curproxy->listen; l != last_listen; l = l->next) |
| 1196 | l->name = strdup(args[cur_arg + 1]); |
| 1197 | |
| 1198 | cur_arg += 2; |
| 1199 | continue; |
| 1200 | } |
| 1201 | |
| 1202 | if (!strcmp(args[cur_arg], "id")) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1203 | struct eb32_node *node; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1204 | struct listener *l; |
| 1205 | |
| 1206 | if (curproxy->listen->next != last_listen) { |
| 1207 | Alert("parsing [%s:%d]: '%s' can be only used with a single socket.\n", |
| 1208 | file, linenum, args[cur_arg]); |
| 1209 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1210 | goto out; |
| 1211 | } |
| 1212 | |
| 1213 | if (!*args[cur_arg + 1]) { |
| 1214 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 1215 | file, linenum, args[cur_arg]); |
| 1216 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1217 | goto out; |
| 1218 | } |
| 1219 | |
| 1220 | curproxy->listen->luid = atol(args[cur_arg + 1]); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1221 | curproxy->listen->conf.id.key = curproxy->listen->luid; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1222 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1223 | if (curproxy->listen->luid <= 0) { |
| 1224 | Alert("parsing [%s:%d]: custom id has to be > 0\n", |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1225 | file, linenum); |
| 1226 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1227 | goto out; |
| 1228 | } |
| 1229 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1230 | node = eb32_lookup(&curproxy->conf.used_listener_id, curproxy->listen->luid); |
| 1231 | if (node) { |
| 1232 | l = container_of(node, struct listener, conf.id); |
| 1233 | Alert("parsing [%s:%d]: custom id %d for socket '%s' already used at %s:%d.\n", |
| 1234 | file, linenum, l->luid, args[1], l->conf.file, l->conf.line); |
| 1235 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1236 | goto out; |
| 1237 | } |
| 1238 | eb32_insert(&curproxy->conf.used_listener_id, &curproxy->listen->conf.id); |
| 1239 | |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1240 | cur_arg += 2; |
| 1241 | continue; |
| 1242 | } |
| 1243 | |
Willy Tarreau | cb6cd43 | 2009-10-13 07:34:14 +0200 | [diff] [blame] | 1244 | Alert("parsing [%s:%d] : '%s' only supports the 'transparent', 'defer-accept', 'name', 'id', 'mss' and 'interface' options.\n", |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 1245 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1246 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1247 | goto out; |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 1248 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1249 | global.maxsock++; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1250 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1251 | } |
| 1252 | else if (!strcmp(args[0], "monitor-net")) { /* set the range of IPs to ignore */ |
| 1253 | if (!*args[1] || !str2net(args[1], &curproxy->mon_net, &curproxy->mon_mask)) { |
| 1254 | Alert("parsing [%s:%d] : '%s' expects address[/mask].\n", |
| 1255 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1256 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1257 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1258 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1259 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1260 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1261 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1262 | /* flush useless bits */ |
| 1263 | curproxy->mon_net.s_addr &= curproxy->mon_mask.s_addr; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1264 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1265 | } |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 1266 | else if (!strcmp(args[0], "monitor-uri")) { /* set the URI to intercept */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1267 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1268 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1269 | |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 1270 | if (!*args[1]) { |
| 1271 | Alert("parsing [%s:%d] : '%s' expects an URI.\n", |
| 1272 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1273 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1274 | goto out; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 1275 | } |
| 1276 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1277 | free(curproxy->monitor_uri); |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 1278 | curproxy->monitor_uri_len = strlen(args[1]); |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 1279 | curproxy->monitor_uri = (char *)calloc(1, curproxy->monitor_uri_len + 1); |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 1280 | memcpy(curproxy->monitor_uri, args[1], curproxy->monitor_uri_len); |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 1281 | curproxy->monitor_uri[curproxy->monitor_uri_len] = '\0'; |
| 1282 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1283 | goto out; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 1284 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1285 | else if (!strcmp(args[0], "mode")) { /* sets the proxy mode */ |
| 1286 | if (!strcmp(args[1], "http")) curproxy->mode = PR_MODE_HTTP; |
| 1287 | else if (!strcmp(args[1], "tcp")) curproxy->mode = PR_MODE_TCP; |
| 1288 | else if (!strcmp(args[1], "health")) curproxy->mode = PR_MODE_HEALTH; |
| 1289 | else { |
| 1290 | Alert("parsing [%s:%d] : unknown proxy mode '%s'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1291 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1292 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1293 | } |
| 1294 | } |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 1295 | else if (!strcmp(args[0], "id")) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1296 | struct eb32_node *node; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 1297 | |
| 1298 | if (curproxy == &defproxy) { |
| 1299 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", |
| 1300 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1301 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1302 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 1303 | } |
| 1304 | |
| 1305 | if (!*args[1]) { |
| 1306 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 1307 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1308 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1309 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 1310 | } |
| 1311 | |
| 1312 | curproxy->uuid = atol(args[1]); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1313 | curproxy->conf.id.key = curproxy->uuid; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 1314 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1315 | if (curproxy->uuid <= 0) { |
| 1316 | Alert("parsing [%s:%d]: custom id has to be > 0.\n", |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 1317 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1318 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1319 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 1320 | } |
| 1321 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1322 | node = eb32_lookup(&used_proxy_id, curproxy->uuid); |
| 1323 | if (node) { |
| 1324 | struct proxy *target = container_of(node, struct proxy, conf.id); |
| 1325 | Alert("parsing [%s:%d]: %s %s reuses same custom id as %s %s (declared at %s:%d).\n", |
| 1326 | file, linenum, proxy_type_str(curproxy), curproxy->id, |
| 1327 | proxy_type_str(target), target->id, target->conf.file, target->conf.line); |
| 1328 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1329 | goto out; |
| 1330 | } |
| 1331 | eb32_insert(&used_proxy_id, &curproxy->conf.id); |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 1332 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1333 | else if (!strcmp(args[0], "description")) { |
| 1334 | int i, len=0; |
| 1335 | char *d; |
| 1336 | |
| 1337 | if (!*args[1]) { |
| 1338 | Alert("parsing [%s:%d]: '%s' expects a string argument.\n", |
| 1339 | file, linenum, args[0]); |
| 1340 | return -1; |
| 1341 | } |
| 1342 | |
| 1343 | for(i=1; *args[i]; i++) |
| 1344 | len += strlen(args[i])+1; |
| 1345 | |
| 1346 | d = (char *)calloc(1, len); |
| 1347 | curproxy->desc = d; |
| 1348 | |
| 1349 | d += sprintf(d, "%s", args[1]); |
| 1350 | for(i=2; *args[i]; i++) |
| 1351 | d += sprintf(d, " %s", args[i]); |
| 1352 | |
| 1353 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1354 | else if (!strcmp(args[0], "disabled")) { /* disables this proxy */ |
| 1355 | curproxy->state = PR_STSTOPPED; |
| 1356 | } |
| 1357 | else if (!strcmp(args[0], "enabled")) { /* enables this proxy (used to revert a disabled default) */ |
| 1358 | curproxy->state = PR_STNEW; |
| 1359 | } |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 1360 | else if (!strcmp(args[0], "bind-process")) { /* enable this proxy only on some processes */ |
| 1361 | int cur_arg = 1; |
| 1362 | unsigned int set = 0; |
| 1363 | |
| 1364 | while (*args[cur_arg]) { |
| 1365 | int u; |
| 1366 | if (strcmp(args[cur_arg], "all") == 0) { |
| 1367 | set = 0; |
| 1368 | break; |
| 1369 | } |
| 1370 | else if (strcmp(args[cur_arg], "odd") == 0) { |
| 1371 | set |= 0x55555555; |
| 1372 | } |
| 1373 | else if (strcmp(args[cur_arg], "even") == 0) { |
| 1374 | set |= 0xAAAAAAAA; |
| 1375 | } |
| 1376 | else { |
| 1377 | u = str2uic(args[cur_arg]); |
| 1378 | if (u < 1 || u > 32) { |
| 1379 | Alert("parsing [%s:%d]: %s expects 'all', 'odd', 'even', or process numbers from 1 to 32.\n", |
| 1380 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1381 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1382 | goto out; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 1383 | } |
| 1384 | if (u > global.nbproc) { |
| 1385 | Warning("parsing [%s:%d]: %s references process number higher than global.nbproc.\n", |
| 1386 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1387 | err_code |= ERR_WARN; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 1388 | } |
| 1389 | set |= 1 << (u - 1); |
| 1390 | } |
| 1391 | cur_arg++; |
| 1392 | } |
| 1393 | curproxy->bind_proc = set; |
| 1394 | } |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 1395 | else if (!strcmp(args[0], "acl")) { /* add an ACL */ |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 1396 | if (curproxy == &defproxy) { |
| 1397 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1398 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1399 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 1400 | } |
| 1401 | |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 1402 | err = invalid_char(args[1]); |
| 1403 | if (err) { |
| 1404 | Alert("parsing [%s:%d] : character '%c' is not permitted in acl name '%s'.\n", |
| 1405 | file, linenum, *err, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1406 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 1407 | } |
| 1408 | |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 1409 | if (parse_acl((const char **)args + 1, &curproxy->acl) == NULL) { |
| 1410 | Alert("parsing [%s:%d] : error detected while parsing ACL '%s'.\n", |
| 1411 | file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1412 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1413 | goto out; |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 1414 | } |
| 1415 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1416 | else if (!strcmp(args[0], "cookie")) { /* cookie name */ |
| 1417 | int cur_arg; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1418 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1419 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1420 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1421 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1422 | if (*(args[1]) == 0) { |
| 1423 | Alert("parsing [%s:%d] : '%s' expects <cookie_name> as argument.\n", |
| 1424 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1425 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1426 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1427 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1428 | |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 1429 | free(curproxy->cookie_domain); curproxy->cookie_domain = NULL; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1430 | free(curproxy->cookie_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1431 | curproxy->cookie_name = strdup(args[1]); |
| 1432 | curproxy->cookie_len = strlen(curproxy->cookie_name); |
| 1433 | |
| 1434 | cur_arg = 2; |
| 1435 | while (*(args[cur_arg])) { |
| 1436 | if (!strcmp(args[cur_arg], "rewrite")) { |
| 1437 | curproxy->options |= PR_O_COOK_RW; |
| 1438 | } |
| 1439 | else if (!strcmp(args[cur_arg], "indirect")) { |
| 1440 | curproxy->options |= PR_O_COOK_IND; |
| 1441 | } |
| 1442 | else if (!strcmp(args[cur_arg], "insert")) { |
| 1443 | curproxy->options |= PR_O_COOK_INS; |
| 1444 | } |
| 1445 | else if (!strcmp(args[cur_arg], "nocache")) { |
| 1446 | curproxy->options |= PR_O_COOK_NOC; |
| 1447 | } |
| 1448 | else if (!strcmp(args[cur_arg], "postonly")) { |
| 1449 | curproxy->options |= PR_O_COOK_POST; |
| 1450 | } |
| 1451 | else if (!strcmp(args[cur_arg], "prefix")) { |
| 1452 | curproxy->options |= PR_O_COOK_PFX; |
| 1453 | } |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 1454 | else if (!strcmp(args[cur_arg], "domain")) { |
| 1455 | if (!*args[cur_arg + 1]) { |
| 1456 | Alert("parsing [%s:%d]: '%s' expects <domain> as argument.\n", |
| 1457 | file, linenum, args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1458 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1459 | goto out; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 1460 | } |
| 1461 | |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 1462 | if (*args[cur_arg + 1] != '.' || !strchr(args[cur_arg + 1] + 1, '.')) { |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 1463 | /* rfc2109, 4.3.2 Rejecting Cookies */ |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 1464 | Warning("parsing [%s:%d]: domain '%s' contains no embedded" |
| 1465 | " dots nor does not start with a dot." |
| 1466 | " RFC forbids it, this configuration may not work properly.\n", |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 1467 | file, linenum, args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 1468 | err_code |= ERR_WARN; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 1469 | } |
| 1470 | |
| 1471 | err = invalid_domainchar(args[cur_arg + 1]); |
| 1472 | if (err) { |
| 1473 | Alert("parsing [%s:%d]: character '%c' is not permitted in domain name '%s'.\n", |
| 1474 | file, linenum, *err, args[cur_arg + 1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1475 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1476 | goto out; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 1477 | } |
| 1478 | |
Willy Tarreau | 68a897b | 2009-12-03 23:28:34 +0100 | [diff] [blame] | 1479 | if (!curproxy->cookie_domain) { |
| 1480 | curproxy->cookie_domain = strdup(args[cur_arg + 1]); |
| 1481 | } else { |
| 1482 | /* one domain was already specified, add another one by |
| 1483 | * building the string which will be returned along with |
| 1484 | * the cookie. |
| 1485 | */ |
| 1486 | char *new_ptr; |
| 1487 | int new_len = strlen(curproxy->cookie_domain) + |
| 1488 | strlen("; domain=") + strlen(args[cur_arg + 1]) + 1; |
| 1489 | new_ptr = malloc(new_len); |
| 1490 | snprintf(new_ptr, new_len, "%s; domain=%s", curproxy->cookie_domain, args[cur_arg+1]); |
| 1491 | free(curproxy->cookie_domain); |
| 1492 | curproxy->cookie_domain = new_ptr; |
| 1493 | } |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 1494 | cur_arg++; |
| 1495 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1496 | else { |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 1497 | Alert("parsing [%s:%d] : '%s' supports 'rewrite', 'insert', 'prefix', 'indirect', 'nocache' and 'postonly', 'domain' options.\n", |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1498 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1499 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1500 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1501 | } |
| 1502 | cur_arg++; |
| 1503 | } |
| 1504 | if (!POWEROF2(curproxy->options & (PR_O_COOK_RW|PR_O_COOK_IND))) { |
| 1505 | Alert("parsing [%s:%d] : cookie 'rewrite' and 'indirect' modes are incompatible.\n", |
| 1506 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1507 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1508 | } |
| 1509 | |
| 1510 | if (!POWEROF2(curproxy->options & (PR_O_COOK_RW|PR_O_COOK_INS|PR_O_COOK_PFX))) { |
| 1511 | Alert("parsing [%s:%d] : cookie 'rewrite', 'insert' and 'prefix' modes are incompatible.\n", |
| 1512 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1513 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1514 | } |
| 1515 | }/* end else if (!strcmp(args[0], "cookie")) */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 1516 | else if (!strcmp(args[0], "persist")) { /* persist */ |
| 1517 | if (*(args[1]) == 0) { |
| 1518 | Alert("parsing [%s:%d] : missing persist method.\n", |
| 1519 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1520 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1521 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 1522 | } |
| 1523 | |
| 1524 | if (!strncmp(args[1], "rdp-cookie", 10)) { |
| 1525 | curproxy->options2 |= PR_O2_RDPC_PRST; |
| 1526 | |
| 1527 | if (*(args[1] + 10 ) == '(') { /* cookie name */ |
| 1528 | const char *beg, *end; |
| 1529 | |
| 1530 | beg = args[1] + 11; |
| 1531 | end = strchr(beg, ')'); |
| 1532 | |
| 1533 | if (!end || end == beg) { |
| 1534 | Alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n", |
| 1535 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1536 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1537 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 1538 | } |
| 1539 | |
| 1540 | free(curproxy->rdp_cookie_name); |
| 1541 | curproxy->rdp_cookie_name = my_strndup(beg, end - beg); |
| 1542 | curproxy->rdp_cookie_len = end-beg; |
| 1543 | } |
| 1544 | else if (*(args[1] + 10 ) == '\0') { /* default cookie name 'msts' */ |
| 1545 | free(curproxy->rdp_cookie_name); |
| 1546 | curproxy->rdp_cookie_name = strdup("msts"); |
| 1547 | curproxy->rdp_cookie_len = strlen(curproxy->rdp_cookie_name); |
| 1548 | } |
| 1549 | else { /* syntax */ |
| 1550 | Alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n", |
| 1551 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1552 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1553 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 1554 | } |
| 1555 | } |
| 1556 | else { |
| 1557 | Alert("parsing [%s:%d] : unknown persist method.\n", |
| 1558 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1559 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1560 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 1561 | } |
| 1562 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1563 | else if (!strcmp(args[0], "appsession")) { /* cookie name */ |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 1564 | int cur_arg; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1565 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1566 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1567 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1568 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1569 | if (*(args[5]) == 0) { |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 1570 | Alert("parsing [%s:%d] : '%s' expects 'appsession' <cookie_name> 'len' <len> 'timeout' <timeout> [options*].\n", |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1571 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1572 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1573 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1574 | } |
| 1575 | have_appsession = 1; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1576 | free(curproxy->appsession_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1577 | curproxy->appsession_name = strdup(args[1]); |
| 1578 | curproxy->appsession_name_len = strlen(curproxy->appsession_name); |
| 1579 | curproxy->appsession_len = atoi(args[3]); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 1580 | err = parse_time_err(args[5], &val, TIME_UNIT_MS); |
| 1581 | if (err) { |
| 1582 | Alert("parsing [%s:%d] : unexpected character '%c' in %s timeout.\n", |
| 1583 | file, linenum, *err, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1584 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1585 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 1586 | } |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 1587 | curproxy->timeout.appsession = val; |
Willy Tarreau | ee99136 | 2007-05-14 14:37:50 +0200 | [diff] [blame] | 1588 | |
Willy Tarreau | 51041c7 | 2007-09-09 21:56:53 +0200 | [diff] [blame] | 1589 | if (appsession_hash_init(&(curproxy->htbl_proxy), destroy) == 0) { |
| 1590 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1591 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1592 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1593 | } |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 1594 | |
| 1595 | cur_arg = 6; |
| 1596 | curproxy->options2 &= ~PR_O2_AS_REQL; |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 1597 | curproxy->options2 &= ~PR_O2_AS_M_ANY; |
| 1598 | curproxy->options2 |= PR_O2_AS_M_PP; |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 1599 | while (*(args[cur_arg])) { |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 1600 | if (!strcmp(args[cur_arg], "request-learn")) { |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 1601 | curproxy->options2 |= PR_O2_AS_REQL; |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 1602 | } else if (!strcmp(args[cur_arg], "prefix")) { |
| 1603 | curproxy->options2 |= PR_O2_AS_PFX; |
| 1604 | } else if (!strcmp(args[cur_arg], "mode")) { |
| 1605 | if (!*args[cur_arg + 1]) { |
| 1606 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 1607 | file, linenum, args[0], args[cur_arg]); |
| 1608 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1609 | goto out; |
| 1610 | } |
| 1611 | |
| 1612 | cur_arg++; |
| 1613 | if (!strcmp(args[cur_arg], "query-string")) { |
| 1614 | curproxy->options2 &= ~PR_O2_AS_M_ANY; |
| 1615 | curproxy->options2 |= PR_O2_AS_M_QS; |
| 1616 | } else if (!strcmp(args[cur_arg], "path-parameters")) { |
| 1617 | curproxy->options2 &= ~PR_O2_AS_M_ANY; |
| 1618 | curproxy->options2 |= PR_O2_AS_M_PP; |
| 1619 | } else { |
| 1620 | Alert("parsing [%s:%d] : unknown mode '%s'\n", file, linenum, args[cur_arg]); |
| 1621 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1622 | goto out; |
| 1623 | } |
| 1624 | } |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 1625 | cur_arg++; |
| 1626 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1627 | } /* Url App Session */ |
| 1628 | else if (!strcmp(args[0], "capture")) { |
Willy Tarreau | 3b6b1a9 | 2009-07-23 13:24:23 +0200 | [diff] [blame] | 1629 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1630 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1631 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1632 | if (!strcmp(args[1], "cookie")) { /* name of a cookie to capture */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1633 | if (*(args[4]) == 0) { |
| 1634 | Alert("parsing [%s:%d] : '%s' expects 'cookie' <cookie_name> 'len' <len>.\n", |
| 1635 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1636 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1637 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1638 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1639 | free(curproxy->capture_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1640 | curproxy->capture_name = strdup(args[2]); |
| 1641 | curproxy->capture_namelen = strlen(curproxy->capture_name); |
| 1642 | curproxy->capture_len = atol(args[4]); |
| 1643 | if (curproxy->capture_len >= CAPTURE_LEN) { |
| 1644 | Warning("parsing [%s:%d] : truncating capture length to %d bytes.\n", |
| 1645 | file, linenum, CAPTURE_LEN - 1); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1646 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1647 | curproxy->capture_len = CAPTURE_LEN - 1; |
| 1648 | } |
| 1649 | curproxy->to_log |= LW_COOKIE; |
| 1650 | } |
| 1651 | else if (!strcmp(args[1], "request") && !strcmp(args[2], "header")) { |
| 1652 | struct cap_hdr *hdr; |
| 1653 | |
| 1654 | if (curproxy == &defproxy) { |
| 1655 | Alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1656 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1657 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1658 | } |
| 1659 | |
| 1660 | if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) { |
| 1661 | Alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n", |
| 1662 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1663 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1664 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1665 | } |
| 1666 | |
| 1667 | hdr = calloc(sizeof(struct cap_hdr), 1); |
| 1668 | hdr->next = curproxy->req_cap; |
| 1669 | hdr->name = strdup(args[3]); |
| 1670 | hdr->namelen = strlen(args[3]); |
| 1671 | hdr->len = atol(args[5]); |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 1672 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1673 | hdr->index = curproxy->nb_req_cap++; |
| 1674 | curproxy->req_cap = hdr; |
| 1675 | curproxy->to_log |= LW_REQHDR; |
| 1676 | } |
| 1677 | else if (!strcmp(args[1], "response") && !strcmp(args[2], "header")) { |
| 1678 | struct cap_hdr *hdr; |
| 1679 | |
| 1680 | if (curproxy == &defproxy) { |
| 1681 | Alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1682 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1683 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1684 | } |
| 1685 | |
| 1686 | if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) { |
| 1687 | Alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n", |
| 1688 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1689 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1690 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1691 | } |
| 1692 | hdr = calloc(sizeof(struct cap_hdr), 1); |
| 1693 | hdr->next = curproxy->rsp_cap; |
| 1694 | hdr->name = strdup(args[3]); |
| 1695 | hdr->namelen = strlen(args[3]); |
| 1696 | hdr->len = atol(args[5]); |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 1697 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1698 | hdr->index = curproxy->nb_rsp_cap++; |
| 1699 | curproxy->rsp_cap = hdr; |
| 1700 | curproxy->to_log |= LW_RSPHDR; |
| 1701 | } |
| 1702 | else { |
| 1703 | Alert("parsing [%s:%d] : '%s' expects 'cookie' or 'request header' or 'response header'.\n", |
| 1704 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1705 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1706 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1707 | } |
| 1708 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1709 | else if (!strcmp(args[0], "retries")) { /* connection retries */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1710 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1711 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1712 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1713 | if (*(args[1]) == 0) { |
| 1714 | Alert("parsing [%s:%d] : '%s' expects an integer argument (dispatch counts for one).\n", |
| 1715 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1716 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1717 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1718 | } |
| 1719 | curproxy->conn_retries = atol(args[1]); |
| 1720 | } |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 1721 | else if (!strcmp(args[0], "block")) { /* early blocking based on ACLs */ |
| 1722 | int pol = ACL_COND_NONE; |
| 1723 | struct acl_cond *cond; |
| 1724 | |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 1725 | if (curproxy == &defproxy) { |
| 1726 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1727 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1728 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 1729 | } |
| 1730 | |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 1731 | if (!strcmp(args[1], "if")) |
| 1732 | pol = ACL_COND_IF; |
| 1733 | else if (!strcmp(args[1], "unless")) |
| 1734 | pol = ACL_COND_UNLESS; |
| 1735 | |
| 1736 | if (pol == ACL_COND_NONE) { |
| 1737 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 1738 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1739 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1740 | goto out; |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 1741 | } |
| 1742 | |
| 1743 | if ((cond = parse_acl_cond((const char **)args + 2, &curproxy->acl, pol)) == NULL) { |
| 1744 | Alert("parsing [%s:%d] : error detected while parsing blocking condition.\n", |
| 1745 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1746 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1747 | goto out; |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 1748 | } |
Willy Tarreau | 8892235 | 2009-10-04 22:02:50 +0200 | [diff] [blame] | 1749 | cond->file = file; |
Willy Tarreau | a980263 | 2008-07-25 19:13:19 +0200 | [diff] [blame] | 1750 | cond->line = linenum; |
Willy Tarreau | a9fb083 | 2009-07-10 20:53:53 +0200 | [diff] [blame] | 1751 | curproxy->acl_requires |= cond->requires; |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 1752 | LIST_ADDQ(&curproxy->block_cond, &cond->list); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 1753 | warnif_misplaced_block(curproxy, file, linenum, args[0]); |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 1754 | } |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 1755 | else if (!strcmp(args[0], "redirect")) { |
| 1756 | int pol = ACL_COND_NONE; |
| 1757 | struct acl_cond *cond; |
| 1758 | struct redirect_rule *rule; |
| 1759 | int cur_arg; |
| 1760 | int type = REDIRECT_TYPE_NONE; |
| 1761 | int code = 302; |
| 1762 | char *destination = NULL; |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 1763 | char *cookie = NULL; |
| 1764 | int cookie_set = 0; |
Willy Tarreau | 79da469 | 2008-11-19 20:03:04 +0100 | [diff] [blame] | 1765 | unsigned int flags = REDIRECT_FLAG_NONE; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 1766 | |
| 1767 | cur_arg = 1; |
| 1768 | while (*(args[cur_arg])) { |
| 1769 | if (!strcmp(args[cur_arg], "location")) { |
| 1770 | if (!*args[cur_arg + 1]) { |
| 1771 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 1772 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1773 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1774 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 1775 | } |
| 1776 | |
| 1777 | type = REDIRECT_TYPE_LOCATION; |
| 1778 | cur_arg++; |
| 1779 | destination = args[cur_arg]; |
| 1780 | } |
| 1781 | else if (!strcmp(args[cur_arg], "prefix")) { |
| 1782 | if (!*args[cur_arg + 1]) { |
| 1783 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 1784 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1785 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1786 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 1787 | } |
| 1788 | |
| 1789 | type = REDIRECT_TYPE_PREFIX; |
| 1790 | cur_arg++; |
| 1791 | destination = args[cur_arg]; |
| 1792 | } |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 1793 | else if (!strcmp(args[cur_arg], "set-cookie")) { |
| 1794 | if (!*args[cur_arg + 1]) { |
| 1795 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 1796 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1797 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1798 | goto out; |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 1799 | } |
| 1800 | |
| 1801 | cur_arg++; |
| 1802 | cookie = args[cur_arg]; |
| 1803 | cookie_set = 1; |
| 1804 | } |
| 1805 | else if (!strcmp(args[cur_arg], "clear-cookie")) { |
| 1806 | if (!*args[cur_arg + 1]) { |
| 1807 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 1808 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1809 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1810 | goto out; |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 1811 | } |
| 1812 | |
| 1813 | cur_arg++; |
| 1814 | cookie = args[cur_arg]; |
| 1815 | cookie_set = 0; |
| 1816 | } |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 1817 | else if (!strcmp(args[cur_arg],"code")) { |
| 1818 | if (!*args[cur_arg + 1]) { |
| 1819 | Alert("parsing [%s:%d] : '%s': missing HTTP code.\n", |
| 1820 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1821 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1822 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 1823 | } |
| 1824 | cur_arg++; |
| 1825 | code = atol(args[cur_arg]); |
| 1826 | if (code < 301 || code > 303) { |
| 1827 | Alert("parsing [%s:%d] : '%s': unsupported HTTP code '%d'.\n", |
| 1828 | file, linenum, args[0], code); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1829 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1830 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 1831 | } |
| 1832 | } |
Willy Tarreau | 79da469 | 2008-11-19 20:03:04 +0100 | [diff] [blame] | 1833 | else if (!strcmp(args[cur_arg],"drop-query")) { |
| 1834 | flags |= REDIRECT_FLAG_DROP_QS; |
| 1835 | } |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 1836 | else if (!strcmp(args[cur_arg], "if")) { |
| 1837 | pol = ACL_COND_IF; |
| 1838 | cur_arg++; |
| 1839 | break; |
| 1840 | } |
| 1841 | else if (!strcmp(args[cur_arg], "unless")) { |
| 1842 | pol = ACL_COND_UNLESS; |
| 1843 | cur_arg++; |
| 1844 | break; |
| 1845 | } |
| 1846 | else { |
| 1847 | Alert("parsing [%s:%d] : '%s' expects 'code', 'prefix' or 'location' (was '%s').\n", |
| 1848 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1849 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1850 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 1851 | } |
| 1852 | cur_arg++; |
| 1853 | } |
| 1854 | |
| 1855 | if (type == REDIRECT_TYPE_NONE) { |
| 1856 | Alert("parsing [%s:%d] : '%s' expects a redirection type ('prefix' or 'location').\n", |
| 1857 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1858 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1859 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 1860 | } |
| 1861 | |
| 1862 | if (pol == ACL_COND_NONE) { |
| 1863 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 1864 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1865 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1866 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 1867 | } |
| 1868 | |
| 1869 | if ((cond = parse_acl_cond((const char **)args + cur_arg, &curproxy->acl, pol)) == NULL) { |
Jeffrey 'jf' Lim | af403fc | 2009-04-02 21:53:56 +0800 | [diff] [blame] | 1870 | Alert("parsing [%s:%d] : '%s': error detected while parsing redirect condition.\n", |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 1871 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1872 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1873 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 1874 | } |
| 1875 | |
Willy Tarreau | 8892235 | 2009-10-04 22:02:50 +0200 | [diff] [blame] | 1876 | cond->file = file; |
Willy Tarreau | a980263 | 2008-07-25 19:13:19 +0200 | [diff] [blame] | 1877 | cond->line = linenum; |
Willy Tarreau | a9fb083 | 2009-07-10 20:53:53 +0200 | [diff] [blame] | 1878 | curproxy->acl_requires |= cond->requires; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 1879 | rule = (struct redirect_rule *)calloc(1, sizeof(*rule)); |
| 1880 | rule->cond = cond; |
| 1881 | rule->rdr_str = strdup(destination); |
| 1882 | rule->rdr_len = strlen(destination); |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 1883 | if (cookie) { |
| 1884 | /* depending on cookie_set, either we want to set the cookie, or to clear it. |
| 1885 | * a clear consists in appending "; Max-Age=0" at the end. |
| 1886 | */ |
| 1887 | rule->cookie_len = strlen(cookie); |
| 1888 | if (cookie_set) |
| 1889 | rule->cookie_str = strdup(cookie); |
| 1890 | else { |
| 1891 | rule->cookie_str = malloc(rule->cookie_len + 12); |
| 1892 | memcpy(rule->cookie_str, cookie, rule->cookie_len); |
| 1893 | memcpy(rule->cookie_str + rule->cookie_len, "; Max-Age=0", 12); |
| 1894 | rule->cookie_len += 11; |
| 1895 | } |
| 1896 | } |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 1897 | rule->type = type; |
| 1898 | rule->code = code; |
Willy Tarreau | 79da469 | 2008-11-19 20:03:04 +0100 | [diff] [blame] | 1899 | rule->flags = flags; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 1900 | LIST_INIT(&rule->list); |
| 1901 | LIST_ADDQ(&curproxy->redirect_rules, &rule->list); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 1902 | warnif_rule_after_use_backend(curproxy, file, linenum, args[0]); |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 1903 | } |
Krzysztof Piotr Oledzki | 7b723ef | 2009-01-27 21:09:41 +0100 | [diff] [blame] | 1904 | else if (!strcmp(args[0], "use_backend")) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 1905 | int pol = ACL_COND_NONE; |
| 1906 | struct acl_cond *cond; |
| 1907 | struct switching_rule *rule; |
| 1908 | |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 1909 | if (curproxy == &defproxy) { |
| 1910 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1911 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1912 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 1913 | } |
| 1914 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 1915 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1916 | err_code |= ERR_WARN; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 1917 | |
| 1918 | if (*(args[1]) == 0) { |
| 1919 | Alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1920 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1921 | goto out; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 1922 | } |
| 1923 | |
| 1924 | if (!strcmp(args[2], "if")) |
| 1925 | pol = ACL_COND_IF; |
| 1926 | else if (!strcmp(args[2], "unless")) |
| 1927 | pol = ACL_COND_UNLESS; |
| 1928 | |
| 1929 | if (pol == ACL_COND_NONE) { |
| 1930 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 1931 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1932 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1933 | goto out; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 1934 | } |
| 1935 | |
| 1936 | if ((cond = parse_acl_cond((const char **)args + 3, &curproxy->acl, pol)) == NULL) { |
Willy Tarreau | a980263 | 2008-07-25 19:13:19 +0200 | [diff] [blame] | 1937 | Alert("parsing [%s:%d] : error detected while parsing switching rule.\n", |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 1938 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1939 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1940 | goto out; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 1941 | } |
| 1942 | |
Willy Tarreau | 8892235 | 2009-10-04 22:02:50 +0200 | [diff] [blame] | 1943 | cond->file = file; |
Willy Tarreau | a980263 | 2008-07-25 19:13:19 +0200 | [diff] [blame] | 1944 | cond->line = linenum; |
Willy Tarreau | a9fb083 | 2009-07-10 20:53:53 +0200 | [diff] [blame] | 1945 | curproxy->acl_requires |= cond->requires; |
Willy Tarreau | a980263 | 2008-07-25 19:13:19 +0200 | [diff] [blame] | 1946 | if (cond->requires & ACL_USE_RTR_ANY) { |
Willy Tarreau | dd64f8d | 2008-07-27 22:02:32 +0200 | [diff] [blame] | 1947 | struct acl *acl; |
| 1948 | const char *name; |
| 1949 | |
| 1950 | acl = cond_find_require(cond, ACL_USE_RTR_ANY); |
| 1951 | name = acl ? acl->name : "(unknown)"; |
| 1952 | Warning("parsing [%s:%d] : acl '%s' involves some response-only criteria which will be ignored.\n", |
| 1953 | file, linenum, name); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1954 | err_code |= ERR_WARN; |
Willy Tarreau | a980263 | 2008-07-25 19:13:19 +0200 | [diff] [blame] | 1955 | } |
| 1956 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 1957 | rule = (struct switching_rule *)calloc(1, sizeof(*rule)); |
| 1958 | rule->cond = cond; |
| 1959 | rule->be.name = strdup(args[1]); |
| 1960 | LIST_INIT(&rule->list); |
| 1961 | LIST_ADDQ(&curproxy->switching_rules, &rule->list); |
| 1962 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1963 | else if (!strcmp(args[0], "stats")) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1964 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1965 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1966 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1967 | if (curproxy != &defproxy && curproxy->uri_auth == defproxy.uri_auth) |
| 1968 | curproxy->uri_auth = NULL; /* we must detach from the default config */ |
| 1969 | |
| 1970 | if (*(args[1]) == 0) { |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1971 | Alert("parsing [%s:%d] : '%s' expects 'uri', 'realm', 'auth', 'scope' or 'enable', 'hide-version', 'show-node', 'show-desc'.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1972 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1973 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1974 | } else if (!strcmp(args[1], "uri")) { |
| 1975 | if (*(args[2]) == 0) { |
| 1976 | Alert("parsing [%s:%d] : 'uri' needs an URI prefix.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1977 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1978 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1979 | } else if (!stats_set_uri(&curproxy->uri_auth, args[2])) { |
| 1980 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1981 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1982 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1983 | } |
| 1984 | } else if (!strcmp(args[1], "realm")) { |
| 1985 | if (*(args[2]) == 0) { |
| 1986 | Alert("parsing [%s:%d] : 'realm' needs an realm name.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1987 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1988 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1989 | } else if (!stats_set_realm(&curproxy->uri_auth, args[2])) { |
| 1990 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1991 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1992 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1993 | } |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 1994 | } else if (!strcmp(args[1], "refresh")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 1995 | unsigned interval; |
| 1996 | |
| 1997 | err = parse_time_err(args[2], &interval, TIME_UNIT_S); |
| 1998 | if (err) { |
| 1999 | Alert("parsing [%s:%d] : unexpected character '%c' in stats refresh interval.\n", |
| 2000 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2001 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2002 | goto out; |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 2003 | } else if (!stats_set_refresh(&curproxy->uri_auth, interval)) { |
| 2004 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2005 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2006 | goto out; |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 2007 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2008 | } else if (!strcmp(args[1], "auth")) { |
| 2009 | if (*(args[2]) == 0) { |
| 2010 | Alert("parsing [%s:%d] : 'auth' needs a user:password account.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2011 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2012 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2013 | } else if (!stats_add_auth(&curproxy->uri_auth, args[2])) { |
| 2014 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2015 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2016 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2017 | } |
| 2018 | } else if (!strcmp(args[1], "scope")) { |
| 2019 | if (*(args[2]) == 0) { |
| 2020 | Alert("parsing [%s:%d] : 'scope' needs a proxy name.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2021 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2022 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2023 | } else if (!stats_add_scope(&curproxy->uri_auth, args[2])) { |
| 2024 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2025 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2026 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2027 | } |
| 2028 | } else if (!strcmp(args[1], "enable")) { |
| 2029 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 2030 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2031 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2032 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2033 | } |
Krzysztof Oledzki | d9db927 | 2007-10-15 10:05:11 +0200 | [diff] [blame] | 2034 | } else if (!strcmp(args[1], "hide-version")) { |
| 2035 | if (!stats_set_flag(&curproxy->uri_auth, ST_HIDEVER)) { |
| 2036 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2037 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2038 | goto out; |
Krzysztof Oledzki | d9db927 | 2007-10-15 10:05:11 +0200 | [diff] [blame] | 2039 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 2040 | } else if (!strcmp(args[1], "show-node")) { |
| 2041 | |
| 2042 | if (*args[2]) { |
| 2043 | int i; |
| 2044 | char c; |
| 2045 | |
| 2046 | for (i=0; args[2][i]; i++) { |
| 2047 | c = args[2][i]; |
Krzysztof Piotr Oledzki | 619caca | 2009-10-03 15:46:08 +0200 | [diff] [blame] | 2048 | if (!isupper(c) && !islower(c) && !isdigit(c) && c != '_' && c != '-' && c != '.') |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 2049 | break; |
| 2050 | } |
| 2051 | |
| 2052 | if (!i || args[2][i]) { |
| 2053 | Alert("parsing [%s:%d]: '%s %s' invalid node name - should be a string" |
| 2054 | "with digits(0-9), letters(A-Z, a-z), hyphen(-) or underscode(_).\n", |
| 2055 | file, linenum, args[0], args[1]); |
| 2056 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2057 | goto out; |
| 2058 | } |
| 2059 | } |
| 2060 | |
| 2061 | if (!stats_set_node(&curproxy->uri_auth, args[2])) { |
| 2062 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 2063 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2064 | goto out; |
| 2065 | } |
| 2066 | } else if (!strcmp(args[1], "show-desc")) { |
| 2067 | char *desc = NULL; |
| 2068 | |
| 2069 | if (*args[2]) { |
| 2070 | int i, len=0; |
| 2071 | char *d; |
| 2072 | |
| 2073 | for(i=2; *args[i]; i++) |
| 2074 | len += strlen(args[i])+1; |
| 2075 | |
| 2076 | desc = d = (char *)calloc(1, len); |
| 2077 | |
| 2078 | d += sprintf(d, "%s", args[2]); |
| 2079 | for(i=3; *args[i]; i++) |
| 2080 | d += sprintf(d, " %s", args[i]); |
| 2081 | } |
| 2082 | |
| 2083 | if (!*args[2] && !global.desc) |
| 2084 | Warning("parsing [%s:%d]: '%s' requires a parameter or 'desc' to be set in the global section.\n", |
| 2085 | file, linenum, args[1]); |
| 2086 | else { |
| 2087 | if (!stats_set_desc(&curproxy->uri_auth, desc)) { |
| 2088 | free(desc); |
| 2089 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 2090 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2091 | goto out; |
| 2092 | } |
| 2093 | free(desc); |
| 2094 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2095 | } else { |
Krzysztof Oledzki | d9db927 | 2007-10-15 10:05:11 +0200 | [diff] [blame] | 2096 | Alert("parsing [%s:%d] : unknown stats parameter '%s' (expects 'hide-version', 'uri', 'realm', 'auth' or 'enable').\n", |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2097 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2098 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2099 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2100 | } |
| 2101 | } |
| 2102 | else if (!strcmp(args[0], "option")) { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 2103 | int optnum; |
| 2104 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 2105 | if (*(args[1]) == '\0') { |
| 2106 | Alert("parsing [%s:%d]: '%s' expects an option name.\n", |
| 2107 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2108 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2109 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2110 | } |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 2111 | |
| 2112 | for (optnum = 0; cfg_opts[optnum].name; optnum++) { |
| 2113 | if (!strcmp(args[1], cfg_opts[optnum].name)) { |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2114 | if (warnifnotcap(curproxy, cfg_opts[optnum].cap, file, linenum, args[1], NULL)) { |
| 2115 | err_code |= ERR_WARN; |
| 2116 | goto out; |
| 2117 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 2118 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 2119 | curproxy->no_options &= ~cfg_opts[optnum].val; |
| 2120 | curproxy->options &= ~cfg_opts[optnum].val; |
| 2121 | |
| 2122 | switch (kwm) { |
| 2123 | case KWM_STD: |
| 2124 | curproxy->options |= cfg_opts[optnum].val; |
| 2125 | break; |
| 2126 | case KWM_NO: |
| 2127 | curproxy->no_options |= cfg_opts[optnum].val; |
| 2128 | break; |
| 2129 | case KWM_DEF: /* already cleared */ |
| 2130 | break; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 2131 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 2132 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2133 | goto out; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 2134 | } |
| 2135 | } |
| 2136 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 2137 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) { |
| 2138 | if (!strcmp(args[1], cfg_opts2[optnum].name)) { |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2139 | if (warnifnotcap(curproxy, cfg_opts2[optnum].cap, file, linenum, args[1], NULL)) { |
| 2140 | err_code |= ERR_WARN; |
| 2141 | goto out; |
| 2142 | } |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 2143 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 2144 | curproxy->no_options2 &= ~cfg_opts2[optnum].val; |
| 2145 | curproxy->options2 &= ~cfg_opts2[optnum].val; |
| 2146 | |
| 2147 | switch (kwm) { |
| 2148 | case KWM_STD: |
| 2149 | curproxy->options2 |= cfg_opts2[optnum].val; |
| 2150 | break; |
| 2151 | case KWM_NO: |
| 2152 | curproxy->no_options2 |= cfg_opts2[optnum].val; |
| 2153 | break; |
| 2154 | case KWM_DEF: /* already cleared */ |
| 2155 | break; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 2156 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2157 | goto out; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 2158 | } |
| 2159 | } |
| 2160 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 2161 | if (kwm != KWM_STD) { |
| 2162 | Alert("parsing [%s:%d]: negation/default is not supported for option '%s'.\n", |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 2163 | file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2164 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2165 | goto out; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 2166 | } |
| 2167 | |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 2168 | if (!strcmp(args[1], "httplog")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2169 | /* generate a complete HTTP log */ |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 2170 | curproxy->options2 &= ~PR_O2_CLFLOG; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2171 | curproxy->to_log |= LW_DATE | LW_CLIP | LW_SVID | LW_REQ | LW_PXID | LW_RESP | LW_BYTES; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 2172 | if (*(args[2]) != '\0') { |
| 2173 | if (!strcmp(args[2], "clf")) { |
| 2174 | curproxy->options2 |= PR_O2_CLFLOG; |
| 2175 | } else { |
| 2176 | Alert("parsing [%s:%d] : keyword '%s' only supports option 'clf'.\n", file, linenum, args[2]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2177 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2178 | goto out; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 2179 | } |
| 2180 | } |
| 2181 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2182 | else if (!strcmp(args[1], "tcplog")) |
| 2183 | /* generate a detailed TCP log */ |
| 2184 | curproxy->to_log |= LW_DATE | LW_CLIP | LW_SVID | LW_PXID | LW_BYTES; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2185 | else if (!strcmp(args[1], "tcpka")) { |
| 2186 | /* enable TCP keep-alives on client and server sessions */ |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 2187 | if (warnifnotcap(curproxy, PR_CAP_BE | PR_CAP_FE, file, linenum, args[1], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2188 | err_code |= ERR_WARN; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 2189 | |
| 2190 | if (curproxy->cap & PR_CAP_FE) |
| 2191 | curproxy->options |= PR_O_TCP_CLI_KA; |
| 2192 | if (curproxy->cap & PR_CAP_BE) |
| 2193 | curproxy->options |= PR_O_TCP_SRV_KA; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2194 | } |
| 2195 | else if (!strcmp(args[1], "httpchk")) { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 2196 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2197 | err_code |= ERR_WARN; |
| 2198 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2199 | /* use HTTP request to check servers' health */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2200 | free(curproxy->check_req); |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 2201 | curproxy->options &= ~PR_O_SSL3_CHK; |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 2202 | curproxy->options &= ~PR_O_SMTP_CHK; |
| 2203 | curproxy->options |= PR_O_HTTP_CHK; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2204 | if (!*args[2]) { /* no argument */ |
| 2205 | curproxy->check_req = strdup(DEF_CHECK_REQ); /* default request */ |
| 2206 | curproxy->check_len = strlen(DEF_CHECK_REQ); |
| 2207 | } else if (!*args[3]) { /* one argument : URI */ |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 2208 | int reqlen = strlen(args[2]) + strlen("OPTIONS HTTP/1.0\r\n\r\n") + 1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2209 | curproxy->check_req = (char *)malloc(reqlen); |
| 2210 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
| 2211 | "OPTIONS %s HTTP/1.0\r\n\r\n", args[2]); /* URI to use */ |
| 2212 | } else { /* more arguments : METHOD URI [HTTP_VER] */ |
| 2213 | int reqlen = strlen(args[2]) + strlen(args[3]) + 3 + strlen("\r\n\r\n"); |
| 2214 | if (*args[4]) |
| 2215 | reqlen += strlen(args[4]); |
| 2216 | else |
| 2217 | reqlen += strlen("HTTP/1.0"); |
| 2218 | |
| 2219 | curproxy->check_req = (char *)malloc(reqlen); |
| 2220 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
| 2221 | "%s %s %s\r\n\r\n", args[2], args[3], *args[4]?args[4]:"HTTP/1.0"); |
| 2222 | } |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 2223 | } |
| 2224 | else if (!strcmp(args[1], "ssl-hello-chk")) { |
| 2225 | /* use SSLv3 CLIENT HELLO to check servers' health */ |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 2226 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2227 | err_code |= ERR_WARN; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 2228 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2229 | free(curproxy->check_req); |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 2230 | curproxy->options &= ~PR_O_HTTP_CHK; |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 2231 | curproxy->options &= ~PR_O_SMTP_CHK; |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 2232 | curproxy->options |= PR_O_SSL3_CHK; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2233 | } |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 2234 | else if (!strcmp(args[1], "smtpchk")) { |
| 2235 | /* use SMTP request to check servers' health */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2236 | free(curproxy->check_req); |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 2237 | curproxy->options &= ~PR_O_HTTP_CHK; |
| 2238 | curproxy->options &= ~PR_O_SSL3_CHK; |
| 2239 | curproxy->options |= PR_O_SMTP_CHK; |
| 2240 | |
| 2241 | if (!*args[2] || !*args[3]) { /* no argument or incomplete EHLO host */ |
| 2242 | curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */ |
| 2243 | curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ); |
| 2244 | } else { /* ESMTP EHLO, or SMTP HELO, and a hostname */ |
| 2245 | if (!strcmp(args[2], "EHLO") || !strcmp(args[2], "HELO")) { |
| 2246 | int reqlen = strlen(args[2]) + strlen(args[3]) + strlen(" \r\n") + 1; |
| 2247 | curproxy->check_req = (char *)malloc(reqlen); |
| 2248 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
| 2249 | "%s %s\r\n", args[2], args[3]); /* HELO hostname */ |
| 2250 | } else { |
| 2251 | /* this just hits the default for now, but you could potentially expand it to allow for other stuff |
| 2252 | though, it's unlikely you'd want to send anything other than an EHLO or HELO */ |
| 2253 | curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */ |
| 2254 | curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ); |
| 2255 | } |
| 2256 | } |
| 2257 | } |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 2258 | else if (!strcmp(args[1], "forwardfor")) { |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 2259 | int cur_arg; |
| 2260 | |
| 2261 | /* insert x-forwarded-for field, but not for the IP address listed as an except. |
| 2262 | * set default options (ie: bitfield, header name, etc) |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 2263 | */ |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 2264 | |
| 2265 | curproxy->options |= PR_O_FWDFOR; |
| 2266 | |
| 2267 | free(curproxy->fwdfor_hdr_name); |
| 2268 | curproxy->fwdfor_hdr_name = strdup(DEF_XFORWARDFOR_HDR); |
| 2269 | curproxy->fwdfor_hdr_len = strlen(DEF_XFORWARDFOR_HDR); |
| 2270 | |
| 2271 | /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */ |
| 2272 | cur_arg = 2; |
| 2273 | while (*(args[cur_arg])) { |
| 2274 | if (!strcmp(args[cur_arg], "except")) { |
| 2275 | /* suboption except - needs additional argument for it */ |
| 2276 | if (!*(args[cur_arg+1]) || !str2net(args[cur_arg+1], &curproxy->except_net, &curproxy->except_mask)) { |
| 2277 | Alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n", |
| 2278 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2279 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2280 | goto out; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 2281 | } |
| 2282 | /* flush useless bits */ |
| 2283 | curproxy->except_net.s_addr &= curproxy->except_mask.s_addr; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 2284 | cur_arg += 2; |
| 2285 | } else if (!strcmp(args[cur_arg], "header")) { |
| 2286 | /* suboption header - needs additional argument for it */ |
| 2287 | if (*(args[cur_arg+1]) == 0) { |
| 2288 | Alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 2289 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2290 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2291 | goto out; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 2292 | } |
| 2293 | free(curproxy->fwdfor_hdr_name); |
| 2294 | curproxy->fwdfor_hdr_name = strdup(args[cur_arg+1]); |
| 2295 | curproxy->fwdfor_hdr_len = strlen(curproxy->fwdfor_hdr_name); |
| 2296 | cur_arg += 2; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 2297 | } else { |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 2298 | /* unknown suboption - catchall */ |
| 2299 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n", |
| 2300 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2301 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2302 | goto out; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 2303 | } |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 2304 | } /* end while loop */ |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 2305 | } |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 2306 | else if (!strcmp(args[1], "originalto")) { |
| 2307 | int cur_arg; |
| 2308 | |
| 2309 | /* insert x-original-to field, but not for the IP address listed as an except. |
| 2310 | * set default options (ie: bitfield, header name, etc) |
| 2311 | */ |
| 2312 | |
| 2313 | curproxy->options |= PR_O_ORGTO; |
| 2314 | |
| 2315 | free(curproxy->orgto_hdr_name); |
| 2316 | curproxy->orgto_hdr_name = strdup(DEF_XORIGINALTO_HDR); |
| 2317 | curproxy->orgto_hdr_len = strlen(DEF_XORIGINALTO_HDR); |
| 2318 | |
| 2319 | /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */ |
| 2320 | cur_arg = 2; |
| 2321 | while (*(args[cur_arg])) { |
| 2322 | if (!strcmp(args[cur_arg], "except")) { |
| 2323 | /* suboption except - needs additional argument for it */ |
| 2324 | if (!*(args[cur_arg+1]) || !str2net(args[cur_arg+1], &curproxy->except_to, &curproxy->except_mask_to)) { |
| 2325 | Alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n", |
| 2326 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2327 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2328 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 2329 | } |
| 2330 | /* flush useless bits */ |
| 2331 | curproxy->except_to.s_addr &= curproxy->except_mask_to.s_addr; |
| 2332 | cur_arg += 2; |
| 2333 | } else if (!strcmp(args[cur_arg], "header")) { |
| 2334 | /* suboption header - needs additional argument for it */ |
| 2335 | if (*(args[cur_arg+1]) == 0) { |
| 2336 | Alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 2337 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2338 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2339 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 2340 | } |
| 2341 | free(curproxy->orgto_hdr_name); |
| 2342 | curproxy->orgto_hdr_name = strdup(args[cur_arg+1]); |
| 2343 | curproxy->orgto_hdr_len = strlen(curproxy->orgto_hdr_name); |
| 2344 | cur_arg += 2; |
| 2345 | } else { |
| 2346 | /* unknown suboption - catchall */ |
| 2347 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n", |
| 2348 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2349 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2350 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 2351 | } |
| 2352 | } /* end while loop */ |
| 2353 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2354 | else { |
| 2355 | Alert("parsing [%s:%d] : unknown option '%s'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2356 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2357 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2358 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2359 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2360 | } |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 2361 | else if (!strcmp(args[0], "default_backend")) { |
| 2362 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2363 | err_code |= ERR_WARN; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 2364 | |
| 2365 | if (*(args[1]) == 0) { |
| 2366 | Alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2367 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2368 | goto out; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 2369 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2370 | free(curproxy->defbe.name); |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 2371 | curproxy->defbe.name = strdup(args[1]); |
| 2372 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2373 | else if (!strcmp(args[0], "redispatch") || !strcmp(args[0], "redisp")) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2374 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2375 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2376 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 2377 | Warning("parsing [%s:%d]: keyword '%s' is deprecated, please use 'option redispatch' instead.\n", |
| 2378 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2379 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2380 | /* enable reconnections to dispatch */ |
| 2381 | curproxy->options |= PR_O_REDISP; |
| 2382 | } |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 2383 | else if (!strcmp(args[0], "http-check")) { |
| 2384 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2385 | err_code |= ERR_WARN; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 2386 | |
| 2387 | if (strcmp(args[1], "disable-on-404") == 0) { |
| 2388 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 2389 | curproxy->options |= PR_O_DISABLE404; |
| 2390 | } |
| 2391 | else { |
| 2392 | Alert("parsing [%s:%d] : '%s' only supports 'disable-on-404'.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2393 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2394 | goto out; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 2395 | } |
| 2396 | } |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 2397 | else if (!strcmp(args[0], "monitor")) { |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2398 | if (curproxy == &defproxy) { |
| 2399 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2400 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2401 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2402 | } |
| 2403 | |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 2404 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2405 | err_code |= ERR_WARN; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 2406 | |
| 2407 | if (strcmp(args[1], "fail") == 0) { |
| 2408 | /* add a condition to fail monitor requests */ |
| 2409 | int pol = ACL_COND_NONE; |
| 2410 | struct acl_cond *cond; |
| 2411 | |
| 2412 | if (!strcmp(args[2], "if")) |
| 2413 | pol = ACL_COND_IF; |
| 2414 | else if (!strcmp(args[2], "unless")) |
| 2415 | pol = ACL_COND_UNLESS; |
| 2416 | |
| 2417 | if (pol == ACL_COND_NONE) { |
| 2418 | Alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n", |
| 2419 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2420 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2421 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 2422 | } |
| 2423 | |
| 2424 | if ((cond = parse_acl_cond((const char **)args + 3, &curproxy->acl, pol)) == NULL) { |
| 2425 | Alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition.\n", |
| 2426 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2427 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2428 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 2429 | } |
Willy Tarreau | 8892235 | 2009-10-04 22:02:50 +0200 | [diff] [blame] | 2430 | cond->file = file; |
Willy Tarreau | a980263 | 2008-07-25 19:13:19 +0200 | [diff] [blame] | 2431 | cond->line = linenum; |
Willy Tarreau | a9fb083 | 2009-07-10 20:53:53 +0200 | [diff] [blame] | 2432 | curproxy->acl_requires |= cond->requires; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 2433 | LIST_ADDQ(&curproxy->mon_fail_cond, &cond->list); |
| 2434 | } |
| 2435 | else { |
| 2436 | Alert("parsing [%s:%d] : '%s' only supports 'fail'.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2437 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2438 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 2439 | } |
| 2440 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2441 | #ifdef TPROXY |
| 2442 | else if (!strcmp(args[0], "transparent")) { |
| 2443 | /* enable transparent proxy connections */ |
| 2444 | curproxy->options |= PR_O_TRANSP; |
| 2445 | } |
| 2446 | #endif |
| 2447 | else if (!strcmp(args[0], "maxconn")) { /* maxconn */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2448 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], " Maybe you want 'fullconn' instead ?")) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2449 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2450 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2451 | if (*(args[1]) == 0) { |
| 2452 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2453 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2454 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2455 | } |
| 2456 | curproxy->maxconn = atol(args[1]); |
| 2457 | } |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 2458 | else if (!strcmp(args[0], "backlog")) { /* backlog */ |
| 2459 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2460 | err_code |= ERR_WARN; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 2461 | |
| 2462 | if (*(args[1]) == 0) { |
| 2463 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2464 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2465 | goto out; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 2466 | } |
| 2467 | curproxy->backlog = atol(args[1]); |
| 2468 | } |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 2469 | else if (!strcmp(args[0], "fullconn")) { /* fullconn */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2470 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], " Maybe you want 'maxconn' instead ?")) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2471 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2472 | |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 2473 | if (*(args[1]) == 0) { |
| 2474 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2475 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2476 | goto out; |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 2477 | } |
| 2478 | curproxy->fullconn = atol(args[1]); |
| 2479 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2480 | else if (!strcmp(args[0], "grace")) { /* grace time (ms) */ |
| 2481 | if (*(args[1]) == 0) { |
| 2482 | Alert("parsing [%s:%d] : '%s' expects a time in milliseconds.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2483 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2484 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2485 | } |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 2486 | err = parse_time_err(args[1], &val, TIME_UNIT_MS); |
| 2487 | if (err) { |
| 2488 | Alert("parsing [%s:%d] : unexpected character '%c' in grace time.\n", |
| 2489 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2490 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2491 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 2492 | } |
| 2493 | curproxy->grace = val; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2494 | } |
| 2495 | else if (!strcmp(args[0], "dispatch")) { /* dispatch address */ |
| 2496 | if (curproxy == &defproxy) { |
| 2497 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2498 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2499 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2500 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2501 | else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2502 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2503 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2504 | if (strchr(args[1], ':') == NULL) { |
| 2505 | Alert("parsing [%s:%d] : '%s' expects <addr:port> as argument.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2506 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2507 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2508 | } |
| 2509 | curproxy->dispatch_addr = *str2sa(args[1]); |
| 2510 | } |
| 2511 | else if (!strcmp(args[0], "balance")) { /* set balancing with optional algorithm */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2512 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2513 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2514 | |
Jeffrey 'jf' Lim | 65cb2f1 | 2008-10-04 18:07:00 +0200 | [diff] [blame] | 2515 | memcpy(trash, "error near 'balance'", 21); |
Willy Tarreau | a0cbda6 | 2007-11-01 21:39:54 +0100 | [diff] [blame] | 2516 | if (backend_parse_balance((const char **)args + 1, trash, sizeof(trash), curproxy) < 0) { |
| 2517 | Alert("parsing [%s:%d] : %s\n", file, linenum, trash); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2518 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2519 | goto out; |
Willy Tarreau | 2fcb500 | 2007-05-08 13:35:26 +0200 | [diff] [blame] | 2520 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2521 | } |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 2522 | else if (!strcmp(args[0], "hash-type")) { /* set hashing method */ |
| 2523 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 2524 | err_code |= ERR_WARN; |
| 2525 | |
| 2526 | if (strcmp(args[1], "consistent") == 0) { /* use consistent hashing */ |
| 2527 | curproxy->lbprm.algo &= ~BE_LB_HASH_TYPE; |
| 2528 | curproxy->lbprm.algo |= BE_LB_HASH_CONS; |
| 2529 | } |
| 2530 | else if (strcmp(args[1], "map-based") == 0) { /* use map-based hashing */ |
| 2531 | curproxy->lbprm.algo &= ~BE_LB_HASH_TYPE; |
| 2532 | curproxy->lbprm.algo |= BE_LB_HASH_MAP; |
| 2533 | } |
| 2534 | else { |
| 2535 | Alert("parsing [%s:%d] : '%s' only supports 'consistent' and 'map-based'.\n", file, linenum, args[0]); |
| 2536 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2537 | goto out; |
| 2538 | } |
| 2539 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2540 | else if (!strcmp(args[0], "server")) { /* server address */ |
| 2541 | int cur_arg; |
| 2542 | char *rport; |
| 2543 | char *raddr; |
| 2544 | short realport; |
| 2545 | int do_check; |
| 2546 | |
| 2547 | if (curproxy == &defproxy) { |
| 2548 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2549 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2550 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2551 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2552 | else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2553 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2554 | |
| 2555 | if (!*args[2]) { |
| 2556 | Alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n", |
| 2557 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2558 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2559 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2560 | } |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 2561 | |
| 2562 | err = invalid_char(args[1]); |
| 2563 | if (err) { |
| 2564 | Alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n", |
| 2565 | file, linenum, *err, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2566 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2567 | goto out; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 2568 | } |
| 2569 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2570 | if ((newsrv = (struct server *)calloc(1, sizeof(struct server))) == NULL) { |
| 2571 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2572 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2573 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2574 | } |
| 2575 | |
| 2576 | /* the servers are linked backwards first */ |
| 2577 | newsrv->next = curproxy->srv; |
| 2578 | curproxy->srv = newsrv; |
| 2579 | newsrv->proxy = curproxy; |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 2580 | newsrv->conf.file = file; |
| 2581 | newsrv->conf.line = linenum; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2582 | |
| 2583 | LIST_INIT(&newsrv->pendconns); |
| 2584 | do_check = 0; |
| 2585 | newsrv->state = SRV_RUNNING; /* early server setup */ |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 2586 | newsrv->last_change = now.tv_sec; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2587 | newsrv->id = strdup(args[1]); |
| 2588 | |
| 2589 | /* several ways to check the port component : |
| 2590 | * - IP => port=+0, relative |
| 2591 | * - IP: => port=+0, relative |
| 2592 | * - IP:N => port=N, absolute |
| 2593 | * - IP:+N => port=+N, relative |
| 2594 | * - IP:-N => port=-N, relative |
| 2595 | */ |
| 2596 | raddr = strdup(args[2]); |
| 2597 | rport = strchr(raddr, ':'); |
| 2598 | if (rport) { |
| 2599 | *rport++ = 0; |
| 2600 | realport = atol(rport); |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 2601 | if (!isdigit((unsigned char)*rport)) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2602 | newsrv->state |= SRV_MAPPORTS; |
| 2603 | } else { |
| 2604 | realport = 0; |
| 2605 | newsrv->state |= SRV_MAPPORTS; |
| 2606 | } |
| 2607 | |
| 2608 | newsrv->addr = *str2sa(raddr); |
| 2609 | newsrv->addr.sin_port = htons(realport); |
| 2610 | free(raddr); |
| 2611 | |
| 2612 | newsrv->curfd = -1; /* no health-check in progress */ |
| 2613 | newsrv->inter = DEF_CHKINTR; |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 2614 | newsrv->fastinter = 0; /* 0 => use newsrv->inter instead */ |
| 2615 | newsrv->downinter = 0; /* 0 => use newsrv->inter instead */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2616 | newsrv->rise = DEF_RISETIME; |
| 2617 | newsrv->fall = DEF_FALLTIME; |
| 2618 | newsrv->health = newsrv->rise; /* up, but will fall down at first failure */ |
Willy Tarreau | 975c50b | 2009-10-10 19:34:06 +0200 | [diff] [blame] | 2619 | newsrv->uweight = newsrv->iweight = 1; |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 2620 | newsrv->maxqueue = 0; |
Willy Tarreau | 9909fc1 | 2007-11-30 17:42:05 +0100 | [diff] [blame] | 2621 | newsrv->slowstart = 0; |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 2622 | newsrv->onerror = DEF_HANA_ONERR; |
| 2623 | newsrv->consecutive_errors_limit = DEF_HANA_ERRLIMIT; |
Willy Tarreau | 0f03c6f | 2007-03-25 20:46:19 +0200 | [diff] [blame] | 2624 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2625 | cur_arg = 3; |
| 2626 | while (*args[cur_arg]) { |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2627 | if (!strcmp(args[cur_arg], "id")) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2628 | struct eb32_node *node; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2629 | |
| 2630 | if (!*args[cur_arg + 1]) { |
| 2631 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 2632 | file, linenum, args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2633 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2634 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2635 | } |
| 2636 | |
| 2637 | newsrv->puid = atol(args[cur_arg + 1]); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2638 | newsrv->conf.id.key = newsrv->puid; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2639 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2640 | if (newsrv->puid <= 0) { |
| 2641 | Alert("parsing [%s:%d]: custom id has to be > 0.\n", |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2642 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2643 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2644 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2645 | } |
| 2646 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2647 | node = eb32_lookup(&curproxy->conf.used_server_id, newsrv->puid); |
| 2648 | if (node) { |
| 2649 | struct server *target = container_of(node, struct server, conf.id); |
| 2650 | Alert("parsing [%s:%d]: server %s reuses same custom id as server %s (declared at %s:%d).\n", |
| 2651 | file, linenum, newsrv->id, target->id, target->conf.file, target->conf.line); |
| 2652 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2653 | goto out; |
| 2654 | } |
| 2655 | eb32_insert(&curproxy->conf.used_server_id, &newsrv->conf.id); |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2656 | cur_arg += 2; |
| 2657 | } |
| 2658 | else if (!strcmp(args[cur_arg], "cookie")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2659 | newsrv->cookie = strdup(args[cur_arg + 1]); |
| 2660 | newsrv->cklen = strlen(args[cur_arg + 1]); |
| 2661 | cur_arg += 2; |
| 2662 | } |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 2663 | else if (!strcmp(args[cur_arg], "redir")) { |
| 2664 | newsrv->rdr_pfx = strdup(args[cur_arg + 1]); |
| 2665 | newsrv->rdr_len = strlen(args[cur_arg + 1]); |
| 2666 | cur_arg += 2; |
| 2667 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2668 | else if (!strcmp(args[cur_arg], "rise")) { |
Krzysztof Piotr Oledzki | 08ff959 | 2009-09-27 16:17:31 +0200 | [diff] [blame] | 2669 | if (!*args[cur_arg + 1]) { |
| 2670 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 2671 | file, linenum, args[cur_arg]); |
| 2672 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2673 | goto out; |
| 2674 | } |
| 2675 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2676 | newsrv->rise = atol(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 08ff959 | 2009-09-27 16:17:31 +0200 | [diff] [blame] | 2677 | if (newsrv->rise <= 0) { |
| 2678 | Alert("parsing [%s:%d]: '%s' has to be > 0.\n", |
| 2679 | file, linenum, args[cur_arg]); |
| 2680 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2681 | goto out; |
| 2682 | } |
| 2683 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2684 | newsrv->health = newsrv->rise; |
| 2685 | cur_arg += 2; |
| 2686 | } |
| 2687 | else if (!strcmp(args[cur_arg], "fall")) { |
| 2688 | newsrv->fall = atol(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 08ff959 | 2009-09-27 16:17:31 +0200 | [diff] [blame] | 2689 | |
| 2690 | if (!*args[cur_arg + 1]) { |
| 2691 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 2692 | file, linenum, args[cur_arg]); |
| 2693 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2694 | goto out; |
| 2695 | } |
| 2696 | |
| 2697 | if (newsrv->fall <= 0) { |
| 2698 | Alert("parsing [%s:%d]: '%s' has to be > 0.\n", |
| 2699 | file, linenum, args[cur_arg]); |
| 2700 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2701 | goto out; |
| 2702 | } |
| 2703 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2704 | cur_arg += 2; |
| 2705 | } |
| 2706 | else if (!strcmp(args[cur_arg], "inter")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 2707 | const char *err = parse_time_err(args[cur_arg + 1], &val, TIME_UNIT_MS); |
| 2708 | if (err) { |
| 2709 | Alert("parsing [%s:%d] : unexpected character '%c' in 'inter' argument of server %s.\n", |
| 2710 | file, linenum, *err, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2711 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2712 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 2713 | } |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 2714 | if (val <= 0) { |
| 2715 | Alert("parsing [%s:%d]: invalid value %d for argument '%s' of server %s.\n", |
| 2716 | file, linenum, val, args[cur_arg], newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2717 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2718 | goto out; |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 2719 | } |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 2720 | newsrv->inter = val; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2721 | cur_arg += 2; |
| 2722 | } |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 2723 | else if (!strcmp(args[cur_arg], "fastinter")) { |
| 2724 | const char *err = parse_time_err(args[cur_arg + 1], &val, TIME_UNIT_MS); |
| 2725 | if (err) { |
| 2726 | Alert("parsing [%s:%d]: unexpected character '%c' in 'fastinter' argument of server %s.\n", |
| 2727 | file, linenum, *err, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2728 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2729 | goto out; |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 2730 | } |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 2731 | if (val <= 0) { |
| 2732 | Alert("parsing [%s:%d]: invalid value %d for argument '%s' of server %s.\n", |
| 2733 | file, linenum, val, args[cur_arg], newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2734 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2735 | goto out; |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 2736 | } |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 2737 | newsrv->fastinter = val; |
| 2738 | cur_arg += 2; |
| 2739 | } |
| 2740 | else if (!strcmp(args[cur_arg], "downinter")) { |
| 2741 | const char *err = parse_time_err(args[cur_arg + 1], &val, TIME_UNIT_MS); |
| 2742 | if (err) { |
| 2743 | Alert("parsing [%s:%d]: unexpected character '%c' in 'downinter' argument of server %s.\n", |
| 2744 | file, linenum, *err, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2745 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2746 | goto out; |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 2747 | } |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 2748 | if (val <= 0) { |
| 2749 | Alert("parsing [%s:%d]: invalid value %d for argument '%s' of server %s.\n", |
| 2750 | file, linenum, val, args[cur_arg], newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2751 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2752 | goto out; |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 2753 | } |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 2754 | newsrv->downinter = val; |
| 2755 | cur_arg += 2; |
| 2756 | } |
Willy Tarreau | 2ea3abb | 2007-03-25 16:45:16 +0200 | [diff] [blame] | 2757 | else if (!strcmp(args[cur_arg], "addr")) { |
| 2758 | newsrv->check_addr = *str2sa(args[cur_arg + 1]); |
Willy Tarreau | 2ea3abb | 2007-03-25 16:45:16 +0200 | [diff] [blame] | 2759 | cur_arg += 2; |
| 2760 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2761 | else if (!strcmp(args[cur_arg], "port")) { |
| 2762 | newsrv->check_port = atol(args[cur_arg + 1]); |
| 2763 | cur_arg += 2; |
| 2764 | } |
| 2765 | else if (!strcmp(args[cur_arg], "backup")) { |
| 2766 | newsrv->state |= SRV_BACKUP; |
| 2767 | cur_arg ++; |
| 2768 | } |
| 2769 | else if (!strcmp(args[cur_arg], "weight")) { |
| 2770 | int w; |
| 2771 | w = atol(args[cur_arg + 1]); |
Willy Tarreau | 6704d67 | 2009-06-15 10:56:05 +0200 | [diff] [blame] | 2772 | if (w < 0 || w > 256) { |
| 2773 | Alert("parsing [%s:%d] : weight of server %s is not within 0 and 256 (%d).\n", |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2774 | file, linenum, newsrv->id, w); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2775 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2776 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2777 | } |
Willy Tarreau | 975c50b | 2009-10-10 19:34:06 +0200 | [diff] [blame] | 2778 | newsrv->uweight = newsrv->iweight = w; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2779 | cur_arg += 2; |
| 2780 | } |
| 2781 | else if (!strcmp(args[cur_arg], "minconn")) { |
| 2782 | newsrv->minconn = atol(args[cur_arg + 1]); |
| 2783 | cur_arg += 2; |
| 2784 | } |
| 2785 | else if (!strcmp(args[cur_arg], "maxconn")) { |
| 2786 | newsrv->maxconn = atol(args[cur_arg + 1]); |
| 2787 | cur_arg += 2; |
| 2788 | } |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 2789 | else if (!strcmp(args[cur_arg], "maxqueue")) { |
| 2790 | newsrv->maxqueue = atol(args[cur_arg + 1]); |
| 2791 | cur_arg += 2; |
| 2792 | } |
Willy Tarreau | 9909fc1 | 2007-11-30 17:42:05 +0100 | [diff] [blame] | 2793 | else if (!strcmp(args[cur_arg], "slowstart")) { |
| 2794 | /* slowstart is stored in seconds */ |
Willy Tarreau | 3259e33 | 2007-12-03 01:51:45 +0100 | [diff] [blame] | 2795 | const char *err = parse_time_err(args[cur_arg + 1], &val, TIME_UNIT_MS); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 2796 | if (err) { |
| 2797 | Alert("parsing [%s:%d] : unexpected character '%c' in 'slowstart' argument of server %s.\n", |
| 2798 | file, linenum, *err, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2799 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2800 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 2801 | } |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 2802 | if (val <= 0) { |
| 2803 | Alert("parsing [%s:%d]: invalid value %d for argument '%s' of server %s.\n", |
| 2804 | file, linenum, val, args[cur_arg], newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2805 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2806 | goto out; |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 2807 | } |
Willy Tarreau | 3259e33 | 2007-12-03 01:51:45 +0100 | [diff] [blame] | 2808 | newsrv->slowstart = (val + 999) / 1000; |
Willy Tarreau | 9909fc1 | 2007-11-30 17:42:05 +0100 | [diff] [blame] | 2809 | cur_arg += 2; |
| 2810 | } |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 2811 | else if (!strcmp(args[cur_arg], "track")) { |
| 2812 | |
| 2813 | if (!*args[cur_arg + 1]) { |
| 2814 | Alert("parsing [%s:%d]: 'track' expects [<proxy>/]<server> as argument.\n", |
| 2815 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2816 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2817 | goto out; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 2818 | } |
| 2819 | |
| 2820 | newsrv->trackit = strdup(args[cur_arg + 1]); |
| 2821 | |
| 2822 | cur_arg += 2; |
| 2823 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2824 | else if (!strcmp(args[cur_arg], "check")) { |
| 2825 | global.maxsock++; |
| 2826 | do_check = 1; |
| 2827 | cur_arg += 1; |
| 2828 | } |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 2829 | else if (!strcmp(args[cur_arg], "observe")) { |
| 2830 | if (!strcmp(args[cur_arg + 1], "none")) |
| 2831 | newsrv->observe = HANA_OBS_NONE; |
| 2832 | else if (!strcmp(args[cur_arg + 1], "layer4")) |
| 2833 | newsrv->observe = HANA_OBS_LAYER4; |
| 2834 | else if (!strcmp(args[cur_arg + 1], "layer7")) { |
| 2835 | if (curproxy->mode != PR_MODE_HTTP) { |
| 2836 | Alert("parsing [%s:%d]: '%s' can only be used in http proxies.\n", |
| 2837 | file, linenum, args[cur_arg + 1]); |
| 2838 | err_code |= ERR_ALERT; |
| 2839 | } |
| 2840 | newsrv->observe = HANA_OBS_LAYER7; |
| 2841 | } |
| 2842 | else { |
| 2843 | Alert("parsing [%s:%d]: '%s' expects one of 'none', " |
| 2844 | "'l4events', 'http-responses' but get '%s'\n", |
| 2845 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
| 2846 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2847 | goto out; |
| 2848 | } |
| 2849 | |
| 2850 | cur_arg += 2; |
| 2851 | } |
| 2852 | else if (!strcmp(args[cur_arg], "on-error")) { |
| 2853 | if (!strcmp(args[cur_arg + 1], "fastinter")) |
| 2854 | newsrv->onerror = HANA_ONERR_FASTINTER; |
| 2855 | else if (!strcmp(args[cur_arg + 1], "fail-check")) |
| 2856 | newsrv->onerror = HANA_ONERR_FAILCHK; |
| 2857 | else if (!strcmp(args[cur_arg + 1], "sudden-death")) |
| 2858 | newsrv->onerror = HANA_ONERR_SUDDTH; |
| 2859 | else if (!strcmp(args[cur_arg + 1], "mark-down")) |
| 2860 | newsrv->onerror = HANA_ONERR_MARKDWN; |
| 2861 | else { |
| 2862 | Alert("parsing [%s:%d]: '%s' expects one of 'fastinter', " |
| 2863 | "'fail-check', 'sudden-death' or 'mark-down' but get '%s'\n", |
| 2864 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
| 2865 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2866 | goto out; |
| 2867 | } |
| 2868 | |
| 2869 | cur_arg += 2; |
| 2870 | } |
| 2871 | else if (!strcmp(args[cur_arg], "error-limit")) { |
| 2872 | if (!*args[cur_arg + 1]) { |
| 2873 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 2874 | file, linenum, args[cur_arg]); |
| 2875 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2876 | goto out; |
| 2877 | } |
| 2878 | |
| 2879 | newsrv->consecutive_errors_limit = atoi(args[cur_arg + 1]); |
| 2880 | |
| 2881 | if (newsrv->consecutive_errors_limit <= 0) { |
| 2882 | Alert("parsing [%s:%d]: %s has to be > 0.\n", |
| 2883 | file, linenum, args[cur_arg]); |
| 2884 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2885 | goto out; |
| 2886 | } |
| 2887 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2888 | else if (!strcmp(args[cur_arg], "source")) { /* address to which we bind when connecting */ |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 2889 | int port_low, port_high; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2890 | if (!*args[cur_arg + 1]) { |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 2891 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 2892 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>[-<port>]], and optional '%s' <addr> as argument.\n", |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 2893 | file, linenum, "source", "usesrc"); |
| 2894 | #else |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 2895 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>[-<port>]] as argument.\n", |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2896 | file, linenum, "source"); |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 2897 | #endif |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2898 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2899 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2900 | } |
| 2901 | newsrv->state |= SRV_BIND_SRC; |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 2902 | newsrv->source_addr = *str2sa_range(args[cur_arg + 1], &port_low, &port_high); |
| 2903 | |
| 2904 | if (port_low != port_high) { |
| 2905 | int i; |
| 2906 | if (port_low <= 0 || port_low > 65535 || |
| 2907 | port_high <= 0 || port_high > 65535 || |
| 2908 | port_low > port_high) { |
| 2909 | Alert("parsing [%s:%d] : invalid source port range %d-%d.\n", |
| 2910 | file, linenum, port_low, port_high); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2911 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2912 | goto out; |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 2913 | } |
| 2914 | newsrv->sport_range = port_range_alloc_range(port_high - port_low + 1); |
| 2915 | for (i = 0; i < newsrv->sport_range->size; i++) |
| 2916 | newsrv->sport_range->ports[i] = port_low + i; |
| 2917 | } |
| 2918 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2919 | cur_arg += 2; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 2920 | while (*(args[cur_arg])) { |
| 2921 | if (!strcmp(args[cur_arg], "usesrc")) { /* address to use outside */ |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 2922 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) |
| 2923 | #if !defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 2924 | if (newsrv->source_addr.sin_addr.s_addr == INADDR_ANY) { |
| 2925 | Alert("parsing [%s:%d] : '%s' requires an explicit '%s' address.\n", |
| 2926 | file, linenum, "usesrc", "source"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2927 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2928 | goto out; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 2929 | } |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 2930 | #endif |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 2931 | if (!*args[cur_arg + 1]) { |
| 2932 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n", |
| 2933 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2934 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2935 | goto out; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 2936 | } |
| 2937 | if (!strcmp(args[cur_arg + 1], "client")) { |
| 2938 | newsrv->state |= SRV_TPROXY_CLI; |
| 2939 | } else if (!strcmp(args[cur_arg + 1], "clientip")) { |
| 2940 | newsrv->state |= SRV_TPROXY_CIP; |
| 2941 | } else { |
| 2942 | newsrv->state |= SRV_TPROXY_ADDR; |
| 2943 | newsrv->tproxy_addr = *str2sa(args[cur_arg + 1]); |
| 2944 | } |
| 2945 | global.last_checks |= LSTCHK_NETADM; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 2946 | #if !defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 2947 | global.last_checks |= LSTCHK_CTTPROXY; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 2948 | #endif |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 2949 | cur_arg += 2; |
| 2950 | continue; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 2951 | #else /* no TPROXY support */ |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 2952 | Alert("parsing [%s:%d] : '%s' not allowed here because support for TPROXY was not compiled in.\n", |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 2953 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2954 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2955 | goto out; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 2956 | #endif /* defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) */ |
| 2957 | } /* "usesrc" */ |
| 2958 | |
| 2959 | if (!strcmp(args[cur_arg], "interface")) { /* specifically bind to this interface */ |
| 2960 | #ifdef SO_BINDTODEVICE |
| 2961 | if (!*args[cur_arg + 1]) { |
| 2962 | Alert("parsing [%s:%d] : '%s' : missing interface name.\n", |
| 2963 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2964 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2965 | goto out; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 2966 | } |
| 2967 | if (newsrv->iface_name) |
| 2968 | free(newsrv->iface_name); |
| 2969 | |
| 2970 | newsrv->iface_name = strdup(args[cur_arg + 1]); |
| 2971 | newsrv->iface_len = strlen(newsrv->iface_name); |
| 2972 | global.last_checks |= LSTCHK_NETADM; |
| 2973 | #else |
| 2974 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 2975 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2976 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2977 | goto out; |
Willy Tarreau | 77074d5 | 2006-11-12 23:57:19 +0100 | [diff] [blame] | 2978 | #endif |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 2979 | cur_arg += 2; |
| 2980 | continue; |
| 2981 | } |
| 2982 | /* this keyword in not an option of "source" */ |
| 2983 | break; |
| 2984 | } /* while */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2985 | } |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 2986 | else if (!strcmp(args[cur_arg], "usesrc")) { /* address to use outside: needs "source" first */ |
| 2987 | Alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n", |
| 2988 | file, linenum, "usesrc", "source"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2989 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2990 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 2991 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2992 | else { |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2993 | Alert("parsing [%s:%d] : server %s only supports options 'backup', 'cookie', 'redir', 'check', 'track', 'id', 'inter', 'fastinter', 'downinter', 'rise', 'fall', 'addr', 'port', 'source', 'minconn', 'maxconn', 'maxqueue', 'slowstart' and 'weight'.\n", |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2994 | file, linenum, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2995 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2996 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2997 | } |
| 2998 | } |
| 2999 | |
| 3000 | if (do_check) { |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 3001 | if (newsrv->trackit) { |
| 3002 | Alert("parsing [%s:%d]: unable to enable checks and tracking at the same time!\n", |
| 3003 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3004 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3005 | goto out; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 3006 | } |
| 3007 | |
Willy Tarreau | 0f03c6f | 2007-03-25 20:46:19 +0200 | [diff] [blame] | 3008 | if (!newsrv->check_port && newsrv->check_addr.sin_port) |
| 3009 | newsrv->check_port = newsrv->check_addr.sin_port; |
| 3010 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3011 | if (!newsrv->check_port && !(newsrv->state & SRV_MAPPORTS)) |
| 3012 | newsrv->check_port = realport; /* by default */ |
| 3013 | if (!newsrv->check_port) { |
Willy Tarreau | ef00b50 | 2007-01-07 02:40:09 +0100 | [diff] [blame] | 3014 | /* not yet valid, because no port was set on |
| 3015 | * the server either. We'll check if we have |
| 3016 | * a known port on the first listener. |
| 3017 | */ |
| 3018 | struct listener *l; |
| 3019 | l = curproxy->listen; |
| 3020 | if (l) { |
| 3021 | int port; |
| 3022 | port = (l->addr.ss_family == AF_INET6) |
| 3023 | ? ntohs(((struct sockaddr_in6 *)(&l->addr))->sin6_port) |
| 3024 | : ntohs(((struct sockaddr_in *)(&l->addr))->sin_port); |
| 3025 | newsrv->check_port = port; |
| 3026 | } |
| 3027 | } |
| 3028 | if (!newsrv->check_port) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3029 | Alert("parsing [%s:%d] : server %s has neither service port nor check port. Check has been disabled.\n", |
| 3030 | file, linenum, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3031 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3032 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3033 | } |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 3034 | |
| 3035 | newsrv->check_status = HCHK_STATUS_INI; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3036 | newsrv->state |= SRV_CHECKED; |
| 3037 | } |
| 3038 | |
| 3039 | if (newsrv->state & SRV_BACKUP) |
| 3040 | curproxy->srv_bck++; |
| 3041 | else |
| 3042 | curproxy->srv_act++; |
Willy Tarreau | b625a08 | 2007-11-26 01:15:43 +0100 | [diff] [blame] | 3043 | |
| 3044 | newsrv->prev_state = newsrv->state; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3045 | } |
| 3046 | else if (!strcmp(args[0], "log")) { /* syslog server address */ |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 3047 | struct logsrv logsrv; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3048 | int facility; |
| 3049 | |
| 3050 | if (*(args[1]) && *(args[2]) == 0 && !strcmp(args[1], "global")) { |
| 3051 | curproxy->logfac1 = global.logfac1; |
| 3052 | curproxy->logsrv1 = global.logsrv1; |
| 3053 | curproxy->loglev1 = global.loglev1; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 3054 | curproxy->minlvl1 = global.minlvl1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3055 | curproxy->logfac2 = global.logfac2; |
| 3056 | curproxy->logsrv2 = global.logsrv2; |
| 3057 | curproxy->loglev2 = global.loglev2; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 3058 | curproxy->minlvl2 = global.minlvl2; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3059 | } |
| 3060 | else if (*(args[1]) && *(args[2])) { |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 3061 | int level, minlvl; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3062 | |
| 3063 | facility = get_log_facility(args[2]); |
| 3064 | if (facility < 0) { |
| 3065 | Alert("parsing [%s:%d] : unknown log facility '%s'\n", file, linenum, args[2]); |
| 3066 | exit(1); |
| 3067 | } |
| 3068 | |
| 3069 | level = 7; /* max syslog level = debug */ |
| 3070 | if (*(args[3])) { |
| 3071 | level = get_log_level(args[3]); |
| 3072 | if (level < 0) { |
| 3073 | Alert("parsing [%s:%d] : unknown optional log level '%s'\n", file, linenum, args[3]); |
| 3074 | exit(1); |
| 3075 | } |
| 3076 | } |
| 3077 | |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 3078 | minlvl = 0; /* limit syslog level to this level (emerg) */ |
| 3079 | if (*(args[4])) { |
| 3080 | minlvl = get_log_level(args[4]); |
| 3081 | if (level < 0) { |
| 3082 | Alert("parsing [%s:%d] : unknown optional minimum log level '%s'\n", file, linenum, args[4]); |
| 3083 | exit(1); |
| 3084 | } |
| 3085 | } |
| 3086 | |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 3087 | if (args[1][0] == '/') { |
| 3088 | logsrv.u.addr.sa_family = AF_UNIX; |
| 3089 | logsrv.u.un = *str2sun(args[1]); |
| 3090 | } else { |
| 3091 | logsrv.u.addr.sa_family = AF_INET; |
| 3092 | logsrv.u.in = *str2sa(args[1]); |
| 3093 | if (!logsrv.u.in.sin_port) { |
| 3094 | logsrv.u.in.sin_port = |
| 3095 | htons(SYSLOG_PORT); |
| 3096 | } |
| 3097 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3098 | |
| 3099 | if (curproxy->logfac1 == -1) { |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 3100 | curproxy->logsrv1 = logsrv; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3101 | curproxy->logfac1 = facility; |
| 3102 | curproxy->loglev1 = level; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 3103 | curproxy->minlvl1 = minlvl; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3104 | } |
| 3105 | else if (curproxy->logfac2 == -1) { |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 3106 | curproxy->logsrv2 = logsrv; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3107 | curproxy->logfac2 = facility; |
| 3108 | curproxy->loglev2 = level; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 3109 | curproxy->minlvl2 = minlvl; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3110 | } |
| 3111 | else { |
| 3112 | Alert("parsing [%s:%d] : too many syslog servers\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3113 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3114 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3115 | } |
| 3116 | } |
| 3117 | else { |
| 3118 | Alert("parsing [%s:%d] : 'log' expects either <address[:port]> and <facility> or 'global' as arguments.\n", |
| 3119 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3120 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3121 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3122 | } |
| 3123 | } |
| 3124 | else if (!strcmp(args[0], "source")) { /* address to which we bind when connecting */ |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 3125 | int cur_arg; |
| 3126 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3127 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3128 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3129 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3130 | if (!*args[1]) { |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 3131 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optionally '%s' <addr>, and '%s' <name>.\n", |
| 3132 | file, linenum, "source", "usesrc", "interface"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3133 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3134 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3135 | } |
Willy Tarreau | 368480c | 2009-03-01 08:27:21 +0100 | [diff] [blame] | 3136 | |
| 3137 | /* we must first clear any optional default setting */ |
| 3138 | curproxy->options &= ~PR_O_TPXY_MASK; |
| 3139 | free(curproxy->iface_name); |
| 3140 | curproxy->iface_name = NULL; |
| 3141 | curproxy->iface_len = 0; |
| 3142 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3143 | curproxy->source_addr = *str2sa(args[1]); |
| 3144 | curproxy->options |= PR_O_BIND_SRC; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 3145 | |
| 3146 | cur_arg = 2; |
| 3147 | while (*(args[cur_arg])) { |
| 3148 | if (!strcmp(args[cur_arg], "usesrc")) { /* address to use outside */ |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 3149 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) |
| 3150 | #if !defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 3151 | if (curproxy->source_addr.sin_addr.s_addr == INADDR_ANY) { |
| 3152 | Alert("parsing [%s:%d] : '%s' requires an explicit 'source' address.\n", |
| 3153 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3154 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3155 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 3156 | } |
| 3157 | #endif |
| 3158 | if (!*args[cur_arg + 1]) { |
| 3159 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n", |
| 3160 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3161 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3162 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 3163 | } |
| 3164 | |
| 3165 | if (!strcmp(args[cur_arg + 1], "client")) { |
| 3166 | curproxy->options |= PR_O_TPXY_CLI; |
| 3167 | } else if (!strcmp(args[cur_arg + 1], "clientip")) { |
| 3168 | curproxy->options |= PR_O_TPXY_CIP; |
| 3169 | } else { |
| 3170 | curproxy->options |= PR_O_TPXY_ADDR; |
| 3171 | curproxy->tproxy_addr = *str2sa(args[cur_arg + 1]); |
| 3172 | } |
| 3173 | global.last_checks |= LSTCHK_NETADM; |
| 3174 | #if !defined(CONFIG_HAP_LINUX_TPROXY) |
| 3175 | global.last_checks |= LSTCHK_CTTPROXY; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 3176 | #endif |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 3177 | #else /* no TPROXY support */ |
| 3178 | Alert("parsing [%s:%d] : '%s' not allowed here because support for TPROXY was not compiled in.\n", |
Willy Tarreau | 77074d5 | 2006-11-12 23:57:19 +0100 | [diff] [blame] | 3179 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3180 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3181 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 3182 | #endif |
| 3183 | cur_arg += 2; |
| 3184 | continue; |
Willy Tarreau | 77074d5 | 2006-11-12 23:57:19 +0100 | [diff] [blame] | 3185 | } |
| 3186 | |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 3187 | if (!strcmp(args[cur_arg], "interface")) { /* specifically bind to this interface */ |
| 3188 | #ifdef SO_BINDTODEVICE |
| 3189 | if (!*args[cur_arg + 1]) { |
| 3190 | Alert("parsing [%s:%d] : '%s' : missing interface name.\n", |
| 3191 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3192 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3193 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 3194 | } |
| 3195 | if (curproxy->iface_name) |
| 3196 | free(curproxy->iface_name); |
| 3197 | |
| 3198 | curproxy->iface_name = strdup(args[cur_arg + 1]); |
| 3199 | curproxy->iface_len = strlen(curproxy->iface_name); |
| 3200 | global.last_checks |= LSTCHK_NETADM; |
| 3201 | #else |
| 3202 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 3203 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3204 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3205 | goto out; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 3206 | #endif |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 3207 | cur_arg += 2; |
| 3208 | continue; |
| 3209 | } |
| 3210 | Alert("parsing [%s:%d] : '%s' only supports optional keywords '%s' and '%s'.\n", |
| 3211 | file, linenum, args[0], "inteface", "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3212 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3213 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 3214 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3215 | } |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 3216 | else if (!strcmp(args[0], "usesrc")) { /* address to use outside: needs "source" first */ |
| 3217 | Alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n", |
| 3218 | file, linenum, "usesrc", "source"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3219 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3220 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 3221 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3222 | else if (!strcmp(args[0], "cliexp") || !strcmp(args[0], "reqrep")) { /* replace request header from a regex */ |
| 3223 | regex_t *preg; |
| 3224 | if (curproxy == &defproxy) { |
| 3225 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3226 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3227 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3228 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3229 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3230 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3231 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3232 | if (*(args[1]) == 0 || *(args[2]) == 0) { |
| 3233 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 3234 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3235 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3236 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3237 | } |
| 3238 | |
| 3239 | preg = calloc(1, sizeof(regex_t)); |
| 3240 | if (regcomp(preg, args[1], REG_EXTENDED) != 0) { |
| 3241 | Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3242 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3243 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3244 | } |
| 3245 | |
| 3246 | err = chain_regex(&curproxy->req_exp, preg, ACT_REPLACE, strdup(args[2])); |
| 3247 | if (err) { |
| 3248 | Alert("parsing [%s:%d] : invalid character or unterminated sequence in replacement string near '%c'.\n", |
| 3249 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3250 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3251 | } |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 3252 | warnif_misplaced_reqxxx(curproxy, file, linenum, args[0]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3253 | } |
| 3254 | else if (!strcmp(args[0], "reqdel")) { /* delete request header from a regex */ |
| 3255 | regex_t *preg; |
| 3256 | if (curproxy == &defproxy) { |
| 3257 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3258 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3259 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3260 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3261 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3262 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3263 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3264 | if (*(args[1]) == 0) { |
| 3265 | Alert("parsing [%s:%d] : '%s' expects <regex> as an argument.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3266 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3267 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3268 | } |
| 3269 | |
| 3270 | preg = calloc(1, sizeof(regex_t)); |
| 3271 | if (regcomp(preg, args[1], REG_EXTENDED) != 0) { |
| 3272 | Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3273 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3274 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3275 | } |
| 3276 | |
| 3277 | chain_regex(&curproxy->req_exp, preg, ACT_REMOVE, NULL); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 3278 | warnif_misplaced_reqxxx(curproxy, file, linenum, args[0]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3279 | } |
| 3280 | else if (!strcmp(args[0], "reqdeny")) { /* deny a request if a header matches this regex */ |
| 3281 | regex_t *preg; |
| 3282 | if (curproxy == &defproxy) { |
| 3283 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3284 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3285 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3286 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3287 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3288 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3289 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3290 | if (*(args[1]) == 0) { |
| 3291 | Alert("parsing [%s:%d] : '%s' expects <regex> as an argument.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3292 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3293 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3294 | } |
| 3295 | |
| 3296 | preg = calloc(1, sizeof(regex_t)); |
| 3297 | if (regcomp(preg, args[1], REG_EXTENDED) != 0) { |
| 3298 | Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3299 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3300 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3301 | } |
| 3302 | |
| 3303 | chain_regex(&curproxy->req_exp, preg, ACT_DENY, NULL); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 3304 | warnif_misplaced_reqxxx(curproxy, file, linenum, args[0]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3305 | } |
| 3306 | else if (!strcmp(args[0], "reqpass")) { /* pass this header without allowing or denying the request */ |
| 3307 | regex_t *preg; |
| 3308 | if (curproxy == &defproxy) { |
| 3309 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3310 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3311 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3312 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3313 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3314 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3315 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3316 | if (*(args[1]) == 0) { |
| 3317 | Alert("parsing [%s:%d] : '%s' expects <regex> as an argument.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3318 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3319 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3320 | } |
| 3321 | |
| 3322 | preg = calloc(1, sizeof(regex_t)); |
| 3323 | if (regcomp(preg, args[1], REG_EXTENDED) != 0) { |
| 3324 | Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3325 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3326 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3327 | } |
| 3328 | |
| 3329 | chain_regex(&curproxy->req_exp, preg, ACT_PASS, NULL); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 3330 | warnif_misplaced_reqxxx(curproxy, file, linenum, args[0]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3331 | } |
| 3332 | else if (!strcmp(args[0], "reqallow")) { /* allow a request if a header matches this regex */ |
| 3333 | regex_t *preg; |
| 3334 | if (curproxy == &defproxy) { |
| 3335 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3336 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3337 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3338 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3339 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3340 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3341 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3342 | if (*(args[1]) == 0) { |
| 3343 | Alert("parsing [%s:%d] : '%s' expects <regex> as an argument.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3344 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3345 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3346 | } |
| 3347 | |
| 3348 | preg = calloc(1, sizeof(regex_t)); |
| 3349 | if (regcomp(preg, args[1], REG_EXTENDED) != 0) { |
| 3350 | Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3351 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3352 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3353 | } |
| 3354 | |
| 3355 | chain_regex(&curproxy->req_exp, preg, ACT_ALLOW, NULL); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 3356 | warnif_misplaced_reqxxx(curproxy, file, linenum, args[0]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3357 | } |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 3358 | else if (!strcmp(args[0], "reqtarpit")) { /* tarpit a request if a header matches this regex */ |
| 3359 | regex_t *preg; |
| 3360 | if (curproxy == &defproxy) { |
| 3361 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3362 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3363 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 3364 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3365 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3366 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3367 | |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 3368 | if (*(args[1]) == 0) { |
| 3369 | Alert("parsing [%s:%d] : '%s' expects <regex> as an argument.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3370 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3371 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 3372 | } |
| 3373 | |
| 3374 | preg = calloc(1, sizeof(regex_t)); |
| 3375 | if (regcomp(preg, args[1], REG_EXTENDED) != 0) { |
| 3376 | Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3377 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3378 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 3379 | } |
| 3380 | |
| 3381 | chain_regex(&curproxy->req_exp, preg, ACT_TARPIT, NULL); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 3382 | warnif_misplaced_reqxxx(curproxy, file, linenum, args[0]); |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 3383 | } |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 3384 | else if (!strcmp(args[0], "reqsetbe")) { /* switch the backend from a regex, respecting case */ |
| 3385 | regex_t *preg; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3386 | if (curproxy == &defproxy) { |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 3387 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3388 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3389 | goto out; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 3390 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3391 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3392 | err_code |= ERR_WARN; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 3393 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3394 | if (*(args[1]) == 0 || *(args[2]) == 0) { |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 3395 | Alert("parsing [%s:%d] : '%s' expects <search> and <target> as arguments.\n", |
| 3396 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3397 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3398 | goto out; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 3399 | } |
| 3400 | |
| 3401 | preg = calloc(1, sizeof(regex_t)); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3402 | if (regcomp(preg, args[1], REG_EXTENDED) != 0) { |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 3403 | Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3404 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3405 | goto out; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 3406 | } |
| 3407 | |
| 3408 | chain_regex(&curproxy->req_exp, preg, ACT_SETBE, strdup(args[2])); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 3409 | warnif_misplaced_reqxxx(curproxy, file, linenum, args[0]); |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 3410 | } |
| 3411 | else if (!strcmp(args[0], "reqisetbe")) { /* switch the backend from a regex, ignoring case */ |
| 3412 | regex_t *preg; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3413 | if (curproxy == &defproxy) { |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 3414 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3415 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3416 | goto out; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 3417 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3418 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3419 | err_code |= ERR_WARN; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 3420 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3421 | if (*(args[1]) == 0 || *(args[2]) == 0) { |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 3422 | Alert("parsing [%s:%d] : '%s' expects <search> and <target> as arguments.\n", |
| 3423 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3424 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3425 | goto out; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 3426 | } |
| 3427 | |
| 3428 | preg = calloc(1, sizeof(regex_t)); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3429 | if (regcomp(preg, args[1], REG_EXTENDED | REG_ICASE) != 0) { |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 3430 | Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3431 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3432 | goto out; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 3433 | } |
| 3434 | |
| 3435 | chain_regex(&curproxy->req_exp, preg, ACT_SETBE, strdup(args[2])); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 3436 | warnif_misplaced_reqxxx(curproxy, file, linenum, args[0]); |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 3437 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3438 | else if (!strcmp(args[0], "reqirep")) { /* replace request header from a regex, ignoring case */ |
| 3439 | regex_t *preg; |
| 3440 | if (curproxy == &defproxy) { |
| 3441 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3442 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3443 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3444 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3445 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3446 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3447 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3448 | if (*(args[1]) == 0 || *(args[2]) == 0) { |
| 3449 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 3450 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3451 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3452 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3453 | } |
| 3454 | |
| 3455 | preg = calloc(1, sizeof(regex_t)); |
| 3456 | if (regcomp(preg, args[1], REG_EXTENDED | REG_ICASE) != 0) { |
| 3457 | Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3458 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3459 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3460 | } |
| 3461 | |
| 3462 | err = chain_regex(&curproxy->req_exp, preg, ACT_REPLACE, strdup(args[2])); |
| 3463 | if (err) { |
| 3464 | Alert("parsing [%s:%d] : invalid character or unterminated sequence in replacement string near '%c'.\n", |
| 3465 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3466 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3467 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3468 | } |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 3469 | warnif_misplaced_reqxxx(curproxy, file, linenum, args[0]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3470 | } |
| 3471 | else if (!strcmp(args[0], "reqidel")) { /* delete request header from a regex ignoring case */ |
| 3472 | regex_t *preg; |
| 3473 | if (curproxy == &defproxy) { |
| 3474 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3475 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3476 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3477 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3478 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3479 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3480 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3481 | if (*(args[1]) == 0) { |
| 3482 | Alert("parsing [%s:%d] : '%s' expects <regex> as an argument.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3483 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3484 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3485 | } |
| 3486 | |
| 3487 | preg = calloc(1, sizeof(regex_t)); |
| 3488 | if (regcomp(preg, args[1], REG_EXTENDED | REG_ICASE) != 0) { |
| 3489 | Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3490 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3491 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3492 | } |
| 3493 | |
| 3494 | chain_regex(&curproxy->req_exp, preg, ACT_REMOVE, NULL); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 3495 | warnif_misplaced_reqxxx(curproxy, file, linenum, args[0]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3496 | } |
| 3497 | else if (!strcmp(args[0], "reqideny")) { /* deny a request if a header matches this regex ignoring case */ |
| 3498 | regex_t *preg; |
| 3499 | if (curproxy == &defproxy) { |
| 3500 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3501 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3502 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3503 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3504 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3505 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3506 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3507 | if (*(args[1]) == 0) { |
| 3508 | Alert("parsing [%s:%d] : '%s' expects <regex> as an argument.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3509 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3510 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3511 | } |
| 3512 | |
| 3513 | preg = calloc(1, sizeof(regex_t)); |
| 3514 | if (regcomp(preg, args[1], REG_EXTENDED | REG_ICASE) != 0) { |
| 3515 | Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3516 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3517 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3518 | } |
| 3519 | |
| 3520 | chain_regex(&curproxy->req_exp, preg, ACT_DENY, NULL); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 3521 | warnif_misplaced_reqxxx(curproxy, file, linenum, args[0]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3522 | } |
| 3523 | else if (!strcmp(args[0], "reqipass")) { /* pass this header without allowing or denying the request */ |
| 3524 | regex_t *preg; |
| 3525 | if (curproxy == &defproxy) { |
| 3526 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3527 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3528 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3529 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3530 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3531 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3532 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3533 | if (*(args[1]) == 0) { |
| 3534 | Alert("parsing [%s:%d] : '%s' expects <regex> as an argument.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3535 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3536 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3537 | } |
| 3538 | |
| 3539 | preg = calloc(1, sizeof(regex_t)); |
| 3540 | if (regcomp(preg, args[1], REG_EXTENDED | REG_ICASE) != 0) { |
| 3541 | Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3542 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3543 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3544 | } |
| 3545 | |
| 3546 | chain_regex(&curproxy->req_exp, preg, ACT_PASS, NULL); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 3547 | warnif_misplaced_reqxxx(curproxy, file, linenum, args[0]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3548 | } |
| 3549 | else if (!strcmp(args[0], "reqiallow")) { /* allow a request if a header matches this regex ignoring case */ |
| 3550 | regex_t *preg; |
| 3551 | if (curproxy == &defproxy) { |
| 3552 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3553 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3554 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3555 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3556 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3557 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3558 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3559 | if (*(args[1]) == 0) { |
| 3560 | Alert("parsing [%s:%d] : '%s' expects <regex> as an argument.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3561 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3562 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3563 | } |
| 3564 | |
| 3565 | preg = calloc(1, sizeof(regex_t)); |
| 3566 | if (regcomp(preg, args[1], REG_EXTENDED | REG_ICASE) != 0) { |
| 3567 | Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3568 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3569 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3570 | } |
| 3571 | |
| 3572 | chain_regex(&curproxy->req_exp, preg, ACT_ALLOW, NULL); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 3573 | warnif_misplaced_reqxxx(curproxy, file, linenum, args[0]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3574 | } |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 3575 | else if (!strcmp(args[0], "reqitarpit")) { /* tarpit a request if a header matches this regex ignoring case */ |
| 3576 | regex_t *preg; |
| 3577 | if (curproxy == &defproxy) { |
| 3578 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3579 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3580 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 3581 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3582 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3583 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3584 | |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 3585 | if (*(args[1]) == 0) { |
| 3586 | Alert("parsing [%s:%d] : '%s' expects <regex> as an argument.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3587 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3588 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 3589 | } |
| 3590 | |
| 3591 | preg = calloc(1, sizeof(regex_t)); |
| 3592 | if (regcomp(preg, args[1], REG_EXTENDED | REG_ICASE) != 0) { |
| 3593 | Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3594 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3595 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 3596 | } |
| 3597 | |
| 3598 | chain_regex(&curproxy->req_exp, preg, ACT_TARPIT, NULL); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 3599 | warnif_misplaced_reqxxx(curproxy, file, linenum, args[0]); |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 3600 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3601 | else if (!strcmp(args[0], "reqadd")) { /* add request header */ |
| 3602 | if (curproxy == &defproxy) { |
| 3603 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3604 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3605 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3606 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3607 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3608 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3609 | |
| 3610 | if (curproxy->nb_reqadd >= MAX_NEWHDR) { |
| 3611 | Alert("parsing [%s:%d] : too many '%s'. Continuing.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3612 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3613 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3614 | } |
| 3615 | |
| 3616 | if (*(args[1]) == 0) { |
| 3617 | Alert("parsing [%s:%d] : '%s' expects <header> as an argument.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3618 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3619 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3620 | } |
| 3621 | |
| 3622 | curproxy->req_add[curproxy->nb_reqadd++] = strdup(args[1]); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 3623 | warnif_misplaced_reqadd(curproxy, file, linenum, args[0]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3624 | } |
| 3625 | else if (!strcmp(args[0], "srvexp") || !strcmp(args[0], "rsprep")) { /* replace response header from a regex */ |
| 3626 | regex_t *preg; |
| 3627 | |
| 3628 | if (*(args[1]) == 0 || *(args[2]) == 0) { |
| 3629 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 3630 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3631 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3632 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3633 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3634 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3635 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3636 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3637 | preg = calloc(1, sizeof(regex_t)); |
| 3638 | if (regcomp(preg, args[1], REG_EXTENDED) != 0) { |
| 3639 | Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3640 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3641 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3642 | } |
| 3643 | |
| 3644 | err = chain_regex(&curproxy->rsp_exp, preg, ACT_REPLACE, strdup(args[2])); |
| 3645 | if (err) { |
| 3646 | Alert("parsing [%s:%d] : invalid character or unterminated sequence in replacement string near '%c'.\n", |
| 3647 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3648 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3649 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3650 | } |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 3651 | warnif_misplaced_reqxxx(curproxy, file, linenum, args[0]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3652 | } |
| 3653 | else if (!strcmp(args[0], "rspdel")) { /* delete response header from a regex */ |
| 3654 | regex_t *preg; |
| 3655 | if (curproxy == &defproxy) { |
| 3656 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3657 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3658 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3659 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3660 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3661 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3662 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3663 | if (*(args[1]) == 0) { |
| 3664 | Alert("parsing [%s:%d] : '%s' expects <search> as an argument.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3665 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3666 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3667 | } |
| 3668 | |
| 3669 | preg = calloc(1, sizeof(regex_t)); |
| 3670 | if (regcomp(preg, args[1], REG_EXTENDED) != 0) { |
| 3671 | Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3672 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3673 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3674 | } |
| 3675 | |
| 3676 | err = chain_regex(&curproxy->rsp_exp, preg, ACT_REMOVE, strdup(args[2])); |
| 3677 | if (err) { |
| 3678 | Alert("parsing [%s:%d] : invalid character or unterminated sequence in replacement string near '%c'.\n", |
| 3679 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3680 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3681 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3682 | } |
| 3683 | } |
| 3684 | else if (!strcmp(args[0], "rspdeny")) { /* block response header from a regex */ |
| 3685 | regex_t *preg; |
| 3686 | if (curproxy == &defproxy) { |
| 3687 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3688 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3689 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3690 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3691 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3692 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3693 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3694 | if (*(args[1]) == 0) { |
| 3695 | Alert("parsing [%s:%d] : '%s' expects <search> as an argument.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3696 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3697 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3698 | } |
| 3699 | |
| 3700 | preg = calloc(1, sizeof(regex_t)); |
| 3701 | if (regcomp(preg, args[1], REG_EXTENDED) != 0) { |
| 3702 | Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3703 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3704 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3705 | } |
| 3706 | |
| 3707 | err = chain_regex(&curproxy->rsp_exp, preg, ACT_DENY, strdup(args[2])); |
| 3708 | if (err) { |
| 3709 | Alert("parsing [%s:%d] : invalid character or unterminated sequence in replacement string near '%c'.\n", |
| 3710 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3711 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3712 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3713 | } |
| 3714 | } |
| 3715 | else if (!strcmp(args[0], "rspirep")) { /* replace response header from a regex ignoring case */ |
| 3716 | regex_t *preg; |
| 3717 | if (curproxy == &defproxy) { |
| 3718 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3719 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3720 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3721 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3722 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3723 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3724 | |
| 3725 | if (*(args[1]) == 0 || *(args[2]) == 0) { |
| 3726 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 3727 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3728 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3729 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3730 | } |
| 3731 | |
| 3732 | preg = calloc(1, sizeof(regex_t)); |
| 3733 | if (regcomp(preg, args[1], REG_EXTENDED | REG_ICASE) != 0) { |
| 3734 | Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3735 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3736 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3737 | } |
| 3738 | |
| 3739 | err = chain_regex(&curproxy->rsp_exp, preg, ACT_REPLACE, strdup(args[2])); |
| 3740 | if (err) { |
| 3741 | Alert("parsing [%s:%d] : invalid character or unterminated sequence in replacement string near '%c'.\n", |
| 3742 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3743 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3744 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3745 | } |
| 3746 | } |
| 3747 | else if (!strcmp(args[0], "rspidel")) { /* delete response header from a regex ignoring case */ |
| 3748 | regex_t *preg; |
| 3749 | if (curproxy == &defproxy) { |
| 3750 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3751 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3752 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3753 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3754 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3755 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3756 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3757 | if (*(args[1]) == 0) { |
| 3758 | Alert("parsing [%s:%d] : '%s' expects <search> as an argument.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3759 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3760 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3761 | } |
| 3762 | |
| 3763 | preg = calloc(1, sizeof(regex_t)); |
| 3764 | if (regcomp(preg, args[1], REG_EXTENDED | REG_ICASE) != 0) { |
| 3765 | Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3766 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3767 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3768 | } |
| 3769 | |
| 3770 | err = chain_regex(&curproxy->rsp_exp, preg, ACT_REMOVE, strdup(args[2])); |
| 3771 | if (err) { |
| 3772 | Alert("parsing [%s:%d] : invalid character or unterminated sequence in replacement string near '%c'.\n", |
| 3773 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3774 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3775 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3776 | } |
| 3777 | } |
| 3778 | else if (!strcmp(args[0], "rspideny")) { /* block response header from a regex ignoring case */ |
| 3779 | regex_t *preg; |
| 3780 | if (curproxy == &defproxy) { |
| 3781 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3782 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3783 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3784 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3785 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3786 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3787 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3788 | if (*(args[1]) == 0) { |
| 3789 | Alert("parsing [%s:%d] : '%s' expects <search> as an argument.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3790 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3791 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3792 | } |
| 3793 | |
| 3794 | preg = calloc(1, sizeof(regex_t)); |
| 3795 | if (regcomp(preg, args[1], REG_EXTENDED | REG_ICASE) != 0) { |
| 3796 | Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3797 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3798 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3799 | } |
| 3800 | |
| 3801 | err = chain_regex(&curproxy->rsp_exp, preg, ACT_DENY, strdup(args[2])); |
| 3802 | if (err) { |
| 3803 | Alert("parsing [%s:%d] : invalid character or unterminated sequence in replacement string near '%c'.\n", |
| 3804 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3805 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3806 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3807 | } |
| 3808 | } |
| 3809 | else if (!strcmp(args[0], "rspadd")) { /* add response header */ |
| 3810 | if (curproxy == &defproxy) { |
| 3811 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3812 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3813 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3814 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3815 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3816 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3817 | |
| 3818 | if (curproxy->nb_rspadd >= MAX_NEWHDR) { |
| 3819 | Alert("parsing [%s:%d] : too many '%s'. Continuing.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3820 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3821 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3822 | } |
| 3823 | |
| 3824 | if (*(args[1]) == 0) { |
| 3825 | Alert("parsing [%s:%d] : '%s' expects <header> as an argument.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3826 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3827 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3828 | } |
| 3829 | |
| 3830 | curproxy->rsp_add[curproxy->nb_rspadd++] = strdup(args[1]); |
| 3831 | } |
| 3832 | else if (!strcmp(args[0], "errorloc") || |
| 3833 | !strcmp(args[0], "errorloc302") || |
| 3834 | !strcmp(args[0], "errorloc303")) { /* error location */ |
| 3835 | int errnum, errlen; |
| 3836 | char *err; |
| 3837 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3838 | if (warnifnotcap(curproxy, PR_CAP_FE | PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3839 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3840 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3841 | if (*(args[2]) == 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 3842 | Alert("parsing [%s:%d] : <%s> expects <status_code> and <url> as arguments.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3843 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3844 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3845 | } |
| 3846 | |
| 3847 | errnum = atol(args[1]); |
| 3848 | if (!strcmp(args[0], "errorloc303")) { |
| 3849 | err = malloc(strlen(HTTP_303) + strlen(args[2]) + 5); |
| 3850 | errlen = sprintf(err, "%s%s\r\n\r\n", HTTP_303, args[2]); |
| 3851 | } else { |
| 3852 | err = malloc(strlen(HTTP_302) + strlen(args[2]) + 5); |
| 3853 | errlen = sprintf(err, "%s%s\r\n\r\n", HTTP_302, args[2]); |
| 3854 | } |
| 3855 | |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 3856 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) { |
| 3857 | if (http_err_codes[rc] == errnum) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 3858 | chunk_destroy(&curproxy->errmsg[rc]); |
| 3859 | chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 3860 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3861 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3862 | } |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 3863 | |
| 3864 | if (rc >= HTTP_ERR_SIZE) { |
| 3865 | Warning("parsing [%s:%d] : status code %d not handled, error relocation will be ignored.\n", |
| 3866 | file, linenum, errnum); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3867 | free(err); |
| 3868 | } |
| 3869 | } |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 3870 | else if (!strcmp(args[0], "errorfile")) { /* error message from a file */ |
| 3871 | int errnum, errlen, fd; |
| 3872 | char *err; |
| 3873 | struct stat stat; |
| 3874 | |
| 3875 | if (warnifnotcap(curproxy, PR_CAP_FE | PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3876 | err_code |= ERR_WARN; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 3877 | |
| 3878 | if (*(args[2]) == 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 3879 | Alert("parsing [%s:%d] : <%s> expects <status_code> and <file> as arguments.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3880 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3881 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 3882 | } |
| 3883 | |
| 3884 | fd = open(args[2], O_RDONLY); |
| 3885 | if ((fd < 0) || (fstat(fd, &stat) < 0)) { |
| 3886 | Alert("parsing [%s:%d] : error opening file <%s> for custom error message <%s>.\n", |
| 3887 | file, linenum, args[2], args[1]); |
| 3888 | if (fd >= 0) |
| 3889 | close(fd); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3890 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3891 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 3892 | } |
| 3893 | |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 3894 | if (stat.st_size <= global.tune.bufsize) { |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 3895 | errlen = stat.st_size; |
| 3896 | } else { |
| 3897 | Warning("parsing [%s:%d] : custom error message file <%s> larger than %d bytes. Truncating.\n", |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 3898 | file, linenum, args[2], global.tune.bufsize); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3899 | err_code |= ERR_WARN; |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 3900 | errlen = global.tune.bufsize; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 3901 | } |
| 3902 | |
| 3903 | err = malloc(errlen); /* malloc() must succeed during parsing */ |
| 3904 | errnum = read(fd, err, errlen); |
| 3905 | if (errnum != errlen) { |
| 3906 | Alert("parsing [%s:%d] : error reading file <%s> for custom error message <%s>.\n", |
| 3907 | file, linenum, args[2], args[1]); |
| 3908 | close(fd); |
| 3909 | free(err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3910 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3911 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 3912 | } |
| 3913 | close(fd); |
| 3914 | |
| 3915 | errnum = atol(args[1]); |
| 3916 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) { |
| 3917 | if (http_err_codes[rc] == errnum) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 3918 | chunk_destroy(&curproxy->errmsg[rc]); |
| 3919 | chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen); |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 3920 | break; |
| 3921 | } |
| 3922 | } |
| 3923 | |
| 3924 | if (rc >= HTTP_ERR_SIZE) { |
| 3925 | Warning("parsing [%s:%d] : status code %d not handled, error customization will be ignored.\n", |
| 3926 | file, linenum, errnum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3927 | err_code |= ERR_WARN; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 3928 | free(err); |
| 3929 | } |
| 3930 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3931 | else { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 3932 | struct cfg_kw_list *kwl; |
| 3933 | int index; |
| 3934 | |
| 3935 | list_for_each_entry(kwl, &cfg_keywords.list, list) { |
| 3936 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 3937 | if (kwl->kw[index].section != CFG_LISTEN) |
| 3938 | continue; |
| 3939 | if (strcmp(kwl->kw[index].kw, args[0]) == 0) { |
| 3940 | /* prepare error message just in case */ |
| 3941 | snprintf(trash, sizeof(trash), |
| 3942 | "error near '%s' in %s section", args[0], cursection); |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 3943 | rc = kwl->kw[index].parse(args, CFG_LISTEN, curproxy, &defproxy, trash, sizeof(trash)); |
| 3944 | if (rc < 0) { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 3945 | Alert("parsing [%s:%d] : %s\n", file, linenum, trash); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3946 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3947 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 3948 | } |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 3949 | else if (rc > 0) { |
| 3950 | Warning("parsing [%s:%d] : %s\n", file, linenum, trash); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3951 | err_code |= ERR_WARN; |
| 3952 | goto out; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 3953 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3954 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 3955 | } |
| 3956 | } |
| 3957 | } |
| 3958 | |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 3959 | Alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3960 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3961 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3962 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3963 | out: |
| 3964 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3965 | } |
| 3966 | |
| 3967 | |
| 3968 | /* |
| 3969 | * This function reads and parses the configuration file given in the argument. |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 3970 | * Returns the error code, 0 if OK, or any combination of : |
| 3971 | * - ERR_ABORT: must abort ASAP |
| 3972 | * - ERR_FATAL: we can continue parsing but not start the service |
| 3973 | * - ERR_WARN: a warning has been emitted |
| 3974 | * - ERR_ALERT: an alert has been emitted |
| 3975 | * Only the two first ones can stop processing, the two others are just |
| 3976 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3977 | */ |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 3978 | int readcfgfile(const char *file) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3979 | { |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 3980 | char thisline[LINESIZE]; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3981 | FILE *f; |
| 3982 | int linenum = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3983 | int confsect = CFG_NONE; |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 3984 | int err_code = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3985 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3986 | if ((f=fopen(file,"r")) == NULL) |
| 3987 | return -1; |
| 3988 | |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 3989 | while (fgets(thisline, sizeof(thisline), f) != NULL) { |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 3990 | int arg, kwm = KWM_STD; |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 3991 | char *end; |
| 3992 | char *args[MAX_LINE_ARGS + 1]; |
| 3993 | char *line = thisline; |
| 3994 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3995 | linenum++; |
| 3996 | |
| 3997 | end = line + strlen(line); |
| 3998 | |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 3999 | if (end-line == sizeof(thisline)-1 && *(end-1) != '\n') { |
| 4000 | /* Check if we reached the limit and the last char is not \n. |
| 4001 | * Watch out for the last line without the terminating '\n'! |
| 4002 | */ |
| 4003 | Alert("parsing [%s:%d]: line too long, limit: %d.\n", |
Willy Tarreau | 5e4a6f1 | 2009-04-11 19:42:49 +0200 | [diff] [blame] | 4004 | file, linenum, (int)sizeof(thisline)-1); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 4005 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 4006 | } |
| 4007 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4008 | /* skip leading spaces */ |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 4009 | while (isspace((unsigned char)*line)) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4010 | line++; |
| 4011 | |
| 4012 | arg = 0; |
| 4013 | args[arg] = line; |
| 4014 | |
| 4015 | while (*line && arg < MAX_LINE_ARGS) { |
| 4016 | /* first, we'll replace \\, \<space>, \#, \r, \n, \t, \xXX with their |
| 4017 | * C equivalent value. Other combinations left unchanged (eg: \1). |
| 4018 | */ |
| 4019 | if (*line == '\\') { |
| 4020 | int skip = 0; |
| 4021 | if (line[1] == ' ' || line[1] == '\\' || line[1] == '#') { |
| 4022 | *line = line[1]; |
| 4023 | skip = 1; |
| 4024 | } |
| 4025 | else if (line[1] == 'r') { |
| 4026 | *line = '\r'; |
| 4027 | skip = 1; |
| 4028 | } |
| 4029 | else if (line[1] == 'n') { |
| 4030 | *line = '\n'; |
| 4031 | skip = 1; |
| 4032 | } |
| 4033 | else if (line[1] == 't') { |
| 4034 | *line = '\t'; |
| 4035 | skip = 1; |
| 4036 | } |
| 4037 | else if (line[1] == 'x') { |
| 4038 | if ((line + 3 < end ) && ishex(line[2]) && ishex(line[3])) { |
| 4039 | unsigned char hex1, hex2; |
| 4040 | hex1 = toupper(line[2]) - '0'; |
| 4041 | hex2 = toupper(line[3]) - '0'; |
| 4042 | if (hex1 > 9) hex1 -= 'A' - '9' - 1; |
| 4043 | if (hex2 > 9) hex2 -= 'A' - '9' - 1; |
| 4044 | *line = (hex1<<4) + hex2; |
| 4045 | skip = 3; |
| 4046 | } |
| 4047 | else { |
| 4048 | Alert("parsing [%s:%d] : invalid or incomplete '\\x' sequence in '%s'.\n", file, linenum, args[0]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 4049 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4050 | } |
| 4051 | } |
| 4052 | if (skip) { |
Cyril Bonté | dd1b01d | 2009-12-06 13:43:42 +0100 | [diff] [blame] | 4053 | memmove(line + 1, line + 1 + skip, end - (line + skip)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4054 | end -= skip; |
| 4055 | } |
| 4056 | line++; |
| 4057 | } |
| 4058 | else if (*line == '#' || *line == '\n' || *line == '\r') { |
| 4059 | /* end of string, end of loop */ |
| 4060 | *line = 0; |
| 4061 | break; |
| 4062 | } |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 4063 | else if (isspace((unsigned char)*line)) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4064 | /* a non-escaped space is an argument separator */ |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 4065 | *line++ = '\0'; |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 4066 | while (isspace((unsigned char)*line)) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4067 | line++; |
| 4068 | args[++arg] = line; |
| 4069 | } |
| 4070 | else { |
| 4071 | line++; |
| 4072 | } |
| 4073 | } |
| 4074 | |
| 4075 | /* empty line */ |
| 4076 | if (!**args) |
| 4077 | continue; |
| 4078 | |
Willy Tarreau | 7bb651e | 2009-11-09 21:16:53 +0100 | [diff] [blame] | 4079 | if (*line) { |
| 4080 | /* we had to stop due to too many args. |
| 4081 | * Let's terminate the string, print the offending part then cut the |
| 4082 | * last arg. |
| 4083 | */ |
| 4084 | while (*line && *line != '#' && *line != '\n' && *line != '\r') |
| 4085 | line++; |
| 4086 | *line = '\0'; |
| 4087 | |
Krzysztof Piotr Oledzki | 500b8f0 | 2009-12-15 22:34:51 +0100 | [diff] [blame] | 4088 | Alert("parsing [%s:%d]: line too long, truncating at word %d, position %ld: <%s>.\n", |
Willy Tarreau | 3ccf94e | 2009-12-17 21:12:16 +0100 | [diff] [blame] | 4089 | file, linenum, arg + 1, (long)(args[arg] - thisline + 1), args[arg]); |
Willy Tarreau | 7bb651e | 2009-11-09 21:16:53 +0100 | [diff] [blame] | 4090 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4091 | args[arg] = line; |
| 4092 | } |
| 4093 | |
Willy Tarreau | 540abe4 | 2007-05-02 20:50:16 +0200 | [diff] [blame] | 4094 | /* zero out remaining args and ensure that at least one entry |
| 4095 | * is zeroed out. |
| 4096 | */ |
| 4097 | while (++arg <= MAX_LINE_ARGS) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4098 | args[arg] = line; |
| 4099 | } |
| 4100 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 4101 | /* check for keyword modifiers "no" and "default" */ |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 4102 | if (!strcmp(args[0], "no")) { |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 4103 | kwm = KWM_NO; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 4104 | for (arg=0; *args[arg+1]; arg++) |
| 4105 | args[arg] = args[arg+1]; // shift args after inversion |
| 4106 | } |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 4107 | else if (!strcmp(args[0], "default")) { |
| 4108 | kwm = KWM_DEF; |
| 4109 | for (arg=0; *args[arg+1]; arg++) |
| 4110 | args[arg] = args[arg+1]; // shift args after inversion |
| 4111 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 4112 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 4113 | if (kwm != KWM_STD && strcmp(args[0], "option") != 0) { |
| 4114 | Alert("parsing [%s:%d]: negation/default currently supported only for options.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 4115 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 4116 | } |
| 4117 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4118 | if (!strcmp(args[0], "listen") || |
| 4119 | !strcmp(args[0], "frontend") || |
| 4120 | !strcmp(args[0], "backend") || |
| 4121 | !strcmp(args[0], "ruleset") || |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 4122 | !strcmp(args[0], "defaults")) { /* new proxy */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4123 | confsect = CFG_LISTEN; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 4124 | free(cursection); |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 4125 | cursection = strdup(args[0]); |
| 4126 | } |
| 4127 | else if (!strcmp(args[0], "global")) { /* global config */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4128 | confsect = CFG_GLOBAL; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 4129 | free(cursection); |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 4130 | cursection = strdup(args[0]); |
| 4131 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4132 | /* else it's a section keyword */ |
| 4133 | |
| 4134 | switch (confsect) { |
| 4135 | case CFG_LISTEN: |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4136 | err_code |= cfg_parse_listen(file, linenum, args, kwm); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4137 | break; |
| 4138 | case CFG_GLOBAL: |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 4139 | err_code |= cfg_parse_global(file, linenum, args, kwm); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4140 | break; |
| 4141 | default: |
| 4142 | Alert("parsing [%s:%d] : unknown keyword '%s' out of section.\n", file, linenum, args[0]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 4143 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4144 | } |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 4145 | |
| 4146 | if (err_code & ERR_ABORT) |
| 4147 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4148 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 4149 | free(cursection); |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 4150 | cursection = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4151 | fclose(f); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 4152 | return err_code; |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 4153 | } |
| 4154 | |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 4155 | /* |
| 4156 | * Returns the error code, 0 if OK, or any combination of : |
| 4157 | * - ERR_ABORT: must abort ASAP |
| 4158 | * - ERR_FATAL: we can continue parsing but not start the service |
| 4159 | * - ERR_WARN: a warning has been emitted |
| 4160 | * - ERR_ALERT: an alert has been emitted |
| 4161 | * Only the two first ones can stop processing, the two others are just |
| 4162 | * indicators. |
| 4163 | */ |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 4164 | int check_config_validity() |
| 4165 | { |
| 4166 | int cfgerr = 0; |
| 4167 | struct proxy *curproxy = NULL; |
| 4168 | struct server *newsrv = NULL; |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 4169 | int err_code = 0; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 4170 | unsigned int next_pxid = 1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4171 | |
| 4172 | /* |
| 4173 | * Now, check for the integrity of all that we have collected. |
| 4174 | */ |
| 4175 | |
| 4176 | /* will be needed further to delay some tasks */ |
Willy Tarreau | b0b37bc | 2008-06-23 14:00:57 +0200 | [diff] [blame] | 4177 | tv_update_date(0,1); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4178 | |
Willy Tarreau | 55bc0f8 | 2009-03-15 14:51:53 +0100 | [diff] [blame] | 4179 | /* first, we will invert the proxy list order */ |
| 4180 | curproxy = NULL; |
| 4181 | while (proxy) { |
| 4182 | struct proxy *next; |
| 4183 | |
| 4184 | next = proxy->next; |
| 4185 | proxy->next = curproxy; |
| 4186 | curproxy = proxy; |
| 4187 | if (!next) |
| 4188 | break; |
| 4189 | proxy = next; |
| 4190 | } |
| 4191 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4192 | if ((curproxy = proxy) == NULL) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 4193 | Alert("config : no <listen> line. Nothing to do !\n"); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 4194 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4195 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4196 | } |
| 4197 | |
| 4198 | while (curproxy != NULL) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 4199 | struct switching_rule *rule; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 4200 | struct listener *listener; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 4201 | unsigned int next_id; |
| 4202 | |
| 4203 | if (!curproxy->uuid) { |
| 4204 | /* proxy ID not set, use automatic numbering with first |
| 4205 | * spare entry starting with next_pxid. |
| 4206 | */ |
| 4207 | next_pxid = get_next_id(&used_proxy_id, next_pxid); |
| 4208 | curproxy->conf.id.key = curproxy->uuid = next_pxid; |
| 4209 | eb32_insert(&used_proxy_id, &curproxy->conf.id); |
| 4210 | next_pxid++; |
| 4211 | } |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 4212 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4213 | if (curproxy->state == PR_STSTOPPED) { |
Willy Tarreau | da250db | 2008-10-12 12:07:48 +0200 | [diff] [blame] | 4214 | /* ensure we don't keep listeners uselessly bound */ |
| 4215 | stop_proxy(curproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4216 | curproxy = curproxy->next; |
| 4217 | continue; |
| 4218 | } |
| 4219 | |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 4220 | switch (curproxy->mode) { |
| 4221 | case PR_MODE_HEALTH: |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 4222 | cfgerr += proxy_cfg_ensure_no_http(curproxy); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 4223 | if (!(curproxy->cap & PR_CAP_FE)) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 4224 | Alert("config : %s '%s' cannot be in health mode as it has no frontend capability.\n", |
| 4225 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 4226 | cfgerr++; |
| 4227 | } |
| 4228 | |
| 4229 | if (curproxy->srv != NULL) |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 4230 | Warning("config : servers will be ignored for %s '%s'.\n", |
| 4231 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 4232 | break; |
| 4233 | |
| 4234 | case PR_MODE_TCP: |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 4235 | cfgerr += proxy_cfg_ensure_no_http(curproxy); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 4236 | break; |
| 4237 | |
| 4238 | case PR_MODE_HTTP: |
Willy Tarreau | a9fb083 | 2009-07-10 20:53:53 +0200 | [diff] [blame] | 4239 | curproxy->acl_requires |= ACL_USE_L7_ANY; |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 4240 | if ((curproxy->cookie_name != NULL) && (curproxy->srv == NULL)) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 4241 | Alert("config : HTTP proxy %s has a cookie but no server list !\n", |
| 4242 | curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 4243 | cfgerr++; |
| 4244 | } |
| 4245 | break; |
| 4246 | } |
| 4247 | |
| 4248 | if ((curproxy->cap & PR_CAP_FE) && (curproxy->listen == NULL)) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 4249 | Alert("config : %s '%s' has no listen address. Please either specify a valid address on the <listen> line, or use the <bind> keyword.\n", |
| 4250 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4251 | cfgerr++; |
| 4252 | } |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 4253 | |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 4254 | if ((curproxy->cap & PR_CAP_BE) && (curproxy->mode != PR_MODE_HEALTH)) { |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 4255 | if (curproxy->lbprm.algo & BE_LB_KIND) { |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 4256 | if (curproxy->options & PR_O_TRANSP) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 4257 | Alert("config : %s '%s' cannot use both transparent and balance mode.\n", |
| 4258 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 4259 | cfgerr++; |
| 4260 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4261 | #ifdef WE_DONT_SUPPORT_SERVERLESS_LISTENERS |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 4262 | else if (curproxy->srv == NULL) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 4263 | Alert("config : %s '%s' needs at least 1 server in balance mode.\n", |
| 4264 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 4265 | cfgerr++; |
| 4266 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4267 | #endif |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 4268 | else if (*(int *)&curproxy->dispatch_addr.sin_addr != 0) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 4269 | Warning("config : dispatch address of %s '%s' will be ignored in balance mode.\n", |
| 4270 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 4271 | err_code |= ERR_WARN; |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 4272 | } |
| 4273 | } |
| 4274 | else if (!(curproxy->options & (PR_O_TRANSP | PR_O_HTTP_PROXY)) && |
| 4275 | (*(int *)&curproxy->dispatch_addr.sin_addr == 0)) { |
| 4276 | /* If no LB algo is set in a backend, and we're not in |
| 4277 | * transparent mode, dispatch mode nor proxy mode, we |
| 4278 | * want to use balance roundrobin by default. |
| 4279 | */ |
| 4280 | curproxy->lbprm.algo &= ~BE_LB_ALGO; |
| 4281 | curproxy->lbprm.algo |= BE_LB_ALGO_RR; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4282 | } |
| 4283 | } |
Willy Tarreau | 193cf93 | 2007-09-17 10:17:23 +0200 | [diff] [blame] | 4284 | |
Willy Tarreau | 8293658 | 2007-11-30 15:20:09 +0100 | [diff] [blame] | 4285 | if ((curproxy->options & PR_O_DISABLE404) && !(curproxy->options & PR_O_HTTP_CHK)) { |
| 4286 | curproxy->options &= ~PR_O_DISABLE404; |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 4287 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n", |
| 4288 | "disable-on-404", proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 4289 | err_code |= ERR_WARN; |
Willy Tarreau | 8293658 | 2007-11-30 15:20:09 +0100 | [diff] [blame] | 4290 | } |
| 4291 | |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 4292 | /* if a default backend was specified, let's find it */ |
| 4293 | if (curproxy->defbe.name) { |
| 4294 | struct proxy *target; |
| 4295 | |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 4296 | target = findproxy_mode(curproxy->defbe.name, curproxy->mode, PR_CAP_BE); |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 4297 | if (!target) { |
| 4298 | Alert("Proxy '%s': unable to find required default_backend: '%s'.\n", |
| 4299 | curproxy->id, curproxy->defbe.name); |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 4300 | cfgerr++; |
| 4301 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 4302 | Alert("Proxy '%s': loop detected for default_backend: '%s'.\n", |
| 4303 | curproxy->id, curproxy->defbe.name); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 4304 | cfgerr++; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 4305 | } else { |
| 4306 | free(curproxy->defbe.name); |
| 4307 | curproxy->defbe.be = target; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 4308 | /* we force the backend to be present on at least all of |
| 4309 | * the frontend's processes. |
| 4310 | */ |
| 4311 | target->bind_proc = curproxy->bind_proc ? |
| 4312 | (target->bind_proc | curproxy->bind_proc) : 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4313 | } |
| 4314 | } |
| 4315 | |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 4316 | /* find the target proxy in setbe */ |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 4317 | if (curproxy->mode == PR_MODE_HTTP && curproxy->req_exp != NULL) { |
| 4318 | /* map jump target for ACT_SETBE in req_rep chain */ |
| 4319 | struct hdr_exp *exp; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 4320 | for (exp = curproxy->req_exp; exp != NULL; exp = exp->next) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 4321 | struct proxy *target; |
| 4322 | |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 4323 | if (exp->action != ACT_SETBE) |
| 4324 | continue; |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 4325 | |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 4326 | target = findproxy_mode(exp->replace, PR_MODE_HTTP, PR_CAP_BE); |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 4327 | if (!target) { |
| 4328 | Alert("Proxy '%s': unable to find required setbe: '%s'.\n", |
| 4329 | curproxy->id, exp->replace); |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 4330 | cfgerr++; |
| 4331 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 4332 | Alert("Proxy '%s': loop detected for setbe: '%s'.\n", |
| 4333 | curproxy->id, exp->replace); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4334 | cfgerr++; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 4335 | } else { |
| 4336 | free((void *)exp->replace); |
| 4337 | exp->replace = (const char *)target; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 4338 | /* we force the backend to be present on at least all of |
| 4339 | * the frontend's processes. |
| 4340 | */ |
| 4341 | target->bind_proc = curproxy->bind_proc ? |
| 4342 | (target->bind_proc | curproxy->bind_proc) : 0; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 4343 | } |
| 4344 | } |
| 4345 | } |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 4346 | |
| 4347 | /* find the target proxy for 'use_backend' rules */ |
| 4348 | list_for_each_entry(rule, &curproxy->switching_rules, list) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 4349 | struct proxy *target; |
| 4350 | |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 4351 | target = findproxy_mode(rule->be.name, curproxy->mode, PR_CAP_BE); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 4352 | |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 4353 | if (!target) { |
| 4354 | Alert("Proxy '%s': unable to find required use_backend: '%s'.\n", |
| 4355 | curproxy->id, rule->be.name); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 4356 | cfgerr++; |
| 4357 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 4358 | Alert("Proxy '%s': loop detected for use_backend: '%s'.\n", |
| 4359 | curproxy->id, rule->be.name); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 4360 | cfgerr++; |
| 4361 | } else { |
| 4362 | free((void *)rule->be.name); |
| 4363 | rule->be.backend = target; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 4364 | /* we force the backend to be present on at least all of |
| 4365 | * the frontend's processes. |
| 4366 | */ |
| 4367 | target->bind_proc = curproxy->bind_proc ? |
| 4368 | (target->bind_proc | curproxy->bind_proc) : 0; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 4369 | } |
| 4370 | } |
| 4371 | |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 4372 | if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) && |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 4373 | (((curproxy->cap & PR_CAP_FE) && !curproxy->timeout.client) || |
Willy Tarreau | d825eef | 2007-05-12 22:35:00 +0200 | [diff] [blame] | 4374 | ((curproxy->cap & PR_CAP_BE) && (curproxy->srv) && |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 4375 | (!curproxy->timeout.connect || !curproxy->timeout.server)))) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 4376 | Warning("config : missing timeouts for %s '%s'.\n" |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 4377 | " | While not properly invalid, you will certainly encounter various problems\n" |
| 4378 | " | with such a configuration. To fix this, please ensure that all following\n" |
Willy Tarreau | 0f68eac | 2008-01-20 23:25:06 +0100 | [diff] [blame] | 4379 | " | timeouts are set to a non-zero value: 'client', 'connect', 'server'.\n", |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 4380 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 4381 | err_code |= ERR_WARN; |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 4382 | } |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 4383 | |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 4384 | /* Historically, the tarpit and queue timeouts were inherited from contimeout. |
| 4385 | * We must still support older configurations, so let's find out whether those |
| 4386 | * parameters have been set or must be copied from contimeouts. |
| 4387 | */ |
| 4388 | if (curproxy != &defproxy) { |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 4389 | if (!curproxy->timeout.tarpit || |
| 4390 | curproxy->timeout.tarpit == defproxy.timeout.tarpit) { |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 4391 | /* tarpit timeout not set. We search in the following order: |
| 4392 | * default.tarpit, curr.connect, default.connect. |
| 4393 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 4394 | if (defproxy.timeout.tarpit) |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 4395 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 4396 | else if (curproxy->timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 4397 | curproxy->timeout.tarpit = curproxy->timeout.connect; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 4398 | else if (defproxy.timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 4399 | curproxy->timeout.tarpit = defproxy.timeout.connect; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 4400 | } |
| 4401 | if ((curproxy->cap & PR_CAP_BE) && |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 4402 | (!curproxy->timeout.queue || |
| 4403 | curproxy->timeout.queue == defproxy.timeout.queue)) { |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 4404 | /* queue timeout not set. We search in the following order: |
| 4405 | * default.queue, curr.connect, default.connect. |
| 4406 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 4407 | if (defproxy.timeout.queue) |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 4408 | curproxy->timeout.queue = defproxy.timeout.queue; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 4409 | else if (curproxy->timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 4410 | curproxy->timeout.queue = curproxy->timeout.connect; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 4411 | else if (defproxy.timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 4412 | curproxy->timeout.queue = defproxy.timeout.connect; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 4413 | } |
| 4414 | } |
| 4415 | |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 4416 | if (curproxy->options & PR_O_SSL3_CHK) { |
| 4417 | curproxy->check_len = sizeof(sslv3_client_hello_pkt); |
| 4418 | curproxy->check_req = (char *)malloc(sizeof(sslv3_client_hello_pkt)); |
| 4419 | memcpy(curproxy->check_req, sslv3_client_hello_pkt, sizeof(sslv3_client_hello_pkt)); |
| 4420 | } |
| 4421 | |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 4422 | /* The small pools required for the capture lists */ |
| 4423 | if (curproxy->nb_req_cap) |
| 4424 | curproxy->req_cap_pool = create_pool("ptrcap", |
| 4425 | curproxy->nb_req_cap * sizeof(char *), |
| 4426 | MEM_F_SHARED); |
| 4427 | if (curproxy->nb_rsp_cap) |
| 4428 | curproxy->rsp_cap_pool = create_pool("ptrcap", |
| 4429 | curproxy->nb_rsp_cap * sizeof(char *), |
| 4430 | MEM_F_SHARED); |
| 4431 | |
Willy Tarreau | 1d4154a | 2007-05-13 22:57:02 +0200 | [diff] [blame] | 4432 | curproxy->hdr_idx_pool = create_pool("hdr_idx", |
| 4433 | MAX_HTTP_HDR * sizeof(struct hdr_idx_elem), |
| 4434 | MEM_F_SHARED); |
| 4435 | |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 4436 | /* for backwards compatibility with "listen" instances, if |
| 4437 | * fullconn is not set but maxconn is set, then maxconn |
| 4438 | * is used. |
| 4439 | */ |
| 4440 | if (!curproxy->fullconn) |
| 4441 | curproxy->fullconn = curproxy->maxconn; |
| 4442 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4443 | /* first, we will invert the servers list order */ |
| 4444 | newsrv = NULL; |
| 4445 | while (curproxy->srv) { |
| 4446 | struct server *next; |
| 4447 | |
| 4448 | next = curproxy->srv->next; |
| 4449 | curproxy->srv->next = newsrv; |
| 4450 | newsrv = curproxy->srv; |
| 4451 | if (!next) |
| 4452 | break; |
| 4453 | curproxy->srv = next; |
| 4454 | } |
| 4455 | |
Willy Tarreau | 2069704 | 2007-11-15 23:26:18 +0100 | [diff] [blame] | 4456 | curproxy->lbprm.wmult = 1; /* default weight multiplier */ |
Willy Tarreau | 5dc2fa6 | 2007-11-19 19:10:18 +0100 | [diff] [blame] | 4457 | curproxy->lbprm.wdiv = 1; /* default weight divider */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4458 | |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 4459 | /* We have to initialize the server lookup mechanism depending |
| 4460 | * on what LB algorithm was choosen. |
| 4461 | */ |
| 4462 | |
| 4463 | curproxy->lbprm.algo &= ~(BE_LB_LKUP | BE_LB_PROP_DYN); |
| 4464 | switch (curproxy->lbprm.algo & BE_LB_KIND) { |
| 4465 | case BE_LB_KIND_RR: |
Willy Tarreau | 9757a38 | 2009-10-03 12:56:50 +0200 | [diff] [blame] | 4466 | if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_RR_STATIC) { |
| 4467 | curproxy->lbprm.algo |= BE_LB_LKUP_MAP; |
| 4468 | init_server_map(curproxy); |
| 4469 | } else { |
| 4470 | curproxy->lbprm.algo |= BE_LB_LKUP_RRTREE | BE_LB_PROP_DYN; |
| 4471 | fwrr_init_server_groups(curproxy); |
| 4472 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 4473 | break; |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 4474 | |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 4475 | case BE_LB_KIND_LC: |
| 4476 | curproxy->lbprm.algo |= BE_LB_LKUP_LCTREE | BE_LB_PROP_DYN; |
Willy Tarreau | 5140623 | 2008-03-10 22:04:20 +0100 | [diff] [blame] | 4477 | fwlc_init_server_tree(curproxy); |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 4478 | break; |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 4479 | |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 4480 | case BE_LB_KIND_HI: |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 4481 | if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS) { |
| 4482 | curproxy->lbprm.algo |= BE_LB_LKUP_CHTREE | BE_LB_PROP_DYN; |
| 4483 | chash_init_server_tree(curproxy); |
| 4484 | } else { |
| 4485 | curproxy->lbprm.algo |= BE_LB_LKUP_MAP; |
| 4486 | init_server_map(curproxy); |
| 4487 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 4488 | break; |
| 4489 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4490 | |
| 4491 | if (curproxy->options & PR_O_LOGASAP) |
| 4492 | curproxy->to_log &= ~LW_BYTES; |
| 4493 | |
Willy Tarreau | e7ded1f | 2009-08-09 10:11:45 +0200 | [diff] [blame] | 4494 | if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) && |
| 4495 | (curproxy->cap & PR_CAP_FE) && curproxy->to_log && curproxy->logfac1 < 0) { |
| 4496 | Warning("config : log format ignored for %s '%s' since it has no log address.\n", |
| 4497 | proxy_type_str(curproxy), curproxy->id); |
| 4498 | err_code |= ERR_WARN; |
| 4499 | } |
| 4500 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4501 | /* |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 4502 | * ensure that we're not cross-dressing a TCP server into HTTP. |
| 4503 | */ |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 4504 | next_id = 1; |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 4505 | newsrv = curproxy->srv; |
| 4506 | while (newsrv != NULL) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 4507 | if (!newsrv->puid) { |
| 4508 | /* server ID not set, use automatic numbering with first |
| 4509 | * spare entry starting with next_svid. |
| 4510 | */ |
| 4511 | next_id = get_next_id(&curproxy->conf.used_server_id, next_id); |
| 4512 | newsrv->conf.id.key = newsrv->puid = next_id; |
| 4513 | eb32_insert(&curproxy->conf.used_server_id, &newsrv->conf.id); |
| 4514 | next_id++; |
| 4515 | } |
| 4516 | |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 4517 | if ((curproxy->mode != PR_MODE_HTTP) && (newsrv->rdr_len || newsrv->cklen)) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 4518 | Alert("config : %s '%s' : server cannot have cookie or redirect prefix in non-HTTP mode.\n", |
| 4519 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 4520 | cfgerr++; |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 4521 | } |
| 4522 | newsrv = newsrv->next; |
| 4523 | } |
| 4524 | |
| 4525 | /* |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4526 | * If this server supports a maxconn parameter, it needs a dedicated |
| 4527 | * tasks to fill the emptied slots when a connection leaves. |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4528 | * Also, resolve deferred tracking dependency if needed. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4529 | */ |
| 4530 | newsrv = curproxy->srv; |
| 4531 | while (newsrv != NULL) { |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 4532 | if (newsrv->minconn > newsrv->maxconn) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4533 | /* Only 'minconn' was specified, or it was higher than or equal |
| 4534 | * to 'maxconn'. Let's turn this into maxconn and clean it, as |
| 4535 | * this will avoid further useless expensive computations. |
| 4536 | */ |
| 4537 | newsrv->maxconn = newsrv->minconn; |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 4538 | } else if (newsrv->maxconn && !newsrv->minconn) { |
| 4539 | /* minconn was not specified, so we set it to maxconn */ |
| 4540 | newsrv->minconn = newsrv->maxconn; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4541 | } else if (newsrv->minconn != newsrv->maxconn && !curproxy->fullconn) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 4542 | Alert("config : %s '%s' : fullconn is mandatory when minconn is set on a server.\n", |
| 4543 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 4544 | cfgerr++; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4545 | } |
| 4546 | |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4547 | if (newsrv->trackit) { |
| 4548 | struct proxy *px; |
| 4549 | struct server *srv; |
| 4550 | char *pname, *sname; |
| 4551 | |
| 4552 | pname = newsrv->trackit; |
| 4553 | sname = strrchr(pname, '/'); |
| 4554 | |
| 4555 | if (sname) |
| 4556 | *sname++ = '\0'; |
| 4557 | else { |
| 4558 | sname = pname; |
| 4559 | pname = NULL; |
| 4560 | } |
| 4561 | |
| 4562 | if (pname) { |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 4563 | px = findproxy(pname, PR_CAP_BE); |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4564 | if (!px) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 4565 | Alert("config : %s '%s', server '%s': unable to find required proxy '%s' for tracking.\n", |
| 4566 | proxy_type_str(curproxy), curproxy->id, |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4567 | newsrv->id, pname); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 4568 | cfgerr++; |
| 4569 | goto next_srv; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4570 | } |
| 4571 | } else |
| 4572 | px = curproxy; |
| 4573 | |
| 4574 | srv = findserver(px, sname); |
| 4575 | if (!srv) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 4576 | Alert("config : %s '%s', server '%s': unable to find required server '%s' for tracking.\n", |
| 4577 | proxy_type_str(curproxy), curproxy->id, |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4578 | newsrv->id, sname); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 4579 | cfgerr++; |
| 4580 | goto next_srv; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4581 | } |
| 4582 | |
| 4583 | if (!(srv->state & SRV_CHECKED)) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 4584 | Alert("config : %s '%s', server '%s': unable to use %s/%s for " |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 4585 | "tracking as it does not have checks enabled.\n", |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 4586 | proxy_type_str(curproxy), curproxy->id, |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4587 | newsrv->id, px->id, srv->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 4588 | cfgerr++; |
| 4589 | goto next_srv; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4590 | } |
| 4591 | |
| 4592 | if (curproxy != px && |
| 4593 | (curproxy->options & PR_O_DISABLE404) != (px->options & PR_O_DISABLE404)) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 4594 | Alert("config : %s '%s', server '%s': unable to use %s/%s for" |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4595 | "tracing: disable-on-404 option inconsistency.\n", |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 4596 | proxy_type_str(curproxy), curproxy->id, |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4597 | newsrv->id, px->id, srv->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 4598 | cfgerr++; |
| 4599 | goto next_srv; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4600 | } |
| 4601 | |
| 4602 | newsrv->tracked = srv; |
| 4603 | newsrv->tracknext = srv->tracknext; |
| 4604 | srv->tracknext = newsrv; |
| 4605 | |
| 4606 | free(newsrv->trackit); |
| 4607 | } |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 4608 | next_srv: |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4609 | newsrv = newsrv->next; |
| 4610 | } |
| 4611 | |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 4612 | if (curproxy->cap & PR_CAP_FE) { |
| 4613 | if (curproxy->tcp_req.inspect_delay || |
| 4614 | !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules)) |
| 4615 | curproxy->fe_req_ana |= AN_REQ_INSPECT; |
| 4616 | |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 4617 | if (curproxy->mode == PR_MODE_HTTP) { |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 4618 | curproxy->fe_req_ana |= AN_REQ_WAIT_HTTP | AN_REQ_HTTP_PROCESS_FE; |
Willy Tarreau | b37c27e | 2009-10-18 22:53:08 +0200 | [diff] [blame] | 4619 | curproxy->fe_rsp_ana |= AN_RES_WAIT_HTTP | AN_RES_HTTP_PROCESS_FE; |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 4620 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 4621 | |
| 4622 | /* both TCP and HTTP must check switching rules */ |
| 4623 | curproxy->fe_req_ana |= AN_REQ_SWITCHING_RULES; |
| 4624 | } |
| 4625 | |
| 4626 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 4627 | if (curproxy->mode == PR_MODE_HTTP) { |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 4628 | curproxy->be_req_ana |= AN_REQ_WAIT_HTTP | AN_REQ_HTTP_INNER | AN_REQ_HTTP_PROCESS_BE; |
Willy Tarreau | b37c27e | 2009-10-18 22:53:08 +0200 | [diff] [blame] | 4629 | curproxy->be_rsp_ana |= AN_RES_WAIT_HTTP | AN_RES_HTTP_PROCESS_BE; |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 4630 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 4631 | |
| 4632 | /* If the backend does requires RDP cookie persistence, we have to |
| 4633 | * enable the corresponding analyser. |
| 4634 | */ |
| 4635 | if (curproxy->options2 & PR_O2_RDPC_PRST) |
| 4636 | curproxy->be_req_ana |= AN_REQ_PRST_RDP_COOKIE; |
| 4637 | } |
| 4638 | |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 4639 | listener = NULL; |
| 4640 | while (curproxy->listen) { |
| 4641 | struct listener *next; |
| 4642 | |
| 4643 | next = curproxy->listen->next; |
| 4644 | curproxy->listen->next = listener; |
| 4645 | listener = curproxy->listen; |
| 4646 | |
| 4647 | if (!next) |
| 4648 | break; |
| 4649 | |
| 4650 | curproxy->listen = next; |
| 4651 | } |
| 4652 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 4653 | /* adjust this proxy's listeners */ |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 4654 | next_id = 1; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 4655 | listener = curproxy->listen; |
| 4656 | while (listener) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 4657 | if (!listener->luid) { |
| 4658 | /* listener ID not set, use automatic numbering with first |
| 4659 | * spare entry starting with next_luid. |
| 4660 | */ |
| 4661 | next_id = get_next_id(&curproxy->conf.used_listener_id, next_id); |
| 4662 | listener->conf.id.key = listener->luid = next_id; |
| 4663 | eb32_insert(&curproxy->conf.used_listener_id, &listener->conf.id); |
| 4664 | next_id++; |
| 4665 | } |
| 4666 | |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 4667 | /* enable separate counters */ |
| 4668 | if (curproxy->options2 & PR_O2_SOCKSTAT) { |
| 4669 | listener->counters = (struct licounters *)calloc(1, sizeof(struct licounters)); |
| 4670 | if (!listener->name) { |
| 4671 | sprintf(trash, "sock-%d", listener->luid); |
| 4672 | listener->name = strdup(trash); |
| 4673 | } |
| 4674 | } |
| 4675 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 4676 | if (curproxy->options & PR_O_TCP_NOLING) |
| 4677 | listener->options |= LI_O_NOLINGER; |
| 4678 | listener->maxconn = curproxy->maxconn; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 4679 | listener->backlog = curproxy->backlog; |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 4680 | listener->timeout = &curproxy->timeout.client; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 4681 | listener->accept = event_accept; |
| 4682 | listener->private = curproxy; |
Willy Tarreau | 3bc1377 | 2008-12-07 11:50:35 +0100 | [diff] [blame] | 4683 | listener->handler = process_session; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 4684 | listener->analysers |= curproxy->fe_req_ana; |
Willy Tarreau | 3bc1377 | 2008-12-07 11:50:35 +0100 | [diff] [blame] | 4685 | |
Willy Tarreau | 9ea05a7 | 2009-06-14 12:07:01 +0200 | [diff] [blame] | 4686 | /* smart accept mode is automatic in HTTP mode */ |
| 4687 | if ((curproxy->options2 & PR_O2_SMARTACC) || |
| 4688 | (curproxy->mode == PR_MODE_HTTP && |
| 4689 | !(curproxy->no_options2 & PR_O2_SMARTACC))) |
| 4690 | listener->options |= LI_O_NOQUICKACK; |
| 4691 | |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 4692 | /* We want the use_backend and default_backend rules to apply */ |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 4693 | listener = listener->next; |
| 4694 | } |
| 4695 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4696 | curproxy = curproxy->next; |
| 4697 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 4698 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 4699 | /* |
| 4700 | * Recount currently required checks. |
| 4701 | */ |
| 4702 | |
| 4703 | for (curproxy=proxy; curproxy; curproxy=curproxy->next) { |
| 4704 | int optnum; |
| 4705 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 4706 | for (optnum = 0; cfg_opts[optnum].name; optnum++) |
| 4707 | if (curproxy->options & cfg_opts[optnum].val) |
| 4708 | global.last_checks |= cfg_opts[optnum].checks; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 4709 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 4710 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) |
| 4711 | if (curproxy->options2 & cfg_opts2[optnum].val) |
| 4712 | global.last_checks |= cfg_opts2[optnum].checks; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 4713 | } |
| 4714 | |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 4715 | if (cfgerr > 0) |
| 4716 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4717 | out: |
| 4718 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4719 | } |
| 4720 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 4721 | /* |
| 4722 | * Registers the CFG keyword list <kwl> as a list of valid keywords for next |
| 4723 | * parsing sessions. |
| 4724 | */ |
| 4725 | void cfg_register_keywords(struct cfg_kw_list *kwl) |
| 4726 | { |
| 4727 | LIST_ADDQ(&cfg_keywords.list, &kwl->list); |
| 4728 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4729 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 4730 | /* |
| 4731 | * Unregisters the CFG keyword list <kwl> from the list of valid keywords. |
| 4732 | */ |
| 4733 | void cfg_unregister_keywords(struct cfg_kw_list *kwl) |
| 4734 | { |
| 4735 | LIST_DEL(&kwl->list); |
| 4736 | LIST_INIT(&kwl->list); |
| 4737 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4738 | |
| 4739 | /* |
| 4740 | * Local variables: |
| 4741 | * c-indent-level: 8 |
| 4742 | * c-basic-offset: 8 |
| 4743 | * End: |
| 4744 | */ |