Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Configuration parser |
| 3 | * |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 4 | * Copyright 2000-2010 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> |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 40 | #include <proto/auth.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 41 | #include <proto/backend.h> |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 42 | #include <proto/buffers.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 43 | #include <proto/checks.h> |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 44 | #include <proto/dumpstats.h> |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 45 | #include <proto/frontend.h> |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 46 | #include <proto/httperr.h> |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 47 | #include <proto/lb_chash.h> |
Willy Tarreau | f89c187 | 2009-10-01 11:19:37 +0200 | [diff] [blame] | 48 | #include <proto/lb_fwlc.h> |
| 49 | #include <proto/lb_fwrr.h> |
| 50 | #include <proto/lb_map.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 51 | #include <proto/log.h> |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 52 | #include <proto/pattern.h> |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 53 | #include <proto/port_range.h> |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 54 | #include <proto/protocols.h> |
| 55 | #include <proto/proto_tcp.h> |
| 56 | #include <proto/proto_http.h> |
Willy Tarreau | 2b5652f | 2006-12-31 17:46:05 +0100 | [diff] [blame] | 57 | #include <proto/proxy.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 58 | #include <proto/server.h> |
Willy Tarreau | 3bc1377 | 2008-12-07 11:50:35 +0100 | [diff] [blame] | 59 | #include <proto/session.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 60 | #include <proto/task.h> |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 61 | #include <proto/stick_table.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 62 | |
| 63 | |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 64 | /* This is the SSLv3 CLIENT HELLO packet used in conjunction with the |
| 65 | * ssl-hello-chk option to ensure that the remote server speaks SSL. |
| 66 | * |
| 67 | * Check RFC 2246 (TLSv1.0) sections A.3 and A.4 for details. |
| 68 | */ |
| 69 | const char sslv3_client_hello_pkt[] = { |
| 70 | "\x16" /* ContentType : 0x16 = Hanshake */ |
| 71 | "\x03\x00" /* ProtocolVersion : 0x0300 = SSLv3 */ |
| 72 | "\x00\x79" /* ContentLength : 0x79 bytes after this one */ |
| 73 | "\x01" /* HanshakeType : 0x01 = CLIENT HELLO */ |
| 74 | "\x00\x00\x75" /* HandshakeLength : 0x75 bytes after this one */ |
| 75 | "\x03\x00" /* Hello Version : 0x0300 = v3 */ |
| 76 | "\x00\x00\x00\x00" /* Unix GMT Time (s) : filled with <now> (@0x0B) */ |
| 77 | "HAPROXYSSLCHK\nHAPROXYSSLCHK\n" /* Random : must be exactly 28 bytes */ |
| 78 | "\x00" /* Session ID length : empty (no session ID) */ |
| 79 | "\x00\x4E" /* Cipher Suite Length : 78 bytes after this one */ |
| 80 | "\x00\x01" "\x00\x02" "\x00\x03" "\x00\x04" /* 39 most common ciphers : */ |
| 81 | "\x00\x05" "\x00\x06" "\x00\x07" "\x00\x08" /* 0x01...0x1B, 0x2F...0x3A */ |
| 82 | "\x00\x09" "\x00\x0A" "\x00\x0B" "\x00\x0C" /* This covers RSA/DH, */ |
| 83 | "\x00\x0D" "\x00\x0E" "\x00\x0F" "\x00\x10" /* various bit lengths, */ |
| 84 | "\x00\x11" "\x00\x12" "\x00\x13" "\x00\x14" /* SHA1/MD5, DES/3DES/AES... */ |
| 85 | "\x00\x15" "\x00\x16" "\x00\x17" "\x00\x18" |
| 86 | "\x00\x19" "\x00\x1A" "\x00\x1B" "\x00\x2F" |
| 87 | "\x00\x30" "\x00\x31" "\x00\x32" "\x00\x33" |
| 88 | "\x00\x34" "\x00\x35" "\x00\x36" "\x00\x37" |
| 89 | "\x00\x38" "\x00\x39" "\x00\x3A" |
| 90 | "\x01" /* Compression Length : 0x01 = 1 byte for types */ |
| 91 | "\x00" /* Compression Type : 0x00 = NULL compression */ |
| 92 | }; |
| 93 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 94 | /* various keyword modifiers */ |
| 95 | enum kw_mod { |
| 96 | KWM_STD = 0, /* normal */ |
| 97 | KWM_NO, /* "no" prefixed before the keyword */ |
| 98 | KWM_DEF, /* "default" prefixed before the keyword */ |
| 99 | }; |
| 100 | |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 101 | /* 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] | 102 | struct cfg_opt { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 103 | const char *name; |
| 104 | unsigned int val; |
| 105 | unsigned int cap; |
Willy Tarreau | 4fee4e9 | 2007-01-06 21:09:17 +0100 | [diff] [blame] | 106 | unsigned int checks; |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 107 | unsigned int mode; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 108 | }; |
| 109 | |
| 110 | /* proxy->options */ |
| 111 | static const struct cfg_opt cfg_opts[] = |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 112 | { |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 113 | { "abortonclose", PR_O_ABRT_CLOSE, PR_CAP_BE, 0, 0 }, |
| 114 | { "allbackups", PR_O_USE_ALL_BK, PR_CAP_BE, 0, 0 }, |
| 115 | { "checkcache", PR_O_CHK_CACHE, PR_CAP_BE, 0, PR_MODE_HTTP }, |
| 116 | { "clitcpka", PR_O_TCP_CLI_KA, PR_CAP_FE, 0, 0 }, |
| 117 | { "contstats", PR_O_CONTSTATS, PR_CAP_FE, 0, 0 }, |
| 118 | { "dontlognull", PR_O_NULLNOLOG, PR_CAP_FE, 0, 0 }, |
| 119 | { "forceclose", PR_O_FORCE_CLO, PR_CAP_FE | PR_CAP_BE, 0, PR_MODE_HTTP }, |
| 120 | { "http_proxy", PR_O_HTTP_PROXY, PR_CAP_FE | PR_CAP_BE, 0, PR_MODE_HTTP }, |
| 121 | { "httpclose", PR_O_HTTP_CLOSE, PR_CAP_FE | PR_CAP_BE, 0, PR_MODE_HTTP }, |
| 122 | { "keepalive", PR_O_KEEPALIVE, PR_CAP_NONE, 0, PR_MODE_HTTP }, |
| 123 | { "http-server-close", PR_O_SERVER_CLO, PR_CAP_FE | PR_CAP_BE, 0, PR_MODE_HTTP }, |
| 124 | { "logasap", PR_O_LOGASAP, PR_CAP_FE, 0, 0 }, |
| 125 | { "nolinger", PR_O_TCP_NOLING, PR_CAP_FE | PR_CAP_BE, 0, 0 }, |
| 126 | { "persist", PR_O_PERSIST, PR_CAP_BE, 0, 0 }, |
| 127 | { "redispatch", PR_O_REDISP, PR_CAP_BE, 0, 0 }, |
| 128 | { "srvtcpka", PR_O_TCP_SRV_KA, PR_CAP_BE, 0, 0 }, |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 129 | #ifdef TPROXY |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 130 | { "transparent", PR_O_TRANSP, PR_CAP_BE, 0, 0 }, |
Willy Tarreau | 8f922fc | 2007-01-06 21:11:49 +0100 | [diff] [blame] | 131 | #endif |
| 132 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 133 | { NULL, 0, 0, 0, 0 } |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 134 | }; |
| 135 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 136 | /* proxy->options2 */ |
| 137 | static const struct cfg_opt cfg_opts2[] = |
| 138 | { |
| 139 | #ifdef CONFIG_HAP_LINUX_SPLICE |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 140 | { "splice-request", PR_O2_SPLIC_REQ, PR_CAP_FE|PR_CAP_BE, 0, 0 }, |
| 141 | { "splice-response", PR_O2_SPLIC_RTR, PR_CAP_FE|PR_CAP_BE, 0, 0 }, |
| 142 | { "splice-auto", PR_O2_SPLIC_AUT, PR_CAP_FE|PR_CAP_BE, 0, 0 }, |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 143 | #endif |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 144 | { "accept-invalid-http-request", PR_O2_REQBUG_OK, PR_CAP_FE, 0, PR_MODE_HTTP }, |
| 145 | { "accept-invalid-http-response", PR_O2_RSPBUG_OK, PR_CAP_BE, 0, PR_MODE_HTTP }, |
| 146 | { "dontlog-normal", PR_O2_NOLOGNORM, PR_CAP_FE, 0, 0 }, |
| 147 | { "log-separate-errors", PR_O2_LOGERRORS, PR_CAP_FE, 0, 0 }, |
| 148 | { "log-health-checks", PR_O2_LOGHCHKS, PR_CAP_BE, 0, 0 }, |
| 149 | { "socket-stats", PR_O2_SOCKSTAT, PR_CAP_FE, 0, 0 }, |
| 150 | { "tcp-smart-accept", PR_O2_SMARTACC, PR_CAP_FE, 0, 0 }, |
| 151 | { "tcp-smart-connect", PR_O2_SMARTCON, PR_CAP_BE, 0, 0 }, |
| 152 | { "independant-streams", PR_O2_INDEPSTR, PR_CAP_FE|PR_CAP_BE, 0, 0 }, |
| 153 | { "http-use-proxy-header", PR_O2_USE_PXHDR, PR_CAP_FE, 0, PR_MODE_HTTP }, |
Willy Tarreau | e52564c | 2010-04-27 22:19:14 +0200 | [diff] [blame] | 154 | { "http-pretend-keepalive", PR_O2_FAKE_KA, PR_CAP_FE|PR_CAP_BE, 0, PR_MODE_HTTP }, |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 155 | { NULL, 0, 0, 0 } |
| 156 | }; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 157 | |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 158 | static char *cursection = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 159 | static struct proxy defproxy; /* fake proxy used to assign default values on all instances */ |
| 160 | int cfg_maxpconn = DEFAULT_MAXCONN; /* # of simultaneous connections per proxy (-N) */ |
Willy Tarreau | 5af24ef | 2009-03-15 15:23:16 +0100 | [diff] [blame] | 161 | int cfg_maxconn = 0; /* # of simultaneous connections, (-n) */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 162 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 163 | /* List head of all known configuration keywords */ |
| 164 | static struct cfg_kw_list cfg_keywords = { |
| 165 | .list = LIST_HEAD_INIT(cfg_keywords.list) |
| 166 | }; |
| 167 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 168 | /* |
| 169 | * converts <str> to a list of listeners which are dynamically allocated. |
| 170 | * The format is "{addr|'*'}:port[-end][,{addr|'*'}:port[-end]]*", where : |
| 171 | * - <addr> can be empty or "*" to indicate INADDR_ANY ; |
| 172 | * - <port> is a numerical port from 1 to 65535 ; |
| 173 | * - <end> indicates to use the range from <port> to <end> instead (inclusive). |
| 174 | * 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] | 175 | * Function returns 1 for success or 0 if error. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 176 | */ |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 177 | static int str2listener(char *str, struct proxy *curproxy) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 178 | { |
| 179 | struct listener *l; |
| 180 | char *c, *next, *range, *dupstr; |
| 181 | int port, end; |
| 182 | |
| 183 | next = dupstr = strdup(str); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 184 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 185 | while (next && *next) { |
| 186 | struct sockaddr_storage ss; |
| 187 | |
| 188 | str = next; |
| 189 | /* 1) look for the end of the first address */ |
Krzysztof Piotr Oledzki | 52d522b | 2009-01-27 16:57:08 +0100 | [diff] [blame] | 190 | if ((next = strchr(str, ',')) != NULL) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 191 | *next++ = 0; |
| 192 | } |
| 193 | |
| 194 | /* 2) look for the addr/port delimiter, it's the last colon. */ |
| 195 | if ((range = strrchr(str, ':')) == NULL) { |
| 196 | Alert("Missing port number: '%s'\n", str); |
| 197 | goto fail; |
| 198 | } |
| 199 | |
| 200 | *range++ = 0; |
| 201 | |
| 202 | if (strrchr(str, ':') != NULL) { |
| 203 | /* IPv6 address contains ':' */ |
| 204 | memset(&ss, 0, sizeof(ss)); |
| 205 | ss.ss_family = AF_INET6; |
| 206 | |
| 207 | if (!inet_pton(ss.ss_family, str, &((struct sockaddr_in6 *)&ss)->sin6_addr)) { |
| 208 | Alert("Invalid server address: '%s'\n", str); |
| 209 | goto fail; |
| 210 | } |
| 211 | } |
| 212 | else { |
| 213 | memset(&ss, 0, sizeof(ss)); |
| 214 | ss.ss_family = AF_INET; |
| 215 | |
| 216 | if (*str == '*' || *str == '\0') { /* INADDR_ANY */ |
| 217 | ((struct sockaddr_in *)&ss)->sin_addr.s_addr = INADDR_ANY; |
| 218 | } |
| 219 | else if (!inet_pton(ss.ss_family, str, &((struct sockaddr_in *)&ss)->sin_addr)) { |
| 220 | struct hostent *he; |
| 221 | |
| 222 | if ((he = gethostbyname(str)) == NULL) { |
| 223 | Alert("Invalid server name: '%s'\n", str); |
| 224 | goto fail; |
| 225 | } |
| 226 | else |
| 227 | ((struct sockaddr_in *)&ss)->sin_addr = |
| 228 | *(struct in_addr *) *(he->h_addr_list); |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | /* 3) look for the port-end delimiter */ |
| 233 | if ((c = strchr(range, '-')) != NULL) { |
| 234 | *c++ = 0; |
| 235 | end = atol(c); |
| 236 | } |
| 237 | else { |
| 238 | end = atol(range); |
| 239 | } |
| 240 | |
| 241 | port = atol(range); |
| 242 | |
| 243 | if (port < 1 || port > 65535) { |
| 244 | Alert("Invalid port '%d' specified for address '%s'.\n", port, str); |
| 245 | goto fail; |
| 246 | } |
| 247 | |
| 248 | if (end < 1 || end > 65535) { |
| 249 | Alert("Invalid port '%d' specified for address '%s'.\n", end, str); |
| 250 | goto fail; |
| 251 | } |
| 252 | |
| 253 | for (; port <= end; port++) { |
| 254 | l = (struct listener *)calloc(1, sizeof(struct listener)); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 255 | l->next = curproxy->listen; |
| 256 | curproxy->listen = l; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 257 | |
| 258 | l->fd = -1; |
| 259 | l->addr = ss; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 260 | l->state = LI_INIT; |
| 261 | |
| 262 | if (ss.ss_family == AF_INET6) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 263 | ((struct sockaddr_in6 *)(&l->addr))->sin6_port = htons(port); |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 264 | tcpv6_add_listener(l); |
| 265 | } else { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 266 | ((struct sockaddr_in *)(&l->addr))->sin_port = htons(port); |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 267 | tcpv4_add_listener(l); |
| 268 | } |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 269 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 270 | listeners++; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 271 | } /* end for(port) */ |
| 272 | } /* end while(next) */ |
| 273 | free(dupstr); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 274 | return 1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 275 | fail: |
| 276 | free(dupstr); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 277 | return 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 278 | } |
| 279 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 280 | /* |
| 281 | * Sends a warning if proxy <proxy> does not have at least one of the |
| 282 | * capabilities in <cap>. An optionnal <hint> may be added at the end |
| 283 | * of the warning to help the user. Returns 1 if a warning was emitted |
| 284 | * or 0 if the condition is valid. |
| 285 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 286 | int warnifnotcap(struct proxy *proxy, int cap, const char *file, int line, const char *arg, const char *hint) |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 287 | { |
| 288 | char *msg; |
| 289 | |
| 290 | switch (cap) { |
| 291 | case PR_CAP_BE: msg = "no backend"; break; |
| 292 | case PR_CAP_FE: msg = "no frontend"; break; |
| 293 | case PR_CAP_RS: msg = "no ruleset"; break; |
| 294 | case PR_CAP_BE|PR_CAP_FE: msg = "neither frontend nor backend"; break; |
| 295 | default: msg = "not enough"; break; |
| 296 | } |
| 297 | |
| 298 | if (!(proxy->cap & cap)) { |
| 299 | 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] | 300 | file, line, arg, proxy_type_str(proxy), proxy->id, msg, hint ? hint : ""); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 301 | return 1; |
| 302 | } |
| 303 | return 0; |
| 304 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 305 | |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 306 | /* Report a warning if a rule is placed after a 'block' rule. |
| 307 | * Return 1 if the warning has been emitted, otherwise 0. |
| 308 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 309 | int warnif_rule_after_block(struct proxy *proxy, const char *file, int line, const char *arg) |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 310 | { |
| 311 | if (!LIST_ISEMPTY(&proxy->block_cond)) { |
| 312 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'block' rule will still be processed before.\n", |
| 313 | file, line, arg); |
| 314 | return 1; |
| 315 | } |
| 316 | return 0; |
| 317 | } |
| 318 | |
| 319 | /* Report a warning if a rule is placed after a reqrewrite rule. |
| 320 | * Return 1 if the warning has been emitted, otherwise 0. |
| 321 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 322 | int warnif_rule_after_reqxxx(struct proxy *proxy, const char *file, int line, const char *arg) |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 323 | { |
| 324 | if (proxy->req_exp) { |
| 325 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'reqxxx' rule will still be processed before.\n", |
| 326 | file, line, arg); |
| 327 | return 1; |
| 328 | } |
| 329 | return 0; |
| 330 | } |
| 331 | |
| 332 | /* Report a warning if a rule is placed after a reqadd rule. |
| 333 | * Return 1 if the warning has been emitted, otherwise 0. |
| 334 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 335 | int warnif_rule_after_reqadd(struct proxy *proxy, const char *file, int line, const char *arg) |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 336 | { |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 337 | if (!LIST_ISEMPTY(&proxy->req_add)) { |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 338 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'reqadd' rule will still be processed before.\n", |
| 339 | file, line, arg); |
| 340 | return 1; |
| 341 | } |
| 342 | return 0; |
| 343 | } |
| 344 | |
| 345 | /* Report a warning if a rule is placed after a redirect rule. |
| 346 | * Return 1 if the warning has been emitted, otherwise 0. |
| 347 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 348 | int warnif_rule_after_redirect(struct proxy *proxy, const char *file, int line, const char *arg) |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 349 | { |
| 350 | if (!LIST_ISEMPTY(&proxy->redirect_rules)) { |
| 351 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'redirect' rule will still be processed before.\n", |
| 352 | file, line, arg); |
| 353 | return 1; |
| 354 | } |
| 355 | return 0; |
| 356 | } |
| 357 | |
| 358 | /* Report a warning if a rule is placed after a 'use_backend' rule. |
| 359 | * Return 1 if the warning has been emitted, otherwise 0. |
| 360 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 361 | int warnif_rule_after_use_backend(struct proxy *proxy, const char *file, int line, const char *arg) |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 362 | { |
| 363 | if (!LIST_ISEMPTY(&proxy->switching_rules)) { |
| 364 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'use_backend' rule will still be processed before.\n", |
| 365 | file, line, arg); |
| 366 | return 1; |
| 367 | } |
| 368 | return 0; |
| 369 | } |
| 370 | |
| 371 | /* report a warning if a block rule is dangerously placed */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 372 | int warnif_misplaced_block(struct proxy *proxy, const char *file, int line, const char *arg) |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 373 | { |
| 374 | return warnif_rule_after_reqxxx(proxy, file, line, arg) || |
| 375 | warnif_rule_after_reqadd(proxy, file, line, arg) || |
| 376 | warnif_rule_after_redirect(proxy, file, line, arg) || |
| 377 | warnif_rule_after_use_backend(proxy, file, line, arg); |
| 378 | } |
| 379 | |
| 380 | /* report a warning if a reqxxx rule is dangerously placed */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 381 | int warnif_misplaced_reqxxx(struct proxy *proxy, const char *file, int line, const char *arg) |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 382 | { |
| 383 | return warnif_rule_after_reqadd(proxy, file, line, arg) || |
| 384 | warnif_rule_after_redirect(proxy, file, line, arg) || |
| 385 | warnif_rule_after_use_backend(proxy, file, line, arg); |
| 386 | } |
| 387 | |
| 388 | /* report a warning if a reqadd rule is dangerously placed */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 389 | int warnif_misplaced_reqadd(struct proxy *proxy, const char *file, int line, const char *arg) |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 390 | { |
| 391 | return warnif_rule_after_redirect(proxy, file, line, arg) || |
| 392 | warnif_rule_after_use_backend(proxy, file, line, arg); |
| 393 | } |
| 394 | |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 395 | /* Report it if a request ACL condition uses some response-only parameters. It |
| 396 | * returns either 0 or ERR_WARN so that its result can be or'ed with err_code. |
| 397 | * Note that <cond> may be NULL and then will be ignored. |
| 398 | */ |
| 399 | static int warnif_cond_requires_resp(const struct acl_cond *cond, const char *file, int line) |
| 400 | { |
| 401 | struct acl *acl; |
| 402 | |
| 403 | if (!cond || !(cond->requires & ACL_USE_RTR_ANY)) |
| 404 | return 0; |
| 405 | |
| 406 | acl = cond_find_require(cond, ACL_USE_RTR_ANY); |
| 407 | Warning("parsing [%s:%d] : acl '%s' involves some response-only criteria which will be ignored.\n", |
| 408 | file, line, acl ? acl->name : "(unknown)"); |
| 409 | return ERR_WARN; |
| 410 | } |
| 411 | |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 412 | /* Report it if a request ACL condition uses some request-only volatile parameters. |
| 413 | * It returns either 0 or ERR_WARN so that its result can be or'ed with err_code. |
| 414 | * Note that <cond> may be NULL and then will be ignored. |
| 415 | */ |
| 416 | static int warnif_cond_requires_req(const struct acl_cond *cond, const char *file, int line) |
| 417 | { |
| 418 | struct acl *acl; |
| 419 | |
| 420 | if (!cond || !(cond->requires & ACL_USE_REQ_VOLATILE)) |
| 421 | return 0; |
| 422 | |
| 423 | acl = cond_find_require(cond, ACL_USE_REQ_VOLATILE); |
| 424 | Warning("parsing [%s:%d] : acl '%s' involves some volatile request-only criteria which will be ignored.\n", |
| 425 | file, line, acl ? acl->name : "(unknown)"); |
| 426 | return ERR_WARN; |
| 427 | } |
| 428 | |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 429 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 430 | /* |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 431 | * parse a line in a <global> section. Returns the error code, 0 if OK, or |
| 432 | * any combination of : |
| 433 | * - ERR_ABORT: must abort ASAP |
| 434 | * - ERR_FATAL: we can continue parsing but not start the service |
| 435 | * - ERR_WARN: a warning has been emitted |
| 436 | * - ERR_ALERT: an alert has been emitted |
| 437 | * Only the two first ones can stop processing, the two others are just |
| 438 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 439 | */ |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 440 | 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] | 441 | { |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 442 | int err_code = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 443 | |
| 444 | if (!strcmp(args[0], "global")) { /* new section */ |
| 445 | /* no option, nothing special to do */ |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 446 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 447 | } |
| 448 | else if (!strcmp(args[0], "daemon")) { |
| 449 | global.mode |= MODE_DAEMON; |
| 450 | } |
| 451 | else if (!strcmp(args[0], "debug")) { |
| 452 | global.mode |= MODE_DEBUG; |
| 453 | } |
| 454 | else if (!strcmp(args[0], "noepoll")) { |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 455 | global.tune.options &= ~GTUNE_USE_EPOLL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 456 | } |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 457 | else if (!strcmp(args[0], "nosepoll")) { |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 458 | global.tune.options &= ~GTUNE_USE_SEPOLL; |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 459 | } |
| 460 | else if (!strcmp(args[0], "nokqueue")) { |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 461 | global.tune.options &= ~GTUNE_USE_KQUEUE; |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 462 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 463 | else if (!strcmp(args[0], "nopoll")) { |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 464 | global.tune.options &= ~GTUNE_USE_POLL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 465 | } |
Willy Tarreau | 3ab68cf | 2009-01-25 16:03:28 +0100 | [diff] [blame] | 466 | else if (!strcmp(args[0], "nosplice")) { |
| 467 | global.tune.options &= ~GTUNE_USE_SPLICE; |
| 468 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 469 | else if (!strcmp(args[0], "quiet")) { |
| 470 | global.mode |= MODE_QUIET; |
| 471 | } |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 472 | else if (!strcmp(args[0], "tune.maxpollevents")) { |
| 473 | if (global.tune.maxpollevents != 0) { |
| 474 | 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] | 475 | err_code |= ERR_ALERT; |
| 476 | goto out; |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 477 | } |
| 478 | if (*(args[1]) == 0) { |
| 479 | 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] | 480 | err_code |= ERR_ALERT | ERR_FATAL; |
| 481 | goto out; |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 482 | } |
| 483 | global.tune.maxpollevents = atol(args[1]); |
| 484 | } |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 485 | else if (!strcmp(args[0], "tune.maxaccept")) { |
| 486 | if (global.tune.maxaccept != 0) { |
| 487 | 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] | 488 | err_code |= ERR_ALERT; |
| 489 | goto out; |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 490 | } |
| 491 | if (*(args[1]) == 0) { |
| 492 | 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] | 493 | err_code |= ERR_ALERT | ERR_FATAL; |
| 494 | goto out; |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 495 | } |
| 496 | global.tune.maxaccept = atol(args[1]); |
| 497 | } |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 498 | else if (!strcmp(args[0], "tune.bufsize")) { |
| 499 | if (*(args[1]) == 0) { |
| 500 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 501 | err_code |= ERR_ALERT | ERR_FATAL; |
| 502 | goto out; |
| 503 | } |
| 504 | global.tune.bufsize = atol(args[1]); |
| 505 | if (global.tune.maxrewrite >= global.tune.bufsize / 2) |
| 506 | global.tune.maxrewrite = global.tune.bufsize / 2; |
| 507 | } |
| 508 | else if (!strcmp(args[0], "tune.maxrewrite")) { |
| 509 | if (*(args[1]) == 0) { |
| 510 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 511 | err_code |= ERR_ALERT | ERR_FATAL; |
| 512 | goto out; |
| 513 | } |
| 514 | global.tune.maxrewrite = atol(args[1]); |
| 515 | if (global.tune.maxrewrite >= global.tune.bufsize / 2) |
| 516 | global.tune.maxrewrite = global.tune.bufsize / 2; |
| 517 | } |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 518 | else if (!strcmp(args[0], "tune.rcvbuf.client")) { |
| 519 | if (global.tune.client_rcvbuf != 0) { |
| 520 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 521 | err_code |= ERR_ALERT; |
| 522 | goto out; |
| 523 | } |
| 524 | if (*(args[1]) == 0) { |
| 525 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 526 | err_code |= ERR_ALERT | ERR_FATAL; |
| 527 | goto out; |
| 528 | } |
| 529 | global.tune.client_rcvbuf = atol(args[1]); |
| 530 | } |
| 531 | else if (!strcmp(args[0], "tune.rcvbuf.server")) { |
| 532 | if (global.tune.server_rcvbuf != 0) { |
| 533 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 534 | err_code |= ERR_ALERT; |
| 535 | goto out; |
| 536 | } |
| 537 | if (*(args[1]) == 0) { |
| 538 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 539 | err_code |= ERR_ALERT | ERR_FATAL; |
| 540 | goto out; |
| 541 | } |
| 542 | global.tune.server_rcvbuf = atol(args[1]); |
| 543 | } |
| 544 | else if (!strcmp(args[0], "tune.sndbuf.client")) { |
| 545 | if (global.tune.client_sndbuf != 0) { |
| 546 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 547 | err_code |= ERR_ALERT; |
| 548 | goto out; |
| 549 | } |
| 550 | if (*(args[1]) == 0) { |
| 551 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 552 | err_code |= ERR_ALERT | ERR_FATAL; |
| 553 | goto out; |
| 554 | } |
| 555 | global.tune.client_sndbuf = atol(args[1]); |
| 556 | } |
| 557 | else if (!strcmp(args[0], "tune.sndbuf.server")) { |
| 558 | if (global.tune.server_sndbuf != 0) { |
| 559 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 560 | err_code |= ERR_ALERT; |
| 561 | goto out; |
| 562 | } |
| 563 | if (*(args[1]) == 0) { |
| 564 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 565 | err_code |= ERR_ALERT | ERR_FATAL; |
| 566 | goto out; |
| 567 | } |
| 568 | global.tune.server_sndbuf = atol(args[1]); |
| 569 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 570 | else if (!strcmp(args[0], "uid")) { |
| 571 | if (global.uid != 0) { |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 572 | Alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 573 | err_code |= ERR_ALERT; |
| 574 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 575 | } |
| 576 | if (*(args[1]) == 0) { |
| 577 | 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] | 578 | err_code |= ERR_ALERT | ERR_FATAL; |
| 579 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 580 | } |
| 581 | global.uid = atol(args[1]); |
| 582 | } |
| 583 | else if (!strcmp(args[0], "gid")) { |
| 584 | if (global.gid != 0) { |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 585 | Alert("parsing [%s:%d] : group/gid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 586 | err_code |= ERR_ALERT; |
| 587 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 588 | } |
| 589 | if (*(args[1]) == 0) { |
| 590 | 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] | 591 | err_code |= ERR_ALERT | ERR_FATAL; |
| 592 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 593 | } |
| 594 | global.gid = atol(args[1]); |
| 595 | } |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 596 | /* user/group name handling */ |
| 597 | else if (!strcmp(args[0], "user")) { |
| 598 | struct passwd *ha_user; |
| 599 | if (global.uid != 0) { |
| 600 | Alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 601 | err_code |= ERR_ALERT; |
| 602 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 603 | } |
| 604 | errno = 0; |
| 605 | ha_user = getpwnam(args[1]); |
| 606 | if (ha_user != NULL) { |
| 607 | global.uid = (int)ha_user->pw_uid; |
| 608 | } |
| 609 | else { |
| 610 | 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] | 611 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 612 | } |
| 613 | } |
| 614 | else if (!strcmp(args[0], "group")) { |
| 615 | struct group *ha_group; |
| 616 | if (global.gid != 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 617 | 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] | 618 | err_code |= ERR_ALERT; |
| 619 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 620 | } |
| 621 | errno = 0; |
| 622 | ha_group = getgrnam(args[1]); |
| 623 | if (ha_group != NULL) { |
| 624 | global.gid = (int)ha_group->gr_gid; |
| 625 | } |
| 626 | else { |
| 627 | 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] | 628 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 629 | } |
| 630 | } |
| 631 | /* end of user/group name handling*/ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 632 | else if (!strcmp(args[0], "nbproc")) { |
| 633 | if (global.nbproc != 0) { |
| 634 | 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] | 635 | err_code |= ERR_ALERT; |
| 636 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 637 | } |
| 638 | if (*(args[1]) == 0) { |
| 639 | 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] | 640 | err_code |= ERR_ALERT | ERR_FATAL; |
| 641 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 642 | } |
| 643 | global.nbproc = atol(args[1]); |
| 644 | } |
| 645 | else if (!strcmp(args[0], "maxconn")) { |
| 646 | if (global.maxconn != 0) { |
| 647 | 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] | 648 | err_code |= ERR_ALERT; |
| 649 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 650 | } |
| 651 | if (*(args[1]) == 0) { |
| 652 | 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] | 653 | err_code |= ERR_ALERT | ERR_FATAL; |
| 654 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 655 | } |
| 656 | global.maxconn = atol(args[1]); |
| 657 | #ifdef SYSTEM_MAXCONN |
| 658 | if (global.maxconn > DEFAULT_MAXCONN && cfg_maxconn <= DEFAULT_MAXCONN) { |
| 659 | 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); |
| 660 | global.maxconn = DEFAULT_MAXCONN; |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 661 | err_code |= ERR_ALERT; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 662 | } |
| 663 | #endif /* SYSTEM_MAXCONN */ |
| 664 | } |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 665 | else if (!strcmp(args[0], "maxpipes")) { |
| 666 | if (global.maxpipes != 0) { |
| 667 | 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] | 668 | err_code |= ERR_ALERT; |
| 669 | goto out; |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 670 | } |
| 671 | if (*(args[1]) == 0) { |
| 672 | 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] | 673 | err_code |= ERR_ALERT | ERR_FATAL; |
| 674 | goto out; |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 675 | } |
| 676 | global.maxpipes = atol(args[1]); |
| 677 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 678 | else if (!strcmp(args[0], "ulimit-n")) { |
| 679 | if (global.rlimit_nofile != 0) { |
| 680 | 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] | 681 | err_code |= ERR_ALERT; |
| 682 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 683 | } |
| 684 | if (*(args[1]) == 0) { |
| 685 | 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] | 686 | err_code |= ERR_ALERT | ERR_FATAL; |
| 687 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 688 | } |
| 689 | global.rlimit_nofile = atol(args[1]); |
| 690 | } |
| 691 | else if (!strcmp(args[0], "chroot")) { |
| 692 | if (global.chroot != NULL) { |
| 693 | 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] | 694 | err_code |= ERR_ALERT; |
| 695 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 696 | } |
| 697 | if (*(args[1]) == 0) { |
| 698 | 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] | 699 | err_code |= ERR_ALERT | ERR_FATAL; |
| 700 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 701 | } |
| 702 | global.chroot = strdup(args[1]); |
| 703 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 704 | else if (!strcmp(args[0], "description")) { |
| 705 | int i, len=0; |
| 706 | char *d; |
| 707 | |
| 708 | if (!*args[1]) { |
| 709 | Alert("parsing [%s:%d]: '%s' expects a string argument.\n", |
| 710 | file, linenum, args[0]); |
| 711 | err_code |= ERR_ALERT | ERR_FATAL; |
| 712 | goto out; |
| 713 | } |
| 714 | |
| 715 | for(i=1; *args[i]; i++) |
| 716 | len += strlen(args[i])+1; |
| 717 | |
| 718 | if (global.desc) |
| 719 | free(global.desc); |
| 720 | |
| 721 | global.desc = d = (char *)calloc(1, len); |
| 722 | |
| 723 | d += sprintf(d, "%s", args[1]); |
| 724 | for(i=2; *args[i]; i++) |
| 725 | d += sprintf(d, " %s", args[i]); |
| 726 | } |
| 727 | else if (!strcmp(args[0], "node")) { |
| 728 | int i; |
| 729 | char c; |
| 730 | |
| 731 | for (i=0; args[1][i]; i++) { |
| 732 | c = args[1][i]; |
Willy Tarreau | 88e0581 | 2010-03-03 00:16:00 +0100 | [diff] [blame] | 733 | if (!isupper((unsigned char)c) && !islower((unsigned char)c) && |
| 734 | !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.') |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 735 | break; |
| 736 | } |
| 737 | |
| 738 | if (!i || args[1][i]) { |
| 739 | Alert("parsing [%s:%d]: '%s' requires valid node name - non-empty string" |
| 740 | " with digits(0-9), letters(A-Z, a-z), dot(.), hyphen(-) or underscode(_).\n", |
| 741 | file, linenum, args[0]); |
| 742 | err_code |= ERR_ALERT | ERR_FATAL; |
| 743 | goto out; |
| 744 | } |
| 745 | |
| 746 | if (global.node) |
| 747 | free(global.node); |
| 748 | |
| 749 | global.node = strdup(args[1]); |
| 750 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 751 | else if (!strcmp(args[0], "pidfile")) { |
| 752 | if (global.pidfile != NULL) { |
| 753 | 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] | 754 | err_code |= ERR_ALERT; |
| 755 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 756 | } |
| 757 | if (*(args[1]) == 0) { |
| 758 | 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] | 759 | err_code |= ERR_ALERT | ERR_FATAL; |
| 760 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 761 | } |
| 762 | global.pidfile = strdup(args[1]); |
| 763 | } |
| 764 | else if (!strcmp(args[0], "log")) { /* syslog server address */ |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 765 | struct logsrv logsrv; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 766 | int facility, level, minlvl; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 767 | |
| 768 | if (*(args[1]) == 0 || *(args[2]) == 0) { |
| 769 | 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] | 770 | err_code |= ERR_ALERT | ERR_FATAL; |
| 771 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 772 | } |
| 773 | |
| 774 | facility = get_log_facility(args[2]); |
| 775 | if (facility < 0) { |
| 776 | 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] | 777 | err_code |= ERR_ALERT | ERR_FATAL; |
| 778 | facility = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 779 | } |
| 780 | |
| 781 | level = 7; /* max syslog level = debug */ |
| 782 | if (*(args[3])) { |
| 783 | level = get_log_level(args[3]); |
| 784 | if (level < 0) { |
| 785 | 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] | 786 | err_code |= ERR_ALERT | ERR_FATAL; |
| 787 | level = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 788 | } |
| 789 | } |
| 790 | |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 791 | minlvl = 0; /* limit syslog level to this level (emerg) */ |
| 792 | if (*(args[4])) { |
| 793 | minlvl = get_log_level(args[4]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 794 | if (minlvl < 0) { |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 795 | 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] | 796 | err_code |= ERR_ALERT | ERR_FATAL; |
| 797 | minlvl = 0; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 798 | } |
| 799 | } |
| 800 | |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 801 | if (args[1][0] == '/') { |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 802 | struct sockaddr_un *sk = str2sun(args[1]); |
| 803 | if (!sk) { |
| 804 | Alert("parsing [%s:%d] : Socket path '%s' too long (max %d)\n", file, linenum, |
| 805 | args[1], (int)sizeof(sk->sun_path) - 1); |
| 806 | err_code |= ERR_ALERT | ERR_FATAL; |
| 807 | goto out; |
| 808 | } |
| 809 | logsrv.u.un = *sk; |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 810 | logsrv.u.addr.sa_family = AF_UNIX; |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 811 | } else { |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 812 | struct sockaddr_in *sk = str2sa(args[1]); |
| 813 | if (!sk) { |
| 814 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[1]); |
| 815 | err_code |= ERR_ALERT | ERR_FATAL; |
| 816 | goto out; |
| 817 | } |
| 818 | logsrv.u.in = *sk; |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 819 | logsrv.u.addr.sa_family = AF_INET; |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 820 | if (!logsrv.u.in.sin_port) |
| 821 | logsrv.u.in.sin_port = htons(SYSLOG_PORT); |
| 822 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 823 | |
| 824 | if (global.logfac1 == -1) { |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 825 | global.logsrv1 = logsrv; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 826 | global.logfac1 = facility; |
| 827 | global.loglev1 = level; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 828 | global.minlvl1 = minlvl; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 829 | } |
| 830 | else if (global.logfac2 == -1) { |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 831 | global.logsrv2 = logsrv; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 832 | global.logfac2 = facility; |
| 833 | global.loglev2 = level; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 834 | global.minlvl2 = minlvl; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 835 | } |
| 836 | else { |
| 837 | Alert("parsing [%s:%d] : too many syslog servers\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 838 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 839 | } |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 840 | } |
| 841 | else if (!strcmp(args[0], "spread-checks")) { /* random time between checks (0-50) */ |
| 842 | if (global.spread_checks != 0) { |
| 843 | Alert("parsing [%s:%d]: spread-checks already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 844 | err_code |= ERR_ALERT; |
| 845 | goto out; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 846 | } |
| 847 | if (*(args[1]) == 0) { |
| 848 | 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] | 849 | err_code |= ERR_ALERT | ERR_FATAL; |
| 850 | goto out; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 851 | } |
| 852 | global.spread_checks = atol(args[1]); |
| 853 | if (global.spread_checks < 0 || global.spread_checks > 50) { |
| 854 | 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] | 855 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 856 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 857 | } |
| 858 | else { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 859 | struct cfg_kw_list *kwl; |
| 860 | int index; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 861 | int rc; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 862 | |
| 863 | list_for_each_entry(kwl, &cfg_keywords.list, list) { |
| 864 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 865 | if (kwl->kw[index].section != CFG_GLOBAL) |
| 866 | continue; |
| 867 | if (strcmp(kwl->kw[index].kw, args[0]) == 0) { |
| 868 | /* prepare error message just in case */ |
| 869 | snprintf(trash, sizeof(trash), |
| 870 | "error near '%s' in '%s' section", args[0], "global"); |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 871 | rc = kwl->kw[index].parse(args, CFG_GLOBAL, NULL, NULL, trash, sizeof(trash)); |
| 872 | if (rc < 0) { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 873 | Alert("parsing [%s:%d] : %s\n", file, linenum, trash); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 874 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 875 | } |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 876 | else if (rc > 0) { |
| 877 | Warning("parsing [%s:%d] : %s\n", file, linenum, trash); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 878 | err_code |= ERR_WARN; |
| 879 | goto out; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 880 | } |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 881 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 882 | } |
| 883 | } |
| 884 | } |
| 885 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 886 | 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] | 887 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 888 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 889 | |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 890 | out: |
| 891 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 892 | } |
| 893 | |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 894 | /* Perform the most basic initialization of a proxy : |
| 895 | * memset(), list_init(*), reset_timeouts(*). |
| 896 | */ |
| 897 | static void init_new_proxy(struct proxy *p) |
| 898 | { |
| 899 | memset(p, 0, sizeof(struct proxy)); |
| 900 | LIST_INIT(&p->pendconns); |
| 901 | LIST_INIT(&p->acl); |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 902 | LIST_INIT(&p->req_acl); |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 903 | LIST_INIT(&p->block_cond); |
| 904 | LIST_INIT(&p->redirect_rules); |
| 905 | LIST_INIT(&p->mon_fail_cond); |
| 906 | LIST_INIT(&p->switching_rules); |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 907 | LIST_INIT(&p->persist_rules); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 908 | LIST_INIT(&p->sticking_rules); |
| 909 | LIST_INIT(&p->storersp_rules); |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 910 | LIST_INIT(&p->tcp_req.inspect_rules); |
Willy Tarreau | ab78619 | 2010-05-23 22:39:25 +0200 | [diff] [blame] | 911 | LIST_INIT(&p->tcp_req.l4_rules); |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 912 | LIST_INIT(&p->req_add); |
| 913 | LIST_INIT(&p->rsp_add); |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 914 | |
| 915 | /* Timeouts are defined as -1 */ |
| 916 | proxy_reset_timeouts(p); |
| 917 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 918 | |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 919 | void init_default_instance() |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 920 | { |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 921 | init_new_proxy(&defproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 922 | defproxy.mode = PR_MODE_TCP; |
| 923 | defproxy.state = PR_STNEW; |
| 924 | defproxy.maxconn = cfg_maxpconn; |
| 925 | defproxy.conn_retries = CONN_RETRIES; |
| 926 | defproxy.logfac1 = defproxy.logfac2 = -1; /* log disabled */ |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 927 | |
| 928 | defproxy.defsrv.inter = DEF_CHKINTR; |
| 929 | defproxy.defsrv.fastinter = 0; |
| 930 | defproxy.defsrv.downinter = 0; |
| 931 | defproxy.defsrv.rise = DEF_RISETIME; |
| 932 | defproxy.defsrv.fall = DEF_FALLTIME; |
| 933 | defproxy.defsrv.check_port = 0; |
| 934 | defproxy.defsrv.maxqueue = 0; |
| 935 | defproxy.defsrv.minconn = 0; |
| 936 | defproxy.defsrv.maxconn = 0; |
| 937 | defproxy.defsrv.slowstart = 0; |
| 938 | defproxy.defsrv.onerror = DEF_HANA_ONERR; |
| 939 | defproxy.defsrv.consecutive_errors_limit = DEF_HANA_ERRLIMIT; |
| 940 | defproxy.defsrv.uweight = defproxy.defsrv.iweight = 1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 941 | } |
| 942 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 943 | |
| 944 | static int create_cond_regex_rule(const char *file, int line, |
| 945 | struct proxy *px, int dir, int action, int flags, |
| 946 | const char *cmd, const char *reg, const char *repl, |
| 947 | const char **cond_start) |
| 948 | { |
| 949 | regex_t *preg = NULL; |
| 950 | const char *err; |
| 951 | int err_code = 0; |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 952 | struct acl_cond *cond = NULL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 953 | |
| 954 | if (px == &defproxy) { |
| 955 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, line, cmd); |
| 956 | err_code |= ERR_ALERT | ERR_FATAL; |
| 957 | goto err; |
| 958 | } |
| 959 | |
| 960 | if (*reg == 0) { |
| 961 | Alert("parsing [%s:%d] : '%s' expects <regex> as an argument.\n", file, line, cmd); |
| 962 | err_code |= ERR_ALERT | ERR_FATAL; |
| 963 | goto err; |
| 964 | } |
| 965 | |
| 966 | if (warnifnotcap(px, PR_CAP_RS, file, line, cmd, NULL)) |
| 967 | err_code |= ERR_WARN; |
| 968 | |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 969 | if (cond_start && |
| 970 | (strcmp(*cond_start, "if") == 0 || strcmp(*cond_start, "unless") == 0)) { |
| 971 | if ((cond = build_acl_cond(file, line, px, cond_start)) == NULL) { |
| 972 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition.\n", |
| 973 | file, line, cmd); |
| 974 | err_code |= ERR_ALERT | ERR_FATAL; |
| 975 | goto err; |
| 976 | } |
| 977 | } |
| 978 | else if (cond_start && **cond_start) { |
| 979 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 980 | file, line, cmd, *cond_start); |
| 981 | err_code |= ERR_ALERT | ERR_FATAL; |
| 982 | goto err; |
| 983 | } |
| 984 | |
| 985 | if (dir == ACL_DIR_REQ) |
| 986 | err_code |= warnif_cond_requires_resp(cond, file, line); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 987 | else |
| 988 | err_code |= warnif_cond_requires_req(cond, file, line); |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 989 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 990 | preg = calloc(1, sizeof(regex_t)); |
| 991 | if (!preg) { |
| 992 | Alert("parsing [%s:%d] : '%s' : not enough memory to build regex.\n", file, line, cmd); |
| 993 | err_code = ERR_ALERT | ERR_FATAL; |
| 994 | goto err; |
| 995 | } |
| 996 | |
| 997 | if (regcomp(preg, reg, REG_EXTENDED | flags) != 0) { |
| 998 | Alert("parsing [%s:%d] : '%s' : bad regular expression '%s'.\n", file, line, cmd, reg); |
| 999 | err_code = ERR_ALERT | ERR_FATAL; |
| 1000 | goto err; |
| 1001 | } |
| 1002 | |
| 1003 | err = chain_regex((dir == ACL_DIR_REQ) ? &px->req_exp : &px->rsp_exp, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1004 | preg, action, repl ? strdup(repl) : NULL, cond); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1005 | if (repl && err) { |
| 1006 | Alert("parsing [%s:%d] : '%s' : invalid character or unterminated sequence in replacement string near '%c'.\n", |
| 1007 | file, line, cmd, *err); |
| 1008 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1009 | goto err; |
| 1010 | } |
| 1011 | |
| 1012 | if (dir == ACL_DIR_REQ && warnif_misplaced_reqxxx(px, file, line, cmd)) |
| 1013 | err_code |= ERR_WARN; |
| 1014 | |
| 1015 | return err_code; |
| 1016 | err: |
| 1017 | free(preg); |
| 1018 | return err_code; |
| 1019 | } |
| 1020 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1021 | /* |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1022 | * Parse a line in a <listen>, <frontend>, <backend> or <ruleset> section. |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1023 | * Returns the error code, 0 if OK, or any combination of : |
| 1024 | * - ERR_ABORT: must abort ASAP |
| 1025 | * - ERR_FATAL: we can continue parsing but not start the service |
| 1026 | * - ERR_WARN: a warning has been emitted |
| 1027 | * - ERR_ALERT: an alert has been emitted |
| 1028 | * Only the two first ones can stop processing, the two others are just |
| 1029 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1030 | */ |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 1031 | 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] | 1032 | { |
| 1033 | static struct proxy *curproxy = NULL; |
| 1034 | struct server *newsrv = NULL; |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 1035 | const char *err; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 1036 | int rc; |
| 1037 | unsigned val; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1038 | int err_code = 0; |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 1039 | struct acl_cond *cond = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1040 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1041 | if (!strcmp(args[0], "listen")) |
| 1042 | rc = PR_CAP_LISTEN; |
| 1043 | else if (!strcmp(args[0], "frontend")) |
| 1044 | rc = PR_CAP_FE | PR_CAP_RS; |
| 1045 | else if (!strcmp(args[0], "backend")) |
| 1046 | rc = PR_CAP_BE | PR_CAP_RS; |
| 1047 | else if (!strcmp(args[0], "ruleset")) |
| 1048 | rc = PR_CAP_RS; |
| 1049 | else |
| 1050 | rc = PR_CAP_NONE; |
| 1051 | |
| 1052 | if (rc != PR_CAP_NONE) { /* new proxy */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1053 | if (!*args[1]) { |
| 1054 | Alert("parsing [%s:%d] : '%s' expects an <id> argument and\n" |
| 1055 | " optionnally supports [addr1]:port1[-end1]{,[addr]:port[-end]}...\n", |
| 1056 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1057 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1058 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1059 | } |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 1060 | |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 1061 | err = invalid_char(args[1]); |
| 1062 | if (err) { |
| 1063 | Alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 1064 | file, linenum, *err, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1065 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 1066 | } |
| 1067 | |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 1068 | for (curproxy = proxy; curproxy != NULL; curproxy = curproxy->next) { |
| 1069 | /* |
| 1070 | * If there are two proxies with the same name only following |
| 1071 | * combinations are allowed: |
| 1072 | * |
| 1073 | * listen backend frontend ruleset |
| 1074 | * listen - - - - |
| 1075 | * backend - - OK - |
| 1076 | * frontend - OK - - |
| 1077 | * ruleset - - - - |
| 1078 | */ |
| 1079 | |
| 1080 | if (!strcmp(curproxy->id, args[1]) && |
| 1081 | (rc!=(PR_CAP_FE|PR_CAP_RS) || curproxy->cap!=(PR_CAP_BE|PR_CAP_RS)) && |
| 1082 | (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] | 1083 | Warning("Parsing [%s:%d]: %s '%s' has same name as another %s (declared at %s:%d).\n", |
| 1084 | file, linenum, proxy_cap_str(rc), args[1], proxy_type_str(curproxy), |
| 1085 | curproxy->conf.file, curproxy->conf.line); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1086 | err_code |= ERR_WARN; |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 1087 | } |
| 1088 | } |
| 1089 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1090 | if ((curproxy = (struct proxy *)calloc(1, sizeof(struct proxy))) == NULL) { |
| 1091 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1092 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1093 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1094 | } |
Willy Tarreau | 5af24ef | 2009-03-15 15:23:16 +0100 | [diff] [blame] | 1095 | |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 1096 | init_new_proxy(curproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1097 | curproxy->next = proxy; |
| 1098 | proxy = curproxy; |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 1099 | curproxy->conf.file = file; |
| 1100 | curproxy->conf.line = linenum; |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 1101 | curproxy->last_change = now.tv_sec; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1102 | curproxy->id = strdup(args[1]); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1103 | curproxy->cap = rc; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1104 | |
| 1105 | /* parse the listener address if any */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1106 | if ((curproxy->cap & PR_CAP_FE) && *args[2]) { |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 1107 | struct listener *new, *last = curproxy->listen; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1108 | if (!str2listener(args[2], curproxy)) { |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1109 | err_code |= ERR_FATAL; |
| 1110 | goto out; |
| 1111 | } |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 1112 | new = curproxy->listen; |
| 1113 | while (new != last) { |
| 1114 | new->conf.file = file; |
| 1115 | new->conf.line = linenum; |
| 1116 | new = new->next; |
| 1117 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1118 | global.maxsock++; |
| 1119 | } |
| 1120 | |
| 1121 | /* set default values */ |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1122 | memcpy(&curproxy->defsrv, &defproxy.defsrv, sizeof(curproxy->defsrv)); |
Willy Tarreau | 7016020 | 2010-04-07 16:06:40 +0200 | [diff] [blame] | 1123 | curproxy->defsrv.id = "default-server"; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1124 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1125 | curproxy->state = defproxy.state; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1126 | curproxy->options = defproxy.options; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 1127 | curproxy->options2 = defproxy.options2; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 1128 | curproxy->no_options = defproxy.no_options; |
| 1129 | curproxy->no_options2 = defproxy.no_options2; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 1130 | curproxy->bind_proc = defproxy.bind_proc; |
Willy Tarreau | 3168223 | 2007-11-29 15:38:04 +0100 | [diff] [blame] | 1131 | curproxy->lbprm.algo = defproxy.lbprm.algo; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 1132 | curproxy->except_net = defproxy.except_net; |
| 1133 | curproxy->except_mask = defproxy.except_mask; |
Maik Broemme | 36db02e | 2009-05-08 17:02:07 +0200 | [diff] [blame] | 1134 | curproxy->except_to = defproxy.except_to; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 1135 | curproxy->except_mask_to = defproxy.except_mask_to; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1136 | |
Willy Tarreau | 79f5fe8 | 2008-08-23 08:18:21 +0200 | [diff] [blame] | 1137 | if (defproxy.fwdfor_hdr_len) { |
| 1138 | curproxy->fwdfor_hdr_len = defproxy.fwdfor_hdr_len; |
| 1139 | curproxy->fwdfor_hdr_name = strdup(defproxy.fwdfor_hdr_name); |
| 1140 | } |
| 1141 | |
Willy Tarreau | b86db34 | 2009-11-30 11:50:16 +0100 | [diff] [blame] | 1142 | if (defproxy.orgto_hdr_len) { |
| 1143 | curproxy->orgto_hdr_len = defproxy.orgto_hdr_len; |
| 1144 | curproxy->orgto_hdr_name = strdup(defproxy.orgto_hdr_name); |
| 1145 | } |
| 1146 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1147 | if (curproxy->cap & PR_CAP_FE) { |
| 1148 | curproxy->maxconn = defproxy.maxconn; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 1149 | curproxy->backlog = defproxy.backlog; |
Willy Tarreau | 13a34bd | 2009-05-10 18:52:49 +0200 | [diff] [blame] | 1150 | curproxy->fe_sps_lim = defproxy.fe_sps_lim; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1151 | |
| 1152 | /* initialize error relocations */ |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1153 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) |
| 1154 | chunk_dup(&curproxy->errmsg[rc], &defproxy.errmsg[rc]); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1155 | |
| 1156 | curproxy->to_log = defproxy.to_log & ~LW_COOKIE & ~LW_REQHDR & ~ LW_RSPHDR; |
| 1157 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1158 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1159 | if (curproxy->cap & PR_CAP_BE) { |
| 1160 | curproxy->fullconn = defproxy.fullconn; |
| 1161 | curproxy->conn_retries = defproxy.conn_retries; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1162 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1163 | if (defproxy.check_req) |
| 1164 | curproxy->check_req = strdup(defproxy.check_req); |
| 1165 | curproxy->check_len = defproxy.check_len; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1166 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1167 | if (defproxy.cookie_name) |
| 1168 | curproxy->cookie_name = strdup(defproxy.cookie_name); |
| 1169 | curproxy->cookie_len = defproxy.cookie_len; |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 1170 | if (defproxy.cookie_domain) |
| 1171 | curproxy->cookie_domain = strdup(defproxy.cookie_domain); |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 1172 | |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 1173 | if (defproxy.rdp_cookie_name) |
| 1174 | curproxy->rdp_cookie_name = strdup(defproxy.rdp_cookie_name); |
| 1175 | curproxy->rdp_cookie_len = defproxy.rdp_cookie_len; |
| 1176 | |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 1177 | if (defproxy.url_param_name) |
| 1178 | curproxy->url_param_name = strdup(defproxy.url_param_name); |
| 1179 | curproxy->url_param_len = defproxy.url_param_len; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 1180 | |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 1181 | if (defproxy.hh_name) |
| 1182 | curproxy->hh_name = strdup(defproxy.hh_name); |
| 1183 | curproxy->hh_len = defproxy.hh_len; |
| 1184 | curproxy->hh_match_domain = defproxy.hh_match_domain; |
| 1185 | |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 1186 | if (defproxy.iface_name) |
| 1187 | curproxy->iface_name = strdup(defproxy.iface_name); |
| 1188 | curproxy->iface_len = defproxy.iface_len; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1189 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1190 | |
Willy Tarreau | 3b6b1a9 | 2009-07-23 13:24:23 +0200 | [diff] [blame] | 1191 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1192 | if (defproxy.capture_name) |
| 1193 | curproxy->capture_name = strdup(defproxy.capture_name); |
| 1194 | curproxy->capture_namelen = defproxy.capture_namelen; |
| 1195 | curproxy->capture_len = defproxy.capture_len; |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 1196 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1197 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1198 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 1199 | curproxy->timeout.client = defproxy.timeout.client; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 1200 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | 036fae0 | 2008-01-06 13:24:40 +0100 | [diff] [blame] | 1201 | curproxy->timeout.httpreq = defproxy.timeout.httpreq; |
Willy Tarreau | b16a574 | 2010-01-10 14:46:16 +0100 | [diff] [blame] | 1202 | curproxy->timeout.httpka = defproxy.timeout.httpka; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1203 | curproxy->uri_auth = defproxy.uri_auth; |
| 1204 | curproxy->mon_net = defproxy.mon_net; |
| 1205 | curproxy->mon_mask = defproxy.mon_mask; |
| 1206 | if (defproxy.monitor_uri) |
| 1207 | curproxy->monitor_uri = strdup(defproxy.monitor_uri); |
| 1208 | curproxy->monitor_uri_len = defproxy.monitor_uri_len; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 1209 | if (defproxy.defbe.name) |
| 1210 | curproxy->defbe.name = strdup(defproxy.defbe.name); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1211 | } |
| 1212 | |
| 1213 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 1214 | curproxy->timeout.connect = defproxy.timeout.connect; |
| 1215 | curproxy->timeout.server = defproxy.timeout.server; |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 1216 | curproxy->timeout.check = defproxy.timeout.check; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 1217 | curproxy->timeout.queue = defproxy.timeout.queue; |
Willy Tarreau | 51c9bde | 2008-01-06 13:40:03 +0100 | [diff] [blame] | 1218 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | cd7afc0 | 2009-07-12 10:03:17 +0200 | [diff] [blame] | 1219 | curproxy->timeout.httpreq = defproxy.timeout.httpreq; |
Willy Tarreau | b16a574 | 2010-01-10 14:46:16 +0100 | [diff] [blame] | 1220 | curproxy->timeout.httpka = defproxy.timeout.httpka; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1221 | curproxy->source_addr = defproxy.source_addr; |
| 1222 | } |
| 1223 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1224 | curproxy->mode = defproxy.mode; |
| 1225 | curproxy->logfac1 = defproxy.logfac1; |
| 1226 | curproxy->logsrv1 = defproxy.logsrv1; |
| 1227 | curproxy->loglev1 = defproxy.loglev1; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 1228 | curproxy->minlvl1 = defproxy.minlvl1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1229 | curproxy->logfac2 = defproxy.logfac2; |
| 1230 | curproxy->logsrv2 = defproxy.logsrv2; |
| 1231 | curproxy->loglev2 = defproxy.loglev2; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 1232 | curproxy->minlvl2 = defproxy.minlvl2; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1233 | curproxy->grace = defproxy.grace; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1234 | curproxy->conf.used_listener_id = EB_ROOT; |
| 1235 | curproxy->conf.used_server_id = EB_ROOT; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 1236 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1237 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1238 | } |
| 1239 | else if (!strcmp(args[0], "defaults")) { /* use this one to assign default values */ |
| 1240 | /* some variables may have already been initialized earlier */ |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 1241 | /* FIXME-20070101: we should do this too at the end of the |
| 1242 | * config parsing to free all default values. |
| 1243 | */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1244 | free(defproxy.check_req); |
| 1245 | free(defproxy.cookie_name); |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 1246 | free(defproxy.rdp_cookie_name); |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 1247 | free(defproxy.cookie_domain); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1248 | free(defproxy.url_param_name); |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 1249 | free(defproxy.hh_name); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1250 | free(defproxy.capture_name); |
| 1251 | free(defproxy.monitor_uri); |
| 1252 | free(defproxy.defbe.name); |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 1253 | free(defproxy.iface_name); |
Willy Tarreau | 79f5fe8 | 2008-08-23 08:18:21 +0200 | [diff] [blame] | 1254 | free(defproxy.fwdfor_hdr_name); |
| 1255 | defproxy.fwdfor_hdr_len = 0; |
Willy Tarreau | b86db34 | 2009-11-30 11:50:16 +0100 | [diff] [blame] | 1256 | free(defproxy.orgto_hdr_name); |
| 1257 | defproxy.orgto_hdr_len = 0; |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 1258 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1259 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1260 | chunk_destroy(&defproxy.errmsg[rc]); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 1261 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1262 | /* we cannot free uri_auth because it might already be used */ |
| 1263 | init_default_instance(); |
| 1264 | curproxy = &defproxy; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1265 | defproxy.cap = PR_CAP_LISTEN; /* all caps for now */ |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1266 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1267 | } |
| 1268 | else if (curproxy == NULL) { |
| 1269 | Alert("parsing [%s:%d] : 'listen' or 'defaults' expected.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1270 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1271 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1272 | } |
| 1273 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1274 | |
| 1275 | /* Now let's parse the proxy-specific keywords */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1276 | if (!strcmp(args[0], "bind")) { /* new listen addresses */ |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 1277 | struct listener *new_listen, *last_listen; |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1278 | int cur_arg; |
| 1279 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1280 | if (curproxy == &defproxy) { |
| 1281 | 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] | 1282 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1283 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1284 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1285 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1286 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1287 | |
| 1288 | if (strchr(args[1], ':') == NULL) { |
| 1289 | Alert("parsing [%s:%d] : '%s' expects [addr1]:port1[-end1]{,[addr]:port[-end]}... as arguments.\n", |
| 1290 | file, linenum, args[0]); |
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 | } |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 1294 | |
| 1295 | last_listen = curproxy->listen; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1296 | if (!str2listener(args[1], curproxy)) { |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1297 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1298 | goto out; |
| 1299 | } |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1300 | |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 1301 | new_listen = curproxy->listen; |
| 1302 | while (new_listen != last_listen) { |
| 1303 | new_listen->conf.file = file; |
| 1304 | new_listen->conf.line = linenum; |
| 1305 | new_listen = new_listen->next; |
| 1306 | } |
| 1307 | |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1308 | cur_arg = 2; |
| 1309 | while (*(args[cur_arg])) { |
| 1310 | if (!strcmp(args[cur_arg], "interface")) { /* specifically bind to this interface */ |
| 1311 | #ifdef SO_BINDTODEVICE |
| 1312 | struct listener *l; |
| 1313 | |
| 1314 | if (!*args[cur_arg + 1]) { |
| 1315 | Alert("parsing [%s:%d] : '%s' : missing interface name.\n", |
| 1316 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1317 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1318 | goto out; |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1319 | } |
| 1320 | |
| 1321 | for (l = curproxy->listen; l != last_listen; l = l->next) |
| 1322 | l->interface = strdup(args[cur_arg + 1]); |
| 1323 | |
| 1324 | global.last_checks |= LSTCHK_NETADM; |
| 1325 | |
| 1326 | cur_arg += 2; |
| 1327 | continue; |
| 1328 | #else |
| 1329 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 1330 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1331 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1332 | goto out; |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1333 | #endif |
| 1334 | } |
Willy Tarreau | be1b918 | 2009-06-14 18:48:19 +0200 | [diff] [blame] | 1335 | if (!strcmp(args[cur_arg], "mss")) { /* set MSS of listening socket */ |
| 1336 | #ifdef TCP_MAXSEG |
| 1337 | struct listener *l; |
| 1338 | int mss; |
| 1339 | |
| 1340 | if (!*args[cur_arg + 1]) { |
| 1341 | Alert("parsing [%s:%d] : '%s' : missing MSS value.\n", |
| 1342 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1343 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1344 | goto out; |
Willy Tarreau | be1b918 | 2009-06-14 18:48:19 +0200 | [diff] [blame] | 1345 | } |
| 1346 | |
| 1347 | mss = str2uic(args[cur_arg + 1]); |
| 1348 | if (mss < 1 || mss > 65535) { |
| 1349 | Alert("parsing [%s:%d]: %s expects an MSS value between 1 and 65535.\n", |
| 1350 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1351 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1352 | goto out; |
Willy Tarreau | be1b918 | 2009-06-14 18:48:19 +0200 | [diff] [blame] | 1353 | } |
| 1354 | |
| 1355 | for (l = curproxy->listen; l != last_listen; l = l->next) |
| 1356 | l->maxseg = mss; |
| 1357 | |
| 1358 | cur_arg += 2; |
| 1359 | continue; |
| 1360 | #else |
| 1361 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 1362 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1363 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1364 | goto out; |
Willy Tarreau | be1b918 | 2009-06-14 18:48:19 +0200 | [diff] [blame] | 1365 | #endif |
| 1366 | } |
Willy Tarreau | cb6cd43 | 2009-10-13 07:34:14 +0200 | [diff] [blame] | 1367 | |
| 1368 | if (!strcmp(args[cur_arg], "defer-accept")) { /* wait for some data for 1 second max before doing accept */ |
| 1369 | #ifdef TCP_DEFER_ACCEPT |
| 1370 | struct listener *l; |
| 1371 | |
| 1372 | for (l = curproxy->listen; l != last_listen; l = l->next) |
| 1373 | l->options |= LI_O_DEF_ACCEPT; |
| 1374 | |
| 1375 | cur_arg ++; |
| 1376 | continue; |
| 1377 | #else |
| 1378 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 1379 | file, linenum, args[0], args[cur_arg]); |
| 1380 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1381 | goto out; |
| 1382 | #endif |
| 1383 | } |
| 1384 | |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1385 | if (!strcmp(args[cur_arg], "transparent")) { /* transparently bind to these addresses */ |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 1386 | #ifdef CONFIG_HAP_LINUX_TPROXY |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 1387 | struct listener *l; |
| 1388 | |
| 1389 | for (l = curproxy->listen; l != last_listen; l = l->next) |
| 1390 | l->options |= LI_O_FOREIGN; |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1391 | |
| 1392 | cur_arg ++; |
| 1393 | continue; |
| 1394 | #else |
| 1395 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 1396 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1397 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1398 | goto out; |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1399 | #endif |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 1400 | } |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1401 | |
| 1402 | if (!strcmp(args[cur_arg], "name")) { |
| 1403 | struct listener *l; |
| 1404 | |
| 1405 | for (l = curproxy->listen; l != last_listen; l = l->next) |
| 1406 | l->name = strdup(args[cur_arg + 1]); |
| 1407 | |
| 1408 | cur_arg += 2; |
| 1409 | continue; |
| 1410 | } |
| 1411 | |
| 1412 | if (!strcmp(args[cur_arg], "id")) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1413 | struct eb32_node *node; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1414 | struct listener *l; |
| 1415 | |
| 1416 | if (curproxy->listen->next != last_listen) { |
| 1417 | Alert("parsing [%s:%d]: '%s' can be only used with a single socket.\n", |
| 1418 | file, linenum, args[cur_arg]); |
| 1419 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1420 | goto out; |
| 1421 | } |
| 1422 | |
| 1423 | if (!*args[cur_arg + 1]) { |
| 1424 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 1425 | file, linenum, args[cur_arg]); |
| 1426 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1427 | goto out; |
| 1428 | } |
| 1429 | |
| 1430 | curproxy->listen->luid = atol(args[cur_arg + 1]); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1431 | curproxy->listen->conf.id.key = curproxy->listen->luid; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1432 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1433 | if (curproxy->listen->luid <= 0) { |
| 1434 | Alert("parsing [%s:%d]: custom id has to be > 0\n", |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1435 | file, linenum); |
| 1436 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1437 | goto out; |
| 1438 | } |
| 1439 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1440 | node = eb32_lookup(&curproxy->conf.used_listener_id, curproxy->listen->luid); |
| 1441 | if (node) { |
| 1442 | l = container_of(node, struct listener, conf.id); |
| 1443 | Alert("parsing [%s:%d]: custom id %d for socket '%s' already used at %s:%d.\n", |
| 1444 | file, linenum, l->luid, args[1], l->conf.file, l->conf.line); |
| 1445 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1446 | goto out; |
| 1447 | } |
| 1448 | eb32_insert(&curproxy->conf.used_listener_id, &curproxy->listen->conf.id); |
| 1449 | |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1450 | cur_arg += 2; |
| 1451 | continue; |
| 1452 | } |
| 1453 | |
Willy Tarreau | cb6cd43 | 2009-10-13 07:34:14 +0200 | [diff] [blame] | 1454 | 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] | 1455 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1456 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1457 | goto out; |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 1458 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1459 | global.maxsock++; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1460 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1461 | } |
| 1462 | else if (!strcmp(args[0], "monitor-net")) { /* set the range of IPs to ignore */ |
| 1463 | if (!*args[1] || !str2net(args[1], &curproxy->mon_net, &curproxy->mon_mask)) { |
| 1464 | Alert("parsing [%s:%d] : '%s' expects address[/mask].\n", |
| 1465 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1466 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1467 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1468 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1469 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1470 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1471 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1472 | /* flush useless bits */ |
| 1473 | curproxy->mon_net.s_addr &= curproxy->mon_mask.s_addr; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1474 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1475 | } |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 1476 | else if (!strcmp(args[0], "monitor-uri")) { /* set the URI to intercept */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1477 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1478 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1479 | |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 1480 | if (!*args[1]) { |
| 1481 | Alert("parsing [%s:%d] : '%s' expects an URI.\n", |
| 1482 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1483 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1484 | goto out; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 1485 | } |
| 1486 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1487 | free(curproxy->monitor_uri); |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 1488 | curproxy->monitor_uri_len = strlen(args[1]); |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 1489 | curproxy->monitor_uri = (char *)calloc(1, curproxy->monitor_uri_len + 1); |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 1490 | memcpy(curproxy->monitor_uri, args[1], curproxy->monitor_uri_len); |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 1491 | curproxy->monitor_uri[curproxy->monitor_uri_len] = '\0'; |
| 1492 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1493 | goto out; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 1494 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1495 | else if (!strcmp(args[0], "mode")) { /* sets the proxy mode */ |
| 1496 | if (!strcmp(args[1], "http")) curproxy->mode = PR_MODE_HTTP; |
| 1497 | else if (!strcmp(args[1], "tcp")) curproxy->mode = PR_MODE_TCP; |
| 1498 | else if (!strcmp(args[1], "health")) curproxy->mode = PR_MODE_HEALTH; |
| 1499 | else { |
| 1500 | 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] | 1501 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1502 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1503 | } |
| 1504 | } |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 1505 | else if (!strcmp(args[0], "id")) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1506 | struct eb32_node *node; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 1507 | |
| 1508 | if (curproxy == &defproxy) { |
| 1509 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", |
| 1510 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1511 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1512 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 1513 | } |
| 1514 | |
| 1515 | if (!*args[1]) { |
| 1516 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 1517 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1518 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1519 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 1520 | } |
| 1521 | |
| 1522 | curproxy->uuid = atol(args[1]); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1523 | curproxy->conf.id.key = curproxy->uuid; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 1524 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1525 | if (curproxy->uuid <= 0) { |
| 1526 | Alert("parsing [%s:%d]: custom id has to be > 0.\n", |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 1527 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1528 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1529 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 1530 | } |
| 1531 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1532 | node = eb32_lookup(&used_proxy_id, curproxy->uuid); |
| 1533 | if (node) { |
| 1534 | struct proxy *target = container_of(node, struct proxy, conf.id); |
| 1535 | Alert("parsing [%s:%d]: %s %s reuses same custom id as %s %s (declared at %s:%d).\n", |
| 1536 | file, linenum, proxy_type_str(curproxy), curproxy->id, |
| 1537 | proxy_type_str(target), target->id, target->conf.file, target->conf.line); |
| 1538 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1539 | goto out; |
| 1540 | } |
| 1541 | eb32_insert(&used_proxy_id, &curproxy->conf.id); |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 1542 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1543 | else if (!strcmp(args[0], "description")) { |
| 1544 | int i, len=0; |
| 1545 | char *d; |
| 1546 | |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 1547 | if (curproxy == &defproxy) { |
| 1548 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", |
| 1549 | file, linenum, args[0]); |
| 1550 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1551 | goto out; |
| 1552 | } |
| 1553 | |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1554 | if (!*args[1]) { |
| 1555 | Alert("parsing [%s:%d]: '%s' expects a string argument.\n", |
| 1556 | file, linenum, args[0]); |
| 1557 | return -1; |
| 1558 | } |
| 1559 | |
| 1560 | for(i=1; *args[i]; i++) |
| 1561 | len += strlen(args[i])+1; |
| 1562 | |
| 1563 | d = (char *)calloc(1, len); |
| 1564 | curproxy->desc = d; |
| 1565 | |
| 1566 | d += sprintf(d, "%s", args[1]); |
| 1567 | for(i=2; *args[i]; i++) |
| 1568 | d += sprintf(d, " %s", args[i]); |
| 1569 | |
| 1570 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1571 | else if (!strcmp(args[0], "disabled")) { /* disables this proxy */ |
| 1572 | curproxy->state = PR_STSTOPPED; |
| 1573 | } |
| 1574 | else if (!strcmp(args[0], "enabled")) { /* enables this proxy (used to revert a disabled default) */ |
| 1575 | curproxy->state = PR_STNEW; |
| 1576 | } |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 1577 | else if (!strcmp(args[0], "bind-process")) { /* enable this proxy only on some processes */ |
| 1578 | int cur_arg = 1; |
| 1579 | unsigned int set = 0; |
| 1580 | |
| 1581 | while (*args[cur_arg]) { |
| 1582 | int u; |
| 1583 | if (strcmp(args[cur_arg], "all") == 0) { |
| 1584 | set = 0; |
| 1585 | break; |
| 1586 | } |
| 1587 | else if (strcmp(args[cur_arg], "odd") == 0) { |
| 1588 | set |= 0x55555555; |
| 1589 | } |
| 1590 | else if (strcmp(args[cur_arg], "even") == 0) { |
| 1591 | set |= 0xAAAAAAAA; |
| 1592 | } |
| 1593 | else { |
| 1594 | u = str2uic(args[cur_arg]); |
| 1595 | if (u < 1 || u > 32) { |
| 1596 | Alert("parsing [%s:%d]: %s expects 'all', 'odd', 'even', or process numbers from 1 to 32.\n", |
| 1597 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1598 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1599 | goto out; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 1600 | } |
| 1601 | if (u > global.nbproc) { |
| 1602 | Warning("parsing [%s:%d]: %s references process number higher than global.nbproc.\n", |
| 1603 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1604 | err_code |= ERR_WARN; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 1605 | } |
| 1606 | set |= 1 << (u - 1); |
| 1607 | } |
| 1608 | cur_arg++; |
| 1609 | } |
| 1610 | curproxy->bind_proc = set; |
| 1611 | } |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 1612 | else if (!strcmp(args[0], "acl")) { /* add an ACL */ |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 1613 | if (curproxy == &defproxy) { |
| 1614 | 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] | 1615 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1616 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 1617 | } |
| 1618 | |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 1619 | err = invalid_char(args[1]); |
| 1620 | if (err) { |
| 1621 | Alert("parsing [%s:%d] : character '%c' is not permitted in acl name '%s'.\n", |
| 1622 | file, linenum, *err, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1623 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 1624 | } |
| 1625 | |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 1626 | if (parse_acl((const char **)args + 1, &curproxy->acl) == NULL) { |
| 1627 | Alert("parsing [%s:%d] : error detected while parsing ACL '%s'.\n", |
| 1628 | file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1629 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1630 | goto out; |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 1631 | } |
| 1632 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1633 | else if (!strcmp(args[0], "cookie")) { /* cookie name */ |
| 1634 | int cur_arg; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1635 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1636 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1637 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1638 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1639 | if (*(args[1]) == 0) { |
| 1640 | Alert("parsing [%s:%d] : '%s' expects <cookie_name> as argument.\n", |
| 1641 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1642 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1643 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1644 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1645 | |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 1646 | free(curproxy->cookie_domain); curproxy->cookie_domain = NULL; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1647 | free(curproxy->cookie_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1648 | curproxy->cookie_name = strdup(args[1]); |
| 1649 | curproxy->cookie_len = strlen(curproxy->cookie_name); |
| 1650 | |
| 1651 | cur_arg = 2; |
| 1652 | while (*(args[cur_arg])) { |
| 1653 | if (!strcmp(args[cur_arg], "rewrite")) { |
| 1654 | curproxy->options |= PR_O_COOK_RW; |
| 1655 | } |
| 1656 | else if (!strcmp(args[cur_arg], "indirect")) { |
| 1657 | curproxy->options |= PR_O_COOK_IND; |
| 1658 | } |
| 1659 | else if (!strcmp(args[cur_arg], "insert")) { |
| 1660 | curproxy->options |= PR_O_COOK_INS; |
| 1661 | } |
| 1662 | else if (!strcmp(args[cur_arg], "nocache")) { |
| 1663 | curproxy->options |= PR_O_COOK_NOC; |
| 1664 | } |
| 1665 | else if (!strcmp(args[cur_arg], "postonly")) { |
| 1666 | curproxy->options |= PR_O_COOK_POST; |
| 1667 | } |
| 1668 | else if (!strcmp(args[cur_arg], "prefix")) { |
| 1669 | curproxy->options |= PR_O_COOK_PFX; |
| 1670 | } |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 1671 | else if (!strcmp(args[cur_arg], "domain")) { |
| 1672 | if (!*args[cur_arg + 1]) { |
| 1673 | Alert("parsing [%s:%d]: '%s' expects <domain> as argument.\n", |
| 1674 | file, linenum, args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1675 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1676 | goto out; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 1677 | } |
| 1678 | |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 1679 | if (*args[cur_arg + 1] != '.' || !strchr(args[cur_arg + 1] + 1, '.')) { |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 1680 | /* rfc2109, 4.3.2 Rejecting Cookies */ |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 1681 | Warning("parsing [%s:%d]: domain '%s' contains no embedded" |
| 1682 | " dots nor does not start with a dot." |
| 1683 | " RFC forbids it, this configuration may not work properly.\n", |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 1684 | file, linenum, args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 1685 | err_code |= ERR_WARN; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 1686 | } |
| 1687 | |
| 1688 | err = invalid_domainchar(args[cur_arg + 1]); |
| 1689 | if (err) { |
| 1690 | Alert("parsing [%s:%d]: character '%c' is not permitted in domain name '%s'.\n", |
| 1691 | file, linenum, *err, args[cur_arg + 1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1692 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1693 | goto out; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 1694 | } |
| 1695 | |
Willy Tarreau | 68a897b | 2009-12-03 23:28:34 +0100 | [diff] [blame] | 1696 | if (!curproxy->cookie_domain) { |
| 1697 | curproxy->cookie_domain = strdup(args[cur_arg + 1]); |
| 1698 | } else { |
| 1699 | /* one domain was already specified, add another one by |
| 1700 | * building the string which will be returned along with |
| 1701 | * the cookie. |
| 1702 | */ |
| 1703 | char *new_ptr; |
| 1704 | int new_len = strlen(curproxy->cookie_domain) + |
| 1705 | strlen("; domain=") + strlen(args[cur_arg + 1]) + 1; |
| 1706 | new_ptr = malloc(new_len); |
| 1707 | snprintf(new_ptr, new_len, "%s; domain=%s", curproxy->cookie_domain, args[cur_arg+1]); |
| 1708 | free(curproxy->cookie_domain); |
| 1709 | curproxy->cookie_domain = new_ptr; |
| 1710 | } |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 1711 | cur_arg++; |
| 1712 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1713 | else { |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 1714 | 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] | 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 | cur_arg++; |
| 1720 | } |
| 1721 | if (!POWEROF2(curproxy->options & (PR_O_COOK_RW|PR_O_COOK_IND))) { |
| 1722 | Alert("parsing [%s:%d] : cookie 'rewrite' and 'indirect' modes are incompatible.\n", |
| 1723 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1724 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1725 | } |
| 1726 | |
| 1727 | if (!POWEROF2(curproxy->options & (PR_O_COOK_RW|PR_O_COOK_INS|PR_O_COOK_PFX))) { |
| 1728 | Alert("parsing [%s:%d] : cookie 'rewrite', 'insert' and 'prefix' modes are incompatible.\n", |
| 1729 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1730 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1731 | } |
| 1732 | }/* end else if (!strcmp(args[0], "cookie")) */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 1733 | else if (!strcmp(args[0], "persist")) { /* persist */ |
| 1734 | if (*(args[1]) == 0) { |
| 1735 | Alert("parsing [%s:%d] : missing persist method.\n", |
| 1736 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1737 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1738 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 1739 | } |
| 1740 | |
| 1741 | if (!strncmp(args[1], "rdp-cookie", 10)) { |
| 1742 | curproxy->options2 |= PR_O2_RDPC_PRST; |
| 1743 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 1744 | if (*(args[1] + 10) == '(') { /* cookie name */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 1745 | const char *beg, *end; |
| 1746 | |
| 1747 | beg = args[1] + 11; |
| 1748 | end = strchr(beg, ')'); |
| 1749 | |
| 1750 | if (!end || end == beg) { |
| 1751 | Alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n", |
| 1752 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1753 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1754 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 1755 | } |
| 1756 | |
| 1757 | free(curproxy->rdp_cookie_name); |
| 1758 | curproxy->rdp_cookie_name = my_strndup(beg, end - beg); |
| 1759 | curproxy->rdp_cookie_len = end-beg; |
| 1760 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 1761 | else if (*(args[1] + 10) == '\0') { /* default cookie name 'msts' */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 1762 | free(curproxy->rdp_cookie_name); |
| 1763 | curproxy->rdp_cookie_name = strdup("msts"); |
| 1764 | curproxy->rdp_cookie_len = strlen(curproxy->rdp_cookie_name); |
| 1765 | } |
| 1766 | else { /* syntax */ |
| 1767 | Alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n", |
| 1768 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1769 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1770 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 1771 | } |
| 1772 | } |
| 1773 | else { |
| 1774 | Alert("parsing [%s:%d] : unknown persist method.\n", |
| 1775 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1776 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1777 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 1778 | } |
| 1779 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1780 | else if (!strcmp(args[0], "appsession")) { /* cookie name */ |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 1781 | int cur_arg; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1782 | |
Cyril Bonté | 3b7a369 | 2010-01-10 17:01:47 +0100 | [diff] [blame] | 1783 | if (curproxy == &defproxy) { |
| 1784 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 1785 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1786 | goto out; |
| 1787 | } |
| 1788 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1789 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1790 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1791 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1792 | if (*(args[5]) == 0) { |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 1793 | 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] | 1794 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1795 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1796 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1797 | } |
| 1798 | have_appsession = 1; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1799 | free(curproxy->appsession_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1800 | curproxy->appsession_name = strdup(args[1]); |
| 1801 | curproxy->appsession_name_len = strlen(curproxy->appsession_name); |
| 1802 | curproxy->appsession_len = atoi(args[3]); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 1803 | err = parse_time_err(args[5], &val, TIME_UNIT_MS); |
| 1804 | if (err) { |
| 1805 | Alert("parsing [%s:%d] : unexpected character '%c' in %s timeout.\n", |
| 1806 | file, linenum, *err, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1807 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1808 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 1809 | } |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 1810 | curproxy->timeout.appsession = val; |
Willy Tarreau | ee99136 | 2007-05-14 14:37:50 +0200 | [diff] [blame] | 1811 | |
Willy Tarreau | 51041c7 | 2007-09-09 21:56:53 +0200 | [diff] [blame] | 1812 | if (appsession_hash_init(&(curproxy->htbl_proxy), destroy) == 0) { |
| 1813 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1814 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1815 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1816 | } |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 1817 | |
| 1818 | cur_arg = 6; |
| 1819 | curproxy->options2 &= ~PR_O2_AS_REQL; |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 1820 | curproxy->options2 &= ~PR_O2_AS_M_ANY; |
| 1821 | curproxy->options2 |= PR_O2_AS_M_PP; |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 1822 | while (*(args[cur_arg])) { |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 1823 | if (!strcmp(args[cur_arg], "request-learn")) { |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 1824 | curproxy->options2 |= PR_O2_AS_REQL; |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 1825 | } else if (!strcmp(args[cur_arg], "prefix")) { |
| 1826 | curproxy->options2 |= PR_O2_AS_PFX; |
| 1827 | } else if (!strcmp(args[cur_arg], "mode")) { |
| 1828 | if (!*args[cur_arg + 1]) { |
| 1829 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 1830 | file, linenum, args[0], args[cur_arg]); |
| 1831 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1832 | goto out; |
| 1833 | } |
| 1834 | |
| 1835 | cur_arg++; |
| 1836 | if (!strcmp(args[cur_arg], "query-string")) { |
| 1837 | curproxy->options2 &= ~PR_O2_AS_M_ANY; |
| 1838 | curproxy->options2 |= PR_O2_AS_M_QS; |
| 1839 | } else if (!strcmp(args[cur_arg], "path-parameters")) { |
| 1840 | curproxy->options2 &= ~PR_O2_AS_M_ANY; |
| 1841 | curproxy->options2 |= PR_O2_AS_M_PP; |
| 1842 | } else { |
| 1843 | Alert("parsing [%s:%d] : unknown mode '%s'\n", file, linenum, args[cur_arg]); |
| 1844 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1845 | goto out; |
| 1846 | } |
| 1847 | } |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 1848 | cur_arg++; |
| 1849 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1850 | } /* Url App Session */ |
| 1851 | else if (!strcmp(args[0], "capture")) { |
Willy Tarreau | 3b6b1a9 | 2009-07-23 13:24:23 +0200 | [diff] [blame] | 1852 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1853 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1854 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1855 | if (!strcmp(args[1], "cookie")) { /* name of a cookie to capture */ |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 1856 | if (curproxy == &defproxy) { |
| 1857 | Alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
| 1858 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1859 | goto out; |
| 1860 | } |
| 1861 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1862 | if (*(args[4]) == 0) { |
| 1863 | Alert("parsing [%s:%d] : '%s' expects 'cookie' <cookie_name> 'len' <len>.\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 | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1867 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1868 | free(curproxy->capture_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1869 | curproxy->capture_name = strdup(args[2]); |
| 1870 | curproxy->capture_namelen = strlen(curproxy->capture_name); |
| 1871 | curproxy->capture_len = atol(args[4]); |
| 1872 | if (curproxy->capture_len >= CAPTURE_LEN) { |
| 1873 | Warning("parsing [%s:%d] : truncating capture length to %d bytes.\n", |
| 1874 | file, linenum, CAPTURE_LEN - 1); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1875 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1876 | curproxy->capture_len = CAPTURE_LEN - 1; |
| 1877 | } |
| 1878 | curproxy->to_log |= LW_COOKIE; |
| 1879 | } |
| 1880 | else if (!strcmp(args[1], "request") && !strcmp(args[2], "header")) { |
| 1881 | struct cap_hdr *hdr; |
| 1882 | |
| 1883 | if (curproxy == &defproxy) { |
| 1884 | 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] | 1885 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1886 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1887 | } |
| 1888 | |
| 1889 | if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) { |
| 1890 | Alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n", |
| 1891 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1892 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1893 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1894 | } |
| 1895 | |
| 1896 | hdr = calloc(sizeof(struct cap_hdr), 1); |
| 1897 | hdr->next = curproxy->req_cap; |
| 1898 | hdr->name = strdup(args[3]); |
| 1899 | hdr->namelen = strlen(args[3]); |
| 1900 | hdr->len = atol(args[5]); |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 1901 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1902 | hdr->index = curproxy->nb_req_cap++; |
| 1903 | curproxy->req_cap = hdr; |
| 1904 | curproxy->to_log |= LW_REQHDR; |
| 1905 | } |
| 1906 | else if (!strcmp(args[1], "response") && !strcmp(args[2], "header")) { |
| 1907 | struct cap_hdr *hdr; |
| 1908 | |
| 1909 | if (curproxy == &defproxy) { |
| 1910 | 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] | 1911 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1912 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1913 | } |
| 1914 | |
| 1915 | if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) { |
| 1916 | Alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n", |
| 1917 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1918 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1919 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1920 | } |
| 1921 | hdr = calloc(sizeof(struct cap_hdr), 1); |
| 1922 | hdr->next = curproxy->rsp_cap; |
| 1923 | hdr->name = strdup(args[3]); |
| 1924 | hdr->namelen = strlen(args[3]); |
| 1925 | hdr->len = atol(args[5]); |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 1926 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1927 | hdr->index = curproxy->nb_rsp_cap++; |
| 1928 | curproxy->rsp_cap = hdr; |
| 1929 | curproxy->to_log |= LW_RSPHDR; |
| 1930 | } |
| 1931 | else { |
| 1932 | Alert("parsing [%s:%d] : '%s' expects 'cookie' or 'request header' or 'response header'.\n", |
| 1933 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1934 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1935 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1936 | } |
| 1937 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1938 | else if (!strcmp(args[0], "retries")) { /* connection retries */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1939 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1940 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1941 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1942 | if (*(args[1]) == 0) { |
| 1943 | Alert("parsing [%s:%d] : '%s' expects an integer argument (dispatch counts for one).\n", |
| 1944 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1945 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1946 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1947 | } |
| 1948 | curproxy->conn_retries = atol(args[1]); |
| 1949 | } |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 1950 | else if (!strcmp(args[0], "http-request")) { /* request access control: allow/deny/auth */ |
| 1951 | struct req_acl_rule *req_acl; |
| 1952 | |
| 1953 | if (curproxy == &defproxy) { |
| 1954 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 1955 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1956 | goto out; |
| 1957 | } |
| 1958 | |
| 1959 | |
| 1960 | if (!LIST_ISEMPTY(&curproxy->req_acl) && !LIST_PREV(&curproxy->req_acl, struct req_acl_rule *, list)->cond) { |
| 1961 | Warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n", |
| 1962 | file, linenum, args[0]); |
| 1963 | err_code |= ERR_WARN; |
| 1964 | } |
| 1965 | |
Willy Tarreau | 9cc670f | 2010-02-01 10:43:44 +0100 | [diff] [blame] | 1966 | req_acl = parse_auth_cond((const char **)args + 1, file, linenum, curproxy); |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 1967 | |
| 1968 | if (!req_acl) { |
| 1969 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1970 | goto out; |
| 1971 | } |
| 1972 | |
Willy Tarreau | 9cc670f | 2010-02-01 10:43:44 +0100 | [diff] [blame] | 1973 | err_code |= warnif_cond_requires_resp(req_acl->cond, file, linenum); |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 1974 | LIST_ADDQ(&curproxy->req_acl, &req_acl->list); |
| 1975 | } |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 1976 | else if (!strcmp(args[0], "block")) { /* early blocking based on ACLs */ |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 1977 | if (curproxy == &defproxy) { |
| 1978 | 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] | 1979 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1980 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 1981 | } |
| 1982 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 1983 | if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) { |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 1984 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 1985 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1986 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1987 | goto out; |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 1988 | } |
| 1989 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 1990 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 1)) == NULL) { |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 1991 | Alert("parsing [%s:%d] : error detected while parsing blocking condition.\n", |
| 1992 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1993 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1994 | goto out; |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 1995 | } |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 1996 | |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 1997 | LIST_ADDQ(&curproxy->block_cond, &cond->list); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 1998 | warnif_misplaced_block(curproxy, file, linenum, args[0]); |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 1999 | } |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2000 | else if (!strcmp(args[0], "redirect")) { |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2001 | struct redirect_rule *rule; |
| 2002 | int cur_arg; |
| 2003 | int type = REDIRECT_TYPE_NONE; |
| 2004 | int code = 302; |
| 2005 | char *destination = NULL; |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2006 | char *cookie = NULL; |
| 2007 | int cookie_set = 0; |
Willy Tarreau | 79da469 | 2008-11-19 20:03:04 +0100 | [diff] [blame] | 2008 | unsigned int flags = REDIRECT_FLAG_NONE; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2009 | |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 2010 | if (curproxy == &defproxy) { |
| 2011 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2012 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2013 | goto out; |
| 2014 | } |
| 2015 | |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2016 | cur_arg = 1; |
| 2017 | while (*(args[cur_arg])) { |
| 2018 | if (!strcmp(args[cur_arg], "location")) { |
| 2019 | if (!*args[cur_arg + 1]) { |
| 2020 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 2021 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2022 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2023 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2024 | } |
| 2025 | |
| 2026 | type = REDIRECT_TYPE_LOCATION; |
| 2027 | cur_arg++; |
| 2028 | destination = args[cur_arg]; |
| 2029 | } |
| 2030 | else if (!strcmp(args[cur_arg], "prefix")) { |
| 2031 | if (!*args[cur_arg + 1]) { |
| 2032 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 2033 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2034 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2035 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2036 | } |
| 2037 | |
| 2038 | type = REDIRECT_TYPE_PREFIX; |
| 2039 | cur_arg++; |
| 2040 | destination = args[cur_arg]; |
| 2041 | } |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2042 | else if (!strcmp(args[cur_arg], "set-cookie")) { |
| 2043 | if (!*args[cur_arg + 1]) { |
| 2044 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 2045 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2046 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2047 | goto out; |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2048 | } |
| 2049 | |
| 2050 | cur_arg++; |
| 2051 | cookie = args[cur_arg]; |
| 2052 | cookie_set = 1; |
| 2053 | } |
| 2054 | else if (!strcmp(args[cur_arg], "clear-cookie")) { |
| 2055 | if (!*args[cur_arg + 1]) { |
| 2056 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 2057 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2058 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2059 | goto out; |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2060 | } |
| 2061 | |
| 2062 | cur_arg++; |
| 2063 | cookie = args[cur_arg]; |
| 2064 | cookie_set = 0; |
| 2065 | } |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2066 | else if (!strcmp(args[cur_arg],"code")) { |
| 2067 | if (!*args[cur_arg + 1]) { |
| 2068 | Alert("parsing [%s:%d] : '%s': missing HTTP code.\n", |
| 2069 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2070 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2071 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2072 | } |
| 2073 | cur_arg++; |
| 2074 | code = atol(args[cur_arg]); |
| 2075 | if (code < 301 || code > 303) { |
| 2076 | Alert("parsing [%s:%d] : '%s': unsupported HTTP code '%d'.\n", |
| 2077 | file, linenum, args[0], code); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2078 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2079 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2080 | } |
| 2081 | } |
Willy Tarreau | 79da469 | 2008-11-19 20:03:04 +0100 | [diff] [blame] | 2082 | else if (!strcmp(args[cur_arg],"drop-query")) { |
| 2083 | flags |= REDIRECT_FLAG_DROP_QS; |
| 2084 | } |
Willy Tarreau | 81e3b4f | 2010-01-10 00:42:19 +0100 | [diff] [blame] | 2085 | else if (!strcmp(args[cur_arg],"append-slash")) { |
| 2086 | flags |= REDIRECT_FLAG_APPEND_SLASH; |
| 2087 | } |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2088 | else if (strcmp(args[cur_arg], "if") == 0 || |
| 2089 | strcmp(args[cur_arg], "unless") == 0) { |
| 2090 | cond = build_acl_cond(file, linenum, curproxy, (const char **)args + cur_arg); |
| 2091 | if (!cond) { |
| 2092 | Alert("parsing [%s:%d] : '%s': error detected while parsing redirect condition.\n", |
| 2093 | file, linenum, args[0]); |
| 2094 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2095 | goto out; |
| 2096 | } |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2097 | break; |
| 2098 | } |
| 2099 | else { |
Willy Tarreau | 81e3b4f | 2010-01-10 00:42:19 +0100 | [diff] [blame] | 2100 | Alert("parsing [%s:%d] : '%s' expects 'code', 'prefix', 'location', 'set-cookie', 'clear-cookie', 'drop-query' or 'append-slash' (was '%s').\n", |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2101 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2102 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2103 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2104 | } |
| 2105 | cur_arg++; |
| 2106 | } |
| 2107 | |
| 2108 | if (type == REDIRECT_TYPE_NONE) { |
| 2109 | Alert("parsing [%s:%d] : '%s' expects a redirection type ('prefix' or 'location').\n", |
| 2110 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2111 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2112 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2113 | } |
| 2114 | |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2115 | rule = (struct redirect_rule *)calloc(1, sizeof(*rule)); |
| 2116 | rule->cond = cond; |
| 2117 | rule->rdr_str = strdup(destination); |
| 2118 | rule->rdr_len = strlen(destination); |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2119 | if (cookie) { |
| 2120 | /* depending on cookie_set, either we want to set the cookie, or to clear it. |
William Turner | d986526 | 2010-03-01 13:30:34 -0500 | [diff] [blame] | 2121 | * a clear consists in appending "; path=/; Max-Age=0;" at the end. |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2122 | */ |
| 2123 | rule->cookie_len = strlen(cookie); |
William Turner | d986526 | 2010-03-01 13:30:34 -0500 | [diff] [blame] | 2124 | if (cookie_set) { |
| 2125 | rule->cookie_str = malloc(rule->cookie_len + 10); |
| 2126 | memcpy(rule->cookie_str, cookie, rule->cookie_len); |
| 2127 | memcpy(rule->cookie_str + rule->cookie_len, "; path=/;", 10); |
| 2128 | rule->cookie_len += 9; |
| 2129 | } else { |
| 2130 | rule->cookie_str = malloc(rule->cookie_len + 21); |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2131 | memcpy(rule->cookie_str, cookie, rule->cookie_len); |
William Turner | d986526 | 2010-03-01 13:30:34 -0500 | [diff] [blame] | 2132 | memcpy(rule->cookie_str + rule->cookie_len, "; path=/; Max-Age=0;", 21); |
| 2133 | rule->cookie_len += 20; |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2134 | } |
| 2135 | } |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2136 | rule->type = type; |
| 2137 | rule->code = code; |
Willy Tarreau | 79da469 | 2008-11-19 20:03:04 +0100 | [diff] [blame] | 2138 | rule->flags = flags; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2139 | LIST_INIT(&rule->list); |
| 2140 | LIST_ADDQ(&curproxy->redirect_rules, &rule->list); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 2141 | warnif_rule_after_use_backend(curproxy, file, linenum, args[0]); |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2142 | } |
Krzysztof Piotr Oledzki | 7b723ef | 2009-01-27 21:09:41 +0100 | [diff] [blame] | 2143 | else if (!strcmp(args[0], "use_backend")) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2144 | struct switching_rule *rule; |
| 2145 | |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2146 | if (curproxy == &defproxy) { |
| 2147 | 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] | 2148 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2149 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2150 | } |
| 2151 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2152 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2153 | err_code |= ERR_WARN; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2154 | |
| 2155 | if (*(args[1]) == 0) { |
| 2156 | 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] | 2157 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2158 | goto out; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2159 | } |
| 2160 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2161 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2162 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 2163 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2164 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2165 | goto out; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2166 | } |
| 2167 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2168 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2)) == NULL) { |
Willy Tarreau | a980263 | 2008-07-25 19:13:19 +0200 | [diff] [blame] | 2169 | Alert("parsing [%s:%d] : error detected while parsing switching rule.\n", |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2170 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2171 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2172 | goto out; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2173 | } |
| 2174 | |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 2175 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
Willy Tarreau | a980263 | 2008-07-25 19:13:19 +0200 | [diff] [blame] | 2176 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2177 | rule = (struct switching_rule *)calloc(1, sizeof(*rule)); |
| 2178 | rule->cond = cond; |
| 2179 | rule->be.name = strdup(args[1]); |
| 2180 | LIST_INIT(&rule->list); |
| 2181 | LIST_ADDQ(&curproxy->switching_rules, &rule->list); |
| 2182 | } |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 2183 | else if ((!strcmp(args[0], "force-persist")) || |
| 2184 | (!strcmp(args[0], "ignore-persist"))) { |
| 2185 | struct persist_rule *rule; |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2186 | |
| 2187 | if (curproxy == &defproxy) { |
| 2188 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2189 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2190 | goto out; |
| 2191 | } |
| 2192 | |
| 2193 | if (warnifnotcap(curproxy, PR_CAP_FE|PR_CAP_BE, file, linenum, args[0], NULL)) |
| 2194 | err_code |= ERR_WARN; |
| 2195 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2196 | if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) { |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2197 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 2198 | file, linenum, args[0]); |
| 2199 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2200 | goto out; |
| 2201 | } |
| 2202 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2203 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 1)) == NULL) { |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 2204 | Alert("parsing [%s:%d] : error detected while parsing a '%s' rule.\n", |
| 2205 | file, linenum, args[0]); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2206 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2207 | goto out; |
| 2208 | } |
| 2209 | |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 2210 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2211 | |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 2212 | rule = (struct persist_rule *)calloc(1, sizeof(*rule)); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2213 | rule->cond = cond; |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 2214 | if (!strcmp(args[0], "force-persist")) { |
| 2215 | rule->type = PERSIST_TYPE_FORCE; |
| 2216 | } else { |
| 2217 | rule->type = PERSIST_TYPE_IGNORE; |
| 2218 | } |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2219 | LIST_INIT(&rule->list); |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 2220 | LIST_ADDQ(&curproxy->persist_rules, &rule->list); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2221 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2222 | else if (!strcmp(args[0], "stick-table")) { |
| 2223 | int myidx = 1; |
| 2224 | |
| 2225 | curproxy->table.type = (unsigned int)-1; |
| 2226 | while (*args[myidx]) { |
| 2227 | const char *err; |
| 2228 | |
| 2229 | if (strcmp(args[myidx], "size") == 0) { |
| 2230 | myidx++; |
| 2231 | if (!*(args[myidx])) { |
| 2232 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 2233 | file, linenum, args[myidx-1]); |
| 2234 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2235 | goto out; |
| 2236 | } |
| 2237 | if ((err = parse_size_err(args[myidx], &curproxy->table.size))) { |
| 2238 | Alert("parsing [%s:%d] : stick-table: unexpected character '%c' in argument of '%s'.\n", |
| 2239 | file, linenum, *err, args[myidx-1]); |
| 2240 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2241 | goto out; |
| 2242 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 2243 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2244 | } |
| 2245 | else if (strcmp(args[myidx], "expire") == 0) { |
| 2246 | myidx++; |
| 2247 | if (!*(args[myidx])) { |
| 2248 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 2249 | file, linenum, args[myidx-1]); |
| 2250 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2251 | goto out; |
| 2252 | } |
| 2253 | err = parse_time_err(args[myidx], &val, TIME_UNIT_MS); |
| 2254 | if (err) { |
| 2255 | Alert("parsing [%s:%d] : stick-table: unexpected character '%c' in argument of '%s'.\n", |
| 2256 | file, linenum, *err, args[myidx-1]); |
| 2257 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2258 | goto out; |
| 2259 | } |
| 2260 | curproxy->table.expire = val; |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 2261 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2262 | } |
| 2263 | else if (strcmp(args[myidx], "nopurge") == 0) { |
| 2264 | curproxy->table.nopurge = 1; |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 2265 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2266 | } |
| 2267 | else if (strcmp(args[myidx], "type") == 0) { |
| 2268 | myidx++; |
| 2269 | if (stktable_parse_type(args, &myidx, &curproxy->table.type, &curproxy->table.key_size) != 0) { |
| 2270 | Alert("parsing [%s:%d] : stick-table: unknown type '%s'.\n", |
| 2271 | file, linenum, args[myidx]); |
| 2272 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2273 | goto out; |
| 2274 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 2275 | /* myidx already points to next arg */ |
| 2276 | } |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 2277 | else if (strcmp(args[myidx], "store") == 0) { |
| 2278 | int type; |
| 2279 | |
| 2280 | myidx++; |
| 2281 | type = stktable_get_data_type(args[myidx]); |
| 2282 | if (type < 0) { |
| 2283 | Alert("parsing [%s:%d] : %s: unknown store option '%s'.\n", |
| 2284 | file, linenum, args[0], args[myidx]); |
| 2285 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2286 | goto out; |
| 2287 | } |
| 2288 | if (!stktable_alloc_data_type(&curproxy->table, type)) { |
| 2289 | Warning("parsing [%s:%d]: %s: store option '%s' already enabled, ignored.\n", |
| 2290 | file, linenum, args[0], args[myidx]); |
| 2291 | err_code |= ERR_WARN; |
| 2292 | } |
| 2293 | myidx++; |
| 2294 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 2295 | else { |
| 2296 | Alert("parsing [%s:%d] : stick-table: unknown argument '%s'.\n", |
| 2297 | file, linenum, args[myidx]); |
| 2298 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2299 | goto out; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2300 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2301 | } |
| 2302 | |
| 2303 | if (!curproxy->table.size) { |
| 2304 | Alert("parsing [%s:%d] : stick-table: missing size.\n", |
| 2305 | file, linenum); |
| 2306 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2307 | goto out; |
| 2308 | } |
| 2309 | |
| 2310 | if (curproxy->table.type == (unsigned int)-1) { |
| 2311 | Alert("parsing [%s:%d] : stick-table: missing type.\n", |
| 2312 | file, linenum); |
| 2313 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2314 | goto out; |
| 2315 | } |
| 2316 | } |
| 2317 | else if (!strcmp(args[0], "stick")) { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2318 | struct sticking_rule *rule; |
| 2319 | struct pattern_expr *expr; |
| 2320 | int myidx = 0; |
| 2321 | const char *name = NULL; |
| 2322 | int flags; |
| 2323 | |
| 2324 | if (curproxy == &defproxy) { |
| 2325 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2326 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2327 | goto out; |
| 2328 | } |
| 2329 | |
| 2330 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) { |
| 2331 | err_code |= ERR_WARN; |
| 2332 | goto out; |
| 2333 | } |
| 2334 | |
| 2335 | myidx++; |
| 2336 | if ((strcmp(args[myidx], "store") == 0) || |
| 2337 | (strcmp(args[myidx], "store-request") == 0)) { |
| 2338 | myidx++; |
| 2339 | flags = STK_IS_STORE; |
| 2340 | } |
| 2341 | else if (strcmp(args[myidx], "store-response") == 0) { |
| 2342 | myidx++; |
| 2343 | flags = STK_IS_STORE | STK_ON_RSP; |
| 2344 | } |
| 2345 | else if (strcmp(args[myidx], "match") == 0) { |
| 2346 | myidx++; |
| 2347 | flags = STK_IS_MATCH; |
| 2348 | } |
| 2349 | else if (strcmp(args[myidx], "on") == 0) { |
| 2350 | myidx++; |
| 2351 | flags = STK_IS_MATCH | STK_IS_STORE; |
| 2352 | } |
| 2353 | else { |
| 2354 | Alert("parsing [%s:%d] : '%s' expects 'on', 'match', or 'store'.\n", file, linenum, args[0]); |
| 2355 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2356 | goto out; |
| 2357 | } |
| 2358 | |
| 2359 | if (*(args[myidx]) == 0) { |
| 2360 | Alert("parsing [%s:%d] : '%s' expects a fetch method.\n", file, linenum, args[0]); |
| 2361 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2362 | goto out; |
| 2363 | } |
| 2364 | |
| 2365 | expr = pattern_parse_expr(args, &myidx); |
| 2366 | if (!expr) { |
| 2367 | Alert("parsing [%s:%d] : '%s': unknown fetch method '%s'.\n", file, linenum, args[0], args[myidx]); |
| 2368 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2369 | goto out; |
| 2370 | } |
| 2371 | |
| 2372 | if (flags & STK_ON_RSP) { |
| 2373 | if (!(expr->fetch->dir & PATTERN_FETCH_RTR)) { |
| 2374 | Alert("parsing [%s:%d] : '%s': fetch method '%s' can not be used on response.\n", |
| 2375 | file, linenum, args[0], expr->fetch->kw); |
| 2376 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2377 | goto out; |
| 2378 | } |
| 2379 | } else { |
| 2380 | if (!(expr->fetch->dir & PATTERN_FETCH_REQ)) { |
| 2381 | Alert("parsing [%s:%d] : '%s': fetch method '%s' can not be used on request.\n", |
| 2382 | file, linenum, args[0], expr->fetch->kw); |
| 2383 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2384 | goto out; |
| 2385 | } |
| 2386 | } |
| 2387 | |
| 2388 | if (strcmp(args[myidx], "table") == 0) { |
| 2389 | myidx++; |
| 2390 | name = args[myidx++]; |
| 2391 | } |
| 2392 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2393 | if (strcmp(args[myidx], "if") == 0 || strcmp(args[myidx], "unless") == 0) { |
| 2394 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + myidx)) == NULL) { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2395 | Alert("parsing [%s:%d] : '%s': error detected while parsing sticking condition.\n", |
| 2396 | file, linenum, args[0]); |
| 2397 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2398 | goto out; |
| 2399 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2400 | } |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2401 | else if (*(args[myidx])) { |
| 2402 | Alert("parsing [%s:%d] : '%s': unknown keyword '%s'.\n", |
| 2403 | file, linenum, args[0], args[myidx]); |
| 2404 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2405 | goto out; |
| 2406 | } |
| 2407 | |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 2408 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
| 2409 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2410 | rule = (struct sticking_rule *)calloc(1, sizeof(*rule)); |
| 2411 | rule->cond = cond; |
| 2412 | rule->expr = expr; |
| 2413 | rule->flags = flags; |
| 2414 | rule->table.name = name ? strdup(name) : NULL; |
| 2415 | LIST_INIT(&rule->list); |
| 2416 | if (flags & STK_ON_RSP) |
| 2417 | LIST_ADDQ(&curproxy->storersp_rules, &rule->list); |
| 2418 | else |
| 2419 | LIST_ADDQ(&curproxy->sticking_rules, &rule->list); |
| 2420 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2421 | else if (!strcmp(args[0], "stats")) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2422 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2423 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2424 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2425 | if (curproxy != &defproxy && curproxy->uri_auth == defproxy.uri_auth) |
| 2426 | curproxy->uri_auth = NULL; /* we must detach from the default config */ |
| 2427 | |
Krzysztof Piotr Oledzki | 260a3bb | 2010-01-06 16:25:05 +0100 | [diff] [blame] | 2428 | if (!*args[1]) { |
| 2429 | goto stats_error_parsing; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2430 | } else if (!strcmp(args[1], "uri")) { |
| 2431 | if (*(args[2]) == 0) { |
| 2432 | Alert("parsing [%s:%d] : 'uri' needs an URI prefix.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2433 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2434 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2435 | } else if (!stats_set_uri(&curproxy->uri_auth, args[2])) { |
| 2436 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2437 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2438 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2439 | } |
| 2440 | } else if (!strcmp(args[1], "realm")) { |
| 2441 | if (*(args[2]) == 0) { |
| 2442 | Alert("parsing [%s:%d] : 'realm' needs an realm name.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2443 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2444 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2445 | } else if (!stats_set_realm(&curproxy->uri_auth, args[2])) { |
| 2446 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2447 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2448 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2449 | } |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 2450 | } else if (!strcmp(args[1], "refresh")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 2451 | unsigned interval; |
| 2452 | |
| 2453 | err = parse_time_err(args[2], &interval, TIME_UNIT_S); |
| 2454 | if (err) { |
| 2455 | Alert("parsing [%s:%d] : unexpected character '%c' in stats refresh interval.\n", |
| 2456 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2457 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2458 | goto out; |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 2459 | } else if (!stats_set_refresh(&curproxy->uri_auth, interval)) { |
| 2460 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2461 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2462 | goto out; |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 2463 | } |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 2464 | } else if (!strcmp(args[1], "http-request")) { /* request access control: allow/deny/auth */ |
| 2465 | struct req_acl_rule *req_acl; |
| 2466 | |
| 2467 | if (curproxy == &defproxy) { |
| 2468 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2469 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2470 | goto out; |
| 2471 | } |
| 2472 | |
| 2473 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 2474 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 2475 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2476 | goto out; |
| 2477 | } |
| 2478 | |
| 2479 | if (!LIST_ISEMPTY(&curproxy->uri_auth->req_acl) && |
| 2480 | !LIST_PREV(&curproxy->uri_auth->req_acl, struct req_acl_rule *, list)->cond) { |
| 2481 | Warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n", |
| 2482 | file, linenum, args[0]); |
| 2483 | err_code |= ERR_WARN; |
| 2484 | } |
| 2485 | |
Willy Tarreau | 9cc670f | 2010-02-01 10:43:44 +0100 | [diff] [blame] | 2486 | req_acl = parse_auth_cond((const char **)args + 2, file, linenum, curproxy); |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 2487 | |
| 2488 | if (!req_acl) { |
| 2489 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2490 | goto out; |
| 2491 | } |
| 2492 | |
Willy Tarreau | 9cc670f | 2010-02-01 10:43:44 +0100 | [diff] [blame] | 2493 | err_code |= warnif_cond_requires_resp(req_acl->cond, file, linenum); |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 2494 | LIST_ADDQ(&curproxy->uri_auth->req_acl, &req_acl->list); |
| 2495 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2496 | } else if (!strcmp(args[1], "auth")) { |
| 2497 | if (*(args[2]) == 0) { |
| 2498 | 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] | 2499 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2500 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2501 | } else if (!stats_add_auth(&curproxy->uri_auth, args[2])) { |
| 2502 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2503 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2504 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2505 | } |
| 2506 | } else if (!strcmp(args[1], "scope")) { |
| 2507 | if (*(args[2]) == 0) { |
| 2508 | Alert("parsing [%s:%d] : 'scope' needs a proxy name.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2509 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2510 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2511 | } else if (!stats_add_scope(&curproxy->uri_auth, args[2])) { |
| 2512 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2513 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2514 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2515 | } |
| 2516 | } else if (!strcmp(args[1], "enable")) { |
| 2517 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 2518 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2519 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2520 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2521 | } |
Krzysztof Oledzki | d9db927 | 2007-10-15 10:05:11 +0200 | [diff] [blame] | 2522 | } else if (!strcmp(args[1], "hide-version")) { |
| 2523 | if (!stats_set_flag(&curproxy->uri_auth, ST_HIDEVER)) { |
| 2524 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2525 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2526 | goto out; |
Krzysztof Oledzki | d9db927 | 2007-10-15 10:05:11 +0200 | [diff] [blame] | 2527 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 2528 | } else if (!strcmp(args[1], "show-legends")) { |
| 2529 | if (!stats_set_flag(&curproxy->uri_auth, ST_SHLGNDS)) { |
| 2530 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 2531 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2532 | goto out; |
| 2533 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 2534 | } else if (!strcmp(args[1], "show-node")) { |
| 2535 | |
| 2536 | if (*args[2]) { |
| 2537 | int i; |
| 2538 | char c; |
| 2539 | |
| 2540 | for (i=0; args[2][i]; i++) { |
| 2541 | c = args[2][i]; |
Willy Tarreau | 88e0581 | 2010-03-03 00:16:00 +0100 | [diff] [blame] | 2542 | if (!isupper((unsigned char)c) && !islower((unsigned char)c) && |
| 2543 | !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.') |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 2544 | break; |
| 2545 | } |
| 2546 | |
| 2547 | if (!i || args[2][i]) { |
| 2548 | Alert("parsing [%s:%d]: '%s %s' invalid node name - should be a string" |
| 2549 | "with digits(0-9), letters(A-Z, a-z), hyphen(-) or underscode(_).\n", |
| 2550 | file, linenum, args[0], args[1]); |
| 2551 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2552 | goto out; |
| 2553 | } |
| 2554 | } |
| 2555 | |
| 2556 | if (!stats_set_node(&curproxy->uri_auth, args[2])) { |
| 2557 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 2558 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2559 | goto out; |
| 2560 | } |
| 2561 | } else if (!strcmp(args[1], "show-desc")) { |
| 2562 | char *desc = NULL; |
| 2563 | |
| 2564 | if (*args[2]) { |
| 2565 | int i, len=0; |
| 2566 | char *d; |
| 2567 | |
| 2568 | for(i=2; *args[i]; i++) |
| 2569 | len += strlen(args[i])+1; |
| 2570 | |
| 2571 | desc = d = (char *)calloc(1, len); |
| 2572 | |
| 2573 | d += sprintf(d, "%s", args[2]); |
| 2574 | for(i=3; *args[i]; i++) |
| 2575 | d += sprintf(d, " %s", args[i]); |
| 2576 | } |
| 2577 | |
| 2578 | if (!*args[2] && !global.desc) |
| 2579 | Warning("parsing [%s:%d]: '%s' requires a parameter or 'desc' to be set in the global section.\n", |
| 2580 | file, linenum, args[1]); |
| 2581 | else { |
| 2582 | if (!stats_set_desc(&curproxy->uri_auth, desc)) { |
| 2583 | free(desc); |
| 2584 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 2585 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2586 | goto out; |
| 2587 | } |
| 2588 | free(desc); |
| 2589 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2590 | } else { |
Krzysztof Piotr Oledzki | 260a3bb | 2010-01-06 16:25:05 +0100 | [diff] [blame] | 2591 | stats_error_parsing: |
| 2592 | Alert("parsing [%s:%d]: %s '%s', expects 'uri', 'realm', 'auth', 'scope', 'enable', 'hide-version', 'show-node', 'show-desc' or 'show-legends'.\n", |
| 2593 | file, linenum, *args[1]?"unknown stats parameter":"missing keyword in", args[*args[1]?1:0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2594 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2595 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2596 | } |
| 2597 | } |
| 2598 | else if (!strcmp(args[0], "option")) { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 2599 | int optnum; |
| 2600 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 2601 | if (*(args[1]) == '\0') { |
| 2602 | Alert("parsing [%s:%d]: '%s' expects an option name.\n", |
| 2603 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2604 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2605 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2606 | } |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 2607 | |
| 2608 | for (optnum = 0; cfg_opts[optnum].name; optnum++) { |
| 2609 | if (!strcmp(args[1], cfg_opts[optnum].name)) { |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2610 | if (warnifnotcap(curproxy, cfg_opts[optnum].cap, file, linenum, args[1], NULL)) { |
| 2611 | err_code |= ERR_WARN; |
| 2612 | goto out; |
| 2613 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 2614 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 2615 | curproxy->no_options &= ~cfg_opts[optnum].val; |
| 2616 | curproxy->options &= ~cfg_opts[optnum].val; |
| 2617 | |
| 2618 | switch (kwm) { |
| 2619 | case KWM_STD: |
| 2620 | curproxy->options |= cfg_opts[optnum].val; |
| 2621 | break; |
| 2622 | case KWM_NO: |
| 2623 | curproxy->no_options |= cfg_opts[optnum].val; |
| 2624 | break; |
| 2625 | case KWM_DEF: /* already cleared */ |
| 2626 | break; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 2627 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 2628 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2629 | goto out; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 2630 | } |
| 2631 | } |
| 2632 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 2633 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) { |
| 2634 | if (!strcmp(args[1], cfg_opts2[optnum].name)) { |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2635 | if (warnifnotcap(curproxy, cfg_opts2[optnum].cap, file, linenum, args[1], NULL)) { |
| 2636 | err_code |= ERR_WARN; |
| 2637 | goto out; |
| 2638 | } |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 2639 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 2640 | curproxy->no_options2 &= ~cfg_opts2[optnum].val; |
| 2641 | curproxy->options2 &= ~cfg_opts2[optnum].val; |
| 2642 | |
| 2643 | switch (kwm) { |
| 2644 | case KWM_STD: |
| 2645 | curproxy->options2 |= cfg_opts2[optnum].val; |
| 2646 | break; |
| 2647 | case KWM_NO: |
| 2648 | curproxy->no_options2 |= cfg_opts2[optnum].val; |
| 2649 | break; |
| 2650 | case KWM_DEF: /* already cleared */ |
| 2651 | break; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 2652 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2653 | goto out; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 2654 | } |
| 2655 | } |
| 2656 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 2657 | if (kwm != KWM_STD) { |
| 2658 | 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] | 2659 | file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2660 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2661 | goto out; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 2662 | } |
| 2663 | |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 2664 | if (!strcmp(args[1], "httplog")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2665 | /* generate a complete HTTP log */ |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 2666 | curproxy->options2 &= ~PR_O2_CLFLOG; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2667 | 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] | 2668 | if (*(args[2]) != '\0') { |
| 2669 | if (!strcmp(args[2], "clf")) { |
| 2670 | curproxy->options2 |= PR_O2_CLFLOG; |
| 2671 | } else { |
| 2672 | 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] | 2673 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2674 | goto out; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 2675 | } |
| 2676 | } |
| 2677 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2678 | else if (!strcmp(args[1], "tcplog")) |
| 2679 | /* generate a detailed TCP log */ |
| 2680 | 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] | 2681 | else if (!strcmp(args[1], "tcpka")) { |
| 2682 | /* enable TCP keep-alives on client and server sessions */ |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 2683 | 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] | 2684 | err_code |= ERR_WARN; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 2685 | |
| 2686 | if (curproxy->cap & PR_CAP_FE) |
| 2687 | curproxy->options |= PR_O_TCP_CLI_KA; |
| 2688 | if (curproxy->cap & PR_CAP_BE) |
| 2689 | curproxy->options |= PR_O_TCP_SRV_KA; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2690 | } |
| 2691 | else if (!strcmp(args[1], "httpchk")) { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 2692 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2693 | err_code |= ERR_WARN; |
| 2694 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2695 | /* use HTTP request to check servers' health */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2696 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 2697 | curproxy->check_req = NULL; |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 2698 | curproxy->options &= ~PR_O_SMTP_CHK; |
Willy Tarreau | 07a5490 | 2010-03-29 18:33:29 +0200 | [diff] [blame] | 2699 | curproxy->options2 &= ~PR_O2_SSL3_CHK; |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 2700 | curproxy->options2 &= ~PR_O2_MYSQL_CHK; |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 2701 | curproxy->options |= PR_O_HTTP_CHK; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2702 | if (!*args[2]) { /* no argument */ |
| 2703 | curproxy->check_req = strdup(DEF_CHECK_REQ); /* default request */ |
| 2704 | curproxy->check_len = strlen(DEF_CHECK_REQ); |
| 2705 | } else if (!*args[3]) { /* one argument : URI */ |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 2706 | int reqlen = strlen(args[2]) + strlen("OPTIONS HTTP/1.0\r\n") + 1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2707 | curproxy->check_req = (char *)malloc(reqlen); |
| 2708 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 2709 | "OPTIONS %s HTTP/1.0\r\n", args[2]); /* URI to use */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2710 | } else { /* more arguments : METHOD URI [HTTP_VER] */ |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 2711 | int reqlen = strlen(args[2]) + strlen(args[3]) + 3 + strlen("\r\n"); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2712 | if (*args[4]) |
| 2713 | reqlen += strlen(args[4]); |
| 2714 | else |
| 2715 | reqlen += strlen("HTTP/1.0"); |
| 2716 | |
| 2717 | curproxy->check_req = (char *)malloc(reqlen); |
| 2718 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 2719 | "%s %s %s\r\n", args[2], args[3], *args[4]?args[4]:"HTTP/1.0"); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2720 | } |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 2721 | } |
| 2722 | else if (!strcmp(args[1], "ssl-hello-chk")) { |
| 2723 | /* use SSLv3 CLIENT HELLO to check servers' health */ |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 2724 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2725 | err_code |= ERR_WARN; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 2726 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2727 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 2728 | curproxy->check_req = NULL; |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 2729 | curproxy->options &= ~PR_O_HTTP_CHK; |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 2730 | curproxy->options &= ~PR_O_SMTP_CHK; |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 2731 | curproxy->options2 &= ~PR_O2_MYSQL_CHK; |
Willy Tarreau | 07a5490 | 2010-03-29 18:33:29 +0200 | [diff] [blame] | 2732 | curproxy->options2 |= PR_O2_SSL3_CHK; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2733 | } |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 2734 | else if (!strcmp(args[1], "smtpchk")) { |
| 2735 | /* use SMTP request to check servers' health */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2736 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 2737 | curproxy->check_req = NULL; |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 2738 | curproxy->options &= ~PR_O_HTTP_CHK; |
Willy Tarreau | 07a5490 | 2010-03-29 18:33:29 +0200 | [diff] [blame] | 2739 | curproxy->options2 &= ~PR_O2_SSL3_CHK; |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 2740 | curproxy->options2 &= ~PR_O2_MYSQL_CHK; |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 2741 | curproxy->options |= PR_O_SMTP_CHK; |
| 2742 | |
| 2743 | if (!*args[2] || !*args[3]) { /* no argument or incomplete EHLO host */ |
| 2744 | curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */ |
| 2745 | curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ); |
| 2746 | } else { /* ESMTP EHLO, or SMTP HELO, and a hostname */ |
| 2747 | if (!strcmp(args[2], "EHLO") || !strcmp(args[2], "HELO")) { |
| 2748 | int reqlen = strlen(args[2]) + strlen(args[3]) + strlen(" \r\n") + 1; |
| 2749 | curproxy->check_req = (char *)malloc(reqlen); |
| 2750 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
| 2751 | "%s %s\r\n", args[2], args[3]); /* HELO hostname */ |
| 2752 | } else { |
| 2753 | /* this just hits the default for now, but you could potentially expand it to allow for other stuff |
| 2754 | though, it's unlikely you'd want to send anything other than an EHLO or HELO */ |
| 2755 | curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */ |
| 2756 | curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ); |
| 2757 | } |
| 2758 | } |
| 2759 | } |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 2760 | else if (!strcmp(args[1], "mysql-check")) { |
| 2761 | /* use MYSQL request to check servers' health */ |
| 2762 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 2763 | curproxy->check_req = NULL; |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 2764 | curproxy->options &= ~PR_O_HTTP_CHK; |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 2765 | curproxy->options &= ~PR_O_SMTP_CHK; |
Willy Tarreau | 07a5490 | 2010-03-29 18:33:29 +0200 | [diff] [blame] | 2766 | curproxy->options2 &= ~PR_O2_SSL3_CHK; |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 2767 | curproxy->options2 |= PR_O2_MYSQL_CHK; |
| 2768 | } |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 2769 | else if (!strcmp(args[1], "forwardfor")) { |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 2770 | int cur_arg; |
| 2771 | |
| 2772 | /* insert x-forwarded-for field, but not for the IP address listed as an except. |
| 2773 | * set default options (ie: bitfield, header name, etc) |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 2774 | */ |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 2775 | |
| 2776 | curproxy->options |= PR_O_FWDFOR; |
| 2777 | |
| 2778 | free(curproxy->fwdfor_hdr_name); |
| 2779 | curproxy->fwdfor_hdr_name = strdup(DEF_XFORWARDFOR_HDR); |
| 2780 | curproxy->fwdfor_hdr_len = strlen(DEF_XFORWARDFOR_HDR); |
| 2781 | |
| 2782 | /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */ |
| 2783 | cur_arg = 2; |
| 2784 | while (*(args[cur_arg])) { |
| 2785 | if (!strcmp(args[cur_arg], "except")) { |
| 2786 | /* suboption except - needs additional argument for it */ |
| 2787 | if (!*(args[cur_arg+1]) || !str2net(args[cur_arg+1], &curproxy->except_net, &curproxy->except_mask)) { |
| 2788 | Alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n", |
| 2789 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2790 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2791 | goto out; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 2792 | } |
| 2793 | /* flush useless bits */ |
| 2794 | curproxy->except_net.s_addr &= curproxy->except_mask.s_addr; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 2795 | cur_arg += 2; |
| 2796 | } else if (!strcmp(args[cur_arg], "header")) { |
| 2797 | /* suboption header - needs additional argument for it */ |
| 2798 | if (*(args[cur_arg+1]) == 0) { |
| 2799 | Alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 2800 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2801 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2802 | goto out; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 2803 | } |
| 2804 | free(curproxy->fwdfor_hdr_name); |
| 2805 | curproxy->fwdfor_hdr_name = strdup(args[cur_arg+1]); |
| 2806 | curproxy->fwdfor_hdr_len = strlen(curproxy->fwdfor_hdr_name); |
| 2807 | cur_arg += 2; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 2808 | } else { |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 2809 | /* unknown suboption - catchall */ |
| 2810 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n", |
| 2811 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2812 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2813 | goto out; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 2814 | } |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 2815 | } /* end while loop */ |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 2816 | } |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 2817 | else if (!strcmp(args[1], "originalto")) { |
| 2818 | int cur_arg; |
| 2819 | |
| 2820 | /* insert x-original-to field, but not for the IP address listed as an except. |
| 2821 | * set default options (ie: bitfield, header name, etc) |
| 2822 | */ |
| 2823 | |
| 2824 | curproxy->options |= PR_O_ORGTO; |
| 2825 | |
| 2826 | free(curproxy->orgto_hdr_name); |
| 2827 | curproxy->orgto_hdr_name = strdup(DEF_XORIGINALTO_HDR); |
| 2828 | curproxy->orgto_hdr_len = strlen(DEF_XORIGINALTO_HDR); |
| 2829 | |
| 2830 | /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */ |
| 2831 | cur_arg = 2; |
| 2832 | while (*(args[cur_arg])) { |
| 2833 | if (!strcmp(args[cur_arg], "except")) { |
| 2834 | /* suboption except - needs additional argument for it */ |
| 2835 | if (!*(args[cur_arg+1]) || !str2net(args[cur_arg+1], &curproxy->except_to, &curproxy->except_mask_to)) { |
| 2836 | Alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n", |
| 2837 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2838 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2839 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 2840 | } |
| 2841 | /* flush useless bits */ |
| 2842 | curproxy->except_to.s_addr &= curproxy->except_mask_to.s_addr; |
| 2843 | cur_arg += 2; |
| 2844 | } else if (!strcmp(args[cur_arg], "header")) { |
| 2845 | /* suboption header - needs additional argument for it */ |
| 2846 | if (*(args[cur_arg+1]) == 0) { |
| 2847 | Alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 2848 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2849 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2850 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 2851 | } |
| 2852 | free(curproxy->orgto_hdr_name); |
| 2853 | curproxy->orgto_hdr_name = strdup(args[cur_arg+1]); |
| 2854 | curproxy->orgto_hdr_len = strlen(curproxy->orgto_hdr_name); |
| 2855 | cur_arg += 2; |
| 2856 | } else { |
| 2857 | /* unknown suboption - catchall */ |
| 2858 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n", |
| 2859 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2860 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2861 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 2862 | } |
| 2863 | } /* end while loop */ |
| 2864 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2865 | else { |
| 2866 | Alert("parsing [%s:%d] : unknown option '%s'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2867 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2868 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2869 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2870 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2871 | } |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 2872 | else if (!strcmp(args[0], "default_backend")) { |
| 2873 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2874 | err_code |= ERR_WARN; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 2875 | |
| 2876 | if (*(args[1]) == 0) { |
| 2877 | 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] | 2878 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2879 | goto out; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 2880 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2881 | free(curproxy->defbe.name); |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 2882 | curproxy->defbe.name = strdup(args[1]); |
| 2883 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2884 | else if (!strcmp(args[0], "redispatch") || !strcmp(args[0], "redisp")) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2885 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2886 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2887 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 2888 | Warning("parsing [%s:%d]: keyword '%s' is deprecated, please use 'option redispatch' instead.\n", |
| 2889 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2890 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2891 | /* enable reconnections to dispatch */ |
| 2892 | curproxy->options |= PR_O_REDISP; |
| 2893 | } |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 2894 | else if (!strcmp(args[0], "http-check")) { |
| 2895 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2896 | err_code |= ERR_WARN; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 2897 | |
| 2898 | if (strcmp(args[1], "disable-on-404") == 0) { |
| 2899 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 2900 | curproxy->options |= PR_O_DISABLE404; |
| 2901 | } |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 2902 | else if (strcmp(args[1], "send-state") == 0) { |
| 2903 | /* enable emission of the apparent state of a server in HTTP checks */ |
| 2904 | curproxy->options2 |= PR_O2_CHK_SNDST; |
| 2905 | } |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 2906 | else { |
| 2907 | 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] | 2908 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2909 | goto out; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 2910 | } |
| 2911 | } |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 2912 | else if (!strcmp(args[0], "monitor")) { |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2913 | if (curproxy == &defproxy) { |
| 2914 | 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] | 2915 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2916 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2917 | } |
| 2918 | |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 2919 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2920 | err_code |= ERR_WARN; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 2921 | |
| 2922 | if (strcmp(args[1], "fail") == 0) { |
| 2923 | /* add a condition to fail monitor requests */ |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2924 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 2925 | Alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n", |
| 2926 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2927 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2928 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 2929 | } |
| 2930 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2931 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2)) == NULL) { |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 2932 | Alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition.\n", |
| 2933 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2934 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2935 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 2936 | } |
| 2937 | LIST_ADDQ(&curproxy->mon_fail_cond, &cond->list); |
| 2938 | } |
| 2939 | else { |
| 2940 | 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] | 2941 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2942 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 2943 | } |
| 2944 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2945 | #ifdef TPROXY |
| 2946 | else if (!strcmp(args[0], "transparent")) { |
| 2947 | /* enable transparent proxy connections */ |
| 2948 | curproxy->options |= PR_O_TRANSP; |
| 2949 | } |
| 2950 | #endif |
| 2951 | else if (!strcmp(args[0], "maxconn")) { /* maxconn */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2952 | 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] | 2953 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2954 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2955 | if (*(args[1]) == 0) { |
| 2956 | 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] | 2957 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2958 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2959 | } |
| 2960 | curproxy->maxconn = atol(args[1]); |
| 2961 | } |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 2962 | else if (!strcmp(args[0], "backlog")) { /* backlog */ |
| 2963 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2964 | err_code |= ERR_WARN; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 2965 | |
| 2966 | if (*(args[1]) == 0) { |
| 2967 | 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] | 2968 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2969 | goto out; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 2970 | } |
| 2971 | curproxy->backlog = atol(args[1]); |
| 2972 | } |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 2973 | else if (!strcmp(args[0], "fullconn")) { /* fullconn */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2974 | 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] | 2975 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2976 | |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 2977 | if (*(args[1]) == 0) { |
| 2978 | 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] | 2979 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2980 | goto out; |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 2981 | } |
| 2982 | curproxy->fullconn = atol(args[1]); |
| 2983 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2984 | else if (!strcmp(args[0], "grace")) { /* grace time (ms) */ |
| 2985 | if (*(args[1]) == 0) { |
| 2986 | 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] | 2987 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2988 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2989 | } |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 2990 | err = parse_time_err(args[1], &val, TIME_UNIT_MS); |
| 2991 | if (err) { |
| 2992 | Alert("parsing [%s:%d] : unexpected character '%c' in grace time.\n", |
| 2993 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2994 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2995 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 2996 | } |
| 2997 | curproxy->grace = val; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2998 | } |
| 2999 | else if (!strcmp(args[0], "dispatch")) { /* dispatch address */ |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 3000 | struct sockaddr_in *sk; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3001 | if (curproxy == &defproxy) { |
| 3002 | 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] | 3003 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3004 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3005 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3006 | else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3007 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3008 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3009 | if (strchr(args[1], ':') == NULL) { |
| 3010 | 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] | 3011 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3012 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3013 | } |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 3014 | sk = str2sa(args[1]); |
| 3015 | if (!sk) { |
| 3016 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[1]); |
| 3017 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3018 | goto out; |
| 3019 | } |
| 3020 | curproxy->dispatch_addr = *sk; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3021 | } |
| 3022 | else if (!strcmp(args[0], "balance")) { /* set balancing with optional algorithm */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3023 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3024 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3025 | |
Jeffrey 'jf' Lim | 65cb2f1 | 2008-10-04 18:07:00 +0200 | [diff] [blame] | 3026 | memcpy(trash, "error near 'balance'", 21); |
Willy Tarreau | a0cbda6 | 2007-11-01 21:39:54 +0100 | [diff] [blame] | 3027 | if (backend_parse_balance((const char **)args + 1, trash, sizeof(trash), curproxy) < 0) { |
| 3028 | Alert("parsing [%s:%d] : %s\n", file, linenum, trash); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3029 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3030 | goto out; |
Willy Tarreau | 2fcb500 | 2007-05-08 13:35:26 +0200 | [diff] [blame] | 3031 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3032 | } |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 3033 | else if (!strcmp(args[0], "hash-type")) { /* set hashing method */ |
| 3034 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 3035 | err_code |= ERR_WARN; |
| 3036 | |
| 3037 | if (strcmp(args[1], "consistent") == 0) { /* use consistent hashing */ |
| 3038 | curproxy->lbprm.algo &= ~BE_LB_HASH_TYPE; |
| 3039 | curproxy->lbprm.algo |= BE_LB_HASH_CONS; |
| 3040 | } |
| 3041 | else if (strcmp(args[1], "map-based") == 0) { /* use map-based hashing */ |
| 3042 | curproxy->lbprm.algo &= ~BE_LB_HASH_TYPE; |
| 3043 | curproxy->lbprm.algo |= BE_LB_HASH_MAP; |
| 3044 | } |
| 3045 | else { |
| 3046 | Alert("parsing [%s:%d] : '%s' only supports 'consistent' and 'map-based'.\n", file, linenum, args[0]); |
| 3047 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3048 | goto out; |
| 3049 | } |
| 3050 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3051 | else if (!strcmp(args[0], "server") || !strcmp(args[0], "default-server")) { /* server address */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3052 | int cur_arg; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3053 | char *rport, *raddr; |
| 3054 | short realport = 0; |
| 3055 | int do_check = 0, defsrv = (*args[0] == 'd'); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3056 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3057 | if (!defsrv && curproxy == &defproxy) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3058 | 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] | 3059 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3060 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3061 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3062 | else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3063 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3064 | |
| 3065 | if (!*args[2]) { |
| 3066 | Alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n", |
| 3067 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3068 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3069 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3070 | } |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 3071 | |
| 3072 | err = invalid_char(args[1]); |
| 3073 | if (err) { |
| 3074 | Alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n", |
| 3075 | file, linenum, *err, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3076 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3077 | goto out; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 3078 | } |
| 3079 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3080 | if (!defsrv) { |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 3081 | struct sockaddr_in *sk; |
| 3082 | |
Krzysztof Piotr Oledzki | aff01ea | 2010-02-05 20:31:44 +0100 | [diff] [blame] | 3083 | if ((newsrv = (struct server *)calloc(1, sizeof(struct server))) == NULL) { |
| 3084 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 3085 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3086 | goto out; |
| 3087 | } |
| 3088 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3089 | /* the servers are linked backwards first */ |
| 3090 | newsrv->next = curproxy->srv; |
| 3091 | curproxy->srv = newsrv; |
| 3092 | newsrv->proxy = curproxy; |
| 3093 | newsrv->conf.file = file; |
| 3094 | newsrv->conf.line = linenum; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3095 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3096 | LIST_INIT(&newsrv->pendconns); |
| 3097 | do_check = 0; |
| 3098 | newsrv->state = SRV_RUNNING; /* early server setup */ |
| 3099 | newsrv->last_change = now.tv_sec; |
| 3100 | newsrv->id = strdup(args[1]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3101 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3102 | /* several ways to check the port component : |
| 3103 | * - IP => port=+0, relative |
| 3104 | * - IP: => port=+0, relative |
| 3105 | * - IP:N => port=N, absolute |
| 3106 | * - IP:+N => port=+N, relative |
| 3107 | * - IP:-N => port=-N, relative |
| 3108 | */ |
| 3109 | raddr = strdup(args[2]); |
| 3110 | rport = strchr(raddr, ':'); |
| 3111 | if (rport) { |
| 3112 | *rport++ = 0; |
| 3113 | realport = atol(rport); |
| 3114 | if (!isdigit((unsigned char)*rport)) |
| 3115 | newsrv->state |= SRV_MAPPORTS; |
| 3116 | } else |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3117 | newsrv->state |= SRV_MAPPORTS; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3118 | |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 3119 | sk = str2sa(raddr); |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3120 | free(raddr); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 3121 | if (!sk) { |
| 3122 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[2]); |
| 3123 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3124 | goto out; |
| 3125 | } |
| 3126 | newsrv->addr = *sk; |
| 3127 | newsrv->addr.sin_port = htons(realport); |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3128 | |
| 3129 | newsrv->check_port = curproxy->defsrv.check_port; |
| 3130 | newsrv->inter = curproxy->defsrv.inter; |
| 3131 | newsrv->fastinter = curproxy->defsrv.fastinter; |
| 3132 | newsrv->downinter = curproxy->defsrv.downinter; |
| 3133 | newsrv->rise = curproxy->defsrv.rise; |
| 3134 | newsrv->fall = curproxy->defsrv.fall; |
| 3135 | newsrv->maxqueue = curproxy->defsrv.maxqueue; |
| 3136 | newsrv->minconn = curproxy->defsrv.minconn; |
| 3137 | newsrv->maxconn = curproxy->defsrv.maxconn; |
| 3138 | newsrv->slowstart = curproxy->defsrv.slowstart; |
| 3139 | newsrv->onerror = curproxy->defsrv.onerror; |
| 3140 | newsrv->consecutive_errors_limit |
| 3141 | = curproxy->defsrv.consecutive_errors_limit; |
| 3142 | newsrv->uweight = newsrv->iweight |
| 3143 | = curproxy->defsrv.iweight; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3144 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3145 | newsrv->curfd = -1; /* no health-check in progress */ |
| 3146 | newsrv->health = newsrv->rise; /* up, but will fall down at first failure */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3147 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3148 | cur_arg = 3; |
| 3149 | } else { |
| 3150 | newsrv = &curproxy->defsrv; |
| 3151 | cur_arg = 1; |
| 3152 | } |
Willy Tarreau | 0f03c6f | 2007-03-25 20:46:19 +0200 | [diff] [blame] | 3153 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3154 | while (*args[cur_arg]) { |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3155 | if (!defsrv && !strcmp(args[cur_arg], "id")) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 3156 | struct eb32_node *node; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3157 | |
| 3158 | if (!*args[cur_arg + 1]) { |
| 3159 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 3160 | file, linenum, args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3161 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3162 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3163 | } |
| 3164 | |
| 3165 | newsrv->puid = atol(args[cur_arg + 1]); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 3166 | newsrv->conf.id.key = newsrv->puid; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3167 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 3168 | if (newsrv->puid <= 0) { |
| 3169 | Alert("parsing [%s:%d]: custom id has to be > 0.\n", |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3170 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3171 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3172 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3173 | } |
| 3174 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 3175 | node = eb32_lookup(&curproxy->conf.used_server_id, newsrv->puid); |
| 3176 | if (node) { |
| 3177 | struct server *target = container_of(node, struct server, conf.id); |
| 3178 | Alert("parsing [%s:%d]: server %s reuses same custom id as server %s (declared at %s:%d).\n", |
| 3179 | file, linenum, newsrv->id, target->id, target->conf.file, target->conf.line); |
| 3180 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3181 | goto out; |
| 3182 | } |
| 3183 | eb32_insert(&curproxy->conf.used_server_id, &newsrv->conf.id); |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3184 | cur_arg += 2; |
| 3185 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3186 | else if (!defsrv && !strcmp(args[cur_arg], "cookie")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3187 | newsrv->cookie = strdup(args[cur_arg + 1]); |
| 3188 | newsrv->cklen = strlen(args[cur_arg + 1]); |
| 3189 | cur_arg += 2; |
| 3190 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3191 | else if (!defsrv && !strcmp(args[cur_arg], "redir")) { |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 3192 | newsrv->rdr_pfx = strdup(args[cur_arg + 1]); |
| 3193 | newsrv->rdr_len = strlen(args[cur_arg + 1]); |
| 3194 | cur_arg += 2; |
| 3195 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3196 | else if (!strcmp(args[cur_arg], "rise")) { |
Krzysztof Piotr Oledzki | 08ff959 | 2009-09-27 16:17:31 +0200 | [diff] [blame] | 3197 | if (!*args[cur_arg + 1]) { |
| 3198 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 3199 | file, linenum, args[cur_arg]); |
| 3200 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3201 | goto out; |
| 3202 | } |
| 3203 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3204 | newsrv->rise = atol(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 08ff959 | 2009-09-27 16:17:31 +0200 | [diff] [blame] | 3205 | if (newsrv->rise <= 0) { |
| 3206 | Alert("parsing [%s:%d]: '%s' has to be > 0.\n", |
| 3207 | file, linenum, args[cur_arg]); |
| 3208 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3209 | goto out; |
| 3210 | } |
| 3211 | |
Willy Tarreau | 9683909 | 2010-03-29 10:02:24 +0200 | [diff] [blame] | 3212 | if (newsrv->health) |
| 3213 | newsrv->health = newsrv->rise; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3214 | cur_arg += 2; |
| 3215 | } |
| 3216 | else if (!strcmp(args[cur_arg], "fall")) { |
| 3217 | newsrv->fall = atol(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 08ff959 | 2009-09-27 16:17:31 +0200 | [diff] [blame] | 3218 | |
| 3219 | if (!*args[cur_arg + 1]) { |
| 3220 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 3221 | file, linenum, args[cur_arg]); |
| 3222 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3223 | goto out; |
| 3224 | } |
| 3225 | |
| 3226 | if (newsrv->fall <= 0) { |
| 3227 | Alert("parsing [%s:%d]: '%s' has to be > 0.\n", |
| 3228 | file, linenum, args[cur_arg]); |
| 3229 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3230 | goto out; |
| 3231 | } |
| 3232 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3233 | cur_arg += 2; |
| 3234 | } |
| 3235 | else if (!strcmp(args[cur_arg], "inter")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 3236 | const char *err = parse_time_err(args[cur_arg + 1], &val, TIME_UNIT_MS); |
| 3237 | if (err) { |
| 3238 | Alert("parsing [%s:%d] : unexpected character '%c' in 'inter' argument of server %s.\n", |
| 3239 | file, linenum, *err, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3240 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3241 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 3242 | } |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 3243 | if (val <= 0) { |
| 3244 | Alert("parsing [%s:%d]: invalid value %d for argument '%s' of server %s.\n", |
| 3245 | file, linenum, val, args[cur_arg], newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3246 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3247 | goto out; |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 3248 | } |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 3249 | newsrv->inter = val; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3250 | cur_arg += 2; |
| 3251 | } |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 3252 | else if (!strcmp(args[cur_arg], "fastinter")) { |
| 3253 | const char *err = parse_time_err(args[cur_arg + 1], &val, TIME_UNIT_MS); |
| 3254 | if (err) { |
| 3255 | Alert("parsing [%s:%d]: unexpected character '%c' in 'fastinter' argument of server %s.\n", |
| 3256 | file, linenum, *err, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3257 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3258 | goto out; |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 3259 | } |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 3260 | if (val <= 0) { |
| 3261 | Alert("parsing [%s:%d]: invalid value %d for argument '%s' of server %s.\n", |
| 3262 | file, linenum, val, args[cur_arg], newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3263 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3264 | goto out; |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 3265 | } |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 3266 | newsrv->fastinter = val; |
| 3267 | cur_arg += 2; |
| 3268 | } |
| 3269 | else if (!strcmp(args[cur_arg], "downinter")) { |
| 3270 | const char *err = parse_time_err(args[cur_arg + 1], &val, TIME_UNIT_MS); |
| 3271 | if (err) { |
| 3272 | Alert("parsing [%s:%d]: unexpected character '%c' in 'downinter' argument of server %s.\n", |
| 3273 | file, linenum, *err, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3274 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3275 | goto out; |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 3276 | } |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 3277 | if (val <= 0) { |
| 3278 | Alert("parsing [%s:%d]: invalid value %d for argument '%s' of server %s.\n", |
| 3279 | file, linenum, val, args[cur_arg], newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3280 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3281 | goto out; |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 3282 | } |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 3283 | newsrv->downinter = val; |
| 3284 | cur_arg += 2; |
| 3285 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3286 | else if (!defsrv && !strcmp(args[cur_arg], "addr")) { |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 3287 | struct sockaddr_in *sk = str2sa(args[cur_arg + 1]); |
| 3288 | if (!sk) { |
| 3289 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[cur_arg + 1]); |
| 3290 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3291 | goto out; |
| 3292 | } |
| 3293 | newsrv->check_addr = *sk; |
Willy Tarreau | 2ea3abb | 2007-03-25 16:45:16 +0200 | [diff] [blame] | 3294 | cur_arg += 2; |
| 3295 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3296 | else if (!strcmp(args[cur_arg], "port")) { |
| 3297 | newsrv->check_port = atol(args[cur_arg + 1]); |
| 3298 | cur_arg += 2; |
| 3299 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3300 | else if (!defsrv && !strcmp(args[cur_arg], "backup")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3301 | newsrv->state |= SRV_BACKUP; |
| 3302 | cur_arg ++; |
| 3303 | } |
| 3304 | else if (!strcmp(args[cur_arg], "weight")) { |
| 3305 | int w; |
| 3306 | w = atol(args[cur_arg + 1]); |
Willy Tarreau | 6704d67 | 2009-06-15 10:56:05 +0200 | [diff] [blame] | 3307 | if (w < 0 || w > 256) { |
| 3308 | 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] | 3309 | file, linenum, newsrv->id, w); |
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 | 975c50b | 2009-10-10 19:34:06 +0200 | [diff] [blame] | 3313 | newsrv->uweight = newsrv->iweight = w; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3314 | cur_arg += 2; |
| 3315 | } |
| 3316 | else if (!strcmp(args[cur_arg], "minconn")) { |
| 3317 | newsrv->minconn = atol(args[cur_arg + 1]); |
| 3318 | cur_arg += 2; |
| 3319 | } |
| 3320 | else if (!strcmp(args[cur_arg], "maxconn")) { |
| 3321 | newsrv->maxconn = atol(args[cur_arg + 1]); |
| 3322 | cur_arg += 2; |
| 3323 | } |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 3324 | else if (!strcmp(args[cur_arg], "maxqueue")) { |
| 3325 | newsrv->maxqueue = atol(args[cur_arg + 1]); |
| 3326 | cur_arg += 2; |
| 3327 | } |
Willy Tarreau | 9909fc1 | 2007-11-30 17:42:05 +0100 | [diff] [blame] | 3328 | else if (!strcmp(args[cur_arg], "slowstart")) { |
| 3329 | /* slowstart is stored in seconds */ |
Willy Tarreau | 3259e33 | 2007-12-03 01:51:45 +0100 | [diff] [blame] | 3330 | 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] | 3331 | if (err) { |
| 3332 | Alert("parsing [%s:%d] : unexpected character '%c' in 'slowstart' argument of server %s.\n", |
| 3333 | file, linenum, *err, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3334 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3335 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 3336 | } |
Willy Tarreau | 4554bc1 | 2010-03-26 10:40:49 +0100 | [diff] [blame] | 3337 | if (val < 0) { |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 3338 | Alert("parsing [%s:%d]: invalid value %d for argument '%s' of server %s.\n", |
| 3339 | file, linenum, val, args[cur_arg], newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3340 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3341 | goto out; |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 3342 | } |
Willy Tarreau | 3259e33 | 2007-12-03 01:51:45 +0100 | [diff] [blame] | 3343 | newsrv->slowstart = (val + 999) / 1000; |
Willy Tarreau | 9909fc1 | 2007-11-30 17:42:05 +0100 | [diff] [blame] | 3344 | cur_arg += 2; |
| 3345 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3346 | else if (!defsrv && !strcmp(args[cur_arg], "track")) { |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 3347 | |
| 3348 | if (!*args[cur_arg + 1]) { |
| 3349 | Alert("parsing [%s:%d]: 'track' expects [<proxy>/]<server> as argument.\n", |
| 3350 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3351 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3352 | goto out; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 3353 | } |
| 3354 | |
| 3355 | newsrv->trackit = strdup(args[cur_arg + 1]); |
| 3356 | |
| 3357 | cur_arg += 2; |
| 3358 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3359 | else if (!defsrv && !strcmp(args[cur_arg], "check")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3360 | global.maxsock++; |
| 3361 | do_check = 1; |
| 3362 | cur_arg += 1; |
| 3363 | } |
Willy Tarreau | 9683909 | 2010-03-29 10:02:24 +0200 | [diff] [blame] | 3364 | else if (!defsrv && !strcmp(args[cur_arg], "disabled")) { |
| 3365 | newsrv->state |= SRV_MAINTAIN; |
| 3366 | newsrv->state &= ~SRV_RUNNING; |
| 3367 | newsrv->health = 0; |
| 3368 | cur_arg += 1; |
| 3369 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3370 | else if (!defsrv && !strcmp(args[cur_arg], "observe")) { |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 3371 | if (!strcmp(args[cur_arg + 1], "none")) |
| 3372 | newsrv->observe = HANA_OBS_NONE; |
| 3373 | else if (!strcmp(args[cur_arg + 1], "layer4")) |
| 3374 | newsrv->observe = HANA_OBS_LAYER4; |
| 3375 | else if (!strcmp(args[cur_arg + 1], "layer7")) { |
| 3376 | if (curproxy->mode != PR_MODE_HTTP) { |
| 3377 | Alert("parsing [%s:%d]: '%s' can only be used in http proxies.\n", |
| 3378 | file, linenum, args[cur_arg + 1]); |
| 3379 | err_code |= ERR_ALERT; |
| 3380 | } |
| 3381 | newsrv->observe = HANA_OBS_LAYER7; |
| 3382 | } |
| 3383 | else { |
| 3384 | Alert("parsing [%s:%d]: '%s' expects one of 'none', " |
| 3385 | "'l4events', 'http-responses' but get '%s'\n", |
| 3386 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
| 3387 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3388 | goto out; |
| 3389 | } |
| 3390 | |
| 3391 | cur_arg += 2; |
| 3392 | } |
| 3393 | else if (!strcmp(args[cur_arg], "on-error")) { |
| 3394 | if (!strcmp(args[cur_arg + 1], "fastinter")) |
| 3395 | newsrv->onerror = HANA_ONERR_FASTINTER; |
| 3396 | else if (!strcmp(args[cur_arg + 1], "fail-check")) |
| 3397 | newsrv->onerror = HANA_ONERR_FAILCHK; |
| 3398 | else if (!strcmp(args[cur_arg + 1], "sudden-death")) |
| 3399 | newsrv->onerror = HANA_ONERR_SUDDTH; |
| 3400 | else if (!strcmp(args[cur_arg + 1], "mark-down")) |
| 3401 | newsrv->onerror = HANA_ONERR_MARKDWN; |
| 3402 | else { |
| 3403 | Alert("parsing [%s:%d]: '%s' expects one of 'fastinter', " |
| 3404 | "'fail-check', 'sudden-death' or 'mark-down' but get '%s'\n", |
| 3405 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
| 3406 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3407 | goto out; |
| 3408 | } |
| 3409 | |
| 3410 | cur_arg += 2; |
| 3411 | } |
| 3412 | else if (!strcmp(args[cur_arg], "error-limit")) { |
| 3413 | if (!*args[cur_arg + 1]) { |
| 3414 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 3415 | file, linenum, args[cur_arg]); |
| 3416 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3417 | goto out; |
| 3418 | } |
| 3419 | |
| 3420 | newsrv->consecutive_errors_limit = atoi(args[cur_arg + 1]); |
| 3421 | |
| 3422 | if (newsrv->consecutive_errors_limit <= 0) { |
| 3423 | Alert("parsing [%s:%d]: %s has to be > 0.\n", |
| 3424 | file, linenum, args[cur_arg]); |
| 3425 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3426 | goto out; |
| 3427 | } |
Willy Tarreau | f53b25d | 2010-03-15 19:40:37 +0100 | [diff] [blame] | 3428 | cur_arg += 2; |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 3429 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3430 | else if (!defsrv && !strcmp(args[cur_arg], "source")) { /* address to which we bind when connecting */ |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 3431 | int port_low, port_high; |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 3432 | struct sockaddr_in *sk; |
| 3433 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3434 | if (!*args[cur_arg + 1]) { |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 3435 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 3436 | 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] | 3437 | file, linenum, "source", "usesrc"); |
| 3438 | #else |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 3439 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>[-<port>]] as argument.\n", |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3440 | file, linenum, "source"); |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 3441 | #endif |
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 | } |
| 3445 | newsrv->state |= SRV_BIND_SRC; |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 3446 | sk = str2sa_range(args[cur_arg + 1], &port_low, &port_high); |
| 3447 | if (!sk) { |
| 3448 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[cur_arg + 1]); |
| 3449 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3450 | goto out; |
| 3451 | } |
| 3452 | newsrv->source_addr = *sk; |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 3453 | |
| 3454 | if (port_low != port_high) { |
| 3455 | int i; |
| 3456 | if (port_low <= 0 || port_low > 65535 || |
| 3457 | port_high <= 0 || port_high > 65535 || |
| 3458 | port_low > port_high) { |
| 3459 | Alert("parsing [%s:%d] : invalid source port range %d-%d.\n", |
| 3460 | file, linenum, port_low, port_high); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3461 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3462 | goto out; |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 3463 | } |
| 3464 | newsrv->sport_range = port_range_alloc_range(port_high - port_low + 1); |
| 3465 | for (i = 0; i < newsrv->sport_range->size; i++) |
| 3466 | newsrv->sport_range->ports[i] = port_low + i; |
| 3467 | } |
| 3468 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3469 | cur_arg += 2; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 3470 | while (*(args[cur_arg])) { |
| 3471 | if (!strcmp(args[cur_arg], "usesrc")) { /* address to use outside */ |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 3472 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) |
| 3473 | #if !defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 3474 | if (newsrv->source_addr.sin_addr.s_addr == INADDR_ANY) { |
| 3475 | Alert("parsing [%s:%d] : '%s' requires an explicit '%s' address.\n", |
| 3476 | file, linenum, "usesrc", "source"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3477 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3478 | goto out; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 3479 | } |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 3480 | #endif |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 3481 | if (!*args[cur_arg + 1]) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 3482 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', 'clientip', or 'hdr_ip(name,#)' as argument.\n", |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 3483 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3484 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3485 | goto out; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 3486 | } |
| 3487 | if (!strcmp(args[cur_arg + 1], "client")) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 3488 | newsrv->state &= ~SRV_TPROXY_MASK; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 3489 | newsrv->state |= SRV_TPROXY_CLI; |
| 3490 | } else if (!strcmp(args[cur_arg + 1], "clientip")) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 3491 | newsrv->state &= ~SRV_TPROXY_MASK; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 3492 | newsrv->state |= SRV_TPROXY_CIP; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 3493 | } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) { |
| 3494 | char *name, *end; |
| 3495 | |
| 3496 | name = args[cur_arg+1] + 7; |
| 3497 | while (isspace(*name)) |
| 3498 | name++; |
| 3499 | |
| 3500 | end = name; |
| 3501 | while (*end && !isspace(*end) && *end != ',' && *end != ')') |
| 3502 | end++; |
| 3503 | |
| 3504 | newsrv->state &= ~SRV_TPROXY_MASK; |
| 3505 | newsrv->state |= SRV_TPROXY_DYN; |
| 3506 | newsrv->bind_hdr_name = calloc(1, end - name + 1); |
| 3507 | newsrv->bind_hdr_len = end - name; |
| 3508 | memcpy(newsrv->bind_hdr_name, name, end - name); |
| 3509 | newsrv->bind_hdr_name[end-name] = '\0'; |
| 3510 | newsrv->bind_hdr_occ = -1; |
| 3511 | |
| 3512 | /* now look for an occurrence number */ |
| 3513 | while (isspace(*end)) |
| 3514 | end++; |
| 3515 | if (*end == ',') { |
| 3516 | end++; |
| 3517 | name = end; |
| 3518 | if (*end == '-') |
| 3519 | end++; |
| 3520 | while (isdigit(*end)) |
| 3521 | end++; |
| 3522 | newsrv->bind_hdr_occ = strl2ic(name, end-name); |
| 3523 | } |
| 3524 | |
| 3525 | if (newsrv->bind_hdr_occ < -MAX_HDR_HISTORY) { |
| 3526 | Alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative" |
| 3527 | " occurrences values smaller than %d.\n", |
| 3528 | file, linenum, MAX_HDR_HISTORY); |
| 3529 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3530 | goto out; |
| 3531 | } |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 3532 | } else { |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 3533 | struct sockaddr_in *sk = str2sa(args[cur_arg + 1]); |
| 3534 | if (!sk) { |
| 3535 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[cur_arg + 1]); |
| 3536 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3537 | goto out; |
| 3538 | } |
| 3539 | newsrv->tproxy_addr = *sk; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 3540 | newsrv->state |= SRV_TPROXY_ADDR; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 3541 | } |
| 3542 | global.last_checks |= LSTCHK_NETADM; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 3543 | #if !defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 3544 | global.last_checks |= LSTCHK_CTTPROXY; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 3545 | #endif |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 3546 | cur_arg += 2; |
| 3547 | continue; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 3548 | #else /* no TPROXY support */ |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 3549 | 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] | 3550 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3551 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3552 | goto out; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 3553 | #endif /* defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) */ |
| 3554 | } /* "usesrc" */ |
| 3555 | |
| 3556 | if (!strcmp(args[cur_arg], "interface")) { /* specifically bind to this interface */ |
| 3557 | #ifdef SO_BINDTODEVICE |
| 3558 | if (!*args[cur_arg + 1]) { |
| 3559 | Alert("parsing [%s:%d] : '%s' : missing interface name.\n", |
| 3560 | 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 | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 3563 | } |
| 3564 | if (newsrv->iface_name) |
| 3565 | free(newsrv->iface_name); |
| 3566 | |
| 3567 | newsrv->iface_name = strdup(args[cur_arg + 1]); |
| 3568 | newsrv->iface_len = strlen(newsrv->iface_name); |
| 3569 | global.last_checks |= LSTCHK_NETADM; |
| 3570 | #else |
| 3571 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 3572 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3573 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3574 | goto out; |
Willy Tarreau | 77074d5 | 2006-11-12 23:57:19 +0100 | [diff] [blame] | 3575 | #endif |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 3576 | cur_arg += 2; |
| 3577 | continue; |
| 3578 | } |
| 3579 | /* this keyword in not an option of "source" */ |
| 3580 | break; |
| 3581 | } /* while */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3582 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3583 | else if (!defsrv && !strcmp(args[cur_arg], "usesrc")) { /* address to use outside: needs "source" first */ |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 3584 | Alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n", |
| 3585 | file, linenum, "usesrc", "source"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3586 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3587 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 3588 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3589 | else { |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3590 | if (!defsrv) |
Willy Tarreau | 9683909 | 2010-03-29 10:02:24 +0200 | [diff] [blame] | 3591 | Alert("parsing [%s:%d] : server %s only supports options 'backup', 'cookie', 'redir', 'observer', 'on-error', 'error-limit', 'check', 'disabled', 'track', 'id', 'inter', 'fastinter', 'downinter', 'rise', 'fall', 'addr', 'port', 'source', 'minconn', 'maxconn', 'maxqueue', 'slowstart' and 'weight'.\n", |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3592 | file, linenum, newsrv->id); |
| 3593 | else |
Krzysztof Piotr Oledzki | a9389b1 | 2010-01-05 16:44:17 +0100 | [diff] [blame] | 3594 | Alert("parsing [%s:%d]: default-server only supports options 'on-error', 'error-limit', 'inter', 'fastinter', 'downinter', 'rise', 'fall', 'port', 'minconn', 'maxconn', 'maxqueue', 'slowstart' and 'weight'.\n", |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3595 | file, linenum); |
| 3596 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3597 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3598 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3599 | } |
| 3600 | } |
| 3601 | |
| 3602 | if (do_check) { |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 3603 | if (newsrv->trackit) { |
| 3604 | Alert("parsing [%s:%d]: unable to enable checks and tracking at the same time!\n", |
| 3605 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3606 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3607 | goto out; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 3608 | } |
| 3609 | |
Willy Tarreau | 0f03c6f | 2007-03-25 20:46:19 +0200 | [diff] [blame] | 3610 | if (!newsrv->check_port && newsrv->check_addr.sin_port) |
| 3611 | newsrv->check_port = newsrv->check_addr.sin_port; |
| 3612 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3613 | if (!newsrv->check_port && !(newsrv->state & SRV_MAPPORTS)) |
| 3614 | newsrv->check_port = realport; /* by default */ |
| 3615 | if (!newsrv->check_port) { |
Willy Tarreau | ef00b50 | 2007-01-07 02:40:09 +0100 | [diff] [blame] | 3616 | /* not yet valid, because no port was set on |
| 3617 | * the server either. We'll check if we have |
| 3618 | * a known port on the first listener. |
| 3619 | */ |
| 3620 | struct listener *l; |
| 3621 | l = curproxy->listen; |
| 3622 | if (l) { |
| 3623 | int port; |
| 3624 | port = (l->addr.ss_family == AF_INET6) |
| 3625 | ? ntohs(((struct sockaddr_in6 *)(&l->addr))->sin6_port) |
| 3626 | : ntohs(((struct sockaddr_in *)(&l->addr))->sin_port); |
| 3627 | newsrv->check_port = port; |
| 3628 | } |
| 3629 | } |
| 3630 | if (!newsrv->check_port) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3631 | Alert("parsing [%s:%d] : server %s has neither service port nor check port. Check has been disabled.\n", |
| 3632 | file, linenum, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3633 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3634 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3635 | } |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 3636 | |
Cyril Bonté | c9f825f | 2010-03-17 18:56:31 +0100 | [diff] [blame] | 3637 | /* Allocate buffer for partial check results... */ |
| 3638 | if ((newsrv->check_data = calloc(BUFSIZE, sizeof(char))) == NULL) { |
| 3639 | Alert("parsing [%s:%d] : out of memory while allocating check buffer.\n", file, linenum); |
| 3640 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3641 | goto out; |
| 3642 | } |
| 3643 | |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 3644 | newsrv->check_status = HCHK_STATUS_INI; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3645 | newsrv->state |= SRV_CHECKED; |
| 3646 | } |
| 3647 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3648 | if (!defsrv) { |
| 3649 | if (newsrv->state & SRV_BACKUP) |
| 3650 | curproxy->srv_bck++; |
| 3651 | else |
| 3652 | curproxy->srv_act++; |
Willy Tarreau | b625a08 | 2007-11-26 01:15:43 +0100 | [diff] [blame] | 3653 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3654 | newsrv->prev_state = newsrv->state; |
| 3655 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3656 | } |
| 3657 | else if (!strcmp(args[0], "log")) { /* syslog server address */ |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 3658 | struct logsrv logsrv; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3659 | int facility; |
| 3660 | |
| 3661 | if (*(args[1]) && *(args[2]) == 0 && !strcmp(args[1], "global")) { |
| 3662 | curproxy->logfac1 = global.logfac1; |
| 3663 | curproxy->logsrv1 = global.logsrv1; |
| 3664 | curproxy->loglev1 = global.loglev1; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 3665 | curproxy->minlvl1 = global.minlvl1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3666 | curproxy->logfac2 = global.logfac2; |
| 3667 | curproxy->logsrv2 = global.logsrv2; |
| 3668 | curproxy->loglev2 = global.loglev2; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 3669 | curproxy->minlvl2 = global.minlvl2; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3670 | } |
| 3671 | else if (*(args[1]) && *(args[2])) { |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 3672 | int level, minlvl; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3673 | |
| 3674 | facility = get_log_facility(args[2]); |
| 3675 | if (facility < 0) { |
| 3676 | Alert("parsing [%s:%d] : unknown log facility '%s'\n", file, linenum, args[2]); |
| 3677 | exit(1); |
| 3678 | } |
| 3679 | |
| 3680 | level = 7; /* max syslog level = debug */ |
| 3681 | if (*(args[3])) { |
| 3682 | level = get_log_level(args[3]); |
| 3683 | if (level < 0) { |
| 3684 | Alert("parsing [%s:%d] : unknown optional log level '%s'\n", file, linenum, args[3]); |
| 3685 | exit(1); |
| 3686 | } |
| 3687 | } |
| 3688 | |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 3689 | minlvl = 0; /* limit syslog level to this level (emerg) */ |
| 3690 | if (*(args[4])) { |
| 3691 | minlvl = get_log_level(args[4]); |
| 3692 | if (level < 0) { |
| 3693 | Alert("parsing [%s:%d] : unknown optional minimum log level '%s'\n", file, linenum, args[4]); |
| 3694 | exit(1); |
| 3695 | } |
| 3696 | } |
| 3697 | |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 3698 | if (args[1][0] == '/') { |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 3699 | struct sockaddr_un *sk = str2sun(args[1]); |
| 3700 | if (!sk) { |
| 3701 | Alert("parsing [%s:%d] : Socket path '%s' too long (max %d)\n", file, linenum, |
| 3702 | args[1], (int)sizeof(sk->sun_path) - 1); |
| 3703 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3704 | goto out; |
| 3705 | } |
| 3706 | logsrv.u.un = *sk; |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 3707 | logsrv.u.addr.sa_family = AF_UNIX; |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 3708 | } else { |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 3709 | struct sockaddr_in *sk = str2sa(args[1]); |
| 3710 | if (!sk) { |
| 3711 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[1]); |
| 3712 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3713 | goto out; |
| 3714 | } |
| 3715 | logsrv.u.in = *sk; |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 3716 | logsrv.u.addr.sa_family = AF_INET; |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 3717 | if (!logsrv.u.in.sin_port) { |
| 3718 | logsrv.u.in.sin_port = |
| 3719 | htons(SYSLOG_PORT); |
| 3720 | } |
| 3721 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3722 | |
| 3723 | if (curproxy->logfac1 == -1) { |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 3724 | curproxy->logsrv1 = logsrv; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3725 | curproxy->logfac1 = facility; |
| 3726 | curproxy->loglev1 = level; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 3727 | curproxy->minlvl1 = minlvl; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3728 | } |
| 3729 | else if (curproxy->logfac2 == -1) { |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 3730 | curproxy->logsrv2 = logsrv; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3731 | curproxy->logfac2 = facility; |
| 3732 | curproxy->loglev2 = level; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 3733 | curproxy->minlvl2 = minlvl; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3734 | } |
| 3735 | else { |
| 3736 | Alert("parsing [%s:%d] : too many syslog servers\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3737 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3738 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3739 | } |
| 3740 | } |
| 3741 | else { |
| 3742 | Alert("parsing [%s:%d] : 'log' expects either <address[:port]> and <facility> or 'global' as arguments.\n", |
| 3743 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3744 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3745 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3746 | } |
| 3747 | } |
| 3748 | 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] | 3749 | int cur_arg; |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 3750 | struct sockaddr_in *sk; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 3751 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3752 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3753 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3754 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3755 | if (!*args[1]) { |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 3756 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optionally '%s' <addr>, and '%s' <name>.\n", |
| 3757 | file, linenum, "source", "usesrc", "interface"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3758 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3759 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3760 | } |
Willy Tarreau | 368480c | 2009-03-01 08:27:21 +0100 | [diff] [blame] | 3761 | |
| 3762 | /* we must first clear any optional default setting */ |
| 3763 | curproxy->options &= ~PR_O_TPXY_MASK; |
| 3764 | free(curproxy->iface_name); |
| 3765 | curproxy->iface_name = NULL; |
| 3766 | curproxy->iface_len = 0; |
| 3767 | |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 3768 | sk = str2sa(args[1]); |
| 3769 | if (!sk) { |
| 3770 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[1]); |
| 3771 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3772 | goto out; |
| 3773 | } |
| 3774 | curproxy->source_addr = *sk; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3775 | curproxy->options |= PR_O_BIND_SRC; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 3776 | |
| 3777 | cur_arg = 2; |
| 3778 | while (*(args[cur_arg])) { |
| 3779 | if (!strcmp(args[cur_arg], "usesrc")) { /* address to use outside */ |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 3780 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) |
| 3781 | #if !defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 3782 | if (curproxy->source_addr.sin_addr.s_addr == INADDR_ANY) { |
| 3783 | Alert("parsing [%s:%d] : '%s' requires an explicit 'source' address.\n", |
| 3784 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3785 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3786 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 3787 | } |
| 3788 | #endif |
| 3789 | if (!*args[cur_arg + 1]) { |
| 3790 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n", |
| 3791 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3792 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3793 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 3794 | } |
| 3795 | |
| 3796 | if (!strcmp(args[cur_arg + 1], "client")) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 3797 | curproxy->options &= ~PR_O_TPXY_MASK; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 3798 | curproxy->options |= PR_O_TPXY_CLI; |
| 3799 | } else if (!strcmp(args[cur_arg + 1], "clientip")) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 3800 | curproxy->options &= ~PR_O_TPXY_MASK; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 3801 | curproxy->options |= PR_O_TPXY_CIP; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 3802 | } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) { |
| 3803 | char *name, *end; |
| 3804 | |
| 3805 | name = args[cur_arg+1] + 7; |
| 3806 | while (isspace(*name)) |
| 3807 | name++; |
| 3808 | |
| 3809 | end = name; |
| 3810 | while (*end && !isspace(*end) && *end != ',' && *end != ')') |
| 3811 | end++; |
| 3812 | |
| 3813 | curproxy->options &= ~PR_O_TPXY_MASK; |
| 3814 | curproxy->options |= PR_O_TPXY_DYN; |
| 3815 | curproxy->bind_hdr_name = calloc(1, end - name + 1); |
| 3816 | curproxy->bind_hdr_len = end - name; |
| 3817 | memcpy(curproxy->bind_hdr_name, name, end - name); |
| 3818 | curproxy->bind_hdr_name[end-name] = '\0'; |
| 3819 | curproxy->bind_hdr_occ = -1; |
| 3820 | |
| 3821 | /* now look for an occurrence number */ |
| 3822 | while (isspace(*end)) |
| 3823 | end++; |
| 3824 | if (*end == ',') { |
| 3825 | end++; |
| 3826 | name = end; |
| 3827 | if (*end == '-') |
| 3828 | end++; |
| 3829 | while (isdigit(*end)) |
| 3830 | end++; |
| 3831 | curproxy->bind_hdr_occ = strl2ic(name, end-name); |
| 3832 | } |
| 3833 | |
| 3834 | if (curproxy->bind_hdr_occ < -MAX_HDR_HISTORY) { |
| 3835 | Alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative" |
| 3836 | " occurrences values smaller than %d.\n", |
| 3837 | file, linenum, MAX_HDR_HISTORY); |
| 3838 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3839 | goto out; |
| 3840 | } |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 3841 | } else { |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 3842 | struct sockaddr_in *sk = str2sa(args[cur_arg + 1]); |
| 3843 | if (!sk) { |
| 3844 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[cur_arg + 1]); |
| 3845 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3846 | goto out; |
| 3847 | } |
| 3848 | curproxy->tproxy_addr = *sk; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 3849 | curproxy->options |= PR_O_TPXY_ADDR; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 3850 | } |
| 3851 | global.last_checks |= LSTCHK_NETADM; |
| 3852 | #if !defined(CONFIG_HAP_LINUX_TPROXY) |
| 3853 | global.last_checks |= LSTCHK_CTTPROXY; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 3854 | #endif |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 3855 | #else /* no TPROXY support */ |
| 3856 | 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] | 3857 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3858 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3859 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 3860 | #endif |
| 3861 | cur_arg += 2; |
| 3862 | continue; |
Willy Tarreau | 77074d5 | 2006-11-12 23:57:19 +0100 | [diff] [blame] | 3863 | } |
| 3864 | |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 3865 | if (!strcmp(args[cur_arg], "interface")) { /* specifically bind to this interface */ |
| 3866 | #ifdef SO_BINDTODEVICE |
| 3867 | if (!*args[cur_arg + 1]) { |
| 3868 | Alert("parsing [%s:%d] : '%s' : missing interface name.\n", |
| 3869 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3870 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3871 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 3872 | } |
| 3873 | if (curproxy->iface_name) |
| 3874 | free(curproxy->iface_name); |
| 3875 | |
| 3876 | curproxy->iface_name = strdup(args[cur_arg + 1]); |
| 3877 | curproxy->iface_len = strlen(curproxy->iface_name); |
| 3878 | global.last_checks |= LSTCHK_NETADM; |
| 3879 | #else |
| 3880 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 3881 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3882 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3883 | goto out; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 3884 | #endif |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 3885 | cur_arg += 2; |
| 3886 | continue; |
| 3887 | } |
| 3888 | Alert("parsing [%s:%d] : '%s' only supports optional keywords '%s' and '%s'.\n", |
| 3889 | file, linenum, args[0], "inteface", "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3890 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3891 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 3892 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3893 | } |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 3894 | else if (!strcmp(args[0], "usesrc")) { /* address to use outside: needs "source" first */ |
| 3895 | Alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n", |
| 3896 | file, linenum, "usesrc", "source"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3897 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3898 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 3899 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3900 | else if (!strcmp(args[0], "cliexp") || !strcmp(args[0], "reqrep")) { /* replace request header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 3901 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3902 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 3903 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3904 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3905 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3906 | } |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 3907 | |
| 3908 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 3909 | ACL_DIR_REQ, ACT_REPLACE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 3910 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 3911 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3912 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3913 | } |
| 3914 | else if (!strcmp(args[0], "reqdel")) { /* delete request header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 3915 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 3916 | ACL_DIR_REQ, ACT_REMOVE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 3917 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 3918 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3919 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3920 | } |
| 3921 | else if (!strcmp(args[0], "reqdeny")) { /* deny a request if a header matches this regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 3922 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 3923 | ACL_DIR_REQ, ACT_DENY, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 3924 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 3925 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3926 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3927 | } |
| 3928 | else if (!strcmp(args[0], "reqpass")) { /* pass this header without allowing or denying the request */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 3929 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 3930 | ACL_DIR_REQ, ACT_PASS, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 3931 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 3932 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3933 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3934 | } |
| 3935 | else if (!strcmp(args[0], "reqallow")) { /* allow a request if a header matches this regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 3936 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 3937 | ACL_DIR_REQ, ACT_ALLOW, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 3938 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 3939 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3940 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3941 | } |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 3942 | else if (!strcmp(args[0], "reqtarpit")) { /* tarpit a request if a header matches this regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 3943 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 3944 | ACL_DIR_REQ, ACT_TARPIT, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 3945 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 3946 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3947 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 3948 | } |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 3949 | else if (!strcmp(args[0], "reqsetbe")) { /* switch the backend from a regex, respecting case */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 3950 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 3951 | ACL_DIR_REQ, ACT_SETBE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 3952 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 3953 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3954 | goto out; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 3955 | } |
| 3956 | else if (!strcmp(args[0], "reqisetbe")) { /* switch the backend from a regex, ignoring case */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 3957 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 3958 | ACL_DIR_REQ, ACT_SETBE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 3959 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 3960 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3961 | goto out; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 3962 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3963 | else if (!strcmp(args[0], "reqirep")) { /* replace request header from a regex, ignoring case */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 3964 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3965 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 3966 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3967 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3968 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3969 | } |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 3970 | |
| 3971 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 3972 | ACL_DIR_REQ, ACT_REPLACE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 3973 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 3974 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3975 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3976 | } |
| 3977 | else if (!strcmp(args[0], "reqidel")) { /* delete request header from a regex ignoring case */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 3978 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 3979 | ACL_DIR_REQ, ACT_REMOVE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 3980 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 3981 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3982 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3983 | } |
| 3984 | else if (!strcmp(args[0], "reqideny")) { /* deny a request if a header matches this regex ignoring case */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 3985 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 3986 | ACL_DIR_REQ, ACT_DENY, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 3987 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 3988 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3989 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3990 | } |
| 3991 | else if (!strcmp(args[0], "reqipass")) { /* pass this header without allowing or denying the request */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 3992 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 3993 | ACL_DIR_REQ, ACT_PASS, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 3994 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 3995 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3996 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3997 | } |
| 3998 | else if (!strcmp(args[0], "reqiallow")) { /* allow a request if a header matches this regex ignoring case */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 3999 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 4000 | ACL_DIR_REQ, ACT_ALLOW, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4001 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4002 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4003 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4004 | } |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 4005 | else if (!strcmp(args[0], "reqitarpit")) { /* tarpit a request if a header matches this regex ignoring case */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4006 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 4007 | ACL_DIR_REQ, ACT_TARPIT, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4008 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4009 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4010 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 4011 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4012 | else if (!strcmp(args[0], "reqadd")) { /* add request header */ |
Willy Tarreau | f4f0412 | 2010-01-28 18:10:50 +0100 | [diff] [blame] | 4013 | struct cond_wordlist *wl; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 4014 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4015 | if (curproxy == &defproxy) { |
| 4016 | 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] | 4017 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4018 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4019 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4020 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4021 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4022 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4023 | if (*(args[1]) == 0) { |
| 4024 | 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] | 4025 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4026 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4027 | } |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 4028 | |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 4029 | if ((strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0)) { |
| 4030 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args+2)) == NULL) { |
| 4031 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition.\n", |
| 4032 | file, linenum, args[0]); |
| 4033 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4034 | goto out; |
| 4035 | } |
| 4036 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
| 4037 | } |
| 4038 | else if (*args[2]) { |
| 4039 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 4040 | file, linenum, args[0], args[2]); |
| 4041 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4042 | goto out; |
| 4043 | } |
| 4044 | |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 4045 | wl = calloc(1, sizeof(*wl)); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 4046 | wl->cond = cond; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 4047 | wl->s = strdup(args[1]); |
| 4048 | LIST_ADDQ(&curproxy->req_add, &wl->list); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 4049 | warnif_misplaced_reqadd(curproxy, file, linenum, args[0]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4050 | } |
| 4051 | else if (!strcmp(args[0], "srvexp") || !strcmp(args[0], "rsprep")) { /* replace response header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4052 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4053 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 4054 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4055 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4056 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4057 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4058 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4059 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 4060 | ACL_DIR_RTR, ACT_REPLACE, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 4061 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4062 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4063 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4064 | } |
| 4065 | else if (!strcmp(args[0], "rspdel")) { /* delete response header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4066 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 4067 | ACL_DIR_RTR, ACT_REMOVE, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 4068 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4069 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4070 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4071 | } |
| 4072 | else if (!strcmp(args[0], "rspdeny")) { /* block response header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4073 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 4074 | ACL_DIR_RTR, ACT_DENY, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 4075 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4076 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4077 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4078 | } |
| 4079 | else if (!strcmp(args[0], "rspirep")) { /* replace response header from a regex ignoring case */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4080 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4081 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 4082 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4083 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4084 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4085 | } |
| 4086 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4087 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 4088 | ACL_DIR_RTR, ACT_REPLACE, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 4089 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4090 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4091 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4092 | } |
| 4093 | else if (!strcmp(args[0], "rspidel")) { /* delete response header from a regex ignoring case */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4094 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 4095 | ACL_DIR_RTR, ACT_REMOVE, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 4096 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4097 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4098 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4099 | } |
| 4100 | else if (!strcmp(args[0], "rspideny")) { /* block response header from a regex ignoring case */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4101 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 4102 | ACL_DIR_RTR, ACT_DENY, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 4103 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4104 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4105 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4106 | } |
| 4107 | else if (!strcmp(args[0], "rspadd")) { /* add response header */ |
Willy Tarreau | f4f0412 | 2010-01-28 18:10:50 +0100 | [diff] [blame] | 4108 | struct cond_wordlist *wl; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 4109 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4110 | if (curproxy == &defproxy) { |
| 4111 | 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] | 4112 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4113 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4114 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4115 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4116 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4117 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4118 | if (*(args[1]) == 0) { |
| 4119 | 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] | 4120 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4121 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4122 | } |
| 4123 | |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 4124 | if ((strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0)) { |
| 4125 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args+2)) == NULL) { |
| 4126 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition.\n", |
| 4127 | file, linenum, args[0]); |
| 4128 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4129 | goto out; |
| 4130 | } |
| 4131 | err_code |= warnif_cond_requires_req(cond, file, linenum); |
| 4132 | } |
| 4133 | else if (*args[2]) { |
| 4134 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 4135 | file, linenum, args[0], args[2]); |
| 4136 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4137 | goto out; |
| 4138 | } |
| 4139 | |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 4140 | wl = calloc(1, sizeof(*wl)); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 4141 | wl->cond = cond; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 4142 | wl->s = strdup(args[1]); |
| 4143 | LIST_ADDQ(&curproxy->rsp_add, &wl->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4144 | } |
| 4145 | else if (!strcmp(args[0], "errorloc") || |
| 4146 | !strcmp(args[0], "errorloc302") || |
| 4147 | !strcmp(args[0], "errorloc303")) { /* error location */ |
| 4148 | int errnum, errlen; |
| 4149 | char *err; |
| 4150 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4151 | 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] | 4152 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4153 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4154 | if (*(args[2]) == 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 4155 | 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] | 4156 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4157 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4158 | } |
| 4159 | |
| 4160 | errnum = atol(args[1]); |
| 4161 | if (!strcmp(args[0], "errorloc303")) { |
| 4162 | err = malloc(strlen(HTTP_303) + strlen(args[2]) + 5); |
| 4163 | errlen = sprintf(err, "%s%s\r\n\r\n", HTTP_303, args[2]); |
| 4164 | } else { |
| 4165 | err = malloc(strlen(HTTP_302) + strlen(args[2]) + 5); |
| 4166 | errlen = sprintf(err, "%s%s\r\n\r\n", HTTP_302, args[2]); |
| 4167 | } |
| 4168 | |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 4169 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) { |
| 4170 | if (http_err_codes[rc] == errnum) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 4171 | chunk_destroy(&curproxy->errmsg[rc]); |
| 4172 | chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 4173 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4174 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4175 | } |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 4176 | |
| 4177 | if (rc >= HTTP_ERR_SIZE) { |
| 4178 | Warning("parsing [%s:%d] : status code %d not handled, error relocation will be ignored.\n", |
| 4179 | file, linenum, errnum); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4180 | free(err); |
| 4181 | } |
| 4182 | } |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 4183 | else if (!strcmp(args[0], "errorfile")) { /* error message from a file */ |
| 4184 | int errnum, errlen, fd; |
| 4185 | char *err; |
| 4186 | struct stat stat; |
| 4187 | |
| 4188 | 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] | 4189 | err_code |= ERR_WARN; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 4190 | |
| 4191 | if (*(args[2]) == 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 4192 | 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] | 4193 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4194 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 4195 | } |
| 4196 | |
| 4197 | fd = open(args[2], O_RDONLY); |
| 4198 | if ((fd < 0) || (fstat(fd, &stat) < 0)) { |
| 4199 | Alert("parsing [%s:%d] : error opening file <%s> for custom error message <%s>.\n", |
| 4200 | file, linenum, args[2], args[1]); |
| 4201 | if (fd >= 0) |
| 4202 | close(fd); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4203 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4204 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 4205 | } |
| 4206 | |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 4207 | if (stat.st_size <= global.tune.bufsize) { |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 4208 | errlen = stat.st_size; |
| 4209 | } else { |
| 4210 | 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] | 4211 | file, linenum, args[2], global.tune.bufsize); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4212 | err_code |= ERR_WARN; |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 4213 | errlen = global.tune.bufsize; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 4214 | } |
| 4215 | |
| 4216 | err = malloc(errlen); /* malloc() must succeed during parsing */ |
| 4217 | errnum = read(fd, err, errlen); |
| 4218 | if (errnum != errlen) { |
| 4219 | Alert("parsing [%s:%d] : error reading file <%s> for custom error message <%s>.\n", |
| 4220 | file, linenum, args[2], args[1]); |
| 4221 | close(fd); |
| 4222 | free(err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4223 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4224 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 4225 | } |
| 4226 | close(fd); |
| 4227 | |
| 4228 | errnum = atol(args[1]); |
| 4229 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) { |
| 4230 | if (http_err_codes[rc] == errnum) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 4231 | chunk_destroy(&curproxy->errmsg[rc]); |
| 4232 | chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen); |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 4233 | break; |
| 4234 | } |
| 4235 | } |
| 4236 | |
| 4237 | if (rc >= HTTP_ERR_SIZE) { |
| 4238 | Warning("parsing [%s:%d] : status code %d not handled, error customization will be ignored.\n", |
| 4239 | file, linenum, errnum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4240 | err_code |= ERR_WARN; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 4241 | free(err); |
| 4242 | } |
| 4243 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4244 | else { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 4245 | struct cfg_kw_list *kwl; |
| 4246 | int index; |
| 4247 | |
| 4248 | list_for_each_entry(kwl, &cfg_keywords.list, list) { |
| 4249 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 4250 | if (kwl->kw[index].section != CFG_LISTEN) |
| 4251 | continue; |
| 4252 | if (strcmp(kwl->kw[index].kw, args[0]) == 0) { |
| 4253 | /* prepare error message just in case */ |
| 4254 | snprintf(trash, sizeof(trash), |
| 4255 | "error near '%s' in %s section", args[0], cursection); |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 4256 | rc = kwl->kw[index].parse(args, CFG_LISTEN, curproxy, &defproxy, trash, sizeof(trash)); |
| 4257 | if (rc < 0) { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 4258 | Alert("parsing [%s:%d] : %s\n", file, linenum, trash); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4259 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4260 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 4261 | } |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 4262 | else if (rc > 0) { |
| 4263 | Warning("parsing [%s:%d] : %s\n", file, linenum, trash); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4264 | err_code |= ERR_WARN; |
| 4265 | goto out; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 4266 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4267 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 4268 | } |
| 4269 | } |
| 4270 | } |
| 4271 | |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 4272 | 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] | 4273 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4274 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4275 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4276 | out: |
| 4277 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4278 | } |
| 4279 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 4280 | int |
| 4281 | cfg_parse_users(const char *file, int linenum, char **args, int kwm) |
| 4282 | { |
| 4283 | |
| 4284 | int err_code = 0; |
| 4285 | const char *err; |
| 4286 | |
| 4287 | if (!strcmp(args[0], "userlist")) { /* new userlist */ |
| 4288 | struct userlist *newul; |
| 4289 | |
| 4290 | if (!*args[1]) { |
| 4291 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 4292 | file, linenum, args[0]); |
| 4293 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4294 | goto out; |
| 4295 | } |
| 4296 | |
| 4297 | err = invalid_char(args[1]); |
| 4298 | if (err) { |
| 4299 | Alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 4300 | file, linenum, *err, args[0], args[1]); |
| 4301 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4302 | goto out; |
| 4303 | } |
| 4304 | |
| 4305 | for (newul = userlist; newul; newul = newul->next) |
| 4306 | if (!strcmp(newul->name, args[1])) { |
| 4307 | Warning("parsing [%s:%d]: ignoring duplicated userlist '%s'.\n", |
| 4308 | file, linenum, args[1]); |
| 4309 | err_code |= ERR_WARN; |
| 4310 | goto out; |
| 4311 | } |
| 4312 | |
| 4313 | newul = (struct userlist *)calloc(1, sizeof(struct userlist)); |
| 4314 | if (!newul) { |
| 4315 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 4316 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4317 | goto out; |
| 4318 | } |
| 4319 | |
| 4320 | newul->groupusers = calloc(MAX_AUTH_GROUPS, sizeof(char *)); |
| 4321 | newul->name = strdup(args[1]); |
| 4322 | |
| 4323 | if (!newul->groupusers | !newul->name) { |
| 4324 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 4325 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4326 | goto out; |
| 4327 | } |
| 4328 | |
| 4329 | newul->next = userlist; |
| 4330 | userlist = newul; |
| 4331 | |
| 4332 | } else if (!strcmp(args[0], "group")) { /* new group */ |
| 4333 | int cur_arg, i; |
| 4334 | const char *err; |
| 4335 | |
| 4336 | if (!*args[1]) { |
| 4337 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 4338 | file, linenum, args[0]); |
| 4339 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4340 | goto out; |
| 4341 | } |
| 4342 | |
| 4343 | err = invalid_char(args[1]); |
| 4344 | if (err) { |
| 4345 | Alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 4346 | file, linenum, *err, args[0], args[1]); |
| 4347 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4348 | goto out; |
| 4349 | } |
| 4350 | |
| 4351 | for(i = 0; i < userlist->grpcnt; i++) |
| 4352 | if (!strcmp(userlist->groups[i], args[1])) { |
| 4353 | Warning("parsing [%s:%d]: ignoring duplicated group '%s' in userlist '%s'.\n", |
| 4354 | file, linenum, args[1], userlist->name); |
| 4355 | err_code |= ERR_ALERT; |
| 4356 | goto out; |
| 4357 | } |
| 4358 | |
| 4359 | if (userlist->grpcnt >= MAX_AUTH_GROUPS) { |
| 4360 | Alert("parsing [%s:%d]: too many groups (%u) in in userlist '%s' while adding group '%s'.\n", |
| 4361 | file, linenum, MAX_AUTH_GROUPS, userlist->name, args[1]); |
| 4362 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4363 | goto out; |
| 4364 | } |
| 4365 | |
| 4366 | cur_arg = 2; |
| 4367 | |
| 4368 | while (*args[cur_arg]) { |
| 4369 | if (!strcmp(args[cur_arg], "users")) { |
| 4370 | userlist->groupusers[userlist->grpcnt] = strdup(args[cur_arg + 1]); |
| 4371 | cur_arg += 2; |
| 4372 | continue; |
| 4373 | } else { |
| 4374 | Alert("parsing [%s:%d]: '%s' only supports 'users' option.\n", |
| 4375 | file, linenum, args[0]); |
| 4376 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4377 | goto out; |
| 4378 | } |
| 4379 | } |
| 4380 | |
| 4381 | userlist->groups[userlist->grpcnt++] = strdup(args[1]); |
| 4382 | } else if (!strcmp(args[0], "user")) { /* new user */ |
| 4383 | struct auth_users *newuser; |
| 4384 | int cur_arg; |
| 4385 | |
| 4386 | if (!*args[1]) { |
| 4387 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 4388 | file, linenum, args[0]); |
| 4389 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4390 | goto out; |
| 4391 | } |
| 4392 | |
| 4393 | for (newuser = userlist->users; newuser; newuser = newuser->next) |
| 4394 | if (!strcmp(newuser->user, args[1])) { |
| 4395 | Warning("parsing [%s:%d]: ignoring duplicated user '%s' in userlist '%s'.\n", |
| 4396 | file, linenum, args[1], userlist->name); |
| 4397 | err_code |= ERR_ALERT; |
| 4398 | goto out; |
| 4399 | } |
| 4400 | |
| 4401 | newuser = (struct auth_users *)calloc(1, sizeof(struct auth_users)); |
| 4402 | if (!newuser) { |
| 4403 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 4404 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4405 | goto out; |
| 4406 | } |
| 4407 | |
| 4408 | newuser->user = strdup(args[1]); |
| 4409 | |
| 4410 | newuser->next = userlist->users; |
| 4411 | userlist->users = newuser; |
| 4412 | |
| 4413 | cur_arg = 2; |
| 4414 | |
| 4415 | while (*args[cur_arg]) { |
| 4416 | if (!strcmp(args[cur_arg], "password")) { |
| 4417 | #ifndef CONFIG_HAP_CRYPT |
| 4418 | Warning("parsing [%s:%d]: no crypt(3) support compiled, encrypted passwords will not work.\n", |
| 4419 | file, linenum); |
| 4420 | err_code |= ERR_ALERT; |
| 4421 | #endif |
| 4422 | newuser->pass = strdup(args[cur_arg + 1]); |
| 4423 | cur_arg += 2; |
| 4424 | continue; |
| 4425 | } else if (!strcmp(args[cur_arg], "insecure-password")) { |
| 4426 | newuser->pass = strdup(args[cur_arg + 1]); |
| 4427 | newuser->flags |= AU_O_INSECURE; |
| 4428 | cur_arg += 2; |
| 4429 | continue; |
| 4430 | } else if (!strcmp(args[cur_arg], "groups")) { |
Willy Tarreau | b4c06b7 | 2010-02-02 11:28:20 +0100 | [diff] [blame] | 4431 | newuser->u.groups = strdup(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 4432 | cur_arg += 2; |
| 4433 | continue; |
| 4434 | } else { |
| 4435 | Alert("parsing [%s:%d]: '%s' only supports 'password', 'insecure-password' and 'groups' options.\n", |
| 4436 | file, linenum, args[0]); |
| 4437 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4438 | goto out; |
| 4439 | } |
| 4440 | } |
| 4441 | } else { |
| 4442 | Alert("parsing [%s:%d]: unknown keyword '%s' in '%s' section\n", file, linenum, args[0], "users"); |
| 4443 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4444 | } |
| 4445 | |
| 4446 | out: |
| 4447 | return err_code; |
| 4448 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4449 | |
| 4450 | /* |
| 4451 | * This function reads and parses the configuration file given in the argument. |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 4452 | * Returns the error code, 0 if OK, or any combination of : |
| 4453 | * - ERR_ABORT: must abort ASAP |
| 4454 | * - ERR_FATAL: we can continue parsing but not start the service |
| 4455 | * - ERR_WARN: a warning has been emitted |
| 4456 | * - ERR_ALERT: an alert has been emitted |
| 4457 | * Only the two first ones can stop processing, the two others are just |
| 4458 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4459 | */ |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 4460 | int readcfgfile(const char *file) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4461 | { |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 4462 | char thisline[LINESIZE]; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4463 | FILE *f; |
| 4464 | int linenum = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4465 | int confsect = CFG_NONE; |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 4466 | int err_code = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4467 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4468 | if ((f=fopen(file,"r")) == NULL) |
| 4469 | return -1; |
| 4470 | |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 4471 | while (fgets(thisline, sizeof(thisline), f) != NULL) { |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 4472 | int arg, kwm = KWM_STD; |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 4473 | char *end; |
| 4474 | char *args[MAX_LINE_ARGS + 1]; |
| 4475 | char *line = thisline; |
| 4476 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4477 | linenum++; |
| 4478 | |
| 4479 | end = line + strlen(line); |
| 4480 | |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 4481 | if (end-line == sizeof(thisline)-1 && *(end-1) != '\n') { |
| 4482 | /* Check if we reached the limit and the last char is not \n. |
| 4483 | * Watch out for the last line without the terminating '\n'! |
| 4484 | */ |
| 4485 | Alert("parsing [%s:%d]: line too long, limit: %d.\n", |
Willy Tarreau | 5e4a6f1 | 2009-04-11 19:42:49 +0200 | [diff] [blame] | 4486 | file, linenum, (int)sizeof(thisline)-1); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 4487 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 4488 | } |
| 4489 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4490 | /* skip leading spaces */ |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 4491 | while (isspace((unsigned char)*line)) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4492 | line++; |
| 4493 | |
| 4494 | arg = 0; |
| 4495 | args[arg] = line; |
| 4496 | |
| 4497 | while (*line && arg < MAX_LINE_ARGS) { |
| 4498 | /* first, we'll replace \\, \<space>, \#, \r, \n, \t, \xXX with their |
| 4499 | * C equivalent value. Other combinations left unchanged (eg: \1). |
| 4500 | */ |
| 4501 | if (*line == '\\') { |
| 4502 | int skip = 0; |
| 4503 | if (line[1] == ' ' || line[1] == '\\' || line[1] == '#') { |
| 4504 | *line = line[1]; |
| 4505 | skip = 1; |
| 4506 | } |
| 4507 | else if (line[1] == 'r') { |
| 4508 | *line = '\r'; |
| 4509 | skip = 1; |
| 4510 | } |
| 4511 | else if (line[1] == 'n') { |
| 4512 | *line = '\n'; |
| 4513 | skip = 1; |
| 4514 | } |
| 4515 | else if (line[1] == 't') { |
| 4516 | *line = '\t'; |
| 4517 | skip = 1; |
| 4518 | } |
| 4519 | else if (line[1] == 'x') { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4520 | if ((line + 3 < end) && ishex(line[2]) && ishex(line[3])) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4521 | unsigned char hex1, hex2; |
| 4522 | hex1 = toupper(line[2]) - '0'; |
| 4523 | hex2 = toupper(line[3]) - '0'; |
| 4524 | if (hex1 > 9) hex1 -= 'A' - '9' - 1; |
| 4525 | if (hex2 > 9) hex2 -= 'A' - '9' - 1; |
| 4526 | *line = (hex1<<4) + hex2; |
| 4527 | skip = 3; |
| 4528 | } |
| 4529 | else { |
| 4530 | 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] | 4531 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4532 | } |
| 4533 | } |
| 4534 | if (skip) { |
Cyril Bonté | dd1b01d | 2009-12-06 13:43:42 +0100 | [diff] [blame] | 4535 | memmove(line + 1, line + 1 + skip, end - (line + skip)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4536 | end -= skip; |
| 4537 | } |
| 4538 | line++; |
| 4539 | } |
| 4540 | else if (*line == '#' || *line == '\n' || *line == '\r') { |
| 4541 | /* end of string, end of loop */ |
| 4542 | *line = 0; |
| 4543 | break; |
| 4544 | } |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 4545 | else if (isspace((unsigned char)*line)) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4546 | /* a non-escaped space is an argument separator */ |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 4547 | *line++ = '\0'; |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 4548 | while (isspace((unsigned char)*line)) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4549 | line++; |
| 4550 | args[++arg] = line; |
| 4551 | } |
| 4552 | else { |
| 4553 | line++; |
| 4554 | } |
| 4555 | } |
| 4556 | |
| 4557 | /* empty line */ |
| 4558 | if (!**args) |
| 4559 | continue; |
| 4560 | |
Willy Tarreau | 7bb651e | 2009-11-09 21:16:53 +0100 | [diff] [blame] | 4561 | if (*line) { |
| 4562 | /* we had to stop due to too many args. |
| 4563 | * Let's terminate the string, print the offending part then cut the |
| 4564 | * last arg. |
| 4565 | */ |
| 4566 | while (*line && *line != '#' && *line != '\n' && *line != '\r') |
| 4567 | line++; |
| 4568 | *line = '\0'; |
| 4569 | |
Krzysztof Piotr Oledzki | 500b8f0 | 2009-12-15 22:34:51 +0100 | [diff] [blame] | 4570 | 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] | 4571 | file, linenum, arg + 1, (long)(args[arg] - thisline + 1), args[arg]); |
Willy Tarreau | 7bb651e | 2009-11-09 21:16:53 +0100 | [diff] [blame] | 4572 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4573 | args[arg] = line; |
| 4574 | } |
| 4575 | |
Willy Tarreau | 540abe4 | 2007-05-02 20:50:16 +0200 | [diff] [blame] | 4576 | /* zero out remaining args and ensure that at least one entry |
| 4577 | * is zeroed out. |
| 4578 | */ |
| 4579 | while (++arg <= MAX_LINE_ARGS) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4580 | args[arg] = line; |
| 4581 | } |
| 4582 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 4583 | /* check for keyword modifiers "no" and "default" */ |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 4584 | if (!strcmp(args[0], "no")) { |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 4585 | kwm = KWM_NO; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 4586 | for (arg=0; *args[arg+1]; arg++) |
| 4587 | args[arg] = args[arg+1]; // shift args after inversion |
| 4588 | } |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 4589 | else if (!strcmp(args[0], "default")) { |
| 4590 | kwm = KWM_DEF; |
| 4591 | for (arg=0; *args[arg+1]; arg++) |
| 4592 | args[arg] = args[arg+1]; // shift args after inversion |
| 4593 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 4594 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 4595 | if (kwm != KWM_STD && strcmp(args[0], "option") != 0) { |
| 4596 | 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] | 4597 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 4598 | } |
| 4599 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4600 | if (!strcmp(args[0], "listen") || |
| 4601 | !strcmp(args[0], "frontend") || |
| 4602 | !strcmp(args[0], "backend") || |
| 4603 | !strcmp(args[0], "ruleset") || |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 4604 | !strcmp(args[0], "defaults")) { /* new proxy */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4605 | confsect = CFG_LISTEN; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 4606 | free(cursection); |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 4607 | cursection = strdup(args[0]); |
| 4608 | } |
| 4609 | else if (!strcmp(args[0], "global")) { /* global config */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4610 | confsect = CFG_GLOBAL; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 4611 | free(cursection); |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 4612 | cursection = strdup(args[0]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 4613 | } else if (!strcmp(args[0], "userlist")) { |
| 4614 | confsect = CFG_USERLIST; |
| 4615 | free(cursection); |
| 4616 | cursection = strdup(args[0]); |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 4617 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4618 | /* else it's a section keyword */ |
| 4619 | |
| 4620 | switch (confsect) { |
| 4621 | case CFG_LISTEN: |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4622 | err_code |= cfg_parse_listen(file, linenum, args, kwm); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4623 | break; |
| 4624 | case CFG_GLOBAL: |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 4625 | err_code |= cfg_parse_global(file, linenum, args, kwm); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4626 | break; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 4627 | case CFG_USERLIST: |
| 4628 | err_code |= cfg_parse_users(file, linenum, args, kwm); |
| 4629 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4630 | default: |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 4631 | 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] | 4632 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4633 | } |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 4634 | |
| 4635 | if (err_code & ERR_ABORT) |
| 4636 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4637 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 4638 | free(cursection); |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 4639 | cursection = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4640 | fclose(f); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 4641 | return err_code; |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 4642 | } |
| 4643 | |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 4644 | /* |
| 4645 | * Returns the error code, 0 if OK, or any combination of : |
| 4646 | * - ERR_ABORT: must abort ASAP |
| 4647 | * - ERR_FATAL: we can continue parsing but not start the service |
| 4648 | * - ERR_WARN: a warning has been emitted |
| 4649 | * - ERR_ALERT: an alert has been emitted |
| 4650 | * Only the two first ones can stop processing, the two others are just |
| 4651 | * indicators. |
| 4652 | */ |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 4653 | int check_config_validity() |
| 4654 | { |
| 4655 | int cfgerr = 0; |
| 4656 | struct proxy *curproxy = NULL; |
| 4657 | struct server *newsrv = NULL; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 4658 | struct userlist *curuserlist = NULL; |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 4659 | int err_code = 0; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 4660 | unsigned int next_pxid = 1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4661 | |
| 4662 | /* |
| 4663 | * Now, check for the integrity of all that we have collected. |
| 4664 | */ |
| 4665 | |
| 4666 | /* will be needed further to delay some tasks */ |
Willy Tarreau | b0b37bc | 2008-06-23 14:00:57 +0200 | [diff] [blame] | 4667 | tv_update_date(0,1); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4668 | |
Willy Tarreau | 55bc0f8 | 2009-03-15 14:51:53 +0100 | [diff] [blame] | 4669 | /* first, we will invert the proxy list order */ |
| 4670 | curproxy = NULL; |
| 4671 | while (proxy) { |
| 4672 | struct proxy *next; |
| 4673 | |
| 4674 | next = proxy->next; |
| 4675 | proxy->next = curproxy; |
| 4676 | curproxy = proxy; |
| 4677 | if (!next) |
| 4678 | break; |
| 4679 | proxy = next; |
| 4680 | } |
| 4681 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4682 | if ((curproxy = proxy) == NULL) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 4683 | Alert("config : no <listen> line. Nothing to do !\n"); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 4684 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4685 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4686 | } |
| 4687 | |
| 4688 | while (curproxy != NULL) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 4689 | struct switching_rule *rule; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4690 | struct sticking_rule *mrule; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 4691 | struct listener *listener; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 4692 | unsigned int next_id; |
| 4693 | |
| 4694 | if (!curproxy->uuid) { |
| 4695 | /* proxy ID not set, use automatic numbering with first |
| 4696 | * spare entry starting with next_pxid. |
| 4697 | */ |
| 4698 | next_pxid = get_next_id(&used_proxy_id, next_pxid); |
| 4699 | curproxy->conf.id.key = curproxy->uuid = next_pxid; |
| 4700 | eb32_insert(&used_proxy_id, &curproxy->conf.id); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 4701 | } |
Krzysztof Piotr Oledzki | df5cb9f | 2010-02-05 20:58:27 +0100 | [diff] [blame] | 4702 | next_pxid++; |
| 4703 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 4704 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4705 | if (curproxy->state == PR_STSTOPPED) { |
Willy Tarreau | da250db | 2008-10-12 12:07:48 +0200 | [diff] [blame] | 4706 | /* ensure we don't keep listeners uselessly bound */ |
| 4707 | stop_proxy(curproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4708 | curproxy = curproxy->next; |
| 4709 | continue; |
| 4710 | } |
| 4711 | |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 4712 | switch (curproxy->mode) { |
| 4713 | case PR_MODE_HEALTH: |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 4714 | cfgerr += proxy_cfg_ensure_no_http(curproxy); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 4715 | if (!(curproxy->cap & PR_CAP_FE)) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 4716 | Alert("config : %s '%s' cannot be in health mode as it has no frontend capability.\n", |
| 4717 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 4718 | cfgerr++; |
| 4719 | } |
| 4720 | |
| 4721 | if (curproxy->srv != NULL) |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 4722 | Warning("config : servers will be ignored for %s '%s'.\n", |
| 4723 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 4724 | break; |
| 4725 | |
| 4726 | case PR_MODE_TCP: |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 4727 | cfgerr += proxy_cfg_ensure_no_http(curproxy); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 4728 | break; |
| 4729 | |
| 4730 | case PR_MODE_HTTP: |
Willy Tarreau | a9fb083 | 2009-07-10 20:53:53 +0200 | [diff] [blame] | 4731 | curproxy->acl_requires |= ACL_USE_L7_ANY; |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 4732 | if ((curproxy->cookie_name != NULL) && (curproxy->srv == NULL)) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 4733 | Alert("config : HTTP proxy %s has a cookie but no server list !\n", |
| 4734 | curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 4735 | cfgerr++; |
| 4736 | } |
| 4737 | break; |
| 4738 | } |
| 4739 | |
| 4740 | if ((curproxy->cap & PR_CAP_FE) && (curproxy->listen == NULL)) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 4741 | Alert("config : %s '%s' has no listen address. Please either specify a valid address on the <listen> line, or use the <bind> keyword.\n", |
| 4742 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4743 | cfgerr++; |
| 4744 | } |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 4745 | |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 4746 | if ((curproxy->cap & PR_CAP_BE) && (curproxy->mode != PR_MODE_HEALTH)) { |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 4747 | if (curproxy->lbprm.algo & BE_LB_KIND) { |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 4748 | if (curproxy->options & PR_O_TRANSP) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 4749 | Alert("config : %s '%s' cannot use both transparent and balance mode.\n", |
| 4750 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 4751 | cfgerr++; |
| 4752 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4753 | #ifdef WE_DONT_SUPPORT_SERVERLESS_LISTENERS |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 4754 | else if (curproxy->srv == NULL) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 4755 | Alert("config : %s '%s' needs at least 1 server in balance mode.\n", |
| 4756 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 4757 | cfgerr++; |
| 4758 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4759 | #endif |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 4760 | else if (*(int *)&curproxy->dispatch_addr.sin_addr != 0) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 4761 | Warning("config : dispatch address of %s '%s' will be ignored in balance mode.\n", |
| 4762 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 4763 | err_code |= ERR_WARN; |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 4764 | } |
| 4765 | } |
| 4766 | else if (!(curproxy->options & (PR_O_TRANSP | PR_O_HTTP_PROXY)) && |
| 4767 | (*(int *)&curproxy->dispatch_addr.sin_addr == 0)) { |
| 4768 | /* If no LB algo is set in a backend, and we're not in |
| 4769 | * transparent mode, dispatch mode nor proxy mode, we |
| 4770 | * want to use balance roundrobin by default. |
| 4771 | */ |
| 4772 | curproxy->lbprm.algo &= ~BE_LB_ALGO; |
| 4773 | curproxy->lbprm.algo |= BE_LB_ALGO_RR; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4774 | } |
| 4775 | } |
Willy Tarreau | 193cf93 | 2007-09-17 10:17:23 +0200 | [diff] [blame] | 4776 | |
Willy Tarreau | 8293658 | 2007-11-30 15:20:09 +0100 | [diff] [blame] | 4777 | if ((curproxy->options & PR_O_DISABLE404) && !(curproxy->options & PR_O_HTTP_CHK)) { |
| 4778 | curproxy->options &= ~PR_O_DISABLE404; |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 4779 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n", |
| 4780 | "disable-on-404", proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 4781 | err_code |= ERR_WARN; |
Willy Tarreau | 8293658 | 2007-11-30 15:20:09 +0100 | [diff] [blame] | 4782 | } |
| 4783 | |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 4784 | if ((curproxy->options2 & PR_O2_CHK_SNDST) && !(curproxy->options & PR_O_HTTP_CHK)) { |
| 4785 | curproxy->options &= ~PR_O2_CHK_SNDST; |
| 4786 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n", |
| 4787 | "send-state", proxy_type_str(curproxy), curproxy->id); |
| 4788 | err_code |= ERR_WARN; |
| 4789 | } |
| 4790 | |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 4791 | /* if a default backend was specified, let's find it */ |
| 4792 | if (curproxy->defbe.name) { |
| 4793 | struct proxy *target; |
| 4794 | |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 4795 | target = findproxy_mode(curproxy->defbe.name, curproxy->mode, PR_CAP_BE); |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 4796 | if (!target) { |
| 4797 | Alert("Proxy '%s': unable to find required default_backend: '%s'.\n", |
| 4798 | curproxy->id, curproxy->defbe.name); |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 4799 | cfgerr++; |
| 4800 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 4801 | Alert("Proxy '%s': loop detected for default_backend: '%s'.\n", |
| 4802 | curproxy->id, curproxy->defbe.name); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 4803 | cfgerr++; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 4804 | } else { |
| 4805 | free(curproxy->defbe.name); |
| 4806 | curproxy->defbe.be = target; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 4807 | /* we force the backend to be present on at least all of |
| 4808 | * the frontend's processes. |
| 4809 | */ |
| 4810 | target->bind_proc = curproxy->bind_proc ? |
| 4811 | (target->bind_proc | curproxy->bind_proc) : 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4812 | } |
| 4813 | } |
| 4814 | |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 4815 | /* find the target proxy in setbe */ |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 4816 | if (curproxy->mode == PR_MODE_HTTP && curproxy->req_exp != NULL) { |
| 4817 | /* map jump target for ACT_SETBE in req_rep chain */ |
| 4818 | struct hdr_exp *exp; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 4819 | for (exp = curproxy->req_exp; exp != NULL; exp = exp->next) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 4820 | struct proxy *target; |
| 4821 | |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 4822 | if (exp->action != ACT_SETBE) |
| 4823 | continue; |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 4824 | |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 4825 | target = findproxy_mode(exp->replace, PR_MODE_HTTP, PR_CAP_BE); |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 4826 | if (!target) { |
| 4827 | Alert("Proxy '%s': unable to find required setbe: '%s'.\n", |
| 4828 | curproxy->id, exp->replace); |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 4829 | cfgerr++; |
| 4830 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 4831 | Alert("Proxy '%s': loop detected for setbe: '%s'.\n", |
| 4832 | curproxy->id, exp->replace); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4833 | cfgerr++; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 4834 | } else { |
| 4835 | free((void *)exp->replace); |
| 4836 | exp->replace = (const char *)target; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 4837 | /* we force the backend to be present on at least all of |
| 4838 | * the frontend's processes. |
| 4839 | */ |
| 4840 | target->bind_proc = curproxy->bind_proc ? |
| 4841 | (target->bind_proc | curproxy->bind_proc) : 0; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 4842 | } |
| 4843 | } |
| 4844 | } |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 4845 | |
| 4846 | /* find the target proxy for 'use_backend' rules */ |
| 4847 | list_for_each_entry(rule, &curproxy->switching_rules, list) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 4848 | struct proxy *target; |
| 4849 | |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 4850 | target = findproxy_mode(rule->be.name, curproxy->mode, PR_CAP_BE); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 4851 | |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 4852 | if (!target) { |
| 4853 | Alert("Proxy '%s': unable to find required use_backend: '%s'.\n", |
| 4854 | curproxy->id, rule->be.name); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 4855 | cfgerr++; |
| 4856 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 4857 | Alert("Proxy '%s': loop detected for use_backend: '%s'.\n", |
| 4858 | curproxy->id, rule->be.name); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 4859 | cfgerr++; |
| 4860 | } else { |
| 4861 | free((void *)rule->be.name); |
| 4862 | rule->be.backend = target; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 4863 | /* we force the backend to be present on at least all of |
| 4864 | * the frontend's processes. |
| 4865 | */ |
| 4866 | target->bind_proc = curproxy->bind_proc ? |
| 4867 | (target->bind_proc | curproxy->bind_proc) : 0; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 4868 | } |
| 4869 | } |
| 4870 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4871 | /* find the target table for 'stick' rules */ |
| 4872 | list_for_each_entry(mrule, &curproxy->sticking_rules, list) { |
| 4873 | struct proxy *target; |
| 4874 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 4875 | curproxy->be_req_ana |= AN_REQ_STICKING_RULES; |
| 4876 | if (mrule->flags & STK_IS_STORE) |
| 4877 | curproxy->be_rsp_ana |= AN_RES_STORE_RULES; |
| 4878 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4879 | if (mrule->table.name) |
Willy Tarreau | c00cdc2 | 2010-06-06 16:48:26 +0200 | [diff] [blame] | 4880 | target = findproxy(mrule->table.name, 0); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4881 | else |
| 4882 | target = curproxy; |
| 4883 | |
| 4884 | if (!target) { |
| 4885 | Alert("Proxy '%s': unable to find stick-table '%s'.\n", |
| 4886 | curproxy->id, mrule->table.name); |
| 4887 | cfgerr++; |
| 4888 | } |
| 4889 | else if (target->table.size == 0) { |
| 4890 | Alert("Proxy '%s': stick-table '%s' used but not configured.\n", |
| 4891 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 4892 | cfgerr++; |
| 4893 | } |
Willy Tarreau | f0b38bf | 2010-06-06 13:22:23 +0200 | [diff] [blame] | 4894 | else if (!stktable_compatible_pattern(mrule->expr, target->table.type)) { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4895 | Alert("Proxy '%s': type of pattern not usable with type of stick-table '%s'.\n", |
| 4896 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 4897 | cfgerr++; |
| 4898 | } |
| 4899 | else { |
| 4900 | free((void *)mrule->table.name); |
| 4901 | mrule->table.t = &(target->table); |
Willy Tarreau | 13c29de | 2010-06-06 16:40:39 +0200 | [diff] [blame] | 4902 | stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4903 | } |
| 4904 | } |
| 4905 | |
| 4906 | /* find the target table for 'store response' rules */ |
| 4907 | list_for_each_entry(mrule, &curproxy->storersp_rules, list) { |
| 4908 | struct proxy *target; |
| 4909 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 4910 | curproxy->be_rsp_ana |= AN_RES_STORE_RULES; |
| 4911 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4912 | if (mrule->table.name) |
Willy Tarreau | c00cdc2 | 2010-06-06 16:48:26 +0200 | [diff] [blame] | 4913 | target = findproxy(mrule->table.name, 0); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4914 | else |
| 4915 | target = curproxy; |
| 4916 | |
| 4917 | if (!target) { |
| 4918 | Alert("Proxy '%s': unable to find store table '%s'.\n", |
| 4919 | curproxy->id, mrule->table.name); |
| 4920 | cfgerr++; |
| 4921 | } |
| 4922 | else if (target->table.size == 0) { |
| 4923 | Alert("Proxy '%s': stick-table '%s' used but not configured.\n", |
| 4924 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 4925 | cfgerr++; |
| 4926 | } |
Willy Tarreau | f0b38bf | 2010-06-06 13:22:23 +0200 | [diff] [blame] | 4927 | else if (!stktable_compatible_pattern(mrule->expr, target->table.type)) { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4928 | Alert("Proxy '%s': type of pattern not usable with type of stick-table '%s'.\n", |
| 4929 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 4930 | cfgerr++; |
| 4931 | } |
| 4932 | else { |
| 4933 | free((void *)mrule->table.name); |
| 4934 | mrule->table.t = &(target->table); |
Willy Tarreau | 13c29de | 2010-06-06 16:40:39 +0200 | [diff] [blame] | 4935 | stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4936 | } |
| 4937 | } |
| 4938 | |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 4939 | if (curproxy->uri_auth && !(curproxy->uri_auth->flags & ST_CONVDONE) && |
| 4940 | !LIST_ISEMPTY(&curproxy->uri_auth->req_acl) && |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 4941 | (curproxy->uri_auth->userlist || curproxy->uri_auth->auth_realm )) { |
| 4942 | Alert("%s '%s': stats 'auth'/'realm' and 'http-request' can't be used at the same time.\n", |
| 4943 | "proxy", curproxy->id); |
| 4944 | cfgerr++; |
| 4945 | goto out_uri_auth_compat; |
| 4946 | } |
| 4947 | |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 4948 | if (curproxy->uri_auth && curproxy->uri_auth->userlist && !(curproxy->uri_auth->flags & ST_CONVDONE)) { |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 4949 | const char *uri_auth_compat_req[10]; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 4950 | struct req_acl_rule *req_acl; |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 4951 | int i = 0; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 4952 | |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 4953 | /* build the ACL condition from scratch. We're relying on anonymous ACLs for that */ |
| 4954 | uri_auth_compat_req[i++] = "auth"; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 4955 | |
| 4956 | if (curproxy->uri_auth->auth_realm) { |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 4957 | uri_auth_compat_req[i++] = "realm"; |
| 4958 | uri_auth_compat_req[i++] = curproxy->uri_auth->auth_realm; |
| 4959 | } |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 4960 | |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 4961 | uri_auth_compat_req[i++] = "unless"; |
| 4962 | uri_auth_compat_req[i++] = "{"; |
| 4963 | uri_auth_compat_req[i++] = "http_auth(.internal-stats-userlist)"; |
| 4964 | uri_auth_compat_req[i++] = "}"; |
| 4965 | uri_auth_compat_req[i++] = ""; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 4966 | |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 4967 | req_acl = parse_auth_cond(uri_auth_compat_req, "internal-stats-auth-compat", 0, curproxy); |
| 4968 | if (!req_acl) { |
| 4969 | cfgerr++; |
| 4970 | break; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 4971 | } |
| 4972 | |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 4973 | LIST_ADDQ(&curproxy->uri_auth->req_acl, &req_acl->list); |
| 4974 | |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 4975 | if (curproxy->uri_auth->auth_realm) { |
| 4976 | free(curproxy->uri_auth->auth_realm); |
| 4977 | curproxy->uri_auth->auth_realm = NULL; |
| 4978 | } |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 4979 | |
| 4980 | curproxy->uri_auth->flags |= ST_CONVDONE; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 4981 | } |
| 4982 | out_uri_auth_compat: |
| 4983 | |
Krzysztof Piotr Oledzki | f9423ae | 2010-01-29 19:26:18 +0100 | [diff] [blame] | 4984 | cfgerr += acl_find_targets(curproxy); |
| 4985 | |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 4986 | if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) && |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 4987 | (((curproxy->cap & PR_CAP_FE) && !curproxy->timeout.client) || |
Willy Tarreau | d825eef | 2007-05-12 22:35:00 +0200 | [diff] [blame] | 4988 | ((curproxy->cap & PR_CAP_BE) && (curproxy->srv) && |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 4989 | (!curproxy->timeout.connect || !curproxy->timeout.server)))) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 4990 | Warning("config : missing timeouts for %s '%s'.\n" |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 4991 | " | While not properly invalid, you will certainly encounter various problems\n" |
| 4992 | " | 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] | 4993 | " | timeouts are set to a non-zero value: 'client', 'connect', 'server'.\n", |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 4994 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 4995 | err_code |= ERR_WARN; |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 4996 | } |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 4997 | |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 4998 | /* Historically, the tarpit and queue timeouts were inherited from contimeout. |
| 4999 | * We must still support older configurations, so let's find out whether those |
| 5000 | * parameters have been set or must be copied from contimeouts. |
| 5001 | */ |
| 5002 | if (curproxy != &defproxy) { |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 5003 | if (!curproxy->timeout.tarpit || |
| 5004 | curproxy->timeout.tarpit == defproxy.timeout.tarpit) { |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 5005 | /* tarpit timeout not set. We search in the following order: |
| 5006 | * default.tarpit, curr.connect, default.connect. |
| 5007 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 5008 | if (defproxy.timeout.tarpit) |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 5009 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 5010 | else if (curproxy->timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 5011 | curproxy->timeout.tarpit = curproxy->timeout.connect; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 5012 | else if (defproxy.timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 5013 | curproxy->timeout.tarpit = defproxy.timeout.connect; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 5014 | } |
| 5015 | if ((curproxy->cap & PR_CAP_BE) && |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 5016 | (!curproxy->timeout.queue || |
| 5017 | curproxy->timeout.queue == defproxy.timeout.queue)) { |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 5018 | /* queue timeout not set. We search in the following order: |
| 5019 | * default.queue, curr.connect, default.connect. |
| 5020 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 5021 | if (defproxy.timeout.queue) |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 5022 | curproxy->timeout.queue = defproxy.timeout.queue; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 5023 | else if (curproxy->timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 5024 | curproxy->timeout.queue = curproxy->timeout.connect; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 5025 | else if (defproxy.timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 5026 | curproxy->timeout.queue = defproxy.timeout.connect; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 5027 | } |
| 5028 | } |
| 5029 | |
Willy Tarreau | 07a5490 | 2010-03-29 18:33:29 +0200 | [diff] [blame] | 5030 | if (curproxy->options2 & PR_O2_SSL3_CHK) { |
Willy Tarreau | 137325d | 2010-02-01 16:38:17 +0100 | [diff] [blame] | 5031 | curproxy->check_len = sizeof(sslv3_client_hello_pkt) - 1; |
| 5032 | curproxy->check_req = (char *)malloc(curproxy->check_len); |
| 5033 | memcpy(curproxy->check_req, sslv3_client_hello_pkt, curproxy->check_len); |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 5034 | } |
| 5035 | |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 5036 | /* The small pools required for the capture lists */ |
| 5037 | if (curproxy->nb_req_cap) |
| 5038 | curproxy->req_cap_pool = create_pool("ptrcap", |
| 5039 | curproxy->nb_req_cap * sizeof(char *), |
| 5040 | MEM_F_SHARED); |
| 5041 | if (curproxy->nb_rsp_cap) |
| 5042 | curproxy->rsp_cap_pool = create_pool("ptrcap", |
| 5043 | curproxy->nb_rsp_cap * sizeof(char *), |
| 5044 | MEM_F_SHARED); |
| 5045 | |
Willy Tarreau | 1d4154a | 2007-05-13 22:57:02 +0200 | [diff] [blame] | 5046 | curproxy->hdr_idx_pool = create_pool("hdr_idx", |
| 5047 | MAX_HTTP_HDR * sizeof(struct hdr_idx_elem), |
| 5048 | MEM_F_SHARED); |
| 5049 | |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 5050 | /* for backwards compatibility with "listen" instances, if |
| 5051 | * fullconn is not set but maxconn is set, then maxconn |
| 5052 | * is used. |
| 5053 | */ |
| 5054 | if (!curproxy->fullconn) |
| 5055 | curproxy->fullconn = curproxy->maxconn; |
| 5056 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5057 | /* first, we will invert the servers list order */ |
| 5058 | newsrv = NULL; |
| 5059 | while (curproxy->srv) { |
| 5060 | struct server *next; |
| 5061 | |
| 5062 | next = curproxy->srv->next; |
| 5063 | curproxy->srv->next = newsrv; |
| 5064 | newsrv = curproxy->srv; |
| 5065 | if (!next) |
| 5066 | break; |
| 5067 | curproxy->srv = next; |
| 5068 | } |
| 5069 | |
Willy Tarreau | dd70165 | 2010-05-25 23:03:02 +0200 | [diff] [blame] | 5070 | /* assign automatic UIDs to servers which don't have one yet */ |
| 5071 | next_id = 1; |
| 5072 | newsrv = curproxy->srv; |
| 5073 | while (newsrv != NULL) { |
| 5074 | if (!newsrv->puid) { |
| 5075 | /* server ID not set, use automatic numbering with first |
| 5076 | * spare entry starting with next_svid. |
| 5077 | */ |
| 5078 | next_id = get_next_id(&curproxy->conf.used_server_id, next_id); |
| 5079 | newsrv->conf.id.key = newsrv->puid = next_id; |
| 5080 | eb32_insert(&curproxy->conf.used_server_id, &newsrv->conf.id); |
| 5081 | } |
| 5082 | next_id++; |
| 5083 | newsrv = newsrv->next; |
| 5084 | } |
| 5085 | |
Willy Tarreau | 2069704 | 2007-11-15 23:26:18 +0100 | [diff] [blame] | 5086 | curproxy->lbprm.wmult = 1; /* default weight multiplier */ |
Willy Tarreau | 5dc2fa6 | 2007-11-19 19:10:18 +0100 | [diff] [blame] | 5087 | curproxy->lbprm.wdiv = 1; /* default weight divider */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5088 | |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 5089 | /* We have to initialize the server lookup mechanism depending |
| 5090 | * on what LB algorithm was choosen. |
| 5091 | */ |
| 5092 | |
| 5093 | curproxy->lbprm.algo &= ~(BE_LB_LKUP | BE_LB_PROP_DYN); |
| 5094 | switch (curproxy->lbprm.algo & BE_LB_KIND) { |
| 5095 | case BE_LB_KIND_RR: |
Willy Tarreau | 9757a38 | 2009-10-03 12:56:50 +0200 | [diff] [blame] | 5096 | if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_RR_STATIC) { |
| 5097 | curproxy->lbprm.algo |= BE_LB_LKUP_MAP; |
| 5098 | init_server_map(curproxy); |
| 5099 | } else { |
| 5100 | curproxy->lbprm.algo |= BE_LB_LKUP_RRTREE | BE_LB_PROP_DYN; |
| 5101 | fwrr_init_server_groups(curproxy); |
| 5102 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 5103 | break; |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 5104 | |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 5105 | case BE_LB_KIND_LC: |
| 5106 | curproxy->lbprm.algo |= BE_LB_LKUP_LCTREE | BE_LB_PROP_DYN; |
Willy Tarreau | 5140623 | 2008-03-10 22:04:20 +0100 | [diff] [blame] | 5107 | fwlc_init_server_tree(curproxy); |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 5108 | break; |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 5109 | |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 5110 | case BE_LB_KIND_HI: |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 5111 | if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS) { |
| 5112 | curproxy->lbprm.algo |= BE_LB_LKUP_CHTREE | BE_LB_PROP_DYN; |
| 5113 | chash_init_server_tree(curproxy); |
| 5114 | } else { |
| 5115 | curproxy->lbprm.algo |= BE_LB_LKUP_MAP; |
| 5116 | init_server_map(curproxy); |
| 5117 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 5118 | break; |
| 5119 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5120 | |
| 5121 | if (curproxy->options & PR_O_LOGASAP) |
| 5122 | curproxy->to_log &= ~LW_BYTES; |
| 5123 | |
Willy Tarreau | e7ded1f | 2009-08-09 10:11:45 +0200 | [diff] [blame] | 5124 | if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) && |
| 5125 | (curproxy->cap & PR_CAP_FE) && curproxy->to_log && curproxy->logfac1 < 0) { |
| 5126 | Warning("config : log format ignored for %s '%s' since it has no log address.\n", |
| 5127 | proxy_type_str(curproxy), curproxy->id); |
| 5128 | err_code |= ERR_WARN; |
| 5129 | } |
| 5130 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 5131 | if (curproxy->mode != PR_MODE_HTTP) { |
| 5132 | int optnum; |
| 5133 | |
| 5134 | if (curproxy->options & PR_O_COOK_ANY) { |
| 5135 | Warning("config : 'cookie' statement ignored for %s '%s' as it requires HTTP mode.\n", |
| 5136 | proxy_type_str(curproxy), curproxy->id); |
| 5137 | err_code |= ERR_WARN; |
| 5138 | } |
| 5139 | |
| 5140 | if (curproxy->uri_auth) { |
| 5141 | Warning("config : 'stats' statement ignored for %s '%s' as it requires HTTP mode.\n", |
| 5142 | proxy_type_str(curproxy), curproxy->id); |
| 5143 | err_code |= ERR_WARN; |
| 5144 | curproxy->uri_auth = NULL; |
| 5145 | } |
| 5146 | |
| 5147 | if (curproxy->options & PR_O_FWDFOR) { |
| 5148 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 5149 | "forwardfor", proxy_type_str(curproxy), curproxy->id); |
| 5150 | err_code |= ERR_WARN; |
| 5151 | curproxy->options &= ~PR_O_FWDFOR; |
| 5152 | } |
| 5153 | |
| 5154 | if (curproxy->options & PR_O_ORGTO) { |
| 5155 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 5156 | "originalto", proxy_type_str(curproxy), curproxy->id); |
| 5157 | err_code |= ERR_WARN; |
| 5158 | curproxy->options &= ~PR_O_ORGTO; |
| 5159 | } |
| 5160 | |
| 5161 | for (optnum = 0; cfg_opts[optnum].name; optnum++) { |
| 5162 | if (cfg_opts[optnum].mode == PR_MODE_HTTP && |
| 5163 | (curproxy->cap & cfg_opts[optnum].cap) && |
| 5164 | (curproxy->options & cfg_opts[optnum].val)) { |
| 5165 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 5166 | cfg_opts[optnum].name, proxy_type_str(curproxy), curproxy->id); |
| 5167 | err_code |= ERR_WARN; |
| 5168 | curproxy->options &= ~cfg_opts[optnum].val; |
| 5169 | } |
| 5170 | } |
| 5171 | |
| 5172 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) { |
| 5173 | if (cfg_opts2[optnum].mode == PR_MODE_HTTP && |
| 5174 | (curproxy->cap & cfg_opts2[optnum].cap) && |
| 5175 | (curproxy->options2 & cfg_opts2[optnum].val)) { |
| 5176 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 5177 | cfg_opts2[optnum].name, proxy_type_str(curproxy), curproxy->id); |
| 5178 | err_code |= ERR_WARN; |
| 5179 | curproxy->options2 &= ~cfg_opts2[optnum].val; |
| 5180 | } |
| 5181 | } |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 5182 | |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 5183 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 5184 | if (curproxy->bind_hdr_occ) { |
| 5185 | curproxy->bind_hdr_occ = 0; |
| 5186 | Warning("config : %s '%s' : ignoring use of header %s as source IP in non-HTTP mode.\n", |
| 5187 | proxy_type_str(curproxy), curproxy->id, curproxy->bind_hdr_name); |
| 5188 | err_code |= ERR_WARN; |
| 5189 | } |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 5190 | #endif |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 5191 | } |
| 5192 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5193 | /* |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 5194 | * ensure that we're not cross-dressing a TCP server into HTTP. |
| 5195 | */ |
| 5196 | newsrv = curproxy->srv; |
| 5197 | while (newsrv != NULL) { |
| 5198 | if ((curproxy->mode != PR_MODE_HTTP) && (newsrv->rdr_len || newsrv->cklen)) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5199 | Alert("config : %s '%s' : server cannot have cookie or redirect prefix in non-HTTP mode.\n", |
| 5200 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 5201 | cfgerr++; |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 5202 | } |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 5203 | |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 5204 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 5205 | if (curproxy->mode != PR_MODE_HTTP && newsrv->bind_hdr_occ) { |
| 5206 | newsrv->bind_hdr_occ = 0; |
| 5207 | Warning("config : %s '%s' : server %s cannot use header %s as source IP in non-HTTP mode.\n", |
| 5208 | proxy_type_str(curproxy), curproxy->id, newsrv->id, newsrv->bind_hdr_name); |
| 5209 | err_code |= ERR_WARN; |
| 5210 | } |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 5211 | #endif |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 5212 | newsrv = newsrv->next; |
| 5213 | } |
| 5214 | |
| 5215 | /* |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5216 | * If this server supports a maxconn parameter, it needs a dedicated |
| 5217 | * tasks to fill the emptied slots when a connection leaves. |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 5218 | * Also, resolve deferred tracking dependency if needed. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5219 | */ |
| 5220 | newsrv = curproxy->srv; |
| 5221 | while (newsrv != NULL) { |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 5222 | if (newsrv->minconn > newsrv->maxconn) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5223 | /* Only 'minconn' was specified, or it was higher than or equal |
| 5224 | * to 'maxconn'. Let's turn this into maxconn and clean it, as |
| 5225 | * this will avoid further useless expensive computations. |
| 5226 | */ |
| 5227 | newsrv->maxconn = newsrv->minconn; |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 5228 | } else if (newsrv->maxconn && !newsrv->minconn) { |
| 5229 | /* minconn was not specified, so we set it to maxconn */ |
| 5230 | newsrv->minconn = newsrv->maxconn; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5231 | } else if (newsrv->minconn != newsrv->maxconn && !curproxy->fullconn) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5232 | Alert("config : %s '%s' : fullconn is mandatory when minconn is set on a server.\n", |
| 5233 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 5234 | cfgerr++; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5235 | } |
| 5236 | |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 5237 | if (newsrv->trackit) { |
| 5238 | struct proxy *px; |
| 5239 | struct server *srv; |
| 5240 | char *pname, *sname; |
| 5241 | |
| 5242 | pname = newsrv->trackit; |
| 5243 | sname = strrchr(pname, '/'); |
| 5244 | |
| 5245 | if (sname) |
| 5246 | *sname++ = '\0'; |
| 5247 | else { |
| 5248 | sname = pname; |
| 5249 | pname = NULL; |
| 5250 | } |
| 5251 | |
| 5252 | if (pname) { |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 5253 | px = findproxy(pname, PR_CAP_BE); |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 5254 | if (!px) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5255 | Alert("config : %s '%s', server '%s': unable to find required proxy '%s' for tracking.\n", |
| 5256 | proxy_type_str(curproxy), curproxy->id, |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 5257 | newsrv->id, pname); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 5258 | cfgerr++; |
| 5259 | goto next_srv; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 5260 | } |
| 5261 | } else |
| 5262 | px = curproxy; |
| 5263 | |
| 5264 | srv = findserver(px, sname); |
| 5265 | if (!srv) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5266 | Alert("config : %s '%s', server '%s': unable to find required server '%s' for tracking.\n", |
| 5267 | proxy_type_str(curproxy), curproxy->id, |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 5268 | newsrv->id, sname); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 5269 | cfgerr++; |
| 5270 | goto next_srv; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 5271 | } |
| 5272 | |
| 5273 | if (!(srv->state & SRV_CHECKED)) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5274 | Alert("config : %s '%s', server '%s': unable to use %s/%s for " |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 5275 | "tracking as it does not have checks enabled.\n", |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5276 | proxy_type_str(curproxy), curproxy->id, |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 5277 | newsrv->id, px->id, srv->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 5278 | cfgerr++; |
| 5279 | goto next_srv; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 5280 | } |
| 5281 | |
| 5282 | if (curproxy != px && |
| 5283 | (curproxy->options & PR_O_DISABLE404) != (px->options & PR_O_DISABLE404)) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5284 | Alert("config : %s '%s', server '%s': unable to use %s/%s for" |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 5285 | "tracking: disable-on-404 option inconsistency.\n", |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5286 | proxy_type_str(curproxy), curproxy->id, |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 5287 | newsrv->id, px->id, srv->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 5288 | cfgerr++; |
| 5289 | goto next_srv; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 5290 | } |
| 5291 | |
| 5292 | newsrv->tracked = srv; |
| 5293 | newsrv->tracknext = srv->tracknext; |
| 5294 | srv->tracknext = newsrv; |
| 5295 | |
| 5296 | free(newsrv->trackit); |
| 5297 | } |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 5298 | next_srv: |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5299 | newsrv = newsrv->next; |
| 5300 | } |
| 5301 | |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 5302 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 5303 | curproxy->accept = frontend_accept; |
| 5304 | |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 5305 | if (curproxy->tcp_req.inspect_delay || |
| 5306 | !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules)) |
| 5307 | curproxy->fe_req_ana |= AN_REQ_INSPECT; |
| 5308 | |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 5309 | if (curproxy->mode == PR_MODE_HTTP) { |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 5310 | 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] | 5311 | 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] | 5312 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 5313 | |
| 5314 | /* both TCP and HTTP must check switching rules */ |
| 5315 | curproxy->fe_req_ana |= AN_REQ_SWITCHING_RULES; |
| 5316 | } |
| 5317 | |
| 5318 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 5319 | if (curproxy->mode == PR_MODE_HTTP) { |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 5320 | 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] | 5321 | 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] | 5322 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 5323 | |
| 5324 | /* If the backend does requires RDP cookie persistence, we have to |
| 5325 | * enable the corresponding analyser. |
| 5326 | */ |
| 5327 | if (curproxy->options2 & PR_O2_RDPC_PRST) |
| 5328 | curproxy->be_req_ana |= AN_REQ_PRST_RDP_COOKIE; |
| 5329 | } |
| 5330 | |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 5331 | listener = NULL; |
| 5332 | while (curproxy->listen) { |
| 5333 | struct listener *next; |
| 5334 | |
| 5335 | next = curproxy->listen->next; |
| 5336 | curproxy->listen->next = listener; |
| 5337 | listener = curproxy->listen; |
| 5338 | |
| 5339 | if (!next) |
| 5340 | break; |
| 5341 | |
| 5342 | curproxy->listen = next; |
| 5343 | } |
| 5344 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 5345 | /* adjust this proxy's listeners */ |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 5346 | next_id = 1; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 5347 | listener = curproxy->listen; |
| 5348 | while (listener) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 5349 | if (!listener->luid) { |
| 5350 | /* listener ID not set, use automatic numbering with first |
| 5351 | * spare entry starting with next_luid. |
| 5352 | */ |
| 5353 | next_id = get_next_id(&curproxy->conf.used_listener_id, next_id); |
| 5354 | listener->conf.id.key = listener->luid = next_id; |
| 5355 | eb32_insert(&curproxy->conf.used_listener_id, &listener->conf.id); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 5356 | } |
Krzysztof Piotr Oledzki | df5cb9f | 2010-02-05 20:58:27 +0100 | [diff] [blame] | 5357 | next_id++; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 5358 | |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 5359 | /* enable separate counters */ |
| 5360 | if (curproxy->options2 & PR_O2_SOCKSTAT) { |
| 5361 | listener->counters = (struct licounters *)calloc(1, sizeof(struct licounters)); |
| 5362 | if (!listener->name) { |
| 5363 | sprintf(trash, "sock-%d", listener->luid); |
| 5364 | listener->name = strdup(trash); |
| 5365 | } |
| 5366 | } |
| 5367 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 5368 | if (curproxy->options & PR_O_TCP_NOLING) |
| 5369 | listener->options |= LI_O_NOLINGER; |
| 5370 | listener->maxconn = curproxy->maxconn; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 5371 | listener->backlog = curproxy->backlog; |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 5372 | listener->timeout = &curproxy->timeout.client; |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 5373 | listener->accept = session_accept; |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 5374 | listener->frontend = curproxy; |
Willy Tarreau | 3bc1377 | 2008-12-07 11:50:35 +0100 | [diff] [blame] | 5375 | listener->handler = process_session; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 5376 | listener->analysers |= curproxy->fe_req_ana; |
Willy Tarreau | 3bc1377 | 2008-12-07 11:50:35 +0100 | [diff] [blame] | 5377 | |
Willy Tarreau | a5c0ab2 | 2010-05-31 10:30:33 +0200 | [diff] [blame] | 5378 | if (!LIST_ISEMPTY(&curproxy->tcp_req.l4_rules)) |
| 5379 | listener->options |= LI_O_TCP_RULES; |
| 5380 | |
Willy Tarreau | de3041d | 2010-05-31 10:56:17 +0200 | [diff] [blame] | 5381 | if (curproxy->mon_mask.s_addr) |
| 5382 | listener->options |= LI_O_CHK_MONNET; |
| 5383 | |
Willy Tarreau | 9ea05a7 | 2009-06-14 12:07:01 +0200 | [diff] [blame] | 5384 | /* smart accept mode is automatic in HTTP mode */ |
| 5385 | if ((curproxy->options2 & PR_O2_SMARTACC) || |
| 5386 | (curproxy->mode == PR_MODE_HTTP && |
| 5387 | !(curproxy->no_options2 & PR_O2_SMARTACC))) |
| 5388 | listener->options |= LI_O_NOQUICKACK; |
| 5389 | |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 5390 | /* We want the use_backend and default_backend rules to apply */ |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 5391 | listener = listener->next; |
| 5392 | } |
| 5393 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5394 | curproxy = curproxy->next; |
| 5395 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5396 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5397 | for (curuserlist = userlist; curuserlist; curuserlist = curuserlist->next) { |
| 5398 | struct auth_users *curuser; |
| 5399 | int g; |
| 5400 | |
| 5401 | for (curuser = curuserlist->users; curuser; curuser = curuser->next) { |
| 5402 | unsigned int group_mask = 0; |
| 5403 | char *group = NULL; |
| 5404 | |
Willy Tarreau | b4c06b7 | 2010-02-02 11:28:20 +0100 | [diff] [blame] | 5405 | if (!curuser->u.groups) |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5406 | continue; |
| 5407 | |
Willy Tarreau | b4c06b7 | 2010-02-02 11:28:20 +0100 | [diff] [blame] | 5408 | while ((group = strtok(group?NULL:curuser->u.groups, ","))) { |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5409 | |
| 5410 | for (g = 0; g < curuserlist->grpcnt; g++) |
| 5411 | if (!strcmp(curuserlist->groups[g], group)) |
| 5412 | break; |
| 5413 | |
| 5414 | if (g == curuserlist->grpcnt) { |
| 5415 | Alert("userlist '%s': no such group '%s' specified in user '%s'\n", |
| 5416 | curuserlist->name, group, curuser->user); |
| 5417 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5418 | goto out; |
| 5419 | } |
| 5420 | |
| 5421 | group_mask |= (1 << g); |
| 5422 | } |
| 5423 | |
Willy Tarreau | b4c06b7 | 2010-02-02 11:28:20 +0100 | [diff] [blame] | 5424 | free(curuser->u.groups); |
| 5425 | curuser->u.group_mask = group_mask; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5426 | } |
| 5427 | |
| 5428 | for (g = 0; g < curuserlist->grpcnt; g++) { |
| 5429 | char *user = NULL; |
| 5430 | |
| 5431 | if (!curuserlist->groupusers[g]) |
| 5432 | continue; |
| 5433 | |
| 5434 | while ((user = strtok(user?NULL:curuserlist->groupusers[g], ","))) { |
| 5435 | for (curuser = curuserlist->users; curuser; curuser = curuser->next) |
| 5436 | if (!strcmp(curuser->user, user)) |
| 5437 | break; |
| 5438 | |
| 5439 | if (!curuser) { |
| 5440 | Alert("userlist '%s': no such user '%s' specified in group '%s'\n", |
| 5441 | curuserlist->name, user, curuserlist->groups[g]); |
| 5442 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5443 | goto out; |
| 5444 | } |
| 5445 | |
Willy Tarreau | b4c06b7 | 2010-02-02 11:28:20 +0100 | [diff] [blame] | 5446 | curuser->u.group_mask |= (1 << g); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5447 | } |
| 5448 | |
| 5449 | free(curuserlist->groupusers[g]); |
| 5450 | } |
| 5451 | |
| 5452 | free(curuserlist->groupusers); |
| 5453 | |
| 5454 | #ifdef DEBUG_AUTH |
| 5455 | for (g = 0; g < curuserlist->grpcnt; g++) { |
| 5456 | fprintf(stderr, "group %s, id %d, mask %08X, users:", curuserlist->groups[g], g , 1 << g); |
| 5457 | |
| 5458 | for (curuser = curuserlist->users; curuser; curuser = curuser->next) { |
| 5459 | if (curuser->group_mask & (1 << g)) |
| 5460 | fprintf(stderr, " %s", curuser->user); |
| 5461 | } |
| 5462 | |
| 5463 | fprintf(stderr, "\n"); |
| 5464 | } |
| 5465 | #endif |
| 5466 | |
| 5467 | } |
| 5468 | |
Willy Tarreau | 056f568 | 2010-06-06 15:51:11 +0200 | [diff] [blame] | 5469 | /* initialize stick-tables on backend capable proxies. This must not |
| 5470 | * be done earlier because the data size may be discovered while parsing |
| 5471 | * other proxies. |
| 5472 | */ |
| 5473 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) |
Willy Tarreau | c00cdc2 | 2010-06-06 16:48:26 +0200 | [diff] [blame] | 5474 | stktable_init(&curproxy->table); |
Willy Tarreau | 056f568 | 2010-06-06 15:51:11 +0200 | [diff] [blame] | 5475 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5476 | /* |
| 5477 | * Recount currently required checks. |
| 5478 | */ |
| 5479 | |
| 5480 | for (curproxy=proxy; curproxy; curproxy=curproxy->next) { |
| 5481 | int optnum; |
| 5482 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 5483 | for (optnum = 0; cfg_opts[optnum].name; optnum++) |
| 5484 | if (curproxy->options & cfg_opts[optnum].val) |
| 5485 | global.last_checks |= cfg_opts[optnum].checks; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5486 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 5487 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) |
| 5488 | if (curproxy->options2 & cfg_opts2[optnum].val) |
| 5489 | global.last_checks |= cfg_opts2[optnum].checks; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5490 | } |
| 5491 | |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 5492 | if (cfgerr > 0) |
| 5493 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5494 | out: |
| 5495 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5496 | } |
| 5497 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 5498 | /* |
| 5499 | * Registers the CFG keyword list <kwl> as a list of valid keywords for next |
| 5500 | * parsing sessions. |
| 5501 | */ |
| 5502 | void cfg_register_keywords(struct cfg_kw_list *kwl) |
| 5503 | { |
| 5504 | LIST_ADDQ(&cfg_keywords.list, &kwl->list); |
| 5505 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5506 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 5507 | /* |
| 5508 | * Unregisters the CFG keyword list <kwl> from the list of valid keywords. |
| 5509 | */ |
| 5510 | void cfg_unregister_keywords(struct cfg_kw_list *kwl) |
| 5511 | { |
| 5512 | LIST_DEL(&kwl->list); |
| 5513 | LIST_INIT(&kwl->list); |
| 5514 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5515 | |
| 5516 | /* |
| 5517 | * Local variables: |
| 5518 | * c-indent-level: 8 |
| 5519 | * c-basic-offset: 8 |
| 5520 | * End: |
| 5521 | */ |