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> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 40 | #include <proto/backend.h> |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 41 | #include <proto/buffers.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 42 | #include <proto/checks.h> |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 43 | #include <proto/dumpstats.h> |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 44 | #include <proto/httperr.h> |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 45 | #include <proto/lb_chash.h> |
Willy Tarreau | f89c187 | 2009-10-01 11:19:37 +0200 | [diff] [blame] | 46 | #include <proto/lb_fwlc.h> |
| 47 | #include <proto/lb_fwrr.h> |
| 48 | #include <proto/lb_map.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 49 | #include <proto/log.h> |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 50 | #include <proto/pattern.h> |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 51 | #include <proto/port_range.h> |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 52 | #include <proto/protocols.h> |
| 53 | #include <proto/proto_tcp.h> |
| 54 | #include <proto/proto_http.h> |
Willy Tarreau | 2b5652f | 2006-12-31 17:46:05 +0100 | [diff] [blame] | 55 | #include <proto/proxy.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 56 | #include <proto/server.h> |
Willy Tarreau | 3bc1377 | 2008-12-07 11:50:35 +0100 | [diff] [blame] | 57 | #include <proto/session.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 58 | #include <proto/task.h> |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 59 | #include <proto/stick_table.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 60 | |
| 61 | |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 62 | /* This is the SSLv3 CLIENT HELLO packet used in conjunction with the |
| 63 | * ssl-hello-chk option to ensure that the remote server speaks SSL. |
| 64 | * |
| 65 | * Check RFC 2246 (TLSv1.0) sections A.3 and A.4 for details. |
| 66 | */ |
| 67 | const char sslv3_client_hello_pkt[] = { |
| 68 | "\x16" /* ContentType : 0x16 = Hanshake */ |
| 69 | "\x03\x00" /* ProtocolVersion : 0x0300 = SSLv3 */ |
| 70 | "\x00\x79" /* ContentLength : 0x79 bytes after this one */ |
| 71 | "\x01" /* HanshakeType : 0x01 = CLIENT HELLO */ |
| 72 | "\x00\x00\x75" /* HandshakeLength : 0x75 bytes after this one */ |
| 73 | "\x03\x00" /* Hello Version : 0x0300 = v3 */ |
| 74 | "\x00\x00\x00\x00" /* Unix GMT Time (s) : filled with <now> (@0x0B) */ |
| 75 | "HAPROXYSSLCHK\nHAPROXYSSLCHK\n" /* Random : must be exactly 28 bytes */ |
| 76 | "\x00" /* Session ID length : empty (no session ID) */ |
| 77 | "\x00\x4E" /* Cipher Suite Length : 78 bytes after this one */ |
| 78 | "\x00\x01" "\x00\x02" "\x00\x03" "\x00\x04" /* 39 most common ciphers : */ |
| 79 | "\x00\x05" "\x00\x06" "\x00\x07" "\x00\x08" /* 0x01...0x1B, 0x2F...0x3A */ |
| 80 | "\x00\x09" "\x00\x0A" "\x00\x0B" "\x00\x0C" /* This covers RSA/DH, */ |
| 81 | "\x00\x0D" "\x00\x0E" "\x00\x0F" "\x00\x10" /* various bit lengths, */ |
| 82 | "\x00\x11" "\x00\x12" "\x00\x13" "\x00\x14" /* SHA1/MD5, DES/3DES/AES... */ |
| 83 | "\x00\x15" "\x00\x16" "\x00\x17" "\x00\x18" |
| 84 | "\x00\x19" "\x00\x1A" "\x00\x1B" "\x00\x2F" |
| 85 | "\x00\x30" "\x00\x31" "\x00\x32" "\x00\x33" |
| 86 | "\x00\x34" "\x00\x35" "\x00\x36" "\x00\x37" |
| 87 | "\x00\x38" "\x00\x39" "\x00\x3A" |
| 88 | "\x01" /* Compression Length : 0x01 = 1 byte for types */ |
| 89 | "\x00" /* Compression Type : 0x00 = NULL compression */ |
| 90 | }; |
| 91 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 92 | /* various keyword modifiers */ |
| 93 | enum kw_mod { |
| 94 | KWM_STD = 0, /* normal */ |
| 95 | KWM_NO, /* "no" prefixed before the keyword */ |
| 96 | KWM_DEF, /* "default" prefixed before the keyword */ |
| 97 | }; |
| 98 | |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 99 | /* 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] | 100 | struct cfg_opt { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 101 | const char *name; |
| 102 | unsigned int val; |
| 103 | unsigned int cap; |
Willy Tarreau | 4fee4e9 | 2007-01-06 21:09:17 +0100 | [diff] [blame] | 104 | unsigned int checks; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 105 | }; |
| 106 | |
| 107 | /* proxy->options */ |
| 108 | static const struct cfg_opt cfg_opts[] = |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 109 | { |
Willy Tarreau | 4fee4e9 | 2007-01-06 21:09:17 +0100 | [diff] [blame] | 110 | { "abortonclose", PR_O_ABRT_CLOSE, PR_CAP_BE, 0 }, |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 111 | { "allbackups", PR_O_USE_ALL_BK, PR_CAP_BE, 0 }, |
Willy Tarreau | 4fee4e9 | 2007-01-06 21:09:17 +0100 | [diff] [blame] | 112 | { "checkcache", PR_O_CHK_CACHE, PR_CAP_BE, 0 }, |
Willy Tarreau | 4fee4e9 | 2007-01-06 21:09:17 +0100 | [diff] [blame] | 113 | { "clitcpka", PR_O_TCP_CLI_KA, PR_CAP_FE, 0 }, |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 114 | { "contstats", PR_O_CONTSTATS, PR_CAP_FE, 0 }, |
| 115 | { "dontlognull", PR_O_NULLNOLOG, PR_CAP_FE, 0 }, |
Willy Tarreau | a31e5df | 2009-12-30 01:10:35 +0100 | [diff] [blame] | 116 | { "forceclose", PR_O_FORCE_CLO, PR_CAP_FE | PR_CAP_BE, 0 }, |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 117 | { "http_proxy", PR_O_HTTP_PROXY, PR_CAP_FE | PR_CAP_BE, 0 }, |
| 118 | { "httpclose", PR_O_HTTP_CLOSE, PR_CAP_FE | PR_CAP_BE, 0 }, |
| 119 | { "keepalive", PR_O_KEEPALIVE, PR_CAP_NONE, 0 }, |
Willy Tarreau | b608feb | 2010-01-02 22:47:18 +0100 | [diff] [blame] | 120 | { "http-server-close", PR_O_SERVER_CLO, PR_CAP_FE | PR_CAP_BE, 0 }, |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 121 | { "logasap", PR_O_LOGASAP, PR_CAP_FE, 0 }, |
| 122 | { "nolinger", PR_O_TCP_NOLING, PR_CAP_FE | PR_CAP_BE, 0 }, |
Willy Tarreau | 4fee4e9 | 2007-01-06 21:09:17 +0100 | [diff] [blame] | 123 | { "persist", PR_O_PERSIST, PR_CAP_BE, 0 }, |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 124 | { "redispatch", PR_O_REDISP, PR_CAP_BE, 0 }, |
| 125 | { "srvtcpka", PR_O_TCP_SRV_KA, PR_CAP_BE, 0 }, |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 126 | #ifdef TPROXY |
Willy Tarreau | 4b1f859 | 2008-12-23 23:13:55 +0100 | [diff] [blame] | 127 | { "transparent", PR_O_TRANSP, PR_CAP_BE, 0 }, |
Willy Tarreau | 8f922fc | 2007-01-06 21:11:49 +0100 | [diff] [blame] | 128 | #endif |
| 129 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 130 | { NULL, 0, 0, 0 } |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 131 | }; |
| 132 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 133 | /* proxy->options2 */ |
| 134 | static const struct cfg_opt cfg_opts2[] = |
| 135 | { |
| 136 | #ifdef CONFIG_HAP_LINUX_SPLICE |
| 137 | { "splice-request", PR_O2_SPLIC_REQ, PR_CAP_FE|PR_CAP_BE, 0 }, |
| 138 | { "splice-response", PR_O2_SPLIC_RTR, PR_CAP_FE|PR_CAP_BE, 0 }, |
| 139 | { "splice-auto", PR_O2_SPLIC_AUT, PR_CAP_FE|PR_CAP_BE, 0 }, |
| 140 | #endif |
Willy Tarreau | 32a4ec0 | 2009-04-02 11:35:18 +0200 | [diff] [blame] | 141 | { "accept-invalid-http-request", PR_O2_REQBUG_OK, PR_CAP_FE, 0 }, |
| 142 | { "accept-invalid-http-response", PR_O2_RSPBUG_OK, PR_CAP_BE, 0 }, |
Willy Tarreau | c9bd0cc | 2009-05-10 11:57:02 +0200 | [diff] [blame] | 143 | { "dontlog-normal", PR_O2_NOLOGNORM, PR_CAP_FE, 0 }, |
| 144 | { "log-separate-errors", PR_O2_LOGERRORS, PR_CAP_FE, 0 }, |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 145 | { "log-health-checks", PR_O2_LOGHCHKS, PR_CAP_BE, 0 }, |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 146 | { "socket-stats", PR_O2_SOCKSTAT, PR_CAP_FE, 0 }, |
Willy Tarreau | 9ea05a7 | 2009-06-14 12:07:01 +0200 | [diff] [blame] | 147 | { "tcp-smart-accept", PR_O2_SMARTACC, PR_CAP_FE, 0 }, |
Willy Tarreau | d88edf2 | 2009-06-14 15:48:17 +0200 | [diff] [blame] | 148 | { "tcp-smart-connect", PR_O2_SMARTCON, PR_CAP_BE, 0 }, |
Willy Tarreau | f27b5ea | 2009-10-03 22:01:18 +0200 | [diff] [blame] | 149 | { "independant-streams", PR_O2_INDEPSTR, PR_CAP_FE|PR_CAP_BE, 0 }, |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 150 | { NULL, 0, 0, 0 } |
| 151 | }; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 152 | |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 153 | static char *cursection = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 154 | static struct proxy defproxy; /* fake proxy used to assign default values on all instances */ |
| 155 | int cfg_maxpconn = DEFAULT_MAXCONN; /* # of simultaneous connections per proxy (-N) */ |
Willy Tarreau | 5af24ef | 2009-03-15 15:23:16 +0100 | [diff] [blame] | 156 | int cfg_maxconn = 0; /* # of simultaneous connections, (-n) */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 157 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 158 | /* List head of all known configuration keywords */ |
| 159 | static struct cfg_kw_list cfg_keywords = { |
| 160 | .list = LIST_HEAD_INIT(cfg_keywords.list) |
| 161 | }; |
| 162 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 163 | /* |
| 164 | * converts <str> to a list of listeners which are dynamically allocated. |
| 165 | * The format is "{addr|'*'}:port[-end][,{addr|'*'}:port[-end]]*", where : |
| 166 | * - <addr> can be empty or "*" to indicate INADDR_ANY ; |
| 167 | * - <port> is a numerical port from 1 to 65535 ; |
| 168 | * - <end> indicates to use the range from <port> to <end> instead (inclusive). |
| 169 | * 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] | 170 | * Function returns 1 for success or 0 if error. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 171 | */ |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 172 | static int str2listener(char *str, struct proxy *curproxy) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 173 | { |
| 174 | struct listener *l; |
| 175 | char *c, *next, *range, *dupstr; |
| 176 | int port, end; |
| 177 | |
| 178 | next = dupstr = strdup(str); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 179 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 180 | while (next && *next) { |
| 181 | struct sockaddr_storage ss; |
| 182 | |
| 183 | str = next; |
| 184 | /* 1) look for the end of the first address */ |
Krzysztof Piotr Oledzki | 52d522b | 2009-01-27 16:57:08 +0100 | [diff] [blame] | 185 | if ((next = strchr(str, ',')) != NULL) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 186 | *next++ = 0; |
| 187 | } |
| 188 | |
| 189 | /* 2) look for the addr/port delimiter, it's the last colon. */ |
| 190 | if ((range = strrchr(str, ':')) == NULL) { |
| 191 | Alert("Missing port number: '%s'\n", str); |
| 192 | goto fail; |
| 193 | } |
| 194 | |
| 195 | *range++ = 0; |
| 196 | |
| 197 | if (strrchr(str, ':') != NULL) { |
| 198 | /* IPv6 address contains ':' */ |
| 199 | memset(&ss, 0, sizeof(ss)); |
| 200 | ss.ss_family = AF_INET6; |
| 201 | |
| 202 | if (!inet_pton(ss.ss_family, str, &((struct sockaddr_in6 *)&ss)->sin6_addr)) { |
| 203 | Alert("Invalid server address: '%s'\n", str); |
| 204 | goto fail; |
| 205 | } |
| 206 | } |
| 207 | else { |
| 208 | memset(&ss, 0, sizeof(ss)); |
| 209 | ss.ss_family = AF_INET; |
| 210 | |
| 211 | if (*str == '*' || *str == '\0') { /* INADDR_ANY */ |
| 212 | ((struct sockaddr_in *)&ss)->sin_addr.s_addr = INADDR_ANY; |
| 213 | } |
| 214 | else if (!inet_pton(ss.ss_family, str, &((struct sockaddr_in *)&ss)->sin_addr)) { |
| 215 | struct hostent *he; |
| 216 | |
| 217 | if ((he = gethostbyname(str)) == NULL) { |
| 218 | Alert("Invalid server name: '%s'\n", str); |
| 219 | goto fail; |
| 220 | } |
| 221 | else |
| 222 | ((struct sockaddr_in *)&ss)->sin_addr = |
| 223 | *(struct in_addr *) *(he->h_addr_list); |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | /* 3) look for the port-end delimiter */ |
| 228 | if ((c = strchr(range, '-')) != NULL) { |
| 229 | *c++ = 0; |
| 230 | end = atol(c); |
| 231 | } |
| 232 | else { |
| 233 | end = atol(range); |
| 234 | } |
| 235 | |
| 236 | port = atol(range); |
| 237 | |
| 238 | if (port < 1 || port > 65535) { |
| 239 | Alert("Invalid port '%d' specified for address '%s'.\n", port, str); |
| 240 | goto fail; |
| 241 | } |
| 242 | |
| 243 | if (end < 1 || end > 65535) { |
| 244 | Alert("Invalid port '%d' specified for address '%s'.\n", end, str); |
| 245 | goto fail; |
| 246 | } |
| 247 | |
| 248 | for (; port <= end; port++) { |
| 249 | l = (struct listener *)calloc(1, sizeof(struct listener)); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 250 | l->next = curproxy->listen; |
| 251 | curproxy->listen = l; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 252 | |
| 253 | l->fd = -1; |
| 254 | l->addr = ss; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 255 | l->state = LI_INIT; |
| 256 | |
| 257 | if (ss.ss_family == AF_INET6) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 258 | ((struct sockaddr_in6 *)(&l->addr))->sin6_port = htons(port); |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 259 | tcpv6_add_listener(l); |
| 260 | } else { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 261 | ((struct sockaddr_in *)(&l->addr))->sin_port = htons(port); |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 262 | tcpv4_add_listener(l); |
| 263 | } |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 264 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 265 | listeners++; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 266 | } /* end for(port) */ |
| 267 | } /* end while(next) */ |
| 268 | free(dupstr); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 269 | return 1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 270 | fail: |
| 271 | free(dupstr); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 272 | return 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 273 | } |
| 274 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 275 | /* |
| 276 | * Sends a warning if proxy <proxy> does not have at least one of the |
| 277 | * capabilities in <cap>. An optionnal <hint> may be added at the end |
| 278 | * of the warning to help the user. Returns 1 if a warning was emitted |
| 279 | * or 0 if the condition is valid. |
| 280 | */ |
| 281 | int warnifnotcap(struct proxy *proxy, int cap, const char *file, int line, char *arg, char *hint) |
| 282 | { |
| 283 | char *msg; |
| 284 | |
| 285 | switch (cap) { |
| 286 | case PR_CAP_BE: msg = "no backend"; break; |
| 287 | case PR_CAP_FE: msg = "no frontend"; break; |
| 288 | case PR_CAP_RS: msg = "no ruleset"; break; |
| 289 | case PR_CAP_BE|PR_CAP_FE: msg = "neither frontend nor backend"; break; |
| 290 | default: msg = "not enough"; break; |
| 291 | } |
| 292 | |
| 293 | if (!(proxy->cap & cap)) { |
| 294 | 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] | 295 | file, line, arg, proxy_type_str(proxy), proxy->id, msg, hint ? hint : ""); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 296 | return 1; |
| 297 | } |
| 298 | return 0; |
| 299 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 300 | |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 301 | /* Report a warning if a rule is placed after a 'block' rule. |
| 302 | * Return 1 if the warning has been emitted, otherwise 0. |
| 303 | */ |
| 304 | int warnif_rule_after_block(struct proxy *proxy, const char *file, int line, char *arg) |
| 305 | { |
| 306 | if (!LIST_ISEMPTY(&proxy->block_cond)) { |
| 307 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'block' rule will still be processed before.\n", |
| 308 | file, line, arg); |
| 309 | return 1; |
| 310 | } |
| 311 | return 0; |
| 312 | } |
| 313 | |
| 314 | /* Report a warning if a rule is placed after a reqrewrite rule. |
| 315 | * Return 1 if the warning has been emitted, otherwise 0. |
| 316 | */ |
| 317 | int warnif_rule_after_reqxxx(struct proxy *proxy, const char *file, int line, char *arg) |
| 318 | { |
| 319 | if (proxy->req_exp) { |
| 320 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'reqxxx' rule will still be processed before.\n", |
| 321 | file, line, arg); |
| 322 | return 1; |
| 323 | } |
| 324 | return 0; |
| 325 | } |
| 326 | |
| 327 | /* Report a warning if a rule is placed after a reqadd rule. |
| 328 | * Return 1 if the warning has been emitted, otherwise 0. |
| 329 | */ |
| 330 | int warnif_rule_after_reqadd(struct proxy *proxy, const char *file, int line, char *arg) |
| 331 | { |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 332 | if (!LIST_ISEMPTY(&proxy->req_add)) { |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 333 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'reqadd' rule will still be processed before.\n", |
| 334 | file, line, arg); |
| 335 | return 1; |
| 336 | } |
| 337 | return 0; |
| 338 | } |
| 339 | |
| 340 | /* Report a warning if a rule is placed after a redirect rule. |
| 341 | * Return 1 if the warning has been emitted, otherwise 0. |
| 342 | */ |
| 343 | int warnif_rule_after_redirect(struct proxy *proxy, const char *file, int line, char *arg) |
| 344 | { |
| 345 | if (!LIST_ISEMPTY(&proxy->redirect_rules)) { |
| 346 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'redirect' rule will still be processed before.\n", |
| 347 | file, line, arg); |
| 348 | return 1; |
| 349 | } |
| 350 | return 0; |
| 351 | } |
| 352 | |
| 353 | /* Report a warning if a rule is placed after a 'use_backend' rule. |
| 354 | * Return 1 if the warning has been emitted, otherwise 0. |
| 355 | */ |
| 356 | int warnif_rule_after_use_backend(struct proxy *proxy, const char *file, int line, char *arg) |
| 357 | { |
| 358 | if (!LIST_ISEMPTY(&proxy->switching_rules)) { |
| 359 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'use_backend' rule will still be processed before.\n", |
| 360 | file, line, arg); |
| 361 | return 1; |
| 362 | } |
| 363 | return 0; |
| 364 | } |
| 365 | |
| 366 | /* report a warning if a block rule is dangerously placed */ |
| 367 | int warnif_misplaced_block(struct proxy *proxy, const char *file, int line, char *arg) |
| 368 | { |
| 369 | return warnif_rule_after_reqxxx(proxy, file, line, arg) || |
| 370 | warnif_rule_after_reqadd(proxy, file, line, arg) || |
| 371 | warnif_rule_after_redirect(proxy, file, line, arg) || |
| 372 | warnif_rule_after_use_backend(proxy, file, line, arg); |
| 373 | } |
| 374 | |
| 375 | /* report a warning if a reqxxx rule is dangerously placed */ |
| 376 | int warnif_misplaced_reqxxx(struct proxy *proxy, const char *file, int line, char *arg) |
| 377 | { |
| 378 | return warnif_rule_after_reqadd(proxy, file, line, arg) || |
| 379 | warnif_rule_after_redirect(proxy, file, line, arg) || |
| 380 | warnif_rule_after_use_backend(proxy, file, line, arg); |
| 381 | } |
| 382 | |
| 383 | /* report a warning if a reqadd rule is dangerously placed */ |
| 384 | int warnif_misplaced_reqadd(struct proxy *proxy, const char *file, int line, char *arg) |
| 385 | { |
| 386 | return warnif_rule_after_redirect(proxy, file, line, arg) || |
| 387 | warnif_rule_after_use_backend(proxy, file, line, arg); |
| 388 | } |
| 389 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 390 | /* |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 391 | * parse a line in a <global> section. Returns the error code, 0 if OK, or |
| 392 | * any combination of : |
| 393 | * - ERR_ABORT: must abort ASAP |
| 394 | * - ERR_FATAL: we can continue parsing but not start the service |
| 395 | * - ERR_WARN: a warning has been emitted |
| 396 | * - ERR_ALERT: an alert has been emitted |
| 397 | * Only the two first ones can stop processing, the two others are just |
| 398 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 399 | */ |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 400 | 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] | 401 | { |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 402 | int err_code = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 403 | |
| 404 | if (!strcmp(args[0], "global")) { /* new section */ |
| 405 | /* no option, nothing special to do */ |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 406 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 407 | } |
| 408 | else if (!strcmp(args[0], "daemon")) { |
| 409 | global.mode |= MODE_DAEMON; |
| 410 | } |
| 411 | else if (!strcmp(args[0], "debug")) { |
| 412 | global.mode |= MODE_DEBUG; |
| 413 | } |
| 414 | else if (!strcmp(args[0], "noepoll")) { |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 415 | global.tune.options &= ~GTUNE_USE_EPOLL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 416 | } |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 417 | else if (!strcmp(args[0], "nosepoll")) { |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 418 | global.tune.options &= ~GTUNE_USE_SEPOLL; |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 419 | } |
| 420 | else if (!strcmp(args[0], "nokqueue")) { |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 421 | global.tune.options &= ~GTUNE_USE_KQUEUE; |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 422 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 423 | else if (!strcmp(args[0], "nopoll")) { |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 424 | global.tune.options &= ~GTUNE_USE_POLL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 425 | } |
Willy Tarreau | 3ab68cf | 2009-01-25 16:03:28 +0100 | [diff] [blame] | 426 | else if (!strcmp(args[0], "nosplice")) { |
| 427 | global.tune.options &= ~GTUNE_USE_SPLICE; |
| 428 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 429 | else if (!strcmp(args[0], "quiet")) { |
| 430 | global.mode |= MODE_QUIET; |
| 431 | } |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 432 | else if (!strcmp(args[0], "tune.maxpollevents")) { |
| 433 | if (global.tune.maxpollevents != 0) { |
| 434 | 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] | 435 | err_code |= ERR_ALERT; |
| 436 | goto out; |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 437 | } |
| 438 | if (*(args[1]) == 0) { |
| 439 | 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] | 440 | err_code |= ERR_ALERT | ERR_FATAL; |
| 441 | goto out; |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 442 | } |
| 443 | global.tune.maxpollevents = atol(args[1]); |
| 444 | } |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 445 | else if (!strcmp(args[0], "tune.maxaccept")) { |
| 446 | if (global.tune.maxaccept != 0) { |
| 447 | 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] | 448 | err_code |= ERR_ALERT; |
| 449 | goto out; |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 450 | } |
| 451 | if (*(args[1]) == 0) { |
| 452 | 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] | 453 | err_code |= ERR_ALERT | ERR_FATAL; |
| 454 | goto out; |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 455 | } |
| 456 | global.tune.maxaccept = atol(args[1]); |
| 457 | } |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 458 | else if (!strcmp(args[0], "tune.bufsize")) { |
| 459 | if (*(args[1]) == 0) { |
| 460 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 461 | err_code |= ERR_ALERT | ERR_FATAL; |
| 462 | goto out; |
| 463 | } |
| 464 | global.tune.bufsize = atol(args[1]); |
| 465 | if (global.tune.maxrewrite >= global.tune.bufsize / 2) |
| 466 | global.tune.maxrewrite = global.tune.bufsize / 2; |
| 467 | } |
| 468 | else if (!strcmp(args[0], "tune.maxrewrite")) { |
| 469 | if (*(args[1]) == 0) { |
| 470 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 471 | err_code |= ERR_ALERT | ERR_FATAL; |
| 472 | goto out; |
| 473 | } |
| 474 | global.tune.maxrewrite = atol(args[1]); |
| 475 | if (global.tune.maxrewrite >= global.tune.bufsize / 2) |
| 476 | global.tune.maxrewrite = global.tune.bufsize / 2; |
| 477 | } |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 478 | else if (!strcmp(args[0], "tune.rcvbuf.client")) { |
| 479 | if (global.tune.client_rcvbuf != 0) { |
| 480 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 481 | err_code |= ERR_ALERT; |
| 482 | goto out; |
| 483 | } |
| 484 | if (*(args[1]) == 0) { |
| 485 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 486 | err_code |= ERR_ALERT | ERR_FATAL; |
| 487 | goto out; |
| 488 | } |
| 489 | global.tune.client_rcvbuf = atol(args[1]); |
| 490 | } |
| 491 | else if (!strcmp(args[0], "tune.rcvbuf.server")) { |
| 492 | if (global.tune.server_rcvbuf != 0) { |
| 493 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 494 | err_code |= ERR_ALERT; |
| 495 | goto out; |
| 496 | } |
| 497 | if (*(args[1]) == 0) { |
| 498 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 499 | err_code |= ERR_ALERT | ERR_FATAL; |
| 500 | goto out; |
| 501 | } |
| 502 | global.tune.server_rcvbuf = atol(args[1]); |
| 503 | } |
| 504 | else if (!strcmp(args[0], "tune.sndbuf.client")) { |
| 505 | if (global.tune.client_sndbuf != 0) { |
| 506 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 507 | err_code |= ERR_ALERT; |
| 508 | goto out; |
| 509 | } |
| 510 | if (*(args[1]) == 0) { |
| 511 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 512 | err_code |= ERR_ALERT | ERR_FATAL; |
| 513 | goto out; |
| 514 | } |
| 515 | global.tune.client_sndbuf = atol(args[1]); |
| 516 | } |
| 517 | else if (!strcmp(args[0], "tune.sndbuf.server")) { |
| 518 | if (global.tune.server_sndbuf != 0) { |
| 519 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 520 | err_code |= ERR_ALERT; |
| 521 | goto out; |
| 522 | } |
| 523 | if (*(args[1]) == 0) { |
| 524 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 525 | err_code |= ERR_ALERT | ERR_FATAL; |
| 526 | goto out; |
| 527 | } |
| 528 | global.tune.server_sndbuf = atol(args[1]); |
| 529 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 530 | else if (!strcmp(args[0], "uid")) { |
| 531 | if (global.uid != 0) { |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 532 | Alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 533 | err_code |= ERR_ALERT; |
| 534 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 535 | } |
| 536 | if (*(args[1]) == 0) { |
| 537 | 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] | 538 | err_code |= ERR_ALERT | ERR_FATAL; |
| 539 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 540 | } |
| 541 | global.uid = atol(args[1]); |
| 542 | } |
| 543 | else if (!strcmp(args[0], "gid")) { |
| 544 | if (global.gid != 0) { |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 545 | Alert("parsing [%s:%d] : group/gid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 546 | err_code |= ERR_ALERT; |
| 547 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 548 | } |
| 549 | if (*(args[1]) == 0) { |
| 550 | 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] | 551 | err_code |= ERR_ALERT | ERR_FATAL; |
| 552 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 553 | } |
| 554 | global.gid = atol(args[1]); |
| 555 | } |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 556 | /* user/group name handling */ |
| 557 | else if (!strcmp(args[0], "user")) { |
| 558 | struct passwd *ha_user; |
| 559 | if (global.uid != 0) { |
| 560 | Alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 561 | err_code |= ERR_ALERT; |
| 562 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 563 | } |
| 564 | errno = 0; |
| 565 | ha_user = getpwnam(args[1]); |
| 566 | if (ha_user != NULL) { |
| 567 | global.uid = (int)ha_user->pw_uid; |
| 568 | } |
| 569 | else { |
| 570 | 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] | 571 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 572 | } |
| 573 | } |
| 574 | else if (!strcmp(args[0], "group")) { |
| 575 | struct group *ha_group; |
| 576 | if (global.gid != 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 577 | 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] | 578 | err_code |= ERR_ALERT; |
| 579 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 580 | } |
| 581 | errno = 0; |
| 582 | ha_group = getgrnam(args[1]); |
| 583 | if (ha_group != NULL) { |
| 584 | global.gid = (int)ha_group->gr_gid; |
| 585 | } |
| 586 | else { |
| 587 | 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] | 588 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 589 | } |
| 590 | } |
| 591 | /* end of user/group name handling*/ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 592 | else if (!strcmp(args[0], "nbproc")) { |
| 593 | if (global.nbproc != 0) { |
| 594 | 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] | 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.nbproc = atol(args[1]); |
| 604 | } |
| 605 | else if (!strcmp(args[0], "maxconn")) { |
| 606 | if (global.maxconn != 0) { |
| 607 | 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] | 608 | err_code |= ERR_ALERT; |
| 609 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 610 | } |
| 611 | if (*(args[1]) == 0) { |
| 612 | 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] | 613 | err_code |= ERR_ALERT | ERR_FATAL; |
| 614 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 615 | } |
| 616 | global.maxconn = atol(args[1]); |
| 617 | #ifdef SYSTEM_MAXCONN |
| 618 | if (global.maxconn > DEFAULT_MAXCONN && cfg_maxconn <= DEFAULT_MAXCONN) { |
| 619 | 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); |
| 620 | global.maxconn = DEFAULT_MAXCONN; |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 621 | err_code |= ERR_ALERT; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 622 | } |
| 623 | #endif /* SYSTEM_MAXCONN */ |
| 624 | } |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 625 | else if (!strcmp(args[0], "maxpipes")) { |
| 626 | if (global.maxpipes != 0) { |
| 627 | 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] | 628 | err_code |= ERR_ALERT; |
| 629 | goto out; |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 630 | } |
| 631 | if (*(args[1]) == 0) { |
| 632 | 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] | 633 | err_code |= ERR_ALERT | ERR_FATAL; |
| 634 | goto out; |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 635 | } |
| 636 | global.maxpipes = atol(args[1]); |
| 637 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 638 | else if (!strcmp(args[0], "ulimit-n")) { |
| 639 | if (global.rlimit_nofile != 0) { |
| 640 | 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] | 641 | err_code |= ERR_ALERT; |
| 642 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 643 | } |
| 644 | if (*(args[1]) == 0) { |
| 645 | 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] | 646 | err_code |= ERR_ALERT | ERR_FATAL; |
| 647 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 648 | } |
| 649 | global.rlimit_nofile = atol(args[1]); |
| 650 | } |
| 651 | else if (!strcmp(args[0], "chroot")) { |
| 652 | if (global.chroot != NULL) { |
| 653 | 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] | 654 | err_code |= ERR_ALERT; |
| 655 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 656 | } |
| 657 | if (*(args[1]) == 0) { |
| 658 | 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] | 659 | err_code |= ERR_ALERT | ERR_FATAL; |
| 660 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 661 | } |
| 662 | global.chroot = strdup(args[1]); |
| 663 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 664 | else if (!strcmp(args[0], "description")) { |
| 665 | int i, len=0; |
| 666 | char *d; |
| 667 | |
| 668 | if (!*args[1]) { |
| 669 | Alert("parsing [%s:%d]: '%s' expects a string argument.\n", |
| 670 | file, linenum, args[0]); |
| 671 | err_code |= ERR_ALERT | ERR_FATAL; |
| 672 | goto out; |
| 673 | } |
| 674 | |
| 675 | for(i=1; *args[i]; i++) |
| 676 | len += strlen(args[i])+1; |
| 677 | |
| 678 | if (global.desc) |
| 679 | free(global.desc); |
| 680 | |
| 681 | global.desc = d = (char *)calloc(1, len); |
| 682 | |
| 683 | d += sprintf(d, "%s", args[1]); |
| 684 | for(i=2; *args[i]; i++) |
| 685 | d += sprintf(d, " %s", args[i]); |
| 686 | } |
| 687 | else if (!strcmp(args[0], "node")) { |
| 688 | int i; |
| 689 | char c; |
| 690 | |
| 691 | for (i=0; args[1][i]; i++) { |
| 692 | c = args[1][i]; |
| 693 | if (!isupper(c) && !islower(c) && !isdigit(c) && c != '_' && c != '-' && c != '.') |
| 694 | break; |
| 695 | } |
| 696 | |
| 697 | if (!i || args[1][i]) { |
| 698 | Alert("parsing [%s:%d]: '%s' requires valid node name - non-empty string" |
| 699 | " with digits(0-9), letters(A-Z, a-z), dot(.), hyphen(-) or underscode(_).\n", |
| 700 | file, linenum, args[0]); |
| 701 | err_code |= ERR_ALERT | ERR_FATAL; |
| 702 | goto out; |
| 703 | } |
| 704 | |
| 705 | if (global.node) |
| 706 | free(global.node); |
| 707 | |
| 708 | global.node = strdup(args[1]); |
| 709 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 710 | else if (!strcmp(args[0], "pidfile")) { |
| 711 | if (global.pidfile != NULL) { |
| 712 | 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] | 713 | err_code |= ERR_ALERT; |
| 714 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 715 | } |
| 716 | if (*(args[1]) == 0) { |
| 717 | 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] | 718 | err_code |= ERR_ALERT | ERR_FATAL; |
| 719 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 720 | } |
| 721 | global.pidfile = strdup(args[1]); |
| 722 | } |
| 723 | else if (!strcmp(args[0], "log")) { /* syslog server address */ |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 724 | struct logsrv logsrv; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 725 | int facility, level, minlvl; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 726 | |
| 727 | if (*(args[1]) == 0 || *(args[2]) == 0) { |
| 728 | 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] | 729 | err_code |= ERR_ALERT | ERR_FATAL; |
| 730 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 731 | } |
| 732 | |
| 733 | facility = get_log_facility(args[2]); |
| 734 | if (facility < 0) { |
| 735 | 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] | 736 | err_code |= ERR_ALERT | ERR_FATAL; |
| 737 | facility = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 738 | } |
| 739 | |
| 740 | level = 7; /* max syslog level = debug */ |
| 741 | if (*(args[3])) { |
| 742 | level = get_log_level(args[3]); |
| 743 | if (level < 0) { |
| 744 | 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] | 745 | err_code |= ERR_ALERT | ERR_FATAL; |
| 746 | level = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 747 | } |
| 748 | } |
| 749 | |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 750 | minlvl = 0; /* limit syslog level to this level (emerg) */ |
| 751 | if (*(args[4])) { |
| 752 | minlvl = get_log_level(args[4]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 753 | if (minlvl < 0) { |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 754 | 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] | 755 | err_code |= ERR_ALERT | ERR_FATAL; |
| 756 | minlvl = 0; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 757 | } |
| 758 | } |
| 759 | |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 760 | if (args[1][0] == '/') { |
| 761 | logsrv.u.addr.sa_family = AF_UNIX; |
| 762 | logsrv.u.un = *str2sun(args[1]); |
| 763 | } else { |
| 764 | logsrv.u.addr.sa_family = AF_INET; |
| 765 | logsrv.u.in = *str2sa(args[1]); |
| 766 | if (!logsrv.u.in.sin_port) |
| 767 | logsrv.u.in.sin_port = htons(SYSLOG_PORT); |
| 768 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 769 | |
| 770 | if (global.logfac1 == -1) { |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 771 | global.logsrv1 = logsrv; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 772 | global.logfac1 = facility; |
| 773 | global.loglev1 = level; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 774 | global.minlvl1 = minlvl; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 775 | } |
| 776 | else if (global.logfac2 == -1) { |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 777 | global.logsrv2 = logsrv; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 778 | global.logfac2 = facility; |
| 779 | global.loglev2 = level; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 780 | global.minlvl2 = minlvl; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 781 | } |
| 782 | else { |
| 783 | Alert("parsing [%s:%d] : too many syslog servers\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 784 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 785 | } |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 786 | } |
| 787 | else if (!strcmp(args[0], "spread-checks")) { /* random time between checks (0-50) */ |
| 788 | if (global.spread_checks != 0) { |
| 789 | Alert("parsing [%s:%d]: spread-checks already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 790 | err_code |= ERR_ALERT; |
| 791 | goto out; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 792 | } |
| 793 | if (*(args[1]) == 0) { |
| 794 | 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] | 795 | err_code |= ERR_ALERT | ERR_FATAL; |
| 796 | goto out; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 797 | } |
| 798 | global.spread_checks = atol(args[1]); |
| 799 | if (global.spread_checks < 0 || global.spread_checks > 50) { |
| 800 | 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] | 801 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 802 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 803 | } |
| 804 | else { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 805 | struct cfg_kw_list *kwl; |
| 806 | int index; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 807 | int rc; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 808 | |
| 809 | list_for_each_entry(kwl, &cfg_keywords.list, list) { |
| 810 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 811 | if (kwl->kw[index].section != CFG_GLOBAL) |
| 812 | continue; |
| 813 | if (strcmp(kwl->kw[index].kw, args[0]) == 0) { |
| 814 | /* prepare error message just in case */ |
| 815 | snprintf(trash, sizeof(trash), |
| 816 | "error near '%s' in '%s' section", args[0], "global"); |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 817 | rc = kwl->kw[index].parse(args, CFG_GLOBAL, NULL, NULL, trash, sizeof(trash)); |
| 818 | if (rc < 0) { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 819 | Alert("parsing [%s:%d] : %s\n", file, linenum, trash); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 820 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 821 | } |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 822 | else if (rc > 0) { |
| 823 | Warning("parsing [%s:%d] : %s\n", file, linenum, trash); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 824 | err_code |= ERR_WARN; |
| 825 | goto out; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 826 | } |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 827 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 828 | } |
| 829 | } |
| 830 | } |
| 831 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 832 | 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] | 833 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 834 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 835 | |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 836 | out: |
| 837 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 838 | } |
| 839 | |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 840 | /* Perform the most basic initialization of a proxy : |
| 841 | * memset(), list_init(*), reset_timeouts(*). |
| 842 | */ |
| 843 | static void init_new_proxy(struct proxy *p) |
| 844 | { |
| 845 | memset(p, 0, sizeof(struct proxy)); |
| 846 | LIST_INIT(&p->pendconns); |
| 847 | LIST_INIT(&p->acl); |
| 848 | LIST_INIT(&p->block_cond); |
| 849 | LIST_INIT(&p->redirect_rules); |
| 850 | LIST_INIT(&p->mon_fail_cond); |
| 851 | LIST_INIT(&p->switching_rules); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 852 | LIST_INIT(&p->force_persist_rules); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 853 | LIST_INIT(&p->sticking_rules); |
| 854 | LIST_INIT(&p->storersp_rules); |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 855 | LIST_INIT(&p->tcp_req.inspect_rules); |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 856 | LIST_INIT(&p->req_add); |
| 857 | LIST_INIT(&p->rsp_add); |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 858 | |
| 859 | /* Timeouts are defined as -1 */ |
| 860 | proxy_reset_timeouts(p); |
| 861 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 862 | |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 863 | void init_default_instance() |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 864 | { |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 865 | init_new_proxy(&defproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 866 | defproxy.mode = PR_MODE_TCP; |
| 867 | defproxy.state = PR_STNEW; |
| 868 | defproxy.maxconn = cfg_maxpconn; |
| 869 | defproxy.conn_retries = CONN_RETRIES; |
| 870 | defproxy.logfac1 = defproxy.logfac2 = -1; /* log disabled */ |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 871 | |
| 872 | defproxy.defsrv.inter = DEF_CHKINTR; |
| 873 | defproxy.defsrv.fastinter = 0; |
| 874 | defproxy.defsrv.downinter = 0; |
| 875 | defproxy.defsrv.rise = DEF_RISETIME; |
| 876 | defproxy.defsrv.fall = DEF_FALLTIME; |
| 877 | defproxy.defsrv.check_port = 0; |
| 878 | defproxy.defsrv.maxqueue = 0; |
| 879 | defproxy.defsrv.minconn = 0; |
| 880 | defproxy.defsrv.maxconn = 0; |
| 881 | defproxy.defsrv.slowstart = 0; |
| 882 | defproxy.defsrv.onerror = DEF_HANA_ONERR; |
| 883 | defproxy.defsrv.consecutive_errors_limit = DEF_HANA_ERRLIMIT; |
| 884 | defproxy.defsrv.uweight = defproxy.defsrv.iweight = 1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 885 | } |
| 886 | |
| 887 | /* |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 888 | * Parse a line in a <listen>, <frontend>, <backend> or <ruleset> section. |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 889 | * Returns the error code, 0 if OK, or any combination of : |
| 890 | * - ERR_ABORT: must abort ASAP |
| 891 | * - ERR_FATAL: we can continue parsing but not start the service |
| 892 | * - ERR_WARN: a warning has been emitted |
| 893 | * - ERR_ALERT: an alert has been emitted |
| 894 | * Only the two first ones can stop processing, the two others are just |
| 895 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 896 | */ |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 897 | 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] | 898 | { |
| 899 | static struct proxy *curproxy = NULL; |
| 900 | struct server *newsrv = NULL; |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 901 | const char *err; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 902 | int rc; |
| 903 | unsigned val; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 904 | int err_code = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 905 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 906 | if (!strcmp(args[0], "listen")) |
| 907 | rc = PR_CAP_LISTEN; |
| 908 | else if (!strcmp(args[0], "frontend")) |
| 909 | rc = PR_CAP_FE | PR_CAP_RS; |
| 910 | else if (!strcmp(args[0], "backend")) |
| 911 | rc = PR_CAP_BE | PR_CAP_RS; |
| 912 | else if (!strcmp(args[0], "ruleset")) |
| 913 | rc = PR_CAP_RS; |
| 914 | else |
| 915 | rc = PR_CAP_NONE; |
| 916 | |
| 917 | if (rc != PR_CAP_NONE) { /* new proxy */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 918 | if (!*args[1]) { |
| 919 | Alert("parsing [%s:%d] : '%s' expects an <id> argument and\n" |
| 920 | " optionnally supports [addr1]:port1[-end1]{,[addr]:port[-end]}...\n", |
| 921 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 922 | err_code |= ERR_ALERT | ERR_ABORT; |
| 923 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 924 | } |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 925 | |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 926 | err = invalid_char(args[1]); |
| 927 | if (err) { |
| 928 | Alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 929 | file, linenum, *err, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 930 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 931 | } |
| 932 | |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 933 | for (curproxy = proxy; curproxy != NULL; curproxy = curproxy->next) { |
| 934 | /* |
| 935 | * If there are two proxies with the same name only following |
| 936 | * combinations are allowed: |
| 937 | * |
| 938 | * listen backend frontend ruleset |
| 939 | * listen - - - - |
| 940 | * backend - - OK - |
| 941 | * frontend - OK - - |
| 942 | * ruleset - - - - |
| 943 | */ |
| 944 | |
| 945 | if (!strcmp(curproxy->id, args[1]) && |
| 946 | (rc!=(PR_CAP_FE|PR_CAP_RS) || curproxy->cap!=(PR_CAP_BE|PR_CAP_RS)) && |
| 947 | (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] | 948 | Warning("Parsing [%s:%d]: %s '%s' has same name as another %s (declared at %s:%d).\n", |
| 949 | file, linenum, proxy_cap_str(rc), args[1], proxy_type_str(curproxy), |
| 950 | curproxy->conf.file, curproxy->conf.line); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 951 | err_code |= ERR_WARN; |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 952 | } |
| 953 | } |
| 954 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 955 | if ((curproxy = (struct proxy *)calloc(1, sizeof(struct proxy))) == NULL) { |
| 956 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 957 | err_code |= ERR_ALERT | ERR_ABORT; |
| 958 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 959 | } |
Willy Tarreau | 5af24ef | 2009-03-15 15:23:16 +0100 | [diff] [blame] | 960 | |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 961 | init_new_proxy(curproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 962 | curproxy->next = proxy; |
| 963 | proxy = curproxy; |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 964 | curproxy->conf.file = file; |
| 965 | curproxy->conf.line = linenum; |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 966 | curproxy->last_change = now.tv_sec; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 967 | curproxy->id = strdup(args[1]); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 968 | curproxy->cap = rc; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 969 | |
| 970 | /* parse the listener address if any */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 971 | if ((curproxy->cap & PR_CAP_FE) && *args[2]) { |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 972 | struct listener *new, *last = curproxy->listen; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 973 | if (!str2listener(args[2], curproxy)) { |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 974 | err_code |= ERR_FATAL; |
| 975 | goto out; |
| 976 | } |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 977 | new = curproxy->listen; |
| 978 | while (new != last) { |
| 979 | new->conf.file = file; |
| 980 | new->conf.line = linenum; |
| 981 | new = new->next; |
| 982 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 983 | global.maxsock++; |
| 984 | } |
| 985 | |
| 986 | /* set default values */ |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 987 | memcpy(&curproxy->defsrv, &defproxy.defsrv, sizeof(curproxy->defsrv)); |
| 988 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 989 | curproxy->state = defproxy.state; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 990 | curproxy->options = defproxy.options; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 991 | curproxy->options2 = defproxy.options2; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 992 | curproxy->no_options = defproxy.no_options; |
| 993 | curproxy->no_options2 = defproxy.no_options2; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 994 | curproxy->bind_proc = defproxy.bind_proc; |
Willy Tarreau | 3168223 | 2007-11-29 15:38:04 +0100 | [diff] [blame] | 995 | curproxy->lbprm.algo = defproxy.lbprm.algo; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 996 | curproxy->except_net = defproxy.except_net; |
| 997 | curproxy->except_mask = defproxy.except_mask; |
Maik Broemme | 36db02e | 2009-05-08 17:02:07 +0200 | [diff] [blame] | 998 | curproxy->except_to = defproxy.except_to; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 999 | curproxy->except_mask_to = defproxy.except_mask_to; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1000 | |
Willy Tarreau | 79f5fe8 | 2008-08-23 08:18:21 +0200 | [diff] [blame] | 1001 | if (defproxy.fwdfor_hdr_len) { |
| 1002 | curproxy->fwdfor_hdr_len = defproxy.fwdfor_hdr_len; |
| 1003 | curproxy->fwdfor_hdr_name = strdup(defproxy.fwdfor_hdr_name); |
| 1004 | } |
| 1005 | |
Willy Tarreau | b86db34 | 2009-11-30 11:50:16 +0100 | [diff] [blame] | 1006 | if (defproxy.orgto_hdr_len) { |
| 1007 | curproxy->orgto_hdr_len = defproxy.orgto_hdr_len; |
| 1008 | curproxy->orgto_hdr_name = strdup(defproxy.orgto_hdr_name); |
| 1009 | } |
| 1010 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1011 | if (curproxy->cap & PR_CAP_FE) { |
| 1012 | curproxy->maxconn = defproxy.maxconn; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 1013 | curproxy->backlog = defproxy.backlog; |
Willy Tarreau | 13a34bd | 2009-05-10 18:52:49 +0200 | [diff] [blame] | 1014 | curproxy->fe_sps_lim = defproxy.fe_sps_lim; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1015 | |
| 1016 | /* initialize error relocations */ |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1017 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) |
| 1018 | chunk_dup(&curproxy->errmsg[rc], &defproxy.errmsg[rc]); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1019 | |
| 1020 | curproxy->to_log = defproxy.to_log & ~LW_COOKIE & ~LW_REQHDR & ~ LW_RSPHDR; |
| 1021 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1022 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1023 | if (curproxy->cap & PR_CAP_BE) { |
| 1024 | curproxy->fullconn = defproxy.fullconn; |
| 1025 | curproxy->conn_retries = defproxy.conn_retries; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1026 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1027 | if (defproxy.check_req) |
| 1028 | curproxy->check_req = strdup(defproxy.check_req); |
| 1029 | curproxy->check_len = defproxy.check_len; |
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 | if (defproxy.cookie_name) |
| 1032 | curproxy->cookie_name = strdup(defproxy.cookie_name); |
| 1033 | curproxy->cookie_len = defproxy.cookie_len; |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 1034 | if (defproxy.cookie_domain) |
| 1035 | curproxy->cookie_domain = strdup(defproxy.cookie_domain); |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 1036 | |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 1037 | if (defproxy.rdp_cookie_name) |
| 1038 | curproxy->rdp_cookie_name = strdup(defproxy.rdp_cookie_name); |
| 1039 | curproxy->rdp_cookie_len = defproxy.rdp_cookie_len; |
| 1040 | |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 1041 | if (defproxy.url_param_name) |
| 1042 | curproxy->url_param_name = strdup(defproxy.url_param_name); |
| 1043 | curproxy->url_param_len = defproxy.url_param_len; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 1044 | |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 1045 | if (defproxy.hh_name) |
| 1046 | curproxy->hh_name = strdup(defproxy.hh_name); |
| 1047 | curproxy->hh_len = defproxy.hh_len; |
| 1048 | curproxy->hh_match_domain = defproxy.hh_match_domain; |
| 1049 | |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 1050 | if (defproxy.iface_name) |
| 1051 | curproxy->iface_name = strdup(defproxy.iface_name); |
| 1052 | curproxy->iface_len = defproxy.iface_len; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1053 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1054 | |
Willy Tarreau | 3b6b1a9 | 2009-07-23 13:24:23 +0200 | [diff] [blame] | 1055 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1056 | if (defproxy.capture_name) |
| 1057 | curproxy->capture_name = strdup(defproxy.capture_name); |
| 1058 | curproxy->capture_namelen = defproxy.capture_namelen; |
| 1059 | curproxy->capture_len = defproxy.capture_len; |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 1060 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1061 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1062 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 1063 | curproxy->timeout.client = defproxy.timeout.client; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 1064 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | 036fae0 | 2008-01-06 13:24:40 +0100 | [diff] [blame] | 1065 | curproxy->timeout.httpreq = defproxy.timeout.httpreq; |
Willy Tarreau | b16a574 | 2010-01-10 14:46:16 +0100 | [diff] [blame] | 1066 | curproxy->timeout.httpka = defproxy.timeout.httpka; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1067 | curproxy->uri_auth = defproxy.uri_auth; |
| 1068 | curproxy->mon_net = defproxy.mon_net; |
| 1069 | curproxy->mon_mask = defproxy.mon_mask; |
| 1070 | if (defproxy.monitor_uri) |
| 1071 | curproxy->monitor_uri = strdup(defproxy.monitor_uri); |
| 1072 | curproxy->monitor_uri_len = defproxy.monitor_uri_len; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 1073 | if (defproxy.defbe.name) |
| 1074 | curproxy->defbe.name = strdup(defproxy.defbe.name); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1075 | } |
| 1076 | |
| 1077 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 1078 | curproxy->timeout.connect = defproxy.timeout.connect; |
| 1079 | curproxy->timeout.server = defproxy.timeout.server; |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 1080 | curproxy->timeout.check = defproxy.timeout.check; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 1081 | curproxy->timeout.queue = defproxy.timeout.queue; |
Willy Tarreau | 51c9bde | 2008-01-06 13:40:03 +0100 | [diff] [blame] | 1082 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | cd7afc0 | 2009-07-12 10:03:17 +0200 | [diff] [blame] | 1083 | curproxy->timeout.httpreq = defproxy.timeout.httpreq; |
Willy Tarreau | b16a574 | 2010-01-10 14:46:16 +0100 | [diff] [blame] | 1084 | curproxy->timeout.httpka = defproxy.timeout.httpka; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1085 | curproxy->source_addr = defproxy.source_addr; |
| 1086 | } |
| 1087 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1088 | curproxy->mode = defproxy.mode; |
| 1089 | curproxy->logfac1 = defproxy.logfac1; |
| 1090 | curproxy->logsrv1 = defproxy.logsrv1; |
| 1091 | curproxy->loglev1 = defproxy.loglev1; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 1092 | curproxy->minlvl1 = defproxy.minlvl1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1093 | curproxy->logfac2 = defproxy.logfac2; |
| 1094 | curproxy->logsrv2 = defproxy.logsrv2; |
| 1095 | curproxy->loglev2 = defproxy.loglev2; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 1096 | curproxy->minlvl2 = defproxy.minlvl2; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1097 | curproxy->grace = defproxy.grace; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1098 | curproxy->conf.used_listener_id = EB_ROOT; |
| 1099 | curproxy->conf.used_server_id = EB_ROOT; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 1100 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1101 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1102 | } |
| 1103 | else if (!strcmp(args[0], "defaults")) { /* use this one to assign default values */ |
| 1104 | /* some variables may have already been initialized earlier */ |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 1105 | /* FIXME-20070101: we should do this too at the end of the |
| 1106 | * config parsing to free all default values. |
| 1107 | */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1108 | free(defproxy.check_req); |
| 1109 | free(defproxy.cookie_name); |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 1110 | free(defproxy.rdp_cookie_name); |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 1111 | free(defproxy.cookie_domain); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1112 | free(defproxy.url_param_name); |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 1113 | free(defproxy.hh_name); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1114 | free(defproxy.capture_name); |
| 1115 | free(defproxy.monitor_uri); |
| 1116 | free(defproxy.defbe.name); |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 1117 | free(defproxy.iface_name); |
Willy Tarreau | 79f5fe8 | 2008-08-23 08:18:21 +0200 | [diff] [blame] | 1118 | free(defproxy.fwdfor_hdr_name); |
| 1119 | defproxy.fwdfor_hdr_len = 0; |
Willy Tarreau | b86db34 | 2009-11-30 11:50:16 +0100 | [diff] [blame] | 1120 | free(defproxy.orgto_hdr_name); |
| 1121 | defproxy.orgto_hdr_len = 0; |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 1122 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1123 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1124 | chunk_destroy(&defproxy.errmsg[rc]); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 1125 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1126 | /* we cannot free uri_auth because it might already be used */ |
| 1127 | init_default_instance(); |
| 1128 | curproxy = &defproxy; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1129 | defproxy.cap = PR_CAP_LISTEN; /* all caps for now */ |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1130 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1131 | } |
| 1132 | else if (curproxy == NULL) { |
| 1133 | Alert("parsing [%s:%d] : 'listen' or 'defaults' expected.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1134 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1135 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1136 | } |
| 1137 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1138 | |
| 1139 | /* Now let's parse the proxy-specific keywords */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1140 | if (!strcmp(args[0], "bind")) { /* new listen addresses */ |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 1141 | struct listener *new_listen, *last_listen; |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1142 | int cur_arg; |
| 1143 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1144 | if (curproxy == &defproxy) { |
| 1145 | 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] | 1146 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1147 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1148 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1149 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1150 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1151 | |
| 1152 | if (strchr(args[1], ':') == NULL) { |
| 1153 | Alert("parsing [%s:%d] : '%s' expects [addr1]:port1[-end1]{,[addr]:port[-end]}... as arguments.\n", |
| 1154 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1155 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1156 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1157 | } |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 1158 | |
| 1159 | last_listen = curproxy->listen; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1160 | if (!str2listener(args[1], curproxy)) { |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1161 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1162 | goto out; |
| 1163 | } |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1164 | |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 1165 | new_listen = curproxy->listen; |
| 1166 | while (new_listen != last_listen) { |
| 1167 | new_listen->conf.file = file; |
| 1168 | new_listen->conf.line = linenum; |
| 1169 | new_listen = new_listen->next; |
| 1170 | } |
| 1171 | |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1172 | cur_arg = 2; |
| 1173 | while (*(args[cur_arg])) { |
| 1174 | if (!strcmp(args[cur_arg], "interface")) { /* specifically bind to this interface */ |
| 1175 | #ifdef SO_BINDTODEVICE |
| 1176 | struct listener *l; |
| 1177 | |
| 1178 | if (!*args[cur_arg + 1]) { |
| 1179 | Alert("parsing [%s:%d] : '%s' : missing interface name.\n", |
| 1180 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1181 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1182 | goto out; |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1183 | } |
| 1184 | |
| 1185 | for (l = curproxy->listen; l != last_listen; l = l->next) |
| 1186 | l->interface = strdup(args[cur_arg + 1]); |
| 1187 | |
| 1188 | global.last_checks |= LSTCHK_NETADM; |
| 1189 | |
| 1190 | cur_arg += 2; |
| 1191 | continue; |
| 1192 | #else |
| 1193 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 1194 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1195 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1196 | goto out; |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1197 | #endif |
| 1198 | } |
Willy Tarreau | be1b918 | 2009-06-14 18:48:19 +0200 | [diff] [blame] | 1199 | if (!strcmp(args[cur_arg], "mss")) { /* set MSS of listening socket */ |
| 1200 | #ifdef TCP_MAXSEG |
| 1201 | struct listener *l; |
| 1202 | int mss; |
| 1203 | |
| 1204 | if (!*args[cur_arg + 1]) { |
| 1205 | Alert("parsing [%s:%d] : '%s' : missing MSS value.\n", |
| 1206 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1207 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1208 | goto out; |
Willy Tarreau | be1b918 | 2009-06-14 18:48:19 +0200 | [diff] [blame] | 1209 | } |
| 1210 | |
| 1211 | mss = str2uic(args[cur_arg + 1]); |
| 1212 | if (mss < 1 || mss > 65535) { |
| 1213 | Alert("parsing [%s:%d]: %s expects an MSS value between 1 and 65535.\n", |
| 1214 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1215 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1216 | goto out; |
Willy Tarreau | be1b918 | 2009-06-14 18:48:19 +0200 | [diff] [blame] | 1217 | } |
| 1218 | |
| 1219 | for (l = curproxy->listen; l != last_listen; l = l->next) |
| 1220 | l->maxseg = mss; |
| 1221 | |
| 1222 | cur_arg += 2; |
| 1223 | continue; |
| 1224 | #else |
| 1225 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 1226 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1227 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1228 | goto out; |
Willy Tarreau | be1b918 | 2009-06-14 18:48:19 +0200 | [diff] [blame] | 1229 | #endif |
| 1230 | } |
Willy Tarreau | cb6cd43 | 2009-10-13 07:34:14 +0200 | [diff] [blame] | 1231 | |
| 1232 | if (!strcmp(args[cur_arg], "defer-accept")) { /* wait for some data for 1 second max before doing accept */ |
| 1233 | #ifdef TCP_DEFER_ACCEPT |
| 1234 | struct listener *l; |
| 1235 | |
| 1236 | for (l = curproxy->listen; l != last_listen; l = l->next) |
| 1237 | l->options |= LI_O_DEF_ACCEPT; |
| 1238 | |
| 1239 | cur_arg ++; |
| 1240 | continue; |
| 1241 | #else |
| 1242 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 1243 | file, linenum, args[0], args[cur_arg]); |
| 1244 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1245 | goto out; |
| 1246 | #endif |
| 1247 | } |
| 1248 | |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1249 | if (!strcmp(args[cur_arg], "transparent")) { /* transparently bind to these addresses */ |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 1250 | #ifdef CONFIG_HAP_LINUX_TPROXY |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 1251 | struct listener *l; |
| 1252 | |
| 1253 | for (l = curproxy->listen; l != last_listen; l = l->next) |
| 1254 | l->options |= LI_O_FOREIGN; |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1255 | |
| 1256 | cur_arg ++; |
| 1257 | continue; |
| 1258 | #else |
| 1259 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 1260 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1261 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1262 | goto out; |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1263 | #endif |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 1264 | } |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1265 | |
| 1266 | if (!strcmp(args[cur_arg], "name")) { |
| 1267 | struct listener *l; |
| 1268 | |
| 1269 | for (l = curproxy->listen; l != last_listen; l = l->next) |
| 1270 | l->name = strdup(args[cur_arg + 1]); |
| 1271 | |
| 1272 | cur_arg += 2; |
| 1273 | continue; |
| 1274 | } |
| 1275 | |
| 1276 | if (!strcmp(args[cur_arg], "id")) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1277 | struct eb32_node *node; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1278 | struct listener *l; |
| 1279 | |
| 1280 | if (curproxy->listen->next != last_listen) { |
| 1281 | Alert("parsing [%s:%d]: '%s' can be only used with a single socket.\n", |
| 1282 | file, linenum, args[cur_arg]); |
| 1283 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1284 | goto out; |
| 1285 | } |
| 1286 | |
| 1287 | if (!*args[cur_arg + 1]) { |
| 1288 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 1289 | file, linenum, args[cur_arg]); |
| 1290 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1291 | goto out; |
| 1292 | } |
| 1293 | |
| 1294 | curproxy->listen->luid = atol(args[cur_arg + 1]); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1295 | curproxy->listen->conf.id.key = curproxy->listen->luid; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1296 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1297 | if (curproxy->listen->luid <= 0) { |
| 1298 | Alert("parsing [%s:%d]: custom id has to be > 0\n", |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1299 | file, linenum); |
| 1300 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1301 | goto out; |
| 1302 | } |
| 1303 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1304 | node = eb32_lookup(&curproxy->conf.used_listener_id, curproxy->listen->luid); |
| 1305 | if (node) { |
| 1306 | l = container_of(node, struct listener, conf.id); |
| 1307 | Alert("parsing [%s:%d]: custom id %d for socket '%s' already used at %s:%d.\n", |
| 1308 | file, linenum, l->luid, args[1], l->conf.file, l->conf.line); |
| 1309 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1310 | goto out; |
| 1311 | } |
| 1312 | eb32_insert(&curproxy->conf.used_listener_id, &curproxy->listen->conf.id); |
| 1313 | |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1314 | cur_arg += 2; |
| 1315 | continue; |
| 1316 | } |
| 1317 | |
Willy Tarreau | cb6cd43 | 2009-10-13 07:34:14 +0200 | [diff] [blame] | 1318 | 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] | 1319 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1320 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1321 | goto out; |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 1322 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1323 | global.maxsock++; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1324 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1325 | } |
| 1326 | else if (!strcmp(args[0], "monitor-net")) { /* set the range of IPs to ignore */ |
| 1327 | if (!*args[1] || !str2net(args[1], &curproxy->mon_net, &curproxy->mon_mask)) { |
| 1328 | Alert("parsing [%s:%d] : '%s' expects address[/mask].\n", |
| 1329 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1330 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1331 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1332 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1333 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1334 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1335 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1336 | /* flush useless bits */ |
| 1337 | curproxy->mon_net.s_addr &= curproxy->mon_mask.s_addr; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1338 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1339 | } |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 1340 | else if (!strcmp(args[0], "monitor-uri")) { /* set the URI to intercept */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1341 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1342 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1343 | |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 1344 | if (!*args[1]) { |
| 1345 | Alert("parsing [%s:%d] : '%s' expects an URI.\n", |
| 1346 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1347 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1348 | goto out; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 1349 | } |
| 1350 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1351 | free(curproxy->monitor_uri); |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 1352 | curproxy->monitor_uri_len = strlen(args[1]); |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 1353 | curproxy->monitor_uri = (char *)calloc(1, curproxy->monitor_uri_len + 1); |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 1354 | memcpy(curproxy->monitor_uri, args[1], curproxy->monitor_uri_len); |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 1355 | curproxy->monitor_uri[curproxy->monitor_uri_len] = '\0'; |
| 1356 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1357 | goto out; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 1358 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1359 | else if (!strcmp(args[0], "mode")) { /* sets the proxy mode */ |
| 1360 | if (!strcmp(args[1], "http")) curproxy->mode = PR_MODE_HTTP; |
| 1361 | else if (!strcmp(args[1], "tcp")) curproxy->mode = PR_MODE_TCP; |
| 1362 | else if (!strcmp(args[1], "health")) curproxy->mode = PR_MODE_HEALTH; |
| 1363 | else { |
| 1364 | 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] | 1365 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1366 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1367 | } |
| 1368 | } |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 1369 | else if (!strcmp(args[0], "id")) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1370 | struct eb32_node *node; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 1371 | |
| 1372 | if (curproxy == &defproxy) { |
| 1373 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", |
| 1374 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1375 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1376 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 1377 | } |
| 1378 | |
| 1379 | if (!*args[1]) { |
| 1380 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 1381 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1382 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1383 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 1384 | } |
| 1385 | |
| 1386 | curproxy->uuid = atol(args[1]); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1387 | curproxy->conf.id.key = curproxy->uuid; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 1388 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1389 | if (curproxy->uuid <= 0) { |
| 1390 | Alert("parsing [%s:%d]: custom id has to be > 0.\n", |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 1391 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1392 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1393 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 1394 | } |
| 1395 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1396 | node = eb32_lookup(&used_proxy_id, curproxy->uuid); |
| 1397 | if (node) { |
| 1398 | struct proxy *target = container_of(node, struct proxy, conf.id); |
| 1399 | Alert("parsing [%s:%d]: %s %s reuses same custom id as %s %s (declared at %s:%d).\n", |
| 1400 | file, linenum, proxy_type_str(curproxy), curproxy->id, |
| 1401 | proxy_type_str(target), target->id, target->conf.file, target->conf.line); |
| 1402 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1403 | goto out; |
| 1404 | } |
| 1405 | eb32_insert(&used_proxy_id, &curproxy->conf.id); |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 1406 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1407 | else if (!strcmp(args[0], "description")) { |
| 1408 | int i, len=0; |
| 1409 | char *d; |
| 1410 | |
| 1411 | if (!*args[1]) { |
| 1412 | Alert("parsing [%s:%d]: '%s' expects a string argument.\n", |
| 1413 | file, linenum, args[0]); |
| 1414 | return -1; |
| 1415 | } |
| 1416 | |
| 1417 | for(i=1; *args[i]; i++) |
| 1418 | len += strlen(args[i])+1; |
| 1419 | |
| 1420 | d = (char *)calloc(1, len); |
| 1421 | curproxy->desc = d; |
| 1422 | |
| 1423 | d += sprintf(d, "%s", args[1]); |
| 1424 | for(i=2; *args[i]; i++) |
| 1425 | d += sprintf(d, " %s", args[i]); |
| 1426 | |
| 1427 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1428 | else if (!strcmp(args[0], "disabled")) { /* disables this proxy */ |
| 1429 | curproxy->state = PR_STSTOPPED; |
| 1430 | } |
| 1431 | else if (!strcmp(args[0], "enabled")) { /* enables this proxy (used to revert a disabled default) */ |
| 1432 | curproxy->state = PR_STNEW; |
| 1433 | } |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 1434 | else if (!strcmp(args[0], "bind-process")) { /* enable this proxy only on some processes */ |
| 1435 | int cur_arg = 1; |
| 1436 | unsigned int set = 0; |
| 1437 | |
| 1438 | while (*args[cur_arg]) { |
| 1439 | int u; |
| 1440 | if (strcmp(args[cur_arg], "all") == 0) { |
| 1441 | set = 0; |
| 1442 | break; |
| 1443 | } |
| 1444 | else if (strcmp(args[cur_arg], "odd") == 0) { |
| 1445 | set |= 0x55555555; |
| 1446 | } |
| 1447 | else if (strcmp(args[cur_arg], "even") == 0) { |
| 1448 | set |= 0xAAAAAAAA; |
| 1449 | } |
| 1450 | else { |
| 1451 | u = str2uic(args[cur_arg]); |
| 1452 | if (u < 1 || u > 32) { |
| 1453 | Alert("parsing [%s:%d]: %s expects 'all', 'odd', 'even', or process numbers from 1 to 32.\n", |
| 1454 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1455 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1456 | goto out; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 1457 | } |
| 1458 | if (u > global.nbproc) { |
| 1459 | Warning("parsing [%s:%d]: %s references process number higher than global.nbproc.\n", |
| 1460 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1461 | err_code |= ERR_WARN; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 1462 | } |
| 1463 | set |= 1 << (u - 1); |
| 1464 | } |
| 1465 | cur_arg++; |
| 1466 | } |
| 1467 | curproxy->bind_proc = set; |
| 1468 | } |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 1469 | else if (!strcmp(args[0], "acl")) { /* add an ACL */ |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 1470 | if (curproxy == &defproxy) { |
| 1471 | 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] | 1472 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1473 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 1474 | } |
| 1475 | |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 1476 | err = invalid_char(args[1]); |
| 1477 | if (err) { |
| 1478 | Alert("parsing [%s:%d] : character '%c' is not permitted in acl name '%s'.\n", |
| 1479 | file, linenum, *err, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1480 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 1481 | } |
| 1482 | |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 1483 | if (parse_acl((const char **)args + 1, &curproxy->acl) == NULL) { |
| 1484 | Alert("parsing [%s:%d] : error detected while parsing ACL '%s'.\n", |
| 1485 | file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1486 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1487 | goto out; |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 1488 | } |
| 1489 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1490 | else if (!strcmp(args[0], "cookie")) { /* cookie name */ |
| 1491 | int cur_arg; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1492 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1493 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1494 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1495 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1496 | if (*(args[1]) == 0) { |
| 1497 | Alert("parsing [%s:%d] : '%s' expects <cookie_name> as argument.\n", |
| 1498 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1499 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1500 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1501 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1502 | |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 1503 | free(curproxy->cookie_domain); curproxy->cookie_domain = NULL; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1504 | free(curproxy->cookie_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1505 | curproxy->cookie_name = strdup(args[1]); |
| 1506 | curproxy->cookie_len = strlen(curproxy->cookie_name); |
| 1507 | |
| 1508 | cur_arg = 2; |
| 1509 | while (*(args[cur_arg])) { |
| 1510 | if (!strcmp(args[cur_arg], "rewrite")) { |
| 1511 | curproxy->options |= PR_O_COOK_RW; |
| 1512 | } |
| 1513 | else if (!strcmp(args[cur_arg], "indirect")) { |
| 1514 | curproxy->options |= PR_O_COOK_IND; |
| 1515 | } |
| 1516 | else if (!strcmp(args[cur_arg], "insert")) { |
| 1517 | curproxy->options |= PR_O_COOK_INS; |
| 1518 | } |
| 1519 | else if (!strcmp(args[cur_arg], "nocache")) { |
| 1520 | curproxy->options |= PR_O_COOK_NOC; |
| 1521 | } |
| 1522 | else if (!strcmp(args[cur_arg], "postonly")) { |
| 1523 | curproxy->options |= PR_O_COOK_POST; |
| 1524 | } |
| 1525 | else if (!strcmp(args[cur_arg], "prefix")) { |
| 1526 | curproxy->options |= PR_O_COOK_PFX; |
| 1527 | } |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 1528 | else if (!strcmp(args[cur_arg], "domain")) { |
| 1529 | if (!*args[cur_arg + 1]) { |
| 1530 | Alert("parsing [%s:%d]: '%s' expects <domain> as argument.\n", |
| 1531 | file, linenum, args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1532 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1533 | goto out; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 1534 | } |
| 1535 | |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 1536 | if (*args[cur_arg + 1] != '.' || !strchr(args[cur_arg + 1] + 1, '.')) { |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 1537 | /* rfc2109, 4.3.2 Rejecting Cookies */ |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 1538 | Warning("parsing [%s:%d]: domain '%s' contains no embedded" |
| 1539 | " dots nor does not start with a dot." |
| 1540 | " RFC forbids it, this configuration may not work properly.\n", |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 1541 | file, linenum, args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 1542 | err_code |= ERR_WARN; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 1543 | } |
| 1544 | |
| 1545 | err = invalid_domainchar(args[cur_arg + 1]); |
| 1546 | if (err) { |
| 1547 | Alert("parsing [%s:%d]: character '%c' is not permitted in domain name '%s'.\n", |
| 1548 | file, linenum, *err, args[cur_arg + 1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1549 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1550 | goto out; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 1551 | } |
| 1552 | |
Willy Tarreau | 68a897b | 2009-12-03 23:28:34 +0100 | [diff] [blame] | 1553 | if (!curproxy->cookie_domain) { |
| 1554 | curproxy->cookie_domain = strdup(args[cur_arg + 1]); |
| 1555 | } else { |
| 1556 | /* one domain was already specified, add another one by |
| 1557 | * building the string which will be returned along with |
| 1558 | * the cookie. |
| 1559 | */ |
| 1560 | char *new_ptr; |
| 1561 | int new_len = strlen(curproxy->cookie_domain) + |
| 1562 | strlen("; domain=") + strlen(args[cur_arg + 1]) + 1; |
| 1563 | new_ptr = malloc(new_len); |
| 1564 | snprintf(new_ptr, new_len, "%s; domain=%s", curproxy->cookie_domain, args[cur_arg+1]); |
| 1565 | free(curproxy->cookie_domain); |
| 1566 | curproxy->cookie_domain = new_ptr; |
| 1567 | } |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 1568 | cur_arg++; |
| 1569 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1570 | else { |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 1571 | Alert("parsing [%s:%d] : '%s' supports 'rewrite', 'insert', 'prefix', 'indirect', 'nocache' and 'postonly', 'domain' options.\n", |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1572 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1573 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1574 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1575 | } |
| 1576 | cur_arg++; |
| 1577 | } |
| 1578 | if (!POWEROF2(curproxy->options & (PR_O_COOK_RW|PR_O_COOK_IND))) { |
| 1579 | Alert("parsing [%s:%d] : cookie 'rewrite' and 'indirect' modes are incompatible.\n", |
| 1580 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1581 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1582 | } |
| 1583 | |
| 1584 | if (!POWEROF2(curproxy->options & (PR_O_COOK_RW|PR_O_COOK_INS|PR_O_COOK_PFX))) { |
| 1585 | Alert("parsing [%s:%d] : cookie 'rewrite', 'insert' and 'prefix' modes are incompatible.\n", |
| 1586 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1587 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1588 | } |
| 1589 | }/* end else if (!strcmp(args[0], "cookie")) */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 1590 | else if (!strcmp(args[0], "persist")) { /* persist */ |
| 1591 | if (*(args[1]) == 0) { |
| 1592 | Alert("parsing [%s:%d] : missing persist method.\n", |
| 1593 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1594 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1595 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 1596 | } |
| 1597 | |
| 1598 | if (!strncmp(args[1], "rdp-cookie", 10)) { |
| 1599 | curproxy->options2 |= PR_O2_RDPC_PRST; |
| 1600 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 1601 | if (*(args[1] + 10) == '(') { /* cookie name */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 1602 | const char *beg, *end; |
| 1603 | |
| 1604 | beg = args[1] + 11; |
| 1605 | end = strchr(beg, ')'); |
| 1606 | |
| 1607 | if (!end || end == beg) { |
| 1608 | Alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n", |
| 1609 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1610 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1611 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 1612 | } |
| 1613 | |
| 1614 | free(curproxy->rdp_cookie_name); |
| 1615 | curproxy->rdp_cookie_name = my_strndup(beg, end - beg); |
| 1616 | curproxy->rdp_cookie_len = end-beg; |
| 1617 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 1618 | else if (*(args[1] + 10) == '\0') { /* default cookie name 'msts' */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 1619 | free(curproxy->rdp_cookie_name); |
| 1620 | curproxy->rdp_cookie_name = strdup("msts"); |
| 1621 | curproxy->rdp_cookie_len = strlen(curproxy->rdp_cookie_name); |
| 1622 | } |
| 1623 | else { /* syntax */ |
| 1624 | Alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n", |
| 1625 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1626 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1627 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 1628 | } |
| 1629 | } |
| 1630 | else { |
| 1631 | Alert("parsing [%s:%d] : unknown persist method.\n", |
| 1632 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1633 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1634 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 1635 | } |
| 1636 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1637 | else if (!strcmp(args[0], "appsession")) { /* cookie name */ |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 1638 | int cur_arg; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1639 | |
Cyril Bonté | 3b7a369 | 2010-01-10 17:01:47 +0100 | [diff] [blame] | 1640 | if (curproxy == &defproxy) { |
| 1641 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 1642 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1643 | goto out; |
| 1644 | } |
| 1645 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1646 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1647 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1648 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1649 | if (*(args[5]) == 0) { |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 1650 | 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] | 1651 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1652 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1653 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1654 | } |
| 1655 | have_appsession = 1; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1656 | free(curproxy->appsession_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1657 | curproxy->appsession_name = strdup(args[1]); |
| 1658 | curproxy->appsession_name_len = strlen(curproxy->appsession_name); |
| 1659 | curproxy->appsession_len = atoi(args[3]); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 1660 | err = parse_time_err(args[5], &val, TIME_UNIT_MS); |
| 1661 | if (err) { |
| 1662 | Alert("parsing [%s:%d] : unexpected character '%c' in %s timeout.\n", |
| 1663 | file, linenum, *err, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1664 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1665 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 1666 | } |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 1667 | curproxy->timeout.appsession = val; |
Willy Tarreau | ee99136 | 2007-05-14 14:37:50 +0200 | [diff] [blame] | 1668 | |
Willy Tarreau | 51041c7 | 2007-09-09 21:56:53 +0200 | [diff] [blame] | 1669 | if (appsession_hash_init(&(curproxy->htbl_proxy), destroy) == 0) { |
| 1670 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1671 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1672 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1673 | } |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 1674 | |
| 1675 | cur_arg = 6; |
| 1676 | curproxy->options2 &= ~PR_O2_AS_REQL; |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 1677 | curproxy->options2 &= ~PR_O2_AS_M_ANY; |
| 1678 | curproxy->options2 |= PR_O2_AS_M_PP; |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 1679 | while (*(args[cur_arg])) { |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 1680 | if (!strcmp(args[cur_arg], "request-learn")) { |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 1681 | curproxy->options2 |= PR_O2_AS_REQL; |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 1682 | } else if (!strcmp(args[cur_arg], "prefix")) { |
| 1683 | curproxy->options2 |= PR_O2_AS_PFX; |
| 1684 | } else if (!strcmp(args[cur_arg], "mode")) { |
| 1685 | if (!*args[cur_arg + 1]) { |
| 1686 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 1687 | file, linenum, args[0], args[cur_arg]); |
| 1688 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1689 | goto out; |
| 1690 | } |
| 1691 | |
| 1692 | cur_arg++; |
| 1693 | if (!strcmp(args[cur_arg], "query-string")) { |
| 1694 | curproxy->options2 &= ~PR_O2_AS_M_ANY; |
| 1695 | curproxy->options2 |= PR_O2_AS_M_QS; |
| 1696 | } else if (!strcmp(args[cur_arg], "path-parameters")) { |
| 1697 | curproxy->options2 &= ~PR_O2_AS_M_ANY; |
| 1698 | curproxy->options2 |= PR_O2_AS_M_PP; |
| 1699 | } else { |
| 1700 | Alert("parsing [%s:%d] : unknown mode '%s'\n", file, linenum, args[cur_arg]); |
| 1701 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1702 | goto out; |
| 1703 | } |
| 1704 | } |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 1705 | cur_arg++; |
| 1706 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1707 | } /* Url App Session */ |
| 1708 | else if (!strcmp(args[0], "capture")) { |
Willy Tarreau | 3b6b1a9 | 2009-07-23 13:24:23 +0200 | [diff] [blame] | 1709 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1710 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1711 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1712 | if (!strcmp(args[1], "cookie")) { /* name of a cookie to capture */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1713 | if (*(args[4]) == 0) { |
| 1714 | Alert("parsing [%s:%d] : '%s' expects 'cookie' <cookie_name> 'len' <len>.\n", |
| 1715 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1716 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1717 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1718 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1719 | free(curproxy->capture_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1720 | curproxy->capture_name = strdup(args[2]); |
| 1721 | curproxy->capture_namelen = strlen(curproxy->capture_name); |
| 1722 | curproxy->capture_len = atol(args[4]); |
| 1723 | if (curproxy->capture_len >= CAPTURE_LEN) { |
| 1724 | Warning("parsing [%s:%d] : truncating capture length to %d bytes.\n", |
| 1725 | file, linenum, CAPTURE_LEN - 1); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1726 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1727 | curproxy->capture_len = CAPTURE_LEN - 1; |
| 1728 | } |
| 1729 | curproxy->to_log |= LW_COOKIE; |
| 1730 | } |
| 1731 | else if (!strcmp(args[1], "request") && !strcmp(args[2], "header")) { |
| 1732 | struct cap_hdr *hdr; |
| 1733 | |
| 1734 | if (curproxy == &defproxy) { |
| 1735 | 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] | 1736 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1737 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1738 | } |
| 1739 | |
| 1740 | if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) { |
| 1741 | Alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n", |
| 1742 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1743 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1744 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1745 | } |
| 1746 | |
| 1747 | hdr = calloc(sizeof(struct cap_hdr), 1); |
| 1748 | hdr->next = curproxy->req_cap; |
| 1749 | hdr->name = strdup(args[3]); |
| 1750 | hdr->namelen = strlen(args[3]); |
| 1751 | hdr->len = atol(args[5]); |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 1752 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1753 | hdr->index = curproxy->nb_req_cap++; |
| 1754 | curproxy->req_cap = hdr; |
| 1755 | curproxy->to_log |= LW_REQHDR; |
| 1756 | } |
| 1757 | else if (!strcmp(args[1], "response") && !strcmp(args[2], "header")) { |
| 1758 | struct cap_hdr *hdr; |
| 1759 | |
| 1760 | if (curproxy == &defproxy) { |
| 1761 | 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] | 1762 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1763 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1764 | } |
| 1765 | |
| 1766 | if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) { |
| 1767 | Alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n", |
| 1768 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1769 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1770 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1771 | } |
| 1772 | hdr = calloc(sizeof(struct cap_hdr), 1); |
| 1773 | hdr->next = curproxy->rsp_cap; |
| 1774 | hdr->name = strdup(args[3]); |
| 1775 | hdr->namelen = strlen(args[3]); |
| 1776 | hdr->len = atol(args[5]); |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 1777 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1778 | hdr->index = curproxy->nb_rsp_cap++; |
| 1779 | curproxy->rsp_cap = hdr; |
| 1780 | curproxy->to_log |= LW_RSPHDR; |
| 1781 | } |
| 1782 | else { |
| 1783 | Alert("parsing [%s:%d] : '%s' expects 'cookie' or 'request header' or 'response header'.\n", |
| 1784 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1785 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1786 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1787 | } |
| 1788 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1789 | else if (!strcmp(args[0], "retries")) { /* connection retries */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1790 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1791 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1792 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1793 | if (*(args[1]) == 0) { |
| 1794 | Alert("parsing [%s:%d] : '%s' expects an integer argument (dispatch counts for one).\n", |
| 1795 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1796 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1797 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1798 | } |
| 1799 | curproxy->conn_retries = atol(args[1]); |
| 1800 | } |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 1801 | else if (!strcmp(args[0], "block")) { /* early blocking based on ACLs */ |
| 1802 | int pol = ACL_COND_NONE; |
| 1803 | struct acl_cond *cond; |
| 1804 | |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 1805 | if (curproxy == &defproxy) { |
| 1806 | 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] | 1807 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1808 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 1809 | } |
| 1810 | |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 1811 | if (!strcmp(args[1], "if")) |
| 1812 | pol = ACL_COND_IF; |
| 1813 | else if (!strcmp(args[1], "unless")) |
| 1814 | pol = ACL_COND_UNLESS; |
| 1815 | |
| 1816 | if (pol == ACL_COND_NONE) { |
| 1817 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 1818 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1819 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1820 | goto out; |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 1821 | } |
| 1822 | |
| 1823 | if ((cond = parse_acl_cond((const char **)args + 2, &curproxy->acl, pol)) == NULL) { |
| 1824 | Alert("parsing [%s:%d] : error detected while parsing blocking condition.\n", |
| 1825 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1826 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1827 | goto out; |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 1828 | } |
Willy Tarreau | 8892235 | 2009-10-04 22:02:50 +0200 | [diff] [blame] | 1829 | cond->file = file; |
Willy Tarreau | a980263 | 2008-07-25 19:13:19 +0200 | [diff] [blame] | 1830 | cond->line = linenum; |
Willy Tarreau | a9fb083 | 2009-07-10 20:53:53 +0200 | [diff] [blame] | 1831 | curproxy->acl_requires |= cond->requires; |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 1832 | LIST_ADDQ(&curproxy->block_cond, &cond->list); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 1833 | warnif_misplaced_block(curproxy, file, linenum, args[0]); |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 1834 | } |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 1835 | else if (!strcmp(args[0], "redirect")) { |
| 1836 | int pol = ACL_COND_NONE; |
Willy Tarreau | f285f54 | 2010-01-03 20:03:03 +0100 | [diff] [blame] | 1837 | struct acl_cond *cond = NULL; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 1838 | struct redirect_rule *rule; |
| 1839 | int cur_arg; |
| 1840 | int type = REDIRECT_TYPE_NONE; |
| 1841 | int code = 302; |
| 1842 | char *destination = NULL; |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 1843 | char *cookie = NULL; |
| 1844 | int cookie_set = 0; |
Willy Tarreau | 79da469 | 2008-11-19 20:03:04 +0100 | [diff] [blame] | 1845 | unsigned int flags = REDIRECT_FLAG_NONE; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 1846 | |
| 1847 | cur_arg = 1; |
| 1848 | while (*(args[cur_arg])) { |
| 1849 | if (!strcmp(args[cur_arg], "location")) { |
| 1850 | if (!*args[cur_arg + 1]) { |
| 1851 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 1852 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1853 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1854 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 1855 | } |
| 1856 | |
| 1857 | type = REDIRECT_TYPE_LOCATION; |
| 1858 | cur_arg++; |
| 1859 | destination = args[cur_arg]; |
| 1860 | } |
| 1861 | else if (!strcmp(args[cur_arg], "prefix")) { |
| 1862 | if (!*args[cur_arg + 1]) { |
| 1863 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 1864 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1865 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1866 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 1867 | } |
| 1868 | |
| 1869 | type = REDIRECT_TYPE_PREFIX; |
| 1870 | cur_arg++; |
| 1871 | destination = args[cur_arg]; |
| 1872 | } |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 1873 | else if (!strcmp(args[cur_arg], "set-cookie")) { |
| 1874 | if (!*args[cur_arg + 1]) { |
| 1875 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 1876 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1877 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1878 | goto out; |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 1879 | } |
| 1880 | |
| 1881 | cur_arg++; |
| 1882 | cookie = args[cur_arg]; |
| 1883 | cookie_set = 1; |
| 1884 | } |
| 1885 | else if (!strcmp(args[cur_arg], "clear-cookie")) { |
| 1886 | if (!*args[cur_arg + 1]) { |
| 1887 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 1888 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1889 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1890 | goto out; |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 1891 | } |
| 1892 | |
| 1893 | cur_arg++; |
| 1894 | cookie = args[cur_arg]; |
| 1895 | cookie_set = 0; |
| 1896 | } |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 1897 | else if (!strcmp(args[cur_arg],"code")) { |
| 1898 | if (!*args[cur_arg + 1]) { |
| 1899 | Alert("parsing [%s:%d] : '%s': missing HTTP code.\n", |
| 1900 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1901 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1902 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 1903 | } |
| 1904 | cur_arg++; |
| 1905 | code = atol(args[cur_arg]); |
| 1906 | if (code < 301 || code > 303) { |
| 1907 | Alert("parsing [%s:%d] : '%s': unsupported HTTP code '%d'.\n", |
| 1908 | file, linenum, args[0], code); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1909 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1910 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 1911 | } |
| 1912 | } |
Willy Tarreau | 79da469 | 2008-11-19 20:03:04 +0100 | [diff] [blame] | 1913 | else if (!strcmp(args[cur_arg],"drop-query")) { |
| 1914 | flags |= REDIRECT_FLAG_DROP_QS; |
| 1915 | } |
Willy Tarreau | 81e3b4f | 2010-01-10 00:42:19 +0100 | [diff] [blame] | 1916 | else if (!strcmp(args[cur_arg],"append-slash")) { |
| 1917 | flags |= REDIRECT_FLAG_APPEND_SLASH; |
| 1918 | } |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 1919 | else if (!strcmp(args[cur_arg], "if")) { |
| 1920 | pol = ACL_COND_IF; |
| 1921 | cur_arg++; |
| 1922 | break; |
| 1923 | } |
| 1924 | else if (!strcmp(args[cur_arg], "unless")) { |
| 1925 | pol = ACL_COND_UNLESS; |
| 1926 | cur_arg++; |
| 1927 | break; |
| 1928 | } |
| 1929 | else { |
Willy Tarreau | 81e3b4f | 2010-01-10 00:42:19 +0100 | [diff] [blame] | 1930 | 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] | 1931 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1932 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1933 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 1934 | } |
| 1935 | cur_arg++; |
| 1936 | } |
| 1937 | |
| 1938 | if (type == REDIRECT_TYPE_NONE) { |
| 1939 | Alert("parsing [%s:%d] : '%s' expects a redirection type ('prefix' or 'location').\n", |
| 1940 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1941 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1942 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 1943 | } |
| 1944 | |
Willy Tarreau | f285f54 | 2010-01-03 20:03:03 +0100 | [diff] [blame] | 1945 | if (pol != ACL_COND_NONE && |
| 1946 | (cond = parse_acl_cond((const char **)args + cur_arg, &curproxy->acl, pol)) == NULL) { |
Jeffrey 'jf' Lim | af403fc | 2009-04-02 21:53:56 +0800 | [diff] [blame] | 1947 | Alert("parsing [%s:%d] : '%s': error detected while parsing redirect condition.\n", |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 1948 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1949 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1950 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 1951 | } |
| 1952 | |
Willy Tarreau | f285f54 | 2010-01-03 20:03:03 +0100 | [diff] [blame] | 1953 | if (cond) { |
| 1954 | cond->file = file; |
| 1955 | cond->line = linenum; |
| 1956 | curproxy->acl_requires |= cond->requires; |
| 1957 | } |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 1958 | rule = (struct redirect_rule *)calloc(1, sizeof(*rule)); |
| 1959 | rule->cond = cond; |
| 1960 | rule->rdr_str = strdup(destination); |
| 1961 | rule->rdr_len = strlen(destination); |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 1962 | if (cookie) { |
| 1963 | /* depending on cookie_set, either we want to set the cookie, or to clear it. |
| 1964 | * a clear consists in appending "; Max-Age=0" at the end. |
| 1965 | */ |
| 1966 | rule->cookie_len = strlen(cookie); |
| 1967 | if (cookie_set) |
| 1968 | rule->cookie_str = strdup(cookie); |
| 1969 | else { |
| 1970 | rule->cookie_str = malloc(rule->cookie_len + 12); |
| 1971 | memcpy(rule->cookie_str, cookie, rule->cookie_len); |
| 1972 | memcpy(rule->cookie_str + rule->cookie_len, "; Max-Age=0", 12); |
| 1973 | rule->cookie_len += 11; |
| 1974 | } |
| 1975 | } |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 1976 | rule->type = type; |
| 1977 | rule->code = code; |
Willy Tarreau | 79da469 | 2008-11-19 20:03:04 +0100 | [diff] [blame] | 1978 | rule->flags = flags; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 1979 | LIST_INIT(&rule->list); |
| 1980 | LIST_ADDQ(&curproxy->redirect_rules, &rule->list); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 1981 | warnif_rule_after_use_backend(curproxy, file, linenum, args[0]); |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 1982 | } |
Krzysztof Piotr Oledzki | 7b723ef | 2009-01-27 21:09:41 +0100 | [diff] [blame] | 1983 | else if (!strcmp(args[0], "use_backend")) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 1984 | int pol = ACL_COND_NONE; |
| 1985 | struct acl_cond *cond; |
| 1986 | struct switching_rule *rule; |
| 1987 | |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 1988 | if (curproxy == &defproxy) { |
| 1989 | 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] | 1990 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1991 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 1992 | } |
| 1993 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 1994 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1995 | err_code |= ERR_WARN; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 1996 | |
| 1997 | if (*(args[1]) == 0) { |
| 1998 | 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] | 1999 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2000 | goto out; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2001 | } |
| 2002 | |
| 2003 | if (!strcmp(args[2], "if")) |
| 2004 | pol = ACL_COND_IF; |
| 2005 | else if (!strcmp(args[2], "unless")) |
| 2006 | pol = ACL_COND_UNLESS; |
| 2007 | |
| 2008 | if (pol == ACL_COND_NONE) { |
| 2009 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 2010 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2011 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2012 | goto out; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2013 | } |
| 2014 | |
| 2015 | if ((cond = parse_acl_cond((const char **)args + 3, &curproxy->acl, pol)) == NULL) { |
Willy Tarreau | a980263 | 2008-07-25 19:13:19 +0200 | [diff] [blame] | 2016 | Alert("parsing [%s:%d] : error detected while parsing switching rule.\n", |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2017 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2018 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2019 | goto out; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2020 | } |
| 2021 | |
Willy Tarreau | 8892235 | 2009-10-04 22:02:50 +0200 | [diff] [blame] | 2022 | cond->file = file; |
Willy Tarreau | a980263 | 2008-07-25 19:13:19 +0200 | [diff] [blame] | 2023 | cond->line = linenum; |
Willy Tarreau | a9fb083 | 2009-07-10 20:53:53 +0200 | [diff] [blame] | 2024 | curproxy->acl_requires |= cond->requires; |
Willy Tarreau | a980263 | 2008-07-25 19:13:19 +0200 | [diff] [blame] | 2025 | if (cond->requires & ACL_USE_RTR_ANY) { |
Willy Tarreau | dd64f8d | 2008-07-27 22:02:32 +0200 | [diff] [blame] | 2026 | struct acl *acl; |
| 2027 | const char *name; |
| 2028 | |
| 2029 | acl = cond_find_require(cond, ACL_USE_RTR_ANY); |
| 2030 | name = acl ? acl->name : "(unknown)"; |
| 2031 | Warning("parsing [%s:%d] : acl '%s' involves some response-only criteria which will be ignored.\n", |
| 2032 | file, linenum, name); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2033 | err_code |= ERR_WARN; |
Willy Tarreau | a980263 | 2008-07-25 19:13:19 +0200 | [diff] [blame] | 2034 | } |
| 2035 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2036 | rule = (struct switching_rule *)calloc(1, sizeof(*rule)); |
| 2037 | rule->cond = cond; |
| 2038 | rule->be.name = strdup(args[1]); |
| 2039 | LIST_INIT(&rule->list); |
| 2040 | LIST_ADDQ(&curproxy->switching_rules, &rule->list); |
| 2041 | } |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2042 | else if (!strcmp(args[0], "force-persist")) { |
| 2043 | int pol = ACL_COND_NONE; |
| 2044 | struct acl_cond *cond; |
| 2045 | struct force_persist_rule *rule; |
| 2046 | |
| 2047 | if (curproxy == &defproxy) { |
| 2048 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2049 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2050 | goto out; |
| 2051 | } |
| 2052 | |
| 2053 | if (warnifnotcap(curproxy, PR_CAP_FE|PR_CAP_BE, file, linenum, args[0], NULL)) |
| 2054 | err_code |= ERR_WARN; |
| 2055 | |
| 2056 | if (!strcmp(args[1], "if")) |
| 2057 | pol = ACL_COND_IF; |
| 2058 | else if (!strcmp(args[1], "unless")) |
| 2059 | pol = ACL_COND_UNLESS; |
| 2060 | |
| 2061 | if (pol == ACL_COND_NONE) { |
| 2062 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 2063 | file, linenum, args[0]); |
| 2064 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2065 | goto out; |
| 2066 | } |
| 2067 | |
| 2068 | if ((cond = parse_acl_cond((const char **)args + 2, &curproxy->acl, pol)) == NULL) { |
| 2069 | Alert("parsing [%s:%d] : error detected while parsing a 'force-persist' rule.\n", |
| 2070 | file, linenum); |
| 2071 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2072 | goto out; |
| 2073 | } |
| 2074 | |
| 2075 | cond->file = file; |
| 2076 | cond->line = linenum; |
| 2077 | curproxy->acl_requires |= cond->requires; |
| 2078 | if (cond->requires & ACL_USE_RTR_ANY) { |
| 2079 | struct acl *acl; |
| 2080 | const char *name; |
| 2081 | |
| 2082 | acl = cond_find_require(cond, ACL_USE_RTR_ANY); |
| 2083 | name = acl ? acl->name : "(unknown)"; |
| 2084 | Warning("parsing [%s:%d] : acl '%s' involves some response-only criteria which will be ignored.\n", |
| 2085 | file, linenum, name); |
| 2086 | err_code |= ERR_WARN; |
| 2087 | } |
| 2088 | |
| 2089 | rule = (struct force_persist_rule *)calloc(1, sizeof(*rule)); |
| 2090 | rule->cond = cond; |
| 2091 | LIST_INIT(&rule->list); |
| 2092 | LIST_ADDQ(&curproxy->force_persist_rules, &rule->list); |
| 2093 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2094 | else if (!strcmp(args[0], "stick-table")) { |
| 2095 | int myidx = 1; |
| 2096 | |
| 2097 | curproxy->table.type = (unsigned int)-1; |
| 2098 | while (*args[myidx]) { |
| 2099 | const char *err; |
| 2100 | |
| 2101 | if (strcmp(args[myidx], "size") == 0) { |
| 2102 | myidx++; |
| 2103 | if (!*(args[myidx])) { |
| 2104 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 2105 | file, linenum, args[myidx-1]); |
| 2106 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2107 | goto out; |
| 2108 | } |
| 2109 | if ((err = parse_size_err(args[myidx], &curproxy->table.size))) { |
| 2110 | Alert("parsing [%s:%d] : stick-table: unexpected character '%c' in argument of '%s'.\n", |
| 2111 | file, linenum, *err, args[myidx-1]); |
| 2112 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2113 | goto out; |
| 2114 | } |
| 2115 | } |
| 2116 | else if (strcmp(args[myidx], "expire") == 0) { |
| 2117 | myidx++; |
| 2118 | if (!*(args[myidx])) { |
| 2119 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 2120 | file, linenum, args[myidx-1]); |
| 2121 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2122 | goto out; |
| 2123 | } |
| 2124 | err = parse_time_err(args[myidx], &val, TIME_UNIT_MS); |
| 2125 | if (err) { |
| 2126 | Alert("parsing [%s:%d] : stick-table: unexpected character '%c' in argument of '%s'.\n", |
| 2127 | file, linenum, *err, args[myidx-1]); |
| 2128 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2129 | goto out; |
| 2130 | } |
| 2131 | curproxy->table.expire = val; |
| 2132 | } |
| 2133 | else if (strcmp(args[myidx], "nopurge") == 0) { |
| 2134 | curproxy->table.nopurge = 1; |
| 2135 | } |
| 2136 | else if (strcmp(args[myidx], "type") == 0) { |
| 2137 | myidx++; |
| 2138 | if (stktable_parse_type(args, &myidx, &curproxy->table.type, &curproxy->table.key_size) != 0) { |
| 2139 | Alert("parsing [%s:%d] : stick-table: unknown type '%s'.\n", |
| 2140 | file, linenum, args[myidx]); |
| 2141 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2142 | goto out; |
| 2143 | } |
| 2144 | } |
| 2145 | myidx++; |
| 2146 | } |
| 2147 | |
| 2148 | if (!curproxy->table.size) { |
| 2149 | Alert("parsing [%s:%d] : stick-table: missing size.\n", |
| 2150 | file, linenum); |
| 2151 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2152 | goto out; |
| 2153 | } |
| 2154 | |
| 2155 | if (curproxy->table.type == (unsigned int)-1) { |
| 2156 | Alert("parsing [%s:%d] : stick-table: missing type.\n", |
| 2157 | file, linenum); |
| 2158 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2159 | goto out; |
| 2160 | } |
| 2161 | } |
| 2162 | else if (!strcmp(args[0], "stick")) { |
| 2163 | int pol = ACL_COND_NONE; |
| 2164 | struct acl_cond *cond = NULL; |
| 2165 | struct sticking_rule *rule; |
| 2166 | struct pattern_expr *expr; |
| 2167 | int myidx = 0; |
| 2168 | const char *name = NULL; |
| 2169 | int flags; |
| 2170 | |
| 2171 | if (curproxy == &defproxy) { |
| 2172 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2173 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2174 | goto out; |
| 2175 | } |
| 2176 | |
| 2177 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) { |
| 2178 | err_code |= ERR_WARN; |
| 2179 | goto out; |
| 2180 | } |
| 2181 | |
| 2182 | myidx++; |
| 2183 | if ((strcmp(args[myidx], "store") == 0) || |
| 2184 | (strcmp(args[myidx], "store-request") == 0)) { |
| 2185 | myidx++; |
| 2186 | flags = STK_IS_STORE; |
| 2187 | } |
| 2188 | else if (strcmp(args[myidx], "store-response") == 0) { |
| 2189 | myidx++; |
| 2190 | flags = STK_IS_STORE | STK_ON_RSP; |
| 2191 | } |
| 2192 | else if (strcmp(args[myidx], "match") == 0) { |
| 2193 | myidx++; |
| 2194 | flags = STK_IS_MATCH; |
| 2195 | } |
| 2196 | else if (strcmp(args[myidx], "on") == 0) { |
| 2197 | myidx++; |
| 2198 | flags = STK_IS_MATCH | STK_IS_STORE; |
| 2199 | } |
| 2200 | else { |
| 2201 | Alert("parsing [%s:%d] : '%s' expects 'on', 'match', or 'store'.\n", file, linenum, args[0]); |
| 2202 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2203 | goto out; |
| 2204 | } |
| 2205 | |
| 2206 | if (*(args[myidx]) == 0) { |
| 2207 | Alert("parsing [%s:%d] : '%s' expects a fetch method.\n", file, linenum, args[0]); |
| 2208 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2209 | goto out; |
| 2210 | } |
| 2211 | |
| 2212 | expr = pattern_parse_expr(args, &myidx); |
| 2213 | if (!expr) { |
| 2214 | Alert("parsing [%s:%d] : '%s': unknown fetch method '%s'.\n", file, linenum, args[0], args[myidx]); |
| 2215 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2216 | goto out; |
| 2217 | } |
| 2218 | |
| 2219 | if (flags & STK_ON_RSP) { |
| 2220 | if (!(expr->fetch->dir & PATTERN_FETCH_RTR)) { |
| 2221 | Alert("parsing [%s:%d] : '%s': fetch method '%s' can not be used on response.\n", |
| 2222 | file, linenum, args[0], expr->fetch->kw); |
| 2223 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2224 | goto out; |
| 2225 | } |
| 2226 | } else { |
| 2227 | if (!(expr->fetch->dir & PATTERN_FETCH_REQ)) { |
| 2228 | Alert("parsing [%s:%d] : '%s': fetch method '%s' can not be used on request.\n", |
| 2229 | file, linenum, args[0], expr->fetch->kw); |
| 2230 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2231 | goto out; |
| 2232 | } |
| 2233 | } |
| 2234 | |
| 2235 | if (strcmp(args[myidx], "table") == 0) { |
| 2236 | myidx++; |
| 2237 | name = args[myidx++]; |
| 2238 | } |
| 2239 | |
| 2240 | if (*(args[myidx]) == 0) |
| 2241 | pol = ACL_COND_NONE; |
| 2242 | else if (strcmp(args[myidx], "if") == 0) |
| 2243 | pol = ACL_COND_IF; |
| 2244 | else if (strcmp(args[myidx], "unless") == 0) |
| 2245 | pol = ACL_COND_UNLESS; |
| 2246 | else { |
| 2247 | Alert("parsing [%s:%d] : '%s': unknown keyword '%s'.\n", |
| 2248 | file, linenum, args[0], args[myidx]); |
| 2249 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2250 | goto out; |
| 2251 | } |
| 2252 | |
| 2253 | if (pol != ACL_COND_NONE) { |
| 2254 | myidx++; |
| 2255 | if ((cond = parse_acl_cond((const char **)args + myidx, &curproxy->acl, pol)) == NULL) { |
| 2256 | Alert("parsing [%s:%d] : '%s': error detected while parsing sticking condition.\n", |
| 2257 | file, linenum, args[0]); |
| 2258 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2259 | goto out; |
| 2260 | } |
| 2261 | |
| 2262 | cond->file = file; |
| 2263 | cond->line = linenum; |
| 2264 | curproxy->acl_requires |= cond->requires; |
| 2265 | if (cond->requires & ACL_USE_RTR_ANY) { |
| 2266 | struct acl *acl; |
| 2267 | const char *name; |
| 2268 | |
| 2269 | acl = cond_find_require(cond, ACL_USE_RTR_ANY); |
| 2270 | name = acl ? acl->name : "(unknown)"; |
| 2271 | Warning("parsing [%s:%d] : '%s' : acl '%s' involves some response-only criteria which will be ignored.\n", |
| 2272 | file, linenum, args[0], name); |
| 2273 | err_code |= ERR_WARN; |
| 2274 | } |
| 2275 | } |
| 2276 | rule = (struct sticking_rule *)calloc(1, sizeof(*rule)); |
| 2277 | rule->cond = cond; |
| 2278 | rule->expr = expr; |
| 2279 | rule->flags = flags; |
| 2280 | rule->table.name = name ? strdup(name) : NULL; |
| 2281 | LIST_INIT(&rule->list); |
| 2282 | if (flags & STK_ON_RSP) |
| 2283 | LIST_ADDQ(&curproxy->storersp_rules, &rule->list); |
| 2284 | else |
| 2285 | LIST_ADDQ(&curproxy->sticking_rules, &rule->list); |
| 2286 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2287 | else if (!strcmp(args[0], "stats")) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2288 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2289 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2290 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2291 | if (curproxy != &defproxy && curproxy->uri_auth == defproxy.uri_auth) |
| 2292 | curproxy->uri_auth = NULL; /* we must detach from the default config */ |
| 2293 | |
Krzysztof Piotr Oledzki | 260a3bb | 2010-01-06 16:25:05 +0100 | [diff] [blame] | 2294 | if (!*args[1]) { |
| 2295 | goto stats_error_parsing; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2296 | } else if (!strcmp(args[1], "uri")) { |
| 2297 | if (*(args[2]) == 0) { |
| 2298 | Alert("parsing [%s:%d] : 'uri' needs an URI prefix.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2299 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2300 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2301 | } else if (!stats_set_uri(&curproxy->uri_auth, args[2])) { |
| 2302 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2303 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2304 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2305 | } |
| 2306 | } else if (!strcmp(args[1], "realm")) { |
| 2307 | if (*(args[2]) == 0) { |
| 2308 | Alert("parsing [%s:%d] : 'realm' needs an realm name.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2309 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2310 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2311 | } else if (!stats_set_realm(&curproxy->uri_auth, args[2])) { |
| 2312 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2313 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2314 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2315 | } |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 2316 | } else if (!strcmp(args[1], "refresh")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 2317 | unsigned interval; |
| 2318 | |
| 2319 | err = parse_time_err(args[2], &interval, TIME_UNIT_S); |
| 2320 | if (err) { |
| 2321 | Alert("parsing [%s:%d] : unexpected character '%c' in stats refresh interval.\n", |
| 2322 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2323 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2324 | goto out; |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 2325 | } else if (!stats_set_refresh(&curproxy->uri_auth, interval)) { |
| 2326 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2327 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2328 | goto out; |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 2329 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2330 | } else if (!strcmp(args[1], "auth")) { |
| 2331 | if (*(args[2]) == 0) { |
| 2332 | 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] | 2333 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2334 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2335 | } else if (!stats_add_auth(&curproxy->uri_auth, args[2])) { |
| 2336 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2337 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2338 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2339 | } |
| 2340 | } else if (!strcmp(args[1], "scope")) { |
| 2341 | if (*(args[2]) == 0) { |
| 2342 | Alert("parsing [%s:%d] : 'scope' needs a proxy name.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2343 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2344 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2345 | } else if (!stats_add_scope(&curproxy->uri_auth, args[2])) { |
| 2346 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2347 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2348 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2349 | } |
| 2350 | } else if (!strcmp(args[1], "enable")) { |
| 2351 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 2352 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2353 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2354 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2355 | } |
Krzysztof Oledzki | d9db927 | 2007-10-15 10:05:11 +0200 | [diff] [blame] | 2356 | } else if (!strcmp(args[1], "hide-version")) { |
| 2357 | if (!stats_set_flag(&curproxy->uri_auth, ST_HIDEVER)) { |
| 2358 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2359 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2360 | goto out; |
Krzysztof Oledzki | d9db927 | 2007-10-15 10:05:11 +0200 | [diff] [blame] | 2361 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 2362 | } else if (!strcmp(args[1], "show-legends")) { |
| 2363 | if (!stats_set_flag(&curproxy->uri_auth, ST_SHLGNDS)) { |
| 2364 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 2365 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2366 | goto out; |
| 2367 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 2368 | } else if (!strcmp(args[1], "show-node")) { |
| 2369 | |
| 2370 | if (*args[2]) { |
| 2371 | int i; |
| 2372 | char c; |
| 2373 | |
| 2374 | for (i=0; args[2][i]; i++) { |
| 2375 | c = args[2][i]; |
Krzysztof Piotr Oledzki | 619caca | 2009-10-03 15:46:08 +0200 | [diff] [blame] | 2376 | if (!isupper(c) && !islower(c) && !isdigit(c) && c != '_' && c != '-' && c != '.') |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 2377 | break; |
| 2378 | } |
| 2379 | |
| 2380 | if (!i || args[2][i]) { |
| 2381 | Alert("parsing [%s:%d]: '%s %s' invalid node name - should be a string" |
| 2382 | "with digits(0-9), letters(A-Z, a-z), hyphen(-) or underscode(_).\n", |
| 2383 | file, linenum, args[0], args[1]); |
| 2384 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2385 | goto out; |
| 2386 | } |
| 2387 | } |
| 2388 | |
| 2389 | if (!stats_set_node(&curproxy->uri_auth, args[2])) { |
| 2390 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 2391 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2392 | goto out; |
| 2393 | } |
| 2394 | } else if (!strcmp(args[1], "show-desc")) { |
| 2395 | char *desc = NULL; |
| 2396 | |
| 2397 | if (*args[2]) { |
| 2398 | int i, len=0; |
| 2399 | char *d; |
| 2400 | |
| 2401 | for(i=2; *args[i]; i++) |
| 2402 | len += strlen(args[i])+1; |
| 2403 | |
| 2404 | desc = d = (char *)calloc(1, len); |
| 2405 | |
| 2406 | d += sprintf(d, "%s", args[2]); |
| 2407 | for(i=3; *args[i]; i++) |
| 2408 | d += sprintf(d, " %s", args[i]); |
| 2409 | } |
| 2410 | |
| 2411 | if (!*args[2] && !global.desc) |
| 2412 | Warning("parsing [%s:%d]: '%s' requires a parameter or 'desc' to be set in the global section.\n", |
| 2413 | file, linenum, args[1]); |
| 2414 | else { |
| 2415 | if (!stats_set_desc(&curproxy->uri_auth, desc)) { |
| 2416 | free(desc); |
| 2417 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 2418 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2419 | goto out; |
| 2420 | } |
| 2421 | free(desc); |
| 2422 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2423 | } else { |
Krzysztof Piotr Oledzki | 260a3bb | 2010-01-06 16:25:05 +0100 | [diff] [blame] | 2424 | stats_error_parsing: |
| 2425 | Alert("parsing [%s:%d]: %s '%s', expects 'uri', 'realm', 'auth', 'scope', 'enable', 'hide-version', 'show-node', 'show-desc' or 'show-legends'.\n", |
| 2426 | 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] | 2427 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2428 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2429 | } |
| 2430 | } |
| 2431 | else if (!strcmp(args[0], "option")) { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 2432 | int optnum; |
| 2433 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 2434 | if (*(args[1]) == '\0') { |
| 2435 | Alert("parsing [%s:%d]: '%s' expects an option name.\n", |
| 2436 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2437 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2438 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2439 | } |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 2440 | |
| 2441 | for (optnum = 0; cfg_opts[optnum].name; optnum++) { |
| 2442 | if (!strcmp(args[1], cfg_opts[optnum].name)) { |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2443 | if (warnifnotcap(curproxy, cfg_opts[optnum].cap, file, linenum, args[1], NULL)) { |
| 2444 | err_code |= ERR_WARN; |
| 2445 | goto out; |
| 2446 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 2447 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 2448 | curproxy->no_options &= ~cfg_opts[optnum].val; |
| 2449 | curproxy->options &= ~cfg_opts[optnum].val; |
| 2450 | |
| 2451 | switch (kwm) { |
| 2452 | case KWM_STD: |
| 2453 | curproxy->options |= cfg_opts[optnum].val; |
| 2454 | break; |
| 2455 | case KWM_NO: |
| 2456 | curproxy->no_options |= cfg_opts[optnum].val; |
| 2457 | break; |
| 2458 | case KWM_DEF: /* already cleared */ |
| 2459 | break; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 2460 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 2461 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2462 | goto out; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 2463 | } |
| 2464 | } |
| 2465 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 2466 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) { |
| 2467 | if (!strcmp(args[1], cfg_opts2[optnum].name)) { |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2468 | if (warnifnotcap(curproxy, cfg_opts2[optnum].cap, file, linenum, args[1], NULL)) { |
| 2469 | err_code |= ERR_WARN; |
| 2470 | goto out; |
| 2471 | } |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 2472 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 2473 | curproxy->no_options2 &= ~cfg_opts2[optnum].val; |
| 2474 | curproxy->options2 &= ~cfg_opts2[optnum].val; |
| 2475 | |
| 2476 | switch (kwm) { |
| 2477 | case KWM_STD: |
| 2478 | curproxy->options2 |= cfg_opts2[optnum].val; |
| 2479 | break; |
| 2480 | case KWM_NO: |
| 2481 | curproxy->no_options2 |= cfg_opts2[optnum].val; |
| 2482 | break; |
| 2483 | case KWM_DEF: /* already cleared */ |
| 2484 | break; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 2485 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2486 | goto out; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 2487 | } |
| 2488 | } |
| 2489 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 2490 | if (kwm != KWM_STD) { |
| 2491 | 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] | 2492 | file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2493 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2494 | goto out; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 2495 | } |
| 2496 | |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 2497 | if (!strcmp(args[1], "httplog")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2498 | /* generate a complete HTTP log */ |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 2499 | curproxy->options2 &= ~PR_O2_CLFLOG; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2500 | 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] | 2501 | if (*(args[2]) != '\0') { |
| 2502 | if (!strcmp(args[2], "clf")) { |
| 2503 | curproxy->options2 |= PR_O2_CLFLOG; |
| 2504 | } else { |
| 2505 | 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] | 2506 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2507 | goto out; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 2508 | } |
| 2509 | } |
| 2510 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2511 | else if (!strcmp(args[1], "tcplog")) |
| 2512 | /* generate a detailed TCP log */ |
| 2513 | 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] | 2514 | else if (!strcmp(args[1], "tcpka")) { |
| 2515 | /* enable TCP keep-alives on client and server sessions */ |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 2516 | 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] | 2517 | err_code |= ERR_WARN; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 2518 | |
| 2519 | if (curproxy->cap & PR_CAP_FE) |
| 2520 | curproxy->options |= PR_O_TCP_CLI_KA; |
| 2521 | if (curproxy->cap & PR_CAP_BE) |
| 2522 | curproxy->options |= PR_O_TCP_SRV_KA; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2523 | } |
| 2524 | else if (!strcmp(args[1], "httpchk")) { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 2525 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2526 | err_code |= ERR_WARN; |
| 2527 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2528 | /* use HTTP request to check servers' health */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2529 | free(curproxy->check_req); |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 2530 | curproxy->options &= ~PR_O_SSL3_CHK; |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 2531 | curproxy->options &= ~PR_O_SMTP_CHK; |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 2532 | curproxy->options2 &= ~PR_O2_MYSQL_CHK; |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 2533 | curproxy->options |= PR_O_HTTP_CHK; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2534 | if (!*args[2]) { /* no argument */ |
| 2535 | curproxy->check_req = strdup(DEF_CHECK_REQ); /* default request */ |
| 2536 | curproxy->check_len = strlen(DEF_CHECK_REQ); |
| 2537 | } else if (!*args[3]) { /* one argument : URI */ |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 2538 | int reqlen = strlen(args[2]) + strlen("OPTIONS HTTP/1.0\r\n\r\n") + 1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2539 | curproxy->check_req = (char *)malloc(reqlen); |
| 2540 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
| 2541 | "OPTIONS %s HTTP/1.0\r\n\r\n", args[2]); /* URI to use */ |
| 2542 | } else { /* more arguments : METHOD URI [HTTP_VER] */ |
| 2543 | int reqlen = strlen(args[2]) + strlen(args[3]) + 3 + strlen("\r\n\r\n"); |
| 2544 | if (*args[4]) |
| 2545 | reqlen += strlen(args[4]); |
| 2546 | else |
| 2547 | reqlen += strlen("HTTP/1.0"); |
| 2548 | |
| 2549 | curproxy->check_req = (char *)malloc(reqlen); |
| 2550 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
| 2551 | "%s %s %s\r\n\r\n", args[2], args[3], *args[4]?args[4]:"HTTP/1.0"); |
| 2552 | } |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 2553 | } |
| 2554 | else if (!strcmp(args[1], "ssl-hello-chk")) { |
| 2555 | /* use SSLv3 CLIENT HELLO to check servers' health */ |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 2556 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2557 | err_code |= ERR_WARN; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 2558 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2559 | free(curproxy->check_req); |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 2560 | curproxy->options &= ~PR_O_HTTP_CHK; |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 2561 | curproxy->options &= ~PR_O_SMTP_CHK; |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 2562 | curproxy->options2 &= ~PR_O2_MYSQL_CHK; |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 2563 | curproxy->options |= PR_O_SSL3_CHK; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2564 | } |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 2565 | else if (!strcmp(args[1], "smtpchk")) { |
| 2566 | /* use SMTP request to check servers' health */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2567 | free(curproxy->check_req); |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 2568 | curproxy->options &= ~PR_O_HTTP_CHK; |
| 2569 | curproxy->options &= ~PR_O_SSL3_CHK; |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 2570 | curproxy->options2 &= ~PR_O2_MYSQL_CHK; |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 2571 | curproxy->options |= PR_O_SMTP_CHK; |
| 2572 | |
| 2573 | if (!*args[2] || !*args[3]) { /* no argument or incomplete EHLO host */ |
| 2574 | curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */ |
| 2575 | curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ); |
| 2576 | } else { /* ESMTP EHLO, or SMTP HELO, and a hostname */ |
| 2577 | if (!strcmp(args[2], "EHLO") || !strcmp(args[2], "HELO")) { |
| 2578 | int reqlen = strlen(args[2]) + strlen(args[3]) + strlen(" \r\n") + 1; |
| 2579 | curproxy->check_req = (char *)malloc(reqlen); |
| 2580 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
| 2581 | "%s %s\r\n", args[2], args[3]); /* HELO hostname */ |
| 2582 | } else { |
| 2583 | /* this just hits the default for now, but you could potentially expand it to allow for other stuff |
| 2584 | though, it's unlikely you'd want to send anything other than an EHLO or HELO */ |
| 2585 | curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */ |
| 2586 | curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ); |
| 2587 | } |
| 2588 | } |
| 2589 | } |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 2590 | else if (!strcmp(args[1], "mysql-check")) { |
| 2591 | /* use MYSQL request to check servers' health */ |
| 2592 | free(curproxy->check_req); |
| 2593 | curproxy->options &= ~PR_O_HTTP_CHK; |
| 2594 | curproxy->options &= ~PR_O_SSL3_CHK; |
| 2595 | curproxy->options &= ~PR_O_SMTP_CHK; |
| 2596 | curproxy->options2 |= PR_O2_MYSQL_CHK; |
| 2597 | } |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 2598 | else if (!strcmp(args[1], "forwardfor")) { |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 2599 | int cur_arg; |
| 2600 | |
| 2601 | /* insert x-forwarded-for field, but not for the IP address listed as an except. |
| 2602 | * set default options (ie: bitfield, header name, etc) |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 2603 | */ |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 2604 | |
| 2605 | curproxy->options |= PR_O_FWDFOR; |
| 2606 | |
| 2607 | free(curproxy->fwdfor_hdr_name); |
| 2608 | curproxy->fwdfor_hdr_name = strdup(DEF_XFORWARDFOR_HDR); |
| 2609 | curproxy->fwdfor_hdr_len = strlen(DEF_XFORWARDFOR_HDR); |
| 2610 | |
| 2611 | /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */ |
| 2612 | cur_arg = 2; |
| 2613 | while (*(args[cur_arg])) { |
| 2614 | if (!strcmp(args[cur_arg], "except")) { |
| 2615 | /* suboption except - needs additional argument for it */ |
| 2616 | if (!*(args[cur_arg+1]) || !str2net(args[cur_arg+1], &curproxy->except_net, &curproxy->except_mask)) { |
| 2617 | Alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n", |
| 2618 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2619 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2620 | goto out; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 2621 | } |
| 2622 | /* flush useless bits */ |
| 2623 | curproxy->except_net.s_addr &= curproxy->except_mask.s_addr; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 2624 | cur_arg += 2; |
| 2625 | } else if (!strcmp(args[cur_arg], "header")) { |
| 2626 | /* suboption header - needs additional argument for it */ |
| 2627 | if (*(args[cur_arg+1]) == 0) { |
| 2628 | Alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 2629 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2630 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2631 | goto out; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 2632 | } |
| 2633 | free(curproxy->fwdfor_hdr_name); |
| 2634 | curproxy->fwdfor_hdr_name = strdup(args[cur_arg+1]); |
| 2635 | curproxy->fwdfor_hdr_len = strlen(curproxy->fwdfor_hdr_name); |
| 2636 | cur_arg += 2; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 2637 | } else { |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 2638 | /* unknown suboption - catchall */ |
| 2639 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n", |
| 2640 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2641 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2642 | goto out; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 2643 | } |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 2644 | } /* end while loop */ |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 2645 | } |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 2646 | else if (!strcmp(args[1], "originalto")) { |
| 2647 | int cur_arg; |
| 2648 | |
| 2649 | /* insert x-original-to field, but not for the IP address listed as an except. |
| 2650 | * set default options (ie: bitfield, header name, etc) |
| 2651 | */ |
| 2652 | |
| 2653 | curproxy->options |= PR_O_ORGTO; |
| 2654 | |
| 2655 | free(curproxy->orgto_hdr_name); |
| 2656 | curproxy->orgto_hdr_name = strdup(DEF_XORIGINALTO_HDR); |
| 2657 | curproxy->orgto_hdr_len = strlen(DEF_XORIGINALTO_HDR); |
| 2658 | |
| 2659 | /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */ |
| 2660 | cur_arg = 2; |
| 2661 | while (*(args[cur_arg])) { |
| 2662 | if (!strcmp(args[cur_arg], "except")) { |
| 2663 | /* suboption except - needs additional argument for it */ |
| 2664 | if (!*(args[cur_arg+1]) || !str2net(args[cur_arg+1], &curproxy->except_to, &curproxy->except_mask_to)) { |
| 2665 | Alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n", |
| 2666 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2667 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2668 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 2669 | } |
| 2670 | /* flush useless bits */ |
| 2671 | curproxy->except_to.s_addr &= curproxy->except_mask_to.s_addr; |
| 2672 | cur_arg += 2; |
| 2673 | } else if (!strcmp(args[cur_arg], "header")) { |
| 2674 | /* suboption header - needs additional argument for it */ |
| 2675 | if (*(args[cur_arg+1]) == 0) { |
| 2676 | Alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 2677 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2678 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2679 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 2680 | } |
| 2681 | free(curproxy->orgto_hdr_name); |
| 2682 | curproxy->orgto_hdr_name = strdup(args[cur_arg+1]); |
| 2683 | curproxy->orgto_hdr_len = strlen(curproxy->orgto_hdr_name); |
| 2684 | cur_arg += 2; |
| 2685 | } else { |
| 2686 | /* unknown suboption - catchall */ |
| 2687 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n", |
| 2688 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2689 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2690 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 2691 | } |
| 2692 | } /* end while loop */ |
| 2693 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2694 | else { |
| 2695 | Alert("parsing [%s:%d] : unknown option '%s'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2696 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2697 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2698 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2699 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2700 | } |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 2701 | else if (!strcmp(args[0], "default_backend")) { |
| 2702 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2703 | err_code |= ERR_WARN; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 2704 | |
| 2705 | if (*(args[1]) == 0) { |
| 2706 | 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] | 2707 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2708 | goto out; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 2709 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2710 | free(curproxy->defbe.name); |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 2711 | curproxy->defbe.name = strdup(args[1]); |
| 2712 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2713 | else if (!strcmp(args[0], "redispatch") || !strcmp(args[0], "redisp")) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2714 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2715 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2716 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 2717 | Warning("parsing [%s:%d]: keyword '%s' is deprecated, please use 'option redispatch' instead.\n", |
| 2718 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2719 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2720 | /* enable reconnections to dispatch */ |
| 2721 | curproxy->options |= PR_O_REDISP; |
| 2722 | } |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 2723 | else if (!strcmp(args[0], "http-check")) { |
| 2724 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2725 | err_code |= ERR_WARN; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 2726 | |
| 2727 | if (strcmp(args[1], "disable-on-404") == 0) { |
| 2728 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 2729 | curproxy->options |= PR_O_DISABLE404; |
| 2730 | } |
| 2731 | else { |
| 2732 | Alert("parsing [%s:%d] : '%s' only supports 'disable-on-404'.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2733 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2734 | goto out; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 2735 | } |
| 2736 | } |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 2737 | else if (!strcmp(args[0], "monitor")) { |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2738 | if (curproxy == &defproxy) { |
| 2739 | 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] | 2740 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2741 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2742 | } |
| 2743 | |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 2744 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2745 | err_code |= ERR_WARN; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 2746 | |
| 2747 | if (strcmp(args[1], "fail") == 0) { |
| 2748 | /* add a condition to fail monitor requests */ |
| 2749 | int pol = ACL_COND_NONE; |
| 2750 | struct acl_cond *cond; |
| 2751 | |
| 2752 | if (!strcmp(args[2], "if")) |
| 2753 | pol = ACL_COND_IF; |
| 2754 | else if (!strcmp(args[2], "unless")) |
| 2755 | pol = ACL_COND_UNLESS; |
| 2756 | |
| 2757 | if (pol == ACL_COND_NONE) { |
| 2758 | Alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n", |
| 2759 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2760 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2761 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 2762 | } |
| 2763 | |
| 2764 | if ((cond = parse_acl_cond((const char **)args + 3, &curproxy->acl, pol)) == NULL) { |
| 2765 | Alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition.\n", |
| 2766 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2767 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2768 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 2769 | } |
Willy Tarreau | 8892235 | 2009-10-04 22:02:50 +0200 | [diff] [blame] | 2770 | cond->file = file; |
Willy Tarreau | a980263 | 2008-07-25 19:13:19 +0200 | [diff] [blame] | 2771 | cond->line = linenum; |
Willy Tarreau | a9fb083 | 2009-07-10 20:53:53 +0200 | [diff] [blame] | 2772 | curproxy->acl_requires |= cond->requires; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 2773 | LIST_ADDQ(&curproxy->mon_fail_cond, &cond->list); |
| 2774 | } |
| 2775 | else { |
| 2776 | 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] | 2777 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2778 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 2779 | } |
| 2780 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2781 | #ifdef TPROXY |
| 2782 | else if (!strcmp(args[0], "transparent")) { |
| 2783 | /* enable transparent proxy connections */ |
| 2784 | curproxy->options |= PR_O_TRANSP; |
| 2785 | } |
| 2786 | #endif |
| 2787 | else if (!strcmp(args[0], "maxconn")) { /* maxconn */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2788 | 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] | 2789 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2790 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2791 | if (*(args[1]) == 0) { |
| 2792 | 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] | 2793 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2794 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2795 | } |
| 2796 | curproxy->maxconn = atol(args[1]); |
| 2797 | } |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 2798 | else if (!strcmp(args[0], "backlog")) { /* backlog */ |
| 2799 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2800 | err_code |= ERR_WARN; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 2801 | |
| 2802 | if (*(args[1]) == 0) { |
| 2803 | 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] | 2804 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2805 | goto out; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 2806 | } |
| 2807 | curproxy->backlog = atol(args[1]); |
| 2808 | } |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 2809 | else if (!strcmp(args[0], "fullconn")) { /* fullconn */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2810 | 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] | 2811 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2812 | |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 2813 | if (*(args[1]) == 0) { |
| 2814 | 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] | 2815 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2816 | goto out; |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 2817 | } |
| 2818 | curproxy->fullconn = atol(args[1]); |
| 2819 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2820 | else if (!strcmp(args[0], "grace")) { /* grace time (ms) */ |
| 2821 | if (*(args[1]) == 0) { |
| 2822 | 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] | 2823 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2824 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2825 | } |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 2826 | err = parse_time_err(args[1], &val, TIME_UNIT_MS); |
| 2827 | if (err) { |
| 2828 | Alert("parsing [%s:%d] : unexpected character '%c' in grace time.\n", |
| 2829 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2830 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2831 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 2832 | } |
| 2833 | curproxy->grace = val; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2834 | } |
| 2835 | else if (!strcmp(args[0], "dispatch")) { /* dispatch address */ |
| 2836 | if (curproxy == &defproxy) { |
| 2837 | 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] | 2838 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2839 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2840 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2841 | else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2842 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2843 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2844 | if (strchr(args[1], ':') == NULL) { |
| 2845 | 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] | 2846 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2847 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2848 | } |
| 2849 | curproxy->dispatch_addr = *str2sa(args[1]); |
| 2850 | } |
| 2851 | else if (!strcmp(args[0], "balance")) { /* set balancing with optional algorithm */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2852 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2853 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2854 | |
Jeffrey 'jf' Lim | 65cb2f1 | 2008-10-04 18:07:00 +0200 | [diff] [blame] | 2855 | memcpy(trash, "error near 'balance'", 21); |
Willy Tarreau | a0cbda6 | 2007-11-01 21:39:54 +0100 | [diff] [blame] | 2856 | if (backend_parse_balance((const char **)args + 1, trash, sizeof(trash), curproxy) < 0) { |
| 2857 | Alert("parsing [%s:%d] : %s\n", file, linenum, trash); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2858 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2859 | goto out; |
Willy Tarreau | 2fcb500 | 2007-05-08 13:35:26 +0200 | [diff] [blame] | 2860 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2861 | } |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 2862 | else if (!strcmp(args[0], "hash-type")) { /* set hashing method */ |
| 2863 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 2864 | err_code |= ERR_WARN; |
| 2865 | |
| 2866 | if (strcmp(args[1], "consistent") == 0) { /* use consistent hashing */ |
| 2867 | curproxy->lbprm.algo &= ~BE_LB_HASH_TYPE; |
| 2868 | curproxy->lbprm.algo |= BE_LB_HASH_CONS; |
| 2869 | } |
| 2870 | else if (strcmp(args[1], "map-based") == 0) { /* use map-based hashing */ |
| 2871 | curproxy->lbprm.algo &= ~BE_LB_HASH_TYPE; |
| 2872 | curproxy->lbprm.algo |= BE_LB_HASH_MAP; |
| 2873 | } |
| 2874 | else { |
| 2875 | Alert("parsing [%s:%d] : '%s' only supports 'consistent' and 'map-based'.\n", file, linenum, args[0]); |
| 2876 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2877 | goto out; |
| 2878 | } |
| 2879 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 2880 | 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] | 2881 | int cur_arg; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 2882 | char *rport, *raddr; |
| 2883 | short realport = 0; |
| 2884 | int do_check = 0, defsrv = (*args[0] == 'd'); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2885 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 2886 | if (!defsrv && curproxy == &defproxy) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2887 | 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] | 2888 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2889 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2890 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2891 | else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2892 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2893 | |
| 2894 | if (!*args[2]) { |
| 2895 | Alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n", |
| 2896 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2897 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2898 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2899 | } |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 2900 | |
| 2901 | err = invalid_char(args[1]); |
| 2902 | if (err) { |
| 2903 | Alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n", |
| 2904 | file, linenum, *err, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2905 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2906 | goto out; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 2907 | } |
| 2908 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2909 | if ((newsrv = (struct server *)calloc(1, sizeof(struct server))) == NULL) { |
| 2910 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2911 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2912 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2913 | } |
| 2914 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 2915 | if (!defsrv) { |
| 2916 | /* the servers are linked backwards first */ |
| 2917 | newsrv->next = curproxy->srv; |
| 2918 | curproxy->srv = newsrv; |
| 2919 | newsrv->proxy = curproxy; |
| 2920 | newsrv->conf.file = file; |
| 2921 | newsrv->conf.line = linenum; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2922 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 2923 | LIST_INIT(&newsrv->pendconns); |
| 2924 | do_check = 0; |
| 2925 | newsrv->state = SRV_RUNNING; /* early server setup */ |
| 2926 | newsrv->last_change = now.tv_sec; |
| 2927 | newsrv->id = strdup(args[1]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2928 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 2929 | /* several ways to check the port component : |
| 2930 | * - IP => port=+0, relative |
| 2931 | * - IP: => port=+0, relative |
| 2932 | * - IP:N => port=N, absolute |
| 2933 | * - IP:+N => port=+N, relative |
| 2934 | * - IP:-N => port=-N, relative |
| 2935 | */ |
| 2936 | raddr = strdup(args[2]); |
| 2937 | rport = strchr(raddr, ':'); |
| 2938 | if (rport) { |
| 2939 | *rport++ = 0; |
| 2940 | realport = atol(rport); |
| 2941 | if (!isdigit((unsigned char)*rport)) |
| 2942 | newsrv->state |= SRV_MAPPORTS; |
| 2943 | } else |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2944 | newsrv->state |= SRV_MAPPORTS; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 2945 | |
| 2946 | newsrv->addr = *str2sa(raddr); |
| 2947 | newsrv->addr.sin_port = htons(realport); |
| 2948 | free(raddr); |
| 2949 | |
| 2950 | newsrv->check_port = curproxy->defsrv.check_port; |
| 2951 | newsrv->inter = curproxy->defsrv.inter; |
| 2952 | newsrv->fastinter = curproxy->defsrv.fastinter; |
| 2953 | newsrv->downinter = curproxy->defsrv.downinter; |
| 2954 | newsrv->rise = curproxy->defsrv.rise; |
| 2955 | newsrv->fall = curproxy->defsrv.fall; |
| 2956 | newsrv->maxqueue = curproxy->defsrv.maxqueue; |
| 2957 | newsrv->minconn = curproxy->defsrv.minconn; |
| 2958 | newsrv->maxconn = curproxy->defsrv.maxconn; |
| 2959 | newsrv->slowstart = curproxy->defsrv.slowstart; |
| 2960 | newsrv->onerror = curproxy->defsrv.onerror; |
| 2961 | newsrv->consecutive_errors_limit |
| 2962 | = curproxy->defsrv.consecutive_errors_limit; |
| 2963 | newsrv->uweight = newsrv->iweight |
| 2964 | = curproxy->defsrv.iweight; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2965 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 2966 | newsrv->curfd = -1; /* no health-check in progress */ |
| 2967 | newsrv->health = newsrv->rise; /* up, but will fall down at first failure */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2968 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 2969 | cur_arg = 3; |
| 2970 | } else { |
| 2971 | newsrv = &curproxy->defsrv; |
| 2972 | cur_arg = 1; |
| 2973 | } |
Willy Tarreau | 0f03c6f | 2007-03-25 20:46:19 +0200 | [diff] [blame] | 2974 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2975 | while (*args[cur_arg]) { |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 2976 | if (!defsrv && !strcmp(args[cur_arg], "id")) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2977 | struct eb32_node *node; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2978 | |
| 2979 | if (!*args[cur_arg + 1]) { |
| 2980 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 2981 | file, linenum, args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2982 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2983 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2984 | } |
| 2985 | |
| 2986 | newsrv->puid = atol(args[cur_arg + 1]); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2987 | newsrv->conf.id.key = newsrv->puid; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2988 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2989 | if (newsrv->puid <= 0) { |
| 2990 | Alert("parsing [%s:%d]: custom id has to be > 0.\n", |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2991 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2992 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2993 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2994 | } |
| 2995 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2996 | node = eb32_lookup(&curproxy->conf.used_server_id, newsrv->puid); |
| 2997 | if (node) { |
| 2998 | struct server *target = container_of(node, struct server, conf.id); |
| 2999 | Alert("parsing [%s:%d]: server %s reuses same custom id as server %s (declared at %s:%d).\n", |
| 3000 | file, linenum, newsrv->id, target->id, target->conf.file, target->conf.line); |
| 3001 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3002 | goto out; |
| 3003 | } |
| 3004 | eb32_insert(&curproxy->conf.used_server_id, &newsrv->conf.id); |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3005 | cur_arg += 2; |
| 3006 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3007 | else if (!defsrv && !strcmp(args[cur_arg], "cookie")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3008 | newsrv->cookie = strdup(args[cur_arg + 1]); |
| 3009 | newsrv->cklen = strlen(args[cur_arg + 1]); |
| 3010 | cur_arg += 2; |
| 3011 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3012 | else if (!defsrv && !strcmp(args[cur_arg], "redir")) { |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 3013 | newsrv->rdr_pfx = strdup(args[cur_arg + 1]); |
| 3014 | newsrv->rdr_len = strlen(args[cur_arg + 1]); |
| 3015 | cur_arg += 2; |
| 3016 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3017 | else if (!strcmp(args[cur_arg], "rise")) { |
Krzysztof Piotr Oledzki | 08ff959 | 2009-09-27 16:17:31 +0200 | [diff] [blame] | 3018 | if (!*args[cur_arg + 1]) { |
| 3019 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 3020 | file, linenum, args[cur_arg]); |
| 3021 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3022 | goto out; |
| 3023 | } |
| 3024 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3025 | newsrv->rise = atol(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 08ff959 | 2009-09-27 16:17:31 +0200 | [diff] [blame] | 3026 | if (newsrv->rise <= 0) { |
| 3027 | Alert("parsing [%s:%d]: '%s' has to be > 0.\n", |
| 3028 | file, linenum, args[cur_arg]); |
| 3029 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3030 | goto out; |
| 3031 | } |
| 3032 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3033 | newsrv->health = newsrv->rise; |
| 3034 | cur_arg += 2; |
| 3035 | } |
| 3036 | else if (!strcmp(args[cur_arg], "fall")) { |
| 3037 | newsrv->fall = atol(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 08ff959 | 2009-09-27 16:17:31 +0200 | [diff] [blame] | 3038 | |
| 3039 | if (!*args[cur_arg + 1]) { |
| 3040 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 3041 | file, linenum, args[cur_arg]); |
| 3042 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3043 | goto out; |
| 3044 | } |
| 3045 | |
| 3046 | if (newsrv->fall <= 0) { |
| 3047 | Alert("parsing [%s:%d]: '%s' has to be > 0.\n", |
| 3048 | file, linenum, args[cur_arg]); |
| 3049 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3050 | goto out; |
| 3051 | } |
| 3052 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3053 | cur_arg += 2; |
| 3054 | } |
| 3055 | else if (!strcmp(args[cur_arg], "inter")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 3056 | const char *err = parse_time_err(args[cur_arg + 1], &val, TIME_UNIT_MS); |
| 3057 | if (err) { |
| 3058 | Alert("parsing [%s:%d] : unexpected character '%c' in 'inter' argument of server %s.\n", |
| 3059 | file, linenum, *err, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3060 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3061 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 3062 | } |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 3063 | if (val <= 0) { |
| 3064 | Alert("parsing [%s:%d]: invalid value %d for argument '%s' of server %s.\n", |
| 3065 | file, linenum, val, args[cur_arg], newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3066 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3067 | goto out; |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 3068 | } |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 3069 | newsrv->inter = val; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3070 | cur_arg += 2; |
| 3071 | } |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 3072 | else if (!strcmp(args[cur_arg], "fastinter")) { |
| 3073 | const char *err = parse_time_err(args[cur_arg + 1], &val, TIME_UNIT_MS); |
| 3074 | if (err) { |
| 3075 | Alert("parsing [%s:%d]: unexpected character '%c' in 'fastinter' argument of server %s.\n", |
| 3076 | file, linenum, *err, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3077 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3078 | goto out; |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 3079 | } |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 3080 | if (val <= 0) { |
| 3081 | Alert("parsing [%s:%d]: invalid value %d for argument '%s' of server %s.\n", |
| 3082 | file, linenum, val, args[cur_arg], newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3083 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3084 | goto out; |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 3085 | } |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 3086 | newsrv->fastinter = val; |
| 3087 | cur_arg += 2; |
| 3088 | } |
| 3089 | else if (!strcmp(args[cur_arg], "downinter")) { |
| 3090 | const char *err = parse_time_err(args[cur_arg + 1], &val, TIME_UNIT_MS); |
| 3091 | if (err) { |
| 3092 | Alert("parsing [%s:%d]: unexpected character '%c' in 'downinter' argument of server %s.\n", |
| 3093 | file, linenum, *err, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3094 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3095 | goto out; |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 3096 | } |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 3097 | if (val <= 0) { |
| 3098 | Alert("parsing [%s:%d]: invalid value %d for argument '%s' of server %s.\n", |
| 3099 | file, linenum, val, args[cur_arg], newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3100 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3101 | goto out; |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 3102 | } |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 3103 | newsrv->downinter = val; |
| 3104 | cur_arg += 2; |
| 3105 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3106 | else if (!defsrv && !strcmp(args[cur_arg], "addr")) { |
Willy Tarreau | 2ea3abb | 2007-03-25 16:45:16 +0200 | [diff] [blame] | 3107 | newsrv->check_addr = *str2sa(args[cur_arg + 1]); |
Willy Tarreau | 2ea3abb | 2007-03-25 16:45:16 +0200 | [diff] [blame] | 3108 | cur_arg += 2; |
| 3109 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3110 | else if (!strcmp(args[cur_arg], "port")) { |
| 3111 | newsrv->check_port = atol(args[cur_arg + 1]); |
| 3112 | cur_arg += 2; |
| 3113 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3114 | else if (!defsrv && !strcmp(args[cur_arg], "backup")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3115 | newsrv->state |= SRV_BACKUP; |
| 3116 | cur_arg ++; |
| 3117 | } |
| 3118 | else if (!strcmp(args[cur_arg], "weight")) { |
| 3119 | int w; |
| 3120 | w = atol(args[cur_arg + 1]); |
Willy Tarreau | 6704d67 | 2009-06-15 10:56:05 +0200 | [diff] [blame] | 3121 | if (w < 0 || w > 256) { |
| 3122 | 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] | 3123 | file, linenum, newsrv->id, w); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3124 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3125 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3126 | } |
Willy Tarreau | 975c50b | 2009-10-10 19:34:06 +0200 | [diff] [blame] | 3127 | newsrv->uweight = newsrv->iweight = w; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3128 | cur_arg += 2; |
| 3129 | } |
| 3130 | else if (!strcmp(args[cur_arg], "minconn")) { |
| 3131 | newsrv->minconn = atol(args[cur_arg + 1]); |
| 3132 | cur_arg += 2; |
| 3133 | } |
| 3134 | else if (!strcmp(args[cur_arg], "maxconn")) { |
| 3135 | newsrv->maxconn = atol(args[cur_arg + 1]); |
| 3136 | cur_arg += 2; |
| 3137 | } |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 3138 | else if (!strcmp(args[cur_arg], "maxqueue")) { |
| 3139 | newsrv->maxqueue = atol(args[cur_arg + 1]); |
| 3140 | cur_arg += 2; |
| 3141 | } |
Willy Tarreau | 9909fc1 | 2007-11-30 17:42:05 +0100 | [diff] [blame] | 3142 | else if (!strcmp(args[cur_arg], "slowstart")) { |
| 3143 | /* slowstart is stored in seconds */ |
Willy Tarreau | 3259e33 | 2007-12-03 01:51:45 +0100 | [diff] [blame] | 3144 | 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] | 3145 | if (err) { |
| 3146 | Alert("parsing [%s:%d] : unexpected character '%c' in 'slowstart' argument of server %s.\n", |
| 3147 | file, linenum, *err, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3148 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3149 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 3150 | } |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 3151 | if (val <= 0) { |
| 3152 | Alert("parsing [%s:%d]: invalid value %d for argument '%s' of server %s.\n", |
| 3153 | file, linenum, val, args[cur_arg], newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3154 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3155 | goto out; |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 3156 | } |
Willy Tarreau | 3259e33 | 2007-12-03 01:51:45 +0100 | [diff] [blame] | 3157 | newsrv->slowstart = (val + 999) / 1000; |
Willy Tarreau | 9909fc1 | 2007-11-30 17:42:05 +0100 | [diff] [blame] | 3158 | cur_arg += 2; |
| 3159 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3160 | else if (!defsrv && !strcmp(args[cur_arg], "track")) { |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 3161 | |
| 3162 | if (!*args[cur_arg + 1]) { |
| 3163 | Alert("parsing [%s:%d]: 'track' expects [<proxy>/]<server> as argument.\n", |
| 3164 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3165 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3166 | goto out; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 3167 | } |
| 3168 | |
| 3169 | newsrv->trackit = strdup(args[cur_arg + 1]); |
| 3170 | |
| 3171 | cur_arg += 2; |
| 3172 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3173 | else if (!defsrv && !strcmp(args[cur_arg], "check")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3174 | global.maxsock++; |
| 3175 | do_check = 1; |
| 3176 | cur_arg += 1; |
| 3177 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3178 | else if (!defsrv && !strcmp(args[cur_arg], "observe")) { |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 3179 | if (!strcmp(args[cur_arg + 1], "none")) |
| 3180 | newsrv->observe = HANA_OBS_NONE; |
| 3181 | else if (!strcmp(args[cur_arg + 1], "layer4")) |
| 3182 | newsrv->observe = HANA_OBS_LAYER4; |
| 3183 | else if (!strcmp(args[cur_arg + 1], "layer7")) { |
| 3184 | if (curproxy->mode != PR_MODE_HTTP) { |
| 3185 | Alert("parsing [%s:%d]: '%s' can only be used in http proxies.\n", |
| 3186 | file, linenum, args[cur_arg + 1]); |
| 3187 | err_code |= ERR_ALERT; |
| 3188 | } |
| 3189 | newsrv->observe = HANA_OBS_LAYER7; |
| 3190 | } |
| 3191 | else { |
| 3192 | Alert("parsing [%s:%d]: '%s' expects one of 'none', " |
| 3193 | "'l4events', 'http-responses' but get '%s'\n", |
| 3194 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
| 3195 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3196 | goto out; |
| 3197 | } |
| 3198 | |
| 3199 | cur_arg += 2; |
| 3200 | } |
| 3201 | else if (!strcmp(args[cur_arg], "on-error")) { |
| 3202 | if (!strcmp(args[cur_arg + 1], "fastinter")) |
| 3203 | newsrv->onerror = HANA_ONERR_FASTINTER; |
| 3204 | else if (!strcmp(args[cur_arg + 1], "fail-check")) |
| 3205 | newsrv->onerror = HANA_ONERR_FAILCHK; |
| 3206 | else if (!strcmp(args[cur_arg + 1], "sudden-death")) |
| 3207 | newsrv->onerror = HANA_ONERR_SUDDTH; |
| 3208 | else if (!strcmp(args[cur_arg + 1], "mark-down")) |
| 3209 | newsrv->onerror = HANA_ONERR_MARKDWN; |
| 3210 | else { |
| 3211 | Alert("parsing [%s:%d]: '%s' expects one of 'fastinter', " |
| 3212 | "'fail-check', 'sudden-death' or 'mark-down' but get '%s'\n", |
| 3213 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
| 3214 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3215 | goto out; |
| 3216 | } |
| 3217 | |
| 3218 | cur_arg += 2; |
| 3219 | } |
| 3220 | else if (!strcmp(args[cur_arg], "error-limit")) { |
| 3221 | if (!*args[cur_arg + 1]) { |
| 3222 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 3223 | file, linenum, args[cur_arg]); |
| 3224 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3225 | goto out; |
| 3226 | } |
| 3227 | |
| 3228 | newsrv->consecutive_errors_limit = atoi(args[cur_arg + 1]); |
| 3229 | |
| 3230 | if (newsrv->consecutive_errors_limit <= 0) { |
| 3231 | Alert("parsing [%s:%d]: %s has to be > 0.\n", |
| 3232 | file, linenum, args[cur_arg]); |
| 3233 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3234 | goto out; |
| 3235 | } |
| 3236 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3237 | 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] | 3238 | int port_low, port_high; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3239 | if (!*args[cur_arg + 1]) { |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 3240 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 3241 | 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] | 3242 | file, linenum, "source", "usesrc"); |
| 3243 | #else |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 3244 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>[-<port>]] as argument.\n", |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3245 | file, linenum, "source"); |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 3246 | #endif |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3247 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3248 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3249 | } |
| 3250 | newsrv->state |= SRV_BIND_SRC; |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 3251 | newsrv->source_addr = *str2sa_range(args[cur_arg + 1], &port_low, &port_high); |
| 3252 | |
| 3253 | if (port_low != port_high) { |
| 3254 | int i; |
| 3255 | if (port_low <= 0 || port_low > 65535 || |
| 3256 | port_high <= 0 || port_high > 65535 || |
| 3257 | port_low > port_high) { |
| 3258 | Alert("parsing [%s:%d] : invalid source port range %d-%d.\n", |
| 3259 | file, linenum, port_low, port_high); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3260 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3261 | goto out; |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 3262 | } |
| 3263 | newsrv->sport_range = port_range_alloc_range(port_high - port_low + 1); |
| 3264 | for (i = 0; i < newsrv->sport_range->size; i++) |
| 3265 | newsrv->sport_range->ports[i] = port_low + i; |
| 3266 | } |
| 3267 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3268 | cur_arg += 2; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 3269 | while (*(args[cur_arg])) { |
| 3270 | if (!strcmp(args[cur_arg], "usesrc")) { /* address to use outside */ |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 3271 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) |
| 3272 | #if !defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 3273 | if (newsrv->source_addr.sin_addr.s_addr == INADDR_ANY) { |
| 3274 | Alert("parsing [%s:%d] : '%s' requires an explicit '%s' address.\n", |
| 3275 | file, linenum, "usesrc", "source"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3276 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3277 | goto out; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 3278 | } |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 3279 | #endif |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 3280 | if (!*args[cur_arg + 1]) { |
| 3281 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n", |
| 3282 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3283 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3284 | goto out; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 3285 | } |
| 3286 | if (!strcmp(args[cur_arg + 1], "client")) { |
| 3287 | newsrv->state |= SRV_TPROXY_CLI; |
| 3288 | } else if (!strcmp(args[cur_arg + 1], "clientip")) { |
| 3289 | newsrv->state |= SRV_TPROXY_CIP; |
| 3290 | } else { |
| 3291 | newsrv->state |= SRV_TPROXY_ADDR; |
| 3292 | newsrv->tproxy_addr = *str2sa(args[cur_arg + 1]); |
| 3293 | } |
| 3294 | global.last_checks |= LSTCHK_NETADM; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 3295 | #if !defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 3296 | global.last_checks |= LSTCHK_CTTPROXY; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 3297 | #endif |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 3298 | cur_arg += 2; |
| 3299 | continue; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 3300 | #else /* no TPROXY support */ |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 3301 | 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] | 3302 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3303 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3304 | goto out; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 3305 | #endif /* defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) */ |
| 3306 | } /* "usesrc" */ |
| 3307 | |
| 3308 | if (!strcmp(args[cur_arg], "interface")) { /* specifically bind to this interface */ |
| 3309 | #ifdef SO_BINDTODEVICE |
| 3310 | if (!*args[cur_arg + 1]) { |
| 3311 | Alert("parsing [%s:%d] : '%s' : missing interface name.\n", |
| 3312 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3313 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3314 | goto out; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 3315 | } |
| 3316 | if (newsrv->iface_name) |
| 3317 | free(newsrv->iface_name); |
| 3318 | |
| 3319 | newsrv->iface_name = strdup(args[cur_arg + 1]); |
| 3320 | newsrv->iface_len = strlen(newsrv->iface_name); |
| 3321 | global.last_checks |= LSTCHK_NETADM; |
| 3322 | #else |
| 3323 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 3324 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3325 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3326 | goto out; |
Willy Tarreau | 77074d5 | 2006-11-12 23:57:19 +0100 | [diff] [blame] | 3327 | #endif |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 3328 | cur_arg += 2; |
| 3329 | continue; |
| 3330 | } |
| 3331 | /* this keyword in not an option of "source" */ |
| 3332 | break; |
| 3333 | } /* while */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3334 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3335 | 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] | 3336 | Alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n", |
| 3337 | file, linenum, "usesrc", "source"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3338 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3339 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 3340 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3341 | else { |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3342 | if (!defsrv) |
Krzysztof Piotr Oledzki | a9389b1 | 2010-01-05 16:44:17 +0100 | [diff] [blame] | 3343 | Alert("parsing [%s:%d] : server %s only supports options 'backup', 'cookie', 'redir', 'observer', 'on-error', 'error-limit', 'check', '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] | 3344 | file, linenum, newsrv->id); |
| 3345 | else |
Krzysztof Piotr Oledzki | a9389b1 | 2010-01-05 16:44:17 +0100 | [diff] [blame] | 3346 | 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] | 3347 | file, linenum); |
| 3348 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3349 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3350 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3351 | } |
| 3352 | } |
| 3353 | |
| 3354 | if (do_check) { |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 3355 | if (newsrv->trackit) { |
| 3356 | Alert("parsing [%s:%d]: unable to enable checks and tracking at the same time!\n", |
| 3357 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3358 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3359 | goto out; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 3360 | } |
| 3361 | |
Willy Tarreau | 0f03c6f | 2007-03-25 20:46:19 +0200 | [diff] [blame] | 3362 | if (!newsrv->check_port && newsrv->check_addr.sin_port) |
| 3363 | newsrv->check_port = newsrv->check_addr.sin_port; |
| 3364 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3365 | if (!newsrv->check_port && !(newsrv->state & SRV_MAPPORTS)) |
| 3366 | newsrv->check_port = realport; /* by default */ |
| 3367 | if (!newsrv->check_port) { |
Willy Tarreau | ef00b50 | 2007-01-07 02:40:09 +0100 | [diff] [blame] | 3368 | /* not yet valid, because no port was set on |
| 3369 | * the server either. We'll check if we have |
| 3370 | * a known port on the first listener. |
| 3371 | */ |
| 3372 | struct listener *l; |
| 3373 | l = curproxy->listen; |
| 3374 | if (l) { |
| 3375 | int port; |
| 3376 | port = (l->addr.ss_family == AF_INET6) |
| 3377 | ? ntohs(((struct sockaddr_in6 *)(&l->addr))->sin6_port) |
| 3378 | : ntohs(((struct sockaddr_in *)(&l->addr))->sin_port); |
| 3379 | newsrv->check_port = port; |
| 3380 | } |
| 3381 | } |
| 3382 | if (!newsrv->check_port) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3383 | Alert("parsing [%s:%d] : server %s has neither service port nor check port. Check has been disabled.\n", |
| 3384 | file, linenum, newsrv->id); |
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 | } |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 3388 | |
| 3389 | newsrv->check_status = HCHK_STATUS_INI; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3390 | newsrv->state |= SRV_CHECKED; |
| 3391 | } |
| 3392 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3393 | if (!defsrv) { |
| 3394 | if (newsrv->state & SRV_BACKUP) |
| 3395 | curproxy->srv_bck++; |
| 3396 | else |
| 3397 | curproxy->srv_act++; |
Willy Tarreau | b625a08 | 2007-11-26 01:15:43 +0100 | [diff] [blame] | 3398 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3399 | newsrv->prev_state = newsrv->state; |
| 3400 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3401 | } |
| 3402 | else if (!strcmp(args[0], "log")) { /* syslog server address */ |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 3403 | struct logsrv logsrv; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3404 | int facility; |
| 3405 | |
| 3406 | if (*(args[1]) && *(args[2]) == 0 && !strcmp(args[1], "global")) { |
| 3407 | curproxy->logfac1 = global.logfac1; |
| 3408 | curproxy->logsrv1 = global.logsrv1; |
| 3409 | curproxy->loglev1 = global.loglev1; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 3410 | curproxy->minlvl1 = global.minlvl1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3411 | curproxy->logfac2 = global.logfac2; |
| 3412 | curproxy->logsrv2 = global.logsrv2; |
| 3413 | curproxy->loglev2 = global.loglev2; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 3414 | curproxy->minlvl2 = global.minlvl2; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3415 | } |
| 3416 | else if (*(args[1]) && *(args[2])) { |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 3417 | int level, minlvl; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3418 | |
| 3419 | facility = get_log_facility(args[2]); |
| 3420 | if (facility < 0) { |
| 3421 | Alert("parsing [%s:%d] : unknown log facility '%s'\n", file, linenum, args[2]); |
| 3422 | exit(1); |
| 3423 | } |
| 3424 | |
| 3425 | level = 7; /* max syslog level = debug */ |
| 3426 | if (*(args[3])) { |
| 3427 | level = get_log_level(args[3]); |
| 3428 | if (level < 0) { |
| 3429 | Alert("parsing [%s:%d] : unknown optional log level '%s'\n", file, linenum, args[3]); |
| 3430 | exit(1); |
| 3431 | } |
| 3432 | } |
| 3433 | |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 3434 | minlvl = 0; /* limit syslog level to this level (emerg) */ |
| 3435 | if (*(args[4])) { |
| 3436 | minlvl = get_log_level(args[4]); |
| 3437 | if (level < 0) { |
| 3438 | Alert("parsing [%s:%d] : unknown optional minimum log level '%s'\n", file, linenum, args[4]); |
| 3439 | exit(1); |
| 3440 | } |
| 3441 | } |
| 3442 | |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 3443 | if (args[1][0] == '/') { |
| 3444 | logsrv.u.addr.sa_family = AF_UNIX; |
| 3445 | logsrv.u.un = *str2sun(args[1]); |
| 3446 | } else { |
| 3447 | logsrv.u.addr.sa_family = AF_INET; |
| 3448 | logsrv.u.in = *str2sa(args[1]); |
| 3449 | if (!logsrv.u.in.sin_port) { |
| 3450 | logsrv.u.in.sin_port = |
| 3451 | htons(SYSLOG_PORT); |
| 3452 | } |
| 3453 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3454 | |
| 3455 | if (curproxy->logfac1 == -1) { |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 3456 | curproxy->logsrv1 = logsrv; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3457 | curproxy->logfac1 = facility; |
| 3458 | curproxy->loglev1 = level; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 3459 | curproxy->minlvl1 = minlvl; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3460 | } |
| 3461 | else if (curproxy->logfac2 == -1) { |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 3462 | curproxy->logsrv2 = logsrv; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3463 | curproxy->logfac2 = facility; |
| 3464 | curproxy->loglev2 = level; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 3465 | curproxy->minlvl2 = minlvl; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3466 | } |
| 3467 | else { |
| 3468 | Alert("parsing [%s:%d] : too many syslog servers\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3469 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3470 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3471 | } |
| 3472 | } |
| 3473 | else { |
| 3474 | Alert("parsing [%s:%d] : 'log' expects either <address[:port]> and <facility> or 'global' as arguments.\n", |
| 3475 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3476 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3477 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3478 | } |
| 3479 | } |
| 3480 | 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] | 3481 | int cur_arg; |
| 3482 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3483 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3484 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3485 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3486 | if (!*args[1]) { |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 3487 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optionally '%s' <addr>, and '%s' <name>.\n", |
| 3488 | file, linenum, "source", "usesrc", "interface"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3489 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3490 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3491 | } |
Willy Tarreau | 368480c | 2009-03-01 08:27:21 +0100 | [diff] [blame] | 3492 | |
| 3493 | /* we must first clear any optional default setting */ |
| 3494 | curproxy->options &= ~PR_O_TPXY_MASK; |
| 3495 | free(curproxy->iface_name); |
| 3496 | curproxy->iface_name = NULL; |
| 3497 | curproxy->iface_len = 0; |
| 3498 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3499 | curproxy->source_addr = *str2sa(args[1]); |
| 3500 | curproxy->options |= PR_O_BIND_SRC; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 3501 | |
| 3502 | cur_arg = 2; |
| 3503 | while (*(args[cur_arg])) { |
| 3504 | if (!strcmp(args[cur_arg], "usesrc")) { /* address to use outside */ |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 3505 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) |
| 3506 | #if !defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 3507 | if (curproxy->source_addr.sin_addr.s_addr == INADDR_ANY) { |
| 3508 | Alert("parsing [%s:%d] : '%s' requires an explicit 'source' address.\n", |
| 3509 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3510 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3511 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 3512 | } |
| 3513 | #endif |
| 3514 | if (!*args[cur_arg + 1]) { |
| 3515 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n", |
| 3516 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3517 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3518 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 3519 | } |
| 3520 | |
| 3521 | if (!strcmp(args[cur_arg + 1], "client")) { |
| 3522 | curproxy->options |= PR_O_TPXY_CLI; |
| 3523 | } else if (!strcmp(args[cur_arg + 1], "clientip")) { |
| 3524 | curproxy->options |= PR_O_TPXY_CIP; |
| 3525 | } else { |
| 3526 | curproxy->options |= PR_O_TPXY_ADDR; |
| 3527 | curproxy->tproxy_addr = *str2sa(args[cur_arg + 1]); |
| 3528 | } |
| 3529 | global.last_checks |= LSTCHK_NETADM; |
| 3530 | #if !defined(CONFIG_HAP_LINUX_TPROXY) |
| 3531 | global.last_checks |= LSTCHK_CTTPROXY; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 3532 | #endif |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 3533 | #else /* no TPROXY support */ |
| 3534 | 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] | 3535 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3536 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3537 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 3538 | #endif |
| 3539 | cur_arg += 2; |
| 3540 | continue; |
Willy Tarreau | 77074d5 | 2006-11-12 23:57:19 +0100 | [diff] [blame] | 3541 | } |
| 3542 | |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 3543 | if (!strcmp(args[cur_arg], "interface")) { /* specifically bind to this interface */ |
| 3544 | #ifdef SO_BINDTODEVICE |
| 3545 | if (!*args[cur_arg + 1]) { |
| 3546 | Alert("parsing [%s:%d] : '%s' : missing interface name.\n", |
| 3547 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3548 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3549 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 3550 | } |
| 3551 | if (curproxy->iface_name) |
| 3552 | free(curproxy->iface_name); |
| 3553 | |
| 3554 | curproxy->iface_name = strdup(args[cur_arg + 1]); |
| 3555 | curproxy->iface_len = strlen(curproxy->iface_name); |
| 3556 | global.last_checks |= LSTCHK_NETADM; |
| 3557 | #else |
| 3558 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 3559 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3560 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3561 | goto out; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 3562 | #endif |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 3563 | cur_arg += 2; |
| 3564 | continue; |
| 3565 | } |
| 3566 | Alert("parsing [%s:%d] : '%s' only supports optional keywords '%s' and '%s'.\n", |
| 3567 | file, linenum, args[0], "inteface", "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3568 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3569 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 3570 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3571 | } |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 3572 | else if (!strcmp(args[0], "usesrc")) { /* address to use outside: needs "source" first */ |
| 3573 | Alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n", |
| 3574 | file, linenum, "usesrc", "source"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3575 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3576 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 3577 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3578 | else if (!strcmp(args[0], "cliexp") || !strcmp(args[0], "reqrep")) { /* replace request header from a regex */ |
| 3579 | regex_t *preg; |
| 3580 | if (curproxy == &defproxy) { |
| 3581 | 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] | 3582 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3583 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3584 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3585 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3586 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3587 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3588 | if (*(args[1]) == 0 || *(args[2]) == 0) { |
| 3589 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 3590 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3591 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3592 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3593 | } |
| 3594 | |
| 3595 | preg = calloc(1, sizeof(regex_t)); |
| 3596 | if (regcomp(preg, args[1], REG_EXTENDED) != 0) { |
| 3597 | Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3598 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3599 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3600 | } |
| 3601 | |
| 3602 | err = chain_regex(&curproxy->req_exp, preg, ACT_REPLACE, strdup(args[2])); |
| 3603 | if (err) { |
| 3604 | Alert("parsing [%s:%d] : invalid character or unterminated sequence in replacement string near '%c'.\n", |
| 3605 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3606 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3607 | } |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 3608 | warnif_misplaced_reqxxx(curproxy, file, linenum, args[0]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3609 | } |
| 3610 | else if (!strcmp(args[0], "reqdel")) { /* delete request header from a regex */ |
| 3611 | regex_t *preg; |
| 3612 | if (curproxy == &defproxy) { |
| 3613 | 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] | 3614 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3615 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3616 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3617 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3618 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3619 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3620 | if (*(args[1]) == 0) { |
| 3621 | Alert("parsing [%s:%d] : '%s' expects <regex> as an argument.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3622 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3623 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3624 | } |
| 3625 | |
| 3626 | preg = calloc(1, sizeof(regex_t)); |
| 3627 | if (regcomp(preg, args[1], REG_EXTENDED) != 0) { |
| 3628 | Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3629 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3630 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3631 | } |
| 3632 | |
| 3633 | chain_regex(&curproxy->req_exp, preg, ACT_REMOVE, NULL); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 3634 | warnif_misplaced_reqxxx(curproxy, file, linenum, args[0]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3635 | } |
| 3636 | else if (!strcmp(args[0], "reqdeny")) { /* deny a request if a header matches this regex */ |
| 3637 | regex_t *preg; |
| 3638 | if (curproxy == &defproxy) { |
| 3639 | 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] | 3640 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3641 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3642 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3643 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3644 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3645 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3646 | if (*(args[1]) == 0) { |
| 3647 | Alert("parsing [%s:%d] : '%s' expects <regex> as an argument.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3648 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3649 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3650 | } |
| 3651 | |
| 3652 | preg = calloc(1, sizeof(regex_t)); |
| 3653 | if (regcomp(preg, args[1], REG_EXTENDED) != 0) { |
| 3654 | Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3655 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3656 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3657 | } |
| 3658 | |
| 3659 | chain_regex(&curproxy->req_exp, preg, ACT_DENY, NULL); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 3660 | warnif_misplaced_reqxxx(curproxy, file, linenum, args[0]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3661 | } |
| 3662 | else if (!strcmp(args[0], "reqpass")) { /* pass this header without allowing or denying the request */ |
| 3663 | regex_t *preg; |
| 3664 | if (curproxy == &defproxy) { |
| 3665 | 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] | 3666 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3667 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3668 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3669 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3670 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3671 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3672 | if (*(args[1]) == 0) { |
| 3673 | Alert("parsing [%s:%d] : '%s' expects <regex> as an argument.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3674 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3675 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3676 | } |
| 3677 | |
| 3678 | preg = calloc(1, sizeof(regex_t)); |
| 3679 | if (regcomp(preg, args[1], REG_EXTENDED) != 0) { |
| 3680 | Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3681 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3682 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3683 | } |
| 3684 | |
| 3685 | chain_regex(&curproxy->req_exp, preg, ACT_PASS, NULL); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 3686 | warnif_misplaced_reqxxx(curproxy, file, linenum, args[0]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3687 | } |
| 3688 | else if (!strcmp(args[0], "reqallow")) { /* allow a request if a header matches this regex */ |
| 3689 | regex_t *preg; |
| 3690 | if (curproxy == &defproxy) { |
| 3691 | 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] | 3692 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3693 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3694 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3695 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3696 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3697 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3698 | if (*(args[1]) == 0) { |
| 3699 | Alert("parsing [%s:%d] : '%s' expects <regex> as an argument.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3700 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3701 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3702 | } |
| 3703 | |
| 3704 | preg = calloc(1, sizeof(regex_t)); |
| 3705 | if (regcomp(preg, args[1], REG_EXTENDED) != 0) { |
| 3706 | Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3707 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3708 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3709 | } |
| 3710 | |
| 3711 | chain_regex(&curproxy->req_exp, preg, ACT_ALLOW, NULL); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 3712 | warnif_misplaced_reqxxx(curproxy, file, linenum, args[0]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3713 | } |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 3714 | else if (!strcmp(args[0], "reqtarpit")) { /* tarpit a request if a header matches this regex */ |
| 3715 | regex_t *preg; |
| 3716 | if (curproxy == &defproxy) { |
| 3717 | 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] | 3718 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3719 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 3720 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3721 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3722 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3723 | |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 3724 | if (*(args[1]) == 0) { |
| 3725 | Alert("parsing [%s:%d] : '%s' expects <regex> as an argument.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3726 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3727 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 3728 | } |
| 3729 | |
| 3730 | preg = calloc(1, sizeof(regex_t)); |
| 3731 | if (regcomp(preg, args[1], REG_EXTENDED) != 0) { |
| 3732 | Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3733 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3734 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 3735 | } |
| 3736 | |
| 3737 | chain_regex(&curproxy->req_exp, preg, ACT_TARPIT, NULL); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 3738 | warnif_misplaced_reqxxx(curproxy, file, linenum, args[0]); |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 3739 | } |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 3740 | else if (!strcmp(args[0], "reqsetbe")) { /* switch the backend from a regex, respecting case */ |
| 3741 | regex_t *preg; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3742 | if (curproxy == &defproxy) { |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 3743 | 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] | 3744 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3745 | goto out; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 3746 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3747 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3748 | err_code |= ERR_WARN; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 3749 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3750 | if (*(args[1]) == 0 || *(args[2]) == 0) { |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 3751 | Alert("parsing [%s:%d] : '%s' expects <search> and <target> as arguments.\n", |
| 3752 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3753 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3754 | goto out; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 3755 | } |
| 3756 | |
| 3757 | preg = calloc(1, sizeof(regex_t)); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3758 | if (regcomp(preg, args[1], REG_EXTENDED) != 0) { |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 3759 | Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3760 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3761 | goto out; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 3762 | } |
| 3763 | |
| 3764 | chain_regex(&curproxy->req_exp, preg, ACT_SETBE, strdup(args[2])); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 3765 | warnif_misplaced_reqxxx(curproxy, file, linenum, args[0]); |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 3766 | } |
| 3767 | else if (!strcmp(args[0], "reqisetbe")) { /* switch the backend from a regex, ignoring case */ |
| 3768 | regex_t *preg; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3769 | if (curproxy == &defproxy) { |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 3770 | 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] | 3771 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3772 | goto out; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 3773 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3774 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3775 | err_code |= ERR_WARN; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 3776 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3777 | if (*(args[1]) == 0 || *(args[2]) == 0) { |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 3778 | Alert("parsing [%s:%d] : '%s' expects <search> and <target> as arguments.\n", |
| 3779 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3780 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3781 | goto out; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 3782 | } |
| 3783 | |
| 3784 | preg = calloc(1, sizeof(regex_t)); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3785 | if (regcomp(preg, args[1], REG_EXTENDED | REG_ICASE) != 0) { |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 3786 | Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3787 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3788 | goto out; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 3789 | } |
| 3790 | |
| 3791 | chain_regex(&curproxy->req_exp, preg, ACT_SETBE, strdup(args[2])); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 3792 | warnif_misplaced_reqxxx(curproxy, file, linenum, args[0]); |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 3793 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3794 | else if (!strcmp(args[0], "reqirep")) { /* replace request header from a regex, ignoring case */ |
| 3795 | regex_t *preg; |
| 3796 | if (curproxy == &defproxy) { |
| 3797 | 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] | 3798 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3799 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3800 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3801 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3802 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3803 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3804 | if (*(args[1]) == 0 || *(args[2]) == 0) { |
| 3805 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 3806 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3807 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3808 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3809 | } |
| 3810 | |
| 3811 | preg = calloc(1, sizeof(regex_t)); |
| 3812 | if (regcomp(preg, args[1], REG_EXTENDED | REG_ICASE) != 0) { |
| 3813 | Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3814 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3815 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3816 | } |
| 3817 | |
| 3818 | err = chain_regex(&curproxy->req_exp, preg, ACT_REPLACE, strdup(args[2])); |
| 3819 | if (err) { |
| 3820 | Alert("parsing [%s:%d] : invalid character or unterminated sequence in replacement string near '%c'.\n", |
| 3821 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3822 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3823 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3824 | } |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 3825 | warnif_misplaced_reqxxx(curproxy, file, linenum, args[0]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3826 | } |
| 3827 | else if (!strcmp(args[0], "reqidel")) { /* delete request header from a regex ignoring case */ |
| 3828 | regex_t *preg; |
| 3829 | if (curproxy == &defproxy) { |
| 3830 | 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] | 3831 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3832 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3833 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3834 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3835 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3836 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3837 | if (*(args[1]) == 0) { |
| 3838 | Alert("parsing [%s:%d] : '%s' expects <regex> as an argument.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3839 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3840 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3841 | } |
| 3842 | |
| 3843 | preg = calloc(1, sizeof(regex_t)); |
| 3844 | if (regcomp(preg, args[1], REG_EXTENDED | REG_ICASE) != 0) { |
| 3845 | Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3846 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3847 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3848 | } |
| 3849 | |
| 3850 | chain_regex(&curproxy->req_exp, preg, ACT_REMOVE, NULL); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 3851 | warnif_misplaced_reqxxx(curproxy, file, linenum, args[0]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3852 | } |
| 3853 | else if (!strcmp(args[0], "reqideny")) { /* deny a request if a header matches this regex ignoring case */ |
| 3854 | regex_t *preg; |
| 3855 | if (curproxy == &defproxy) { |
| 3856 | 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] | 3857 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3858 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3859 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3860 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3861 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3862 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3863 | if (*(args[1]) == 0) { |
| 3864 | Alert("parsing [%s:%d] : '%s' expects <regex> as an argument.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3865 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3866 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3867 | } |
| 3868 | |
| 3869 | preg = calloc(1, sizeof(regex_t)); |
| 3870 | if (regcomp(preg, args[1], REG_EXTENDED | REG_ICASE) != 0) { |
| 3871 | Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3872 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3873 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3874 | } |
| 3875 | |
| 3876 | chain_regex(&curproxy->req_exp, preg, ACT_DENY, NULL); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 3877 | warnif_misplaced_reqxxx(curproxy, file, linenum, args[0]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3878 | } |
| 3879 | else if (!strcmp(args[0], "reqipass")) { /* pass this header without allowing or denying the request */ |
| 3880 | regex_t *preg; |
| 3881 | if (curproxy == &defproxy) { |
| 3882 | 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] | 3883 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3884 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3885 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3886 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3887 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3888 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3889 | if (*(args[1]) == 0) { |
| 3890 | Alert("parsing [%s:%d] : '%s' expects <regex> as an argument.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3891 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3892 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3893 | } |
| 3894 | |
| 3895 | preg = calloc(1, sizeof(regex_t)); |
| 3896 | if (regcomp(preg, args[1], REG_EXTENDED | REG_ICASE) != 0) { |
| 3897 | Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3898 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3899 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3900 | } |
| 3901 | |
| 3902 | chain_regex(&curproxy->req_exp, preg, ACT_PASS, NULL); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 3903 | warnif_misplaced_reqxxx(curproxy, file, linenum, args[0]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3904 | } |
| 3905 | else if (!strcmp(args[0], "reqiallow")) { /* allow a request if a header matches this regex ignoring case */ |
| 3906 | regex_t *preg; |
| 3907 | if (curproxy == &defproxy) { |
| 3908 | 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] | 3909 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3910 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3911 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3912 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3913 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3914 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3915 | if (*(args[1]) == 0) { |
| 3916 | Alert("parsing [%s:%d] : '%s' expects <regex> as an argument.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3917 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3918 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3919 | } |
| 3920 | |
| 3921 | preg = calloc(1, sizeof(regex_t)); |
| 3922 | if (regcomp(preg, args[1], REG_EXTENDED | REG_ICASE) != 0) { |
| 3923 | Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3924 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3925 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3926 | } |
| 3927 | |
| 3928 | chain_regex(&curproxy->req_exp, preg, ACT_ALLOW, NULL); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 3929 | warnif_misplaced_reqxxx(curproxy, file, linenum, args[0]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3930 | } |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 3931 | else if (!strcmp(args[0], "reqitarpit")) { /* tarpit a request if a header matches this regex ignoring case */ |
| 3932 | regex_t *preg; |
| 3933 | if (curproxy == &defproxy) { |
| 3934 | 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] | 3935 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3936 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 3937 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3938 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3939 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3940 | |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 3941 | if (*(args[1]) == 0) { |
| 3942 | Alert("parsing [%s:%d] : '%s' expects <regex> as an argument.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3943 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3944 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 3945 | } |
| 3946 | |
| 3947 | preg = calloc(1, sizeof(regex_t)); |
| 3948 | if (regcomp(preg, args[1], REG_EXTENDED | REG_ICASE) != 0) { |
| 3949 | Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3950 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3951 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 3952 | } |
| 3953 | |
| 3954 | chain_regex(&curproxy->req_exp, preg, ACT_TARPIT, NULL); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 3955 | warnif_misplaced_reqxxx(curproxy, file, linenum, args[0]); |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 3956 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3957 | else if (!strcmp(args[0], "reqadd")) { /* add request header */ |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 3958 | struct wordlist *wl; |
| 3959 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3960 | if (curproxy == &defproxy) { |
| 3961 | 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] | 3962 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3963 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3964 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3965 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3966 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3967 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3968 | if (*(args[1]) == 0) { |
| 3969 | 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] | 3970 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3971 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3972 | } |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 3973 | |
| 3974 | wl = calloc(1, sizeof(*wl)); |
| 3975 | wl->s = strdup(args[1]); |
| 3976 | LIST_ADDQ(&curproxy->req_add, &wl->list); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 3977 | warnif_misplaced_reqadd(curproxy, file, linenum, args[0]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3978 | } |
| 3979 | else if (!strcmp(args[0], "srvexp") || !strcmp(args[0], "rsprep")) { /* replace response header from a regex */ |
| 3980 | regex_t *preg; |
| 3981 | |
| 3982 | if (*(args[1]) == 0 || *(args[2]) == 0) { |
| 3983 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 3984 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3985 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3986 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3987 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3988 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3989 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3990 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3991 | preg = calloc(1, sizeof(regex_t)); |
| 3992 | if (regcomp(preg, args[1], REG_EXTENDED) != 0) { |
| 3993 | Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3994 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3995 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3996 | } |
| 3997 | |
| 3998 | err = chain_regex(&curproxy->rsp_exp, preg, ACT_REPLACE, strdup(args[2])); |
| 3999 | if (err) { |
| 4000 | Alert("parsing [%s:%d] : invalid character or unterminated sequence in replacement string near '%c'.\n", |
| 4001 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4002 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4003 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4004 | } |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 4005 | warnif_misplaced_reqxxx(curproxy, file, linenum, args[0]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4006 | } |
| 4007 | else if (!strcmp(args[0], "rspdel")) { /* delete response header from a regex */ |
| 4008 | regex_t *preg; |
| 4009 | if (curproxy == &defproxy) { |
| 4010 | 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] | 4011 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4012 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4013 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4014 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4015 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4016 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4017 | if (*(args[1]) == 0) { |
| 4018 | Alert("parsing [%s:%d] : '%s' expects <search> as an argument.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4019 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4020 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4021 | } |
| 4022 | |
| 4023 | preg = calloc(1, sizeof(regex_t)); |
| 4024 | if (regcomp(preg, args[1], REG_EXTENDED) != 0) { |
| 4025 | Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4026 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4027 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4028 | } |
| 4029 | |
| 4030 | err = chain_regex(&curproxy->rsp_exp, preg, ACT_REMOVE, strdup(args[2])); |
| 4031 | if (err) { |
| 4032 | Alert("parsing [%s:%d] : invalid character or unterminated sequence in replacement string near '%c'.\n", |
| 4033 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4034 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4035 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4036 | } |
| 4037 | } |
| 4038 | else if (!strcmp(args[0], "rspdeny")) { /* block response header from a regex */ |
| 4039 | regex_t *preg; |
| 4040 | if (curproxy == &defproxy) { |
| 4041 | 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] | 4042 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4043 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4044 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4045 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4046 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4047 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4048 | if (*(args[1]) == 0) { |
| 4049 | Alert("parsing [%s:%d] : '%s' expects <search> as an argument.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4050 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4051 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4052 | } |
| 4053 | |
| 4054 | preg = calloc(1, sizeof(regex_t)); |
| 4055 | if (regcomp(preg, args[1], REG_EXTENDED) != 0) { |
| 4056 | Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4057 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4058 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4059 | } |
| 4060 | |
| 4061 | err = chain_regex(&curproxy->rsp_exp, preg, ACT_DENY, strdup(args[2])); |
| 4062 | if (err) { |
| 4063 | Alert("parsing [%s:%d] : invalid character or unterminated sequence in replacement string near '%c'.\n", |
| 4064 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4065 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4066 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4067 | } |
| 4068 | } |
| 4069 | else if (!strcmp(args[0], "rspirep")) { /* replace response header from a regex ignoring case */ |
| 4070 | regex_t *preg; |
| 4071 | if (curproxy == &defproxy) { |
| 4072 | 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] | 4073 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4074 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4075 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4076 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4077 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4078 | |
| 4079 | if (*(args[1]) == 0 || *(args[2]) == 0) { |
| 4080 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 4081 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4082 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4083 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4084 | } |
| 4085 | |
| 4086 | preg = calloc(1, sizeof(regex_t)); |
| 4087 | if (regcomp(preg, args[1], REG_EXTENDED | REG_ICASE) != 0) { |
| 4088 | Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4089 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4090 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4091 | } |
| 4092 | |
| 4093 | err = chain_regex(&curproxy->rsp_exp, preg, ACT_REPLACE, strdup(args[2])); |
| 4094 | if (err) { |
| 4095 | Alert("parsing [%s:%d] : invalid character or unterminated sequence in replacement string near '%c'.\n", |
| 4096 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4097 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4098 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4099 | } |
| 4100 | } |
| 4101 | else if (!strcmp(args[0], "rspidel")) { /* delete response header from a regex ignoring case */ |
| 4102 | regex_t *preg; |
| 4103 | if (curproxy == &defproxy) { |
| 4104 | 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] | 4105 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4106 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4107 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4108 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4109 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4110 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4111 | if (*(args[1]) == 0) { |
| 4112 | Alert("parsing [%s:%d] : '%s' expects <search> as an argument.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4113 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4114 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4115 | } |
| 4116 | |
| 4117 | preg = calloc(1, sizeof(regex_t)); |
| 4118 | if (regcomp(preg, args[1], REG_EXTENDED | REG_ICASE) != 0) { |
| 4119 | Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4120 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4121 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4122 | } |
| 4123 | |
| 4124 | err = chain_regex(&curproxy->rsp_exp, preg, ACT_REMOVE, strdup(args[2])); |
| 4125 | if (err) { |
| 4126 | Alert("parsing [%s:%d] : invalid character or unterminated sequence in replacement string near '%c'.\n", |
| 4127 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4128 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4129 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4130 | } |
| 4131 | } |
| 4132 | else if (!strcmp(args[0], "rspideny")) { /* block response header from a regex ignoring case */ |
| 4133 | regex_t *preg; |
| 4134 | if (curproxy == &defproxy) { |
| 4135 | 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] | 4136 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4137 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4138 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4139 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4140 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4141 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4142 | if (*(args[1]) == 0) { |
| 4143 | Alert("parsing [%s:%d] : '%s' expects <search> as an argument.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4144 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4145 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4146 | } |
| 4147 | |
| 4148 | preg = calloc(1, sizeof(regex_t)); |
| 4149 | if (regcomp(preg, args[1], REG_EXTENDED | REG_ICASE) != 0) { |
| 4150 | Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4151 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4152 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4153 | } |
| 4154 | |
| 4155 | err = chain_regex(&curproxy->rsp_exp, preg, ACT_DENY, strdup(args[2])); |
| 4156 | if (err) { |
| 4157 | Alert("parsing [%s:%d] : invalid character or unterminated sequence in replacement string near '%c'.\n", |
| 4158 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4159 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4160 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4161 | } |
| 4162 | } |
| 4163 | else if (!strcmp(args[0], "rspadd")) { /* add response header */ |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 4164 | struct wordlist *wl; |
| 4165 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4166 | if (curproxy == &defproxy) { |
| 4167 | 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] | 4168 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4169 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4170 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4171 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4172 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4173 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4174 | if (*(args[1]) == 0) { |
| 4175 | 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] | 4176 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4177 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4178 | } |
| 4179 | |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 4180 | wl = calloc(1, sizeof(*wl)); |
| 4181 | wl->s = strdup(args[1]); |
| 4182 | LIST_ADDQ(&curproxy->rsp_add, &wl->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4183 | } |
| 4184 | else if (!strcmp(args[0], "errorloc") || |
| 4185 | !strcmp(args[0], "errorloc302") || |
| 4186 | !strcmp(args[0], "errorloc303")) { /* error location */ |
| 4187 | int errnum, errlen; |
| 4188 | char *err; |
| 4189 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4190 | 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] | 4191 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4192 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4193 | if (*(args[2]) == 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 4194 | 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] | 4195 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4196 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4197 | } |
| 4198 | |
| 4199 | errnum = atol(args[1]); |
| 4200 | if (!strcmp(args[0], "errorloc303")) { |
| 4201 | err = malloc(strlen(HTTP_303) + strlen(args[2]) + 5); |
| 4202 | errlen = sprintf(err, "%s%s\r\n\r\n", HTTP_303, args[2]); |
| 4203 | } else { |
| 4204 | err = malloc(strlen(HTTP_302) + strlen(args[2]) + 5); |
| 4205 | errlen = sprintf(err, "%s%s\r\n\r\n", HTTP_302, args[2]); |
| 4206 | } |
| 4207 | |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 4208 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) { |
| 4209 | if (http_err_codes[rc] == errnum) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 4210 | chunk_destroy(&curproxy->errmsg[rc]); |
| 4211 | chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 4212 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4213 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4214 | } |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 4215 | |
| 4216 | if (rc >= HTTP_ERR_SIZE) { |
| 4217 | Warning("parsing [%s:%d] : status code %d not handled, error relocation will be ignored.\n", |
| 4218 | file, linenum, errnum); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4219 | free(err); |
| 4220 | } |
| 4221 | } |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 4222 | else if (!strcmp(args[0], "errorfile")) { /* error message from a file */ |
| 4223 | int errnum, errlen, fd; |
| 4224 | char *err; |
| 4225 | struct stat stat; |
| 4226 | |
| 4227 | 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] | 4228 | err_code |= ERR_WARN; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 4229 | |
| 4230 | if (*(args[2]) == 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 4231 | 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] | 4232 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4233 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 4234 | } |
| 4235 | |
| 4236 | fd = open(args[2], O_RDONLY); |
| 4237 | if ((fd < 0) || (fstat(fd, &stat) < 0)) { |
| 4238 | Alert("parsing [%s:%d] : error opening file <%s> for custom error message <%s>.\n", |
| 4239 | file, linenum, args[2], args[1]); |
| 4240 | if (fd >= 0) |
| 4241 | close(fd); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4242 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4243 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 4244 | } |
| 4245 | |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 4246 | if (stat.st_size <= global.tune.bufsize) { |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 4247 | errlen = stat.st_size; |
| 4248 | } else { |
| 4249 | 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] | 4250 | file, linenum, args[2], global.tune.bufsize); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4251 | err_code |= ERR_WARN; |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 4252 | errlen = global.tune.bufsize; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 4253 | } |
| 4254 | |
| 4255 | err = malloc(errlen); /* malloc() must succeed during parsing */ |
| 4256 | errnum = read(fd, err, errlen); |
| 4257 | if (errnum != errlen) { |
| 4258 | Alert("parsing [%s:%d] : error reading file <%s> for custom error message <%s>.\n", |
| 4259 | file, linenum, args[2], args[1]); |
| 4260 | close(fd); |
| 4261 | free(err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4262 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4263 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 4264 | } |
| 4265 | close(fd); |
| 4266 | |
| 4267 | errnum = atol(args[1]); |
| 4268 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) { |
| 4269 | if (http_err_codes[rc] == errnum) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 4270 | chunk_destroy(&curproxy->errmsg[rc]); |
| 4271 | chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen); |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 4272 | break; |
| 4273 | } |
| 4274 | } |
| 4275 | |
| 4276 | if (rc >= HTTP_ERR_SIZE) { |
| 4277 | Warning("parsing [%s:%d] : status code %d not handled, error customization will be ignored.\n", |
| 4278 | file, linenum, errnum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4279 | err_code |= ERR_WARN; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 4280 | free(err); |
| 4281 | } |
| 4282 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4283 | else { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 4284 | struct cfg_kw_list *kwl; |
| 4285 | int index; |
| 4286 | |
| 4287 | list_for_each_entry(kwl, &cfg_keywords.list, list) { |
| 4288 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 4289 | if (kwl->kw[index].section != CFG_LISTEN) |
| 4290 | continue; |
| 4291 | if (strcmp(kwl->kw[index].kw, args[0]) == 0) { |
| 4292 | /* prepare error message just in case */ |
| 4293 | snprintf(trash, sizeof(trash), |
| 4294 | "error near '%s' in %s section", args[0], cursection); |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 4295 | rc = kwl->kw[index].parse(args, CFG_LISTEN, curproxy, &defproxy, trash, sizeof(trash)); |
| 4296 | if (rc < 0) { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 4297 | Alert("parsing [%s:%d] : %s\n", file, linenum, trash); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4298 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4299 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 4300 | } |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 4301 | else if (rc > 0) { |
| 4302 | Warning("parsing [%s:%d] : %s\n", file, linenum, trash); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4303 | err_code |= ERR_WARN; |
| 4304 | goto out; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 4305 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4306 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 4307 | } |
| 4308 | } |
| 4309 | } |
| 4310 | |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 4311 | 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] | 4312 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4313 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4314 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4315 | out: |
| 4316 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4317 | } |
| 4318 | |
| 4319 | |
| 4320 | /* |
| 4321 | * This function reads and parses the configuration file given in the argument. |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 4322 | * Returns the error code, 0 if OK, or any combination of : |
| 4323 | * - ERR_ABORT: must abort ASAP |
| 4324 | * - ERR_FATAL: we can continue parsing but not start the service |
| 4325 | * - ERR_WARN: a warning has been emitted |
| 4326 | * - ERR_ALERT: an alert has been emitted |
| 4327 | * Only the two first ones can stop processing, the two others are just |
| 4328 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4329 | */ |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 4330 | int readcfgfile(const char *file) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4331 | { |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 4332 | char thisline[LINESIZE]; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4333 | FILE *f; |
| 4334 | int linenum = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4335 | int confsect = CFG_NONE; |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 4336 | int err_code = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4337 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4338 | if ((f=fopen(file,"r")) == NULL) |
| 4339 | return -1; |
| 4340 | |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 4341 | while (fgets(thisline, sizeof(thisline), f) != NULL) { |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 4342 | int arg, kwm = KWM_STD; |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 4343 | char *end; |
| 4344 | char *args[MAX_LINE_ARGS + 1]; |
| 4345 | char *line = thisline; |
| 4346 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4347 | linenum++; |
| 4348 | |
| 4349 | end = line + strlen(line); |
| 4350 | |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 4351 | if (end-line == sizeof(thisline)-1 && *(end-1) != '\n') { |
| 4352 | /* Check if we reached the limit and the last char is not \n. |
| 4353 | * Watch out for the last line without the terminating '\n'! |
| 4354 | */ |
| 4355 | Alert("parsing [%s:%d]: line too long, limit: %d.\n", |
Willy Tarreau | 5e4a6f1 | 2009-04-11 19:42:49 +0200 | [diff] [blame] | 4356 | file, linenum, (int)sizeof(thisline)-1); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 4357 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 4358 | } |
| 4359 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4360 | /* skip leading spaces */ |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 4361 | while (isspace((unsigned char)*line)) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4362 | line++; |
| 4363 | |
| 4364 | arg = 0; |
| 4365 | args[arg] = line; |
| 4366 | |
| 4367 | while (*line && arg < MAX_LINE_ARGS) { |
| 4368 | /* first, we'll replace \\, \<space>, \#, \r, \n, \t, \xXX with their |
| 4369 | * C equivalent value. Other combinations left unchanged (eg: \1). |
| 4370 | */ |
| 4371 | if (*line == '\\') { |
| 4372 | int skip = 0; |
| 4373 | if (line[1] == ' ' || line[1] == '\\' || line[1] == '#') { |
| 4374 | *line = line[1]; |
| 4375 | skip = 1; |
| 4376 | } |
| 4377 | else if (line[1] == 'r') { |
| 4378 | *line = '\r'; |
| 4379 | skip = 1; |
| 4380 | } |
| 4381 | else if (line[1] == 'n') { |
| 4382 | *line = '\n'; |
| 4383 | skip = 1; |
| 4384 | } |
| 4385 | else if (line[1] == 't') { |
| 4386 | *line = '\t'; |
| 4387 | skip = 1; |
| 4388 | } |
| 4389 | else if (line[1] == 'x') { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4390 | if ((line + 3 < end) && ishex(line[2]) && ishex(line[3])) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4391 | unsigned char hex1, hex2; |
| 4392 | hex1 = toupper(line[2]) - '0'; |
| 4393 | hex2 = toupper(line[3]) - '0'; |
| 4394 | if (hex1 > 9) hex1 -= 'A' - '9' - 1; |
| 4395 | if (hex2 > 9) hex2 -= 'A' - '9' - 1; |
| 4396 | *line = (hex1<<4) + hex2; |
| 4397 | skip = 3; |
| 4398 | } |
| 4399 | else { |
| 4400 | 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] | 4401 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4402 | } |
| 4403 | } |
| 4404 | if (skip) { |
Cyril Bonté | dd1b01d | 2009-12-06 13:43:42 +0100 | [diff] [blame] | 4405 | memmove(line + 1, line + 1 + skip, end - (line + skip)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4406 | end -= skip; |
| 4407 | } |
| 4408 | line++; |
| 4409 | } |
| 4410 | else if (*line == '#' || *line == '\n' || *line == '\r') { |
| 4411 | /* end of string, end of loop */ |
| 4412 | *line = 0; |
| 4413 | break; |
| 4414 | } |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 4415 | else if (isspace((unsigned char)*line)) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4416 | /* a non-escaped space is an argument separator */ |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 4417 | *line++ = '\0'; |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 4418 | while (isspace((unsigned char)*line)) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4419 | line++; |
| 4420 | args[++arg] = line; |
| 4421 | } |
| 4422 | else { |
| 4423 | line++; |
| 4424 | } |
| 4425 | } |
| 4426 | |
| 4427 | /* empty line */ |
| 4428 | if (!**args) |
| 4429 | continue; |
| 4430 | |
Willy Tarreau | 7bb651e | 2009-11-09 21:16:53 +0100 | [diff] [blame] | 4431 | if (*line) { |
| 4432 | /* we had to stop due to too many args. |
| 4433 | * Let's terminate the string, print the offending part then cut the |
| 4434 | * last arg. |
| 4435 | */ |
| 4436 | while (*line && *line != '#' && *line != '\n' && *line != '\r') |
| 4437 | line++; |
| 4438 | *line = '\0'; |
| 4439 | |
Krzysztof Piotr Oledzki | 500b8f0 | 2009-12-15 22:34:51 +0100 | [diff] [blame] | 4440 | 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] | 4441 | file, linenum, arg + 1, (long)(args[arg] - thisline + 1), args[arg]); |
Willy Tarreau | 7bb651e | 2009-11-09 21:16:53 +0100 | [diff] [blame] | 4442 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4443 | args[arg] = line; |
| 4444 | } |
| 4445 | |
Willy Tarreau | 540abe4 | 2007-05-02 20:50:16 +0200 | [diff] [blame] | 4446 | /* zero out remaining args and ensure that at least one entry |
| 4447 | * is zeroed out. |
| 4448 | */ |
| 4449 | while (++arg <= MAX_LINE_ARGS) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4450 | args[arg] = line; |
| 4451 | } |
| 4452 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 4453 | /* check for keyword modifiers "no" and "default" */ |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 4454 | if (!strcmp(args[0], "no")) { |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 4455 | kwm = KWM_NO; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 4456 | for (arg=0; *args[arg+1]; arg++) |
| 4457 | args[arg] = args[arg+1]; // shift args after inversion |
| 4458 | } |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 4459 | else if (!strcmp(args[0], "default")) { |
| 4460 | kwm = KWM_DEF; |
| 4461 | for (arg=0; *args[arg+1]; arg++) |
| 4462 | args[arg] = args[arg+1]; // shift args after inversion |
| 4463 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 4464 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 4465 | if (kwm != KWM_STD && strcmp(args[0], "option") != 0) { |
| 4466 | 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] | 4467 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 4468 | } |
| 4469 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4470 | if (!strcmp(args[0], "listen") || |
| 4471 | !strcmp(args[0], "frontend") || |
| 4472 | !strcmp(args[0], "backend") || |
| 4473 | !strcmp(args[0], "ruleset") || |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 4474 | !strcmp(args[0], "defaults")) { /* new proxy */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4475 | confsect = CFG_LISTEN; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 4476 | free(cursection); |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 4477 | cursection = strdup(args[0]); |
| 4478 | } |
| 4479 | else if (!strcmp(args[0], "global")) { /* global config */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4480 | confsect = CFG_GLOBAL; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 4481 | free(cursection); |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 4482 | cursection = strdup(args[0]); |
| 4483 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4484 | /* else it's a section keyword */ |
| 4485 | |
| 4486 | switch (confsect) { |
| 4487 | case CFG_LISTEN: |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4488 | err_code |= cfg_parse_listen(file, linenum, args, kwm); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4489 | break; |
| 4490 | case CFG_GLOBAL: |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 4491 | err_code |= cfg_parse_global(file, linenum, args, kwm); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4492 | break; |
| 4493 | default: |
| 4494 | 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] | 4495 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4496 | } |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 4497 | |
| 4498 | if (err_code & ERR_ABORT) |
| 4499 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4500 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 4501 | free(cursection); |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 4502 | cursection = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4503 | fclose(f); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 4504 | return err_code; |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 4505 | } |
| 4506 | |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 4507 | /* |
| 4508 | * Returns the error code, 0 if OK, or any combination of : |
| 4509 | * - ERR_ABORT: must abort ASAP |
| 4510 | * - ERR_FATAL: we can continue parsing but not start the service |
| 4511 | * - ERR_WARN: a warning has been emitted |
| 4512 | * - ERR_ALERT: an alert has been emitted |
| 4513 | * Only the two first ones can stop processing, the two others are just |
| 4514 | * indicators. |
| 4515 | */ |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 4516 | int check_config_validity() |
| 4517 | { |
| 4518 | int cfgerr = 0; |
| 4519 | struct proxy *curproxy = NULL; |
| 4520 | struct server *newsrv = NULL; |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 4521 | int err_code = 0; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 4522 | unsigned int next_pxid = 1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4523 | |
| 4524 | /* |
| 4525 | * Now, check for the integrity of all that we have collected. |
| 4526 | */ |
| 4527 | |
| 4528 | /* will be needed further to delay some tasks */ |
Willy Tarreau | b0b37bc | 2008-06-23 14:00:57 +0200 | [diff] [blame] | 4529 | tv_update_date(0,1); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4530 | |
Willy Tarreau | 55bc0f8 | 2009-03-15 14:51:53 +0100 | [diff] [blame] | 4531 | /* first, we will invert the proxy list order */ |
| 4532 | curproxy = NULL; |
| 4533 | while (proxy) { |
| 4534 | struct proxy *next; |
| 4535 | |
| 4536 | next = proxy->next; |
| 4537 | proxy->next = curproxy; |
| 4538 | curproxy = proxy; |
| 4539 | if (!next) |
| 4540 | break; |
| 4541 | proxy = next; |
| 4542 | } |
| 4543 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4544 | if ((curproxy = proxy) == NULL) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 4545 | Alert("config : no <listen> line. Nothing to do !\n"); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 4546 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4547 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4548 | } |
| 4549 | |
| 4550 | while (curproxy != NULL) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 4551 | struct switching_rule *rule; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4552 | struct sticking_rule *mrule; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 4553 | struct listener *listener; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 4554 | unsigned int next_id; |
| 4555 | |
| 4556 | if (!curproxy->uuid) { |
| 4557 | /* proxy ID not set, use automatic numbering with first |
| 4558 | * spare entry starting with next_pxid. |
| 4559 | */ |
| 4560 | next_pxid = get_next_id(&used_proxy_id, next_pxid); |
| 4561 | curproxy->conf.id.key = curproxy->uuid = next_pxid; |
| 4562 | eb32_insert(&used_proxy_id, &curproxy->conf.id); |
| 4563 | next_pxid++; |
| 4564 | } |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 4565 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4566 | if (curproxy->state == PR_STSTOPPED) { |
Willy Tarreau | da250db | 2008-10-12 12:07:48 +0200 | [diff] [blame] | 4567 | /* ensure we don't keep listeners uselessly bound */ |
| 4568 | stop_proxy(curproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4569 | curproxy = curproxy->next; |
| 4570 | continue; |
| 4571 | } |
| 4572 | |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 4573 | switch (curproxy->mode) { |
| 4574 | case PR_MODE_HEALTH: |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 4575 | cfgerr += proxy_cfg_ensure_no_http(curproxy); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 4576 | if (!(curproxy->cap & PR_CAP_FE)) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 4577 | Alert("config : %s '%s' cannot be in health mode as it has no frontend capability.\n", |
| 4578 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 4579 | cfgerr++; |
| 4580 | } |
| 4581 | |
| 4582 | if (curproxy->srv != NULL) |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 4583 | Warning("config : servers will be ignored for %s '%s'.\n", |
| 4584 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 4585 | break; |
| 4586 | |
| 4587 | case PR_MODE_TCP: |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 4588 | cfgerr += proxy_cfg_ensure_no_http(curproxy); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 4589 | break; |
| 4590 | |
| 4591 | case PR_MODE_HTTP: |
Willy Tarreau | a9fb083 | 2009-07-10 20:53:53 +0200 | [diff] [blame] | 4592 | curproxy->acl_requires |= ACL_USE_L7_ANY; |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 4593 | if ((curproxy->cookie_name != NULL) && (curproxy->srv == NULL)) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 4594 | Alert("config : HTTP proxy %s has a cookie but no server list !\n", |
| 4595 | curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 4596 | cfgerr++; |
| 4597 | } |
| 4598 | break; |
| 4599 | } |
| 4600 | |
| 4601 | if ((curproxy->cap & PR_CAP_FE) && (curproxy->listen == NULL)) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 4602 | Alert("config : %s '%s' has no listen address. Please either specify a valid address on the <listen> line, or use the <bind> keyword.\n", |
| 4603 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4604 | cfgerr++; |
| 4605 | } |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 4606 | |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 4607 | if ((curproxy->cap & PR_CAP_BE) && (curproxy->mode != PR_MODE_HEALTH)) { |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 4608 | if (curproxy->lbprm.algo & BE_LB_KIND) { |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 4609 | if (curproxy->options & PR_O_TRANSP) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 4610 | Alert("config : %s '%s' cannot use both transparent and balance mode.\n", |
| 4611 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 4612 | cfgerr++; |
| 4613 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4614 | #ifdef WE_DONT_SUPPORT_SERVERLESS_LISTENERS |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 4615 | else if (curproxy->srv == NULL) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 4616 | Alert("config : %s '%s' needs at least 1 server in balance mode.\n", |
| 4617 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 4618 | cfgerr++; |
| 4619 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4620 | #endif |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 4621 | else if (*(int *)&curproxy->dispatch_addr.sin_addr != 0) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 4622 | Warning("config : dispatch address of %s '%s' will be ignored in balance mode.\n", |
| 4623 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 4624 | err_code |= ERR_WARN; |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 4625 | } |
| 4626 | } |
| 4627 | else if (!(curproxy->options & (PR_O_TRANSP | PR_O_HTTP_PROXY)) && |
| 4628 | (*(int *)&curproxy->dispatch_addr.sin_addr == 0)) { |
| 4629 | /* If no LB algo is set in a backend, and we're not in |
| 4630 | * transparent mode, dispatch mode nor proxy mode, we |
| 4631 | * want to use balance roundrobin by default. |
| 4632 | */ |
| 4633 | curproxy->lbprm.algo &= ~BE_LB_ALGO; |
| 4634 | curproxy->lbprm.algo |= BE_LB_ALGO_RR; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4635 | } |
| 4636 | } |
Willy Tarreau | 193cf93 | 2007-09-17 10:17:23 +0200 | [diff] [blame] | 4637 | |
Willy Tarreau | 8293658 | 2007-11-30 15:20:09 +0100 | [diff] [blame] | 4638 | if ((curproxy->options & PR_O_DISABLE404) && !(curproxy->options & PR_O_HTTP_CHK)) { |
| 4639 | curproxy->options &= ~PR_O_DISABLE404; |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 4640 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n", |
| 4641 | "disable-on-404", proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 4642 | err_code |= ERR_WARN; |
Willy Tarreau | 8293658 | 2007-11-30 15:20:09 +0100 | [diff] [blame] | 4643 | } |
| 4644 | |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 4645 | /* if a default backend was specified, let's find it */ |
| 4646 | if (curproxy->defbe.name) { |
| 4647 | struct proxy *target; |
| 4648 | |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 4649 | target = findproxy_mode(curproxy->defbe.name, curproxy->mode, PR_CAP_BE); |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 4650 | if (!target) { |
| 4651 | Alert("Proxy '%s': unable to find required default_backend: '%s'.\n", |
| 4652 | curproxy->id, curproxy->defbe.name); |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 4653 | cfgerr++; |
| 4654 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 4655 | Alert("Proxy '%s': loop detected for default_backend: '%s'.\n", |
| 4656 | curproxy->id, curproxy->defbe.name); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 4657 | cfgerr++; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 4658 | } else { |
| 4659 | free(curproxy->defbe.name); |
| 4660 | curproxy->defbe.be = target; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 4661 | /* we force the backend to be present on at least all of |
| 4662 | * the frontend's processes. |
| 4663 | */ |
| 4664 | target->bind_proc = curproxy->bind_proc ? |
| 4665 | (target->bind_proc | curproxy->bind_proc) : 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4666 | } |
| 4667 | } |
| 4668 | |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 4669 | /* find the target proxy in setbe */ |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 4670 | if (curproxy->mode == PR_MODE_HTTP && curproxy->req_exp != NULL) { |
| 4671 | /* map jump target for ACT_SETBE in req_rep chain */ |
| 4672 | struct hdr_exp *exp; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 4673 | for (exp = curproxy->req_exp; exp != NULL; exp = exp->next) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 4674 | struct proxy *target; |
| 4675 | |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 4676 | if (exp->action != ACT_SETBE) |
| 4677 | continue; |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 4678 | |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 4679 | target = findproxy_mode(exp->replace, PR_MODE_HTTP, PR_CAP_BE); |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 4680 | if (!target) { |
| 4681 | Alert("Proxy '%s': unable to find required setbe: '%s'.\n", |
| 4682 | curproxy->id, exp->replace); |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 4683 | cfgerr++; |
| 4684 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 4685 | Alert("Proxy '%s': loop detected for setbe: '%s'.\n", |
| 4686 | curproxy->id, exp->replace); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4687 | cfgerr++; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 4688 | } else { |
| 4689 | free((void *)exp->replace); |
| 4690 | exp->replace = (const char *)target; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 4691 | /* we force the backend to be present on at least all of |
| 4692 | * the frontend's processes. |
| 4693 | */ |
| 4694 | target->bind_proc = curproxy->bind_proc ? |
| 4695 | (target->bind_proc | curproxy->bind_proc) : 0; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 4696 | } |
| 4697 | } |
| 4698 | } |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 4699 | |
| 4700 | /* find the target proxy for 'use_backend' rules */ |
| 4701 | list_for_each_entry(rule, &curproxy->switching_rules, list) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 4702 | struct proxy *target; |
| 4703 | |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 4704 | target = findproxy_mode(rule->be.name, curproxy->mode, PR_CAP_BE); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 4705 | |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 4706 | if (!target) { |
| 4707 | Alert("Proxy '%s': unable to find required use_backend: '%s'.\n", |
| 4708 | curproxy->id, rule->be.name); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 4709 | cfgerr++; |
| 4710 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 4711 | Alert("Proxy '%s': loop detected for use_backend: '%s'.\n", |
| 4712 | curproxy->id, rule->be.name); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 4713 | cfgerr++; |
| 4714 | } else { |
| 4715 | free((void *)rule->be.name); |
| 4716 | rule->be.backend = target; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 4717 | /* we force the backend to be present on at least all of |
| 4718 | * the frontend's processes. |
| 4719 | */ |
| 4720 | target->bind_proc = curproxy->bind_proc ? |
| 4721 | (target->bind_proc | curproxy->bind_proc) : 0; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 4722 | } |
| 4723 | } |
| 4724 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4725 | /* find the target table for 'stick' rules */ |
| 4726 | list_for_each_entry(mrule, &curproxy->sticking_rules, list) { |
| 4727 | struct proxy *target; |
| 4728 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 4729 | curproxy->be_req_ana |= AN_REQ_STICKING_RULES; |
| 4730 | if (mrule->flags & STK_IS_STORE) |
| 4731 | curproxy->be_rsp_ana |= AN_RES_STORE_RULES; |
| 4732 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4733 | if (mrule->table.name) |
| 4734 | target = findproxy(mrule->table.name, PR_CAP_BE); |
| 4735 | else |
| 4736 | target = curproxy; |
| 4737 | |
| 4738 | if (!target) { |
| 4739 | Alert("Proxy '%s': unable to find stick-table '%s'.\n", |
| 4740 | curproxy->id, mrule->table.name); |
| 4741 | cfgerr++; |
| 4742 | } |
| 4743 | else if (target->table.size == 0) { |
| 4744 | Alert("Proxy '%s': stick-table '%s' used but not configured.\n", |
| 4745 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 4746 | cfgerr++; |
| 4747 | } |
| 4748 | else if (pattern_notusable_key(mrule->expr, target->table.type)) { |
| 4749 | Alert("Proxy '%s': type of pattern not usable with type of stick-table '%s'.\n", |
| 4750 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 4751 | cfgerr++; |
| 4752 | } |
| 4753 | else { |
| 4754 | free((void *)mrule->table.name); |
| 4755 | mrule->table.t = &(target->table); |
| 4756 | } |
| 4757 | } |
| 4758 | |
| 4759 | /* find the target table for 'store response' rules */ |
| 4760 | list_for_each_entry(mrule, &curproxy->storersp_rules, list) { |
| 4761 | struct proxy *target; |
| 4762 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 4763 | curproxy->be_rsp_ana |= AN_RES_STORE_RULES; |
| 4764 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4765 | if (mrule->table.name) |
| 4766 | target = findproxy(mrule->table.name, PR_CAP_BE); |
| 4767 | else |
| 4768 | target = curproxy; |
| 4769 | |
| 4770 | if (!target) { |
| 4771 | Alert("Proxy '%s': unable to find store table '%s'.\n", |
| 4772 | curproxy->id, mrule->table.name); |
| 4773 | cfgerr++; |
| 4774 | } |
| 4775 | else if (target->table.size == 0) { |
| 4776 | Alert("Proxy '%s': stick-table '%s' used but not configured.\n", |
| 4777 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 4778 | cfgerr++; |
| 4779 | } |
| 4780 | else if (pattern_notusable_key(mrule->expr, target->table.type)) { |
| 4781 | Alert("Proxy '%s': type of pattern not usable with type of stick-table '%s'.\n", |
| 4782 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 4783 | cfgerr++; |
| 4784 | } |
| 4785 | else { |
| 4786 | free((void *)mrule->table.name); |
| 4787 | mrule->table.t = &(target->table); |
| 4788 | } |
| 4789 | } |
| 4790 | |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 4791 | if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) && |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 4792 | (((curproxy->cap & PR_CAP_FE) && !curproxy->timeout.client) || |
Willy Tarreau | d825eef | 2007-05-12 22:35:00 +0200 | [diff] [blame] | 4793 | ((curproxy->cap & PR_CAP_BE) && (curproxy->srv) && |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 4794 | (!curproxy->timeout.connect || !curproxy->timeout.server)))) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 4795 | Warning("config : missing timeouts for %s '%s'.\n" |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 4796 | " | While not properly invalid, you will certainly encounter various problems\n" |
| 4797 | " | 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] | 4798 | " | timeouts are set to a non-zero value: 'client', 'connect', 'server'.\n", |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 4799 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 4800 | err_code |= ERR_WARN; |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 4801 | } |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 4802 | |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 4803 | /* Historically, the tarpit and queue timeouts were inherited from contimeout. |
| 4804 | * We must still support older configurations, so let's find out whether those |
| 4805 | * parameters have been set or must be copied from contimeouts. |
| 4806 | */ |
| 4807 | if (curproxy != &defproxy) { |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 4808 | if (!curproxy->timeout.tarpit || |
| 4809 | curproxy->timeout.tarpit == defproxy.timeout.tarpit) { |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 4810 | /* tarpit timeout not set. We search in the following order: |
| 4811 | * default.tarpit, curr.connect, default.connect. |
| 4812 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 4813 | if (defproxy.timeout.tarpit) |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 4814 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 4815 | else if (curproxy->timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 4816 | curproxy->timeout.tarpit = curproxy->timeout.connect; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 4817 | else if (defproxy.timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 4818 | curproxy->timeout.tarpit = defproxy.timeout.connect; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 4819 | } |
| 4820 | if ((curproxy->cap & PR_CAP_BE) && |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 4821 | (!curproxy->timeout.queue || |
| 4822 | curproxy->timeout.queue == defproxy.timeout.queue)) { |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 4823 | /* queue timeout not set. We search in the following order: |
| 4824 | * default.queue, curr.connect, default.connect. |
| 4825 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 4826 | if (defproxy.timeout.queue) |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 4827 | curproxy->timeout.queue = defproxy.timeout.queue; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 4828 | else if (curproxy->timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 4829 | curproxy->timeout.queue = curproxy->timeout.connect; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 4830 | else if (defproxy.timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 4831 | curproxy->timeout.queue = defproxy.timeout.connect; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 4832 | } |
| 4833 | } |
| 4834 | |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 4835 | if (curproxy->options & PR_O_SSL3_CHK) { |
| 4836 | curproxy->check_len = sizeof(sslv3_client_hello_pkt); |
| 4837 | curproxy->check_req = (char *)malloc(sizeof(sslv3_client_hello_pkt)); |
| 4838 | memcpy(curproxy->check_req, sslv3_client_hello_pkt, sizeof(sslv3_client_hello_pkt)); |
| 4839 | } |
| 4840 | |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 4841 | /* The small pools required for the capture lists */ |
| 4842 | if (curproxy->nb_req_cap) |
| 4843 | curproxy->req_cap_pool = create_pool("ptrcap", |
| 4844 | curproxy->nb_req_cap * sizeof(char *), |
| 4845 | MEM_F_SHARED); |
| 4846 | if (curproxy->nb_rsp_cap) |
| 4847 | curproxy->rsp_cap_pool = create_pool("ptrcap", |
| 4848 | curproxy->nb_rsp_cap * sizeof(char *), |
| 4849 | MEM_F_SHARED); |
| 4850 | |
Willy Tarreau | 1d4154a | 2007-05-13 22:57:02 +0200 | [diff] [blame] | 4851 | curproxy->hdr_idx_pool = create_pool("hdr_idx", |
| 4852 | MAX_HTTP_HDR * sizeof(struct hdr_idx_elem), |
| 4853 | MEM_F_SHARED); |
| 4854 | |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 4855 | /* for backwards compatibility with "listen" instances, if |
| 4856 | * fullconn is not set but maxconn is set, then maxconn |
| 4857 | * is used. |
| 4858 | */ |
| 4859 | if (!curproxy->fullconn) |
| 4860 | curproxy->fullconn = curproxy->maxconn; |
| 4861 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4862 | /* first, we will invert the servers list order */ |
| 4863 | newsrv = NULL; |
| 4864 | while (curproxy->srv) { |
| 4865 | struct server *next; |
| 4866 | |
| 4867 | next = curproxy->srv->next; |
| 4868 | curproxy->srv->next = newsrv; |
| 4869 | newsrv = curproxy->srv; |
| 4870 | if (!next) |
| 4871 | break; |
| 4872 | curproxy->srv = next; |
| 4873 | } |
| 4874 | |
Willy Tarreau | 2069704 | 2007-11-15 23:26:18 +0100 | [diff] [blame] | 4875 | curproxy->lbprm.wmult = 1; /* default weight multiplier */ |
Willy Tarreau | 5dc2fa6 | 2007-11-19 19:10:18 +0100 | [diff] [blame] | 4876 | curproxy->lbprm.wdiv = 1; /* default weight divider */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4877 | |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 4878 | /* We have to initialize the server lookup mechanism depending |
| 4879 | * on what LB algorithm was choosen. |
| 4880 | */ |
| 4881 | |
| 4882 | curproxy->lbprm.algo &= ~(BE_LB_LKUP | BE_LB_PROP_DYN); |
| 4883 | switch (curproxy->lbprm.algo & BE_LB_KIND) { |
| 4884 | case BE_LB_KIND_RR: |
Willy Tarreau | 9757a38 | 2009-10-03 12:56:50 +0200 | [diff] [blame] | 4885 | if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_RR_STATIC) { |
| 4886 | curproxy->lbprm.algo |= BE_LB_LKUP_MAP; |
| 4887 | init_server_map(curproxy); |
| 4888 | } else { |
| 4889 | curproxy->lbprm.algo |= BE_LB_LKUP_RRTREE | BE_LB_PROP_DYN; |
| 4890 | fwrr_init_server_groups(curproxy); |
| 4891 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 4892 | break; |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 4893 | |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 4894 | case BE_LB_KIND_LC: |
| 4895 | curproxy->lbprm.algo |= BE_LB_LKUP_LCTREE | BE_LB_PROP_DYN; |
Willy Tarreau | 5140623 | 2008-03-10 22:04:20 +0100 | [diff] [blame] | 4896 | fwlc_init_server_tree(curproxy); |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 4897 | break; |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 4898 | |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 4899 | case BE_LB_KIND_HI: |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 4900 | if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS) { |
| 4901 | curproxy->lbprm.algo |= BE_LB_LKUP_CHTREE | BE_LB_PROP_DYN; |
| 4902 | chash_init_server_tree(curproxy); |
| 4903 | } else { |
| 4904 | curproxy->lbprm.algo |= BE_LB_LKUP_MAP; |
| 4905 | init_server_map(curproxy); |
| 4906 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 4907 | break; |
| 4908 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4909 | |
| 4910 | if (curproxy->options & PR_O_LOGASAP) |
| 4911 | curproxy->to_log &= ~LW_BYTES; |
| 4912 | |
Willy Tarreau | e7ded1f | 2009-08-09 10:11:45 +0200 | [diff] [blame] | 4913 | if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) && |
| 4914 | (curproxy->cap & PR_CAP_FE) && curproxy->to_log && curproxy->logfac1 < 0) { |
| 4915 | Warning("config : log format ignored for %s '%s' since it has no log address.\n", |
| 4916 | proxy_type_str(curproxy), curproxy->id); |
| 4917 | err_code |= ERR_WARN; |
| 4918 | } |
| 4919 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4920 | /* |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 4921 | * ensure that we're not cross-dressing a TCP server into HTTP. |
| 4922 | */ |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 4923 | next_id = 1; |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 4924 | newsrv = curproxy->srv; |
| 4925 | while (newsrv != NULL) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 4926 | if (!newsrv->puid) { |
| 4927 | /* server ID not set, use automatic numbering with first |
| 4928 | * spare entry starting with next_svid. |
| 4929 | */ |
| 4930 | next_id = get_next_id(&curproxy->conf.used_server_id, next_id); |
| 4931 | newsrv->conf.id.key = newsrv->puid = next_id; |
| 4932 | eb32_insert(&curproxy->conf.used_server_id, &newsrv->conf.id); |
| 4933 | next_id++; |
| 4934 | } |
| 4935 | |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 4936 | if ((curproxy->mode != PR_MODE_HTTP) && (newsrv->rdr_len || newsrv->cklen)) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 4937 | Alert("config : %s '%s' : server cannot have cookie or redirect prefix in non-HTTP mode.\n", |
| 4938 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 4939 | cfgerr++; |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 4940 | } |
| 4941 | newsrv = newsrv->next; |
| 4942 | } |
| 4943 | |
| 4944 | /* |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4945 | * If this server supports a maxconn parameter, it needs a dedicated |
| 4946 | * tasks to fill the emptied slots when a connection leaves. |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4947 | * Also, resolve deferred tracking dependency if needed. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4948 | */ |
| 4949 | newsrv = curproxy->srv; |
| 4950 | while (newsrv != NULL) { |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 4951 | if (newsrv->minconn > newsrv->maxconn) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4952 | /* Only 'minconn' was specified, or it was higher than or equal |
| 4953 | * to 'maxconn'. Let's turn this into maxconn and clean it, as |
| 4954 | * this will avoid further useless expensive computations. |
| 4955 | */ |
| 4956 | newsrv->maxconn = newsrv->minconn; |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 4957 | } else if (newsrv->maxconn && !newsrv->minconn) { |
| 4958 | /* minconn was not specified, so we set it to maxconn */ |
| 4959 | newsrv->minconn = newsrv->maxconn; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4960 | } else if (newsrv->minconn != newsrv->maxconn && !curproxy->fullconn) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 4961 | Alert("config : %s '%s' : fullconn is mandatory when minconn is set on a server.\n", |
| 4962 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 4963 | cfgerr++; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4964 | } |
| 4965 | |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4966 | if (newsrv->trackit) { |
| 4967 | struct proxy *px; |
| 4968 | struct server *srv; |
| 4969 | char *pname, *sname; |
| 4970 | |
| 4971 | pname = newsrv->trackit; |
| 4972 | sname = strrchr(pname, '/'); |
| 4973 | |
| 4974 | if (sname) |
| 4975 | *sname++ = '\0'; |
| 4976 | else { |
| 4977 | sname = pname; |
| 4978 | pname = NULL; |
| 4979 | } |
| 4980 | |
| 4981 | if (pname) { |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 4982 | px = findproxy(pname, PR_CAP_BE); |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4983 | if (!px) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 4984 | Alert("config : %s '%s', server '%s': unable to find required proxy '%s' for tracking.\n", |
| 4985 | proxy_type_str(curproxy), curproxy->id, |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4986 | newsrv->id, pname); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 4987 | cfgerr++; |
| 4988 | goto next_srv; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4989 | } |
| 4990 | } else |
| 4991 | px = curproxy; |
| 4992 | |
| 4993 | srv = findserver(px, sname); |
| 4994 | if (!srv) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 4995 | Alert("config : %s '%s', server '%s': unable to find required server '%s' for tracking.\n", |
| 4996 | proxy_type_str(curproxy), curproxy->id, |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4997 | newsrv->id, sname); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 4998 | cfgerr++; |
| 4999 | goto next_srv; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 5000 | } |
| 5001 | |
| 5002 | if (!(srv->state & SRV_CHECKED)) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5003 | Alert("config : %s '%s', server '%s': unable to use %s/%s for " |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 5004 | "tracking as it does not have checks enabled.\n", |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5005 | proxy_type_str(curproxy), curproxy->id, |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 5006 | newsrv->id, px->id, srv->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 5007 | cfgerr++; |
| 5008 | goto next_srv; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 5009 | } |
| 5010 | |
| 5011 | if (curproxy != px && |
| 5012 | (curproxy->options & PR_O_DISABLE404) != (px->options & PR_O_DISABLE404)) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5013 | Alert("config : %s '%s', server '%s': unable to use %s/%s for" |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 5014 | "tracing: disable-on-404 option inconsistency.\n", |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5015 | proxy_type_str(curproxy), curproxy->id, |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 5016 | newsrv->id, px->id, srv->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 5017 | cfgerr++; |
| 5018 | goto next_srv; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 5019 | } |
| 5020 | |
| 5021 | newsrv->tracked = srv; |
| 5022 | newsrv->tracknext = srv->tracknext; |
| 5023 | srv->tracknext = newsrv; |
| 5024 | |
| 5025 | free(newsrv->trackit); |
| 5026 | } |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 5027 | next_srv: |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5028 | newsrv = newsrv->next; |
| 5029 | } |
| 5030 | |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 5031 | if (curproxy->cap & PR_CAP_FE) { |
| 5032 | if (curproxy->tcp_req.inspect_delay || |
| 5033 | !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules)) |
| 5034 | curproxy->fe_req_ana |= AN_REQ_INSPECT; |
| 5035 | |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 5036 | if (curproxy->mode == PR_MODE_HTTP) { |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 5037 | 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] | 5038 | 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] | 5039 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 5040 | |
| 5041 | /* both TCP and HTTP must check switching rules */ |
| 5042 | curproxy->fe_req_ana |= AN_REQ_SWITCHING_RULES; |
| 5043 | } |
| 5044 | |
| 5045 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 5046 | if (curproxy->mode == PR_MODE_HTTP) { |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 5047 | 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] | 5048 | 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] | 5049 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 5050 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5051 | /* init table on backend capabilities proxy */ |
| 5052 | stktable_init(&curproxy->table); |
| 5053 | |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 5054 | /* If the backend does requires RDP cookie persistence, we have to |
| 5055 | * enable the corresponding analyser. |
| 5056 | */ |
| 5057 | if (curproxy->options2 & PR_O2_RDPC_PRST) |
| 5058 | curproxy->be_req_ana |= AN_REQ_PRST_RDP_COOKIE; |
| 5059 | } |
| 5060 | |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 5061 | listener = NULL; |
| 5062 | while (curproxy->listen) { |
| 5063 | struct listener *next; |
| 5064 | |
| 5065 | next = curproxy->listen->next; |
| 5066 | curproxy->listen->next = listener; |
| 5067 | listener = curproxy->listen; |
| 5068 | |
| 5069 | if (!next) |
| 5070 | break; |
| 5071 | |
| 5072 | curproxy->listen = next; |
| 5073 | } |
| 5074 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 5075 | /* adjust this proxy's listeners */ |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 5076 | next_id = 1; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 5077 | listener = curproxy->listen; |
| 5078 | while (listener) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 5079 | if (!listener->luid) { |
| 5080 | /* listener ID not set, use automatic numbering with first |
| 5081 | * spare entry starting with next_luid. |
| 5082 | */ |
| 5083 | next_id = get_next_id(&curproxy->conf.used_listener_id, next_id); |
| 5084 | listener->conf.id.key = listener->luid = next_id; |
| 5085 | eb32_insert(&curproxy->conf.used_listener_id, &listener->conf.id); |
| 5086 | next_id++; |
| 5087 | } |
| 5088 | |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 5089 | /* enable separate counters */ |
| 5090 | if (curproxy->options2 & PR_O2_SOCKSTAT) { |
| 5091 | listener->counters = (struct licounters *)calloc(1, sizeof(struct licounters)); |
| 5092 | if (!listener->name) { |
| 5093 | sprintf(trash, "sock-%d", listener->luid); |
| 5094 | listener->name = strdup(trash); |
| 5095 | } |
| 5096 | } |
| 5097 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 5098 | if (curproxy->options & PR_O_TCP_NOLING) |
| 5099 | listener->options |= LI_O_NOLINGER; |
| 5100 | listener->maxconn = curproxy->maxconn; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 5101 | listener->backlog = curproxy->backlog; |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 5102 | listener->timeout = &curproxy->timeout.client; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 5103 | listener->accept = event_accept; |
| 5104 | listener->private = curproxy; |
Willy Tarreau | 3bc1377 | 2008-12-07 11:50:35 +0100 | [diff] [blame] | 5105 | listener->handler = process_session; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 5106 | listener->analysers |= curproxy->fe_req_ana; |
Willy Tarreau | 3bc1377 | 2008-12-07 11:50:35 +0100 | [diff] [blame] | 5107 | |
Willy Tarreau | 9ea05a7 | 2009-06-14 12:07:01 +0200 | [diff] [blame] | 5108 | /* smart accept mode is automatic in HTTP mode */ |
| 5109 | if ((curproxy->options2 & PR_O2_SMARTACC) || |
| 5110 | (curproxy->mode == PR_MODE_HTTP && |
| 5111 | !(curproxy->no_options2 & PR_O2_SMARTACC))) |
| 5112 | listener->options |= LI_O_NOQUICKACK; |
| 5113 | |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 5114 | /* We want the use_backend and default_backend rules to apply */ |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 5115 | listener = listener->next; |
| 5116 | } |
| 5117 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5118 | curproxy = curproxy->next; |
| 5119 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5120 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5121 | /* |
| 5122 | * Recount currently required checks. |
| 5123 | */ |
| 5124 | |
| 5125 | for (curproxy=proxy; curproxy; curproxy=curproxy->next) { |
| 5126 | int optnum; |
| 5127 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 5128 | for (optnum = 0; cfg_opts[optnum].name; optnum++) |
| 5129 | if (curproxy->options & cfg_opts[optnum].val) |
| 5130 | global.last_checks |= cfg_opts[optnum].checks; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5131 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 5132 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) |
| 5133 | if (curproxy->options2 & cfg_opts2[optnum].val) |
| 5134 | global.last_checks |= cfg_opts2[optnum].checks; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5135 | } |
| 5136 | |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 5137 | if (cfgerr > 0) |
| 5138 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5139 | out: |
| 5140 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5141 | } |
| 5142 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 5143 | /* |
| 5144 | * Registers the CFG keyword list <kwl> as a list of valid keywords for next |
| 5145 | * parsing sessions. |
| 5146 | */ |
| 5147 | void cfg_register_keywords(struct cfg_kw_list *kwl) |
| 5148 | { |
| 5149 | LIST_ADDQ(&cfg_keywords.list, &kwl->list); |
| 5150 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5151 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 5152 | /* |
| 5153 | * Unregisters the CFG keyword list <kwl> from the list of valid keywords. |
| 5154 | */ |
| 5155 | void cfg_unregister_keywords(struct cfg_kw_list *kwl) |
| 5156 | { |
| 5157 | LIST_DEL(&kwl->list); |
| 5158 | LIST_INIT(&kwl->list); |
| 5159 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5160 | |
| 5161 | /* |
| 5162 | * Local variables: |
| 5163 | * c-indent-level: 8 |
| 5164 | * c-basic-offset: 8 |
| 5165 | * End: |
| 5166 | */ |