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 | af7ad00 | 2010-08-31 15:39:26 +0200 | [diff] [blame] | 270 | jobs++; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 271 | listeners++; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 272 | } /* end for(port) */ |
| 273 | } /* end while(next) */ |
| 274 | free(dupstr); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 275 | return 1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 276 | fail: |
| 277 | free(dupstr); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 278 | return 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 279 | } |
| 280 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 281 | /* |
| 282 | * Sends a warning if proxy <proxy> does not have at least one of the |
| 283 | * capabilities in <cap>. An optionnal <hint> may be added at the end |
| 284 | * of the warning to help the user. Returns 1 if a warning was emitted |
| 285 | * or 0 if the condition is valid. |
| 286 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 287 | 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] | 288 | { |
| 289 | char *msg; |
| 290 | |
| 291 | switch (cap) { |
| 292 | case PR_CAP_BE: msg = "no backend"; break; |
| 293 | case PR_CAP_FE: msg = "no frontend"; break; |
| 294 | case PR_CAP_RS: msg = "no ruleset"; break; |
| 295 | case PR_CAP_BE|PR_CAP_FE: msg = "neither frontend nor backend"; break; |
| 296 | default: msg = "not enough"; break; |
| 297 | } |
| 298 | |
| 299 | if (!(proxy->cap & cap)) { |
| 300 | 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] | 301 | file, line, arg, proxy_type_str(proxy), proxy->id, msg, hint ? hint : ""); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 302 | return 1; |
| 303 | } |
| 304 | return 0; |
| 305 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 306 | |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 307 | /* Report a warning if a rule is placed after a 'block' rule. |
| 308 | * Return 1 if the warning has been emitted, otherwise 0. |
| 309 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 310 | 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] | 311 | { |
| 312 | if (!LIST_ISEMPTY(&proxy->block_cond)) { |
| 313 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'block' rule will still be processed before.\n", |
| 314 | file, line, arg); |
| 315 | return 1; |
| 316 | } |
| 317 | return 0; |
| 318 | } |
| 319 | |
| 320 | /* Report a warning if a rule is placed after a reqrewrite rule. |
| 321 | * Return 1 if the warning has been emitted, otherwise 0. |
| 322 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 323 | 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] | 324 | { |
| 325 | if (proxy->req_exp) { |
| 326 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'reqxxx' rule will still be processed before.\n", |
| 327 | file, line, arg); |
| 328 | return 1; |
| 329 | } |
| 330 | return 0; |
| 331 | } |
| 332 | |
| 333 | /* Report a warning if a rule is placed after a reqadd rule. |
| 334 | * Return 1 if the warning has been emitted, otherwise 0. |
| 335 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 336 | 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] | 337 | { |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 338 | if (!LIST_ISEMPTY(&proxy->req_add)) { |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 339 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'reqadd' rule will still be processed before.\n", |
| 340 | file, line, arg); |
| 341 | return 1; |
| 342 | } |
| 343 | return 0; |
| 344 | } |
| 345 | |
| 346 | /* Report a warning if a rule is placed after a redirect rule. |
| 347 | * Return 1 if the warning has been emitted, otherwise 0. |
| 348 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 349 | 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] | 350 | { |
| 351 | if (!LIST_ISEMPTY(&proxy->redirect_rules)) { |
| 352 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'redirect' rule will still be processed before.\n", |
| 353 | file, line, arg); |
| 354 | return 1; |
| 355 | } |
| 356 | return 0; |
| 357 | } |
| 358 | |
| 359 | /* Report a warning if a rule is placed after a 'use_backend' rule. |
| 360 | * Return 1 if the warning has been emitted, otherwise 0. |
| 361 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 362 | 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] | 363 | { |
| 364 | if (!LIST_ISEMPTY(&proxy->switching_rules)) { |
| 365 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'use_backend' rule will still be processed before.\n", |
| 366 | file, line, arg); |
| 367 | return 1; |
| 368 | } |
| 369 | return 0; |
| 370 | } |
| 371 | |
| 372 | /* report a warning if a block rule is dangerously placed */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 373 | 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] | 374 | { |
| 375 | return warnif_rule_after_reqxxx(proxy, file, line, arg) || |
| 376 | warnif_rule_after_reqadd(proxy, file, line, arg) || |
| 377 | warnif_rule_after_redirect(proxy, file, line, arg) || |
| 378 | warnif_rule_after_use_backend(proxy, file, line, arg); |
| 379 | } |
| 380 | |
| 381 | /* report a warning if a reqxxx rule is dangerously placed */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 382 | 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] | 383 | { |
| 384 | return warnif_rule_after_reqadd(proxy, file, line, arg) || |
| 385 | warnif_rule_after_redirect(proxy, file, line, arg) || |
| 386 | warnif_rule_after_use_backend(proxy, file, line, arg); |
| 387 | } |
| 388 | |
| 389 | /* report a warning if a reqadd rule is dangerously placed */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 390 | 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] | 391 | { |
| 392 | return warnif_rule_after_redirect(proxy, file, line, arg) || |
| 393 | warnif_rule_after_use_backend(proxy, file, line, arg); |
| 394 | } |
| 395 | |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 396 | /* Report it if a request ACL condition uses some response-only parameters. It |
| 397 | * returns either 0 or ERR_WARN so that its result can be or'ed with err_code. |
| 398 | * Note that <cond> may be NULL and then will be ignored. |
| 399 | */ |
| 400 | static int warnif_cond_requires_resp(const struct acl_cond *cond, const char *file, int line) |
| 401 | { |
| 402 | struct acl *acl; |
| 403 | |
| 404 | if (!cond || !(cond->requires & ACL_USE_RTR_ANY)) |
| 405 | return 0; |
| 406 | |
| 407 | acl = cond_find_require(cond, ACL_USE_RTR_ANY); |
| 408 | Warning("parsing [%s:%d] : acl '%s' involves some response-only criteria which will be ignored.\n", |
| 409 | file, line, acl ? acl->name : "(unknown)"); |
| 410 | return ERR_WARN; |
| 411 | } |
| 412 | |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 413 | /* Report it if a request ACL condition uses some request-only volatile parameters. |
| 414 | * It returns either 0 or ERR_WARN so that its result can be or'ed with err_code. |
| 415 | * Note that <cond> may be NULL and then will be ignored. |
| 416 | */ |
| 417 | static int warnif_cond_requires_req(const struct acl_cond *cond, const char *file, int line) |
| 418 | { |
| 419 | struct acl *acl; |
| 420 | |
| 421 | if (!cond || !(cond->requires & ACL_USE_REQ_VOLATILE)) |
| 422 | return 0; |
| 423 | |
| 424 | acl = cond_find_require(cond, ACL_USE_REQ_VOLATILE); |
| 425 | Warning("parsing [%s:%d] : acl '%s' involves some volatile request-only criteria which will be ignored.\n", |
| 426 | file, line, acl ? acl->name : "(unknown)"); |
| 427 | return ERR_WARN; |
| 428 | } |
| 429 | |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 430 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 431 | /* |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 432 | * parse a line in a <global> section. Returns the error code, 0 if OK, or |
| 433 | * any combination of : |
| 434 | * - ERR_ABORT: must abort ASAP |
| 435 | * - ERR_FATAL: we can continue parsing but not start the service |
| 436 | * - ERR_WARN: a warning has been emitted |
| 437 | * - ERR_ALERT: an alert has been emitted |
| 438 | * Only the two first ones can stop processing, the two others are just |
| 439 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 440 | */ |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 441 | 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] | 442 | { |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 443 | int err_code = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 444 | |
| 445 | if (!strcmp(args[0], "global")) { /* new section */ |
| 446 | /* no option, nothing special to do */ |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 447 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 448 | } |
| 449 | else if (!strcmp(args[0], "daemon")) { |
| 450 | global.mode |= MODE_DAEMON; |
| 451 | } |
| 452 | else if (!strcmp(args[0], "debug")) { |
| 453 | global.mode |= MODE_DEBUG; |
| 454 | } |
| 455 | else if (!strcmp(args[0], "noepoll")) { |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 456 | global.tune.options &= ~GTUNE_USE_EPOLL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 457 | } |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 458 | else if (!strcmp(args[0], "nosepoll")) { |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 459 | global.tune.options &= ~GTUNE_USE_SEPOLL; |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 460 | } |
| 461 | else if (!strcmp(args[0], "nokqueue")) { |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 462 | global.tune.options &= ~GTUNE_USE_KQUEUE; |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 463 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 464 | else if (!strcmp(args[0], "nopoll")) { |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 465 | global.tune.options &= ~GTUNE_USE_POLL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 466 | } |
Willy Tarreau | 3ab68cf | 2009-01-25 16:03:28 +0100 | [diff] [blame] | 467 | else if (!strcmp(args[0], "nosplice")) { |
| 468 | global.tune.options &= ~GTUNE_USE_SPLICE; |
| 469 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 470 | else if (!strcmp(args[0], "quiet")) { |
| 471 | global.mode |= MODE_QUIET; |
| 472 | } |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 473 | else if (!strcmp(args[0], "tune.maxpollevents")) { |
| 474 | if (global.tune.maxpollevents != 0) { |
| 475 | 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] | 476 | err_code |= ERR_ALERT; |
| 477 | goto out; |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 478 | } |
| 479 | if (*(args[1]) == 0) { |
| 480 | 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] | 481 | err_code |= ERR_ALERT | ERR_FATAL; |
| 482 | goto out; |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 483 | } |
| 484 | global.tune.maxpollevents = atol(args[1]); |
| 485 | } |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 486 | else if (!strcmp(args[0], "tune.maxaccept")) { |
| 487 | if (global.tune.maxaccept != 0) { |
| 488 | 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] | 489 | err_code |= ERR_ALERT; |
| 490 | goto out; |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 491 | } |
| 492 | if (*(args[1]) == 0) { |
| 493 | 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] | 494 | err_code |= ERR_ALERT | ERR_FATAL; |
| 495 | goto out; |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 496 | } |
| 497 | global.tune.maxaccept = atol(args[1]); |
| 498 | } |
Willy Tarreau | 43961d5 | 2010-10-04 20:39:20 +0200 | [diff] [blame] | 499 | else if (!strcmp(args[0], "tune.chksize")) { |
| 500 | if (*(args[1]) == 0) { |
| 501 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 502 | err_code |= ERR_ALERT | ERR_FATAL; |
| 503 | goto out; |
| 504 | } |
| 505 | global.tune.chksize = atol(args[1]); |
| 506 | } |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 507 | else if (!strcmp(args[0], "tune.bufsize")) { |
| 508 | if (*(args[1]) == 0) { |
| 509 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 510 | err_code |= ERR_ALERT | ERR_FATAL; |
| 511 | goto out; |
| 512 | } |
| 513 | global.tune.bufsize = atol(args[1]); |
| 514 | if (global.tune.maxrewrite >= global.tune.bufsize / 2) |
| 515 | global.tune.maxrewrite = global.tune.bufsize / 2; |
| 516 | } |
| 517 | else if (!strcmp(args[0], "tune.maxrewrite")) { |
| 518 | if (*(args[1]) == 0) { |
| 519 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 520 | err_code |= ERR_ALERT | ERR_FATAL; |
| 521 | goto out; |
| 522 | } |
| 523 | global.tune.maxrewrite = atol(args[1]); |
| 524 | if (global.tune.maxrewrite >= global.tune.bufsize / 2) |
| 525 | global.tune.maxrewrite = global.tune.bufsize / 2; |
| 526 | } |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 527 | else if (!strcmp(args[0], "tune.rcvbuf.client")) { |
| 528 | if (global.tune.client_rcvbuf != 0) { |
| 529 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 530 | err_code |= ERR_ALERT; |
| 531 | goto out; |
| 532 | } |
| 533 | if (*(args[1]) == 0) { |
| 534 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 535 | err_code |= ERR_ALERT | ERR_FATAL; |
| 536 | goto out; |
| 537 | } |
| 538 | global.tune.client_rcvbuf = atol(args[1]); |
| 539 | } |
| 540 | else if (!strcmp(args[0], "tune.rcvbuf.server")) { |
| 541 | if (global.tune.server_rcvbuf != 0) { |
| 542 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 543 | err_code |= ERR_ALERT; |
| 544 | goto out; |
| 545 | } |
| 546 | if (*(args[1]) == 0) { |
| 547 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 548 | err_code |= ERR_ALERT | ERR_FATAL; |
| 549 | goto out; |
| 550 | } |
| 551 | global.tune.server_rcvbuf = atol(args[1]); |
| 552 | } |
| 553 | else if (!strcmp(args[0], "tune.sndbuf.client")) { |
| 554 | if (global.tune.client_sndbuf != 0) { |
| 555 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 556 | err_code |= ERR_ALERT; |
| 557 | goto out; |
| 558 | } |
| 559 | if (*(args[1]) == 0) { |
| 560 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 561 | err_code |= ERR_ALERT | ERR_FATAL; |
| 562 | goto out; |
| 563 | } |
| 564 | global.tune.client_sndbuf = atol(args[1]); |
| 565 | } |
| 566 | else if (!strcmp(args[0], "tune.sndbuf.server")) { |
| 567 | if (global.tune.server_sndbuf != 0) { |
| 568 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 569 | err_code |= ERR_ALERT; |
| 570 | goto out; |
| 571 | } |
| 572 | if (*(args[1]) == 0) { |
| 573 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 574 | err_code |= ERR_ALERT | ERR_FATAL; |
| 575 | goto out; |
| 576 | } |
| 577 | global.tune.server_sndbuf = atol(args[1]); |
| 578 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 579 | else if (!strcmp(args[0], "uid")) { |
| 580 | if (global.uid != 0) { |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 581 | Alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 582 | err_code |= ERR_ALERT; |
| 583 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 584 | } |
| 585 | if (*(args[1]) == 0) { |
| 586 | 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] | 587 | err_code |= ERR_ALERT | ERR_FATAL; |
| 588 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 589 | } |
| 590 | global.uid = atol(args[1]); |
| 591 | } |
| 592 | else if (!strcmp(args[0], "gid")) { |
| 593 | if (global.gid != 0) { |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 594 | Alert("parsing [%s:%d] : group/gid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 595 | err_code |= ERR_ALERT; |
| 596 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 597 | } |
| 598 | if (*(args[1]) == 0) { |
| 599 | 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] | 600 | err_code |= ERR_ALERT | ERR_FATAL; |
| 601 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 602 | } |
| 603 | global.gid = atol(args[1]); |
| 604 | } |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 605 | /* user/group name handling */ |
| 606 | else if (!strcmp(args[0], "user")) { |
| 607 | struct passwd *ha_user; |
| 608 | if (global.uid != 0) { |
| 609 | Alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 610 | err_code |= ERR_ALERT; |
| 611 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 612 | } |
| 613 | errno = 0; |
| 614 | ha_user = getpwnam(args[1]); |
| 615 | if (ha_user != NULL) { |
| 616 | global.uid = (int)ha_user->pw_uid; |
| 617 | } |
| 618 | else { |
| 619 | 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] | 620 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 621 | } |
| 622 | } |
| 623 | else if (!strcmp(args[0], "group")) { |
| 624 | struct group *ha_group; |
| 625 | if (global.gid != 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 626 | 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] | 627 | err_code |= ERR_ALERT; |
| 628 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 629 | } |
| 630 | errno = 0; |
| 631 | ha_group = getgrnam(args[1]); |
| 632 | if (ha_group != NULL) { |
| 633 | global.gid = (int)ha_group->gr_gid; |
| 634 | } |
| 635 | else { |
| 636 | 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] | 637 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 638 | } |
| 639 | } |
| 640 | /* end of user/group name handling*/ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 641 | else if (!strcmp(args[0], "nbproc")) { |
| 642 | if (global.nbproc != 0) { |
| 643 | 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] | 644 | err_code |= ERR_ALERT; |
| 645 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 646 | } |
| 647 | if (*(args[1]) == 0) { |
| 648 | 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] | 649 | err_code |= ERR_ALERT | ERR_FATAL; |
| 650 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 651 | } |
| 652 | global.nbproc = atol(args[1]); |
| 653 | } |
| 654 | else if (!strcmp(args[0], "maxconn")) { |
| 655 | if (global.maxconn != 0) { |
| 656 | 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] | 657 | err_code |= ERR_ALERT; |
| 658 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 659 | } |
| 660 | if (*(args[1]) == 0) { |
| 661 | 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] | 662 | err_code |= ERR_ALERT | ERR_FATAL; |
| 663 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 664 | } |
| 665 | global.maxconn = atol(args[1]); |
| 666 | #ifdef SYSTEM_MAXCONN |
| 667 | if (global.maxconn > DEFAULT_MAXCONN && cfg_maxconn <= DEFAULT_MAXCONN) { |
| 668 | 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); |
| 669 | global.maxconn = DEFAULT_MAXCONN; |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 670 | err_code |= ERR_ALERT; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 671 | } |
| 672 | #endif /* SYSTEM_MAXCONN */ |
| 673 | } |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 674 | else if (!strcmp(args[0], "maxpipes")) { |
| 675 | if (global.maxpipes != 0) { |
| 676 | 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] | 677 | err_code |= ERR_ALERT; |
| 678 | goto out; |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 679 | } |
| 680 | if (*(args[1]) == 0) { |
| 681 | 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] | 682 | err_code |= ERR_ALERT | ERR_FATAL; |
| 683 | goto out; |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 684 | } |
| 685 | global.maxpipes = atol(args[1]); |
| 686 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 687 | else if (!strcmp(args[0], "ulimit-n")) { |
| 688 | if (global.rlimit_nofile != 0) { |
| 689 | 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] | 690 | err_code |= ERR_ALERT; |
| 691 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 692 | } |
| 693 | if (*(args[1]) == 0) { |
| 694 | 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] | 695 | err_code |= ERR_ALERT | ERR_FATAL; |
| 696 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 697 | } |
| 698 | global.rlimit_nofile = atol(args[1]); |
| 699 | } |
| 700 | else if (!strcmp(args[0], "chroot")) { |
| 701 | if (global.chroot != NULL) { |
| 702 | 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] | 703 | err_code |= ERR_ALERT; |
| 704 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 705 | } |
| 706 | if (*(args[1]) == 0) { |
| 707 | 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] | 708 | err_code |= ERR_ALERT | ERR_FATAL; |
| 709 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 710 | } |
| 711 | global.chroot = strdup(args[1]); |
| 712 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 713 | else if (!strcmp(args[0], "description")) { |
| 714 | int i, len=0; |
| 715 | char *d; |
| 716 | |
| 717 | if (!*args[1]) { |
| 718 | Alert("parsing [%s:%d]: '%s' expects a string argument.\n", |
| 719 | file, linenum, args[0]); |
| 720 | err_code |= ERR_ALERT | ERR_FATAL; |
| 721 | goto out; |
| 722 | } |
| 723 | |
| 724 | for(i=1; *args[i]; i++) |
| 725 | len += strlen(args[i])+1; |
| 726 | |
| 727 | if (global.desc) |
| 728 | free(global.desc); |
| 729 | |
| 730 | global.desc = d = (char *)calloc(1, len); |
| 731 | |
| 732 | d += sprintf(d, "%s", args[1]); |
| 733 | for(i=2; *args[i]; i++) |
| 734 | d += sprintf(d, " %s", args[i]); |
| 735 | } |
| 736 | else if (!strcmp(args[0], "node")) { |
| 737 | int i; |
| 738 | char c; |
| 739 | |
| 740 | for (i=0; args[1][i]; i++) { |
| 741 | c = args[1][i]; |
Willy Tarreau | 88e0581 | 2010-03-03 00:16:00 +0100 | [diff] [blame] | 742 | if (!isupper((unsigned char)c) && !islower((unsigned char)c) && |
| 743 | !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.') |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 744 | break; |
| 745 | } |
| 746 | |
| 747 | if (!i || args[1][i]) { |
| 748 | Alert("parsing [%s:%d]: '%s' requires valid node name - non-empty string" |
| 749 | " with digits(0-9), letters(A-Z, a-z), dot(.), hyphen(-) or underscode(_).\n", |
| 750 | file, linenum, args[0]); |
| 751 | err_code |= ERR_ALERT | ERR_FATAL; |
| 752 | goto out; |
| 753 | } |
| 754 | |
| 755 | if (global.node) |
| 756 | free(global.node); |
| 757 | |
| 758 | global.node = strdup(args[1]); |
| 759 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 760 | else if (!strcmp(args[0], "pidfile")) { |
| 761 | if (global.pidfile != NULL) { |
| 762 | 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] | 763 | err_code |= ERR_ALERT; |
| 764 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 765 | } |
| 766 | if (*(args[1]) == 0) { |
| 767 | 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] | 768 | err_code |= ERR_ALERT | ERR_FATAL; |
| 769 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 770 | } |
| 771 | global.pidfile = strdup(args[1]); |
| 772 | } |
| 773 | else if (!strcmp(args[0], "log")) { /* syslog server address */ |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 774 | struct logsrv logsrv; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 775 | int facility, level, minlvl; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 776 | |
| 777 | if (*(args[1]) == 0 || *(args[2]) == 0) { |
| 778 | 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] | 779 | err_code |= ERR_ALERT | ERR_FATAL; |
| 780 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 781 | } |
| 782 | |
| 783 | facility = get_log_facility(args[2]); |
| 784 | if (facility < 0) { |
| 785 | 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] | 786 | err_code |= ERR_ALERT | ERR_FATAL; |
| 787 | facility = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 788 | } |
| 789 | |
| 790 | level = 7; /* max syslog level = debug */ |
| 791 | if (*(args[3])) { |
| 792 | level = get_log_level(args[3]); |
| 793 | if (level < 0) { |
| 794 | 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] | 795 | err_code |= ERR_ALERT | ERR_FATAL; |
| 796 | level = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 797 | } |
| 798 | } |
| 799 | |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 800 | minlvl = 0; /* limit syslog level to this level (emerg) */ |
| 801 | if (*(args[4])) { |
| 802 | minlvl = get_log_level(args[4]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 803 | if (minlvl < 0) { |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 804 | 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] | 805 | err_code |= ERR_ALERT | ERR_FATAL; |
| 806 | minlvl = 0; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 807 | } |
| 808 | } |
| 809 | |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 810 | if (args[1][0] == '/') { |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 811 | struct sockaddr_un *sk = str2sun(args[1]); |
| 812 | if (!sk) { |
| 813 | Alert("parsing [%s:%d] : Socket path '%s' too long (max %d)\n", file, linenum, |
| 814 | args[1], (int)sizeof(sk->sun_path) - 1); |
| 815 | err_code |= ERR_ALERT | ERR_FATAL; |
| 816 | goto out; |
| 817 | } |
| 818 | logsrv.u.un = *sk; |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 819 | logsrv.u.addr.sa_family = AF_UNIX; |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 820 | } else { |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 821 | struct sockaddr_in *sk = str2sa(args[1]); |
| 822 | if (!sk) { |
| 823 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[1]); |
| 824 | err_code |= ERR_ALERT | ERR_FATAL; |
| 825 | goto out; |
| 826 | } |
| 827 | logsrv.u.in = *sk; |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 828 | logsrv.u.addr.sa_family = AF_INET; |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 829 | if (!logsrv.u.in.sin_port) |
| 830 | logsrv.u.in.sin_port = htons(SYSLOG_PORT); |
| 831 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 832 | |
| 833 | if (global.logfac1 == -1) { |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 834 | global.logsrv1 = logsrv; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 835 | global.logfac1 = facility; |
| 836 | global.loglev1 = level; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 837 | global.minlvl1 = minlvl; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 838 | } |
| 839 | else if (global.logfac2 == -1) { |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 840 | global.logsrv2 = logsrv; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 841 | global.logfac2 = facility; |
| 842 | global.loglev2 = level; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 843 | global.minlvl2 = minlvl; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 844 | } |
| 845 | else { |
| 846 | Alert("parsing [%s:%d] : too many syslog servers\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 847 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 848 | } |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 849 | } |
| 850 | else if (!strcmp(args[0], "spread-checks")) { /* random time between checks (0-50) */ |
| 851 | if (global.spread_checks != 0) { |
| 852 | Alert("parsing [%s:%d]: spread-checks already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 853 | err_code |= ERR_ALERT; |
| 854 | goto out; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 855 | } |
| 856 | if (*(args[1]) == 0) { |
| 857 | 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] | 858 | err_code |= ERR_ALERT | ERR_FATAL; |
| 859 | goto out; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 860 | } |
| 861 | global.spread_checks = atol(args[1]); |
| 862 | if (global.spread_checks < 0 || global.spread_checks > 50) { |
| 863 | 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] | 864 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 865 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 866 | } |
| 867 | else { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 868 | struct cfg_kw_list *kwl; |
| 869 | int index; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 870 | int rc; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 871 | |
| 872 | list_for_each_entry(kwl, &cfg_keywords.list, list) { |
| 873 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 874 | if (kwl->kw[index].section != CFG_GLOBAL) |
| 875 | continue; |
| 876 | if (strcmp(kwl->kw[index].kw, args[0]) == 0) { |
| 877 | /* prepare error message just in case */ |
| 878 | snprintf(trash, sizeof(trash), |
| 879 | "error near '%s' in '%s' section", args[0], "global"); |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 880 | rc = kwl->kw[index].parse(args, CFG_GLOBAL, NULL, NULL, trash, sizeof(trash)); |
| 881 | if (rc < 0) { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 882 | Alert("parsing [%s:%d] : %s\n", file, linenum, trash); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 883 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 884 | } |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 885 | else if (rc > 0) { |
| 886 | Warning("parsing [%s:%d] : %s\n", file, linenum, trash); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 887 | err_code |= ERR_WARN; |
| 888 | goto out; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 889 | } |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 890 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 891 | } |
| 892 | } |
| 893 | } |
| 894 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 895 | 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] | 896 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 897 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 898 | |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 899 | out: |
| 900 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 901 | } |
| 902 | |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 903 | /* Perform the most basic initialization of a proxy : |
| 904 | * memset(), list_init(*), reset_timeouts(*). |
| 905 | */ |
| 906 | static void init_new_proxy(struct proxy *p) |
| 907 | { |
| 908 | memset(p, 0, sizeof(struct proxy)); |
| 909 | LIST_INIT(&p->pendconns); |
| 910 | LIST_INIT(&p->acl); |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 911 | LIST_INIT(&p->req_acl); |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 912 | LIST_INIT(&p->block_cond); |
| 913 | LIST_INIT(&p->redirect_rules); |
| 914 | LIST_INIT(&p->mon_fail_cond); |
| 915 | LIST_INIT(&p->switching_rules); |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 916 | LIST_INIT(&p->persist_rules); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 917 | LIST_INIT(&p->sticking_rules); |
| 918 | LIST_INIT(&p->storersp_rules); |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 919 | LIST_INIT(&p->tcp_req.inspect_rules); |
Willy Tarreau | ab78619 | 2010-05-23 22:39:25 +0200 | [diff] [blame] | 920 | LIST_INIT(&p->tcp_req.l4_rules); |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 921 | LIST_INIT(&p->req_add); |
| 922 | LIST_INIT(&p->rsp_add); |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 923 | |
| 924 | /* Timeouts are defined as -1 */ |
| 925 | proxy_reset_timeouts(p); |
| 926 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 927 | |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 928 | void init_default_instance() |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 929 | { |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 930 | init_new_proxy(&defproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 931 | defproxy.mode = PR_MODE_TCP; |
| 932 | defproxy.state = PR_STNEW; |
| 933 | defproxy.maxconn = cfg_maxpconn; |
| 934 | defproxy.conn_retries = CONN_RETRIES; |
| 935 | defproxy.logfac1 = defproxy.logfac2 = -1; /* log disabled */ |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 936 | |
| 937 | defproxy.defsrv.inter = DEF_CHKINTR; |
| 938 | defproxy.defsrv.fastinter = 0; |
| 939 | defproxy.defsrv.downinter = 0; |
| 940 | defproxy.defsrv.rise = DEF_RISETIME; |
| 941 | defproxy.defsrv.fall = DEF_FALLTIME; |
| 942 | defproxy.defsrv.check_port = 0; |
| 943 | defproxy.defsrv.maxqueue = 0; |
| 944 | defproxy.defsrv.minconn = 0; |
| 945 | defproxy.defsrv.maxconn = 0; |
| 946 | defproxy.defsrv.slowstart = 0; |
| 947 | defproxy.defsrv.onerror = DEF_HANA_ONERR; |
| 948 | defproxy.defsrv.consecutive_errors_limit = DEF_HANA_ERRLIMIT; |
| 949 | defproxy.defsrv.uweight = defproxy.defsrv.iweight = 1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 950 | } |
| 951 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 952 | |
| 953 | static int create_cond_regex_rule(const char *file, int line, |
| 954 | struct proxy *px, int dir, int action, int flags, |
| 955 | const char *cmd, const char *reg, const char *repl, |
| 956 | const char **cond_start) |
| 957 | { |
| 958 | regex_t *preg = NULL; |
| 959 | const char *err; |
| 960 | int err_code = 0; |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 961 | struct acl_cond *cond = NULL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 962 | |
| 963 | if (px == &defproxy) { |
| 964 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, line, cmd); |
| 965 | err_code |= ERR_ALERT | ERR_FATAL; |
| 966 | goto err; |
| 967 | } |
| 968 | |
| 969 | if (*reg == 0) { |
| 970 | Alert("parsing [%s:%d] : '%s' expects <regex> as an argument.\n", file, line, cmd); |
| 971 | err_code |= ERR_ALERT | ERR_FATAL; |
| 972 | goto err; |
| 973 | } |
| 974 | |
| 975 | if (warnifnotcap(px, PR_CAP_RS, file, line, cmd, NULL)) |
| 976 | err_code |= ERR_WARN; |
| 977 | |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 978 | if (cond_start && |
| 979 | (strcmp(*cond_start, "if") == 0 || strcmp(*cond_start, "unless") == 0)) { |
| 980 | if ((cond = build_acl_cond(file, line, px, cond_start)) == NULL) { |
| 981 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition.\n", |
| 982 | file, line, cmd); |
| 983 | err_code |= ERR_ALERT | ERR_FATAL; |
| 984 | goto err; |
| 985 | } |
| 986 | } |
| 987 | else if (cond_start && **cond_start) { |
| 988 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 989 | file, line, cmd, *cond_start); |
| 990 | err_code |= ERR_ALERT | ERR_FATAL; |
| 991 | goto err; |
| 992 | } |
| 993 | |
| 994 | if (dir == ACL_DIR_REQ) |
| 995 | err_code |= warnif_cond_requires_resp(cond, file, line); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 996 | else |
| 997 | err_code |= warnif_cond_requires_req(cond, file, line); |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 998 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 999 | preg = calloc(1, sizeof(regex_t)); |
| 1000 | if (!preg) { |
| 1001 | Alert("parsing [%s:%d] : '%s' : not enough memory to build regex.\n", file, line, cmd); |
| 1002 | err_code = ERR_ALERT | ERR_FATAL; |
| 1003 | goto err; |
| 1004 | } |
| 1005 | |
| 1006 | if (regcomp(preg, reg, REG_EXTENDED | flags) != 0) { |
| 1007 | Alert("parsing [%s:%d] : '%s' : bad regular expression '%s'.\n", file, line, cmd, reg); |
| 1008 | err_code = ERR_ALERT | ERR_FATAL; |
| 1009 | goto err; |
| 1010 | } |
| 1011 | |
| 1012 | 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] | 1013 | preg, action, repl ? strdup(repl) : NULL, cond); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1014 | if (repl && err) { |
| 1015 | Alert("parsing [%s:%d] : '%s' : invalid character or unterminated sequence in replacement string near '%c'.\n", |
| 1016 | file, line, cmd, *err); |
| 1017 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1018 | goto err; |
| 1019 | } |
| 1020 | |
| 1021 | if (dir == ACL_DIR_REQ && warnif_misplaced_reqxxx(px, file, line, cmd)) |
| 1022 | err_code |= ERR_WARN; |
| 1023 | |
| 1024 | return err_code; |
| 1025 | err: |
| 1026 | free(preg); |
| 1027 | return err_code; |
| 1028 | } |
| 1029 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1030 | /* |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1031 | * Parse a line in a <listen>, <frontend>, <backend> or <ruleset> section. |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1032 | * Returns the error code, 0 if OK, or any combination of : |
| 1033 | * - ERR_ABORT: must abort ASAP |
| 1034 | * - ERR_FATAL: we can continue parsing but not start the service |
| 1035 | * - ERR_WARN: a warning has been emitted |
| 1036 | * - ERR_ALERT: an alert has been emitted |
| 1037 | * Only the two first ones can stop processing, the two others are just |
| 1038 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1039 | */ |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 1040 | 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] | 1041 | { |
| 1042 | static struct proxy *curproxy = NULL; |
| 1043 | struct server *newsrv = NULL; |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 1044 | const char *err; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 1045 | int rc; |
| 1046 | unsigned val; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1047 | int err_code = 0; |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 1048 | struct acl_cond *cond = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1049 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1050 | if (!strcmp(args[0], "listen")) |
| 1051 | rc = PR_CAP_LISTEN; |
| 1052 | else if (!strcmp(args[0], "frontend")) |
| 1053 | rc = PR_CAP_FE | PR_CAP_RS; |
| 1054 | else if (!strcmp(args[0], "backend")) |
| 1055 | rc = PR_CAP_BE | PR_CAP_RS; |
| 1056 | else if (!strcmp(args[0], "ruleset")) |
| 1057 | rc = PR_CAP_RS; |
| 1058 | else |
| 1059 | rc = PR_CAP_NONE; |
| 1060 | |
| 1061 | if (rc != PR_CAP_NONE) { /* new proxy */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1062 | if (!*args[1]) { |
| 1063 | Alert("parsing [%s:%d] : '%s' expects an <id> argument and\n" |
| 1064 | " optionnally supports [addr1]:port1[-end1]{,[addr]:port[-end]}...\n", |
| 1065 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1066 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1067 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1068 | } |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 1069 | |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 1070 | err = invalid_char(args[1]); |
| 1071 | if (err) { |
| 1072 | Alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 1073 | file, linenum, *err, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1074 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 1075 | } |
| 1076 | |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 1077 | for (curproxy = proxy; curproxy != NULL; curproxy = curproxy->next) { |
| 1078 | /* |
| 1079 | * If there are two proxies with the same name only following |
| 1080 | * combinations are allowed: |
| 1081 | * |
| 1082 | * listen backend frontend ruleset |
| 1083 | * listen - - - - |
| 1084 | * backend - - OK - |
| 1085 | * frontend - OK - - |
| 1086 | * ruleset - - - - |
| 1087 | */ |
| 1088 | |
| 1089 | if (!strcmp(curproxy->id, args[1]) && |
| 1090 | (rc!=(PR_CAP_FE|PR_CAP_RS) || curproxy->cap!=(PR_CAP_BE|PR_CAP_RS)) && |
| 1091 | (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] | 1092 | Warning("Parsing [%s:%d]: %s '%s' has same name as another %s (declared at %s:%d).\n", |
| 1093 | file, linenum, proxy_cap_str(rc), args[1], proxy_type_str(curproxy), |
| 1094 | curproxy->conf.file, curproxy->conf.line); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1095 | err_code |= ERR_WARN; |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 1096 | } |
| 1097 | } |
| 1098 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1099 | if ((curproxy = (struct proxy *)calloc(1, sizeof(struct proxy))) == NULL) { |
| 1100 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1101 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1102 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1103 | } |
Willy Tarreau | 5af24ef | 2009-03-15 15:23:16 +0100 | [diff] [blame] | 1104 | |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 1105 | init_new_proxy(curproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1106 | curproxy->next = proxy; |
| 1107 | proxy = curproxy; |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 1108 | curproxy->conf.file = file; |
| 1109 | curproxy->conf.line = linenum; |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 1110 | curproxy->last_change = now.tv_sec; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1111 | curproxy->id = strdup(args[1]); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1112 | curproxy->cap = rc; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1113 | |
| 1114 | /* parse the listener address if any */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1115 | if ((curproxy->cap & PR_CAP_FE) && *args[2]) { |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 1116 | struct listener *new, *last = curproxy->listen; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1117 | if (!str2listener(args[2], curproxy)) { |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1118 | err_code |= ERR_FATAL; |
| 1119 | goto out; |
| 1120 | } |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 1121 | new = curproxy->listen; |
| 1122 | while (new != last) { |
| 1123 | new->conf.file = file; |
| 1124 | new->conf.line = linenum; |
| 1125 | new = new->next; |
| 1126 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1127 | global.maxsock++; |
| 1128 | } |
| 1129 | |
| 1130 | /* set default values */ |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1131 | memcpy(&curproxy->defsrv, &defproxy.defsrv, sizeof(curproxy->defsrv)); |
Willy Tarreau | 7016020 | 2010-04-07 16:06:40 +0200 | [diff] [blame] | 1132 | curproxy->defsrv.id = "default-server"; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1133 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1134 | curproxy->state = defproxy.state; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1135 | curproxy->options = defproxy.options; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 1136 | curproxy->options2 = defproxy.options2; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 1137 | curproxy->no_options = defproxy.no_options; |
| 1138 | curproxy->no_options2 = defproxy.no_options2; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 1139 | curproxy->bind_proc = defproxy.bind_proc; |
Willy Tarreau | 3168223 | 2007-11-29 15:38:04 +0100 | [diff] [blame] | 1140 | curproxy->lbprm.algo = defproxy.lbprm.algo; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 1141 | curproxy->except_net = defproxy.except_net; |
| 1142 | curproxy->except_mask = defproxy.except_mask; |
Maik Broemme | 36db02e | 2009-05-08 17:02:07 +0200 | [diff] [blame] | 1143 | curproxy->except_to = defproxy.except_to; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 1144 | curproxy->except_mask_to = defproxy.except_mask_to; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1145 | |
Willy Tarreau | 79f5fe8 | 2008-08-23 08:18:21 +0200 | [diff] [blame] | 1146 | if (defproxy.fwdfor_hdr_len) { |
| 1147 | curproxy->fwdfor_hdr_len = defproxy.fwdfor_hdr_len; |
| 1148 | curproxy->fwdfor_hdr_name = strdup(defproxy.fwdfor_hdr_name); |
| 1149 | } |
| 1150 | |
Willy Tarreau | b86db34 | 2009-11-30 11:50:16 +0100 | [diff] [blame] | 1151 | if (defproxy.orgto_hdr_len) { |
| 1152 | curproxy->orgto_hdr_len = defproxy.orgto_hdr_len; |
| 1153 | curproxy->orgto_hdr_name = strdup(defproxy.orgto_hdr_name); |
| 1154 | } |
| 1155 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1156 | if (curproxy->cap & PR_CAP_FE) { |
| 1157 | curproxy->maxconn = defproxy.maxconn; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 1158 | curproxy->backlog = defproxy.backlog; |
Willy Tarreau | 13a34bd | 2009-05-10 18:52:49 +0200 | [diff] [blame] | 1159 | curproxy->fe_sps_lim = defproxy.fe_sps_lim; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1160 | |
| 1161 | /* initialize error relocations */ |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1162 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) |
| 1163 | chunk_dup(&curproxy->errmsg[rc], &defproxy.errmsg[rc]); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1164 | |
| 1165 | curproxy->to_log = defproxy.to_log & ~LW_COOKIE & ~LW_REQHDR & ~ LW_RSPHDR; |
| 1166 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1167 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1168 | if (curproxy->cap & PR_CAP_BE) { |
| 1169 | curproxy->fullconn = defproxy.fullconn; |
| 1170 | curproxy->conn_retries = defproxy.conn_retries; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1171 | |
Willy Tarreau | aa2f389 | 2010-10-22 16:15:31 +0200 | [diff] [blame] | 1172 | if (defproxy.check_req) { |
| 1173 | curproxy->check_req = calloc(1, defproxy.check_len); |
| 1174 | memcpy(curproxy->check_req, defproxy.check_req, defproxy.check_len); |
| 1175 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1176 | curproxy->check_len = defproxy.check_len; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1177 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1178 | if (defproxy.cookie_name) |
| 1179 | curproxy->cookie_name = strdup(defproxy.cookie_name); |
| 1180 | curproxy->cookie_len = defproxy.cookie_len; |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 1181 | if (defproxy.cookie_domain) |
| 1182 | curproxy->cookie_domain = strdup(defproxy.cookie_domain); |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 1183 | |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 1184 | if (defproxy.cookie_maxidle) |
| 1185 | curproxy->cookie_maxidle = defproxy.cookie_maxidle; |
| 1186 | |
| 1187 | if (defproxy.cookie_maxlife) |
| 1188 | curproxy->cookie_maxlife = defproxy.cookie_maxlife; |
| 1189 | |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 1190 | if (defproxy.rdp_cookie_name) |
| 1191 | curproxy->rdp_cookie_name = strdup(defproxy.rdp_cookie_name); |
| 1192 | curproxy->rdp_cookie_len = defproxy.rdp_cookie_len; |
| 1193 | |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 1194 | if (defproxy.url_param_name) |
| 1195 | curproxy->url_param_name = strdup(defproxy.url_param_name); |
| 1196 | curproxy->url_param_len = defproxy.url_param_len; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 1197 | |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 1198 | if (defproxy.hh_name) |
| 1199 | curproxy->hh_name = strdup(defproxy.hh_name); |
| 1200 | curproxy->hh_len = defproxy.hh_len; |
| 1201 | curproxy->hh_match_domain = defproxy.hh_match_domain; |
| 1202 | |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 1203 | if (defproxy.iface_name) |
| 1204 | curproxy->iface_name = strdup(defproxy.iface_name); |
| 1205 | curproxy->iface_len = defproxy.iface_len; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1206 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1207 | |
Willy Tarreau | 3b6b1a9 | 2009-07-23 13:24:23 +0200 | [diff] [blame] | 1208 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1209 | if (defproxy.capture_name) |
| 1210 | curproxy->capture_name = strdup(defproxy.capture_name); |
| 1211 | curproxy->capture_namelen = defproxy.capture_namelen; |
| 1212 | curproxy->capture_len = defproxy.capture_len; |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 1213 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1214 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1215 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 1216 | curproxy->timeout.client = defproxy.timeout.client; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 1217 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | 036fae0 | 2008-01-06 13:24:40 +0100 | [diff] [blame] | 1218 | curproxy->timeout.httpreq = defproxy.timeout.httpreq; |
Willy Tarreau | b16a574 | 2010-01-10 14:46:16 +0100 | [diff] [blame] | 1219 | curproxy->timeout.httpka = defproxy.timeout.httpka; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1220 | curproxy->uri_auth = defproxy.uri_auth; |
| 1221 | curproxy->mon_net = defproxy.mon_net; |
| 1222 | curproxy->mon_mask = defproxy.mon_mask; |
| 1223 | if (defproxy.monitor_uri) |
| 1224 | curproxy->monitor_uri = strdup(defproxy.monitor_uri); |
| 1225 | curproxy->monitor_uri_len = defproxy.monitor_uri_len; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 1226 | if (defproxy.defbe.name) |
| 1227 | curproxy->defbe.name = strdup(defproxy.defbe.name); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1228 | } |
| 1229 | |
| 1230 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 1231 | curproxy->timeout.connect = defproxy.timeout.connect; |
| 1232 | curproxy->timeout.server = defproxy.timeout.server; |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 1233 | curproxy->timeout.check = defproxy.timeout.check; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 1234 | curproxy->timeout.queue = defproxy.timeout.queue; |
Willy Tarreau | 51c9bde | 2008-01-06 13:40:03 +0100 | [diff] [blame] | 1235 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | cd7afc0 | 2009-07-12 10:03:17 +0200 | [diff] [blame] | 1236 | curproxy->timeout.httpreq = defproxy.timeout.httpreq; |
Willy Tarreau | b16a574 | 2010-01-10 14:46:16 +0100 | [diff] [blame] | 1237 | curproxy->timeout.httpka = defproxy.timeout.httpka; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1238 | curproxy->source_addr = defproxy.source_addr; |
| 1239 | } |
| 1240 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1241 | curproxy->mode = defproxy.mode; |
| 1242 | curproxy->logfac1 = defproxy.logfac1; |
| 1243 | curproxy->logsrv1 = defproxy.logsrv1; |
| 1244 | curproxy->loglev1 = defproxy.loglev1; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 1245 | curproxy->minlvl1 = defproxy.minlvl1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1246 | curproxy->logfac2 = defproxy.logfac2; |
| 1247 | curproxy->logsrv2 = defproxy.logsrv2; |
| 1248 | curproxy->loglev2 = defproxy.loglev2; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 1249 | curproxy->minlvl2 = defproxy.minlvl2; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1250 | curproxy->grace = defproxy.grace; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1251 | curproxy->conf.used_listener_id = EB_ROOT; |
| 1252 | curproxy->conf.used_server_id = EB_ROOT; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 1253 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1254 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1255 | } |
| 1256 | else if (!strcmp(args[0], "defaults")) { /* use this one to assign default values */ |
| 1257 | /* some variables may have already been initialized earlier */ |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 1258 | /* FIXME-20070101: we should do this too at the end of the |
| 1259 | * config parsing to free all default values. |
| 1260 | */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1261 | free(defproxy.check_req); |
| 1262 | free(defproxy.cookie_name); |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 1263 | free(defproxy.rdp_cookie_name); |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 1264 | free(defproxy.cookie_domain); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1265 | free(defproxy.url_param_name); |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 1266 | free(defproxy.hh_name); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1267 | free(defproxy.capture_name); |
| 1268 | free(defproxy.monitor_uri); |
| 1269 | free(defproxy.defbe.name); |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 1270 | free(defproxy.iface_name); |
Willy Tarreau | 79f5fe8 | 2008-08-23 08:18:21 +0200 | [diff] [blame] | 1271 | free(defproxy.fwdfor_hdr_name); |
| 1272 | defproxy.fwdfor_hdr_len = 0; |
Willy Tarreau | b86db34 | 2009-11-30 11:50:16 +0100 | [diff] [blame] | 1273 | free(defproxy.orgto_hdr_name); |
| 1274 | defproxy.orgto_hdr_len = 0; |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 1275 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1276 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1277 | chunk_destroy(&defproxy.errmsg[rc]); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 1278 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1279 | /* we cannot free uri_auth because it might already be used */ |
| 1280 | init_default_instance(); |
| 1281 | curproxy = &defproxy; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1282 | defproxy.cap = PR_CAP_LISTEN; /* all caps for now */ |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1283 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1284 | } |
| 1285 | else if (curproxy == NULL) { |
| 1286 | Alert("parsing [%s:%d] : 'listen' or 'defaults' expected.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1287 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1288 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1289 | } |
| 1290 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1291 | |
| 1292 | /* Now let's parse the proxy-specific keywords */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1293 | if (!strcmp(args[0], "bind")) { /* new listen addresses */ |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 1294 | struct listener *new_listen, *last_listen; |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1295 | int cur_arg; |
| 1296 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1297 | if (curproxy == &defproxy) { |
| 1298 | 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] | 1299 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1300 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1301 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1302 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1303 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1304 | |
| 1305 | if (strchr(args[1], ':') == NULL) { |
| 1306 | Alert("parsing [%s:%d] : '%s' expects [addr1]:port1[-end1]{,[addr]:port[-end]}... as arguments.\n", |
| 1307 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1308 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1309 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1310 | } |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 1311 | |
| 1312 | last_listen = curproxy->listen; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1313 | if (!str2listener(args[1], curproxy)) { |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1314 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1315 | goto out; |
| 1316 | } |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1317 | |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 1318 | new_listen = curproxy->listen; |
| 1319 | while (new_listen != last_listen) { |
| 1320 | new_listen->conf.file = file; |
| 1321 | new_listen->conf.line = linenum; |
| 1322 | new_listen = new_listen->next; |
| 1323 | } |
| 1324 | |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1325 | cur_arg = 2; |
| 1326 | while (*(args[cur_arg])) { |
| 1327 | if (!strcmp(args[cur_arg], "interface")) { /* specifically bind to this interface */ |
| 1328 | #ifdef SO_BINDTODEVICE |
| 1329 | struct listener *l; |
| 1330 | |
| 1331 | if (!*args[cur_arg + 1]) { |
| 1332 | Alert("parsing [%s:%d] : '%s' : missing interface name.\n", |
| 1333 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1334 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1335 | goto out; |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1336 | } |
| 1337 | |
| 1338 | for (l = curproxy->listen; l != last_listen; l = l->next) |
| 1339 | l->interface = strdup(args[cur_arg + 1]); |
| 1340 | |
| 1341 | global.last_checks |= LSTCHK_NETADM; |
| 1342 | |
| 1343 | cur_arg += 2; |
| 1344 | continue; |
| 1345 | #else |
| 1346 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 1347 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1348 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1349 | goto out; |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1350 | #endif |
| 1351 | } |
Willy Tarreau | be1b918 | 2009-06-14 18:48:19 +0200 | [diff] [blame] | 1352 | if (!strcmp(args[cur_arg], "mss")) { /* set MSS of listening socket */ |
| 1353 | #ifdef TCP_MAXSEG |
| 1354 | struct listener *l; |
| 1355 | int mss; |
| 1356 | |
| 1357 | if (!*args[cur_arg + 1]) { |
| 1358 | Alert("parsing [%s:%d] : '%s' : missing MSS value.\n", |
| 1359 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1360 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1361 | goto out; |
Willy Tarreau | be1b918 | 2009-06-14 18:48:19 +0200 | [diff] [blame] | 1362 | } |
| 1363 | |
| 1364 | mss = str2uic(args[cur_arg + 1]); |
| 1365 | if (mss < 1 || mss > 65535) { |
| 1366 | Alert("parsing [%s:%d]: %s expects an MSS value between 1 and 65535.\n", |
| 1367 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1368 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1369 | goto out; |
Willy Tarreau | be1b918 | 2009-06-14 18:48:19 +0200 | [diff] [blame] | 1370 | } |
| 1371 | |
| 1372 | for (l = curproxy->listen; l != last_listen; l = l->next) |
| 1373 | l->maxseg = mss; |
| 1374 | |
| 1375 | cur_arg += 2; |
| 1376 | continue; |
| 1377 | #else |
| 1378 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 1379 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1380 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1381 | goto out; |
Willy Tarreau | be1b918 | 2009-06-14 18:48:19 +0200 | [diff] [blame] | 1382 | #endif |
| 1383 | } |
Willy Tarreau | cb6cd43 | 2009-10-13 07:34:14 +0200 | [diff] [blame] | 1384 | |
| 1385 | if (!strcmp(args[cur_arg], "defer-accept")) { /* wait for some data for 1 second max before doing accept */ |
| 1386 | #ifdef TCP_DEFER_ACCEPT |
| 1387 | struct listener *l; |
| 1388 | |
| 1389 | for (l = curproxy->listen; l != last_listen; l = l->next) |
| 1390 | l->options |= LI_O_DEF_ACCEPT; |
| 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]); |
| 1397 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1398 | goto out; |
| 1399 | #endif |
| 1400 | } |
| 1401 | |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1402 | if (!strcmp(args[cur_arg], "transparent")) { /* transparently bind to these addresses */ |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 1403 | #ifdef CONFIG_HAP_LINUX_TPROXY |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 1404 | struct listener *l; |
| 1405 | |
| 1406 | for (l = curproxy->listen; l != last_listen; l = l->next) |
| 1407 | l->options |= LI_O_FOREIGN; |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1408 | |
| 1409 | cur_arg ++; |
| 1410 | continue; |
| 1411 | #else |
| 1412 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 1413 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1414 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1415 | goto out; |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1416 | #endif |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 1417 | } |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1418 | |
| 1419 | if (!strcmp(args[cur_arg], "name")) { |
| 1420 | struct listener *l; |
| 1421 | |
| 1422 | for (l = curproxy->listen; l != last_listen; l = l->next) |
| 1423 | l->name = strdup(args[cur_arg + 1]); |
| 1424 | |
| 1425 | cur_arg += 2; |
| 1426 | continue; |
| 1427 | } |
| 1428 | |
| 1429 | if (!strcmp(args[cur_arg], "id")) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1430 | struct eb32_node *node; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1431 | struct listener *l; |
| 1432 | |
| 1433 | if (curproxy->listen->next != last_listen) { |
| 1434 | Alert("parsing [%s:%d]: '%s' can be only used with a single socket.\n", |
| 1435 | file, linenum, args[cur_arg]); |
| 1436 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1437 | goto out; |
| 1438 | } |
| 1439 | |
| 1440 | if (!*args[cur_arg + 1]) { |
| 1441 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 1442 | file, linenum, args[cur_arg]); |
| 1443 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1444 | goto out; |
| 1445 | } |
| 1446 | |
| 1447 | curproxy->listen->luid = atol(args[cur_arg + 1]); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1448 | curproxy->listen->conf.id.key = curproxy->listen->luid; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1449 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1450 | if (curproxy->listen->luid <= 0) { |
| 1451 | Alert("parsing [%s:%d]: custom id has to be > 0\n", |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1452 | file, linenum); |
| 1453 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1454 | goto out; |
| 1455 | } |
| 1456 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1457 | node = eb32_lookup(&curproxy->conf.used_listener_id, curproxy->listen->luid); |
| 1458 | if (node) { |
| 1459 | l = container_of(node, struct listener, conf.id); |
| 1460 | Alert("parsing [%s:%d]: custom id %d for socket '%s' already used at %s:%d.\n", |
| 1461 | file, linenum, l->luid, args[1], l->conf.file, l->conf.line); |
| 1462 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1463 | goto out; |
| 1464 | } |
| 1465 | eb32_insert(&curproxy->conf.used_listener_id, &curproxy->listen->conf.id); |
| 1466 | |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1467 | cur_arg += 2; |
| 1468 | continue; |
| 1469 | } |
| 1470 | |
Willy Tarreau | cb6cd43 | 2009-10-13 07:34:14 +0200 | [diff] [blame] | 1471 | 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] | 1472 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1473 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1474 | goto out; |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 1475 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1476 | global.maxsock++; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1477 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1478 | } |
| 1479 | else if (!strcmp(args[0], "monitor-net")) { /* set the range of IPs to ignore */ |
| 1480 | if (!*args[1] || !str2net(args[1], &curproxy->mon_net, &curproxy->mon_mask)) { |
| 1481 | Alert("parsing [%s:%d] : '%s' expects address[/mask].\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 | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1485 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1486 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1487 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1488 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1489 | /* flush useless bits */ |
| 1490 | curproxy->mon_net.s_addr &= curproxy->mon_mask.s_addr; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1491 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1492 | } |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 1493 | else if (!strcmp(args[0], "monitor-uri")) { /* set the URI to intercept */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1494 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1495 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1496 | |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 1497 | if (!*args[1]) { |
| 1498 | Alert("parsing [%s:%d] : '%s' expects an URI.\n", |
| 1499 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1500 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1501 | goto out; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 1502 | } |
| 1503 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1504 | free(curproxy->monitor_uri); |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 1505 | curproxy->monitor_uri_len = strlen(args[1]); |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 1506 | curproxy->monitor_uri = (char *)calloc(1, curproxy->monitor_uri_len + 1); |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 1507 | memcpy(curproxy->monitor_uri, args[1], curproxy->monitor_uri_len); |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 1508 | curproxy->monitor_uri[curproxy->monitor_uri_len] = '\0'; |
| 1509 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1510 | goto out; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 1511 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1512 | else if (!strcmp(args[0], "mode")) { /* sets the proxy mode */ |
| 1513 | if (!strcmp(args[1], "http")) curproxy->mode = PR_MODE_HTTP; |
| 1514 | else if (!strcmp(args[1], "tcp")) curproxy->mode = PR_MODE_TCP; |
| 1515 | else if (!strcmp(args[1], "health")) curproxy->mode = PR_MODE_HEALTH; |
| 1516 | else { |
| 1517 | 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] | 1518 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1519 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1520 | } |
| 1521 | } |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 1522 | else if (!strcmp(args[0], "id")) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1523 | struct eb32_node *node; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 1524 | |
| 1525 | if (curproxy == &defproxy) { |
| 1526 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", |
| 1527 | file, linenum, args[0]); |
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 | |
| 1532 | if (!*args[1]) { |
| 1533 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 1534 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1535 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1536 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 1537 | } |
| 1538 | |
| 1539 | curproxy->uuid = atol(args[1]); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1540 | curproxy->conf.id.key = curproxy->uuid; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 1541 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1542 | if (curproxy->uuid <= 0) { |
| 1543 | Alert("parsing [%s:%d]: custom id has to be > 0.\n", |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 1544 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1545 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1546 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 1547 | } |
| 1548 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1549 | node = eb32_lookup(&used_proxy_id, curproxy->uuid); |
| 1550 | if (node) { |
| 1551 | struct proxy *target = container_of(node, struct proxy, conf.id); |
| 1552 | Alert("parsing [%s:%d]: %s %s reuses same custom id as %s %s (declared at %s:%d).\n", |
| 1553 | file, linenum, proxy_type_str(curproxy), curproxy->id, |
| 1554 | proxy_type_str(target), target->id, target->conf.file, target->conf.line); |
| 1555 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1556 | goto out; |
| 1557 | } |
| 1558 | eb32_insert(&used_proxy_id, &curproxy->conf.id); |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 1559 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1560 | else if (!strcmp(args[0], "description")) { |
| 1561 | int i, len=0; |
| 1562 | char *d; |
| 1563 | |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 1564 | if (curproxy == &defproxy) { |
| 1565 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", |
| 1566 | file, linenum, args[0]); |
| 1567 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1568 | goto out; |
| 1569 | } |
| 1570 | |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1571 | if (!*args[1]) { |
| 1572 | Alert("parsing [%s:%d]: '%s' expects a string argument.\n", |
| 1573 | file, linenum, args[0]); |
| 1574 | return -1; |
| 1575 | } |
| 1576 | |
| 1577 | for(i=1; *args[i]; i++) |
| 1578 | len += strlen(args[i])+1; |
| 1579 | |
| 1580 | d = (char *)calloc(1, len); |
| 1581 | curproxy->desc = d; |
| 1582 | |
| 1583 | d += sprintf(d, "%s", args[1]); |
| 1584 | for(i=2; *args[i]; i++) |
| 1585 | d += sprintf(d, " %s", args[i]); |
| 1586 | |
| 1587 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1588 | else if (!strcmp(args[0], "disabled")) { /* disables this proxy */ |
| 1589 | curproxy->state = PR_STSTOPPED; |
| 1590 | } |
| 1591 | else if (!strcmp(args[0], "enabled")) { /* enables this proxy (used to revert a disabled default) */ |
| 1592 | curproxy->state = PR_STNEW; |
| 1593 | } |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 1594 | else if (!strcmp(args[0], "bind-process")) { /* enable this proxy only on some processes */ |
| 1595 | int cur_arg = 1; |
| 1596 | unsigned int set = 0; |
| 1597 | |
| 1598 | while (*args[cur_arg]) { |
| 1599 | int u; |
| 1600 | if (strcmp(args[cur_arg], "all") == 0) { |
| 1601 | set = 0; |
| 1602 | break; |
| 1603 | } |
| 1604 | else if (strcmp(args[cur_arg], "odd") == 0) { |
| 1605 | set |= 0x55555555; |
| 1606 | } |
| 1607 | else if (strcmp(args[cur_arg], "even") == 0) { |
| 1608 | set |= 0xAAAAAAAA; |
| 1609 | } |
| 1610 | else { |
| 1611 | u = str2uic(args[cur_arg]); |
| 1612 | if (u < 1 || u > 32) { |
| 1613 | Alert("parsing [%s:%d]: %s expects 'all', 'odd', 'even', or process numbers from 1 to 32.\n", |
| 1614 | 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 | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 1617 | } |
| 1618 | if (u > global.nbproc) { |
| 1619 | Warning("parsing [%s:%d]: %s references process number higher than global.nbproc.\n", |
| 1620 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1621 | err_code |= ERR_WARN; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 1622 | } |
| 1623 | set |= 1 << (u - 1); |
| 1624 | } |
| 1625 | cur_arg++; |
| 1626 | } |
| 1627 | curproxy->bind_proc = set; |
| 1628 | } |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 1629 | else if (!strcmp(args[0], "acl")) { /* add an ACL */ |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 1630 | if (curproxy == &defproxy) { |
| 1631 | 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] | 1632 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1633 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 1634 | } |
| 1635 | |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 1636 | err = invalid_char(args[1]); |
| 1637 | if (err) { |
| 1638 | Alert("parsing [%s:%d] : character '%c' is not permitted in acl name '%s'.\n", |
| 1639 | file, linenum, *err, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1640 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 1641 | } |
| 1642 | |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 1643 | if (parse_acl((const char **)args + 1, &curproxy->acl) == NULL) { |
| 1644 | Alert("parsing [%s:%d] : error detected while parsing ACL '%s'.\n", |
| 1645 | file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1646 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1647 | goto out; |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 1648 | } |
| 1649 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1650 | else if (!strcmp(args[0], "cookie")) { /* cookie name */ |
| 1651 | int cur_arg; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1652 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1653 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1654 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1655 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1656 | if (*(args[1]) == 0) { |
| 1657 | Alert("parsing [%s:%d] : '%s' expects <cookie_name> as argument.\n", |
| 1658 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1659 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1660 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1661 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1662 | |
Willy Tarreau | c63d4bb | 2010-10-23 11:37:27 +0200 | [diff] [blame] | 1663 | curproxy->options &= ~PR_O_COOK_ANY; |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 1664 | curproxy->options2 &= ~PR_O2_COOK_PSV; |
Willy Tarreau | c63d4bb | 2010-10-23 11:37:27 +0200 | [diff] [blame] | 1665 | curproxy->cookie_maxidle = curproxy->cookie_maxlife = 0; |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 1666 | free(curproxy->cookie_domain); curproxy->cookie_domain = NULL; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1667 | free(curproxy->cookie_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1668 | curproxy->cookie_name = strdup(args[1]); |
| 1669 | curproxy->cookie_len = strlen(curproxy->cookie_name); |
Willy Tarreau | c63d4bb | 2010-10-23 11:37:27 +0200 | [diff] [blame] | 1670 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1671 | cur_arg = 2; |
| 1672 | while (*(args[cur_arg])) { |
| 1673 | if (!strcmp(args[cur_arg], "rewrite")) { |
| 1674 | curproxy->options |= PR_O_COOK_RW; |
| 1675 | } |
| 1676 | else if (!strcmp(args[cur_arg], "indirect")) { |
| 1677 | curproxy->options |= PR_O_COOK_IND; |
| 1678 | } |
| 1679 | else if (!strcmp(args[cur_arg], "insert")) { |
| 1680 | curproxy->options |= PR_O_COOK_INS; |
| 1681 | } |
| 1682 | else if (!strcmp(args[cur_arg], "nocache")) { |
| 1683 | curproxy->options |= PR_O_COOK_NOC; |
| 1684 | } |
| 1685 | else if (!strcmp(args[cur_arg], "postonly")) { |
| 1686 | curproxy->options |= PR_O_COOK_POST; |
| 1687 | } |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 1688 | else if (!strcmp(args[cur_arg], "preserve")) { |
| 1689 | curproxy->options2 |= PR_O2_COOK_PSV; |
| 1690 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1691 | else if (!strcmp(args[cur_arg], "prefix")) { |
| 1692 | curproxy->options |= PR_O_COOK_PFX; |
| 1693 | } |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 1694 | else if (!strcmp(args[cur_arg], "domain")) { |
| 1695 | if (!*args[cur_arg + 1]) { |
| 1696 | Alert("parsing [%s:%d]: '%s' expects <domain> as argument.\n", |
| 1697 | file, linenum, args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1698 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1699 | goto out; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 1700 | } |
| 1701 | |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 1702 | if (*args[cur_arg + 1] != '.' || !strchr(args[cur_arg + 1] + 1, '.')) { |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 1703 | /* rfc2109, 4.3.2 Rejecting Cookies */ |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 1704 | Warning("parsing [%s:%d]: domain '%s' contains no embedded" |
| 1705 | " dots nor does not start with a dot." |
| 1706 | " RFC forbids it, this configuration may not work properly.\n", |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 1707 | file, linenum, args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 1708 | err_code |= ERR_WARN; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 1709 | } |
| 1710 | |
| 1711 | err = invalid_domainchar(args[cur_arg + 1]); |
| 1712 | if (err) { |
| 1713 | Alert("parsing [%s:%d]: character '%c' is not permitted in domain name '%s'.\n", |
| 1714 | file, linenum, *err, args[cur_arg + 1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1715 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1716 | goto out; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 1717 | } |
| 1718 | |
Willy Tarreau | 68a897b | 2009-12-03 23:28:34 +0100 | [diff] [blame] | 1719 | if (!curproxy->cookie_domain) { |
| 1720 | curproxy->cookie_domain = strdup(args[cur_arg + 1]); |
| 1721 | } else { |
| 1722 | /* one domain was already specified, add another one by |
| 1723 | * building the string which will be returned along with |
| 1724 | * the cookie. |
| 1725 | */ |
| 1726 | char *new_ptr; |
| 1727 | int new_len = strlen(curproxy->cookie_domain) + |
| 1728 | strlen("; domain=") + strlen(args[cur_arg + 1]) + 1; |
| 1729 | new_ptr = malloc(new_len); |
| 1730 | snprintf(new_ptr, new_len, "%s; domain=%s", curproxy->cookie_domain, args[cur_arg+1]); |
| 1731 | free(curproxy->cookie_domain); |
| 1732 | curproxy->cookie_domain = new_ptr; |
| 1733 | } |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 1734 | cur_arg++; |
| 1735 | } |
| 1736 | else if (!strcmp(args[cur_arg], "maxidle")) { |
| 1737 | unsigned int maxidle; |
| 1738 | const char *res; |
| 1739 | |
| 1740 | if (!*args[cur_arg + 1]) { |
| 1741 | Alert("parsing [%s:%d]: '%s' expects <idletime> in seconds as argument.\n", |
| 1742 | file, linenum, args[cur_arg]); |
| 1743 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1744 | goto out; |
| 1745 | } |
| 1746 | |
| 1747 | res = parse_time_err(args[cur_arg + 1], &maxidle, TIME_UNIT_S); |
| 1748 | if (res) { |
| 1749 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 1750 | file, linenum, *res, args[cur_arg]); |
| 1751 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1752 | goto out; |
| 1753 | } |
| 1754 | curproxy->cookie_maxidle = maxidle; |
| 1755 | cur_arg++; |
| 1756 | } |
| 1757 | else if (!strcmp(args[cur_arg], "maxlife")) { |
| 1758 | unsigned int maxlife; |
| 1759 | const char *res; |
| 1760 | |
| 1761 | if (!*args[cur_arg + 1]) { |
| 1762 | Alert("parsing [%s:%d]: '%s' expects <lifetime> in seconds as argument.\n", |
| 1763 | file, linenum, args[cur_arg]); |
| 1764 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1765 | goto out; |
| 1766 | } |
| 1767 | |
| 1768 | res = parse_time_err(args[cur_arg + 1], &maxlife, TIME_UNIT_S); |
| 1769 | if (res) { |
| 1770 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 1771 | file, linenum, *res, args[cur_arg]); |
| 1772 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1773 | goto out; |
| 1774 | } |
| 1775 | curproxy->cookie_maxlife = maxlife; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 1776 | cur_arg++; |
| 1777 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1778 | else { |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 1779 | Alert("parsing [%s:%d] : '%s' supports 'rewrite', 'insert', 'prefix', 'indirect', 'nocache', 'postonly', 'domain', 'maxidle, and 'maxlife' options.\n", |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1780 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1781 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1782 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1783 | } |
| 1784 | cur_arg++; |
| 1785 | } |
| 1786 | if (!POWEROF2(curproxy->options & (PR_O_COOK_RW|PR_O_COOK_IND))) { |
| 1787 | Alert("parsing [%s:%d] : cookie 'rewrite' and 'indirect' modes are incompatible.\n", |
| 1788 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1789 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1790 | } |
| 1791 | |
| 1792 | if (!POWEROF2(curproxy->options & (PR_O_COOK_RW|PR_O_COOK_INS|PR_O_COOK_PFX))) { |
| 1793 | Alert("parsing [%s:%d] : cookie 'rewrite', 'insert' and 'prefix' modes are incompatible.\n", |
| 1794 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1795 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1796 | } |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 1797 | |
| 1798 | if ((curproxy->options2 & PR_O2_COOK_PSV) && !(curproxy->options & (PR_O_COOK_INS|PR_O_COOK_IND))) { |
| 1799 | Alert("parsing [%s:%d] : cookie 'preserve' requires at least 'insert' or 'indirect'.\n", |
| 1800 | file, linenum); |
| 1801 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1802 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1803 | }/* end else if (!strcmp(args[0], "cookie")) */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 1804 | else if (!strcmp(args[0], "persist")) { /* persist */ |
| 1805 | if (*(args[1]) == 0) { |
| 1806 | Alert("parsing [%s:%d] : missing persist method.\n", |
| 1807 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1808 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1809 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 1810 | } |
| 1811 | |
| 1812 | if (!strncmp(args[1], "rdp-cookie", 10)) { |
| 1813 | curproxy->options2 |= PR_O2_RDPC_PRST; |
| 1814 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 1815 | if (*(args[1] + 10) == '(') { /* cookie name */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 1816 | const char *beg, *end; |
| 1817 | |
| 1818 | beg = args[1] + 11; |
| 1819 | end = strchr(beg, ')'); |
| 1820 | |
| 1821 | if (!end || end == beg) { |
| 1822 | Alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n", |
| 1823 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1824 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1825 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 1826 | } |
| 1827 | |
| 1828 | free(curproxy->rdp_cookie_name); |
| 1829 | curproxy->rdp_cookie_name = my_strndup(beg, end - beg); |
| 1830 | curproxy->rdp_cookie_len = end-beg; |
| 1831 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 1832 | else if (*(args[1] + 10) == '\0') { /* default cookie name 'msts' */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 1833 | free(curproxy->rdp_cookie_name); |
| 1834 | curproxy->rdp_cookie_name = strdup("msts"); |
| 1835 | curproxy->rdp_cookie_len = strlen(curproxy->rdp_cookie_name); |
| 1836 | } |
| 1837 | else { /* syntax */ |
| 1838 | Alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n", |
| 1839 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1840 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1841 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 1842 | } |
| 1843 | } |
| 1844 | else { |
| 1845 | Alert("parsing [%s:%d] : unknown persist method.\n", |
| 1846 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1847 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1848 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 1849 | } |
| 1850 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1851 | else if (!strcmp(args[0], "appsession")) { /* cookie name */ |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 1852 | int cur_arg; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1853 | |
Cyril Bonté | 3b7a369 | 2010-01-10 17:01:47 +0100 | [diff] [blame] | 1854 | if (curproxy == &defproxy) { |
| 1855 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 1856 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1857 | goto out; |
| 1858 | } |
| 1859 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1860 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1861 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1862 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1863 | if (*(args[5]) == 0) { |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 1864 | 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] | 1865 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1866 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1867 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1868 | } |
| 1869 | have_appsession = 1; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1870 | free(curproxy->appsession_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1871 | curproxy->appsession_name = strdup(args[1]); |
| 1872 | curproxy->appsession_name_len = strlen(curproxy->appsession_name); |
| 1873 | curproxy->appsession_len = atoi(args[3]); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 1874 | err = parse_time_err(args[5], &val, TIME_UNIT_MS); |
| 1875 | if (err) { |
| 1876 | Alert("parsing [%s:%d] : unexpected character '%c' in %s timeout.\n", |
| 1877 | file, linenum, *err, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1878 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1879 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 1880 | } |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 1881 | curproxy->timeout.appsession = val; |
Willy Tarreau | ee99136 | 2007-05-14 14:37:50 +0200 | [diff] [blame] | 1882 | |
Willy Tarreau | 51041c7 | 2007-09-09 21:56:53 +0200 | [diff] [blame] | 1883 | if (appsession_hash_init(&(curproxy->htbl_proxy), destroy) == 0) { |
| 1884 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1885 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1886 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1887 | } |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 1888 | |
| 1889 | cur_arg = 6; |
| 1890 | curproxy->options2 &= ~PR_O2_AS_REQL; |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 1891 | curproxy->options2 &= ~PR_O2_AS_M_ANY; |
| 1892 | curproxy->options2 |= PR_O2_AS_M_PP; |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 1893 | while (*(args[cur_arg])) { |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 1894 | if (!strcmp(args[cur_arg], "request-learn")) { |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 1895 | curproxy->options2 |= PR_O2_AS_REQL; |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 1896 | } else if (!strcmp(args[cur_arg], "prefix")) { |
| 1897 | curproxy->options2 |= PR_O2_AS_PFX; |
| 1898 | } else if (!strcmp(args[cur_arg], "mode")) { |
| 1899 | if (!*args[cur_arg + 1]) { |
| 1900 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 1901 | file, linenum, args[0], args[cur_arg]); |
| 1902 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1903 | goto out; |
| 1904 | } |
| 1905 | |
| 1906 | cur_arg++; |
| 1907 | if (!strcmp(args[cur_arg], "query-string")) { |
| 1908 | curproxy->options2 &= ~PR_O2_AS_M_ANY; |
| 1909 | curproxy->options2 |= PR_O2_AS_M_QS; |
| 1910 | } else if (!strcmp(args[cur_arg], "path-parameters")) { |
| 1911 | curproxy->options2 &= ~PR_O2_AS_M_ANY; |
| 1912 | curproxy->options2 |= PR_O2_AS_M_PP; |
| 1913 | } else { |
| 1914 | Alert("parsing [%s:%d] : unknown mode '%s'\n", file, linenum, args[cur_arg]); |
| 1915 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1916 | goto out; |
| 1917 | } |
| 1918 | } |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 1919 | cur_arg++; |
| 1920 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1921 | } /* Url App Session */ |
| 1922 | else if (!strcmp(args[0], "capture")) { |
Willy Tarreau | 3b6b1a9 | 2009-07-23 13:24:23 +0200 | [diff] [blame] | 1923 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1924 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1925 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1926 | if (!strcmp(args[1], "cookie")) { /* name of a cookie to capture */ |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 1927 | if (curproxy == &defproxy) { |
| 1928 | Alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
| 1929 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1930 | goto out; |
| 1931 | } |
| 1932 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1933 | if (*(args[4]) == 0) { |
| 1934 | Alert("parsing [%s:%d] : '%s' expects 'cookie' <cookie_name> 'len' <len>.\n", |
| 1935 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1936 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1937 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1938 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1939 | free(curproxy->capture_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1940 | curproxy->capture_name = strdup(args[2]); |
| 1941 | curproxy->capture_namelen = strlen(curproxy->capture_name); |
| 1942 | curproxy->capture_len = atol(args[4]); |
| 1943 | if (curproxy->capture_len >= CAPTURE_LEN) { |
| 1944 | Warning("parsing [%s:%d] : truncating capture length to %d bytes.\n", |
| 1945 | file, linenum, CAPTURE_LEN - 1); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1946 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1947 | curproxy->capture_len = CAPTURE_LEN - 1; |
| 1948 | } |
| 1949 | curproxy->to_log |= LW_COOKIE; |
| 1950 | } |
| 1951 | else if (!strcmp(args[1], "request") && !strcmp(args[2], "header")) { |
| 1952 | struct cap_hdr *hdr; |
| 1953 | |
| 1954 | if (curproxy == &defproxy) { |
| 1955 | 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] | 1956 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1957 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1958 | } |
| 1959 | |
| 1960 | if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) { |
| 1961 | Alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n", |
| 1962 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1963 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1964 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1965 | } |
| 1966 | |
| 1967 | hdr = calloc(sizeof(struct cap_hdr), 1); |
| 1968 | hdr->next = curproxy->req_cap; |
| 1969 | hdr->name = strdup(args[3]); |
| 1970 | hdr->namelen = strlen(args[3]); |
| 1971 | hdr->len = atol(args[5]); |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 1972 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1973 | hdr->index = curproxy->nb_req_cap++; |
| 1974 | curproxy->req_cap = hdr; |
| 1975 | curproxy->to_log |= LW_REQHDR; |
| 1976 | } |
| 1977 | else if (!strcmp(args[1], "response") && !strcmp(args[2], "header")) { |
| 1978 | struct cap_hdr *hdr; |
| 1979 | |
| 1980 | if (curproxy == &defproxy) { |
| 1981 | 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] | 1982 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1983 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1984 | } |
| 1985 | |
| 1986 | if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) { |
| 1987 | Alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n", |
| 1988 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1989 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1990 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1991 | } |
| 1992 | hdr = calloc(sizeof(struct cap_hdr), 1); |
| 1993 | hdr->next = curproxy->rsp_cap; |
| 1994 | hdr->name = strdup(args[3]); |
| 1995 | hdr->namelen = strlen(args[3]); |
| 1996 | hdr->len = atol(args[5]); |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 1997 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1998 | hdr->index = curproxy->nb_rsp_cap++; |
| 1999 | curproxy->rsp_cap = hdr; |
| 2000 | curproxy->to_log |= LW_RSPHDR; |
| 2001 | } |
| 2002 | else { |
| 2003 | Alert("parsing [%s:%d] : '%s' expects 'cookie' or 'request header' or 'response header'.\n", |
| 2004 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2005 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2006 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2007 | } |
| 2008 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2009 | else if (!strcmp(args[0], "retries")) { /* connection retries */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2010 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2011 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2012 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2013 | if (*(args[1]) == 0) { |
| 2014 | Alert("parsing [%s:%d] : '%s' expects an integer argument (dispatch counts for one).\n", |
| 2015 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2016 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2017 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2018 | } |
| 2019 | curproxy->conn_retries = atol(args[1]); |
| 2020 | } |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2021 | else if (!strcmp(args[0], "http-request")) { /* request access control: allow/deny/auth */ |
| 2022 | struct req_acl_rule *req_acl; |
| 2023 | |
| 2024 | if (curproxy == &defproxy) { |
| 2025 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2026 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2027 | goto out; |
| 2028 | } |
| 2029 | |
| 2030 | |
| 2031 | if (!LIST_ISEMPTY(&curproxy->req_acl) && !LIST_PREV(&curproxy->req_acl, struct req_acl_rule *, list)->cond) { |
| 2032 | Warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n", |
| 2033 | file, linenum, args[0]); |
| 2034 | err_code |= ERR_WARN; |
| 2035 | } |
| 2036 | |
Willy Tarreau | 9cc670f | 2010-02-01 10:43:44 +0100 | [diff] [blame] | 2037 | 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] | 2038 | |
| 2039 | if (!req_acl) { |
| 2040 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2041 | goto out; |
| 2042 | } |
| 2043 | |
Willy Tarreau | 9cc670f | 2010-02-01 10:43:44 +0100 | [diff] [blame] | 2044 | err_code |= warnif_cond_requires_resp(req_acl->cond, file, linenum); |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2045 | LIST_ADDQ(&curproxy->req_acl, &req_acl->list); |
| 2046 | } |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2047 | else if (!strcmp(args[0], "block")) { /* early blocking based on ACLs */ |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2048 | if (curproxy == &defproxy) { |
| 2049 | 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] | 2050 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2051 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2052 | } |
| 2053 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2054 | if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) { |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2055 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 2056 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2057 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2058 | goto out; |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2059 | } |
| 2060 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2061 | 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] | 2062 | Alert("parsing [%s:%d] : error detected while parsing blocking condition.\n", |
| 2063 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2064 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2065 | goto out; |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2066 | } |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2067 | |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2068 | LIST_ADDQ(&curproxy->block_cond, &cond->list); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 2069 | warnif_misplaced_block(curproxy, file, linenum, args[0]); |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2070 | } |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2071 | else if (!strcmp(args[0], "redirect")) { |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2072 | struct redirect_rule *rule; |
| 2073 | int cur_arg; |
| 2074 | int type = REDIRECT_TYPE_NONE; |
| 2075 | int code = 302; |
| 2076 | char *destination = NULL; |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2077 | char *cookie = NULL; |
| 2078 | int cookie_set = 0; |
Willy Tarreau | 79da469 | 2008-11-19 20:03:04 +0100 | [diff] [blame] | 2079 | unsigned int flags = REDIRECT_FLAG_NONE; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2080 | |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 2081 | if (curproxy == &defproxy) { |
| 2082 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2083 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2084 | goto out; |
| 2085 | } |
| 2086 | |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2087 | cur_arg = 1; |
| 2088 | while (*(args[cur_arg])) { |
| 2089 | if (!strcmp(args[cur_arg], "location")) { |
| 2090 | if (!*args[cur_arg + 1]) { |
| 2091 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 2092 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2093 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2094 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2095 | } |
| 2096 | |
| 2097 | type = REDIRECT_TYPE_LOCATION; |
| 2098 | cur_arg++; |
| 2099 | destination = args[cur_arg]; |
| 2100 | } |
| 2101 | else if (!strcmp(args[cur_arg], "prefix")) { |
| 2102 | if (!*args[cur_arg + 1]) { |
| 2103 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 2104 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2105 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2106 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2107 | } |
| 2108 | |
| 2109 | type = REDIRECT_TYPE_PREFIX; |
| 2110 | cur_arg++; |
| 2111 | destination = args[cur_arg]; |
| 2112 | } |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2113 | else if (!strcmp(args[cur_arg], "set-cookie")) { |
| 2114 | if (!*args[cur_arg + 1]) { |
| 2115 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 2116 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2117 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2118 | goto out; |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2119 | } |
| 2120 | |
| 2121 | cur_arg++; |
| 2122 | cookie = args[cur_arg]; |
| 2123 | cookie_set = 1; |
| 2124 | } |
| 2125 | else if (!strcmp(args[cur_arg], "clear-cookie")) { |
| 2126 | if (!*args[cur_arg + 1]) { |
| 2127 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 2128 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2129 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2130 | goto out; |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2131 | } |
| 2132 | |
| 2133 | cur_arg++; |
| 2134 | cookie = args[cur_arg]; |
| 2135 | cookie_set = 0; |
| 2136 | } |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2137 | else if (!strcmp(args[cur_arg],"code")) { |
| 2138 | if (!*args[cur_arg + 1]) { |
| 2139 | Alert("parsing [%s:%d] : '%s': missing HTTP code.\n", |
| 2140 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2141 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2142 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2143 | } |
| 2144 | cur_arg++; |
| 2145 | code = atol(args[cur_arg]); |
| 2146 | if (code < 301 || code > 303) { |
| 2147 | Alert("parsing [%s:%d] : '%s': unsupported HTTP code '%d'.\n", |
| 2148 | file, linenum, args[0], code); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2149 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2150 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2151 | } |
| 2152 | } |
Willy Tarreau | 79da469 | 2008-11-19 20:03:04 +0100 | [diff] [blame] | 2153 | else if (!strcmp(args[cur_arg],"drop-query")) { |
| 2154 | flags |= REDIRECT_FLAG_DROP_QS; |
| 2155 | } |
Willy Tarreau | 81e3b4f | 2010-01-10 00:42:19 +0100 | [diff] [blame] | 2156 | else if (!strcmp(args[cur_arg],"append-slash")) { |
| 2157 | flags |= REDIRECT_FLAG_APPEND_SLASH; |
| 2158 | } |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2159 | else if (strcmp(args[cur_arg], "if") == 0 || |
| 2160 | strcmp(args[cur_arg], "unless") == 0) { |
| 2161 | cond = build_acl_cond(file, linenum, curproxy, (const char **)args + cur_arg); |
| 2162 | if (!cond) { |
| 2163 | Alert("parsing [%s:%d] : '%s': error detected while parsing redirect condition.\n", |
| 2164 | file, linenum, args[0]); |
| 2165 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2166 | goto out; |
| 2167 | } |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2168 | break; |
| 2169 | } |
| 2170 | else { |
Willy Tarreau | 81e3b4f | 2010-01-10 00:42:19 +0100 | [diff] [blame] | 2171 | 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] | 2172 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2173 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2174 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2175 | } |
| 2176 | cur_arg++; |
| 2177 | } |
| 2178 | |
| 2179 | if (type == REDIRECT_TYPE_NONE) { |
| 2180 | Alert("parsing [%s:%d] : '%s' expects a redirection type ('prefix' or 'location').\n", |
| 2181 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2182 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2183 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2184 | } |
| 2185 | |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2186 | rule = (struct redirect_rule *)calloc(1, sizeof(*rule)); |
| 2187 | rule->cond = cond; |
| 2188 | rule->rdr_str = strdup(destination); |
| 2189 | rule->rdr_len = strlen(destination); |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2190 | if (cookie) { |
| 2191 | /* 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] | 2192 | * a clear consists in appending "; path=/; Max-Age=0;" at the end. |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2193 | */ |
| 2194 | rule->cookie_len = strlen(cookie); |
William Turner | d986526 | 2010-03-01 13:30:34 -0500 | [diff] [blame] | 2195 | if (cookie_set) { |
| 2196 | rule->cookie_str = malloc(rule->cookie_len + 10); |
| 2197 | memcpy(rule->cookie_str, cookie, rule->cookie_len); |
| 2198 | memcpy(rule->cookie_str + rule->cookie_len, "; path=/;", 10); |
| 2199 | rule->cookie_len += 9; |
| 2200 | } else { |
| 2201 | rule->cookie_str = malloc(rule->cookie_len + 21); |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2202 | memcpy(rule->cookie_str, cookie, rule->cookie_len); |
William Turner | d986526 | 2010-03-01 13:30:34 -0500 | [diff] [blame] | 2203 | memcpy(rule->cookie_str + rule->cookie_len, "; path=/; Max-Age=0;", 21); |
| 2204 | rule->cookie_len += 20; |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2205 | } |
| 2206 | } |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2207 | rule->type = type; |
| 2208 | rule->code = code; |
Willy Tarreau | 79da469 | 2008-11-19 20:03:04 +0100 | [diff] [blame] | 2209 | rule->flags = flags; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2210 | LIST_INIT(&rule->list); |
| 2211 | LIST_ADDQ(&curproxy->redirect_rules, &rule->list); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 2212 | warnif_rule_after_use_backend(curproxy, file, linenum, args[0]); |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2213 | } |
Krzysztof Piotr Oledzki | 7b723ef | 2009-01-27 21:09:41 +0100 | [diff] [blame] | 2214 | else if (!strcmp(args[0], "use_backend")) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2215 | struct switching_rule *rule; |
| 2216 | |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2217 | if (curproxy == &defproxy) { |
| 2218 | 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] | 2219 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2220 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2221 | } |
| 2222 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2223 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2224 | err_code |= ERR_WARN; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2225 | |
| 2226 | if (*(args[1]) == 0) { |
| 2227 | 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] | 2228 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2229 | goto out; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2230 | } |
| 2231 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2232 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2233 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 2234 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2235 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2236 | goto out; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2237 | } |
| 2238 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2239 | 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] | 2240 | Alert("parsing [%s:%d] : error detected while parsing switching rule.\n", |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2241 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2242 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2243 | goto out; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2244 | } |
| 2245 | |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 2246 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
Willy Tarreau | a980263 | 2008-07-25 19:13:19 +0200 | [diff] [blame] | 2247 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2248 | rule = (struct switching_rule *)calloc(1, sizeof(*rule)); |
| 2249 | rule->cond = cond; |
| 2250 | rule->be.name = strdup(args[1]); |
| 2251 | LIST_INIT(&rule->list); |
| 2252 | LIST_ADDQ(&curproxy->switching_rules, &rule->list); |
| 2253 | } |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 2254 | else if ((!strcmp(args[0], "force-persist")) || |
| 2255 | (!strcmp(args[0], "ignore-persist"))) { |
| 2256 | struct persist_rule *rule; |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2257 | |
| 2258 | if (curproxy == &defproxy) { |
| 2259 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2260 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2261 | goto out; |
| 2262 | } |
| 2263 | |
| 2264 | if (warnifnotcap(curproxy, PR_CAP_FE|PR_CAP_BE, file, linenum, args[0], NULL)) |
| 2265 | err_code |= ERR_WARN; |
| 2266 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2267 | if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) { |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2268 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 2269 | file, linenum, args[0]); |
| 2270 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2271 | goto out; |
| 2272 | } |
| 2273 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2274 | 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] | 2275 | Alert("parsing [%s:%d] : error detected while parsing a '%s' rule.\n", |
| 2276 | file, linenum, args[0]); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2277 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2278 | goto out; |
| 2279 | } |
| 2280 | |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 2281 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2282 | |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 2283 | rule = (struct persist_rule *)calloc(1, sizeof(*rule)); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2284 | rule->cond = cond; |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 2285 | if (!strcmp(args[0], "force-persist")) { |
| 2286 | rule->type = PERSIST_TYPE_FORCE; |
| 2287 | } else { |
| 2288 | rule->type = PERSIST_TYPE_IGNORE; |
| 2289 | } |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2290 | LIST_INIT(&rule->list); |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 2291 | LIST_ADDQ(&curproxy->persist_rules, &rule->list); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2292 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2293 | else if (!strcmp(args[0], "stick-table")) { |
| 2294 | int myidx = 1; |
| 2295 | |
| 2296 | curproxy->table.type = (unsigned int)-1; |
| 2297 | while (*args[myidx]) { |
| 2298 | const char *err; |
| 2299 | |
| 2300 | if (strcmp(args[myidx], "size") == 0) { |
| 2301 | myidx++; |
| 2302 | if (!*(args[myidx])) { |
| 2303 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 2304 | file, linenum, args[myidx-1]); |
| 2305 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2306 | goto out; |
| 2307 | } |
| 2308 | if ((err = parse_size_err(args[myidx], &curproxy->table.size))) { |
| 2309 | Alert("parsing [%s:%d] : stick-table: unexpected character '%c' in argument of '%s'.\n", |
| 2310 | file, linenum, *err, args[myidx-1]); |
| 2311 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2312 | goto out; |
| 2313 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 2314 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2315 | } |
| 2316 | else if (strcmp(args[myidx], "expire") == 0) { |
| 2317 | myidx++; |
| 2318 | if (!*(args[myidx])) { |
| 2319 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 2320 | file, linenum, args[myidx-1]); |
| 2321 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2322 | goto out; |
| 2323 | } |
| 2324 | err = parse_time_err(args[myidx], &val, TIME_UNIT_MS); |
| 2325 | if (err) { |
| 2326 | Alert("parsing [%s:%d] : stick-table: unexpected character '%c' in argument of '%s'.\n", |
| 2327 | file, linenum, *err, args[myidx-1]); |
| 2328 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2329 | goto out; |
| 2330 | } |
| 2331 | curproxy->table.expire = val; |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 2332 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2333 | } |
| 2334 | else if (strcmp(args[myidx], "nopurge") == 0) { |
| 2335 | curproxy->table.nopurge = 1; |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 2336 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2337 | } |
| 2338 | else if (strcmp(args[myidx], "type") == 0) { |
| 2339 | myidx++; |
| 2340 | if (stktable_parse_type(args, &myidx, &curproxy->table.type, &curproxy->table.key_size) != 0) { |
| 2341 | Alert("parsing [%s:%d] : stick-table: unknown type '%s'.\n", |
| 2342 | file, linenum, args[myidx]); |
| 2343 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2344 | goto out; |
| 2345 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 2346 | /* myidx already points to next arg */ |
| 2347 | } |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 2348 | else if (strcmp(args[myidx], "store") == 0) { |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 2349 | int type, err; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 2350 | char *cw, *nw, *sa; |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 2351 | |
| 2352 | myidx++; |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 2353 | nw = args[myidx]; |
| 2354 | while (*nw) { |
| 2355 | /* the "store" keyword supports a comma-separated list */ |
| 2356 | cw = nw; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 2357 | sa = NULL; /* store arg */ |
| 2358 | while (*nw && *nw != ',') { |
| 2359 | if (*nw == '(') { |
| 2360 | *nw = 0; |
| 2361 | sa = ++nw; |
| 2362 | while (*nw != ')') { |
| 2363 | if (!*nw) { |
| 2364 | Alert("parsing [%s:%d] : %s: missing closing parenthesis after store option '%s'.\n", |
| 2365 | file, linenum, args[0], cw); |
| 2366 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2367 | goto out; |
| 2368 | } |
| 2369 | nw++; |
| 2370 | } |
| 2371 | *nw = '\0'; |
| 2372 | } |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 2373 | nw++; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 2374 | } |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 2375 | if (*nw) |
| 2376 | *nw++ = '\0'; |
| 2377 | type = stktable_get_data_type(cw); |
| 2378 | if (type < 0) { |
| 2379 | Alert("parsing [%s:%d] : %s: unknown store option '%s'.\n", |
| 2380 | file, linenum, args[0], cw); |
| 2381 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2382 | goto out; |
| 2383 | } |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 2384 | |
| 2385 | err = stktable_alloc_data_type(&curproxy->table, type, sa); |
| 2386 | switch (err) { |
| 2387 | case PE_NONE: break; |
| 2388 | case PE_EXIST: |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 2389 | Warning("parsing [%s:%d]: %s: store option '%s' already enabled, ignored.\n", |
| 2390 | file, linenum, args[0], cw); |
| 2391 | err_code |= ERR_WARN; |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 2392 | break; |
| 2393 | |
| 2394 | case PE_ARG_MISSING: |
| 2395 | Alert("parsing [%s:%d] : %s: missing argument to store option '%s'.\n", |
| 2396 | file, linenum, args[0], cw); |
| 2397 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2398 | goto out; |
| 2399 | |
| 2400 | case PE_ARG_NOT_USED: |
| 2401 | Alert("parsing [%s:%d] : %s: unexpected argument to store option '%s'.\n", |
| 2402 | file, linenum, args[0], cw); |
| 2403 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2404 | goto out; |
| 2405 | |
| 2406 | default: |
| 2407 | Alert("parsing [%s:%d] : %s: error when processing store option '%s'.\n", |
| 2408 | file, linenum, args[0], cw); |
| 2409 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2410 | goto out; |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 2411 | } |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 2412 | } |
| 2413 | myidx++; |
| 2414 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 2415 | else { |
| 2416 | Alert("parsing [%s:%d] : stick-table: unknown argument '%s'.\n", |
| 2417 | file, linenum, args[myidx]); |
| 2418 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2419 | goto out; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2420 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2421 | } |
| 2422 | |
| 2423 | if (!curproxy->table.size) { |
| 2424 | Alert("parsing [%s:%d] : stick-table: missing size.\n", |
| 2425 | file, linenum); |
| 2426 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2427 | goto out; |
| 2428 | } |
| 2429 | |
| 2430 | if (curproxy->table.type == (unsigned int)-1) { |
| 2431 | Alert("parsing [%s:%d] : stick-table: missing type.\n", |
| 2432 | file, linenum); |
| 2433 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2434 | goto out; |
| 2435 | } |
| 2436 | } |
| 2437 | else if (!strcmp(args[0], "stick")) { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2438 | struct sticking_rule *rule; |
| 2439 | struct pattern_expr *expr; |
| 2440 | int myidx = 0; |
| 2441 | const char *name = NULL; |
| 2442 | int flags; |
| 2443 | |
| 2444 | if (curproxy == &defproxy) { |
| 2445 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2446 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2447 | goto out; |
| 2448 | } |
| 2449 | |
| 2450 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) { |
| 2451 | err_code |= ERR_WARN; |
| 2452 | goto out; |
| 2453 | } |
| 2454 | |
| 2455 | myidx++; |
| 2456 | if ((strcmp(args[myidx], "store") == 0) || |
| 2457 | (strcmp(args[myidx], "store-request") == 0)) { |
| 2458 | myidx++; |
| 2459 | flags = STK_IS_STORE; |
| 2460 | } |
| 2461 | else if (strcmp(args[myidx], "store-response") == 0) { |
| 2462 | myidx++; |
| 2463 | flags = STK_IS_STORE | STK_ON_RSP; |
| 2464 | } |
| 2465 | else if (strcmp(args[myidx], "match") == 0) { |
| 2466 | myidx++; |
| 2467 | flags = STK_IS_MATCH; |
| 2468 | } |
| 2469 | else if (strcmp(args[myidx], "on") == 0) { |
| 2470 | myidx++; |
| 2471 | flags = STK_IS_MATCH | STK_IS_STORE; |
| 2472 | } |
| 2473 | else { |
| 2474 | Alert("parsing [%s:%d] : '%s' expects 'on', 'match', or 'store'.\n", file, linenum, args[0]); |
| 2475 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2476 | goto out; |
| 2477 | } |
| 2478 | |
| 2479 | if (*(args[myidx]) == 0) { |
| 2480 | Alert("parsing [%s:%d] : '%s' expects a fetch method.\n", file, linenum, args[0]); |
| 2481 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2482 | goto out; |
| 2483 | } |
| 2484 | |
| 2485 | expr = pattern_parse_expr(args, &myidx); |
| 2486 | if (!expr) { |
| 2487 | Alert("parsing [%s:%d] : '%s': unknown fetch method '%s'.\n", file, linenum, args[0], args[myidx]); |
| 2488 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2489 | goto out; |
| 2490 | } |
| 2491 | |
| 2492 | if (flags & STK_ON_RSP) { |
| 2493 | if (!(expr->fetch->dir & PATTERN_FETCH_RTR)) { |
| 2494 | Alert("parsing [%s:%d] : '%s': fetch method '%s' can not be used on response.\n", |
| 2495 | file, linenum, args[0], expr->fetch->kw); |
| 2496 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2497 | goto out; |
| 2498 | } |
| 2499 | } else { |
| 2500 | if (!(expr->fetch->dir & PATTERN_FETCH_REQ)) { |
| 2501 | Alert("parsing [%s:%d] : '%s': fetch method '%s' can not be used on request.\n", |
| 2502 | file, linenum, args[0], expr->fetch->kw); |
| 2503 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2504 | goto out; |
| 2505 | } |
| 2506 | } |
| 2507 | |
| 2508 | if (strcmp(args[myidx], "table") == 0) { |
| 2509 | myidx++; |
| 2510 | name = args[myidx++]; |
| 2511 | } |
| 2512 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2513 | if (strcmp(args[myidx], "if") == 0 || strcmp(args[myidx], "unless") == 0) { |
| 2514 | 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] | 2515 | Alert("parsing [%s:%d] : '%s': error detected while parsing sticking condition.\n", |
| 2516 | file, linenum, args[0]); |
| 2517 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2518 | goto out; |
| 2519 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2520 | } |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2521 | else if (*(args[myidx])) { |
| 2522 | Alert("parsing [%s:%d] : '%s': unknown keyword '%s'.\n", |
| 2523 | file, linenum, args[0], args[myidx]); |
| 2524 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2525 | goto out; |
| 2526 | } |
| 2527 | |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 2528 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
| 2529 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2530 | rule = (struct sticking_rule *)calloc(1, sizeof(*rule)); |
| 2531 | rule->cond = cond; |
| 2532 | rule->expr = expr; |
| 2533 | rule->flags = flags; |
| 2534 | rule->table.name = name ? strdup(name) : NULL; |
| 2535 | LIST_INIT(&rule->list); |
| 2536 | if (flags & STK_ON_RSP) |
| 2537 | LIST_ADDQ(&curproxy->storersp_rules, &rule->list); |
| 2538 | else |
| 2539 | LIST_ADDQ(&curproxy->sticking_rules, &rule->list); |
| 2540 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2541 | else if (!strcmp(args[0], "stats")) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2542 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2543 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2544 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2545 | if (curproxy != &defproxy && curproxy->uri_auth == defproxy.uri_auth) |
| 2546 | curproxy->uri_auth = NULL; /* we must detach from the default config */ |
| 2547 | |
Krzysztof Piotr Oledzki | 260a3bb | 2010-01-06 16:25:05 +0100 | [diff] [blame] | 2548 | if (!*args[1]) { |
| 2549 | goto stats_error_parsing; |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 2550 | } else if (!strcmp(args[1], "admin")) { |
| 2551 | struct stats_admin_rule *rule; |
| 2552 | |
| 2553 | if (curproxy == &defproxy) { |
| 2554 | Alert("parsing [%s:%d]: '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
| 2555 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2556 | goto out; |
| 2557 | } |
| 2558 | |
| 2559 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 2560 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 2561 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2562 | goto out; |
| 2563 | } |
| 2564 | |
| 2565 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
| 2566 | Alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n", |
| 2567 | file, linenum, args[0], args[1]); |
| 2568 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2569 | goto out; |
| 2570 | } |
| 2571 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2)) == NULL) { |
| 2572 | Alert("parsing [%s:%d] : error detected while parsing a '%s %s' rule.\n", |
| 2573 | file, linenum, args[0], args[1]); |
| 2574 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2575 | goto out; |
| 2576 | } |
| 2577 | |
| 2578 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
| 2579 | |
| 2580 | rule = (struct stats_admin_rule *)calloc(1, sizeof(*rule)); |
| 2581 | rule->cond = cond; |
| 2582 | LIST_INIT(&rule->list); |
| 2583 | LIST_ADDQ(&curproxy->uri_auth->admin_rules, &rule->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2584 | } else if (!strcmp(args[1], "uri")) { |
| 2585 | if (*(args[2]) == 0) { |
| 2586 | Alert("parsing [%s:%d] : 'uri' needs an URI prefix.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2587 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2588 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2589 | } else if (!stats_set_uri(&curproxy->uri_auth, args[2])) { |
| 2590 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2591 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2592 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2593 | } |
| 2594 | } else if (!strcmp(args[1], "realm")) { |
| 2595 | if (*(args[2]) == 0) { |
| 2596 | Alert("parsing [%s:%d] : 'realm' needs an realm name.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2597 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2598 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2599 | } else if (!stats_set_realm(&curproxy->uri_auth, args[2])) { |
| 2600 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2601 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2602 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2603 | } |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 2604 | } else if (!strcmp(args[1], "refresh")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 2605 | unsigned interval; |
| 2606 | |
| 2607 | err = parse_time_err(args[2], &interval, TIME_UNIT_S); |
| 2608 | if (err) { |
| 2609 | Alert("parsing [%s:%d] : unexpected character '%c' in stats refresh interval.\n", |
| 2610 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2611 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2612 | goto out; |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 2613 | } else if (!stats_set_refresh(&curproxy->uri_auth, interval)) { |
| 2614 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2615 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2616 | goto out; |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 2617 | } |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 2618 | } else if (!strcmp(args[1], "http-request")) { /* request access control: allow/deny/auth */ |
| 2619 | struct req_acl_rule *req_acl; |
| 2620 | |
| 2621 | if (curproxy == &defproxy) { |
| 2622 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2623 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2624 | goto out; |
| 2625 | } |
| 2626 | |
| 2627 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 2628 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 2629 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2630 | goto out; |
| 2631 | } |
| 2632 | |
| 2633 | if (!LIST_ISEMPTY(&curproxy->uri_auth->req_acl) && |
| 2634 | !LIST_PREV(&curproxy->uri_auth->req_acl, struct req_acl_rule *, list)->cond) { |
| 2635 | Warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n", |
| 2636 | file, linenum, args[0]); |
| 2637 | err_code |= ERR_WARN; |
| 2638 | } |
| 2639 | |
Willy Tarreau | 9cc670f | 2010-02-01 10:43:44 +0100 | [diff] [blame] | 2640 | 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] | 2641 | |
| 2642 | if (!req_acl) { |
| 2643 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2644 | goto out; |
| 2645 | } |
| 2646 | |
Willy Tarreau | 9cc670f | 2010-02-01 10:43:44 +0100 | [diff] [blame] | 2647 | err_code |= warnif_cond_requires_resp(req_acl->cond, file, linenum); |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 2648 | LIST_ADDQ(&curproxy->uri_auth->req_acl, &req_acl->list); |
| 2649 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2650 | } else if (!strcmp(args[1], "auth")) { |
| 2651 | if (*(args[2]) == 0) { |
| 2652 | 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] | 2653 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2654 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2655 | } else if (!stats_add_auth(&curproxy->uri_auth, args[2])) { |
| 2656 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2657 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2658 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2659 | } |
| 2660 | } else if (!strcmp(args[1], "scope")) { |
| 2661 | if (*(args[2]) == 0) { |
| 2662 | Alert("parsing [%s:%d] : 'scope' needs a proxy name.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2663 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2664 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2665 | } else if (!stats_add_scope(&curproxy->uri_auth, args[2])) { |
| 2666 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2667 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2668 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2669 | } |
| 2670 | } else if (!strcmp(args[1], "enable")) { |
| 2671 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 2672 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2673 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2674 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2675 | } |
Krzysztof Oledzki | d9db927 | 2007-10-15 10:05:11 +0200 | [diff] [blame] | 2676 | } else if (!strcmp(args[1], "hide-version")) { |
| 2677 | if (!stats_set_flag(&curproxy->uri_auth, ST_HIDEVER)) { |
| 2678 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2679 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2680 | goto out; |
Krzysztof Oledzki | d9db927 | 2007-10-15 10:05:11 +0200 | [diff] [blame] | 2681 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 2682 | } else if (!strcmp(args[1], "show-legends")) { |
| 2683 | if (!stats_set_flag(&curproxy->uri_auth, ST_SHLGNDS)) { |
| 2684 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 2685 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2686 | goto out; |
| 2687 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 2688 | } else if (!strcmp(args[1], "show-node")) { |
| 2689 | |
| 2690 | if (*args[2]) { |
| 2691 | int i; |
| 2692 | char c; |
| 2693 | |
| 2694 | for (i=0; args[2][i]; i++) { |
| 2695 | c = args[2][i]; |
Willy Tarreau | 88e0581 | 2010-03-03 00:16:00 +0100 | [diff] [blame] | 2696 | if (!isupper((unsigned char)c) && !islower((unsigned char)c) && |
| 2697 | !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.') |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 2698 | break; |
| 2699 | } |
| 2700 | |
| 2701 | if (!i || args[2][i]) { |
| 2702 | Alert("parsing [%s:%d]: '%s %s' invalid node name - should be a string" |
| 2703 | "with digits(0-9), letters(A-Z, a-z), hyphen(-) or underscode(_).\n", |
| 2704 | file, linenum, args[0], args[1]); |
| 2705 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2706 | goto out; |
| 2707 | } |
| 2708 | } |
| 2709 | |
| 2710 | if (!stats_set_node(&curproxy->uri_auth, args[2])) { |
| 2711 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 2712 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2713 | goto out; |
| 2714 | } |
| 2715 | } else if (!strcmp(args[1], "show-desc")) { |
| 2716 | char *desc = NULL; |
| 2717 | |
| 2718 | if (*args[2]) { |
| 2719 | int i, len=0; |
| 2720 | char *d; |
| 2721 | |
| 2722 | for(i=2; *args[i]; i++) |
| 2723 | len += strlen(args[i])+1; |
| 2724 | |
| 2725 | desc = d = (char *)calloc(1, len); |
| 2726 | |
| 2727 | d += sprintf(d, "%s", args[2]); |
| 2728 | for(i=3; *args[i]; i++) |
| 2729 | d += sprintf(d, " %s", args[i]); |
| 2730 | } |
| 2731 | |
| 2732 | if (!*args[2] && !global.desc) |
| 2733 | Warning("parsing [%s:%d]: '%s' requires a parameter or 'desc' to be set in the global section.\n", |
| 2734 | file, linenum, args[1]); |
| 2735 | else { |
| 2736 | if (!stats_set_desc(&curproxy->uri_auth, desc)) { |
| 2737 | free(desc); |
| 2738 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 2739 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2740 | goto out; |
| 2741 | } |
| 2742 | free(desc); |
| 2743 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2744 | } else { |
Krzysztof Piotr Oledzki | 260a3bb | 2010-01-06 16:25:05 +0100 | [diff] [blame] | 2745 | stats_error_parsing: |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 2746 | Alert("parsing [%s:%d]: %s '%s', expects 'admin', 'uri', 'realm', 'auth', 'scope', 'enable', 'hide-version', 'show-node', 'show-desc' or 'show-legends'.\n", |
Krzysztof Piotr Oledzki | 260a3bb | 2010-01-06 16:25:05 +0100 | [diff] [blame] | 2747 | 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] | 2748 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2749 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2750 | } |
| 2751 | } |
| 2752 | else if (!strcmp(args[0], "option")) { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 2753 | int optnum; |
| 2754 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 2755 | if (*(args[1]) == '\0') { |
| 2756 | Alert("parsing [%s:%d]: '%s' expects an option name.\n", |
| 2757 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2758 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2759 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2760 | } |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 2761 | |
| 2762 | for (optnum = 0; cfg_opts[optnum].name; optnum++) { |
| 2763 | if (!strcmp(args[1], cfg_opts[optnum].name)) { |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2764 | if (warnifnotcap(curproxy, cfg_opts[optnum].cap, file, linenum, args[1], NULL)) { |
| 2765 | err_code |= ERR_WARN; |
| 2766 | goto out; |
| 2767 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 2768 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 2769 | curproxy->no_options &= ~cfg_opts[optnum].val; |
| 2770 | curproxy->options &= ~cfg_opts[optnum].val; |
| 2771 | |
| 2772 | switch (kwm) { |
| 2773 | case KWM_STD: |
| 2774 | curproxy->options |= cfg_opts[optnum].val; |
| 2775 | break; |
| 2776 | case KWM_NO: |
| 2777 | curproxy->no_options |= cfg_opts[optnum].val; |
| 2778 | break; |
| 2779 | case KWM_DEF: /* already cleared */ |
| 2780 | break; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 2781 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 2782 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2783 | goto out; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 2784 | } |
| 2785 | } |
| 2786 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 2787 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) { |
| 2788 | if (!strcmp(args[1], cfg_opts2[optnum].name)) { |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2789 | if (warnifnotcap(curproxy, cfg_opts2[optnum].cap, file, linenum, args[1], NULL)) { |
| 2790 | err_code |= ERR_WARN; |
| 2791 | goto out; |
| 2792 | } |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 2793 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 2794 | curproxy->no_options2 &= ~cfg_opts2[optnum].val; |
| 2795 | curproxy->options2 &= ~cfg_opts2[optnum].val; |
| 2796 | |
| 2797 | switch (kwm) { |
| 2798 | case KWM_STD: |
| 2799 | curproxy->options2 |= cfg_opts2[optnum].val; |
| 2800 | break; |
| 2801 | case KWM_NO: |
| 2802 | curproxy->no_options2 |= cfg_opts2[optnum].val; |
| 2803 | break; |
| 2804 | case KWM_DEF: /* already cleared */ |
| 2805 | break; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 2806 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2807 | goto out; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 2808 | } |
| 2809 | } |
| 2810 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 2811 | if (kwm != KWM_STD) { |
| 2812 | 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] | 2813 | file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2814 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2815 | goto out; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 2816 | } |
| 2817 | |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 2818 | if (!strcmp(args[1], "httplog")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2819 | /* generate a complete HTTP log */ |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 2820 | curproxy->options2 &= ~PR_O2_CLFLOG; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2821 | 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] | 2822 | if (*(args[2]) != '\0') { |
| 2823 | if (!strcmp(args[2], "clf")) { |
| 2824 | curproxy->options2 |= PR_O2_CLFLOG; |
| 2825 | } else { |
| 2826 | 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] | 2827 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2828 | goto out; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 2829 | } |
| 2830 | } |
| 2831 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2832 | else if (!strcmp(args[1], "tcplog")) |
| 2833 | /* generate a detailed TCP log */ |
| 2834 | 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] | 2835 | else if (!strcmp(args[1], "tcpka")) { |
| 2836 | /* enable TCP keep-alives on client and server sessions */ |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 2837 | 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] | 2838 | err_code |= ERR_WARN; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 2839 | |
| 2840 | if (curproxy->cap & PR_CAP_FE) |
| 2841 | curproxy->options |= PR_O_TCP_CLI_KA; |
| 2842 | if (curproxy->cap & PR_CAP_BE) |
| 2843 | curproxy->options |= PR_O_TCP_SRV_KA; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2844 | } |
| 2845 | else if (!strcmp(args[1], "httpchk")) { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 2846 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2847 | err_code |= ERR_WARN; |
| 2848 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2849 | /* use HTTP request to check servers' health */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2850 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 2851 | curproxy->check_req = NULL; |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 2852 | curproxy->options &= ~PR_O_SMTP_CHK; |
Willy Tarreau | 07a5490 | 2010-03-29 18:33:29 +0200 | [diff] [blame] | 2853 | curproxy->options2 &= ~PR_O2_SSL3_CHK; |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 2854 | curproxy->options2 &= ~PR_O2_MYSQL_CHK; |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 2855 | curproxy->options2 &= ~PR_O2_LDAP_CHK; |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 2856 | curproxy->options |= PR_O_HTTP_CHK; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2857 | if (!*args[2]) { /* no argument */ |
| 2858 | curproxy->check_req = strdup(DEF_CHECK_REQ); /* default request */ |
| 2859 | curproxy->check_len = strlen(DEF_CHECK_REQ); |
| 2860 | } else if (!*args[3]) { /* one argument : URI */ |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 2861 | 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] | 2862 | curproxy->check_req = (char *)malloc(reqlen); |
| 2863 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 2864 | "OPTIONS %s HTTP/1.0\r\n", args[2]); /* URI to use */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2865 | } else { /* more arguments : METHOD URI [HTTP_VER] */ |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 2866 | int reqlen = strlen(args[2]) + strlen(args[3]) + 3 + strlen("\r\n"); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2867 | if (*args[4]) |
| 2868 | reqlen += strlen(args[4]); |
| 2869 | else |
| 2870 | reqlen += strlen("HTTP/1.0"); |
| 2871 | |
| 2872 | curproxy->check_req = (char *)malloc(reqlen); |
| 2873 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 2874 | "%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] | 2875 | } |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 2876 | } |
| 2877 | else if (!strcmp(args[1], "ssl-hello-chk")) { |
| 2878 | /* use SSLv3 CLIENT HELLO to check servers' health */ |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 2879 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2880 | err_code |= ERR_WARN; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 2881 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2882 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 2883 | curproxy->check_req = NULL; |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 2884 | curproxy->options &= ~PR_O_HTTP_CHK; |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 2885 | curproxy->options &= ~PR_O_SMTP_CHK; |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 2886 | curproxy->options2 &= ~PR_O2_MYSQL_CHK; |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 2887 | curproxy->options2 &= ~PR_O2_LDAP_CHK; |
Willy Tarreau | 07a5490 | 2010-03-29 18:33:29 +0200 | [diff] [blame] | 2888 | curproxy->options2 |= PR_O2_SSL3_CHK; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2889 | } |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 2890 | else if (!strcmp(args[1], "smtpchk")) { |
| 2891 | /* use SMTP request to check servers' health */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2892 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 2893 | curproxy->check_req = NULL; |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 2894 | curproxy->options &= ~PR_O_HTTP_CHK; |
Willy Tarreau | 07a5490 | 2010-03-29 18:33:29 +0200 | [diff] [blame] | 2895 | curproxy->options2 &= ~PR_O2_SSL3_CHK; |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 2896 | curproxy->options2 &= ~PR_O2_MYSQL_CHK; |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 2897 | curproxy->options2 &= ~PR_O2_LDAP_CHK; |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 2898 | curproxy->options |= PR_O_SMTP_CHK; |
| 2899 | |
| 2900 | if (!*args[2] || !*args[3]) { /* no argument or incomplete EHLO host */ |
| 2901 | curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */ |
| 2902 | curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ); |
| 2903 | } else { /* ESMTP EHLO, or SMTP HELO, and a hostname */ |
| 2904 | if (!strcmp(args[2], "EHLO") || !strcmp(args[2], "HELO")) { |
| 2905 | int reqlen = strlen(args[2]) + strlen(args[3]) + strlen(" \r\n") + 1; |
| 2906 | curproxy->check_req = (char *)malloc(reqlen); |
| 2907 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
| 2908 | "%s %s\r\n", args[2], args[3]); /* HELO hostname */ |
| 2909 | } else { |
| 2910 | /* this just hits the default for now, but you could potentially expand it to allow for other stuff |
| 2911 | though, it's unlikely you'd want to send anything other than an EHLO or HELO */ |
| 2912 | curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */ |
| 2913 | curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ); |
| 2914 | } |
| 2915 | } |
| 2916 | } |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 2917 | else if (!strcmp(args[1], "mysql-check")) { |
| 2918 | /* use MYSQL request to check servers' health */ |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 2919 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 2920 | err_code |= ERR_WARN; |
| 2921 | |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 2922 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 2923 | curproxy->check_req = NULL; |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 2924 | curproxy->options &= ~PR_O_HTTP_CHK; |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 2925 | curproxy->options &= ~PR_O_SMTP_CHK; |
Willy Tarreau | 07a5490 | 2010-03-29 18:33:29 +0200 | [diff] [blame] | 2926 | curproxy->options2 &= ~PR_O2_SSL3_CHK; |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 2927 | curproxy->options2 &= ~PR_O2_LDAP_CHK; |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 2928 | curproxy->options2 |= PR_O2_MYSQL_CHK; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 2929 | |
| 2930 | /* This is an exemple of an MySQL >=4.0 client Authentication packet kindly provided by Cyril Bonte. |
| 2931 | * const char mysql40_client_auth_pkt[] = { |
| 2932 | * "\x0e\x00\x00" // packet length |
| 2933 | * "\x01" // packet number |
| 2934 | * "\x00\x00" // client capabilities |
| 2935 | * "\x00\x00\x01" // max packet |
| 2936 | * "haproxy\x00" // username (null terminated string) |
| 2937 | * "\x00" // filler (always 0x00) |
| 2938 | * "\x01\x00\x00" // packet length |
| 2939 | * "\x00" // packet number |
| 2940 | * "\x01" // COM_QUIT command |
| 2941 | * }; |
| 2942 | */ |
| 2943 | |
| 2944 | if (*(args[2])) { |
| 2945 | int cur_arg = 2; |
| 2946 | |
| 2947 | while (*(args[cur_arg])) { |
| 2948 | if (strcmp(args[cur_arg], "user") == 0) { |
| 2949 | char *mysqluser; |
| 2950 | int packetlen, reqlen, userlen; |
| 2951 | |
| 2952 | /* suboption header - needs additional argument for it */ |
| 2953 | if (*(args[cur_arg+1]) == 0) { |
| 2954 | Alert("parsing [%s:%d] : '%s %s %s' expects <username> as argument.\n", |
| 2955 | file, linenum, args[0], args[1], args[cur_arg]); |
| 2956 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2957 | goto out; |
| 2958 | } |
| 2959 | mysqluser = args[cur_arg + 1]; |
| 2960 | userlen = strlen(mysqluser); |
| 2961 | packetlen = userlen + 7; |
| 2962 | reqlen = packetlen + 9; |
| 2963 | |
| 2964 | free(curproxy->check_req); |
| 2965 | curproxy->check_req = (char *)calloc(1, reqlen); |
| 2966 | curproxy->check_len = reqlen; |
| 2967 | |
| 2968 | snprintf(curproxy->check_req, 4, "%c%c%c", |
| 2969 | ((unsigned char) packetlen & 0xff), |
| 2970 | ((unsigned char) (packetlen >> 8) & 0xff), |
| 2971 | ((unsigned char) (packetlen >> 16) & 0xff)); |
| 2972 | |
| 2973 | curproxy->check_req[3] = 1; |
| 2974 | curproxy->check_req[8] = 1; |
| 2975 | memcpy(&curproxy->check_req[9], mysqluser, userlen); |
| 2976 | curproxy->check_req[9 + userlen + 1 + 1] = 1; |
| 2977 | curproxy->check_req[9 + userlen + 1 + 1 + 4] = 1; |
| 2978 | cur_arg += 2; |
| 2979 | } else { |
| 2980 | /* unknown suboption - catchall */ |
| 2981 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'user'.\n", |
| 2982 | file, linenum, args[0], args[1]); |
| 2983 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2984 | goto out; |
| 2985 | } |
| 2986 | } /* end while loop */ |
| 2987 | } |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 2988 | } |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 2989 | else if (!strcmp(args[1], "ldap-check")) { |
| 2990 | /* use LDAP request to check servers' health */ |
| 2991 | free(curproxy->check_req); |
| 2992 | curproxy->check_req = NULL; |
| 2993 | curproxy->options &= ~PR_O_HTTP_CHK; |
| 2994 | curproxy->options &= ~PR_O_SMTP_CHK; |
| 2995 | curproxy->options2 &= ~PR_O2_SSL3_CHK; |
| 2996 | curproxy->options2 &= ~PR_O2_MYSQL_CHK; |
| 2997 | curproxy->options2 |= PR_O2_LDAP_CHK; |
| 2998 | |
| 2999 | curproxy->check_req = (char *) malloc(sizeof(DEF_LDAP_CHECK_REQ) - 1); |
| 3000 | memcpy(curproxy->check_req, DEF_LDAP_CHECK_REQ, sizeof(DEF_LDAP_CHECK_REQ) - 1); |
| 3001 | curproxy->check_len = sizeof(DEF_LDAP_CHECK_REQ) - 1; |
| 3002 | } |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3003 | else if (!strcmp(args[1], "forwardfor")) { |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3004 | int cur_arg; |
| 3005 | |
| 3006 | /* insert x-forwarded-for field, but not for the IP address listed as an except. |
| 3007 | * set default options (ie: bitfield, header name, etc) |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3008 | */ |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3009 | |
| 3010 | curproxy->options |= PR_O_FWDFOR; |
| 3011 | |
| 3012 | free(curproxy->fwdfor_hdr_name); |
| 3013 | curproxy->fwdfor_hdr_name = strdup(DEF_XFORWARDFOR_HDR); |
| 3014 | curproxy->fwdfor_hdr_len = strlen(DEF_XFORWARDFOR_HDR); |
| 3015 | |
| 3016 | /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */ |
| 3017 | cur_arg = 2; |
| 3018 | while (*(args[cur_arg])) { |
| 3019 | if (!strcmp(args[cur_arg], "except")) { |
| 3020 | /* suboption except - needs additional argument for it */ |
| 3021 | if (!*(args[cur_arg+1]) || !str2net(args[cur_arg+1], &curproxy->except_net, &curproxy->except_mask)) { |
| 3022 | Alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n", |
| 3023 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3024 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3025 | goto out; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3026 | } |
| 3027 | /* flush useless bits */ |
| 3028 | curproxy->except_net.s_addr &= curproxy->except_mask.s_addr; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3029 | cur_arg += 2; |
| 3030 | } else if (!strcmp(args[cur_arg], "header")) { |
| 3031 | /* suboption header - needs additional argument for it */ |
| 3032 | if (*(args[cur_arg+1]) == 0) { |
| 3033 | Alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 3034 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3035 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3036 | goto out; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3037 | } |
| 3038 | free(curproxy->fwdfor_hdr_name); |
| 3039 | curproxy->fwdfor_hdr_name = strdup(args[cur_arg+1]); |
| 3040 | curproxy->fwdfor_hdr_len = strlen(curproxy->fwdfor_hdr_name); |
| 3041 | cur_arg += 2; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3042 | } else { |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3043 | /* unknown suboption - catchall */ |
| 3044 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n", |
| 3045 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3046 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3047 | goto out; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3048 | } |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3049 | } /* end while loop */ |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3050 | } |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 3051 | else if (!strcmp(args[1], "originalto")) { |
| 3052 | int cur_arg; |
| 3053 | |
| 3054 | /* insert x-original-to field, but not for the IP address listed as an except. |
| 3055 | * set default options (ie: bitfield, header name, etc) |
| 3056 | */ |
| 3057 | |
| 3058 | curproxy->options |= PR_O_ORGTO; |
| 3059 | |
| 3060 | free(curproxy->orgto_hdr_name); |
| 3061 | curproxy->orgto_hdr_name = strdup(DEF_XORIGINALTO_HDR); |
| 3062 | curproxy->orgto_hdr_len = strlen(DEF_XORIGINALTO_HDR); |
| 3063 | |
| 3064 | /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */ |
| 3065 | cur_arg = 2; |
| 3066 | while (*(args[cur_arg])) { |
| 3067 | if (!strcmp(args[cur_arg], "except")) { |
| 3068 | /* suboption except - needs additional argument for it */ |
| 3069 | if (!*(args[cur_arg+1]) || !str2net(args[cur_arg+1], &curproxy->except_to, &curproxy->except_mask_to)) { |
| 3070 | Alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n", |
| 3071 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3072 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3073 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 3074 | } |
| 3075 | /* flush useless bits */ |
| 3076 | curproxy->except_to.s_addr &= curproxy->except_mask_to.s_addr; |
| 3077 | cur_arg += 2; |
| 3078 | } else if (!strcmp(args[cur_arg], "header")) { |
| 3079 | /* suboption header - needs additional argument for it */ |
| 3080 | if (*(args[cur_arg+1]) == 0) { |
| 3081 | Alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 3082 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3083 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3084 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 3085 | } |
| 3086 | free(curproxy->orgto_hdr_name); |
| 3087 | curproxy->orgto_hdr_name = strdup(args[cur_arg+1]); |
| 3088 | curproxy->orgto_hdr_len = strlen(curproxy->orgto_hdr_name); |
| 3089 | cur_arg += 2; |
| 3090 | } else { |
| 3091 | /* unknown suboption - catchall */ |
| 3092 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n", |
| 3093 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3094 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3095 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 3096 | } |
| 3097 | } /* end while loop */ |
| 3098 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3099 | else { |
| 3100 | Alert("parsing [%s:%d] : unknown option '%s'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3101 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3102 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3103 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3104 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3105 | } |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 3106 | else if (!strcmp(args[0], "default_backend")) { |
| 3107 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3108 | err_code |= ERR_WARN; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 3109 | |
| 3110 | if (*(args[1]) == 0) { |
| 3111 | 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] | 3112 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3113 | goto out; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 3114 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3115 | free(curproxy->defbe.name); |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 3116 | curproxy->defbe.name = strdup(args[1]); |
| 3117 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3118 | else if (!strcmp(args[0], "redispatch") || !strcmp(args[0], "redisp")) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3119 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3120 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3121 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3122 | Warning("parsing [%s:%d]: keyword '%s' is deprecated, please use 'option redispatch' instead.\n", |
| 3123 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3124 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3125 | /* enable reconnections to dispatch */ |
| 3126 | curproxy->options |= PR_O_REDISP; |
| 3127 | } |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 3128 | else if (!strcmp(args[0], "http-check")) { |
| 3129 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3130 | err_code |= ERR_WARN; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 3131 | |
| 3132 | if (strcmp(args[1], "disable-on-404") == 0) { |
| 3133 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 3134 | curproxy->options |= PR_O_DISABLE404; |
| 3135 | } |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 3136 | else if (strcmp(args[1], "send-state") == 0) { |
| 3137 | /* enable emission of the apparent state of a server in HTTP checks */ |
| 3138 | curproxy->options2 |= PR_O2_CHK_SNDST; |
| 3139 | } |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 3140 | else if (strcmp(args[1], "expect") == 0) { |
| 3141 | const char *ptr_arg; |
| 3142 | int cur_arg; |
| 3143 | |
| 3144 | if (curproxy->options2 & PR_O2_EXP_TYPE) { |
| 3145 | Alert("parsing [%s:%d] : '%s %s' already specified.\n", file, linenum, args[0], args[1]); |
| 3146 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3147 | goto out; |
| 3148 | } |
| 3149 | |
| 3150 | cur_arg = 2; |
| 3151 | /* consider exclamation marks, sole or at the beginning of a word */ |
| 3152 | while (*(ptr_arg = args[cur_arg])) { |
| 3153 | while (*ptr_arg == '!') { |
| 3154 | curproxy->options2 ^= PR_O2_EXP_INV; |
| 3155 | ptr_arg++; |
| 3156 | } |
| 3157 | if (*ptr_arg) |
| 3158 | break; |
| 3159 | cur_arg++; |
| 3160 | } |
| 3161 | /* now ptr_arg points to the beginning of a word past any possible |
| 3162 | * exclamation mark, and cur_arg is the argument which holds this word. |
| 3163 | */ |
| 3164 | if (strcmp(ptr_arg, "status") == 0) { |
| 3165 | if (!*(args[cur_arg + 1])) { |
| 3166 | Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 3167 | file, linenum, args[0], args[1], ptr_arg); |
| 3168 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3169 | goto out; |
| 3170 | } |
| 3171 | curproxy->options2 |= PR_O2_EXP_STS; |
| 3172 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
| 3173 | } |
| 3174 | else if (strcmp(ptr_arg, "string") == 0) { |
| 3175 | if (!*(args[cur_arg + 1])) { |
| 3176 | Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 3177 | file, linenum, args[0], args[1], ptr_arg); |
| 3178 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3179 | goto out; |
| 3180 | } |
| 3181 | curproxy->options2 |= PR_O2_EXP_STR; |
| 3182 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
| 3183 | } |
| 3184 | else if (strcmp(ptr_arg, "rstatus") == 0) { |
| 3185 | if (!*(args[cur_arg + 1])) { |
| 3186 | Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 3187 | file, linenum, args[0], args[1], ptr_arg); |
| 3188 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3189 | goto out; |
| 3190 | } |
| 3191 | curproxy->options2 |= PR_O2_EXP_RSTS; |
| 3192 | curproxy->expect_regex = calloc(1, sizeof(regex_t)); |
| 3193 | if (regcomp(curproxy->expect_regex, args[cur_arg + 1], REG_EXTENDED) != 0) { |
| 3194 | Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s'.\n", |
| 3195 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1]); |
| 3196 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3197 | goto out; |
| 3198 | } |
| 3199 | } |
| 3200 | else if (strcmp(ptr_arg, "rstring") == 0) { |
| 3201 | if (!*(args[cur_arg + 1])) { |
| 3202 | Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 3203 | file, linenum, args[0], args[1], ptr_arg); |
| 3204 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3205 | goto out; |
| 3206 | } |
| 3207 | curproxy->options2 |= PR_O2_EXP_RSTR; |
| 3208 | curproxy->expect_regex = calloc(1, sizeof(regex_t)); |
| 3209 | if (regcomp(curproxy->expect_regex, args[cur_arg + 1], REG_EXTENDED) != 0) { |
| 3210 | Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s'.\n", |
| 3211 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1]); |
| 3212 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3213 | goto out; |
| 3214 | } |
| 3215 | } |
| 3216 | else { |
| 3217 | Alert("parsing [%s:%d] : '%s %s' only supports [!] 'status', 'string', 'rstatus', 'rstring', found '%s'.\n", |
| 3218 | file, linenum, args[0], args[1], ptr_arg); |
| 3219 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3220 | goto out; |
| 3221 | } |
| 3222 | } |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 3223 | else { |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 3224 | Alert("parsing [%s:%d] : '%s' only supports 'disable-on-404', 'expect' .\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3225 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3226 | goto out; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 3227 | } |
| 3228 | } |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3229 | else if (!strcmp(args[0], "monitor")) { |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3230 | if (curproxy == &defproxy) { |
| 3231 | 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] | 3232 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3233 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3234 | } |
| 3235 | |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3236 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3237 | err_code |= ERR_WARN; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3238 | |
| 3239 | if (strcmp(args[1], "fail") == 0) { |
| 3240 | /* add a condition to fail monitor requests */ |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 3241 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3242 | Alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n", |
| 3243 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3244 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3245 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3246 | } |
| 3247 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 3248 | 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] | 3249 | Alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition.\n", |
| 3250 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3251 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3252 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3253 | } |
| 3254 | LIST_ADDQ(&curproxy->mon_fail_cond, &cond->list); |
| 3255 | } |
| 3256 | else { |
| 3257 | 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] | 3258 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3259 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3260 | } |
| 3261 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3262 | #ifdef TPROXY |
| 3263 | else if (!strcmp(args[0], "transparent")) { |
| 3264 | /* enable transparent proxy connections */ |
| 3265 | curproxy->options |= PR_O_TRANSP; |
| 3266 | } |
| 3267 | #endif |
| 3268 | else if (!strcmp(args[0], "maxconn")) { /* maxconn */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3269 | 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] | 3270 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3271 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3272 | if (*(args[1]) == 0) { |
| 3273 | 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] | 3274 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3275 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3276 | } |
| 3277 | curproxy->maxconn = atol(args[1]); |
| 3278 | } |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 3279 | else if (!strcmp(args[0], "backlog")) { /* backlog */ |
| 3280 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3281 | err_code |= ERR_WARN; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 3282 | |
| 3283 | if (*(args[1]) == 0) { |
| 3284 | 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] | 3285 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3286 | goto out; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 3287 | } |
| 3288 | curproxy->backlog = atol(args[1]); |
| 3289 | } |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 3290 | else if (!strcmp(args[0], "fullconn")) { /* fullconn */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3291 | 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] | 3292 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3293 | |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 3294 | if (*(args[1]) == 0) { |
| 3295 | 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] | 3296 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3297 | goto out; |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 3298 | } |
| 3299 | curproxy->fullconn = atol(args[1]); |
| 3300 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3301 | else if (!strcmp(args[0], "grace")) { /* grace time (ms) */ |
| 3302 | if (*(args[1]) == 0) { |
| 3303 | 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] | 3304 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3305 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3306 | } |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 3307 | err = parse_time_err(args[1], &val, TIME_UNIT_MS); |
| 3308 | if (err) { |
| 3309 | Alert("parsing [%s:%d] : unexpected character '%c' in grace time.\n", |
| 3310 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3311 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3312 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 3313 | } |
| 3314 | curproxy->grace = val; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3315 | } |
| 3316 | else if (!strcmp(args[0], "dispatch")) { /* dispatch address */ |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 3317 | struct sockaddr_in *sk; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3318 | if (curproxy == &defproxy) { |
| 3319 | 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] | 3320 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3321 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3322 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3323 | else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3324 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3325 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3326 | if (strchr(args[1], ':') == NULL) { |
| 3327 | 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] | 3328 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3329 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3330 | } |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 3331 | sk = str2sa(args[1]); |
| 3332 | if (!sk) { |
| 3333 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[1]); |
| 3334 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3335 | goto out; |
| 3336 | } |
| 3337 | curproxy->dispatch_addr = *sk; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3338 | } |
| 3339 | else if (!strcmp(args[0], "balance")) { /* set balancing with optional algorithm */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3340 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3341 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3342 | |
Jeffrey 'jf' Lim | 65cb2f1 | 2008-10-04 18:07:00 +0200 | [diff] [blame] | 3343 | memcpy(trash, "error near 'balance'", 21); |
Willy Tarreau | a0cbda6 | 2007-11-01 21:39:54 +0100 | [diff] [blame] | 3344 | if (backend_parse_balance((const char **)args + 1, trash, sizeof(trash), curproxy) < 0) { |
| 3345 | Alert("parsing [%s:%d] : %s\n", file, linenum, trash); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3346 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3347 | goto out; |
Willy Tarreau | 2fcb500 | 2007-05-08 13:35:26 +0200 | [diff] [blame] | 3348 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3349 | } |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 3350 | else if (!strcmp(args[0], "hash-type")) { /* set hashing method */ |
| 3351 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 3352 | err_code |= ERR_WARN; |
| 3353 | |
| 3354 | if (strcmp(args[1], "consistent") == 0) { /* use consistent hashing */ |
| 3355 | curproxy->lbprm.algo &= ~BE_LB_HASH_TYPE; |
| 3356 | curproxy->lbprm.algo |= BE_LB_HASH_CONS; |
| 3357 | } |
| 3358 | else if (strcmp(args[1], "map-based") == 0) { /* use map-based hashing */ |
| 3359 | curproxy->lbprm.algo &= ~BE_LB_HASH_TYPE; |
| 3360 | curproxy->lbprm.algo |= BE_LB_HASH_MAP; |
| 3361 | } |
| 3362 | else { |
| 3363 | Alert("parsing [%s:%d] : '%s' only supports 'consistent' and 'map-based'.\n", file, linenum, args[0]); |
| 3364 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3365 | goto out; |
| 3366 | } |
| 3367 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3368 | 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] | 3369 | int cur_arg; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3370 | char *rport, *raddr; |
| 3371 | short realport = 0; |
| 3372 | int do_check = 0, defsrv = (*args[0] == 'd'); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3373 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3374 | if (!defsrv && curproxy == &defproxy) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3375 | 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] | 3376 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3377 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3378 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3379 | else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3380 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3381 | |
| 3382 | if (!*args[2]) { |
| 3383 | Alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n", |
| 3384 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3385 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3386 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3387 | } |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 3388 | |
| 3389 | err = invalid_char(args[1]); |
| 3390 | if (err) { |
| 3391 | Alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n", |
| 3392 | file, linenum, *err, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3393 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3394 | goto out; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 3395 | } |
| 3396 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3397 | if (!defsrv) { |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 3398 | struct sockaddr_in *sk; |
| 3399 | |
Krzysztof Piotr Oledzki | aff01ea | 2010-02-05 20:31:44 +0100 | [diff] [blame] | 3400 | if ((newsrv = (struct server *)calloc(1, sizeof(struct server))) == NULL) { |
| 3401 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 3402 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3403 | goto out; |
| 3404 | } |
| 3405 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3406 | /* the servers are linked backwards first */ |
| 3407 | newsrv->next = curproxy->srv; |
| 3408 | curproxy->srv = newsrv; |
| 3409 | newsrv->proxy = curproxy; |
| 3410 | newsrv->conf.file = file; |
| 3411 | newsrv->conf.line = linenum; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3412 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3413 | LIST_INIT(&newsrv->pendconns); |
| 3414 | do_check = 0; |
| 3415 | newsrv->state = SRV_RUNNING; /* early server setup */ |
| 3416 | newsrv->last_change = now.tv_sec; |
| 3417 | newsrv->id = strdup(args[1]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3418 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3419 | /* several ways to check the port component : |
| 3420 | * - IP => port=+0, relative |
| 3421 | * - IP: => port=+0, relative |
| 3422 | * - IP:N => port=N, absolute |
| 3423 | * - IP:+N => port=+N, relative |
| 3424 | * - IP:-N => port=-N, relative |
| 3425 | */ |
| 3426 | raddr = strdup(args[2]); |
| 3427 | rport = strchr(raddr, ':'); |
| 3428 | if (rport) { |
| 3429 | *rport++ = 0; |
| 3430 | realport = atol(rport); |
| 3431 | if (!isdigit((unsigned char)*rport)) |
| 3432 | newsrv->state |= SRV_MAPPORTS; |
| 3433 | } else |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3434 | newsrv->state |= SRV_MAPPORTS; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3435 | |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 3436 | sk = str2sa(raddr); |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3437 | free(raddr); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 3438 | if (!sk) { |
| 3439 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[2]); |
| 3440 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3441 | goto out; |
| 3442 | } |
| 3443 | newsrv->addr = *sk; |
| 3444 | newsrv->addr.sin_port = htons(realport); |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3445 | |
| 3446 | newsrv->check_port = curproxy->defsrv.check_port; |
| 3447 | newsrv->inter = curproxy->defsrv.inter; |
| 3448 | newsrv->fastinter = curproxy->defsrv.fastinter; |
| 3449 | newsrv->downinter = curproxy->defsrv.downinter; |
| 3450 | newsrv->rise = curproxy->defsrv.rise; |
| 3451 | newsrv->fall = curproxy->defsrv.fall; |
| 3452 | newsrv->maxqueue = curproxy->defsrv.maxqueue; |
| 3453 | newsrv->minconn = curproxy->defsrv.minconn; |
| 3454 | newsrv->maxconn = curproxy->defsrv.maxconn; |
| 3455 | newsrv->slowstart = curproxy->defsrv.slowstart; |
| 3456 | newsrv->onerror = curproxy->defsrv.onerror; |
| 3457 | newsrv->consecutive_errors_limit |
| 3458 | = curproxy->defsrv.consecutive_errors_limit; |
| 3459 | newsrv->uweight = newsrv->iweight |
| 3460 | = curproxy->defsrv.iweight; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3461 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3462 | newsrv->curfd = -1; /* no health-check in progress */ |
| 3463 | newsrv->health = newsrv->rise; /* up, but will fall down at first failure */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3464 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3465 | cur_arg = 3; |
| 3466 | } else { |
| 3467 | newsrv = &curproxy->defsrv; |
| 3468 | cur_arg = 1; |
| 3469 | } |
Willy Tarreau | 0f03c6f | 2007-03-25 20:46:19 +0200 | [diff] [blame] | 3470 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3471 | while (*args[cur_arg]) { |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3472 | if (!defsrv && !strcmp(args[cur_arg], "id")) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 3473 | struct eb32_node *node; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3474 | |
| 3475 | if (!*args[cur_arg + 1]) { |
| 3476 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 3477 | file, linenum, args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3478 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3479 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3480 | } |
| 3481 | |
| 3482 | newsrv->puid = atol(args[cur_arg + 1]); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 3483 | newsrv->conf.id.key = newsrv->puid; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3484 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 3485 | if (newsrv->puid <= 0) { |
| 3486 | Alert("parsing [%s:%d]: custom id has to be > 0.\n", |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3487 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3488 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3489 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3490 | } |
| 3491 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 3492 | node = eb32_lookup(&curproxy->conf.used_server_id, newsrv->puid); |
| 3493 | if (node) { |
| 3494 | struct server *target = container_of(node, struct server, conf.id); |
| 3495 | Alert("parsing [%s:%d]: server %s reuses same custom id as server %s (declared at %s:%d).\n", |
| 3496 | file, linenum, newsrv->id, target->id, target->conf.file, target->conf.line); |
| 3497 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3498 | goto out; |
| 3499 | } |
| 3500 | eb32_insert(&curproxy->conf.used_server_id, &newsrv->conf.id); |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3501 | cur_arg += 2; |
| 3502 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3503 | else if (!defsrv && !strcmp(args[cur_arg], "cookie")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3504 | newsrv->cookie = strdup(args[cur_arg + 1]); |
| 3505 | newsrv->cklen = strlen(args[cur_arg + 1]); |
| 3506 | cur_arg += 2; |
| 3507 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3508 | else if (!defsrv && !strcmp(args[cur_arg], "redir")) { |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 3509 | newsrv->rdr_pfx = strdup(args[cur_arg + 1]); |
| 3510 | newsrv->rdr_len = strlen(args[cur_arg + 1]); |
| 3511 | cur_arg += 2; |
| 3512 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3513 | else if (!strcmp(args[cur_arg], "rise")) { |
Krzysztof Piotr Oledzki | 08ff959 | 2009-09-27 16:17:31 +0200 | [diff] [blame] | 3514 | if (!*args[cur_arg + 1]) { |
| 3515 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 3516 | file, linenum, args[cur_arg]); |
| 3517 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3518 | goto out; |
| 3519 | } |
| 3520 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3521 | newsrv->rise = atol(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 08ff959 | 2009-09-27 16:17:31 +0200 | [diff] [blame] | 3522 | if (newsrv->rise <= 0) { |
| 3523 | Alert("parsing [%s:%d]: '%s' has to be > 0.\n", |
| 3524 | file, linenum, args[cur_arg]); |
| 3525 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3526 | goto out; |
| 3527 | } |
| 3528 | |
Willy Tarreau | 9683909 | 2010-03-29 10:02:24 +0200 | [diff] [blame] | 3529 | if (newsrv->health) |
| 3530 | newsrv->health = newsrv->rise; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3531 | cur_arg += 2; |
| 3532 | } |
| 3533 | else if (!strcmp(args[cur_arg], "fall")) { |
| 3534 | newsrv->fall = atol(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 08ff959 | 2009-09-27 16:17:31 +0200 | [diff] [blame] | 3535 | |
| 3536 | if (!*args[cur_arg + 1]) { |
| 3537 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 3538 | file, linenum, args[cur_arg]); |
| 3539 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3540 | goto out; |
| 3541 | } |
| 3542 | |
| 3543 | if (newsrv->fall <= 0) { |
| 3544 | Alert("parsing [%s:%d]: '%s' has to be > 0.\n", |
| 3545 | file, linenum, args[cur_arg]); |
| 3546 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3547 | goto out; |
| 3548 | } |
| 3549 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3550 | cur_arg += 2; |
| 3551 | } |
| 3552 | else if (!strcmp(args[cur_arg], "inter")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 3553 | const char *err = parse_time_err(args[cur_arg + 1], &val, TIME_UNIT_MS); |
| 3554 | if (err) { |
| 3555 | Alert("parsing [%s:%d] : unexpected character '%c' in 'inter' argument of server %s.\n", |
| 3556 | file, linenum, *err, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3557 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3558 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 3559 | } |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 3560 | if (val <= 0) { |
| 3561 | Alert("parsing [%s:%d]: invalid value %d for argument '%s' of server %s.\n", |
| 3562 | file, linenum, val, args[cur_arg], newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3563 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3564 | goto out; |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 3565 | } |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 3566 | newsrv->inter = val; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3567 | cur_arg += 2; |
| 3568 | } |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 3569 | else if (!strcmp(args[cur_arg], "fastinter")) { |
| 3570 | const char *err = parse_time_err(args[cur_arg + 1], &val, TIME_UNIT_MS); |
| 3571 | if (err) { |
| 3572 | Alert("parsing [%s:%d]: unexpected character '%c' in 'fastinter' argument of server %s.\n", |
| 3573 | file, linenum, *err, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3574 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3575 | goto out; |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 3576 | } |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 3577 | if (val <= 0) { |
| 3578 | Alert("parsing [%s:%d]: invalid value %d for argument '%s' of server %s.\n", |
| 3579 | file, linenum, val, args[cur_arg], newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3580 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3581 | goto out; |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 3582 | } |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 3583 | newsrv->fastinter = val; |
| 3584 | cur_arg += 2; |
| 3585 | } |
| 3586 | else if (!strcmp(args[cur_arg], "downinter")) { |
| 3587 | const char *err = parse_time_err(args[cur_arg + 1], &val, TIME_UNIT_MS); |
| 3588 | if (err) { |
| 3589 | Alert("parsing [%s:%d]: unexpected character '%c' in 'downinter' argument of server %s.\n", |
| 3590 | file, linenum, *err, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3591 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3592 | goto out; |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 3593 | } |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 3594 | if (val <= 0) { |
| 3595 | Alert("parsing [%s:%d]: invalid value %d for argument '%s' of server %s.\n", |
| 3596 | file, linenum, val, args[cur_arg], newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3597 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3598 | goto out; |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 3599 | } |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 3600 | newsrv->downinter = val; |
| 3601 | cur_arg += 2; |
| 3602 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3603 | else if (!defsrv && !strcmp(args[cur_arg], "addr")) { |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 3604 | struct sockaddr_in *sk = str2sa(args[cur_arg + 1]); |
| 3605 | if (!sk) { |
| 3606 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[cur_arg + 1]); |
| 3607 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3608 | goto out; |
| 3609 | } |
| 3610 | newsrv->check_addr = *sk; |
Willy Tarreau | 2ea3abb | 2007-03-25 16:45:16 +0200 | [diff] [blame] | 3611 | cur_arg += 2; |
| 3612 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3613 | else if (!strcmp(args[cur_arg], "port")) { |
| 3614 | newsrv->check_port = atol(args[cur_arg + 1]); |
| 3615 | cur_arg += 2; |
| 3616 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3617 | else if (!defsrv && !strcmp(args[cur_arg], "backup")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3618 | newsrv->state |= SRV_BACKUP; |
| 3619 | cur_arg ++; |
| 3620 | } |
| 3621 | else if (!strcmp(args[cur_arg], "weight")) { |
| 3622 | int w; |
| 3623 | w = atol(args[cur_arg + 1]); |
Willy Tarreau | 6704d67 | 2009-06-15 10:56:05 +0200 | [diff] [blame] | 3624 | if (w < 0 || w > 256) { |
| 3625 | 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] | 3626 | file, linenum, newsrv->id, w); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3627 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3628 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3629 | } |
Willy Tarreau | 975c50b | 2009-10-10 19:34:06 +0200 | [diff] [blame] | 3630 | newsrv->uweight = newsrv->iweight = w; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3631 | cur_arg += 2; |
| 3632 | } |
| 3633 | else if (!strcmp(args[cur_arg], "minconn")) { |
| 3634 | newsrv->minconn = atol(args[cur_arg + 1]); |
| 3635 | cur_arg += 2; |
| 3636 | } |
| 3637 | else if (!strcmp(args[cur_arg], "maxconn")) { |
| 3638 | newsrv->maxconn = atol(args[cur_arg + 1]); |
| 3639 | cur_arg += 2; |
| 3640 | } |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 3641 | else if (!strcmp(args[cur_arg], "maxqueue")) { |
| 3642 | newsrv->maxqueue = atol(args[cur_arg + 1]); |
| 3643 | cur_arg += 2; |
| 3644 | } |
Willy Tarreau | 9909fc1 | 2007-11-30 17:42:05 +0100 | [diff] [blame] | 3645 | else if (!strcmp(args[cur_arg], "slowstart")) { |
| 3646 | /* slowstart is stored in seconds */ |
Willy Tarreau | 3259e33 | 2007-12-03 01:51:45 +0100 | [diff] [blame] | 3647 | 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] | 3648 | if (err) { |
| 3649 | Alert("parsing [%s:%d] : unexpected character '%c' in 'slowstart' argument of server %s.\n", |
| 3650 | file, linenum, *err, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3651 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3652 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 3653 | } |
Willy Tarreau | 4554bc1 | 2010-03-26 10:40:49 +0100 | [diff] [blame] | 3654 | if (val < 0) { |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 3655 | Alert("parsing [%s:%d]: invalid value %d for argument '%s' of server %s.\n", |
| 3656 | file, linenum, val, args[cur_arg], newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3657 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3658 | goto out; |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 3659 | } |
Willy Tarreau | 3259e33 | 2007-12-03 01:51:45 +0100 | [diff] [blame] | 3660 | newsrv->slowstart = (val + 999) / 1000; |
Willy Tarreau | 9909fc1 | 2007-11-30 17:42:05 +0100 | [diff] [blame] | 3661 | cur_arg += 2; |
| 3662 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3663 | else if (!defsrv && !strcmp(args[cur_arg], "track")) { |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 3664 | |
| 3665 | if (!*args[cur_arg + 1]) { |
| 3666 | Alert("parsing [%s:%d]: 'track' expects [<proxy>/]<server> as argument.\n", |
| 3667 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3668 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3669 | goto out; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 3670 | } |
| 3671 | |
| 3672 | newsrv->trackit = strdup(args[cur_arg + 1]); |
| 3673 | |
| 3674 | cur_arg += 2; |
| 3675 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3676 | else if (!defsrv && !strcmp(args[cur_arg], "check")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3677 | global.maxsock++; |
| 3678 | do_check = 1; |
| 3679 | cur_arg += 1; |
| 3680 | } |
Willy Tarreau | 9683909 | 2010-03-29 10:02:24 +0200 | [diff] [blame] | 3681 | else if (!defsrv && !strcmp(args[cur_arg], "disabled")) { |
| 3682 | newsrv->state |= SRV_MAINTAIN; |
| 3683 | newsrv->state &= ~SRV_RUNNING; |
| 3684 | newsrv->health = 0; |
| 3685 | cur_arg += 1; |
| 3686 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3687 | else if (!defsrv && !strcmp(args[cur_arg], "observe")) { |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 3688 | if (!strcmp(args[cur_arg + 1], "none")) |
| 3689 | newsrv->observe = HANA_OBS_NONE; |
| 3690 | else if (!strcmp(args[cur_arg + 1], "layer4")) |
| 3691 | newsrv->observe = HANA_OBS_LAYER4; |
| 3692 | else if (!strcmp(args[cur_arg + 1], "layer7")) { |
| 3693 | if (curproxy->mode != PR_MODE_HTTP) { |
| 3694 | Alert("parsing [%s:%d]: '%s' can only be used in http proxies.\n", |
| 3695 | file, linenum, args[cur_arg + 1]); |
| 3696 | err_code |= ERR_ALERT; |
| 3697 | } |
| 3698 | newsrv->observe = HANA_OBS_LAYER7; |
| 3699 | } |
| 3700 | else { |
| 3701 | Alert("parsing [%s:%d]: '%s' expects one of 'none', " |
Willy Tarreau | 53621e0 | 2010-10-22 14:53:40 +0200 | [diff] [blame] | 3702 | "'layer4', 'layer7' but got '%s'\n", |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 3703 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
| 3704 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3705 | goto out; |
| 3706 | } |
| 3707 | |
| 3708 | cur_arg += 2; |
| 3709 | } |
| 3710 | else if (!strcmp(args[cur_arg], "on-error")) { |
| 3711 | if (!strcmp(args[cur_arg + 1], "fastinter")) |
| 3712 | newsrv->onerror = HANA_ONERR_FASTINTER; |
| 3713 | else if (!strcmp(args[cur_arg + 1], "fail-check")) |
| 3714 | newsrv->onerror = HANA_ONERR_FAILCHK; |
| 3715 | else if (!strcmp(args[cur_arg + 1], "sudden-death")) |
| 3716 | newsrv->onerror = HANA_ONERR_SUDDTH; |
| 3717 | else if (!strcmp(args[cur_arg + 1], "mark-down")) |
| 3718 | newsrv->onerror = HANA_ONERR_MARKDWN; |
| 3719 | else { |
| 3720 | Alert("parsing [%s:%d]: '%s' expects one of 'fastinter', " |
Willy Tarreau | 53621e0 | 2010-10-22 14:53:40 +0200 | [diff] [blame] | 3721 | "'fail-check', 'sudden-death' or 'mark-down' but got '%s'\n", |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 3722 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
| 3723 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3724 | goto out; |
| 3725 | } |
| 3726 | |
| 3727 | cur_arg += 2; |
| 3728 | } |
| 3729 | else if (!strcmp(args[cur_arg], "error-limit")) { |
| 3730 | if (!*args[cur_arg + 1]) { |
| 3731 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 3732 | file, linenum, args[cur_arg]); |
| 3733 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3734 | goto out; |
| 3735 | } |
| 3736 | |
| 3737 | newsrv->consecutive_errors_limit = atoi(args[cur_arg + 1]); |
| 3738 | |
| 3739 | if (newsrv->consecutive_errors_limit <= 0) { |
| 3740 | Alert("parsing [%s:%d]: %s has to be > 0.\n", |
| 3741 | file, linenum, args[cur_arg]); |
| 3742 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3743 | goto out; |
| 3744 | } |
Willy Tarreau | f53b25d | 2010-03-15 19:40:37 +0100 | [diff] [blame] | 3745 | cur_arg += 2; |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 3746 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3747 | 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] | 3748 | int port_low, port_high; |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 3749 | struct sockaddr_in *sk; |
| 3750 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3751 | if (!*args[cur_arg + 1]) { |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 3752 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 3753 | 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] | 3754 | file, linenum, "source", "usesrc"); |
| 3755 | #else |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 3756 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>[-<port>]] as argument.\n", |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3757 | file, linenum, "source"); |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 3758 | #endif |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3759 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3760 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3761 | } |
| 3762 | newsrv->state |= SRV_BIND_SRC; |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 3763 | sk = str2sa_range(args[cur_arg + 1], &port_low, &port_high); |
| 3764 | if (!sk) { |
| 3765 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[cur_arg + 1]); |
| 3766 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3767 | goto out; |
| 3768 | } |
| 3769 | newsrv->source_addr = *sk; |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 3770 | |
| 3771 | if (port_low != port_high) { |
| 3772 | int i; |
| 3773 | if (port_low <= 0 || port_low > 65535 || |
| 3774 | port_high <= 0 || port_high > 65535 || |
| 3775 | port_low > port_high) { |
| 3776 | Alert("parsing [%s:%d] : invalid source port range %d-%d.\n", |
| 3777 | file, linenum, port_low, port_high); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3778 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3779 | goto out; |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 3780 | } |
| 3781 | newsrv->sport_range = port_range_alloc_range(port_high - port_low + 1); |
| 3782 | for (i = 0; i < newsrv->sport_range->size; i++) |
| 3783 | newsrv->sport_range->ports[i] = port_low + i; |
| 3784 | } |
| 3785 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3786 | cur_arg += 2; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 3787 | while (*(args[cur_arg])) { |
| 3788 | if (!strcmp(args[cur_arg], "usesrc")) { /* address to use outside */ |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 3789 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) |
| 3790 | #if !defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 3791 | if (newsrv->source_addr.sin_addr.s_addr == INADDR_ANY) { |
| 3792 | Alert("parsing [%s:%d] : '%s' requires an explicit '%s' address.\n", |
| 3793 | file, linenum, "usesrc", "source"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3794 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3795 | goto out; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 3796 | } |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 3797 | #endif |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 3798 | if (!*args[cur_arg + 1]) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 3799 | 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] | 3800 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3801 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3802 | goto out; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 3803 | } |
| 3804 | if (!strcmp(args[cur_arg + 1], "client")) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 3805 | newsrv->state &= ~SRV_TPROXY_MASK; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 3806 | newsrv->state |= SRV_TPROXY_CLI; |
| 3807 | } else if (!strcmp(args[cur_arg + 1], "clientip")) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 3808 | newsrv->state &= ~SRV_TPROXY_MASK; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 3809 | newsrv->state |= SRV_TPROXY_CIP; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 3810 | } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) { |
| 3811 | char *name, *end; |
| 3812 | |
| 3813 | name = args[cur_arg+1] + 7; |
| 3814 | while (isspace(*name)) |
| 3815 | name++; |
| 3816 | |
| 3817 | end = name; |
| 3818 | while (*end && !isspace(*end) && *end != ',' && *end != ')') |
| 3819 | end++; |
| 3820 | |
| 3821 | newsrv->state &= ~SRV_TPROXY_MASK; |
| 3822 | newsrv->state |= SRV_TPROXY_DYN; |
| 3823 | newsrv->bind_hdr_name = calloc(1, end - name + 1); |
| 3824 | newsrv->bind_hdr_len = end - name; |
| 3825 | memcpy(newsrv->bind_hdr_name, name, end - name); |
| 3826 | newsrv->bind_hdr_name[end-name] = '\0'; |
| 3827 | newsrv->bind_hdr_occ = -1; |
| 3828 | |
| 3829 | /* now look for an occurrence number */ |
| 3830 | while (isspace(*end)) |
| 3831 | end++; |
| 3832 | if (*end == ',') { |
| 3833 | end++; |
| 3834 | name = end; |
| 3835 | if (*end == '-') |
| 3836 | end++; |
| 3837 | while (isdigit(*end)) |
| 3838 | end++; |
| 3839 | newsrv->bind_hdr_occ = strl2ic(name, end-name); |
| 3840 | } |
| 3841 | |
| 3842 | if (newsrv->bind_hdr_occ < -MAX_HDR_HISTORY) { |
| 3843 | Alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative" |
| 3844 | " occurrences values smaller than %d.\n", |
| 3845 | file, linenum, MAX_HDR_HISTORY); |
| 3846 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3847 | goto out; |
| 3848 | } |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 3849 | } else { |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 3850 | struct sockaddr_in *sk = str2sa(args[cur_arg + 1]); |
| 3851 | if (!sk) { |
| 3852 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[cur_arg + 1]); |
| 3853 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3854 | goto out; |
| 3855 | } |
| 3856 | newsrv->tproxy_addr = *sk; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 3857 | newsrv->state |= SRV_TPROXY_ADDR; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 3858 | } |
| 3859 | global.last_checks |= LSTCHK_NETADM; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 3860 | #if !defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 3861 | global.last_checks |= LSTCHK_CTTPROXY; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 3862 | #endif |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 3863 | cur_arg += 2; |
| 3864 | continue; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 3865 | #else /* no TPROXY support */ |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 3866 | 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] | 3867 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3868 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3869 | goto out; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 3870 | #endif /* defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) */ |
| 3871 | } /* "usesrc" */ |
| 3872 | |
| 3873 | if (!strcmp(args[cur_arg], "interface")) { /* specifically bind to this interface */ |
| 3874 | #ifdef SO_BINDTODEVICE |
| 3875 | if (!*args[cur_arg + 1]) { |
| 3876 | Alert("parsing [%s:%d] : '%s' : missing interface name.\n", |
| 3877 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3878 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3879 | goto out; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 3880 | } |
| 3881 | if (newsrv->iface_name) |
| 3882 | free(newsrv->iface_name); |
| 3883 | |
| 3884 | newsrv->iface_name = strdup(args[cur_arg + 1]); |
| 3885 | newsrv->iface_len = strlen(newsrv->iface_name); |
| 3886 | global.last_checks |= LSTCHK_NETADM; |
| 3887 | #else |
| 3888 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 3889 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3890 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3891 | goto out; |
Willy Tarreau | 77074d5 | 2006-11-12 23:57:19 +0100 | [diff] [blame] | 3892 | #endif |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 3893 | cur_arg += 2; |
| 3894 | continue; |
| 3895 | } |
| 3896 | /* this keyword in not an option of "source" */ |
| 3897 | break; |
| 3898 | } /* while */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3899 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3900 | 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] | 3901 | Alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n", |
| 3902 | file, linenum, "usesrc", "source"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3903 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3904 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 3905 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3906 | else { |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3907 | if (!defsrv) |
Willy Tarreau | 9683909 | 2010-03-29 10:02:24 +0200 | [diff] [blame] | 3908 | 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] | 3909 | file, linenum, newsrv->id); |
| 3910 | else |
Krzysztof Piotr Oledzki | a9389b1 | 2010-01-05 16:44:17 +0100 | [diff] [blame] | 3911 | 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] | 3912 | file, linenum); |
| 3913 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3914 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3915 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3916 | } |
| 3917 | } |
| 3918 | |
| 3919 | if (do_check) { |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 3920 | if (newsrv->trackit) { |
| 3921 | Alert("parsing [%s:%d]: unable to enable checks and tracking at the same time!\n", |
| 3922 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3923 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3924 | goto out; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 3925 | } |
| 3926 | |
Willy Tarreau | 0f03c6f | 2007-03-25 20:46:19 +0200 | [diff] [blame] | 3927 | if (!newsrv->check_port && newsrv->check_addr.sin_port) |
| 3928 | newsrv->check_port = newsrv->check_addr.sin_port; |
| 3929 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3930 | if (!newsrv->check_port && !(newsrv->state & SRV_MAPPORTS)) |
| 3931 | newsrv->check_port = realport; /* by default */ |
| 3932 | if (!newsrv->check_port) { |
Willy Tarreau | ef00b50 | 2007-01-07 02:40:09 +0100 | [diff] [blame] | 3933 | /* not yet valid, because no port was set on |
| 3934 | * the server either. We'll check if we have |
| 3935 | * a known port on the first listener. |
| 3936 | */ |
| 3937 | struct listener *l; |
| 3938 | l = curproxy->listen; |
| 3939 | if (l) { |
| 3940 | int port; |
| 3941 | port = (l->addr.ss_family == AF_INET6) |
| 3942 | ? ntohs(((struct sockaddr_in6 *)(&l->addr))->sin6_port) |
| 3943 | : ntohs(((struct sockaddr_in *)(&l->addr))->sin_port); |
| 3944 | newsrv->check_port = port; |
| 3945 | } |
| 3946 | } |
| 3947 | if (!newsrv->check_port) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3948 | Alert("parsing [%s:%d] : server %s has neither service port nor check port. Check has been disabled.\n", |
| 3949 | file, linenum, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3950 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3951 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3952 | } |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 3953 | |
Cyril Bonté | c9f825f | 2010-03-17 18:56:31 +0100 | [diff] [blame] | 3954 | /* Allocate buffer for partial check results... */ |
Willy Tarreau | 43961d5 | 2010-10-04 20:39:20 +0200 | [diff] [blame] | 3955 | if ((newsrv->check_data = calloc(global.tune.chksize, sizeof(char))) == NULL) { |
Cyril Bonté | c9f825f | 2010-03-17 18:56:31 +0100 | [diff] [blame] | 3956 | Alert("parsing [%s:%d] : out of memory while allocating check buffer.\n", file, linenum); |
| 3957 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3958 | goto out; |
| 3959 | } |
| 3960 | |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 3961 | newsrv->check_status = HCHK_STATUS_INI; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3962 | newsrv->state |= SRV_CHECKED; |
| 3963 | } |
| 3964 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3965 | if (!defsrv) { |
| 3966 | if (newsrv->state & SRV_BACKUP) |
| 3967 | curproxy->srv_bck++; |
| 3968 | else |
| 3969 | curproxy->srv_act++; |
Willy Tarreau | b625a08 | 2007-11-26 01:15:43 +0100 | [diff] [blame] | 3970 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3971 | newsrv->prev_state = newsrv->state; |
| 3972 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3973 | } |
| 3974 | else if (!strcmp(args[0], "log")) { /* syslog server address */ |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 3975 | struct logsrv logsrv; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3976 | int facility; |
| 3977 | |
| 3978 | if (*(args[1]) && *(args[2]) == 0 && !strcmp(args[1], "global")) { |
| 3979 | curproxy->logfac1 = global.logfac1; |
| 3980 | curproxy->logsrv1 = global.logsrv1; |
| 3981 | curproxy->loglev1 = global.loglev1; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 3982 | curproxy->minlvl1 = global.minlvl1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3983 | curproxy->logfac2 = global.logfac2; |
| 3984 | curproxy->logsrv2 = global.logsrv2; |
| 3985 | curproxy->loglev2 = global.loglev2; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 3986 | curproxy->minlvl2 = global.minlvl2; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3987 | } |
| 3988 | else if (*(args[1]) && *(args[2])) { |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 3989 | int level, minlvl; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3990 | |
| 3991 | facility = get_log_facility(args[2]); |
| 3992 | if (facility < 0) { |
| 3993 | Alert("parsing [%s:%d] : unknown log facility '%s'\n", file, linenum, args[2]); |
| 3994 | exit(1); |
| 3995 | } |
| 3996 | |
| 3997 | level = 7; /* max syslog level = debug */ |
| 3998 | if (*(args[3])) { |
| 3999 | level = get_log_level(args[3]); |
| 4000 | if (level < 0) { |
| 4001 | Alert("parsing [%s:%d] : unknown optional log level '%s'\n", file, linenum, args[3]); |
| 4002 | exit(1); |
| 4003 | } |
| 4004 | } |
| 4005 | |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 4006 | minlvl = 0; /* limit syslog level to this level (emerg) */ |
| 4007 | if (*(args[4])) { |
| 4008 | minlvl = get_log_level(args[4]); |
| 4009 | if (level < 0) { |
| 4010 | Alert("parsing [%s:%d] : unknown optional minimum log level '%s'\n", file, linenum, args[4]); |
| 4011 | exit(1); |
| 4012 | } |
| 4013 | } |
| 4014 | |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 4015 | if (args[1][0] == '/') { |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4016 | struct sockaddr_un *sk = str2sun(args[1]); |
| 4017 | if (!sk) { |
| 4018 | Alert("parsing [%s:%d] : Socket path '%s' too long (max %d)\n", file, linenum, |
| 4019 | args[1], (int)sizeof(sk->sun_path) - 1); |
| 4020 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4021 | goto out; |
| 4022 | } |
| 4023 | logsrv.u.un = *sk; |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 4024 | logsrv.u.addr.sa_family = AF_UNIX; |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 4025 | } else { |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4026 | struct sockaddr_in *sk = str2sa(args[1]); |
| 4027 | if (!sk) { |
| 4028 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[1]); |
| 4029 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4030 | goto out; |
| 4031 | } |
| 4032 | logsrv.u.in = *sk; |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 4033 | logsrv.u.addr.sa_family = AF_INET; |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 4034 | if (!logsrv.u.in.sin_port) { |
| 4035 | logsrv.u.in.sin_port = |
| 4036 | htons(SYSLOG_PORT); |
| 4037 | } |
| 4038 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4039 | |
| 4040 | if (curproxy->logfac1 == -1) { |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 4041 | curproxy->logsrv1 = logsrv; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4042 | curproxy->logfac1 = facility; |
| 4043 | curproxy->loglev1 = level; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 4044 | curproxy->minlvl1 = minlvl; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4045 | } |
| 4046 | else if (curproxy->logfac2 == -1) { |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 4047 | curproxy->logsrv2 = logsrv; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4048 | curproxy->logfac2 = facility; |
| 4049 | curproxy->loglev2 = level; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 4050 | curproxy->minlvl2 = minlvl; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4051 | } |
| 4052 | else { |
| 4053 | Alert("parsing [%s:%d] : too many syslog servers\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4054 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4055 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4056 | } |
| 4057 | } |
| 4058 | else { |
| 4059 | Alert("parsing [%s:%d] : 'log' expects either <address[:port]> and <facility> or 'global' as arguments.\n", |
| 4060 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4061 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4062 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4063 | } |
| 4064 | } |
| 4065 | 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] | 4066 | int cur_arg; |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4067 | struct sockaddr_in *sk; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4068 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4069 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4070 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4071 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4072 | if (!*args[1]) { |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4073 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optionally '%s' <addr>, and '%s' <name>.\n", |
| 4074 | file, linenum, "source", "usesrc", "interface"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4075 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4076 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4077 | } |
Willy Tarreau | 368480c | 2009-03-01 08:27:21 +0100 | [diff] [blame] | 4078 | |
| 4079 | /* we must first clear any optional default setting */ |
| 4080 | curproxy->options &= ~PR_O_TPXY_MASK; |
| 4081 | free(curproxy->iface_name); |
| 4082 | curproxy->iface_name = NULL; |
| 4083 | curproxy->iface_len = 0; |
| 4084 | |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4085 | sk = str2sa(args[1]); |
| 4086 | if (!sk) { |
| 4087 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[1]); |
| 4088 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4089 | goto out; |
| 4090 | } |
| 4091 | curproxy->source_addr = *sk; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4092 | curproxy->options |= PR_O_BIND_SRC; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4093 | |
| 4094 | cur_arg = 2; |
| 4095 | while (*(args[cur_arg])) { |
| 4096 | if (!strcmp(args[cur_arg], "usesrc")) { /* address to use outside */ |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4097 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) |
| 4098 | #if !defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4099 | if (curproxy->source_addr.sin_addr.s_addr == INADDR_ANY) { |
| 4100 | Alert("parsing [%s:%d] : '%s' requires an explicit 'source' address.\n", |
| 4101 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4102 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4103 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4104 | } |
| 4105 | #endif |
| 4106 | if (!*args[cur_arg + 1]) { |
| 4107 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n", |
| 4108 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4109 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4110 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4111 | } |
| 4112 | |
| 4113 | if (!strcmp(args[cur_arg + 1], "client")) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4114 | curproxy->options &= ~PR_O_TPXY_MASK; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4115 | curproxy->options |= PR_O_TPXY_CLI; |
| 4116 | } else if (!strcmp(args[cur_arg + 1], "clientip")) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4117 | curproxy->options &= ~PR_O_TPXY_MASK; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4118 | curproxy->options |= PR_O_TPXY_CIP; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4119 | } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) { |
| 4120 | char *name, *end; |
| 4121 | |
| 4122 | name = args[cur_arg+1] + 7; |
| 4123 | while (isspace(*name)) |
| 4124 | name++; |
| 4125 | |
| 4126 | end = name; |
| 4127 | while (*end && !isspace(*end) && *end != ',' && *end != ')') |
| 4128 | end++; |
| 4129 | |
| 4130 | curproxy->options &= ~PR_O_TPXY_MASK; |
| 4131 | curproxy->options |= PR_O_TPXY_DYN; |
| 4132 | curproxy->bind_hdr_name = calloc(1, end - name + 1); |
| 4133 | curproxy->bind_hdr_len = end - name; |
| 4134 | memcpy(curproxy->bind_hdr_name, name, end - name); |
| 4135 | curproxy->bind_hdr_name[end-name] = '\0'; |
| 4136 | curproxy->bind_hdr_occ = -1; |
| 4137 | |
| 4138 | /* now look for an occurrence number */ |
| 4139 | while (isspace(*end)) |
| 4140 | end++; |
| 4141 | if (*end == ',') { |
| 4142 | end++; |
| 4143 | name = end; |
| 4144 | if (*end == '-') |
| 4145 | end++; |
| 4146 | while (isdigit(*end)) |
| 4147 | end++; |
| 4148 | curproxy->bind_hdr_occ = strl2ic(name, end-name); |
| 4149 | } |
| 4150 | |
| 4151 | if (curproxy->bind_hdr_occ < -MAX_HDR_HISTORY) { |
| 4152 | Alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative" |
| 4153 | " occurrences values smaller than %d.\n", |
| 4154 | file, linenum, MAX_HDR_HISTORY); |
| 4155 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4156 | goto out; |
| 4157 | } |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4158 | } else { |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4159 | struct sockaddr_in *sk = str2sa(args[cur_arg + 1]); |
| 4160 | if (!sk) { |
| 4161 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[cur_arg + 1]); |
| 4162 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4163 | goto out; |
| 4164 | } |
| 4165 | curproxy->tproxy_addr = *sk; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4166 | curproxy->options |= PR_O_TPXY_ADDR; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4167 | } |
| 4168 | global.last_checks |= LSTCHK_NETADM; |
| 4169 | #if !defined(CONFIG_HAP_LINUX_TPROXY) |
| 4170 | global.last_checks |= LSTCHK_CTTPROXY; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4171 | #endif |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4172 | #else /* no TPROXY support */ |
| 4173 | 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] | 4174 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4175 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4176 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4177 | #endif |
| 4178 | cur_arg += 2; |
| 4179 | continue; |
Willy Tarreau | 77074d5 | 2006-11-12 23:57:19 +0100 | [diff] [blame] | 4180 | } |
| 4181 | |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4182 | if (!strcmp(args[cur_arg], "interface")) { /* specifically bind to this interface */ |
| 4183 | #ifdef SO_BINDTODEVICE |
| 4184 | if (!*args[cur_arg + 1]) { |
| 4185 | Alert("parsing [%s:%d] : '%s' : missing interface name.\n", |
| 4186 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4187 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4188 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4189 | } |
| 4190 | if (curproxy->iface_name) |
| 4191 | free(curproxy->iface_name); |
| 4192 | |
| 4193 | curproxy->iface_name = strdup(args[cur_arg + 1]); |
| 4194 | curproxy->iface_len = strlen(curproxy->iface_name); |
| 4195 | global.last_checks |= LSTCHK_NETADM; |
| 4196 | #else |
| 4197 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 4198 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4199 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4200 | goto out; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4201 | #endif |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4202 | cur_arg += 2; |
| 4203 | continue; |
| 4204 | } |
| 4205 | Alert("parsing [%s:%d] : '%s' only supports optional keywords '%s' and '%s'.\n", |
| 4206 | file, linenum, args[0], "inteface", "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4207 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4208 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 4209 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4210 | } |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 4211 | else if (!strcmp(args[0], "usesrc")) { /* address to use outside: needs "source" first */ |
| 4212 | Alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n", |
| 4213 | file, linenum, "usesrc", "source"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4214 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4215 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 4216 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4217 | 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] | 4218 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4219 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 4220 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4221 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4222 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4223 | } |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4224 | |
| 4225 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 4226 | ACL_DIR_REQ, ACT_REPLACE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4227 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4228 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4229 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4230 | } |
| 4231 | else if (!strcmp(args[0], "reqdel")) { /* delete request header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4232 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 4233 | ACL_DIR_REQ, ACT_REMOVE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4234 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4235 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4236 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4237 | } |
| 4238 | 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] | 4239 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 4240 | ACL_DIR_REQ, ACT_DENY, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4241 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4242 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4243 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4244 | } |
| 4245 | 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] | 4246 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 4247 | ACL_DIR_REQ, ACT_PASS, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4248 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4249 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4250 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4251 | } |
| 4252 | 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] | 4253 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 4254 | ACL_DIR_REQ, ACT_ALLOW, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4255 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4256 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4257 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4258 | } |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 4259 | 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] | 4260 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 4261 | ACL_DIR_REQ, ACT_TARPIT, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4262 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4263 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4264 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 4265 | } |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 4266 | 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] | 4267 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 4268 | ACL_DIR_REQ, ACT_SETBE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4269 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4270 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4271 | goto out; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 4272 | } |
| 4273 | 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] | 4274 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 4275 | ACL_DIR_REQ, ACT_SETBE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4276 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4277 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4278 | goto out; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 4279 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4280 | 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] | 4281 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4282 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 4283 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4284 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4285 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4286 | } |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4287 | |
| 4288 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 4289 | ACL_DIR_REQ, ACT_REPLACE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4290 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4291 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4292 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4293 | } |
| 4294 | 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] | 4295 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 4296 | ACL_DIR_REQ, ACT_REMOVE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4297 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4298 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4299 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4300 | } |
| 4301 | 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] | 4302 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 4303 | ACL_DIR_REQ, ACT_DENY, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4304 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4305 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4306 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4307 | } |
| 4308 | 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] | 4309 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 4310 | ACL_DIR_REQ, ACT_PASS, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4311 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4312 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4313 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4314 | } |
| 4315 | 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] | 4316 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 4317 | ACL_DIR_REQ, ACT_ALLOW, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4318 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4319 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4320 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4321 | } |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 4322 | 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] | 4323 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 4324 | ACL_DIR_REQ, ACT_TARPIT, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4325 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4326 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4327 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 4328 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4329 | else if (!strcmp(args[0], "reqadd")) { /* add request header */ |
Willy Tarreau | f4f0412 | 2010-01-28 18:10:50 +0100 | [diff] [blame] | 4330 | struct cond_wordlist *wl; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 4331 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4332 | if (curproxy == &defproxy) { |
| 4333 | 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] | 4334 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4335 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4336 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4337 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4338 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4339 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4340 | if (*(args[1]) == 0) { |
| 4341 | 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] | 4342 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4343 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4344 | } |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 4345 | |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 4346 | if ((strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0)) { |
| 4347 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args+2)) == NULL) { |
| 4348 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition.\n", |
| 4349 | file, linenum, args[0]); |
| 4350 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4351 | goto out; |
| 4352 | } |
| 4353 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
| 4354 | } |
| 4355 | else if (*args[2]) { |
| 4356 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 4357 | file, linenum, args[0], args[2]); |
| 4358 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4359 | goto out; |
| 4360 | } |
| 4361 | |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 4362 | wl = calloc(1, sizeof(*wl)); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 4363 | wl->cond = cond; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 4364 | wl->s = strdup(args[1]); |
| 4365 | LIST_ADDQ(&curproxy->req_add, &wl->list); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 4366 | warnif_misplaced_reqadd(curproxy, file, linenum, args[0]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4367 | } |
| 4368 | 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] | 4369 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4370 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 4371 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4372 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4373 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4374 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4375 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4376 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 4377 | ACL_DIR_RTR, ACT_REPLACE, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 4378 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4379 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4380 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4381 | } |
| 4382 | else if (!strcmp(args[0], "rspdel")) { /* delete response header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4383 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 4384 | ACL_DIR_RTR, ACT_REMOVE, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 4385 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4386 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4387 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4388 | } |
| 4389 | else if (!strcmp(args[0], "rspdeny")) { /* block response header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4390 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 4391 | ACL_DIR_RTR, ACT_DENY, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 4392 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4393 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4394 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4395 | } |
| 4396 | 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] | 4397 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4398 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 4399 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4400 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4401 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4402 | } |
| 4403 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4404 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 4405 | ACL_DIR_RTR, ACT_REPLACE, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 4406 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4407 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4408 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4409 | } |
| 4410 | 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] | 4411 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 4412 | ACL_DIR_RTR, ACT_REMOVE, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 4413 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4414 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4415 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4416 | } |
| 4417 | 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] | 4418 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 4419 | ACL_DIR_RTR, ACT_DENY, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 4420 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4421 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4422 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4423 | } |
| 4424 | else if (!strcmp(args[0], "rspadd")) { /* add response header */ |
Willy Tarreau | f4f0412 | 2010-01-28 18:10:50 +0100 | [diff] [blame] | 4425 | struct cond_wordlist *wl; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 4426 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4427 | if (curproxy == &defproxy) { |
| 4428 | 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] | 4429 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4430 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4431 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4432 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4433 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4434 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4435 | if (*(args[1]) == 0) { |
| 4436 | 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] | 4437 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4438 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4439 | } |
| 4440 | |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 4441 | if ((strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0)) { |
| 4442 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args+2)) == NULL) { |
| 4443 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition.\n", |
| 4444 | file, linenum, args[0]); |
| 4445 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4446 | goto out; |
| 4447 | } |
| 4448 | err_code |= warnif_cond_requires_req(cond, file, linenum); |
| 4449 | } |
| 4450 | else if (*args[2]) { |
| 4451 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 4452 | file, linenum, args[0], args[2]); |
| 4453 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4454 | goto out; |
| 4455 | } |
| 4456 | |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 4457 | wl = calloc(1, sizeof(*wl)); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 4458 | wl->cond = cond; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 4459 | wl->s = strdup(args[1]); |
| 4460 | LIST_ADDQ(&curproxy->rsp_add, &wl->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4461 | } |
| 4462 | else if (!strcmp(args[0], "errorloc") || |
| 4463 | !strcmp(args[0], "errorloc302") || |
| 4464 | !strcmp(args[0], "errorloc303")) { /* error location */ |
| 4465 | int errnum, errlen; |
| 4466 | char *err; |
| 4467 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4468 | 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] | 4469 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4470 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4471 | if (*(args[2]) == 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 4472 | 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] | 4473 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4474 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4475 | } |
| 4476 | |
| 4477 | errnum = atol(args[1]); |
| 4478 | if (!strcmp(args[0], "errorloc303")) { |
| 4479 | err = malloc(strlen(HTTP_303) + strlen(args[2]) + 5); |
| 4480 | errlen = sprintf(err, "%s%s\r\n\r\n", HTTP_303, args[2]); |
| 4481 | } else { |
| 4482 | err = malloc(strlen(HTTP_302) + strlen(args[2]) + 5); |
| 4483 | errlen = sprintf(err, "%s%s\r\n\r\n", HTTP_302, args[2]); |
| 4484 | } |
| 4485 | |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 4486 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) { |
| 4487 | if (http_err_codes[rc] == errnum) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 4488 | chunk_destroy(&curproxy->errmsg[rc]); |
| 4489 | chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 4490 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4491 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4492 | } |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 4493 | |
| 4494 | if (rc >= HTTP_ERR_SIZE) { |
| 4495 | Warning("parsing [%s:%d] : status code %d not handled, error relocation will be ignored.\n", |
| 4496 | file, linenum, errnum); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4497 | free(err); |
| 4498 | } |
| 4499 | } |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 4500 | else if (!strcmp(args[0], "errorfile")) { /* error message from a file */ |
| 4501 | int errnum, errlen, fd; |
| 4502 | char *err; |
| 4503 | struct stat stat; |
| 4504 | |
| 4505 | 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] | 4506 | err_code |= ERR_WARN; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 4507 | |
| 4508 | if (*(args[2]) == 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 4509 | 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] | 4510 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4511 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 4512 | } |
| 4513 | |
| 4514 | fd = open(args[2], O_RDONLY); |
| 4515 | if ((fd < 0) || (fstat(fd, &stat) < 0)) { |
| 4516 | Alert("parsing [%s:%d] : error opening file <%s> for custom error message <%s>.\n", |
| 4517 | file, linenum, args[2], args[1]); |
| 4518 | if (fd >= 0) |
| 4519 | close(fd); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4520 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4521 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 4522 | } |
| 4523 | |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 4524 | if (stat.st_size <= global.tune.bufsize) { |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 4525 | errlen = stat.st_size; |
| 4526 | } else { |
| 4527 | 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] | 4528 | file, linenum, args[2], global.tune.bufsize); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4529 | err_code |= ERR_WARN; |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 4530 | errlen = global.tune.bufsize; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 4531 | } |
| 4532 | |
| 4533 | err = malloc(errlen); /* malloc() must succeed during parsing */ |
| 4534 | errnum = read(fd, err, errlen); |
| 4535 | if (errnum != errlen) { |
| 4536 | Alert("parsing [%s:%d] : error reading file <%s> for custom error message <%s>.\n", |
| 4537 | file, linenum, args[2], args[1]); |
| 4538 | close(fd); |
| 4539 | free(err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4540 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4541 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 4542 | } |
| 4543 | close(fd); |
| 4544 | |
| 4545 | errnum = atol(args[1]); |
| 4546 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) { |
| 4547 | if (http_err_codes[rc] == errnum) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 4548 | chunk_destroy(&curproxy->errmsg[rc]); |
| 4549 | chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen); |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 4550 | break; |
| 4551 | } |
| 4552 | } |
| 4553 | |
| 4554 | if (rc >= HTTP_ERR_SIZE) { |
| 4555 | Warning("parsing [%s:%d] : status code %d not handled, error customization will be ignored.\n", |
| 4556 | file, linenum, errnum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4557 | err_code |= ERR_WARN; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 4558 | free(err); |
| 4559 | } |
| 4560 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4561 | else { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 4562 | struct cfg_kw_list *kwl; |
| 4563 | int index; |
| 4564 | |
| 4565 | list_for_each_entry(kwl, &cfg_keywords.list, list) { |
| 4566 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 4567 | if (kwl->kw[index].section != CFG_LISTEN) |
| 4568 | continue; |
| 4569 | if (strcmp(kwl->kw[index].kw, args[0]) == 0) { |
| 4570 | /* prepare error message just in case */ |
| 4571 | snprintf(trash, sizeof(trash), |
| 4572 | "error near '%s' in %s section", args[0], cursection); |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 4573 | rc = kwl->kw[index].parse(args, CFG_LISTEN, curproxy, &defproxy, trash, sizeof(trash)); |
| 4574 | if (rc < 0) { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 4575 | Alert("parsing [%s:%d] : %s\n", file, linenum, trash); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4576 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4577 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 4578 | } |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 4579 | else if (rc > 0) { |
| 4580 | Warning("parsing [%s:%d] : %s\n", file, linenum, trash); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4581 | err_code |= ERR_WARN; |
| 4582 | goto out; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 4583 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4584 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 4585 | } |
| 4586 | } |
| 4587 | } |
| 4588 | |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 4589 | 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] | 4590 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4591 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4592 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4593 | out: |
| 4594 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4595 | } |
| 4596 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 4597 | int |
| 4598 | cfg_parse_users(const char *file, int linenum, char **args, int kwm) |
| 4599 | { |
| 4600 | |
| 4601 | int err_code = 0; |
| 4602 | const char *err; |
| 4603 | |
| 4604 | if (!strcmp(args[0], "userlist")) { /* new userlist */ |
| 4605 | struct userlist *newul; |
| 4606 | |
| 4607 | if (!*args[1]) { |
| 4608 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 4609 | file, linenum, args[0]); |
| 4610 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4611 | goto out; |
| 4612 | } |
| 4613 | |
| 4614 | err = invalid_char(args[1]); |
| 4615 | if (err) { |
| 4616 | Alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 4617 | file, linenum, *err, args[0], args[1]); |
| 4618 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4619 | goto out; |
| 4620 | } |
| 4621 | |
| 4622 | for (newul = userlist; newul; newul = newul->next) |
| 4623 | if (!strcmp(newul->name, args[1])) { |
| 4624 | Warning("parsing [%s:%d]: ignoring duplicated userlist '%s'.\n", |
| 4625 | file, linenum, args[1]); |
| 4626 | err_code |= ERR_WARN; |
| 4627 | goto out; |
| 4628 | } |
| 4629 | |
| 4630 | newul = (struct userlist *)calloc(1, sizeof(struct userlist)); |
| 4631 | if (!newul) { |
| 4632 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 4633 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4634 | goto out; |
| 4635 | } |
| 4636 | |
| 4637 | newul->groupusers = calloc(MAX_AUTH_GROUPS, sizeof(char *)); |
| 4638 | newul->name = strdup(args[1]); |
| 4639 | |
| 4640 | if (!newul->groupusers | !newul->name) { |
| 4641 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 4642 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4643 | goto out; |
| 4644 | } |
| 4645 | |
| 4646 | newul->next = userlist; |
| 4647 | userlist = newul; |
| 4648 | |
| 4649 | } else if (!strcmp(args[0], "group")) { /* new group */ |
| 4650 | int cur_arg, i; |
| 4651 | const char *err; |
| 4652 | |
| 4653 | if (!*args[1]) { |
| 4654 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 4655 | file, linenum, args[0]); |
| 4656 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4657 | goto out; |
| 4658 | } |
| 4659 | |
| 4660 | err = invalid_char(args[1]); |
| 4661 | if (err) { |
| 4662 | Alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 4663 | file, linenum, *err, args[0], args[1]); |
| 4664 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4665 | goto out; |
| 4666 | } |
| 4667 | |
| 4668 | for(i = 0; i < userlist->grpcnt; i++) |
| 4669 | if (!strcmp(userlist->groups[i], args[1])) { |
| 4670 | Warning("parsing [%s:%d]: ignoring duplicated group '%s' in userlist '%s'.\n", |
| 4671 | file, linenum, args[1], userlist->name); |
| 4672 | err_code |= ERR_ALERT; |
| 4673 | goto out; |
| 4674 | } |
| 4675 | |
| 4676 | if (userlist->grpcnt >= MAX_AUTH_GROUPS) { |
| 4677 | Alert("parsing [%s:%d]: too many groups (%u) in in userlist '%s' while adding group '%s'.\n", |
| 4678 | file, linenum, MAX_AUTH_GROUPS, userlist->name, args[1]); |
| 4679 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4680 | goto out; |
| 4681 | } |
| 4682 | |
| 4683 | cur_arg = 2; |
| 4684 | |
| 4685 | while (*args[cur_arg]) { |
| 4686 | if (!strcmp(args[cur_arg], "users")) { |
| 4687 | userlist->groupusers[userlist->grpcnt] = strdup(args[cur_arg + 1]); |
| 4688 | cur_arg += 2; |
| 4689 | continue; |
| 4690 | } else { |
| 4691 | Alert("parsing [%s:%d]: '%s' only supports 'users' option.\n", |
| 4692 | file, linenum, args[0]); |
| 4693 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4694 | goto out; |
| 4695 | } |
| 4696 | } |
| 4697 | |
| 4698 | userlist->groups[userlist->grpcnt++] = strdup(args[1]); |
| 4699 | } else if (!strcmp(args[0], "user")) { /* new user */ |
| 4700 | struct auth_users *newuser; |
| 4701 | int cur_arg; |
| 4702 | |
| 4703 | if (!*args[1]) { |
| 4704 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 4705 | file, linenum, args[0]); |
| 4706 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4707 | goto out; |
| 4708 | } |
| 4709 | |
| 4710 | for (newuser = userlist->users; newuser; newuser = newuser->next) |
| 4711 | if (!strcmp(newuser->user, args[1])) { |
| 4712 | Warning("parsing [%s:%d]: ignoring duplicated user '%s' in userlist '%s'.\n", |
| 4713 | file, linenum, args[1], userlist->name); |
| 4714 | err_code |= ERR_ALERT; |
| 4715 | goto out; |
| 4716 | } |
| 4717 | |
| 4718 | newuser = (struct auth_users *)calloc(1, sizeof(struct auth_users)); |
| 4719 | if (!newuser) { |
| 4720 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 4721 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4722 | goto out; |
| 4723 | } |
| 4724 | |
| 4725 | newuser->user = strdup(args[1]); |
| 4726 | |
| 4727 | newuser->next = userlist->users; |
| 4728 | userlist->users = newuser; |
| 4729 | |
| 4730 | cur_arg = 2; |
| 4731 | |
| 4732 | while (*args[cur_arg]) { |
| 4733 | if (!strcmp(args[cur_arg], "password")) { |
| 4734 | #ifndef CONFIG_HAP_CRYPT |
| 4735 | Warning("parsing [%s:%d]: no crypt(3) support compiled, encrypted passwords will not work.\n", |
| 4736 | file, linenum); |
| 4737 | err_code |= ERR_ALERT; |
| 4738 | #endif |
| 4739 | newuser->pass = strdup(args[cur_arg + 1]); |
| 4740 | cur_arg += 2; |
| 4741 | continue; |
| 4742 | } else if (!strcmp(args[cur_arg], "insecure-password")) { |
| 4743 | newuser->pass = strdup(args[cur_arg + 1]); |
| 4744 | newuser->flags |= AU_O_INSECURE; |
| 4745 | cur_arg += 2; |
| 4746 | continue; |
| 4747 | } else if (!strcmp(args[cur_arg], "groups")) { |
Willy Tarreau | b4c06b7 | 2010-02-02 11:28:20 +0100 | [diff] [blame] | 4748 | newuser->u.groups = strdup(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 4749 | cur_arg += 2; |
| 4750 | continue; |
| 4751 | } else { |
| 4752 | Alert("parsing [%s:%d]: '%s' only supports 'password', 'insecure-password' and 'groups' options.\n", |
| 4753 | file, linenum, args[0]); |
| 4754 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4755 | goto out; |
| 4756 | } |
| 4757 | } |
| 4758 | } else { |
| 4759 | Alert("parsing [%s:%d]: unknown keyword '%s' in '%s' section\n", file, linenum, args[0], "users"); |
| 4760 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4761 | } |
| 4762 | |
| 4763 | out: |
| 4764 | return err_code; |
| 4765 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4766 | |
| 4767 | /* |
| 4768 | * This function reads and parses the configuration file given in the argument. |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 4769 | * Returns the error code, 0 if OK, or any combination of : |
| 4770 | * - ERR_ABORT: must abort ASAP |
| 4771 | * - ERR_FATAL: we can continue parsing but not start the service |
| 4772 | * - ERR_WARN: a warning has been emitted |
| 4773 | * - ERR_ALERT: an alert has been emitted |
| 4774 | * Only the two first ones can stop processing, the two others are just |
| 4775 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4776 | */ |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 4777 | int readcfgfile(const char *file) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4778 | { |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 4779 | char thisline[LINESIZE]; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4780 | FILE *f; |
| 4781 | int linenum = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4782 | int confsect = CFG_NONE; |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 4783 | int err_code = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4784 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4785 | if ((f=fopen(file,"r")) == NULL) |
| 4786 | return -1; |
| 4787 | |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 4788 | while (fgets(thisline, sizeof(thisline), f) != NULL) { |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 4789 | int arg, kwm = KWM_STD; |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 4790 | char *end; |
| 4791 | char *args[MAX_LINE_ARGS + 1]; |
| 4792 | char *line = thisline; |
| 4793 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4794 | linenum++; |
| 4795 | |
| 4796 | end = line + strlen(line); |
| 4797 | |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 4798 | if (end-line == sizeof(thisline)-1 && *(end-1) != '\n') { |
| 4799 | /* Check if we reached the limit and the last char is not \n. |
| 4800 | * Watch out for the last line without the terminating '\n'! |
| 4801 | */ |
| 4802 | Alert("parsing [%s:%d]: line too long, limit: %d.\n", |
Willy Tarreau | 5e4a6f1 | 2009-04-11 19:42:49 +0200 | [diff] [blame] | 4803 | file, linenum, (int)sizeof(thisline)-1); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 4804 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 4805 | } |
| 4806 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4807 | /* skip leading spaces */ |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 4808 | while (isspace((unsigned char)*line)) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4809 | line++; |
| 4810 | |
| 4811 | arg = 0; |
| 4812 | args[arg] = line; |
| 4813 | |
| 4814 | while (*line && arg < MAX_LINE_ARGS) { |
| 4815 | /* first, we'll replace \\, \<space>, \#, \r, \n, \t, \xXX with their |
| 4816 | * C equivalent value. Other combinations left unchanged (eg: \1). |
| 4817 | */ |
| 4818 | if (*line == '\\') { |
| 4819 | int skip = 0; |
| 4820 | if (line[1] == ' ' || line[1] == '\\' || line[1] == '#') { |
| 4821 | *line = line[1]; |
| 4822 | skip = 1; |
| 4823 | } |
| 4824 | else if (line[1] == 'r') { |
| 4825 | *line = '\r'; |
| 4826 | skip = 1; |
| 4827 | } |
| 4828 | else if (line[1] == 'n') { |
| 4829 | *line = '\n'; |
| 4830 | skip = 1; |
| 4831 | } |
| 4832 | else if (line[1] == 't') { |
| 4833 | *line = '\t'; |
| 4834 | skip = 1; |
| 4835 | } |
| 4836 | else if (line[1] == 'x') { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4837 | if ((line + 3 < end) && ishex(line[2]) && ishex(line[3])) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4838 | unsigned char hex1, hex2; |
| 4839 | hex1 = toupper(line[2]) - '0'; |
| 4840 | hex2 = toupper(line[3]) - '0'; |
| 4841 | if (hex1 > 9) hex1 -= 'A' - '9' - 1; |
| 4842 | if (hex2 > 9) hex2 -= 'A' - '9' - 1; |
| 4843 | *line = (hex1<<4) + hex2; |
| 4844 | skip = 3; |
| 4845 | } |
| 4846 | else { |
| 4847 | 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] | 4848 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4849 | } |
| 4850 | } |
| 4851 | if (skip) { |
Cyril Bonté | dd1b01d | 2009-12-06 13:43:42 +0100 | [diff] [blame] | 4852 | memmove(line + 1, line + 1 + skip, end - (line + skip)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4853 | end -= skip; |
| 4854 | } |
| 4855 | line++; |
| 4856 | } |
| 4857 | else if (*line == '#' || *line == '\n' || *line == '\r') { |
| 4858 | /* end of string, end of loop */ |
| 4859 | *line = 0; |
| 4860 | break; |
| 4861 | } |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 4862 | else if (isspace((unsigned char)*line)) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4863 | /* a non-escaped space is an argument separator */ |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 4864 | *line++ = '\0'; |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 4865 | while (isspace((unsigned char)*line)) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4866 | line++; |
| 4867 | args[++arg] = line; |
| 4868 | } |
| 4869 | else { |
| 4870 | line++; |
| 4871 | } |
| 4872 | } |
| 4873 | |
| 4874 | /* empty line */ |
| 4875 | if (!**args) |
| 4876 | continue; |
| 4877 | |
Willy Tarreau | 7bb651e | 2009-11-09 21:16:53 +0100 | [diff] [blame] | 4878 | if (*line) { |
| 4879 | /* we had to stop due to too many args. |
| 4880 | * Let's terminate the string, print the offending part then cut the |
| 4881 | * last arg. |
| 4882 | */ |
| 4883 | while (*line && *line != '#' && *line != '\n' && *line != '\r') |
| 4884 | line++; |
| 4885 | *line = '\0'; |
| 4886 | |
Krzysztof Piotr Oledzki | 500b8f0 | 2009-12-15 22:34:51 +0100 | [diff] [blame] | 4887 | 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] | 4888 | file, linenum, arg + 1, (long)(args[arg] - thisline + 1), args[arg]); |
Willy Tarreau | 7bb651e | 2009-11-09 21:16:53 +0100 | [diff] [blame] | 4889 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4890 | args[arg] = line; |
| 4891 | } |
| 4892 | |
Willy Tarreau | 540abe4 | 2007-05-02 20:50:16 +0200 | [diff] [blame] | 4893 | /* zero out remaining args and ensure that at least one entry |
| 4894 | * is zeroed out. |
| 4895 | */ |
| 4896 | while (++arg <= MAX_LINE_ARGS) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4897 | args[arg] = line; |
| 4898 | } |
| 4899 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 4900 | /* check for keyword modifiers "no" and "default" */ |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 4901 | if (!strcmp(args[0], "no")) { |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 4902 | kwm = KWM_NO; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 4903 | for (arg=0; *args[arg+1]; arg++) |
| 4904 | args[arg] = args[arg+1]; // shift args after inversion |
| 4905 | } |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 4906 | else if (!strcmp(args[0], "default")) { |
| 4907 | kwm = KWM_DEF; |
| 4908 | for (arg=0; *args[arg+1]; arg++) |
| 4909 | args[arg] = args[arg+1]; // shift args after inversion |
| 4910 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 4911 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 4912 | if (kwm != KWM_STD && strcmp(args[0], "option") != 0) { |
| 4913 | 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] | 4914 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 4915 | } |
| 4916 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4917 | if (!strcmp(args[0], "listen") || |
| 4918 | !strcmp(args[0], "frontend") || |
| 4919 | !strcmp(args[0], "backend") || |
| 4920 | !strcmp(args[0], "ruleset") || |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 4921 | !strcmp(args[0], "defaults")) { /* new proxy */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4922 | confsect = CFG_LISTEN; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 4923 | free(cursection); |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 4924 | cursection = strdup(args[0]); |
| 4925 | } |
| 4926 | else if (!strcmp(args[0], "global")) { /* global config */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4927 | confsect = CFG_GLOBAL; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 4928 | free(cursection); |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 4929 | cursection = strdup(args[0]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 4930 | } else if (!strcmp(args[0], "userlist")) { |
| 4931 | confsect = CFG_USERLIST; |
| 4932 | free(cursection); |
| 4933 | cursection = strdup(args[0]); |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 4934 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4935 | /* else it's a section keyword */ |
| 4936 | |
| 4937 | switch (confsect) { |
| 4938 | case CFG_LISTEN: |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4939 | err_code |= cfg_parse_listen(file, linenum, args, kwm); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4940 | break; |
| 4941 | case CFG_GLOBAL: |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 4942 | err_code |= cfg_parse_global(file, linenum, args, kwm); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4943 | break; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 4944 | case CFG_USERLIST: |
| 4945 | err_code |= cfg_parse_users(file, linenum, args, kwm); |
| 4946 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4947 | default: |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 4948 | 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] | 4949 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4950 | } |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 4951 | |
| 4952 | if (err_code & ERR_ABORT) |
| 4953 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4954 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 4955 | free(cursection); |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 4956 | cursection = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4957 | fclose(f); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 4958 | return err_code; |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 4959 | } |
| 4960 | |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 4961 | /* |
| 4962 | * Returns the error code, 0 if OK, or any combination of : |
| 4963 | * - ERR_ABORT: must abort ASAP |
| 4964 | * - ERR_FATAL: we can continue parsing but not start the service |
| 4965 | * - ERR_WARN: a warning has been emitted |
| 4966 | * - ERR_ALERT: an alert has been emitted |
| 4967 | * Only the two first ones can stop processing, the two others are just |
| 4968 | * indicators. |
| 4969 | */ |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 4970 | int check_config_validity() |
| 4971 | { |
| 4972 | int cfgerr = 0; |
| 4973 | struct proxy *curproxy = NULL; |
| 4974 | struct server *newsrv = NULL; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 4975 | struct userlist *curuserlist = NULL; |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 4976 | int err_code = 0; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 4977 | unsigned int next_pxid = 1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4978 | |
| 4979 | /* |
| 4980 | * Now, check for the integrity of all that we have collected. |
| 4981 | */ |
| 4982 | |
| 4983 | /* will be needed further to delay some tasks */ |
Willy Tarreau | b0b37bc | 2008-06-23 14:00:57 +0200 | [diff] [blame] | 4984 | tv_update_date(0,1); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4985 | |
Willy Tarreau | 55bc0f8 | 2009-03-15 14:51:53 +0100 | [diff] [blame] | 4986 | /* first, we will invert the proxy list order */ |
| 4987 | curproxy = NULL; |
| 4988 | while (proxy) { |
| 4989 | struct proxy *next; |
| 4990 | |
| 4991 | next = proxy->next; |
| 4992 | proxy->next = curproxy; |
| 4993 | curproxy = proxy; |
| 4994 | if (!next) |
| 4995 | break; |
| 4996 | proxy = next; |
| 4997 | } |
| 4998 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4999 | if ((curproxy = proxy) == NULL) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5000 | Alert("config : no <listen> line. Nothing to do !\n"); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 5001 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5002 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5003 | } |
| 5004 | |
| 5005 | while (curproxy != NULL) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 5006 | struct switching_rule *rule; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5007 | struct sticking_rule *mrule; |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 5008 | struct tcp_rule *trule; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 5009 | struct listener *listener; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 5010 | unsigned int next_id; |
| 5011 | |
| 5012 | if (!curproxy->uuid) { |
| 5013 | /* proxy ID not set, use automatic numbering with first |
| 5014 | * spare entry starting with next_pxid. |
| 5015 | */ |
| 5016 | next_pxid = get_next_id(&used_proxy_id, next_pxid); |
| 5017 | curproxy->conf.id.key = curproxy->uuid = next_pxid; |
| 5018 | eb32_insert(&used_proxy_id, &curproxy->conf.id); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 5019 | } |
Krzysztof Piotr Oledzki | df5cb9f | 2010-02-05 20:58:27 +0100 | [diff] [blame] | 5020 | next_pxid++; |
| 5021 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 5022 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5023 | if (curproxy->state == PR_STSTOPPED) { |
Willy Tarreau | da250db | 2008-10-12 12:07:48 +0200 | [diff] [blame] | 5024 | /* ensure we don't keep listeners uselessly bound */ |
| 5025 | stop_proxy(curproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5026 | curproxy = curproxy->next; |
| 5027 | continue; |
| 5028 | } |
| 5029 | |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 5030 | switch (curproxy->mode) { |
| 5031 | case PR_MODE_HEALTH: |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5032 | cfgerr += proxy_cfg_ensure_no_http(curproxy); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 5033 | if (!(curproxy->cap & PR_CAP_FE)) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5034 | Alert("config : %s '%s' cannot be in health mode as it has no frontend capability.\n", |
| 5035 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 5036 | cfgerr++; |
| 5037 | } |
| 5038 | |
| 5039 | if (curproxy->srv != NULL) |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5040 | Warning("config : servers will be ignored for %s '%s'.\n", |
| 5041 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 5042 | break; |
| 5043 | |
| 5044 | case PR_MODE_TCP: |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5045 | cfgerr += proxy_cfg_ensure_no_http(curproxy); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 5046 | break; |
| 5047 | |
| 5048 | case PR_MODE_HTTP: |
Willy Tarreau | a9fb083 | 2009-07-10 20:53:53 +0200 | [diff] [blame] | 5049 | curproxy->acl_requires |= ACL_USE_L7_ANY; |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 5050 | if ((curproxy->cookie_name != NULL) && (curproxy->srv == NULL)) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5051 | Alert("config : HTTP proxy %s has a cookie but no server list !\n", |
| 5052 | curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 5053 | cfgerr++; |
| 5054 | } |
| 5055 | break; |
| 5056 | } |
| 5057 | |
| 5058 | if ((curproxy->cap & PR_CAP_FE) && (curproxy->listen == NULL)) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5059 | Alert("config : %s '%s' has no listen address. Please either specify a valid address on the <listen> line, or use the <bind> keyword.\n", |
| 5060 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5061 | cfgerr++; |
| 5062 | } |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 5063 | |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 5064 | if ((curproxy->cap & PR_CAP_BE) && (curproxy->mode != PR_MODE_HEALTH)) { |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 5065 | if (curproxy->lbprm.algo & BE_LB_KIND) { |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 5066 | if (curproxy->options & PR_O_TRANSP) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5067 | Alert("config : %s '%s' cannot use both transparent and balance mode.\n", |
| 5068 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 5069 | cfgerr++; |
| 5070 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5071 | #ifdef WE_DONT_SUPPORT_SERVERLESS_LISTENERS |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 5072 | else if (curproxy->srv == NULL) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5073 | Alert("config : %s '%s' needs at least 1 server in balance mode.\n", |
| 5074 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 5075 | cfgerr++; |
| 5076 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5077 | #endif |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 5078 | else if (*(int *)&curproxy->dispatch_addr.sin_addr != 0) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5079 | Warning("config : dispatch address of %s '%s' will be ignored in balance mode.\n", |
| 5080 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 5081 | err_code |= ERR_WARN; |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 5082 | } |
| 5083 | } |
| 5084 | else if (!(curproxy->options & (PR_O_TRANSP | PR_O_HTTP_PROXY)) && |
| 5085 | (*(int *)&curproxy->dispatch_addr.sin_addr == 0)) { |
| 5086 | /* If no LB algo is set in a backend, and we're not in |
| 5087 | * transparent mode, dispatch mode nor proxy mode, we |
| 5088 | * want to use balance roundrobin by default. |
| 5089 | */ |
| 5090 | curproxy->lbprm.algo &= ~BE_LB_ALGO; |
| 5091 | curproxy->lbprm.algo |= BE_LB_ALGO_RR; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5092 | } |
| 5093 | } |
Willy Tarreau | 193cf93 | 2007-09-17 10:17:23 +0200 | [diff] [blame] | 5094 | |
Willy Tarreau | 8293658 | 2007-11-30 15:20:09 +0100 | [diff] [blame] | 5095 | if ((curproxy->options & PR_O_DISABLE404) && !(curproxy->options & PR_O_HTTP_CHK)) { |
| 5096 | curproxy->options &= ~PR_O_DISABLE404; |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5097 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n", |
| 5098 | "disable-on-404", proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 5099 | err_code |= ERR_WARN; |
Willy Tarreau | 8293658 | 2007-11-30 15:20:09 +0100 | [diff] [blame] | 5100 | } |
| 5101 | |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 5102 | if ((curproxy->options2 & PR_O2_CHK_SNDST) && !(curproxy->options & PR_O_HTTP_CHK)) { |
| 5103 | curproxy->options &= ~PR_O2_CHK_SNDST; |
| 5104 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n", |
| 5105 | "send-state", proxy_type_str(curproxy), curproxy->id); |
| 5106 | err_code |= ERR_WARN; |
| 5107 | } |
| 5108 | |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5109 | /* if a default backend was specified, let's find it */ |
| 5110 | if (curproxy->defbe.name) { |
| 5111 | struct proxy *target; |
| 5112 | |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 5113 | target = findproxy_mode(curproxy->defbe.name, curproxy->mode, PR_CAP_BE); |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 5114 | if (!target) { |
| 5115 | Alert("Proxy '%s': unable to find required default_backend: '%s'.\n", |
| 5116 | curproxy->id, curproxy->defbe.name); |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5117 | cfgerr++; |
| 5118 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 5119 | Alert("Proxy '%s': loop detected for default_backend: '%s'.\n", |
| 5120 | curproxy->id, curproxy->defbe.name); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 5121 | cfgerr++; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5122 | } else { |
| 5123 | free(curproxy->defbe.name); |
| 5124 | curproxy->defbe.be = target; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 5125 | /* we force the backend to be present on at least all of |
| 5126 | * the frontend's processes. |
| 5127 | */ |
| 5128 | target->bind_proc = curproxy->bind_proc ? |
| 5129 | (target->bind_proc | curproxy->bind_proc) : 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5130 | } |
| 5131 | } |
| 5132 | |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5133 | /* find the target proxy in setbe */ |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5134 | if (curproxy->mode == PR_MODE_HTTP && curproxy->req_exp != NULL) { |
| 5135 | /* map jump target for ACT_SETBE in req_rep chain */ |
| 5136 | struct hdr_exp *exp; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5137 | for (exp = curproxy->req_exp; exp != NULL; exp = exp->next) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 5138 | struct proxy *target; |
| 5139 | |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5140 | if (exp->action != ACT_SETBE) |
| 5141 | continue; |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 5142 | |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 5143 | target = findproxy_mode(exp->replace, PR_MODE_HTTP, PR_CAP_BE); |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 5144 | if (!target) { |
| 5145 | Alert("Proxy '%s': unable to find required setbe: '%s'.\n", |
| 5146 | curproxy->id, exp->replace); |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5147 | cfgerr++; |
| 5148 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 5149 | Alert("Proxy '%s': loop detected for setbe: '%s'.\n", |
| 5150 | curproxy->id, exp->replace); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5151 | cfgerr++; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5152 | } else { |
| 5153 | free((void *)exp->replace); |
| 5154 | exp->replace = (const char *)target; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 5155 | /* we force the backend to be present on at least all of |
| 5156 | * the frontend's processes. |
| 5157 | */ |
| 5158 | target->bind_proc = curproxy->bind_proc ? |
| 5159 | (target->bind_proc | curproxy->bind_proc) : 0; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5160 | } |
| 5161 | } |
| 5162 | } |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 5163 | |
| 5164 | /* find the target proxy for 'use_backend' rules */ |
| 5165 | list_for_each_entry(rule, &curproxy->switching_rules, list) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 5166 | struct proxy *target; |
| 5167 | |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 5168 | target = findproxy_mode(rule->be.name, curproxy->mode, PR_CAP_BE); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 5169 | |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 5170 | if (!target) { |
| 5171 | Alert("Proxy '%s': unable to find required use_backend: '%s'.\n", |
| 5172 | curproxy->id, rule->be.name); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 5173 | cfgerr++; |
| 5174 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 5175 | Alert("Proxy '%s': loop detected for use_backend: '%s'.\n", |
| 5176 | curproxy->id, rule->be.name); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 5177 | cfgerr++; |
| 5178 | } else { |
| 5179 | free((void *)rule->be.name); |
| 5180 | rule->be.backend = target; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 5181 | /* we force the backend to be present on at least all of |
| 5182 | * the frontend's processes. |
| 5183 | */ |
| 5184 | target->bind_proc = curproxy->bind_proc ? |
| 5185 | (target->bind_proc | curproxy->bind_proc) : 0; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 5186 | } |
| 5187 | } |
| 5188 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5189 | /* find the target table for 'stick' rules */ |
| 5190 | list_for_each_entry(mrule, &curproxy->sticking_rules, list) { |
| 5191 | struct proxy *target; |
| 5192 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 5193 | curproxy->be_req_ana |= AN_REQ_STICKING_RULES; |
| 5194 | if (mrule->flags & STK_IS_STORE) |
| 5195 | curproxy->be_rsp_ana |= AN_RES_STORE_RULES; |
| 5196 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5197 | if (mrule->table.name) |
Willy Tarreau | c00cdc2 | 2010-06-06 16:48:26 +0200 | [diff] [blame] | 5198 | target = findproxy(mrule->table.name, 0); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5199 | else |
| 5200 | target = curproxy; |
| 5201 | |
| 5202 | if (!target) { |
| 5203 | Alert("Proxy '%s': unable to find stick-table '%s'.\n", |
| 5204 | curproxy->id, mrule->table.name); |
| 5205 | cfgerr++; |
| 5206 | } |
| 5207 | else if (target->table.size == 0) { |
| 5208 | Alert("Proxy '%s': stick-table '%s' used but not configured.\n", |
| 5209 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 5210 | cfgerr++; |
| 5211 | } |
Willy Tarreau | f0b38bf | 2010-06-06 13:22:23 +0200 | [diff] [blame] | 5212 | else if (!stktable_compatible_pattern(mrule->expr, target->table.type)) { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5213 | Alert("Proxy '%s': type of pattern not usable with type of stick-table '%s'.\n", |
| 5214 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 5215 | cfgerr++; |
| 5216 | } |
| 5217 | else { |
| 5218 | free((void *)mrule->table.name); |
| 5219 | mrule->table.t = &(target->table); |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 5220 | stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID, NULL); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5221 | } |
| 5222 | } |
| 5223 | |
| 5224 | /* find the target table for 'store response' rules */ |
| 5225 | list_for_each_entry(mrule, &curproxy->storersp_rules, list) { |
| 5226 | struct proxy *target; |
| 5227 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 5228 | curproxy->be_rsp_ana |= AN_RES_STORE_RULES; |
| 5229 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5230 | if (mrule->table.name) |
Willy Tarreau | c00cdc2 | 2010-06-06 16:48:26 +0200 | [diff] [blame] | 5231 | target = findproxy(mrule->table.name, 0); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5232 | else |
| 5233 | target = curproxy; |
| 5234 | |
| 5235 | if (!target) { |
| 5236 | Alert("Proxy '%s': unable to find store table '%s'.\n", |
| 5237 | curproxy->id, mrule->table.name); |
| 5238 | cfgerr++; |
| 5239 | } |
| 5240 | else if (target->table.size == 0) { |
| 5241 | Alert("Proxy '%s': stick-table '%s' used but not configured.\n", |
| 5242 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 5243 | cfgerr++; |
| 5244 | } |
Willy Tarreau | f0b38bf | 2010-06-06 13:22:23 +0200 | [diff] [blame] | 5245 | else if (!stktable_compatible_pattern(mrule->expr, target->table.type)) { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5246 | Alert("Proxy '%s': type of pattern not usable with type of stick-table '%s'.\n", |
| 5247 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 5248 | cfgerr++; |
| 5249 | } |
| 5250 | else { |
| 5251 | free((void *)mrule->table.name); |
| 5252 | mrule->table.t = &(target->table); |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 5253 | stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID, NULL); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5254 | } |
| 5255 | } |
| 5256 | |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 5257 | /* find the target table for 'tcp-request' layer 4 rules */ |
| 5258 | list_for_each_entry(trule, &curproxy->tcp_req.l4_rules, list) { |
| 5259 | struct proxy *target; |
| 5260 | |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 5261 | if (trule->action != TCP_ACT_TRK_SC1 && trule->action != TCP_ACT_TRK_SC2) |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 5262 | continue; |
| 5263 | |
| 5264 | if (trule->act_prm.trk_ctr.table.n) |
| 5265 | target = findproxy(trule->act_prm.trk_ctr.table.n, 0); |
| 5266 | else |
| 5267 | target = curproxy; |
| 5268 | |
| 5269 | if (!target) { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 5270 | Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n", |
| 5271 | curproxy->id, trule->act_prm.trk_ctr.table.n, |
| 5272 | trule->action == TCP_ACT_TRK_SC1 ? 1 : 2); |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 5273 | cfgerr++; |
| 5274 | } |
| 5275 | else if (target->table.size == 0) { |
| 5276 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
| 5277 | curproxy->id, trule->act_prm.trk_ctr.table.n ? trule->act_prm.trk_ctr.table.n : curproxy->id); |
| 5278 | cfgerr++; |
| 5279 | } |
| 5280 | else if (trule->act_prm.trk_ctr.type != target->table.type) { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 5281 | Alert("Proxy '%s': type of tracking key for sticky counter not usable with type of stick-table '%s'.\n", |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 5282 | curproxy->id, trule->act_prm.trk_ctr.table.n ? trule->act_prm.trk_ctr.table.n : curproxy->id); |
| 5283 | cfgerr++; |
| 5284 | } |
| 5285 | else { |
| 5286 | free(trule->act_prm.trk_ctr.table.n); |
| 5287 | trule->act_prm.trk_ctr.table.t = &target->table; |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 5288 | /* Note: if we decide to enhance the track-sc syntax, we may be able |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 5289 | * to pass a list of counters to track and allocate them right here using |
| 5290 | * stktable_alloc_data_type(). |
| 5291 | */ |
| 5292 | } |
| 5293 | } |
| 5294 | |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 5295 | /* find the target table for 'tcp-request' layer 6 rules */ |
| 5296 | list_for_each_entry(trule, &curproxy->tcp_req.inspect_rules, list) { |
| 5297 | struct proxy *target; |
| 5298 | |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 5299 | if (trule->action != TCP_ACT_TRK_SC1 && trule->action != TCP_ACT_TRK_SC2) |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 5300 | continue; |
| 5301 | |
| 5302 | if (trule->act_prm.trk_ctr.table.n) |
| 5303 | target = findproxy(trule->act_prm.trk_ctr.table.n, 0); |
| 5304 | else |
| 5305 | target = curproxy; |
| 5306 | |
| 5307 | if (!target) { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 5308 | Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n", |
| 5309 | curproxy->id, trule->act_prm.trk_ctr.table.n, |
| 5310 | trule->action == TCP_ACT_TRK_SC1 ? 1 : 2); |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 5311 | cfgerr++; |
| 5312 | } |
| 5313 | else if (target->table.size == 0) { |
| 5314 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
| 5315 | curproxy->id, trule->act_prm.trk_ctr.table.n ? trule->act_prm.trk_ctr.table.n : curproxy->id); |
| 5316 | cfgerr++; |
| 5317 | } |
| 5318 | else if (trule->act_prm.trk_ctr.type != target->table.type) { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 5319 | Alert("Proxy '%s': type of tracking key for sticky counter not usable with type of stick-table '%s'.\n", |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 5320 | curproxy->id, trule->act_prm.trk_ctr.table.n ? trule->act_prm.trk_ctr.table.n : curproxy->id); |
| 5321 | cfgerr++; |
| 5322 | } |
| 5323 | else { |
| 5324 | free(trule->act_prm.trk_ctr.table.n); |
| 5325 | trule->act_prm.trk_ctr.table.t = &target->table; |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 5326 | /* Note: if we decide to enhance the track-sc syntax, we may be able |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 5327 | * to pass a list of counters to track and allocate them right here using |
| 5328 | * stktable_alloc_data_type(). |
| 5329 | */ |
| 5330 | } |
| 5331 | } |
| 5332 | |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 5333 | if (curproxy->uri_auth && !(curproxy->uri_auth->flags & ST_CONVDONE) && |
| 5334 | !LIST_ISEMPTY(&curproxy->uri_auth->req_acl) && |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 5335 | (curproxy->uri_auth->userlist || curproxy->uri_auth->auth_realm )) { |
| 5336 | Alert("%s '%s': stats 'auth'/'realm' and 'http-request' can't be used at the same time.\n", |
| 5337 | "proxy", curproxy->id); |
| 5338 | cfgerr++; |
| 5339 | goto out_uri_auth_compat; |
| 5340 | } |
| 5341 | |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 5342 | 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] | 5343 | const char *uri_auth_compat_req[10]; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 5344 | struct req_acl_rule *req_acl; |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 5345 | int i = 0; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 5346 | |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 5347 | /* build the ACL condition from scratch. We're relying on anonymous ACLs for that */ |
| 5348 | uri_auth_compat_req[i++] = "auth"; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 5349 | |
| 5350 | if (curproxy->uri_auth->auth_realm) { |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 5351 | uri_auth_compat_req[i++] = "realm"; |
| 5352 | uri_auth_compat_req[i++] = curproxy->uri_auth->auth_realm; |
| 5353 | } |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 5354 | |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 5355 | uri_auth_compat_req[i++] = "unless"; |
| 5356 | uri_auth_compat_req[i++] = "{"; |
| 5357 | uri_auth_compat_req[i++] = "http_auth(.internal-stats-userlist)"; |
| 5358 | uri_auth_compat_req[i++] = "}"; |
| 5359 | uri_auth_compat_req[i++] = ""; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 5360 | |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 5361 | req_acl = parse_auth_cond(uri_auth_compat_req, "internal-stats-auth-compat", 0, curproxy); |
| 5362 | if (!req_acl) { |
| 5363 | cfgerr++; |
| 5364 | break; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 5365 | } |
| 5366 | |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 5367 | LIST_ADDQ(&curproxy->uri_auth->req_acl, &req_acl->list); |
| 5368 | |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 5369 | if (curproxy->uri_auth->auth_realm) { |
| 5370 | free(curproxy->uri_auth->auth_realm); |
| 5371 | curproxy->uri_auth->auth_realm = NULL; |
| 5372 | } |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 5373 | |
| 5374 | curproxy->uri_auth->flags |= ST_CONVDONE; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 5375 | } |
| 5376 | out_uri_auth_compat: |
| 5377 | |
Krzysztof Piotr Oledzki | f9423ae | 2010-01-29 19:26:18 +0100 | [diff] [blame] | 5378 | cfgerr += acl_find_targets(curproxy); |
| 5379 | |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 5380 | if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) && |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 5381 | (((curproxy->cap & PR_CAP_FE) && !curproxy->timeout.client) || |
Willy Tarreau | d825eef | 2007-05-12 22:35:00 +0200 | [diff] [blame] | 5382 | ((curproxy->cap & PR_CAP_BE) && (curproxy->srv) && |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 5383 | (!curproxy->timeout.connect || !curproxy->timeout.server)))) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5384 | Warning("config : missing timeouts for %s '%s'.\n" |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 5385 | " | While not properly invalid, you will certainly encounter various problems\n" |
| 5386 | " | 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] | 5387 | " | timeouts are set to a non-zero value: 'client', 'connect', 'server'.\n", |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5388 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 5389 | err_code |= ERR_WARN; |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 5390 | } |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 5391 | |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 5392 | /* Historically, the tarpit and queue timeouts were inherited from contimeout. |
| 5393 | * We must still support older configurations, so let's find out whether those |
| 5394 | * parameters have been set or must be copied from contimeouts. |
| 5395 | */ |
| 5396 | if (curproxy != &defproxy) { |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 5397 | if (!curproxy->timeout.tarpit || |
| 5398 | curproxy->timeout.tarpit == defproxy.timeout.tarpit) { |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 5399 | /* tarpit timeout not set. We search in the following order: |
| 5400 | * default.tarpit, curr.connect, default.connect. |
| 5401 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 5402 | if (defproxy.timeout.tarpit) |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 5403 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 5404 | else if (curproxy->timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 5405 | curproxy->timeout.tarpit = curproxy->timeout.connect; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 5406 | else if (defproxy.timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 5407 | curproxy->timeout.tarpit = defproxy.timeout.connect; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 5408 | } |
| 5409 | if ((curproxy->cap & PR_CAP_BE) && |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 5410 | (!curproxy->timeout.queue || |
| 5411 | curproxy->timeout.queue == defproxy.timeout.queue)) { |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 5412 | /* queue timeout not set. We search in the following order: |
| 5413 | * default.queue, curr.connect, default.connect. |
| 5414 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 5415 | if (defproxy.timeout.queue) |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 5416 | curproxy->timeout.queue = defproxy.timeout.queue; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 5417 | else if (curproxy->timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 5418 | curproxy->timeout.queue = curproxy->timeout.connect; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 5419 | else if (defproxy.timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 5420 | curproxy->timeout.queue = defproxy.timeout.connect; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 5421 | } |
| 5422 | } |
| 5423 | |
Willy Tarreau | 07a5490 | 2010-03-29 18:33:29 +0200 | [diff] [blame] | 5424 | if (curproxy->options2 & PR_O2_SSL3_CHK) { |
Willy Tarreau | 137325d | 2010-02-01 16:38:17 +0100 | [diff] [blame] | 5425 | curproxy->check_len = sizeof(sslv3_client_hello_pkt) - 1; |
| 5426 | curproxy->check_req = (char *)malloc(curproxy->check_len); |
| 5427 | memcpy(curproxy->check_req, sslv3_client_hello_pkt, curproxy->check_len); |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 5428 | } |
| 5429 | |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 5430 | /* The small pools required for the capture lists */ |
| 5431 | if (curproxy->nb_req_cap) |
| 5432 | curproxy->req_cap_pool = create_pool("ptrcap", |
| 5433 | curproxy->nb_req_cap * sizeof(char *), |
| 5434 | MEM_F_SHARED); |
| 5435 | if (curproxy->nb_rsp_cap) |
| 5436 | curproxy->rsp_cap_pool = create_pool("ptrcap", |
| 5437 | curproxy->nb_rsp_cap * sizeof(char *), |
| 5438 | MEM_F_SHARED); |
| 5439 | |
Willy Tarreau | 1d4154a | 2007-05-13 22:57:02 +0200 | [diff] [blame] | 5440 | curproxy->hdr_idx_pool = create_pool("hdr_idx", |
| 5441 | MAX_HTTP_HDR * sizeof(struct hdr_idx_elem), |
| 5442 | MEM_F_SHARED); |
| 5443 | |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 5444 | /* for backwards compatibility with "listen" instances, if |
| 5445 | * fullconn is not set but maxconn is set, then maxconn |
| 5446 | * is used. |
| 5447 | */ |
| 5448 | if (!curproxy->fullconn) |
| 5449 | curproxy->fullconn = curproxy->maxconn; |
| 5450 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5451 | /* first, we will invert the servers list order */ |
| 5452 | newsrv = NULL; |
| 5453 | while (curproxy->srv) { |
| 5454 | struct server *next; |
| 5455 | |
| 5456 | next = curproxy->srv->next; |
| 5457 | curproxy->srv->next = newsrv; |
| 5458 | newsrv = curproxy->srv; |
| 5459 | if (!next) |
| 5460 | break; |
| 5461 | curproxy->srv = next; |
| 5462 | } |
| 5463 | |
Willy Tarreau | dd70165 | 2010-05-25 23:03:02 +0200 | [diff] [blame] | 5464 | /* assign automatic UIDs to servers which don't have one yet */ |
| 5465 | next_id = 1; |
| 5466 | newsrv = curproxy->srv; |
| 5467 | while (newsrv != NULL) { |
| 5468 | if (!newsrv->puid) { |
| 5469 | /* server ID not set, use automatic numbering with first |
| 5470 | * spare entry starting with next_svid. |
| 5471 | */ |
| 5472 | next_id = get_next_id(&curproxy->conf.used_server_id, next_id); |
| 5473 | newsrv->conf.id.key = newsrv->puid = next_id; |
| 5474 | eb32_insert(&curproxy->conf.used_server_id, &newsrv->conf.id); |
| 5475 | } |
| 5476 | next_id++; |
| 5477 | newsrv = newsrv->next; |
| 5478 | } |
| 5479 | |
Willy Tarreau | 2069704 | 2007-11-15 23:26:18 +0100 | [diff] [blame] | 5480 | curproxy->lbprm.wmult = 1; /* default weight multiplier */ |
Willy Tarreau | 5dc2fa6 | 2007-11-19 19:10:18 +0100 | [diff] [blame] | 5481 | curproxy->lbprm.wdiv = 1; /* default weight divider */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5482 | |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 5483 | /* We have to initialize the server lookup mechanism depending |
| 5484 | * on what LB algorithm was choosen. |
| 5485 | */ |
| 5486 | |
| 5487 | curproxy->lbprm.algo &= ~(BE_LB_LKUP | BE_LB_PROP_DYN); |
| 5488 | switch (curproxy->lbprm.algo & BE_LB_KIND) { |
| 5489 | case BE_LB_KIND_RR: |
Willy Tarreau | 9757a38 | 2009-10-03 12:56:50 +0200 | [diff] [blame] | 5490 | if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_RR_STATIC) { |
| 5491 | curproxy->lbprm.algo |= BE_LB_LKUP_MAP; |
| 5492 | init_server_map(curproxy); |
| 5493 | } else { |
| 5494 | curproxy->lbprm.algo |= BE_LB_LKUP_RRTREE | BE_LB_PROP_DYN; |
| 5495 | fwrr_init_server_groups(curproxy); |
| 5496 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 5497 | break; |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 5498 | |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 5499 | case BE_LB_KIND_LC: |
| 5500 | curproxy->lbprm.algo |= BE_LB_LKUP_LCTREE | BE_LB_PROP_DYN; |
Willy Tarreau | 5140623 | 2008-03-10 22:04:20 +0100 | [diff] [blame] | 5501 | fwlc_init_server_tree(curproxy); |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 5502 | break; |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 5503 | |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 5504 | case BE_LB_KIND_HI: |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 5505 | if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS) { |
| 5506 | curproxy->lbprm.algo |= BE_LB_LKUP_CHTREE | BE_LB_PROP_DYN; |
| 5507 | chash_init_server_tree(curproxy); |
| 5508 | } else { |
| 5509 | curproxy->lbprm.algo |= BE_LB_LKUP_MAP; |
| 5510 | init_server_map(curproxy); |
| 5511 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 5512 | break; |
| 5513 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5514 | |
| 5515 | if (curproxy->options & PR_O_LOGASAP) |
| 5516 | curproxy->to_log &= ~LW_BYTES; |
| 5517 | |
Willy Tarreau | e7ded1f | 2009-08-09 10:11:45 +0200 | [diff] [blame] | 5518 | if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) && |
| 5519 | (curproxy->cap & PR_CAP_FE) && curproxy->to_log && curproxy->logfac1 < 0) { |
| 5520 | Warning("config : log format ignored for %s '%s' since it has no log address.\n", |
| 5521 | proxy_type_str(curproxy), curproxy->id); |
| 5522 | err_code |= ERR_WARN; |
| 5523 | } |
| 5524 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 5525 | if (curproxy->mode != PR_MODE_HTTP) { |
| 5526 | int optnum; |
| 5527 | |
| 5528 | if (curproxy->options & PR_O_COOK_ANY) { |
| 5529 | Warning("config : 'cookie' statement ignored for %s '%s' as it requires HTTP mode.\n", |
| 5530 | proxy_type_str(curproxy), curproxy->id); |
| 5531 | err_code |= ERR_WARN; |
| 5532 | } |
| 5533 | |
| 5534 | if (curproxy->uri_auth) { |
| 5535 | Warning("config : 'stats' statement ignored for %s '%s' as it requires HTTP mode.\n", |
| 5536 | proxy_type_str(curproxy), curproxy->id); |
| 5537 | err_code |= ERR_WARN; |
| 5538 | curproxy->uri_auth = NULL; |
| 5539 | } |
| 5540 | |
| 5541 | if (curproxy->options & PR_O_FWDFOR) { |
| 5542 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 5543 | "forwardfor", proxy_type_str(curproxy), curproxy->id); |
| 5544 | err_code |= ERR_WARN; |
| 5545 | curproxy->options &= ~PR_O_FWDFOR; |
| 5546 | } |
| 5547 | |
| 5548 | if (curproxy->options & PR_O_ORGTO) { |
| 5549 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 5550 | "originalto", proxy_type_str(curproxy), curproxy->id); |
| 5551 | err_code |= ERR_WARN; |
| 5552 | curproxy->options &= ~PR_O_ORGTO; |
| 5553 | } |
| 5554 | |
| 5555 | for (optnum = 0; cfg_opts[optnum].name; optnum++) { |
| 5556 | if (cfg_opts[optnum].mode == PR_MODE_HTTP && |
| 5557 | (curproxy->cap & cfg_opts[optnum].cap) && |
| 5558 | (curproxy->options & cfg_opts[optnum].val)) { |
| 5559 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 5560 | cfg_opts[optnum].name, proxy_type_str(curproxy), curproxy->id); |
| 5561 | err_code |= ERR_WARN; |
| 5562 | curproxy->options &= ~cfg_opts[optnum].val; |
| 5563 | } |
| 5564 | } |
| 5565 | |
| 5566 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) { |
| 5567 | if (cfg_opts2[optnum].mode == PR_MODE_HTTP && |
| 5568 | (curproxy->cap & cfg_opts2[optnum].cap) && |
| 5569 | (curproxy->options2 & cfg_opts2[optnum].val)) { |
| 5570 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 5571 | cfg_opts2[optnum].name, proxy_type_str(curproxy), curproxy->id); |
| 5572 | err_code |= ERR_WARN; |
| 5573 | curproxy->options2 &= ~cfg_opts2[optnum].val; |
| 5574 | } |
| 5575 | } |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 5576 | |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 5577 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 5578 | if (curproxy->bind_hdr_occ) { |
| 5579 | curproxy->bind_hdr_occ = 0; |
| 5580 | Warning("config : %s '%s' : ignoring use of header %s as source IP in non-HTTP mode.\n", |
| 5581 | proxy_type_str(curproxy), curproxy->id, curproxy->bind_hdr_name); |
| 5582 | err_code |= ERR_WARN; |
| 5583 | } |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 5584 | #endif |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 5585 | } |
| 5586 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5587 | /* |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 5588 | * ensure that we're not cross-dressing a TCP server into HTTP. |
| 5589 | */ |
| 5590 | newsrv = curproxy->srv; |
| 5591 | while (newsrv != NULL) { |
| 5592 | if ((curproxy->mode != PR_MODE_HTTP) && (newsrv->rdr_len || newsrv->cklen)) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5593 | Alert("config : %s '%s' : server cannot have cookie or redirect prefix in non-HTTP mode.\n", |
| 5594 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 5595 | cfgerr++; |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 5596 | } |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 5597 | |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 5598 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 5599 | if (curproxy->mode != PR_MODE_HTTP && newsrv->bind_hdr_occ) { |
| 5600 | newsrv->bind_hdr_occ = 0; |
| 5601 | Warning("config : %s '%s' : server %s cannot use header %s as source IP in non-HTTP mode.\n", |
| 5602 | proxy_type_str(curproxy), curproxy->id, newsrv->id, newsrv->bind_hdr_name); |
| 5603 | err_code |= ERR_WARN; |
| 5604 | } |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 5605 | #endif |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 5606 | newsrv = newsrv->next; |
| 5607 | } |
| 5608 | |
| 5609 | /* |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5610 | * If this server supports a maxconn parameter, it needs a dedicated |
| 5611 | * tasks to fill the emptied slots when a connection leaves. |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 5612 | * Also, resolve deferred tracking dependency if needed. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5613 | */ |
| 5614 | newsrv = curproxy->srv; |
| 5615 | while (newsrv != NULL) { |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 5616 | if (newsrv->minconn > newsrv->maxconn) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5617 | /* Only 'minconn' was specified, or it was higher than or equal |
| 5618 | * to 'maxconn'. Let's turn this into maxconn and clean it, as |
| 5619 | * this will avoid further useless expensive computations. |
| 5620 | */ |
| 5621 | newsrv->maxconn = newsrv->minconn; |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 5622 | } else if (newsrv->maxconn && !newsrv->minconn) { |
| 5623 | /* minconn was not specified, so we set it to maxconn */ |
| 5624 | newsrv->minconn = newsrv->maxconn; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5625 | } else if (newsrv->minconn != newsrv->maxconn && !curproxy->fullconn) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5626 | Alert("config : %s '%s' : fullconn is mandatory when minconn is set on a server.\n", |
| 5627 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 5628 | cfgerr++; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5629 | } |
| 5630 | |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 5631 | if (newsrv->trackit) { |
| 5632 | struct proxy *px; |
| 5633 | struct server *srv; |
| 5634 | char *pname, *sname; |
| 5635 | |
| 5636 | pname = newsrv->trackit; |
| 5637 | sname = strrchr(pname, '/'); |
| 5638 | |
| 5639 | if (sname) |
| 5640 | *sname++ = '\0'; |
| 5641 | else { |
| 5642 | sname = pname; |
| 5643 | pname = NULL; |
| 5644 | } |
| 5645 | |
| 5646 | if (pname) { |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 5647 | px = findproxy(pname, PR_CAP_BE); |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 5648 | if (!px) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5649 | Alert("config : %s '%s', server '%s': unable to find required proxy '%s' for tracking.\n", |
| 5650 | proxy_type_str(curproxy), curproxy->id, |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 5651 | newsrv->id, pname); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 5652 | cfgerr++; |
| 5653 | goto next_srv; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 5654 | } |
| 5655 | } else |
| 5656 | px = curproxy; |
| 5657 | |
| 5658 | srv = findserver(px, sname); |
| 5659 | if (!srv) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5660 | Alert("config : %s '%s', server '%s': unable to find required server '%s' for tracking.\n", |
| 5661 | proxy_type_str(curproxy), curproxy->id, |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 5662 | newsrv->id, sname); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 5663 | cfgerr++; |
| 5664 | goto next_srv; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 5665 | } |
| 5666 | |
| 5667 | if (!(srv->state & SRV_CHECKED)) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5668 | Alert("config : %s '%s', server '%s': unable to use %s/%s for " |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 5669 | "tracking as it does not have checks enabled.\n", |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5670 | proxy_type_str(curproxy), curproxy->id, |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 5671 | newsrv->id, px->id, srv->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 5672 | cfgerr++; |
| 5673 | goto next_srv; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 5674 | } |
| 5675 | |
| 5676 | if (curproxy != px && |
| 5677 | (curproxy->options & PR_O_DISABLE404) != (px->options & PR_O_DISABLE404)) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5678 | Alert("config : %s '%s', server '%s': unable to use %s/%s for" |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 5679 | "tracking: disable-on-404 option inconsistency.\n", |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5680 | proxy_type_str(curproxy), curproxy->id, |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 5681 | newsrv->id, px->id, srv->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 5682 | cfgerr++; |
| 5683 | goto next_srv; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 5684 | } |
| 5685 | |
| 5686 | newsrv->tracked = srv; |
| 5687 | newsrv->tracknext = srv->tracknext; |
| 5688 | srv->tracknext = newsrv; |
| 5689 | |
| 5690 | free(newsrv->trackit); |
| 5691 | } |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 5692 | next_srv: |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5693 | newsrv = newsrv->next; |
| 5694 | } |
| 5695 | |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 5696 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 5697 | curproxy->accept = frontend_accept; |
| 5698 | |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 5699 | if (curproxy->tcp_req.inspect_delay || |
| 5700 | !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules)) |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 5701 | curproxy->fe_req_ana |= AN_REQ_INSPECT_FE; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 5702 | |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 5703 | if (curproxy->mode == PR_MODE_HTTP) { |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 5704 | 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] | 5705 | 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] | 5706 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 5707 | |
| 5708 | /* both TCP and HTTP must check switching rules */ |
| 5709 | curproxy->fe_req_ana |= AN_REQ_SWITCHING_RULES; |
| 5710 | } |
| 5711 | |
| 5712 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 5713 | if (curproxy->tcp_req.inspect_delay || |
| 5714 | !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules)) |
| 5715 | curproxy->be_req_ana |= AN_REQ_INSPECT_BE; |
| 5716 | |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 5717 | if (curproxy->mode == PR_MODE_HTTP) { |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 5718 | 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] | 5719 | 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] | 5720 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 5721 | |
| 5722 | /* If the backend does requires RDP cookie persistence, we have to |
| 5723 | * enable the corresponding analyser. |
| 5724 | */ |
| 5725 | if (curproxy->options2 & PR_O2_RDPC_PRST) |
| 5726 | curproxy->be_req_ana |= AN_REQ_PRST_RDP_COOKIE; |
| 5727 | } |
| 5728 | |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 5729 | listener = NULL; |
| 5730 | while (curproxy->listen) { |
| 5731 | struct listener *next; |
| 5732 | |
| 5733 | next = curproxy->listen->next; |
| 5734 | curproxy->listen->next = listener; |
| 5735 | listener = curproxy->listen; |
| 5736 | |
| 5737 | if (!next) |
| 5738 | break; |
| 5739 | |
| 5740 | curproxy->listen = next; |
| 5741 | } |
| 5742 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 5743 | /* adjust this proxy's listeners */ |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 5744 | next_id = 1; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 5745 | listener = curproxy->listen; |
| 5746 | while (listener) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 5747 | if (!listener->luid) { |
| 5748 | /* listener ID not set, use automatic numbering with first |
| 5749 | * spare entry starting with next_luid. |
| 5750 | */ |
| 5751 | next_id = get_next_id(&curproxy->conf.used_listener_id, next_id); |
| 5752 | listener->conf.id.key = listener->luid = next_id; |
| 5753 | eb32_insert(&curproxy->conf.used_listener_id, &listener->conf.id); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 5754 | } |
Krzysztof Piotr Oledzki | df5cb9f | 2010-02-05 20:58:27 +0100 | [diff] [blame] | 5755 | next_id++; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 5756 | |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 5757 | /* enable separate counters */ |
| 5758 | if (curproxy->options2 & PR_O2_SOCKSTAT) { |
| 5759 | listener->counters = (struct licounters *)calloc(1, sizeof(struct licounters)); |
| 5760 | if (!listener->name) { |
| 5761 | sprintf(trash, "sock-%d", listener->luid); |
| 5762 | listener->name = strdup(trash); |
| 5763 | } |
| 5764 | } |
| 5765 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 5766 | if (curproxy->options & PR_O_TCP_NOLING) |
| 5767 | listener->options |= LI_O_NOLINGER; |
| 5768 | listener->maxconn = curproxy->maxconn; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 5769 | listener->backlog = curproxy->backlog; |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 5770 | listener->timeout = &curproxy->timeout.client; |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 5771 | listener->accept = session_accept; |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 5772 | listener->frontend = curproxy; |
Willy Tarreau | 3bc1377 | 2008-12-07 11:50:35 +0100 | [diff] [blame] | 5773 | listener->handler = process_session; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 5774 | listener->analysers |= curproxy->fe_req_ana; |
Willy Tarreau | 3bc1377 | 2008-12-07 11:50:35 +0100 | [diff] [blame] | 5775 | |
Willy Tarreau | a5c0ab2 | 2010-05-31 10:30:33 +0200 | [diff] [blame] | 5776 | if (!LIST_ISEMPTY(&curproxy->tcp_req.l4_rules)) |
| 5777 | listener->options |= LI_O_TCP_RULES; |
| 5778 | |
Willy Tarreau | de3041d | 2010-05-31 10:56:17 +0200 | [diff] [blame] | 5779 | if (curproxy->mon_mask.s_addr) |
| 5780 | listener->options |= LI_O_CHK_MONNET; |
| 5781 | |
Willy Tarreau | 9ea05a7 | 2009-06-14 12:07:01 +0200 | [diff] [blame] | 5782 | /* smart accept mode is automatic in HTTP mode */ |
| 5783 | if ((curproxy->options2 & PR_O2_SMARTACC) || |
| 5784 | (curproxy->mode == PR_MODE_HTTP && |
| 5785 | !(curproxy->no_options2 & PR_O2_SMARTACC))) |
| 5786 | listener->options |= LI_O_NOQUICKACK; |
| 5787 | |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 5788 | /* We want the use_backend and default_backend rules to apply */ |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 5789 | listener = listener->next; |
| 5790 | } |
| 5791 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5792 | curproxy = curproxy->next; |
| 5793 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5794 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5795 | for (curuserlist = userlist; curuserlist; curuserlist = curuserlist->next) { |
| 5796 | struct auth_users *curuser; |
| 5797 | int g; |
| 5798 | |
| 5799 | for (curuser = curuserlist->users; curuser; curuser = curuser->next) { |
| 5800 | unsigned int group_mask = 0; |
| 5801 | char *group = NULL; |
| 5802 | |
Willy Tarreau | b4c06b7 | 2010-02-02 11:28:20 +0100 | [diff] [blame] | 5803 | if (!curuser->u.groups) |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5804 | continue; |
| 5805 | |
Willy Tarreau | b4c06b7 | 2010-02-02 11:28:20 +0100 | [diff] [blame] | 5806 | while ((group = strtok(group?NULL:curuser->u.groups, ","))) { |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5807 | |
| 5808 | for (g = 0; g < curuserlist->grpcnt; g++) |
| 5809 | if (!strcmp(curuserlist->groups[g], group)) |
| 5810 | break; |
| 5811 | |
| 5812 | if (g == curuserlist->grpcnt) { |
| 5813 | Alert("userlist '%s': no such group '%s' specified in user '%s'\n", |
| 5814 | curuserlist->name, group, curuser->user); |
| 5815 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5816 | goto out; |
| 5817 | } |
| 5818 | |
| 5819 | group_mask |= (1 << g); |
| 5820 | } |
| 5821 | |
Willy Tarreau | b4c06b7 | 2010-02-02 11:28:20 +0100 | [diff] [blame] | 5822 | free(curuser->u.groups); |
| 5823 | curuser->u.group_mask = group_mask; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5824 | } |
| 5825 | |
| 5826 | for (g = 0; g < curuserlist->grpcnt; g++) { |
| 5827 | char *user = NULL; |
| 5828 | |
| 5829 | if (!curuserlist->groupusers[g]) |
| 5830 | continue; |
| 5831 | |
| 5832 | while ((user = strtok(user?NULL:curuserlist->groupusers[g], ","))) { |
| 5833 | for (curuser = curuserlist->users; curuser; curuser = curuser->next) |
| 5834 | if (!strcmp(curuser->user, user)) |
| 5835 | break; |
| 5836 | |
| 5837 | if (!curuser) { |
| 5838 | Alert("userlist '%s': no such user '%s' specified in group '%s'\n", |
| 5839 | curuserlist->name, user, curuserlist->groups[g]); |
| 5840 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5841 | goto out; |
| 5842 | } |
| 5843 | |
Willy Tarreau | b4c06b7 | 2010-02-02 11:28:20 +0100 | [diff] [blame] | 5844 | curuser->u.group_mask |= (1 << g); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5845 | } |
| 5846 | |
| 5847 | free(curuserlist->groupusers[g]); |
| 5848 | } |
| 5849 | |
| 5850 | free(curuserlist->groupusers); |
| 5851 | |
| 5852 | #ifdef DEBUG_AUTH |
| 5853 | for (g = 0; g < curuserlist->grpcnt; g++) { |
| 5854 | fprintf(stderr, "group %s, id %d, mask %08X, users:", curuserlist->groups[g], g , 1 << g); |
| 5855 | |
| 5856 | for (curuser = curuserlist->users; curuser; curuser = curuser->next) { |
| 5857 | if (curuser->group_mask & (1 << g)) |
| 5858 | fprintf(stderr, " %s", curuser->user); |
| 5859 | } |
| 5860 | |
| 5861 | fprintf(stderr, "\n"); |
| 5862 | } |
| 5863 | #endif |
| 5864 | |
| 5865 | } |
| 5866 | |
Willy Tarreau | 056f568 | 2010-06-06 15:51:11 +0200 | [diff] [blame] | 5867 | /* initialize stick-tables on backend capable proxies. This must not |
| 5868 | * be done earlier because the data size may be discovered while parsing |
| 5869 | * other proxies. |
| 5870 | */ |
| 5871 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) |
Willy Tarreau | c00cdc2 | 2010-06-06 16:48:26 +0200 | [diff] [blame] | 5872 | stktable_init(&curproxy->table); |
Willy Tarreau | 056f568 | 2010-06-06 15:51:11 +0200 | [diff] [blame] | 5873 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5874 | /* |
| 5875 | * Recount currently required checks. |
| 5876 | */ |
| 5877 | |
| 5878 | for (curproxy=proxy; curproxy; curproxy=curproxy->next) { |
| 5879 | int optnum; |
| 5880 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 5881 | for (optnum = 0; cfg_opts[optnum].name; optnum++) |
| 5882 | if (curproxy->options & cfg_opts[optnum].val) |
| 5883 | global.last_checks |= cfg_opts[optnum].checks; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5884 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 5885 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) |
| 5886 | if (curproxy->options2 & cfg_opts2[optnum].val) |
| 5887 | global.last_checks |= cfg_opts2[optnum].checks; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5888 | } |
| 5889 | |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 5890 | if (cfgerr > 0) |
| 5891 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5892 | out: |
| 5893 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5894 | } |
| 5895 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 5896 | /* |
| 5897 | * Registers the CFG keyword list <kwl> as a list of valid keywords for next |
| 5898 | * parsing sessions. |
| 5899 | */ |
| 5900 | void cfg_register_keywords(struct cfg_kw_list *kwl) |
| 5901 | { |
| 5902 | LIST_ADDQ(&cfg_keywords.list, &kwl->list); |
| 5903 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5904 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 5905 | /* |
| 5906 | * Unregisters the CFG keyword list <kwl> from the list of valid keywords. |
| 5907 | */ |
| 5908 | void cfg_unregister_keywords(struct cfg_kw_list *kwl) |
| 5909 | { |
| 5910 | LIST_DEL(&kwl->list); |
| 5911 | LIST_INIT(&kwl->list); |
| 5912 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5913 | |
| 5914 | /* |
| 5915 | * Local variables: |
| 5916 | * c-indent-level: 8 |
| 5917 | * c-basic-offset: 8 |
| 5918 | * End: |
| 5919 | */ |