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