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