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 | 0f03c6f | 2007-03-25 20:46:19 +0200 | [diff] [blame] | 1200 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1201 | cur_arg = 3; |
| 1202 | while (*args[cur_arg]) { |
| 1203 | if (!strcmp(args[cur_arg], "cookie")) { |
| 1204 | newsrv->cookie = strdup(args[cur_arg + 1]); |
| 1205 | newsrv->cklen = strlen(args[cur_arg + 1]); |
| 1206 | cur_arg += 2; |
| 1207 | } |
| 1208 | else if (!strcmp(args[cur_arg], "rise")) { |
| 1209 | newsrv->rise = atol(args[cur_arg + 1]); |
| 1210 | newsrv->health = newsrv->rise; |
| 1211 | cur_arg += 2; |
| 1212 | } |
| 1213 | else if (!strcmp(args[cur_arg], "fall")) { |
| 1214 | newsrv->fall = atol(args[cur_arg + 1]); |
| 1215 | cur_arg += 2; |
| 1216 | } |
| 1217 | else if (!strcmp(args[cur_arg], "inter")) { |
| 1218 | newsrv->inter = atol(args[cur_arg + 1]); |
| 1219 | cur_arg += 2; |
| 1220 | } |
Willy Tarreau | 2ea3abb | 2007-03-25 16:45:16 +0200 | [diff] [blame] | 1221 | else if (!strcmp(args[cur_arg], "addr")) { |
| 1222 | newsrv->check_addr = *str2sa(args[cur_arg + 1]); |
Willy Tarreau | 2ea3abb | 2007-03-25 16:45:16 +0200 | [diff] [blame] | 1223 | cur_arg += 2; |
| 1224 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1225 | else if (!strcmp(args[cur_arg], "port")) { |
| 1226 | newsrv->check_port = atol(args[cur_arg + 1]); |
| 1227 | cur_arg += 2; |
| 1228 | } |
| 1229 | else if (!strcmp(args[cur_arg], "backup")) { |
| 1230 | newsrv->state |= SRV_BACKUP; |
| 1231 | cur_arg ++; |
| 1232 | } |
| 1233 | else if (!strcmp(args[cur_arg], "weight")) { |
| 1234 | int w; |
| 1235 | w = atol(args[cur_arg + 1]); |
| 1236 | if (w < 1 || w > 256) { |
| 1237 | Alert("parsing [%s:%d] : weight of server %s is not within 1 and 256 (%d).\n", |
| 1238 | file, linenum, newsrv->id, w); |
| 1239 | return -1; |
| 1240 | } |
| 1241 | newsrv->uweight = w - 1; |
| 1242 | cur_arg += 2; |
| 1243 | } |
| 1244 | else if (!strcmp(args[cur_arg], "minconn")) { |
| 1245 | newsrv->minconn = atol(args[cur_arg + 1]); |
| 1246 | cur_arg += 2; |
| 1247 | } |
| 1248 | else if (!strcmp(args[cur_arg], "maxconn")) { |
| 1249 | newsrv->maxconn = atol(args[cur_arg + 1]); |
| 1250 | cur_arg += 2; |
| 1251 | } |
| 1252 | else if (!strcmp(args[cur_arg], "check")) { |
| 1253 | global.maxsock++; |
| 1254 | do_check = 1; |
| 1255 | cur_arg += 1; |
| 1256 | } |
| 1257 | else if (!strcmp(args[cur_arg], "source")) { /* address to which we bind when connecting */ |
| 1258 | if (!*args[cur_arg + 1]) { |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 1259 | #ifdef CONFIG_HAP_CTTPROXY |
| 1260 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optional '%s' <addr> as argument.\n", |
| 1261 | file, linenum, "source", "usesrc"); |
| 1262 | #else |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1263 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>] as argument.\n", |
| 1264 | file, linenum, "source"); |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 1265 | #endif |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1266 | return -1; |
| 1267 | } |
| 1268 | newsrv->state |= SRV_BIND_SRC; |
| 1269 | newsrv->source_addr = *str2sa(args[cur_arg + 1]); |
| 1270 | cur_arg += 2; |
Willy Tarreau | 77074d5 | 2006-11-12 23:57:19 +0100 | [diff] [blame] | 1271 | if (!strcmp(args[cur_arg], "usesrc")) { /* address to use outside */ |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 1272 | #ifdef CONFIG_HAP_CTTPROXY |
Willy Tarreau | 77074d5 | 2006-11-12 23:57:19 +0100 | [diff] [blame] | 1273 | if (newsrv->source_addr.sin_addr.s_addr == INADDR_ANY) { |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 1274 | Alert("parsing [%s:%d] : '%s' requires an explicit '%s' address.\n", |
| 1275 | file, linenum, "usesrc", "source"); |
Willy Tarreau | 77074d5 | 2006-11-12 23:57:19 +0100 | [diff] [blame] | 1276 | return -1; |
| 1277 | } |
| 1278 | if (!*args[cur_arg + 1]) { |
| 1279 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n", |
| 1280 | file, linenum, "usesrc"); |
| 1281 | return -1; |
| 1282 | } |
| 1283 | if (!strcmp(args[cur_arg + 1], "client")) { |
| 1284 | newsrv->state |= SRV_TPROXY_CLI; |
| 1285 | } else if (!strcmp(args[cur_arg + 1], "clientip")) { |
| 1286 | newsrv->state |= SRV_TPROXY_CIP; |
| 1287 | } else { |
| 1288 | newsrv->state |= SRV_TPROXY_ADDR; |
| 1289 | newsrv->tproxy_addr = *str2sa(args[cur_arg + 1]); |
| 1290 | } |
| 1291 | global.last_checks |= LSTCHK_CTTPROXY | LSTCHK_NETADM; |
| 1292 | cur_arg += 2; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 1293 | #else /* no CTTPROXY support */ |
| 1294 | Alert("parsing [%s:%d] : '%s' not allowed here because support for cttproxy was not compiled in.\n", |
| 1295 | file, linenum, "usesrc"); |
| 1296 | return -1; |
Willy Tarreau | 77074d5 | 2006-11-12 23:57:19 +0100 | [diff] [blame] | 1297 | #endif |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 1298 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1299 | } |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 1300 | #ifdef CONFIG_HAP_CTTPROXY |
| 1301 | else if (!strcmp(args[cur_arg], "usesrc")) { /* address to use outside: needs "source" first */ |
| 1302 | Alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n", |
| 1303 | file, linenum, "usesrc", "source"); |
| 1304 | return -1; |
| 1305 | } |
| 1306 | #endif |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1307 | else { |
Willy Tarreau | 0f03c6f | 2007-03-25 20:46:19 +0200 | [diff] [blame] | 1308 | 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] | 1309 | file, linenum, newsrv->id); |
| 1310 | return -1; |
| 1311 | } |
| 1312 | } |
| 1313 | |
| 1314 | if (do_check) { |
Willy Tarreau | 0f03c6f | 2007-03-25 20:46:19 +0200 | [diff] [blame] | 1315 | if (!newsrv->check_port && newsrv->check_addr.sin_port) |
| 1316 | newsrv->check_port = newsrv->check_addr.sin_port; |
| 1317 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1318 | if (!newsrv->check_port && !(newsrv->state & SRV_MAPPORTS)) |
| 1319 | newsrv->check_port = realport; /* by default */ |
| 1320 | if (!newsrv->check_port) { |
Willy Tarreau | ef00b50 | 2007-01-07 02:40:09 +0100 | [diff] [blame] | 1321 | /* not yet valid, because no port was set on |
| 1322 | * the server either. We'll check if we have |
| 1323 | * a known port on the first listener. |
| 1324 | */ |
| 1325 | struct listener *l; |
| 1326 | l = curproxy->listen; |
| 1327 | if (l) { |
| 1328 | int port; |
| 1329 | port = (l->addr.ss_family == AF_INET6) |
| 1330 | ? ntohs(((struct sockaddr_in6 *)(&l->addr))->sin6_port) |
| 1331 | : ntohs(((struct sockaddr_in *)(&l->addr))->sin_port); |
| 1332 | newsrv->check_port = port; |
| 1333 | } |
| 1334 | } |
| 1335 | if (!newsrv->check_port) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1336 | Alert("parsing [%s:%d] : server %s has neither service port nor check port. Check has been disabled.\n", |
| 1337 | file, linenum, newsrv->id); |
| 1338 | return -1; |
| 1339 | } |
| 1340 | newsrv->state |= SRV_CHECKED; |
| 1341 | } |
| 1342 | |
| 1343 | if (newsrv->state & SRV_BACKUP) |
| 1344 | curproxy->srv_bck++; |
| 1345 | else |
| 1346 | curproxy->srv_act++; |
| 1347 | } |
| 1348 | else if (!strcmp(args[0], "log")) { /* syslog server address */ |
| 1349 | struct sockaddr_in *sa; |
| 1350 | int facility; |
| 1351 | |
| 1352 | if (*(args[1]) && *(args[2]) == 0 && !strcmp(args[1], "global")) { |
| 1353 | curproxy->logfac1 = global.logfac1; |
| 1354 | curproxy->logsrv1 = global.logsrv1; |
| 1355 | curproxy->loglev1 = global.loglev1; |
| 1356 | curproxy->logfac2 = global.logfac2; |
| 1357 | curproxy->logsrv2 = global.logsrv2; |
| 1358 | curproxy->loglev2 = global.loglev2; |
| 1359 | } |
| 1360 | else if (*(args[1]) && *(args[2])) { |
| 1361 | int level; |
| 1362 | |
| 1363 | facility = get_log_facility(args[2]); |
| 1364 | if (facility < 0) { |
| 1365 | Alert("parsing [%s:%d] : unknown log facility '%s'\n", file, linenum, args[2]); |
| 1366 | exit(1); |
| 1367 | } |
| 1368 | |
| 1369 | level = 7; /* max syslog level = debug */ |
| 1370 | if (*(args[3])) { |
| 1371 | level = get_log_level(args[3]); |
| 1372 | if (level < 0) { |
| 1373 | Alert("parsing [%s:%d] : unknown optional log level '%s'\n", file, linenum, args[3]); |
| 1374 | exit(1); |
| 1375 | } |
| 1376 | } |
| 1377 | |
| 1378 | sa = str2sa(args[1]); |
| 1379 | if (!sa->sin_port) |
| 1380 | sa->sin_port = htons(SYSLOG_PORT); |
| 1381 | |
| 1382 | if (curproxy->logfac1 == -1) { |
| 1383 | curproxy->logsrv1 = *sa; |
| 1384 | curproxy->logfac1 = facility; |
| 1385 | curproxy->loglev1 = level; |
| 1386 | } |
| 1387 | else if (curproxy->logfac2 == -1) { |
| 1388 | curproxy->logsrv2 = *sa; |
| 1389 | curproxy->logfac2 = facility; |
| 1390 | curproxy->loglev2 = level; |
| 1391 | } |
| 1392 | else { |
| 1393 | Alert("parsing [%s:%d] : too many syslog servers\n", file, linenum); |
| 1394 | return -1; |
| 1395 | } |
| 1396 | } |
| 1397 | else { |
| 1398 | Alert("parsing [%s:%d] : 'log' expects either <address[:port]> and <facility> or 'global' as arguments.\n", |
| 1399 | file, linenum); |
| 1400 | return -1; |
| 1401 | } |
| 1402 | } |
| 1403 | 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] | 1404 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 1405 | return 0; |
| 1406 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1407 | if (!*args[1]) { |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 1408 | #ifdef CONFIG_HAP_CTTPROXY |
| 1409 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optional '%s' <addr> as argument.\n", |
| 1410 | file, linenum, "source", "usesrc"); |
| 1411 | #else |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1412 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>] as argument.\n", |
| 1413 | file, linenum, "source"); |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 1414 | #endif |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1415 | return -1; |
| 1416 | } |
| 1417 | |
| 1418 | curproxy->source_addr = *str2sa(args[1]); |
| 1419 | curproxy->options |= PR_O_BIND_SRC; |
Willy Tarreau | 77074d5 | 2006-11-12 23:57:19 +0100 | [diff] [blame] | 1420 | if (!strcmp(args[2], "usesrc")) { /* address to use outside */ |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 1421 | #ifdef CONFIG_HAP_CTTPROXY |
Willy Tarreau | 77074d5 | 2006-11-12 23:57:19 +0100 | [diff] [blame] | 1422 | if (curproxy->source_addr.sin_addr.s_addr == INADDR_ANY) { |
| 1423 | Alert("parsing [%s:%d] : '%s' requires an explicit 'source' address.\n", |
| 1424 | file, linenum, "usesrc"); |
| 1425 | return -1; |
| 1426 | } |
| 1427 | if (!*args[3]) { |
| 1428 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n", |
| 1429 | file, linenum, "usesrc"); |
| 1430 | return -1; |
| 1431 | } |
| 1432 | |
| 1433 | if (!strcmp(args[3], "client")) { |
| 1434 | curproxy->options |= PR_O_TPXY_CLI; |
| 1435 | } else if (!strcmp(args[3], "clientip")) { |
| 1436 | curproxy->options |= PR_O_TPXY_CIP; |
| 1437 | } else { |
| 1438 | curproxy->options |= PR_O_TPXY_ADDR; |
| 1439 | curproxy->tproxy_addr = *str2sa(args[3]); |
| 1440 | } |
| 1441 | global.last_checks |= LSTCHK_CTTPROXY | LSTCHK_NETADM; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 1442 | #else /* no CTTPROXY support */ |
| 1443 | Alert("parsing [%s:%d] : '%s' not allowed here because support for cttproxy was not compiled in.\n", |
| 1444 | file, linenum, "usesrc"); |
| 1445 | return -1; |
Willy Tarreau | 77074d5 | 2006-11-12 23:57:19 +0100 | [diff] [blame] | 1446 | #endif |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 1447 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1448 | } |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 1449 | #ifdef CONFIG_HAP_CTTPROXY |
| 1450 | else if (!strcmp(args[0], "usesrc")) { /* address to use outside: needs "source" first */ |
| 1451 | Alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n", |
| 1452 | file, linenum, "usesrc", "source"); |
| 1453 | return -1; |
| 1454 | } |
| 1455 | #endif |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1456 | else if (!strcmp(args[0], "cliexp") || !strcmp(args[0], "reqrep")) { /* replace request header from a regex */ |
| 1457 | regex_t *preg; |
| 1458 | if (curproxy == &defproxy) { |
| 1459 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 1460 | return -1; |
| 1461 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1462 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
| 1463 | return 0; |
| 1464 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1465 | if (*(args[1]) == 0 || *(args[2]) == 0) { |
| 1466 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 1467 | file, linenum, args[0]); |
| 1468 | return -1; |
| 1469 | } |
| 1470 | |
| 1471 | preg = calloc(1, sizeof(regex_t)); |
| 1472 | if (regcomp(preg, args[1], REG_EXTENDED) != 0) { |
| 1473 | Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]); |
| 1474 | return -1; |
| 1475 | } |
| 1476 | |
| 1477 | err = chain_regex(&curproxy->req_exp, preg, ACT_REPLACE, strdup(args[2])); |
| 1478 | if (err) { |
| 1479 | Alert("parsing [%s:%d] : invalid character or unterminated sequence in replacement string near '%c'.\n", |
| 1480 | file, linenum, *err); |
| 1481 | return -1; |
| 1482 | } |
| 1483 | } |
| 1484 | else if (!strcmp(args[0], "reqdel")) { /* delete request header from a regex */ |
| 1485 | regex_t *preg; |
| 1486 | if (curproxy == &defproxy) { |
| 1487 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 1488 | return -1; |
| 1489 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1490 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
| 1491 | return 0; |
| 1492 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1493 | if (*(args[1]) == 0) { |
| 1494 | Alert("parsing [%s:%d] : '%s' expects <regex> as an argument.\n", file, linenum, args[0]); |
| 1495 | return -1; |
| 1496 | } |
| 1497 | |
| 1498 | preg = calloc(1, sizeof(regex_t)); |
| 1499 | if (regcomp(preg, args[1], REG_EXTENDED) != 0) { |
| 1500 | Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]); |
| 1501 | return -1; |
| 1502 | } |
| 1503 | |
| 1504 | chain_regex(&curproxy->req_exp, preg, ACT_REMOVE, NULL); |
| 1505 | } |
| 1506 | else if (!strcmp(args[0], "reqdeny")) { /* deny a request if a header matches this regex */ |
| 1507 | regex_t *preg; |
| 1508 | if (curproxy == &defproxy) { |
| 1509 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 1510 | return -1; |
| 1511 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1512 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
| 1513 | return 0; |
| 1514 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1515 | if (*(args[1]) == 0) { |
| 1516 | Alert("parsing [%s:%d] : '%s' expects <regex> as an argument.\n", file, linenum, args[0]); |
| 1517 | return -1; |
| 1518 | } |
| 1519 | |
| 1520 | preg = calloc(1, sizeof(regex_t)); |
| 1521 | if (regcomp(preg, args[1], REG_EXTENDED) != 0) { |
| 1522 | Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]); |
| 1523 | return -1; |
| 1524 | } |
| 1525 | |
| 1526 | chain_regex(&curproxy->req_exp, preg, ACT_DENY, NULL); |
| 1527 | } |
| 1528 | else if (!strcmp(args[0], "reqpass")) { /* pass this header without allowing or denying the request */ |
| 1529 | regex_t *preg; |
| 1530 | if (curproxy == &defproxy) { |
| 1531 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 1532 | return -1; |
| 1533 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1534 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
| 1535 | return 0; |
| 1536 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1537 | if (*(args[1]) == 0) { |
| 1538 | Alert("parsing [%s:%d] : '%s' expects <regex> as an argument.\n", file, linenum, args[0]); |
| 1539 | return -1; |
| 1540 | } |
| 1541 | |
| 1542 | preg = calloc(1, sizeof(regex_t)); |
| 1543 | if (regcomp(preg, args[1], REG_EXTENDED) != 0) { |
| 1544 | Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]); |
| 1545 | return -1; |
| 1546 | } |
| 1547 | |
| 1548 | chain_regex(&curproxy->req_exp, preg, ACT_PASS, NULL); |
| 1549 | } |
| 1550 | else if (!strcmp(args[0], "reqallow")) { /* allow a request if a header matches this regex */ |
| 1551 | regex_t *preg; |
| 1552 | if (curproxy == &defproxy) { |
| 1553 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 1554 | return -1; |
| 1555 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1556 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
| 1557 | return 0; |
| 1558 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1559 | if (*(args[1]) == 0) { |
| 1560 | Alert("parsing [%s:%d] : '%s' expects <regex> as an argument.\n", file, linenum, args[0]); |
| 1561 | return -1; |
| 1562 | } |
| 1563 | |
| 1564 | preg = calloc(1, sizeof(regex_t)); |
| 1565 | if (regcomp(preg, args[1], REG_EXTENDED) != 0) { |
| 1566 | Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]); |
| 1567 | return -1; |
| 1568 | } |
| 1569 | |
| 1570 | chain_regex(&curproxy->req_exp, preg, ACT_ALLOW, NULL); |
| 1571 | } |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 1572 | else if (!strcmp(args[0], "reqtarpit")) { /* tarpit a request if a header matches this regex */ |
| 1573 | regex_t *preg; |
| 1574 | if (curproxy == &defproxy) { |
| 1575 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 1576 | return -1; |
| 1577 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1578 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
| 1579 | return 0; |
| 1580 | |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 1581 | if (*(args[1]) == 0) { |
| 1582 | Alert("parsing [%s:%d] : '%s' expects <regex> as an argument.\n", file, linenum, args[0]); |
| 1583 | return -1; |
| 1584 | } |
| 1585 | |
| 1586 | preg = calloc(1, sizeof(regex_t)); |
| 1587 | if (regcomp(preg, args[1], REG_EXTENDED) != 0) { |
| 1588 | Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]); |
| 1589 | return -1; |
| 1590 | } |
| 1591 | |
| 1592 | chain_regex(&curproxy->req_exp, preg, ACT_TARPIT, NULL); |
| 1593 | } |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 1594 | else if (!strcmp(args[0], "reqsetbe")) { /* switch the backend from a regex, respecting case */ |
| 1595 | regex_t *preg; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1596 | if (curproxy == &defproxy) { |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 1597 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 1598 | return -1; |
| 1599 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1600 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
| 1601 | return 0; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 1602 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1603 | if (*(args[1]) == 0 || *(args[2]) == 0) { |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 1604 | Alert("parsing [%s:%d] : '%s' expects <search> and <target> as arguments.\n", |
| 1605 | file, linenum, args[0]); |
| 1606 | return -1; |
| 1607 | } |
| 1608 | |
| 1609 | preg = calloc(1, sizeof(regex_t)); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1610 | if (regcomp(preg, args[1], REG_EXTENDED) != 0) { |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 1611 | Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]); |
| 1612 | } |
| 1613 | |
| 1614 | chain_regex(&curproxy->req_exp, preg, ACT_SETBE, strdup(args[2])); |
| 1615 | } |
| 1616 | else if (!strcmp(args[0], "reqisetbe")) { /* switch the backend from a regex, ignoring case */ |
| 1617 | regex_t *preg; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1618 | if (curproxy == &defproxy) { |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 1619 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 1620 | return -1; |
| 1621 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1622 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
| 1623 | return 0; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 1624 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1625 | if (*(args[1]) == 0 || *(args[2]) == 0) { |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 1626 | Alert("parsing [%s:%d] : '%s' expects <search> and <target> as arguments.\n", |
| 1627 | file, linenum, args[0]); |
| 1628 | return -1; |
| 1629 | } |
| 1630 | |
| 1631 | preg = calloc(1, sizeof(regex_t)); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1632 | if (regcomp(preg, args[1], REG_EXTENDED | REG_ICASE) != 0) { |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 1633 | Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]); |
| 1634 | } |
| 1635 | |
| 1636 | chain_regex(&curproxy->req_exp, preg, ACT_SETBE, strdup(args[2])); |
| 1637 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1638 | else if (!strcmp(args[0], "reqirep")) { /* replace request header from a regex, ignoring case */ |
| 1639 | regex_t *preg; |
| 1640 | if (curproxy == &defproxy) { |
| 1641 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 1642 | return -1; |
| 1643 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1644 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
| 1645 | return 0; |
| 1646 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1647 | if (*(args[1]) == 0 || *(args[2]) == 0) { |
| 1648 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 1649 | file, linenum, args[0]); |
| 1650 | return -1; |
| 1651 | } |
| 1652 | |
| 1653 | preg = calloc(1, sizeof(regex_t)); |
| 1654 | if (regcomp(preg, args[1], REG_EXTENDED | REG_ICASE) != 0) { |
| 1655 | Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]); |
| 1656 | return -1; |
| 1657 | } |
| 1658 | |
| 1659 | err = chain_regex(&curproxy->req_exp, preg, ACT_REPLACE, strdup(args[2])); |
| 1660 | if (err) { |
| 1661 | Alert("parsing [%s:%d] : invalid character or unterminated sequence in replacement string near '%c'.\n", |
| 1662 | file, linenum, *err); |
| 1663 | return -1; |
| 1664 | } |
| 1665 | } |
| 1666 | else if (!strcmp(args[0], "reqidel")) { /* delete request header from a regex ignoring case */ |
| 1667 | regex_t *preg; |
| 1668 | if (curproxy == &defproxy) { |
| 1669 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 1670 | return -1; |
| 1671 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1672 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
| 1673 | return 0; |
| 1674 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1675 | if (*(args[1]) == 0) { |
| 1676 | Alert("parsing [%s:%d] : '%s' expects <regex> as an argument.\n", file, linenum, args[0]); |
| 1677 | return -1; |
| 1678 | } |
| 1679 | |
| 1680 | preg = calloc(1, sizeof(regex_t)); |
| 1681 | if (regcomp(preg, args[1], REG_EXTENDED | REG_ICASE) != 0) { |
| 1682 | Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]); |
| 1683 | return -1; |
| 1684 | } |
| 1685 | |
| 1686 | chain_regex(&curproxy->req_exp, preg, ACT_REMOVE, NULL); |
| 1687 | } |
| 1688 | else if (!strcmp(args[0], "reqideny")) { /* deny a request if a header matches this regex ignoring case */ |
| 1689 | regex_t *preg; |
| 1690 | if (curproxy == &defproxy) { |
| 1691 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 1692 | return -1; |
| 1693 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1694 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
| 1695 | return 0; |
| 1696 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1697 | if (*(args[1]) == 0) { |
| 1698 | Alert("parsing [%s:%d] : '%s' expects <regex> as an argument.\n", file, linenum, args[0]); |
| 1699 | return -1; |
| 1700 | } |
| 1701 | |
| 1702 | preg = calloc(1, sizeof(regex_t)); |
| 1703 | if (regcomp(preg, args[1], REG_EXTENDED | REG_ICASE) != 0) { |
| 1704 | Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]); |
| 1705 | return -1; |
| 1706 | } |
| 1707 | |
| 1708 | chain_regex(&curproxy->req_exp, preg, ACT_DENY, NULL); |
| 1709 | } |
| 1710 | else if (!strcmp(args[0], "reqipass")) { /* pass this header without allowing or denying the request */ |
| 1711 | regex_t *preg; |
| 1712 | if (curproxy == &defproxy) { |
| 1713 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 1714 | return -1; |
| 1715 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1716 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
| 1717 | return 0; |
| 1718 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1719 | if (*(args[1]) == 0) { |
| 1720 | Alert("parsing [%s:%d] : '%s' expects <regex> as an argument.\n", file, linenum, args[0]); |
| 1721 | return -1; |
| 1722 | } |
| 1723 | |
| 1724 | preg = calloc(1, sizeof(regex_t)); |
| 1725 | if (regcomp(preg, args[1], REG_EXTENDED | REG_ICASE) != 0) { |
| 1726 | Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]); |
| 1727 | return -1; |
| 1728 | } |
| 1729 | |
| 1730 | chain_regex(&curproxy->req_exp, preg, ACT_PASS, NULL); |
| 1731 | } |
| 1732 | else if (!strcmp(args[0], "reqiallow")) { /* allow a request if a header matches this regex ignoring case */ |
| 1733 | regex_t *preg; |
| 1734 | if (curproxy == &defproxy) { |
| 1735 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 1736 | return -1; |
| 1737 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1738 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
| 1739 | return 0; |
| 1740 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1741 | if (*(args[1]) == 0) { |
| 1742 | Alert("parsing [%s:%d] : '%s' expects <regex> as an argument.\n", file, linenum, args[0]); |
| 1743 | return -1; |
| 1744 | } |
| 1745 | |
| 1746 | preg = calloc(1, sizeof(regex_t)); |
| 1747 | if (regcomp(preg, args[1], REG_EXTENDED | REG_ICASE) != 0) { |
| 1748 | Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]); |
| 1749 | return -1; |
| 1750 | } |
| 1751 | |
| 1752 | chain_regex(&curproxy->req_exp, preg, ACT_ALLOW, NULL); |
| 1753 | } |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 1754 | else if (!strcmp(args[0], "reqitarpit")) { /* tarpit a request if a header matches this regex ignoring case */ |
| 1755 | regex_t *preg; |
| 1756 | if (curproxy == &defproxy) { |
| 1757 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 1758 | return -1; |
| 1759 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1760 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
| 1761 | return 0; |
| 1762 | |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 1763 | if (*(args[1]) == 0) { |
| 1764 | Alert("parsing [%s:%d] : '%s' expects <regex> as an argument.\n", file, linenum, args[0]); |
| 1765 | return -1; |
| 1766 | } |
| 1767 | |
| 1768 | preg = calloc(1, sizeof(regex_t)); |
| 1769 | if (regcomp(preg, args[1], REG_EXTENDED | REG_ICASE) != 0) { |
| 1770 | Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]); |
| 1771 | return -1; |
| 1772 | } |
| 1773 | |
| 1774 | chain_regex(&curproxy->req_exp, preg, ACT_TARPIT, NULL); |
| 1775 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1776 | else if (!strcmp(args[0], "reqadd")) { /* add request header */ |
| 1777 | if (curproxy == &defproxy) { |
| 1778 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 1779 | return -1; |
| 1780 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1781 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
| 1782 | return 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1783 | |
| 1784 | if (curproxy->nb_reqadd >= MAX_NEWHDR) { |
| 1785 | Alert("parsing [%s:%d] : too many '%s'. Continuing.\n", file, linenum, args[0]); |
| 1786 | return 0; |
| 1787 | } |
| 1788 | |
| 1789 | if (*(args[1]) == 0) { |
| 1790 | Alert("parsing [%s:%d] : '%s' expects <header> as an argument.\n", file, linenum, args[0]); |
| 1791 | return -1; |
| 1792 | } |
| 1793 | |
| 1794 | curproxy->req_add[curproxy->nb_reqadd++] = strdup(args[1]); |
| 1795 | } |
| 1796 | else if (!strcmp(args[0], "srvexp") || !strcmp(args[0], "rsprep")) { /* replace response header from a regex */ |
| 1797 | regex_t *preg; |
| 1798 | |
| 1799 | if (*(args[1]) == 0 || *(args[2]) == 0) { |
| 1800 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 1801 | file, linenum, args[0]); |
| 1802 | return -1; |
| 1803 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1804 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
| 1805 | return 0; |
| 1806 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1807 | preg = calloc(1, sizeof(regex_t)); |
| 1808 | if (regcomp(preg, args[1], REG_EXTENDED) != 0) { |
| 1809 | Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]); |
| 1810 | return -1; |
| 1811 | } |
| 1812 | |
| 1813 | err = chain_regex(&curproxy->rsp_exp, preg, ACT_REPLACE, strdup(args[2])); |
| 1814 | if (err) { |
| 1815 | Alert("parsing [%s:%d] : invalid character or unterminated sequence in replacement string near '%c'.\n", |
| 1816 | file, linenum, *err); |
| 1817 | return -1; |
| 1818 | } |
| 1819 | } |
| 1820 | else if (!strcmp(args[0], "rspdel")) { /* delete response header from a regex */ |
| 1821 | regex_t *preg; |
| 1822 | if (curproxy == &defproxy) { |
| 1823 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 1824 | return -1; |
| 1825 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1826 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
| 1827 | return 0; |
| 1828 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1829 | if (*(args[1]) == 0) { |
| 1830 | Alert("parsing [%s:%d] : '%s' expects <search> as an argument.\n", file, linenum, args[0]); |
| 1831 | return -1; |
| 1832 | } |
| 1833 | |
| 1834 | preg = calloc(1, sizeof(regex_t)); |
| 1835 | if (regcomp(preg, args[1], REG_EXTENDED) != 0) { |
| 1836 | Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]); |
| 1837 | return -1; |
| 1838 | } |
| 1839 | |
| 1840 | err = chain_regex(&curproxy->rsp_exp, preg, ACT_REMOVE, strdup(args[2])); |
| 1841 | if (err) { |
| 1842 | Alert("parsing [%s:%d] : invalid character or unterminated sequence in replacement string near '%c'.\n", |
| 1843 | file, linenum, *err); |
| 1844 | return -1; |
| 1845 | } |
| 1846 | } |
| 1847 | else if (!strcmp(args[0], "rspdeny")) { /* block response header from a regex */ |
| 1848 | regex_t *preg; |
| 1849 | if (curproxy == &defproxy) { |
| 1850 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 1851 | return -1; |
| 1852 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1853 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
| 1854 | return 0; |
| 1855 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1856 | if (*(args[1]) == 0) { |
| 1857 | Alert("parsing [%s:%d] : '%s' expects <search> as an argument.\n", file, linenum, args[0]); |
| 1858 | return -1; |
| 1859 | } |
| 1860 | |
| 1861 | preg = calloc(1, sizeof(regex_t)); |
| 1862 | if (regcomp(preg, args[1], REG_EXTENDED) != 0) { |
| 1863 | Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]); |
| 1864 | return -1; |
| 1865 | } |
| 1866 | |
| 1867 | err = chain_regex(&curproxy->rsp_exp, preg, ACT_DENY, strdup(args[2])); |
| 1868 | if (err) { |
| 1869 | Alert("parsing [%s:%d] : invalid character or unterminated sequence in replacement string near '%c'.\n", |
| 1870 | file, linenum, *err); |
| 1871 | return -1; |
| 1872 | } |
| 1873 | } |
| 1874 | else if (!strcmp(args[0], "rspirep")) { /* replace response header from a regex ignoring case */ |
| 1875 | regex_t *preg; |
| 1876 | if (curproxy == &defproxy) { |
| 1877 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 1878 | return -1; |
| 1879 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1880 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
| 1881 | return 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1882 | |
| 1883 | if (*(args[1]) == 0 || *(args[2]) == 0) { |
| 1884 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 1885 | file, linenum, args[0]); |
| 1886 | return -1; |
| 1887 | } |
| 1888 | |
| 1889 | preg = calloc(1, sizeof(regex_t)); |
| 1890 | if (regcomp(preg, args[1], REG_EXTENDED | REG_ICASE) != 0) { |
| 1891 | Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]); |
| 1892 | return -1; |
| 1893 | } |
| 1894 | |
| 1895 | err = chain_regex(&curproxy->rsp_exp, preg, ACT_REPLACE, strdup(args[2])); |
| 1896 | if (err) { |
| 1897 | Alert("parsing [%s:%d] : invalid character or unterminated sequence in replacement string near '%c'.\n", |
| 1898 | file, linenum, *err); |
| 1899 | return -1; |
| 1900 | } |
| 1901 | } |
| 1902 | else if (!strcmp(args[0], "rspidel")) { /* delete response header from a regex ignoring case */ |
| 1903 | regex_t *preg; |
| 1904 | if (curproxy == &defproxy) { |
| 1905 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 1906 | return -1; |
| 1907 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1908 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
| 1909 | return 0; |
| 1910 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1911 | if (*(args[1]) == 0) { |
| 1912 | Alert("parsing [%s:%d] : '%s' expects <search> as an argument.\n", file, linenum, args[0]); |
| 1913 | return -1; |
| 1914 | } |
| 1915 | |
| 1916 | preg = calloc(1, sizeof(regex_t)); |
| 1917 | if (regcomp(preg, args[1], REG_EXTENDED | REG_ICASE) != 0) { |
| 1918 | Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]); |
| 1919 | return -1; |
| 1920 | } |
| 1921 | |
| 1922 | err = chain_regex(&curproxy->rsp_exp, preg, ACT_REMOVE, strdup(args[2])); |
| 1923 | if (err) { |
| 1924 | Alert("parsing [%s:%d] : invalid character or unterminated sequence in replacement string near '%c'.\n", |
| 1925 | file, linenum, *err); |
| 1926 | return -1; |
| 1927 | } |
| 1928 | } |
| 1929 | else if (!strcmp(args[0], "rspideny")) { /* block response header from a regex ignoring case */ |
| 1930 | regex_t *preg; |
| 1931 | if (curproxy == &defproxy) { |
| 1932 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 1933 | return -1; |
| 1934 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1935 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
| 1936 | return 0; |
| 1937 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1938 | if (*(args[1]) == 0) { |
| 1939 | Alert("parsing [%s:%d] : '%s' expects <search> as an argument.\n", file, linenum, args[0]); |
| 1940 | return -1; |
| 1941 | } |
| 1942 | |
| 1943 | preg = calloc(1, sizeof(regex_t)); |
| 1944 | if (regcomp(preg, args[1], REG_EXTENDED | REG_ICASE) != 0) { |
| 1945 | Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]); |
| 1946 | return -1; |
| 1947 | } |
| 1948 | |
| 1949 | err = chain_regex(&curproxy->rsp_exp, preg, ACT_DENY, strdup(args[2])); |
| 1950 | if (err) { |
| 1951 | Alert("parsing [%s:%d] : invalid character or unterminated sequence in replacement string near '%c'.\n", |
| 1952 | file, linenum, *err); |
| 1953 | return -1; |
| 1954 | } |
| 1955 | } |
| 1956 | else if (!strcmp(args[0], "rspadd")) { /* add response header */ |
| 1957 | if (curproxy == &defproxy) { |
| 1958 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 1959 | return -1; |
| 1960 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1961 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
| 1962 | return 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1963 | |
| 1964 | if (curproxy->nb_rspadd >= MAX_NEWHDR) { |
| 1965 | Alert("parsing [%s:%d] : too many '%s'. Continuing.\n", file, linenum, args[0]); |
| 1966 | return 0; |
| 1967 | } |
| 1968 | |
| 1969 | if (*(args[1]) == 0) { |
| 1970 | Alert("parsing [%s:%d] : '%s' expects <header> as an argument.\n", file, linenum, args[0]); |
| 1971 | return -1; |
| 1972 | } |
| 1973 | |
| 1974 | curproxy->rsp_add[curproxy->nb_rspadd++] = strdup(args[1]); |
| 1975 | } |
| 1976 | else if (!strcmp(args[0], "errorloc") || |
| 1977 | !strcmp(args[0], "errorloc302") || |
| 1978 | !strcmp(args[0], "errorloc303")) { /* error location */ |
| 1979 | int errnum, errlen; |
| 1980 | char *err; |
| 1981 | |
| 1982 | // if (curproxy == &defproxy) { |
| 1983 | // Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 1984 | // return -1; |
| 1985 | // } |
| 1986 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1987 | if (warnifnotcap(curproxy, PR_CAP_FE | PR_CAP_BE, file, linenum, args[0], NULL)) |
| 1988 | return 0; |
| 1989 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1990 | if (*(args[2]) == 0) { |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 1991 | 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] | 1992 | return -1; |
| 1993 | } |
| 1994 | |
| 1995 | errnum = atol(args[1]); |
| 1996 | if (!strcmp(args[0], "errorloc303")) { |
| 1997 | err = malloc(strlen(HTTP_303) + strlen(args[2]) + 5); |
| 1998 | errlen = sprintf(err, "%s%s\r\n\r\n", HTTP_303, args[2]); |
| 1999 | } else { |
| 2000 | err = malloc(strlen(HTTP_302) + strlen(args[2]) + 5); |
| 2001 | errlen = sprintf(err, "%s%s\r\n\r\n", HTTP_302, args[2]); |
| 2002 | } |
| 2003 | |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 2004 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) { |
| 2005 | if (http_err_codes[rc] == errnum) { |
| 2006 | if (curproxy->errmsg[rc].str) |
| 2007 | free(curproxy->errmsg[rc].str); |
| 2008 | curproxy->errmsg[rc].str = err; |
| 2009 | curproxy->errmsg[rc].len = errlen; |
| 2010 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2011 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2012 | } |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 2013 | |
| 2014 | if (rc >= HTTP_ERR_SIZE) { |
| 2015 | Warning("parsing [%s:%d] : status code %d not handled, error relocation will be ignored.\n", |
| 2016 | file, linenum, errnum); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2017 | free(err); |
| 2018 | } |
| 2019 | } |
| 2020 | else { |
| 2021 | Alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], "listen"); |
| 2022 | return -1; |
| 2023 | } |
| 2024 | return 0; |
| 2025 | } |
| 2026 | |
| 2027 | |
| 2028 | /* |
| 2029 | * This function reads and parses the configuration file given in the argument. |
| 2030 | * returns 0 if OK, -1 if error. |
| 2031 | */ |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 2032 | int readcfgfile(const char *file) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2033 | { |
| 2034 | char thisline[256]; |
| 2035 | char *line; |
| 2036 | FILE *f; |
| 2037 | int linenum = 0; |
| 2038 | char *end; |
| 2039 | char *args[MAX_LINE_ARGS]; |
| 2040 | int arg; |
| 2041 | int cfgerr = 0; |
Willy Tarreau | 8058743 | 2006-12-24 17:47:20 +0100 | [diff] [blame] | 2042 | int nbchk, mininter; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2043 | int confsect = CFG_NONE; |
| 2044 | |
| 2045 | struct proxy *curproxy = NULL; |
| 2046 | struct server *newsrv = NULL; |
| 2047 | |
| 2048 | if ((f=fopen(file,"r")) == NULL) |
| 2049 | return -1; |
| 2050 | |
| 2051 | init_default_instance(); |
| 2052 | |
| 2053 | while (fgets(line = thisline, sizeof(thisline), f) != NULL) { |
| 2054 | linenum++; |
| 2055 | |
| 2056 | end = line + strlen(line); |
| 2057 | |
| 2058 | /* skip leading spaces */ |
| 2059 | while (isspace((int)*line)) |
| 2060 | line++; |
| 2061 | |
| 2062 | arg = 0; |
| 2063 | args[arg] = line; |
| 2064 | |
| 2065 | while (*line && arg < MAX_LINE_ARGS) { |
| 2066 | /* first, we'll replace \\, \<space>, \#, \r, \n, \t, \xXX with their |
| 2067 | * C equivalent value. Other combinations left unchanged (eg: \1). |
| 2068 | */ |
| 2069 | if (*line == '\\') { |
| 2070 | int skip = 0; |
| 2071 | if (line[1] == ' ' || line[1] == '\\' || line[1] == '#') { |
| 2072 | *line = line[1]; |
| 2073 | skip = 1; |
| 2074 | } |
| 2075 | else if (line[1] == 'r') { |
| 2076 | *line = '\r'; |
| 2077 | skip = 1; |
| 2078 | } |
| 2079 | else if (line[1] == 'n') { |
| 2080 | *line = '\n'; |
| 2081 | skip = 1; |
| 2082 | } |
| 2083 | else if (line[1] == 't') { |
| 2084 | *line = '\t'; |
| 2085 | skip = 1; |
| 2086 | } |
| 2087 | else if (line[1] == 'x') { |
| 2088 | if ((line + 3 < end ) && ishex(line[2]) && ishex(line[3])) { |
| 2089 | unsigned char hex1, hex2; |
| 2090 | hex1 = toupper(line[2]) - '0'; |
| 2091 | hex2 = toupper(line[3]) - '0'; |
| 2092 | if (hex1 > 9) hex1 -= 'A' - '9' - 1; |
| 2093 | if (hex2 > 9) hex2 -= 'A' - '9' - 1; |
| 2094 | *line = (hex1<<4) + hex2; |
| 2095 | skip = 3; |
| 2096 | } |
| 2097 | else { |
| 2098 | Alert("parsing [%s:%d] : invalid or incomplete '\\x' sequence in '%s'.\n", file, linenum, args[0]); |
| 2099 | return -1; |
| 2100 | } |
| 2101 | } |
| 2102 | if (skip) { |
| 2103 | memmove(line + 1, line + 1 + skip, end - (line + skip + 1)); |
| 2104 | end -= skip; |
| 2105 | } |
| 2106 | line++; |
| 2107 | } |
| 2108 | else if (*line == '#' || *line == '\n' || *line == '\r') { |
| 2109 | /* end of string, end of loop */ |
| 2110 | *line = 0; |
| 2111 | break; |
| 2112 | } |
| 2113 | else if (isspace((int)*line)) { |
| 2114 | /* a non-escaped space is an argument separator */ |
| 2115 | *line++ = 0; |
| 2116 | while (isspace((int)*line)) |
| 2117 | line++; |
| 2118 | args[++arg] = line; |
| 2119 | } |
| 2120 | else { |
| 2121 | line++; |
| 2122 | } |
| 2123 | } |
| 2124 | |
| 2125 | /* empty line */ |
| 2126 | if (!**args) |
| 2127 | continue; |
| 2128 | |
| 2129 | /* zero out remaining args */ |
| 2130 | while (++arg < MAX_LINE_ARGS) { |
| 2131 | args[arg] = line; |
| 2132 | } |
| 2133 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2134 | if (!strcmp(args[0], "listen") || |
| 2135 | !strcmp(args[0], "frontend") || |
| 2136 | !strcmp(args[0], "backend") || |
| 2137 | !strcmp(args[0], "ruleset") || |
| 2138 | !strcmp(args[0], "defaults")) /* new proxy */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2139 | confsect = CFG_LISTEN; |
| 2140 | else if (!strcmp(args[0], "global")) /* global config */ |
| 2141 | confsect = CFG_GLOBAL; |
| 2142 | /* else it's a section keyword */ |
| 2143 | |
| 2144 | switch (confsect) { |
| 2145 | case CFG_LISTEN: |
| 2146 | if (cfg_parse_listen(file, linenum, args) < 0) |
| 2147 | return -1; |
| 2148 | break; |
| 2149 | case CFG_GLOBAL: |
| 2150 | if (cfg_parse_global(file, linenum, args) < 0) |
| 2151 | return -1; |
| 2152 | break; |
| 2153 | default: |
| 2154 | Alert("parsing [%s:%d] : unknown keyword '%s' out of section.\n", file, linenum, args[0]); |
| 2155 | return -1; |
| 2156 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2157 | } |
| 2158 | fclose(f); |
| 2159 | |
| 2160 | /* |
| 2161 | * Now, check for the integrity of all that we have collected. |
| 2162 | */ |
| 2163 | |
| 2164 | /* will be needed further to delay some tasks */ |
| 2165 | tv_now(&now); |
| 2166 | |
| 2167 | if ((curproxy = proxy) == NULL) { |
| 2168 | Alert("parsing %s : no <listen> line. Nothing to do !\n", |
| 2169 | file); |
| 2170 | return -1; |
| 2171 | } |
| 2172 | |
| 2173 | while (curproxy != NULL) { |
Willy Tarreau | 97a738f | 2006-12-17 18:02:30 +0100 | [diff] [blame] | 2174 | curproxy->fiprm = curproxy->beprm = curproxy; |
| 2175 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2176 | if (curproxy->state == PR_STSTOPPED) { |
| 2177 | curproxy = curproxy->next; |
| 2178 | continue; |
| 2179 | } |
| 2180 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2181 | if (curproxy->cap & PR_CAP_FE && curproxy->listen == NULL) { |
| 2182 | 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] | 2183 | file, proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2184 | cfgerr++; |
| 2185 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2186 | else if (curproxy->cap & PR_CAP_BE && |
| 2187 | ((curproxy->mode != PR_MODE_HEALTH) && |
| 2188 | !(curproxy->options & (PR_O_TRANSP | PR_O_BALANCE)) && |
| 2189 | (*(int *)&curproxy->dispatch_addr.sin_addr == 0))) { |
| 2190 | 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] | 2191 | file, proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2192 | cfgerr++; |
| 2193 | } |
| 2194 | else if ((curproxy->mode != PR_MODE_HEALTH) && (curproxy->options & PR_O_BALANCE)) { |
| 2195 | if (curproxy->options & PR_O_TRANSP) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2196 | 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] | 2197 | file, proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2198 | cfgerr++; |
| 2199 | } |
| 2200 | #ifdef WE_DONT_SUPPORT_SERVERLESS_LISTENERS |
| 2201 | else if (curproxy->srv == NULL) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2202 | 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] | 2203 | file, proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2204 | cfgerr++; |
| 2205 | } |
| 2206 | #endif |
| 2207 | else if (*(int *)&curproxy->dispatch_addr.sin_addr != 0) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2208 | 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] | 2209 | file, proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2210 | } |
| 2211 | } |
| 2212 | else if (curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HEALTH) { /* TCP PROXY or HEALTH CHECK */ |
| 2213 | if (curproxy->cookie_name != NULL) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2214 | Warning("parsing %s : cookie will be ignored for %s '%s'.\n", |
Willy Tarreau | 2b5652f | 2006-12-31 17:46:05 +0100 | [diff] [blame] | 2215 | file, proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2216 | } |
| 2217 | if ((newsrv = curproxy->srv) != NULL) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2218 | Warning("parsing %s : servers will be ignored for %s '%s'.\n", |
Willy Tarreau | 2b5652f | 2006-12-31 17:46:05 +0100 | [diff] [blame] | 2219 | file, proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2220 | } |
| 2221 | if (curproxy->rsp_exp != NULL) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2222 | 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] | 2223 | file, proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2224 | } |
| 2225 | if (curproxy->req_exp != NULL) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2226 | 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] | 2227 | file, proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2228 | } |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2229 | if (curproxy->monitor_uri != NULL) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2230 | Warning("parsing %s : monitor-uri will be ignored for %s '%s'.\n", |
Willy Tarreau | 2b5652f | 2006-12-31 17:46:05 +0100 | [diff] [blame] | 2231 | file, proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2232 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2233 | } |
| 2234 | else if (curproxy->mode == PR_MODE_HTTP) { /* HTTP PROXY */ |
| 2235 | if ((curproxy->cookie_name != NULL) && ((newsrv = curproxy->srv) == NULL)) { |
| 2236 | Alert("parsing %s : HTTP proxy %s has a cookie but no server list !\n", |
| 2237 | file, curproxy->id); |
| 2238 | cfgerr++; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 2239 | } |
| 2240 | } |
| 2241 | |
| 2242 | /* if a default backend was specified, let's find it */ |
| 2243 | if (curproxy->defbe.name) { |
| 2244 | struct proxy *target; |
| 2245 | |
| 2246 | for (target = proxy; target != NULL; target = target->next) { |
| 2247 | if (strcmp(target->id, curproxy->defbe.name) == 0) |
| 2248 | break; |
| 2249 | } |
| 2250 | if (target == NULL) { |
| 2251 | Alert("parsing %s : default backend '%s' in HTTP %s '%s' was not found !\n", |
| 2252 | file, curproxy->defbe.name, proxy_type_str(curproxy), curproxy->id); |
| 2253 | cfgerr++; |
| 2254 | } else if (target == curproxy) { |
| 2255 | Alert("parsing %s : loop detected for default backend %s !\n", file, curproxy->defbe.name); |
| 2256 | cfgerr++; |
| 2257 | } else if (!(target->cap & PR_CAP_BE)) { |
| 2258 | Alert("parsing %s : default backend '%s' in HTTP %s '%s' has no backend capability !\n", |
| 2259 | file, curproxy->defbe.name, proxy_type_str(curproxy), curproxy->id); |
| 2260 | cfgerr++; |
| 2261 | } else if (target->mode != curproxy->mode) { |
| 2262 | Alert("parsing %s : default backend '%s' in HTTP %s '%s' is not of same mode (tcp/http) !\n", |
| 2263 | file, curproxy->defbe.name, proxy_type_str(curproxy), curproxy->id); |
| 2264 | cfgerr++; |
| 2265 | } else { |
| 2266 | free(curproxy->defbe.name); |
| 2267 | curproxy->defbe.be = target; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2268 | } |
| 2269 | } |
| 2270 | |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 2271 | /* find the target proxy in setbe */ |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 2272 | if (curproxy->mode == PR_MODE_HTTP && curproxy->req_exp != NULL) { |
| 2273 | /* map jump target for ACT_SETBE in req_rep chain */ |
| 2274 | struct hdr_exp *exp; |
| 2275 | struct proxy *target; |
| 2276 | for (exp = curproxy->req_exp; exp != NULL; exp = exp->next) { |
| 2277 | if (exp->action != ACT_SETBE) |
| 2278 | continue; |
| 2279 | for (target = proxy; target != NULL; target = target->next) { |
| 2280 | if (strcmp(target->id, exp->replace) == 0) |
| 2281 | break; |
| 2282 | } |
| 2283 | if (target == NULL) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2284 | 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] | 2285 | file, exp->replace, proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 2286 | cfgerr++; |
| 2287 | } else if (target == curproxy) { |
| 2288 | Alert("parsing %s : loop detected for backend %s !\n", file, exp->replace); |
| 2289 | cfgerr++; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2290 | } else if (!(target->cap & PR_CAP_BE)) { |
| 2291 | 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] | 2292 | file, exp->replace, proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2293 | cfgerr++; |
| 2294 | } else if (target->mode != PR_MODE_HTTP) { |
| 2295 | 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] | 2296 | file, exp->replace, proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2297 | cfgerr++; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 2298 | } else { |
| 2299 | free((void *)exp->replace); |
| 2300 | exp->replace = (const char *)target; |
| 2301 | } |
| 2302 | } |
| 2303 | } |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 2304 | if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) && |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2305 | (((curproxy->cap & PR_CAP_FE) && !curproxy->clitimeout) || |
| 2306 | ((curproxy->cap & PR_CAP_BE) && (curproxy->srv) && (!curproxy->contimeout || !curproxy->srvtimeout)))) { |
| 2307 | Warning("parsing %s : missing timeouts for %s '%s'.\n" |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 2308 | " | While not properly invalid, you will certainly encounter various problems\n" |
| 2309 | " | with such a configuration. To fix this, please ensure that all following\n" |
| 2310 | " | values are set to a non-zero value: clitimeout, contimeout, srvtimeout.\n", |
Willy Tarreau | 2b5652f | 2006-12-31 17:46:05 +0100 | [diff] [blame] | 2311 | file, proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 2312 | } |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 2313 | |
| 2314 | if (curproxy->options & PR_O_SSL3_CHK) { |
| 2315 | curproxy->check_len = sizeof(sslv3_client_hello_pkt); |
| 2316 | curproxy->check_req = (char *)malloc(sizeof(sslv3_client_hello_pkt)); |
| 2317 | memcpy(curproxy->check_req, sslv3_client_hello_pkt, sizeof(sslv3_client_hello_pkt)); |
| 2318 | } |
| 2319 | |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 2320 | /* for backwards compatibility with "listen" instances, if |
| 2321 | * fullconn is not set but maxconn is set, then maxconn |
| 2322 | * is used. |
| 2323 | */ |
| 2324 | if (!curproxy->fullconn) |
| 2325 | curproxy->fullconn = curproxy->maxconn; |
| 2326 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2327 | /* first, we will invert the servers list order */ |
| 2328 | newsrv = NULL; |
| 2329 | while (curproxy->srv) { |
| 2330 | struct server *next; |
| 2331 | |
| 2332 | next = curproxy->srv->next; |
| 2333 | curproxy->srv->next = newsrv; |
| 2334 | newsrv = curproxy->srv; |
| 2335 | if (!next) |
| 2336 | break; |
| 2337 | curproxy->srv = next; |
| 2338 | } |
| 2339 | |
| 2340 | /* now, newsrv == curproxy->srv */ |
| 2341 | if (newsrv) { |
| 2342 | struct server *srv; |
| 2343 | int pgcd; |
| 2344 | int act, bck; |
| 2345 | |
| 2346 | /* We will factor the weights to reduce the table, |
| 2347 | * using Euclide's largest common divisor algorithm |
| 2348 | */ |
| 2349 | pgcd = newsrv->uweight + 1; |
| 2350 | for (srv = newsrv->next; srv && pgcd > 1; srv = srv->next) { |
| 2351 | int t, w; |
| 2352 | |
| 2353 | w = srv->uweight + 1; |
| 2354 | while (w) { |
| 2355 | t = pgcd % w; |
| 2356 | pgcd = w; |
| 2357 | w = t; |
| 2358 | } |
| 2359 | } |
| 2360 | |
| 2361 | act = bck = 0; |
| 2362 | for (srv = newsrv; srv; srv = srv->next) { |
| 2363 | srv->eweight = ((srv->uweight + 1) / pgcd) - 1; |
| 2364 | if (srv->state & SRV_BACKUP) |
| 2365 | bck += srv->eweight + 1; |
| 2366 | else |
| 2367 | act += srv->eweight + 1; |
| 2368 | } |
| 2369 | |
| 2370 | /* this is the largest map we will ever need for this servers list */ |
| 2371 | if (act < bck) |
| 2372 | act = bck; |
| 2373 | |
| 2374 | curproxy->srv_map = (struct server **)calloc(act, sizeof(struct server *)); |
| 2375 | /* recounts servers and their weights */ |
| 2376 | recount_servers(curproxy); |
| 2377 | recalc_server_map(curproxy); |
| 2378 | } |
| 2379 | |
| 2380 | if (curproxy->options & PR_O_LOGASAP) |
| 2381 | curproxy->to_log &= ~LW_BYTES; |
| 2382 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2383 | /* |
| 2384 | * If this server supports a maxconn parameter, it needs a dedicated |
| 2385 | * tasks to fill the emptied slots when a connection leaves. |
| 2386 | */ |
| 2387 | newsrv = curproxy->srv; |
| 2388 | while (newsrv != NULL) { |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 2389 | if (newsrv->minconn > newsrv->maxconn) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2390 | /* Only 'minconn' was specified, or it was higher than or equal |
| 2391 | * to 'maxconn'. Let's turn this into maxconn and clean it, as |
| 2392 | * this will avoid further useless expensive computations. |
| 2393 | */ |
| 2394 | newsrv->maxconn = newsrv->minconn; |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 2395 | } else if (newsrv->maxconn && !newsrv->minconn) { |
| 2396 | /* minconn was not specified, so we set it to maxconn */ |
| 2397 | newsrv->minconn = newsrv->maxconn; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2398 | } else if (newsrv->minconn != newsrv->maxconn && !curproxy->fullconn) { |
| 2399 | 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] | 2400 | file, proxy_type_str(curproxy), curproxy->id, linenum); |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 2401 | return -1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2402 | } |
| 2403 | |
| 2404 | if (newsrv->maxconn > 0) { |
| 2405 | struct task *t; |
| 2406 | |
| 2407 | if ((t = pool_alloc(task)) == NULL) { |
| 2408 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 2409 | return -1; |
| 2410 | } |
| 2411 | |
Willy Tarreau | 964c936 | 2007-01-07 00:38:00 +0100 | [diff] [blame] | 2412 | t->rqnext = NULL; |
| 2413 | t->wq = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2414 | t->state = TASK_IDLE; |
| 2415 | t->process = process_srv_queue; |
| 2416 | t->context = newsrv; |
| 2417 | newsrv->queue_mgt = t; |
| 2418 | |
| 2419 | /* never run it unless specifically woken up */ |
| 2420 | tv_eternity(&t->expire); |
| 2421 | task_queue(t); |
| 2422 | } |
| 2423 | newsrv = newsrv->next; |
| 2424 | } |
| 2425 | |
| 2426 | /* now we'll start this proxy's health checks if any */ |
| 2427 | /* 1- count the checkers to run simultaneously */ |
| 2428 | nbchk = 0; |
| 2429 | mininter = 0; |
| 2430 | newsrv = curproxy->srv; |
| 2431 | while (newsrv != NULL) { |
| 2432 | if (newsrv->state & SRV_CHECKED) { |
| 2433 | if (!mininter || mininter > newsrv->inter) |
| 2434 | mininter = newsrv->inter; |
| 2435 | nbchk++; |
| 2436 | } |
| 2437 | newsrv = newsrv->next; |
| 2438 | } |
| 2439 | |
| 2440 | /* 2- start them as far as possible from each others while respecting |
| 2441 | * their own intervals. For this, we will start them after their own |
| 2442 | * interval added to the min interval divided by the number of servers, |
| 2443 | * weighted by the server's position in the list. |
| 2444 | */ |
| 2445 | if (nbchk > 0) { |
| 2446 | struct task *t; |
| 2447 | int srvpos; |
| 2448 | |
| 2449 | newsrv = curproxy->srv; |
| 2450 | srvpos = 0; |
| 2451 | while (newsrv != NULL) { |
| 2452 | /* should this server be checked ? */ |
| 2453 | if (newsrv->state & SRV_CHECKED) { |
| 2454 | if ((t = pool_alloc(task)) == NULL) { |
| 2455 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 2456 | return -1; |
| 2457 | } |
| 2458 | |
Willy Tarreau | 964c936 | 2007-01-07 00:38:00 +0100 | [diff] [blame] | 2459 | t->wq = NULL; |
| 2460 | t->rqnext = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2461 | t->state = TASK_IDLE; |
| 2462 | t->process = process_chk; |
| 2463 | t->context = newsrv; |
| 2464 | |
| 2465 | /* check this every ms */ |
| 2466 | tv_delayfrom(&t->expire, &now, |
| 2467 | newsrv->inter + mininter * srvpos / nbchk); |
| 2468 | task_queue(t); |
| 2469 | //task_wakeup(&rq, t); |
| 2470 | srvpos++; |
| 2471 | } |
| 2472 | newsrv = newsrv->next; |
| 2473 | } |
| 2474 | } |
| 2475 | |
| 2476 | curproxy = curproxy->next; |
| 2477 | } |
| 2478 | if (cfgerr > 0) { |
| 2479 | Alert("Errors found in configuration file, aborting.\n"); |
| 2480 | return -1; |
| 2481 | } |
| 2482 | else |
| 2483 | return 0; |
| 2484 | } |
| 2485 | |
| 2486 | |
| 2487 | |
| 2488 | /* |
| 2489 | * Local variables: |
| 2490 | * c-indent-level: 8 |
| 2491 | * c-basic-offset: 8 |
| 2492 | * End: |
| 2493 | */ |