Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Configuration parser |
| 3 | * |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 4 | * Copyright 2000-2011 Willy Tarreau <w@1wt.eu> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * as published by the Free Software Foundation; either version |
| 9 | * 2 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | */ |
| 12 | |
| 13 | #include <stdio.h> |
| 14 | #include <stdlib.h> |
| 15 | #include <string.h> |
| 16 | #include <netdb.h> |
| 17 | #include <ctype.h> |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 18 | #include <pwd.h> |
| 19 | #include <grp.h> |
Willy Tarreau | 0b4ed90 | 2007-03-26 00:18:40 +0200 | [diff] [blame] | 20 | #include <errno.h> |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 21 | #include <sys/types.h> |
| 22 | #include <sys/stat.h> |
| 23 | #include <fcntl.h> |
| 24 | #include <unistd.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 25 | |
Willy Tarreau | be1b918 | 2009-06-14 18:48:19 +0200 | [diff] [blame] | 26 | #include <netinet/tcp.h> |
| 27 | |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 28 | #include <common/cfgparse.h> |
| 29 | #include <common/config.h> |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 30 | #include <common/errors.h> |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 31 | #include <common/memory.h> |
| 32 | #include <common/standard.h> |
| 33 | #include <common/time.h> |
| 34 | #include <common/uri_auth.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 35 | |
| 36 | #include <types/capture.h> |
| 37 | #include <types/global.h> |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 38 | #include <types/peers.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 39 | |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 40 | #include <proto/acl.h> |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 41 | #include <proto/auth.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 42 | #include <proto/backend.h> |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 43 | #include <proto/buffers.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 44 | #include <proto/checks.h> |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 45 | #include <proto/dumpstats.h> |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 46 | #include <proto/frontend.h> |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 47 | #include <proto/hdr_idx.h> |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 48 | #include <proto/lb_chash.h> |
Willy Tarreau | f89c187 | 2009-10-01 11:19:37 +0200 | [diff] [blame] | 49 | #include <proto/lb_fwlc.h> |
| 50 | #include <proto/lb_fwrr.h> |
| 51 | #include <proto/lb_map.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 52 | #include <proto/log.h> |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 53 | #include <proto/pattern.h> |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 54 | #include <proto/port_range.h> |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 55 | #include <proto/protocols.h> |
| 56 | #include <proto/proto_tcp.h> |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 57 | #include <proto/proto_uxst.h> |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 58 | #include <proto/proto_http.h> |
Willy Tarreau | 2b5652f | 2006-12-31 17:46:05 +0100 | [diff] [blame] | 59 | #include <proto/proxy.h> |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 60 | #include <proto/peers.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 61 | #include <proto/server.h> |
Willy Tarreau | 3bc1377 | 2008-12-07 11:50:35 +0100 | [diff] [blame] | 62 | #include <proto/session.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 63 | #include <proto/task.h> |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 64 | #include <proto/stick_table.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 65 | |
| 66 | |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 67 | /* This is the SSLv3 CLIENT HELLO packet used in conjunction with the |
| 68 | * ssl-hello-chk option to ensure that the remote server speaks SSL. |
| 69 | * |
| 70 | * Check RFC 2246 (TLSv1.0) sections A.3 and A.4 for details. |
| 71 | */ |
| 72 | const char sslv3_client_hello_pkt[] = { |
| 73 | "\x16" /* ContentType : 0x16 = Hanshake */ |
| 74 | "\x03\x00" /* ProtocolVersion : 0x0300 = SSLv3 */ |
| 75 | "\x00\x79" /* ContentLength : 0x79 bytes after this one */ |
| 76 | "\x01" /* HanshakeType : 0x01 = CLIENT HELLO */ |
| 77 | "\x00\x00\x75" /* HandshakeLength : 0x75 bytes after this one */ |
| 78 | "\x03\x00" /* Hello Version : 0x0300 = v3 */ |
| 79 | "\x00\x00\x00\x00" /* Unix GMT Time (s) : filled with <now> (@0x0B) */ |
| 80 | "HAPROXYSSLCHK\nHAPROXYSSLCHK\n" /* Random : must be exactly 28 bytes */ |
| 81 | "\x00" /* Session ID length : empty (no session ID) */ |
| 82 | "\x00\x4E" /* Cipher Suite Length : 78 bytes after this one */ |
| 83 | "\x00\x01" "\x00\x02" "\x00\x03" "\x00\x04" /* 39 most common ciphers : */ |
| 84 | "\x00\x05" "\x00\x06" "\x00\x07" "\x00\x08" /* 0x01...0x1B, 0x2F...0x3A */ |
| 85 | "\x00\x09" "\x00\x0A" "\x00\x0B" "\x00\x0C" /* This covers RSA/DH, */ |
| 86 | "\x00\x0D" "\x00\x0E" "\x00\x0F" "\x00\x10" /* various bit lengths, */ |
| 87 | "\x00\x11" "\x00\x12" "\x00\x13" "\x00\x14" /* SHA1/MD5, DES/3DES/AES... */ |
| 88 | "\x00\x15" "\x00\x16" "\x00\x17" "\x00\x18" |
| 89 | "\x00\x19" "\x00\x1A" "\x00\x1B" "\x00\x2F" |
| 90 | "\x00\x30" "\x00\x31" "\x00\x32" "\x00\x33" |
| 91 | "\x00\x34" "\x00\x35" "\x00\x36" "\x00\x37" |
| 92 | "\x00\x38" "\x00\x39" "\x00\x3A" |
| 93 | "\x01" /* Compression Length : 0x01 = 1 byte for types */ |
| 94 | "\x00" /* Compression Type : 0x00 = NULL compression */ |
| 95 | }; |
| 96 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 97 | /* various keyword modifiers */ |
| 98 | enum kw_mod { |
| 99 | KWM_STD = 0, /* normal */ |
| 100 | KWM_NO, /* "no" prefixed before the keyword */ |
| 101 | KWM_DEF, /* "default" prefixed before the keyword */ |
| 102 | }; |
| 103 | |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 104 | /* some of the most common options which are also the easiest to handle */ |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 105 | struct cfg_opt { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 106 | const char *name; |
| 107 | unsigned int val; |
| 108 | unsigned int cap; |
Willy Tarreau | 4fee4e9 | 2007-01-06 21:09:17 +0100 | [diff] [blame] | 109 | unsigned int checks; |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 110 | unsigned int mode; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 111 | }; |
| 112 | |
| 113 | /* proxy->options */ |
| 114 | static const struct cfg_opt cfg_opts[] = |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 115 | { |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 116 | { "abortonclose", PR_O_ABRT_CLOSE, PR_CAP_BE, 0, 0 }, |
| 117 | { "allbackups", PR_O_USE_ALL_BK, PR_CAP_BE, 0, 0 }, |
| 118 | { "checkcache", PR_O_CHK_CACHE, PR_CAP_BE, 0, PR_MODE_HTTP }, |
| 119 | { "clitcpka", PR_O_TCP_CLI_KA, PR_CAP_FE, 0, 0 }, |
| 120 | { "contstats", PR_O_CONTSTATS, PR_CAP_FE, 0, 0 }, |
| 121 | { "dontlognull", PR_O_NULLNOLOG, PR_CAP_FE, 0, 0 }, |
| 122 | { "forceclose", PR_O_FORCE_CLO, PR_CAP_FE | PR_CAP_BE, 0, PR_MODE_HTTP }, |
| 123 | { "http_proxy", PR_O_HTTP_PROXY, PR_CAP_FE | PR_CAP_BE, 0, PR_MODE_HTTP }, |
| 124 | { "httpclose", PR_O_HTTP_CLOSE, PR_CAP_FE | PR_CAP_BE, 0, PR_MODE_HTTP }, |
| 125 | { "keepalive", PR_O_KEEPALIVE, PR_CAP_NONE, 0, PR_MODE_HTTP }, |
| 126 | { "http-server-close", PR_O_SERVER_CLO, PR_CAP_FE | PR_CAP_BE, 0, PR_MODE_HTTP }, |
| 127 | { "logasap", PR_O_LOGASAP, PR_CAP_FE, 0, 0 }, |
| 128 | { "nolinger", PR_O_TCP_NOLING, PR_CAP_FE | PR_CAP_BE, 0, 0 }, |
| 129 | { "persist", PR_O_PERSIST, PR_CAP_BE, 0, 0 }, |
| 130 | { "redispatch", PR_O_REDISP, PR_CAP_BE, 0, 0 }, |
| 131 | { "srvtcpka", PR_O_TCP_SRV_KA, PR_CAP_BE, 0, 0 }, |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 132 | #ifdef TPROXY |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 133 | { "transparent", PR_O_TRANSP, PR_CAP_BE, 0, 0 }, |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 134 | #else |
| 135 | { "transparent", 0, 0, 0, 0 }, |
Willy Tarreau | 8f922fc | 2007-01-06 21:11:49 +0100 | [diff] [blame] | 136 | #endif |
| 137 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 138 | { NULL, 0, 0, 0, 0 } |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 139 | }; |
| 140 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 141 | /* proxy->options2 */ |
| 142 | static const struct cfg_opt cfg_opts2[] = |
| 143 | { |
| 144 | #ifdef CONFIG_HAP_LINUX_SPLICE |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 145 | { "splice-request", PR_O2_SPLIC_REQ, PR_CAP_FE|PR_CAP_BE, 0, 0 }, |
| 146 | { "splice-response", PR_O2_SPLIC_RTR, PR_CAP_FE|PR_CAP_BE, 0, 0 }, |
| 147 | { "splice-auto", PR_O2_SPLIC_AUT, PR_CAP_FE|PR_CAP_BE, 0, 0 }, |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 148 | #else |
| 149 | { "splice-request", 0, 0, 0, 0 }, |
| 150 | { "splice-response", 0, 0, 0, 0 }, |
| 151 | { "splice-auto", 0, 0, 0, 0 }, |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 152 | #endif |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 153 | { "accept-invalid-http-request", PR_O2_REQBUG_OK, PR_CAP_FE, 0, PR_MODE_HTTP }, |
| 154 | { "accept-invalid-http-response", PR_O2_RSPBUG_OK, PR_CAP_BE, 0, PR_MODE_HTTP }, |
| 155 | { "dontlog-normal", PR_O2_NOLOGNORM, PR_CAP_FE, 0, 0 }, |
| 156 | { "log-separate-errors", PR_O2_LOGERRORS, PR_CAP_FE, 0, 0 }, |
| 157 | { "log-health-checks", PR_O2_LOGHCHKS, PR_CAP_BE, 0, 0 }, |
| 158 | { "socket-stats", PR_O2_SOCKSTAT, PR_CAP_FE, 0, 0 }, |
| 159 | { "tcp-smart-accept", PR_O2_SMARTACC, PR_CAP_FE, 0, 0 }, |
| 160 | { "tcp-smart-connect", PR_O2_SMARTCON, PR_CAP_BE, 0, 0 }, |
| 161 | { "independant-streams", PR_O2_INDEPSTR, PR_CAP_FE|PR_CAP_BE, 0, 0 }, |
| 162 | { "http-use-proxy-header", PR_O2_USE_PXHDR, PR_CAP_FE, 0, PR_MODE_HTTP }, |
Willy Tarreau | e52564c | 2010-04-27 22:19:14 +0200 | [diff] [blame] | 163 | { "http-pretend-keepalive", PR_O2_FAKE_KA, PR_CAP_FE|PR_CAP_BE, 0, PR_MODE_HTTP }, |
Willy Tarreau | 96e3121 | 2011-05-30 18:10:30 +0200 | [diff] [blame] | 164 | { "http-no-delay", PR_O2_NODELAY, PR_CAP_FE|PR_CAP_BE, 0, PR_MODE_HTTP }, |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 165 | { NULL, 0, 0, 0 } |
| 166 | }; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 167 | |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 168 | static char *cursection = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 169 | static struct proxy defproxy; /* fake proxy used to assign default values on all instances */ |
| 170 | int cfg_maxpconn = DEFAULT_MAXCONN; /* # of simultaneous connections per proxy (-N) */ |
Willy Tarreau | 5af24ef | 2009-03-15 15:23:16 +0100 | [diff] [blame] | 171 | int cfg_maxconn = 0; /* # of simultaneous connections, (-n) */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 172 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 173 | /* List head of all known configuration keywords */ |
| 174 | static struct cfg_kw_list cfg_keywords = { |
| 175 | .list = LIST_HEAD_INIT(cfg_keywords.list) |
| 176 | }; |
| 177 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 178 | /* |
| 179 | * converts <str> to a list of listeners which are dynamically allocated. |
| 180 | * The format is "{addr|'*'}:port[-end][,{addr|'*'}:port[-end]]*", where : |
| 181 | * - <addr> can be empty or "*" to indicate INADDR_ANY ; |
| 182 | * - <port> is a numerical port from 1 to 65535 ; |
| 183 | * - <end> indicates to use the range from <port> to <end> instead (inclusive). |
| 184 | * This can be repeated as many times as necessary, separated by a coma. |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 185 | * Function returns 1 for success or 0 if error. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 186 | */ |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 187 | static int str2listener(char *str, struct proxy *curproxy, const char *file, int line) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 188 | { |
| 189 | struct listener *l; |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 190 | char *next, *dupstr; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 191 | int port, end; |
| 192 | |
| 193 | next = dupstr = strdup(str); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 194 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 195 | while (next && *next) { |
| 196 | struct sockaddr_storage ss; |
| 197 | |
| 198 | str = next; |
| 199 | /* 1) look for the end of the first address */ |
Krzysztof Piotr Oledzki | 52d522b | 2009-01-27 16:57:08 +0100 | [diff] [blame] | 200 | if ((next = strchr(str, ',')) != NULL) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 201 | *next++ = 0; |
| 202 | } |
| 203 | |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 204 | if (*str == '/') { |
| 205 | /* sun_path during a soft_stop rename is <unix_bind_prefix><path>.<pid>.<bak|tmp> */ |
| 206 | /* so compute max path */ |
| 207 | int prefix_path_len = global.unix_bind.prefix ? strlen(global.unix_bind.prefix) : 0; |
| 208 | int max_path_len = (sizeof(((struct sockaddr_un *)&ss)->sun_path) - 1) - (prefix_path_len + 1 + 5 + 1 + 3); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 209 | |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 210 | if (strlen(str) > max_path_len) { |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 211 | Alert("parsing [%s:%d] : socket path '%s' too long (max %d)\n", |
| 212 | file, line, str, max_path_len); |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 213 | goto fail; |
| 214 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 215 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 216 | memset(&ss, 0, sizeof(ss)); |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 217 | ss.ss_family = AF_UNIX; |
| 218 | if (global.unix_bind.prefix) { |
| 219 | memcpy(((struct sockaddr_un *)&ss)->sun_path, global.unix_bind.prefix, prefix_path_len); |
| 220 | strcpy(((struct sockaddr_un *)&ss)->sun_path+prefix_path_len, str); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 221 | } |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 222 | else { |
| 223 | strcpy(((struct sockaddr_un *)&ss)->sun_path, str); |
| 224 | } |
| 225 | port = end = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 226 | } |
| 227 | else { |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 228 | struct sockaddr_storage *ss2; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 229 | |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 230 | ss2 = str2sa_range(str, &port, &end); |
| 231 | if (!ss2) { |
| 232 | Alert("parsing [%s:%d] : invalid listening address: '%s'\n", |
| 233 | file, line, str); |
| 234 | goto fail; |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 235 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 236 | |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 237 | if (!port) { |
| 238 | Alert("parsing [%s:%d] : missing port number: '%s'\n", |
| 239 | file, line, str); |
| 240 | goto fail; |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 241 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 242 | |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 243 | /* OK the address looks correct */ |
| 244 | ss = *ss2; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 245 | |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 246 | if (port < 1 || port > 65535) { |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 247 | Alert("parsing [%s:%d] : invalid port '%d' specified for address '%s'.\n", |
| 248 | file, line, port, str); |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 249 | goto fail; |
| 250 | } |
| 251 | |
| 252 | if (end < 1 || end > 65535) { |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 253 | Alert("parsing [%s:%d] : invalid port '%d' specified for address '%s'.\n", |
| 254 | file, line, end, str); |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 255 | goto fail; |
| 256 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | for (; port <= end; port++) { |
| 260 | l = (struct listener *)calloc(1, sizeof(struct listener)); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 261 | l->next = curproxy->listen; |
| 262 | curproxy->listen = l; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 263 | |
| 264 | l->fd = -1; |
| 265 | l->addr = ss; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 266 | l->state = LI_INIT; |
| 267 | |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 268 | if (ss.ss_family == AF_INET) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 269 | ((struct sockaddr_in *)(&l->addr))->sin_port = htons(port); |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 270 | tcpv4_add_listener(l); |
| 271 | } |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 272 | else if (ss.ss_family == AF_INET6) { |
| 273 | ((struct sockaddr_in6 *)(&l->addr))->sin6_port = htons(port); |
| 274 | tcpv6_add_listener(l); |
| 275 | } |
| 276 | else { |
| 277 | l->perm.ux.gid = l->perm.ux.uid = -1; |
| 278 | l->perm.ux.mode = 0; |
| 279 | uxst_add_listener(l); |
| 280 | } |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 281 | |
Willy Tarreau | af7ad00 | 2010-08-31 15:39:26 +0200 | [diff] [blame] | 282 | jobs++; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 283 | listeners++; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 284 | } /* end for(port) */ |
| 285 | } /* end while(next) */ |
| 286 | free(dupstr); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 287 | return 1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 288 | fail: |
| 289 | free(dupstr); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 290 | return 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 291 | } |
| 292 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 293 | /* |
| 294 | * Sends a warning if proxy <proxy> does not have at least one of the |
| 295 | * capabilities in <cap>. An optionnal <hint> may be added at the end |
| 296 | * of the warning to help the user. Returns 1 if a warning was emitted |
| 297 | * or 0 if the condition is valid. |
| 298 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 299 | int warnifnotcap(struct proxy *proxy, int cap, const char *file, int line, const char *arg, const char *hint) |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 300 | { |
| 301 | char *msg; |
| 302 | |
| 303 | switch (cap) { |
| 304 | case PR_CAP_BE: msg = "no backend"; break; |
| 305 | case PR_CAP_FE: msg = "no frontend"; break; |
| 306 | case PR_CAP_RS: msg = "no ruleset"; break; |
| 307 | case PR_CAP_BE|PR_CAP_FE: msg = "neither frontend nor backend"; break; |
| 308 | default: msg = "not enough"; break; |
| 309 | } |
| 310 | |
| 311 | if (!(proxy->cap & cap)) { |
| 312 | 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] | 313 | file, line, arg, proxy_type_str(proxy), proxy->id, msg, hint ? hint : ""); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 314 | return 1; |
| 315 | } |
| 316 | return 0; |
| 317 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 318 | |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 319 | /* Report a warning if a rule is placed after a 'block' rule. |
| 320 | * Return 1 if the warning has been emitted, otherwise 0. |
| 321 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 322 | int warnif_rule_after_block(struct proxy *proxy, const char *file, int line, const char *arg) |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 323 | { |
| 324 | if (!LIST_ISEMPTY(&proxy->block_cond)) { |
| 325 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'block' rule will still be processed before.\n", |
| 326 | file, line, arg); |
| 327 | return 1; |
| 328 | } |
| 329 | return 0; |
| 330 | } |
| 331 | |
| 332 | /* Report a warning if a rule is placed after a reqrewrite rule. |
| 333 | * Return 1 if the warning has been emitted, otherwise 0. |
| 334 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 335 | int warnif_rule_after_reqxxx(struct proxy *proxy, const char *file, int line, const char *arg) |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 336 | { |
| 337 | if (proxy->req_exp) { |
| 338 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'reqxxx' rule will still be processed before.\n", |
| 339 | file, line, arg); |
| 340 | return 1; |
| 341 | } |
| 342 | return 0; |
| 343 | } |
| 344 | |
| 345 | /* Report a warning if a rule is placed after a reqadd rule. |
| 346 | * Return 1 if the warning has been emitted, otherwise 0. |
| 347 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 348 | int warnif_rule_after_reqadd(struct proxy *proxy, const char *file, int line, const char *arg) |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 349 | { |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 350 | if (!LIST_ISEMPTY(&proxy->req_add)) { |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 351 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'reqadd' rule will still be processed before.\n", |
| 352 | file, line, arg); |
| 353 | return 1; |
| 354 | } |
| 355 | return 0; |
| 356 | } |
| 357 | |
| 358 | /* Report a warning if a rule is placed after a redirect rule. |
| 359 | * Return 1 if the warning has been emitted, otherwise 0. |
| 360 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 361 | int warnif_rule_after_redirect(struct proxy *proxy, const char *file, int line, const char *arg) |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 362 | { |
| 363 | if (!LIST_ISEMPTY(&proxy->redirect_rules)) { |
| 364 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'redirect' rule will still be processed before.\n", |
| 365 | file, line, arg); |
| 366 | return 1; |
| 367 | } |
| 368 | return 0; |
| 369 | } |
| 370 | |
| 371 | /* Report a warning if a rule is placed after a 'use_backend' rule. |
| 372 | * Return 1 if the warning has been emitted, otherwise 0. |
| 373 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 374 | int warnif_rule_after_use_backend(struct proxy *proxy, const char *file, int line, const char *arg) |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 375 | { |
| 376 | if (!LIST_ISEMPTY(&proxy->switching_rules)) { |
| 377 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'use_backend' rule will still be processed before.\n", |
| 378 | file, line, arg); |
| 379 | return 1; |
| 380 | } |
| 381 | return 0; |
| 382 | } |
| 383 | |
| 384 | /* report a warning if a block rule is dangerously placed */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 385 | int warnif_misplaced_block(struct proxy *proxy, const char *file, int line, const char *arg) |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 386 | { |
| 387 | return warnif_rule_after_reqxxx(proxy, file, line, arg) || |
| 388 | warnif_rule_after_reqadd(proxy, file, line, arg) || |
| 389 | warnif_rule_after_redirect(proxy, file, line, arg) || |
| 390 | warnif_rule_after_use_backend(proxy, file, line, arg); |
| 391 | } |
| 392 | |
| 393 | /* report a warning if a reqxxx rule is dangerously placed */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 394 | int warnif_misplaced_reqxxx(struct proxy *proxy, const char *file, int line, const char *arg) |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 395 | { |
| 396 | return warnif_rule_after_reqadd(proxy, file, line, arg) || |
| 397 | warnif_rule_after_redirect(proxy, file, line, arg) || |
| 398 | warnif_rule_after_use_backend(proxy, file, line, arg); |
| 399 | } |
| 400 | |
| 401 | /* report a warning if a reqadd rule is dangerously placed */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 402 | int warnif_misplaced_reqadd(struct proxy *proxy, const char *file, int line, const char *arg) |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 403 | { |
| 404 | return warnif_rule_after_redirect(proxy, file, line, arg) || |
| 405 | warnif_rule_after_use_backend(proxy, file, line, arg); |
| 406 | } |
| 407 | |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 408 | /* Report it if a request ACL condition uses some response-only parameters. It |
| 409 | * returns either 0 or ERR_WARN so that its result can be or'ed with err_code. |
| 410 | * Note that <cond> may be NULL and then will be ignored. |
| 411 | */ |
| 412 | static int warnif_cond_requires_resp(const struct acl_cond *cond, const char *file, int line) |
| 413 | { |
| 414 | struct acl *acl; |
| 415 | |
| 416 | if (!cond || !(cond->requires & ACL_USE_RTR_ANY)) |
| 417 | return 0; |
| 418 | |
| 419 | acl = cond_find_require(cond, ACL_USE_RTR_ANY); |
| 420 | Warning("parsing [%s:%d] : acl '%s' involves some response-only criteria which will be ignored.\n", |
| 421 | file, line, acl ? acl->name : "(unknown)"); |
| 422 | return ERR_WARN; |
| 423 | } |
| 424 | |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 425 | /* Report it if a request ACL condition uses some request-only volatile parameters. |
| 426 | * It returns either 0 or ERR_WARN so that its result can be or'ed with err_code. |
| 427 | * Note that <cond> may be NULL and then will be ignored. |
| 428 | */ |
| 429 | static int warnif_cond_requires_req(const struct acl_cond *cond, const char *file, int line) |
| 430 | { |
| 431 | struct acl *acl; |
| 432 | |
| 433 | if (!cond || !(cond->requires & ACL_USE_REQ_VOLATILE)) |
| 434 | return 0; |
| 435 | |
| 436 | acl = cond_find_require(cond, ACL_USE_REQ_VOLATILE); |
| 437 | Warning("parsing [%s:%d] : acl '%s' involves some volatile request-only criteria which will be ignored.\n", |
| 438 | file, line, acl ? acl->name : "(unknown)"); |
| 439 | return ERR_WARN; |
| 440 | } |
| 441 | |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 442 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 443 | /* |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 444 | * parse a line in a <global> section. Returns the error code, 0 if OK, or |
| 445 | * any combination of : |
| 446 | * - ERR_ABORT: must abort ASAP |
| 447 | * - ERR_FATAL: we can continue parsing but not start the service |
| 448 | * - ERR_WARN: a warning has been emitted |
| 449 | * - ERR_ALERT: an alert has been emitted |
| 450 | * Only the two first ones can stop processing, the two others are just |
| 451 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 452 | */ |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 453 | int cfg_parse_global(const char *file, int linenum, char **args, int kwm) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 454 | { |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 455 | int err_code = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 456 | |
| 457 | if (!strcmp(args[0], "global")) { /* new section */ |
| 458 | /* no option, nothing special to do */ |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 459 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 460 | } |
| 461 | else if (!strcmp(args[0], "daemon")) { |
| 462 | global.mode |= MODE_DAEMON; |
| 463 | } |
| 464 | else if (!strcmp(args[0], "debug")) { |
| 465 | global.mode |= MODE_DEBUG; |
| 466 | } |
| 467 | else if (!strcmp(args[0], "noepoll")) { |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 468 | global.tune.options &= ~GTUNE_USE_EPOLL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 469 | } |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 470 | else if (!strcmp(args[0], "nosepoll")) { |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 471 | global.tune.options &= ~GTUNE_USE_SEPOLL; |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 472 | } |
| 473 | else if (!strcmp(args[0], "nokqueue")) { |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 474 | global.tune.options &= ~GTUNE_USE_KQUEUE; |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 475 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 476 | else if (!strcmp(args[0], "nopoll")) { |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 477 | global.tune.options &= ~GTUNE_USE_POLL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 478 | } |
Willy Tarreau | 3ab68cf | 2009-01-25 16:03:28 +0100 | [diff] [blame] | 479 | else if (!strcmp(args[0], "nosplice")) { |
| 480 | global.tune.options &= ~GTUNE_USE_SPLICE; |
| 481 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 482 | else if (!strcmp(args[0], "quiet")) { |
| 483 | global.mode |= MODE_QUIET; |
| 484 | } |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 485 | else if (!strcmp(args[0], "tune.maxpollevents")) { |
| 486 | if (global.tune.maxpollevents != 0) { |
| 487 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 488 | err_code |= ERR_ALERT; |
| 489 | goto out; |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 490 | } |
| 491 | if (*(args[1]) == 0) { |
| 492 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 493 | err_code |= ERR_ALERT | ERR_FATAL; |
| 494 | goto out; |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 495 | } |
| 496 | global.tune.maxpollevents = atol(args[1]); |
| 497 | } |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 498 | else if (!strcmp(args[0], "tune.maxaccept")) { |
| 499 | if (global.tune.maxaccept != 0) { |
| 500 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 501 | err_code |= ERR_ALERT; |
| 502 | goto out; |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 503 | } |
| 504 | if (*(args[1]) == 0) { |
| 505 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 506 | err_code |= ERR_ALERT | ERR_FATAL; |
| 507 | goto out; |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 508 | } |
| 509 | global.tune.maxaccept = atol(args[1]); |
| 510 | } |
Willy Tarreau | 43961d5 | 2010-10-04 20:39:20 +0200 | [diff] [blame] | 511 | else if (!strcmp(args[0], "tune.chksize")) { |
| 512 | if (*(args[1]) == 0) { |
| 513 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 514 | err_code |= ERR_ALERT | ERR_FATAL; |
| 515 | goto out; |
| 516 | } |
| 517 | global.tune.chksize = atol(args[1]); |
| 518 | } |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 519 | else if (!strcmp(args[0], "tune.bufsize")) { |
| 520 | if (*(args[1]) == 0) { |
| 521 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 522 | err_code |= ERR_ALERT | ERR_FATAL; |
| 523 | goto out; |
| 524 | } |
| 525 | global.tune.bufsize = atol(args[1]); |
| 526 | if (global.tune.maxrewrite >= global.tune.bufsize / 2) |
| 527 | global.tune.maxrewrite = global.tune.bufsize / 2; |
| 528 | } |
| 529 | else if (!strcmp(args[0], "tune.maxrewrite")) { |
| 530 | if (*(args[1]) == 0) { |
| 531 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 532 | err_code |= ERR_ALERT | ERR_FATAL; |
| 533 | goto out; |
| 534 | } |
| 535 | global.tune.maxrewrite = atol(args[1]); |
| 536 | if (global.tune.maxrewrite >= global.tune.bufsize / 2) |
| 537 | global.tune.maxrewrite = global.tune.bufsize / 2; |
| 538 | } |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 539 | else if (!strcmp(args[0], "tune.rcvbuf.client")) { |
| 540 | if (global.tune.client_rcvbuf != 0) { |
| 541 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 542 | err_code |= ERR_ALERT; |
| 543 | goto out; |
| 544 | } |
| 545 | if (*(args[1]) == 0) { |
| 546 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 547 | err_code |= ERR_ALERT | ERR_FATAL; |
| 548 | goto out; |
| 549 | } |
| 550 | global.tune.client_rcvbuf = atol(args[1]); |
| 551 | } |
| 552 | else if (!strcmp(args[0], "tune.rcvbuf.server")) { |
| 553 | if (global.tune.server_rcvbuf != 0) { |
| 554 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 555 | err_code |= ERR_ALERT; |
| 556 | goto out; |
| 557 | } |
| 558 | if (*(args[1]) == 0) { |
| 559 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 560 | err_code |= ERR_ALERT | ERR_FATAL; |
| 561 | goto out; |
| 562 | } |
| 563 | global.tune.server_rcvbuf = atol(args[1]); |
| 564 | } |
| 565 | else if (!strcmp(args[0], "tune.sndbuf.client")) { |
| 566 | if (global.tune.client_sndbuf != 0) { |
| 567 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 568 | err_code |= ERR_ALERT; |
| 569 | goto out; |
| 570 | } |
| 571 | if (*(args[1]) == 0) { |
| 572 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 573 | err_code |= ERR_ALERT | ERR_FATAL; |
| 574 | goto out; |
| 575 | } |
| 576 | global.tune.client_sndbuf = atol(args[1]); |
| 577 | } |
| 578 | else if (!strcmp(args[0], "tune.sndbuf.server")) { |
| 579 | if (global.tune.server_sndbuf != 0) { |
| 580 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 581 | err_code |= ERR_ALERT; |
| 582 | goto out; |
| 583 | } |
| 584 | if (*(args[1]) == 0) { |
| 585 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 586 | err_code |= ERR_ALERT | ERR_FATAL; |
| 587 | goto out; |
| 588 | } |
| 589 | global.tune.server_sndbuf = atol(args[1]); |
| 590 | } |
Willy Tarreau | bd9a0a7 | 2011-10-23 21:14:29 +0200 | [diff] [blame] | 591 | else if (!strcmp(args[0], "tune.pipesize")) { |
| 592 | if (*(args[1]) == 0) { |
| 593 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 594 | err_code |= ERR_ALERT | ERR_FATAL; |
| 595 | goto out; |
| 596 | } |
| 597 | global.tune.pipesize = atol(args[1]); |
| 598 | } |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame^] | 599 | else if (!strcmp(args[0], "tune.http.maxhdr")) { |
| 600 | if (*(args[1]) == 0) { |
| 601 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 602 | err_code |= ERR_ALERT | ERR_FATAL; |
| 603 | goto out; |
| 604 | } |
| 605 | global.tune.max_http_hdr = atol(args[1]); |
| 606 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 607 | else if (!strcmp(args[0], "uid")) { |
| 608 | if (global.uid != 0) { |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 609 | Alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 610 | err_code |= ERR_ALERT; |
| 611 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 612 | } |
| 613 | if (*(args[1]) == 0) { |
| 614 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 615 | err_code |= ERR_ALERT | ERR_FATAL; |
| 616 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 617 | } |
| 618 | global.uid = atol(args[1]); |
| 619 | } |
| 620 | else if (!strcmp(args[0], "gid")) { |
| 621 | if (global.gid != 0) { |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 622 | Alert("parsing [%s:%d] : group/gid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 623 | err_code |= ERR_ALERT; |
| 624 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 625 | } |
| 626 | if (*(args[1]) == 0) { |
| 627 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 628 | err_code |= ERR_ALERT | ERR_FATAL; |
| 629 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 630 | } |
| 631 | global.gid = atol(args[1]); |
| 632 | } |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 633 | /* user/group name handling */ |
| 634 | else if (!strcmp(args[0], "user")) { |
| 635 | struct passwd *ha_user; |
| 636 | if (global.uid != 0) { |
| 637 | Alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 638 | err_code |= ERR_ALERT; |
| 639 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 640 | } |
| 641 | errno = 0; |
| 642 | ha_user = getpwnam(args[1]); |
| 643 | if (ha_user != NULL) { |
| 644 | global.uid = (int)ha_user->pw_uid; |
| 645 | } |
| 646 | else { |
| 647 | Alert("parsing [%s:%d] : cannot find user id for '%s' (%d:%s)\n", file, linenum, args[1], errno, strerror(errno)); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 648 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 649 | } |
| 650 | } |
| 651 | else if (!strcmp(args[0], "group")) { |
| 652 | struct group *ha_group; |
| 653 | if (global.gid != 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 654 | Alert("parsing [%s:%d] : gid/group was already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 655 | err_code |= ERR_ALERT; |
| 656 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 657 | } |
| 658 | errno = 0; |
| 659 | ha_group = getgrnam(args[1]); |
| 660 | if (ha_group != NULL) { |
| 661 | global.gid = (int)ha_group->gr_gid; |
| 662 | } |
| 663 | else { |
| 664 | Alert("parsing [%s:%d] : cannot find group id for '%s' (%d:%s)\n", file, linenum, args[1], errno, strerror(errno)); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 665 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 666 | } |
| 667 | } |
| 668 | /* end of user/group name handling*/ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 669 | else if (!strcmp(args[0], "nbproc")) { |
| 670 | if (global.nbproc != 0) { |
| 671 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 672 | err_code |= ERR_ALERT; |
| 673 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 674 | } |
| 675 | if (*(args[1]) == 0) { |
| 676 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 677 | err_code |= ERR_ALERT | ERR_FATAL; |
| 678 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 679 | } |
| 680 | global.nbproc = atol(args[1]); |
| 681 | } |
| 682 | else if (!strcmp(args[0], "maxconn")) { |
| 683 | if (global.maxconn != 0) { |
| 684 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 685 | err_code |= ERR_ALERT; |
| 686 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 687 | } |
| 688 | if (*(args[1]) == 0) { |
| 689 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 690 | err_code |= ERR_ALERT | ERR_FATAL; |
| 691 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 692 | } |
| 693 | global.maxconn = atol(args[1]); |
| 694 | #ifdef SYSTEM_MAXCONN |
| 695 | if (global.maxconn > DEFAULT_MAXCONN && cfg_maxconn <= DEFAULT_MAXCONN) { |
| 696 | 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); |
| 697 | global.maxconn = DEFAULT_MAXCONN; |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 698 | err_code |= ERR_ALERT; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 699 | } |
| 700 | #endif /* SYSTEM_MAXCONN */ |
| 701 | } |
Willy Tarreau | 81c25d0 | 2011-09-07 15:17:21 +0200 | [diff] [blame] | 702 | else if (!strcmp(args[0], "maxconnrate")) { |
| 703 | if (global.cps_lim != 0) { |
| 704 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 705 | err_code |= ERR_ALERT; |
| 706 | goto out; |
| 707 | } |
| 708 | if (*(args[1]) == 0) { |
| 709 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 710 | err_code |= ERR_ALERT | ERR_FATAL; |
| 711 | goto out; |
| 712 | } |
| 713 | global.cps_lim = atol(args[1]); |
| 714 | } |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 715 | else if (!strcmp(args[0], "maxpipes")) { |
| 716 | if (global.maxpipes != 0) { |
| 717 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 718 | err_code |= ERR_ALERT; |
| 719 | goto out; |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 720 | } |
| 721 | if (*(args[1]) == 0) { |
| 722 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 723 | err_code |= ERR_ALERT | ERR_FATAL; |
| 724 | goto out; |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 725 | } |
| 726 | global.maxpipes = atol(args[1]); |
| 727 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 728 | else if (!strcmp(args[0], "ulimit-n")) { |
| 729 | if (global.rlimit_nofile != 0) { |
| 730 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 731 | err_code |= ERR_ALERT; |
| 732 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 733 | } |
| 734 | if (*(args[1]) == 0) { |
| 735 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 736 | err_code |= ERR_ALERT | ERR_FATAL; |
| 737 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 738 | } |
| 739 | global.rlimit_nofile = atol(args[1]); |
| 740 | } |
| 741 | else if (!strcmp(args[0], "chroot")) { |
| 742 | if (global.chroot != NULL) { |
| 743 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 744 | err_code |= ERR_ALERT; |
| 745 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 746 | } |
| 747 | if (*(args[1]) == 0) { |
| 748 | Alert("parsing [%s:%d] : '%s' expects a directory as an argument.\n", file, linenum, args[0]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 749 | err_code |= ERR_ALERT | ERR_FATAL; |
| 750 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 751 | } |
| 752 | global.chroot = strdup(args[1]); |
| 753 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 754 | else if (!strcmp(args[0], "description")) { |
| 755 | int i, len=0; |
| 756 | char *d; |
| 757 | |
| 758 | if (!*args[1]) { |
| 759 | Alert("parsing [%s:%d]: '%s' expects a string argument.\n", |
| 760 | file, linenum, args[0]); |
| 761 | err_code |= ERR_ALERT | ERR_FATAL; |
| 762 | goto out; |
| 763 | } |
| 764 | |
| 765 | for(i=1; *args[i]; i++) |
| 766 | len += strlen(args[i])+1; |
| 767 | |
| 768 | if (global.desc) |
| 769 | free(global.desc); |
| 770 | |
| 771 | global.desc = d = (char *)calloc(1, len); |
| 772 | |
| 773 | d += sprintf(d, "%s", args[1]); |
| 774 | for(i=2; *args[i]; i++) |
| 775 | d += sprintf(d, " %s", args[i]); |
| 776 | } |
| 777 | else if (!strcmp(args[0], "node")) { |
| 778 | int i; |
| 779 | char c; |
| 780 | |
| 781 | for (i=0; args[1][i]; i++) { |
| 782 | c = args[1][i]; |
Willy Tarreau | 88e0581 | 2010-03-03 00:16:00 +0100 | [diff] [blame] | 783 | if (!isupper((unsigned char)c) && !islower((unsigned char)c) && |
| 784 | !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.') |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 785 | break; |
| 786 | } |
| 787 | |
| 788 | if (!i || args[1][i]) { |
| 789 | Alert("parsing [%s:%d]: '%s' requires valid node name - non-empty string" |
| 790 | " with digits(0-9), letters(A-Z, a-z), dot(.), hyphen(-) or underscode(_).\n", |
| 791 | file, linenum, args[0]); |
| 792 | err_code |= ERR_ALERT | ERR_FATAL; |
| 793 | goto out; |
| 794 | } |
| 795 | |
| 796 | if (global.node) |
| 797 | free(global.node); |
| 798 | |
| 799 | global.node = strdup(args[1]); |
| 800 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 801 | else if (!strcmp(args[0], "pidfile")) { |
| 802 | if (global.pidfile != NULL) { |
| 803 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 804 | err_code |= ERR_ALERT; |
| 805 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 806 | } |
| 807 | if (*(args[1]) == 0) { |
| 808 | Alert("parsing [%s:%d] : '%s' expects a file name as an argument.\n", file, linenum, args[0]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 809 | err_code |= ERR_ALERT | ERR_FATAL; |
| 810 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 811 | } |
| 812 | global.pidfile = strdup(args[1]); |
| 813 | } |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 814 | else if (!strcmp(args[0], "unix-bind")) { |
| 815 | int cur_arg = 1; |
| 816 | while (*(args[cur_arg])) { |
| 817 | if (!strcmp(args[cur_arg], "prefix")) { |
| 818 | if (global.unix_bind.prefix != NULL) { |
| 819 | Alert("parsing [%s:%d] : unix-bind '%s' already specified. Continuing.\n", file, linenum, args[cur_arg]); |
| 820 | err_code |= ERR_ALERT; |
| 821 | cur_arg += 2; |
| 822 | continue; |
| 823 | } |
| 824 | |
| 825 | if (*(args[cur_arg+1]) == 0) { |
| 826 | Alert("parsing [%s:%d] : unix_bind '%s' expects a path as an argument.\n", file, linenum, args[cur_arg]); |
| 827 | err_code |= ERR_ALERT | ERR_FATAL; |
| 828 | goto out; |
| 829 | } |
| 830 | global.unix_bind.prefix = strdup(args[cur_arg+1]); |
| 831 | cur_arg += 2; |
| 832 | continue; |
| 833 | } |
| 834 | |
| 835 | if (!strcmp(args[cur_arg], "mode")) { |
| 836 | |
| 837 | global.unix_bind.ux.mode = strtol(args[cur_arg + 1], NULL, 8); |
| 838 | cur_arg += 2; |
| 839 | continue; |
| 840 | } |
| 841 | |
| 842 | if (!strcmp(args[cur_arg], "uid")) { |
| 843 | |
| 844 | global.unix_bind.ux.uid = atol(args[cur_arg + 1 ]); |
| 845 | cur_arg += 2; |
| 846 | continue; |
| 847 | } |
| 848 | |
| 849 | if (!strcmp(args[cur_arg], "gid")) { |
| 850 | |
| 851 | global.unix_bind.ux.gid = atol(args[cur_arg + 1 ]); |
| 852 | cur_arg += 2; |
| 853 | continue; |
| 854 | } |
| 855 | |
| 856 | if (!strcmp(args[cur_arg], "user")) { |
| 857 | struct passwd *user; |
| 858 | |
| 859 | user = getpwnam(args[cur_arg + 1]); |
| 860 | if (!user) { |
| 861 | Alert("parsing [%s:%d] : '%s' : '%s' unknown user.\n", |
| 862 | file, linenum, args[0], args[cur_arg + 1 ]); |
| 863 | err_code |= ERR_ALERT | ERR_FATAL; |
| 864 | goto out; |
| 865 | } |
| 866 | |
| 867 | global.unix_bind.ux.uid = user->pw_uid; |
| 868 | cur_arg += 2; |
| 869 | continue; |
| 870 | } |
| 871 | |
| 872 | if (!strcmp(args[cur_arg], "group")) { |
| 873 | struct group *group; |
| 874 | |
| 875 | group = getgrnam(args[cur_arg + 1]); |
| 876 | if (!group) { |
| 877 | Alert("parsing [%s:%d] : '%s' : '%s' unknown group.\n", |
| 878 | file, linenum, args[0], args[cur_arg + 1 ]); |
| 879 | err_code |= ERR_ALERT | ERR_FATAL; |
| 880 | goto out; |
| 881 | } |
| 882 | |
| 883 | global.unix_bind.ux.gid = group->gr_gid; |
| 884 | cur_arg += 2; |
| 885 | continue; |
| 886 | } |
| 887 | |
Willy Tarreau | b48f958 | 2011-09-05 01:17:06 +0200 | [diff] [blame] | 888 | Alert("parsing [%s:%d] : '%s' only supports the 'prefix', 'mode', 'uid', 'gid', 'user' and 'group' options.\n", |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 889 | file, linenum, args[0]); |
| 890 | err_code |= ERR_ALERT | ERR_FATAL; |
| 891 | goto out; |
| 892 | } |
| 893 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 894 | else if (!strcmp(args[0], "log")) { /* syslog server address */ |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 895 | struct logsrv logsrv; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 896 | int facility, level, minlvl; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 897 | |
| 898 | if (*(args[1]) == 0 || *(args[2]) == 0) { |
| 899 | Alert("parsing [%s:%d] : '%s' expects <address> and <facility> as arguments.\n", file, linenum, args[0]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 900 | err_code |= ERR_ALERT | ERR_FATAL; |
| 901 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 902 | } |
| 903 | |
| 904 | facility = get_log_facility(args[2]); |
| 905 | if (facility < 0) { |
| 906 | Alert("parsing [%s:%d] : unknown log facility '%s'\n", file, linenum, args[2]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 907 | err_code |= ERR_ALERT | ERR_FATAL; |
| 908 | facility = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 909 | } |
| 910 | |
| 911 | level = 7; /* max syslog level = debug */ |
| 912 | if (*(args[3])) { |
| 913 | level = get_log_level(args[3]); |
| 914 | if (level < 0) { |
| 915 | Alert("parsing [%s:%d] : unknown optional log level '%s'\n", file, linenum, args[3]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 916 | err_code |= ERR_ALERT | ERR_FATAL; |
| 917 | level = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 918 | } |
| 919 | } |
| 920 | |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 921 | minlvl = 0; /* limit syslog level to this level (emerg) */ |
| 922 | if (*(args[4])) { |
| 923 | minlvl = get_log_level(args[4]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 924 | if (minlvl < 0) { |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 925 | Alert("parsing [%s:%d] : unknown optional minimum log level '%s'\n", file, linenum, args[4]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 926 | err_code |= ERR_ALERT | ERR_FATAL; |
| 927 | minlvl = 0; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 928 | } |
| 929 | } |
| 930 | |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 931 | if (args[1][0] == '/') { |
David du Colombier | 11bcb6c | 2011-03-24 12:23:00 +0100 | [diff] [blame] | 932 | struct sockaddr_storage *sk = (struct sockaddr_storage *)str2sun(args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 933 | if (!sk) { |
| 934 | Alert("parsing [%s:%d] : Socket path '%s' too long (max %d)\n", file, linenum, |
David du Colombier | 11bcb6c | 2011-03-24 12:23:00 +0100 | [diff] [blame] | 935 | args[1], (int)sizeof(((struct sockaddr_un *)&sk)->sun_path) - 1); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 936 | err_code |= ERR_ALERT | ERR_FATAL; |
| 937 | goto out; |
| 938 | } |
David du Colombier | 11bcb6c | 2011-03-24 12:23:00 +0100 | [diff] [blame] | 939 | logsrv.addr = *sk; |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 940 | } else { |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 941 | struct sockaddr_storage *sk = str2sa(args[1]); |
David du Colombier | 11bcb6c | 2011-03-24 12:23:00 +0100 | [diff] [blame] | 942 | if (!sk) { |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 943 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[1]); |
| 944 | err_code |= ERR_ALERT | ERR_FATAL; |
| 945 | goto out; |
| 946 | } |
David du Colombier | 11bcb6c | 2011-03-24 12:23:00 +0100 | [diff] [blame] | 947 | logsrv.addr = *sk; |
| 948 | if (!get_host_port(&logsrv.addr)) |
| 949 | set_host_port(&logsrv.addr, SYSLOG_PORT); |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 950 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 951 | |
| 952 | if (global.logfac1 == -1) { |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 953 | global.logsrv1 = logsrv; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 954 | global.logfac1 = facility; |
| 955 | global.loglev1 = level; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 956 | global.minlvl1 = minlvl; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 957 | } |
| 958 | else if (global.logfac2 == -1) { |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 959 | global.logsrv2 = logsrv; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 960 | global.logfac2 = facility; |
| 961 | global.loglev2 = level; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 962 | global.minlvl2 = minlvl; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 963 | } |
| 964 | else { |
| 965 | Alert("parsing [%s:%d] : too many syslog servers\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 966 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 967 | } |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 968 | } |
Joe Williams | df5b38f | 2010-12-29 17:05:48 +0100 | [diff] [blame] | 969 | else if (!strcmp(args[0], "log-send-hostname")) { /* set the hostname in syslog header */ |
| 970 | char *name; |
| 971 | int len; |
| 972 | |
| 973 | if (global.log_send_hostname != NULL) { |
| 974 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 975 | err_code |= ERR_ALERT; |
| 976 | goto out; |
| 977 | } |
| 978 | |
| 979 | if (*(args[1])) |
| 980 | name = args[1]; |
| 981 | else |
| 982 | name = hostname; |
| 983 | |
| 984 | len = strlen(name); |
| 985 | |
| 986 | /* We'll add a space after the name to respect the log format */ |
| 987 | free(global.log_send_hostname); |
| 988 | global.log_send_hostname = malloc(len + 2); |
| 989 | snprintf(global.log_send_hostname, len + 2, "%s ", name); |
| 990 | } |
Kevinm | 48936af | 2010-12-22 16:08:21 +0000 | [diff] [blame] | 991 | else if (!strcmp(args[0], "log-tag")) { /* tag to report to syslog */ |
| 992 | if (*(args[1]) == 0) { |
| 993 | Alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]); |
| 994 | err_code |= ERR_ALERT | ERR_FATAL; |
| 995 | goto out; |
| 996 | } |
| 997 | free(global.log_tag); |
| 998 | global.log_tag = strdup(args[1]); |
| 999 | } |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1000 | else if (!strcmp(args[0], "spread-checks")) { /* random time between checks (0-50) */ |
| 1001 | if (global.spread_checks != 0) { |
| 1002 | Alert("parsing [%s:%d]: spread-checks already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1003 | err_code |= ERR_ALERT; |
| 1004 | goto out; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1005 | } |
| 1006 | if (*(args[1]) == 0) { |
| 1007 | Alert("parsing [%s:%d]: '%s' expects an integer argument (0..50).\n", file, linenum, args[0]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1008 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1009 | goto out; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1010 | } |
| 1011 | global.spread_checks = atol(args[1]); |
| 1012 | if (global.spread_checks < 0 || global.spread_checks > 50) { |
| 1013 | Alert("parsing [%s:%d]: 'spread-checks' needs a positive value in range 0..50.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1014 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1015 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1016 | } |
| 1017 | else { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1018 | struct cfg_kw_list *kwl; |
| 1019 | int index; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1020 | int rc; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1021 | |
| 1022 | list_for_each_entry(kwl, &cfg_keywords.list, list) { |
| 1023 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 1024 | if (kwl->kw[index].section != CFG_GLOBAL) |
| 1025 | continue; |
| 1026 | if (strcmp(kwl->kw[index].kw, args[0]) == 0) { |
| 1027 | /* prepare error message just in case */ |
| 1028 | snprintf(trash, sizeof(trash), |
| 1029 | "error near '%s' in '%s' section", args[0], "global"); |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1030 | rc = kwl->kw[index].parse(args, CFG_GLOBAL, NULL, NULL, trash, sizeof(trash)); |
| 1031 | if (rc < 0) { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1032 | Alert("parsing [%s:%d] : %s\n", file, linenum, trash); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1033 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1034 | } |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1035 | else if (rc > 0) { |
| 1036 | Warning("parsing [%s:%d] : %s\n", file, linenum, trash); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1037 | err_code |= ERR_WARN; |
| 1038 | goto out; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1039 | } |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1040 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1041 | } |
| 1042 | } |
| 1043 | } |
| 1044 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1045 | Alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], "global"); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1046 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1047 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1048 | |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1049 | out: |
| 1050 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1051 | } |
| 1052 | |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 1053 | void init_default_instance() |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1054 | { |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 1055 | init_new_proxy(&defproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1056 | defproxy.mode = PR_MODE_TCP; |
| 1057 | defproxy.state = PR_STNEW; |
| 1058 | defproxy.maxconn = cfg_maxpconn; |
| 1059 | defproxy.conn_retries = CONN_RETRIES; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1060 | |
| 1061 | defproxy.defsrv.inter = DEF_CHKINTR; |
| 1062 | defproxy.defsrv.fastinter = 0; |
| 1063 | defproxy.defsrv.downinter = 0; |
| 1064 | defproxy.defsrv.rise = DEF_RISETIME; |
| 1065 | defproxy.defsrv.fall = DEF_FALLTIME; |
| 1066 | defproxy.defsrv.check_port = 0; |
| 1067 | defproxy.defsrv.maxqueue = 0; |
| 1068 | defproxy.defsrv.minconn = 0; |
| 1069 | defproxy.defsrv.maxconn = 0; |
| 1070 | defproxy.defsrv.slowstart = 0; |
| 1071 | defproxy.defsrv.onerror = DEF_HANA_ONERR; |
| 1072 | defproxy.defsrv.consecutive_errors_limit = DEF_HANA_ERRLIMIT; |
| 1073 | defproxy.defsrv.uweight = defproxy.defsrv.iweight = 1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1074 | } |
| 1075 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1076 | |
| 1077 | static int create_cond_regex_rule(const char *file, int line, |
| 1078 | struct proxy *px, int dir, int action, int flags, |
| 1079 | const char *cmd, const char *reg, const char *repl, |
| 1080 | const char **cond_start) |
| 1081 | { |
| 1082 | regex_t *preg = NULL; |
| 1083 | const char *err; |
| 1084 | int err_code = 0; |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1085 | struct acl_cond *cond = NULL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1086 | |
| 1087 | if (px == &defproxy) { |
| 1088 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, line, cmd); |
| 1089 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1090 | goto err; |
| 1091 | } |
| 1092 | |
| 1093 | if (*reg == 0) { |
| 1094 | Alert("parsing [%s:%d] : '%s' expects <regex> as an argument.\n", file, line, cmd); |
| 1095 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1096 | goto err; |
| 1097 | } |
| 1098 | |
| 1099 | if (warnifnotcap(px, PR_CAP_RS, file, line, cmd, NULL)) |
| 1100 | err_code |= ERR_WARN; |
| 1101 | |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1102 | if (cond_start && |
| 1103 | (strcmp(*cond_start, "if") == 0 || strcmp(*cond_start, "unless") == 0)) { |
| 1104 | if ((cond = build_acl_cond(file, line, px, cond_start)) == NULL) { |
| 1105 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition.\n", |
| 1106 | file, line, cmd); |
| 1107 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1108 | goto err; |
| 1109 | } |
| 1110 | } |
| 1111 | else if (cond_start && **cond_start) { |
| 1112 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 1113 | file, line, cmd, *cond_start); |
| 1114 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1115 | goto err; |
| 1116 | } |
| 1117 | |
| 1118 | if (dir == ACL_DIR_REQ) |
| 1119 | err_code |= warnif_cond_requires_resp(cond, file, line); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 1120 | else |
| 1121 | err_code |= warnif_cond_requires_req(cond, file, line); |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1122 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1123 | preg = calloc(1, sizeof(regex_t)); |
| 1124 | if (!preg) { |
| 1125 | Alert("parsing [%s:%d] : '%s' : not enough memory to build regex.\n", file, line, cmd); |
| 1126 | err_code = ERR_ALERT | ERR_FATAL; |
| 1127 | goto err; |
| 1128 | } |
| 1129 | |
| 1130 | if (regcomp(preg, reg, REG_EXTENDED | flags) != 0) { |
| 1131 | Alert("parsing [%s:%d] : '%s' : bad regular expression '%s'.\n", file, line, cmd, reg); |
| 1132 | err_code = ERR_ALERT | ERR_FATAL; |
| 1133 | goto err; |
| 1134 | } |
| 1135 | |
| 1136 | err = chain_regex((dir == ACL_DIR_REQ) ? &px->req_exp : &px->rsp_exp, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1137 | preg, action, repl ? strdup(repl) : NULL, cond); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1138 | if (repl && err) { |
| 1139 | Alert("parsing [%s:%d] : '%s' : invalid character or unterminated sequence in replacement string near '%c'.\n", |
| 1140 | file, line, cmd, *err); |
| 1141 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1142 | goto err; |
| 1143 | } |
| 1144 | |
| 1145 | if (dir == ACL_DIR_REQ && warnif_misplaced_reqxxx(px, file, line, cmd)) |
| 1146 | err_code |= ERR_WARN; |
| 1147 | |
| 1148 | return err_code; |
| 1149 | err: |
| 1150 | free(preg); |
| 1151 | return err_code; |
| 1152 | } |
| 1153 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1154 | /* |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1155 | * Parse a line in a <listen>, <frontend>, <backend> or <ruleset> section. |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1156 | * Returns the error code, 0 if OK, or any combination of : |
| 1157 | * - ERR_ABORT: must abort ASAP |
| 1158 | * - ERR_FATAL: we can continue parsing but not start the service |
| 1159 | * - ERR_WARN: a warning has been emitted |
| 1160 | * - ERR_ALERT: an alert has been emitted |
| 1161 | * Only the two first ones can stop processing, the two others are just |
| 1162 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1163 | */ |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1164 | int cfg_parse_peers(const char *file, int linenum, char **args, int kwm) |
| 1165 | { |
| 1166 | static struct peers *curpeers = NULL; |
| 1167 | struct peer *newpeer = NULL; |
| 1168 | const char *err; |
| 1169 | int err_code = 0; |
| 1170 | |
| 1171 | if (strcmp(args[0], "peers") == 0) { /* new peers section */ |
| 1172 | |
| 1173 | err = invalid_char(args[1]); |
| 1174 | if (err) { |
| 1175 | Alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 1176 | file, linenum, *err, args[0], args[1]); |
| 1177 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1178 | } |
| 1179 | |
| 1180 | for (curpeers = peers; curpeers != NULL; curpeers = curpeers->next) { |
| 1181 | /* |
| 1182 | * If there are two proxies with the same name only following |
| 1183 | * combinations are allowed: |
| 1184 | */ |
| 1185 | if (strcmp(curpeers->id, args[1]) == 0) { |
| 1186 | Warning("Parsing [%s:%d]: peers '%s' has same name as another peers (declared at %s:%d).\n", |
| 1187 | file, linenum, args[1], curpeers->conf.file, curpeers->conf.line); |
| 1188 | err_code |= ERR_WARN; |
| 1189 | } |
| 1190 | } |
| 1191 | |
| 1192 | if ((curpeers = (struct peers *)calloc(1, sizeof(struct peers))) == NULL) { |
| 1193 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1194 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1195 | goto out; |
| 1196 | } |
| 1197 | |
| 1198 | curpeers->next = peers; |
| 1199 | peers = curpeers; |
| 1200 | curpeers->conf.file = file; |
| 1201 | curpeers->conf.line = linenum; |
| 1202 | curpeers->last_change = now.tv_sec; |
| 1203 | curpeers->id = strdup(args[1]); |
| 1204 | } |
| 1205 | else if (strcmp(args[0], "peer") == 0) { /* peer definition */ |
| 1206 | char *rport, *raddr; |
| 1207 | short realport = 0; |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 1208 | struct sockaddr_storage *sk; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1209 | |
| 1210 | if (!*args[2]) { |
| 1211 | Alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n", |
| 1212 | file, linenum, args[0]); |
| 1213 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1214 | goto out; |
| 1215 | } |
| 1216 | |
| 1217 | err = invalid_char(args[1]); |
| 1218 | if (err) { |
| 1219 | Alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n", |
| 1220 | file, linenum, *err, args[1]); |
| 1221 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1222 | goto out; |
| 1223 | } |
| 1224 | |
| 1225 | if ((newpeer = (struct peer *)calloc(1, sizeof(struct peer))) == NULL) { |
| 1226 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1227 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1228 | goto out; |
| 1229 | } |
| 1230 | |
| 1231 | /* the peers are linked backwards first */ |
| 1232 | curpeers->count++; |
| 1233 | newpeer->next = curpeers->remote; |
| 1234 | curpeers->remote = newpeer; |
| 1235 | newpeer->peers = curpeers; |
| 1236 | newpeer->conf.file = file; |
| 1237 | newpeer->conf.line = linenum; |
| 1238 | |
| 1239 | newpeer->last_change = now.tv_sec; |
| 1240 | newpeer->id = strdup(args[1]); |
| 1241 | |
| 1242 | raddr = strdup(args[2]); |
Willy Tarreau | fab5a43 | 2011-03-04 15:31:53 +0100 | [diff] [blame] | 1243 | rport = strrchr(raddr, ':'); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1244 | if (rport) { |
| 1245 | *rport++ = 0; |
| 1246 | realport = atol(rport); |
| 1247 | } |
| 1248 | if (!realport) { |
| 1249 | Alert("parsing [%s:%d] : Missing or invalid port in '%s'\n", file, linenum, args[2]); |
| 1250 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1251 | goto out; |
| 1252 | } |
| 1253 | |
Willy Tarreau | fab5a43 | 2011-03-04 15:31:53 +0100 | [diff] [blame] | 1254 | sk = str2ip(raddr); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1255 | free(raddr); |
| 1256 | if (!sk) { |
| 1257 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[2]); |
| 1258 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1259 | goto out; |
| 1260 | } |
| 1261 | newpeer->addr = *sk; |
Willy Tarreau | 86ad42c | 2011-08-27 12:29:07 +0200 | [diff] [blame] | 1262 | set_host_port(&newpeer->addr, realport); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1263 | |
| 1264 | if (strcmp(newpeer->id, localpeer) == 0) { |
| 1265 | /* Current is local peer, it define a frontend */ |
| 1266 | newpeer->local = 1; |
| 1267 | |
| 1268 | if (!curpeers->peers_fe) { |
| 1269 | if ((curpeers->peers_fe = calloc(1, sizeof(struct proxy))) == NULL) { |
| 1270 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1271 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1272 | goto out; |
| 1273 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1274 | |
Willy Tarreau | 237250c | 2011-07-29 01:49:03 +0200 | [diff] [blame] | 1275 | init_new_proxy(curpeers->peers_fe); |
| 1276 | curpeers->peers_fe->parent = curpeers; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1277 | |
| 1278 | curpeers->peers_fe->last_change = now.tv_sec; |
| 1279 | curpeers->peers_fe->id = strdup(args[1]); |
| 1280 | curpeers->peers_fe->cap = PR_CAP_FE; |
Willy Tarreau | 3ae65a1 | 2011-09-07 17:40:39 +0200 | [diff] [blame] | 1281 | curpeers->peers_fe->maxconn = 0; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1282 | curpeers->peers_fe->conn_retries = CONN_RETRIES; |
| 1283 | curpeers->peers_fe->timeout.connect = 5000; |
| 1284 | curpeers->peers_fe->accept = peer_accept; |
| 1285 | curpeers->peers_fe->options2 |= PR_O2_INDEPSTR | PR_O2_SMARTCON | PR_O2_SMARTACC; |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 1286 | if (!str2listener(args[2], curpeers->peers_fe, file, linenum)) { |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1287 | err_code |= ERR_FATAL; |
| 1288 | goto out; |
| 1289 | } |
| 1290 | curpeers->peers_fe->listen->maxconn = ((struct proxy *)curpeers->peers_fe)->maxconn; |
| 1291 | curpeers->peers_fe->listen->backlog = ((struct proxy *)curpeers->peers_fe)->backlog; |
| 1292 | curpeers->peers_fe->listen->timeout = &((struct proxy *)curpeers->peers_fe)->timeout.client; |
| 1293 | curpeers->peers_fe->listen->accept = session_accept; |
| 1294 | curpeers->peers_fe->listen->frontend = ((struct proxy *)curpeers->peers_fe); |
| 1295 | curpeers->peers_fe->listen->handler = process_session; |
| 1296 | curpeers->peers_fe->listen->analysers |= ((struct proxy *)curpeers->peers_fe)->fe_req_ana; |
Willy Tarreau | 3c63fd8 | 2011-09-07 18:00:47 +0200 | [diff] [blame] | 1297 | curpeers->peers_fe->listen->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */ |
| 1298 | global.maxsock += curpeers->peers_fe->listen->maxconn; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1299 | } |
| 1300 | } |
| 1301 | } /* neither "peer" nor "peers" */ |
| 1302 | else if (*args[0] != 0) { |
| 1303 | Alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection); |
| 1304 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1305 | goto out; |
| 1306 | } |
| 1307 | |
| 1308 | out: |
| 1309 | return err_code; |
| 1310 | } |
| 1311 | |
| 1312 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 1313 | int cfg_parse_listen(const char *file, int linenum, char **args, int kwm) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1314 | { |
| 1315 | static struct proxy *curproxy = NULL; |
| 1316 | struct server *newsrv = NULL; |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 1317 | const char *err; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 1318 | int rc; |
| 1319 | unsigned val; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1320 | int err_code = 0; |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 1321 | struct acl_cond *cond = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1322 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1323 | if (!strcmp(args[0], "listen")) |
| 1324 | rc = PR_CAP_LISTEN; |
| 1325 | else if (!strcmp(args[0], "frontend")) |
| 1326 | rc = PR_CAP_FE | PR_CAP_RS; |
| 1327 | else if (!strcmp(args[0], "backend")) |
| 1328 | rc = PR_CAP_BE | PR_CAP_RS; |
| 1329 | else if (!strcmp(args[0], "ruleset")) |
| 1330 | rc = PR_CAP_RS; |
| 1331 | else |
| 1332 | rc = PR_CAP_NONE; |
| 1333 | |
| 1334 | if (rc != PR_CAP_NONE) { /* new proxy */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1335 | if (!*args[1]) { |
| 1336 | Alert("parsing [%s:%d] : '%s' expects an <id> argument and\n" |
| 1337 | " optionnally supports [addr1]:port1[-end1]{,[addr]:port[-end]}...\n", |
| 1338 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1339 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1340 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1341 | } |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 1342 | |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 1343 | err = invalid_char(args[1]); |
| 1344 | if (err) { |
| 1345 | Alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 1346 | file, linenum, *err, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1347 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 1348 | } |
| 1349 | |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 1350 | for (curproxy = proxy; curproxy != NULL; curproxy = curproxy->next) { |
| 1351 | /* |
| 1352 | * If there are two proxies with the same name only following |
| 1353 | * combinations are allowed: |
| 1354 | * |
| 1355 | * listen backend frontend ruleset |
| 1356 | * listen - - - - |
| 1357 | * backend - - OK - |
| 1358 | * frontend - OK - - |
| 1359 | * ruleset - - - - |
| 1360 | */ |
| 1361 | |
| 1362 | if (!strcmp(curproxy->id, args[1]) && |
| 1363 | (rc!=(PR_CAP_FE|PR_CAP_RS) || curproxy->cap!=(PR_CAP_BE|PR_CAP_RS)) && |
| 1364 | (rc!=(PR_CAP_BE|PR_CAP_RS) || curproxy->cap!=(PR_CAP_FE|PR_CAP_RS))) { |
Willy Tarreau | 092549f | 2009-10-04 21:11:42 +0200 | [diff] [blame] | 1365 | Warning("Parsing [%s:%d]: %s '%s' has same name as another %s (declared at %s:%d).\n", |
| 1366 | file, linenum, proxy_cap_str(rc), args[1], proxy_type_str(curproxy), |
| 1367 | curproxy->conf.file, curproxy->conf.line); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1368 | err_code |= ERR_WARN; |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 1369 | } |
| 1370 | } |
| 1371 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1372 | if ((curproxy = (struct proxy *)calloc(1, sizeof(struct proxy))) == NULL) { |
| 1373 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1374 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1375 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1376 | } |
Willy Tarreau | 5af24ef | 2009-03-15 15:23:16 +0100 | [diff] [blame] | 1377 | |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 1378 | init_new_proxy(curproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1379 | curproxy->next = proxy; |
| 1380 | proxy = curproxy; |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 1381 | curproxy->conf.file = file; |
| 1382 | curproxy->conf.line = linenum; |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 1383 | curproxy->last_change = now.tv_sec; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1384 | curproxy->id = strdup(args[1]); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1385 | curproxy->cap = rc; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1386 | |
| 1387 | /* parse the listener address if any */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1388 | if ((curproxy->cap & PR_CAP_FE) && *args[2]) { |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 1389 | struct listener *new, *last = curproxy->listen; |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 1390 | if (!str2listener(args[2], curproxy, file, linenum)) { |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1391 | err_code |= ERR_FATAL; |
| 1392 | goto out; |
| 1393 | } |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 1394 | new = curproxy->listen; |
| 1395 | while (new != last) { |
| 1396 | new->conf.file = file; |
| 1397 | new->conf.line = linenum; |
| 1398 | new = new->next; |
Willy Tarreau | c8b1109 | 2011-02-16 11:08:57 +0100 | [diff] [blame] | 1399 | global.maxsock++; |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 1400 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1401 | } |
| 1402 | |
| 1403 | /* set default values */ |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1404 | memcpy(&curproxy->defsrv, &defproxy.defsrv, sizeof(curproxy->defsrv)); |
Willy Tarreau | 7016020 | 2010-04-07 16:06:40 +0200 | [diff] [blame] | 1405 | curproxy->defsrv.id = "default-server"; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1406 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1407 | curproxy->state = defproxy.state; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1408 | curproxy->options = defproxy.options; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 1409 | curproxy->options2 = defproxy.options2; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 1410 | curproxy->no_options = defproxy.no_options; |
| 1411 | curproxy->no_options2 = defproxy.no_options2; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 1412 | curproxy->bind_proc = defproxy.bind_proc; |
Willy Tarreau | 3168223 | 2007-11-29 15:38:04 +0100 | [diff] [blame] | 1413 | curproxy->lbprm.algo = defproxy.lbprm.algo; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 1414 | curproxy->except_net = defproxy.except_net; |
| 1415 | curproxy->except_mask = defproxy.except_mask; |
Maik Broemme | 36db02e | 2009-05-08 17:02:07 +0200 | [diff] [blame] | 1416 | curproxy->except_to = defproxy.except_to; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 1417 | curproxy->except_mask_to = defproxy.except_mask_to; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1418 | |
Willy Tarreau | 79f5fe8 | 2008-08-23 08:18:21 +0200 | [diff] [blame] | 1419 | if (defproxy.fwdfor_hdr_len) { |
| 1420 | curproxy->fwdfor_hdr_len = defproxy.fwdfor_hdr_len; |
| 1421 | curproxy->fwdfor_hdr_name = strdup(defproxy.fwdfor_hdr_name); |
| 1422 | } |
| 1423 | |
Willy Tarreau | b86db34 | 2009-11-30 11:50:16 +0100 | [diff] [blame] | 1424 | if (defproxy.orgto_hdr_len) { |
| 1425 | curproxy->orgto_hdr_len = defproxy.orgto_hdr_len; |
| 1426 | curproxy->orgto_hdr_name = strdup(defproxy.orgto_hdr_name); |
| 1427 | } |
| 1428 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1429 | if (curproxy->cap & PR_CAP_FE) { |
| 1430 | curproxy->maxconn = defproxy.maxconn; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 1431 | curproxy->backlog = defproxy.backlog; |
Willy Tarreau | 13a34bd | 2009-05-10 18:52:49 +0200 | [diff] [blame] | 1432 | curproxy->fe_sps_lim = defproxy.fe_sps_lim; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1433 | |
| 1434 | /* initialize error relocations */ |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1435 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) |
| 1436 | chunk_dup(&curproxy->errmsg[rc], &defproxy.errmsg[rc]); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1437 | |
| 1438 | curproxy->to_log = defproxy.to_log & ~LW_COOKIE & ~LW_REQHDR & ~ LW_RSPHDR; |
| 1439 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1440 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1441 | if (curproxy->cap & PR_CAP_BE) { |
| 1442 | curproxy->fullconn = defproxy.fullconn; |
| 1443 | curproxy->conn_retries = defproxy.conn_retries; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1444 | |
Willy Tarreau | aa2f389 | 2010-10-22 16:15:31 +0200 | [diff] [blame] | 1445 | if (defproxy.check_req) { |
| 1446 | curproxy->check_req = calloc(1, defproxy.check_len); |
| 1447 | memcpy(curproxy->check_req, defproxy.check_req, defproxy.check_len); |
| 1448 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1449 | curproxy->check_len = defproxy.check_len; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1450 | |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 1451 | if (defproxy.expect_str) { |
| 1452 | curproxy->expect_str = strdup(defproxy.expect_str); |
| 1453 | if (defproxy.expect_regex) { |
| 1454 | /* note: this regex is known to be valid */ |
| 1455 | curproxy->expect_regex = calloc(1, sizeof(regex_t)); |
| 1456 | regcomp(curproxy->expect_regex, defproxy.expect_str, REG_EXTENDED); |
| 1457 | } |
| 1458 | } |
| 1459 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1460 | if (defproxy.cookie_name) |
| 1461 | curproxy->cookie_name = strdup(defproxy.cookie_name); |
| 1462 | curproxy->cookie_len = defproxy.cookie_len; |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 1463 | if (defproxy.cookie_domain) |
| 1464 | curproxy->cookie_domain = strdup(defproxy.cookie_domain); |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 1465 | |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 1466 | if (defproxy.cookie_maxidle) |
| 1467 | curproxy->cookie_maxidle = defproxy.cookie_maxidle; |
| 1468 | |
| 1469 | if (defproxy.cookie_maxlife) |
| 1470 | curproxy->cookie_maxlife = defproxy.cookie_maxlife; |
| 1471 | |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 1472 | if (defproxy.rdp_cookie_name) |
| 1473 | curproxy->rdp_cookie_name = strdup(defproxy.rdp_cookie_name); |
| 1474 | curproxy->rdp_cookie_len = defproxy.rdp_cookie_len; |
| 1475 | |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 1476 | if (defproxy.url_param_name) |
| 1477 | curproxy->url_param_name = strdup(defproxy.url_param_name); |
| 1478 | curproxy->url_param_len = defproxy.url_param_len; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 1479 | |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 1480 | if (defproxy.hh_name) |
| 1481 | curproxy->hh_name = strdup(defproxy.hh_name); |
| 1482 | curproxy->hh_len = defproxy.hh_len; |
| 1483 | curproxy->hh_match_domain = defproxy.hh_match_domain; |
| 1484 | |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 1485 | if (defproxy.iface_name) |
| 1486 | curproxy->iface_name = strdup(defproxy.iface_name); |
| 1487 | curproxy->iface_len = defproxy.iface_len; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1488 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1489 | |
Willy Tarreau | 3b6b1a9 | 2009-07-23 13:24:23 +0200 | [diff] [blame] | 1490 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1491 | if (defproxy.capture_name) |
| 1492 | curproxy->capture_name = strdup(defproxy.capture_name); |
| 1493 | curproxy->capture_namelen = defproxy.capture_namelen; |
| 1494 | curproxy->capture_len = defproxy.capture_len; |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 1495 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1496 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1497 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 1498 | curproxy->timeout.client = defproxy.timeout.client; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 1499 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | 036fae0 | 2008-01-06 13:24:40 +0100 | [diff] [blame] | 1500 | curproxy->timeout.httpreq = defproxy.timeout.httpreq; |
Willy Tarreau | b16a574 | 2010-01-10 14:46:16 +0100 | [diff] [blame] | 1501 | curproxy->timeout.httpka = defproxy.timeout.httpka; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1502 | curproxy->uri_auth = defproxy.uri_auth; |
| 1503 | curproxy->mon_net = defproxy.mon_net; |
| 1504 | curproxy->mon_mask = defproxy.mon_mask; |
| 1505 | if (defproxy.monitor_uri) |
| 1506 | curproxy->monitor_uri = strdup(defproxy.monitor_uri); |
| 1507 | curproxy->monitor_uri_len = defproxy.monitor_uri_len; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 1508 | if (defproxy.defbe.name) |
| 1509 | curproxy->defbe.name = strdup(defproxy.defbe.name); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1510 | } |
| 1511 | |
| 1512 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 1513 | curproxy->timeout.connect = defproxy.timeout.connect; |
| 1514 | curproxy->timeout.server = defproxy.timeout.server; |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 1515 | curproxy->timeout.check = defproxy.timeout.check; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 1516 | curproxy->timeout.queue = defproxy.timeout.queue; |
Willy Tarreau | 51c9bde | 2008-01-06 13:40:03 +0100 | [diff] [blame] | 1517 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | cd7afc0 | 2009-07-12 10:03:17 +0200 | [diff] [blame] | 1518 | curproxy->timeout.httpreq = defproxy.timeout.httpreq; |
Willy Tarreau | b16a574 | 2010-01-10 14:46:16 +0100 | [diff] [blame] | 1519 | curproxy->timeout.httpka = defproxy.timeout.httpka; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1520 | curproxy->source_addr = defproxy.source_addr; |
| 1521 | } |
| 1522 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1523 | curproxy->mode = defproxy.mode; |
| 1524 | curproxy->logfac1 = defproxy.logfac1; |
| 1525 | curproxy->logsrv1 = defproxy.logsrv1; |
| 1526 | curproxy->loglev1 = defproxy.loglev1; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 1527 | curproxy->minlvl1 = defproxy.minlvl1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1528 | curproxy->logfac2 = defproxy.logfac2; |
| 1529 | curproxy->logsrv2 = defproxy.logsrv2; |
| 1530 | curproxy->loglev2 = defproxy.loglev2; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 1531 | curproxy->minlvl2 = defproxy.minlvl2; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1532 | curproxy->grace = defproxy.grace; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1533 | curproxy->conf.used_listener_id = EB_ROOT; |
| 1534 | curproxy->conf.used_server_id = EB_ROOT; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 1535 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1536 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1537 | } |
| 1538 | else if (!strcmp(args[0], "defaults")) { /* use this one to assign default values */ |
| 1539 | /* some variables may have already been initialized earlier */ |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 1540 | /* FIXME-20070101: we should do this too at the end of the |
| 1541 | * config parsing to free all default values. |
| 1542 | */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1543 | free(defproxy.check_req); |
| 1544 | free(defproxy.cookie_name); |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 1545 | free(defproxy.rdp_cookie_name); |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 1546 | free(defproxy.cookie_domain); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1547 | free(defproxy.url_param_name); |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 1548 | free(defproxy.hh_name); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1549 | free(defproxy.capture_name); |
| 1550 | free(defproxy.monitor_uri); |
| 1551 | free(defproxy.defbe.name); |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 1552 | free(defproxy.iface_name); |
Willy Tarreau | 79f5fe8 | 2008-08-23 08:18:21 +0200 | [diff] [blame] | 1553 | free(defproxy.fwdfor_hdr_name); |
| 1554 | defproxy.fwdfor_hdr_len = 0; |
Willy Tarreau | b86db34 | 2009-11-30 11:50:16 +0100 | [diff] [blame] | 1555 | free(defproxy.orgto_hdr_name); |
| 1556 | defproxy.orgto_hdr_len = 0; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 1557 | free(defproxy.expect_str); |
| 1558 | if (defproxy.expect_regex) regfree(defproxy.expect_regex); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 1559 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1560 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1561 | chunk_destroy(&defproxy.errmsg[rc]); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 1562 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1563 | /* we cannot free uri_auth because it might already be used */ |
| 1564 | init_default_instance(); |
| 1565 | curproxy = &defproxy; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1566 | defproxy.cap = PR_CAP_LISTEN; /* all caps for now */ |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1567 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1568 | } |
| 1569 | else if (curproxy == NULL) { |
| 1570 | Alert("parsing [%s:%d] : 'listen' or 'defaults' expected.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1571 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1572 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1573 | } |
| 1574 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1575 | |
| 1576 | /* Now let's parse the proxy-specific keywords */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1577 | if (!strcmp(args[0], "bind")) { /* new listen addresses */ |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 1578 | struct listener *new_listen, *last_listen; |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1579 | int cur_arg; |
| 1580 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1581 | if (curproxy == &defproxy) { |
| 1582 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1583 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1584 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1585 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1586 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1587 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1588 | |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 1589 | if ( *(args[1]) != '/' && strchr(args[1], ':') == NULL) { |
Willy Tarreau | d55c3fe | 2010-11-09 09:50:37 +0100 | [diff] [blame] | 1590 | Alert("parsing [%s:%d] : '%s' expects {<path>|[addr1]:port1[-end1]}{,[addr]:port[-end]}... as arguments.\n", |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1591 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1592 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1593 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1594 | } |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 1595 | |
| 1596 | last_listen = curproxy->listen; |
Willy Tarreau | 8a95691 | 2010-10-15 14:27:08 +0200 | [diff] [blame] | 1597 | |
| 1598 | /* NOTE: the following line might create several listeners if there |
| 1599 | * are comma-separated IPs or port ranges. So all further processing |
| 1600 | * will have to be applied to all listeners created after last_listen. |
| 1601 | */ |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 1602 | if (!str2listener(args[1], curproxy, file, linenum)) { |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1603 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1604 | goto out; |
| 1605 | } |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1606 | |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 1607 | new_listen = curproxy->listen; |
| 1608 | while (new_listen != last_listen) { |
| 1609 | new_listen->conf.file = file; |
| 1610 | new_listen->conf.line = linenum; |
| 1611 | new_listen = new_listen->next; |
Willy Tarreau | c8b1109 | 2011-02-16 11:08:57 +0100 | [diff] [blame] | 1612 | global.maxsock++; |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 1613 | } |
| 1614 | |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 1615 | /* Set default global rights and owner for unix bind */ |
| 1616 | if (curproxy->listen->addr.ss_family == AF_UNIX) { |
| 1617 | memcpy(&(curproxy->listen->perm.ux), &(global.unix_bind.ux), sizeof(global.unix_bind.ux)); |
| 1618 | } |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1619 | cur_arg = 2; |
| 1620 | while (*(args[cur_arg])) { |
| 1621 | if (!strcmp(args[cur_arg], "interface")) { /* specifically bind to this interface */ |
| 1622 | #ifdef SO_BINDTODEVICE |
| 1623 | struct listener *l; |
| 1624 | |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 1625 | if (curproxy->listen->addr.ss_family == AF_UNIX) { |
| 1626 | Alert("parsing [%s:%d] : '%s' : '%s' option not supported on unix sockets.\n", |
| 1627 | file, linenum, args[0], args[cur_arg]); |
| 1628 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1629 | goto out; |
| 1630 | } |
| 1631 | |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1632 | if (!*args[cur_arg + 1]) { |
| 1633 | Alert("parsing [%s:%d] : '%s' : missing interface name.\n", |
| 1634 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1635 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1636 | goto out; |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1637 | } |
| 1638 | |
| 1639 | for (l = curproxy->listen; l != last_listen; l = l->next) |
| 1640 | l->interface = strdup(args[cur_arg + 1]); |
| 1641 | |
| 1642 | global.last_checks |= LSTCHK_NETADM; |
| 1643 | |
| 1644 | cur_arg += 2; |
| 1645 | continue; |
| 1646 | #else |
| 1647 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 1648 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1649 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1650 | goto out; |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1651 | #endif |
| 1652 | } |
Willy Tarreau | be1b918 | 2009-06-14 18:48:19 +0200 | [diff] [blame] | 1653 | if (!strcmp(args[cur_arg], "mss")) { /* set MSS of listening socket */ |
| 1654 | #ifdef TCP_MAXSEG |
| 1655 | struct listener *l; |
| 1656 | int mss; |
| 1657 | |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 1658 | if (curproxy->listen->addr.ss_family == AF_UNIX) { |
| 1659 | Alert("parsing [%s:%d] : '%s' : '%s' option not supported on unix sockets.\n", |
| 1660 | file, linenum, args[0], args[cur_arg]); |
| 1661 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1662 | goto out; |
| 1663 | } |
| 1664 | |
Willy Tarreau | be1b918 | 2009-06-14 18:48:19 +0200 | [diff] [blame] | 1665 | if (!*args[cur_arg + 1]) { |
| 1666 | Alert("parsing [%s:%d] : '%s' : missing MSS value.\n", |
| 1667 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1668 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1669 | goto out; |
Willy Tarreau | be1b918 | 2009-06-14 18:48:19 +0200 | [diff] [blame] | 1670 | } |
| 1671 | |
Willy Tarreau | 48a7e72 | 2010-12-24 15:26:39 +0100 | [diff] [blame] | 1672 | mss = atoi(args[cur_arg + 1]); |
| 1673 | if (!mss || abs(mss) > 65535) { |
| 1674 | Alert("parsing [%s:%d]: %s expects an MSS with and absolute value between 1 and 65535.\n", |
Willy Tarreau | be1b918 | 2009-06-14 18:48:19 +0200 | [diff] [blame] | 1675 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1676 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1677 | goto out; |
Willy Tarreau | be1b918 | 2009-06-14 18:48:19 +0200 | [diff] [blame] | 1678 | } |
| 1679 | |
| 1680 | for (l = curproxy->listen; l != last_listen; l = l->next) |
| 1681 | l->maxseg = mss; |
| 1682 | |
| 1683 | cur_arg += 2; |
| 1684 | continue; |
| 1685 | #else |
| 1686 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 1687 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1688 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1689 | goto out; |
Willy Tarreau | be1b918 | 2009-06-14 18:48:19 +0200 | [diff] [blame] | 1690 | #endif |
| 1691 | } |
Willy Tarreau | cb6cd43 | 2009-10-13 07:34:14 +0200 | [diff] [blame] | 1692 | |
| 1693 | if (!strcmp(args[cur_arg], "defer-accept")) { /* wait for some data for 1 second max before doing accept */ |
| 1694 | #ifdef TCP_DEFER_ACCEPT |
| 1695 | struct listener *l; |
| 1696 | |
| 1697 | for (l = curproxy->listen; l != last_listen; l = l->next) |
| 1698 | l->options |= LI_O_DEF_ACCEPT; |
| 1699 | |
| 1700 | cur_arg ++; |
| 1701 | continue; |
| 1702 | #else |
| 1703 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 1704 | file, linenum, args[0], args[cur_arg]); |
| 1705 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1706 | goto out; |
| 1707 | #endif |
| 1708 | } |
| 1709 | |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1710 | if (!strcmp(args[cur_arg], "transparent")) { /* transparently bind to these addresses */ |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 1711 | #ifdef CONFIG_HAP_LINUX_TPROXY |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 1712 | struct listener *l; |
| 1713 | |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 1714 | if (curproxy->listen->addr.ss_family == AF_UNIX) { |
| 1715 | Alert("parsing [%s:%d] : '%s' : '%s' option not supported on unix sockets.\n", |
| 1716 | file, linenum, args[0], args[cur_arg]); |
| 1717 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1718 | goto out; |
| 1719 | } |
| 1720 | |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 1721 | for (l = curproxy->listen; l != last_listen; l = l->next) |
| 1722 | l->options |= LI_O_FOREIGN; |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1723 | |
| 1724 | cur_arg ++; |
| 1725 | continue; |
| 1726 | #else |
| 1727 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 1728 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1729 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1730 | goto out; |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1731 | #endif |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 1732 | } |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1733 | |
Willy Tarreau | 8a95691 | 2010-10-15 14:27:08 +0200 | [diff] [blame] | 1734 | if (!strcmp(args[cur_arg], "accept-proxy")) { /* expect a 'PROXY' line first */ |
| 1735 | struct listener *l; |
| 1736 | |
| 1737 | for (l = curproxy->listen; l != last_listen; l = l->next) |
| 1738 | l->options |= LI_O_ACC_PROXY; |
| 1739 | |
| 1740 | cur_arg ++; |
| 1741 | continue; |
| 1742 | } |
| 1743 | |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1744 | if (!strcmp(args[cur_arg], "name")) { |
| 1745 | struct listener *l; |
| 1746 | |
| 1747 | for (l = curproxy->listen; l != last_listen; l = l->next) |
| 1748 | l->name = strdup(args[cur_arg + 1]); |
| 1749 | |
| 1750 | cur_arg += 2; |
| 1751 | continue; |
| 1752 | } |
| 1753 | |
| 1754 | if (!strcmp(args[cur_arg], "id")) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1755 | struct eb32_node *node; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1756 | struct listener *l; |
| 1757 | |
| 1758 | if (curproxy->listen->next != last_listen) { |
| 1759 | Alert("parsing [%s:%d]: '%s' can be only used with a single socket.\n", |
| 1760 | file, linenum, args[cur_arg]); |
| 1761 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1762 | goto out; |
| 1763 | } |
| 1764 | |
| 1765 | if (!*args[cur_arg + 1]) { |
| 1766 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 1767 | file, linenum, args[cur_arg]); |
| 1768 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1769 | goto out; |
| 1770 | } |
| 1771 | |
| 1772 | curproxy->listen->luid = atol(args[cur_arg + 1]); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1773 | curproxy->listen->conf.id.key = curproxy->listen->luid; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1774 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1775 | if (curproxy->listen->luid <= 0) { |
| 1776 | Alert("parsing [%s:%d]: custom id has to be > 0\n", |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1777 | file, linenum); |
| 1778 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1779 | goto out; |
| 1780 | } |
| 1781 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1782 | node = eb32_lookup(&curproxy->conf.used_listener_id, curproxy->listen->luid); |
| 1783 | if (node) { |
| 1784 | l = container_of(node, struct listener, conf.id); |
| 1785 | Alert("parsing [%s:%d]: custom id %d for socket '%s' already used at %s:%d.\n", |
| 1786 | file, linenum, l->luid, args[1], l->conf.file, l->conf.line); |
| 1787 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1788 | goto out; |
| 1789 | } |
| 1790 | eb32_insert(&curproxy->conf.used_listener_id, &curproxy->listen->conf.id); |
| 1791 | |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1792 | cur_arg += 2; |
| 1793 | continue; |
| 1794 | } |
| 1795 | |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 1796 | if (!strcmp(args[cur_arg], "mode")) { |
| 1797 | |
| 1798 | if (curproxy->listen->addr.ss_family != AF_UNIX) { |
| 1799 | Alert("parsing [%s:%d] : '%s' : '%s' option only supported on unix sockets.\n", |
| 1800 | file, linenum, args[0], args[cur_arg]); |
| 1801 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1802 | goto out; |
| 1803 | } |
| 1804 | |
| 1805 | curproxy->listen->perm.ux.mode = strtol(args[cur_arg + 1], NULL, 8); |
| 1806 | |
| 1807 | cur_arg += 2; |
| 1808 | continue; |
| 1809 | } |
| 1810 | |
| 1811 | if (!strcmp(args[cur_arg], "uid")) { |
| 1812 | |
| 1813 | if (curproxy->listen->addr.ss_family != AF_UNIX) { |
| 1814 | Alert("parsing [%s:%d] : '%s' : '%s' option only supported on unix sockets.\n", |
| 1815 | file, linenum, args[0], args[cur_arg]); |
| 1816 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1817 | goto out; |
| 1818 | } |
| 1819 | |
| 1820 | curproxy->listen->perm.ux.uid = atol(args[cur_arg + 1 ]); |
| 1821 | cur_arg += 2; |
| 1822 | continue; |
| 1823 | } |
| 1824 | |
| 1825 | if (!strcmp(args[cur_arg], "gid")) { |
| 1826 | |
| 1827 | if (curproxy->listen->addr.ss_family != AF_UNIX) { |
| 1828 | Alert("parsing [%s:%d] : '%s' : '%s' option only supported on unix sockets.\n", |
| 1829 | file, linenum, args[0], args[cur_arg]); |
| 1830 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1831 | goto out; |
| 1832 | } |
| 1833 | |
| 1834 | curproxy->listen->perm.ux.gid = atol(args[cur_arg + 1 ]); |
| 1835 | cur_arg += 2; |
| 1836 | continue; |
| 1837 | } |
| 1838 | |
| 1839 | if (!strcmp(args[cur_arg], "user")) { |
| 1840 | struct passwd *user; |
| 1841 | |
| 1842 | if (curproxy->listen->addr.ss_family != AF_UNIX) { |
| 1843 | Alert("parsing [%s:%d] : '%s' : '%s' option only supported on unix sockets.\n", |
| 1844 | file, linenum, args[0], args[cur_arg]); |
| 1845 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1846 | goto out; |
| 1847 | } |
| 1848 | user = getpwnam(args[cur_arg + 1]); |
| 1849 | if (!user) { |
| 1850 | Alert("parsing [%s:%d] : '%s' : '%s' unknown user.\n", |
| 1851 | file, linenum, args[0], args[cur_arg + 1 ]); |
| 1852 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1853 | goto out; |
| 1854 | } |
| 1855 | |
| 1856 | curproxy->listen->perm.ux.uid = user->pw_uid; |
| 1857 | cur_arg += 2; |
| 1858 | continue; |
| 1859 | } |
| 1860 | |
| 1861 | if (!strcmp(args[cur_arg], "group")) { |
| 1862 | struct group *group; |
| 1863 | |
| 1864 | if (curproxy->listen->addr.ss_family != AF_UNIX) { |
| 1865 | Alert("parsing [%s:%d] : '%s' : '%s' option only supported on unix sockets.\n", |
| 1866 | file, linenum, args[0], args[cur_arg]); |
| 1867 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1868 | goto out; |
| 1869 | } |
| 1870 | group = getgrnam(args[cur_arg + 1]); |
| 1871 | if (!group) { |
| 1872 | Alert("parsing [%s:%d] : '%s' : '%s' unknown group.\n", |
| 1873 | file, linenum, args[0], args[cur_arg + 1 ]); |
| 1874 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1875 | goto out; |
| 1876 | } |
| 1877 | |
| 1878 | curproxy->listen->perm.ux.gid = group->gr_gid; |
| 1879 | cur_arg += 2; |
| 1880 | continue; |
| 1881 | } |
| 1882 | |
Willy Tarreau | b48f958 | 2011-09-05 01:17:06 +0200 | [diff] [blame] | 1883 | Alert("parsing [%s:%d] : '%s' only supports the 'transparent', 'accept-proxy', 'defer-accept', 'name', 'id', 'mss', 'mode', 'uid', 'gid', 'user', 'group' and 'interface' options.\n", |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 1884 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1885 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1886 | goto out; |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 1887 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1888 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1889 | } |
| 1890 | else if (!strcmp(args[0], "monitor-net")) { /* set the range of IPs to ignore */ |
| 1891 | if (!*args[1] || !str2net(args[1], &curproxy->mon_net, &curproxy->mon_mask)) { |
| 1892 | Alert("parsing [%s:%d] : '%s' expects address[/mask].\n", |
| 1893 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1894 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1895 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1896 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1897 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1898 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1899 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1900 | /* flush useless bits */ |
| 1901 | curproxy->mon_net.s_addr &= curproxy->mon_mask.s_addr; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1902 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1903 | } |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 1904 | else if (!strcmp(args[0], "monitor-uri")) { /* set the URI to intercept */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1905 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1906 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1907 | |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 1908 | if (!*args[1]) { |
| 1909 | Alert("parsing [%s:%d] : '%s' expects an URI.\n", |
| 1910 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1911 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1912 | goto out; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 1913 | } |
| 1914 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1915 | free(curproxy->monitor_uri); |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 1916 | curproxy->monitor_uri_len = strlen(args[1]); |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 1917 | curproxy->monitor_uri = (char *)calloc(1, curproxy->monitor_uri_len + 1); |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 1918 | memcpy(curproxy->monitor_uri, args[1], curproxy->monitor_uri_len); |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 1919 | curproxy->monitor_uri[curproxy->monitor_uri_len] = '\0'; |
| 1920 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1921 | goto out; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 1922 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1923 | else if (!strcmp(args[0], "mode")) { /* sets the proxy mode */ |
| 1924 | if (!strcmp(args[1], "http")) curproxy->mode = PR_MODE_HTTP; |
| 1925 | else if (!strcmp(args[1], "tcp")) curproxy->mode = PR_MODE_TCP; |
| 1926 | else if (!strcmp(args[1], "health")) curproxy->mode = PR_MODE_HEALTH; |
| 1927 | else { |
| 1928 | Alert("parsing [%s:%d] : unknown proxy mode '%s'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1929 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1930 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1931 | } |
| 1932 | } |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 1933 | else if (!strcmp(args[0], "id")) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1934 | struct eb32_node *node; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 1935 | |
| 1936 | if (curproxy == &defproxy) { |
| 1937 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", |
| 1938 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1939 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1940 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 1941 | } |
| 1942 | |
| 1943 | if (!*args[1]) { |
| 1944 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 1945 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1946 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1947 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 1948 | } |
| 1949 | |
| 1950 | curproxy->uuid = atol(args[1]); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1951 | curproxy->conf.id.key = curproxy->uuid; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 1952 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1953 | if (curproxy->uuid <= 0) { |
| 1954 | Alert("parsing [%s:%d]: custom id has to be > 0.\n", |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 1955 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1956 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1957 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 1958 | } |
| 1959 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1960 | node = eb32_lookup(&used_proxy_id, curproxy->uuid); |
| 1961 | if (node) { |
| 1962 | struct proxy *target = container_of(node, struct proxy, conf.id); |
| 1963 | Alert("parsing [%s:%d]: %s %s reuses same custom id as %s %s (declared at %s:%d).\n", |
| 1964 | file, linenum, proxy_type_str(curproxy), curproxy->id, |
| 1965 | proxy_type_str(target), target->id, target->conf.file, target->conf.line); |
| 1966 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1967 | goto out; |
| 1968 | } |
| 1969 | eb32_insert(&used_proxy_id, &curproxy->conf.id); |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 1970 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1971 | else if (!strcmp(args[0], "description")) { |
| 1972 | int i, len=0; |
| 1973 | char *d; |
| 1974 | |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 1975 | if (curproxy == &defproxy) { |
| 1976 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", |
| 1977 | file, linenum, args[0]); |
| 1978 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1979 | goto out; |
| 1980 | } |
| 1981 | |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1982 | if (!*args[1]) { |
| 1983 | Alert("parsing [%s:%d]: '%s' expects a string argument.\n", |
| 1984 | file, linenum, args[0]); |
| 1985 | return -1; |
| 1986 | } |
| 1987 | |
| 1988 | for(i=1; *args[i]; i++) |
| 1989 | len += strlen(args[i])+1; |
| 1990 | |
| 1991 | d = (char *)calloc(1, len); |
| 1992 | curproxy->desc = d; |
| 1993 | |
| 1994 | d += sprintf(d, "%s", args[1]); |
| 1995 | for(i=2; *args[i]; i++) |
| 1996 | d += sprintf(d, " %s", args[i]); |
| 1997 | |
| 1998 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1999 | else if (!strcmp(args[0], "disabled")) { /* disables this proxy */ |
| 2000 | curproxy->state = PR_STSTOPPED; |
| 2001 | } |
| 2002 | else if (!strcmp(args[0], "enabled")) { /* enables this proxy (used to revert a disabled default) */ |
| 2003 | curproxy->state = PR_STNEW; |
| 2004 | } |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2005 | else if (!strcmp(args[0], "bind-process")) { /* enable this proxy only on some processes */ |
| 2006 | int cur_arg = 1; |
| 2007 | unsigned int set = 0; |
| 2008 | |
| 2009 | while (*args[cur_arg]) { |
| 2010 | int u; |
| 2011 | if (strcmp(args[cur_arg], "all") == 0) { |
| 2012 | set = 0; |
| 2013 | break; |
| 2014 | } |
| 2015 | else if (strcmp(args[cur_arg], "odd") == 0) { |
| 2016 | set |= 0x55555555; |
| 2017 | } |
| 2018 | else if (strcmp(args[cur_arg], "even") == 0) { |
| 2019 | set |= 0xAAAAAAAA; |
| 2020 | } |
| 2021 | else { |
| 2022 | u = str2uic(args[cur_arg]); |
| 2023 | if (u < 1 || u > 32) { |
| 2024 | Alert("parsing [%s:%d]: %s expects 'all', 'odd', 'even', or process numbers from 1 to 32.\n", |
| 2025 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2026 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2027 | goto out; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2028 | } |
| 2029 | if (u > global.nbproc) { |
| 2030 | Warning("parsing [%s:%d]: %s references process number higher than global.nbproc.\n", |
| 2031 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2032 | err_code |= ERR_WARN; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2033 | } |
| 2034 | set |= 1 << (u - 1); |
| 2035 | } |
| 2036 | cur_arg++; |
| 2037 | } |
| 2038 | curproxy->bind_proc = set; |
| 2039 | } |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 2040 | else if (!strcmp(args[0], "acl")) { /* add an ACL */ |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2041 | if (curproxy == &defproxy) { |
| 2042 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2043 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2044 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2045 | } |
| 2046 | |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 2047 | err = invalid_char(args[1]); |
| 2048 | if (err) { |
| 2049 | Alert("parsing [%s:%d] : character '%c' is not permitted in acl name '%s'.\n", |
| 2050 | file, linenum, *err, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2051 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 2052 | } |
| 2053 | |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 2054 | if (parse_acl((const char **)args + 1, &curproxy->acl) == NULL) { |
| 2055 | Alert("parsing [%s:%d] : error detected while parsing ACL '%s'.\n", |
| 2056 | file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2057 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2058 | goto out; |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 2059 | } |
| 2060 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2061 | else if (!strcmp(args[0], "cookie")) { /* cookie name */ |
| 2062 | int cur_arg; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2063 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2064 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2065 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2066 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2067 | if (*(args[1]) == 0) { |
| 2068 | Alert("parsing [%s:%d] : '%s' expects <cookie_name> as argument.\n", |
| 2069 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2070 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2071 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2072 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2073 | |
Willy Tarreau | c63d4bb | 2010-10-23 11:37:27 +0200 | [diff] [blame] | 2074 | curproxy->options &= ~PR_O_COOK_ANY; |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 2075 | curproxy->options2 &= ~PR_O2_COOK_PSV; |
Willy Tarreau | c63d4bb | 2010-10-23 11:37:27 +0200 | [diff] [blame] | 2076 | curproxy->cookie_maxidle = curproxy->cookie_maxlife = 0; |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 2077 | free(curproxy->cookie_domain); curproxy->cookie_domain = NULL; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2078 | free(curproxy->cookie_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2079 | curproxy->cookie_name = strdup(args[1]); |
| 2080 | curproxy->cookie_len = strlen(curproxy->cookie_name); |
Willy Tarreau | c63d4bb | 2010-10-23 11:37:27 +0200 | [diff] [blame] | 2081 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2082 | cur_arg = 2; |
| 2083 | while (*(args[cur_arg])) { |
| 2084 | if (!strcmp(args[cur_arg], "rewrite")) { |
| 2085 | curproxy->options |= PR_O_COOK_RW; |
| 2086 | } |
| 2087 | else if (!strcmp(args[cur_arg], "indirect")) { |
| 2088 | curproxy->options |= PR_O_COOK_IND; |
| 2089 | } |
| 2090 | else if (!strcmp(args[cur_arg], "insert")) { |
| 2091 | curproxy->options |= PR_O_COOK_INS; |
| 2092 | } |
| 2093 | else if (!strcmp(args[cur_arg], "nocache")) { |
| 2094 | curproxy->options |= PR_O_COOK_NOC; |
| 2095 | } |
| 2096 | else if (!strcmp(args[cur_arg], "postonly")) { |
| 2097 | curproxy->options |= PR_O_COOK_POST; |
| 2098 | } |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 2099 | else if (!strcmp(args[cur_arg], "preserve")) { |
| 2100 | curproxy->options2 |= PR_O2_COOK_PSV; |
| 2101 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2102 | else if (!strcmp(args[cur_arg], "prefix")) { |
| 2103 | curproxy->options |= PR_O_COOK_PFX; |
| 2104 | } |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2105 | else if (!strcmp(args[cur_arg], "domain")) { |
| 2106 | if (!*args[cur_arg + 1]) { |
| 2107 | Alert("parsing [%s:%d]: '%s' expects <domain> as argument.\n", |
| 2108 | file, linenum, args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2109 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2110 | goto out; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2111 | } |
| 2112 | |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 2113 | if (*args[cur_arg + 1] != '.' || !strchr(args[cur_arg + 1] + 1, '.')) { |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2114 | /* rfc2109, 4.3.2 Rejecting Cookies */ |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 2115 | Warning("parsing [%s:%d]: domain '%s' contains no embedded" |
| 2116 | " dots nor does not start with a dot." |
| 2117 | " RFC forbids it, this configuration may not work properly.\n", |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2118 | file, linenum, args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 2119 | err_code |= ERR_WARN; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2120 | } |
| 2121 | |
| 2122 | err = invalid_domainchar(args[cur_arg + 1]); |
| 2123 | if (err) { |
| 2124 | Alert("parsing [%s:%d]: character '%c' is not permitted in domain name '%s'.\n", |
| 2125 | file, linenum, *err, args[cur_arg + 1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2126 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2127 | goto out; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2128 | } |
| 2129 | |
Willy Tarreau | 68a897b | 2009-12-03 23:28:34 +0100 | [diff] [blame] | 2130 | if (!curproxy->cookie_domain) { |
| 2131 | curproxy->cookie_domain = strdup(args[cur_arg + 1]); |
| 2132 | } else { |
| 2133 | /* one domain was already specified, add another one by |
| 2134 | * building the string which will be returned along with |
| 2135 | * the cookie. |
| 2136 | */ |
| 2137 | char *new_ptr; |
| 2138 | int new_len = strlen(curproxy->cookie_domain) + |
| 2139 | strlen("; domain=") + strlen(args[cur_arg + 1]) + 1; |
| 2140 | new_ptr = malloc(new_len); |
| 2141 | snprintf(new_ptr, new_len, "%s; domain=%s", curproxy->cookie_domain, args[cur_arg+1]); |
| 2142 | free(curproxy->cookie_domain); |
| 2143 | curproxy->cookie_domain = new_ptr; |
| 2144 | } |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 2145 | cur_arg++; |
| 2146 | } |
| 2147 | else if (!strcmp(args[cur_arg], "maxidle")) { |
| 2148 | unsigned int maxidle; |
| 2149 | const char *res; |
| 2150 | |
| 2151 | if (!*args[cur_arg + 1]) { |
| 2152 | Alert("parsing [%s:%d]: '%s' expects <idletime> in seconds as argument.\n", |
| 2153 | file, linenum, args[cur_arg]); |
| 2154 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2155 | goto out; |
| 2156 | } |
| 2157 | |
| 2158 | res = parse_time_err(args[cur_arg + 1], &maxidle, TIME_UNIT_S); |
| 2159 | if (res) { |
| 2160 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 2161 | file, linenum, *res, args[cur_arg]); |
| 2162 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2163 | goto out; |
| 2164 | } |
| 2165 | curproxy->cookie_maxidle = maxidle; |
| 2166 | cur_arg++; |
| 2167 | } |
| 2168 | else if (!strcmp(args[cur_arg], "maxlife")) { |
| 2169 | unsigned int maxlife; |
| 2170 | const char *res; |
| 2171 | |
| 2172 | if (!*args[cur_arg + 1]) { |
| 2173 | Alert("parsing [%s:%d]: '%s' expects <lifetime> in seconds as argument.\n", |
| 2174 | file, linenum, args[cur_arg]); |
| 2175 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2176 | goto out; |
| 2177 | } |
| 2178 | |
| 2179 | res = parse_time_err(args[cur_arg + 1], &maxlife, TIME_UNIT_S); |
| 2180 | if (res) { |
| 2181 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 2182 | file, linenum, *res, args[cur_arg]); |
| 2183 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2184 | goto out; |
| 2185 | } |
| 2186 | curproxy->cookie_maxlife = maxlife; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2187 | cur_arg++; |
| 2188 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2189 | else { |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 2190 | Alert("parsing [%s:%d] : '%s' supports 'rewrite', 'insert', 'prefix', 'indirect', 'nocache', 'postonly', 'domain', 'maxidle, and 'maxlife' options.\n", |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2191 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2192 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2193 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2194 | } |
| 2195 | cur_arg++; |
| 2196 | } |
| 2197 | if (!POWEROF2(curproxy->options & (PR_O_COOK_RW|PR_O_COOK_IND))) { |
| 2198 | Alert("parsing [%s:%d] : cookie 'rewrite' and 'indirect' modes are incompatible.\n", |
| 2199 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2200 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2201 | } |
| 2202 | |
| 2203 | if (!POWEROF2(curproxy->options & (PR_O_COOK_RW|PR_O_COOK_INS|PR_O_COOK_PFX))) { |
| 2204 | Alert("parsing [%s:%d] : cookie 'rewrite', 'insert' and 'prefix' modes are incompatible.\n", |
| 2205 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2206 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2207 | } |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 2208 | |
| 2209 | if ((curproxy->options2 & PR_O2_COOK_PSV) && !(curproxy->options & (PR_O_COOK_INS|PR_O_COOK_IND))) { |
| 2210 | Alert("parsing [%s:%d] : cookie 'preserve' requires at least 'insert' or 'indirect'.\n", |
| 2211 | file, linenum); |
| 2212 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2213 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2214 | }/* end else if (!strcmp(args[0], "cookie")) */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2215 | else if (!strcmp(args[0], "persist")) { /* persist */ |
| 2216 | if (*(args[1]) == 0) { |
| 2217 | Alert("parsing [%s:%d] : missing persist method.\n", |
| 2218 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2219 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2220 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2221 | } |
| 2222 | |
| 2223 | if (!strncmp(args[1], "rdp-cookie", 10)) { |
| 2224 | curproxy->options2 |= PR_O2_RDPC_PRST; |
| 2225 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2226 | if (*(args[1] + 10) == '(') { /* cookie name */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2227 | const char *beg, *end; |
| 2228 | |
| 2229 | beg = args[1] + 11; |
| 2230 | end = strchr(beg, ')'); |
| 2231 | |
| 2232 | if (!end || end == beg) { |
| 2233 | Alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n", |
| 2234 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2235 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2236 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2237 | } |
| 2238 | |
| 2239 | free(curproxy->rdp_cookie_name); |
| 2240 | curproxy->rdp_cookie_name = my_strndup(beg, end - beg); |
| 2241 | curproxy->rdp_cookie_len = end-beg; |
| 2242 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2243 | else if (*(args[1] + 10) == '\0') { /* default cookie name 'msts' */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2244 | free(curproxy->rdp_cookie_name); |
| 2245 | curproxy->rdp_cookie_name = strdup("msts"); |
| 2246 | curproxy->rdp_cookie_len = strlen(curproxy->rdp_cookie_name); |
| 2247 | } |
| 2248 | else { /* syntax */ |
| 2249 | Alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n", |
| 2250 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2251 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2252 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2253 | } |
| 2254 | } |
| 2255 | else { |
| 2256 | Alert("parsing [%s:%d] : unknown persist method.\n", |
| 2257 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2258 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2259 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2260 | } |
| 2261 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2262 | else if (!strcmp(args[0], "appsession")) { /* cookie name */ |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2263 | int cur_arg; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2264 | |
Cyril Bonté | 3b7a369 | 2010-01-10 17:01:47 +0100 | [diff] [blame] | 2265 | if (curproxy == &defproxy) { |
| 2266 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2267 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2268 | goto out; |
| 2269 | } |
| 2270 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2271 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2272 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2273 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2274 | if (*(args[5]) == 0) { |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2275 | Alert("parsing [%s:%d] : '%s' expects 'appsession' <cookie_name> 'len' <len> 'timeout' <timeout> [options*].\n", |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2276 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2277 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2278 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2279 | } |
| 2280 | have_appsession = 1; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2281 | free(curproxy->appsession_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2282 | curproxy->appsession_name = strdup(args[1]); |
| 2283 | curproxy->appsession_name_len = strlen(curproxy->appsession_name); |
| 2284 | curproxy->appsession_len = atoi(args[3]); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 2285 | err = parse_time_err(args[5], &val, TIME_UNIT_MS); |
| 2286 | if (err) { |
| 2287 | Alert("parsing [%s:%d] : unexpected character '%c' in %s timeout.\n", |
| 2288 | file, linenum, *err, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2289 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2290 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 2291 | } |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 2292 | curproxy->timeout.appsession = val; |
Willy Tarreau | ee99136 | 2007-05-14 14:37:50 +0200 | [diff] [blame] | 2293 | |
Willy Tarreau | 51041c7 | 2007-09-09 21:56:53 +0200 | [diff] [blame] | 2294 | if (appsession_hash_init(&(curproxy->htbl_proxy), destroy) == 0) { |
| 2295 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2296 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2297 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2298 | } |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2299 | |
| 2300 | cur_arg = 6; |
| 2301 | curproxy->options2 &= ~PR_O2_AS_REQL; |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2302 | curproxy->options2 &= ~PR_O2_AS_M_ANY; |
| 2303 | curproxy->options2 |= PR_O2_AS_M_PP; |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2304 | while (*(args[cur_arg])) { |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2305 | if (!strcmp(args[cur_arg], "request-learn")) { |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2306 | curproxy->options2 |= PR_O2_AS_REQL; |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2307 | } else if (!strcmp(args[cur_arg], "prefix")) { |
| 2308 | curproxy->options2 |= PR_O2_AS_PFX; |
| 2309 | } else if (!strcmp(args[cur_arg], "mode")) { |
| 2310 | if (!*args[cur_arg + 1]) { |
| 2311 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 2312 | file, linenum, args[0], args[cur_arg]); |
| 2313 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2314 | goto out; |
| 2315 | } |
| 2316 | |
| 2317 | cur_arg++; |
| 2318 | if (!strcmp(args[cur_arg], "query-string")) { |
| 2319 | curproxy->options2 &= ~PR_O2_AS_M_ANY; |
| 2320 | curproxy->options2 |= PR_O2_AS_M_QS; |
| 2321 | } else if (!strcmp(args[cur_arg], "path-parameters")) { |
| 2322 | curproxy->options2 &= ~PR_O2_AS_M_ANY; |
| 2323 | curproxy->options2 |= PR_O2_AS_M_PP; |
| 2324 | } else { |
| 2325 | Alert("parsing [%s:%d] : unknown mode '%s'\n", file, linenum, args[cur_arg]); |
| 2326 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2327 | goto out; |
| 2328 | } |
| 2329 | } |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2330 | cur_arg++; |
| 2331 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2332 | } /* Url App Session */ |
| 2333 | else if (!strcmp(args[0], "capture")) { |
Willy Tarreau | 3b6b1a9 | 2009-07-23 13:24:23 +0200 | [diff] [blame] | 2334 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2335 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2336 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2337 | if (!strcmp(args[1], "cookie")) { /* name of a cookie to capture */ |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 2338 | if (curproxy == &defproxy) { |
| 2339 | Alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
| 2340 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2341 | goto out; |
| 2342 | } |
| 2343 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2344 | if (*(args[4]) == 0) { |
| 2345 | Alert("parsing [%s:%d] : '%s' expects 'cookie' <cookie_name> 'len' <len>.\n", |
| 2346 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2347 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2348 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2349 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2350 | free(curproxy->capture_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2351 | curproxy->capture_name = strdup(args[2]); |
| 2352 | curproxy->capture_namelen = strlen(curproxy->capture_name); |
| 2353 | curproxy->capture_len = atol(args[4]); |
| 2354 | if (curproxy->capture_len >= CAPTURE_LEN) { |
| 2355 | Warning("parsing [%s:%d] : truncating capture length to %d bytes.\n", |
| 2356 | file, linenum, CAPTURE_LEN - 1); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2357 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2358 | curproxy->capture_len = CAPTURE_LEN - 1; |
| 2359 | } |
| 2360 | curproxy->to_log |= LW_COOKIE; |
| 2361 | } |
| 2362 | else if (!strcmp(args[1], "request") && !strcmp(args[2], "header")) { |
| 2363 | struct cap_hdr *hdr; |
| 2364 | |
| 2365 | if (curproxy == &defproxy) { |
| 2366 | Alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2367 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2368 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2369 | } |
| 2370 | |
| 2371 | if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) { |
| 2372 | Alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n", |
| 2373 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2374 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2375 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2376 | } |
| 2377 | |
| 2378 | hdr = calloc(sizeof(struct cap_hdr), 1); |
| 2379 | hdr->next = curproxy->req_cap; |
| 2380 | hdr->name = strdup(args[3]); |
| 2381 | hdr->namelen = strlen(args[3]); |
| 2382 | hdr->len = atol(args[5]); |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 2383 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2384 | hdr->index = curproxy->nb_req_cap++; |
| 2385 | curproxy->req_cap = hdr; |
| 2386 | curproxy->to_log |= LW_REQHDR; |
| 2387 | } |
| 2388 | else if (!strcmp(args[1], "response") && !strcmp(args[2], "header")) { |
| 2389 | struct cap_hdr *hdr; |
| 2390 | |
| 2391 | if (curproxy == &defproxy) { |
| 2392 | Alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2393 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2394 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2395 | } |
| 2396 | |
| 2397 | if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) { |
| 2398 | Alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n", |
| 2399 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2400 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2401 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2402 | } |
| 2403 | hdr = calloc(sizeof(struct cap_hdr), 1); |
| 2404 | hdr->next = curproxy->rsp_cap; |
| 2405 | hdr->name = strdup(args[3]); |
| 2406 | hdr->namelen = strlen(args[3]); |
| 2407 | hdr->len = atol(args[5]); |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 2408 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2409 | hdr->index = curproxy->nb_rsp_cap++; |
| 2410 | curproxy->rsp_cap = hdr; |
| 2411 | curproxy->to_log |= LW_RSPHDR; |
| 2412 | } |
| 2413 | else { |
| 2414 | Alert("parsing [%s:%d] : '%s' expects 'cookie' or 'request header' or 'response header'.\n", |
| 2415 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2416 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2417 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2418 | } |
| 2419 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2420 | else if (!strcmp(args[0], "retries")) { /* connection retries */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2421 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2422 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2423 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2424 | if (*(args[1]) == 0) { |
| 2425 | Alert("parsing [%s:%d] : '%s' expects an integer argument (dispatch counts for one).\n", |
| 2426 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2427 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2428 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2429 | } |
| 2430 | curproxy->conn_retries = atol(args[1]); |
| 2431 | } |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2432 | else if (!strcmp(args[0], "http-request")) { /* request access control: allow/deny/auth */ |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 2433 | struct http_req_rule *rule; |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2434 | |
| 2435 | if (curproxy == &defproxy) { |
| 2436 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2437 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2438 | goto out; |
| 2439 | } |
| 2440 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 2441 | if (!LIST_ISEMPTY(&curproxy->http_req_rules) && !LIST_PREV(&curproxy->http_req_rules, struct http_req_rule *, list)->cond) { |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2442 | Warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n", |
| 2443 | file, linenum, args[0]); |
| 2444 | err_code |= ERR_WARN; |
| 2445 | } |
| 2446 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 2447 | rule = parse_http_req_cond((const char **)args + 1, file, linenum, curproxy); |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2448 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 2449 | if (!rule) { |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2450 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2451 | goto out; |
| 2452 | } |
| 2453 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 2454 | err_code |= warnif_cond_requires_resp(rule->cond, file, linenum); |
| 2455 | LIST_ADDQ(&curproxy->http_req_rules, &rule->list); |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2456 | } |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2457 | else if (!strcmp(args[0], "block")) { /* early blocking based on ACLs */ |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2458 | if (curproxy == &defproxy) { |
| 2459 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2460 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2461 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2462 | } |
| 2463 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2464 | if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) { |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2465 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 2466 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2467 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2468 | goto out; |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2469 | } |
| 2470 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2471 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 1)) == NULL) { |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2472 | Alert("parsing [%s:%d] : error detected while parsing blocking condition.\n", |
| 2473 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2474 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2475 | goto out; |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2476 | } |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2477 | |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2478 | LIST_ADDQ(&curproxy->block_cond, &cond->list); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 2479 | warnif_misplaced_block(curproxy, file, linenum, args[0]); |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2480 | } |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2481 | else if (!strcmp(args[0], "redirect")) { |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2482 | struct redirect_rule *rule; |
| 2483 | int cur_arg; |
| 2484 | int type = REDIRECT_TYPE_NONE; |
| 2485 | int code = 302; |
| 2486 | char *destination = NULL; |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2487 | char *cookie = NULL; |
| 2488 | int cookie_set = 0; |
Willy Tarreau | 79da469 | 2008-11-19 20:03:04 +0100 | [diff] [blame] | 2489 | unsigned int flags = REDIRECT_FLAG_NONE; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2490 | |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 2491 | if (curproxy == &defproxy) { |
| 2492 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2493 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2494 | goto out; |
| 2495 | } |
| 2496 | |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2497 | cur_arg = 1; |
| 2498 | while (*(args[cur_arg])) { |
| 2499 | if (!strcmp(args[cur_arg], "location")) { |
| 2500 | if (!*args[cur_arg + 1]) { |
| 2501 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 2502 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2503 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2504 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2505 | } |
| 2506 | |
| 2507 | type = REDIRECT_TYPE_LOCATION; |
| 2508 | cur_arg++; |
| 2509 | destination = args[cur_arg]; |
| 2510 | } |
| 2511 | else if (!strcmp(args[cur_arg], "prefix")) { |
| 2512 | if (!*args[cur_arg + 1]) { |
| 2513 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 2514 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2515 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2516 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2517 | } |
| 2518 | |
| 2519 | type = REDIRECT_TYPE_PREFIX; |
| 2520 | cur_arg++; |
| 2521 | destination = args[cur_arg]; |
| 2522 | } |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2523 | else if (!strcmp(args[cur_arg], "set-cookie")) { |
| 2524 | if (!*args[cur_arg + 1]) { |
| 2525 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 2526 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2527 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2528 | goto out; |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2529 | } |
| 2530 | |
| 2531 | cur_arg++; |
| 2532 | cookie = args[cur_arg]; |
| 2533 | cookie_set = 1; |
| 2534 | } |
| 2535 | else if (!strcmp(args[cur_arg], "clear-cookie")) { |
| 2536 | if (!*args[cur_arg + 1]) { |
| 2537 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 2538 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2539 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2540 | goto out; |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2541 | } |
| 2542 | |
| 2543 | cur_arg++; |
| 2544 | cookie = args[cur_arg]; |
| 2545 | cookie_set = 0; |
| 2546 | } |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2547 | else if (!strcmp(args[cur_arg],"code")) { |
| 2548 | if (!*args[cur_arg + 1]) { |
| 2549 | Alert("parsing [%s:%d] : '%s': missing HTTP code.\n", |
| 2550 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2551 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2552 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2553 | } |
| 2554 | cur_arg++; |
| 2555 | code = atol(args[cur_arg]); |
| 2556 | if (code < 301 || code > 303) { |
| 2557 | Alert("parsing [%s:%d] : '%s': unsupported HTTP code '%d'.\n", |
| 2558 | file, linenum, args[0], code); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2559 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2560 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2561 | } |
| 2562 | } |
Willy Tarreau | 79da469 | 2008-11-19 20:03:04 +0100 | [diff] [blame] | 2563 | else if (!strcmp(args[cur_arg],"drop-query")) { |
| 2564 | flags |= REDIRECT_FLAG_DROP_QS; |
| 2565 | } |
Willy Tarreau | 81e3b4f | 2010-01-10 00:42:19 +0100 | [diff] [blame] | 2566 | else if (!strcmp(args[cur_arg],"append-slash")) { |
| 2567 | flags |= REDIRECT_FLAG_APPEND_SLASH; |
| 2568 | } |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2569 | else if (strcmp(args[cur_arg], "if") == 0 || |
| 2570 | strcmp(args[cur_arg], "unless") == 0) { |
| 2571 | cond = build_acl_cond(file, linenum, curproxy, (const char **)args + cur_arg); |
| 2572 | if (!cond) { |
| 2573 | Alert("parsing [%s:%d] : '%s': error detected while parsing redirect condition.\n", |
| 2574 | file, linenum, args[0]); |
| 2575 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2576 | goto out; |
| 2577 | } |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2578 | break; |
| 2579 | } |
| 2580 | else { |
Willy Tarreau | 81e3b4f | 2010-01-10 00:42:19 +0100 | [diff] [blame] | 2581 | Alert("parsing [%s:%d] : '%s' expects 'code', 'prefix', 'location', 'set-cookie', 'clear-cookie', 'drop-query' or 'append-slash' (was '%s').\n", |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2582 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2583 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2584 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2585 | } |
| 2586 | cur_arg++; |
| 2587 | } |
| 2588 | |
| 2589 | if (type == REDIRECT_TYPE_NONE) { |
| 2590 | Alert("parsing [%s:%d] : '%s' expects a redirection type ('prefix' or 'location').\n", |
| 2591 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2592 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2593 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2594 | } |
| 2595 | |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2596 | rule = (struct redirect_rule *)calloc(1, sizeof(*rule)); |
| 2597 | rule->cond = cond; |
| 2598 | rule->rdr_str = strdup(destination); |
| 2599 | rule->rdr_len = strlen(destination); |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2600 | if (cookie) { |
| 2601 | /* depending on cookie_set, either we want to set the cookie, or to clear it. |
William Turner | d986526 | 2010-03-01 13:30:34 -0500 | [diff] [blame] | 2602 | * a clear consists in appending "; path=/; Max-Age=0;" at the end. |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2603 | */ |
| 2604 | rule->cookie_len = strlen(cookie); |
William Turner | d986526 | 2010-03-01 13:30:34 -0500 | [diff] [blame] | 2605 | if (cookie_set) { |
| 2606 | rule->cookie_str = malloc(rule->cookie_len + 10); |
| 2607 | memcpy(rule->cookie_str, cookie, rule->cookie_len); |
| 2608 | memcpy(rule->cookie_str + rule->cookie_len, "; path=/;", 10); |
| 2609 | rule->cookie_len += 9; |
| 2610 | } else { |
| 2611 | rule->cookie_str = malloc(rule->cookie_len + 21); |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2612 | memcpy(rule->cookie_str, cookie, rule->cookie_len); |
William Turner | d986526 | 2010-03-01 13:30:34 -0500 | [diff] [blame] | 2613 | memcpy(rule->cookie_str + rule->cookie_len, "; path=/; Max-Age=0;", 21); |
| 2614 | rule->cookie_len += 20; |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2615 | } |
| 2616 | } |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2617 | rule->type = type; |
| 2618 | rule->code = code; |
Willy Tarreau | 79da469 | 2008-11-19 20:03:04 +0100 | [diff] [blame] | 2619 | rule->flags = flags; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2620 | LIST_INIT(&rule->list); |
| 2621 | LIST_ADDQ(&curproxy->redirect_rules, &rule->list); |
Willy Tarreau | 9d9ed01 | 2011-02-23 15:24:42 +0100 | [diff] [blame] | 2622 | err_code |= warnif_rule_after_use_backend(curproxy, file, linenum, args[0]); |
| 2623 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2624 | } |
Krzysztof Piotr Oledzki | 7b723ef | 2009-01-27 21:09:41 +0100 | [diff] [blame] | 2625 | else if (!strcmp(args[0], "use_backend")) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2626 | struct switching_rule *rule; |
| 2627 | |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2628 | if (curproxy == &defproxy) { |
| 2629 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2630 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2631 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2632 | } |
| 2633 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2634 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2635 | err_code |= ERR_WARN; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2636 | |
| 2637 | if (*(args[1]) == 0) { |
| 2638 | Alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2639 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2640 | goto out; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2641 | } |
| 2642 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2643 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2644 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 2645 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2646 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2647 | goto out; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2648 | } |
| 2649 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2650 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2)) == NULL) { |
Willy Tarreau | a980263 | 2008-07-25 19:13:19 +0200 | [diff] [blame] | 2651 | Alert("parsing [%s:%d] : error detected while parsing switching rule.\n", |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2652 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2653 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2654 | goto out; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2655 | } |
| 2656 | |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 2657 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
Willy Tarreau | a980263 | 2008-07-25 19:13:19 +0200 | [diff] [blame] | 2658 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2659 | rule = (struct switching_rule *)calloc(1, sizeof(*rule)); |
| 2660 | rule->cond = cond; |
| 2661 | rule->be.name = strdup(args[1]); |
| 2662 | LIST_INIT(&rule->list); |
| 2663 | LIST_ADDQ(&curproxy->switching_rules, &rule->list); |
| 2664 | } |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 2665 | else if ((!strcmp(args[0], "force-persist")) || |
| 2666 | (!strcmp(args[0], "ignore-persist"))) { |
| 2667 | struct persist_rule *rule; |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2668 | |
| 2669 | if (curproxy == &defproxy) { |
| 2670 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2671 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2672 | goto out; |
| 2673 | } |
| 2674 | |
| 2675 | if (warnifnotcap(curproxy, PR_CAP_FE|PR_CAP_BE, file, linenum, args[0], NULL)) |
| 2676 | err_code |= ERR_WARN; |
| 2677 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2678 | if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) { |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2679 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 2680 | file, linenum, args[0]); |
| 2681 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2682 | goto out; |
| 2683 | } |
| 2684 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2685 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 1)) == NULL) { |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 2686 | Alert("parsing [%s:%d] : error detected while parsing a '%s' rule.\n", |
| 2687 | file, linenum, args[0]); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2688 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2689 | goto out; |
| 2690 | } |
| 2691 | |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 2692 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2693 | |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 2694 | rule = (struct persist_rule *)calloc(1, sizeof(*rule)); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2695 | rule->cond = cond; |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 2696 | if (!strcmp(args[0], "force-persist")) { |
| 2697 | rule->type = PERSIST_TYPE_FORCE; |
| 2698 | } else { |
| 2699 | rule->type = PERSIST_TYPE_IGNORE; |
| 2700 | } |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2701 | LIST_INIT(&rule->list); |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 2702 | LIST_ADDQ(&curproxy->persist_rules, &rule->list); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2703 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2704 | else if (!strcmp(args[0], "stick-table")) { |
| 2705 | int myidx = 1; |
| 2706 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2707 | curproxy->table.id = curproxy->id; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2708 | curproxy->table.type = (unsigned int)-1; |
| 2709 | while (*args[myidx]) { |
| 2710 | const char *err; |
| 2711 | |
| 2712 | if (strcmp(args[myidx], "size") == 0) { |
| 2713 | myidx++; |
| 2714 | if (!*(args[myidx])) { |
| 2715 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 2716 | file, linenum, args[myidx-1]); |
| 2717 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2718 | goto out; |
| 2719 | } |
| 2720 | if ((err = parse_size_err(args[myidx], &curproxy->table.size))) { |
| 2721 | Alert("parsing [%s:%d] : stick-table: unexpected character '%c' in argument of '%s'.\n", |
| 2722 | file, linenum, *err, args[myidx-1]); |
| 2723 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2724 | goto out; |
| 2725 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 2726 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2727 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2728 | else if (strcmp(args[myidx], "peers") == 0) { |
| 2729 | myidx++; |
| 2730 | if (!*(args[myidx])) { |
| 2731 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 2732 | file, linenum, args[myidx-1]); |
| 2733 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2734 | goto out; |
| 2735 | } |
| 2736 | curproxy->table.peers.name = strdup(args[myidx++]); |
| 2737 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2738 | else if (strcmp(args[myidx], "expire") == 0) { |
| 2739 | myidx++; |
| 2740 | if (!*(args[myidx])) { |
| 2741 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 2742 | file, linenum, args[myidx-1]); |
| 2743 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2744 | goto out; |
| 2745 | } |
| 2746 | err = parse_time_err(args[myidx], &val, TIME_UNIT_MS); |
| 2747 | if (err) { |
| 2748 | Alert("parsing [%s:%d] : stick-table: unexpected character '%c' in argument of '%s'.\n", |
| 2749 | file, linenum, *err, args[myidx-1]); |
| 2750 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2751 | goto out; |
| 2752 | } |
| 2753 | curproxy->table.expire = val; |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 2754 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2755 | } |
| 2756 | else if (strcmp(args[myidx], "nopurge") == 0) { |
| 2757 | curproxy->table.nopurge = 1; |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 2758 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2759 | } |
| 2760 | else if (strcmp(args[myidx], "type") == 0) { |
| 2761 | myidx++; |
| 2762 | if (stktable_parse_type(args, &myidx, &curproxy->table.type, &curproxy->table.key_size) != 0) { |
| 2763 | Alert("parsing [%s:%d] : stick-table: unknown type '%s'.\n", |
| 2764 | file, linenum, args[myidx]); |
| 2765 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2766 | goto out; |
| 2767 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 2768 | /* myidx already points to next arg */ |
| 2769 | } |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 2770 | else if (strcmp(args[myidx], "store") == 0) { |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 2771 | int type, err; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 2772 | char *cw, *nw, *sa; |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 2773 | |
| 2774 | myidx++; |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 2775 | nw = args[myidx]; |
| 2776 | while (*nw) { |
| 2777 | /* the "store" keyword supports a comma-separated list */ |
| 2778 | cw = nw; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 2779 | sa = NULL; /* store arg */ |
| 2780 | while (*nw && *nw != ',') { |
| 2781 | if (*nw == '(') { |
| 2782 | *nw = 0; |
| 2783 | sa = ++nw; |
| 2784 | while (*nw != ')') { |
| 2785 | if (!*nw) { |
| 2786 | Alert("parsing [%s:%d] : %s: missing closing parenthesis after store option '%s'.\n", |
| 2787 | file, linenum, args[0], cw); |
| 2788 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2789 | goto out; |
| 2790 | } |
| 2791 | nw++; |
| 2792 | } |
| 2793 | *nw = '\0'; |
| 2794 | } |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 2795 | nw++; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 2796 | } |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 2797 | if (*nw) |
| 2798 | *nw++ = '\0'; |
| 2799 | type = stktable_get_data_type(cw); |
| 2800 | if (type < 0) { |
| 2801 | Alert("parsing [%s:%d] : %s: unknown store option '%s'.\n", |
| 2802 | file, linenum, args[0], cw); |
| 2803 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2804 | goto out; |
| 2805 | } |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 2806 | |
| 2807 | err = stktable_alloc_data_type(&curproxy->table, type, sa); |
| 2808 | switch (err) { |
| 2809 | case PE_NONE: break; |
| 2810 | case PE_EXIST: |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 2811 | Warning("parsing [%s:%d]: %s: store option '%s' already enabled, ignored.\n", |
| 2812 | file, linenum, args[0], cw); |
| 2813 | err_code |= ERR_WARN; |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 2814 | break; |
| 2815 | |
| 2816 | case PE_ARG_MISSING: |
| 2817 | Alert("parsing [%s:%d] : %s: missing argument to store option '%s'.\n", |
| 2818 | file, linenum, args[0], cw); |
| 2819 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2820 | goto out; |
| 2821 | |
| 2822 | case PE_ARG_NOT_USED: |
| 2823 | Alert("parsing [%s:%d] : %s: unexpected argument to store option '%s'.\n", |
| 2824 | file, linenum, args[0], cw); |
| 2825 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2826 | goto out; |
| 2827 | |
| 2828 | default: |
| 2829 | Alert("parsing [%s:%d] : %s: error when processing store option '%s'.\n", |
| 2830 | file, linenum, args[0], cw); |
| 2831 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2832 | goto out; |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 2833 | } |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 2834 | } |
| 2835 | myidx++; |
| 2836 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 2837 | else { |
| 2838 | Alert("parsing [%s:%d] : stick-table: unknown argument '%s'.\n", |
| 2839 | file, linenum, args[myidx]); |
| 2840 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2841 | goto out; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2842 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2843 | } |
| 2844 | |
| 2845 | if (!curproxy->table.size) { |
| 2846 | Alert("parsing [%s:%d] : stick-table: missing size.\n", |
| 2847 | file, linenum); |
| 2848 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2849 | goto out; |
| 2850 | } |
| 2851 | |
| 2852 | if (curproxy->table.type == (unsigned int)-1) { |
| 2853 | Alert("parsing [%s:%d] : stick-table: missing type.\n", |
| 2854 | file, linenum); |
| 2855 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2856 | goto out; |
| 2857 | } |
| 2858 | } |
| 2859 | else if (!strcmp(args[0], "stick")) { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2860 | struct sticking_rule *rule; |
| 2861 | struct pattern_expr *expr; |
| 2862 | int myidx = 0; |
| 2863 | const char *name = NULL; |
| 2864 | int flags; |
| 2865 | |
| 2866 | if (curproxy == &defproxy) { |
| 2867 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2868 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2869 | goto out; |
| 2870 | } |
| 2871 | |
| 2872 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) { |
| 2873 | err_code |= ERR_WARN; |
| 2874 | goto out; |
| 2875 | } |
| 2876 | |
| 2877 | myidx++; |
| 2878 | if ((strcmp(args[myidx], "store") == 0) || |
| 2879 | (strcmp(args[myidx], "store-request") == 0)) { |
| 2880 | myidx++; |
| 2881 | flags = STK_IS_STORE; |
| 2882 | } |
| 2883 | else if (strcmp(args[myidx], "store-response") == 0) { |
| 2884 | myidx++; |
| 2885 | flags = STK_IS_STORE | STK_ON_RSP; |
| 2886 | } |
| 2887 | else if (strcmp(args[myidx], "match") == 0) { |
| 2888 | myidx++; |
| 2889 | flags = STK_IS_MATCH; |
| 2890 | } |
| 2891 | else if (strcmp(args[myidx], "on") == 0) { |
| 2892 | myidx++; |
| 2893 | flags = STK_IS_MATCH | STK_IS_STORE; |
| 2894 | } |
| 2895 | else { |
| 2896 | Alert("parsing [%s:%d] : '%s' expects 'on', 'match', or 'store'.\n", file, linenum, args[0]); |
| 2897 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2898 | goto out; |
| 2899 | } |
| 2900 | |
| 2901 | if (*(args[myidx]) == 0) { |
| 2902 | Alert("parsing [%s:%d] : '%s' expects a fetch method.\n", file, linenum, args[0]); |
| 2903 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2904 | goto out; |
| 2905 | } |
| 2906 | |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 2907 | expr = pattern_parse_expr(args, &myidx, trash, sizeof(trash)); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2908 | if (!expr) { |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 2909 | Alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], trash); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2910 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2911 | goto out; |
| 2912 | } |
| 2913 | |
| 2914 | if (flags & STK_ON_RSP) { |
| 2915 | if (!(expr->fetch->dir & PATTERN_FETCH_RTR)) { |
| 2916 | Alert("parsing [%s:%d] : '%s': fetch method '%s' can not be used on response.\n", |
| 2917 | file, linenum, args[0], expr->fetch->kw); |
| 2918 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 2919 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2920 | goto out; |
| 2921 | } |
| 2922 | } else { |
| 2923 | if (!(expr->fetch->dir & PATTERN_FETCH_REQ)) { |
| 2924 | Alert("parsing [%s:%d] : '%s': fetch method '%s' can not be used on request.\n", |
| 2925 | file, linenum, args[0], expr->fetch->kw); |
| 2926 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 2927 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2928 | goto out; |
| 2929 | } |
| 2930 | } |
| 2931 | |
| 2932 | if (strcmp(args[myidx], "table") == 0) { |
| 2933 | myidx++; |
| 2934 | name = args[myidx++]; |
| 2935 | } |
| 2936 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2937 | if (strcmp(args[myidx], "if") == 0 || strcmp(args[myidx], "unless") == 0) { |
| 2938 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + myidx)) == NULL) { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2939 | Alert("parsing [%s:%d] : '%s': error detected while parsing sticking condition.\n", |
| 2940 | file, linenum, args[0]); |
| 2941 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 2942 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2943 | goto out; |
| 2944 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2945 | } |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2946 | else if (*(args[myidx])) { |
| 2947 | Alert("parsing [%s:%d] : '%s': unknown keyword '%s'.\n", |
| 2948 | file, linenum, args[0], args[myidx]); |
| 2949 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 2950 | free(expr); |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2951 | goto out; |
| 2952 | } |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 2953 | if (flags & STK_ON_RSP) |
| 2954 | err_code |= warnif_cond_requires_req(cond, file, linenum); |
| 2955 | else |
| 2956 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 2957 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2958 | rule = (struct sticking_rule *)calloc(1, sizeof(*rule)); |
| 2959 | rule->cond = cond; |
| 2960 | rule->expr = expr; |
| 2961 | rule->flags = flags; |
| 2962 | rule->table.name = name ? strdup(name) : NULL; |
| 2963 | LIST_INIT(&rule->list); |
| 2964 | if (flags & STK_ON_RSP) |
| 2965 | LIST_ADDQ(&curproxy->storersp_rules, &rule->list); |
| 2966 | else |
| 2967 | LIST_ADDQ(&curproxy->sticking_rules, &rule->list); |
| 2968 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2969 | else if (!strcmp(args[0], "stats")) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2970 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2971 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2972 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2973 | if (curproxy != &defproxy && curproxy->uri_auth == defproxy.uri_auth) |
| 2974 | curproxy->uri_auth = NULL; /* we must detach from the default config */ |
| 2975 | |
Krzysztof Piotr Oledzki | 260a3bb | 2010-01-06 16:25:05 +0100 | [diff] [blame] | 2976 | if (!*args[1]) { |
| 2977 | goto stats_error_parsing; |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 2978 | } else if (!strcmp(args[1], "admin")) { |
| 2979 | struct stats_admin_rule *rule; |
| 2980 | |
| 2981 | if (curproxy == &defproxy) { |
| 2982 | Alert("parsing [%s:%d]: '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
| 2983 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2984 | goto out; |
| 2985 | } |
| 2986 | |
| 2987 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 2988 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 2989 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2990 | goto out; |
| 2991 | } |
| 2992 | |
| 2993 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
| 2994 | Alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n", |
| 2995 | file, linenum, args[0], args[1]); |
| 2996 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2997 | goto out; |
| 2998 | } |
| 2999 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2)) == NULL) { |
| 3000 | Alert("parsing [%s:%d] : error detected while parsing a '%s %s' rule.\n", |
| 3001 | file, linenum, args[0], args[1]); |
| 3002 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3003 | goto out; |
| 3004 | } |
| 3005 | |
| 3006 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
| 3007 | |
| 3008 | rule = (struct stats_admin_rule *)calloc(1, sizeof(*rule)); |
| 3009 | rule->cond = cond; |
| 3010 | LIST_INIT(&rule->list); |
| 3011 | LIST_ADDQ(&curproxy->uri_auth->admin_rules, &rule->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3012 | } else if (!strcmp(args[1], "uri")) { |
| 3013 | if (*(args[2]) == 0) { |
| 3014 | Alert("parsing [%s:%d] : 'uri' needs an URI prefix.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3015 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3016 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3017 | } else if (!stats_set_uri(&curproxy->uri_auth, args[2])) { |
| 3018 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3019 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3020 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3021 | } |
| 3022 | } else if (!strcmp(args[1], "realm")) { |
| 3023 | if (*(args[2]) == 0) { |
| 3024 | Alert("parsing [%s:%d] : 'realm' needs an realm name.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3025 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3026 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3027 | } else if (!stats_set_realm(&curproxy->uri_auth, args[2])) { |
| 3028 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3029 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3030 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3031 | } |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 3032 | } else if (!strcmp(args[1], "refresh")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 3033 | unsigned interval; |
| 3034 | |
| 3035 | err = parse_time_err(args[2], &interval, TIME_UNIT_S); |
| 3036 | if (err) { |
| 3037 | Alert("parsing [%s:%d] : unexpected character '%c' in stats refresh interval.\n", |
| 3038 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3039 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3040 | goto out; |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 3041 | } else if (!stats_set_refresh(&curproxy->uri_auth, interval)) { |
| 3042 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3043 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3044 | goto out; |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 3045 | } |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3046 | } else if (!strcmp(args[1], "http-request")) { /* request access control: allow/deny/auth */ |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3047 | struct http_req_rule *rule; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3048 | |
| 3049 | if (curproxy == &defproxy) { |
| 3050 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3051 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3052 | goto out; |
| 3053 | } |
| 3054 | |
| 3055 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 3056 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3057 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3058 | goto out; |
| 3059 | } |
| 3060 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3061 | if (!LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) && |
| 3062 | !LIST_PREV(&curproxy->uri_auth->http_req_rules, struct http_req_rule *, list)->cond) { |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3063 | Warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n", |
| 3064 | file, linenum, args[0]); |
| 3065 | err_code |= ERR_WARN; |
| 3066 | } |
| 3067 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3068 | rule = parse_http_req_cond((const char **)args + 2, file, linenum, curproxy); |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3069 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3070 | if (!rule) { |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3071 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3072 | goto out; |
| 3073 | } |
| 3074 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3075 | err_code |= warnif_cond_requires_resp(rule->cond, file, linenum); |
| 3076 | LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list); |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3077 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3078 | } else if (!strcmp(args[1], "auth")) { |
| 3079 | if (*(args[2]) == 0) { |
| 3080 | Alert("parsing [%s:%d] : 'auth' needs a user:password account.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3081 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3082 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3083 | } else if (!stats_add_auth(&curproxy->uri_auth, args[2])) { |
| 3084 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3085 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3086 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3087 | } |
| 3088 | } else if (!strcmp(args[1], "scope")) { |
| 3089 | if (*(args[2]) == 0) { |
| 3090 | Alert("parsing [%s:%d] : 'scope' needs a proxy name.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3091 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3092 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3093 | } else if (!stats_add_scope(&curproxy->uri_auth, args[2])) { |
| 3094 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3095 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3096 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3097 | } |
| 3098 | } else if (!strcmp(args[1], "enable")) { |
| 3099 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 3100 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3101 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3102 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3103 | } |
Krzysztof Oledzki | d9db927 | 2007-10-15 10:05:11 +0200 | [diff] [blame] | 3104 | } else if (!strcmp(args[1], "hide-version")) { |
| 3105 | if (!stats_set_flag(&curproxy->uri_auth, ST_HIDEVER)) { |
| 3106 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3107 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3108 | goto out; |
Krzysztof Oledzki | d9db927 | 2007-10-15 10:05:11 +0200 | [diff] [blame] | 3109 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3110 | } else if (!strcmp(args[1], "show-legends")) { |
| 3111 | if (!stats_set_flag(&curproxy->uri_auth, ST_SHLGNDS)) { |
| 3112 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3113 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3114 | goto out; |
| 3115 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3116 | } else if (!strcmp(args[1], "show-node")) { |
| 3117 | |
| 3118 | if (*args[2]) { |
| 3119 | int i; |
| 3120 | char c; |
| 3121 | |
| 3122 | for (i=0; args[2][i]; i++) { |
| 3123 | c = args[2][i]; |
Willy Tarreau | 88e0581 | 2010-03-03 00:16:00 +0100 | [diff] [blame] | 3124 | if (!isupper((unsigned char)c) && !islower((unsigned char)c) && |
| 3125 | !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.') |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3126 | break; |
| 3127 | } |
| 3128 | |
| 3129 | if (!i || args[2][i]) { |
| 3130 | Alert("parsing [%s:%d]: '%s %s' invalid node name - should be a string" |
| 3131 | "with digits(0-9), letters(A-Z, a-z), hyphen(-) or underscode(_).\n", |
| 3132 | file, linenum, args[0], args[1]); |
| 3133 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3134 | goto out; |
| 3135 | } |
| 3136 | } |
| 3137 | |
| 3138 | if (!stats_set_node(&curproxy->uri_auth, args[2])) { |
| 3139 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3140 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3141 | goto out; |
| 3142 | } |
| 3143 | } else if (!strcmp(args[1], "show-desc")) { |
| 3144 | char *desc = NULL; |
| 3145 | |
| 3146 | if (*args[2]) { |
| 3147 | int i, len=0; |
| 3148 | char *d; |
| 3149 | |
| 3150 | for(i=2; *args[i]; i++) |
| 3151 | len += strlen(args[i])+1; |
| 3152 | |
| 3153 | desc = d = (char *)calloc(1, len); |
| 3154 | |
| 3155 | d += sprintf(d, "%s", args[2]); |
| 3156 | for(i=3; *args[i]; i++) |
| 3157 | d += sprintf(d, " %s", args[i]); |
| 3158 | } |
| 3159 | |
| 3160 | if (!*args[2] && !global.desc) |
| 3161 | Warning("parsing [%s:%d]: '%s' requires a parameter or 'desc' to be set in the global section.\n", |
| 3162 | file, linenum, args[1]); |
| 3163 | else { |
| 3164 | if (!stats_set_desc(&curproxy->uri_auth, desc)) { |
| 3165 | free(desc); |
| 3166 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3167 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3168 | goto out; |
| 3169 | } |
| 3170 | free(desc); |
| 3171 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3172 | } else { |
Krzysztof Piotr Oledzki | 260a3bb | 2010-01-06 16:25:05 +0100 | [diff] [blame] | 3173 | stats_error_parsing: |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3174 | Alert("parsing [%s:%d]: %s '%s', expects 'admin', 'uri', 'realm', 'auth', 'scope', 'enable', 'hide-version', 'show-node', 'show-desc' or 'show-legends'.\n", |
Krzysztof Piotr Oledzki | 260a3bb | 2010-01-06 16:25:05 +0100 | [diff] [blame] | 3175 | file, linenum, *args[1]?"unknown stats parameter":"missing keyword in", args[*args[1]?1:0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3176 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3177 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3178 | } |
| 3179 | } |
| 3180 | else if (!strcmp(args[0], "option")) { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3181 | int optnum; |
| 3182 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3183 | if (*(args[1]) == '\0') { |
| 3184 | Alert("parsing [%s:%d]: '%s' expects an option name.\n", |
| 3185 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3186 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3187 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3188 | } |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3189 | |
| 3190 | for (optnum = 0; cfg_opts[optnum].name; optnum++) { |
| 3191 | if (!strcmp(args[1], cfg_opts[optnum].name)) { |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 3192 | if (cfg_opts[optnum].cap == PR_CAP_NONE) { |
| 3193 | Alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n", |
| 3194 | file, linenum, cfg_opts[optnum].name); |
| 3195 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3196 | goto out; |
| 3197 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3198 | if (warnifnotcap(curproxy, cfg_opts[optnum].cap, file, linenum, args[1], NULL)) { |
| 3199 | err_code |= ERR_WARN; |
| 3200 | goto out; |
| 3201 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3202 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 3203 | curproxy->no_options &= ~cfg_opts[optnum].val; |
| 3204 | curproxy->options &= ~cfg_opts[optnum].val; |
| 3205 | |
| 3206 | switch (kwm) { |
| 3207 | case KWM_STD: |
| 3208 | curproxy->options |= cfg_opts[optnum].val; |
| 3209 | break; |
| 3210 | case KWM_NO: |
| 3211 | curproxy->no_options |= cfg_opts[optnum].val; |
| 3212 | break; |
| 3213 | case KWM_DEF: /* already cleared */ |
| 3214 | break; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 3215 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3216 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3217 | goto out; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3218 | } |
| 3219 | } |
| 3220 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 3221 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) { |
| 3222 | if (!strcmp(args[1], cfg_opts2[optnum].name)) { |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 3223 | if (cfg_opts2[optnum].cap == PR_CAP_NONE) { |
| 3224 | Alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n", |
| 3225 | file, linenum, cfg_opts2[optnum].name); |
| 3226 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3227 | goto out; |
| 3228 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3229 | if (warnifnotcap(curproxy, cfg_opts2[optnum].cap, file, linenum, args[1], NULL)) { |
| 3230 | err_code |= ERR_WARN; |
| 3231 | goto out; |
| 3232 | } |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 3233 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 3234 | curproxy->no_options2 &= ~cfg_opts2[optnum].val; |
| 3235 | curproxy->options2 &= ~cfg_opts2[optnum].val; |
| 3236 | |
| 3237 | switch (kwm) { |
| 3238 | case KWM_STD: |
| 3239 | curproxy->options2 |= cfg_opts2[optnum].val; |
| 3240 | break; |
| 3241 | case KWM_NO: |
| 3242 | curproxy->no_options2 |= cfg_opts2[optnum].val; |
| 3243 | break; |
| 3244 | case KWM_DEF: /* already cleared */ |
| 3245 | break; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 3246 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3247 | goto out; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 3248 | } |
| 3249 | } |
| 3250 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 3251 | if (kwm != KWM_STD) { |
| 3252 | Alert("parsing [%s:%d]: negation/default is not supported for option '%s'.\n", |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3253 | file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3254 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3255 | goto out; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3256 | } |
| 3257 | |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3258 | if (!strcmp(args[1], "httplog")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3259 | /* generate a complete HTTP log */ |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3260 | curproxy->options2 &= ~PR_O2_CLFLOG; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3261 | curproxy->to_log |= LW_DATE | LW_CLIP | LW_SVID | LW_REQ | LW_PXID | LW_RESP | LW_BYTES; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3262 | if (*(args[2]) != '\0') { |
| 3263 | if (!strcmp(args[2], "clf")) { |
| 3264 | curproxy->options2 |= PR_O2_CLFLOG; |
| 3265 | } else { |
| 3266 | Alert("parsing [%s:%d] : keyword '%s' only supports option 'clf'.\n", file, linenum, args[2]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3267 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3268 | goto out; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3269 | } |
| 3270 | } |
| 3271 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3272 | else if (!strcmp(args[1], "tcplog")) |
| 3273 | /* generate a detailed TCP log */ |
| 3274 | 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] | 3275 | else if (!strcmp(args[1], "tcpka")) { |
| 3276 | /* enable TCP keep-alives on client and server sessions */ |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3277 | if (warnifnotcap(curproxy, PR_CAP_BE | PR_CAP_FE, file, linenum, args[1], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3278 | err_code |= ERR_WARN; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3279 | |
| 3280 | if (curproxy->cap & PR_CAP_FE) |
| 3281 | curproxy->options |= PR_O_TCP_CLI_KA; |
| 3282 | if (curproxy->cap & PR_CAP_BE) |
| 3283 | curproxy->options |= PR_O_TCP_SRV_KA; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3284 | } |
| 3285 | else if (!strcmp(args[1], "httpchk")) { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3286 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3287 | err_code |= ERR_WARN; |
| 3288 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3289 | /* use HTTP request to check servers' health */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3290 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 3291 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3292 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 3293 | curproxy->options2 |= PR_O2_HTTP_CHK; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3294 | if (!*args[2]) { /* no argument */ |
| 3295 | curproxy->check_req = strdup(DEF_CHECK_REQ); /* default request */ |
| 3296 | curproxy->check_len = strlen(DEF_CHECK_REQ); |
| 3297 | } else if (!*args[3]) { /* one argument : URI */ |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3298 | int reqlen = strlen(args[2]) + strlen("OPTIONS HTTP/1.0\r\n") + 1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3299 | curproxy->check_req = (char *)malloc(reqlen); |
| 3300 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3301 | "OPTIONS %s HTTP/1.0\r\n", args[2]); /* URI to use */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3302 | } else { /* more arguments : METHOD URI [HTTP_VER] */ |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3303 | int reqlen = strlen(args[2]) + strlen(args[3]) + 3 + strlen("\r\n"); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3304 | if (*args[4]) |
| 3305 | reqlen += strlen(args[4]); |
| 3306 | else |
| 3307 | reqlen += strlen("HTTP/1.0"); |
| 3308 | |
| 3309 | curproxy->check_req = (char *)malloc(reqlen); |
| 3310 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3311 | "%s %s %s\r\n", args[2], args[3], *args[4]?args[4]:"HTTP/1.0"); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3312 | } |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 3313 | } |
| 3314 | else if (!strcmp(args[1], "ssl-hello-chk")) { |
| 3315 | /* use SSLv3 CLIENT HELLO to check servers' health */ |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3316 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3317 | err_code |= ERR_WARN; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3318 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3319 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 3320 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3321 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Willy Tarreau | 07a5490 | 2010-03-29 18:33:29 +0200 | [diff] [blame] | 3322 | curproxy->options2 |= PR_O2_SSL3_CHK; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3323 | } |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 3324 | else if (!strcmp(args[1], "smtpchk")) { |
| 3325 | /* use SMTP request to check servers' health */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3326 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 3327 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3328 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 3329 | curproxy->options2 |= PR_O2_SMTP_CHK; |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 3330 | |
| 3331 | if (!*args[2] || !*args[3]) { /* no argument or incomplete EHLO host */ |
| 3332 | curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */ |
| 3333 | curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ); |
| 3334 | } else { /* ESMTP EHLO, or SMTP HELO, and a hostname */ |
| 3335 | if (!strcmp(args[2], "EHLO") || !strcmp(args[2], "HELO")) { |
| 3336 | int reqlen = strlen(args[2]) + strlen(args[3]) + strlen(" \r\n") + 1; |
| 3337 | curproxy->check_req = (char *)malloc(reqlen); |
| 3338 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
| 3339 | "%s %s\r\n", args[2], args[3]); /* HELO hostname */ |
| 3340 | } else { |
| 3341 | /* this just hits the default for now, but you could potentially expand it to allow for other stuff |
| 3342 | though, it's unlikely you'd want to send anything other than an EHLO or HELO */ |
| 3343 | curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */ |
| 3344 | curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ); |
| 3345 | } |
| 3346 | } |
| 3347 | } |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 3348 | else if (!strcmp(args[1], "pgsql-check")) { |
| 3349 | /* use PostgreSQL request to check servers' health */ |
| 3350 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 3351 | err_code |= ERR_WARN; |
| 3352 | |
| 3353 | free(curproxy->check_req); |
| 3354 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3355 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 3356 | curproxy->options2 |= PR_O2_PGSQL_CHK; |
| 3357 | |
| 3358 | if (*(args[2])) { |
| 3359 | int cur_arg = 2; |
| 3360 | |
| 3361 | while (*(args[cur_arg])) { |
| 3362 | if (strcmp(args[cur_arg], "user") == 0) { |
| 3363 | char * packet; |
| 3364 | uint32_t packet_len; |
| 3365 | uint32_t pv; |
| 3366 | |
| 3367 | /* suboption header - needs additional argument for it */ |
| 3368 | if (*(args[cur_arg+1]) == 0) { |
| 3369 | Alert("parsing [%s:%d] : '%s %s %s' expects <username> as argument.\n", |
| 3370 | file, linenum, args[0], args[1], args[cur_arg]); |
| 3371 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3372 | goto out; |
| 3373 | } |
| 3374 | |
| 3375 | /* uint32_t + uint32_t + strlen("user")+1 + strlen(username)+1 + 1 */ |
| 3376 | packet_len = 4 + 4 + 5 + strlen(args[cur_arg + 1])+1 +1; |
| 3377 | pv = htonl(0x30000); /* protocol version 3.0 */ |
| 3378 | |
| 3379 | packet = (char*) calloc(1, packet_len); |
| 3380 | |
| 3381 | memcpy(packet + 4, &pv, 4); |
| 3382 | |
| 3383 | /* copy "user" */ |
| 3384 | memcpy(packet + 8, "user", 4); |
| 3385 | |
| 3386 | /* copy username */ |
| 3387 | memcpy(packet + 13, args[cur_arg+1], strlen(args[cur_arg+1])); |
| 3388 | |
| 3389 | free(curproxy->check_req); |
| 3390 | curproxy->check_req = packet; |
| 3391 | curproxy->check_len = packet_len; |
| 3392 | |
| 3393 | packet_len = htonl(packet_len); |
| 3394 | memcpy(packet, &packet_len, 4); |
| 3395 | cur_arg += 2; |
| 3396 | } else { |
| 3397 | /* unknown suboption - catchall */ |
| 3398 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'user'.\n", |
| 3399 | file, linenum, args[0], args[1]); |
| 3400 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3401 | goto out; |
| 3402 | } |
| 3403 | } /* end while loop */ |
| 3404 | } |
| 3405 | } |
| 3406 | |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 3407 | else if (!strcmp(args[1], "redis-check")) { |
| 3408 | /* use REDIS PING request to check servers' health */ |
| 3409 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 3410 | err_code |= ERR_WARN; |
| 3411 | |
| 3412 | free(curproxy->check_req); |
| 3413 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3414 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 3415 | curproxy->options2 |= PR_O2_REDIS_CHK; |
| 3416 | |
| 3417 | curproxy->check_req = (char *) malloc(sizeof(DEF_REDIS_CHECK_REQ) - 1); |
| 3418 | memcpy(curproxy->check_req, DEF_REDIS_CHECK_REQ, sizeof(DEF_REDIS_CHECK_REQ) - 1); |
| 3419 | curproxy->check_len = sizeof(DEF_REDIS_CHECK_REQ) - 1; |
| 3420 | } |
| 3421 | |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 3422 | else if (!strcmp(args[1], "mysql-check")) { |
| 3423 | /* use MYSQL request to check servers' health */ |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 3424 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 3425 | err_code |= ERR_WARN; |
| 3426 | |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 3427 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 3428 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3429 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 3430 | curproxy->options2 |= PR_O2_MYSQL_CHK; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 3431 | |
| 3432 | /* This is an exemple of an MySQL >=4.0 client Authentication packet kindly provided by Cyril Bonte. |
| 3433 | * const char mysql40_client_auth_pkt[] = { |
| 3434 | * "\x0e\x00\x00" // packet length |
| 3435 | * "\x01" // packet number |
| 3436 | * "\x00\x00" // client capabilities |
| 3437 | * "\x00\x00\x01" // max packet |
| 3438 | * "haproxy\x00" // username (null terminated string) |
| 3439 | * "\x00" // filler (always 0x00) |
| 3440 | * "\x01\x00\x00" // packet length |
| 3441 | * "\x00" // packet number |
| 3442 | * "\x01" // COM_QUIT command |
| 3443 | * }; |
| 3444 | */ |
| 3445 | |
| 3446 | if (*(args[2])) { |
| 3447 | int cur_arg = 2; |
| 3448 | |
| 3449 | while (*(args[cur_arg])) { |
| 3450 | if (strcmp(args[cur_arg], "user") == 0) { |
| 3451 | char *mysqluser; |
| 3452 | int packetlen, reqlen, userlen; |
| 3453 | |
| 3454 | /* suboption header - needs additional argument for it */ |
| 3455 | if (*(args[cur_arg+1]) == 0) { |
| 3456 | Alert("parsing [%s:%d] : '%s %s %s' expects <username> as argument.\n", |
| 3457 | file, linenum, args[0], args[1], args[cur_arg]); |
| 3458 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3459 | goto out; |
| 3460 | } |
| 3461 | mysqluser = args[cur_arg + 1]; |
| 3462 | userlen = strlen(mysqluser); |
| 3463 | packetlen = userlen + 7; |
| 3464 | reqlen = packetlen + 9; |
| 3465 | |
| 3466 | free(curproxy->check_req); |
| 3467 | curproxy->check_req = (char *)calloc(1, reqlen); |
| 3468 | curproxy->check_len = reqlen; |
| 3469 | |
| 3470 | snprintf(curproxy->check_req, 4, "%c%c%c", |
| 3471 | ((unsigned char) packetlen & 0xff), |
| 3472 | ((unsigned char) (packetlen >> 8) & 0xff), |
| 3473 | ((unsigned char) (packetlen >> 16) & 0xff)); |
| 3474 | |
| 3475 | curproxy->check_req[3] = 1; |
Hervé COMMOWICK | 212f778 | 2011-06-10 14:05:59 +0200 | [diff] [blame] | 3476 | curproxy->check_req[5] = 128; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 3477 | curproxy->check_req[8] = 1; |
| 3478 | memcpy(&curproxy->check_req[9], mysqluser, userlen); |
| 3479 | curproxy->check_req[9 + userlen + 1 + 1] = 1; |
| 3480 | curproxy->check_req[9 + userlen + 1 + 1 + 4] = 1; |
| 3481 | cur_arg += 2; |
| 3482 | } else { |
| 3483 | /* unknown suboption - catchall */ |
| 3484 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'user'.\n", |
| 3485 | file, linenum, args[0], args[1]); |
| 3486 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3487 | goto out; |
| 3488 | } |
| 3489 | } /* end while loop */ |
| 3490 | } |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 3491 | } |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 3492 | else if (!strcmp(args[1], "ldap-check")) { |
| 3493 | /* use LDAP request to check servers' health */ |
| 3494 | free(curproxy->check_req); |
| 3495 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3496 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 3497 | curproxy->options2 |= PR_O2_LDAP_CHK; |
| 3498 | |
| 3499 | curproxy->check_req = (char *) malloc(sizeof(DEF_LDAP_CHECK_REQ) - 1); |
| 3500 | memcpy(curproxy->check_req, DEF_LDAP_CHECK_REQ, sizeof(DEF_LDAP_CHECK_REQ) - 1); |
| 3501 | curproxy->check_len = sizeof(DEF_LDAP_CHECK_REQ) - 1; |
| 3502 | } |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3503 | else if (!strcmp(args[1], "forwardfor")) { |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3504 | int cur_arg; |
| 3505 | |
| 3506 | /* insert x-forwarded-for field, but not for the IP address listed as an except. |
| 3507 | * set default options (ie: bitfield, header name, etc) |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3508 | */ |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3509 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 3510 | curproxy->options |= PR_O_FWDFOR | PR_O_FF_ALWAYS; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3511 | |
| 3512 | free(curproxy->fwdfor_hdr_name); |
| 3513 | curproxy->fwdfor_hdr_name = strdup(DEF_XFORWARDFOR_HDR); |
| 3514 | curproxy->fwdfor_hdr_len = strlen(DEF_XFORWARDFOR_HDR); |
| 3515 | |
| 3516 | /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */ |
| 3517 | cur_arg = 2; |
| 3518 | while (*(args[cur_arg])) { |
| 3519 | if (!strcmp(args[cur_arg], "except")) { |
| 3520 | /* suboption except - needs additional argument for it */ |
| 3521 | if (!*(args[cur_arg+1]) || !str2net(args[cur_arg+1], &curproxy->except_net, &curproxy->except_mask)) { |
| 3522 | Alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n", |
| 3523 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3524 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3525 | goto out; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3526 | } |
| 3527 | /* flush useless bits */ |
| 3528 | curproxy->except_net.s_addr &= curproxy->except_mask.s_addr; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3529 | cur_arg += 2; |
| 3530 | } else if (!strcmp(args[cur_arg], "header")) { |
| 3531 | /* suboption header - needs additional argument for it */ |
| 3532 | if (*(args[cur_arg+1]) == 0) { |
| 3533 | Alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 3534 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3535 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3536 | goto out; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3537 | } |
| 3538 | free(curproxy->fwdfor_hdr_name); |
| 3539 | curproxy->fwdfor_hdr_name = strdup(args[cur_arg+1]); |
| 3540 | curproxy->fwdfor_hdr_len = strlen(curproxy->fwdfor_hdr_name); |
| 3541 | cur_arg += 2; |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 3542 | } else if (!strcmp(args[cur_arg], "if-none")) { |
| 3543 | curproxy->options &= ~PR_O_FF_ALWAYS; |
| 3544 | cur_arg += 1; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3545 | } else { |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3546 | /* unknown suboption - catchall */ |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 3547 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except', 'header' and 'if-none'.\n", |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3548 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3549 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3550 | goto out; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3551 | } |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3552 | } /* end while loop */ |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3553 | } |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 3554 | else if (!strcmp(args[1], "originalto")) { |
| 3555 | int cur_arg; |
| 3556 | |
| 3557 | /* insert x-original-to field, but not for the IP address listed as an except. |
| 3558 | * set default options (ie: bitfield, header name, etc) |
| 3559 | */ |
| 3560 | |
| 3561 | curproxy->options |= PR_O_ORGTO; |
| 3562 | |
| 3563 | free(curproxy->orgto_hdr_name); |
| 3564 | curproxy->orgto_hdr_name = strdup(DEF_XORIGINALTO_HDR); |
| 3565 | curproxy->orgto_hdr_len = strlen(DEF_XORIGINALTO_HDR); |
| 3566 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 3567 | /* loop to go through arguments - start at 2, since 0+1 = "option" "originalto" */ |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 3568 | cur_arg = 2; |
| 3569 | while (*(args[cur_arg])) { |
| 3570 | if (!strcmp(args[cur_arg], "except")) { |
| 3571 | /* suboption except - needs additional argument for it */ |
| 3572 | if (!*(args[cur_arg+1]) || !str2net(args[cur_arg+1], &curproxy->except_to, &curproxy->except_mask_to)) { |
| 3573 | Alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n", |
| 3574 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3575 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3576 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 3577 | } |
| 3578 | /* flush useless bits */ |
| 3579 | curproxy->except_to.s_addr &= curproxy->except_mask_to.s_addr; |
| 3580 | cur_arg += 2; |
| 3581 | } else if (!strcmp(args[cur_arg], "header")) { |
| 3582 | /* suboption header - needs additional argument for it */ |
| 3583 | if (*(args[cur_arg+1]) == 0) { |
| 3584 | Alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 3585 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3586 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3587 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 3588 | } |
| 3589 | free(curproxy->orgto_hdr_name); |
| 3590 | curproxy->orgto_hdr_name = strdup(args[cur_arg+1]); |
| 3591 | curproxy->orgto_hdr_len = strlen(curproxy->orgto_hdr_name); |
| 3592 | cur_arg += 2; |
| 3593 | } else { |
| 3594 | /* unknown suboption - catchall */ |
| 3595 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n", |
| 3596 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3597 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3598 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 3599 | } |
| 3600 | } /* end while loop */ |
| 3601 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3602 | else { |
| 3603 | Alert("parsing [%s:%d] : unknown option '%s'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3604 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3605 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3606 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3607 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3608 | } |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 3609 | else if (!strcmp(args[0], "default_backend")) { |
| 3610 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3611 | err_code |= ERR_WARN; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 3612 | |
| 3613 | if (*(args[1]) == 0) { |
| 3614 | Alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3615 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3616 | goto out; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 3617 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3618 | free(curproxy->defbe.name); |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 3619 | curproxy->defbe.name = strdup(args[1]); |
| 3620 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3621 | else if (!strcmp(args[0], "redispatch") || !strcmp(args[0], "redisp")) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3622 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3623 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3624 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3625 | Warning("parsing [%s:%d]: keyword '%s' is deprecated, please use 'option redispatch' instead.\n", |
| 3626 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3627 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3628 | /* enable reconnections to dispatch */ |
| 3629 | curproxy->options |= PR_O_REDISP; |
| 3630 | } |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 3631 | else if (!strcmp(args[0], "http-check")) { |
| 3632 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3633 | err_code |= ERR_WARN; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 3634 | |
| 3635 | if (strcmp(args[1], "disable-on-404") == 0) { |
| 3636 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 3637 | curproxy->options |= PR_O_DISABLE404; |
| 3638 | } |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 3639 | else if (strcmp(args[1], "send-state") == 0) { |
| 3640 | /* enable emission of the apparent state of a server in HTTP checks */ |
| 3641 | curproxy->options2 |= PR_O2_CHK_SNDST; |
| 3642 | } |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 3643 | else if (strcmp(args[1], "expect") == 0) { |
| 3644 | const char *ptr_arg; |
| 3645 | int cur_arg; |
| 3646 | |
| 3647 | if (curproxy->options2 & PR_O2_EXP_TYPE) { |
| 3648 | Alert("parsing [%s:%d] : '%s %s' already specified.\n", file, linenum, args[0], args[1]); |
| 3649 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3650 | goto out; |
| 3651 | } |
| 3652 | |
| 3653 | cur_arg = 2; |
| 3654 | /* consider exclamation marks, sole or at the beginning of a word */ |
| 3655 | while (*(ptr_arg = args[cur_arg])) { |
| 3656 | while (*ptr_arg == '!') { |
| 3657 | curproxy->options2 ^= PR_O2_EXP_INV; |
| 3658 | ptr_arg++; |
| 3659 | } |
| 3660 | if (*ptr_arg) |
| 3661 | break; |
| 3662 | cur_arg++; |
| 3663 | } |
| 3664 | /* now ptr_arg points to the beginning of a word past any possible |
| 3665 | * exclamation mark, and cur_arg is the argument which holds this word. |
| 3666 | */ |
| 3667 | if (strcmp(ptr_arg, "status") == 0) { |
| 3668 | if (!*(args[cur_arg + 1])) { |
| 3669 | Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 3670 | file, linenum, args[0], args[1], ptr_arg); |
| 3671 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3672 | goto out; |
| 3673 | } |
| 3674 | curproxy->options2 |= PR_O2_EXP_STS; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 3675 | free(curproxy->expect_str); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 3676 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
| 3677 | } |
| 3678 | else if (strcmp(ptr_arg, "string") == 0) { |
| 3679 | if (!*(args[cur_arg + 1])) { |
| 3680 | Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 3681 | file, linenum, args[0], args[1], ptr_arg); |
| 3682 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3683 | goto out; |
| 3684 | } |
| 3685 | curproxy->options2 |= PR_O2_EXP_STR; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 3686 | free(curproxy->expect_str); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 3687 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
| 3688 | } |
| 3689 | else if (strcmp(ptr_arg, "rstatus") == 0) { |
| 3690 | if (!*(args[cur_arg + 1])) { |
| 3691 | Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 3692 | file, linenum, args[0], args[1], ptr_arg); |
| 3693 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3694 | goto out; |
| 3695 | } |
| 3696 | curproxy->options2 |= PR_O2_EXP_RSTS; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 3697 | free(curproxy->expect_str); |
| 3698 | if (curproxy->expect_regex) regfree(curproxy->expect_regex); |
| 3699 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 3700 | curproxy->expect_regex = calloc(1, sizeof(regex_t)); |
| 3701 | if (regcomp(curproxy->expect_regex, args[cur_arg + 1], REG_EXTENDED) != 0) { |
| 3702 | Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s'.\n", |
| 3703 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1]); |
| 3704 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3705 | goto out; |
| 3706 | } |
| 3707 | } |
| 3708 | else if (strcmp(ptr_arg, "rstring") == 0) { |
| 3709 | if (!*(args[cur_arg + 1])) { |
| 3710 | Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 3711 | file, linenum, args[0], args[1], ptr_arg); |
| 3712 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3713 | goto out; |
| 3714 | } |
| 3715 | curproxy->options2 |= PR_O2_EXP_RSTR; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 3716 | free(curproxy->expect_str); |
| 3717 | if (curproxy->expect_regex) regfree(curproxy->expect_regex); |
| 3718 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 3719 | curproxy->expect_regex = calloc(1, sizeof(regex_t)); |
| 3720 | if (regcomp(curproxy->expect_regex, args[cur_arg + 1], REG_EXTENDED) != 0) { |
| 3721 | Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s'.\n", |
| 3722 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1]); |
| 3723 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3724 | goto out; |
| 3725 | } |
| 3726 | } |
| 3727 | else { |
| 3728 | Alert("parsing [%s:%d] : '%s %s' only supports [!] 'status', 'string', 'rstatus', 'rstring', found '%s'.\n", |
| 3729 | file, linenum, args[0], args[1], ptr_arg); |
| 3730 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3731 | goto out; |
| 3732 | } |
| 3733 | } |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 3734 | else { |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 3735 | Alert("parsing [%s:%d] : '%s' only supports 'disable-on-404', 'send-state', 'expect'.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3736 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3737 | goto out; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 3738 | } |
| 3739 | } |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3740 | else if (!strcmp(args[0], "monitor")) { |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3741 | if (curproxy == &defproxy) { |
| 3742 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3743 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3744 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3745 | } |
| 3746 | |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3747 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3748 | err_code |= ERR_WARN; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3749 | |
| 3750 | if (strcmp(args[1], "fail") == 0) { |
| 3751 | /* add a condition to fail monitor requests */ |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 3752 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3753 | Alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n", |
| 3754 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3755 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3756 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3757 | } |
| 3758 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 3759 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2)) == NULL) { |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3760 | Alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition.\n", |
| 3761 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3762 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3763 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3764 | } |
| 3765 | LIST_ADDQ(&curproxy->mon_fail_cond, &cond->list); |
| 3766 | } |
| 3767 | else { |
| 3768 | Alert("parsing [%s:%d] : '%s' only supports 'fail'.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3769 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3770 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3771 | } |
| 3772 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3773 | #ifdef TPROXY |
| 3774 | else if (!strcmp(args[0], "transparent")) { |
| 3775 | /* enable transparent proxy connections */ |
| 3776 | curproxy->options |= PR_O_TRANSP; |
| 3777 | } |
| 3778 | #endif |
| 3779 | else if (!strcmp(args[0], "maxconn")) { /* maxconn */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3780 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], " Maybe you want 'fullconn' instead ?")) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3781 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3782 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3783 | if (*(args[1]) == 0) { |
| 3784 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3785 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3786 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3787 | } |
| 3788 | curproxy->maxconn = atol(args[1]); |
| 3789 | } |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 3790 | else if (!strcmp(args[0], "backlog")) { /* backlog */ |
| 3791 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3792 | err_code |= ERR_WARN; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 3793 | |
| 3794 | if (*(args[1]) == 0) { |
| 3795 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3796 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3797 | goto out; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 3798 | } |
| 3799 | curproxy->backlog = atol(args[1]); |
| 3800 | } |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 3801 | else if (!strcmp(args[0], "fullconn")) { /* fullconn */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3802 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], " Maybe you want 'maxconn' instead ?")) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3803 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3804 | |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 3805 | if (*(args[1]) == 0) { |
| 3806 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3807 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3808 | goto out; |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 3809 | } |
| 3810 | curproxy->fullconn = atol(args[1]); |
| 3811 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3812 | else if (!strcmp(args[0], "grace")) { /* grace time (ms) */ |
| 3813 | if (*(args[1]) == 0) { |
| 3814 | Alert("parsing [%s:%d] : '%s' expects a time in milliseconds.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3815 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3816 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3817 | } |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 3818 | err = parse_time_err(args[1], &val, TIME_UNIT_MS); |
| 3819 | if (err) { |
| 3820 | Alert("parsing [%s:%d] : unexpected character '%c' in grace time.\n", |
| 3821 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3822 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3823 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 3824 | } |
| 3825 | curproxy->grace = val; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3826 | } |
| 3827 | else if (!strcmp(args[0], "dispatch")) { /* dispatch address */ |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 3828 | struct sockaddr_storage *sk; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3829 | if (curproxy == &defproxy) { |
| 3830 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3831 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3832 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3833 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3834 | else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3835 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3836 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3837 | if (strchr(args[1], ':') == NULL) { |
| 3838 | Alert("parsing [%s:%d] : '%s' expects <addr:port> as argument.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3839 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3840 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3841 | } |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 3842 | sk = str2sa(args[1]); |
| 3843 | if (!sk) { |
| 3844 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[1]); |
| 3845 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3846 | goto out; |
| 3847 | } |
| 3848 | curproxy->dispatch_addr = *sk; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3849 | curproxy->options |= PR_O_DISPATCH; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3850 | } |
| 3851 | else if (!strcmp(args[0], "balance")) { /* set balancing with optional algorithm */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3852 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3853 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3854 | |
Jeffrey 'jf' Lim | 65cb2f1 | 2008-10-04 18:07:00 +0200 | [diff] [blame] | 3855 | memcpy(trash, "error near 'balance'", 21); |
Willy Tarreau | a0cbda6 | 2007-11-01 21:39:54 +0100 | [diff] [blame] | 3856 | if (backend_parse_balance((const char **)args + 1, trash, sizeof(trash), curproxy) < 0) { |
| 3857 | Alert("parsing [%s:%d] : %s\n", file, linenum, trash); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3858 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3859 | goto out; |
Willy Tarreau | 2fcb500 | 2007-05-08 13:35:26 +0200 | [diff] [blame] | 3860 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3861 | } |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 3862 | else if (!strcmp(args[0], "hash-type")) { /* set hashing method */ |
| 3863 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 3864 | err_code |= ERR_WARN; |
| 3865 | |
| 3866 | if (strcmp(args[1], "consistent") == 0) { /* use consistent hashing */ |
| 3867 | curproxy->lbprm.algo &= ~BE_LB_HASH_TYPE; |
| 3868 | curproxy->lbprm.algo |= BE_LB_HASH_CONS; |
| 3869 | } |
| 3870 | else if (strcmp(args[1], "map-based") == 0) { /* use map-based hashing */ |
| 3871 | curproxy->lbprm.algo &= ~BE_LB_HASH_TYPE; |
| 3872 | curproxy->lbprm.algo |= BE_LB_HASH_MAP; |
| 3873 | } |
Willy Tarreau | 798a39c | 2010-11-24 15:04:29 +0100 | [diff] [blame] | 3874 | else if (strcmp(args[1], "avalanche") == 0) { /* use full hash before map-based hashing */ |
| 3875 | curproxy->lbprm.algo &= ~BE_LB_HASH_TYPE; |
| 3876 | curproxy->lbprm.algo |= BE_LB_HASH_AVAL; |
| 3877 | } |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 3878 | else { |
Willy Tarreau | 798a39c | 2010-11-24 15:04:29 +0100 | [diff] [blame] | 3879 | Alert("parsing [%s:%d] : '%s' only supports 'avalanche', 'consistent' and 'map-based'.\n", file, linenum, args[0]); |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 3880 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3881 | goto out; |
| 3882 | } |
| 3883 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3884 | else if (!strcmp(args[0], "server") || !strcmp(args[0], "default-server")) { /* server address */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3885 | int cur_arg; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3886 | char *rport, *raddr; |
| 3887 | short realport = 0; |
| 3888 | int do_check = 0, defsrv = (*args[0] == 'd'); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3889 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3890 | if (!defsrv && curproxy == &defproxy) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3891 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3892 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3893 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3894 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3895 | else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3896 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3897 | |
| 3898 | if (!*args[2]) { |
| 3899 | Alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n", |
| 3900 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3901 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3902 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3903 | } |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 3904 | |
| 3905 | err = invalid_char(args[1]); |
| 3906 | if (err) { |
| 3907 | Alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n", |
| 3908 | file, linenum, *err, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3909 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3910 | goto out; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 3911 | } |
| 3912 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3913 | if (!defsrv) { |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 3914 | struct sockaddr_storage *sk; |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 3915 | |
Krzysztof Piotr Oledzki | aff01ea | 2010-02-05 20:31:44 +0100 | [diff] [blame] | 3916 | if ((newsrv = (struct server *)calloc(1, sizeof(struct server))) == NULL) { |
| 3917 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 3918 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3919 | goto out; |
| 3920 | } |
| 3921 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3922 | /* the servers are linked backwards first */ |
| 3923 | newsrv->next = curproxy->srv; |
| 3924 | curproxy->srv = newsrv; |
| 3925 | newsrv->proxy = curproxy; |
| 3926 | newsrv->conf.file = file; |
| 3927 | newsrv->conf.line = linenum; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3928 | |
Simon Horman | af51495 | 2011-06-21 14:34:57 +0900 | [diff] [blame] | 3929 | LIST_INIT(&newsrv->actconns); |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3930 | LIST_INIT(&newsrv->pendconns); |
| 3931 | do_check = 0; |
| 3932 | newsrv->state = SRV_RUNNING; /* early server setup */ |
| 3933 | newsrv->last_change = now.tv_sec; |
| 3934 | newsrv->id = strdup(args[1]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3935 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3936 | /* several ways to check the port component : |
David du Colombier | 9842ff1 | 2011-03-17 10:40:28 +0100 | [diff] [blame] | 3937 | * - IP => port=+0, relative (IPv4 only) |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3938 | * - IP: => port=+0, relative |
| 3939 | * - IP:N => port=N, absolute |
| 3940 | * - IP:+N => port=+N, relative |
| 3941 | * - IP:-N => port=-N, relative |
| 3942 | */ |
| 3943 | raddr = strdup(args[2]); |
Willy Tarreau | fab5a43 | 2011-03-04 15:31:53 +0100 | [diff] [blame] | 3944 | rport = strrchr(raddr, ':'); |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3945 | if (rport) { |
| 3946 | *rport++ = 0; |
| 3947 | realport = atol(rport); |
| 3948 | if (!isdigit((unsigned char)*rport)) |
| 3949 | newsrv->state |= SRV_MAPPORTS; |
| 3950 | } else |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3951 | newsrv->state |= SRV_MAPPORTS; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3952 | |
Willy Tarreau | fab5a43 | 2011-03-04 15:31:53 +0100 | [diff] [blame] | 3953 | sk = str2ip(raddr); |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3954 | free(raddr); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 3955 | if (!sk) { |
| 3956 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[2]); |
| 3957 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3958 | goto out; |
| 3959 | } |
| 3960 | newsrv->addr = *sk; |
Willy Tarreau | 86ad42c | 2011-08-27 12:29:07 +0200 | [diff] [blame] | 3961 | set_host_port(&newsrv->addr, realport); |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3962 | |
| 3963 | newsrv->check_port = curproxy->defsrv.check_port; |
| 3964 | newsrv->inter = curproxy->defsrv.inter; |
| 3965 | newsrv->fastinter = curproxy->defsrv.fastinter; |
| 3966 | newsrv->downinter = curproxy->defsrv.downinter; |
| 3967 | newsrv->rise = curproxy->defsrv.rise; |
| 3968 | newsrv->fall = curproxy->defsrv.fall; |
| 3969 | newsrv->maxqueue = curproxy->defsrv.maxqueue; |
| 3970 | newsrv->minconn = curproxy->defsrv.minconn; |
| 3971 | newsrv->maxconn = curproxy->defsrv.maxconn; |
| 3972 | newsrv->slowstart = curproxy->defsrv.slowstart; |
| 3973 | newsrv->onerror = curproxy->defsrv.onerror; |
| 3974 | newsrv->consecutive_errors_limit |
| 3975 | = curproxy->defsrv.consecutive_errors_limit; |
| 3976 | newsrv->uweight = newsrv->iweight |
| 3977 | = curproxy->defsrv.iweight; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3978 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3979 | newsrv->curfd = -1; /* no health-check in progress */ |
| 3980 | newsrv->health = newsrv->rise; /* up, but will fall down at first failure */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3981 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3982 | cur_arg = 3; |
| 3983 | } else { |
| 3984 | newsrv = &curproxy->defsrv; |
| 3985 | cur_arg = 1; |
| 3986 | } |
Willy Tarreau | 0f03c6f | 2007-03-25 20:46:19 +0200 | [diff] [blame] | 3987 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3988 | while (*args[cur_arg]) { |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3989 | if (!defsrv && !strcmp(args[cur_arg], "id")) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 3990 | struct eb32_node *node; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3991 | |
| 3992 | if (!*args[cur_arg + 1]) { |
| 3993 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 3994 | file, linenum, args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3995 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3996 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3997 | } |
| 3998 | |
| 3999 | newsrv->puid = atol(args[cur_arg + 1]); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 4000 | newsrv->conf.id.key = newsrv->puid; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 4001 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 4002 | if (newsrv->puid <= 0) { |
| 4003 | Alert("parsing [%s:%d]: custom id has to be > 0.\n", |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 4004 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4005 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4006 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 4007 | } |
| 4008 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 4009 | node = eb32_lookup(&curproxy->conf.used_server_id, newsrv->puid); |
| 4010 | if (node) { |
| 4011 | struct server *target = container_of(node, struct server, conf.id); |
| 4012 | Alert("parsing [%s:%d]: server %s reuses same custom id as server %s (declared at %s:%d).\n", |
| 4013 | file, linenum, newsrv->id, target->id, target->conf.file, target->conf.line); |
| 4014 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4015 | goto out; |
| 4016 | } |
| 4017 | eb32_insert(&curproxy->conf.used_server_id, &newsrv->conf.id); |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 4018 | cur_arg += 2; |
| 4019 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4020 | else if (!defsrv && !strcmp(args[cur_arg], "cookie")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4021 | newsrv->cookie = strdup(args[cur_arg + 1]); |
| 4022 | newsrv->cklen = strlen(args[cur_arg + 1]); |
| 4023 | cur_arg += 2; |
| 4024 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4025 | else if (!defsrv && !strcmp(args[cur_arg], "redir")) { |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 4026 | newsrv->rdr_pfx = strdup(args[cur_arg + 1]); |
| 4027 | newsrv->rdr_len = strlen(args[cur_arg + 1]); |
| 4028 | cur_arg += 2; |
| 4029 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4030 | else if (!strcmp(args[cur_arg], "rise")) { |
Krzysztof Piotr Oledzki | 08ff959 | 2009-09-27 16:17:31 +0200 | [diff] [blame] | 4031 | if (!*args[cur_arg + 1]) { |
| 4032 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 4033 | file, linenum, args[cur_arg]); |
| 4034 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4035 | goto out; |
| 4036 | } |
| 4037 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4038 | newsrv->rise = atol(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 08ff959 | 2009-09-27 16:17:31 +0200 | [diff] [blame] | 4039 | if (newsrv->rise <= 0) { |
| 4040 | Alert("parsing [%s:%d]: '%s' has to be > 0.\n", |
| 4041 | file, linenum, args[cur_arg]); |
| 4042 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4043 | goto out; |
| 4044 | } |
| 4045 | |
Willy Tarreau | 9683909 | 2010-03-29 10:02:24 +0200 | [diff] [blame] | 4046 | if (newsrv->health) |
| 4047 | newsrv->health = newsrv->rise; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4048 | cur_arg += 2; |
| 4049 | } |
| 4050 | else if (!strcmp(args[cur_arg], "fall")) { |
| 4051 | newsrv->fall = atol(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 08ff959 | 2009-09-27 16:17:31 +0200 | [diff] [blame] | 4052 | |
| 4053 | if (!*args[cur_arg + 1]) { |
| 4054 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 4055 | file, linenum, args[cur_arg]); |
| 4056 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4057 | goto out; |
| 4058 | } |
| 4059 | |
| 4060 | if (newsrv->fall <= 0) { |
| 4061 | Alert("parsing [%s:%d]: '%s' has to be > 0.\n", |
| 4062 | file, linenum, args[cur_arg]); |
| 4063 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4064 | goto out; |
| 4065 | } |
| 4066 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4067 | cur_arg += 2; |
| 4068 | } |
| 4069 | else if (!strcmp(args[cur_arg], "inter")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4070 | const char *err = parse_time_err(args[cur_arg + 1], &val, TIME_UNIT_MS); |
| 4071 | if (err) { |
| 4072 | Alert("parsing [%s:%d] : unexpected character '%c' in 'inter' argument of server %s.\n", |
| 4073 | file, linenum, *err, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4074 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4075 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4076 | } |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4077 | if (val <= 0) { |
| 4078 | Alert("parsing [%s:%d]: invalid value %d for argument '%s' of server %s.\n", |
| 4079 | file, linenum, val, args[cur_arg], newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4080 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4081 | goto out; |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4082 | } |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4083 | newsrv->inter = val; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4084 | cur_arg += 2; |
| 4085 | } |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 4086 | else if (!strcmp(args[cur_arg], "fastinter")) { |
| 4087 | const char *err = parse_time_err(args[cur_arg + 1], &val, TIME_UNIT_MS); |
| 4088 | if (err) { |
| 4089 | Alert("parsing [%s:%d]: unexpected character '%c' in 'fastinter' argument of server %s.\n", |
| 4090 | file, linenum, *err, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4091 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4092 | goto out; |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 4093 | } |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4094 | if (val <= 0) { |
| 4095 | Alert("parsing [%s:%d]: invalid value %d for argument '%s' of server %s.\n", |
| 4096 | file, linenum, val, args[cur_arg], newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4097 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4098 | goto out; |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4099 | } |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 4100 | newsrv->fastinter = val; |
| 4101 | cur_arg += 2; |
| 4102 | } |
| 4103 | else if (!strcmp(args[cur_arg], "downinter")) { |
| 4104 | const char *err = parse_time_err(args[cur_arg + 1], &val, TIME_UNIT_MS); |
| 4105 | if (err) { |
| 4106 | Alert("parsing [%s:%d]: unexpected character '%c' in 'downinter' argument of server %s.\n", |
| 4107 | file, linenum, *err, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4108 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4109 | goto out; |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 4110 | } |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4111 | if (val <= 0) { |
| 4112 | Alert("parsing [%s:%d]: invalid value %d for argument '%s' of server %s.\n", |
| 4113 | file, linenum, val, args[cur_arg], newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4114 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4115 | goto out; |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4116 | } |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 4117 | newsrv->downinter = val; |
| 4118 | cur_arg += 2; |
| 4119 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4120 | else if (!defsrv && !strcmp(args[cur_arg], "addr")) { |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4121 | struct sockaddr_storage *sk = str2sa(args[cur_arg + 1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4122 | if (!sk) { |
| 4123 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[cur_arg + 1]); |
| 4124 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4125 | goto out; |
| 4126 | } |
| 4127 | newsrv->check_addr = *sk; |
Willy Tarreau | 2ea3abb | 2007-03-25 16:45:16 +0200 | [diff] [blame] | 4128 | cur_arg += 2; |
| 4129 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4130 | else if (!strcmp(args[cur_arg], "port")) { |
| 4131 | newsrv->check_port = atol(args[cur_arg + 1]); |
| 4132 | cur_arg += 2; |
| 4133 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4134 | else if (!defsrv && !strcmp(args[cur_arg], "backup")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4135 | newsrv->state |= SRV_BACKUP; |
| 4136 | cur_arg ++; |
| 4137 | } |
Simon Horman | fa46168 | 2011-06-25 09:39:49 +0900 | [diff] [blame] | 4138 | else if (!defsrv && !strcmp(args[cur_arg], "non-stick")) { |
| 4139 | newsrv->state |= SRV_NON_STICK; |
| 4140 | cur_arg ++; |
| 4141 | } |
Willy Tarreau | 5ab04ec | 2011-03-20 10:32:26 +0100 | [diff] [blame] | 4142 | else if (!defsrv && !strcmp(args[cur_arg], "send-proxy")) { |
| 4143 | newsrv->state |= SRV_SEND_PROXY; |
| 4144 | cur_arg ++; |
| 4145 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4146 | else if (!strcmp(args[cur_arg], "weight")) { |
| 4147 | int w; |
| 4148 | w = atol(args[cur_arg + 1]); |
Willy Tarreau | 6704d67 | 2009-06-15 10:56:05 +0200 | [diff] [blame] | 4149 | if (w < 0 || w > 256) { |
| 4150 | Alert("parsing [%s:%d] : weight of server %s is not within 0 and 256 (%d).\n", |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4151 | file, linenum, newsrv->id, w); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4152 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4153 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4154 | } |
Willy Tarreau | 975c50b | 2009-10-10 19:34:06 +0200 | [diff] [blame] | 4155 | newsrv->uweight = newsrv->iweight = w; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4156 | cur_arg += 2; |
| 4157 | } |
| 4158 | else if (!strcmp(args[cur_arg], "minconn")) { |
| 4159 | newsrv->minconn = atol(args[cur_arg + 1]); |
| 4160 | cur_arg += 2; |
| 4161 | } |
| 4162 | else if (!strcmp(args[cur_arg], "maxconn")) { |
| 4163 | newsrv->maxconn = atol(args[cur_arg + 1]); |
| 4164 | cur_arg += 2; |
| 4165 | } |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 4166 | else if (!strcmp(args[cur_arg], "maxqueue")) { |
| 4167 | newsrv->maxqueue = atol(args[cur_arg + 1]); |
| 4168 | cur_arg += 2; |
| 4169 | } |
Willy Tarreau | 9909fc1 | 2007-11-30 17:42:05 +0100 | [diff] [blame] | 4170 | else if (!strcmp(args[cur_arg], "slowstart")) { |
| 4171 | /* slowstart is stored in seconds */ |
Willy Tarreau | 3259e33 | 2007-12-03 01:51:45 +0100 | [diff] [blame] | 4172 | const char *err = parse_time_err(args[cur_arg + 1], &val, TIME_UNIT_MS); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4173 | if (err) { |
| 4174 | Alert("parsing [%s:%d] : unexpected character '%c' in 'slowstart' argument of server %s.\n", |
| 4175 | file, linenum, *err, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4176 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4177 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4178 | } |
Willy Tarreau | 4554bc1 | 2010-03-26 10:40:49 +0100 | [diff] [blame] | 4179 | if (val < 0) { |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4180 | Alert("parsing [%s:%d]: invalid value %d for argument '%s' of server %s.\n", |
| 4181 | file, linenum, val, args[cur_arg], newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4182 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4183 | goto out; |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4184 | } |
Willy Tarreau | 3259e33 | 2007-12-03 01:51:45 +0100 | [diff] [blame] | 4185 | newsrv->slowstart = (val + 999) / 1000; |
Willy Tarreau | 9909fc1 | 2007-11-30 17:42:05 +0100 | [diff] [blame] | 4186 | cur_arg += 2; |
| 4187 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4188 | else if (!defsrv && !strcmp(args[cur_arg], "track")) { |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4189 | |
| 4190 | if (!*args[cur_arg + 1]) { |
| 4191 | Alert("parsing [%s:%d]: 'track' expects [<proxy>/]<server> as argument.\n", |
| 4192 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4193 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4194 | goto out; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4195 | } |
| 4196 | |
| 4197 | newsrv->trackit = strdup(args[cur_arg + 1]); |
| 4198 | |
| 4199 | cur_arg += 2; |
| 4200 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4201 | else if (!defsrv && !strcmp(args[cur_arg], "check")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4202 | global.maxsock++; |
| 4203 | do_check = 1; |
| 4204 | cur_arg += 1; |
| 4205 | } |
Willy Tarreau | 9683909 | 2010-03-29 10:02:24 +0200 | [diff] [blame] | 4206 | else if (!defsrv && !strcmp(args[cur_arg], "disabled")) { |
| 4207 | newsrv->state |= SRV_MAINTAIN; |
| 4208 | newsrv->state &= ~SRV_RUNNING; |
| 4209 | newsrv->health = 0; |
| 4210 | cur_arg += 1; |
| 4211 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4212 | else if (!defsrv && !strcmp(args[cur_arg], "observe")) { |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 4213 | if (!strcmp(args[cur_arg + 1], "none")) |
| 4214 | newsrv->observe = HANA_OBS_NONE; |
| 4215 | else if (!strcmp(args[cur_arg + 1], "layer4")) |
| 4216 | newsrv->observe = HANA_OBS_LAYER4; |
| 4217 | else if (!strcmp(args[cur_arg + 1], "layer7")) { |
| 4218 | if (curproxy->mode != PR_MODE_HTTP) { |
| 4219 | Alert("parsing [%s:%d]: '%s' can only be used in http proxies.\n", |
| 4220 | file, linenum, args[cur_arg + 1]); |
| 4221 | err_code |= ERR_ALERT; |
| 4222 | } |
| 4223 | newsrv->observe = HANA_OBS_LAYER7; |
| 4224 | } |
| 4225 | else { |
| 4226 | Alert("parsing [%s:%d]: '%s' expects one of 'none', " |
Willy Tarreau | 53621e0 | 2010-10-22 14:53:40 +0200 | [diff] [blame] | 4227 | "'layer4', 'layer7' but got '%s'\n", |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 4228 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
| 4229 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4230 | goto out; |
| 4231 | } |
| 4232 | |
| 4233 | cur_arg += 2; |
| 4234 | } |
| 4235 | else if (!strcmp(args[cur_arg], "on-error")) { |
| 4236 | if (!strcmp(args[cur_arg + 1], "fastinter")) |
| 4237 | newsrv->onerror = HANA_ONERR_FASTINTER; |
| 4238 | else if (!strcmp(args[cur_arg + 1], "fail-check")) |
| 4239 | newsrv->onerror = HANA_ONERR_FAILCHK; |
| 4240 | else if (!strcmp(args[cur_arg + 1], "sudden-death")) |
| 4241 | newsrv->onerror = HANA_ONERR_SUDDTH; |
| 4242 | else if (!strcmp(args[cur_arg + 1], "mark-down")) |
| 4243 | newsrv->onerror = HANA_ONERR_MARKDWN; |
| 4244 | else { |
| 4245 | Alert("parsing [%s:%d]: '%s' expects one of 'fastinter', " |
Willy Tarreau | 53621e0 | 2010-10-22 14:53:40 +0200 | [diff] [blame] | 4246 | "'fail-check', 'sudden-death' or 'mark-down' but got '%s'\n", |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 4247 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
| 4248 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4249 | goto out; |
| 4250 | } |
| 4251 | |
| 4252 | cur_arg += 2; |
| 4253 | } |
Simon Horman | e0d1bfb | 2011-06-21 14:34:58 +0900 | [diff] [blame] | 4254 | else if (!strcmp(args[cur_arg], "on-marked-down")) { |
| 4255 | if (!strcmp(args[cur_arg + 1], "shutdown-sessions")) |
| 4256 | newsrv->onmarkeddown = HANA_ONMARKEDDOWN_SHUTDOWNSESSIONS; |
| 4257 | else { |
| 4258 | Alert("parsing [%s:%d]: '%s' expects 'shutdown-sessions' but got '%s'\n", |
| 4259 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
| 4260 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4261 | goto out; |
| 4262 | } |
| 4263 | |
| 4264 | cur_arg += 2; |
| 4265 | } |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 4266 | else if (!strcmp(args[cur_arg], "error-limit")) { |
| 4267 | if (!*args[cur_arg + 1]) { |
| 4268 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 4269 | file, linenum, args[cur_arg]); |
| 4270 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4271 | goto out; |
| 4272 | } |
| 4273 | |
| 4274 | newsrv->consecutive_errors_limit = atoi(args[cur_arg + 1]); |
| 4275 | |
| 4276 | if (newsrv->consecutive_errors_limit <= 0) { |
| 4277 | Alert("parsing [%s:%d]: %s has to be > 0.\n", |
| 4278 | file, linenum, args[cur_arg]); |
| 4279 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4280 | goto out; |
| 4281 | } |
Willy Tarreau | f53b25d | 2010-03-15 19:40:37 +0100 | [diff] [blame] | 4282 | cur_arg += 2; |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 4283 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4284 | else if (!defsrv && !strcmp(args[cur_arg], "source")) { /* address to which we bind when connecting */ |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 4285 | int port_low, port_high; |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4286 | struct sockaddr_storage *sk; |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4287 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4288 | if (!*args[cur_arg + 1]) { |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4289 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 4290 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>[-<port>]], and optional '%s' <addr> as argument.\n", |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 4291 | file, linenum, "source", "usesrc"); |
| 4292 | #else |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 4293 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>[-<port>]] as argument.\n", |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4294 | file, linenum, "source"); |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 4295 | #endif |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4296 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4297 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4298 | } |
| 4299 | newsrv->state |= SRV_BIND_SRC; |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4300 | sk = str2sa_range(args[cur_arg + 1], &port_low, &port_high); |
| 4301 | if (!sk) { |
| 4302 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[cur_arg + 1]); |
| 4303 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4304 | goto out; |
| 4305 | } |
| 4306 | newsrv->source_addr = *sk; |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 4307 | |
| 4308 | if (port_low != port_high) { |
| 4309 | int i; |
| 4310 | if (port_low <= 0 || port_low > 65535 || |
| 4311 | port_high <= 0 || port_high > 65535 || |
| 4312 | port_low > port_high) { |
| 4313 | Alert("parsing [%s:%d] : invalid source port range %d-%d.\n", |
| 4314 | file, linenum, port_low, port_high); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4315 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4316 | goto out; |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 4317 | } |
| 4318 | newsrv->sport_range = port_range_alloc_range(port_high - port_low + 1); |
| 4319 | for (i = 0; i < newsrv->sport_range->size; i++) |
| 4320 | newsrv->sport_range->ports[i] = port_low + i; |
| 4321 | } |
| 4322 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4323 | cur_arg += 2; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4324 | while (*(args[cur_arg])) { |
| 4325 | if (!strcmp(args[cur_arg], "usesrc")) { /* address to use outside */ |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4326 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) |
| 4327 | #if !defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4328 | if (newsrv->source_addr.sin_addr.s_addr == INADDR_ANY) { |
| 4329 | Alert("parsing [%s:%d] : '%s' requires an explicit '%s' address.\n", |
| 4330 | file, linenum, "usesrc", "source"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4331 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4332 | goto out; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4333 | } |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4334 | #endif |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4335 | if (!*args[cur_arg + 1]) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4336 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', 'clientip', or 'hdr_ip(name,#)' as argument.\n", |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4337 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4338 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4339 | goto out; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4340 | } |
| 4341 | if (!strcmp(args[cur_arg + 1], "client")) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4342 | newsrv->state &= ~SRV_TPROXY_MASK; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4343 | newsrv->state |= SRV_TPROXY_CLI; |
| 4344 | } else if (!strcmp(args[cur_arg + 1], "clientip")) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4345 | newsrv->state &= ~SRV_TPROXY_MASK; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4346 | newsrv->state |= SRV_TPROXY_CIP; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4347 | } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) { |
| 4348 | char *name, *end; |
| 4349 | |
| 4350 | name = args[cur_arg+1] + 7; |
| 4351 | while (isspace(*name)) |
| 4352 | name++; |
| 4353 | |
| 4354 | end = name; |
| 4355 | while (*end && !isspace(*end) && *end != ',' && *end != ')') |
| 4356 | end++; |
| 4357 | |
| 4358 | newsrv->state &= ~SRV_TPROXY_MASK; |
| 4359 | newsrv->state |= SRV_TPROXY_DYN; |
| 4360 | newsrv->bind_hdr_name = calloc(1, end - name + 1); |
| 4361 | newsrv->bind_hdr_len = end - name; |
| 4362 | memcpy(newsrv->bind_hdr_name, name, end - name); |
| 4363 | newsrv->bind_hdr_name[end-name] = '\0'; |
| 4364 | newsrv->bind_hdr_occ = -1; |
| 4365 | |
| 4366 | /* now look for an occurrence number */ |
| 4367 | while (isspace(*end)) |
| 4368 | end++; |
| 4369 | if (*end == ',') { |
| 4370 | end++; |
| 4371 | name = end; |
| 4372 | if (*end == '-') |
| 4373 | end++; |
| 4374 | while (isdigit(*end)) |
| 4375 | end++; |
| 4376 | newsrv->bind_hdr_occ = strl2ic(name, end-name); |
| 4377 | } |
| 4378 | |
| 4379 | if (newsrv->bind_hdr_occ < -MAX_HDR_HISTORY) { |
| 4380 | Alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative" |
| 4381 | " occurrences values smaller than %d.\n", |
| 4382 | file, linenum, MAX_HDR_HISTORY); |
| 4383 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4384 | goto out; |
| 4385 | } |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4386 | } else { |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4387 | struct sockaddr_storage *sk = str2sa(args[cur_arg + 1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4388 | if (!sk) { |
| 4389 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[cur_arg + 1]); |
| 4390 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4391 | goto out; |
| 4392 | } |
| 4393 | newsrv->tproxy_addr = *sk; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4394 | newsrv->state |= SRV_TPROXY_ADDR; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4395 | } |
| 4396 | global.last_checks |= LSTCHK_NETADM; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4397 | #if !defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4398 | global.last_checks |= LSTCHK_CTTPROXY; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4399 | #endif |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4400 | cur_arg += 2; |
| 4401 | continue; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4402 | #else /* no TPROXY support */ |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4403 | Alert("parsing [%s:%d] : '%s' not allowed here because support for TPROXY was not compiled in.\n", |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 4404 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4405 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4406 | goto out; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4407 | #endif /* defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) */ |
| 4408 | } /* "usesrc" */ |
| 4409 | |
| 4410 | if (!strcmp(args[cur_arg], "interface")) { /* specifically bind to this interface */ |
| 4411 | #ifdef SO_BINDTODEVICE |
| 4412 | if (!*args[cur_arg + 1]) { |
| 4413 | Alert("parsing [%s:%d] : '%s' : missing interface name.\n", |
| 4414 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4415 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4416 | goto out; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4417 | } |
| 4418 | if (newsrv->iface_name) |
| 4419 | free(newsrv->iface_name); |
| 4420 | |
| 4421 | newsrv->iface_name = strdup(args[cur_arg + 1]); |
| 4422 | newsrv->iface_len = strlen(newsrv->iface_name); |
| 4423 | global.last_checks |= LSTCHK_NETADM; |
| 4424 | #else |
| 4425 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 4426 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4427 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4428 | goto out; |
Willy Tarreau | 77074d5 | 2006-11-12 23:57:19 +0100 | [diff] [blame] | 4429 | #endif |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4430 | cur_arg += 2; |
| 4431 | continue; |
| 4432 | } |
| 4433 | /* this keyword in not an option of "source" */ |
| 4434 | break; |
| 4435 | } /* while */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4436 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4437 | else if (!defsrv && !strcmp(args[cur_arg], "usesrc")) { /* address to use outside: needs "source" first */ |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 4438 | Alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n", |
| 4439 | file, linenum, "usesrc", "source"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4440 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4441 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 4442 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4443 | else { |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4444 | if (!defsrv) |
Simon Horman | e0d1bfb | 2011-06-21 14:34:58 +0900 | [diff] [blame] | 4445 | Alert("parsing [%s:%d] : server %s only supports options 'backup', 'cookie', 'redir', 'observer', 'on-error', 'on-marked-down', 'error-limit', 'check', 'disabled', 'track', 'id', 'inter', 'fastinter', 'downinter', 'rise', 'fall', 'addr', 'port', 'source', 'send-proxy', 'minconn', 'maxconn', 'maxqueue', 'slowstart' and 'weight'.\n", |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4446 | file, linenum, newsrv->id); |
| 4447 | else |
Krzysztof Piotr Oledzki | a9389b1 | 2010-01-05 16:44:17 +0100 | [diff] [blame] | 4448 | Alert("parsing [%s:%d]: default-server only supports options 'on-error', 'error-limit', 'inter', 'fastinter', 'downinter', 'rise', 'fall', 'port', 'minconn', 'maxconn', 'maxqueue', 'slowstart' and 'weight'.\n", |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4449 | file, linenum); |
| 4450 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4451 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4452 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4453 | } |
| 4454 | } |
| 4455 | |
| 4456 | if (do_check) { |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4457 | if (newsrv->trackit) { |
| 4458 | Alert("parsing [%s:%d]: unable to enable checks and tracking at the same time!\n", |
| 4459 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4460 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4461 | goto out; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4462 | } |
| 4463 | |
Willy Tarreau | 86ad42c | 2011-08-27 12:29:07 +0200 | [diff] [blame] | 4464 | /* try to get the port from check_addr if check_port not set */ |
| 4465 | if (!newsrv->check_port) |
| 4466 | newsrv->check_port = get_host_port(&newsrv->check_addr); |
Willy Tarreau | 0f03c6f | 2007-03-25 20:46:19 +0200 | [diff] [blame] | 4467 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4468 | if (!newsrv->check_port && !(newsrv->state & SRV_MAPPORTS)) |
| 4469 | newsrv->check_port = realport; /* by default */ |
| 4470 | if (!newsrv->check_port) { |
Willy Tarreau | ef00b50 | 2007-01-07 02:40:09 +0100 | [diff] [blame] | 4471 | /* not yet valid, because no port was set on |
| 4472 | * the server either. We'll check if we have |
| 4473 | * a known port on the first listener. |
| 4474 | */ |
Willy Tarreau | 86ad42c | 2011-08-27 12:29:07 +0200 | [diff] [blame] | 4475 | struct listener *l = curproxy->listen; |
| 4476 | while (l && !(newsrv->check_port = get_host_port(&l->addr))) |
| 4477 | l = l->next; |
Willy Tarreau | ef00b50 | 2007-01-07 02:40:09 +0100 | [diff] [blame] | 4478 | } |
| 4479 | if (!newsrv->check_port) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4480 | Alert("parsing [%s:%d] : server %s has neither service port nor check port. Check has been disabled.\n", |
| 4481 | file, linenum, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4482 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4483 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4484 | } |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 4485 | |
Cyril Bonté | c9f825f | 2010-03-17 18:56:31 +0100 | [diff] [blame] | 4486 | /* Allocate buffer for partial check results... */ |
Willy Tarreau | 43961d5 | 2010-10-04 20:39:20 +0200 | [diff] [blame] | 4487 | if ((newsrv->check_data = calloc(global.tune.chksize, sizeof(char))) == NULL) { |
Cyril Bonté | c9f825f | 2010-03-17 18:56:31 +0100 | [diff] [blame] | 4488 | Alert("parsing [%s:%d] : out of memory while allocating check buffer.\n", file, linenum); |
| 4489 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4490 | goto out; |
| 4491 | } |
| 4492 | |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 4493 | newsrv->check_status = HCHK_STATUS_INI; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4494 | newsrv->state |= SRV_CHECKED; |
| 4495 | } |
| 4496 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4497 | if (!defsrv) { |
| 4498 | if (newsrv->state & SRV_BACKUP) |
| 4499 | curproxy->srv_bck++; |
| 4500 | else |
| 4501 | curproxy->srv_act++; |
Willy Tarreau | b625a08 | 2007-11-26 01:15:43 +0100 | [diff] [blame] | 4502 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4503 | newsrv->prev_state = newsrv->state; |
| 4504 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4505 | } |
| 4506 | else if (!strcmp(args[0], "log")) { /* syslog server address */ |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 4507 | struct logsrv logsrv; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4508 | int facility; |
| 4509 | |
| 4510 | if (*(args[1]) && *(args[2]) == 0 && !strcmp(args[1], "global")) { |
| 4511 | curproxy->logfac1 = global.logfac1; |
| 4512 | curproxy->logsrv1 = global.logsrv1; |
| 4513 | curproxy->loglev1 = global.loglev1; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 4514 | curproxy->minlvl1 = global.minlvl1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4515 | curproxy->logfac2 = global.logfac2; |
| 4516 | curproxy->logsrv2 = global.logsrv2; |
| 4517 | curproxy->loglev2 = global.loglev2; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 4518 | curproxy->minlvl2 = global.minlvl2; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4519 | } |
| 4520 | else if (*(args[1]) && *(args[2])) { |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 4521 | int level, minlvl; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4522 | |
| 4523 | facility = get_log_facility(args[2]); |
| 4524 | if (facility < 0) { |
| 4525 | Alert("parsing [%s:%d] : unknown log facility '%s'\n", file, linenum, args[2]); |
| 4526 | exit(1); |
| 4527 | } |
| 4528 | |
| 4529 | level = 7; /* max syslog level = debug */ |
| 4530 | if (*(args[3])) { |
| 4531 | level = get_log_level(args[3]); |
| 4532 | if (level < 0) { |
| 4533 | Alert("parsing [%s:%d] : unknown optional log level '%s'\n", file, linenum, args[3]); |
| 4534 | exit(1); |
| 4535 | } |
| 4536 | } |
| 4537 | |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 4538 | minlvl = 0; /* limit syslog level to this level (emerg) */ |
| 4539 | if (*(args[4])) { |
| 4540 | minlvl = get_log_level(args[4]); |
| 4541 | if (level < 0) { |
| 4542 | Alert("parsing [%s:%d] : unknown optional minimum log level '%s'\n", file, linenum, args[4]); |
| 4543 | exit(1); |
| 4544 | } |
| 4545 | } |
| 4546 | |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 4547 | if (args[1][0] == '/') { |
David du Colombier | 11bcb6c | 2011-03-24 12:23:00 +0100 | [diff] [blame] | 4548 | struct sockaddr_storage *sk = (struct sockaddr_storage *)str2sun(args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4549 | if (!sk) { |
| 4550 | Alert("parsing [%s:%d] : Socket path '%s' too long (max %d)\n", file, linenum, |
David du Colombier | 11bcb6c | 2011-03-24 12:23:00 +0100 | [diff] [blame] | 4551 | args[1], (int)sizeof(((struct sockaddr_un *)sk)->sun_path) - 1); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4552 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4553 | goto out; |
| 4554 | } |
David du Colombier | 11bcb6c | 2011-03-24 12:23:00 +0100 | [diff] [blame] | 4555 | logsrv.addr = *sk; |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 4556 | } else { |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4557 | struct sockaddr_storage *sk = str2sa(args[1]); |
David du Colombier | 11bcb6c | 2011-03-24 12:23:00 +0100 | [diff] [blame] | 4558 | if (!sk) { |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4559 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[1]); |
| 4560 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4561 | goto out; |
| 4562 | } |
David du Colombier | 11bcb6c | 2011-03-24 12:23:00 +0100 | [diff] [blame] | 4563 | logsrv.addr = *sk; |
| 4564 | if (!get_host_port(&logsrv.addr)) |
| 4565 | set_host_port(&logsrv.addr, SYSLOG_PORT); |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 4566 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4567 | |
| 4568 | if (curproxy->logfac1 == -1) { |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 4569 | curproxy->logsrv1 = logsrv; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4570 | curproxy->logfac1 = facility; |
| 4571 | curproxy->loglev1 = level; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 4572 | curproxy->minlvl1 = minlvl; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4573 | } |
| 4574 | else if (curproxy->logfac2 == -1) { |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 4575 | curproxy->logsrv2 = logsrv; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4576 | curproxy->logfac2 = facility; |
| 4577 | curproxy->loglev2 = level; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 4578 | curproxy->minlvl2 = minlvl; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4579 | } |
| 4580 | else { |
| 4581 | Alert("parsing [%s:%d] : too many syslog servers\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4582 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4583 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4584 | } |
| 4585 | } |
| 4586 | else { |
| 4587 | Alert("parsing [%s:%d] : 'log' expects either <address[:port]> and <facility> or 'global' as arguments.\n", |
| 4588 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4589 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4590 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4591 | } |
| 4592 | } |
| 4593 | else if (!strcmp(args[0], "source")) { /* address to which we bind when connecting */ |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4594 | int cur_arg; |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4595 | struct sockaddr_storage *sk; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4596 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4597 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4598 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4599 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4600 | if (!*args[1]) { |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4601 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optionally '%s' <addr>, and '%s' <name>.\n", |
| 4602 | file, linenum, "source", "usesrc", "interface"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4603 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4604 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4605 | } |
Willy Tarreau | 368480c | 2009-03-01 08:27:21 +0100 | [diff] [blame] | 4606 | |
| 4607 | /* we must first clear any optional default setting */ |
| 4608 | curproxy->options &= ~PR_O_TPXY_MASK; |
| 4609 | free(curproxy->iface_name); |
| 4610 | curproxy->iface_name = NULL; |
| 4611 | curproxy->iface_len = 0; |
| 4612 | |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4613 | sk = str2sa(args[1]); |
| 4614 | if (!sk) { |
| 4615 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[1]); |
| 4616 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4617 | goto out; |
| 4618 | } |
| 4619 | curproxy->source_addr = *sk; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4620 | curproxy->options |= PR_O_BIND_SRC; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4621 | |
| 4622 | cur_arg = 2; |
| 4623 | while (*(args[cur_arg])) { |
| 4624 | if (!strcmp(args[cur_arg], "usesrc")) { /* address to use outside */ |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4625 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) |
| 4626 | #if !defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4627 | if (curproxy->source_addr.sin_addr.s_addr == INADDR_ANY) { |
| 4628 | Alert("parsing [%s:%d] : '%s' requires an explicit 'source' address.\n", |
| 4629 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4630 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4631 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4632 | } |
| 4633 | #endif |
| 4634 | if (!*args[cur_arg + 1]) { |
| 4635 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n", |
| 4636 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4637 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4638 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4639 | } |
| 4640 | |
| 4641 | if (!strcmp(args[cur_arg + 1], "client")) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4642 | curproxy->options &= ~PR_O_TPXY_MASK; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4643 | curproxy->options |= PR_O_TPXY_CLI; |
| 4644 | } else if (!strcmp(args[cur_arg + 1], "clientip")) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4645 | curproxy->options &= ~PR_O_TPXY_MASK; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4646 | curproxy->options |= PR_O_TPXY_CIP; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4647 | } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) { |
| 4648 | char *name, *end; |
| 4649 | |
| 4650 | name = args[cur_arg+1] + 7; |
| 4651 | while (isspace(*name)) |
| 4652 | name++; |
| 4653 | |
| 4654 | end = name; |
| 4655 | while (*end && !isspace(*end) && *end != ',' && *end != ')') |
| 4656 | end++; |
| 4657 | |
| 4658 | curproxy->options &= ~PR_O_TPXY_MASK; |
| 4659 | curproxy->options |= PR_O_TPXY_DYN; |
| 4660 | curproxy->bind_hdr_name = calloc(1, end - name + 1); |
| 4661 | curproxy->bind_hdr_len = end - name; |
| 4662 | memcpy(curproxy->bind_hdr_name, name, end - name); |
| 4663 | curproxy->bind_hdr_name[end-name] = '\0'; |
| 4664 | curproxy->bind_hdr_occ = -1; |
| 4665 | |
| 4666 | /* now look for an occurrence number */ |
| 4667 | while (isspace(*end)) |
| 4668 | end++; |
| 4669 | if (*end == ',') { |
| 4670 | end++; |
| 4671 | name = end; |
| 4672 | if (*end == '-') |
| 4673 | end++; |
| 4674 | while (isdigit(*end)) |
| 4675 | end++; |
| 4676 | curproxy->bind_hdr_occ = strl2ic(name, end-name); |
| 4677 | } |
| 4678 | |
| 4679 | if (curproxy->bind_hdr_occ < -MAX_HDR_HISTORY) { |
| 4680 | Alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative" |
| 4681 | " occurrences values smaller than %d.\n", |
| 4682 | file, linenum, MAX_HDR_HISTORY); |
| 4683 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4684 | goto out; |
| 4685 | } |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4686 | } else { |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4687 | struct sockaddr_storage *sk = str2sa(args[cur_arg + 1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4688 | if (!sk) { |
| 4689 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[cur_arg + 1]); |
| 4690 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4691 | goto out; |
| 4692 | } |
| 4693 | curproxy->tproxy_addr = *sk; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4694 | curproxy->options |= PR_O_TPXY_ADDR; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4695 | } |
| 4696 | global.last_checks |= LSTCHK_NETADM; |
| 4697 | #if !defined(CONFIG_HAP_LINUX_TPROXY) |
| 4698 | global.last_checks |= LSTCHK_CTTPROXY; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4699 | #endif |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4700 | #else /* no TPROXY support */ |
| 4701 | Alert("parsing [%s:%d] : '%s' not allowed here because support for TPROXY was not compiled in.\n", |
Willy Tarreau | 77074d5 | 2006-11-12 23:57:19 +0100 | [diff] [blame] | 4702 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4703 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4704 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4705 | #endif |
| 4706 | cur_arg += 2; |
| 4707 | continue; |
Willy Tarreau | 77074d5 | 2006-11-12 23:57:19 +0100 | [diff] [blame] | 4708 | } |
| 4709 | |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4710 | if (!strcmp(args[cur_arg], "interface")) { /* specifically bind to this interface */ |
| 4711 | #ifdef SO_BINDTODEVICE |
| 4712 | if (!*args[cur_arg + 1]) { |
| 4713 | Alert("parsing [%s:%d] : '%s' : missing interface name.\n", |
| 4714 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4715 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4716 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4717 | } |
| 4718 | if (curproxy->iface_name) |
| 4719 | free(curproxy->iface_name); |
| 4720 | |
| 4721 | curproxy->iface_name = strdup(args[cur_arg + 1]); |
| 4722 | curproxy->iface_len = strlen(curproxy->iface_name); |
| 4723 | global.last_checks |= LSTCHK_NETADM; |
| 4724 | #else |
| 4725 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 4726 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4727 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4728 | goto out; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4729 | #endif |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4730 | cur_arg += 2; |
| 4731 | continue; |
| 4732 | } |
| 4733 | Alert("parsing [%s:%d] : '%s' only supports optional keywords '%s' and '%s'.\n", |
| 4734 | file, linenum, args[0], "inteface", "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4735 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4736 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 4737 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4738 | } |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 4739 | else if (!strcmp(args[0], "usesrc")) { /* address to use outside: needs "source" first */ |
| 4740 | Alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n", |
| 4741 | file, linenum, "usesrc", "source"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4742 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4743 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 4744 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4745 | else if (!strcmp(args[0], "cliexp") || !strcmp(args[0], "reqrep")) { /* replace request header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4746 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4747 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 4748 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4749 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4750 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4751 | } |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4752 | |
| 4753 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 4754 | ACL_DIR_REQ, ACT_REPLACE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4755 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4756 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4757 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4758 | } |
| 4759 | else if (!strcmp(args[0], "reqdel")) { /* delete request header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4760 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 4761 | ACL_DIR_REQ, ACT_REMOVE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4762 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4763 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4764 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4765 | } |
| 4766 | else if (!strcmp(args[0], "reqdeny")) { /* deny a request if a header matches this regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4767 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 4768 | ACL_DIR_REQ, ACT_DENY, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4769 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4770 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4771 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4772 | } |
| 4773 | else if (!strcmp(args[0], "reqpass")) { /* pass this header without allowing or denying the request */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4774 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 4775 | ACL_DIR_REQ, ACT_PASS, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4776 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4777 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4778 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4779 | } |
| 4780 | else if (!strcmp(args[0], "reqallow")) { /* allow a request if a header matches this regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4781 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 4782 | ACL_DIR_REQ, ACT_ALLOW, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4783 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4784 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4785 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4786 | } |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 4787 | else if (!strcmp(args[0], "reqtarpit")) { /* tarpit a request if a header matches this regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4788 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 4789 | ACL_DIR_REQ, ACT_TARPIT, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4790 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4791 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4792 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 4793 | } |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 4794 | else if (!strcmp(args[0], "reqsetbe")) { /* switch the backend from a regex, respecting case */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4795 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 4796 | ACL_DIR_REQ, ACT_SETBE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4797 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4798 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4799 | goto out; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 4800 | } |
| 4801 | else if (!strcmp(args[0], "reqisetbe")) { /* switch the backend from a regex, ignoring case */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4802 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 4803 | ACL_DIR_REQ, ACT_SETBE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4804 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4805 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4806 | goto out; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 4807 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4808 | else if (!strcmp(args[0], "reqirep")) { /* replace request header from a regex, ignoring case */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4809 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4810 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 4811 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4812 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4813 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4814 | } |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4815 | |
| 4816 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 4817 | ACL_DIR_REQ, ACT_REPLACE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4818 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4819 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4820 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4821 | } |
| 4822 | else if (!strcmp(args[0], "reqidel")) { /* delete request header from a regex ignoring case */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4823 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 4824 | ACL_DIR_REQ, ACT_REMOVE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4825 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4826 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4827 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4828 | } |
| 4829 | else if (!strcmp(args[0], "reqideny")) { /* deny a request if a header matches this regex ignoring case */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4830 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 4831 | ACL_DIR_REQ, ACT_DENY, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4832 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4833 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4834 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4835 | } |
| 4836 | else if (!strcmp(args[0], "reqipass")) { /* pass this header without allowing or denying the request */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4837 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 4838 | ACL_DIR_REQ, ACT_PASS, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4839 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4840 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4841 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4842 | } |
| 4843 | else if (!strcmp(args[0], "reqiallow")) { /* allow a request if a header matches this regex ignoring case */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4844 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 4845 | ACL_DIR_REQ, ACT_ALLOW, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4846 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4847 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4848 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4849 | } |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 4850 | else if (!strcmp(args[0], "reqitarpit")) { /* tarpit a request if a header matches this regex ignoring case */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4851 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 4852 | ACL_DIR_REQ, ACT_TARPIT, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4853 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4854 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4855 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 4856 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4857 | else if (!strcmp(args[0], "reqadd")) { /* add request header */ |
Willy Tarreau | f4f0412 | 2010-01-28 18:10:50 +0100 | [diff] [blame] | 4858 | struct cond_wordlist *wl; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 4859 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4860 | if (curproxy == &defproxy) { |
| 4861 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4862 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4863 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4864 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4865 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4866 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4867 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4868 | if (*(args[1]) == 0) { |
| 4869 | Alert("parsing [%s:%d] : '%s' expects <header> as an argument.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4870 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4871 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4872 | } |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 4873 | |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 4874 | if ((strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0)) { |
| 4875 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args+2)) == NULL) { |
| 4876 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition.\n", |
| 4877 | file, linenum, args[0]); |
| 4878 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4879 | goto out; |
| 4880 | } |
| 4881 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
| 4882 | } |
| 4883 | else if (*args[2]) { |
| 4884 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 4885 | file, linenum, args[0], args[2]); |
| 4886 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4887 | goto out; |
| 4888 | } |
| 4889 | |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 4890 | wl = calloc(1, sizeof(*wl)); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 4891 | wl->cond = cond; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 4892 | wl->s = strdup(args[1]); |
| 4893 | LIST_ADDQ(&curproxy->req_add, &wl->list); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 4894 | warnif_misplaced_reqadd(curproxy, file, linenum, args[0]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4895 | } |
| 4896 | else if (!strcmp(args[0], "srvexp") || !strcmp(args[0], "rsprep")) { /* replace response header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4897 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4898 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 4899 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4900 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4901 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4902 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4903 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4904 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 4905 | ACL_DIR_RTR, ACT_REPLACE, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 4906 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4907 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4908 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4909 | } |
| 4910 | else if (!strcmp(args[0], "rspdel")) { /* delete response header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4911 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 4912 | ACL_DIR_RTR, ACT_REMOVE, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 4913 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4914 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4915 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4916 | } |
| 4917 | else if (!strcmp(args[0], "rspdeny")) { /* block response header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4918 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 4919 | ACL_DIR_RTR, ACT_DENY, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 4920 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4921 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4922 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4923 | } |
| 4924 | else if (!strcmp(args[0], "rspirep")) { /* replace response header from a regex ignoring case */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4925 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4926 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 4927 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4928 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4929 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4930 | } |
| 4931 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4932 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 4933 | ACL_DIR_RTR, ACT_REPLACE, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 4934 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4935 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4936 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4937 | } |
| 4938 | else if (!strcmp(args[0], "rspidel")) { /* delete response header from a regex ignoring case */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4939 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 4940 | ACL_DIR_RTR, ACT_REMOVE, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 4941 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4942 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4943 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4944 | } |
| 4945 | else if (!strcmp(args[0], "rspideny")) { /* block response header from a regex ignoring case */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4946 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 4947 | ACL_DIR_RTR, ACT_DENY, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 4948 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4949 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4950 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4951 | } |
| 4952 | else if (!strcmp(args[0], "rspadd")) { /* add response header */ |
Willy Tarreau | f4f0412 | 2010-01-28 18:10:50 +0100 | [diff] [blame] | 4953 | struct cond_wordlist *wl; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 4954 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4955 | if (curproxy == &defproxy) { |
| 4956 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4957 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4958 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4959 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4960 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4961 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4962 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4963 | if (*(args[1]) == 0) { |
| 4964 | Alert("parsing [%s:%d] : '%s' expects <header> as an argument.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4965 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4966 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4967 | } |
| 4968 | |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 4969 | if ((strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0)) { |
| 4970 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args+2)) == NULL) { |
| 4971 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition.\n", |
| 4972 | file, linenum, args[0]); |
| 4973 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4974 | goto out; |
| 4975 | } |
| 4976 | err_code |= warnif_cond_requires_req(cond, file, linenum); |
| 4977 | } |
| 4978 | else if (*args[2]) { |
| 4979 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 4980 | file, linenum, args[0], args[2]); |
| 4981 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4982 | goto out; |
| 4983 | } |
| 4984 | |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 4985 | wl = calloc(1, sizeof(*wl)); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 4986 | wl->cond = cond; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 4987 | wl->s = strdup(args[1]); |
| 4988 | LIST_ADDQ(&curproxy->rsp_add, &wl->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4989 | } |
| 4990 | else if (!strcmp(args[0], "errorloc") || |
| 4991 | !strcmp(args[0], "errorloc302") || |
| 4992 | !strcmp(args[0], "errorloc303")) { /* error location */ |
| 4993 | int errnum, errlen; |
| 4994 | char *err; |
| 4995 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4996 | if (warnifnotcap(curproxy, PR_CAP_FE | PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4997 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4998 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4999 | if (*(args[2]) == 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 5000 | Alert("parsing [%s:%d] : <%s> expects <status_code> and <url> as arguments.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5001 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5002 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5003 | } |
| 5004 | |
| 5005 | errnum = atol(args[1]); |
| 5006 | if (!strcmp(args[0], "errorloc303")) { |
| 5007 | err = malloc(strlen(HTTP_303) + strlen(args[2]) + 5); |
| 5008 | errlen = sprintf(err, "%s%s\r\n\r\n", HTTP_303, args[2]); |
| 5009 | } else { |
| 5010 | err = malloc(strlen(HTTP_302) + strlen(args[2]) + 5); |
| 5011 | errlen = sprintf(err, "%s%s\r\n\r\n", HTTP_302, args[2]); |
| 5012 | } |
| 5013 | |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 5014 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) { |
| 5015 | if (http_err_codes[rc] == errnum) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 5016 | chunk_destroy(&curproxy->errmsg[rc]); |
| 5017 | chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 5018 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5019 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5020 | } |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 5021 | |
| 5022 | if (rc >= HTTP_ERR_SIZE) { |
| 5023 | Warning("parsing [%s:%d] : status code %d not handled, error relocation will be ignored.\n", |
| 5024 | file, linenum, errnum); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5025 | free(err); |
| 5026 | } |
| 5027 | } |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5028 | else if (!strcmp(args[0], "errorfile")) { /* error message from a file */ |
| 5029 | int errnum, errlen, fd; |
| 5030 | char *err; |
| 5031 | struct stat stat; |
| 5032 | |
| 5033 | if (warnifnotcap(curproxy, PR_CAP_FE | PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5034 | err_code |= ERR_WARN; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5035 | |
| 5036 | if (*(args[2]) == 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 5037 | Alert("parsing [%s:%d] : <%s> expects <status_code> and <file> as arguments.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5038 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5039 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5040 | } |
| 5041 | |
| 5042 | fd = open(args[2], O_RDONLY); |
| 5043 | if ((fd < 0) || (fstat(fd, &stat) < 0)) { |
| 5044 | Alert("parsing [%s:%d] : error opening file <%s> for custom error message <%s>.\n", |
| 5045 | file, linenum, args[2], args[1]); |
| 5046 | if (fd >= 0) |
| 5047 | close(fd); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5048 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5049 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5050 | } |
| 5051 | |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 5052 | if (stat.st_size <= global.tune.bufsize) { |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5053 | errlen = stat.st_size; |
| 5054 | } else { |
| 5055 | Warning("parsing [%s:%d] : custom error message file <%s> larger than %d bytes. Truncating.\n", |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 5056 | file, linenum, args[2], global.tune.bufsize); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5057 | err_code |= ERR_WARN; |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 5058 | errlen = global.tune.bufsize; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5059 | } |
| 5060 | |
| 5061 | err = malloc(errlen); /* malloc() must succeed during parsing */ |
| 5062 | errnum = read(fd, err, errlen); |
| 5063 | if (errnum != errlen) { |
| 5064 | Alert("parsing [%s:%d] : error reading file <%s> for custom error message <%s>.\n", |
| 5065 | file, linenum, args[2], args[1]); |
| 5066 | close(fd); |
| 5067 | free(err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5068 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5069 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5070 | } |
| 5071 | close(fd); |
| 5072 | |
| 5073 | errnum = atol(args[1]); |
| 5074 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) { |
| 5075 | if (http_err_codes[rc] == errnum) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 5076 | chunk_destroy(&curproxy->errmsg[rc]); |
| 5077 | chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen); |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5078 | break; |
| 5079 | } |
| 5080 | } |
| 5081 | |
| 5082 | if (rc >= HTTP_ERR_SIZE) { |
| 5083 | Warning("parsing [%s:%d] : status code %d not handled, error customization will be ignored.\n", |
| 5084 | file, linenum, errnum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5085 | err_code |= ERR_WARN; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5086 | free(err); |
| 5087 | } |
| 5088 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5089 | else { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 5090 | struct cfg_kw_list *kwl; |
| 5091 | int index; |
| 5092 | |
| 5093 | list_for_each_entry(kwl, &cfg_keywords.list, list) { |
| 5094 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 5095 | if (kwl->kw[index].section != CFG_LISTEN) |
| 5096 | continue; |
| 5097 | if (strcmp(kwl->kw[index].kw, args[0]) == 0) { |
| 5098 | /* prepare error message just in case */ |
| 5099 | snprintf(trash, sizeof(trash), |
| 5100 | "error near '%s' in %s section", args[0], cursection); |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 5101 | rc = kwl->kw[index].parse(args, CFG_LISTEN, curproxy, &defproxy, trash, sizeof(trash)); |
| 5102 | if (rc < 0) { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 5103 | Alert("parsing [%s:%d] : %s\n", file, linenum, trash); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5104 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5105 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 5106 | } |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 5107 | else if (rc > 0) { |
| 5108 | Warning("parsing [%s:%d] : %s\n", file, linenum, trash); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5109 | err_code |= ERR_WARN; |
| 5110 | goto out; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 5111 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5112 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 5113 | } |
| 5114 | } |
| 5115 | } |
| 5116 | |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5117 | Alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5118 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5119 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5120 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5121 | out: |
| 5122 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5123 | } |
| 5124 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5125 | int |
| 5126 | cfg_parse_users(const char *file, int linenum, char **args, int kwm) |
| 5127 | { |
| 5128 | |
| 5129 | int err_code = 0; |
| 5130 | const char *err; |
| 5131 | |
| 5132 | if (!strcmp(args[0], "userlist")) { /* new userlist */ |
| 5133 | struct userlist *newul; |
| 5134 | |
| 5135 | if (!*args[1]) { |
| 5136 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 5137 | file, linenum, args[0]); |
| 5138 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5139 | goto out; |
| 5140 | } |
| 5141 | |
| 5142 | err = invalid_char(args[1]); |
| 5143 | if (err) { |
| 5144 | Alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 5145 | file, linenum, *err, args[0], args[1]); |
| 5146 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5147 | goto out; |
| 5148 | } |
| 5149 | |
| 5150 | for (newul = userlist; newul; newul = newul->next) |
| 5151 | if (!strcmp(newul->name, args[1])) { |
| 5152 | Warning("parsing [%s:%d]: ignoring duplicated userlist '%s'.\n", |
| 5153 | file, linenum, args[1]); |
| 5154 | err_code |= ERR_WARN; |
| 5155 | goto out; |
| 5156 | } |
| 5157 | |
| 5158 | newul = (struct userlist *)calloc(1, sizeof(struct userlist)); |
| 5159 | if (!newul) { |
| 5160 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 5161 | err_code |= ERR_ALERT | ERR_ABORT; |
| 5162 | goto out; |
| 5163 | } |
| 5164 | |
| 5165 | newul->groupusers = calloc(MAX_AUTH_GROUPS, sizeof(char *)); |
| 5166 | newul->name = strdup(args[1]); |
| 5167 | |
| 5168 | if (!newul->groupusers | !newul->name) { |
| 5169 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 5170 | err_code |= ERR_ALERT | ERR_ABORT; |
| 5171 | goto out; |
| 5172 | } |
| 5173 | |
| 5174 | newul->next = userlist; |
| 5175 | userlist = newul; |
| 5176 | |
| 5177 | } else if (!strcmp(args[0], "group")) { /* new group */ |
| 5178 | int cur_arg, i; |
| 5179 | const char *err; |
| 5180 | |
| 5181 | if (!*args[1]) { |
| 5182 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 5183 | file, linenum, args[0]); |
| 5184 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5185 | goto out; |
| 5186 | } |
| 5187 | |
| 5188 | err = invalid_char(args[1]); |
| 5189 | if (err) { |
| 5190 | Alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 5191 | file, linenum, *err, args[0], args[1]); |
| 5192 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5193 | goto out; |
| 5194 | } |
| 5195 | |
| 5196 | for(i = 0; i < userlist->grpcnt; i++) |
| 5197 | if (!strcmp(userlist->groups[i], args[1])) { |
| 5198 | Warning("parsing [%s:%d]: ignoring duplicated group '%s' in userlist '%s'.\n", |
| 5199 | file, linenum, args[1], userlist->name); |
| 5200 | err_code |= ERR_ALERT; |
| 5201 | goto out; |
| 5202 | } |
| 5203 | |
| 5204 | if (userlist->grpcnt >= MAX_AUTH_GROUPS) { |
| 5205 | Alert("parsing [%s:%d]: too many groups (%u) in in userlist '%s' while adding group '%s'.\n", |
| 5206 | file, linenum, MAX_AUTH_GROUPS, userlist->name, args[1]); |
| 5207 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5208 | goto out; |
| 5209 | } |
| 5210 | |
| 5211 | cur_arg = 2; |
| 5212 | |
| 5213 | while (*args[cur_arg]) { |
| 5214 | if (!strcmp(args[cur_arg], "users")) { |
| 5215 | userlist->groupusers[userlist->grpcnt] = strdup(args[cur_arg + 1]); |
| 5216 | cur_arg += 2; |
| 5217 | continue; |
| 5218 | } else { |
| 5219 | Alert("parsing [%s:%d]: '%s' only supports 'users' option.\n", |
| 5220 | file, linenum, args[0]); |
| 5221 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5222 | goto out; |
| 5223 | } |
| 5224 | } |
| 5225 | |
| 5226 | userlist->groups[userlist->grpcnt++] = strdup(args[1]); |
| 5227 | } else if (!strcmp(args[0], "user")) { /* new user */ |
| 5228 | struct auth_users *newuser; |
| 5229 | int cur_arg; |
| 5230 | |
| 5231 | if (!*args[1]) { |
| 5232 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 5233 | file, linenum, args[0]); |
| 5234 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5235 | goto out; |
| 5236 | } |
| 5237 | |
| 5238 | for (newuser = userlist->users; newuser; newuser = newuser->next) |
| 5239 | if (!strcmp(newuser->user, args[1])) { |
| 5240 | Warning("parsing [%s:%d]: ignoring duplicated user '%s' in userlist '%s'.\n", |
| 5241 | file, linenum, args[1], userlist->name); |
| 5242 | err_code |= ERR_ALERT; |
| 5243 | goto out; |
| 5244 | } |
| 5245 | |
| 5246 | newuser = (struct auth_users *)calloc(1, sizeof(struct auth_users)); |
| 5247 | if (!newuser) { |
| 5248 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 5249 | err_code |= ERR_ALERT | ERR_ABORT; |
| 5250 | goto out; |
| 5251 | } |
| 5252 | |
| 5253 | newuser->user = strdup(args[1]); |
| 5254 | |
| 5255 | newuser->next = userlist->users; |
| 5256 | userlist->users = newuser; |
| 5257 | |
| 5258 | cur_arg = 2; |
| 5259 | |
| 5260 | while (*args[cur_arg]) { |
| 5261 | if (!strcmp(args[cur_arg], "password")) { |
| 5262 | #ifndef CONFIG_HAP_CRYPT |
| 5263 | Warning("parsing [%s:%d]: no crypt(3) support compiled, encrypted passwords will not work.\n", |
| 5264 | file, linenum); |
| 5265 | err_code |= ERR_ALERT; |
| 5266 | #endif |
| 5267 | newuser->pass = strdup(args[cur_arg + 1]); |
| 5268 | cur_arg += 2; |
| 5269 | continue; |
| 5270 | } else if (!strcmp(args[cur_arg], "insecure-password")) { |
| 5271 | newuser->pass = strdup(args[cur_arg + 1]); |
| 5272 | newuser->flags |= AU_O_INSECURE; |
| 5273 | cur_arg += 2; |
| 5274 | continue; |
| 5275 | } else if (!strcmp(args[cur_arg], "groups")) { |
Willy Tarreau | b4c06b7 | 2010-02-02 11:28:20 +0100 | [diff] [blame] | 5276 | newuser->u.groups = strdup(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5277 | cur_arg += 2; |
| 5278 | continue; |
| 5279 | } else { |
| 5280 | Alert("parsing [%s:%d]: '%s' only supports 'password', 'insecure-password' and 'groups' options.\n", |
| 5281 | file, linenum, args[0]); |
| 5282 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5283 | goto out; |
| 5284 | } |
| 5285 | } |
| 5286 | } else { |
| 5287 | Alert("parsing [%s:%d]: unknown keyword '%s' in '%s' section\n", file, linenum, args[0], "users"); |
| 5288 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5289 | } |
| 5290 | |
| 5291 | out: |
| 5292 | return err_code; |
| 5293 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5294 | |
| 5295 | /* |
| 5296 | * This function reads and parses the configuration file given in the argument. |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5297 | * Returns the error code, 0 if OK, or any combination of : |
| 5298 | * - ERR_ABORT: must abort ASAP |
| 5299 | * - ERR_FATAL: we can continue parsing but not start the service |
| 5300 | * - ERR_WARN: a warning has been emitted |
| 5301 | * - ERR_ALERT: an alert has been emitted |
| 5302 | * Only the two first ones can stop processing, the two others are just |
| 5303 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5304 | */ |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 5305 | int readcfgfile(const char *file) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5306 | { |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5307 | char thisline[LINESIZE]; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5308 | FILE *f; |
| 5309 | int linenum = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5310 | int confsect = CFG_NONE; |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5311 | int err_code = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5312 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5313 | if ((f=fopen(file,"r")) == NULL) |
| 5314 | return -1; |
| 5315 | |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5316 | while (fgets(thisline, sizeof(thisline), f) != NULL) { |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 5317 | int arg, kwm = KWM_STD; |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5318 | char *end; |
| 5319 | char *args[MAX_LINE_ARGS + 1]; |
| 5320 | char *line = thisline; |
| 5321 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5322 | linenum++; |
| 5323 | |
| 5324 | end = line + strlen(line); |
| 5325 | |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5326 | if (end-line == sizeof(thisline)-1 && *(end-1) != '\n') { |
| 5327 | /* Check if we reached the limit and the last char is not \n. |
| 5328 | * Watch out for the last line without the terminating '\n'! |
| 5329 | */ |
| 5330 | Alert("parsing [%s:%d]: line too long, limit: %d.\n", |
Willy Tarreau | 5e4a6f1 | 2009-04-11 19:42:49 +0200 | [diff] [blame] | 5331 | file, linenum, (int)sizeof(thisline)-1); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5332 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5333 | } |
| 5334 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5335 | /* skip leading spaces */ |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 5336 | while (isspace((unsigned char)*line)) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5337 | line++; |
| 5338 | |
| 5339 | arg = 0; |
| 5340 | args[arg] = line; |
| 5341 | |
| 5342 | while (*line && arg < MAX_LINE_ARGS) { |
| 5343 | /* first, we'll replace \\, \<space>, \#, \r, \n, \t, \xXX with their |
| 5344 | * C equivalent value. Other combinations left unchanged (eg: \1). |
| 5345 | */ |
| 5346 | if (*line == '\\') { |
| 5347 | int skip = 0; |
| 5348 | if (line[1] == ' ' || line[1] == '\\' || line[1] == '#') { |
| 5349 | *line = line[1]; |
| 5350 | skip = 1; |
| 5351 | } |
| 5352 | else if (line[1] == 'r') { |
| 5353 | *line = '\r'; |
| 5354 | skip = 1; |
| 5355 | } |
| 5356 | else if (line[1] == 'n') { |
| 5357 | *line = '\n'; |
| 5358 | skip = 1; |
| 5359 | } |
| 5360 | else if (line[1] == 't') { |
| 5361 | *line = '\t'; |
| 5362 | skip = 1; |
| 5363 | } |
| 5364 | else if (line[1] == 'x') { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5365 | if ((line + 3 < end) && ishex(line[2]) && ishex(line[3])) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5366 | unsigned char hex1, hex2; |
| 5367 | hex1 = toupper(line[2]) - '0'; |
| 5368 | hex2 = toupper(line[3]) - '0'; |
| 5369 | if (hex1 > 9) hex1 -= 'A' - '9' - 1; |
| 5370 | if (hex2 > 9) hex2 -= 'A' - '9' - 1; |
| 5371 | *line = (hex1<<4) + hex2; |
| 5372 | skip = 3; |
| 5373 | } |
| 5374 | else { |
| 5375 | Alert("parsing [%s:%d] : invalid or incomplete '\\x' sequence in '%s'.\n", file, linenum, args[0]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5376 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5377 | } |
| 5378 | } |
| 5379 | if (skip) { |
Cyril Bonté | dd1b01d | 2009-12-06 13:43:42 +0100 | [diff] [blame] | 5380 | memmove(line + 1, line + 1 + skip, end - (line + skip)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5381 | end -= skip; |
| 5382 | } |
| 5383 | line++; |
| 5384 | } |
| 5385 | else if (*line == '#' || *line == '\n' || *line == '\r') { |
| 5386 | /* end of string, end of loop */ |
| 5387 | *line = 0; |
| 5388 | break; |
| 5389 | } |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 5390 | else if (isspace((unsigned char)*line)) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5391 | /* a non-escaped space is an argument separator */ |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5392 | *line++ = '\0'; |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 5393 | while (isspace((unsigned char)*line)) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5394 | line++; |
| 5395 | args[++arg] = line; |
| 5396 | } |
| 5397 | else { |
| 5398 | line++; |
| 5399 | } |
| 5400 | } |
| 5401 | |
| 5402 | /* empty line */ |
| 5403 | if (!**args) |
| 5404 | continue; |
| 5405 | |
Willy Tarreau | 7bb651e | 2009-11-09 21:16:53 +0100 | [diff] [blame] | 5406 | if (*line) { |
| 5407 | /* we had to stop due to too many args. |
| 5408 | * Let's terminate the string, print the offending part then cut the |
| 5409 | * last arg. |
| 5410 | */ |
| 5411 | while (*line && *line != '#' && *line != '\n' && *line != '\r') |
| 5412 | line++; |
| 5413 | *line = '\0'; |
| 5414 | |
Krzysztof Piotr Oledzki | 500b8f0 | 2009-12-15 22:34:51 +0100 | [diff] [blame] | 5415 | Alert("parsing [%s:%d]: line too long, truncating at word %d, position %ld: <%s>.\n", |
Willy Tarreau | 3ccf94e | 2009-12-17 21:12:16 +0100 | [diff] [blame] | 5416 | file, linenum, arg + 1, (long)(args[arg] - thisline + 1), args[arg]); |
Willy Tarreau | 7bb651e | 2009-11-09 21:16:53 +0100 | [diff] [blame] | 5417 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5418 | args[arg] = line; |
| 5419 | } |
| 5420 | |
Willy Tarreau | 540abe4 | 2007-05-02 20:50:16 +0200 | [diff] [blame] | 5421 | /* zero out remaining args and ensure that at least one entry |
| 5422 | * is zeroed out. |
| 5423 | */ |
| 5424 | while (++arg <= MAX_LINE_ARGS) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5425 | args[arg] = line; |
| 5426 | } |
| 5427 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 5428 | /* check for keyword modifiers "no" and "default" */ |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5429 | if (!strcmp(args[0], "no")) { |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 5430 | kwm = KWM_NO; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5431 | for (arg=0; *args[arg+1]; arg++) |
| 5432 | args[arg] = args[arg+1]; // shift args after inversion |
| 5433 | } |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 5434 | else if (!strcmp(args[0], "default")) { |
| 5435 | kwm = KWM_DEF; |
| 5436 | for (arg=0; *args[arg+1]; arg++) |
| 5437 | args[arg] = args[arg+1]; // shift args after inversion |
| 5438 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5439 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 5440 | if (kwm != KWM_STD && strcmp(args[0], "option") != 0) { |
| 5441 | Alert("parsing [%s:%d]: negation/default currently supported only for options.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5442 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5443 | } |
| 5444 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5445 | if (!strcmp(args[0], "listen") || |
| 5446 | !strcmp(args[0], "frontend") || |
| 5447 | !strcmp(args[0], "backend") || |
| 5448 | !strcmp(args[0], "ruleset") || |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5449 | !strcmp(args[0], "defaults")) { /* new proxy */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5450 | confsect = CFG_LISTEN; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 5451 | free(cursection); |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5452 | cursection = strdup(args[0]); |
| 5453 | } |
| 5454 | else if (!strcmp(args[0], "global")) { /* global config */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5455 | confsect = CFG_GLOBAL; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 5456 | free(cursection); |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5457 | cursection = strdup(args[0]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 5458 | } |
| 5459 | else if (!strcmp(args[0], "userlist")) { |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5460 | confsect = CFG_USERLIST; |
| 5461 | free(cursection); |
| 5462 | cursection = strdup(args[0]); |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5463 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 5464 | else if (!strcmp(args[0], "peers")) { |
| 5465 | confsect = CFG_PEERS; |
| 5466 | free(cursection); |
| 5467 | cursection = strdup(args[0]); |
| 5468 | } |
| 5469 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5470 | /* else it's a section keyword */ |
| 5471 | |
| 5472 | switch (confsect) { |
| 5473 | case CFG_LISTEN: |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5474 | err_code |= cfg_parse_listen(file, linenum, args, kwm); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5475 | break; |
| 5476 | case CFG_GLOBAL: |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5477 | err_code |= cfg_parse_global(file, linenum, args, kwm); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5478 | break; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5479 | case CFG_USERLIST: |
| 5480 | err_code |= cfg_parse_users(file, linenum, args, kwm); |
| 5481 | break; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 5482 | case CFG_PEERS: |
| 5483 | err_code |= cfg_parse_peers(file, linenum, args, kwm); |
| 5484 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5485 | default: |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5486 | Alert("parsing [%s:%d]: unknown keyword '%s' out of section.\n", file, linenum, args[0]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5487 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5488 | } |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5489 | |
| 5490 | if (err_code & ERR_ABORT) |
| 5491 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5492 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 5493 | free(cursection); |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5494 | cursection = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5495 | fclose(f); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5496 | return err_code; |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5497 | } |
| 5498 | |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 5499 | /* |
| 5500 | * Returns the error code, 0 if OK, or any combination of : |
| 5501 | * - ERR_ABORT: must abort ASAP |
| 5502 | * - ERR_FATAL: we can continue parsing but not start the service |
| 5503 | * - ERR_WARN: a warning has been emitted |
| 5504 | * - ERR_ALERT: an alert has been emitted |
| 5505 | * Only the two first ones can stop processing, the two others are just |
| 5506 | * indicators. |
| 5507 | */ |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5508 | int check_config_validity() |
| 5509 | { |
| 5510 | int cfgerr = 0; |
| 5511 | struct proxy *curproxy = NULL; |
| 5512 | struct server *newsrv = NULL; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5513 | struct userlist *curuserlist = NULL; |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 5514 | int err_code = 0; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 5515 | unsigned int next_pxid = 1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5516 | |
| 5517 | /* |
| 5518 | * Now, check for the integrity of all that we have collected. |
| 5519 | */ |
| 5520 | |
| 5521 | /* will be needed further to delay some tasks */ |
Willy Tarreau | b0b37bc | 2008-06-23 14:00:57 +0200 | [diff] [blame] | 5522 | tv_update_date(0,1); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5523 | |
Willy Tarreau | 55bc0f8 | 2009-03-15 14:51:53 +0100 | [diff] [blame] | 5524 | /* first, we will invert the proxy list order */ |
| 5525 | curproxy = NULL; |
| 5526 | while (proxy) { |
| 5527 | struct proxy *next; |
| 5528 | |
| 5529 | next = proxy->next; |
| 5530 | proxy->next = curproxy; |
| 5531 | curproxy = proxy; |
| 5532 | if (!next) |
| 5533 | break; |
| 5534 | proxy = next; |
| 5535 | } |
| 5536 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5537 | if ((curproxy = proxy) == NULL) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5538 | Alert("config : no <listen> line. Nothing to do !\n"); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 5539 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5540 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5541 | } |
| 5542 | |
| 5543 | while (curproxy != NULL) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 5544 | struct switching_rule *rule; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5545 | struct sticking_rule *mrule; |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 5546 | struct tcp_rule *trule; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 5547 | struct listener *listener; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 5548 | unsigned int next_id; |
| 5549 | |
| 5550 | if (!curproxy->uuid) { |
| 5551 | /* proxy ID not set, use automatic numbering with first |
| 5552 | * spare entry starting with next_pxid. |
| 5553 | */ |
| 5554 | next_pxid = get_next_id(&used_proxy_id, next_pxid); |
| 5555 | curproxy->conf.id.key = curproxy->uuid = next_pxid; |
| 5556 | eb32_insert(&used_proxy_id, &curproxy->conf.id); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 5557 | } |
Krzysztof Piotr Oledzki | df5cb9f | 2010-02-05 20:58:27 +0100 | [diff] [blame] | 5558 | next_pxid++; |
| 5559 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 5560 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5561 | if (curproxy->state == PR_STSTOPPED) { |
Willy Tarreau | da250db | 2008-10-12 12:07:48 +0200 | [diff] [blame] | 5562 | /* ensure we don't keep listeners uselessly bound */ |
| 5563 | stop_proxy(curproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5564 | curproxy = curproxy->next; |
| 5565 | continue; |
| 5566 | } |
| 5567 | |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 5568 | switch (curproxy->mode) { |
| 5569 | case PR_MODE_HEALTH: |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5570 | cfgerr += proxy_cfg_ensure_no_http(curproxy); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 5571 | if (!(curproxy->cap & PR_CAP_FE)) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5572 | Alert("config : %s '%s' cannot be in health mode as it has no frontend capability.\n", |
| 5573 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 5574 | cfgerr++; |
| 5575 | } |
| 5576 | |
| 5577 | if (curproxy->srv != NULL) |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5578 | Warning("config : servers will be ignored for %s '%s'.\n", |
| 5579 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 5580 | break; |
| 5581 | |
| 5582 | case PR_MODE_TCP: |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5583 | cfgerr += proxy_cfg_ensure_no_http(curproxy); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 5584 | break; |
| 5585 | |
| 5586 | case PR_MODE_HTTP: |
Willy Tarreau | a9fb083 | 2009-07-10 20:53:53 +0200 | [diff] [blame] | 5587 | curproxy->acl_requires |= ACL_USE_L7_ANY; |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 5588 | break; |
| 5589 | } |
| 5590 | |
| 5591 | if ((curproxy->cap & PR_CAP_FE) && (curproxy->listen == NULL)) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5592 | Alert("config : %s '%s' has no listen address. Please either specify a valid address on the <listen> line, or use the <bind> keyword.\n", |
| 5593 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5594 | cfgerr++; |
| 5595 | } |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 5596 | |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 5597 | if ((curproxy->cap & PR_CAP_BE) && (curproxy->mode != PR_MODE_HEALTH)) { |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 5598 | if (curproxy->lbprm.algo & BE_LB_KIND) { |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 5599 | if (curproxy->options & PR_O_TRANSP) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5600 | Alert("config : %s '%s' cannot use both transparent and balance mode.\n", |
| 5601 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 5602 | cfgerr++; |
| 5603 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5604 | #ifdef WE_DONT_SUPPORT_SERVERLESS_LISTENERS |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 5605 | else if (curproxy->srv == NULL) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5606 | Alert("config : %s '%s' needs at least 1 server in balance mode.\n", |
| 5607 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 5608 | cfgerr++; |
| 5609 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5610 | #endif |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 5611 | else if (curproxy->options & PR_O_DISPATCH) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5612 | Warning("config : dispatch address of %s '%s' will be ignored in balance mode.\n", |
| 5613 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 5614 | err_code |= ERR_WARN; |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 5615 | } |
| 5616 | } |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 5617 | else if (!(curproxy->options & (PR_O_TRANSP | PR_O_DISPATCH | PR_O_HTTP_PROXY))) { |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 5618 | /* If no LB algo is set in a backend, and we're not in |
| 5619 | * transparent mode, dispatch mode nor proxy mode, we |
| 5620 | * want to use balance roundrobin by default. |
| 5621 | */ |
| 5622 | curproxy->lbprm.algo &= ~BE_LB_ALGO; |
| 5623 | curproxy->lbprm.algo |= BE_LB_ALGO_RR; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5624 | } |
| 5625 | } |
Willy Tarreau | 193cf93 | 2007-09-17 10:17:23 +0200 | [diff] [blame] | 5626 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 5627 | if (curproxy->options & PR_O_DISPATCH) |
| 5628 | curproxy->options &= ~(PR_O_TRANSP | PR_O_HTTP_PROXY); |
| 5629 | else if (curproxy->options & PR_O_HTTP_PROXY) |
| 5630 | curproxy->options &= ~(PR_O_DISPATCH | PR_O_TRANSP); |
| 5631 | else if (curproxy->options & PR_O_TRANSP) |
| 5632 | curproxy->options &= ~(PR_O_DISPATCH | PR_O_HTTP_PROXY); |
Willy Tarreau | 8293658 | 2007-11-30 15:20:09 +0100 | [diff] [blame] | 5633 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 5634 | if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_HTTP_CHK) { |
| 5635 | if (curproxy->options & PR_O_DISABLE404) { |
| 5636 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n", |
| 5637 | "disable-on-404", proxy_type_str(curproxy), curproxy->id); |
| 5638 | err_code |= ERR_WARN; |
| 5639 | curproxy->options &= ~PR_O_DISABLE404; |
| 5640 | } |
| 5641 | if (curproxy->options2 & PR_O2_CHK_SNDST) { |
| 5642 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n", |
| 5643 | "send-state", proxy_type_str(curproxy), curproxy->id); |
| 5644 | err_code |= ERR_WARN; |
| 5645 | curproxy->options &= ~PR_O2_CHK_SNDST; |
| 5646 | } |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 5647 | } |
| 5648 | |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5649 | /* if a default backend was specified, let's find it */ |
| 5650 | if (curproxy->defbe.name) { |
| 5651 | struct proxy *target; |
| 5652 | |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 5653 | target = findproxy_mode(curproxy->defbe.name, curproxy->mode, PR_CAP_BE); |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 5654 | if (!target) { |
| 5655 | Alert("Proxy '%s': unable to find required default_backend: '%s'.\n", |
| 5656 | curproxy->id, curproxy->defbe.name); |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5657 | cfgerr++; |
| 5658 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 5659 | Alert("Proxy '%s': loop detected for default_backend: '%s'.\n", |
| 5660 | curproxy->id, curproxy->defbe.name); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 5661 | cfgerr++; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5662 | } else { |
| 5663 | free(curproxy->defbe.name); |
| 5664 | curproxy->defbe.be = target; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 5665 | /* we force the backend to be present on at least all of |
| 5666 | * the frontend's processes. |
| 5667 | */ |
| 5668 | target->bind_proc = curproxy->bind_proc ? |
| 5669 | (target->bind_proc | curproxy->bind_proc) : 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5670 | } |
| 5671 | } |
| 5672 | |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5673 | /* find the target proxy in setbe */ |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5674 | if (curproxy->mode == PR_MODE_HTTP && curproxy->req_exp != NULL) { |
| 5675 | /* map jump target for ACT_SETBE in req_rep chain */ |
| 5676 | struct hdr_exp *exp; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5677 | for (exp = curproxy->req_exp; exp != NULL; exp = exp->next) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 5678 | struct proxy *target; |
| 5679 | |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5680 | if (exp->action != ACT_SETBE) |
| 5681 | continue; |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 5682 | |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 5683 | target = findproxy_mode(exp->replace, PR_MODE_HTTP, PR_CAP_BE); |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 5684 | if (!target) { |
| 5685 | Alert("Proxy '%s': unable to find required setbe: '%s'.\n", |
| 5686 | curproxy->id, exp->replace); |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5687 | cfgerr++; |
| 5688 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 5689 | Alert("Proxy '%s': loop detected for setbe: '%s'.\n", |
| 5690 | curproxy->id, exp->replace); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5691 | cfgerr++; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5692 | } else { |
| 5693 | free((void *)exp->replace); |
| 5694 | exp->replace = (const char *)target; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 5695 | /* we force the backend to be present on at least all of |
| 5696 | * the frontend's processes. |
| 5697 | */ |
| 5698 | target->bind_proc = curproxy->bind_proc ? |
| 5699 | (target->bind_proc | curproxy->bind_proc) : 0; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5700 | } |
| 5701 | } |
| 5702 | } |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 5703 | |
| 5704 | /* find the target proxy for 'use_backend' rules */ |
| 5705 | list_for_each_entry(rule, &curproxy->switching_rules, list) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 5706 | struct proxy *target; |
| 5707 | |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 5708 | target = findproxy_mode(rule->be.name, curproxy->mode, PR_CAP_BE); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 5709 | |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 5710 | if (!target) { |
| 5711 | Alert("Proxy '%s': unable to find required use_backend: '%s'.\n", |
| 5712 | curproxy->id, rule->be.name); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 5713 | cfgerr++; |
| 5714 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 5715 | Alert("Proxy '%s': loop detected for use_backend: '%s'.\n", |
| 5716 | curproxy->id, rule->be.name); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 5717 | cfgerr++; |
| 5718 | } else { |
| 5719 | free((void *)rule->be.name); |
| 5720 | rule->be.backend = target; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 5721 | /* we force the backend to be present on at least all of |
| 5722 | * the frontend's processes. |
| 5723 | */ |
| 5724 | target->bind_proc = curproxy->bind_proc ? |
| 5725 | (target->bind_proc | curproxy->bind_proc) : 0; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 5726 | } |
| 5727 | } |
| 5728 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5729 | /* find the target table for 'stick' rules */ |
| 5730 | list_for_each_entry(mrule, &curproxy->sticking_rules, list) { |
| 5731 | struct proxy *target; |
| 5732 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 5733 | curproxy->be_req_ana |= AN_REQ_STICKING_RULES; |
| 5734 | if (mrule->flags & STK_IS_STORE) |
| 5735 | curproxy->be_rsp_ana |= AN_RES_STORE_RULES; |
| 5736 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5737 | if (mrule->table.name) |
Willy Tarreau | c00cdc2 | 2010-06-06 16:48:26 +0200 | [diff] [blame] | 5738 | target = findproxy(mrule->table.name, 0); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5739 | else |
| 5740 | target = curproxy; |
| 5741 | |
| 5742 | if (!target) { |
| 5743 | Alert("Proxy '%s': unable to find stick-table '%s'.\n", |
| 5744 | curproxy->id, mrule->table.name); |
| 5745 | cfgerr++; |
| 5746 | } |
| 5747 | else if (target->table.size == 0) { |
| 5748 | Alert("Proxy '%s': stick-table '%s' used but not configured.\n", |
| 5749 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 5750 | cfgerr++; |
| 5751 | } |
Willy Tarreau | f0b38bf | 2010-06-06 13:22:23 +0200 | [diff] [blame] | 5752 | else if (!stktable_compatible_pattern(mrule->expr, target->table.type)) { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5753 | Alert("Proxy '%s': type of pattern not usable with type of stick-table '%s'.\n", |
| 5754 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 5755 | cfgerr++; |
| 5756 | } |
| 5757 | else { |
| 5758 | free((void *)mrule->table.name); |
| 5759 | mrule->table.t = &(target->table); |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 5760 | stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID, NULL); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5761 | } |
| 5762 | } |
| 5763 | |
| 5764 | /* find the target table for 'store response' rules */ |
| 5765 | list_for_each_entry(mrule, &curproxy->storersp_rules, list) { |
| 5766 | struct proxy *target; |
| 5767 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 5768 | curproxy->be_rsp_ana |= AN_RES_STORE_RULES; |
| 5769 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5770 | if (mrule->table.name) |
Willy Tarreau | c00cdc2 | 2010-06-06 16:48:26 +0200 | [diff] [blame] | 5771 | target = findproxy(mrule->table.name, 0); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5772 | else |
| 5773 | target = curproxy; |
| 5774 | |
| 5775 | if (!target) { |
| 5776 | Alert("Proxy '%s': unable to find store table '%s'.\n", |
| 5777 | curproxy->id, mrule->table.name); |
| 5778 | cfgerr++; |
| 5779 | } |
| 5780 | else if (target->table.size == 0) { |
| 5781 | Alert("Proxy '%s': stick-table '%s' used but not configured.\n", |
| 5782 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 5783 | cfgerr++; |
| 5784 | } |
Willy Tarreau | f0b38bf | 2010-06-06 13:22:23 +0200 | [diff] [blame] | 5785 | else if (!stktable_compatible_pattern(mrule->expr, target->table.type)) { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5786 | Alert("Proxy '%s': type of pattern not usable with type of stick-table '%s'.\n", |
| 5787 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 5788 | cfgerr++; |
| 5789 | } |
| 5790 | else { |
| 5791 | free((void *)mrule->table.name); |
| 5792 | mrule->table.t = &(target->table); |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 5793 | stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID, NULL); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5794 | } |
| 5795 | } |
| 5796 | |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 5797 | /* find the target table for 'tcp-request' layer 4 rules */ |
| 5798 | list_for_each_entry(trule, &curproxy->tcp_req.l4_rules, list) { |
| 5799 | struct proxy *target; |
| 5800 | |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 5801 | if (trule->action != TCP_ACT_TRK_SC1 && trule->action != TCP_ACT_TRK_SC2) |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 5802 | continue; |
| 5803 | |
| 5804 | if (trule->act_prm.trk_ctr.table.n) |
| 5805 | target = findproxy(trule->act_prm.trk_ctr.table.n, 0); |
| 5806 | else |
| 5807 | target = curproxy; |
| 5808 | |
| 5809 | if (!target) { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 5810 | Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n", |
| 5811 | curproxy->id, trule->act_prm.trk_ctr.table.n, |
| 5812 | trule->action == TCP_ACT_TRK_SC1 ? 1 : 2); |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 5813 | cfgerr++; |
| 5814 | } |
| 5815 | else if (target->table.size == 0) { |
| 5816 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
| 5817 | curproxy->id, trule->act_prm.trk_ctr.table.n ? trule->act_prm.trk_ctr.table.n : curproxy->id); |
| 5818 | cfgerr++; |
| 5819 | } |
| 5820 | else if (trule->act_prm.trk_ctr.type != target->table.type) { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 5821 | Alert("Proxy '%s': type of tracking key for sticky counter not usable with type of stick-table '%s'.\n", |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 5822 | curproxy->id, trule->act_prm.trk_ctr.table.n ? trule->act_prm.trk_ctr.table.n : curproxy->id); |
| 5823 | cfgerr++; |
| 5824 | } |
| 5825 | else { |
| 5826 | free(trule->act_prm.trk_ctr.table.n); |
| 5827 | trule->act_prm.trk_ctr.table.t = &target->table; |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 5828 | /* Note: if we decide to enhance the track-sc syntax, we may be able |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 5829 | * to pass a list of counters to track and allocate them right here using |
| 5830 | * stktable_alloc_data_type(). |
| 5831 | */ |
| 5832 | } |
| 5833 | } |
| 5834 | |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 5835 | /* find the target table for 'tcp-request' layer 6 rules */ |
| 5836 | list_for_each_entry(trule, &curproxy->tcp_req.inspect_rules, list) { |
| 5837 | struct proxy *target; |
| 5838 | |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 5839 | if (trule->action != TCP_ACT_TRK_SC1 && trule->action != TCP_ACT_TRK_SC2) |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 5840 | continue; |
| 5841 | |
| 5842 | if (trule->act_prm.trk_ctr.table.n) |
| 5843 | target = findproxy(trule->act_prm.trk_ctr.table.n, 0); |
| 5844 | else |
| 5845 | target = curproxy; |
| 5846 | |
| 5847 | if (!target) { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 5848 | Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n", |
| 5849 | curproxy->id, trule->act_prm.trk_ctr.table.n, |
| 5850 | trule->action == TCP_ACT_TRK_SC1 ? 1 : 2); |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 5851 | cfgerr++; |
| 5852 | } |
| 5853 | else if (target->table.size == 0) { |
| 5854 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
| 5855 | curproxy->id, trule->act_prm.trk_ctr.table.n ? trule->act_prm.trk_ctr.table.n : curproxy->id); |
| 5856 | cfgerr++; |
| 5857 | } |
| 5858 | else if (trule->act_prm.trk_ctr.type != target->table.type) { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 5859 | Alert("Proxy '%s': type of tracking key for sticky counter not usable with type of stick-table '%s'.\n", |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 5860 | curproxy->id, trule->act_prm.trk_ctr.table.n ? trule->act_prm.trk_ctr.table.n : curproxy->id); |
| 5861 | cfgerr++; |
| 5862 | } |
| 5863 | else { |
| 5864 | free(trule->act_prm.trk_ctr.table.n); |
| 5865 | trule->act_prm.trk_ctr.table.t = &target->table; |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 5866 | /* Note: if we decide to enhance the track-sc syntax, we may be able |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 5867 | * to pass a list of counters to track and allocate them right here using |
| 5868 | * stktable_alloc_data_type(). |
| 5869 | */ |
| 5870 | } |
| 5871 | } |
| 5872 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 5873 | if (curproxy->table.peers.name) { |
| 5874 | struct peers *curpeers = peers; |
| 5875 | |
| 5876 | for (curpeers = peers; curpeers; curpeers = curpeers->next) { |
| 5877 | if (strcmp(curpeers->id, curproxy->table.peers.name) == 0) { |
| 5878 | free((void *)curproxy->table.peers.name); |
| 5879 | curproxy->table.peers.p = peers; |
| 5880 | break; |
| 5881 | } |
| 5882 | } |
| 5883 | |
| 5884 | if (!curpeers) { |
| 5885 | Alert("Proxy '%s': unable to find sync peers '%s'.\n", |
| 5886 | curproxy->id, curproxy->table.peers.name); |
| 5887 | cfgerr++; |
| 5888 | } |
| 5889 | else if (!curpeers->peers_fe) { |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 5890 | Alert("Proxy '%s': unable to find local peer '%s' in peers section '%s'.\n", |
| 5891 | curproxy->id, localpeer, curpeers->id); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 5892 | cfgerr++; |
| 5893 | } |
| 5894 | } |
| 5895 | |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 5896 | if (curproxy->uri_auth && !(curproxy->uri_auth->flags & ST_CONVDONE) && |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 5897 | !LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) && |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 5898 | (curproxy->uri_auth->userlist || curproxy->uri_auth->auth_realm )) { |
| 5899 | Alert("%s '%s': stats 'auth'/'realm' and 'http-request' can't be used at the same time.\n", |
| 5900 | "proxy", curproxy->id); |
| 5901 | cfgerr++; |
| 5902 | goto out_uri_auth_compat; |
| 5903 | } |
| 5904 | |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 5905 | if (curproxy->uri_auth && curproxy->uri_auth->userlist && !(curproxy->uri_auth->flags & ST_CONVDONE)) { |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 5906 | const char *uri_auth_compat_req[10]; |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 5907 | struct http_req_rule *rule; |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 5908 | int i = 0; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 5909 | |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 5910 | /* build the ACL condition from scratch. We're relying on anonymous ACLs for that */ |
| 5911 | uri_auth_compat_req[i++] = "auth"; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 5912 | |
| 5913 | if (curproxy->uri_auth->auth_realm) { |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 5914 | uri_auth_compat_req[i++] = "realm"; |
| 5915 | uri_auth_compat_req[i++] = curproxy->uri_auth->auth_realm; |
| 5916 | } |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 5917 | |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 5918 | uri_auth_compat_req[i++] = "unless"; |
| 5919 | uri_auth_compat_req[i++] = "{"; |
| 5920 | uri_auth_compat_req[i++] = "http_auth(.internal-stats-userlist)"; |
| 5921 | uri_auth_compat_req[i++] = "}"; |
| 5922 | uri_auth_compat_req[i++] = ""; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 5923 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 5924 | rule = parse_http_req_cond(uri_auth_compat_req, "internal-stats-auth-compat", 0, curproxy); |
| 5925 | if (!rule) { |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 5926 | cfgerr++; |
| 5927 | break; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 5928 | } |
| 5929 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 5930 | LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list); |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 5931 | |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 5932 | if (curproxy->uri_auth->auth_realm) { |
| 5933 | free(curproxy->uri_auth->auth_realm); |
| 5934 | curproxy->uri_auth->auth_realm = NULL; |
| 5935 | } |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 5936 | |
| 5937 | curproxy->uri_auth->flags |= ST_CONVDONE; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 5938 | } |
| 5939 | out_uri_auth_compat: |
| 5940 | |
Krzysztof Piotr Oledzki | f9423ae | 2010-01-29 19:26:18 +0100 | [diff] [blame] | 5941 | cfgerr += acl_find_targets(curproxy); |
| 5942 | |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 5943 | if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) && |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 5944 | (((curproxy->cap & PR_CAP_FE) && !curproxy->timeout.client) || |
Willy Tarreau | d825eef | 2007-05-12 22:35:00 +0200 | [diff] [blame] | 5945 | ((curproxy->cap & PR_CAP_BE) && (curproxy->srv) && |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 5946 | (!curproxy->timeout.connect || !curproxy->timeout.server)))) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5947 | Warning("config : missing timeouts for %s '%s'.\n" |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 5948 | " | While not properly invalid, you will certainly encounter various problems\n" |
| 5949 | " | with such a configuration. To fix this, please ensure that all following\n" |
Willy Tarreau | 0f68eac | 2008-01-20 23:25:06 +0100 | [diff] [blame] | 5950 | " | timeouts are set to a non-zero value: 'client', 'connect', 'server'.\n", |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5951 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 5952 | err_code |= ERR_WARN; |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 5953 | } |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 5954 | |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 5955 | /* Historically, the tarpit and queue timeouts were inherited from contimeout. |
| 5956 | * We must still support older configurations, so let's find out whether those |
| 5957 | * parameters have been set or must be copied from contimeouts. |
| 5958 | */ |
| 5959 | if (curproxy != &defproxy) { |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 5960 | if (!curproxy->timeout.tarpit || |
| 5961 | curproxy->timeout.tarpit == defproxy.timeout.tarpit) { |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 5962 | /* tarpit timeout not set. We search in the following order: |
| 5963 | * default.tarpit, curr.connect, default.connect. |
| 5964 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 5965 | if (defproxy.timeout.tarpit) |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 5966 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 5967 | else if (curproxy->timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 5968 | curproxy->timeout.tarpit = curproxy->timeout.connect; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 5969 | else if (defproxy.timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 5970 | curproxy->timeout.tarpit = defproxy.timeout.connect; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 5971 | } |
| 5972 | if ((curproxy->cap & PR_CAP_BE) && |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 5973 | (!curproxy->timeout.queue || |
| 5974 | curproxy->timeout.queue == defproxy.timeout.queue)) { |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 5975 | /* queue timeout not set. We search in the following order: |
| 5976 | * default.queue, curr.connect, default.connect. |
| 5977 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 5978 | if (defproxy.timeout.queue) |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 5979 | curproxy->timeout.queue = defproxy.timeout.queue; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 5980 | else if (curproxy->timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 5981 | curproxy->timeout.queue = curproxy->timeout.connect; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 5982 | else if (defproxy.timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 5983 | curproxy->timeout.queue = defproxy.timeout.connect; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 5984 | } |
| 5985 | } |
| 5986 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 5987 | if ((curproxy->options2 & PR_O2_CHK_ANY) == PR_O2_SSL3_CHK) { |
Willy Tarreau | 137325d | 2010-02-01 16:38:17 +0100 | [diff] [blame] | 5988 | curproxy->check_len = sizeof(sslv3_client_hello_pkt) - 1; |
| 5989 | curproxy->check_req = (char *)malloc(curproxy->check_len); |
| 5990 | memcpy(curproxy->check_req, sslv3_client_hello_pkt, curproxy->check_len); |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 5991 | } |
| 5992 | |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 5993 | /* The small pools required for the capture lists */ |
| 5994 | if (curproxy->nb_req_cap) |
| 5995 | curproxy->req_cap_pool = create_pool("ptrcap", |
| 5996 | curproxy->nb_req_cap * sizeof(char *), |
| 5997 | MEM_F_SHARED); |
| 5998 | if (curproxy->nb_rsp_cap) |
| 5999 | curproxy->rsp_cap_pool = create_pool("ptrcap", |
| 6000 | curproxy->nb_rsp_cap * sizeof(char *), |
| 6001 | MEM_F_SHARED); |
| 6002 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6003 | /* first, we will invert the servers list order */ |
| 6004 | newsrv = NULL; |
| 6005 | while (curproxy->srv) { |
| 6006 | struct server *next; |
| 6007 | |
| 6008 | next = curproxy->srv->next; |
| 6009 | curproxy->srv->next = newsrv; |
| 6010 | newsrv = curproxy->srv; |
| 6011 | if (!next) |
| 6012 | break; |
| 6013 | curproxy->srv = next; |
| 6014 | } |
| 6015 | |
Willy Tarreau | dd70165 | 2010-05-25 23:03:02 +0200 | [diff] [blame] | 6016 | /* assign automatic UIDs to servers which don't have one yet */ |
| 6017 | next_id = 1; |
| 6018 | newsrv = curproxy->srv; |
| 6019 | while (newsrv != NULL) { |
| 6020 | if (!newsrv->puid) { |
| 6021 | /* server ID not set, use automatic numbering with first |
| 6022 | * spare entry starting with next_svid. |
| 6023 | */ |
| 6024 | next_id = get_next_id(&curproxy->conf.used_server_id, next_id); |
| 6025 | newsrv->conf.id.key = newsrv->puid = next_id; |
| 6026 | eb32_insert(&curproxy->conf.used_server_id, &newsrv->conf.id); |
| 6027 | } |
| 6028 | next_id++; |
| 6029 | newsrv = newsrv->next; |
| 6030 | } |
| 6031 | |
Willy Tarreau | 2069704 | 2007-11-15 23:26:18 +0100 | [diff] [blame] | 6032 | curproxy->lbprm.wmult = 1; /* default weight multiplier */ |
Willy Tarreau | 5dc2fa6 | 2007-11-19 19:10:18 +0100 | [diff] [blame] | 6033 | curproxy->lbprm.wdiv = 1; /* default weight divider */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6034 | |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6035 | /* We have to initialize the server lookup mechanism depending |
| 6036 | * on what LB algorithm was choosen. |
| 6037 | */ |
| 6038 | |
| 6039 | curproxy->lbprm.algo &= ~(BE_LB_LKUP | BE_LB_PROP_DYN); |
| 6040 | switch (curproxy->lbprm.algo & BE_LB_KIND) { |
| 6041 | case BE_LB_KIND_RR: |
Willy Tarreau | 9757a38 | 2009-10-03 12:56:50 +0200 | [diff] [blame] | 6042 | if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_RR_STATIC) { |
| 6043 | curproxy->lbprm.algo |= BE_LB_LKUP_MAP; |
| 6044 | init_server_map(curproxy); |
| 6045 | } else { |
| 6046 | curproxy->lbprm.algo |= BE_LB_LKUP_RRTREE | BE_LB_PROP_DYN; |
| 6047 | fwrr_init_server_groups(curproxy); |
| 6048 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6049 | break; |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 6050 | |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6051 | case BE_LB_KIND_LC: |
| 6052 | curproxy->lbprm.algo |= BE_LB_LKUP_LCTREE | BE_LB_PROP_DYN; |
Willy Tarreau | 5140623 | 2008-03-10 22:04:20 +0100 | [diff] [blame] | 6053 | fwlc_init_server_tree(curproxy); |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6054 | break; |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 6055 | |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6056 | case BE_LB_KIND_HI: |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 6057 | if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS) { |
| 6058 | curproxy->lbprm.algo |= BE_LB_LKUP_CHTREE | BE_LB_PROP_DYN; |
| 6059 | chash_init_server_tree(curproxy); |
| 6060 | } else { |
| 6061 | curproxy->lbprm.algo |= BE_LB_LKUP_MAP; |
| 6062 | init_server_map(curproxy); |
| 6063 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6064 | break; |
| 6065 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6066 | |
| 6067 | if (curproxy->options & PR_O_LOGASAP) |
| 6068 | curproxy->to_log &= ~LW_BYTES; |
| 6069 | |
Willy Tarreau | e7ded1f | 2009-08-09 10:11:45 +0200 | [diff] [blame] | 6070 | if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) && |
| 6071 | (curproxy->cap & PR_CAP_FE) && curproxy->to_log && curproxy->logfac1 < 0) { |
| 6072 | Warning("config : log format ignored for %s '%s' since it has no log address.\n", |
| 6073 | proxy_type_str(curproxy), curproxy->id); |
| 6074 | err_code |= ERR_WARN; |
| 6075 | } |
| 6076 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 6077 | if (curproxy->mode != PR_MODE_HTTP) { |
| 6078 | int optnum; |
| 6079 | |
| 6080 | if (curproxy->options & PR_O_COOK_ANY) { |
| 6081 | Warning("config : 'cookie' statement ignored for %s '%s' as it requires HTTP mode.\n", |
| 6082 | proxy_type_str(curproxy), curproxy->id); |
| 6083 | err_code |= ERR_WARN; |
| 6084 | } |
| 6085 | |
| 6086 | if (curproxy->uri_auth) { |
| 6087 | Warning("config : 'stats' statement ignored for %s '%s' as it requires HTTP mode.\n", |
| 6088 | proxy_type_str(curproxy), curproxy->id); |
| 6089 | err_code |= ERR_WARN; |
| 6090 | curproxy->uri_auth = NULL; |
| 6091 | } |
| 6092 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 6093 | if (curproxy->options & (PR_O_FWDFOR | PR_O_FF_ALWAYS)) { |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 6094 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6095 | "forwardfor", proxy_type_str(curproxy), curproxy->id); |
| 6096 | err_code |= ERR_WARN; |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 6097 | curproxy->options &= ~(PR_O_FWDFOR | PR_O_FF_ALWAYS); |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 6098 | } |
| 6099 | |
| 6100 | if (curproxy->options & PR_O_ORGTO) { |
| 6101 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6102 | "originalto", proxy_type_str(curproxy), curproxy->id); |
| 6103 | err_code |= ERR_WARN; |
| 6104 | curproxy->options &= ~PR_O_ORGTO; |
| 6105 | } |
| 6106 | |
| 6107 | for (optnum = 0; cfg_opts[optnum].name; optnum++) { |
| 6108 | if (cfg_opts[optnum].mode == PR_MODE_HTTP && |
| 6109 | (curproxy->cap & cfg_opts[optnum].cap) && |
| 6110 | (curproxy->options & cfg_opts[optnum].val)) { |
| 6111 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6112 | cfg_opts[optnum].name, proxy_type_str(curproxy), curproxy->id); |
| 6113 | err_code |= ERR_WARN; |
| 6114 | curproxy->options &= ~cfg_opts[optnum].val; |
| 6115 | } |
| 6116 | } |
| 6117 | |
| 6118 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) { |
| 6119 | if (cfg_opts2[optnum].mode == PR_MODE_HTTP && |
| 6120 | (curproxy->cap & cfg_opts2[optnum].cap) && |
| 6121 | (curproxy->options2 & cfg_opts2[optnum].val)) { |
| 6122 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6123 | cfg_opts2[optnum].name, proxy_type_str(curproxy), curproxy->id); |
| 6124 | err_code |= ERR_WARN; |
| 6125 | curproxy->options2 &= ~cfg_opts2[optnum].val; |
| 6126 | } |
| 6127 | } |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6128 | |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 6129 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6130 | if (curproxy->bind_hdr_occ) { |
| 6131 | curproxy->bind_hdr_occ = 0; |
| 6132 | Warning("config : %s '%s' : ignoring use of header %s as source IP in non-HTTP mode.\n", |
| 6133 | proxy_type_str(curproxy), curproxy->id, curproxy->bind_hdr_name); |
| 6134 | err_code |= ERR_WARN; |
| 6135 | } |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 6136 | #endif |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 6137 | } |
| 6138 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6139 | /* |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 6140 | * ensure that we're not cross-dressing a TCP server into HTTP. |
| 6141 | */ |
| 6142 | newsrv = curproxy->srv; |
| 6143 | while (newsrv != NULL) { |
| 6144 | if ((curproxy->mode != PR_MODE_HTTP) && (newsrv->rdr_len || newsrv->cklen)) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6145 | Alert("config : %s '%s' : server cannot have cookie or redirect prefix in non-HTTP mode.\n", |
| 6146 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6147 | cfgerr++; |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 6148 | } |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6149 | |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 6150 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6151 | if (curproxy->mode != PR_MODE_HTTP && newsrv->bind_hdr_occ) { |
| 6152 | newsrv->bind_hdr_occ = 0; |
| 6153 | Warning("config : %s '%s' : server %s cannot use header %s as source IP in non-HTTP mode.\n", |
| 6154 | proxy_type_str(curproxy), curproxy->id, newsrv->id, newsrv->bind_hdr_name); |
| 6155 | err_code |= ERR_WARN; |
| 6156 | } |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 6157 | #endif |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 6158 | newsrv = newsrv->next; |
| 6159 | } |
| 6160 | |
| 6161 | /* |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6162 | * If this server supports a maxconn parameter, it needs a dedicated |
| 6163 | * tasks to fill the emptied slots when a connection leaves. |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 6164 | * Also, resolve deferred tracking dependency if needed. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6165 | */ |
| 6166 | newsrv = curproxy->srv; |
| 6167 | while (newsrv != NULL) { |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 6168 | if (newsrv->minconn > newsrv->maxconn) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6169 | /* Only 'minconn' was specified, or it was higher than or equal |
| 6170 | * to 'maxconn'. Let's turn this into maxconn and clean it, as |
| 6171 | * this will avoid further useless expensive computations. |
| 6172 | */ |
| 6173 | newsrv->maxconn = newsrv->minconn; |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 6174 | } else if (newsrv->maxconn && !newsrv->minconn) { |
| 6175 | /* minconn was not specified, so we set it to maxconn */ |
| 6176 | newsrv->minconn = newsrv->maxconn; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6177 | } |
| 6178 | |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 6179 | if (newsrv->trackit) { |
| 6180 | struct proxy *px; |
| 6181 | struct server *srv; |
| 6182 | char *pname, *sname; |
| 6183 | |
| 6184 | pname = newsrv->trackit; |
| 6185 | sname = strrchr(pname, '/'); |
| 6186 | |
| 6187 | if (sname) |
| 6188 | *sname++ = '\0'; |
| 6189 | else { |
| 6190 | sname = pname; |
| 6191 | pname = NULL; |
| 6192 | } |
| 6193 | |
| 6194 | if (pname) { |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 6195 | px = findproxy(pname, PR_CAP_BE); |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 6196 | if (!px) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6197 | Alert("config : %s '%s', server '%s': unable to find required proxy '%s' for tracking.\n", |
| 6198 | proxy_type_str(curproxy), curproxy->id, |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 6199 | newsrv->id, pname); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6200 | cfgerr++; |
| 6201 | goto next_srv; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 6202 | } |
| 6203 | } else |
| 6204 | px = curproxy; |
| 6205 | |
| 6206 | srv = findserver(px, sname); |
| 6207 | if (!srv) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6208 | Alert("config : %s '%s', server '%s': unable to find required server '%s' for tracking.\n", |
| 6209 | proxy_type_str(curproxy), curproxy->id, |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 6210 | newsrv->id, sname); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6211 | cfgerr++; |
| 6212 | goto next_srv; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 6213 | } |
| 6214 | |
| 6215 | if (!(srv->state & SRV_CHECKED)) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6216 | Alert("config : %s '%s', server '%s': unable to use %s/%s for " |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 6217 | "tracking as it does not have checks enabled.\n", |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6218 | proxy_type_str(curproxy), curproxy->id, |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 6219 | newsrv->id, px->id, srv->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6220 | cfgerr++; |
| 6221 | goto next_srv; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 6222 | } |
| 6223 | |
| 6224 | if (curproxy != px && |
| 6225 | (curproxy->options & PR_O_DISABLE404) != (px->options & PR_O_DISABLE404)) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6226 | Alert("config : %s '%s', server '%s': unable to use %s/%s for" |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 6227 | "tracking: disable-on-404 option inconsistency.\n", |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6228 | proxy_type_str(curproxy), curproxy->id, |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 6229 | newsrv->id, px->id, srv->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6230 | cfgerr++; |
| 6231 | goto next_srv; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 6232 | } |
| 6233 | |
| 6234 | newsrv->tracked = srv; |
| 6235 | newsrv->tracknext = srv->tracknext; |
| 6236 | srv->tracknext = newsrv; |
| 6237 | |
| 6238 | free(newsrv->trackit); |
| 6239 | } |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6240 | next_srv: |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6241 | newsrv = newsrv->next; |
| 6242 | } |
| 6243 | |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6244 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 6245 | curproxy->accept = frontend_accept; |
| 6246 | |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6247 | if (curproxy->tcp_req.inspect_delay || |
| 6248 | !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules)) |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 6249 | curproxy->fe_req_ana |= AN_REQ_INSPECT_FE; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6250 | |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 6251 | if (curproxy->mode == PR_MODE_HTTP) { |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6252 | curproxy->fe_req_ana |= AN_REQ_WAIT_HTTP | AN_REQ_HTTP_PROCESS_FE; |
Willy Tarreau | b37c27e | 2009-10-18 22:53:08 +0200 | [diff] [blame] | 6253 | curproxy->fe_rsp_ana |= AN_RES_WAIT_HTTP | AN_RES_HTTP_PROCESS_FE; |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 6254 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6255 | |
| 6256 | /* both TCP and HTTP must check switching rules */ |
| 6257 | curproxy->fe_req_ana |= AN_REQ_SWITCHING_RULES; |
| 6258 | } |
| 6259 | |
| 6260 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 6261 | if (curproxy->tcp_req.inspect_delay || |
| 6262 | !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules)) |
| 6263 | curproxy->be_req_ana |= AN_REQ_INSPECT_BE; |
| 6264 | |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 6265 | if (!LIST_ISEMPTY(&curproxy->tcp_rep.inspect_rules)) |
| 6266 | curproxy->be_rsp_ana |= AN_RES_INSPECT; |
| 6267 | |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 6268 | if (curproxy->mode == PR_MODE_HTTP) { |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6269 | curproxy->be_req_ana |= AN_REQ_WAIT_HTTP | AN_REQ_HTTP_INNER | AN_REQ_HTTP_PROCESS_BE; |
Willy Tarreau | b37c27e | 2009-10-18 22:53:08 +0200 | [diff] [blame] | 6270 | curproxy->be_rsp_ana |= AN_RES_WAIT_HTTP | AN_RES_HTTP_PROCESS_BE; |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 6271 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6272 | |
| 6273 | /* If the backend does requires RDP cookie persistence, we have to |
| 6274 | * enable the corresponding analyser. |
| 6275 | */ |
| 6276 | if (curproxy->options2 & PR_O2_RDPC_PRST) |
| 6277 | curproxy->be_req_ana |= AN_REQ_PRST_RDP_COOKIE; |
| 6278 | } |
| 6279 | |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 6280 | listener = NULL; |
| 6281 | while (curproxy->listen) { |
| 6282 | struct listener *next; |
| 6283 | |
| 6284 | next = curproxy->listen->next; |
| 6285 | curproxy->listen->next = listener; |
| 6286 | listener = curproxy->listen; |
| 6287 | |
| 6288 | if (!next) |
| 6289 | break; |
| 6290 | |
| 6291 | curproxy->listen = next; |
| 6292 | } |
| 6293 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 6294 | /* adjust this proxy's listeners */ |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6295 | next_id = 1; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 6296 | listener = curproxy->listen; |
| 6297 | while (listener) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6298 | if (!listener->luid) { |
| 6299 | /* listener ID not set, use automatic numbering with first |
| 6300 | * spare entry starting with next_luid. |
| 6301 | */ |
| 6302 | next_id = get_next_id(&curproxy->conf.used_listener_id, next_id); |
| 6303 | listener->conf.id.key = listener->luid = next_id; |
| 6304 | eb32_insert(&curproxy->conf.used_listener_id, &listener->conf.id); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6305 | } |
Krzysztof Piotr Oledzki | df5cb9f | 2010-02-05 20:58:27 +0100 | [diff] [blame] | 6306 | next_id++; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6307 | |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 6308 | /* enable separate counters */ |
| 6309 | if (curproxy->options2 & PR_O2_SOCKSTAT) { |
| 6310 | listener->counters = (struct licounters *)calloc(1, sizeof(struct licounters)); |
| 6311 | if (!listener->name) { |
| 6312 | sprintf(trash, "sock-%d", listener->luid); |
| 6313 | listener->name = strdup(trash); |
| 6314 | } |
| 6315 | } |
| 6316 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 6317 | if (curproxy->options & PR_O_TCP_NOLING) |
| 6318 | listener->options |= LI_O_NOLINGER; |
| 6319 | listener->maxconn = curproxy->maxconn; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 6320 | listener->backlog = curproxy->backlog; |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6321 | listener->timeout = &curproxy->timeout.client; |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 6322 | listener->accept = session_accept; |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 6323 | listener->frontend = curproxy; |
Willy Tarreau | 3bc1377 | 2008-12-07 11:50:35 +0100 | [diff] [blame] | 6324 | listener->handler = process_session; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6325 | listener->analysers |= curproxy->fe_req_ana; |
Willy Tarreau | 3bc1377 | 2008-12-07 11:50:35 +0100 | [diff] [blame] | 6326 | |
Willy Tarreau | 8a95691 | 2010-10-15 14:27:08 +0200 | [diff] [blame] | 6327 | if (listener->options & LI_O_ACC_PROXY) |
| 6328 | listener->analysers |= AN_REQ_DECODE_PROXY; |
| 6329 | |
Willy Tarreau | a5c0ab2 | 2010-05-31 10:30:33 +0200 | [diff] [blame] | 6330 | if (!LIST_ISEMPTY(&curproxy->tcp_req.l4_rules)) |
| 6331 | listener->options |= LI_O_TCP_RULES; |
| 6332 | |
Willy Tarreau | de3041d | 2010-05-31 10:56:17 +0200 | [diff] [blame] | 6333 | if (curproxy->mon_mask.s_addr) |
| 6334 | listener->options |= LI_O_CHK_MONNET; |
| 6335 | |
Willy Tarreau | 9ea05a7 | 2009-06-14 12:07:01 +0200 | [diff] [blame] | 6336 | /* smart accept mode is automatic in HTTP mode */ |
| 6337 | if ((curproxy->options2 & PR_O2_SMARTACC) || |
| 6338 | (curproxy->mode == PR_MODE_HTTP && |
| 6339 | !(curproxy->no_options2 & PR_O2_SMARTACC))) |
| 6340 | listener->options |= LI_O_NOQUICKACK; |
| 6341 | |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 6342 | /* We want the use_backend and default_backend rules to apply */ |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 6343 | listener = listener->next; |
| 6344 | } |
| 6345 | |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 6346 | /* Check multi-process mode compatibility for the current proxy */ |
| 6347 | if (global.nbproc > 1) { |
| 6348 | int nbproc = 0; |
| 6349 | if (curproxy->bind_proc) { |
| 6350 | int proc; |
| 6351 | for (proc = 0; proc < global.nbproc; proc++) { |
| 6352 | if (curproxy->bind_proc & (1 << proc)) { |
| 6353 | nbproc++; |
| 6354 | } |
| 6355 | } |
| 6356 | } else { |
| 6357 | nbproc = global.nbproc; |
| 6358 | } |
| 6359 | if (curproxy->table.peers.name) { |
| 6360 | Alert("Proxy '%s': peers can't be used in multi-process mode (nbproc > 1).\n", |
| 6361 | curproxy->id); |
| 6362 | cfgerr++; |
| 6363 | } |
| 6364 | if (nbproc > 1) { |
| 6365 | if (curproxy->uri_auth) { |
| 6366 | Warning("Proxy '%s': in multi-process mode, stats will be limited to process assigned to the current request.\n", |
| 6367 | curproxy->id); |
| 6368 | if (!LIST_ISEMPTY(&curproxy->uri_auth->admin_rules)) { |
| 6369 | Warning("Proxy '%s': stats admin will not work correctly in multi-process mode.\n", |
| 6370 | curproxy->id); |
| 6371 | } |
| 6372 | } |
| 6373 | if (curproxy->appsession_name) { |
| 6374 | Warning("Proxy '%s': appsession will not work correctly in multi-process mode.\n", |
| 6375 | curproxy->id); |
| 6376 | } |
| 6377 | if (!LIST_ISEMPTY(&curproxy->sticking_rules)) { |
| 6378 | Warning("Proxy '%s': sticking rules will not work correctly in multi-process mode.\n", |
| 6379 | curproxy->id); |
| 6380 | } |
| 6381 | } |
| 6382 | } |
Willy Tarreau | 918ff60 | 2011-07-25 16:33:49 +0200 | [diff] [blame] | 6383 | |
| 6384 | /* create the task associated with the proxy */ |
| 6385 | curproxy->task = task_new(); |
| 6386 | if (curproxy->task) { |
| 6387 | curproxy->task->context = curproxy; |
| 6388 | curproxy->task->process = manage_proxy; |
| 6389 | /* no need to queue, it will be done automatically if some |
| 6390 | * listener gets limited. |
| 6391 | */ |
| 6392 | curproxy->task->expire = TICK_ETERNITY; |
| 6393 | } else { |
| 6394 | Alert("Proxy '%s': no more memory when trying to allocate the management task\n", |
| 6395 | curproxy->id); |
| 6396 | cfgerr++; |
| 6397 | } |
| 6398 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6399 | curproxy = curproxy->next; |
| 6400 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 6401 | |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 6402 | /* Check multi-process mode compatibility */ |
| 6403 | if (global.nbproc > 1) { |
| 6404 | if (global.stats_fe) { |
| 6405 | Warning("stats socket will not work correctly in multi-process mode (nbproc > 1).\n"); |
| 6406 | } |
| 6407 | } |
| 6408 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6409 | for (curuserlist = userlist; curuserlist; curuserlist = curuserlist->next) { |
| 6410 | struct auth_users *curuser; |
| 6411 | int g; |
| 6412 | |
| 6413 | for (curuser = curuserlist->users; curuser; curuser = curuser->next) { |
| 6414 | unsigned int group_mask = 0; |
| 6415 | char *group = NULL; |
| 6416 | |
Willy Tarreau | b4c06b7 | 2010-02-02 11:28:20 +0100 | [diff] [blame] | 6417 | if (!curuser->u.groups) |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6418 | continue; |
| 6419 | |
Willy Tarreau | b4c06b7 | 2010-02-02 11:28:20 +0100 | [diff] [blame] | 6420 | while ((group = strtok(group?NULL:curuser->u.groups, ","))) { |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6421 | |
| 6422 | for (g = 0; g < curuserlist->grpcnt; g++) |
| 6423 | if (!strcmp(curuserlist->groups[g], group)) |
| 6424 | break; |
| 6425 | |
| 6426 | if (g == curuserlist->grpcnt) { |
| 6427 | Alert("userlist '%s': no such group '%s' specified in user '%s'\n", |
| 6428 | curuserlist->name, group, curuser->user); |
| 6429 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6430 | goto out; |
| 6431 | } |
| 6432 | |
| 6433 | group_mask |= (1 << g); |
| 6434 | } |
| 6435 | |
Willy Tarreau | b4c06b7 | 2010-02-02 11:28:20 +0100 | [diff] [blame] | 6436 | free(curuser->u.groups); |
| 6437 | curuser->u.group_mask = group_mask; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6438 | } |
| 6439 | |
| 6440 | for (g = 0; g < curuserlist->grpcnt; g++) { |
| 6441 | char *user = NULL; |
| 6442 | |
| 6443 | if (!curuserlist->groupusers[g]) |
| 6444 | continue; |
| 6445 | |
| 6446 | while ((user = strtok(user?NULL:curuserlist->groupusers[g], ","))) { |
| 6447 | for (curuser = curuserlist->users; curuser; curuser = curuser->next) |
| 6448 | if (!strcmp(curuser->user, user)) |
| 6449 | break; |
| 6450 | |
| 6451 | if (!curuser) { |
| 6452 | Alert("userlist '%s': no such user '%s' specified in group '%s'\n", |
| 6453 | curuserlist->name, user, curuserlist->groups[g]); |
| 6454 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6455 | goto out; |
| 6456 | } |
| 6457 | |
Willy Tarreau | b4c06b7 | 2010-02-02 11:28:20 +0100 | [diff] [blame] | 6458 | curuser->u.group_mask |= (1 << g); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6459 | } |
| 6460 | |
| 6461 | free(curuserlist->groupusers[g]); |
| 6462 | } |
| 6463 | |
| 6464 | free(curuserlist->groupusers); |
| 6465 | |
| 6466 | #ifdef DEBUG_AUTH |
| 6467 | for (g = 0; g < curuserlist->grpcnt; g++) { |
| 6468 | fprintf(stderr, "group %s, id %d, mask %08X, users:", curuserlist->groups[g], g , 1 << g); |
| 6469 | |
| 6470 | for (curuser = curuserlist->users; curuser; curuser = curuser->next) { |
| 6471 | if (curuser->group_mask & (1 << g)) |
| 6472 | fprintf(stderr, " %s", curuser->user); |
| 6473 | } |
| 6474 | |
| 6475 | fprintf(stderr, "\n"); |
| 6476 | } |
| 6477 | #endif |
| 6478 | |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 6479 | } |
| 6480 | |
| 6481 | /* automatically compute fullconn if not set. We must not do it in the |
| 6482 | * loop above because cross-references are not yet fully resolved. |
| 6483 | */ |
| 6484 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 6485 | /* If <fullconn> is not set, let's set it to 10% of the sum of |
| 6486 | * the possible incoming frontend's maxconns. |
| 6487 | */ |
| 6488 | if (!curproxy->fullconn && (curproxy->cap & PR_CAP_BE)) { |
| 6489 | struct proxy *fe; |
| 6490 | int total = 0; |
| 6491 | |
| 6492 | /* sum up the number of maxconns of frontends which |
| 6493 | * reference this backend at least once or which are |
| 6494 | * the same one ('listen'). |
| 6495 | */ |
| 6496 | for (fe = proxy; fe; fe = fe->next) { |
| 6497 | struct switching_rule *rule; |
| 6498 | struct hdr_exp *exp; |
| 6499 | int found = 0; |
| 6500 | |
| 6501 | if (!(fe->cap & PR_CAP_FE)) |
| 6502 | continue; |
| 6503 | |
| 6504 | if (fe == curproxy) /* we're on a "listen" instance */ |
| 6505 | found = 1; |
| 6506 | |
| 6507 | if (fe->defbe.be == curproxy) /* "default_backend" */ |
| 6508 | found = 1; |
| 6509 | |
| 6510 | /* check if a "use_backend" rule matches */ |
| 6511 | if (!found) { |
| 6512 | list_for_each_entry(rule, &fe->switching_rules, list) { |
| 6513 | if (rule->be.backend == curproxy) { |
| 6514 | found = 1; |
| 6515 | break; |
| 6516 | } |
| 6517 | } |
| 6518 | } |
| 6519 | |
| 6520 | /* check if a "reqsetbe" rule matches */ |
| 6521 | for (exp = fe->req_exp; !found && exp; exp = exp->next) { |
| 6522 | if (exp->action == ACT_SETBE && |
| 6523 | (struct proxy *)exp->replace == curproxy) { |
| 6524 | found = 1; |
| 6525 | break; |
| 6526 | } |
| 6527 | } |
| 6528 | |
| 6529 | /* now we've checked all possible ways to reference a backend |
| 6530 | * from a frontend. |
| 6531 | */ |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 6532 | if (!found) |
| 6533 | continue; |
| 6534 | total += fe->maxconn; |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 6535 | } |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 6536 | /* we have the sum of the maxconns in <total>. We only |
| 6537 | * keep 10% of that sum to set the default fullconn, with |
| 6538 | * a hard minimum of 1 (to avoid a divide by zero). |
| 6539 | */ |
| 6540 | curproxy->fullconn = (total + 9) / 10; |
| 6541 | if (!curproxy->fullconn) |
| 6542 | curproxy->fullconn = 1; |
| 6543 | } |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6544 | } |
| 6545 | |
Willy Tarreau | 056f568 | 2010-06-06 15:51:11 +0200 | [diff] [blame] | 6546 | /* initialize stick-tables on backend capable proxies. This must not |
| 6547 | * be done earlier because the data size may be discovered while parsing |
| 6548 | * other proxies. |
| 6549 | */ |
| 6550 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) |
Willy Tarreau | c00cdc2 | 2010-06-06 16:48:26 +0200 | [diff] [blame] | 6551 | stktable_init(&curproxy->table); |
Willy Tarreau | 056f568 | 2010-06-06 15:51:11 +0200 | [diff] [blame] | 6552 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 6553 | /* |
| 6554 | * Recount currently required checks. |
| 6555 | */ |
| 6556 | |
| 6557 | for (curproxy=proxy; curproxy; curproxy=curproxy->next) { |
| 6558 | int optnum; |
| 6559 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 6560 | for (optnum = 0; cfg_opts[optnum].name; optnum++) |
| 6561 | if (curproxy->options & cfg_opts[optnum].val) |
| 6562 | global.last_checks |= cfg_opts[optnum].checks; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 6563 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 6564 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) |
| 6565 | if (curproxy->options2 & cfg_opts2[optnum].val) |
| 6566 | global.last_checks |= cfg_opts2[optnum].checks; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 6567 | } |
| 6568 | |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 6569 | if (peers) { |
| 6570 | struct peers *curpeers = peers, **last; |
| 6571 | struct peer *p, *pb; |
| 6572 | |
| 6573 | /* Remove all peers sections which don't have a valid listener. |
| 6574 | * This can happen when a peers section is never referenced and |
| 6575 | * does not contain a local peer. |
| 6576 | */ |
| 6577 | last = &peers; |
| 6578 | while (*last) { |
| 6579 | curpeers = *last; |
| 6580 | if (curpeers->peers_fe) { |
| 6581 | last = &curpeers->next; |
| 6582 | continue; |
| 6583 | } |
| 6584 | |
| 6585 | Warning("Removing incomplete section 'peers %s' (no peer named '%s').\n", |
| 6586 | curpeers->id, localpeer); |
| 6587 | |
| 6588 | p = curpeers->remote; |
| 6589 | while (p) { |
| 6590 | pb = p->next; |
| 6591 | free(p->id); |
| 6592 | free(p); |
| 6593 | p = pb; |
| 6594 | } |
| 6595 | |
| 6596 | /* Destroy and unlink this curpeers section. |
| 6597 | * Note: curpeers is backed up into *last. |
| 6598 | */ |
| 6599 | free(curpeers->id); |
| 6600 | curpeers = curpeers->next; |
| 6601 | free(*last); |
| 6602 | *last = curpeers; |
| 6603 | } |
| 6604 | } |
| 6605 | |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame^] | 6606 | if (!global.tune.max_http_hdr) |
| 6607 | global.tune.max_http_hdr = MAX_HTTP_HDR; |
| 6608 | |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 6609 | pool2_hdr_idx = create_pool("hdr_idx", |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame^] | 6610 | global.tune.max_http_hdr * sizeof(struct hdr_idx_elem), |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 6611 | MEM_F_SHARED); |
| 6612 | |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6613 | if (cfgerr > 0) |
| 6614 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6615 | out: |
| 6616 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6617 | } |
| 6618 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 6619 | /* |
| 6620 | * Registers the CFG keyword list <kwl> as a list of valid keywords for next |
| 6621 | * parsing sessions. |
| 6622 | */ |
| 6623 | void cfg_register_keywords(struct cfg_kw_list *kwl) |
| 6624 | { |
| 6625 | LIST_ADDQ(&cfg_keywords.list, &kwl->list); |
| 6626 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6627 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 6628 | /* |
| 6629 | * Unregisters the CFG keyword list <kwl> from the list of valid keywords. |
| 6630 | */ |
| 6631 | void cfg_unregister_keywords(struct cfg_kw_list *kwl) |
| 6632 | { |
| 6633 | LIST_DEL(&kwl->list); |
| 6634 | LIST_INIT(&kwl->list); |
| 6635 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6636 | |
| 6637 | /* |
| 6638 | * Local variables: |
| 6639 | * c-indent-level: 8 |
| 6640 | * c-basic-offset: 8 |
| 6641 | * End: |
| 6642 | */ |