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 | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 47 | #include <proto/lb_chash.h> |
Willy Tarreau | f89c187 | 2009-10-01 11:19:37 +0200 | [diff] [blame] | 48 | #include <proto/lb_fwlc.h> |
| 49 | #include <proto/lb_fwrr.h> |
| 50 | #include <proto/lb_map.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 51 | #include <proto/log.h> |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 52 | #include <proto/pattern.h> |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 53 | #include <proto/port_range.h> |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 54 | #include <proto/protocols.h> |
| 55 | #include <proto/proto_tcp.h> |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 56 | #include <proto/proto_uxst.h> |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 57 | #include <proto/proto_http.h> |
Willy Tarreau | 2b5652f | 2006-12-31 17:46:05 +0100 | [diff] [blame] | 58 | #include <proto/proxy.h> |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 59 | #include <proto/peers.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 60 | #include <proto/server.h> |
Willy Tarreau | 3bc1377 | 2008-12-07 11:50:35 +0100 | [diff] [blame] | 61 | #include <proto/session.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 62 | #include <proto/task.h> |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 63 | #include <proto/stick_table.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 64 | |
| 65 | |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 66 | /* This is the SSLv3 CLIENT HELLO packet used in conjunction with the |
| 67 | * ssl-hello-chk option to ensure that the remote server speaks SSL. |
| 68 | * |
| 69 | * Check RFC 2246 (TLSv1.0) sections A.3 and A.4 for details. |
| 70 | */ |
| 71 | const char sslv3_client_hello_pkt[] = { |
| 72 | "\x16" /* ContentType : 0x16 = Hanshake */ |
| 73 | "\x03\x00" /* ProtocolVersion : 0x0300 = SSLv3 */ |
| 74 | "\x00\x79" /* ContentLength : 0x79 bytes after this one */ |
| 75 | "\x01" /* HanshakeType : 0x01 = CLIENT HELLO */ |
| 76 | "\x00\x00\x75" /* HandshakeLength : 0x75 bytes after this one */ |
| 77 | "\x03\x00" /* Hello Version : 0x0300 = v3 */ |
| 78 | "\x00\x00\x00\x00" /* Unix GMT Time (s) : filled with <now> (@0x0B) */ |
| 79 | "HAPROXYSSLCHK\nHAPROXYSSLCHK\n" /* Random : must be exactly 28 bytes */ |
| 80 | "\x00" /* Session ID length : empty (no session ID) */ |
| 81 | "\x00\x4E" /* Cipher Suite Length : 78 bytes after this one */ |
| 82 | "\x00\x01" "\x00\x02" "\x00\x03" "\x00\x04" /* 39 most common ciphers : */ |
| 83 | "\x00\x05" "\x00\x06" "\x00\x07" "\x00\x08" /* 0x01...0x1B, 0x2F...0x3A */ |
| 84 | "\x00\x09" "\x00\x0A" "\x00\x0B" "\x00\x0C" /* This covers RSA/DH, */ |
| 85 | "\x00\x0D" "\x00\x0E" "\x00\x0F" "\x00\x10" /* various bit lengths, */ |
| 86 | "\x00\x11" "\x00\x12" "\x00\x13" "\x00\x14" /* SHA1/MD5, DES/3DES/AES... */ |
| 87 | "\x00\x15" "\x00\x16" "\x00\x17" "\x00\x18" |
| 88 | "\x00\x19" "\x00\x1A" "\x00\x1B" "\x00\x2F" |
| 89 | "\x00\x30" "\x00\x31" "\x00\x32" "\x00\x33" |
| 90 | "\x00\x34" "\x00\x35" "\x00\x36" "\x00\x37" |
| 91 | "\x00\x38" "\x00\x39" "\x00\x3A" |
| 92 | "\x01" /* Compression Length : 0x01 = 1 byte for types */ |
| 93 | "\x00" /* Compression Type : 0x00 = NULL compression */ |
| 94 | }; |
| 95 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 96 | /* various keyword modifiers */ |
| 97 | enum kw_mod { |
| 98 | KWM_STD = 0, /* normal */ |
| 99 | KWM_NO, /* "no" prefixed before the keyword */ |
| 100 | KWM_DEF, /* "default" prefixed before the keyword */ |
| 101 | }; |
| 102 | |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 103 | /* 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] | 104 | struct cfg_opt { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 105 | const char *name; |
| 106 | unsigned int val; |
| 107 | unsigned int cap; |
Willy Tarreau | 4fee4e9 | 2007-01-06 21:09:17 +0100 | [diff] [blame] | 108 | unsigned int checks; |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 109 | unsigned int mode; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 110 | }; |
| 111 | |
| 112 | /* proxy->options */ |
| 113 | static const struct cfg_opt cfg_opts[] = |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 114 | { |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 115 | { "abortonclose", PR_O_ABRT_CLOSE, PR_CAP_BE, 0, 0 }, |
| 116 | { "allbackups", PR_O_USE_ALL_BK, PR_CAP_BE, 0, 0 }, |
| 117 | { "checkcache", PR_O_CHK_CACHE, PR_CAP_BE, 0, PR_MODE_HTTP }, |
| 118 | { "clitcpka", PR_O_TCP_CLI_KA, PR_CAP_FE, 0, 0 }, |
| 119 | { "contstats", PR_O_CONTSTATS, PR_CAP_FE, 0, 0 }, |
| 120 | { "dontlognull", PR_O_NULLNOLOG, PR_CAP_FE, 0, 0 }, |
| 121 | { "forceclose", PR_O_FORCE_CLO, PR_CAP_FE | PR_CAP_BE, 0, PR_MODE_HTTP }, |
| 122 | { "http_proxy", PR_O_HTTP_PROXY, PR_CAP_FE | PR_CAP_BE, 0, PR_MODE_HTTP }, |
| 123 | { "httpclose", PR_O_HTTP_CLOSE, PR_CAP_FE | PR_CAP_BE, 0, PR_MODE_HTTP }, |
| 124 | { "keepalive", PR_O_KEEPALIVE, PR_CAP_NONE, 0, PR_MODE_HTTP }, |
| 125 | { "http-server-close", PR_O_SERVER_CLO, PR_CAP_FE | PR_CAP_BE, 0, PR_MODE_HTTP }, |
| 126 | { "logasap", PR_O_LOGASAP, PR_CAP_FE, 0, 0 }, |
| 127 | { "nolinger", PR_O_TCP_NOLING, PR_CAP_FE | PR_CAP_BE, 0, 0 }, |
| 128 | { "persist", PR_O_PERSIST, PR_CAP_BE, 0, 0 }, |
| 129 | { "redispatch", PR_O_REDISP, PR_CAP_BE, 0, 0 }, |
| 130 | { "srvtcpka", PR_O_TCP_SRV_KA, PR_CAP_BE, 0, 0 }, |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 131 | #ifdef TPROXY |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 132 | { "transparent", PR_O_TRANSP, PR_CAP_BE, 0, 0 }, |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 133 | #else |
| 134 | { "transparent", 0, 0, 0, 0 }, |
Willy Tarreau | 8f922fc | 2007-01-06 21:11:49 +0100 | [diff] [blame] | 135 | #endif |
| 136 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 137 | { NULL, 0, 0, 0, 0 } |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 138 | }; |
| 139 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 140 | /* proxy->options2 */ |
| 141 | static const struct cfg_opt cfg_opts2[] = |
| 142 | { |
| 143 | #ifdef CONFIG_HAP_LINUX_SPLICE |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 144 | { "splice-request", PR_O2_SPLIC_REQ, PR_CAP_FE|PR_CAP_BE, 0, 0 }, |
| 145 | { "splice-response", PR_O2_SPLIC_RTR, PR_CAP_FE|PR_CAP_BE, 0, 0 }, |
| 146 | { "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] | 147 | #else |
| 148 | { "splice-request", 0, 0, 0, 0 }, |
| 149 | { "splice-response", 0, 0, 0, 0 }, |
| 150 | { "splice-auto", 0, 0, 0, 0 }, |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 151 | #endif |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 152 | { "accept-invalid-http-request", PR_O2_REQBUG_OK, PR_CAP_FE, 0, PR_MODE_HTTP }, |
| 153 | { "accept-invalid-http-response", PR_O2_RSPBUG_OK, PR_CAP_BE, 0, PR_MODE_HTTP }, |
| 154 | { "dontlog-normal", PR_O2_NOLOGNORM, PR_CAP_FE, 0, 0 }, |
| 155 | { "log-separate-errors", PR_O2_LOGERRORS, PR_CAP_FE, 0, 0 }, |
| 156 | { "log-health-checks", PR_O2_LOGHCHKS, PR_CAP_BE, 0, 0 }, |
| 157 | { "socket-stats", PR_O2_SOCKSTAT, PR_CAP_FE, 0, 0 }, |
| 158 | { "tcp-smart-accept", PR_O2_SMARTACC, PR_CAP_FE, 0, 0 }, |
| 159 | { "tcp-smart-connect", PR_O2_SMARTCON, PR_CAP_BE, 0, 0 }, |
| 160 | { "independant-streams", PR_O2_INDEPSTR, PR_CAP_FE|PR_CAP_BE, 0, 0 }, |
| 161 | { "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] | 162 | { "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] | 163 | { "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] | 164 | { NULL, 0, 0, 0 } |
| 165 | }; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 166 | |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 167 | static char *cursection = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 168 | static struct proxy defproxy; /* fake proxy used to assign default values on all instances */ |
| 169 | int cfg_maxpconn = DEFAULT_MAXCONN; /* # of simultaneous connections per proxy (-N) */ |
Willy Tarreau | 5af24ef | 2009-03-15 15:23:16 +0100 | [diff] [blame] | 170 | int cfg_maxconn = 0; /* # of simultaneous connections, (-n) */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 171 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 172 | /* List head of all known configuration keywords */ |
| 173 | static struct cfg_kw_list cfg_keywords = { |
| 174 | .list = LIST_HEAD_INIT(cfg_keywords.list) |
| 175 | }; |
| 176 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 177 | /* |
| 178 | * converts <str> to a list of listeners which are dynamically allocated. |
| 179 | * The format is "{addr|'*'}:port[-end][,{addr|'*'}:port[-end]]*", where : |
| 180 | * - <addr> can be empty or "*" to indicate INADDR_ANY ; |
| 181 | * - <port> is a numerical port from 1 to 65535 ; |
| 182 | * - <end> indicates to use the range from <port> to <end> instead (inclusive). |
| 183 | * 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] | 184 | * Function returns 1 for success or 0 if error. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 185 | */ |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 186 | 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] | 187 | { |
| 188 | struct listener *l; |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 189 | char *next, *dupstr; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 190 | int port, end; |
| 191 | |
| 192 | next = dupstr = strdup(str); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 193 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 194 | while (next && *next) { |
| 195 | struct sockaddr_storage ss; |
| 196 | |
| 197 | str = next; |
| 198 | /* 1) look for the end of the first address */ |
Krzysztof Piotr Oledzki | 52d522b | 2009-01-27 16:57:08 +0100 | [diff] [blame] | 199 | if ((next = strchr(str, ',')) != NULL) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 200 | *next++ = 0; |
| 201 | } |
| 202 | |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 203 | if (*str == '/') { |
| 204 | /* sun_path during a soft_stop rename is <unix_bind_prefix><path>.<pid>.<bak|tmp> */ |
| 205 | /* so compute max path */ |
| 206 | int prefix_path_len = global.unix_bind.prefix ? strlen(global.unix_bind.prefix) : 0; |
| 207 | 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] | 208 | |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 209 | if (strlen(str) > max_path_len) { |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 210 | Alert("parsing [%s:%d] : socket path '%s' too long (max %d)\n", |
| 211 | file, line, str, max_path_len); |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 212 | goto fail; |
| 213 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 214 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 215 | memset(&ss, 0, sizeof(ss)); |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 216 | ss.ss_family = AF_UNIX; |
| 217 | if (global.unix_bind.prefix) { |
| 218 | memcpy(((struct sockaddr_un *)&ss)->sun_path, global.unix_bind.prefix, prefix_path_len); |
| 219 | strcpy(((struct sockaddr_un *)&ss)->sun_path+prefix_path_len, str); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 220 | } |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 221 | else { |
| 222 | strcpy(((struct sockaddr_un *)&ss)->sun_path, str); |
| 223 | } |
| 224 | port = end = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 225 | } |
| 226 | else { |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 227 | struct sockaddr_storage *ss2; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 228 | |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 229 | ss2 = str2sa_range(str, &port, &end); |
| 230 | if (!ss2) { |
| 231 | Alert("parsing [%s:%d] : invalid listening address: '%s'\n", |
| 232 | file, line, str); |
| 233 | goto fail; |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 234 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 235 | |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 236 | if (!port) { |
| 237 | Alert("parsing [%s:%d] : missing port number: '%s'\n", |
| 238 | file, line, str); |
| 239 | goto fail; |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 240 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 241 | |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 242 | /* OK the address looks correct */ |
| 243 | ss = *ss2; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 244 | |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 245 | if (port < 1 || port > 65535) { |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 246 | Alert("parsing [%s:%d] : invalid port '%d' specified for address '%s'.\n", |
| 247 | file, line, port, str); |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 248 | goto fail; |
| 249 | } |
| 250 | |
| 251 | if (end < 1 || end > 65535) { |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 252 | Alert("parsing [%s:%d] : invalid port '%d' specified for address '%s'.\n", |
| 253 | file, line, end, str); |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 254 | goto fail; |
| 255 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | for (; port <= end; port++) { |
| 259 | l = (struct listener *)calloc(1, sizeof(struct listener)); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 260 | l->next = curproxy->listen; |
| 261 | curproxy->listen = l; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 262 | |
| 263 | l->fd = -1; |
| 264 | l->addr = ss; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 265 | l->state = LI_INIT; |
| 266 | |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 267 | if (ss.ss_family == AF_INET) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 268 | ((struct sockaddr_in *)(&l->addr))->sin_port = htons(port); |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 269 | tcpv4_add_listener(l); |
| 270 | } |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 271 | else if (ss.ss_family == AF_INET6) { |
| 272 | ((struct sockaddr_in6 *)(&l->addr))->sin6_port = htons(port); |
| 273 | tcpv6_add_listener(l); |
| 274 | } |
| 275 | else { |
| 276 | l->perm.ux.gid = l->perm.ux.uid = -1; |
| 277 | l->perm.ux.mode = 0; |
| 278 | uxst_add_listener(l); |
| 279 | } |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 280 | |
Willy Tarreau | af7ad00 | 2010-08-31 15:39:26 +0200 | [diff] [blame] | 281 | jobs++; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 282 | listeners++; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 283 | } /* end for(port) */ |
| 284 | } /* end while(next) */ |
| 285 | free(dupstr); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 286 | return 1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 287 | fail: |
| 288 | free(dupstr); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 289 | return 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 290 | } |
| 291 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 292 | /* |
| 293 | * Sends a warning if proxy <proxy> does not have at least one of the |
| 294 | * capabilities in <cap>. An optionnal <hint> may be added at the end |
| 295 | * of the warning to help the user. Returns 1 if a warning was emitted |
| 296 | * or 0 if the condition is valid. |
| 297 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 298 | 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] | 299 | { |
| 300 | char *msg; |
| 301 | |
| 302 | switch (cap) { |
| 303 | case PR_CAP_BE: msg = "no backend"; break; |
| 304 | case PR_CAP_FE: msg = "no frontend"; break; |
| 305 | case PR_CAP_RS: msg = "no ruleset"; break; |
| 306 | case PR_CAP_BE|PR_CAP_FE: msg = "neither frontend nor backend"; break; |
| 307 | default: msg = "not enough"; break; |
| 308 | } |
| 309 | |
| 310 | if (!(proxy->cap & cap)) { |
| 311 | 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] | 312 | file, line, arg, proxy_type_str(proxy), proxy->id, msg, hint ? hint : ""); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 313 | return 1; |
| 314 | } |
| 315 | return 0; |
| 316 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 317 | |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 318 | /* Report a warning if a rule is placed after a 'block' rule. |
| 319 | * Return 1 if the warning has been emitted, otherwise 0. |
| 320 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 321 | 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] | 322 | { |
| 323 | if (!LIST_ISEMPTY(&proxy->block_cond)) { |
| 324 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'block' rule will still be processed before.\n", |
| 325 | file, line, arg); |
| 326 | return 1; |
| 327 | } |
| 328 | return 0; |
| 329 | } |
| 330 | |
| 331 | /* Report a warning if a rule is placed after a reqrewrite rule. |
| 332 | * Return 1 if the warning has been emitted, otherwise 0. |
| 333 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 334 | 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] | 335 | { |
| 336 | if (proxy->req_exp) { |
| 337 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'reqxxx' rule will still be processed before.\n", |
| 338 | file, line, arg); |
| 339 | return 1; |
| 340 | } |
| 341 | return 0; |
| 342 | } |
| 343 | |
| 344 | /* Report a warning if a rule is placed after a reqadd rule. |
| 345 | * Return 1 if the warning has been emitted, otherwise 0. |
| 346 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 347 | 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] | 348 | { |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 349 | if (!LIST_ISEMPTY(&proxy->req_add)) { |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 350 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'reqadd' rule will still be processed before.\n", |
| 351 | file, line, arg); |
| 352 | return 1; |
| 353 | } |
| 354 | return 0; |
| 355 | } |
| 356 | |
| 357 | /* Report a warning if a rule is placed after a redirect rule. |
| 358 | * Return 1 if the warning has been emitted, otherwise 0. |
| 359 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 360 | 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] | 361 | { |
| 362 | if (!LIST_ISEMPTY(&proxy->redirect_rules)) { |
| 363 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'redirect' rule will still be processed before.\n", |
| 364 | file, line, arg); |
| 365 | return 1; |
| 366 | } |
| 367 | return 0; |
| 368 | } |
| 369 | |
| 370 | /* Report a warning if a rule is placed after a 'use_backend' rule. |
| 371 | * Return 1 if the warning has been emitted, otherwise 0. |
| 372 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 373 | 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] | 374 | { |
| 375 | if (!LIST_ISEMPTY(&proxy->switching_rules)) { |
| 376 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'use_backend' rule will still be processed before.\n", |
| 377 | file, line, arg); |
| 378 | return 1; |
| 379 | } |
| 380 | return 0; |
| 381 | } |
| 382 | |
| 383 | /* report a warning if a block rule is dangerously placed */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 384 | 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] | 385 | { |
| 386 | return warnif_rule_after_reqxxx(proxy, file, line, arg) || |
| 387 | warnif_rule_after_reqadd(proxy, file, line, arg) || |
| 388 | warnif_rule_after_redirect(proxy, file, line, arg) || |
| 389 | warnif_rule_after_use_backend(proxy, file, line, arg); |
| 390 | } |
| 391 | |
| 392 | /* report a warning if a reqxxx rule is dangerously placed */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 393 | 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] | 394 | { |
| 395 | return warnif_rule_after_reqadd(proxy, file, line, arg) || |
| 396 | warnif_rule_after_redirect(proxy, file, line, arg) || |
| 397 | warnif_rule_after_use_backend(proxy, file, line, arg); |
| 398 | } |
| 399 | |
| 400 | /* report a warning if a reqadd rule is dangerously placed */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 401 | 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] | 402 | { |
| 403 | return warnif_rule_after_redirect(proxy, file, line, arg) || |
| 404 | warnif_rule_after_use_backend(proxy, file, line, arg); |
| 405 | } |
| 406 | |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 407 | /* Report it if a request ACL condition uses some response-only parameters. It |
| 408 | * returns either 0 or ERR_WARN so that its result can be or'ed with err_code. |
| 409 | * Note that <cond> may be NULL and then will be ignored. |
| 410 | */ |
| 411 | static int warnif_cond_requires_resp(const struct acl_cond *cond, const char *file, int line) |
| 412 | { |
| 413 | struct acl *acl; |
| 414 | |
| 415 | if (!cond || !(cond->requires & ACL_USE_RTR_ANY)) |
| 416 | return 0; |
| 417 | |
| 418 | acl = cond_find_require(cond, ACL_USE_RTR_ANY); |
| 419 | Warning("parsing [%s:%d] : acl '%s' involves some response-only criteria which will be ignored.\n", |
| 420 | file, line, acl ? acl->name : "(unknown)"); |
| 421 | return ERR_WARN; |
| 422 | } |
| 423 | |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 424 | /* Report it if a request ACL condition uses some request-only volatile parameters. |
| 425 | * It returns either 0 or ERR_WARN so that its result can be or'ed with err_code. |
| 426 | * Note that <cond> may be NULL and then will be ignored. |
| 427 | */ |
| 428 | static int warnif_cond_requires_req(const struct acl_cond *cond, const char *file, int line) |
| 429 | { |
| 430 | struct acl *acl; |
| 431 | |
| 432 | if (!cond || !(cond->requires & ACL_USE_REQ_VOLATILE)) |
| 433 | return 0; |
| 434 | |
| 435 | acl = cond_find_require(cond, ACL_USE_REQ_VOLATILE); |
| 436 | Warning("parsing [%s:%d] : acl '%s' involves some volatile request-only criteria which will be ignored.\n", |
| 437 | file, line, acl ? acl->name : "(unknown)"); |
| 438 | return ERR_WARN; |
| 439 | } |
| 440 | |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 441 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 442 | /* |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 443 | * parse a line in a <global> section. Returns the error code, 0 if OK, or |
| 444 | * any combination of : |
| 445 | * - ERR_ABORT: must abort ASAP |
| 446 | * - ERR_FATAL: we can continue parsing but not start the service |
| 447 | * - ERR_WARN: a warning has been emitted |
| 448 | * - ERR_ALERT: an alert has been emitted |
| 449 | * Only the two first ones can stop processing, the two others are just |
| 450 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 451 | */ |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 452 | 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] | 453 | { |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 454 | int err_code = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 455 | |
| 456 | if (!strcmp(args[0], "global")) { /* new section */ |
| 457 | /* no option, nothing special to do */ |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 458 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 459 | } |
| 460 | else if (!strcmp(args[0], "daemon")) { |
| 461 | global.mode |= MODE_DAEMON; |
| 462 | } |
| 463 | else if (!strcmp(args[0], "debug")) { |
| 464 | global.mode |= MODE_DEBUG; |
| 465 | } |
| 466 | else if (!strcmp(args[0], "noepoll")) { |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 467 | global.tune.options &= ~GTUNE_USE_EPOLL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 468 | } |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 469 | else if (!strcmp(args[0], "nosepoll")) { |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 470 | global.tune.options &= ~GTUNE_USE_SEPOLL; |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 471 | } |
| 472 | else if (!strcmp(args[0], "nokqueue")) { |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 473 | global.tune.options &= ~GTUNE_USE_KQUEUE; |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 474 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 475 | else if (!strcmp(args[0], "nopoll")) { |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 476 | global.tune.options &= ~GTUNE_USE_POLL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 477 | } |
Willy Tarreau | 3ab68cf | 2009-01-25 16:03:28 +0100 | [diff] [blame] | 478 | else if (!strcmp(args[0], "nosplice")) { |
| 479 | global.tune.options &= ~GTUNE_USE_SPLICE; |
| 480 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 481 | else if (!strcmp(args[0], "quiet")) { |
| 482 | global.mode |= MODE_QUIET; |
| 483 | } |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 484 | else if (!strcmp(args[0], "tune.maxpollevents")) { |
| 485 | if (global.tune.maxpollevents != 0) { |
| 486 | 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] | 487 | err_code |= ERR_ALERT; |
| 488 | goto out; |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 489 | } |
| 490 | if (*(args[1]) == 0) { |
| 491 | 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] | 492 | err_code |= ERR_ALERT | ERR_FATAL; |
| 493 | goto out; |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 494 | } |
| 495 | global.tune.maxpollevents = atol(args[1]); |
| 496 | } |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 497 | else if (!strcmp(args[0], "tune.maxaccept")) { |
| 498 | if (global.tune.maxaccept != 0) { |
| 499 | 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] | 500 | err_code |= ERR_ALERT; |
| 501 | goto out; |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 502 | } |
| 503 | if (*(args[1]) == 0) { |
| 504 | 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] | 505 | err_code |= ERR_ALERT | ERR_FATAL; |
| 506 | goto out; |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 507 | } |
| 508 | global.tune.maxaccept = atol(args[1]); |
| 509 | } |
Willy Tarreau | 43961d5 | 2010-10-04 20:39:20 +0200 | [diff] [blame] | 510 | else if (!strcmp(args[0], "tune.chksize")) { |
| 511 | if (*(args[1]) == 0) { |
| 512 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 513 | err_code |= ERR_ALERT | ERR_FATAL; |
| 514 | goto out; |
| 515 | } |
| 516 | global.tune.chksize = atol(args[1]); |
| 517 | } |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 518 | else if (!strcmp(args[0], "tune.bufsize")) { |
| 519 | if (*(args[1]) == 0) { |
| 520 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 521 | err_code |= ERR_ALERT | ERR_FATAL; |
| 522 | goto out; |
| 523 | } |
| 524 | global.tune.bufsize = atol(args[1]); |
| 525 | if (global.tune.maxrewrite >= global.tune.bufsize / 2) |
| 526 | global.tune.maxrewrite = global.tune.bufsize / 2; |
| 527 | } |
| 528 | else if (!strcmp(args[0], "tune.maxrewrite")) { |
| 529 | if (*(args[1]) == 0) { |
| 530 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 531 | err_code |= ERR_ALERT | ERR_FATAL; |
| 532 | goto out; |
| 533 | } |
| 534 | global.tune.maxrewrite = atol(args[1]); |
| 535 | if (global.tune.maxrewrite >= global.tune.bufsize / 2) |
| 536 | global.tune.maxrewrite = global.tune.bufsize / 2; |
| 537 | } |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 538 | else if (!strcmp(args[0], "tune.rcvbuf.client")) { |
| 539 | if (global.tune.client_rcvbuf != 0) { |
| 540 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 541 | err_code |= ERR_ALERT; |
| 542 | goto out; |
| 543 | } |
| 544 | if (*(args[1]) == 0) { |
| 545 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 546 | err_code |= ERR_ALERT | ERR_FATAL; |
| 547 | goto out; |
| 548 | } |
| 549 | global.tune.client_rcvbuf = atol(args[1]); |
| 550 | } |
| 551 | else if (!strcmp(args[0], "tune.rcvbuf.server")) { |
| 552 | if (global.tune.server_rcvbuf != 0) { |
| 553 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 554 | err_code |= ERR_ALERT; |
| 555 | goto out; |
| 556 | } |
| 557 | if (*(args[1]) == 0) { |
| 558 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 559 | err_code |= ERR_ALERT | ERR_FATAL; |
| 560 | goto out; |
| 561 | } |
| 562 | global.tune.server_rcvbuf = atol(args[1]); |
| 563 | } |
| 564 | else if (!strcmp(args[0], "tune.sndbuf.client")) { |
| 565 | if (global.tune.client_sndbuf != 0) { |
| 566 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 567 | err_code |= ERR_ALERT; |
| 568 | goto out; |
| 569 | } |
| 570 | if (*(args[1]) == 0) { |
| 571 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 572 | err_code |= ERR_ALERT | ERR_FATAL; |
| 573 | goto out; |
| 574 | } |
| 575 | global.tune.client_sndbuf = atol(args[1]); |
| 576 | } |
| 577 | else if (!strcmp(args[0], "tune.sndbuf.server")) { |
| 578 | if (global.tune.server_sndbuf != 0) { |
| 579 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 580 | err_code |= ERR_ALERT; |
| 581 | goto out; |
| 582 | } |
| 583 | if (*(args[1]) == 0) { |
| 584 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 585 | err_code |= ERR_ALERT | ERR_FATAL; |
| 586 | goto out; |
| 587 | } |
| 588 | global.tune.server_sndbuf = atol(args[1]); |
| 589 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 590 | else if (!strcmp(args[0], "uid")) { |
| 591 | if (global.uid != 0) { |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 592 | Alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 593 | err_code |= ERR_ALERT; |
| 594 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 595 | } |
| 596 | if (*(args[1]) == 0) { |
| 597 | 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] | 598 | err_code |= ERR_ALERT | ERR_FATAL; |
| 599 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 600 | } |
| 601 | global.uid = atol(args[1]); |
| 602 | } |
| 603 | else if (!strcmp(args[0], "gid")) { |
| 604 | if (global.gid != 0) { |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 605 | Alert("parsing [%s:%d] : group/gid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 606 | err_code |= ERR_ALERT; |
| 607 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 608 | } |
| 609 | if (*(args[1]) == 0) { |
| 610 | 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] | 611 | err_code |= ERR_ALERT | ERR_FATAL; |
| 612 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 613 | } |
| 614 | global.gid = atol(args[1]); |
| 615 | } |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 616 | /* user/group name handling */ |
| 617 | else if (!strcmp(args[0], "user")) { |
| 618 | struct passwd *ha_user; |
| 619 | if (global.uid != 0) { |
| 620 | Alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 621 | err_code |= ERR_ALERT; |
| 622 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 623 | } |
| 624 | errno = 0; |
| 625 | ha_user = getpwnam(args[1]); |
| 626 | if (ha_user != NULL) { |
| 627 | global.uid = (int)ha_user->pw_uid; |
| 628 | } |
| 629 | else { |
| 630 | 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] | 631 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 632 | } |
| 633 | } |
| 634 | else if (!strcmp(args[0], "group")) { |
| 635 | struct group *ha_group; |
| 636 | if (global.gid != 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 637 | 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] | 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_group = getgrnam(args[1]); |
| 643 | if (ha_group != NULL) { |
| 644 | global.gid = (int)ha_group->gr_gid; |
| 645 | } |
| 646 | else { |
| 647 | 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] | 648 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 649 | } |
| 650 | } |
| 651 | /* end of user/group name handling*/ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 652 | else if (!strcmp(args[0], "nbproc")) { |
| 653 | if (global.nbproc != 0) { |
| 654 | 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] | 655 | err_code |= ERR_ALERT; |
| 656 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 657 | } |
| 658 | if (*(args[1]) == 0) { |
| 659 | 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] | 660 | err_code |= ERR_ALERT | ERR_FATAL; |
| 661 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 662 | } |
| 663 | global.nbproc = atol(args[1]); |
| 664 | } |
| 665 | else if (!strcmp(args[0], "maxconn")) { |
| 666 | if (global.maxconn != 0) { |
| 667 | 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] | 668 | err_code |= ERR_ALERT; |
| 669 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 670 | } |
| 671 | if (*(args[1]) == 0) { |
| 672 | 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] | 673 | err_code |= ERR_ALERT | ERR_FATAL; |
| 674 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 675 | } |
| 676 | global.maxconn = atol(args[1]); |
| 677 | #ifdef SYSTEM_MAXCONN |
| 678 | if (global.maxconn > DEFAULT_MAXCONN && cfg_maxconn <= DEFAULT_MAXCONN) { |
| 679 | 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); |
| 680 | global.maxconn = DEFAULT_MAXCONN; |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 681 | err_code |= ERR_ALERT; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 682 | } |
| 683 | #endif /* SYSTEM_MAXCONN */ |
| 684 | } |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 685 | else if (!strcmp(args[0], "maxpipes")) { |
| 686 | if (global.maxpipes != 0) { |
| 687 | 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] | 688 | err_code |= ERR_ALERT; |
| 689 | goto out; |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 690 | } |
| 691 | if (*(args[1]) == 0) { |
| 692 | 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] | 693 | err_code |= ERR_ALERT | ERR_FATAL; |
| 694 | goto out; |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 695 | } |
| 696 | global.maxpipes = atol(args[1]); |
| 697 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 698 | else if (!strcmp(args[0], "ulimit-n")) { |
| 699 | if (global.rlimit_nofile != 0) { |
| 700 | 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] | 701 | err_code |= ERR_ALERT; |
| 702 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 703 | } |
| 704 | if (*(args[1]) == 0) { |
| 705 | 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] | 706 | err_code |= ERR_ALERT | ERR_FATAL; |
| 707 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 708 | } |
| 709 | global.rlimit_nofile = atol(args[1]); |
| 710 | } |
| 711 | else if (!strcmp(args[0], "chroot")) { |
| 712 | if (global.chroot != NULL) { |
| 713 | 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] | 714 | err_code |= ERR_ALERT; |
| 715 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 716 | } |
| 717 | if (*(args[1]) == 0) { |
| 718 | 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] | 719 | err_code |= ERR_ALERT | ERR_FATAL; |
| 720 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 721 | } |
| 722 | global.chroot = strdup(args[1]); |
| 723 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 724 | else if (!strcmp(args[0], "description")) { |
| 725 | int i, len=0; |
| 726 | char *d; |
| 727 | |
| 728 | if (!*args[1]) { |
| 729 | Alert("parsing [%s:%d]: '%s' expects a string argument.\n", |
| 730 | file, linenum, args[0]); |
| 731 | err_code |= ERR_ALERT | ERR_FATAL; |
| 732 | goto out; |
| 733 | } |
| 734 | |
| 735 | for(i=1; *args[i]; i++) |
| 736 | len += strlen(args[i])+1; |
| 737 | |
| 738 | if (global.desc) |
| 739 | free(global.desc); |
| 740 | |
| 741 | global.desc = d = (char *)calloc(1, len); |
| 742 | |
| 743 | d += sprintf(d, "%s", args[1]); |
| 744 | for(i=2; *args[i]; i++) |
| 745 | d += sprintf(d, " %s", args[i]); |
| 746 | } |
| 747 | else if (!strcmp(args[0], "node")) { |
| 748 | int i; |
| 749 | char c; |
| 750 | |
| 751 | for (i=0; args[1][i]; i++) { |
| 752 | c = args[1][i]; |
Willy Tarreau | 88e0581 | 2010-03-03 00:16:00 +0100 | [diff] [blame] | 753 | if (!isupper((unsigned char)c) && !islower((unsigned char)c) && |
| 754 | !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.') |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 755 | break; |
| 756 | } |
| 757 | |
| 758 | if (!i || args[1][i]) { |
| 759 | Alert("parsing [%s:%d]: '%s' requires valid node name - non-empty string" |
| 760 | " with digits(0-9), letters(A-Z, a-z), dot(.), hyphen(-) or underscode(_).\n", |
| 761 | file, linenum, args[0]); |
| 762 | err_code |= ERR_ALERT | ERR_FATAL; |
| 763 | goto out; |
| 764 | } |
| 765 | |
| 766 | if (global.node) |
| 767 | free(global.node); |
| 768 | |
| 769 | global.node = strdup(args[1]); |
| 770 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 771 | else if (!strcmp(args[0], "pidfile")) { |
| 772 | if (global.pidfile != NULL) { |
| 773 | 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] | 774 | err_code |= ERR_ALERT; |
| 775 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 776 | } |
| 777 | if (*(args[1]) == 0) { |
| 778 | 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] | 779 | err_code |= ERR_ALERT | ERR_FATAL; |
| 780 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 781 | } |
| 782 | global.pidfile = strdup(args[1]); |
| 783 | } |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 784 | else if (!strcmp(args[0], "unix-bind")) { |
| 785 | int cur_arg = 1; |
| 786 | while (*(args[cur_arg])) { |
| 787 | if (!strcmp(args[cur_arg], "prefix")) { |
| 788 | if (global.unix_bind.prefix != NULL) { |
| 789 | Alert("parsing [%s:%d] : unix-bind '%s' already specified. Continuing.\n", file, linenum, args[cur_arg]); |
| 790 | err_code |= ERR_ALERT; |
| 791 | cur_arg += 2; |
| 792 | continue; |
| 793 | } |
| 794 | |
| 795 | if (*(args[cur_arg+1]) == 0) { |
| 796 | Alert("parsing [%s:%d] : unix_bind '%s' expects a path as an argument.\n", file, linenum, args[cur_arg]); |
| 797 | err_code |= ERR_ALERT | ERR_FATAL; |
| 798 | goto out; |
| 799 | } |
| 800 | global.unix_bind.prefix = strdup(args[cur_arg+1]); |
| 801 | cur_arg += 2; |
| 802 | continue; |
| 803 | } |
| 804 | |
| 805 | if (!strcmp(args[cur_arg], "mode")) { |
| 806 | |
| 807 | global.unix_bind.ux.mode = strtol(args[cur_arg + 1], NULL, 8); |
| 808 | cur_arg += 2; |
| 809 | continue; |
| 810 | } |
| 811 | |
| 812 | if (!strcmp(args[cur_arg], "uid")) { |
| 813 | |
| 814 | global.unix_bind.ux.uid = atol(args[cur_arg + 1 ]); |
| 815 | cur_arg += 2; |
| 816 | continue; |
| 817 | } |
| 818 | |
| 819 | if (!strcmp(args[cur_arg], "gid")) { |
| 820 | |
| 821 | global.unix_bind.ux.gid = atol(args[cur_arg + 1 ]); |
| 822 | cur_arg += 2; |
| 823 | continue; |
| 824 | } |
| 825 | |
| 826 | if (!strcmp(args[cur_arg], "user")) { |
| 827 | struct passwd *user; |
| 828 | |
| 829 | user = getpwnam(args[cur_arg + 1]); |
| 830 | if (!user) { |
| 831 | Alert("parsing [%s:%d] : '%s' : '%s' unknown user.\n", |
| 832 | file, linenum, args[0], args[cur_arg + 1 ]); |
| 833 | err_code |= ERR_ALERT | ERR_FATAL; |
| 834 | goto out; |
| 835 | } |
| 836 | |
| 837 | global.unix_bind.ux.uid = user->pw_uid; |
| 838 | cur_arg += 2; |
| 839 | continue; |
| 840 | } |
| 841 | |
| 842 | if (!strcmp(args[cur_arg], "group")) { |
| 843 | struct group *group; |
| 844 | |
| 845 | group = getgrnam(args[cur_arg + 1]); |
| 846 | if (!group) { |
| 847 | Alert("parsing [%s:%d] : '%s' : '%s' unknown group.\n", |
| 848 | file, linenum, args[0], args[cur_arg + 1 ]); |
| 849 | err_code |= ERR_ALERT | ERR_FATAL; |
| 850 | goto out; |
| 851 | } |
| 852 | |
| 853 | global.unix_bind.ux.gid = group->gr_gid; |
| 854 | cur_arg += 2; |
| 855 | continue; |
| 856 | } |
| 857 | |
| 858 | Alert("parsing [%s:%d] : '%s' only supports the 'transparent', 'accept-proxy', 'defer-accept', 'name', 'id', 'mss' and 'interface' options.\n", |
| 859 | file, linenum, args[0]); |
| 860 | err_code |= ERR_ALERT | ERR_FATAL; |
| 861 | goto out; |
| 862 | } |
| 863 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 864 | else if (!strcmp(args[0], "log")) { /* syslog server address */ |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 865 | struct logsrv logsrv; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 866 | int facility, level, minlvl; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 867 | |
| 868 | if (*(args[1]) == 0 || *(args[2]) == 0) { |
| 869 | 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] | 870 | err_code |= ERR_ALERT | ERR_FATAL; |
| 871 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 872 | } |
| 873 | |
| 874 | facility = get_log_facility(args[2]); |
| 875 | if (facility < 0) { |
| 876 | 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] | 877 | err_code |= ERR_ALERT | ERR_FATAL; |
| 878 | facility = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 879 | } |
| 880 | |
| 881 | level = 7; /* max syslog level = debug */ |
| 882 | if (*(args[3])) { |
| 883 | level = get_log_level(args[3]); |
| 884 | if (level < 0) { |
| 885 | 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] | 886 | err_code |= ERR_ALERT | ERR_FATAL; |
| 887 | level = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 888 | } |
| 889 | } |
| 890 | |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 891 | minlvl = 0; /* limit syslog level to this level (emerg) */ |
| 892 | if (*(args[4])) { |
| 893 | minlvl = get_log_level(args[4]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 894 | if (minlvl < 0) { |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 895 | 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] | 896 | err_code |= ERR_ALERT | ERR_FATAL; |
| 897 | minlvl = 0; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 898 | } |
| 899 | } |
| 900 | |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 901 | if (args[1][0] == '/') { |
David du Colombier | 11bcb6c | 2011-03-24 12:23:00 +0100 | [diff] [blame] | 902 | struct sockaddr_storage *sk = (struct sockaddr_storage *)str2sun(args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 903 | if (!sk) { |
| 904 | 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] | 905 | args[1], (int)sizeof(((struct sockaddr_un *)&sk)->sun_path) - 1); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 906 | err_code |= ERR_ALERT | ERR_FATAL; |
| 907 | goto out; |
| 908 | } |
David du Colombier | 11bcb6c | 2011-03-24 12:23:00 +0100 | [diff] [blame] | 909 | logsrv.addr = *sk; |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 910 | } else { |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 911 | struct sockaddr_storage *sk = str2sa(args[1]); |
David du Colombier | 11bcb6c | 2011-03-24 12:23:00 +0100 | [diff] [blame] | 912 | if (!sk) { |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 913 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[1]); |
| 914 | err_code |= ERR_ALERT | ERR_FATAL; |
| 915 | goto out; |
| 916 | } |
David du Colombier | 11bcb6c | 2011-03-24 12:23:00 +0100 | [diff] [blame] | 917 | logsrv.addr = *sk; |
| 918 | if (!get_host_port(&logsrv.addr)) |
| 919 | set_host_port(&logsrv.addr, SYSLOG_PORT); |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 920 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 921 | |
| 922 | if (global.logfac1 == -1) { |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 923 | global.logsrv1 = logsrv; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 924 | global.logfac1 = facility; |
| 925 | global.loglev1 = level; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 926 | global.minlvl1 = minlvl; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 927 | } |
| 928 | else if (global.logfac2 == -1) { |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 929 | global.logsrv2 = logsrv; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 930 | global.logfac2 = facility; |
| 931 | global.loglev2 = level; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 932 | global.minlvl2 = minlvl; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 933 | } |
| 934 | else { |
| 935 | Alert("parsing [%s:%d] : too many syslog servers\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 936 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 937 | } |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 938 | } |
Joe Williams | df5b38f | 2010-12-29 17:05:48 +0100 | [diff] [blame] | 939 | else if (!strcmp(args[0], "log-send-hostname")) { /* set the hostname in syslog header */ |
| 940 | char *name; |
| 941 | int len; |
| 942 | |
| 943 | if (global.log_send_hostname != NULL) { |
| 944 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 945 | err_code |= ERR_ALERT; |
| 946 | goto out; |
| 947 | } |
| 948 | |
| 949 | if (*(args[1])) |
| 950 | name = args[1]; |
| 951 | else |
| 952 | name = hostname; |
| 953 | |
| 954 | len = strlen(name); |
| 955 | |
| 956 | /* We'll add a space after the name to respect the log format */ |
| 957 | free(global.log_send_hostname); |
| 958 | global.log_send_hostname = malloc(len + 2); |
| 959 | snprintf(global.log_send_hostname, len + 2, "%s ", name); |
| 960 | } |
Kevinm | 48936af | 2010-12-22 16:08:21 +0000 | [diff] [blame] | 961 | else if (!strcmp(args[0], "log-tag")) { /* tag to report to syslog */ |
| 962 | if (*(args[1]) == 0) { |
| 963 | Alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]); |
| 964 | err_code |= ERR_ALERT | ERR_FATAL; |
| 965 | goto out; |
| 966 | } |
| 967 | free(global.log_tag); |
| 968 | global.log_tag = strdup(args[1]); |
| 969 | } |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 970 | else if (!strcmp(args[0], "spread-checks")) { /* random time between checks (0-50) */ |
| 971 | if (global.spread_checks != 0) { |
| 972 | Alert("parsing [%s:%d]: spread-checks already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 973 | err_code |= ERR_ALERT; |
| 974 | goto out; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 975 | } |
| 976 | if (*(args[1]) == 0) { |
| 977 | 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] | 978 | err_code |= ERR_ALERT | ERR_FATAL; |
| 979 | goto out; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 980 | } |
| 981 | global.spread_checks = atol(args[1]); |
| 982 | if (global.spread_checks < 0 || global.spread_checks > 50) { |
| 983 | 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] | 984 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 985 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 986 | } |
| 987 | else { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 988 | struct cfg_kw_list *kwl; |
| 989 | int index; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 990 | int rc; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 991 | |
| 992 | list_for_each_entry(kwl, &cfg_keywords.list, list) { |
| 993 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 994 | if (kwl->kw[index].section != CFG_GLOBAL) |
| 995 | continue; |
| 996 | if (strcmp(kwl->kw[index].kw, args[0]) == 0) { |
| 997 | /* prepare error message just in case */ |
| 998 | snprintf(trash, sizeof(trash), |
| 999 | "error near '%s' in '%s' section", args[0], "global"); |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1000 | rc = kwl->kw[index].parse(args, CFG_GLOBAL, NULL, NULL, trash, sizeof(trash)); |
| 1001 | if (rc < 0) { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1002 | Alert("parsing [%s:%d] : %s\n", file, linenum, trash); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1003 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1004 | } |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1005 | else if (rc > 0) { |
| 1006 | Warning("parsing [%s:%d] : %s\n", file, linenum, trash); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1007 | err_code |= ERR_WARN; |
| 1008 | goto out; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1009 | } |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1010 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1011 | } |
| 1012 | } |
| 1013 | } |
| 1014 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1015 | 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] | 1016 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1017 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1018 | |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1019 | out: |
| 1020 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1021 | } |
| 1022 | |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 1023 | /* Perform the most basic initialization of a proxy : |
| 1024 | * memset(), list_init(*), reset_timeouts(*). |
| 1025 | */ |
| 1026 | static void init_new_proxy(struct proxy *p) |
| 1027 | { |
| 1028 | memset(p, 0, sizeof(struct proxy)); |
| 1029 | LIST_INIT(&p->pendconns); |
| 1030 | LIST_INIT(&p->acl); |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 1031 | LIST_INIT(&p->http_req_rules); |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 1032 | LIST_INIT(&p->block_cond); |
| 1033 | LIST_INIT(&p->redirect_rules); |
| 1034 | LIST_INIT(&p->mon_fail_cond); |
| 1035 | LIST_INIT(&p->switching_rules); |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 1036 | LIST_INIT(&p->persist_rules); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 1037 | LIST_INIT(&p->sticking_rules); |
| 1038 | LIST_INIT(&p->storersp_rules); |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 1039 | LIST_INIT(&p->tcp_req.inspect_rules); |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 1040 | LIST_INIT(&p->tcp_rep.inspect_rules); |
Willy Tarreau | ab78619 | 2010-05-23 22:39:25 +0200 | [diff] [blame] | 1041 | LIST_INIT(&p->tcp_req.l4_rules); |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 1042 | LIST_INIT(&p->req_add); |
| 1043 | LIST_INIT(&p->rsp_add); |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 1044 | |
| 1045 | /* Timeouts are defined as -1 */ |
| 1046 | proxy_reset_timeouts(p); |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 1047 | p->tcp_rep.inspect_delay = TICK_ETERNITY; |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 1048 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1049 | |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 1050 | void init_default_instance() |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1051 | { |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 1052 | init_new_proxy(&defproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1053 | defproxy.mode = PR_MODE_TCP; |
| 1054 | defproxy.state = PR_STNEW; |
| 1055 | defproxy.maxconn = cfg_maxpconn; |
| 1056 | defproxy.conn_retries = CONN_RETRIES; |
| 1057 | defproxy.logfac1 = defproxy.logfac2 = -1; /* log disabled */ |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1058 | |
| 1059 | defproxy.defsrv.inter = DEF_CHKINTR; |
| 1060 | defproxy.defsrv.fastinter = 0; |
| 1061 | defproxy.defsrv.downinter = 0; |
| 1062 | defproxy.defsrv.rise = DEF_RISETIME; |
| 1063 | defproxy.defsrv.fall = DEF_FALLTIME; |
| 1064 | defproxy.defsrv.check_port = 0; |
| 1065 | defproxy.defsrv.maxqueue = 0; |
| 1066 | defproxy.defsrv.minconn = 0; |
| 1067 | defproxy.defsrv.maxconn = 0; |
| 1068 | defproxy.defsrv.slowstart = 0; |
| 1069 | defproxy.defsrv.onerror = DEF_HANA_ONERR; |
| 1070 | defproxy.defsrv.consecutive_errors_limit = DEF_HANA_ERRLIMIT; |
| 1071 | defproxy.defsrv.uweight = defproxy.defsrv.iweight = 1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1072 | } |
| 1073 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1074 | |
| 1075 | static int create_cond_regex_rule(const char *file, int line, |
| 1076 | struct proxy *px, int dir, int action, int flags, |
| 1077 | const char *cmd, const char *reg, const char *repl, |
| 1078 | const char **cond_start) |
| 1079 | { |
| 1080 | regex_t *preg = NULL; |
| 1081 | const char *err; |
| 1082 | int err_code = 0; |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1083 | struct acl_cond *cond = NULL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1084 | |
| 1085 | if (px == &defproxy) { |
| 1086 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, line, cmd); |
| 1087 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1088 | goto err; |
| 1089 | } |
| 1090 | |
| 1091 | if (*reg == 0) { |
| 1092 | Alert("parsing [%s:%d] : '%s' expects <regex> as an argument.\n", file, line, cmd); |
| 1093 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1094 | goto err; |
| 1095 | } |
| 1096 | |
| 1097 | if (warnifnotcap(px, PR_CAP_RS, file, line, cmd, NULL)) |
| 1098 | err_code |= ERR_WARN; |
| 1099 | |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1100 | if (cond_start && |
| 1101 | (strcmp(*cond_start, "if") == 0 || strcmp(*cond_start, "unless") == 0)) { |
| 1102 | if ((cond = build_acl_cond(file, line, px, cond_start)) == NULL) { |
| 1103 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition.\n", |
| 1104 | file, line, cmd); |
| 1105 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1106 | goto err; |
| 1107 | } |
| 1108 | } |
| 1109 | else if (cond_start && **cond_start) { |
| 1110 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 1111 | file, line, cmd, *cond_start); |
| 1112 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1113 | goto err; |
| 1114 | } |
| 1115 | |
| 1116 | if (dir == ACL_DIR_REQ) |
| 1117 | err_code |= warnif_cond_requires_resp(cond, file, line); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 1118 | else |
| 1119 | err_code |= warnif_cond_requires_req(cond, file, line); |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1120 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1121 | preg = calloc(1, sizeof(regex_t)); |
| 1122 | if (!preg) { |
| 1123 | Alert("parsing [%s:%d] : '%s' : not enough memory to build regex.\n", file, line, cmd); |
| 1124 | err_code = ERR_ALERT | ERR_FATAL; |
| 1125 | goto err; |
| 1126 | } |
| 1127 | |
| 1128 | if (regcomp(preg, reg, REG_EXTENDED | flags) != 0) { |
| 1129 | Alert("parsing [%s:%d] : '%s' : bad regular expression '%s'.\n", file, line, cmd, reg); |
| 1130 | err_code = ERR_ALERT | ERR_FATAL; |
| 1131 | goto err; |
| 1132 | } |
| 1133 | |
| 1134 | 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] | 1135 | preg, action, repl ? strdup(repl) : NULL, cond); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1136 | if (repl && err) { |
| 1137 | Alert("parsing [%s:%d] : '%s' : invalid character or unterminated sequence in replacement string near '%c'.\n", |
| 1138 | file, line, cmd, *err); |
| 1139 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1140 | goto err; |
| 1141 | } |
| 1142 | |
| 1143 | if (dir == ACL_DIR_REQ && warnif_misplaced_reqxxx(px, file, line, cmd)) |
| 1144 | err_code |= ERR_WARN; |
| 1145 | |
| 1146 | return err_code; |
| 1147 | err: |
| 1148 | free(preg); |
| 1149 | return err_code; |
| 1150 | } |
| 1151 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1152 | /* |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1153 | * Parse a line in a <listen>, <frontend>, <backend> or <ruleset> section. |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1154 | * Returns the error code, 0 if OK, or any combination of : |
| 1155 | * - ERR_ABORT: must abort ASAP |
| 1156 | * - ERR_FATAL: we can continue parsing but not start the service |
| 1157 | * - ERR_WARN: a warning has been emitted |
| 1158 | * - ERR_ALERT: an alert has been emitted |
| 1159 | * Only the two first ones can stop processing, the two others are just |
| 1160 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1161 | */ |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1162 | int cfg_parse_peers(const char *file, int linenum, char **args, int kwm) |
| 1163 | { |
| 1164 | static struct peers *curpeers = NULL; |
| 1165 | struct peer *newpeer = NULL; |
| 1166 | const char *err; |
| 1167 | int err_code = 0; |
| 1168 | |
| 1169 | if (strcmp(args[0], "peers") == 0) { /* new peers section */ |
| 1170 | |
| 1171 | err = invalid_char(args[1]); |
| 1172 | if (err) { |
| 1173 | Alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 1174 | file, linenum, *err, args[0], args[1]); |
| 1175 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1176 | } |
| 1177 | |
| 1178 | for (curpeers = peers; curpeers != NULL; curpeers = curpeers->next) { |
| 1179 | /* |
| 1180 | * If there are two proxies with the same name only following |
| 1181 | * combinations are allowed: |
| 1182 | */ |
| 1183 | if (strcmp(curpeers->id, args[1]) == 0) { |
| 1184 | Warning("Parsing [%s:%d]: peers '%s' has same name as another peers (declared at %s:%d).\n", |
| 1185 | file, linenum, args[1], curpeers->conf.file, curpeers->conf.line); |
| 1186 | err_code |= ERR_WARN; |
| 1187 | } |
| 1188 | } |
| 1189 | |
| 1190 | if ((curpeers = (struct peers *)calloc(1, sizeof(struct peers))) == NULL) { |
| 1191 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1192 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1193 | goto out; |
| 1194 | } |
| 1195 | |
| 1196 | curpeers->next = peers; |
| 1197 | peers = curpeers; |
| 1198 | curpeers->conf.file = file; |
| 1199 | curpeers->conf.line = linenum; |
| 1200 | curpeers->last_change = now.tv_sec; |
| 1201 | curpeers->id = strdup(args[1]); |
| 1202 | } |
| 1203 | else if (strcmp(args[0], "peer") == 0) { /* peer definition */ |
| 1204 | char *rport, *raddr; |
| 1205 | short realport = 0; |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 1206 | struct sockaddr_storage *sk; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1207 | |
| 1208 | if (!*args[2]) { |
| 1209 | Alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n", |
| 1210 | file, linenum, args[0]); |
| 1211 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1212 | goto out; |
| 1213 | } |
| 1214 | |
| 1215 | err = invalid_char(args[1]); |
| 1216 | if (err) { |
| 1217 | Alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n", |
| 1218 | file, linenum, *err, args[1]); |
| 1219 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1220 | goto out; |
| 1221 | } |
| 1222 | |
| 1223 | if ((newpeer = (struct peer *)calloc(1, sizeof(struct peer))) == NULL) { |
| 1224 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1225 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1226 | goto out; |
| 1227 | } |
| 1228 | |
| 1229 | /* the peers are linked backwards first */ |
| 1230 | curpeers->count++; |
| 1231 | newpeer->next = curpeers->remote; |
| 1232 | curpeers->remote = newpeer; |
| 1233 | newpeer->peers = curpeers; |
| 1234 | newpeer->conf.file = file; |
| 1235 | newpeer->conf.line = linenum; |
| 1236 | |
| 1237 | newpeer->last_change = now.tv_sec; |
| 1238 | newpeer->id = strdup(args[1]); |
| 1239 | |
| 1240 | raddr = strdup(args[2]); |
Willy Tarreau | fab5a43 | 2011-03-04 15:31:53 +0100 | [diff] [blame] | 1241 | rport = strrchr(raddr, ':'); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1242 | if (rport) { |
| 1243 | *rport++ = 0; |
| 1244 | realport = atol(rport); |
| 1245 | } |
| 1246 | if (!realport) { |
| 1247 | Alert("parsing [%s:%d] : Missing or invalid port in '%s'\n", file, linenum, args[2]); |
| 1248 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1249 | goto out; |
| 1250 | } |
| 1251 | |
Willy Tarreau | fab5a43 | 2011-03-04 15:31:53 +0100 | [diff] [blame] | 1252 | sk = str2ip(raddr); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1253 | free(raddr); |
| 1254 | if (!sk) { |
| 1255 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[2]); |
| 1256 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1257 | goto out; |
| 1258 | } |
| 1259 | newpeer->addr = *sk; |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 1260 | |
| 1261 | switch (newpeer->addr.ss_family) { |
| 1262 | case AF_INET: |
| 1263 | ((struct sockaddr_in *)&newpeer->addr)->sin_port = htons(realport); |
| 1264 | break; |
| 1265 | case AF_INET6: |
| 1266 | ((struct sockaddr_in6 *)&newpeer->addr)->sin6_port = htons(realport); |
| 1267 | break; |
| 1268 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1269 | |
| 1270 | if (strcmp(newpeer->id, localpeer) == 0) { |
| 1271 | /* Current is local peer, it define a frontend */ |
| 1272 | newpeer->local = 1; |
| 1273 | |
| 1274 | if (!curpeers->peers_fe) { |
| 1275 | if ((curpeers->peers_fe = calloc(1, sizeof(struct proxy))) == NULL) { |
| 1276 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1277 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1278 | goto out; |
| 1279 | } |
| 1280 | curpeers->peers_fe->parent = curpeers; |
| 1281 | |
| 1282 | LIST_INIT(&(curpeers->peers_fe)->pendconns); |
| 1283 | LIST_INIT(&(curpeers->peers_fe)->acl); |
| 1284 | LIST_INIT(&(curpeers->peers_fe)->block_cond); |
| 1285 | LIST_INIT(&(curpeers->peers_fe)->redirect_rules); |
| 1286 | LIST_INIT(&(curpeers->peers_fe)->mon_fail_cond); |
| 1287 | LIST_INIT(&(curpeers->peers_fe)->switching_rules); |
| 1288 | LIST_INIT(&(curpeers->peers_fe)->tcp_req.inspect_rules); |
| 1289 | LIST_INIT(&(curpeers->peers_fe)->tcp_rep.inspect_rules); |
| 1290 | |
| 1291 | proxy_reset_timeouts(curpeers->peers_fe); |
| 1292 | |
| 1293 | curpeers->peers_fe->last_change = now.tv_sec; |
| 1294 | curpeers->peers_fe->id = strdup(args[1]); |
| 1295 | curpeers->peers_fe->cap = PR_CAP_FE; |
| 1296 | curpeers->peers_fe->maxconn = 65000; |
| 1297 | curpeers->peers_fe->conn_retries = CONN_RETRIES; |
| 1298 | curpeers->peers_fe->timeout.connect = 5000; |
| 1299 | curpeers->peers_fe->accept = peer_accept; |
| 1300 | 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] | 1301 | if (!str2listener(args[2], curpeers->peers_fe, file, linenum)) { |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1302 | err_code |= ERR_FATAL; |
| 1303 | goto out; |
| 1304 | } |
| 1305 | curpeers->peers_fe->listen->maxconn = ((struct proxy *)curpeers->peers_fe)->maxconn; |
| 1306 | curpeers->peers_fe->listen->backlog = ((struct proxy *)curpeers->peers_fe)->backlog; |
| 1307 | curpeers->peers_fe->listen->timeout = &((struct proxy *)curpeers->peers_fe)->timeout.client; |
| 1308 | curpeers->peers_fe->listen->accept = session_accept; |
| 1309 | curpeers->peers_fe->listen->frontend = ((struct proxy *)curpeers->peers_fe); |
| 1310 | curpeers->peers_fe->listen->handler = process_session; |
| 1311 | curpeers->peers_fe->listen->analysers |= ((struct proxy *)curpeers->peers_fe)->fe_req_ana; |
| 1312 | } |
| 1313 | } |
| 1314 | } /* neither "peer" nor "peers" */ |
| 1315 | else if (*args[0] != 0) { |
| 1316 | Alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection); |
| 1317 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1318 | goto out; |
| 1319 | } |
| 1320 | |
| 1321 | out: |
| 1322 | return err_code; |
| 1323 | } |
| 1324 | |
| 1325 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 1326 | 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] | 1327 | { |
| 1328 | static struct proxy *curproxy = NULL; |
| 1329 | struct server *newsrv = NULL; |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 1330 | const char *err; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 1331 | int rc; |
| 1332 | unsigned val; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1333 | int err_code = 0; |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 1334 | struct acl_cond *cond = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1335 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1336 | if (!strcmp(args[0], "listen")) |
| 1337 | rc = PR_CAP_LISTEN; |
| 1338 | else if (!strcmp(args[0], "frontend")) |
| 1339 | rc = PR_CAP_FE | PR_CAP_RS; |
| 1340 | else if (!strcmp(args[0], "backend")) |
| 1341 | rc = PR_CAP_BE | PR_CAP_RS; |
| 1342 | else if (!strcmp(args[0], "ruleset")) |
| 1343 | rc = PR_CAP_RS; |
| 1344 | else |
| 1345 | rc = PR_CAP_NONE; |
| 1346 | |
| 1347 | if (rc != PR_CAP_NONE) { /* new proxy */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1348 | if (!*args[1]) { |
| 1349 | Alert("parsing [%s:%d] : '%s' expects an <id> argument and\n" |
| 1350 | " optionnally supports [addr1]:port1[-end1]{,[addr]:port[-end]}...\n", |
| 1351 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1352 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1353 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1354 | } |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 1355 | |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 1356 | err = invalid_char(args[1]); |
| 1357 | if (err) { |
| 1358 | Alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 1359 | file, linenum, *err, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1360 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 1361 | } |
| 1362 | |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 1363 | for (curproxy = proxy; curproxy != NULL; curproxy = curproxy->next) { |
| 1364 | /* |
| 1365 | * If there are two proxies with the same name only following |
| 1366 | * combinations are allowed: |
| 1367 | * |
| 1368 | * listen backend frontend ruleset |
| 1369 | * listen - - - - |
| 1370 | * backend - - OK - |
| 1371 | * frontend - OK - - |
| 1372 | * ruleset - - - - |
| 1373 | */ |
| 1374 | |
| 1375 | if (!strcmp(curproxy->id, args[1]) && |
| 1376 | (rc!=(PR_CAP_FE|PR_CAP_RS) || curproxy->cap!=(PR_CAP_BE|PR_CAP_RS)) && |
| 1377 | (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] | 1378 | Warning("Parsing [%s:%d]: %s '%s' has same name as another %s (declared at %s:%d).\n", |
| 1379 | file, linenum, proxy_cap_str(rc), args[1], proxy_type_str(curproxy), |
| 1380 | curproxy->conf.file, curproxy->conf.line); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1381 | err_code |= ERR_WARN; |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 1382 | } |
| 1383 | } |
| 1384 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1385 | if ((curproxy = (struct proxy *)calloc(1, sizeof(struct proxy))) == NULL) { |
| 1386 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1387 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1388 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1389 | } |
Willy Tarreau | 5af24ef | 2009-03-15 15:23:16 +0100 | [diff] [blame] | 1390 | |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 1391 | init_new_proxy(curproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1392 | curproxy->next = proxy; |
| 1393 | proxy = curproxy; |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 1394 | curproxy->conf.file = file; |
| 1395 | curproxy->conf.line = linenum; |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 1396 | curproxy->last_change = now.tv_sec; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1397 | curproxy->id = strdup(args[1]); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1398 | curproxy->cap = rc; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1399 | |
| 1400 | /* parse the listener address if any */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1401 | if ((curproxy->cap & PR_CAP_FE) && *args[2]) { |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 1402 | struct listener *new, *last = curproxy->listen; |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 1403 | if (!str2listener(args[2], curproxy, file, linenum)) { |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1404 | err_code |= ERR_FATAL; |
| 1405 | goto out; |
| 1406 | } |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 1407 | new = curproxy->listen; |
| 1408 | while (new != last) { |
| 1409 | new->conf.file = file; |
| 1410 | new->conf.line = linenum; |
| 1411 | new = new->next; |
Willy Tarreau | c8b1109 | 2011-02-16 11:08:57 +0100 | [diff] [blame] | 1412 | global.maxsock++; |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 1413 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1414 | } |
| 1415 | |
| 1416 | /* set default values */ |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1417 | memcpy(&curproxy->defsrv, &defproxy.defsrv, sizeof(curproxy->defsrv)); |
Willy Tarreau | 7016020 | 2010-04-07 16:06:40 +0200 | [diff] [blame] | 1418 | curproxy->defsrv.id = "default-server"; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1419 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1420 | curproxy->state = defproxy.state; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1421 | curproxy->options = defproxy.options; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 1422 | curproxy->options2 = defproxy.options2; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 1423 | curproxy->no_options = defproxy.no_options; |
| 1424 | curproxy->no_options2 = defproxy.no_options2; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 1425 | curproxy->bind_proc = defproxy.bind_proc; |
Willy Tarreau | 3168223 | 2007-11-29 15:38:04 +0100 | [diff] [blame] | 1426 | curproxy->lbprm.algo = defproxy.lbprm.algo; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 1427 | curproxy->except_net = defproxy.except_net; |
| 1428 | curproxy->except_mask = defproxy.except_mask; |
Maik Broemme | 36db02e | 2009-05-08 17:02:07 +0200 | [diff] [blame] | 1429 | curproxy->except_to = defproxy.except_to; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 1430 | curproxy->except_mask_to = defproxy.except_mask_to; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1431 | |
Willy Tarreau | 79f5fe8 | 2008-08-23 08:18:21 +0200 | [diff] [blame] | 1432 | if (defproxy.fwdfor_hdr_len) { |
| 1433 | curproxy->fwdfor_hdr_len = defproxy.fwdfor_hdr_len; |
| 1434 | curproxy->fwdfor_hdr_name = strdup(defproxy.fwdfor_hdr_name); |
| 1435 | } |
| 1436 | |
Willy Tarreau | b86db34 | 2009-11-30 11:50:16 +0100 | [diff] [blame] | 1437 | if (defproxy.orgto_hdr_len) { |
| 1438 | curproxy->orgto_hdr_len = defproxy.orgto_hdr_len; |
| 1439 | curproxy->orgto_hdr_name = strdup(defproxy.orgto_hdr_name); |
| 1440 | } |
| 1441 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1442 | if (curproxy->cap & PR_CAP_FE) { |
| 1443 | curproxy->maxconn = defproxy.maxconn; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 1444 | curproxy->backlog = defproxy.backlog; |
Willy Tarreau | 13a34bd | 2009-05-10 18:52:49 +0200 | [diff] [blame] | 1445 | curproxy->fe_sps_lim = defproxy.fe_sps_lim; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1446 | |
| 1447 | /* initialize error relocations */ |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1448 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) |
| 1449 | chunk_dup(&curproxy->errmsg[rc], &defproxy.errmsg[rc]); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1450 | |
| 1451 | curproxy->to_log = defproxy.to_log & ~LW_COOKIE & ~LW_REQHDR & ~ LW_RSPHDR; |
| 1452 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1453 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1454 | if (curproxy->cap & PR_CAP_BE) { |
| 1455 | curproxy->fullconn = defproxy.fullconn; |
| 1456 | curproxy->conn_retries = defproxy.conn_retries; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1457 | |
Willy Tarreau | aa2f389 | 2010-10-22 16:15:31 +0200 | [diff] [blame] | 1458 | if (defproxy.check_req) { |
| 1459 | curproxy->check_req = calloc(1, defproxy.check_len); |
| 1460 | memcpy(curproxy->check_req, defproxy.check_req, defproxy.check_len); |
| 1461 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1462 | curproxy->check_len = defproxy.check_len; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1463 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1464 | if (defproxy.cookie_name) |
| 1465 | curproxy->cookie_name = strdup(defproxy.cookie_name); |
| 1466 | curproxy->cookie_len = defproxy.cookie_len; |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 1467 | if (defproxy.cookie_domain) |
| 1468 | curproxy->cookie_domain = strdup(defproxy.cookie_domain); |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 1469 | |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 1470 | if (defproxy.cookie_maxidle) |
| 1471 | curproxy->cookie_maxidle = defproxy.cookie_maxidle; |
| 1472 | |
| 1473 | if (defproxy.cookie_maxlife) |
| 1474 | curproxy->cookie_maxlife = defproxy.cookie_maxlife; |
| 1475 | |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 1476 | if (defproxy.rdp_cookie_name) |
| 1477 | curproxy->rdp_cookie_name = strdup(defproxy.rdp_cookie_name); |
| 1478 | curproxy->rdp_cookie_len = defproxy.rdp_cookie_len; |
| 1479 | |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 1480 | if (defproxy.url_param_name) |
| 1481 | curproxy->url_param_name = strdup(defproxy.url_param_name); |
| 1482 | curproxy->url_param_len = defproxy.url_param_len; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 1483 | |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 1484 | if (defproxy.hh_name) |
| 1485 | curproxy->hh_name = strdup(defproxy.hh_name); |
| 1486 | curproxy->hh_len = defproxy.hh_len; |
| 1487 | curproxy->hh_match_domain = defproxy.hh_match_domain; |
| 1488 | |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 1489 | if (defproxy.iface_name) |
| 1490 | curproxy->iface_name = strdup(defproxy.iface_name); |
| 1491 | curproxy->iface_len = defproxy.iface_len; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1492 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1493 | |
Willy Tarreau | 3b6b1a9 | 2009-07-23 13:24:23 +0200 | [diff] [blame] | 1494 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1495 | if (defproxy.capture_name) |
| 1496 | curproxy->capture_name = strdup(defproxy.capture_name); |
| 1497 | curproxy->capture_namelen = defproxy.capture_namelen; |
| 1498 | curproxy->capture_len = defproxy.capture_len; |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 1499 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1500 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1501 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 1502 | curproxy->timeout.client = defproxy.timeout.client; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 1503 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | 036fae0 | 2008-01-06 13:24:40 +0100 | [diff] [blame] | 1504 | curproxy->timeout.httpreq = defproxy.timeout.httpreq; |
Willy Tarreau | b16a574 | 2010-01-10 14:46:16 +0100 | [diff] [blame] | 1505 | curproxy->timeout.httpka = defproxy.timeout.httpka; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1506 | curproxy->uri_auth = defproxy.uri_auth; |
| 1507 | curproxy->mon_net = defproxy.mon_net; |
| 1508 | curproxy->mon_mask = defproxy.mon_mask; |
| 1509 | if (defproxy.monitor_uri) |
| 1510 | curproxy->monitor_uri = strdup(defproxy.monitor_uri); |
| 1511 | curproxy->monitor_uri_len = defproxy.monitor_uri_len; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 1512 | if (defproxy.defbe.name) |
| 1513 | curproxy->defbe.name = strdup(defproxy.defbe.name); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1514 | } |
| 1515 | |
| 1516 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 1517 | curproxy->timeout.connect = defproxy.timeout.connect; |
| 1518 | curproxy->timeout.server = defproxy.timeout.server; |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 1519 | curproxy->timeout.check = defproxy.timeout.check; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 1520 | curproxy->timeout.queue = defproxy.timeout.queue; |
Willy Tarreau | 51c9bde | 2008-01-06 13:40:03 +0100 | [diff] [blame] | 1521 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | cd7afc0 | 2009-07-12 10:03:17 +0200 | [diff] [blame] | 1522 | curproxy->timeout.httpreq = defproxy.timeout.httpreq; |
Willy Tarreau | b16a574 | 2010-01-10 14:46:16 +0100 | [diff] [blame] | 1523 | curproxy->timeout.httpka = defproxy.timeout.httpka; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1524 | curproxy->source_addr = defproxy.source_addr; |
| 1525 | } |
| 1526 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1527 | curproxy->mode = defproxy.mode; |
| 1528 | curproxy->logfac1 = defproxy.logfac1; |
| 1529 | curproxy->logsrv1 = defproxy.logsrv1; |
| 1530 | curproxy->loglev1 = defproxy.loglev1; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 1531 | curproxy->minlvl1 = defproxy.minlvl1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1532 | curproxy->logfac2 = defproxy.logfac2; |
| 1533 | curproxy->logsrv2 = defproxy.logsrv2; |
| 1534 | curproxy->loglev2 = defproxy.loglev2; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 1535 | curproxy->minlvl2 = defproxy.minlvl2; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1536 | curproxy->grace = defproxy.grace; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1537 | curproxy->conf.used_listener_id = EB_ROOT; |
| 1538 | curproxy->conf.used_server_id = EB_ROOT; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 1539 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1540 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1541 | } |
| 1542 | else if (!strcmp(args[0], "defaults")) { /* use this one to assign default values */ |
| 1543 | /* some variables may have already been initialized earlier */ |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 1544 | /* FIXME-20070101: we should do this too at the end of the |
| 1545 | * config parsing to free all default values. |
| 1546 | */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1547 | free(defproxy.check_req); |
| 1548 | free(defproxy.cookie_name); |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 1549 | free(defproxy.rdp_cookie_name); |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 1550 | free(defproxy.cookie_domain); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1551 | free(defproxy.url_param_name); |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 1552 | free(defproxy.hh_name); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1553 | free(defproxy.capture_name); |
| 1554 | free(defproxy.monitor_uri); |
| 1555 | free(defproxy.defbe.name); |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 1556 | free(defproxy.iface_name); |
Willy Tarreau | 79f5fe8 | 2008-08-23 08:18:21 +0200 | [diff] [blame] | 1557 | free(defproxy.fwdfor_hdr_name); |
| 1558 | defproxy.fwdfor_hdr_len = 0; |
Willy Tarreau | b86db34 | 2009-11-30 11:50:16 +0100 | [diff] [blame] | 1559 | free(defproxy.orgto_hdr_name); |
| 1560 | defproxy.orgto_hdr_len = 0; |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 1561 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1562 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1563 | chunk_destroy(&defproxy.errmsg[rc]); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 1564 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1565 | /* we cannot free uri_auth because it might already be used */ |
| 1566 | init_default_instance(); |
| 1567 | curproxy = &defproxy; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1568 | defproxy.cap = PR_CAP_LISTEN; /* all caps for now */ |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1569 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1570 | } |
| 1571 | else if (curproxy == NULL) { |
| 1572 | Alert("parsing [%s:%d] : 'listen' or 'defaults' expected.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1573 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1574 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1575 | } |
| 1576 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1577 | |
| 1578 | /* Now let's parse the proxy-specific keywords */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1579 | if (!strcmp(args[0], "bind")) { /* new listen addresses */ |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 1580 | struct listener *new_listen, *last_listen; |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1581 | int cur_arg; |
| 1582 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1583 | if (curproxy == &defproxy) { |
| 1584 | 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] | 1585 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1586 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1587 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1588 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1589 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1590 | |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 1591 | if ( *(args[1]) != '/' && strchr(args[1], ':') == NULL) { |
Willy Tarreau | d55c3fe | 2010-11-09 09:50:37 +0100 | [diff] [blame] | 1592 | 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] | 1593 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1594 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1595 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1596 | } |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 1597 | |
| 1598 | last_listen = curproxy->listen; |
Willy Tarreau | 8a95691 | 2010-10-15 14:27:08 +0200 | [diff] [blame] | 1599 | |
| 1600 | /* NOTE: the following line might create several listeners if there |
| 1601 | * are comma-separated IPs or port ranges. So all further processing |
| 1602 | * will have to be applied to all listeners created after last_listen. |
| 1603 | */ |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 1604 | if (!str2listener(args[1], curproxy, file, linenum)) { |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1605 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1606 | goto out; |
| 1607 | } |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1608 | |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 1609 | new_listen = curproxy->listen; |
| 1610 | while (new_listen != last_listen) { |
| 1611 | new_listen->conf.file = file; |
| 1612 | new_listen->conf.line = linenum; |
| 1613 | new_listen = new_listen->next; |
Willy Tarreau | c8b1109 | 2011-02-16 11:08:57 +0100 | [diff] [blame] | 1614 | global.maxsock++; |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 1615 | } |
| 1616 | |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 1617 | /* Set default global rights and owner for unix bind */ |
| 1618 | if (curproxy->listen->addr.ss_family == AF_UNIX) { |
| 1619 | memcpy(&(curproxy->listen->perm.ux), &(global.unix_bind.ux), sizeof(global.unix_bind.ux)); |
| 1620 | } |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1621 | cur_arg = 2; |
| 1622 | while (*(args[cur_arg])) { |
| 1623 | if (!strcmp(args[cur_arg], "interface")) { /* specifically bind to this interface */ |
| 1624 | #ifdef SO_BINDTODEVICE |
| 1625 | struct listener *l; |
| 1626 | |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 1627 | if (curproxy->listen->addr.ss_family == AF_UNIX) { |
| 1628 | Alert("parsing [%s:%d] : '%s' : '%s' option not supported on unix sockets.\n", |
| 1629 | file, linenum, args[0], args[cur_arg]); |
| 1630 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1631 | goto out; |
| 1632 | } |
| 1633 | |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1634 | if (!*args[cur_arg + 1]) { |
| 1635 | Alert("parsing [%s:%d] : '%s' : missing interface name.\n", |
| 1636 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1637 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1638 | goto out; |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1639 | } |
| 1640 | |
| 1641 | for (l = curproxy->listen; l != last_listen; l = l->next) |
| 1642 | l->interface = strdup(args[cur_arg + 1]); |
| 1643 | |
| 1644 | global.last_checks |= LSTCHK_NETADM; |
| 1645 | |
| 1646 | cur_arg += 2; |
| 1647 | continue; |
| 1648 | #else |
| 1649 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 1650 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1651 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1652 | goto out; |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1653 | #endif |
| 1654 | } |
Willy Tarreau | be1b918 | 2009-06-14 18:48:19 +0200 | [diff] [blame] | 1655 | if (!strcmp(args[cur_arg], "mss")) { /* set MSS of listening socket */ |
| 1656 | #ifdef TCP_MAXSEG |
| 1657 | struct listener *l; |
| 1658 | int mss; |
| 1659 | |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 1660 | if (curproxy->listen->addr.ss_family == AF_UNIX) { |
| 1661 | Alert("parsing [%s:%d] : '%s' : '%s' option not supported on unix sockets.\n", |
| 1662 | file, linenum, args[0], args[cur_arg]); |
| 1663 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1664 | goto out; |
| 1665 | } |
| 1666 | |
Willy Tarreau | be1b918 | 2009-06-14 18:48:19 +0200 | [diff] [blame] | 1667 | if (!*args[cur_arg + 1]) { |
| 1668 | Alert("parsing [%s:%d] : '%s' : missing MSS value.\n", |
| 1669 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1670 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1671 | goto out; |
Willy Tarreau | be1b918 | 2009-06-14 18:48:19 +0200 | [diff] [blame] | 1672 | } |
| 1673 | |
Willy Tarreau | 48a7e72 | 2010-12-24 15:26:39 +0100 | [diff] [blame] | 1674 | mss = atoi(args[cur_arg + 1]); |
| 1675 | if (!mss || abs(mss) > 65535) { |
| 1676 | 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] | 1677 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1678 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1679 | goto out; |
Willy Tarreau | be1b918 | 2009-06-14 18:48:19 +0200 | [diff] [blame] | 1680 | } |
| 1681 | |
| 1682 | for (l = curproxy->listen; l != last_listen; l = l->next) |
| 1683 | l->maxseg = mss; |
| 1684 | |
| 1685 | cur_arg += 2; |
| 1686 | continue; |
| 1687 | #else |
| 1688 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 1689 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1690 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1691 | goto out; |
Willy Tarreau | be1b918 | 2009-06-14 18:48:19 +0200 | [diff] [blame] | 1692 | #endif |
| 1693 | } |
Willy Tarreau | cb6cd43 | 2009-10-13 07:34:14 +0200 | [diff] [blame] | 1694 | |
| 1695 | if (!strcmp(args[cur_arg], "defer-accept")) { /* wait for some data for 1 second max before doing accept */ |
| 1696 | #ifdef TCP_DEFER_ACCEPT |
| 1697 | struct listener *l; |
| 1698 | |
| 1699 | for (l = curproxy->listen; l != last_listen; l = l->next) |
| 1700 | l->options |= LI_O_DEF_ACCEPT; |
| 1701 | |
| 1702 | cur_arg ++; |
| 1703 | continue; |
| 1704 | #else |
| 1705 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 1706 | file, linenum, args[0], args[cur_arg]); |
| 1707 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1708 | goto out; |
| 1709 | #endif |
| 1710 | } |
| 1711 | |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1712 | if (!strcmp(args[cur_arg], "transparent")) { /* transparently bind to these addresses */ |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 1713 | #ifdef CONFIG_HAP_LINUX_TPROXY |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 1714 | struct listener *l; |
| 1715 | |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 1716 | if (curproxy->listen->addr.ss_family == AF_UNIX) { |
| 1717 | Alert("parsing [%s:%d] : '%s' : '%s' option not supported on unix sockets.\n", |
| 1718 | file, linenum, args[0], args[cur_arg]); |
| 1719 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1720 | goto out; |
| 1721 | } |
| 1722 | |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 1723 | for (l = curproxy->listen; l != last_listen; l = l->next) |
| 1724 | l->options |= LI_O_FOREIGN; |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1725 | |
| 1726 | cur_arg ++; |
| 1727 | continue; |
| 1728 | #else |
| 1729 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 1730 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1731 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1732 | goto out; |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1733 | #endif |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 1734 | } |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1735 | |
Willy Tarreau | 8a95691 | 2010-10-15 14:27:08 +0200 | [diff] [blame] | 1736 | if (!strcmp(args[cur_arg], "accept-proxy")) { /* expect a 'PROXY' line first */ |
| 1737 | struct listener *l; |
| 1738 | |
| 1739 | for (l = curproxy->listen; l != last_listen; l = l->next) |
| 1740 | l->options |= LI_O_ACC_PROXY; |
| 1741 | |
| 1742 | cur_arg ++; |
| 1743 | continue; |
| 1744 | } |
| 1745 | |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1746 | if (!strcmp(args[cur_arg], "name")) { |
| 1747 | struct listener *l; |
| 1748 | |
| 1749 | for (l = curproxy->listen; l != last_listen; l = l->next) |
| 1750 | l->name = strdup(args[cur_arg + 1]); |
| 1751 | |
| 1752 | cur_arg += 2; |
| 1753 | continue; |
| 1754 | } |
| 1755 | |
| 1756 | if (!strcmp(args[cur_arg], "id")) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1757 | struct eb32_node *node; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1758 | struct listener *l; |
| 1759 | |
| 1760 | if (curproxy->listen->next != last_listen) { |
| 1761 | Alert("parsing [%s:%d]: '%s' can be only used with a single socket.\n", |
| 1762 | file, linenum, args[cur_arg]); |
| 1763 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1764 | goto out; |
| 1765 | } |
| 1766 | |
| 1767 | if (!*args[cur_arg + 1]) { |
| 1768 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 1769 | file, linenum, args[cur_arg]); |
| 1770 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1771 | goto out; |
| 1772 | } |
| 1773 | |
| 1774 | curproxy->listen->luid = atol(args[cur_arg + 1]); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1775 | curproxy->listen->conf.id.key = curproxy->listen->luid; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1776 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1777 | if (curproxy->listen->luid <= 0) { |
| 1778 | Alert("parsing [%s:%d]: custom id has to be > 0\n", |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1779 | file, linenum); |
| 1780 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1781 | goto out; |
| 1782 | } |
| 1783 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1784 | node = eb32_lookup(&curproxy->conf.used_listener_id, curproxy->listen->luid); |
| 1785 | if (node) { |
| 1786 | l = container_of(node, struct listener, conf.id); |
| 1787 | Alert("parsing [%s:%d]: custom id %d for socket '%s' already used at %s:%d.\n", |
| 1788 | file, linenum, l->luid, args[1], l->conf.file, l->conf.line); |
| 1789 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1790 | goto out; |
| 1791 | } |
| 1792 | eb32_insert(&curproxy->conf.used_listener_id, &curproxy->listen->conf.id); |
| 1793 | |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1794 | cur_arg += 2; |
| 1795 | continue; |
| 1796 | } |
| 1797 | |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 1798 | if (!strcmp(args[cur_arg], "mode")) { |
| 1799 | |
| 1800 | if (curproxy->listen->addr.ss_family != AF_UNIX) { |
| 1801 | Alert("parsing [%s:%d] : '%s' : '%s' option only supported on unix sockets.\n", |
| 1802 | file, linenum, args[0], args[cur_arg]); |
| 1803 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1804 | goto out; |
| 1805 | } |
| 1806 | |
| 1807 | curproxy->listen->perm.ux.mode = strtol(args[cur_arg + 1], NULL, 8); |
| 1808 | |
| 1809 | cur_arg += 2; |
| 1810 | continue; |
| 1811 | } |
| 1812 | |
| 1813 | if (!strcmp(args[cur_arg], "uid")) { |
| 1814 | |
| 1815 | if (curproxy->listen->addr.ss_family != AF_UNIX) { |
| 1816 | Alert("parsing [%s:%d] : '%s' : '%s' option only supported on unix sockets.\n", |
| 1817 | file, linenum, args[0], args[cur_arg]); |
| 1818 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1819 | goto out; |
| 1820 | } |
| 1821 | |
| 1822 | curproxy->listen->perm.ux.uid = atol(args[cur_arg + 1 ]); |
| 1823 | cur_arg += 2; |
| 1824 | continue; |
| 1825 | } |
| 1826 | |
| 1827 | if (!strcmp(args[cur_arg], "gid")) { |
| 1828 | |
| 1829 | if (curproxy->listen->addr.ss_family != AF_UNIX) { |
| 1830 | Alert("parsing [%s:%d] : '%s' : '%s' option only supported on unix sockets.\n", |
| 1831 | file, linenum, args[0], args[cur_arg]); |
| 1832 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1833 | goto out; |
| 1834 | } |
| 1835 | |
| 1836 | curproxy->listen->perm.ux.gid = atol(args[cur_arg + 1 ]); |
| 1837 | cur_arg += 2; |
| 1838 | continue; |
| 1839 | } |
| 1840 | |
| 1841 | if (!strcmp(args[cur_arg], "user")) { |
| 1842 | struct passwd *user; |
| 1843 | |
| 1844 | if (curproxy->listen->addr.ss_family != AF_UNIX) { |
| 1845 | Alert("parsing [%s:%d] : '%s' : '%s' option only supported on unix sockets.\n", |
| 1846 | file, linenum, args[0], args[cur_arg]); |
| 1847 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1848 | goto out; |
| 1849 | } |
| 1850 | user = getpwnam(args[cur_arg + 1]); |
| 1851 | if (!user) { |
| 1852 | Alert("parsing [%s:%d] : '%s' : '%s' unknown user.\n", |
| 1853 | file, linenum, args[0], args[cur_arg + 1 ]); |
| 1854 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1855 | goto out; |
| 1856 | } |
| 1857 | |
| 1858 | curproxy->listen->perm.ux.uid = user->pw_uid; |
| 1859 | cur_arg += 2; |
| 1860 | continue; |
| 1861 | } |
| 1862 | |
| 1863 | if (!strcmp(args[cur_arg], "group")) { |
| 1864 | struct group *group; |
| 1865 | |
| 1866 | if (curproxy->listen->addr.ss_family != AF_UNIX) { |
| 1867 | Alert("parsing [%s:%d] : '%s' : '%s' option only supported on unix sockets.\n", |
| 1868 | file, linenum, args[0], args[cur_arg]); |
| 1869 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1870 | goto out; |
| 1871 | } |
| 1872 | group = getgrnam(args[cur_arg + 1]); |
| 1873 | if (!group) { |
| 1874 | Alert("parsing [%s:%d] : '%s' : '%s' unknown group.\n", |
| 1875 | file, linenum, args[0], args[cur_arg + 1 ]); |
| 1876 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1877 | goto out; |
| 1878 | } |
| 1879 | |
| 1880 | curproxy->listen->perm.ux.gid = group->gr_gid; |
| 1881 | cur_arg += 2; |
| 1882 | continue; |
| 1883 | } |
| 1884 | |
Willy Tarreau | 8a95691 | 2010-10-15 14:27:08 +0200 | [diff] [blame] | 1885 | Alert("parsing [%s:%d] : '%s' only supports the 'transparent', 'accept-proxy', 'defer-accept', 'name', 'id', 'mss' and 'interface' options.\n", |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 1886 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1887 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1888 | goto out; |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 1889 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1890 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1891 | } |
| 1892 | else if (!strcmp(args[0], "monitor-net")) { /* set the range of IPs to ignore */ |
| 1893 | if (!*args[1] || !str2net(args[1], &curproxy->mon_net, &curproxy->mon_mask)) { |
| 1894 | Alert("parsing [%s:%d] : '%s' expects address[/mask].\n", |
| 1895 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1896 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1897 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1898 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1899 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1900 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1901 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1902 | /* flush useless bits */ |
| 1903 | curproxy->mon_net.s_addr &= curproxy->mon_mask.s_addr; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1904 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1905 | } |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 1906 | else if (!strcmp(args[0], "monitor-uri")) { /* set the URI to intercept */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1907 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1908 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1909 | |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 1910 | if (!*args[1]) { |
| 1911 | Alert("parsing [%s:%d] : '%s' expects an URI.\n", |
| 1912 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1913 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1914 | goto out; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 1915 | } |
| 1916 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1917 | free(curproxy->monitor_uri); |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 1918 | curproxy->monitor_uri_len = strlen(args[1]); |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 1919 | curproxy->monitor_uri = (char *)calloc(1, curproxy->monitor_uri_len + 1); |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 1920 | memcpy(curproxy->monitor_uri, args[1], curproxy->monitor_uri_len); |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 1921 | curproxy->monitor_uri[curproxy->monitor_uri_len] = '\0'; |
| 1922 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1923 | goto out; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 1924 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1925 | else if (!strcmp(args[0], "mode")) { /* sets the proxy mode */ |
| 1926 | if (!strcmp(args[1], "http")) curproxy->mode = PR_MODE_HTTP; |
| 1927 | else if (!strcmp(args[1], "tcp")) curproxy->mode = PR_MODE_TCP; |
| 1928 | else if (!strcmp(args[1], "health")) curproxy->mode = PR_MODE_HEALTH; |
| 1929 | else { |
| 1930 | 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] | 1931 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1932 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1933 | } |
| 1934 | } |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 1935 | else if (!strcmp(args[0], "id")) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1936 | struct eb32_node *node; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 1937 | |
| 1938 | if (curproxy == &defproxy) { |
| 1939 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", |
| 1940 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1941 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1942 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 1943 | } |
| 1944 | |
| 1945 | if (!*args[1]) { |
| 1946 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 1947 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1948 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1949 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 1950 | } |
| 1951 | |
| 1952 | curproxy->uuid = atol(args[1]); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1953 | curproxy->conf.id.key = curproxy->uuid; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 1954 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1955 | if (curproxy->uuid <= 0) { |
| 1956 | Alert("parsing [%s:%d]: custom id has to be > 0.\n", |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 1957 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1958 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1959 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 1960 | } |
| 1961 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1962 | node = eb32_lookup(&used_proxy_id, curproxy->uuid); |
| 1963 | if (node) { |
| 1964 | struct proxy *target = container_of(node, struct proxy, conf.id); |
| 1965 | Alert("parsing [%s:%d]: %s %s reuses same custom id as %s %s (declared at %s:%d).\n", |
| 1966 | file, linenum, proxy_type_str(curproxy), curproxy->id, |
| 1967 | proxy_type_str(target), target->id, target->conf.file, target->conf.line); |
| 1968 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1969 | goto out; |
| 1970 | } |
| 1971 | eb32_insert(&used_proxy_id, &curproxy->conf.id); |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 1972 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1973 | else if (!strcmp(args[0], "description")) { |
| 1974 | int i, len=0; |
| 1975 | char *d; |
| 1976 | |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 1977 | if (curproxy == &defproxy) { |
| 1978 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", |
| 1979 | file, linenum, args[0]); |
| 1980 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1981 | goto out; |
| 1982 | } |
| 1983 | |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1984 | if (!*args[1]) { |
| 1985 | Alert("parsing [%s:%d]: '%s' expects a string argument.\n", |
| 1986 | file, linenum, args[0]); |
| 1987 | return -1; |
| 1988 | } |
| 1989 | |
| 1990 | for(i=1; *args[i]; i++) |
| 1991 | len += strlen(args[i])+1; |
| 1992 | |
| 1993 | d = (char *)calloc(1, len); |
| 1994 | curproxy->desc = d; |
| 1995 | |
| 1996 | d += sprintf(d, "%s", args[1]); |
| 1997 | for(i=2; *args[i]; i++) |
| 1998 | d += sprintf(d, " %s", args[i]); |
| 1999 | |
| 2000 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2001 | else if (!strcmp(args[0], "disabled")) { /* disables this proxy */ |
| 2002 | curproxy->state = PR_STSTOPPED; |
| 2003 | } |
| 2004 | else if (!strcmp(args[0], "enabled")) { /* enables this proxy (used to revert a disabled default) */ |
| 2005 | curproxy->state = PR_STNEW; |
| 2006 | } |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2007 | else if (!strcmp(args[0], "bind-process")) { /* enable this proxy only on some processes */ |
| 2008 | int cur_arg = 1; |
| 2009 | unsigned int set = 0; |
| 2010 | |
| 2011 | while (*args[cur_arg]) { |
| 2012 | int u; |
| 2013 | if (strcmp(args[cur_arg], "all") == 0) { |
| 2014 | set = 0; |
| 2015 | break; |
| 2016 | } |
| 2017 | else if (strcmp(args[cur_arg], "odd") == 0) { |
| 2018 | set |= 0x55555555; |
| 2019 | } |
| 2020 | else if (strcmp(args[cur_arg], "even") == 0) { |
| 2021 | set |= 0xAAAAAAAA; |
| 2022 | } |
| 2023 | else { |
| 2024 | u = str2uic(args[cur_arg]); |
| 2025 | if (u < 1 || u > 32) { |
| 2026 | Alert("parsing [%s:%d]: %s expects 'all', 'odd', 'even', or process numbers from 1 to 32.\n", |
| 2027 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2028 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2029 | goto out; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2030 | } |
| 2031 | if (u > global.nbproc) { |
| 2032 | Warning("parsing [%s:%d]: %s references process number higher than global.nbproc.\n", |
| 2033 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2034 | err_code |= ERR_WARN; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2035 | } |
| 2036 | set |= 1 << (u - 1); |
| 2037 | } |
| 2038 | cur_arg++; |
| 2039 | } |
| 2040 | curproxy->bind_proc = set; |
| 2041 | } |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 2042 | else if (!strcmp(args[0], "acl")) { /* add an ACL */ |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2043 | if (curproxy == &defproxy) { |
| 2044 | 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] | 2045 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2046 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2047 | } |
| 2048 | |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 2049 | err = invalid_char(args[1]); |
| 2050 | if (err) { |
| 2051 | Alert("parsing [%s:%d] : character '%c' is not permitted in acl name '%s'.\n", |
| 2052 | file, linenum, *err, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2053 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 2054 | } |
| 2055 | |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 2056 | if (parse_acl((const char **)args + 1, &curproxy->acl) == NULL) { |
| 2057 | Alert("parsing [%s:%d] : error detected while parsing ACL '%s'.\n", |
| 2058 | file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2059 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2060 | goto out; |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 2061 | } |
| 2062 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2063 | else if (!strcmp(args[0], "cookie")) { /* cookie name */ |
| 2064 | int cur_arg; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2065 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2066 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2067 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2068 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2069 | if (*(args[1]) == 0) { |
| 2070 | Alert("parsing [%s:%d] : '%s' expects <cookie_name> as argument.\n", |
| 2071 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2072 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2073 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2074 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2075 | |
Willy Tarreau | c63d4bb | 2010-10-23 11:37:27 +0200 | [diff] [blame] | 2076 | curproxy->options &= ~PR_O_COOK_ANY; |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 2077 | curproxy->options2 &= ~PR_O2_COOK_PSV; |
Willy Tarreau | c63d4bb | 2010-10-23 11:37:27 +0200 | [diff] [blame] | 2078 | curproxy->cookie_maxidle = curproxy->cookie_maxlife = 0; |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 2079 | free(curproxy->cookie_domain); curproxy->cookie_domain = NULL; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2080 | free(curproxy->cookie_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2081 | curproxy->cookie_name = strdup(args[1]); |
| 2082 | curproxy->cookie_len = strlen(curproxy->cookie_name); |
Willy Tarreau | c63d4bb | 2010-10-23 11:37:27 +0200 | [diff] [blame] | 2083 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2084 | cur_arg = 2; |
| 2085 | while (*(args[cur_arg])) { |
| 2086 | if (!strcmp(args[cur_arg], "rewrite")) { |
| 2087 | curproxy->options |= PR_O_COOK_RW; |
| 2088 | } |
| 2089 | else if (!strcmp(args[cur_arg], "indirect")) { |
| 2090 | curproxy->options |= PR_O_COOK_IND; |
| 2091 | } |
| 2092 | else if (!strcmp(args[cur_arg], "insert")) { |
| 2093 | curproxy->options |= PR_O_COOK_INS; |
| 2094 | } |
| 2095 | else if (!strcmp(args[cur_arg], "nocache")) { |
| 2096 | curproxy->options |= PR_O_COOK_NOC; |
| 2097 | } |
| 2098 | else if (!strcmp(args[cur_arg], "postonly")) { |
| 2099 | curproxy->options |= PR_O_COOK_POST; |
| 2100 | } |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 2101 | else if (!strcmp(args[cur_arg], "preserve")) { |
| 2102 | curproxy->options2 |= PR_O2_COOK_PSV; |
| 2103 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2104 | else if (!strcmp(args[cur_arg], "prefix")) { |
| 2105 | curproxy->options |= PR_O_COOK_PFX; |
| 2106 | } |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2107 | else if (!strcmp(args[cur_arg], "domain")) { |
| 2108 | if (!*args[cur_arg + 1]) { |
| 2109 | Alert("parsing [%s:%d]: '%s' expects <domain> as argument.\n", |
| 2110 | file, linenum, args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2111 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2112 | goto out; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2113 | } |
| 2114 | |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 2115 | if (*args[cur_arg + 1] != '.' || !strchr(args[cur_arg + 1] + 1, '.')) { |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2116 | /* rfc2109, 4.3.2 Rejecting Cookies */ |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 2117 | Warning("parsing [%s:%d]: domain '%s' contains no embedded" |
| 2118 | " dots nor does not start with a dot." |
| 2119 | " RFC forbids it, this configuration may not work properly.\n", |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2120 | file, linenum, args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 2121 | err_code |= ERR_WARN; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2122 | } |
| 2123 | |
| 2124 | err = invalid_domainchar(args[cur_arg + 1]); |
| 2125 | if (err) { |
| 2126 | Alert("parsing [%s:%d]: character '%c' is not permitted in domain name '%s'.\n", |
| 2127 | file, linenum, *err, args[cur_arg + 1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2128 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2129 | goto out; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2130 | } |
| 2131 | |
Willy Tarreau | 68a897b | 2009-12-03 23:28:34 +0100 | [diff] [blame] | 2132 | if (!curproxy->cookie_domain) { |
| 2133 | curproxy->cookie_domain = strdup(args[cur_arg + 1]); |
| 2134 | } else { |
| 2135 | /* one domain was already specified, add another one by |
| 2136 | * building the string which will be returned along with |
| 2137 | * the cookie. |
| 2138 | */ |
| 2139 | char *new_ptr; |
| 2140 | int new_len = strlen(curproxy->cookie_domain) + |
| 2141 | strlen("; domain=") + strlen(args[cur_arg + 1]) + 1; |
| 2142 | new_ptr = malloc(new_len); |
| 2143 | snprintf(new_ptr, new_len, "%s; domain=%s", curproxy->cookie_domain, args[cur_arg+1]); |
| 2144 | free(curproxy->cookie_domain); |
| 2145 | curproxy->cookie_domain = new_ptr; |
| 2146 | } |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 2147 | cur_arg++; |
| 2148 | } |
| 2149 | else if (!strcmp(args[cur_arg], "maxidle")) { |
| 2150 | unsigned int maxidle; |
| 2151 | const char *res; |
| 2152 | |
| 2153 | if (!*args[cur_arg + 1]) { |
| 2154 | Alert("parsing [%s:%d]: '%s' expects <idletime> in seconds as argument.\n", |
| 2155 | file, linenum, args[cur_arg]); |
| 2156 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2157 | goto out; |
| 2158 | } |
| 2159 | |
| 2160 | res = parse_time_err(args[cur_arg + 1], &maxidle, TIME_UNIT_S); |
| 2161 | if (res) { |
| 2162 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 2163 | file, linenum, *res, args[cur_arg]); |
| 2164 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2165 | goto out; |
| 2166 | } |
| 2167 | curproxy->cookie_maxidle = maxidle; |
| 2168 | cur_arg++; |
| 2169 | } |
| 2170 | else if (!strcmp(args[cur_arg], "maxlife")) { |
| 2171 | unsigned int maxlife; |
| 2172 | const char *res; |
| 2173 | |
| 2174 | if (!*args[cur_arg + 1]) { |
| 2175 | Alert("parsing [%s:%d]: '%s' expects <lifetime> in seconds as argument.\n", |
| 2176 | file, linenum, args[cur_arg]); |
| 2177 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2178 | goto out; |
| 2179 | } |
| 2180 | |
| 2181 | res = parse_time_err(args[cur_arg + 1], &maxlife, TIME_UNIT_S); |
| 2182 | if (res) { |
| 2183 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 2184 | file, linenum, *res, args[cur_arg]); |
| 2185 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2186 | goto out; |
| 2187 | } |
| 2188 | curproxy->cookie_maxlife = maxlife; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2189 | cur_arg++; |
| 2190 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2191 | else { |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 2192 | 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] | 2193 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2194 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2195 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2196 | } |
| 2197 | cur_arg++; |
| 2198 | } |
| 2199 | if (!POWEROF2(curproxy->options & (PR_O_COOK_RW|PR_O_COOK_IND))) { |
| 2200 | Alert("parsing [%s:%d] : cookie 'rewrite' and 'indirect' modes are incompatible.\n", |
| 2201 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2202 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2203 | } |
| 2204 | |
| 2205 | if (!POWEROF2(curproxy->options & (PR_O_COOK_RW|PR_O_COOK_INS|PR_O_COOK_PFX))) { |
| 2206 | Alert("parsing [%s:%d] : cookie 'rewrite', 'insert' and 'prefix' modes are incompatible.\n", |
| 2207 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2208 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2209 | } |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 2210 | |
| 2211 | if ((curproxy->options2 & PR_O2_COOK_PSV) && !(curproxy->options & (PR_O_COOK_INS|PR_O_COOK_IND))) { |
| 2212 | Alert("parsing [%s:%d] : cookie 'preserve' requires at least 'insert' or 'indirect'.\n", |
| 2213 | file, linenum); |
| 2214 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2215 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2216 | }/* end else if (!strcmp(args[0], "cookie")) */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2217 | else if (!strcmp(args[0], "persist")) { /* persist */ |
| 2218 | if (*(args[1]) == 0) { |
| 2219 | Alert("parsing [%s:%d] : missing persist method.\n", |
| 2220 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2221 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2222 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2223 | } |
| 2224 | |
| 2225 | if (!strncmp(args[1], "rdp-cookie", 10)) { |
| 2226 | curproxy->options2 |= PR_O2_RDPC_PRST; |
| 2227 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2228 | if (*(args[1] + 10) == '(') { /* cookie name */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2229 | const char *beg, *end; |
| 2230 | |
| 2231 | beg = args[1] + 11; |
| 2232 | end = strchr(beg, ')'); |
| 2233 | |
| 2234 | if (!end || end == beg) { |
| 2235 | Alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n", |
| 2236 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2237 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2238 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2239 | } |
| 2240 | |
| 2241 | free(curproxy->rdp_cookie_name); |
| 2242 | curproxy->rdp_cookie_name = my_strndup(beg, end - beg); |
| 2243 | curproxy->rdp_cookie_len = end-beg; |
| 2244 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2245 | else if (*(args[1] + 10) == '\0') { /* default cookie name 'msts' */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2246 | free(curproxy->rdp_cookie_name); |
| 2247 | curproxy->rdp_cookie_name = strdup("msts"); |
| 2248 | curproxy->rdp_cookie_len = strlen(curproxy->rdp_cookie_name); |
| 2249 | } |
| 2250 | else { /* syntax */ |
| 2251 | Alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n", |
| 2252 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2253 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2254 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2255 | } |
| 2256 | } |
| 2257 | else { |
| 2258 | Alert("parsing [%s:%d] : unknown persist method.\n", |
| 2259 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2260 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2261 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2262 | } |
| 2263 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2264 | else if (!strcmp(args[0], "appsession")) { /* cookie name */ |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2265 | int cur_arg; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2266 | |
Cyril Bonté | 3b7a369 | 2010-01-10 17:01:47 +0100 | [diff] [blame] | 2267 | if (curproxy == &defproxy) { |
| 2268 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2269 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2270 | goto out; |
| 2271 | } |
| 2272 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2273 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2274 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2275 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2276 | if (*(args[5]) == 0) { |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2277 | 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] | 2278 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2279 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2280 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2281 | } |
| 2282 | have_appsession = 1; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2283 | free(curproxy->appsession_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2284 | curproxy->appsession_name = strdup(args[1]); |
| 2285 | curproxy->appsession_name_len = strlen(curproxy->appsession_name); |
| 2286 | curproxy->appsession_len = atoi(args[3]); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 2287 | err = parse_time_err(args[5], &val, TIME_UNIT_MS); |
| 2288 | if (err) { |
| 2289 | Alert("parsing [%s:%d] : unexpected character '%c' in %s timeout.\n", |
| 2290 | file, linenum, *err, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2291 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2292 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 2293 | } |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 2294 | curproxy->timeout.appsession = val; |
Willy Tarreau | ee99136 | 2007-05-14 14:37:50 +0200 | [diff] [blame] | 2295 | |
Willy Tarreau | 51041c7 | 2007-09-09 21:56:53 +0200 | [diff] [blame] | 2296 | if (appsession_hash_init(&(curproxy->htbl_proxy), destroy) == 0) { |
| 2297 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2298 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2299 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2300 | } |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2301 | |
| 2302 | cur_arg = 6; |
| 2303 | curproxy->options2 &= ~PR_O2_AS_REQL; |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2304 | curproxy->options2 &= ~PR_O2_AS_M_ANY; |
| 2305 | curproxy->options2 |= PR_O2_AS_M_PP; |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2306 | while (*(args[cur_arg])) { |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2307 | if (!strcmp(args[cur_arg], "request-learn")) { |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2308 | curproxy->options2 |= PR_O2_AS_REQL; |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2309 | } else if (!strcmp(args[cur_arg], "prefix")) { |
| 2310 | curproxy->options2 |= PR_O2_AS_PFX; |
| 2311 | } else if (!strcmp(args[cur_arg], "mode")) { |
| 2312 | if (!*args[cur_arg + 1]) { |
| 2313 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 2314 | file, linenum, args[0], args[cur_arg]); |
| 2315 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2316 | goto out; |
| 2317 | } |
| 2318 | |
| 2319 | cur_arg++; |
| 2320 | if (!strcmp(args[cur_arg], "query-string")) { |
| 2321 | curproxy->options2 &= ~PR_O2_AS_M_ANY; |
| 2322 | curproxy->options2 |= PR_O2_AS_M_QS; |
| 2323 | } else if (!strcmp(args[cur_arg], "path-parameters")) { |
| 2324 | curproxy->options2 &= ~PR_O2_AS_M_ANY; |
| 2325 | curproxy->options2 |= PR_O2_AS_M_PP; |
| 2326 | } else { |
| 2327 | Alert("parsing [%s:%d] : unknown mode '%s'\n", file, linenum, args[cur_arg]); |
| 2328 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2329 | goto out; |
| 2330 | } |
| 2331 | } |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2332 | cur_arg++; |
| 2333 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2334 | } /* Url App Session */ |
| 2335 | else if (!strcmp(args[0], "capture")) { |
Willy Tarreau | 3b6b1a9 | 2009-07-23 13:24:23 +0200 | [diff] [blame] | 2336 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2337 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2338 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2339 | if (!strcmp(args[1], "cookie")) { /* name of a cookie to capture */ |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 2340 | if (curproxy == &defproxy) { |
| 2341 | Alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
| 2342 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2343 | goto out; |
| 2344 | } |
| 2345 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2346 | if (*(args[4]) == 0) { |
| 2347 | Alert("parsing [%s:%d] : '%s' expects 'cookie' <cookie_name> 'len' <len>.\n", |
| 2348 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2349 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2350 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2351 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2352 | free(curproxy->capture_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2353 | curproxy->capture_name = strdup(args[2]); |
| 2354 | curproxy->capture_namelen = strlen(curproxy->capture_name); |
| 2355 | curproxy->capture_len = atol(args[4]); |
| 2356 | if (curproxy->capture_len >= CAPTURE_LEN) { |
| 2357 | Warning("parsing [%s:%d] : truncating capture length to %d bytes.\n", |
| 2358 | file, linenum, CAPTURE_LEN - 1); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2359 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2360 | curproxy->capture_len = CAPTURE_LEN - 1; |
| 2361 | } |
| 2362 | curproxy->to_log |= LW_COOKIE; |
| 2363 | } |
| 2364 | else if (!strcmp(args[1], "request") && !strcmp(args[2], "header")) { |
| 2365 | struct cap_hdr *hdr; |
| 2366 | |
| 2367 | if (curproxy == &defproxy) { |
| 2368 | 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] | 2369 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2370 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2371 | } |
| 2372 | |
| 2373 | if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) { |
| 2374 | Alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n", |
| 2375 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2376 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2377 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2378 | } |
| 2379 | |
| 2380 | hdr = calloc(sizeof(struct cap_hdr), 1); |
| 2381 | hdr->next = curproxy->req_cap; |
| 2382 | hdr->name = strdup(args[3]); |
| 2383 | hdr->namelen = strlen(args[3]); |
| 2384 | hdr->len = atol(args[5]); |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 2385 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2386 | hdr->index = curproxy->nb_req_cap++; |
| 2387 | curproxy->req_cap = hdr; |
| 2388 | curproxy->to_log |= LW_REQHDR; |
| 2389 | } |
| 2390 | else if (!strcmp(args[1], "response") && !strcmp(args[2], "header")) { |
| 2391 | struct cap_hdr *hdr; |
| 2392 | |
| 2393 | if (curproxy == &defproxy) { |
| 2394 | 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] | 2395 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2396 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2397 | } |
| 2398 | |
| 2399 | if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) { |
| 2400 | Alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n", |
| 2401 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2402 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2403 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2404 | } |
| 2405 | hdr = calloc(sizeof(struct cap_hdr), 1); |
| 2406 | hdr->next = curproxy->rsp_cap; |
| 2407 | hdr->name = strdup(args[3]); |
| 2408 | hdr->namelen = strlen(args[3]); |
| 2409 | hdr->len = atol(args[5]); |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 2410 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2411 | hdr->index = curproxy->nb_rsp_cap++; |
| 2412 | curproxy->rsp_cap = hdr; |
| 2413 | curproxy->to_log |= LW_RSPHDR; |
| 2414 | } |
| 2415 | else { |
| 2416 | Alert("parsing [%s:%d] : '%s' expects 'cookie' or 'request header' or 'response header'.\n", |
| 2417 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2418 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2419 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2420 | } |
| 2421 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2422 | else if (!strcmp(args[0], "retries")) { /* connection retries */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2423 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2424 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2425 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2426 | if (*(args[1]) == 0) { |
| 2427 | Alert("parsing [%s:%d] : '%s' expects an integer argument (dispatch counts for one).\n", |
| 2428 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2429 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2430 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2431 | } |
| 2432 | curproxy->conn_retries = atol(args[1]); |
| 2433 | } |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2434 | 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] | 2435 | struct http_req_rule *rule; |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2436 | |
| 2437 | if (curproxy == &defproxy) { |
| 2438 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2439 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2440 | goto out; |
| 2441 | } |
| 2442 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 2443 | 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] | 2444 | Warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n", |
| 2445 | file, linenum, args[0]); |
| 2446 | err_code |= ERR_WARN; |
| 2447 | } |
| 2448 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 2449 | 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] | 2450 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 2451 | if (!rule) { |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2452 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2453 | goto out; |
| 2454 | } |
| 2455 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 2456 | err_code |= warnif_cond_requires_resp(rule->cond, file, linenum); |
| 2457 | LIST_ADDQ(&curproxy->http_req_rules, &rule->list); |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2458 | } |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2459 | else if (!strcmp(args[0], "block")) { /* early blocking based on ACLs */ |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2460 | if (curproxy == &defproxy) { |
| 2461 | 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] | 2462 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2463 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2464 | } |
| 2465 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2466 | if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) { |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2467 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 2468 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2469 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2470 | goto out; |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2471 | } |
| 2472 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2473 | 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] | 2474 | Alert("parsing [%s:%d] : error detected while parsing blocking condition.\n", |
| 2475 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2476 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2477 | goto out; |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2478 | } |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2479 | |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2480 | LIST_ADDQ(&curproxy->block_cond, &cond->list); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 2481 | warnif_misplaced_block(curproxy, file, linenum, args[0]); |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2482 | } |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2483 | else if (!strcmp(args[0], "redirect")) { |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2484 | struct redirect_rule *rule; |
| 2485 | int cur_arg; |
| 2486 | int type = REDIRECT_TYPE_NONE; |
| 2487 | int code = 302; |
| 2488 | char *destination = NULL; |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2489 | char *cookie = NULL; |
| 2490 | int cookie_set = 0; |
Willy Tarreau | 79da469 | 2008-11-19 20:03:04 +0100 | [diff] [blame] | 2491 | unsigned int flags = REDIRECT_FLAG_NONE; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2492 | |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 2493 | if (curproxy == &defproxy) { |
| 2494 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2495 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2496 | goto out; |
| 2497 | } |
| 2498 | |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2499 | cur_arg = 1; |
| 2500 | while (*(args[cur_arg])) { |
| 2501 | if (!strcmp(args[cur_arg], "location")) { |
| 2502 | if (!*args[cur_arg + 1]) { |
| 2503 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 2504 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2505 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2506 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2507 | } |
| 2508 | |
| 2509 | type = REDIRECT_TYPE_LOCATION; |
| 2510 | cur_arg++; |
| 2511 | destination = args[cur_arg]; |
| 2512 | } |
| 2513 | else if (!strcmp(args[cur_arg], "prefix")) { |
| 2514 | if (!*args[cur_arg + 1]) { |
| 2515 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 2516 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2517 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2518 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2519 | } |
| 2520 | |
| 2521 | type = REDIRECT_TYPE_PREFIX; |
| 2522 | cur_arg++; |
| 2523 | destination = args[cur_arg]; |
| 2524 | } |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2525 | else if (!strcmp(args[cur_arg], "set-cookie")) { |
| 2526 | if (!*args[cur_arg + 1]) { |
| 2527 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 2528 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2529 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2530 | goto out; |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2531 | } |
| 2532 | |
| 2533 | cur_arg++; |
| 2534 | cookie = args[cur_arg]; |
| 2535 | cookie_set = 1; |
| 2536 | } |
| 2537 | else if (!strcmp(args[cur_arg], "clear-cookie")) { |
| 2538 | if (!*args[cur_arg + 1]) { |
| 2539 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 2540 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2541 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2542 | goto out; |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2543 | } |
| 2544 | |
| 2545 | cur_arg++; |
| 2546 | cookie = args[cur_arg]; |
| 2547 | cookie_set = 0; |
| 2548 | } |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2549 | else if (!strcmp(args[cur_arg],"code")) { |
| 2550 | if (!*args[cur_arg + 1]) { |
| 2551 | Alert("parsing [%s:%d] : '%s': missing HTTP code.\n", |
| 2552 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2553 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2554 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2555 | } |
| 2556 | cur_arg++; |
| 2557 | code = atol(args[cur_arg]); |
| 2558 | if (code < 301 || code > 303) { |
| 2559 | Alert("parsing [%s:%d] : '%s': unsupported HTTP code '%d'.\n", |
| 2560 | file, linenum, args[0], code); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2561 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2562 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2563 | } |
| 2564 | } |
Willy Tarreau | 79da469 | 2008-11-19 20:03:04 +0100 | [diff] [blame] | 2565 | else if (!strcmp(args[cur_arg],"drop-query")) { |
| 2566 | flags |= REDIRECT_FLAG_DROP_QS; |
| 2567 | } |
Willy Tarreau | 81e3b4f | 2010-01-10 00:42:19 +0100 | [diff] [blame] | 2568 | else if (!strcmp(args[cur_arg],"append-slash")) { |
| 2569 | flags |= REDIRECT_FLAG_APPEND_SLASH; |
| 2570 | } |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2571 | else if (strcmp(args[cur_arg], "if") == 0 || |
| 2572 | strcmp(args[cur_arg], "unless") == 0) { |
| 2573 | cond = build_acl_cond(file, linenum, curproxy, (const char **)args + cur_arg); |
| 2574 | if (!cond) { |
| 2575 | Alert("parsing [%s:%d] : '%s': error detected while parsing redirect condition.\n", |
| 2576 | file, linenum, args[0]); |
| 2577 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2578 | goto out; |
| 2579 | } |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2580 | break; |
| 2581 | } |
| 2582 | else { |
Willy Tarreau | 81e3b4f | 2010-01-10 00:42:19 +0100 | [diff] [blame] | 2583 | 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] | 2584 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2585 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2586 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2587 | } |
| 2588 | cur_arg++; |
| 2589 | } |
| 2590 | |
| 2591 | if (type == REDIRECT_TYPE_NONE) { |
| 2592 | Alert("parsing [%s:%d] : '%s' expects a redirection type ('prefix' or 'location').\n", |
| 2593 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2594 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2595 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2596 | } |
| 2597 | |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2598 | rule = (struct redirect_rule *)calloc(1, sizeof(*rule)); |
| 2599 | rule->cond = cond; |
| 2600 | rule->rdr_str = strdup(destination); |
| 2601 | rule->rdr_len = strlen(destination); |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2602 | if (cookie) { |
| 2603 | /* 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] | 2604 | * a clear consists in appending "; path=/; Max-Age=0;" at the end. |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2605 | */ |
| 2606 | rule->cookie_len = strlen(cookie); |
William Turner | d986526 | 2010-03-01 13:30:34 -0500 | [diff] [blame] | 2607 | if (cookie_set) { |
| 2608 | rule->cookie_str = malloc(rule->cookie_len + 10); |
| 2609 | memcpy(rule->cookie_str, cookie, rule->cookie_len); |
| 2610 | memcpy(rule->cookie_str + rule->cookie_len, "; path=/;", 10); |
| 2611 | rule->cookie_len += 9; |
| 2612 | } else { |
| 2613 | rule->cookie_str = malloc(rule->cookie_len + 21); |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2614 | memcpy(rule->cookie_str, cookie, rule->cookie_len); |
William Turner | d986526 | 2010-03-01 13:30:34 -0500 | [diff] [blame] | 2615 | memcpy(rule->cookie_str + rule->cookie_len, "; path=/; Max-Age=0;", 21); |
| 2616 | rule->cookie_len += 20; |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2617 | } |
| 2618 | } |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2619 | rule->type = type; |
| 2620 | rule->code = code; |
Willy Tarreau | 79da469 | 2008-11-19 20:03:04 +0100 | [diff] [blame] | 2621 | rule->flags = flags; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2622 | LIST_INIT(&rule->list); |
| 2623 | LIST_ADDQ(&curproxy->redirect_rules, &rule->list); |
Willy Tarreau | 9d9ed01 | 2011-02-23 15:24:42 +0100 | [diff] [blame] | 2624 | err_code |= warnif_rule_after_use_backend(curproxy, file, linenum, args[0]); |
| 2625 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2626 | } |
Krzysztof Piotr Oledzki | 7b723ef | 2009-01-27 21:09:41 +0100 | [diff] [blame] | 2627 | else if (!strcmp(args[0], "use_backend")) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2628 | struct switching_rule *rule; |
| 2629 | |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2630 | if (curproxy == &defproxy) { |
| 2631 | 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] | 2632 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2633 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2634 | } |
| 2635 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2636 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2637 | err_code |= ERR_WARN; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2638 | |
| 2639 | if (*(args[1]) == 0) { |
| 2640 | 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] | 2641 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2642 | goto out; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2643 | } |
| 2644 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2645 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2646 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 2647 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2648 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2649 | goto out; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2650 | } |
| 2651 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2652 | 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] | 2653 | Alert("parsing [%s:%d] : error detected while parsing switching rule.\n", |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2654 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2655 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2656 | goto out; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2657 | } |
| 2658 | |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 2659 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
Willy Tarreau | a980263 | 2008-07-25 19:13:19 +0200 | [diff] [blame] | 2660 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2661 | rule = (struct switching_rule *)calloc(1, sizeof(*rule)); |
| 2662 | rule->cond = cond; |
| 2663 | rule->be.name = strdup(args[1]); |
| 2664 | LIST_INIT(&rule->list); |
| 2665 | LIST_ADDQ(&curproxy->switching_rules, &rule->list); |
| 2666 | } |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 2667 | else if ((!strcmp(args[0], "force-persist")) || |
| 2668 | (!strcmp(args[0], "ignore-persist"))) { |
| 2669 | struct persist_rule *rule; |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2670 | |
| 2671 | if (curproxy == &defproxy) { |
| 2672 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2673 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2674 | goto out; |
| 2675 | } |
| 2676 | |
| 2677 | if (warnifnotcap(curproxy, PR_CAP_FE|PR_CAP_BE, file, linenum, args[0], NULL)) |
| 2678 | err_code |= ERR_WARN; |
| 2679 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2680 | if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) { |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2681 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 2682 | file, linenum, args[0]); |
| 2683 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2684 | goto out; |
| 2685 | } |
| 2686 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2687 | 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] | 2688 | Alert("parsing [%s:%d] : error detected while parsing a '%s' rule.\n", |
| 2689 | file, linenum, args[0]); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2690 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2691 | goto out; |
| 2692 | } |
| 2693 | |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 2694 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2695 | |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 2696 | rule = (struct persist_rule *)calloc(1, sizeof(*rule)); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2697 | rule->cond = cond; |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 2698 | if (!strcmp(args[0], "force-persist")) { |
| 2699 | rule->type = PERSIST_TYPE_FORCE; |
| 2700 | } else { |
| 2701 | rule->type = PERSIST_TYPE_IGNORE; |
| 2702 | } |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2703 | LIST_INIT(&rule->list); |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 2704 | LIST_ADDQ(&curproxy->persist_rules, &rule->list); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2705 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2706 | else if (!strcmp(args[0], "stick-table")) { |
| 2707 | int myidx = 1; |
| 2708 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2709 | curproxy->table.id = curproxy->id; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2710 | curproxy->table.type = (unsigned int)-1; |
| 2711 | while (*args[myidx]) { |
| 2712 | const char *err; |
| 2713 | |
| 2714 | if (strcmp(args[myidx], "size") == 0) { |
| 2715 | myidx++; |
| 2716 | if (!*(args[myidx])) { |
| 2717 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 2718 | file, linenum, args[myidx-1]); |
| 2719 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2720 | goto out; |
| 2721 | } |
| 2722 | if ((err = parse_size_err(args[myidx], &curproxy->table.size))) { |
| 2723 | Alert("parsing [%s:%d] : stick-table: unexpected character '%c' in argument of '%s'.\n", |
| 2724 | file, linenum, *err, args[myidx-1]); |
| 2725 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2726 | goto out; |
| 2727 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 2728 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2729 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2730 | else if (strcmp(args[myidx], "peers") == 0) { |
| 2731 | myidx++; |
| 2732 | if (!*(args[myidx])) { |
| 2733 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 2734 | file, linenum, args[myidx-1]); |
| 2735 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2736 | goto out; |
| 2737 | } |
| 2738 | curproxy->table.peers.name = strdup(args[myidx++]); |
| 2739 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2740 | else if (strcmp(args[myidx], "expire") == 0) { |
| 2741 | myidx++; |
| 2742 | if (!*(args[myidx])) { |
| 2743 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 2744 | file, linenum, args[myidx-1]); |
| 2745 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2746 | goto out; |
| 2747 | } |
| 2748 | err = parse_time_err(args[myidx], &val, TIME_UNIT_MS); |
| 2749 | if (err) { |
| 2750 | Alert("parsing [%s:%d] : stick-table: unexpected character '%c' in argument of '%s'.\n", |
| 2751 | file, linenum, *err, args[myidx-1]); |
| 2752 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2753 | goto out; |
| 2754 | } |
| 2755 | curproxy->table.expire = val; |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 2756 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2757 | } |
| 2758 | else if (strcmp(args[myidx], "nopurge") == 0) { |
| 2759 | curproxy->table.nopurge = 1; |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 2760 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2761 | } |
| 2762 | else if (strcmp(args[myidx], "type") == 0) { |
| 2763 | myidx++; |
| 2764 | if (stktable_parse_type(args, &myidx, &curproxy->table.type, &curproxy->table.key_size) != 0) { |
| 2765 | Alert("parsing [%s:%d] : stick-table: unknown type '%s'.\n", |
| 2766 | file, linenum, args[myidx]); |
| 2767 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2768 | goto out; |
| 2769 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 2770 | /* myidx already points to next arg */ |
| 2771 | } |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 2772 | else if (strcmp(args[myidx], "store") == 0) { |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 2773 | int type, err; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 2774 | char *cw, *nw, *sa; |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 2775 | |
| 2776 | myidx++; |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 2777 | nw = args[myidx]; |
| 2778 | while (*nw) { |
| 2779 | /* the "store" keyword supports a comma-separated list */ |
| 2780 | cw = nw; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 2781 | sa = NULL; /* store arg */ |
| 2782 | while (*nw && *nw != ',') { |
| 2783 | if (*nw == '(') { |
| 2784 | *nw = 0; |
| 2785 | sa = ++nw; |
| 2786 | while (*nw != ')') { |
| 2787 | if (!*nw) { |
| 2788 | Alert("parsing [%s:%d] : %s: missing closing parenthesis after store option '%s'.\n", |
| 2789 | file, linenum, args[0], cw); |
| 2790 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2791 | goto out; |
| 2792 | } |
| 2793 | nw++; |
| 2794 | } |
| 2795 | *nw = '\0'; |
| 2796 | } |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 2797 | nw++; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 2798 | } |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 2799 | if (*nw) |
| 2800 | *nw++ = '\0'; |
| 2801 | type = stktable_get_data_type(cw); |
| 2802 | if (type < 0) { |
| 2803 | Alert("parsing [%s:%d] : %s: unknown store option '%s'.\n", |
| 2804 | file, linenum, args[0], cw); |
| 2805 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2806 | goto out; |
| 2807 | } |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 2808 | |
| 2809 | err = stktable_alloc_data_type(&curproxy->table, type, sa); |
| 2810 | switch (err) { |
| 2811 | case PE_NONE: break; |
| 2812 | case PE_EXIST: |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 2813 | Warning("parsing [%s:%d]: %s: store option '%s' already enabled, ignored.\n", |
| 2814 | file, linenum, args[0], cw); |
| 2815 | err_code |= ERR_WARN; |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 2816 | break; |
| 2817 | |
| 2818 | case PE_ARG_MISSING: |
| 2819 | Alert("parsing [%s:%d] : %s: missing argument to store option '%s'.\n", |
| 2820 | file, linenum, args[0], cw); |
| 2821 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2822 | goto out; |
| 2823 | |
| 2824 | case PE_ARG_NOT_USED: |
| 2825 | Alert("parsing [%s:%d] : %s: unexpected argument to store option '%s'.\n", |
| 2826 | file, linenum, args[0], cw); |
| 2827 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2828 | goto out; |
| 2829 | |
| 2830 | default: |
| 2831 | Alert("parsing [%s:%d] : %s: error when processing store option '%s'.\n", |
| 2832 | file, linenum, args[0], cw); |
| 2833 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2834 | goto out; |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 2835 | } |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 2836 | } |
| 2837 | myidx++; |
| 2838 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 2839 | else { |
| 2840 | Alert("parsing [%s:%d] : stick-table: unknown argument '%s'.\n", |
| 2841 | file, linenum, args[myidx]); |
| 2842 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2843 | goto out; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2844 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2845 | } |
| 2846 | |
| 2847 | if (!curproxy->table.size) { |
| 2848 | Alert("parsing [%s:%d] : stick-table: missing size.\n", |
| 2849 | file, linenum); |
| 2850 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2851 | goto out; |
| 2852 | } |
| 2853 | |
| 2854 | if (curproxy->table.type == (unsigned int)-1) { |
| 2855 | Alert("parsing [%s:%d] : stick-table: missing type.\n", |
| 2856 | file, linenum); |
| 2857 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2858 | goto out; |
| 2859 | } |
| 2860 | } |
| 2861 | else if (!strcmp(args[0], "stick")) { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2862 | struct sticking_rule *rule; |
| 2863 | struct pattern_expr *expr; |
| 2864 | int myidx = 0; |
| 2865 | const char *name = NULL; |
| 2866 | int flags; |
| 2867 | |
| 2868 | if (curproxy == &defproxy) { |
| 2869 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2870 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2871 | goto out; |
| 2872 | } |
| 2873 | |
| 2874 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) { |
| 2875 | err_code |= ERR_WARN; |
| 2876 | goto out; |
| 2877 | } |
| 2878 | |
| 2879 | myidx++; |
| 2880 | if ((strcmp(args[myidx], "store") == 0) || |
| 2881 | (strcmp(args[myidx], "store-request") == 0)) { |
| 2882 | myidx++; |
| 2883 | flags = STK_IS_STORE; |
| 2884 | } |
| 2885 | else if (strcmp(args[myidx], "store-response") == 0) { |
| 2886 | myidx++; |
| 2887 | flags = STK_IS_STORE | STK_ON_RSP; |
| 2888 | } |
| 2889 | else if (strcmp(args[myidx], "match") == 0) { |
| 2890 | myidx++; |
| 2891 | flags = STK_IS_MATCH; |
| 2892 | } |
| 2893 | else if (strcmp(args[myidx], "on") == 0) { |
| 2894 | myidx++; |
| 2895 | flags = STK_IS_MATCH | STK_IS_STORE; |
| 2896 | } |
| 2897 | else { |
| 2898 | Alert("parsing [%s:%d] : '%s' expects 'on', 'match', or 'store'.\n", file, linenum, args[0]); |
| 2899 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2900 | goto out; |
| 2901 | } |
| 2902 | |
| 2903 | if (*(args[myidx]) == 0) { |
| 2904 | Alert("parsing [%s:%d] : '%s' expects a fetch method.\n", file, linenum, args[0]); |
| 2905 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2906 | goto out; |
| 2907 | } |
| 2908 | |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 2909 | expr = pattern_parse_expr(args, &myidx, trash, sizeof(trash)); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2910 | if (!expr) { |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 2911 | Alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], trash); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2912 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2913 | goto out; |
| 2914 | } |
| 2915 | |
| 2916 | if (flags & STK_ON_RSP) { |
| 2917 | if (!(expr->fetch->dir & PATTERN_FETCH_RTR)) { |
| 2918 | Alert("parsing [%s:%d] : '%s': fetch method '%s' can not be used on response.\n", |
| 2919 | file, linenum, args[0], expr->fetch->kw); |
| 2920 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2921 | goto out; |
| 2922 | } |
| 2923 | } else { |
| 2924 | if (!(expr->fetch->dir & PATTERN_FETCH_REQ)) { |
| 2925 | Alert("parsing [%s:%d] : '%s': fetch method '%s' can not be used on request.\n", |
| 2926 | file, linenum, args[0], expr->fetch->kw); |
| 2927 | err_code |= ERR_ALERT | ERR_FATAL; |
| 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; |
| 2942 | goto out; |
| 2943 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2944 | } |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2945 | else if (*(args[myidx])) { |
| 2946 | Alert("parsing [%s:%d] : '%s': unknown keyword '%s'.\n", |
| 2947 | file, linenum, args[0], args[myidx]); |
| 2948 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2949 | goto out; |
| 2950 | } |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 2951 | if (flags & STK_ON_RSP) |
| 2952 | err_code |= warnif_cond_requires_req(cond, file, linenum); |
| 2953 | else |
| 2954 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 2955 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2956 | rule = (struct sticking_rule *)calloc(1, sizeof(*rule)); |
| 2957 | rule->cond = cond; |
| 2958 | rule->expr = expr; |
| 2959 | rule->flags = flags; |
| 2960 | rule->table.name = name ? strdup(name) : NULL; |
| 2961 | LIST_INIT(&rule->list); |
| 2962 | if (flags & STK_ON_RSP) |
| 2963 | LIST_ADDQ(&curproxy->storersp_rules, &rule->list); |
| 2964 | else |
| 2965 | LIST_ADDQ(&curproxy->sticking_rules, &rule->list); |
| 2966 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2967 | else if (!strcmp(args[0], "stats")) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2968 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2969 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2970 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2971 | if (curproxy != &defproxy && curproxy->uri_auth == defproxy.uri_auth) |
| 2972 | curproxy->uri_auth = NULL; /* we must detach from the default config */ |
| 2973 | |
Krzysztof Piotr Oledzki | 260a3bb | 2010-01-06 16:25:05 +0100 | [diff] [blame] | 2974 | if (!*args[1]) { |
| 2975 | goto stats_error_parsing; |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 2976 | } else if (!strcmp(args[1], "admin")) { |
| 2977 | struct stats_admin_rule *rule; |
| 2978 | |
| 2979 | if (curproxy == &defproxy) { |
| 2980 | Alert("parsing [%s:%d]: '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
| 2981 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2982 | goto out; |
| 2983 | } |
| 2984 | |
| 2985 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 2986 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 2987 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2988 | goto out; |
| 2989 | } |
| 2990 | |
| 2991 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
| 2992 | Alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n", |
| 2993 | file, linenum, args[0], args[1]); |
| 2994 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2995 | goto out; |
| 2996 | } |
| 2997 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2)) == NULL) { |
| 2998 | Alert("parsing [%s:%d] : error detected while parsing a '%s %s' rule.\n", |
| 2999 | file, linenum, args[0], args[1]); |
| 3000 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3001 | goto out; |
| 3002 | } |
| 3003 | |
| 3004 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
| 3005 | |
| 3006 | rule = (struct stats_admin_rule *)calloc(1, sizeof(*rule)); |
| 3007 | rule->cond = cond; |
| 3008 | LIST_INIT(&rule->list); |
| 3009 | LIST_ADDQ(&curproxy->uri_auth->admin_rules, &rule->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3010 | } else if (!strcmp(args[1], "uri")) { |
| 3011 | if (*(args[2]) == 0) { |
| 3012 | Alert("parsing [%s:%d] : 'uri' needs an URI prefix.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3013 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3014 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3015 | } else if (!stats_set_uri(&curproxy->uri_auth, args[2])) { |
| 3016 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3017 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3018 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3019 | } |
| 3020 | } else if (!strcmp(args[1], "realm")) { |
| 3021 | if (*(args[2]) == 0) { |
| 3022 | Alert("parsing [%s:%d] : 'realm' needs an realm name.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3023 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3024 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3025 | } else if (!stats_set_realm(&curproxy->uri_auth, args[2])) { |
| 3026 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3027 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3028 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3029 | } |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 3030 | } else if (!strcmp(args[1], "refresh")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 3031 | unsigned interval; |
| 3032 | |
| 3033 | err = parse_time_err(args[2], &interval, TIME_UNIT_S); |
| 3034 | if (err) { |
| 3035 | Alert("parsing [%s:%d] : unexpected character '%c' in stats refresh interval.\n", |
| 3036 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3037 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3038 | goto out; |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 3039 | } else if (!stats_set_refresh(&curproxy->uri_auth, interval)) { |
| 3040 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3041 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3042 | goto out; |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 3043 | } |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3044 | } 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] | 3045 | struct http_req_rule *rule; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3046 | |
| 3047 | if (curproxy == &defproxy) { |
| 3048 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3049 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3050 | goto out; |
| 3051 | } |
| 3052 | |
| 3053 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 3054 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3055 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3056 | goto out; |
| 3057 | } |
| 3058 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3059 | if (!LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) && |
| 3060 | !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] | 3061 | Warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n", |
| 3062 | file, linenum, args[0]); |
| 3063 | err_code |= ERR_WARN; |
| 3064 | } |
| 3065 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3066 | 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] | 3067 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3068 | if (!rule) { |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3069 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3070 | goto out; |
| 3071 | } |
| 3072 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3073 | err_code |= warnif_cond_requires_resp(rule->cond, file, linenum); |
| 3074 | LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list); |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3075 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3076 | } else if (!strcmp(args[1], "auth")) { |
| 3077 | if (*(args[2]) == 0) { |
| 3078 | 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] | 3079 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3080 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3081 | } else if (!stats_add_auth(&curproxy->uri_auth, args[2])) { |
| 3082 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3083 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3084 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3085 | } |
| 3086 | } else if (!strcmp(args[1], "scope")) { |
| 3087 | if (*(args[2]) == 0) { |
| 3088 | Alert("parsing [%s:%d] : 'scope' needs a proxy name.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3089 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3090 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3091 | } else if (!stats_add_scope(&curproxy->uri_auth, args[2])) { |
| 3092 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3093 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3094 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3095 | } |
| 3096 | } else if (!strcmp(args[1], "enable")) { |
| 3097 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 3098 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3099 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3100 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3101 | } |
Krzysztof Oledzki | d9db927 | 2007-10-15 10:05:11 +0200 | [diff] [blame] | 3102 | } else if (!strcmp(args[1], "hide-version")) { |
| 3103 | if (!stats_set_flag(&curproxy->uri_auth, ST_HIDEVER)) { |
| 3104 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3105 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3106 | goto out; |
Krzysztof Oledzki | d9db927 | 2007-10-15 10:05:11 +0200 | [diff] [blame] | 3107 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3108 | } else if (!strcmp(args[1], "show-legends")) { |
| 3109 | if (!stats_set_flag(&curproxy->uri_auth, ST_SHLGNDS)) { |
| 3110 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3111 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3112 | goto out; |
| 3113 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3114 | } else if (!strcmp(args[1], "show-node")) { |
| 3115 | |
| 3116 | if (*args[2]) { |
| 3117 | int i; |
| 3118 | char c; |
| 3119 | |
| 3120 | for (i=0; args[2][i]; i++) { |
| 3121 | c = args[2][i]; |
Willy Tarreau | 88e0581 | 2010-03-03 00:16:00 +0100 | [diff] [blame] | 3122 | if (!isupper((unsigned char)c) && !islower((unsigned char)c) && |
| 3123 | !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.') |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3124 | break; |
| 3125 | } |
| 3126 | |
| 3127 | if (!i || args[2][i]) { |
| 3128 | Alert("parsing [%s:%d]: '%s %s' invalid node name - should be a string" |
| 3129 | "with digits(0-9), letters(A-Z, a-z), hyphen(-) or underscode(_).\n", |
| 3130 | file, linenum, args[0], args[1]); |
| 3131 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3132 | goto out; |
| 3133 | } |
| 3134 | } |
| 3135 | |
| 3136 | if (!stats_set_node(&curproxy->uri_auth, args[2])) { |
| 3137 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3138 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3139 | goto out; |
| 3140 | } |
| 3141 | } else if (!strcmp(args[1], "show-desc")) { |
| 3142 | char *desc = NULL; |
| 3143 | |
| 3144 | if (*args[2]) { |
| 3145 | int i, len=0; |
| 3146 | char *d; |
| 3147 | |
| 3148 | for(i=2; *args[i]; i++) |
| 3149 | len += strlen(args[i])+1; |
| 3150 | |
| 3151 | desc = d = (char *)calloc(1, len); |
| 3152 | |
| 3153 | d += sprintf(d, "%s", args[2]); |
| 3154 | for(i=3; *args[i]; i++) |
| 3155 | d += sprintf(d, " %s", args[i]); |
| 3156 | } |
| 3157 | |
| 3158 | if (!*args[2] && !global.desc) |
| 3159 | Warning("parsing [%s:%d]: '%s' requires a parameter or 'desc' to be set in the global section.\n", |
| 3160 | file, linenum, args[1]); |
| 3161 | else { |
| 3162 | if (!stats_set_desc(&curproxy->uri_auth, desc)) { |
| 3163 | free(desc); |
| 3164 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3165 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3166 | goto out; |
| 3167 | } |
| 3168 | free(desc); |
| 3169 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3170 | } else { |
Krzysztof Piotr Oledzki | 260a3bb | 2010-01-06 16:25:05 +0100 | [diff] [blame] | 3171 | stats_error_parsing: |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3172 | 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] | 3173 | 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] | 3174 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3175 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3176 | } |
| 3177 | } |
| 3178 | else if (!strcmp(args[0], "option")) { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3179 | int optnum; |
| 3180 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3181 | if (*(args[1]) == '\0') { |
| 3182 | Alert("parsing [%s:%d]: '%s' expects an option name.\n", |
| 3183 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3184 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3185 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3186 | } |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3187 | |
| 3188 | for (optnum = 0; cfg_opts[optnum].name; optnum++) { |
| 3189 | if (!strcmp(args[1], cfg_opts[optnum].name)) { |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 3190 | if (cfg_opts[optnum].cap == PR_CAP_NONE) { |
| 3191 | Alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n", |
| 3192 | file, linenum, cfg_opts[optnum].name); |
| 3193 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3194 | goto out; |
| 3195 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3196 | if (warnifnotcap(curproxy, cfg_opts[optnum].cap, file, linenum, args[1], NULL)) { |
| 3197 | err_code |= ERR_WARN; |
| 3198 | goto out; |
| 3199 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3200 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 3201 | curproxy->no_options &= ~cfg_opts[optnum].val; |
| 3202 | curproxy->options &= ~cfg_opts[optnum].val; |
| 3203 | |
| 3204 | switch (kwm) { |
| 3205 | case KWM_STD: |
| 3206 | curproxy->options |= cfg_opts[optnum].val; |
| 3207 | break; |
| 3208 | case KWM_NO: |
| 3209 | curproxy->no_options |= cfg_opts[optnum].val; |
| 3210 | break; |
| 3211 | case KWM_DEF: /* already cleared */ |
| 3212 | break; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 3213 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3214 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3215 | goto out; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3216 | } |
| 3217 | } |
| 3218 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 3219 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) { |
| 3220 | if (!strcmp(args[1], cfg_opts2[optnum].name)) { |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 3221 | if (cfg_opts2[optnum].cap == PR_CAP_NONE) { |
| 3222 | Alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n", |
| 3223 | file, linenum, cfg_opts2[optnum].name); |
| 3224 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3225 | goto out; |
| 3226 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3227 | if (warnifnotcap(curproxy, cfg_opts2[optnum].cap, file, linenum, args[1], NULL)) { |
| 3228 | err_code |= ERR_WARN; |
| 3229 | goto out; |
| 3230 | } |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 3231 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 3232 | curproxy->no_options2 &= ~cfg_opts2[optnum].val; |
| 3233 | curproxy->options2 &= ~cfg_opts2[optnum].val; |
| 3234 | |
| 3235 | switch (kwm) { |
| 3236 | case KWM_STD: |
| 3237 | curproxy->options2 |= cfg_opts2[optnum].val; |
| 3238 | break; |
| 3239 | case KWM_NO: |
| 3240 | curproxy->no_options2 |= cfg_opts2[optnum].val; |
| 3241 | break; |
| 3242 | case KWM_DEF: /* already cleared */ |
| 3243 | break; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 3244 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3245 | goto out; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 3246 | } |
| 3247 | } |
| 3248 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 3249 | if (kwm != KWM_STD) { |
| 3250 | 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] | 3251 | file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3252 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3253 | goto out; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3254 | } |
| 3255 | |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3256 | if (!strcmp(args[1], "httplog")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3257 | /* generate a complete HTTP log */ |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3258 | curproxy->options2 &= ~PR_O2_CLFLOG; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3259 | 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] | 3260 | if (*(args[2]) != '\0') { |
| 3261 | if (!strcmp(args[2], "clf")) { |
| 3262 | curproxy->options2 |= PR_O2_CLFLOG; |
| 3263 | } else { |
| 3264 | 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] | 3265 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3266 | goto out; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3267 | } |
| 3268 | } |
| 3269 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3270 | else if (!strcmp(args[1], "tcplog")) |
| 3271 | /* generate a detailed TCP log */ |
| 3272 | 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] | 3273 | else if (!strcmp(args[1], "tcpka")) { |
| 3274 | /* enable TCP keep-alives on client and server sessions */ |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3275 | 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] | 3276 | err_code |= ERR_WARN; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3277 | |
| 3278 | if (curproxy->cap & PR_CAP_FE) |
| 3279 | curproxy->options |= PR_O_TCP_CLI_KA; |
| 3280 | if (curproxy->cap & PR_CAP_BE) |
| 3281 | curproxy->options |= PR_O_TCP_SRV_KA; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3282 | } |
| 3283 | else if (!strcmp(args[1], "httpchk")) { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3284 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3285 | err_code |= ERR_WARN; |
| 3286 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3287 | /* use HTTP request to check servers' health */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3288 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 3289 | curproxy->check_req = NULL; |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 3290 | curproxy->options &= ~PR_O_SMTP_CHK; |
Willy Tarreau | 07a5490 | 2010-03-29 18:33:29 +0200 | [diff] [blame] | 3291 | curproxy->options2 &= ~PR_O2_SSL3_CHK; |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 3292 | curproxy->options2 &= ~PR_O2_MYSQL_CHK; |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 3293 | curproxy->options2 &= ~PR_O2_PGSQL_CHK; |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 3294 | curproxy->options2 &= ~PR_O2_LDAP_CHK; |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 3295 | curproxy->options |= PR_O_HTTP_CHK; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3296 | if (!*args[2]) { /* no argument */ |
| 3297 | curproxy->check_req = strdup(DEF_CHECK_REQ); /* default request */ |
| 3298 | curproxy->check_len = strlen(DEF_CHECK_REQ); |
| 3299 | } else if (!*args[3]) { /* one argument : URI */ |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3300 | 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] | 3301 | curproxy->check_req = (char *)malloc(reqlen); |
| 3302 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3303 | "OPTIONS %s HTTP/1.0\r\n", args[2]); /* URI to use */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3304 | } else { /* more arguments : METHOD URI [HTTP_VER] */ |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3305 | int reqlen = strlen(args[2]) + strlen(args[3]) + 3 + strlen("\r\n"); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3306 | if (*args[4]) |
| 3307 | reqlen += strlen(args[4]); |
| 3308 | else |
| 3309 | reqlen += strlen("HTTP/1.0"); |
| 3310 | |
| 3311 | curproxy->check_req = (char *)malloc(reqlen); |
| 3312 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3313 | "%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] | 3314 | } |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 3315 | } |
| 3316 | else if (!strcmp(args[1], "ssl-hello-chk")) { |
| 3317 | /* use SSLv3 CLIENT HELLO to check servers' health */ |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3318 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3319 | err_code |= ERR_WARN; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3320 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3321 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 3322 | curproxy->check_req = NULL; |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 3323 | curproxy->options &= ~PR_O_HTTP_CHK; |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 3324 | curproxy->options &= ~PR_O_SMTP_CHK; |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 3325 | curproxy->options2 &= ~PR_O2_MYSQL_CHK; |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 3326 | curproxy->options2 &= ~PR_O2_PGSQL_CHK; |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 3327 | curproxy->options2 &= ~PR_O2_LDAP_CHK; |
Willy Tarreau | 07a5490 | 2010-03-29 18:33:29 +0200 | [diff] [blame] | 3328 | curproxy->options2 |= PR_O2_SSL3_CHK; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3329 | } |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 3330 | else if (!strcmp(args[1], "smtpchk")) { |
| 3331 | /* use SMTP request to check servers' health */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3332 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 3333 | curproxy->check_req = NULL; |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 3334 | curproxy->options &= ~PR_O_HTTP_CHK; |
Willy Tarreau | 07a5490 | 2010-03-29 18:33:29 +0200 | [diff] [blame] | 3335 | curproxy->options2 &= ~PR_O2_SSL3_CHK; |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 3336 | curproxy->options2 &= ~PR_O2_MYSQL_CHK; |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 3337 | curproxy->options2 &= ~PR_O2_PGSQL_CHK; |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 3338 | curproxy->options2 &= ~PR_O2_LDAP_CHK; |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 3339 | curproxy->options |= PR_O_SMTP_CHK; |
| 3340 | |
| 3341 | if (!*args[2] || !*args[3]) { /* no argument or incomplete EHLO host */ |
| 3342 | curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */ |
| 3343 | curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ); |
| 3344 | } else { /* ESMTP EHLO, or SMTP HELO, and a hostname */ |
| 3345 | if (!strcmp(args[2], "EHLO") || !strcmp(args[2], "HELO")) { |
| 3346 | int reqlen = strlen(args[2]) + strlen(args[3]) + strlen(" \r\n") + 1; |
| 3347 | curproxy->check_req = (char *)malloc(reqlen); |
| 3348 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
| 3349 | "%s %s\r\n", args[2], args[3]); /* HELO hostname */ |
| 3350 | } else { |
| 3351 | /* this just hits the default for now, but you could potentially expand it to allow for other stuff |
| 3352 | though, it's unlikely you'd want to send anything other than an EHLO or HELO */ |
| 3353 | curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */ |
| 3354 | curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ); |
| 3355 | } |
| 3356 | } |
| 3357 | } |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 3358 | else if (!strcmp(args[1], "pgsql-check")) { |
| 3359 | /* use PostgreSQL request to check servers' health */ |
| 3360 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 3361 | err_code |= ERR_WARN; |
| 3362 | |
| 3363 | free(curproxy->check_req); |
| 3364 | curproxy->check_req = NULL; |
| 3365 | curproxy->options &= ~PR_O_HTTP_CHK; |
| 3366 | curproxy->options &= ~PR_O_SMTP_CHK; |
| 3367 | curproxy->options2 &= ~PR_O2_SSL3_CHK; |
| 3368 | curproxy->options2 &= ~PR_O2_LDAP_CHK; |
| 3369 | curproxy->options2 &= ~PR_O2_MYSQL_CHK; |
| 3370 | curproxy->options2 |= PR_O2_PGSQL_CHK; |
| 3371 | |
| 3372 | if (*(args[2])) { |
| 3373 | int cur_arg = 2; |
| 3374 | |
| 3375 | while (*(args[cur_arg])) { |
| 3376 | if (strcmp(args[cur_arg], "user") == 0) { |
| 3377 | char * packet; |
| 3378 | uint32_t packet_len; |
| 3379 | uint32_t pv; |
| 3380 | |
| 3381 | /* suboption header - needs additional argument for it */ |
| 3382 | if (*(args[cur_arg+1]) == 0) { |
| 3383 | Alert("parsing [%s:%d] : '%s %s %s' expects <username> as argument.\n", |
| 3384 | file, linenum, args[0], args[1], args[cur_arg]); |
| 3385 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3386 | goto out; |
| 3387 | } |
| 3388 | |
| 3389 | /* uint32_t + uint32_t + strlen("user")+1 + strlen(username)+1 + 1 */ |
| 3390 | packet_len = 4 + 4 + 5 + strlen(args[cur_arg + 1])+1 +1; |
| 3391 | pv = htonl(0x30000); /* protocol version 3.0 */ |
| 3392 | |
| 3393 | packet = (char*) calloc(1, packet_len); |
| 3394 | |
| 3395 | memcpy(packet + 4, &pv, 4); |
| 3396 | |
| 3397 | /* copy "user" */ |
| 3398 | memcpy(packet + 8, "user", 4); |
| 3399 | |
| 3400 | /* copy username */ |
| 3401 | memcpy(packet + 13, args[cur_arg+1], strlen(args[cur_arg+1])); |
| 3402 | |
| 3403 | free(curproxy->check_req); |
| 3404 | curproxy->check_req = packet; |
| 3405 | curproxy->check_len = packet_len; |
| 3406 | |
| 3407 | packet_len = htonl(packet_len); |
| 3408 | memcpy(packet, &packet_len, 4); |
| 3409 | cur_arg += 2; |
| 3410 | } else { |
| 3411 | /* unknown suboption - catchall */ |
| 3412 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'user'.\n", |
| 3413 | file, linenum, args[0], args[1]); |
| 3414 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3415 | goto out; |
| 3416 | } |
| 3417 | } /* end while loop */ |
| 3418 | } |
| 3419 | } |
| 3420 | |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 3421 | else if (!strcmp(args[1], "mysql-check")) { |
| 3422 | /* use MYSQL request to check servers' health */ |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 3423 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 3424 | err_code |= ERR_WARN; |
| 3425 | |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 3426 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 3427 | curproxy->check_req = NULL; |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 3428 | curproxy->options &= ~PR_O_HTTP_CHK; |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 3429 | curproxy->options &= ~PR_O_SMTP_CHK; |
Willy Tarreau | 07a5490 | 2010-03-29 18:33:29 +0200 | [diff] [blame] | 3430 | curproxy->options2 &= ~PR_O2_SSL3_CHK; |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 3431 | curproxy->options2 &= ~PR_O2_LDAP_CHK; |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 3432 | curproxy->options2 &= ~PR_O2_PGSQL_CHK; |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 3433 | curproxy->options2 |= PR_O2_MYSQL_CHK; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 3434 | |
| 3435 | /* This is an exemple of an MySQL >=4.0 client Authentication packet kindly provided by Cyril Bonte. |
| 3436 | * const char mysql40_client_auth_pkt[] = { |
| 3437 | * "\x0e\x00\x00" // packet length |
| 3438 | * "\x01" // packet number |
| 3439 | * "\x00\x00" // client capabilities |
| 3440 | * "\x00\x00\x01" // max packet |
| 3441 | * "haproxy\x00" // username (null terminated string) |
| 3442 | * "\x00" // filler (always 0x00) |
| 3443 | * "\x01\x00\x00" // packet length |
| 3444 | * "\x00" // packet number |
| 3445 | * "\x01" // COM_QUIT command |
| 3446 | * }; |
| 3447 | */ |
| 3448 | |
| 3449 | if (*(args[2])) { |
| 3450 | int cur_arg = 2; |
| 3451 | |
| 3452 | while (*(args[cur_arg])) { |
| 3453 | if (strcmp(args[cur_arg], "user") == 0) { |
| 3454 | char *mysqluser; |
| 3455 | int packetlen, reqlen, userlen; |
| 3456 | |
| 3457 | /* suboption header - needs additional argument for it */ |
| 3458 | if (*(args[cur_arg+1]) == 0) { |
| 3459 | Alert("parsing [%s:%d] : '%s %s %s' expects <username> as argument.\n", |
| 3460 | file, linenum, args[0], args[1], args[cur_arg]); |
| 3461 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3462 | goto out; |
| 3463 | } |
| 3464 | mysqluser = args[cur_arg + 1]; |
| 3465 | userlen = strlen(mysqluser); |
| 3466 | packetlen = userlen + 7; |
| 3467 | reqlen = packetlen + 9; |
| 3468 | |
| 3469 | free(curproxy->check_req); |
| 3470 | curproxy->check_req = (char *)calloc(1, reqlen); |
| 3471 | curproxy->check_len = reqlen; |
| 3472 | |
| 3473 | snprintf(curproxy->check_req, 4, "%c%c%c", |
| 3474 | ((unsigned char) packetlen & 0xff), |
| 3475 | ((unsigned char) (packetlen >> 8) & 0xff), |
| 3476 | ((unsigned char) (packetlen >> 16) & 0xff)); |
| 3477 | |
| 3478 | curproxy->check_req[3] = 1; |
| 3479 | curproxy->check_req[8] = 1; |
| 3480 | memcpy(&curproxy->check_req[9], mysqluser, userlen); |
| 3481 | curproxy->check_req[9 + userlen + 1 + 1] = 1; |
| 3482 | curproxy->check_req[9 + userlen + 1 + 1 + 4] = 1; |
| 3483 | cur_arg += 2; |
| 3484 | } else { |
| 3485 | /* unknown suboption - catchall */ |
| 3486 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'user'.\n", |
| 3487 | file, linenum, args[0], args[1]); |
| 3488 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3489 | goto out; |
| 3490 | } |
| 3491 | } /* end while loop */ |
| 3492 | } |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 3493 | } |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 3494 | else if (!strcmp(args[1], "ldap-check")) { |
| 3495 | /* use LDAP request to check servers' health */ |
| 3496 | free(curproxy->check_req); |
| 3497 | curproxy->check_req = NULL; |
| 3498 | curproxy->options &= ~PR_O_HTTP_CHK; |
| 3499 | curproxy->options &= ~PR_O_SMTP_CHK; |
| 3500 | curproxy->options2 &= ~PR_O2_SSL3_CHK; |
| 3501 | curproxy->options2 &= ~PR_O2_MYSQL_CHK; |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 3502 | curproxy->options2 &= ~PR_O2_PGSQL_CHK; |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 3503 | curproxy->options2 |= PR_O2_LDAP_CHK; |
| 3504 | |
| 3505 | curproxy->check_req = (char *) malloc(sizeof(DEF_LDAP_CHECK_REQ) - 1); |
| 3506 | memcpy(curproxy->check_req, DEF_LDAP_CHECK_REQ, sizeof(DEF_LDAP_CHECK_REQ) - 1); |
| 3507 | curproxy->check_len = sizeof(DEF_LDAP_CHECK_REQ) - 1; |
| 3508 | } |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3509 | else if (!strcmp(args[1], "forwardfor")) { |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3510 | int cur_arg; |
| 3511 | |
| 3512 | /* insert x-forwarded-for field, but not for the IP address listed as an except. |
| 3513 | * set default options (ie: bitfield, header name, etc) |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3514 | */ |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3515 | |
| 3516 | curproxy->options |= PR_O_FWDFOR; |
| 3517 | |
| 3518 | free(curproxy->fwdfor_hdr_name); |
| 3519 | curproxy->fwdfor_hdr_name = strdup(DEF_XFORWARDFOR_HDR); |
| 3520 | curproxy->fwdfor_hdr_len = strlen(DEF_XFORWARDFOR_HDR); |
| 3521 | |
| 3522 | /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */ |
| 3523 | cur_arg = 2; |
| 3524 | while (*(args[cur_arg])) { |
| 3525 | if (!strcmp(args[cur_arg], "except")) { |
| 3526 | /* suboption except - needs additional argument for it */ |
| 3527 | if (!*(args[cur_arg+1]) || !str2net(args[cur_arg+1], &curproxy->except_net, &curproxy->except_mask)) { |
| 3528 | Alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n", |
| 3529 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3530 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3531 | goto out; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3532 | } |
| 3533 | /* flush useless bits */ |
| 3534 | curproxy->except_net.s_addr &= curproxy->except_mask.s_addr; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3535 | cur_arg += 2; |
| 3536 | } else if (!strcmp(args[cur_arg], "header")) { |
| 3537 | /* suboption header - needs additional argument for it */ |
| 3538 | if (*(args[cur_arg+1]) == 0) { |
| 3539 | Alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 3540 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3541 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3542 | goto out; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3543 | } |
| 3544 | free(curproxy->fwdfor_hdr_name); |
| 3545 | curproxy->fwdfor_hdr_name = strdup(args[cur_arg+1]); |
| 3546 | curproxy->fwdfor_hdr_len = strlen(curproxy->fwdfor_hdr_name); |
| 3547 | cur_arg += 2; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3548 | } else { |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3549 | /* unknown suboption - catchall */ |
| 3550 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n", |
| 3551 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3552 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3553 | goto out; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3554 | } |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3555 | } /* end while loop */ |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3556 | } |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 3557 | else if (!strcmp(args[1], "originalto")) { |
| 3558 | int cur_arg; |
| 3559 | |
| 3560 | /* insert x-original-to field, but not for the IP address listed as an except. |
| 3561 | * set default options (ie: bitfield, header name, etc) |
| 3562 | */ |
| 3563 | |
| 3564 | curproxy->options |= PR_O_ORGTO; |
| 3565 | |
| 3566 | free(curproxy->orgto_hdr_name); |
| 3567 | curproxy->orgto_hdr_name = strdup(DEF_XORIGINALTO_HDR); |
| 3568 | curproxy->orgto_hdr_len = strlen(DEF_XORIGINALTO_HDR); |
| 3569 | |
| 3570 | /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */ |
| 3571 | cur_arg = 2; |
| 3572 | while (*(args[cur_arg])) { |
| 3573 | if (!strcmp(args[cur_arg], "except")) { |
| 3574 | /* suboption except - needs additional argument for it */ |
| 3575 | if (!*(args[cur_arg+1]) || !str2net(args[cur_arg+1], &curproxy->except_to, &curproxy->except_mask_to)) { |
| 3576 | Alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n", |
| 3577 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3578 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3579 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 3580 | } |
| 3581 | /* flush useless bits */ |
| 3582 | curproxy->except_to.s_addr &= curproxy->except_mask_to.s_addr; |
| 3583 | cur_arg += 2; |
| 3584 | } else if (!strcmp(args[cur_arg], "header")) { |
| 3585 | /* suboption header - needs additional argument for it */ |
| 3586 | if (*(args[cur_arg+1]) == 0) { |
| 3587 | Alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 3588 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3589 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3590 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 3591 | } |
| 3592 | free(curproxy->orgto_hdr_name); |
| 3593 | curproxy->orgto_hdr_name = strdup(args[cur_arg+1]); |
| 3594 | curproxy->orgto_hdr_len = strlen(curproxy->orgto_hdr_name); |
| 3595 | cur_arg += 2; |
| 3596 | } else { |
| 3597 | /* unknown suboption - catchall */ |
| 3598 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n", |
| 3599 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3600 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3601 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 3602 | } |
| 3603 | } /* end while loop */ |
| 3604 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3605 | else { |
| 3606 | Alert("parsing [%s:%d] : unknown option '%s'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3607 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3608 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3609 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3610 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3611 | } |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 3612 | else if (!strcmp(args[0], "default_backend")) { |
| 3613 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3614 | err_code |= ERR_WARN; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 3615 | |
| 3616 | if (*(args[1]) == 0) { |
| 3617 | 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] | 3618 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3619 | goto out; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 3620 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3621 | free(curproxy->defbe.name); |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 3622 | curproxy->defbe.name = strdup(args[1]); |
| 3623 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3624 | else if (!strcmp(args[0], "redispatch") || !strcmp(args[0], "redisp")) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3625 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3626 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3627 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3628 | Warning("parsing [%s:%d]: keyword '%s' is deprecated, please use 'option redispatch' instead.\n", |
| 3629 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3630 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3631 | /* enable reconnections to dispatch */ |
| 3632 | curproxy->options |= PR_O_REDISP; |
| 3633 | } |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 3634 | else if (!strcmp(args[0], "http-check")) { |
| 3635 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3636 | err_code |= ERR_WARN; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 3637 | |
| 3638 | if (strcmp(args[1], "disable-on-404") == 0) { |
| 3639 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 3640 | curproxy->options |= PR_O_DISABLE404; |
| 3641 | } |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 3642 | else if (strcmp(args[1], "send-state") == 0) { |
| 3643 | /* enable emission of the apparent state of a server in HTTP checks */ |
| 3644 | curproxy->options2 |= PR_O2_CHK_SNDST; |
| 3645 | } |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 3646 | else if (strcmp(args[1], "expect") == 0) { |
| 3647 | const char *ptr_arg; |
| 3648 | int cur_arg; |
| 3649 | |
| 3650 | if (curproxy->options2 & PR_O2_EXP_TYPE) { |
| 3651 | Alert("parsing [%s:%d] : '%s %s' already specified.\n", file, linenum, args[0], args[1]); |
| 3652 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3653 | goto out; |
| 3654 | } |
| 3655 | |
| 3656 | cur_arg = 2; |
| 3657 | /* consider exclamation marks, sole or at the beginning of a word */ |
| 3658 | while (*(ptr_arg = args[cur_arg])) { |
| 3659 | while (*ptr_arg == '!') { |
| 3660 | curproxy->options2 ^= PR_O2_EXP_INV; |
| 3661 | ptr_arg++; |
| 3662 | } |
| 3663 | if (*ptr_arg) |
| 3664 | break; |
| 3665 | cur_arg++; |
| 3666 | } |
| 3667 | /* now ptr_arg points to the beginning of a word past any possible |
| 3668 | * exclamation mark, and cur_arg is the argument which holds this word. |
| 3669 | */ |
| 3670 | if (strcmp(ptr_arg, "status") == 0) { |
| 3671 | if (!*(args[cur_arg + 1])) { |
| 3672 | Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 3673 | file, linenum, args[0], args[1], ptr_arg); |
| 3674 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3675 | goto out; |
| 3676 | } |
| 3677 | curproxy->options2 |= PR_O2_EXP_STS; |
| 3678 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
| 3679 | } |
| 3680 | else if (strcmp(ptr_arg, "string") == 0) { |
| 3681 | if (!*(args[cur_arg + 1])) { |
| 3682 | Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 3683 | file, linenum, args[0], args[1], ptr_arg); |
| 3684 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3685 | goto out; |
| 3686 | } |
| 3687 | curproxy->options2 |= PR_O2_EXP_STR; |
| 3688 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
| 3689 | } |
| 3690 | else if (strcmp(ptr_arg, "rstatus") == 0) { |
| 3691 | if (!*(args[cur_arg + 1])) { |
| 3692 | Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 3693 | file, linenum, args[0], args[1], ptr_arg); |
| 3694 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3695 | goto out; |
| 3696 | } |
| 3697 | curproxy->options2 |= PR_O2_EXP_RSTS; |
| 3698 | curproxy->expect_regex = calloc(1, sizeof(regex_t)); |
| 3699 | if (regcomp(curproxy->expect_regex, args[cur_arg + 1], REG_EXTENDED) != 0) { |
| 3700 | Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s'.\n", |
| 3701 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1]); |
| 3702 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3703 | goto out; |
| 3704 | } |
| 3705 | } |
| 3706 | else if (strcmp(ptr_arg, "rstring") == 0) { |
| 3707 | if (!*(args[cur_arg + 1])) { |
| 3708 | Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 3709 | file, linenum, args[0], args[1], ptr_arg); |
| 3710 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3711 | goto out; |
| 3712 | } |
| 3713 | curproxy->options2 |= PR_O2_EXP_RSTR; |
| 3714 | curproxy->expect_regex = calloc(1, sizeof(regex_t)); |
| 3715 | if (regcomp(curproxy->expect_regex, args[cur_arg + 1], REG_EXTENDED) != 0) { |
| 3716 | Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s'.\n", |
| 3717 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1]); |
| 3718 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3719 | goto out; |
| 3720 | } |
| 3721 | } |
| 3722 | else { |
| 3723 | Alert("parsing [%s:%d] : '%s %s' only supports [!] 'status', 'string', 'rstatus', 'rstring', found '%s'.\n", |
| 3724 | file, linenum, args[0], args[1], ptr_arg); |
| 3725 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3726 | goto out; |
| 3727 | } |
| 3728 | } |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 3729 | else { |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 3730 | Alert("parsing [%s:%d] : '%s' only supports 'disable-on-404', 'expect' .\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3731 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3732 | goto out; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 3733 | } |
| 3734 | } |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3735 | else if (!strcmp(args[0], "monitor")) { |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3736 | if (curproxy == &defproxy) { |
| 3737 | 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] | 3738 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3739 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3740 | } |
| 3741 | |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3742 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3743 | err_code |= ERR_WARN; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3744 | |
| 3745 | if (strcmp(args[1], "fail") == 0) { |
| 3746 | /* add a condition to fail monitor requests */ |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 3747 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3748 | Alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n", |
| 3749 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3750 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3751 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3752 | } |
| 3753 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 3754 | 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] | 3755 | Alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition.\n", |
| 3756 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3757 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3758 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3759 | } |
| 3760 | LIST_ADDQ(&curproxy->mon_fail_cond, &cond->list); |
| 3761 | } |
| 3762 | else { |
| 3763 | 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] | 3764 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3765 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3766 | } |
| 3767 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3768 | #ifdef TPROXY |
| 3769 | else if (!strcmp(args[0], "transparent")) { |
| 3770 | /* enable transparent proxy connections */ |
| 3771 | curproxy->options |= PR_O_TRANSP; |
| 3772 | } |
| 3773 | #endif |
| 3774 | else if (!strcmp(args[0], "maxconn")) { /* maxconn */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3775 | 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] | 3776 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3777 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3778 | if (*(args[1]) == 0) { |
| 3779 | 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] | 3780 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3781 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3782 | } |
| 3783 | curproxy->maxconn = atol(args[1]); |
| 3784 | } |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 3785 | else if (!strcmp(args[0], "backlog")) { /* backlog */ |
| 3786 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3787 | err_code |= ERR_WARN; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 3788 | |
| 3789 | if (*(args[1]) == 0) { |
| 3790 | 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] | 3791 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3792 | goto out; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 3793 | } |
| 3794 | curproxy->backlog = atol(args[1]); |
| 3795 | } |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 3796 | else if (!strcmp(args[0], "fullconn")) { /* fullconn */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3797 | 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] | 3798 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3799 | |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 3800 | if (*(args[1]) == 0) { |
| 3801 | 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] | 3802 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3803 | goto out; |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 3804 | } |
| 3805 | curproxy->fullconn = atol(args[1]); |
| 3806 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3807 | else if (!strcmp(args[0], "grace")) { /* grace time (ms) */ |
| 3808 | if (*(args[1]) == 0) { |
| 3809 | 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] | 3810 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3811 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3812 | } |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 3813 | err = parse_time_err(args[1], &val, TIME_UNIT_MS); |
| 3814 | if (err) { |
| 3815 | Alert("parsing [%s:%d] : unexpected character '%c' in grace time.\n", |
| 3816 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3817 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3818 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 3819 | } |
| 3820 | curproxy->grace = val; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3821 | } |
| 3822 | else if (!strcmp(args[0], "dispatch")) { /* dispatch address */ |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 3823 | struct sockaddr_storage *sk; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3824 | if (curproxy == &defproxy) { |
| 3825 | 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] | 3826 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3827 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3828 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3829 | else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3830 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3831 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3832 | if (strchr(args[1], ':') == NULL) { |
| 3833 | 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] | 3834 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3835 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3836 | } |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 3837 | sk = str2sa(args[1]); |
| 3838 | if (!sk) { |
| 3839 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[1]); |
| 3840 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3841 | goto out; |
| 3842 | } |
| 3843 | curproxy->dispatch_addr = *sk; |
Willy Tarreau | f5ab69a | 2011-03-04 22:44:16 +0100 | [diff] [blame] | 3844 | curproxy->options2 |= PR_O2_DISPATCH; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3845 | } |
| 3846 | else if (!strcmp(args[0], "balance")) { /* set balancing with optional algorithm */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3847 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3848 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3849 | |
Jeffrey 'jf' Lim | 65cb2f1 | 2008-10-04 18:07:00 +0200 | [diff] [blame] | 3850 | memcpy(trash, "error near 'balance'", 21); |
Willy Tarreau | a0cbda6 | 2007-11-01 21:39:54 +0100 | [diff] [blame] | 3851 | if (backend_parse_balance((const char **)args + 1, trash, sizeof(trash), curproxy) < 0) { |
| 3852 | Alert("parsing [%s:%d] : %s\n", file, linenum, trash); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3853 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3854 | goto out; |
Willy Tarreau | 2fcb500 | 2007-05-08 13:35:26 +0200 | [diff] [blame] | 3855 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3856 | } |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 3857 | else if (!strcmp(args[0], "hash-type")) { /* set hashing method */ |
| 3858 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 3859 | err_code |= ERR_WARN; |
| 3860 | |
| 3861 | if (strcmp(args[1], "consistent") == 0) { /* use consistent hashing */ |
| 3862 | curproxy->lbprm.algo &= ~BE_LB_HASH_TYPE; |
| 3863 | curproxy->lbprm.algo |= BE_LB_HASH_CONS; |
| 3864 | } |
| 3865 | else if (strcmp(args[1], "map-based") == 0) { /* use map-based hashing */ |
| 3866 | curproxy->lbprm.algo &= ~BE_LB_HASH_TYPE; |
| 3867 | curproxy->lbprm.algo |= BE_LB_HASH_MAP; |
| 3868 | } |
Willy Tarreau | 798a39c | 2010-11-24 15:04:29 +0100 | [diff] [blame] | 3869 | else if (strcmp(args[1], "avalanche") == 0) { /* use full hash before map-based hashing */ |
| 3870 | curproxy->lbprm.algo &= ~BE_LB_HASH_TYPE; |
| 3871 | curproxy->lbprm.algo |= BE_LB_HASH_AVAL; |
| 3872 | } |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 3873 | else { |
Willy Tarreau | 798a39c | 2010-11-24 15:04:29 +0100 | [diff] [blame] | 3874 | 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] | 3875 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3876 | goto out; |
| 3877 | } |
| 3878 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3879 | 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] | 3880 | int cur_arg; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3881 | char *rport, *raddr; |
| 3882 | short realport = 0; |
| 3883 | int do_check = 0, defsrv = (*args[0] == 'd'); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3884 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3885 | if (!defsrv && curproxy == &defproxy) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3886 | 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] | 3887 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3888 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3889 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3890 | else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3891 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3892 | |
| 3893 | if (!*args[2]) { |
| 3894 | Alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n", |
| 3895 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3896 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3897 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3898 | } |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 3899 | |
| 3900 | err = invalid_char(args[1]); |
| 3901 | if (err) { |
| 3902 | Alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n", |
| 3903 | file, linenum, *err, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3904 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3905 | goto out; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 3906 | } |
| 3907 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3908 | if (!defsrv) { |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 3909 | struct sockaddr_storage *sk; |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 3910 | |
Krzysztof Piotr Oledzki | aff01ea | 2010-02-05 20:31:44 +0100 | [diff] [blame] | 3911 | if ((newsrv = (struct server *)calloc(1, sizeof(struct server))) == NULL) { |
| 3912 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 3913 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3914 | goto out; |
| 3915 | } |
| 3916 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3917 | /* the servers are linked backwards first */ |
| 3918 | newsrv->next = curproxy->srv; |
| 3919 | curproxy->srv = newsrv; |
| 3920 | newsrv->proxy = curproxy; |
| 3921 | newsrv->conf.file = file; |
| 3922 | newsrv->conf.line = linenum; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3923 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3924 | LIST_INIT(&newsrv->pendconns); |
| 3925 | do_check = 0; |
| 3926 | newsrv->state = SRV_RUNNING; /* early server setup */ |
| 3927 | newsrv->last_change = now.tv_sec; |
| 3928 | newsrv->id = strdup(args[1]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3929 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3930 | /* several ways to check the port component : |
David du Colombier | 9842ff1 | 2011-03-17 10:40:28 +0100 | [diff] [blame] | 3931 | * - IP => port=+0, relative (IPv4 only) |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3932 | * - IP: => port=+0, relative |
| 3933 | * - IP:N => port=N, absolute |
| 3934 | * - IP:+N => port=+N, relative |
| 3935 | * - IP:-N => port=-N, relative |
| 3936 | */ |
| 3937 | raddr = strdup(args[2]); |
Willy Tarreau | fab5a43 | 2011-03-04 15:31:53 +0100 | [diff] [blame] | 3938 | rport = strrchr(raddr, ':'); |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3939 | if (rport) { |
| 3940 | *rport++ = 0; |
| 3941 | realport = atol(rport); |
| 3942 | if (!isdigit((unsigned char)*rport)) |
| 3943 | newsrv->state |= SRV_MAPPORTS; |
| 3944 | } else |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3945 | newsrv->state |= SRV_MAPPORTS; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3946 | |
Willy Tarreau | fab5a43 | 2011-03-04 15:31:53 +0100 | [diff] [blame] | 3947 | sk = str2ip(raddr); |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3948 | free(raddr); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 3949 | if (!sk) { |
| 3950 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[2]); |
| 3951 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3952 | goto out; |
| 3953 | } |
| 3954 | newsrv->addr = *sk; |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 3955 | |
| 3956 | switch (newsrv->addr.ss_family) { |
| 3957 | case AF_INET: |
| 3958 | ((struct sockaddr_in *)&newsrv->addr)->sin_port = htons(realport); |
| 3959 | break; |
| 3960 | case AF_INET6: |
| 3961 | ((struct sockaddr_in6 *)&newsrv->addr)->sin6_port = htons(realport); |
| 3962 | break; |
| 3963 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3964 | |
| 3965 | newsrv->check_port = curproxy->defsrv.check_port; |
| 3966 | newsrv->inter = curproxy->defsrv.inter; |
| 3967 | newsrv->fastinter = curproxy->defsrv.fastinter; |
| 3968 | newsrv->downinter = curproxy->defsrv.downinter; |
| 3969 | newsrv->rise = curproxy->defsrv.rise; |
| 3970 | newsrv->fall = curproxy->defsrv.fall; |
| 3971 | newsrv->maxqueue = curproxy->defsrv.maxqueue; |
| 3972 | newsrv->minconn = curproxy->defsrv.minconn; |
| 3973 | newsrv->maxconn = curproxy->defsrv.maxconn; |
| 3974 | newsrv->slowstart = curproxy->defsrv.slowstart; |
| 3975 | newsrv->onerror = curproxy->defsrv.onerror; |
| 3976 | newsrv->consecutive_errors_limit |
| 3977 | = curproxy->defsrv.consecutive_errors_limit; |
| 3978 | newsrv->uweight = newsrv->iweight |
| 3979 | = curproxy->defsrv.iweight; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3980 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3981 | newsrv->curfd = -1; /* no health-check in progress */ |
| 3982 | newsrv->health = newsrv->rise; /* up, but will fall down at first failure */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3983 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3984 | cur_arg = 3; |
| 3985 | } else { |
| 3986 | newsrv = &curproxy->defsrv; |
| 3987 | cur_arg = 1; |
| 3988 | } |
Willy Tarreau | 0f03c6f | 2007-03-25 20:46:19 +0200 | [diff] [blame] | 3989 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3990 | while (*args[cur_arg]) { |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3991 | if (!defsrv && !strcmp(args[cur_arg], "id")) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 3992 | struct eb32_node *node; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3993 | |
| 3994 | if (!*args[cur_arg + 1]) { |
| 3995 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 3996 | file, linenum, args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3997 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3998 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3999 | } |
| 4000 | |
| 4001 | newsrv->puid = atol(args[cur_arg + 1]); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 4002 | newsrv->conf.id.key = newsrv->puid; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 4003 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 4004 | if (newsrv->puid <= 0) { |
| 4005 | Alert("parsing [%s:%d]: custom id has to be > 0.\n", |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 4006 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4007 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4008 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 4009 | } |
| 4010 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 4011 | node = eb32_lookup(&curproxy->conf.used_server_id, newsrv->puid); |
| 4012 | if (node) { |
| 4013 | struct server *target = container_of(node, struct server, conf.id); |
| 4014 | Alert("parsing [%s:%d]: server %s reuses same custom id as server %s (declared at %s:%d).\n", |
| 4015 | file, linenum, newsrv->id, target->id, target->conf.file, target->conf.line); |
| 4016 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4017 | goto out; |
| 4018 | } |
| 4019 | eb32_insert(&curproxy->conf.used_server_id, &newsrv->conf.id); |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 4020 | cur_arg += 2; |
| 4021 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4022 | else if (!defsrv && !strcmp(args[cur_arg], "cookie")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4023 | newsrv->cookie = strdup(args[cur_arg + 1]); |
| 4024 | newsrv->cklen = strlen(args[cur_arg + 1]); |
| 4025 | cur_arg += 2; |
| 4026 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4027 | else if (!defsrv && !strcmp(args[cur_arg], "redir")) { |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 4028 | newsrv->rdr_pfx = strdup(args[cur_arg + 1]); |
| 4029 | newsrv->rdr_len = strlen(args[cur_arg + 1]); |
| 4030 | cur_arg += 2; |
| 4031 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4032 | else if (!strcmp(args[cur_arg], "rise")) { |
Krzysztof Piotr Oledzki | 08ff959 | 2009-09-27 16:17:31 +0200 | [diff] [blame] | 4033 | if (!*args[cur_arg + 1]) { |
| 4034 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 4035 | file, linenum, args[cur_arg]); |
| 4036 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4037 | goto out; |
| 4038 | } |
| 4039 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4040 | newsrv->rise = atol(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 08ff959 | 2009-09-27 16:17:31 +0200 | [diff] [blame] | 4041 | if (newsrv->rise <= 0) { |
| 4042 | Alert("parsing [%s:%d]: '%s' has to be > 0.\n", |
| 4043 | file, linenum, args[cur_arg]); |
| 4044 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4045 | goto out; |
| 4046 | } |
| 4047 | |
Willy Tarreau | 9683909 | 2010-03-29 10:02:24 +0200 | [diff] [blame] | 4048 | if (newsrv->health) |
| 4049 | newsrv->health = newsrv->rise; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4050 | cur_arg += 2; |
| 4051 | } |
| 4052 | else if (!strcmp(args[cur_arg], "fall")) { |
| 4053 | newsrv->fall = atol(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 08ff959 | 2009-09-27 16:17:31 +0200 | [diff] [blame] | 4054 | |
| 4055 | if (!*args[cur_arg + 1]) { |
| 4056 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 4057 | file, linenum, args[cur_arg]); |
| 4058 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4059 | goto out; |
| 4060 | } |
| 4061 | |
| 4062 | if (newsrv->fall <= 0) { |
| 4063 | Alert("parsing [%s:%d]: '%s' has to be > 0.\n", |
| 4064 | file, linenum, args[cur_arg]); |
| 4065 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4066 | goto out; |
| 4067 | } |
| 4068 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4069 | cur_arg += 2; |
| 4070 | } |
| 4071 | else if (!strcmp(args[cur_arg], "inter")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4072 | const char *err = parse_time_err(args[cur_arg + 1], &val, TIME_UNIT_MS); |
| 4073 | if (err) { |
| 4074 | Alert("parsing [%s:%d] : unexpected character '%c' in 'inter' argument of server %s.\n", |
| 4075 | file, linenum, *err, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4076 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4077 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4078 | } |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4079 | if (val <= 0) { |
| 4080 | Alert("parsing [%s:%d]: invalid value %d for argument '%s' of server %s.\n", |
| 4081 | file, linenum, val, args[cur_arg], newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4082 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4083 | goto out; |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4084 | } |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4085 | newsrv->inter = val; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4086 | cur_arg += 2; |
| 4087 | } |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 4088 | else if (!strcmp(args[cur_arg], "fastinter")) { |
| 4089 | const char *err = parse_time_err(args[cur_arg + 1], &val, TIME_UNIT_MS); |
| 4090 | if (err) { |
| 4091 | Alert("parsing [%s:%d]: unexpected character '%c' in 'fastinter' argument of server %s.\n", |
| 4092 | file, linenum, *err, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4093 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4094 | goto out; |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 4095 | } |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4096 | if (val <= 0) { |
| 4097 | Alert("parsing [%s:%d]: invalid value %d for argument '%s' of server %s.\n", |
| 4098 | file, linenum, val, args[cur_arg], newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4099 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4100 | goto out; |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4101 | } |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 4102 | newsrv->fastinter = val; |
| 4103 | cur_arg += 2; |
| 4104 | } |
| 4105 | else if (!strcmp(args[cur_arg], "downinter")) { |
| 4106 | const char *err = parse_time_err(args[cur_arg + 1], &val, TIME_UNIT_MS); |
| 4107 | if (err) { |
| 4108 | Alert("parsing [%s:%d]: unexpected character '%c' in 'downinter' argument of server %s.\n", |
| 4109 | file, linenum, *err, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4110 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4111 | goto out; |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 4112 | } |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4113 | if (val <= 0) { |
| 4114 | Alert("parsing [%s:%d]: invalid value %d for argument '%s' of server %s.\n", |
| 4115 | file, linenum, val, args[cur_arg], newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4116 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4117 | goto out; |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4118 | } |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 4119 | newsrv->downinter = val; |
| 4120 | cur_arg += 2; |
| 4121 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4122 | else if (!defsrv && !strcmp(args[cur_arg], "addr")) { |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4123 | struct sockaddr_storage *sk = str2sa(args[cur_arg + 1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4124 | if (!sk) { |
| 4125 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[cur_arg + 1]); |
| 4126 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4127 | goto out; |
| 4128 | } |
| 4129 | newsrv->check_addr = *sk; |
Willy Tarreau | 2ea3abb | 2007-03-25 16:45:16 +0200 | [diff] [blame] | 4130 | cur_arg += 2; |
| 4131 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4132 | else if (!strcmp(args[cur_arg], "port")) { |
| 4133 | newsrv->check_port = atol(args[cur_arg + 1]); |
| 4134 | cur_arg += 2; |
| 4135 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4136 | else if (!defsrv && !strcmp(args[cur_arg], "backup")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4137 | newsrv->state |= SRV_BACKUP; |
| 4138 | cur_arg ++; |
| 4139 | } |
Willy Tarreau | 5ab04ec | 2011-03-20 10:32:26 +0100 | [diff] [blame] | 4140 | else if (!defsrv && !strcmp(args[cur_arg], "send-proxy")) { |
| 4141 | newsrv->state |= SRV_SEND_PROXY; |
| 4142 | cur_arg ++; |
| 4143 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4144 | else if (!strcmp(args[cur_arg], "weight")) { |
| 4145 | int w; |
| 4146 | w = atol(args[cur_arg + 1]); |
Willy Tarreau | 6704d67 | 2009-06-15 10:56:05 +0200 | [diff] [blame] | 4147 | if (w < 0 || w > 256) { |
| 4148 | 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] | 4149 | file, linenum, newsrv->id, w); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4150 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4151 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4152 | } |
Willy Tarreau | 975c50b | 2009-10-10 19:34:06 +0200 | [diff] [blame] | 4153 | newsrv->uweight = newsrv->iweight = w; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4154 | cur_arg += 2; |
| 4155 | } |
| 4156 | else if (!strcmp(args[cur_arg], "minconn")) { |
| 4157 | newsrv->minconn = atol(args[cur_arg + 1]); |
| 4158 | cur_arg += 2; |
| 4159 | } |
| 4160 | else if (!strcmp(args[cur_arg], "maxconn")) { |
| 4161 | newsrv->maxconn = atol(args[cur_arg + 1]); |
| 4162 | cur_arg += 2; |
| 4163 | } |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 4164 | else if (!strcmp(args[cur_arg], "maxqueue")) { |
| 4165 | newsrv->maxqueue = atol(args[cur_arg + 1]); |
| 4166 | cur_arg += 2; |
| 4167 | } |
Willy Tarreau | 9909fc1 | 2007-11-30 17:42:05 +0100 | [diff] [blame] | 4168 | else if (!strcmp(args[cur_arg], "slowstart")) { |
| 4169 | /* slowstart is stored in seconds */ |
Willy Tarreau | 3259e33 | 2007-12-03 01:51:45 +0100 | [diff] [blame] | 4170 | 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] | 4171 | if (err) { |
| 4172 | Alert("parsing [%s:%d] : unexpected character '%c' in 'slowstart' argument of server %s.\n", |
| 4173 | file, linenum, *err, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4174 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4175 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4176 | } |
Willy Tarreau | 4554bc1 | 2010-03-26 10:40:49 +0100 | [diff] [blame] | 4177 | if (val < 0) { |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4178 | Alert("parsing [%s:%d]: invalid value %d for argument '%s' of server %s.\n", |
| 4179 | file, linenum, val, args[cur_arg], newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4180 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4181 | goto out; |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4182 | } |
Willy Tarreau | 3259e33 | 2007-12-03 01:51:45 +0100 | [diff] [blame] | 4183 | newsrv->slowstart = (val + 999) / 1000; |
Willy Tarreau | 9909fc1 | 2007-11-30 17:42:05 +0100 | [diff] [blame] | 4184 | cur_arg += 2; |
| 4185 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4186 | else if (!defsrv && !strcmp(args[cur_arg], "track")) { |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4187 | |
| 4188 | if (!*args[cur_arg + 1]) { |
| 4189 | Alert("parsing [%s:%d]: 'track' expects [<proxy>/]<server> as argument.\n", |
| 4190 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4191 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4192 | goto out; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4193 | } |
| 4194 | |
| 4195 | newsrv->trackit = strdup(args[cur_arg + 1]); |
| 4196 | |
| 4197 | cur_arg += 2; |
| 4198 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4199 | else if (!defsrv && !strcmp(args[cur_arg], "check")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4200 | global.maxsock++; |
| 4201 | do_check = 1; |
| 4202 | cur_arg += 1; |
| 4203 | } |
Willy Tarreau | 9683909 | 2010-03-29 10:02:24 +0200 | [diff] [blame] | 4204 | else if (!defsrv && !strcmp(args[cur_arg], "disabled")) { |
| 4205 | newsrv->state |= SRV_MAINTAIN; |
| 4206 | newsrv->state &= ~SRV_RUNNING; |
| 4207 | newsrv->health = 0; |
| 4208 | cur_arg += 1; |
| 4209 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4210 | else if (!defsrv && !strcmp(args[cur_arg], "observe")) { |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 4211 | if (!strcmp(args[cur_arg + 1], "none")) |
| 4212 | newsrv->observe = HANA_OBS_NONE; |
| 4213 | else if (!strcmp(args[cur_arg + 1], "layer4")) |
| 4214 | newsrv->observe = HANA_OBS_LAYER4; |
| 4215 | else if (!strcmp(args[cur_arg + 1], "layer7")) { |
| 4216 | if (curproxy->mode != PR_MODE_HTTP) { |
| 4217 | Alert("parsing [%s:%d]: '%s' can only be used in http proxies.\n", |
| 4218 | file, linenum, args[cur_arg + 1]); |
| 4219 | err_code |= ERR_ALERT; |
| 4220 | } |
| 4221 | newsrv->observe = HANA_OBS_LAYER7; |
| 4222 | } |
| 4223 | else { |
| 4224 | Alert("parsing [%s:%d]: '%s' expects one of 'none', " |
Willy Tarreau | 53621e0 | 2010-10-22 14:53:40 +0200 | [diff] [blame] | 4225 | "'layer4', 'layer7' but got '%s'\n", |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 4226 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
| 4227 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4228 | goto out; |
| 4229 | } |
| 4230 | |
| 4231 | cur_arg += 2; |
| 4232 | } |
| 4233 | else if (!strcmp(args[cur_arg], "on-error")) { |
| 4234 | if (!strcmp(args[cur_arg + 1], "fastinter")) |
| 4235 | newsrv->onerror = HANA_ONERR_FASTINTER; |
| 4236 | else if (!strcmp(args[cur_arg + 1], "fail-check")) |
| 4237 | newsrv->onerror = HANA_ONERR_FAILCHK; |
| 4238 | else if (!strcmp(args[cur_arg + 1], "sudden-death")) |
| 4239 | newsrv->onerror = HANA_ONERR_SUDDTH; |
| 4240 | else if (!strcmp(args[cur_arg + 1], "mark-down")) |
| 4241 | newsrv->onerror = HANA_ONERR_MARKDWN; |
| 4242 | else { |
| 4243 | Alert("parsing [%s:%d]: '%s' expects one of 'fastinter', " |
Willy Tarreau | 53621e0 | 2010-10-22 14:53:40 +0200 | [diff] [blame] | 4244 | "'fail-check', 'sudden-death' or 'mark-down' but got '%s'\n", |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 4245 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
| 4246 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4247 | goto out; |
| 4248 | } |
| 4249 | |
| 4250 | cur_arg += 2; |
| 4251 | } |
| 4252 | else if (!strcmp(args[cur_arg], "error-limit")) { |
| 4253 | if (!*args[cur_arg + 1]) { |
| 4254 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 4255 | file, linenum, args[cur_arg]); |
| 4256 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4257 | goto out; |
| 4258 | } |
| 4259 | |
| 4260 | newsrv->consecutive_errors_limit = atoi(args[cur_arg + 1]); |
| 4261 | |
| 4262 | if (newsrv->consecutive_errors_limit <= 0) { |
| 4263 | Alert("parsing [%s:%d]: %s has to be > 0.\n", |
| 4264 | file, linenum, args[cur_arg]); |
| 4265 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4266 | goto out; |
| 4267 | } |
Willy Tarreau | f53b25d | 2010-03-15 19:40:37 +0100 | [diff] [blame] | 4268 | cur_arg += 2; |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 4269 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4270 | 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] | 4271 | int port_low, port_high; |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4272 | struct sockaddr_storage *sk; |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4273 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4274 | if (!*args[cur_arg + 1]) { |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4275 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 4276 | 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] | 4277 | file, linenum, "source", "usesrc"); |
| 4278 | #else |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 4279 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>[-<port>]] as argument.\n", |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4280 | file, linenum, "source"); |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 4281 | #endif |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4282 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4283 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4284 | } |
| 4285 | newsrv->state |= SRV_BIND_SRC; |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4286 | sk = str2sa_range(args[cur_arg + 1], &port_low, &port_high); |
| 4287 | if (!sk) { |
| 4288 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[cur_arg + 1]); |
| 4289 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4290 | goto out; |
| 4291 | } |
| 4292 | newsrv->source_addr = *sk; |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 4293 | |
| 4294 | if (port_low != port_high) { |
| 4295 | int i; |
| 4296 | if (port_low <= 0 || port_low > 65535 || |
| 4297 | port_high <= 0 || port_high > 65535 || |
| 4298 | port_low > port_high) { |
| 4299 | Alert("parsing [%s:%d] : invalid source port range %d-%d.\n", |
| 4300 | file, linenum, port_low, port_high); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4301 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4302 | goto out; |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 4303 | } |
| 4304 | newsrv->sport_range = port_range_alloc_range(port_high - port_low + 1); |
| 4305 | for (i = 0; i < newsrv->sport_range->size; i++) |
| 4306 | newsrv->sport_range->ports[i] = port_low + i; |
| 4307 | } |
| 4308 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4309 | cur_arg += 2; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4310 | while (*(args[cur_arg])) { |
| 4311 | if (!strcmp(args[cur_arg], "usesrc")) { /* address to use outside */ |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4312 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) |
| 4313 | #if !defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4314 | if (newsrv->source_addr.sin_addr.s_addr == INADDR_ANY) { |
| 4315 | Alert("parsing [%s:%d] : '%s' requires an explicit '%s' address.\n", |
| 4316 | file, linenum, "usesrc", "source"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4317 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4318 | goto out; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4319 | } |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4320 | #endif |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4321 | if (!*args[cur_arg + 1]) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4322 | 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] | 4323 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4324 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4325 | goto out; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4326 | } |
| 4327 | if (!strcmp(args[cur_arg + 1], "client")) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4328 | newsrv->state &= ~SRV_TPROXY_MASK; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4329 | newsrv->state |= SRV_TPROXY_CLI; |
| 4330 | } else if (!strcmp(args[cur_arg + 1], "clientip")) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4331 | newsrv->state &= ~SRV_TPROXY_MASK; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4332 | newsrv->state |= SRV_TPROXY_CIP; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4333 | } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) { |
| 4334 | char *name, *end; |
| 4335 | |
| 4336 | name = args[cur_arg+1] + 7; |
| 4337 | while (isspace(*name)) |
| 4338 | name++; |
| 4339 | |
| 4340 | end = name; |
| 4341 | while (*end && !isspace(*end) && *end != ',' && *end != ')') |
| 4342 | end++; |
| 4343 | |
| 4344 | newsrv->state &= ~SRV_TPROXY_MASK; |
| 4345 | newsrv->state |= SRV_TPROXY_DYN; |
| 4346 | newsrv->bind_hdr_name = calloc(1, end - name + 1); |
| 4347 | newsrv->bind_hdr_len = end - name; |
| 4348 | memcpy(newsrv->bind_hdr_name, name, end - name); |
| 4349 | newsrv->bind_hdr_name[end-name] = '\0'; |
| 4350 | newsrv->bind_hdr_occ = -1; |
| 4351 | |
| 4352 | /* now look for an occurrence number */ |
| 4353 | while (isspace(*end)) |
| 4354 | end++; |
| 4355 | if (*end == ',') { |
| 4356 | end++; |
| 4357 | name = end; |
| 4358 | if (*end == '-') |
| 4359 | end++; |
| 4360 | while (isdigit(*end)) |
| 4361 | end++; |
| 4362 | newsrv->bind_hdr_occ = strl2ic(name, end-name); |
| 4363 | } |
| 4364 | |
| 4365 | if (newsrv->bind_hdr_occ < -MAX_HDR_HISTORY) { |
| 4366 | Alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative" |
| 4367 | " occurrences values smaller than %d.\n", |
| 4368 | file, linenum, MAX_HDR_HISTORY); |
| 4369 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4370 | goto out; |
| 4371 | } |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4372 | } else { |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4373 | struct sockaddr_storage *sk = str2sa(args[cur_arg + 1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4374 | if (!sk) { |
| 4375 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[cur_arg + 1]); |
| 4376 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4377 | goto out; |
| 4378 | } |
| 4379 | newsrv->tproxy_addr = *sk; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4380 | newsrv->state |= SRV_TPROXY_ADDR; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4381 | } |
| 4382 | global.last_checks |= LSTCHK_NETADM; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4383 | #if !defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4384 | global.last_checks |= LSTCHK_CTTPROXY; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4385 | #endif |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4386 | cur_arg += 2; |
| 4387 | continue; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4388 | #else /* no TPROXY support */ |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4389 | 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] | 4390 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4391 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4392 | goto out; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4393 | #endif /* defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) */ |
| 4394 | } /* "usesrc" */ |
| 4395 | |
| 4396 | if (!strcmp(args[cur_arg], "interface")) { /* specifically bind to this interface */ |
| 4397 | #ifdef SO_BINDTODEVICE |
| 4398 | if (!*args[cur_arg + 1]) { |
| 4399 | Alert("parsing [%s:%d] : '%s' : missing interface name.\n", |
| 4400 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4401 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4402 | goto out; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4403 | } |
| 4404 | if (newsrv->iface_name) |
| 4405 | free(newsrv->iface_name); |
| 4406 | |
| 4407 | newsrv->iface_name = strdup(args[cur_arg + 1]); |
| 4408 | newsrv->iface_len = strlen(newsrv->iface_name); |
| 4409 | global.last_checks |= LSTCHK_NETADM; |
| 4410 | #else |
| 4411 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 4412 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4413 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4414 | goto out; |
Willy Tarreau | 77074d5 | 2006-11-12 23:57:19 +0100 | [diff] [blame] | 4415 | #endif |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4416 | cur_arg += 2; |
| 4417 | continue; |
| 4418 | } |
| 4419 | /* this keyword in not an option of "source" */ |
| 4420 | break; |
| 4421 | } /* while */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4422 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4423 | 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] | 4424 | Alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n", |
| 4425 | file, linenum, "usesrc", "source"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4426 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4427 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 4428 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4429 | else { |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4430 | if (!defsrv) |
Willy Tarreau | 5ab04ec | 2011-03-20 10:32:26 +0100 | [diff] [blame] | 4431 | Alert("parsing [%s:%d] : server %s only supports options 'backup', 'cookie', 'redir', 'observer', 'on-error', '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] | 4432 | file, linenum, newsrv->id); |
| 4433 | else |
Krzysztof Piotr Oledzki | a9389b1 | 2010-01-05 16:44:17 +0100 | [diff] [blame] | 4434 | 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] | 4435 | file, linenum); |
| 4436 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4437 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4438 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4439 | } |
| 4440 | } |
| 4441 | |
| 4442 | if (do_check) { |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4443 | if (newsrv->trackit) { |
| 4444 | Alert("parsing [%s:%d]: unable to enable checks and tracking at the same time!\n", |
| 4445 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4446 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4447 | goto out; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4448 | } |
| 4449 | |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4450 | switch (newsrv->check_addr.ss_family) { |
| 4451 | case AF_INET: |
| 4452 | if (!newsrv->check_port && ((struct sockaddr_in *)&newsrv->check_addr)->sin_port) |
| 4453 | newsrv->check_port = ntohs(((struct sockaddr_in *)&newsrv->check_addr)->sin_port); |
| 4454 | break; |
| 4455 | case AF_INET6: |
| 4456 | if (!newsrv->check_port && ((struct sockaddr_in6 *)&newsrv->check_addr)->sin6_port) |
| 4457 | newsrv->check_port = ntohs(((struct sockaddr_in6 *)&newsrv->check_addr)->sin6_port); |
| 4458 | break; |
| 4459 | } |
Willy Tarreau | 0f03c6f | 2007-03-25 20:46:19 +0200 | [diff] [blame] | 4460 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4461 | if (!newsrv->check_port && !(newsrv->state & SRV_MAPPORTS)) |
| 4462 | newsrv->check_port = realport; /* by default */ |
| 4463 | if (!newsrv->check_port) { |
Willy Tarreau | ef00b50 | 2007-01-07 02:40:09 +0100 | [diff] [blame] | 4464 | /* not yet valid, because no port was set on |
| 4465 | * the server either. We'll check if we have |
| 4466 | * a known port on the first listener. |
| 4467 | */ |
| 4468 | struct listener *l; |
| 4469 | l = curproxy->listen; |
| 4470 | if (l) { |
| 4471 | int port; |
| 4472 | port = (l->addr.ss_family == AF_INET6) |
| 4473 | ? ntohs(((struct sockaddr_in6 *)(&l->addr))->sin6_port) |
| 4474 | : ntohs(((struct sockaddr_in *)(&l->addr))->sin_port); |
| 4475 | newsrv->check_port = port; |
| 4476 | } |
| 4477 | } |
| 4478 | if (!newsrv->check_port) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4479 | Alert("parsing [%s:%d] : server %s has neither service port nor check port. Check has been disabled.\n", |
| 4480 | file, linenum, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4481 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4482 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4483 | } |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 4484 | |
Cyril Bonté | c9f825f | 2010-03-17 18:56:31 +0100 | [diff] [blame] | 4485 | /* Allocate buffer for partial check results... */ |
Willy Tarreau | 43961d5 | 2010-10-04 20:39:20 +0200 | [diff] [blame] | 4486 | if ((newsrv->check_data = calloc(global.tune.chksize, sizeof(char))) == NULL) { |
Cyril Bonté | c9f825f | 2010-03-17 18:56:31 +0100 | [diff] [blame] | 4487 | Alert("parsing [%s:%d] : out of memory while allocating check buffer.\n", file, linenum); |
| 4488 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4489 | goto out; |
| 4490 | } |
| 4491 | |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 4492 | newsrv->check_status = HCHK_STATUS_INI; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4493 | newsrv->state |= SRV_CHECKED; |
| 4494 | } |
| 4495 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4496 | if (!defsrv) { |
| 4497 | if (newsrv->state & SRV_BACKUP) |
| 4498 | curproxy->srv_bck++; |
| 4499 | else |
| 4500 | curproxy->srv_act++; |
Willy Tarreau | b625a08 | 2007-11-26 01:15:43 +0100 | [diff] [blame] | 4501 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4502 | newsrv->prev_state = newsrv->state; |
| 4503 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4504 | } |
| 4505 | else if (!strcmp(args[0], "log")) { /* syslog server address */ |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 4506 | struct logsrv logsrv; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4507 | int facility; |
| 4508 | |
| 4509 | if (*(args[1]) && *(args[2]) == 0 && !strcmp(args[1], "global")) { |
| 4510 | curproxy->logfac1 = global.logfac1; |
| 4511 | curproxy->logsrv1 = global.logsrv1; |
| 4512 | curproxy->loglev1 = global.loglev1; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 4513 | curproxy->minlvl1 = global.minlvl1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4514 | curproxy->logfac2 = global.logfac2; |
| 4515 | curproxy->logsrv2 = global.logsrv2; |
| 4516 | curproxy->loglev2 = global.loglev2; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 4517 | curproxy->minlvl2 = global.minlvl2; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4518 | } |
| 4519 | else if (*(args[1]) && *(args[2])) { |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 4520 | int level, minlvl; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4521 | |
| 4522 | facility = get_log_facility(args[2]); |
| 4523 | if (facility < 0) { |
| 4524 | Alert("parsing [%s:%d] : unknown log facility '%s'\n", file, linenum, args[2]); |
| 4525 | exit(1); |
| 4526 | } |
| 4527 | |
| 4528 | level = 7; /* max syslog level = debug */ |
| 4529 | if (*(args[3])) { |
| 4530 | level = get_log_level(args[3]); |
| 4531 | if (level < 0) { |
| 4532 | Alert("parsing [%s:%d] : unknown optional log level '%s'\n", file, linenum, args[3]); |
| 4533 | exit(1); |
| 4534 | } |
| 4535 | } |
| 4536 | |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 4537 | minlvl = 0; /* limit syslog level to this level (emerg) */ |
| 4538 | if (*(args[4])) { |
| 4539 | minlvl = get_log_level(args[4]); |
| 4540 | if (level < 0) { |
| 4541 | Alert("parsing [%s:%d] : unknown optional minimum log level '%s'\n", file, linenum, args[4]); |
| 4542 | exit(1); |
| 4543 | } |
| 4544 | } |
| 4545 | |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 4546 | if (args[1][0] == '/') { |
David du Colombier | 11bcb6c | 2011-03-24 12:23:00 +0100 | [diff] [blame] | 4547 | struct sockaddr_storage *sk = (struct sockaddr_storage *)str2sun(args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4548 | if (!sk) { |
| 4549 | 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] | 4550 | args[1], (int)sizeof(((struct sockaddr_un *)sk)->sun_path) - 1); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4551 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4552 | goto out; |
| 4553 | } |
David du Colombier | 11bcb6c | 2011-03-24 12:23:00 +0100 | [diff] [blame] | 4554 | logsrv.addr = *sk; |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 4555 | } else { |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4556 | struct sockaddr_storage *sk = str2sa(args[1]); |
David du Colombier | 11bcb6c | 2011-03-24 12:23:00 +0100 | [diff] [blame] | 4557 | if (!sk) { |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4558 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[1]); |
| 4559 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4560 | goto out; |
| 4561 | } |
David du Colombier | 11bcb6c | 2011-03-24 12:23:00 +0100 | [diff] [blame] | 4562 | logsrv.addr = *sk; |
| 4563 | if (!get_host_port(&logsrv.addr)) |
| 4564 | set_host_port(&logsrv.addr, SYSLOG_PORT); |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 4565 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4566 | |
| 4567 | if (curproxy->logfac1 == -1) { |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 4568 | curproxy->logsrv1 = logsrv; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4569 | curproxy->logfac1 = facility; |
| 4570 | curproxy->loglev1 = level; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 4571 | curproxy->minlvl1 = minlvl; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4572 | } |
| 4573 | else if (curproxy->logfac2 == -1) { |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 4574 | curproxy->logsrv2 = logsrv; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4575 | curproxy->logfac2 = facility; |
| 4576 | curproxy->loglev2 = level; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 4577 | curproxy->minlvl2 = minlvl; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4578 | } |
| 4579 | else { |
| 4580 | Alert("parsing [%s:%d] : too many syslog servers\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4581 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4582 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4583 | } |
| 4584 | } |
| 4585 | else { |
| 4586 | Alert("parsing [%s:%d] : 'log' expects either <address[:port]> and <facility> or 'global' as arguments.\n", |
| 4587 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4588 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4589 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4590 | } |
| 4591 | } |
| 4592 | 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] | 4593 | int cur_arg; |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4594 | struct sockaddr_storage *sk; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4595 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4596 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4597 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4598 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4599 | if (!*args[1]) { |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4600 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optionally '%s' <addr>, and '%s' <name>.\n", |
| 4601 | file, linenum, "source", "usesrc", "interface"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4602 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4603 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4604 | } |
Willy Tarreau | 368480c | 2009-03-01 08:27:21 +0100 | [diff] [blame] | 4605 | |
| 4606 | /* we must first clear any optional default setting */ |
| 4607 | curproxy->options &= ~PR_O_TPXY_MASK; |
| 4608 | free(curproxy->iface_name); |
| 4609 | curproxy->iface_name = NULL; |
| 4610 | curproxy->iface_len = 0; |
| 4611 | |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4612 | sk = str2sa(args[1]); |
| 4613 | if (!sk) { |
| 4614 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[1]); |
| 4615 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4616 | goto out; |
| 4617 | } |
| 4618 | curproxy->source_addr = *sk; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4619 | curproxy->options |= PR_O_BIND_SRC; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4620 | |
| 4621 | cur_arg = 2; |
| 4622 | while (*(args[cur_arg])) { |
| 4623 | if (!strcmp(args[cur_arg], "usesrc")) { /* address to use outside */ |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4624 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) |
| 4625 | #if !defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4626 | if (curproxy->source_addr.sin_addr.s_addr == INADDR_ANY) { |
| 4627 | Alert("parsing [%s:%d] : '%s' requires an explicit 'source' address.\n", |
| 4628 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4629 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4630 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4631 | } |
| 4632 | #endif |
| 4633 | if (!*args[cur_arg + 1]) { |
| 4634 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n", |
| 4635 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4636 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4637 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4638 | } |
| 4639 | |
| 4640 | if (!strcmp(args[cur_arg + 1], "client")) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4641 | curproxy->options &= ~PR_O_TPXY_MASK; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4642 | curproxy->options |= PR_O_TPXY_CLI; |
| 4643 | } else if (!strcmp(args[cur_arg + 1], "clientip")) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4644 | curproxy->options &= ~PR_O_TPXY_MASK; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4645 | curproxy->options |= PR_O_TPXY_CIP; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4646 | } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) { |
| 4647 | char *name, *end; |
| 4648 | |
| 4649 | name = args[cur_arg+1] + 7; |
| 4650 | while (isspace(*name)) |
| 4651 | name++; |
| 4652 | |
| 4653 | end = name; |
| 4654 | while (*end && !isspace(*end) && *end != ',' && *end != ')') |
| 4655 | end++; |
| 4656 | |
| 4657 | curproxy->options &= ~PR_O_TPXY_MASK; |
| 4658 | curproxy->options |= PR_O_TPXY_DYN; |
| 4659 | curproxy->bind_hdr_name = calloc(1, end - name + 1); |
| 4660 | curproxy->bind_hdr_len = end - name; |
| 4661 | memcpy(curproxy->bind_hdr_name, name, end - name); |
| 4662 | curproxy->bind_hdr_name[end-name] = '\0'; |
| 4663 | curproxy->bind_hdr_occ = -1; |
| 4664 | |
| 4665 | /* now look for an occurrence number */ |
| 4666 | while (isspace(*end)) |
| 4667 | end++; |
| 4668 | if (*end == ',') { |
| 4669 | end++; |
| 4670 | name = end; |
| 4671 | if (*end == '-') |
| 4672 | end++; |
| 4673 | while (isdigit(*end)) |
| 4674 | end++; |
| 4675 | curproxy->bind_hdr_occ = strl2ic(name, end-name); |
| 4676 | } |
| 4677 | |
| 4678 | if (curproxy->bind_hdr_occ < -MAX_HDR_HISTORY) { |
| 4679 | Alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative" |
| 4680 | " occurrences values smaller than %d.\n", |
| 4681 | file, linenum, MAX_HDR_HISTORY); |
| 4682 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4683 | goto out; |
| 4684 | } |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4685 | } else { |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4686 | struct sockaddr_storage *sk = str2sa(args[cur_arg + 1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4687 | if (!sk) { |
| 4688 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[cur_arg + 1]); |
| 4689 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4690 | goto out; |
| 4691 | } |
| 4692 | curproxy->tproxy_addr = *sk; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4693 | curproxy->options |= PR_O_TPXY_ADDR; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4694 | } |
| 4695 | global.last_checks |= LSTCHK_NETADM; |
| 4696 | #if !defined(CONFIG_HAP_LINUX_TPROXY) |
| 4697 | global.last_checks |= LSTCHK_CTTPROXY; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4698 | #endif |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4699 | #else /* no TPROXY support */ |
| 4700 | 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] | 4701 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4702 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4703 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4704 | #endif |
| 4705 | cur_arg += 2; |
| 4706 | continue; |
Willy Tarreau | 77074d5 | 2006-11-12 23:57:19 +0100 | [diff] [blame] | 4707 | } |
| 4708 | |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4709 | if (!strcmp(args[cur_arg], "interface")) { /* specifically bind to this interface */ |
| 4710 | #ifdef SO_BINDTODEVICE |
| 4711 | if (!*args[cur_arg + 1]) { |
| 4712 | Alert("parsing [%s:%d] : '%s' : missing interface name.\n", |
| 4713 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4714 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4715 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4716 | } |
| 4717 | if (curproxy->iface_name) |
| 4718 | free(curproxy->iface_name); |
| 4719 | |
| 4720 | curproxy->iface_name = strdup(args[cur_arg + 1]); |
| 4721 | curproxy->iface_len = strlen(curproxy->iface_name); |
| 4722 | global.last_checks |= LSTCHK_NETADM; |
| 4723 | #else |
| 4724 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 4725 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4726 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4727 | goto out; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4728 | #endif |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4729 | cur_arg += 2; |
| 4730 | continue; |
| 4731 | } |
| 4732 | Alert("parsing [%s:%d] : '%s' only supports optional keywords '%s' and '%s'.\n", |
| 4733 | file, linenum, args[0], "inteface", "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4734 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4735 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 4736 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4737 | } |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 4738 | else if (!strcmp(args[0], "usesrc")) { /* address to use outside: needs "source" first */ |
| 4739 | Alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n", |
| 4740 | file, linenum, "usesrc", "source"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4741 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4742 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 4743 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4744 | 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] | 4745 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4746 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 4747 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4748 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4749 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4750 | } |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4751 | |
| 4752 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 4753 | ACL_DIR_REQ, ACT_REPLACE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4754 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4755 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4756 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4757 | } |
| 4758 | else if (!strcmp(args[0], "reqdel")) { /* delete request header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4759 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 4760 | ACL_DIR_REQ, ACT_REMOVE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4761 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4762 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4763 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4764 | } |
| 4765 | 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] | 4766 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 4767 | ACL_DIR_REQ, ACT_DENY, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4768 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4769 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4770 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4771 | } |
| 4772 | 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] | 4773 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 4774 | ACL_DIR_REQ, ACT_PASS, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4775 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4776 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4777 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4778 | } |
| 4779 | 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] | 4780 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 4781 | ACL_DIR_REQ, ACT_ALLOW, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4782 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4783 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4784 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4785 | } |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 4786 | 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] | 4787 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 4788 | ACL_DIR_REQ, ACT_TARPIT, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4789 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4790 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4791 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 4792 | } |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 4793 | 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] | 4794 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 4795 | ACL_DIR_REQ, ACT_SETBE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4796 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4797 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4798 | goto out; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 4799 | } |
| 4800 | 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] | 4801 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 4802 | ACL_DIR_REQ, ACT_SETBE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4803 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4804 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4805 | goto out; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 4806 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4807 | 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] | 4808 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4809 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 4810 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4811 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4812 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4813 | } |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4814 | |
| 4815 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 4816 | ACL_DIR_REQ, ACT_REPLACE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4817 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4818 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4819 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4820 | } |
| 4821 | 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] | 4822 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 4823 | ACL_DIR_REQ, ACT_REMOVE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4824 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4825 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4826 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4827 | } |
| 4828 | 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] | 4829 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 4830 | ACL_DIR_REQ, ACT_DENY, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4831 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4832 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4833 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4834 | } |
| 4835 | 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] | 4836 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 4837 | ACL_DIR_REQ, ACT_PASS, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4838 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4839 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4840 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4841 | } |
| 4842 | 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] | 4843 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 4844 | ACL_DIR_REQ, ACT_ALLOW, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4845 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4846 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4847 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4848 | } |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 4849 | 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] | 4850 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 4851 | ACL_DIR_REQ, ACT_TARPIT, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4852 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4853 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4854 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 4855 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4856 | else if (!strcmp(args[0], "reqadd")) { /* add request header */ |
Willy Tarreau | f4f0412 | 2010-01-28 18:10:50 +0100 | [diff] [blame] | 4857 | struct cond_wordlist *wl; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 4858 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4859 | if (curproxy == &defproxy) { |
| 4860 | 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] | 4861 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4862 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4863 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4864 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4865 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4866 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4867 | if (*(args[1]) == 0) { |
| 4868 | 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] | 4869 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4870 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4871 | } |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 4872 | |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 4873 | if ((strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0)) { |
| 4874 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args+2)) == NULL) { |
| 4875 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition.\n", |
| 4876 | file, linenum, args[0]); |
| 4877 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4878 | goto out; |
| 4879 | } |
| 4880 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
| 4881 | } |
| 4882 | else if (*args[2]) { |
| 4883 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 4884 | file, linenum, args[0], args[2]); |
| 4885 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4886 | goto out; |
| 4887 | } |
| 4888 | |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 4889 | wl = calloc(1, sizeof(*wl)); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 4890 | wl->cond = cond; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 4891 | wl->s = strdup(args[1]); |
| 4892 | LIST_ADDQ(&curproxy->req_add, &wl->list); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 4893 | warnif_misplaced_reqadd(curproxy, file, linenum, args[0]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4894 | } |
| 4895 | 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] | 4896 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4897 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 4898 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4899 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4900 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4901 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4902 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4903 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 4904 | ACL_DIR_RTR, ACT_REPLACE, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 4905 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4906 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4907 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4908 | } |
| 4909 | else if (!strcmp(args[0], "rspdel")) { /* delete response header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4910 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 4911 | ACL_DIR_RTR, ACT_REMOVE, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 4912 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4913 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4914 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4915 | } |
| 4916 | else if (!strcmp(args[0], "rspdeny")) { /* block response header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4917 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 4918 | ACL_DIR_RTR, ACT_DENY, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 4919 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4920 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4921 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4922 | } |
| 4923 | 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] | 4924 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4925 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 4926 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4927 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4928 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4929 | } |
| 4930 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4931 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 4932 | ACL_DIR_RTR, ACT_REPLACE, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 4933 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4934 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4935 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4936 | } |
| 4937 | 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] | 4938 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 4939 | ACL_DIR_RTR, ACT_REMOVE, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 4940 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4941 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4942 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4943 | } |
| 4944 | 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] | 4945 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
| 4946 | ACL_DIR_RTR, ACT_DENY, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 4947 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4948 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4949 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4950 | } |
| 4951 | else if (!strcmp(args[0], "rspadd")) { /* add response header */ |
Willy Tarreau | f4f0412 | 2010-01-28 18:10:50 +0100 | [diff] [blame] | 4952 | struct cond_wordlist *wl; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 4953 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4954 | if (curproxy == &defproxy) { |
| 4955 | 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] | 4956 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4957 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4958 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4959 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4960 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4961 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4962 | if (*(args[1]) == 0) { |
| 4963 | 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] | 4964 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4965 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4966 | } |
| 4967 | |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 4968 | if ((strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0)) { |
| 4969 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args+2)) == NULL) { |
| 4970 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition.\n", |
| 4971 | file, linenum, args[0]); |
| 4972 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4973 | goto out; |
| 4974 | } |
| 4975 | err_code |= warnif_cond_requires_req(cond, file, linenum); |
| 4976 | } |
| 4977 | else if (*args[2]) { |
| 4978 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 4979 | file, linenum, args[0], args[2]); |
| 4980 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4981 | goto out; |
| 4982 | } |
| 4983 | |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 4984 | wl = calloc(1, sizeof(*wl)); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 4985 | wl->cond = cond; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 4986 | wl->s = strdup(args[1]); |
| 4987 | LIST_ADDQ(&curproxy->rsp_add, &wl->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4988 | } |
| 4989 | else if (!strcmp(args[0], "errorloc") || |
| 4990 | !strcmp(args[0], "errorloc302") || |
| 4991 | !strcmp(args[0], "errorloc303")) { /* error location */ |
| 4992 | int errnum, errlen; |
| 4993 | char *err; |
| 4994 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4995 | 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] | 4996 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4997 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4998 | if (*(args[2]) == 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 4999 | 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] | 5000 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5001 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5002 | } |
| 5003 | |
| 5004 | errnum = atol(args[1]); |
| 5005 | if (!strcmp(args[0], "errorloc303")) { |
| 5006 | err = malloc(strlen(HTTP_303) + strlen(args[2]) + 5); |
| 5007 | errlen = sprintf(err, "%s%s\r\n\r\n", HTTP_303, args[2]); |
| 5008 | } else { |
| 5009 | err = malloc(strlen(HTTP_302) + strlen(args[2]) + 5); |
| 5010 | errlen = sprintf(err, "%s%s\r\n\r\n", HTTP_302, args[2]); |
| 5011 | } |
| 5012 | |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 5013 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) { |
| 5014 | if (http_err_codes[rc] == errnum) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 5015 | chunk_destroy(&curproxy->errmsg[rc]); |
| 5016 | chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 5017 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5018 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5019 | } |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 5020 | |
| 5021 | if (rc >= HTTP_ERR_SIZE) { |
| 5022 | Warning("parsing [%s:%d] : status code %d not handled, error relocation will be ignored.\n", |
| 5023 | file, linenum, errnum); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5024 | free(err); |
| 5025 | } |
| 5026 | } |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5027 | else if (!strcmp(args[0], "errorfile")) { /* error message from a file */ |
| 5028 | int errnum, errlen, fd; |
| 5029 | char *err; |
| 5030 | struct stat stat; |
| 5031 | |
| 5032 | 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] | 5033 | err_code |= ERR_WARN; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5034 | |
| 5035 | if (*(args[2]) == 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 5036 | 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] | 5037 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5038 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5039 | } |
| 5040 | |
| 5041 | fd = open(args[2], O_RDONLY); |
| 5042 | if ((fd < 0) || (fstat(fd, &stat) < 0)) { |
| 5043 | Alert("parsing [%s:%d] : error opening file <%s> for custom error message <%s>.\n", |
| 5044 | file, linenum, args[2], args[1]); |
| 5045 | if (fd >= 0) |
| 5046 | close(fd); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5047 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5048 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5049 | } |
| 5050 | |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 5051 | if (stat.st_size <= global.tune.bufsize) { |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5052 | errlen = stat.st_size; |
| 5053 | } else { |
| 5054 | 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] | 5055 | file, linenum, args[2], global.tune.bufsize); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5056 | err_code |= ERR_WARN; |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 5057 | errlen = global.tune.bufsize; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5058 | } |
| 5059 | |
| 5060 | err = malloc(errlen); /* malloc() must succeed during parsing */ |
| 5061 | errnum = read(fd, err, errlen); |
| 5062 | if (errnum != errlen) { |
| 5063 | Alert("parsing [%s:%d] : error reading file <%s> for custom error message <%s>.\n", |
| 5064 | file, linenum, args[2], args[1]); |
| 5065 | close(fd); |
| 5066 | free(err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5067 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5068 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5069 | } |
| 5070 | close(fd); |
| 5071 | |
| 5072 | errnum = atol(args[1]); |
| 5073 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) { |
| 5074 | if (http_err_codes[rc] == errnum) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 5075 | chunk_destroy(&curproxy->errmsg[rc]); |
| 5076 | chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen); |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5077 | break; |
| 5078 | } |
| 5079 | } |
| 5080 | |
| 5081 | if (rc >= HTTP_ERR_SIZE) { |
| 5082 | Warning("parsing [%s:%d] : status code %d not handled, error customization will be ignored.\n", |
| 5083 | file, linenum, errnum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5084 | err_code |= ERR_WARN; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5085 | free(err); |
| 5086 | } |
| 5087 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5088 | else { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 5089 | struct cfg_kw_list *kwl; |
| 5090 | int index; |
| 5091 | |
| 5092 | list_for_each_entry(kwl, &cfg_keywords.list, list) { |
| 5093 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 5094 | if (kwl->kw[index].section != CFG_LISTEN) |
| 5095 | continue; |
| 5096 | if (strcmp(kwl->kw[index].kw, args[0]) == 0) { |
| 5097 | /* prepare error message just in case */ |
| 5098 | snprintf(trash, sizeof(trash), |
| 5099 | "error near '%s' in %s section", args[0], cursection); |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 5100 | rc = kwl->kw[index].parse(args, CFG_LISTEN, curproxy, &defproxy, trash, sizeof(trash)); |
| 5101 | if (rc < 0) { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 5102 | Alert("parsing [%s:%d] : %s\n", file, linenum, trash); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5103 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5104 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 5105 | } |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 5106 | else if (rc > 0) { |
| 5107 | Warning("parsing [%s:%d] : %s\n", file, linenum, trash); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5108 | err_code |= ERR_WARN; |
| 5109 | goto out; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 5110 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5111 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 5112 | } |
| 5113 | } |
| 5114 | } |
| 5115 | |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5116 | 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] | 5117 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5118 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5119 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5120 | out: |
| 5121 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5122 | } |
| 5123 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5124 | int |
| 5125 | cfg_parse_users(const char *file, int linenum, char **args, int kwm) |
| 5126 | { |
| 5127 | |
| 5128 | int err_code = 0; |
| 5129 | const char *err; |
| 5130 | |
| 5131 | if (!strcmp(args[0], "userlist")) { /* new userlist */ |
| 5132 | struct userlist *newul; |
| 5133 | |
| 5134 | if (!*args[1]) { |
| 5135 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 5136 | file, linenum, args[0]); |
| 5137 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5138 | goto out; |
| 5139 | } |
| 5140 | |
| 5141 | err = invalid_char(args[1]); |
| 5142 | if (err) { |
| 5143 | Alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 5144 | file, linenum, *err, args[0], args[1]); |
| 5145 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5146 | goto out; |
| 5147 | } |
| 5148 | |
| 5149 | for (newul = userlist; newul; newul = newul->next) |
| 5150 | if (!strcmp(newul->name, args[1])) { |
| 5151 | Warning("parsing [%s:%d]: ignoring duplicated userlist '%s'.\n", |
| 5152 | file, linenum, args[1]); |
| 5153 | err_code |= ERR_WARN; |
| 5154 | goto out; |
| 5155 | } |
| 5156 | |
| 5157 | newul = (struct userlist *)calloc(1, sizeof(struct userlist)); |
| 5158 | if (!newul) { |
| 5159 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 5160 | err_code |= ERR_ALERT | ERR_ABORT; |
| 5161 | goto out; |
| 5162 | } |
| 5163 | |
| 5164 | newul->groupusers = calloc(MAX_AUTH_GROUPS, sizeof(char *)); |
| 5165 | newul->name = strdup(args[1]); |
| 5166 | |
| 5167 | if (!newul->groupusers | !newul->name) { |
| 5168 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 5169 | err_code |= ERR_ALERT | ERR_ABORT; |
| 5170 | goto out; |
| 5171 | } |
| 5172 | |
| 5173 | newul->next = userlist; |
| 5174 | userlist = newul; |
| 5175 | |
| 5176 | } else if (!strcmp(args[0], "group")) { /* new group */ |
| 5177 | int cur_arg, i; |
| 5178 | const char *err; |
| 5179 | |
| 5180 | if (!*args[1]) { |
| 5181 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 5182 | file, linenum, args[0]); |
| 5183 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5184 | goto out; |
| 5185 | } |
| 5186 | |
| 5187 | err = invalid_char(args[1]); |
| 5188 | if (err) { |
| 5189 | Alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 5190 | file, linenum, *err, args[0], args[1]); |
| 5191 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5192 | goto out; |
| 5193 | } |
| 5194 | |
| 5195 | for(i = 0; i < userlist->grpcnt; i++) |
| 5196 | if (!strcmp(userlist->groups[i], args[1])) { |
| 5197 | Warning("parsing [%s:%d]: ignoring duplicated group '%s' in userlist '%s'.\n", |
| 5198 | file, linenum, args[1], userlist->name); |
| 5199 | err_code |= ERR_ALERT; |
| 5200 | goto out; |
| 5201 | } |
| 5202 | |
| 5203 | if (userlist->grpcnt >= MAX_AUTH_GROUPS) { |
| 5204 | Alert("parsing [%s:%d]: too many groups (%u) in in userlist '%s' while adding group '%s'.\n", |
| 5205 | file, linenum, MAX_AUTH_GROUPS, userlist->name, args[1]); |
| 5206 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5207 | goto out; |
| 5208 | } |
| 5209 | |
| 5210 | cur_arg = 2; |
| 5211 | |
| 5212 | while (*args[cur_arg]) { |
| 5213 | if (!strcmp(args[cur_arg], "users")) { |
| 5214 | userlist->groupusers[userlist->grpcnt] = strdup(args[cur_arg + 1]); |
| 5215 | cur_arg += 2; |
| 5216 | continue; |
| 5217 | } else { |
| 5218 | Alert("parsing [%s:%d]: '%s' only supports 'users' option.\n", |
| 5219 | file, linenum, args[0]); |
| 5220 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5221 | goto out; |
| 5222 | } |
| 5223 | } |
| 5224 | |
| 5225 | userlist->groups[userlist->grpcnt++] = strdup(args[1]); |
| 5226 | } else if (!strcmp(args[0], "user")) { /* new user */ |
| 5227 | struct auth_users *newuser; |
| 5228 | int cur_arg; |
| 5229 | |
| 5230 | if (!*args[1]) { |
| 5231 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 5232 | file, linenum, args[0]); |
| 5233 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5234 | goto out; |
| 5235 | } |
| 5236 | |
| 5237 | for (newuser = userlist->users; newuser; newuser = newuser->next) |
| 5238 | if (!strcmp(newuser->user, args[1])) { |
| 5239 | Warning("parsing [%s:%d]: ignoring duplicated user '%s' in userlist '%s'.\n", |
| 5240 | file, linenum, args[1], userlist->name); |
| 5241 | err_code |= ERR_ALERT; |
| 5242 | goto out; |
| 5243 | } |
| 5244 | |
| 5245 | newuser = (struct auth_users *)calloc(1, sizeof(struct auth_users)); |
| 5246 | if (!newuser) { |
| 5247 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 5248 | err_code |= ERR_ALERT | ERR_ABORT; |
| 5249 | goto out; |
| 5250 | } |
| 5251 | |
| 5252 | newuser->user = strdup(args[1]); |
| 5253 | |
| 5254 | newuser->next = userlist->users; |
| 5255 | userlist->users = newuser; |
| 5256 | |
| 5257 | cur_arg = 2; |
| 5258 | |
| 5259 | while (*args[cur_arg]) { |
| 5260 | if (!strcmp(args[cur_arg], "password")) { |
| 5261 | #ifndef CONFIG_HAP_CRYPT |
| 5262 | Warning("parsing [%s:%d]: no crypt(3) support compiled, encrypted passwords will not work.\n", |
| 5263 | file, linenum); |
| 5264 | err_code |= ERR_ALERT; |
| 5265 | #endif |
| 5266 | newuser->pass = strdup(args[cur_arg + 1]); |
| 5267 | cur_arg += 2; |
| 5268 | continue; |
| 5269 | } else if (!strcmp(args[cur_arg], "insecure-password")) { |
| 5270 | newuser->pass = strdup(args[cur_arg + 1]); |
| 5271 | newuser->flags |= AU_O_INSECURE; |
| 5272 | cur_arg += 2; |
| 5273 | continue; |
| 5274 | } else if (!strcmp(args[cur_arg], "groups")) { |
Willy Tarreau | b4c06b7 | 2010-02-02 11:28:20 +0100 | [diff] [blame] | 5275 | newuser->u.groups = strdup(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5276 | cur_arg += 2; |
| 5277 | continue; |
| 5278 | } else { |
| 5279 | Alert("parsing [%s:%d]: '%s' only supports 'password', 'insecure-password' and 'groups' options.\n", |
| 5280 | file, linenum, args[0]); |
| 5281 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5282 | goto out; |
| 5283 | } |
| 5284 | } |
| 5285 | } else { |
| 5286 | Alert("parsing [%s:%d]: unknown keyword '%s' in '%s' section\n", file, linenum, args[0], "users"); |
| 5287 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5288 | } |
| 5289 | |
| 5290 | out: |
| 5291 | return err_code; |
| 5292 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5293 | |
| 5294 | /* |
| 5295 | * This function reads and parses the configuration file given in the argument. |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5296 | * Returns the error code, 0 if OK, or any combination of : |
| 5297 | * - ERR_ABORT: must abort ASAP |
| 5298 | * - ERR_FATAL: we can continue parsing but not start the service |
| 5299 | * - ERR_WARN: a warning has been emitted |
| 5300 | * - ERR_ALERT: an alert has been emitted |
| 5301 | * Only the two first ones can stop processing, the two others are just |
| 5302 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5303 | */ |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 5304 | int readcfgfile(const char *file) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5305 | { |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5306 | char thisline[LINESIZE]; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5307 | FILE *f; |
| 5308 | int linenum = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5309 | int confsect = CFG_NONE; |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5310 | int err_code = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5311 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5312 | if ((f=fopen(file,"r")) == NULL) |
| 5313 | return -1; |
| 5314 | |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5315 | while (fgets(thisline, sizeof(thisline), f) != NULL) { |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 5316 | int arg, kwm = KWM_STD; |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5317 | char *end; |
| 5318 | char *args[MAX_LINE_ARGS + 1]; |
| 5319 | char *line = thisline; |
| 5320 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5321 | linenum++; |
| 5322 | |
| 5323 | end = line + strlen(line); |
| 5324 | |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5325 | if (end-line == sizeof(thisline)-1 && *(end-1) != '\n') { |
| 5326 | /* Check if we reached the limit and the last char is not \n. |
| 5327 | * Watch out for the last line without the terminating '\n'! |
| 5328 | */ |
| 5329 | Alert("parsing [%s:%d]: line too long, limit: %d.\n", |
Willy Tarreau | 5e4a6f1 | 2009-04-11 19:42:49 +0200 | [diff] [blame] | 5330 | file, linenum, (int)sizeof(thisline)-1); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5331 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5332 | } |
| 5333 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5334 | /* skip leading spaces */ |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 5335 | while (isspace((unsigned char)*line)) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5336 | line++; |
| 5337 | |
| 5338 | arg = 0; |
| 5339 | args[arg] = line; |
| 5340 | |
| 5341 | while (*line && arg < MAX_LINE_ARGS) { |
| 5342 | /* first, we'll replace \\, \<space>, \#, \r, \n, \t, \xXX with their |
| 5343 | * C equivalent value. Other combinations left unchanged (eg: \1). |
| 5344 | */ |
| 5345 | if (*line == '\\') { |
| 5346 | int skip = 0; |
| 5347 | if (line[1] == ' ' || line[1] == '\\' || line[1] == '#') { |
| 5348 | *line = line[1]; |
| 5349 | skip = 1; |
| 5350 | } |
| 5351 | else if (line[1] == 'r') { |
| 5352 | *line = '\r'; |
| 5353 | skip = 1; |
| 5354 | } |
| 5355 | else if (line[1] == 'n') { |
| 5356 | *line = '\n'; |
| 5357 | skip = 1; |
| 5358 | } |
| 5359 | else if (line[1] == 't') { |
| 5360 | *line = '\t'; |
| 5361 | skip = 1; |
| 5362 | } |
| 5363 | else if (line[1] == 'x') { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5364 | if ((line + 3 < end) && ishex(line[2]) && ishex(line[3])) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5365 | unsigned char hex1, hex2; |
| 5366 | hex1 = toupper(line[2]) - '0'; |
| 5367 | hex2 = toupper(line[3]) - '0'; |
| 5368 | if (hex1 > 9) hex1 -= 'A' - '9' - 1; |
| 5369 | if (hex2 > 9) hex2 -= 'A' - '9' - 1; |
| 5370 | *line = (hex1<<4) + hex2; |
| 5371 | skip = 3; |
| 5372 | } |
| 5373 | else { |
| 5374 | 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] | 5375 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5376 | } |
| 5377 | } |
| 5378 | if (skip) { |
Cyril Bonté | dd1b01d | 2009-12-06 13:43:42 +0100 | [diff] [blame] | 5379 | memmove(line + 1, line + 1 + skip, end - (line + skip)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5380 | end -= skip; |
| 5381 | } |
| 5382 | line++; |
| 5383 | } |
| 5384 | else if (*line == '#' || *line == '\n' || *line == '\r') { |
| 5385 | /* end of string, end of loop */ |
| 5386 | *line = 0; |
| 5387 | break; |
| 5388 | } |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 5389 | else if (isspace((unsigned char)*line)) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5390 | /* a non-escaped space is an argument separator */ |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5391 | *line++ = '\0'; |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 5392 | while (isspace((unsigned char)*line)) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5393 | line++; |
| 5394 | args[++arg] = line; |
| 5395 | } |
| 5396 | else { |
| 5397 | line++; |
| 5398 | } |
| 5399 | } |
| 5400 | |
| 5401 | /* empty line */ |
| 5402 | if (!**args) |
| 5403 | continue; |
| 5404 | |
Willy Tarreau | 7bb651e | 2009-11-09 21:16:53 +0100 | [diff] [blame] | 5405 | if (*line) { |
| 5406 | /* we had to stop due to too many args. |
| 5407 | * Let's terminate the string, print the offending part then cut the |
| 5408 | * last arg. |
| 5409 | */ |
| 5410 | while (*line && *line != '#' && *line != '\n' && *line != '\r') |
| 5411 | line++; |
| 5412 | *line = '\0'; |
| 5413 | |
Krzysztof Piotr Oledzki | 500b8f0 | 2009-12-15 22:34:51 +0100 | [diff] [blame] | 5414 | 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] | 5415 | file, linenum, arg + 1, (long)(args[arg] - thisline + 1), args[arg]); |
Willy Tarreau | 7bb651e | 2009-11-09 21:16:53 +0100 | [diff] [blame] | 5416 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5417 | args[arg] = line; |
| 5418 | } |
| 5419 | |
Willy Tarreau | 540abe4 | 2007-05-02 20:50:16 +0200 | [diff] [blame] | 5420 | /* zero out remaining args and ensure that at least one entry |
| 5421 | * is zeroed out. |
| 5422 | */ |
| 5423 | while (++arg <= MAX_LINE_ARGS) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5424 | args[arg] = line; |
| 5425 | } |
| 5426 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 5427 | /* check for keyword modifiers "no" and "default" */ |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5428 | if (!strcmp(args[0], "no")) { |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 5429 | kwm = KWM_NO; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5430 | for (arg=0; *args[arg+1]; arg++) |
| 5431 | args[arg] = args[arg+1]; // shift args after inversion |
| 5432 | } |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 5433 | else if (!strcmp(args[0], "default")) { |
| 5434 | kwm = KWM_DEF; |
| 5435 | for (arg=0; *args[arg+1]; arg++) |
| 5436 | args[arg] = args[arg+1]; // shift args after inversion |
| 5437 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5438 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 5439 | if (kwm != KWM_STD && strcmp(args[0], "option") != 0) { |
| 5440 | 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] | 5441 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5442 | } |
| 5443 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5444 | if (!strcmp(args[0], "listen") || |
| 5445 | !strcmp(args[0], "frontend") || |
| 5446 | !strcmp(args[0], "backend") || |
| 5447 | !strcmp(args[0], "ruleset") || |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5448 | !strcmp(args[0], "defaults")) { /* new proxy */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5449 | confsect = CFG_LISTEN; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 5450 | free(cursection); |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5451 | cursection = strdup(args[0]); |
| 5452 | } |
| 5453 | else if (!strcmp(args[0], "global")) { /* global config */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5454 | confsect = CFG_GLOBAL; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 5455 | free(cursection); |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5456 | cursection = strdup(args[0]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 5457 | } |
| 5458 | else if (!strcmp(args[0], "userlist")) { |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5459 | confsect = CFG_USERLIST; |
| 5460 | free(cursection); |
| 5461 | cursection = strdup(args[0]); |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5462 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 5463 | else if (!strcmp(args[0], "peers")) { |
| 5464 | confsect = CFG_PEERS; |
| 5465 | free(cursection); |
| 5466 | cursection = strdup(args[0]); |
| 5467 | } |
| 5468 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5469 | /* else it's a section keyword */ |
| 5470 | |
| 5471 | switch (confsect) { |
| 5472 | case CFG_LISTEN: |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5473 | err_code |= cfg_parse_listen(file, linenum, args, kwm); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5474 | break; |
| 5475 | case CFG_GLOBAL: |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5476 | err_code |= cfg_parse_global(file, linenum, args, kwm); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5477 | break; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5478 | case CFG_USERLIST: |
| 5479 | err_code |= cfg_parse_users(file, linenum, args, kwm); |
| 5480 | break; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 5481 | case CFG_PEERS: |
| 5482 | err_code |= cfg_parse_peers(file, linenum, args, kwm); |
| 5483 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5484 | default: |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5485 | 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] | 5486 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5487 | } |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5488 | |
| 5489 | if (err_code & ERR_ABORT) |
| 5490 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5491 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 5492 | free(cursection); |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5493 | cursection = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5494 | fclose(f); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5495 | return err_code; |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5496 | } |
| 5497 | |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 5498 | /* |
| 5499 | * Returns the error code, 0 if OK, or any combination of : |
| 5500 | * - ERR_ABORT: must abort ASAP |
| 5501 | * - ERR_FATAL: we can continue parsing but not start the service |
| 5502 | * - ERR_WARN: a warning has been emitted |
| 5503 | * - ERR_ALERT: an alert has been emitted |
| 5504 | * Only the two first ones can stop processing, the two others are just |
| 5505 | * indicators. |
| 5506 | */ |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5507 | int check_config_validity() |
| 5508 | { |
| 5509 | int cfgerr = 0; |
| 5510 | struct proxy *curproxy = NULL; |
| 5511 | struct server *newsrv = NULL; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5512 | struct userlist *curuserlist = NULL; |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 5513 | int err_code = 0; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 5514 | unsigned int next_pxid = 1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5515 | |
| 5516 | /* |
| 5517 | * Now, check for the integrity of all that we have collected. |
| 5518 | */ |
| 5519 | |
| 5520 | /* will be needed further to delay some tasks */ |
Willy Tarreau | b0b37bc | 2008-06-23 14:00:57 +0200 | [diff] [blame] | 5521 | tv_update_date(0,1); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5522 | |
Willy Tarreau | 55bc0f8 | 2009-03-15 14:51:53 +0100 | [diff] [blame] | 5523 | /* first, we will invert the proxy list order */ |
| 5524 | curproxy = NULL; |
| 5525 | while (proxy) { |
| 5526 | struct proxy *next; |
| 5527 | |
| 5528 | next = proxy->next; |
| 5529 | proxy->next = curproxy; |
| 5530 | curproxy = proxy; |
| 5531 | if (!next) |
| 5532 | break; |
| 5533 | proxy = next; |
| 5534 | } |
| 5535 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5536 | if ((curproxy = proxy) == NULL) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5537 | Alert("config : no <listen> line. Nothing to do !\n"); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 5538 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5539 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5540 | } |
| 5541 | |
| 5542 | while (curproxy != NULL) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 5543 | struct switching_rule *rule; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5544 | struct sticking_rule *mrule; |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 5545 | struct tcp_rule *trule; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 5546 | struct listener *listener; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 5547 | unsigned int next_id; |
| 5548 | |
| 5549 | if (!curproxy->uuid) { |
| 5550 | /* proxy ID not set, use automatic numbering with first |
| 5551 | * spare entry starting with next_pxid. |
| 5552 | */ |
| 5553 | next_pxid = get_next_id(&used_proxy_id, next_pxid); |
| 5554 | curproxy->conf.id.key = curproxy->uuid = next_pxid; |
| 5555 | eb32_insert(&used_proxy_id, &curproxy->conf.id); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 5556 | } |
Krzysztof Piotr Oledzki | df5cb9f | 2010-02-05 20:58:27 +0100 | [diff] [blame] | 5557 | next_pxid++; |
| 5558 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 5559 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5560 | if (curproxy->state == PR_STSTOPPED) { |
Willy Tarreau | da250db | 2008-10-12 12:07:48 +0200 | [diff] [blame] | 5561 | /* ensure we don't keep listeners uselessly bound */ |
| 5562 | stop_proxy(curproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5563 | curproxy = curproxy->next; |
| 5564 | continue; |
| 5565 | } |
| 5566 | |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 5567 | switch (curproxy->mode) { |
| 5568 | case PR_MODE_HEALTH: |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5569 | cfgerr += proxy_cfg_ensure_no_http(curproxy); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 5570 | if (!(curproxy->cap & PR_CAP_FE)) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5571 | Alert("config : %s '%s' cannot be in health mode as it has no frontend capability.\n", |
| 5572 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 5573 | cfgerr++; |
| 5574 | } |
| 5575 | |
| 5576 | if (curproxy->srv != NULL) |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5577 | Warning("config : servers will be ignored for %s '%s'.\n", |
| 5578 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 5579 | break; |
| 5580 | |
| 5581 | case PR_MODE_TCP: |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5582 | cfgerr += proxy_cfg_ensure_no_http(curproxy); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 5583 | break; |
| 5584 | |
| 5585 | case PR_MODE_HTTP: |
Willy Tarreau | a9fb083 | 2009-07-10 20:53:53 +0200 | [diff] [blame] | 5586 | curproxy->acl_requires |= ACL_USE_L7_ANY; |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 5587 | break; |
| 5588 | } |
| 5589 | |
| 5590 | if ((curproxy->cap & PR_CAP_FE) && (curproxy->listen == NULL)) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5591 | Alert("config : %s '%s' has no listen address. Please either specify a valid address on the <listen> line, or use the <bind> keyword.\n", |
| 5592 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5593 | cfgerr++; |
| 5594 | } |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 5595 | |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 5596 | if ((curproxy->cap & PR_CAP_BE) && (curproxy->mode != PR_MODE_HEALTH)) { |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 5597 | if (curproxy->lbprm.algo & BE_LB_KIND) { |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 5598 | if (curproxy->options & PR_O_TRANSP) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5599 | Alert("config : %s '%s' cannot use both transparent and balance mode.\n", |
| 5600 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 5601 | cfgerr++; |
| 5602 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5603 | #ifdef WE_DONT_SUPPORT_SERVERLESS_LISTENERS |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 5604 | else if (curproxy->srv == NULL) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5605 | Alert("config : %s '%s' needs at least 1 server in balance mode.\n", |
| 5606 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 5607 | cfgerr++; |
| 5608 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5609 | #endif |
Willy Tarreau | f5ab69a | 2011-03-04 22:44:16 +0100 | [diff] [blame] | 5610 | else if (curproxy->options2 & PR_O2_DISPATCH) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5611 | Warning("config : dispatch address of %s '%s' will be ignored in balance mode.\n", |
| 5612 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 5613 | err_code |= ERR_WARN; |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 5614 | } |
| 5615 | } |
| 5616 | else if (!(curproxy->options & (PR_O_TRANSP | PR_O_HTTP_PROXY)) && |
Willy Tarreau | f5ab69a | 2011-03-04 22:44:16 +0100 | [diff] [blame] | 5617 | !(curproxy->options2 & PR_O2_DISPATCH)) { |
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 | d6cc532 | 2011-03-04 17:30:54 +0100 | [diff] [blame] | 5627 | if (curproxy->options2 & PR_O2_DISPATCH) { |
| 5628 | curproxy->options &= ~PR_O_TRANSP; |
| 5629 | curproxy->options &= ~PR_O_HTTP_PROXY; |
| 5630 | } |
| 5631 | else if (curproxy->options & PR_O_HTTP_PROXY) { |
| 5632 | curproxy->options2 &= ~PR_O2_DISPATCH; |
| 5633 | curproxy->options &= ~PR_O_TRANSP; |
| 5634 | } |
| 5635 | else if (curproxy->options & PR_O_TRANSP) { |
| 5636 | curproxy->options2 &= ~PR_O2_DISPATCH; |
| 5637 | curproxy->options &= ~PR_O_HTTP_PROXY; |
| 5638 | } |
| 5639 | |
Willy Tarreau | 8293658 | 2007-11-30 15:20:09 +0100 | [diff] [blame] | 5640 | if ((curproxy->options & PR_O_DISABLE404) && !(curproxy->options & PR_O_HTTP_CHK)) { |
| 5641 | curproxy->options &= ~PR_O_DISABLE404; |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5642 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n", |
| 5643 | "disable-on-404", proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 5644 | err_code |= ERR_WARN; |
Willy Tarreau | 8293658 | 2007-11-30 15:20:09 +0100 | [diff] [blame] | 5645 | } |
| 5646 | |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 5647 | if ((curproxy->options2 & PR_O2_CHK_SNDST) && !(curproxy->options & PR_O_HTTP_CHK)) { |
| 5648 | curproxy->options &= ~PR_O2_CHK_SNDST; |
| 5649 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n", |
| 5650 | "send-state", proxy_type_str(curproxy), curproxy->id); |
| 5651 | err_code |= ERR_WARN; |
| 5652 | } |
| 5653 | |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5654 | /* if a default backend was specified, let's find it */ |
| 5655 | if (curproxy->defbe.name) { |
| 5656 | struct proxy *target; |
| 5657 | |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 5658 | target = findproxy_mode(curproxy->defbe.name, curproxy->mode, PR_CAP_BE); |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 5659 | if (!target) { |
| 5660 | Alert("Proxy '%s': unable to find required default_backend: '%s'.\n", |
| 5661 | curproxy->id, curproxy->defbe.name); |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5662 | cfgerr++; |
| 5663 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 5664 | Alert("Proxy '%s': loop detected for default_backend: '%s'.\n", |
| 5665 | curproxy->id, curproxy->defbe.name); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 5666 | cfgerr++; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5667 | } else { |
| 5668 | free(curproxy->defbe.name); |
| 5669 | curproxy->defbe.be = target; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 5670 | /* we force the backend to be present on at least all of |
| 5671 | * the frontend's processes. |
| 5672 | */ |
| 5673 | target->bind_proc = curproxy->bind_proc ? |
| 5674 | (target->bind_proc | curproxy->bind_proc) : 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5675 | } |
| 5676 | } |
| 5677 | |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5678 | /* find the target proxy in setbe */ |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5679 | if (curproxy->mode == PR_MODE_HTTP && curproxy->req_exp != NULL) { |
| 5680 | /* map jump target for ACT_SETBE in req_rep chain */ |
| 5681 | struct hdr_exp *exp; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5682 | for (exp = curproxy->req_exp; exp != NULL; exp = exp->next) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 5683 | struct proxy *target; |
| 5684 | |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5685 | if (exp->action != ACT_SETBE) |
| 5686 | continue; |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 5687 | |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 5688 | target = findproxy_mode(exp->replace, PR_MODE_HTTP, PR_CAP_BE); |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 5689 | if (!target) { |
| 5690 | Alert("Proxy '%s': unable to find required setbe: '%s'.\n", |
| 5691 | curproxy->id, exp->replace); |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5692 | cfgerr++; |
| 5693 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 5694 | Alert("Proxy '%s': loop detected for setbe: '%s'.\n", |
| 5695 | curproxy->id, exp->replace); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5696 | cfgerr++; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5697 | } else { |
| 5698 | free((void *)exp->replace); |
| 5699 | exp->replace = (const char *)target; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 5700 | /* we force the backend to be present on at least all of |
| 5701 | * the frontend's processes. |
| 5702 | */ |
| 5703 | target->bind_proc = curproxy->bind_proc ? |
| 5704 | (target->bind_proc | curproxy->bind_proc) : 0; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5705 | } |
| 5706 | } |
| 5707 | } |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 5708 | |
| 5709 | /* find the target proxy for 'use_backend' rules */ |
| 5710 | list_for_each_entry(rule, &curproxy->switching_rules, list) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 5711 | struct proxy *target; |
| 5712 | |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 5713 | target = findproxy_mode(rule->be.name, curproxy->mode, PR_CAP_BE); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 5714 | |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 5715 | if (!target) { |
| 5716 | Alert("Proxy '%s': unable to find required use_backend: '%s'.\n", |
| 5717 | curproxy->id, rule->be.name); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 5718 | cfgerr++; |
| 5719 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 5720 | Alert("Proxy '%s': loop detected for use_backend: '%s'.\n", |
| 5721 | curproxy->id, rule->be.name); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 5722 | cfgerr++; |
| 5723 | } else { |
| 5724 | free((void *)rule->be.name); |
| 5725 | rule->be.backend = target; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 5726 | /* we force the backend to be present on at least all of |
| 5727 | * the frontend's processes. |
| 5728 | */ |
| 5729 | target->bind_proc = curproxy->bind_proc ? |
| 5730 | (target->bind_proc | curproxy->bind_proc) : 0; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 5731 | } |
| 5732 | } |
| 5733 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5734 | /* find the target table for 'stick' rules */ |
| 5735 | list_for_each_entry(mrule, &curproxy->sticking_rules, list) { |
| 5736 | struct proxy *target; |
| 5737 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 5738 | curproxy->be_req_ana |= AN_REQ_STICKING_RULES; |
| 5739 | if (mrule->flags & STK_IS_STORE) |
| 5740 | curproxy->be_rsp_ana |= AN_RES_STORE_RULES; |
| 5741 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5742 | if (mrule->table.name) |
Willy Tarreau | c00cdc2 | 2010-06-06 16:48:26 +0200 | [diff] [blame] | 5743 | target = findproxy(mrule->table.name, 0); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5744 | else |
| 5745 | target = curproxy; |
| 5746 | |
| 5747 | if (!target) { |
| 5748 | Alert("Proxy '%s': unable to find stick-table '%s'.\n", |
| 5749 | curproxy->id, mrule->table.name); |
| 5750 | cfgerr++; |
| 5751 | } |
| 5752 | else if (target->table.size == 0) { |
| 5753 | Alert("Proxy '%s': stick-table '%s' used but not configured.\n", |
| 5754 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 5755 | cfgerr++; |
| 5756 | } |
Willy Tarreau | f0b38bf | 2010-06-06 13:22:23 +0200 | [diff] [blame] | 5757 | else if (!stktable_compatible_pattern(mrule->expr, target->table.type)) { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5758 | Alert("Proxy '%s': type of pattern not usable with type of stick-table '%s'.\n", |
| 5759 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 5760 | cfgerr++; |
| 5761 | } |
| 5762 | else { |
| 5763 | free((void *)mrule->table.name); |
| 5764 | mrule->table.t = &(target->table); |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 5765 | stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID, NULL); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5766 | } |
| 5767 | } |
| 5768 | |
| 5769 | /* find the target table for 'store response' rules */ |
| 5770 | list_for_each_entry(mrule, &curproxy->storersp_rules, list) { |
| 5771 | struct proxy *target; |
| 5772 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 5773 | curproxy->be_rsp_ana |= AN_RES_STORE_RULES; |
| 5774 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5775 | if (mrule->table.name) |
Willy Tarreau | c00cdc2 | 2010-06-06 16:48:26 +0200 | [diff] [blame] | 5776 | target = findproxy(mrule->table.name, 0); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5777 | else |
| 5778 | target = curproxy; |
| 5779 | |
| 5780 | if (!target) { |
| 5781 | Alert("Proxy '%s': unable to find store table '%s'.\n", |
| 5782 | curproxy->id, mrule->table.name); |
| 5783 | cfgerr++; |
| 5784 | } |
| 5785 | else if (target->table.size == 0) { |
| 5786 | Alert("Proxy '%s': stick-table '%s' used but not configured.\n", |
| 5787 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 5788 | cfgerr++; |
| 5789 | } |
Willy Tarreau | f0b38bf | 2010-06-06 13:22:23 +0200 | [diff] [blame] | 5790 | else if (!stktable_compatible_pattern(mrule->expr, target->table.type)) { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5791 | Alert("Proxy '%s': type of pattern not usable with type of stick-table '%s'.\n", |
| 5792 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 5793 | cfgerr++; |
| 5794 | } |
| 5795 | else { |
| 5796 | free((void *)mrule->table.name); |
| 5797 | mrule->table.t = &(target->table); |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 5798 | stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID, NULL); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5799 | } |
| 5800 | } |
| 5801 | |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 5802 | /* find the target table for 'tcp-request' layer 4 rules */ |
| 5803 | list_for_each_entry(trule, &curproxy->tcp_req.l4_rules, list) { |
| 5804 | struct proxy *target; |
| 5805 | |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 5806 | 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] | 5807 | continue; |
| 5808 | |
| 5809 | if (trule->act_prm.trk_ctr.table.n) |
| 5810 | target = findproxy(trule->act_prm.trk_ctr.table.n, 0); |
| 5811 | else |
| 5812 | target = curproxy; |
| 5813 | |
| 5814 | if (!target) { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 5815 | Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n", |
| 5816 | curproxy->id, trule->act_prm.trk_ctr.table.n, |
| 5817 | trule->action == TCP_ACT_TRK_SC1 ? 1 : 2); |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 5818 | cfgerr++; |
| 5819 | } |
| 5820 | else if (target->table.size == 0) { |
| 5821 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
| 5822 | curproxy->id, trule->act_prm.trk_ctr.table.n ? trule->act_prm.trk_ctr.table.n : curproxy->id); |
| 5823 | cfgerr++; |
| 5824 | } |
| 5825 | else if (trule->act_prm.trk_ctr.type != target->table.type) { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 5826 | 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] | 5827 | curproxy->id, trule->act_prm.trk_ctr.table.n ? trule->act_prm.trk_ctr.table.n : curproxy->id); |
| 5828 | cfgerr++; |
| 5829 | } |
| 5830 | else { |
| 5831 | free(trule->act_prm.trk_ctr.table.n); |
| 5832 | trule->act_prm.trk_ctr.table.t = &target->table; |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 5833 | /* 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] | 5834 | * to pass a list of counters to track and allocate them right here using |
| 5835 | * stktable_alloc_data_type(). |
| 5836 | */ |
| 5837 | } |
| 5838 | } |
| 5839 | |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 5840 | /* find the target table for 'tcp-request' layer 6 rules */ |
| 5841 | list_for_each_entry(trule, &curproxy->tcp_req.inspect_rules, list) { |
| 5842 | struct proxy *target; |
| 5843 | |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 5844 | 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] | 5845 | continue; |
| 5846 | |
| 5847 | if (trule->act_prm.trk_ctr.table.n) |
| 5848 | target = findproxy(trule->act_prm.trk_ctr.table.n, 0); |
| 5849 | else |
| 5850 | target = curproxy; |
| 5851 | |
| 5852 | if (!target) { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 5853 | Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n", |
| 5854 | curproxy->id, trule->act_prm.trk_ctr.table.n, |
| 5855 | trule->action == TCP_ACT_TRK_SC1 ? 1 : 2); |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 5856 | cfgerr++; |
| 5857 | } |
| 5858 | else if (target->table.size == 0) { |
| 5859 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
| 5860 | curproxy->id, trule->act_prm.trk_ctr.table.n ? trule->act_prm.trk_ctr.table.n : curproxy->id); |
| 5861 | cfgerr++; |
| 5862 | } |
| 5863 | else if (trule->act_prm.trk_ctr.type != target->table.type) { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 5864 | 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] | 5865 | curproxy->id, trule->act_prm.trk_ctr.table.n ? trule->act_prm.trk_ctr.table.n : curproxy->id); |
| 5866 | cfgerr++; |
| 5867 | } |
| 5868 | else { |
| 5869 | free(trule->act_prm.trk_ctr.table.n); |
| 5870 | trule->act_prm.trk_ctr.table.t = &target->table; |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 5871 | /* 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] | 5872 | * to pass a list of counters to track and allocate them right here using |
| 5873 | * stktable_alloc_data_type(). |
| 5874 | */ |
| 5875 | } |
| 5876 | } |
| 5877 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 5878 | if (curproxy->table.peers.name) { |
| 5879 | struct peers *curpeers = peers; |
| 5880 | |
| 5881 | for (curpeers = peers; curpeers; curpeers = curpeers->next) { |
| 5882 | if (strcmp(curpeers->id, curproxy->table.peers.name) == 0) { |
| 5883 | free((void *)curproxy->table.peers.name); |
| 5884 | curproxy->table.peers.p = peers; |
| 5885 | break; |
| 5886 | } |
| 5887 | } |
| 5888 | |
| 5889 | if (!curpeers) { |
| 5890 | Alert("Proxy '%s': unable to find sync peers '%s'.\n", |
| 5891 | curproxy->id, curproxy->table.peers.name); |
| 5892 | cfgerr++; |
| 5893 | } |
| 5894 | else if (!curpeers->peers_fe) { |
| 5895 | Alert("Proxy '%s': unable to identify local peer in peers section '%s'.\n", |
| 5896 | curproxy->id, curpeers->id); |
| 5897 | cfgerr++; |
| 5898 | } |
| 5899 | } |
| 5900 | |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 5901 | if (curproxy->uri_auth && !(curproxy->uri_auth->flags & ST_CONVDONE) && |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 5902 | !LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) && |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 5903 | (curproxy->uri_auth->userlist || curproxy->uri_auth->auth_realm )) { |
| 5904 | Alert("%s '%s': stats 'auth'/'realm' and 'http-request' can't be used at the same time.\n", |
| 5905 | "proxy", curproxy->id); |
| 5906 | cfgerr++; |
| 5907 | goto out_uri_auth_compat; |
| 5908 | } |
| 5909 | |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 5910 | 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] | 5911 | const char *uri_auth_compat_req[10]; |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 5912 | struct http_req_rule *rule; |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 5913 | int i = 0; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 5914 | |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 5915 | /* build the ACL condition from scratch. We're relying on anonymous ACLs for that */ |
| 5916 | uri_auth_compat_req[i++] = "auth"; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 5917 | |
| 5918 | if (curproxy->uri_auth->auth_realm) { |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 5919 | uri_auth_compat_req[i++] = "realm"; |
| 5920 | uri_auth_compat_req[i++] = curproxy->uri_auth->auth_realm; |
| 5921 | } |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 5922 | |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 5923 | uri_auth_compat_req[i++] = "unless"; |
| 5924 | uri_auth_compat_req[i++] = "{"; |
| 5925 | uri_auth_compat_req[i++] = "http_auth(.internal-stats-userlist)"; |
| 5926 | uri_auth_compat_req[i++] = "}"; |
| 5927 | uri_auth_compat_req[i++] = ""; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 5928 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 5929 | rule = parse_http_req_cond(uri_auth_compat_req, "internal-stats-auth-compat", 0, curproxy); |
| 5930 | if (!rule) { |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 5931 | cfgerr++; |
| 5932 | break; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 5933 | } |
| 5934 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 5935 | LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list); |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 5936 | |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 5937 | if (curproxy->uri_auth->auth_realm) { |
| 5938 | free(curproxy->uri_auth->auth_realm); |
| 5939 | curproxy->uri_auth->auth_realm = NULL; |
| 5940 | } |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 5941 | |
| 5942 | curproxy->uri_auth->flags |= ST_CONVDONE; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 5943 | } |
| 5944 | out_uri_auth_compat: |
| 5945 | |
Krzysztof Piotr Oledzki | f9423ae | 2010-01-29 19:26:18 +0100 | [diff] [blame] | 5946 | cfgerr += acl_find_targets(curproxy); |
| 5947 | |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 5948 | if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) && |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 5949 | (((curproxy->cap & PR_CAP_FE) && !curproxy->timeout.client) || |
Willy Tarreau | d825eef | 2007-05-12 22:35:00 +0200 | [diff] [blame] | 5950 | ((curproxy->cap & PR_CAP_BE) && (curproxy->srv) && |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 5951 | (!curproxy->timeout.connect || !curproxy->timeout.server)))) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5952 | Warning("config : missing timeouts for %s '%s'.\n" |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 5953 | " | While not properly invalid, you will certainly encounter various problems\n" |
| 5954 | " | 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] | 5955 | " | timeouts are set to a non-zero value: 'client', 'connect', 'server'.\n", |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5956 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 5957 | err_code |= ERR_WARN; |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 5958 | } |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 5959 | |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 5960 | /* Historically, the tarpit and queue timeouts were inherited from contimeout. |
| 5961 | * We must still support older configurations, so let's find out whether those |
| 5962 | * parameters have been set or must be copied from contimeouts. |
| 5963 | */ |
| 5964 | if (curproxy != &defproxy) { |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 5965 | if (!curproxy->timeout.tarpit || |
| 5966 | curproxy->timeout.tarpit == defproxy.timeout.tarpit) { |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 5967 | /* tarpit timeout not set. We search in the following order: |
| 5968 | * default.tarpit, curr.connect, default.connect. |
| 5969 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 5970 | if (defproxy.timeout.tarpit) |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 5971 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 5972 | else if (curproxy->timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 5973 | curproxy->timeout.tarpit = curproxy->timeout.connect; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 5974 | else if (defproxy.timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 5975 | curproxy->timeout.tarpit = defproxy.timeout.connect; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 5976 | } |
| 5977 | if ((curproxy->cap & PR_CAP_BE) && |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 5978 | (!curproxy->timeout.queue || |
| 5979 | curproxy->timeout.queue == defproxy.timeout.queue)) { |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 5980 | /* queue timeout not set. We search in the following order: |
| 5981 | * default.queue, curr.connect, default.connect. |
| 5982 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 5983 | if (defproxy.timeout.queue) |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 5984 | curproxy->timeout.queue = defproxy.timeout.queue; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 5985 | else if (curproxy->timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 5986 | curproxy->timeout.queue = curproxy->timeout.connect; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 5987 | else if (defproxy.timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 5988 | curproxy->timeout.queue = defproxy.timeout.connect; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 5989 | } |
| 5990 | } |
| 5991 | |
Willy Tarreau | 07a5490 | 2010-03-29 18:33:29 +0200 | [diff] [blame] | 5992 | if (curproxy->options2 & PR_O2_SSL3_CHK) { |
Willy Tarreau | 137325d | 2010-02-01 16:38:17 +0100 | [diff] [blame] | 5993 | curproxy->check_len = sizeof(sslv3_client_hello_pkt) - 1; |
| 5994 | curproxy->check_req = (char *)malloc(curproxy->check_len); |
| 5995 | memcpy(curproxy->check_req, sslv3_client_hello_pkt, curproxy->check_len); |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 5996 | } |
| 5997 | |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 5998 | /* The small pools required for the capture lists */ |
| 5999 | if (curproxy->nb_req_cap) |
| 6000 | curproxy->req_cap_pool = create_pool("ptrcap", |
| 6001 | curproxy->nb_req_cap * sizeof(char *), |
| 6002 | MEM_F_SHARED); |
| 6003 | if (curproxy->nb_rsp_cap) |
| 6004 | curproxy->rsp_cap_pool = create_pool("ptrcap", |
| 6005 | curproxy->nb_rsp_cap * sizeof(char *), |
| 6006 | MEM_F_SHARED); |
| 6007 | |
Willy Tarreau | 1d4154a | 2007-05-13 22:57:02 +0200 | [diff] [blame] | 6008 | curproxy->hdr_idx_pool = create_pool("hdr_idx", |
| 6009 | MAX_HTTP_HDR * sizeof(struct hdr_idx_elem), |
| 6010 | MEM_F_SHARED); |
| 6011 | |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 6012 | /* for backwards compatibility with "listen" instances, if |
| 6013 | * fullconn is not set but maxconn is set, then maxconn |
| 6014 | * is used. |
| 6015 | */ |
| 6016 | if (!curproxy->fullconn) |
| 6017 | curproxy->fullconn = curproxy->maxconn; |
| 6018 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6019 | /* first, we will invert the servers list order */ |
| 6020 | newsrv = NULL; |
| 6021 | while (curproxy->srv) { |
| 6022 | struct server *next; |
| 6023 | |
| 6024 | next = curproxy->srv->next; |
| 6025 | curproxy->srv->next = newsrv; |
| 6026 | newsrv = curproxy->srv; |
| 6027 | if (!next) |
| 6028 | break; |
| 6029 | curproxy->srv = next; |
| 6030 | } |
| 6031 | |
Willy Tarreau | dd70165 | 2010-05-25 23:03:02 +0200 | [diff] [blame] | 6032 | /* assign automatic UIDs to servers which don't have one yet */ |
| 6033 | next_id = 1; |
| 6034 | newsrv = curproxy->srv; |
| 6035 | while (newsrv != NULL) { |
| 6036 | if (!newsrv->puid) { |
| 6037 | /* server ID not set, use automatic numbering with first |
| 6038 | * spare entry starting with next_svid. |
| 6039 | */ |
| 6040 | next_id = get_next_id(&curproxy->conf.used_server_id, next_id); |
| 6041 | newsrv->conf.id.key = newsrv->puid = next_id; |
| 6042 | eb32_insert(&curproxy->conf.used_server_id, &newsrv->conf.id); |
| 6043 | } |
| 6044 | next_id++; |
| 6045 | newsrv = newsrv->next; |
| 6046 | } |
| 6047 | |
Willy Tarreau | 2069704 | 2007-11-15 23:26:18 +0100 | [diff] [blame] | 6048 | curproxy->lbprm.wmult = 1; /* default weight multiplier */ |
Willy Tarreau | 5dc2fa6 | 2007-11-19 19:10:18 +0100 | [diff] [blame] | 6049 | curproxy->lbprm.wdiv = 1; /* default weight divider */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6050 | |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6051 | /* We have to initialize the server lookup mechanism depending |
| 6052 | * on what LB algorithm was choosen. |
| 6053 | */ |
| 6054 | |
| 6055 | curproxy->lbprm.algo &= ~(BE_LB_LKUP | BE_LB_PROP_DYN); |
| 6056 | switch (curproxy->lbprm.algo & BE_LB_KIND) { |
| 6057 | case BE_LB_KIND_RR: |
Willy Tarreau | 9757a38 | 2009-10-03 12:56:50 +0200 | [diff] [blame] | 6058 | if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_RR_STATIC) { |
| 6059 | curproxy->lbprm.algo |= BE_LB_LKUP_MAP; |
| 6060 | init_server_map(curproxy); |
| 6061 | } else { |
| 6062 | curproxy->lbprm.algo |= BE_LB_LKUP_RRTREE | BE_LB_PROP_DYN; |
| 6063 | fwrr_init_server_groups(curproxy); |
| 6064 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6065 | break; |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 6066 | |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6067 | case BE_LB_KIND_LC: |
| 6068 | curproxy->lbprm.algo |= BE_LB_LKUP_LCTREE | BE_LB_PROP_DYN; |
Willy Tarreau | 5140623 | 2008-03-10 22:04:20 +0100 | [diff] [blame] | 6069 | fwlc_init_server_tree(curproxy); |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6070 | break; |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 6071 | |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6072 | case BE_LB_KIND_HI: |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 6073 | if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS) { |
| 6074 | curproxy->lbprm.algo |= BE_LB_LKUP_CHTREE | BE_LB_PROP_DYN; |
| 6075 | chash_init_server_tree(curproxy); |
| 6076 | } else { |
| 6077 | curproxy->lbprm.algo |= BE_LB_LKUP_MAP; |
| 6078 | init_server_map(curproxy); |
| 6079 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6080 | break; |
| 6081 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6082 | |
| 6083 | if (curproxy->options & PR_O_LOGASAP) |
| 6084 | curproxy->to_log &= ~LW_BYTES; |
| 6085 | |
Willy Tarreau | e7ded1f | 2009-08-09 10:11:45 +0200 | [diff] [blame] | 6086 | if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) && |
| 6087 | (curproxy->cap & PR_CAP_FE) && curproxy->to_log && curproxy->logfac1 < 0) { |
| 6088 | Warning("config : log format ignored for %s '%s' since it has no log address.\n", |
| 6089 | proxy_type_str(curproxy), curproxy->id); |
| 6090 | err_code |= ERR_WARN; |
| 6091 | } |
| 6092 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 6093 | if (curproxy->mode != PR_MODE_HTTP) { |
| 6094 | int optnum; |
| 6095 | |
| 6096 | if (curproxy->options & PR_O_COOK_ANY) { |
| 6097 | Warning("config : 'cookie' statement ignored for %s '%s' as it requires HTTP mode.\n", |
| 6098 | proxy_type_str(curproxy), curproxy->id); |
| 6099 | err_code |= ERR_WARN; |
| 6100 | } |
| 6101 | |
| 6102 | if (curproxy->uri_auth) { |
| 6103 | Warning("config : 'stats' statement ignored for %s '%s' as it requires HTTP mode.\n", |
| 6104 | proxy_type_str(curproxy), curproxy->id); |
| 6105 | err_code |= ERR_WARN; |
| 6106 | curproxy->uri_auth = NULL; |
| 6107 | } |
| 6108 | |
| 6109 | if (curproxy->options & PR_O_FWDFOR) { |
| 6110 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6111 | "forwardfor", proxy_type_str(curproxy), curproxy->id); |
| 6112 | err_code |= ERR_WARN; |
| 6113 | curproxy->options &= ~PR_O_FWDFOR; |
| 6114 | } |
| 6115 | |
| 6116 | if (curproxy->options & PR_O_ORGTO) { |
| 6117 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6118 | "originalto", proxy_type_str(curproxy), curproxy->id); |
| 6119 | err_code |= ERR_WARN; |
| 6120 | curproxy->options &= ~PR_O_ORGTO; |
| 6121 | } |
| 6122 | |
| 6123 | for (optnum = 0; cfg_opts[optnum].name; optnum++) { |
| 6124 | if (cfg_opts[optnum].mode == PR_MODE_HTTP && |
| 6125 | (curproxy->cap & cfg_opts[optnum].cap) && |
| 6126 | (curproxy->options & cfg_opts[optnum].val)) { |
| 6127 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6128 | cfg_opts[optnum].name, proxy_type_str(curproxy), curproxy->id); |
| 6129 | err_code |= ERR_WARN; |
| 6130 | curproxy->options &= ~cfg_opts[optnum].val; |
| 6131 | } |
| 6132 | } |
| 6133 | |
| 6134 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) { |
| 6135 | if (cfg_opts2[optnum].mode == PR_MODE_HTTP && |
| 6136 | (curproxy->cap & cfg_opts2[optnum].cap) && |
| 6137 | (curproxy->options2 & cfg_opts2[optnum].val)) { |
| 6138 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6139 | cfg_opts2[optnum].name, proxy_type_str(curproxy), curproxy->id); |
| 6140 | err_code |= ERR_WARN; |
| 6141 | curproxy->options2 &= ~cfg_opts2[optnum].val; |
| 6142 | } |
| 6143 | } |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6144 | |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 6145 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6146 | if (curproxy->bind_hdr_occ) { |
| 6147 | curproxy->bind_hdr_occ = 0; |
| 6148 | Warning("config : %s '%s' : ignoring use of header %s as source IP in non-HTTP mode.\n", |
| 6149 | proxy_type_str(curproxy), curproxy->id, curproxy->bind_hdr_name); |
| 6150 | err_code |= ERR_WARN; |
| 6151 | } |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 6152 | #endif |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 6153 | } |
| 6154 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6155 | /* |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 6156 | * ensure that we're not cross-dressing a TCP server into HTTP. |
| 6157 | */ |
| 6158 | newsrv = curproxy->srv; |
| 6159 | while (newsrv != NULL) { |
| 6160 | if ((curproxy->mode != PR_MODE_HTTP) && (newsrv->rdr_len || newsrv->cklen)) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6161 | Alert("config : %s '%s' : server cannot have cookie or redirect prefix in non-HTTP mode.\n", |
| 6162 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6163 | cfgerr++; |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 6164 | } |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6165 | |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 6166 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6167 | if (curproxy->mode != PR_MODE_HTTP && newsrv->bind_hdr_occ) { |
| 6168 | newsrv->bind_hdr_occ = 0; |
| 6169 | Warning("config : %s '%s' : server %s cannot use header %s as source IP in non-HTTP mode.\n", |
| 6170 | proxy_type_str(curproxy), curproxy->id, newsrv->id, newsrv->bind_hdr_name); |
| 6171 | err_code |= ERR_WARN; |
| 6172 | } |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 6173 | #endif |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 6174 | newsrv = newsrv->next; |
| 6175 | } |
| 6176 | |
| 6177 | /* |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6178 | * If this server supports a maxconn parameter, it needs a dedicated |
| 6179 | * tasks to fill the emptied slots when a connection leaves. |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 6180 | * Also, resolve deferred tracking dependency if needed. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6181 | */ |
| 6182 | newsrv = curproxy->srv; |
| 6183 | while (newsrv != NULL) { |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 6184 | if (newsrv->minconn > newsrv->maxconn) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6185 | /* Only 'minconn' was specified, or it was higher than or equal |
| 6186 | * to 'maxconn'. Let's turn this into maxconn and clean it, as |
| 6187 | * this will avoid further useless expensive computations. |
| 6188 | */ |
| 6189 | newsrv->maxconn = newsrv->minconn; |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 6190 | } else if (newsrv->maxconn && !newsrv->minconn) { |
| 6191 | /* minconn was not specified, so we set it to maxconn */ |
| 6192 | newsrv->minconn = newsrv->maxconn; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 6193 | } else if (newsrv->minconn != newsrv->maxconn && !curproxy->fullconn) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6194 | Alert("config : %s '%s' : fullconn is mandatory when minconn is set on a server.\n", |
| 6195 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6196 | cfgerr++; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6197 | } |
| 6198 | |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 6199 | if (newsrv->trackit) { |
| 6200 | struct proxy *px; |
| 6201 | struct server *srv; |
| 6202 | char *pname, *sname; |
| 6203 | |
| 6204 | pname = newsrv->trackit; |
| 6205 | sname = strrchr(pname, '/'); |
| 6206 | |
| 6207 | if (sname) |
| 6208 | *sname++ = '\0'; |
| 6209 | else { |
| 6210 | sname = pname; |
| 6211 | pname = NULL; |
| 6212 | } |
| 6213 | |
| 6214 | if (pname) { |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 6215 | px = findproxy(pname, PR_CAP_BE); |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 6216 | if (!px) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6217 | Alert("config : %s '%s', server '%s': unable to find required proxy '%s' for tracking.\n", |
| 6218 | proxy_type_str(curproxy), curproxy->id, |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 6219 | newsrv->id, pname); |
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 | } else |
| 6224 | px = curproxy; |
| 6225 | |
| 6226 | srv = findserver(px, sname); |
| 6227 | if (!srv) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6228 | Alert("config : %s '%s', server '%s': unable to find required server '%s' for tracking.\n", |
| 6229 | proxy_type_str(curproxy), curproxy->id, |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 6230 | newsrv->id, sname); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6231 | cfgerr++; |
| 6232 | goto next_srv; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 6233 | } |
| 6234 | |
| 6235 | if (!(srv->state & SRV_CHECKED)) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6236 | Alert("config : %s '%s', server '%s': unable to use %s/%s for " |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 6237 | "tracking as it does not have checks enabled.\n", |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6238 | proxy_type_str(curproxy), curproxy->id, |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 6239 | newsrv->id, px->id, srv->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6240 | cfgerr++; |
| 6241 | goto next_srv; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 6242 | } |
| 6243 | |
| 6244 | if (curproxy != px && |
| 6245 | (curproxy->options & PR_O_DISABLE404) != (px->options & PR_O_DISABLE404)) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6246 | Alert("config : %s '%s', server '%s': unable to use %s/%s for" |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 6247 | "tracking: disable-on-404 option inconsistency.\n", |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6248 | proxy_type_str(curproxy), curproxy->id, |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 6249 | newsrv->id, px->id, srv->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6250 | cfgerr++; |
| 6251 | goto next_srv; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 6252 | } |
| 6253 | |
| 6254 | newsrv->tracked = srv; |
| 6255 | newsrv->tracknext = srv->tracknext; |
| 6256 | srv->tracknext = newsrv; |
| 6257 | |
| 6258 | free(newsrv->trackit); |
| 6259 | } |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6260 | next_srv: |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6261 | newsrv = newsrv->next; |
| 6262 | } |
| 6263 | |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6264 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 6265 | curproxy->accept = frontend_accept; |
| 6266 | |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6267 | if (curproxy->tcp_req.inspect_delay || |
| 6268 | !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules)) |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 6269 | curproxy->fe_req_ana |= AN_REQ_INSPECT_FE; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6270 | |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 6271 | if (curproxy->mode == PR_MODE_HTTP) { |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6272 | 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] | 6273 | 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] | 6274 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6275 | |
| 6276 | /* both TCP and HTTP must check switching rules */ |
| 6277 | curproxy->fe_req_ana |= AN_REQ_SWITCHING_RULES; |
| 6278 | } |
| 6279 | |
| 6280 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 6281 | if (curproxy->tcp_req.inspect_delay || |
| 6282 | !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules)) |
| 6283 | curproxy->be_req_ana |= AN_REQ_INSPECT_BE; |
| 6284 | |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 6285 | if (!LIST_ISEMPTY(&curproxy->tcp_rep.inspect_rules)) |
| 6286 | curproxy->be_rsp_ana |= AN_RES_INSPECT; |
| 6287 | |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 6288 | if (curproxy->mode == PR_MODE_HTTP) { |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6289 | 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] | 6290 | 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] | 6291 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6292 | |
| 6293 | /* If the backend does requires RDP cookie persistence, we have to |
| 6294 | * enable the corresponding analyser. |
| 6295 | */ |
| 6296 | if (curproxy->options2 & PR_O2_RDPC_PRST) |
| 6297 | curproxy->be_req_ana |= AN_REQ_PRST_RDP_COOKIE; |
| 6298 | } |
| 6299 | |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 6300 | listener = NULL; |
| 6301 | while (curproxy->listen) { |
| 6302 | struct listener *next; |
| 6303 | |
| 6304 | next = curproxy->listen->next; |
| 6305 | curproxy->listen->next = listener; |
| 6306 | listener = curproxy->listen; |
| 6307 | |
| 6308 | if (!next) |
| 6309 | break; |
| 6310 | |
| 6311 | curproxy->listen = next; |
| 6312 | } |
| 6313 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 6314 | /* adjust this proxy's listeners */ |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6315 | next_id = 1; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 6316 | listener = curproxy->listen; |
| 6317 | while (listener) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6318 | if (!listener->luid) { |
| 6319 | /* listener ID not set, use automatic numbering with first |
| 6320 | * spare entry starting with next_luid. |
| 6321 | */ |
| 6322 | next_id = get_next_id(&curproxy->conf.used_listener_id, next_id); |
| 6323 | listener->conf.id.key = listener->luid = next_id; |
| 6324 | eb32_insert(&curproxy->conf.used_listener_id, &listener->conf.id); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6325 | } |
Krzysztof Piotr Oledzki | df5cb9f | 2010-02-05 20:58:27 +0100 | [diff] [blame] | 6326 | next_id++; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6327 | |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 6328 | /* enable separate counters */ |
| 6329 | if (curproxy->options2 & PR_O2_SOCKSTAT) { |
| 6330 | listener->counters = (struct licounters *)calloc(1, sizeof(struct licounters)); |
| 6331 | if (!listener->name) { |
| 6332 | sprintf(trash, "sock-%d", listener->luid); |
| 6333 | listener->name = strdup(trash); |
| 6334 | } |
| 6335 | } |
| 6336 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 6337 | if (curproxy->options & PR_O_TCP_NOLING) |
| 6338 | listener->options |= LI_O_NOLINGER; |
| 6339 | listener->maxconn = curproxy->maxconn; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 6340 | listener->backlog = curproxy->backlog; |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6341 | listener->timeout = &curproxy->timeout.client; |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 6342 | listener->accept = session_accept; |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 6343 | listener->frontend = curproxy; |
Willy Tarreau | 3bc1377 | 2008-12-07 11:50:35 +0100 | [diff] [blame] | 6344 | listener->handler = process_session; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6345 | listener->analysers |= curproxy->fe_req_ana; |
Willy Tarreau | 3bc1377 | 2008-12-07 11:50:35 +0100 | [diff] [blame] | 6346 | |
Willy Tarreau | 8a95691 | 2010-10-15 14:27:08 +0200 | [diff] [blame] | 6347 | if (listener->options & LI_O_ACC_PROXY) |
| 6348 | listener->analysers |= AN_REQ_DECODE_PROXY; |
| 6349 | |
Willy Tarreau | a5c0ab2 | 2010-05-31 10:30:33 +0200 | [diff] [blame] | 6350 | if (!LIST_ISEMPTY(&curproxy->tcp_req.l4_rules)) |
| 6351 | listener->options |= LI_O_TCP_RULES; |
| 6352 | |
Willy Tarreau | de3041d | 2010-05-31 10:56:17 +0200 | [diff] [blame] | 6353 | if (curproxy->mon_mask.s_addr) |
| 6354 | listener->options |= LI_O_CHK_MONNET; |
| 6355 | |
Willy Tarreau | 9ea05a7 | 2009-06-14 12:07:01 +0200 | [diff] [blame] | 6356 | /* smart accept mode is automatic in HTTP mode */ |
| 6357 | if ((curproxy->options2 & PR_O2_SMARTACC) || |
| 6358 | (curproxy->mode == PR_MODE_HTTP && |
| 6359 | !(curproxy->no_options2 & PR_O2_SMARTACC))) |
| 6360 | listener->options |= LI_O_NOQUICKACK; |
| 6361 | |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 6362 | /* We want the use_backend and default_backend rules to apply */ |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 6363 | listener = listener->next; |
| 6364 | } |
| 6365 | |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 6366 | /* Check multi-process mode compatibility for the current proxy */ |
| 6367 | if (global.nbproc > 1) { |
| 6368 | int nbproc = 0; |
| 6369 | if (curproxy->bind_proc) { |
| 6370 | int proc; |
| 6371 | for (proc = 0; proc < global.nbproc; proc++) { |
| 6372 | if (curproxy->bind_proc & (1 << proc)) { |
| 6373 | nbproc++; |
| 6374 | } |
| 6375 | } |
| 6376 | } else { |
| 6377 | nbproc = global.nbproc; |
| 6378 | } |
| 6379 | if (curproxy->table.peers.name) { |
| 6380 | Alert("Proxy '%s': peers can't be used in multi-process mode (nbproc > 1).\n", |
| 6381 | curproxy->id); |
| 6382 | cfgerr++; |
| 6383 | } |
| 6384 | if (nbproc > 1) { |
| 6385 | if (curproxy->uri_auth) { |
| 6386 | Warning("Proxy '%s': in multi-process mode, stats will be limited to process assigned to the current request.\n", |
| 6387 | curproxy->id); |
| 6388 | if (!LIST_ISEMPTY(&curproxy->uri_auth->admin_rules)) { |
| 6389 | Warning("Proxy '%s': stats admin will not work correctly in multi-process mode.\n", |
| 6390 | curproxy->id); |
| 6391 | } |
| 6392 | } |
| 6393 | if (curproxy->appsession_name) { |
| 6394 | Warning("Proxy '%s': appsession will not work correctly in multi-process mode.\n", |
| 6395 | curproxy->id); |
| 6396 | } |
| 6397 | if (!LIST_ISEMPTY(&curproxy->sticking_rules)) { |
| 6398 | Warning("Proxy '%s': sticking rules will not work correctly in multi-process mode.\n", |
| 6399 | curproxy->id); |
| 6400 | } |
| 6401 | } |
| 6402 | } |
| 6403 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6404 | curproxy = curproxy->next; |
| 6405 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 6406 | |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 6407 | /* Check multi-process mode compatibility */ |
| 6408 | if (global.nbproc > 1) { |
| 6409 | if (global.stats_fe) { |
| 6410 | Warning("stats socket will not work correctly in multi-process mode (nbproc > 1).\n"); |
| 6411 | } |
| 6412 | } |
| 6413 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6414 | for (curuserlist = userlist; curuserlist; curuserlist = curuserlist->next) { |
| 6415 | struct auth_users *curuser; |
| 6416 | int g; |
| 6417 | |
| 6418 | for (curuser = curuserlist->users; curuser; curuser = curuser->next) { |
| 6419 | unsigned int group_mask = 0; |
| 6420 | char *group = NULL; |
| 6421 | |
Willy Tarreau | b4c06b7 | 2010-02-02 11:28:20 +0100 | [diff] [blame] | 6422 | if (!curuser->u.groups) |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6423 | continue; |
| 6424 | |
Willy Tarreau | b4c06b7 | 2010-02-02 11:28:20 +0100 | [diff] [blame] | 6425 | while ((group = strtok(group?NULL:curuser->u.groups, ","))) { |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6426 | |
| 6427 | for (g = 0; g < curuserlist->grpcnt; g++) |
| 6428 | if (!strcmp(curuserlist->groups[g], group)) |
| 6429 | break; |
| 6430 | |
| 6431 | if (g == curuserlist->grpcnt) { |
| 6432 | Alert("userlist '%s': no such group '%s' specified in user '%s'\n", |
| 6433 | curuserlist->name, group, curuser->user); |
| 6434 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6435 | goto out; |
| 6436 | } |
| 6437 | |
| 6438 | group_mask |= (1 << g); |
| 6439 | } |
| 6440 | |
Willy Tarreau | b4c06b7 | 2010-02-02 11:28:20 +0100 | [diff] [blame] | 6441 | free(curuser->u.groups); |
| 6442 | curuser->u.group_mask = group_mask; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6443 | } |
| 6444 | |
| 6445 | for (g = 0; g < curuserlist->grpcnt; g++) { |
| 6446 | char *user = NULL; |
| 6447 | |
| 6448 | if (!curuserlist->groupusers[g]) |
| 6449 | continue; |
| 6450 | |
| 6451 | while ((user = strtok(user?NULL:curuserlist->groupusers[g], ","))) { |
| 6452 | for (curuser = curuserlist->users; curuser; curuser = curuser->next) |
| 6453 | if (!strcmp(curuser->user, user)) |
| 6454 | break; |
| 6455 | |
| 6456 | if (!curuser) { |
| 6457 | Alert("userlist '%s': no such user '%s' specified in group '%s'\n", |
| 6458 | curuserlist->name, user, curuserlist->groups[g]); |
| 6459 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6460 | goto out; |
| 6461 | } |
| 6462 | |
Willy Tarreau | b4c06b7 | 2010-02-02 11:28:20 +0100 | [diff] [blame] | 6463 | curuser->u.group_mask |= (1 << g); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6464 | } |
| 6465 | |
| 6466 | free(curuserlist->groupusers[g]); |
| 6467 | } |
| 6468 | |
| 6469 | free(curuserlist->groupusers); |
| 6470 | |
| 6471 | #ifdef DEBUG_AUTH |
| 6472 | for (g = 0; g < curuserlist->grpcnt; g++) { |
| 6473 | fprintf(stderr, "group %s, id %d, mask %08X, users:", curuserlist->groups[g], g , 1 << g); |
| 6474 | |
| 6475 | for (curuser = curuserlist->users; curuser; curuser = curuser->next) { |
| 6476 | if (curuser->group_mask & (1 << g)) |
| 6477 | fprintf(stderr, " %s", curuser->user); |
| 6478 | } |
| 6479 | |
| 6480 | fprintf(stderr, "\n"); |
| 6481 | } |
| 6482 | #endif |
| 6483 | |
| 6484 | } |
| 6485 | |
Willy Tarreau | 056f568 | 2010-06-06 15:51:11 +0200 | [diff] [blame] | 6486 | /* initialize stick-tables on backend capable proxies. This must not |
| 6487 | * be done earlier because the data size may be discovered while parsing |
| 6488 | * other proxies. |
| 6489 | */ |
| 6490 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) |
Willy Tarreau | c00cdc2 | 2010-06-06 16:48:26 +0200 | [diff] [blame] | 6491 | stktable_init(&curproxy->table); |
Willy Tarreau | 056f568 | 2010-06-06 15:51:11 +0200 | [diff] [blame] | 6492 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 6493 | /* |
| 6494 | * Recount currently required checks. |
| 6495 | */ |
| 6496 | |
| 6497 | for (curproxy=proxy; curproxy; curproxy=curproxy->next) { |
| 6498 | int optnum; |
| 6499 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 6500 | for (optnum = 0; cfg_opts[optnum].name; optnum++) |
| 6501 | if (curproxy->options & cfg_opts[optnum].val) |
| 6502 | global.last_checks |= cfg_opts[optnum].checks; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 6503 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 6504 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) |
| 6505 | if (curproxy->options2 & cfg_opts2[optnum].val) |
| 6506 | global.last_checks |= cfg_opts2[optnum].checks; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 6507 | } |
| 6508 | |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6509 | if (cfgerr > 0) |
| 6510 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6511 | out: |
| 6512 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6513 | } |
| 6514 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 6515 | /* |
| 6516 | * Registers the CFG keyword list <kwl> as a list of valid keywords for next |
| 6517 | * parsing sessions. |
| 6518 | */ |
| 6519 | void cfg_register_keywords(struct cfg_kw_list *kwl) |
| 6520 | { |
| 6521 | LIST_ADDQ(&cfg_keywords.list, &kwl->list); |
| 6522 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6523 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 6524 | /* |
| 6525 | * Unregisters the CFG keyword list <kwl> from the list of valid keywords. |
| 6526 | */ |
| 6527 | void cfg_unregister_keywords(struct cfg_kw_list *kwl) |
| 6528 | { |
| 6529 | LIST_DEL(&kwl->list); |
| 6530 | LIST_INIT(&kwl->list); |
| 6531 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6532 | |
| 6533 | /* |
| 6534 | * Local variables: |
| 6535 | * c-indent-level: 8 |
| 6536 | * c-basic-offset: 8 |
| 6537 | * End: |
| 6538 | */ |