Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Configuration parser |
| 3 | * |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 4 | * Copyright 2000-2011 Willy Tarreau <w@1wt.eu> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * as published by the Free Software Foundation; either version |
| 9 | * 2 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | */ |
| 12 | |
| 13 | #include <stdio.h> |
| 14 | #include <stdlib.h> |
| 15 | #include <string.h> |
| 16 | #include <netdb.h> |
| 17 | #include <ctype.h> |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 18 | #include <pwd.h> |
| 19 | #include <grp.h> |
Willy Tarreau | 0b4ed90 | 2007-03-26 00:18:40 +0200 | [diff] [blame] | 20 | #include <errno.h> |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 21 | #include <sys/types.h> |
| 22 | #include <sys/stat.h> |
| 23 | #include <fcntl.h> |
| 24 | #include <unistd.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 25 | |
Willy Tarreau | be1b918 | 2009-06-14 18:48:19 +0200 | [diff] [blame] | 26 | #include <netinet/tcp.h> |
| 27 | |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 28 | #include <common/cfgparse.h> |
| 29 | #include <common/config.h> |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 30 | #include <common/errors.h> |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 31 | #include <common/memory.h> |
| 32 | #include <common/standard.h> |
| 33 | #include <common/time.h> |
| 34 | #include <common/uri_auth.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 35 | |
| 36 | #include <types/capture.h> |
| 37 | #include <types/global.h> |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 38 | #include <types/peers.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 39 | |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 40 | #include <proto/acl.h> |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 41 | #include <proto/auth.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 42 | #include <proto/backend.h> |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 43 | #include <proto/buffers.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 44 | #include <proto/checks.h> |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 45 | #include <proto/dumpstats.h> |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 46 | #include <proto/frontend.h> |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 47 | #include <proto/hdr_idx.h> |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 48 | #include <proto/lb_chash.h> |
Willy Tarreau | f09c660 | 2012-02-13 17:12:08 +0100 | [diff] [blame] | 49 | #include <proto/lb_fas.h> |
Willy Tarreau | f89c187 | 2009-10-01 11:19:37 +0200 | [diff] [blame] | 50 | #include <proto/lb_fwlc.h> |
| 51 | #include <proto/lb_fwrr.h> |
| 52 | #include <proto/lb_map.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 53 | #include <proto/log.h> |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 54 | #include <proto/port_range.h> |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 55 | #include <proto/protocols.h> |
| 56 | #include <proto/proto_tcp.h> |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 57 | #include <proto/proto_uxst.h> |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 58 | #include <proto/proto_http.h> |
Willy Tarreau | 2b5652f | 2006-12-31 17:46:05 +0100 | [diff] [blame] | 59 | #include <proto/proxy.h> |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 60 | #include <proto/peers.h> |
Willy Tarreau | cd3b094 | 2012-04-27 21:52:18 +0200 | [diff] [blame] | 61 | #include <proto/sample.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 62 | #include <proto/server.h> |
Willy Tarreau | 3bc1377 | 2008-12-07 11:50:35 +0100 | [diff] [blame] | 63 | #include <proto/session.h> |
Willy Tarreau | d02394b | 2012-05-11 18:32:18 +0200 | [diff] [blame] | 64 | #include <proto/sock_raw.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 65 | #include <proto/task.h> |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 66 | #include <proto/stick_table.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 67 | |
| 68 | |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 69 | /* This is the SSLv3 CLIENT HELLO packet used in conjunction with the |
| 70 | * ssl-hello-chk option to ensure that the remote server speaks SSL. |
| 71 | * |
| 72 | * Check RFC 2246 (TLSv1.0) sections A.3 and A.4 for details. |
| 73 | */ |
| 74 | const char sslv3_client_hello_pkt[] = { |
| 75 | "\x16" /* ContentType : 0x16 = Hanshake */ |
| 76 | "\x03\x00" /* ProtocolVersion : 0x0300 = SSLv3 */ |
| 77 | "\x00\x79" /* ContentLength : 0x79 bytes after this one */ |
| 78 | "\x01" /* HanshakeType : 0x01 = CLIENT HELLO */ |
| 79 | "\x00\x00\x75" /* HandshakeLength : 0x75 bytes after this one */ |
| 80 | "\x03\x00" /* Hello Version : 0x0300 = v3 */ |
| 81 | "\x00\x00\x00\x00" /* Unix GMT Time (s) : filled with <now> (@0x0B) */ |
| 82 | "HAPROXYSSLCHK\nHAPROXYSSLCHK\n" /* Random : must be exactly 28 bytes */ |
| 83 | "\x00" /* Session ID length : empty (no session ID) */ |
| 84 | "\x00\x4E" /* Cipher Suite Length : 78 bytes after this one */ |
| 85 | "\x00\x01" "\x00\x02" "\x00\x03" "\x00\x04" /* 39 most common ciphers : */ |
| 86 | "\x00\x05" "\x00\x06" "\x00\x07" "\x00\x08" /* 0x01...0x1B, 0x2F...0x3A */ |
| 87 | "\x00\x09" "\x00\x0A" "\x00\x0B" "\x00\x0C" /* This covers RSA/DH, */ |
| 88 | "\x00\x0D" "\x00\x0E" "\x00\x0F" "\x00\x10" /* various bit lengths, */ |
| 89 | "\x00\x11" "\x00\x12" "\x00\x13" "\x00\x14" /* SHA1/MD5, DES/3DES/AES... */ |
| 90 | "\x00\x15" "\x00\x16" "\x00\x17" "\x00\x18" |
| 91 | "\x00\x19" "\x00\x1A" "\x00\x1B" "\x00\x2F" |
| 92 | "\x00\x30" "\x00\x31" "\x00\x32" "\x00\x33" |
| 93 | "\x00\x34" "\x00\x35" "\x00\x36" "\x00\x37" |
| 94 | "\x00\x38" "\x00\x39" "\x00\x3A" |
| 95 | "\x01" /* Compression Length : 0x01 = 1 byte for types */ |
| 96 | "\x00" /* Compression Type : 0x00 = NULL compression */ |
| 97 | }; |
| 98 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 99 | /* various keyword modifiers */ |
| 100 | enum kw_mod { |
| 101 | KWM_STD = 0, /* normal */ |
| 102 | KWM_NO, /* "no" prefixed before the keyword */ |
| 103 | KWM_DEF, /* "default" prefixed before the keyword */ |
| 104 | }; |
| 105 | |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 106 | /* 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] | 107 | struct cfg_opt { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 108 | const char *name; |
| 109 | unsigned int val; |
| 110 | unsigned int cap; |
Willy Tarreau | 4fee4e9 | 2007-01-06 21:09:17 +0100 | [diff] [blame] | 111 | unsigned int checks; |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 112 | unsigned int mode; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 113 | }; |
| 114 | |
| 115 | /* proxy->options */ |
| 116 | static const struct cfg_opt cfg_opts[] = |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 117 | { |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 118 | { "abortonclose", PR_O_ABRT_CLOSE, PR_CAP_BE, 0, 0 }, |
| 119 | { "allbackups", PR_O_USE_ALL_BK, PR_CAP_BE, 0, 0 }, |
| 120 | { "checkcache", PR_O_CHK_CACHE, PR_CAP_BE, 0, PR_MODE_HTTP }, |
| 121 | { "clitcpka", PR_O_TCP_CLI_KA, PR_CAP_FE, 0, 0 }, |
| 122 | { "contstats", PR_O_CONTSTATS, PR_CAP_FE, 0, 0 }, |
| 123 | { "dontlognull", PR_O_NULLNOLOG, PR_CAP_FE, 0, 0 }, |
| 124 | { "forceclose", PR_O_FORCE_CLO, PR_CAP_FE | PR_CAP_BE, 0, PR_MODE_HTTP }, |
| 125 | { "http_proxy", PR_O_HTTP_PROXY, PR_CAP_FE | PR_CAP_BE, 0, PR_MODE_HTTP }, |
| 126 | { "httpclose", PR_O_HTTP_CLOSE, PR_CAP_FE | PR_CAP_BE, 0, PR_MODE_HTTP }, |
| 127 | { "keepalive", PR_O_KEEPALIVE, PR_CAP_NONE, 0, PR_MODE_HTTP }, |
| 128 | { "http-server-close", PR_O_SERVER_CLO, PR_CAP_FE | PR_CAP_BE, 0, PR_MODE_HTTP }, |
| 129 | { "logasap", PR_O_LOGASAP, PR_CAP_FE, 0, 0 }, |
| 130 | { "nolinger", PR_O_TCP_NOLING, PR_CAP_FE | PR_CAP_BE, 0, 0 }, |
| 131 | { "persist", PR_O_PERSIST, PR_CAP_BE, 0, 0 }, |
| 132 | { "redispatch", PR_O_REDISP, PR_CAP_BE, 0, 0 }, |
| 133 | { "srvtcpka", PR_O_TCP_SRV_KA, PR_CAP_BE, 0, 0 }, |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 134 | #ifdef TPROXY |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 135 | { "transparent", PR_O_TRANSP, PR_CAP_BE, 0, 0 }, |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 136 | #else |
| 137 | { "transparent", 0, 0, 0, 0 }, |
Willy Tarreau | 8f922fc | 2007-01-06 21:11:49 +0100 | [diff] [blame] | 138 | #endif |
| 139 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 140 | { NULL, 0, 0, 0, 0 } |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 141 | }; |
| 142 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 143 | /* proxy->options2 */ |
| 144 | static const struct cfg_opt cfg_opts2[] = |
| 145 | { |
| 146 | #ifdef CONFIG_HAP_LINUX_SPLICE |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 147 | { "splice-request", PR_O2_SPLIC_REQ, PR_CAP_FE|PR_CAP_BE, 0, 0 }, |
| 148 | { "splice-response", PR_O2_SPLIC_RTR, PR_CAP_FE|PR_CAP_BE, 0, 0 }, |
| 149 | { "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] | 150 | #else |
| 151 | { "splice-request", 0, 0, 0, 0 }, |
| 152 | { "splice-response", 0, 0, 0, 0 }, |
| 153 | { "splice-auto", 0, 0, 0, 0 }, |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 154 | #endif |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 155 | { "accept-invalid-http-request", PR_O2_REQBUG_OK, PR_CAP_FE, 0, PR_MODE_HTTP }, |
| 156 | { "accept-invalid-http-response", PR_O2_RSPBUG_OK, PR_CAP_BE, 0, PR_MODE_HTTP }, |
| 157 | { "dontlog-normal", PR_O2_NOLOGNORM, PR_CAP_FE, 0, 0 }, |
| 158 | { "log-separate-errors", PR_O2_LOGERRORS, PR_CAP_FE, 0, 0 }, |
| 159 | { "log-health-checks", PR_O2_LOGHCHKS, PR_CAP_BE, 0, 0 }, |
| 160 | { "socket-stats", PR_O2_SOCKSTAT, PR_CAP_FE, 0, 0 }, |
| 161 | { "tcp-smart-accept", PR_O2_SMARTACC, PR_CAP_FE, 0, 0 }, |
| 162 | { "tcp-smart-connect", PR_O2_SMARTCON, PR_CAP_BE, 0, 0 }, |
| 163 | { "independant-streams", PR_O2_INDEPSTR, PR_CAP_FE|PR_CAP_BE, 0, 0 }, |
| 164 | { "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] | 165 | { "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] | 166 | { "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] | 167 | { NULL, 0, 0, 0 } |
| 168 | }; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 169 | |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 170 | static char *cursection = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 171 | static struct proxy defproxy; /* fake proxy used to assign default values on all instances */ |
| 172 | int cfg_maxpconn = DEFAULT_MAXCONN; /* # of simultaneous connections per proxy (-N) */ |
Willy Tarreau | 5af24ef | 2009-03-15 15:23:16 +0100 | [diff] [blame] | 173 | int cfg_maxconn = 0; /* # of simultaneous connections, (-n) */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 174 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 175 | /* List head of all known configuration keywords */ |
| 176 | static struct cfg_kw_list cfg_keywords = { |
| 177 | .list = LIST_HEAD_INIT(cfg_keywords.list) |
| 178 | }; |
| 179 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 180 | /* |
| 181 | * converts <str> to a list of listeners which are dynamically allocated. |
| 182 | * The format is "{addr|'*'}:port[-end][,{addr|'*'}:port[-end]]*", where : |
| 183 | * - <addr> can be empty or "*" to indicate INADDR_ANY ; |
| 184 | * - <port> is a numerical port from 1 to 65535 ; |
| 185 | * - <end> indicates to use the range from <port> to <end> instead (inclusive). |
| 186 | * 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] | 187 | * Function returns 1 for success or 0 if error. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 188 | */ |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 189 | 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] | 190 | { |
| 191 | struct listener *l; |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 192 | char *next, *dupstr; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 193 | int port, end; |
| 194 | |
| 195 | next = dupstr = strdup(str); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 196 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 197 | while (next && *next) { |
| 198 | struct sockaddr_storage ss; |
| 199 | |
| 200 | str = next; |
| 201 | /* 1) look for the end of the first address */ |
Krzysztof Piotr Oledzki | 52d522b | 2009-01-27 16:57:08 +0100 | [diff] [blame] | 202 | if ((next = strchr(str, ',')) != NULL) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 203 | *next++ = 0; |
| 204 | } |
| 205 | |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 206 | if (*str == '/') { |
| 207 | /* sun_path during a soft_stop rename is <unix_bind_prefix><path>.<pid>.<bak|tmp> */ |
| 208 | /* so compute max path */ |
| 209 | int prefix_path_len = global.unix_bind.prefix ? strlen(global.unix_bind.prefix) : 0; |
| 210 | 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] | 211 | |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 212 | if (strlen(str) > max_path_len) { |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 213 | Alert("parsing [%s:%d] : socket path '%s' too long (max %d)\n", |
| 214 | file, line, str, max_path_len); |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 215 | goto fail; |
| 216 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 217 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 218 | memset(&ss, 0, sizeof(ss)); |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 219 | ss.ss_family = AF_UNIX; |
| 220 | if (global.unix_bind.prefix) { |
| 221 | memcpy(((struct sockaddr_un *)&ss)->sun_path, global.unix_bind.prefix, prefix_path_len); |
| 222 | strcpy(((struct sockaddr_un *)&ss)->sun_path+prefix_path_len, str); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 223 | } |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 224 | else { |
| 225 | strcpy(((struct sockaddr_un *)&ss)->sun_path, str); |
| 226 | } |
| 227 | port = end = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 228 | } |
| 229 | else { |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 230 | struct sockaddr_storage *ss2; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 231 | |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 232 | ss2 = str2sa_range(str, &port, &end); |
| 233 | if (!ss2) { |
| 234 | Alert("parsing [%s:%d] : invalid listening address: '%s'\n", |
| 235 | file, line, str); |
| 236 | goto fail; |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 237 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 238 | |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 239 | if (!port) { |
| 240 | Alert("parsing [%s:%d] : missing port number: '%s'\n", |
| 241 | file, line, str); |
| 242 | goto fail; |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 243 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 244 | |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 245 | /* OK the address looks correct */ |
| 246 | ss = *ss2; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 247 | |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 248 | if (port < 1 || port > 65535) { |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 249 | Alert("parsing [%s:%d] : invalid port '%d' specified for address '%s'.\n", |
| 250 | file, line, port, str); |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 251 | goto fail; |
| 252 | } |
| 253 | |
| 254 | if (end < 1 || end > 65535) { |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 255 | Alert("parsing [%s:%d] : invalid port '%d' specified for address '%s'.\n", |
| 256 | file, line, end, str); |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 257 | goto fail; |
| 258 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | for (; port <= end; port++) { |
| 262 | l = (struct listener *)calloc(1, sizeof(struct listener)); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 263 | l->next = curproxy->listen; |
| 264 | curproxy->listen = l; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 265 | |
| 266 | l->fd = -1; |
| 267 | l->addr = ss; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 268 | l->state = LI_INIT; |
| 269 | |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 270 | if (ss.ss_family == AF_INET) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 271 | ((struct sockaddr_in *)(&l->addr))->sin_port = htons(port); |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 272 | tcpv4_add_listener(l); |
| 273 | } |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 274 | else if (ss.ss_family == AF_INET6) { |
| 275 | ((struct sockaddr_in6 *)(&l->addr))->sin6_port = htons(port); |
| 276 | tcpv6_add_listener(l); |
| 277 | } |
| 278 | else { |
| 279 | l->perm.ux.gid = l->perm.ux.uid = -1; |
| 280 | l->perm.ux.mode = 0; |
| 281 | uxst_add_listener(l); |
| 282 | } |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 283 | |
Willy Tarreau | af7ad00 | 2010-08-31 15:39:26 +0200 | [diff] [blame] | 284 | jobs++; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 285 | listeners++; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 286 | } /* end for(port) */ |
| 287 | } /* end while(next) */ |
| 288 | free(dupstr); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 289 | return 1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 290 | fail: |
| 291 | free(dupstr); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 292 | return 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 293 | } |
| 294 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 295 | /* |
| 296 | * Sends a warning if proxy <proxy> does not have at least one of the |
| 297 | * capabilities in <cap>. An optionnal <hint> may be added at the end |
| 298 | * of the warning to help the user. Returns 1 if a warning was emitted |
| 299 | * or 0 if the condition is valid. |
| 300 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 301 | 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] | 302 | { |
| 303 | char *msg; |
| 304 | |
| 305 | switch (cap) { |
| 306 | case PR_CAP_BE: msg = "no backend"; break; |
| 307 | case PR_CAP_FE: msg = "no frontend"; break; |
| 308 | case PR_CAP_RS: msg = "no ruleset"; break; |
| 309 | case PR_CAP_BE|PR_CAP_FE: msg = "neither frontend nor backend"; break; |
| 310 | default: msg = "not enough"; break; |
| 311 | } |
| 312 | |
| 313 | if (!(proxy->cap & cap)) { |
| 314 | 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] | 315 | file, line, arg, proxy_type_str(proxy), proxy->id, msg, hint ? hint : ""); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 316 | return 1; |
| 317 | } |
| 318 | return 0; |
| 319 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 320 | |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 321 | /* Report a warning if a rule is placed after a 'block' rule. |
| 322 | * Return 1 if the warning has been emitted, otherwise 0. |
| 323 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 324 | 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] | 325 | { |
| 326 | if (!LIST_ISEMPTY(&proxy->block_cond)) { |
| 327 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'block' rule will still be processed before.\n", |
| 328 | file, line, arg); |
| 329 | return 1; |
| 330 | } |
| 331 | return 0; |
| 332 | } |
| 333 | |
| 334 | /* Report a warning if a rule is placed after a reqrewrite rule. |
| 335 | * Return 1 if the warning has been emitted, otherwise 0. |
| 336 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 337 | 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] | 338 | { |
| 339 | if (proxy->req_exp) { |
| 340 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'reqxxx' rule will still be processed before.\n", |
| 341 | file, line, arg); |
| 342 | return 1; |
| 343 | } |
| 344 | return 0; |
| 345 | } |
| 346 | |
| 347 | /* Report a warning if a rule is placed after a reqadd rule. |
| 348 | * Return 1 if the warning has been emitted, otherwise 0. |
| 349 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 350 | 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] | 351 | { |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 352 | if (!LIST_ISEMPTY(&proxy->req_add)) { |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 353 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'reqadd' rule will still be processed before.\n", |
| 354 | file, line, arg); |
| 355 | return 1; |
| 356 | } |
| 357 | return 0; |
| 358 | } |
| 359 | |
| 360 | /* Report a warning if a rule is placed after a redirect rule. |
| 361 | * Return 1 if the warning has been emitted, otherwise 0. |
| 362 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 363 | 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] | 364 | { |
| 365 | if (!LIST_ISEMPTY(&proxy->redirect_rules)) { |
| 366 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'redirect' rule will still be processed before.\n", |
| 367 | file, line, arg); |
| 368 | return 1; |
| 369 | } |
| 370 | return 0; |
| 371 | } |
| 372 | |
| 373 | /* Report a warning if a rule is placed after a 'use_backend' rule. |
| 374 | * Return 1 if the warning has been emitted, otherwise 0. |
| 375 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 376 | 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] | 377 | { |
| 378 | if (!LIST_ISEMPTY(&proxy->switching_rules)) { |
| 379 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'use_backend' rule will still be processed before.\n", |
| 380 | file, line, arg); |
| 381 | return 1; |
| 382 | } |
| 383 | return 0; |
| 384 | } |
| 385 | |
| 386 | /* report a warning if a block rule is dangerously placed */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 387 | 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] | 388 | { |
| 389 | return warnif_rule_after_reqxxx(proxy, file, line, arg) || |
| 390 | warnif_rule_after_reqadd(proxy, file, line, arg) || |
| 391 | warnif_rule_after_redirect(proxy, file, line, arg) || |
| 392 | warnif_rule_after_use_backend(proxy, file, line, arg); |
| 393 | } |
| 394 | |
| 395 | /* report a warning if a reqxxx rule is dangerously placed */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 396 | 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] | 397 | { |
| 398 | return warnif_rule_after_reqadd(proxy, file, line, arg) || |
| 399 | warnif_rule_after_redirect(proxy, file, line, arg) || |
| 400 | warnif_rule_after_use_backend(proxy, file, line, arg); |
| 401 | } |
| 402 | |
| 403 | /* report a warning if a reqadd rule is dangerously placed */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 404 | 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] | 405 | { |
| 406 | return warnif_rule_after_redirect(proxy, file, line, arg) || |
| 407 | warnif_rule_after_use_backend(proxy, file, line, arg); |
| 408 | } |
| 409 | |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 410 | /* Report it if a request ACL condition uses some response-only parameters. It |
| 411 | * returns either 0 or ERR_WARN so that its result can be or'ed with err_code. |
| 412 | * Note that <cond> may be NULL and then will be ignored. |
| 413 | */ |
| 414 | static int warnif_cond_requires_resp(const struct acl_cond *cond, const char *file, int line) |
| 415 | { |
| 416 | struct acl *acl; |
| 417 | |
| 418 | if (!cond || !(cond->requires & ACL_USE_RTR_ANY)) |
| 419 | return 0; |
| 420 | |
| 421 | acl = cond_find_require(cond, ACL_USE_RTR_ANY); |
| 422 | Warning("parsing [%s:%d] : acl '%s' involves some response-only criteria which will be ignored.\n", |
| 423 | file, line, acl ? acl->name : "(unknown)"); |
| 424 | return ERR_WARN; |
| 425 | } |
| 426 | |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 427 | /* Report it if a request ACL condition uses some request-only volatile parameters. |
| 428 | * It returns either 0 or ERR_WARN so that its result can be or'ed with err_code. |
| 429 | * Note that <cond> may be NULL and then will be ignored. |
| 430 | */ |
| 431 | static int warnif_cond_requires_req(const struct acl_cond *cond, const char *file, int line) |
| 432 | { |
| 433 | struct acl *acl; |
| 434 | |
| 435 | if (!cond || !(cond->requires & ACL_USE_REQ_VOLATILE)) |
| 436 | return 0; |
| 437 | |
| 438 | acl = cond_find_require(cond, ACL_USE_REQ_VOLATILE); |
| 439 | Warning("parsing [%s:%d] : acl '%s' involves some volatile request-only criteria which will be ignored.\n", |
| 440 | file, line, acl ? acl->name : "(unknown)"); |
| 441 | return ERR_WARN; |
| 442 | } |
| 443 | |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 444 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 445 | /* |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 446 | * parse a line in a <global> section. Returns the error code, 0 if OK, or |
| 447 | * any combination of : |
| 448 | * - ERR_ABORT: must abort ASAP |
| 449 | * - ERR_FATAL: we can continue parsing but not start the service |
| 450 | * - ERR_WARN: a warning has been emitted |
| 451 | * - ERR_ALERT: an alert has been emitted |
| 452 | * Only the two first ones can stop processing, the two others are just |
| 453 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 454 | */ |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 455 | 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] | 456 | { |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 457 | int err_code = 0; |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 458 | char *errmsg = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 459 | |
| 460 | if (!strcmp(args[0], "global")) { /* new section */ |
| 461 | /* no option, nothing special to do */ |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 462 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 463 | } |
| 464 | else if (!strcmp(args[0], "daemon")) { |
| 465 | global.mode |= MODE_DAEMON; |
| 466 | } |
| 467 | else if (!strcmp(args[0], "debug")) { |
| 468 | global.mode |= MODE_DEBUG; |
| 469 | } |
| 470 | else if (!strcmp(args[0], "noepoll")) { |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 471 | global.tune.options &= ~GTUNE_USE_EPOLL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 472 | } |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 473 | else if (!strcmp(args[0], "nosepoll")) { |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 474 | global.tune.options &= ~GTUNE_USE_SEPOLL; |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 475 | } |
| 476 | else if (!strcmp(args[0], "nokqueue")) { |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 477 | global.tune.options &= ~GTUNE_USE_KQUEUE; |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 478 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 479 | else if (!strcmp(args[0], "nopoll")) { |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 480 | global.tune.options &= ~GTUNE_USE_POLL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 481 | } |
Willy Tarreau | 3ab68cf | 2009-01-25 16:03:28 +0100 | [diff] [blame] | 482 | else if (!strcmp(args[0], "nosplice")) { |
| 483 | global.tune.options &= ~GTUNE_USE_SPLICE; |
| 484 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 485 | else if (!strcmp(args[0], "quiet")) { |
| 486 | global.mode |= MODE_QUIET; |
| 487 | } |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 488 | else if (!strcmp(args[0], "tune.maxpollevents")) { |
| 489 | if (global.tune.maxpollevents != 0) { |
| 490 | 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] | 491 | err_code |= ERR_ALERT; |
| 492 | goto out; |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 493 | } |
| 494 | if (*(args[1]) == 0) { |
| 495 | 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] | 496 | err_code |= ERR_ALERT | ERR_FATAL; |
| 497 | goto out; |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 498 | } |
| 499 | global.tune.maxpollevents = atol(args[1]); |
| 500 | } |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 501 | else if (!strcmp(args[0], "tune.maxaccept")) { |
| 502 | if (global.tune.maxaccept != 0) { |
| 503 | 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] | 504 | err_code |= ERR_ALERT; |
| 505 | goto out; |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 506 | } |
| 507 | if (*(args[1]) == 0) { |
| 508 | 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] | 509 | err_code |= ERR_ALERT | ERR_FATAL; |
| 510 | goto out; |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 511 | } |
| 512 | global.tune.maxaccept = atol(args[1]); |
| 513 | } |
Willy Tarreau | 43961d5 | 2010-10-04 20:39:20 +0200 | [diff] [blame] | 514 | else if (!strcmp(args[0], "tune.chksize")) { |
| 515 | if (*(args[1]) == 0) { |
| 516 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 517 | err_code |= ERR_ALERT | ERR_FATAL; |
| 518 | goto out; |
| 519 | } |
| 520 | global.tune.chksize = atol(args[1]); |
| 521 | } |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 522 | else if (!strcmp(args[0], "tune.bufsize")) { |
| 523 | if (*(args[1]) == 0) { |
| 524 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 525 | err_code |= ERR_ALERT | ERR_FATAL; |
| 526 | goto out; |
| 527 | } |
| 528 | global.tune.bufsize = atol(args[1]); |
| 529 | if (global.tune.maxrewrite >= global.tune.bufsize / 2) |
| 530 | global.tune.maxrewrite = global.tune.bufsize / 2; |
| 531 | } |
| 532 | else if (!strcmp(args[0], "tune.maxrewrite")) { |
| 533 | if (*(args[1]) == 0) { |
| 534 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 535 | err_code |= ERR_ALERT | ERR_FATAL; |
| 536 | goto out; |
| 537 | } |
| 538 | global.tune.maxrewrite = atol(args[1]); |
| 539 | if (global.tune.maxrewrite >= global.tune.bufsize / 2) |
| 540 | global.tune.maxrewrite = global.tune.bufsize / 2; |
| 541 | } |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 542 | else if (!strcmp(args[0], "tune.rcvbuf.client")) { |
| 543 | if (global.tune.client_rcvbuf != 0) { |
| 544 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 545 | err_code |= ERR_ALERT; |
| 546 | goto out; |
| 547 | } |
| 548 | if (*(args[1]) == 0) { |
| 549 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 550 | err_code |= ERR_ALERT | ERR_FATAL; |
| 551 | goto out; |
| 552 | } |
| 553 | global.tune.client_rcvbuf = atol(args[1]); |
| 554 | } |
| 555 | else if (!strcmp(args[0], "tune.rcvbuf.server")) { |
| 556 | if (global.tune.server_rcvbuf != 0) { |
| 557 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 558 | err_code |= ERR_ALERT; |
| 559 | goto out; |
| 560 | } |
| 561 | if (*(args[1]) == 0) { |
| 562 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 563 | err_code |= ERR_ALERT | ERR_FATAL; |
| 564 | goto out; |
| 565 | } |
| 566 | global.tune.server_rcvbuf = atol(args[1]); |
| 567 | } |
| 568 | else if (!strcmp(args[0], "tune.sndbuf.client")) { |
| 569 | if (global.tune.client_sndbuf != 0) { |
| 570 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 571 | err_code |= ERR_ALERT; |
| 572 | goto out; |
| 573 | } |
| 574 | if (*(args[1]) == 0) { |
| 575 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 576 | err_code |= ERR_ALERT | ERR_FATAL; |
| 577 | goto out; |
| 578 | } |
| 579 | global.tune.client_sndbuf = atol(args[1]); |
| 580 | } |
| 581 | else if (!strcmp(args[0], "tune.sndbuf.server")) { |
| 582 | if (global.tune.server_sndbuf != 0) { |
| 583 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 584 | err_code |= ERR_ALERT; |
| 585 | goto out; |
| 586 | } |
| 587 | if (*(args[1]) == 0) { |
| 588 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 589 | err_code |= ERR_ALERT | ERR_FATAL; |
| 590 | goto out; |
| 591 | } |
| 592 | global.tune.server_sndbuf = atol(args[1]); |
| 593 | } |
Willy Tarreau | bd9a0a7 | 2011-10-23 21:14:29 +0200 | [diff] [blame] | 594 | else if (!strcmp(args[0], "tune.pipesize")) { |
| 595 | if (*(args[1]) == 0) { |
| 596 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 597 | err_code |= ERR_ALERT | ERR_FATAL; |
| 598 | goto out; |
| 599 | } |
| 600 | global.tune.pipesize = atol(args[1]); |
| 601 | } |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame] | 602 | else if (!strcmp(args[0], "tune.http.maxhdr")) { |
| 603 | if (*(args[1]) == 0) { |
| 604 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 605 | err_code |= ERR_ALERT | ERR_FATAL; |
| 606 | goto out; |
| 607 | } |
| 608 | global.tune.max_http_hdr = atol(args[1]); |
| 609 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 610 | else if (!strcmp(args[0], "uid")) { |
| 611 | if (global.uid != 0) { |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 612 | Alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 613 | err_code |= ERR_ALERT; |
| 614 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 615 | } |
| 616 | if (*(args[1]) == 0) { |
| 617 | 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] | 618 | err_code |= ERR_ALERT | ERR_FATAL; |
| 619 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 620 | } |
| 621 | global.uid = atol(args[1]); |
| 622 | } |
| 623 | else if (!strcmp(args[0], "gid")) { |
| 624 | if (global.gid != 0) { |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 625 | Alert("parsing [%s:%d] : group/gid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 626 | err_code |= ERR_ALERT; |
| 627 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 628 | } |
| 629 | if (*(args[1]) == 0) { |
| 630 | 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] | 631 | err_code |= ERR_ALERT | ERR_FATAL; |
| 632 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 633 | } |
| 634 | global.gid = atol(args[1]); |
| 635 | } |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 636 | /* user/group name handling */ |
| 637 | else if (!strcmp(args[0], "user")) { |
| 638 | struct passwd *ha_user; |
| 639 | if (global.uid != 0) { |
| 640 | Alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 641 | err_code |= ERR_ALERT; |
| 642 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 643 | } |
| 644 | errno = 0; |
| 645 | ha_user = getpwnam(args[1]); |
| 646 | if (ha_user != NULL) { |
| 647 | global.uid = (int)ha_user->pw_uid; |
| 648 | } |
| 649 | else { |
| 650 | 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] | 651 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 652 | } |
| 653 | } |
| 654 | else if (!strcmp(args[0], "group")) { |
| 655 | struct group *ha_group; |
| 656 | if (global.gid != 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 657 | 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] | 658 | err_code |= ERR_ALERT; |
| 659 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 660 | } |
| 661 | errno = 0; |
| 662 | ha_group = getgrnam(args[1]); |
| 663 | if (ha_group != NULL) { |
| 664 | global.gid = (int)ha_group->gr_gid; |
| 665 | } |
| 666 | else { |
| 667 | 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] | 668 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 669 | } |
| 670 | } |
| 671 | /* end of user/group name handling*/ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 672 | else if (!strcmp(args[0], "nbproc")) { |
| 673 | if (global.nbproc != 0) { |
| 674 | 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] | 675 | err_code |= ERR_ALERT; |
| 676 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 677 | } |
| 678 | if (*(args[1]) == 0) { |
| 679 | 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] | 680 | err_code |= ERR_ALERT | ERR_FATAL; |
| 681 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 682 | } |
| 683 | global.nbproc = atol(args[1]); |
| 684 | } |
| 685 | else if (!strcmp(args[0], "maxconn")) { |
| 686 | if (global.maxconn != 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 | baaee00 | 2006-06-26 02:48:02 +0200 | [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 | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 695 | } |
| 696 | global.maxconn = atol(args[1]); |
| 697 | #ifdef SYSTEM_MAXCONN |
| 698 | if (global.maxconn > DEFAULT_MAXCONN && cfg_maxconn <= DEFAULT_MAXCONN) { |
| 699 | 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); |
| 700 | global.maxconn = DEFAULT_MAXCONN; |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 701 | err_code |= ERR_ALERT; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 702 | } |
| 703 | #endif /* SYSTEM_MAXCONN */ |
| 704 | } |
Willy Tarreau | 81c25d0 | 2011-09-07 15:17:21 +0200 | [diff] [blame] | 705 | else if (!strcmp(args[0], "maxconnrate")) { |
| 706 | if (global.cps_lim != 0) { |
| 707 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 708 | err_code |= ERR_ALERT; |
| 709 | goto out; |
| 710 | } |
| 711 | if (*(args[1]) == 0) { |
| 712 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 713 | err_code |= ERR_ALERT | ERR_FATAL; |
| 714 | goto out; |
| 715 | } |
| 716 | global.cps_lim = atol(args[1]); |
| 717 | } |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 718 | else if (!strcmp(args[0], "maxpipes")) { |
| 719 | if (global.maxpipes != 0) { |
| 720 | 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] | 721 | err_code |= ERR_ALERT; |
| 722 | goto out; |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 723 | } |
| 724 | if (*(args[1]) == 0) { |
| 725 | 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] | 726 | err_code |= ERR_ALERT | ERR_FATAL; |
| 727 | goto out; |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 728 | } |
| 729 | global.maxpipes = atol(args[1]); |
| 730 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 731 | else if (!strcmp(args[0], "ulimit-n")) { |
| 732 | if (global.rlimit_nofile != 0) { |
| 733 | 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] | 734 | err_code |= ERR_ALERT; |
| 735 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 736 | } |
| 737 | if (*(args[1]) == 0) { |
| 738 | 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] | 739 | err_code |= ERR_ALERT | ERR_FATAL; |
| 740 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 741 | } |
| 742 | global.rlimit_nofile = atol(args[1]); |
| 743 | } |
| 744 | else if (!strcmp(args[0], "chroot")) { |
| 745 | if (global.chroot != NULL) { |
| 746 | 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] | 747 | err_code |= ERR_ALERT; |
| 748 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 749 | } |
| 750 | if (*(args[1]) == 0) { |
| 751 | 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] | 752 | err_code |= ERR_ALERT | ERR_FATAL; |
| 753 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 754 | } |
| 755 | global.chroot = strdup(args[1]); |
| 756 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 757 | else if (!strcmp(args[0], "description")) { |
| 758 | int i, len=0; |
| 759 | char *d; |
| 760 | |
| 761 | if (!*args[1]) { |
| 762 | Alert("parsing [%s:%d]: '%s' expects a string argument.\n", |
| 763 | file, linenum, args[0]); |
| 764 | err_code |= ERR_ALERT | ERR_FATAL; |
| 765 | goto out; |
| 766 | } |
| 767 | |
| 768 | for(i=1; *args[i]; i++) |
| 769 | len += strlen(args[i])+1; |
| 770 | |
| 771 | if (global.desc) |
| 772 | free(global.desc); |
| 773 | |
| 774 | global.desc = d = (char *)calloc(1, len); |
| 775 | |
| 776 | d += sprintf(d, "%s", args[1]); |
| 777 | for(i=2; *args[i]; i++) |
| 778 | d += sprintf(d, " %s", args[i]); |
| 779 | } |
| 780 | else if (!strcmp(args[0], "node")) { |
| 781 | int i; |
| 782 | char c; |
| 783 | |
| 784 | for (i=0; args[1][i]; i++) { |
| 785 | c = args[1][i]; |
Willy Tarreau | 88e0581 | 2010-03-03 00:16:00 +0100 | [diff] [blame] | 786 | if (!isupper((unsigned char)c) && !islower((unsigned char)c) && |
| 787 | !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.') |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 788 | break; |
| 789 | } |
| 790 | |
| 791 | if (!i || args[1][i]) { |
| 792 | Alert("parsing [%s:%d]: '%s' requires valid node name - non-empty string" |
| 793 | " with digits(0-9), letters(A-Z, a-z), dot(.), hyphen(-) or underscode(_).\n", |
| 794 | file, linenum, args[0]); |
| 795 | err_code |= ERR_ALERT | ERR_FATAL; |
| 796 | goto out; |
| 797 | } |
| 798 | |
| 799 | if (global.node) |
| 800 | free(global.node); |
| 801 | |
| 802 | global.node = strdup(args[1]); |
| 803 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 804 | else if (!strcmp(args[0], "pidfile")) { |
| 805 | if (global.pidfile != NULL) { |
| 806 | 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] | 807 | err_code |= ERR_ALERT; |
| 808 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 809 | } |
| 810 | if (*(args[1]) == 0) { |
| 811 | 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] | 812 | err_code |= ERR_ALERT | ERR_FATAL; |
| 813 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 814 | } |
| 815 | global.pidfile = strdup(args[1]); |
| 816 | } |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 817 | else if (!strcmp(args[0], "unix-bind")) { |
| 818 | int cur_arg = 1; |
| 819 | while (*(args[cur_arg])) { |
| 820 | if (!strcmp(args[cur_arg], "prefix")) { |
| 821 | if (global.unix_bind.prefix != NULL) { |
| 822 | Alert("parsing [%s:%d] : unix-bind '%s' already specified. Continuing.\n", file, linenum, args[cur_arg]); |
| 823 | err_code |= ERR_ALERT; |
| 824 | cur_arg += 2; |
| 825 | continue; |
| 826 | } |
| 827 | |
| 828 | if (*(args[cur_arg+1]) == 0) { |
| 829 | Alert("parsing [%s:%d] : unix_bind '%s' expects a path as an argument.\n", file, linenum, args[cur_arg]); |
| 830 | err_code |= ERR_ALERT | ERR_FATAL; |
| 831 | goto out; |
| 832 | } |
| 833 | global.unix_bind.prefix = strdup(args[cur_arg+1]); |
| 834 | cur_arg += 2; |
| 835 | continue; |
| 836 | } |
| 837 | |
| 838 | if (!strcmp(args[cur_arg], "mode")) { |
| 839 | |
| 840 | global.unix_bind.ux.mode = strtol(args[cur_arg + 1], NULL, 8); |
| 841 | cur_arg += 2; |
| 842 | continue; |
| 843 | } |
| 844 | |
| 845 | if (!strcmp(args[cur_arg], "uid")) { |
| 846 | |
| 847 | global.unix_bind.ux.uid = atol(args[cur_arg + 1 ]); |
| 848 | cur_arg += 2; |
| 849 | continue; |
| 850 | } |
| 851 | |
| 852 | if (!strcmp(args[cur_arg], "gid")) { |
| 853 | |
| 854 | global.unix_bind.ux.gid = atol(args[cur_arg + 1 ]); |
| 855 | cur_arg += 2; |
| 856 | continue; |
| 857 | } |
| 858 | |
| 859 | if (!strcmp(args[cur_arg], "user")) { |
| 860 | struct passwd *user; |
| 861 | |
| 862 | user = getpwnam(args[cur_arg + 1]); |
| 863 | if (!user) { |
| 864 | Alert("parsing [%s:%d] : '%s' : '%s' unknown user.\n", |
| 865 | file, linenum, args[0], args[cur_arg + 1 ]); |
| 866 | err_code |= ERR_ALERT | ERR_FATAL; |
| 867 | goto out; |
| 868 | } |
| 869 | |
| 870 | global.unix_bind.ux.uid = user->pw_uid; |
| 871 | cur_arg += 2; |
| 872 | continue; |
| 873 | } |
| 874 | |
| 875 | if (!strcmp(args[cur_arg], "group")) { |
| 876 | struct group *group; |
| 877 | |
| 878 | group = getgrnam(args[cur_arg + 1]); |
| 879 | if (!group) { |
| 880 | Alert("parsing [%s:%d] : '%s' : '%s' unknown group.\n", |
| 881 | file, linenum, args[0], args[cur_arg + 1 ]); |
| 882 | err_code |= ERR_ALERT | ERR_FATAL; |
| 883 | goto out; |
| 884 | } |
| 885 | |
| 886 | global.unix_bind.ux.gid = group->gr_gid; |
| 887 | cur_arg += 2; |
| 888 | continue; |
| 889 | } |
| 890 | |
Willy Tarreau | b48f958 | 2011-09-05 01:17:06 +0200 | [diff] [blame] | 891 | Alert("parsing [%s:%d] : '%s' only supports the 'prefix', 'mode', 'uid', 'gid', 'user' and 'group' options.\n", |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 892 | file, linenum, args[0]); |
| 893 | err_code |= ERR_ALERT | ERR_FATAL; |
| 894 | goto out; |
| 895 | } |
| 896 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 897 | else if (!strcmp(args[0], "log") && kwm == KWM_NO) { /* no log */ |
| 898 | /* delete previous herited or defined syslog servers */ |
| 899 | struct logsrv *back; |
| 900 | struct logsrv *tmp; |
| 901 | |
| 902 | if (*(args[1]) != 0) { |
| 903 | Alert("parsing [%s:%d]:%s : 'no log' does not expect arguments.\n", file, linenum, args[1]); |
| 904 | err_code |= ERR_ALERT | ERR_FATAL; |
| 905 | goto out; |
| 906 | } |
| 907 | |
| 908 | list_for_each_entry_safe(tmp, back, &global.logsrvs, list) { |
| 909 | LIST_DEL(&tmp->list); |
| 910 | free(tmp); |
| 911 | } |
| 912 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 913 | else if (!strcmp(args[0], "log")) { /* syslog server address */ |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 914 | struct logsrv *logsrv; |
| 915 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 916 | if (*(args[1]) == 0 || *(args[2]) == 0) { |
| 917 | 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] | 918 | err_code |= ERR_ALERT | ERR_FATAL; |
| 919 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 920 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 921 | |
| 922 | logsrv = calloc(1, sizeof(struct logsrv)); |
| 923 | |
| 924 | logsrv->facility = get_log_facility(args[2]); |
| 925 | if (logsrv->facility < 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 926 | 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] | 927 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 928 | logsrv->facility = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 929 | } |
| 930 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 931 | logsrv->level = 7; /* max syslog level = debug */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 932 | if (*(args[3])) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 933 | logsrv->level = get_log_level(args[3]); |
| 934 | if (logsrv->level < 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 935 | 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] | 936 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 937 | logsrv->level = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 938 | } |
| 939 | } |
| 940 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 941 | logsrv->minlvl = 0; /* limit syslog level to this level (emerg) */ |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 942 | if (*(args[4])) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 943 | logsrv->minlvl = get_log_level(args[4]); |
| 944 | if (logsrv->minlvl < 0) { |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 945 | 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] | 946 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 947 | logsrv->minlvl = 0; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 948 | } |
| 949 | } |
| 950 | |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 951 | if (args[1][0] == '/') { |
David du Colombier | 11bcb6c | 2011-03-24 12:23:00 +0100 | [diff] [blame] | 952 | struct sockaddr_storage *sk = (struct sockaddr_storage *)str2sun(args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 953 | if (!sk) { |
| 954 | 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] | 955 | args[1], (int)sizeof(((struct sockaddr_un *)&sk)->sun_path) - 1); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 956 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 957 | free(logsrv); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 958 | goto out; |
| 959 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 960 | logsrv->addr = *sk; |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 961 | } else { |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 962 | struct sockaddr_storage *sk = str2sa(args[1]); |
David du Colombier | 11bcb6c | 2011-03-24 12:23:00 +0100 | [diff] [blame] | 963 | if (!sk) { |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 964 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[1]); |
| 965 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 966 | free(logsrv); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 967 | goto out; |
| 968 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 969 | logsrv->addr = *sk; |
| 970 | if (!get_host_port(&logsrv->addr)) |
| 971 | set_host_port(&logsrv->addr, SYSLOG_PORT); |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 972 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 973 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 974 | LIST_ADDQ(&global.logsrvs, &logsrv->list); |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 975 | } |
Joe Williams | df5b38f | 2010-12-29 17:05:48 +0100 | [diff] [blame] | 976 | else if (!strcmp(args[0], "log-send-hostname")) { /* set the hostname in syslog header */ |
| 977 | char *name; |
| 978 | int len; |
| 979 | |
| 980 | if (global.log_send_hostname != NULL) { |
| 981 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 982 | err_code |= ERR_ALERT; |
| 983 | goto out; |
| 984 | } |
| 985 | |
| 986 | if (*(args[1])) |
| 987 | name = args[1]; |
| 988 | else |
| 989 | name = hostname; |
| 990 | |
| 991 | len = strlen(name); |
| 992 | |
| 993 | /* We'll add a space after the name to respect the log format */ |
| 994 | free(global.log_send_hostname); |
| 995 | global.log_send_hostname = malloc(len + 2); |
| 996 | snprintf(global.log_send_hostname, len + 2, "%s ", name); |
| 997 | } |
Kevinm | 48936af | 2010-12-22 16:08:21 +0000 | [diff] [blame] | 998 | else if (!strcmp(args[0], "log-tag")) { /* tag to report to syslog */ |
| 999 | if (*(args[1]) == 0) { |
| 1000 | Alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]); |
| 1001 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1002 | goto out; |
| 1003 | } |
| 1004 | free(global.log_tag); |
| 1005 | global.log_tag = strdup(args[1]); |
| 1006 | } |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1007 | else if (!strcmp(args[0], "spread-checks")) { /* random time between checks (0-50) */ |
| 1008 | if (global.spread_checks != 0) { |
| 1009 | Alert("parsing [%s:%d]: spread-checks already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1010 | err_code |= ERR_ALERT; |
| 1011 | goto out; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1012 | } |
| 1013 | if (*(args[1]) == 0) { |
| 1014 | 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] | 1015 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1016 | goto out; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1017 | } |
| 1018 | global.spread_checks = atol(args[1]); |
| 1019 | if (global.spread_checks < 0 || global.spread_checks > 50) { |
| 1020 | 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] | 1021 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1022 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1023 | } |
| 1024 | else { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1025 | struct cfg_kw_list *kwl; |
| 1026 | int index; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1027 | int rc; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1028 | |
| 1029 | list_for_each_entry(kwl, &cfg_keywords.list, list) { |
| 1030 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 1031 | if (kwl->kw[index].section != CFG_GLOBAL) |
| 1032 | continue; |
| 1033 | if (strcmp(kwl->kw[index].kw, args[0]) == 0) { |
| 1034 | /* prepare error message just in case */ |
| 1035 | snprintf(trash, sizeof(trash), |
| 1036 | "error near '%s' in '%s' section", args[0], "global"); |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 1037 | rc = kwl->kw[index].parse(args, CFG_GLOBAL, NULL, NULL, &errmsg); |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1038 | if (rc < 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 1039 | Alert("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1040 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1041 | } |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1042 | else if (rc > 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 1043 | Warning("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1044 | err_code |= ERR_WARN; |
| 1045 | goto out; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1046 | } |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1047 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1048 | } |
| 1049 | } |
| 1050 | } |
| 1051 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1052 | 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] | 1053 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1054 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1055 | |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1056 | out: |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 1057 | free(errmsg); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1058 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1059 | } |
| 1060 | |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 1061 | void init_default_instance() |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1062 | { |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 1063 | init_new_proxy(&defproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1064 | defproxy.mode = PR_MODE_TCP; |
| 1065 | defproxy.state = PR_STNEW; |
| 1066 | defproxy.maxconn = cfg_maxpconn; |
| 1067 | defproxy.conn_retries = CONN_RETRIES; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1068 | |
| 1069 | defproxy.defsrv.inter = DEF_CHKINTR; |
| 1070 | defproxy.defsrv.fastinter = 0; |
| 1071 | defproxy.defsrv.downinter = 0; |
| 1072 | defproxy.defsrv.rise = DEF_RISETIME; |
| 1073 | defproxy.defsrv.fall = DEF_FALLTIME; |
| 1074 | defproxy.defsrv.check_port = 0; |
| 1075 | defproxy.defsrv.maxqueue = 0; |
| 1076 | defproxy.defsrv.minconn = 0; |
| 1077 | defproxy.defsrv.maxconn = 0; |
| 1078 | defproxy.defsrv.slowstart = 0; |
| 1079 | defproxy.defsrv.onerror = DEF_HANA_ONERR; |
| 1080 | defproxy.defsrv.consecutive_errors_limit = DEF_HANA_ERRLIMIT; |
| 1081 | defproxy.defsrv.uweight = defproxy.defsrv.iweight = 1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1082 | } |
| 1083 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1084 | |
| 1085 | static int create_cond_regex_rule(const char *file, int line, |
| 1086 | struct proxy *px, int dir, int action, int flags, |
| 1087 | const char *cmd, const char *reg, const char *repl, |
| 1088 | const char **cond_start) |
| 1089 | { |
| 1090 | regex_t *preg = NULL; |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 1091 | char *errmsg = NULL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1092 | const char *err; |
| 1093 | int err_code = 0; |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1094 | struct acl_cond *cond = NULL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1095 | |
| 1096 | if (px == &defproxy) { |
| 1097 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, line, cmd); |
| 1098 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1099 | goto err; |
| 1100 | } |
| 1101 | |
| 1102 | if (*reg == 0) { |
| 1103 | Alert("parsing [%s:%d] : '%s' expects <regex> as an argument.\n", file, line, cmd); |
| 1104 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1105 | goto err; |
| 1106 | } |
| 1107 | |
| 1108 | if (warnifnotcap(px, PR_CAP_RS, file, line, cmd, NULL)) |
| 1109 | err_code |= ERR_WARN; |
| 1110 | |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1111 | if (cond_start && |
| 1112 | (strcmp(*cond_start, "if") == 0 || strcmp(*cond_start, "unless") == 0)) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 1113 | if ((cond = build_acl_cond(file, line, px, cond_start, &errmsg)) == NULL) { |
| 1114 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 1115 | file, line, cmd, errmsg); |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1116 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1117 | goto err; |
| 1118 | } |
| 1119 | } |
| 1120 | else if (cond_start && **cond_start) { |
| 1121 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 1122 | file, line, cmd, *cond_start); |
| 1123 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1124 | goto err; |
| 1125 | } |
| 1126 | |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 1127 | if (dir == SMP_OPT_DIR_REQ) |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1128 | err_code |= warnif_cond_requires_resp(cond, file, line); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 1129 | else |
| 1130 | err_code |= warnif_cond_requires_req(cond, file, line); |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1131 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1132 | preg = calloc(1, sizeof(regex_t)); |
| 1133 | if (!preg) { |
| 1134 | Alert("parsing [%s:%d] : '%s' : not enough memory to build regex.\n", file, line, cmd); |
| 1135 | err_code = ERR_ALERT | ERR_FATAL; |
| 1136 | goto err; |
| 1137 | } |
| 1138 | |
| 1139 | if (regcomp(preg, reg, REG_EXTENDED | flags) != 0) { |
| 1140 | Alert("parsing [%s:%d] : '%s' : bad regular expression '%s'.\n", file, line, cmd, reg); |
| 1141 | err_code = ERR_ALERT | ERR_FATAL; |
| 1142 | goto err; |
| 1143 | } |
| 1144 | |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 1145 | err = chain_regex((dir == SMP_OPT_DIR_REQ) ? &px->req_exp : &px->rsp_exp, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1146 | preg, action, repl ? strdup(repl) : NULL, cond); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1147 | if (repl && err) { |
| 1148 | Alert("parsing [%s:%d] : '%s' : invalid character or unterminated sequence in replacement string near '%c'.\n", |
| 1149 | file, line, cmd, *err); |
| 1150 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1151 | goto err; |
| 1152 | } |
| 1153 | |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 1154 | if (dir == SMP_OPT_DIR_REQ && warnif_misplaced_reqxxx(px, file, line, cmd)) |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1155 | err_code |= ERR_WARN; |
| 1156 | |
Willy Tarreau | f4068b6 | 2012-05-08 17:37:49 +0200 | [diff] [blame] | 1157 | free(errmsg); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1158 | return err_code; |
| 1159 | err: |
Willy Tarreau | f4068b6 | 2012-05-08 17:37:49 +0200 | [diff] [blame] | 1160 | free(errmsg); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1161 | free(preg); |
| 1162 | return err_code; |
| 1163 | } |
| 1164 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1165 | /* |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1166 | * Parse a line in a <listen>, <frontend>, <backend> or <ruleset> section. |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1167 | * Returns the error code, 0 if OK, or any combination of : |
| 1168 | * - ERR_ABORT: must abort ASAP |
| 1169 | * - ERR_FATAL: we can continue parsing but not start the service |
| 1170 | * - ERR_WARN: a warning has been emitted |
| 1171 | * - ERR_ALERT: an alert has been emitted |
| 1172 | * Only the two first ones can stop processing, the two others are just |
| 1173 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1174 | */ |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1175 | int cfg_parse_peers(const char *file, int linenum, char **args, int kwm) |
| 1176 | { |
| 1177 | static struct peers *curpeers = NULL; |
| 1178 | struct peer *newpeer = NULL; |
| 1179 | const char *err; |
| 1180 | int err_code = 0; |
| 1181 | |
| 1182 | if (strcmp(args[0], "peers") == 0) { /* new peers section */ |
| 1183 | |
| 1184 | err = invalid_char(args[1]); |
| 1185 | if (err) { |
| 1186 | Alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 1187 | file, linenum, *err, args[0], args[1]); |
| 1188 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1189 | } |
| 1190 | |
| 1191 | for (curpeers = peers; curpeers != NULL; curpeers = curpeers->next) { |
| 1192 | /* |
| 1193 | * If there are two proxies with the same name only following |
| 1194 | * combinations are allowed: |
| 1195 | */ |
| 1196 | if (strcmp(curpeers->id, args[1]) == 0) { |
| 1197 | Warning("Parsing [%s:%d]: peers '%s' has same name as another peers (declared at %s:%d).\n", |
| 1198 | file, linenum, args[1], curpeers->conf.file, curpeers->conf.line); |
| 1199 | err_code |= ERR_WARN; |
| 1200 | } |
| 1201 | } |
| 1202 | |
| 1203 | if ((curpeers = (struct peers *)calloc(1, sizeof(struct peers))) == NULL) { |
| 1204 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1205 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1206 | goto out; |
| 1207 | } |
| 1208 | |
| 1209 | curpeers->next = peers; |
| 1210 | peers = curpeers; |
| 1211 | curpeers->conf.file = file; |
| 1212 | curpeers->conf.line = linenum; |
| 1213 | curpeers->last_change = now.tv_sec; |
| 1214 | curpeers->id = strdup(args[1]); |
| 1215 | } |
| 1216 | else if (strcmp(args[0], "peer") == 0) { /* peer definition */ |
| 1217 | char *rport, *raddr; |
| 1218 | short realport = 0; |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 1219 | struct sockaddr_storage *sk; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1220 | |
| 1221 | if (!*args[2]) { |
| 1222 | Alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n", |
| 1223 | file, linenum, args[0]); |
| 1224 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1225 | goto out; |
| 1226 | } |
| 1227 | |
| 1228 | err = invalid_char(args[1]); |
| 1229 | if (err) { |
| 1230 | Alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n", |
| 1231 | file, linenum, *err, args[1]); |
| 1232 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1233 | goto out; |
| 1234 | } |
| 1235 | |
| 1236 | if ((newpeer = (struct peer *)calloc(1, sizeof(struct peer))) == NULL) { |
| 1237 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1238 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1239 | goto out; |
| 1240 | } |
| 1241 | |
| 1242 | /* the peers are linked backwards first */ |
| 1243 | curpeers->count++; |
| 1244 | newpeer->next = curpeers->remote; |
| 1245 | curpeers->remote = newpeer; |
| 1246 | newpeer->peers = curpeers; |
| 1247 | newpeer->conf.file = file; |
| 1248 | newpeer->conf.line = linenum; |
| 1249 | |
| 1250 | newpeer->last_change = now.tv_sec; |
| 1251 | newpeer->id = strdup(args[1]); |
| 1252 | |
| 1253 | raddr = strdup(args[2]); |
Willy Tarreau | fab5a43 | 2011-03-04 15:31:53 +0100 | [diff] [blame] | 1254 | rport = strrchr(raddr, ':'); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1255 | if (rport) { |
| 1256 | *rport++ = 0; |
| 1257 | realport = atol(rport); |
| 1258 | } |
| 1259 | if (!realport) { |
| 1260 | Alert("parsing [%s:%d] : Missing or invalid port in '%s'\n", file, linenum, args[2]); |
| 1261 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1262 | goto out; |
| 1263 | } |
| 1264 | |
Willy Tarreau | fab5a43 | 2011-03-04 15:31:53 +0100 | [diff] [blame] | 1265 | sk = str2ip(raddr); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1266 | free(raddr); |
| 1267 | if (!sk) { |
| 1268 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[2]); |
| 1269 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1270 | goto out; |
| 1271 | } |
| 1272 | newpeer->addr = *sk; |
Willy Tarreau | 26d8c59 | 2012-05-07 18:12:14 +0200 | [diff] [blame] | 1273 | newpeer->proto = protocol_by_family(newpeer->addr.ss_family); |
Willy Tarreau | d02394b | 2012-05-11 18:32:18 +0200 | [diff] [blame] | 1274 | newpeer->sock = &sock_raw; |
| 1275 | newpeer->sock_init_arg = NULL; |
Willy Tarreau | 26d8c59 | 2012-05-07 18:12:14 +0200 | [diff] [blame] | 1276 | |
| 1277 | if (!sk) { |
| 1278 | Alert("parsing [%s:%d] : Unknown protocol family %d '%s'\n", |
| 1279 | file, linenum, newpeer->addr.ss_family, args[2]); |
| 1280 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1281 | goto out; |
| 1282 | } |
| 1283 | |
Willy Tarreau | 86ad42c | 2011-08-27 12:29:07 +0200 | [diff] [blame] | 1284 | set_host_port(&newpeer->addr, realport); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1285 | |
| 1286 | if (strcmp(newpeer->id, localpeer) == 0) { |
| 1287 | /* Current is local peer, it define a frontend */ |
| 1288 | newpeer->local = 1; |
| 1289 | |
| 1290 | if (!curpeers->peers_fe) { |
| 1291 | if ((curpeers->peers_fe = calloc(1, sizeof(struct proxy))) == NULL) { |
| 1292 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1293 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1294 | goto out; |
| 1295 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1296 | |
Willy Tarreau | 237250c | 2011-07-29 01:49:03 +0200 | [diff] [blame] | 1297 | init_new_proxy(curpeers->peers_fe); |
| 1298 | curpeers->peers_fe->parent = curpeers; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1299 | |
| 1300 | curpeers->peers_fe->last_change = now.tv_sec; |
| 1301 | curpeers->peers_fe->id = strdup(args[1]); |
| 1302 | curpeers->peers_fe->cap = PR_CAP_FE; |
Willy Tarreau | 3ae65a1 | 2011-09-07 17:40:39 +0200 | [diff] [blame] | 1303 | curpeers->peers_fe->maxconn = 0; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1304 | curpeers->peers_fe->conn_retries = CONN_RETRIES; |
| 1305 | curpeers->peers_fe->timeout.connect = 5000; |
| 1306 | curpeers->peers_fe->accept = peer_accept; |
| 1307 | 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] | 1308 | if (!str2listener(args[2], curpeers->peers_fe, file, linenum)) { |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1309 | err_code |= ERR_FATAL; |
| 1310 | goto out; |
| 1311 | } |
| 1312 | curpeers->peers_fe->listen->maxconn = ((struct proxy *)curpeers->peers_fe)->maxconn; |
| 1313 | curpeers->peers_fe->listen->backlog = ((struct proxy *)curpeers->peers_fe)->backlog; |
| 1314 | curpeers->peers_fe->listen->timeout = &((struct proxy *)curpeers->peers_fe)->timeout.client; |
| 1315 | curpeers->peers_fe->listen->accept = session_accept; |
| 1316 | curpeers->peers_fe->listen->frontend = ((struct proxy *)curpeers->peers_fe); |
| 1317 | curpeers->peers_fe->listen->handler = process_session; |
| 1318 | curpeers->peers_fe->listen->analysers |= ((struct proxy *)curpeers->peers_fe)->fe_req_ana; |
Willy Tarreau | 3c63fd8 | 2011-09-07 18:00:47 +0200 | [diff] [blame] | 1319 | curpeers->peers_fe->listen->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */ |
| 1320 | global.maxsock += curpeers->peers_fe->listen->maxconn; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1321 | } |
| 1322 | } |
| 1323 | } /* neither "peer" nor "peers" */ |
| 1324 | else if (*args[0] != 0) { |
| 1325 | Alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection); |
| 1326 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1327 | goto out; |
| 1328 | } |
| 1329 | |
| 1330 | out: |
| 1331 | return err_code; |
| 1332 | } |
| 1333 | |
| 1334 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 1335 | 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] | 1336 | { |
| 1337 | static struct proxy *curproxy = NULL; |
| 1338 | struct server *newsrv = NULL; |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 1339 | const char *err; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 1340 | int rc; |
| 1341 | unsigned val; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1342 | int err_code = 0; |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 1343 | struct acl_cond *cond = NULL; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 1344 | struct logsrv *tmplogsrv; |
| 1345 | struct logformat_node *tmplf; |
Willy Tarreau | f4068b6 | 2012-05-08 17:37:49 +0200 | [diff] [blame] | 1346 | char *errmsg = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1347 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1348 | if (!strcmp(args[0], "listen")) |
| 1349 | rc = PR_CAP_LISTEN; |
| 1350 | else if (!strcmp(args[0], "frontend")) |
| 1351 | rc = PR_CAP_FE | PR_CAP_RS; |
| 1352 | else if (!strcmp(args[0], "backend")) |
| 1353 | rc = PR_CAP_BE | PR_CAP_RS; |
| 1354 | else if (!strcmp(args[0], "ruleset")) |
| 1355 | rc = PR_CAP_RS; |
| 1356 | else |
| 1357 | rc = PR_CAP_NONE; |
| 1358 | |
| 1359 | if (rc != PR_CAP_NONE) { /* new proxy */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1360 | if (!*args[1]) { |
| 1361 | Alert("parsing [%s:%d] : '%s' expects an <id> argument and\n" |
| 1362 | " optionnally supports [addr1]:port1[-end1]{,[addr]:port[-end]}...\n", |
| 1363 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1364 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1365 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1366 | } |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 1367 | |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 1368 | err = invalid_char(args[1]); |
| 1369 | if (err) { |
| 1370 | Alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 1371 | file, linenum, *err, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1372 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 1373 | } |
| 1374 | |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 1375 | for (curproxy = proxy; curproxy != NULL; curproxy = curproxy->next) { |
| 1376 | /* |
| 1377 | * If there are two proxies with the same name only following |
| 1378 | * combinations are allowed: |
| 1379 | * |
| 1380 | * listen backend frontend ruleset |
| 1381 | * listen - - - - |
| 1382 | * backend - - OK - |
| 1383 | * frontend - OK - - |
| 1384 | * ruleset - - - - |
| 1385 | */ |
| 1386 | |
| 1387 | if (!strcmp(curproxy->id, args[1]) && |
| 1388 | (rc!=(PR_CAP_FE|PR_CAP_RS) || curproxy->cap!=(PR_CAP_BE|PR_CAP_RS)) && |
| 1389 | (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] | 1390 | Warning("Parsing [%s:%d]: %s '%s' has same name as another %s (declared at %s:%d).\n", |
| 1391 | file, linenum, proxy_cap_str(rc), args[1], proxy_type_str(curproxy), |
| 1392 | curproxy->conf.file, curproxy->conf.line); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1393 | err_code |= ERR_WARN; |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 1394 | } |
| 1395 | } |
| 1396 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1397 | if ((curproxy = (struct proxy *)calloc(1, sizeof(struct proxy))) == NULL) { |
| 1398 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1399 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1400 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1401 | } |
Willy Tarreau | 5af24ef | 2009-03-15 15:23:16 +0100 | [diff] [blame] | 1402 | |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 1403 | init_new_proxy(curproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1404 | curproxy->next = proxy; |
| 1405 | proxy = curproxy; |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 1406 | curproxy->conf.file = file; |
| 1407 | curproxy->conf.line = linenum; |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 1408 | curproxy->last_change = now.tv_sec; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1409 | curproxy->id = strdup(args[1]); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1410 | curproxy->cap = rc; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1411 | |
| 1412 | /* parse the listener address if any */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1413 | if ((curproxy->cap & PR_CAP_FE) && *args[2]) { |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 1414 | struct listener *new, *last = curproxy->listen; |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 1415 | if (!str2listener(args[2], curproxy, file, linenum)) { |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1416 | err_code |= ERR_FATAL; |
| 1417 | goto out; |
| 1418 | } |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 1419 | new = curproxy->listen; |
| 1420 | while (new != last) { |
| 1421 | new->conf.file = file; |
| 1422 | new->conf.line = linenum; |
| 1423 | new = new->next; |
Willy Tarreau | c8b1109 | 2011-02-16 11:08:57 +0100 | [diff] [blame] | 1424 | global.maxsock++; |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 1425 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1426 | } |
| 1427 | |
| 1428 | /* set default values */ |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1429 | memcpy(&curproxy->defsrv, &defproxy.defsrv, sizeof(curproxy->defsrv)); |
Willy Tarreau | 7016020 | 2010-04-07 16:06:40 +0200 | [diff] [blame] | 1430 | curproxy->defsrv.id = "default-server"; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1431 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1432 | curproxy->state = defproxy.state; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1433 | curproxy->options = defproxy.options; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 1434 | curproxy->options2 = defproxy.options2; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 1435 | curproxy->no_options = defproxy.no_options; |
| 1436 | curproxy->no_options2 = defproxy.no_options2; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 1437 | curproxy->bind_proc = defproxy.bind_proc; |
Willy Tarreau | 3168223 | 2007-11-29 15:38:04 +0100 | [diff] [blame] | 1438 | curproxy->lbprm.algo = defproxy.lbprm.algo; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 1439 | curproxy->except_net = defproxy.except_net; |
| 1440 | curproxy->except_mask = defproxy.except_mask; |
Maik Broemme | 36db02e | 2009-05-08 17:02:07 +0200 | [diff] [blame] | 1441 | curproxy->except_to = defproxy.except_to; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 1442 | curproxy->except_mask_to = defproxy.except_mask_to; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1443 | |
Willy Tarreau | 79f5fe8 | 2008-08-23 08:18:21 +0200 | [diff] [blame] | 1444 | if (defproxy.fwdfor_hdr_len) { |
| 1445 | curproxy->fwdfor_hdr_len = defproxy.fwdfor_hdr_len; |
| 1446 | curproxy->fwdfor_hdr_name = strdup(defproxy.fwdfor_hdr_name); |
| 1447 | } |
| 1448 | |
Willy Tarreau | b86db34 | 2009-11-30 11:50:16 +0100 | [diff] [blame] | 1449 | if (defproxy.orgto_hdr_len) { |
| 1450 | curproxy->orgto_hdr_len = defproxy.orgto_hdr_len; |
| 1451 | curproxy->orgto_hdr_name = strdup(defproxy.orgto_hdr_name); |
| 1452 | } |
| 1453 | |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 1454 | if (defproxy.server_id_hdr_len) { |
| 1455 | curproxy->server_id_hdr_len = defproxy.server_id_hdr_len; |
| 1456 | curproxy->server_id_hdr_name = strdup(defproxy.server_id_hdr_name); |
| 1457 | } |
| 1458 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1459 | if (curproxy->cap & PR_CAP_FE) { |
| 1460 | curproxy->maxconn = defproxy.maxconn; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 1461 | curproxy->backlog = defproxy.backlog; |
Willy Tarreau | 13a34bd | 2009-05-10 18:52:49 +0200 | [diff] [blame] | 1462 | curproxy->fe_sps_lim = defproxy.fe_sps_lim; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1463 | |
| 1464 | /* initialize error relocations */ |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1465 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) |
| 1466 | chunk_dup(&curproxy->errmsg[rc], &defproxy.errmsg[rc]); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1467 | |
| 1468 | curproxy->to_log = defproxy.to_log & ~LW_COOKIE & ~LW_REQHDR & ~ LW_RSPHDR; |
| 1469 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1470 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1471 | if (curproxy->cap & PR_CAP_BE) { |
| 1472 | curproxy->fullconn = defproxy.fullconn; |
| 1473 | curproxy->conn_retries = defproxy.conn_retries; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1474 | |
Willy Tarreau | aa2f389 | 2010-10-22 16:15:31 +0200 | [diff] [blame] | 1475 | if (defproxy.check_req) { |
| 1476 | curproxy->check_req = calloc(1, defproxy.check_len); |
| 1477 | memcpy(curproxy->check_req, defproxy.check_req, defproxy.check_len); |
| 1478 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1479 | curproxy->check_len = defproxy.check_len; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1480 | |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 1481 | if (defproxy.expect_str) { |
| 1482 | curproxy->expect_str = strdup(defproxy.expect_str); |
| 1483 | if (defproxy.expect_regex) { |
| 1484 | /* note: this regex is known to be valid */ |
| 1485 | curproxy->expect_regex = calloc(1, sizeof(regex_t)); |
| 1486 | regcomp(curproxy->expect_regex, defproxy.expect_str, REG_EXTENDED); |
| 1487 | } |
| 1488 | } |
| 1489 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1490 | if (defproxy.cookie_name) |
| 1491 | curproxy->cookie_name = strdup(defproxy.cookie_name); |
| 1492 | curproxy->cookie_len = defproxy.cookie_len; |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 1493 | if (defproxy.cookie_domain) |
| 1494 | curproxy->cookie_domain = strdup(defproxy.cookie_domain); |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 1495 | |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 1496 | if (defproxy.cookie_maxidle) |
| 1497 | curproxy->cookie_maxidle = defproxy.cookie_maxidle; |
| 1498 | |
| 1499 | if (defproxy.cookie_maxlife) |
| 1500 | curproxy->cookie_maxlife = defproxy.cookie_maxlife; |
| 1501 | |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 1502 | if (defproxy.rdp_cookie_name) |
| 1503 | curproxy->rdp_cookie_name = strdup(defproxy.rdp_cookie_name); |
| 1504 | curproxy->rdp_cookie_len = defproxy.rdp_cookie_len; |
| 1505 | |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 1506 | if (defproxy.url_param_name) |
| 1507 | curproxy->url_param_name = strdup(defproxy.url_param_name); |
| 1508 | curproxy->url_param_len = defproxy.url_param_len; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 1509 | |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 1510 | if (defproxy.hh_name) |
| 1511 | curproxy->hh_name = strdup(defproxy.hh_name); |
| 1512 | curproxy->hh_len = defproxy.hh_len; |
| 1513 | curproxy->hh_match_domain = defproxy.hh_match_domain; |
| 1514 | |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 1515 | if (defproxy.iface_name) |
| 1516 | curproxy->iface_name = strdup(defproxy.iface_name); |
| 1517 | curproxy->iface_len = defproxy.iface_len; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1518 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1519 | |
Willy Tarreau | 3b6b1a9 | 2009-07-23 13:24:23 +0200 | [diff] [blame] | 1520 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1521 | if (defproxy.capture_name) |
| 1522 | curproxy->capture_name = strdup(defproxy.capture_name); |
| 1523 | curproxy->capture_namelen = defproxy.capture_namelen; |
| 1524 | curproxy->capture_len = defproxy.capture_len; |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 1525 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1526 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1527 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 1528 | curproxy->timeout.client = defproxy.timeout.client; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 1529 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | 036fae0 | 2008-01-06 13:24:40 +0100 | [diff] [blame] | 1530 | curproxy->timeout.httpreq = defproxy.timeout.httpreq; |
Willy Tarreau | b16a574 | 2010-01-10 14:46:16 +0100 | [diff] [blame] | 1531 | curproxy->timeout.httpka = defproxy.timeout.httpka; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1532 | curproxy->uri_auth = defproxy.uri_auth; |
| 1533 | curproxy->mon_net = defproxy.mon_net; |
| 1534 | curproxy->mon_mask = defproxy.mon_mask; |
| 1535 | if (defproxy.monitor_uri) |
| 1536 | curproxy->monitor_uri = strdup(defproxy.monitor_uri); |
| 1537 | curproxy->monitor_uri_len = defproxy.monitor_uri_len; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 1538 | if (defproxy.defbe.name) |
| 1539 | curproxy->defbe.name = strdup(defproxy.defbe.name); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1540 | } |
| 1541 | |
| 1542 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 1543 | curproxy->timeout.connect = defproxy.timeout.connect; |
| 1544 | curproxy->timeout.server = defproxy.timeout.server; |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 1545 | curproxy->timeout.check = defproxy.timeout.check; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 1546 | curproxy->timeout.queue = defproxy.timeout.queue; |
Willy Tarreau | 51c9bde | 2008-01-06 13:40:03 +0100 | [diff] [blame] | 1547 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | cd7afc0 | 2009-07-12 10:03:17 +0200 | [diff] [blame] | 1548 | curproxy->timeout.httpreq = defproxy.timeout.httpreq; |
Willy Tarreau | b16a574 | 2010-01-10 14:46:16 +0100 | [diff] [blame] | 1549 | curproxy->timeout.httpka = defproxy.timeout.httpka; |
Willy Tarreau | ce887fd | 2012-05-12 12:50:00 +0200 | [diff] [blame] | 1550 | curproxy->timeout.tunnel = defproxy.timeout.tunnel; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1551 | curproxy->source_addr = defproxy.source_addr; |
| 1552 | } |
| 1553 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1554 | curproxy->mode = defproxy.mode; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1555 | |
| 1556 | /* copy default logsrvs to curproxy */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 1557 | list_for_each_entry(tmplogsrv, &defproxy.logsrvs, list) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1558 | struct logsrv *node = malloc(sizeof(struct logsrv)); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 1559 | memcpy(node, tmplogsrv, sizeof(struct logsrv)); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1560 | LIST_INIT(&node->list); |
| 1561 | LIST_ADDQ(&curproxy->logsrvs, &node->list); |
| 1562 | } |
| 1563 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 1564 | /* copy default log_format to curproxy */ |
| 1565 | list_for_each_entry(tmplf, &defproxy.logformat, list) { |
| 1566 | struct logformat_node *node = malloc(sizeof(struct logformat_node)); |
| 1567 | memcpy(node, tmplf, sizeof(struct logformat_node)); |
| 1568 | LIST_INIT(&node->list); |
| 1569 | LIST_ADDQ(&curproxy->logformat, &node->list); |
| 1570 | } |
| 1571 | |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 1572 | /* copy default unique_id to curproxy */ |
| 1573 | list_for_each_entry(tmplf, &defproxy.format_unique_id, list) { |
| 1574 | struct logformat_node *node = malloc(sizeof(struct logformat_node)); |
| 1575 | memcpy(node, tmplf, sizeof(struct logformat_node)); |
| 1576 | LIST_INIT(&node->list); |
| 1577 | LIST_ADDQ(&curproxy->format_unique_id, &node->list); |
| 1578 | } |
| 1579 | |
| 1580 | /* copy default header unique id */ |
| 1581 | if (defproxy.header_unique_id) |
| 1582 | curproxy->header_unique_id = strdup(defproxy.header_unique_id); |
| 1583 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1584 | curproxy->grace = defproxy.grace; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1585 | curproxy->conf.used_listener_id = EB_ROOT; |
| 1586 | curproxy->conf.used_server_id = EB_ROOT; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 1587 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1588 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1589 | } |
| 1590 | else if (!strcmp(args[0], "defaults")) { /* use this one to assign default values */ |
| 1591 | /* some variables may have already been initialized earlier */ |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 1592 | /* FIXME-20070101: we should do this too at the end of the |
| 1593 | * config parsing to free all default values. |
| 1594 | */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1595 | free(defproxy.check_req); |
| 1596 | free(defproxy.cookie_name); |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 1597 | free(defproxy.rdp_cookie_name); |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 1598 | free(defproxy.cookie_domain); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1599 | free(defproxy.url_param_name); |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 1600 | free(defproxy.hh_name); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1601 | free(defproxy.capture_name); |
| 1602 | free(defproxy.monitor_uri); |
| 1603 | free(defproxy.defbe.name); |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 1604 | free(defproxy.iface_name); |
Willy Tarreau | 79f5fe8 | 2008-08-23 08:18:21 +0200 | [diff] [blame] | 1605 | free(defproxy.fwdfor_hdr_name); |
| 1606 | defproxy.fwdfor_hdr_len = 0; |
Willy Tarreau | b86db34 | 2009-11-30 11:50:16 +0100 | [diff] [blame] | 1607 | free(defproxy.orgto_hdr_name); |
| 1608 | defproxy.orgto_hdr_len = 0; |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 1609 | free(defproxy.server_id_hdr_name); |
| 1610 | defproxy.server_id_hdr_len = 0; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 1611 | free(defproxy.expect_str); |
| 1612 | if (defproxy.expect_regex) regfree(defproxy.expect_regex); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 1613 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1614 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1615 | chunk_destroy(&defproxy.errmsg[rc]); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 1616 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1617 | /* we cannot free uri_auth because it might already be used */ |
| 1618 | init_default_instance(); |
| 1619 | curproxy = &defproxy; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1620 | defproxy.cap = PR_CAP_LISTEN; /* all caps for now */ |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1621 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1622 | } |
| 1623 | else if (curproxy == NULL) { |
| 1624 | Alert("parsing [%s:%d] : 'listen' or 'defaults' expected.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1625 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1626 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1627 | } |
| 1628 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1629 | |
| 1630 | /* Now let's parse the proxy-specific keywords */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1631 | if (!strcmp(args[0], "bind")) { /* new listen addresses */ |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 1632 | struct listener *new_listen, *last_listen; |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1633 | int cur_arg; |
| 1634 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1635 | if (curproxy == &defproxy) { |
| 1636 | 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] | 1637 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1638 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1639 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1640 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1641 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1642 | |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 1643 | if ( *(args[1]) != '/' && strchr(args[1], ':') == NULL) { |
Willy Tarreau | d55c3fe | 2010-11-09 09:50:37 +0100 | [diff] [blame] | 1644 | 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] | 1645 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1646 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1647 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1648 | } |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 1649 | |
| 1650 | last_listen = curproxy->listen; |
Willy Tarreau | 8a95691 | 2010-10-15 14:27:08 +0200 | [diff] [blame] | 1651 | |
| 1652 | /* NOTE: the following line might create several listeners if there |
| 1653 | * are comma-separated IPs or port ranges. So all further processing |
| 1654 | * will have to be applied to all listeners created after last_listen. |
| 1655 | */ |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 1656 | if (!str2listener(args[1], curproxy, file, linenum)) { |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1657 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1658 | goto out; |
| 1659 | } |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1660 | |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 1661 | new_listen = curproxy->listen; |
| 1662 | while (new_listen != last_listen) { |
| 1663 | new_listen->conf.file = file; |
| 1664 | new_listen->conf.line = linenum; |
| 1665 | new_listen = new_listen->next; |
Willy Tarreau | c8b1109 | 2011-02-16 11:08:57 +0100 | [diff] [blame] | 1666 | global.maxsock++; |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 1667 | } |
| 1668 | |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 1669 | /* Set default global rights and owner for unix bind */ |
| 1670 | if (curproxy->listen->addr.ss_family == AF_UNIX) { |
| 1671 | memcpy(&(curproxy->listen->perm.ux), &(global.unix_bind.ux), sizeof(global.unix_bind.ux)); |
| 1672 | } |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1673 | cur_arg = 2; |
| 1674 | while (*(args[cur_arg])) { |
| 1675 | if (!strcmp(args[cur_arg], "interface")) { /* specifically bind to this interface */ |
| 1676 | #ifdef SO_BINDTODEVICE |
| 1677 | struct listener *l; |
| 1678 | |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 1679 | if (curproxy->listen->addr.ss_family == AF_UNIX) { |
| 1680 | Alert("parsing [%s:%d] : '%s' : '%s' option not supported on unix sockets.\n", |
| 1681 | file, linenum, args[0], args[cur_arg]); |
| 1682 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1683 | goto out; |
| 1684 | } |
| 1685 | |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1686 | if (!*args[cur_arg + 1]) { |
| 1687 | Alert("parsing [%s:%d] : '%s' : missing interface name.\n", |
| 1688 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1689 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1690 | goto out; |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1691 | } |
| 1692 | |
| 1693 | for (l = curproxy->listen; l != last_listen; l = l->next) |
| 1694 | l->interface = strdup(args[cur_arg + 1]); |
| 1695 | |
| 1696 | global.last_checks |= LSTCHK_NETADM; |
| 1697 | |
| 1698 | cur_arg += 2; |
| 1699 | continue; |
| 1700 | #else |
| 1701 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 1702 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1703 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1704 | goto out; |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1705 | #endif |
| 1706 | } |
Willy Tarreau | be1b918 | 2009-06-14 18:48:19 +0200 | [diff] [blame] | 1707 | if (!strcmp(args[cur_arg], "mss")) { /* set MSS of listening socket */ |
| 1708 | #ifdef TCP_MAXSEG |
| 1709 | struct listener *l; |
| 1710 | int mss; |
| 1711 | |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 1712 | if (curproxy->listen->addr.ss_family == AF_UNIX) { |
| 1713 | Alert("parsing [%s:%d] : '%s' : '%s' option not supported on unix sockets.\n", |
| 1714 | file, linenum, args[0], args[cur_arg]); |
| 1715 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1716 | goto out; |
| 1717 | } |
| 1718 | |
Willy Tarreau | be1b918 | 2009-06-14 18:48:19 +0200 | [diff] [blame] | 1719 | if (!*args[cur_arg + 1]) { |
| 1720 | Alert("parsing [%s:%d] : '%s' : missing MSS value.\n", |
| 1721 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1722 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1723 | goto out; |
Willy Tarreau | be1b918 | 2009-06-14 18:48:19 +0200 | [diff] [blame] | 1724 | } |
| 1725 | |
Willy Tarreau | 48a7e72 | 2010-12-24 15:26:39 +0100 | [diff] [blame] | 1726 | mss = atoi(args[cur_arg + 1]); |
| 1727 | if (!mss || abs(mss) > 65535) { |
| 1728 | 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] | 1729 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1730 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1731 | goto out; |
Willy Tarreau | be1b918 | 2009-06-14 18:48:19 +0200 | [diff] [blame] | 1732 | } |
| 1733 | |
| 1734 | for (l = curproxy->listen; l != last_listen; l = l->next) |
| 1735 | l->maxseg = mss; |
| 1736 | |
| 1737 | cur_arg += 2; |
| 1738 | continue; |
| 1739 | #else |
| 1740 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 1741 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1742 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1743 | goto out; |
Willy Tarreau | be1b918 | 2009-06-14 18:48:19 +0200 | [diff] [blame] | 1744 | #endif |
| 1745 | } |
Willy Tarreau | cb6cd43 | 2009-10-13 07:34:14 +0200 | [diff] [blame] | 1746 | |
| 1747 | if (!strcmp(args[cur_arg], "defer-accept")) { /* wait for some data for 1 second max before doing accept */ |
| 1748 | #ifdef TCP_DEFER_ACCEPT |
| 1749 | struct listener *l; |
| 1750 | |
| 1751 | for (l = curproxy->listen; l != last_listen; l = l->next) |
| 1752 | l->options |= LI_O_DEF_ACCEPT; |
| 1753 | |
| 1754 | cur_arg ++; |
| 1755 | continue; |
| 1756 | #else |
| 1757 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 1758 | file, linenum, args[0], args[cur_arg]); |
| 1759 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1760 | goto out; |
| 1761 | #endif |
| 1762 | } |
| 1763 | |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1764 | if (!strcmp(args[cur_arg], "transparent")) { /* transparently bind to these addresses */ |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 1765 | #ifdef CONFIG_HAP_LINUX_TPROXY |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 1766 | struct listener *l; |
| 1767 | |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 1768 | if (curproxy->listen->addr.ss_family == AF_UNIX) { |
| 1769 | Alert("parsing [%s:%d] : '%s' : '%s' option not supported on unix sockets.\n", |
| 1770 | file, linenum, args[0], args[cur_arg]); |
| 1771 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1772 | goto out; |
| 1773 | } |
| 1774 | |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 1775 | for (l = curproxy->listen; l != last_listen; l = l->next) |
| 1776 | l->options |= LI_O_FOREIGN; |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1777 | |
| 1778 | cur_arg ++; |
| 1779 | continue; |
| 1780 | #else |
| 1781 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 1782 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1783 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1784 | goto out; |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1785 | #endif |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 1786 | } |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1787 | |
Willy Tarreau | 8a95691 | 2010-10-15 14:27:08 +0200 | [diff] [blame] | 1788 | if (!strcmp(args[cur_arg], "accept-proxy")) { /* expect a 'PROXY' line first */ |
| 1789 | struct listener *l; |
| 1790 | |
| 1791 | for (l = curproxy->listen; l != last_listen; l = l->next) |
| 1792 | l->options |= LI_O_ACC_PROXY; |
| 1793 | |
| 1794 | cur_arg ++; |
| 1795 | continue; |
| 1796 | } |
| 1797 | |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1798 | if (!strcmp(args[cur_arg], "name")) { |
| 1799 | struct listener *l; |
| 1800 | |
| 1801 | for (l = curproxy->listen; l != last_listen; l = l->next) |
| 1802 | l->name = strdup(args[cur_arg + 1]); |
| 1803 | |
| 1804 | cur_arg += 2; |
| 1805 | continue; |
| 1806 | } |
| 1807 | |
| 1808 | if (!strcmp(args[cur_arg], "id")) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1809 | struct eb32_node *node; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1810 | struct listener *l; |
| 1811 | |
| 1812 | if (curproxy->listen->next != last_listen) { |
| 1813 | Alert("parsing [%s:%d]: '%s' can be only used with a single socket.\n", |
| 1814 | file, linenum, args[cur_arg]); |
| 1815 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1816 | goto out; |
| 1817 | } |
| 1818 | |
| 1819 | if (!*args[cur_arg + 1]) { |
| 1820 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 1821 | file, linenum, args[cur_arg]); |
| 1822 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1823 | goto out; |
| 1824 | } |
| 1825 | |
| 1826 | curproxy->listen->luid = atol(args[cur_arg + 1]); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1827 | curproxy->listen->conf.id.key = curproxy->listen->luid; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1828 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1829 | if (curproxy->listen->luid <= 0) { |
| 1830 | Alert("parsing [%s:%d]: custom id has to be > 0\n", |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1831 | file, linenum); |
| 1832 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1833 | goto out; |
| 1834 | } |
| 1835 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1836 | node = eb32_lookup(&curproxy->conf.used_listener_id, curproxy->listen->luid); |
| 1837 | if (node) { |
| 1838 | l = container_of(node, struct listener, conf.id); |
| 1839 | Alert("parsing [%s:%d]: custom id %d for socket '%s' already used at %s:%d.\n", |
| 1840 | file, linenum, l->luid, args[1], l->conf.file, l->conf.line); |
| 1841 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1842 | goto out; |
| 1843 | } |
| 1844 | eb32_insert(&curproxy->conf.used_listener_id, &curproxy->listen->conf.id); |
| 1845 | |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1846 | cur_arg += 2; |
| 1847 | continue; |
| 1848 | } |
| 1849 | |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 1850 | if (!strcmp(args[cur_arg], "mode")) { |
| 1851 | |
| 1852 | if (curproxy->listen->addr.ss_family != AF_UNIX) { |
| 1853 | Alert("parsing [%s:%d] : '%s' : '%s' option only supported on unix sockets.\n", |
| 1854 | file, linenum, args[0], args[cur_arg]); |
| 1855 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1856 | goto out; |
| 1857 | } |
| 1858 | |
| 1859 | curproxy->listen->perm.ux.mode = strtol(args[cur_arg + 1], NULL, 8); |
| 1860 | |
| 1861 | cur_arg += 2; |
| 1862 | continue; |
| 1863 | } |
| 1864 | |
| 1865 | if (!strcmp(args[cur_arg], "uid")) { |
| 1866 | |
| 1867 | if (curproxy->listen->addr.ss_family != AF_UNIX) { |
| 1868 | Alert("parsing [%s:%d] : '%s' : '%s' option only supported on unix sockets.\n", |
| 1869 | file, linenum, args[0], args[cur_arg]); |
| 1870 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1871 | goto out; |
| 1872 | } |
| 1873 | |
| 1874 | curproxy->listen->perm.ux.uid = atol(args[cur_arg + 1 ]); |
| 1875 | cur_arg += 2; |
| 1876 | continue; |
| 1877 | } |
| 1878 | |
| 1879 | if (!strcmp(args[cur_arg], "gid")) { |
| 1880 | |
| 1881 | if (curproxy->listen->addr.ss_family != AF_UNIX) { |
| 1882 | Alert("parsing [%s:%d] : '%s' : '%s' option only supported on unix sockets.\n", |
| 1883 | file, linenum, args[0], args[cur_arg]); |
| 1884 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1885 | goto out; |
| 1886 | } |
| 1887 | |
| 1888 | curproxy->listen->perm.ux.gid = atol(args[cur_arg + 1 ]); |
| 1889 | cur_arg += 2; |
| 1890 | continue; |
| 1891 | } |
| 1892 | |
| 1893 | if (!strcmp(args[cur_arg], "user")) { |
| 1894 | struct passwd *user; |
| 1895 | |
| 1896 | if (curproxy->listen->addr.ss_family != AF_UNIX) { |
| 1897 | Alert("parsing [%s:%d] : '%s' : '%s' option only supported on unix sockets.\n", |
| 1898 | file, linenum, args[0], args[cur_arg]); |
| 1899 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1900 | goto out; |
| 1901 | } |
| 1902 | user = getpwnam(args[cur_arg + 1]); |
| 1903 | if (!user) { |
| 1904 | Alert("parsing [%s:%d] : '%s' : '%s' unknown user.\n", |
| 1905 | file, linenum, args[0], args[cur_arg + 1 ]); |
| 1906 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1907 | goto out; |
| 1908 | } |
| 1909 | |
| 1910 | curproxy->listen->perm.ux.uid = user->pw_uid; |
| 1911 | cur_arg += 2; |
| 1912 | continue; |
| 1913 | } |
| 1914 | |
| 1915 | if (!strcmp(args[cur_arg], "group")) { |
| 1916 | struct group *group; |
| 1917 | |
| 1918 | if (curproxy->listen->addr.ss_family != AF_UNIX) { |
| 1919 | Alert("parsing [%s:%d] : '%s' : '%s' option only supported on unix sockets.\n", |
| 1920 | file, linenum, args[0], args[cur_arg]); |
| 1921 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1922 | goto out; |
| 1923 | } |
| 1924 | group = getgrnam(args[cur_arg + 1]); |
| 1925 | if (!group) { |
| 1926 | Alert("parsing [%s:%d] : '%s' : '%s' unknown group.\n", |
| 1927 | file, linenum, args[0], args[cur_arg + 1 ]); |
| 1928 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1929 | goto out; |
| 1930 | } |
| 1931 | |
| 1932 | curproxy->listen->perm.ux.gid = group->gr_gid; |
| 1933 | cur_arg += 2; |
| 1934 | continue; |
| 1935 | } |
| 1936 | |
Willy Tarreau | b48f958 | 2011-09-05 01:17:06 +0200 | [diff] [blame] | 1937 | Alert("parsing [%s:%d] : '%s' only supports the 'transparent', 'accept-proxy', 'defer-accept', 'name', 'id', 'mss', 'mode', 'uid', 'gid', 'user', 'group' and 'interface' options.\n", |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 1938 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1939 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1940 | goto out; |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 1941 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1942 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1943 | } |
| 1944 | else if (!strcmp(args[0], "monitor-net")) { /* set the range of IPs to ignore */ |
| 1945 | if (!*args[1] || !str2net(args[1], &curproxy->mon_net, &curproxy->mon_mask)) { |
| 1946 | Alert("parsing [%s:%d] : '%s' expects address[/mask].\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; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1950 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1951 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1952 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1953 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1954 | /* flush useless bits */ |
| 1955 | curproxy->mon_net.s_addr &= curproxy->mon_mask.s_addr; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1956 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1957 | } |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 1958 | else if (!strcmp(args[0], "monitor-uri")) { /* set the URI to intercept */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1959 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1960 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1961 | |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 1962 | if (!*args[1]) { |
| 1963 | Alert("parsing [%s:%d] : '%s' expects an URI.\n", |
| 1964 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1965 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1966 | goto out; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 1967 | } |
| 1968 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1969 | free(curproxy->monitor_uri); |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 1970 | curproxy->monitor_uri_len = strlen(args[1]); |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 1971 | curproxy->monitor_uri = (char *)calloc(1, curproxy->monitor_uri_len + 1); |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 1972 | memcpy(curproxy->monitor_uri, args[1], curproxy->monitor_uri_len); |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 1973 | curproxy->monitor_uri[curproxy->monitor_uri_len] = '\0'; |
| 1974 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1975 | goto out; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 1976 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1977 | else if (!strcmp(args[0], "mode")) { /* sets the proxy mode */ |
| 1978 | if (!strcmp(args[1], "http")) curproxy->mode = PR_MODE_HTTP; |
| 1979 | else if (!strcmp(args[1], "tcp")) curproxy->mode = PR_MODE_TCP; |
| 1980 | else if (!strcmp(args[1], "health")) curproxy->mode = PR_MODE_HEALTH; |
| 1981 | else { |
| 1982 | 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] | 1983 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1984 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1985 | } |
| 1986 | } |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 1987 | else if (!strcmp(args[0], "id")) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1988 | struct eb32_node *node; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 1989 | |
| 1990 | if (curproxy == &defproxy) { |
| 1991 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", |
| 1992 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1993 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1994 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 1995 | } |
| 1996 | |
| 1997 | if (!*args[1]) { |
| 1998 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 1999 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2000 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2001 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2002 | } |
| 2003 | |
| 2004 | curproxy->uuid = atol(args[1]); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2005 | curproxy->conf.id.key = curproxy->uuid; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2006 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2007 | if (curproxy->uuid <= 0) { |
| 2008 | Alert("parsing [%s:%d]: custom id has to be > 0.\n", |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2009 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2010 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2011 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2012 | } |
| 2013 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2014 | node = eb32_lookup(&used_proxy_id, curproxy->uuid); |
| 2015 | if (node) { |
| 2016 | struct proxy *target = container_of(node, struct proxy, conf.id); |
| 2017 | Alert("parsing [%s:%d]: %s %s reuses same custom id as %s %s (declared at %s:%d).\n", |
| 2018 | file, linenum, proxy_type_str(curproxy), curproxy->id, |
| 2019 | proxy_type_str(target), target->id, target->conf.file, target->conf.line); |
| 2020 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2021 | goto out; |
| 2022 | } |
| 2023 | eb32_insert(&used_proxy_id, &curproxy->conf.id); |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2024 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 2025 | else if (!strcmp(args[0], "description")) { |
| 2026 | int i, len=0; |
| 2027 | char *d; |
| 2028 | |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 2029 | if (curproxy == &defproxy) { |
| 2030 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", |
| 2031 | file, linenum, args[0]); |
| 2032 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2033 | goto out; |
| 2034 | } |
| 2035 | |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 2036 | if (!*args[1]) { |
| 2037 | Alert("parsing [%s:%d]: '%s' expects a string argument.\n", |
| 2038 | file, linenum, args[0]); |
| 2039 | return -1; |
| 2040 | } |
| 2041 | |
| 2042 | for(i=1; *args[i]; i++) |
| 2043 | len += strlen(args[i])+1; |
| 2044 | |
| 2045 | d = (char *)calloc(1, len); |
| 2046 | curproxy->desc = d; |
| 2047 | |
| 2048 | d += sprintf(d, "%s", args[1]); |
| 2049 | for(i=2; *args[i]; i++) |
| 2050 | d += sprintf(d, " %s", args[i]); |
| 2051 | |
| 2052 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2053 | else if (!strcmp(args[0], "disabled")) { /* disables this proxy */ |
| 2054 | curproxy->state = PR_STSTOPPED; |
| 2055 | } |
| 2056 | else if (!strcmp(args[0], "enabled")) { /* enables this proxy (used to revert a disabled default) */ |
| 2057 | curproxy->state = PR_STNEW; |
| 2058 | } |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2059 | else if (!strcmp(args[0], "bind-process")) { /* enable this proxy only on some processes */ |
| 2060 | int cur_arg = 1; |
| 2061 | unsigned int set = 0; |
| 2062 | |
| 2063 | while (*args[cur_arg]) { |
| 2064 | int u; |
| 2065 | if (strcmp(args[cur_arg], "all") == 0) { |
| 2066 | set = 0; |
| 2067 | break; |
| 2068 | } |
| 2069 | else if (strcmp(args[cur_arg], "odd") == 0) { |
| 2070 | set |= 0x55555555; |
| 2071 | } |
| 2072 | else if (strcmp(args[cur_arg], "even") == 0) { |
| 2073 | set |= 0xAAAAAAAA; |
| 2074 | } |
| 2075 | else { |
| 2076 | u = str2uic(args[cur_arg]); |
| 2077 | if (u < 1 || u > 32) { |
| 2078 | Alert("parsing [%s:%d]: %s expects 'all', 'odd', 'even', or process numbers from 1 to 32.\n", |
| 2079 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2080 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2081 | goto out; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2082 | } |
| 2083 | if (u > global.nbproc) { |
| 2084 | Warning("parsing [%s:%d]: %s references process number higher than global.nbproc.\n", |
| 2085 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2086 | err_code |= ERR_WARN; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2087 | } |
| 2088 | set |= 1 << (u - 1); |
| 2089 | } |
| 2090 | cur_arg++; |
| 2091 | } |
| 2092 | curproxy->bind_proc = set; |
| 2093 | } |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 2094 | else if (!strcmp(args[0], "acl")) { /* add an ACL */ |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2095 | if (curproxy == &defproxy) { |
| 2096 | 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] | 2097 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2098 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2099 | } |
| 2100 | |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 2101 | err = invalid_char(args[1]); |
| 2102 | if (err) { |
| 2103 | Alert("parsing [%s:%d] : character '%c' is not permitted in acl name '%s'.\n", |
| 2104 | file, linenum, *err, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2105 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 2106 | } |
| 2107 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 2108 | if (parse_acl((const char **)args + 1, &curproxy->acl, &errmsg) == NULL) { |
| 2109 | Alert("parsing [%s:%d] : error detected while parsing ACL '%s' : %s.\n", |
| 2110 | file, linenum, args[1], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2111 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2112 | goto out; |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 2113 | } |
| 2114 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2115 | else if (!strcmp(args[0], "cookie")) { /* cookie name */ |
| 2116 | int cur_arg; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2117 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2118 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2119 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2120 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2121 | if (*(args[1]) == 0) { |
| 2122 | Alert("parsing [%s:%d] : '%s' expects <cookie_name> as argument.\n", |
| 2123 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2124 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2125 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2126 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2127 | |
Willy Tarreau | c63d4bb | 2010-10-23 11:37:27 +0200 | [diff] [blame] | 2128 | curproxy->options &= ~PR_O_COOK_ANY; |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 2129 | curproxy->options2 &= ~PR_O2_COOK_PSV; |
Willy Tarreau | c63d4bb | 2010-10-23 11:37:27 +0200 | [diff] [blame] | 2130 | curproxy->cookie_maxidle = curproxy->cookie_maxlife = 0; |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 2131 | free(curproxy->cookie_domain); curproxy->cookie_domain = NULL; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2132 | free(curproxy->cookie_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2133 | curproxy->cookie_name = strdup(args[1]); |
| 2134 | curproxy->cookie_len = strlen(curproxy->cookie_name); |
Willy Tarreau | c63d4bb | 2010-10-23 11:37:27 +0200 | [diff] [blame] | 2135 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2136 | cur_arg = 2; |
| 2137 | while (*(args[cur_arg])) { |
| 2138 | if (!strcmp(args[cur_arg], "rewrite")) { |
| 2139 | curproxy->options |= PR_O_COOK_RW; |
| 2140 | } |
| 2141 | else if (!strcmp(args[cur_arg], "indirect")) { |
| 2142 | curproxy->options |= PR_O_COOK_IND; |
| 2143 | } |
| 2144 | else if (!strcmp(args[cur_arg], "insert")) { |
| 2145 | curproxy->options |= PR_O_COOK_INS; |
| 2146 | } |
| 2147 | else if (!strcmp(args[cur_arg], "nocache")) { |
| 2148 | curproxy->options |= PR_O_COOK_NOC; |
| 2149 | } |
| 2150 | else if (!strcmp(args[cur_arg], "postonly")) { |
| 2151 | curproxy->options |= PR_O_COOK_POST; |
| 2152 | } |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 2153 | else if (!strcmp(args[cur_arg], "preserve")) { |
| 2154 | curproxy->options2 |= PR_O2_COOK_PSV; |
| 2155 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2156 | else if (!strcmp(args[cur_arg], "prefix")) { |
| 2157 | curproxy->options |= PR_O_COOK_PFX; |
| 2158 | } |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2159 | else if (!strcmp(args[cur_arg], "domain")) { |
| 2160 | if (!*args[cur_arg + 1]) { |
| 2161 | Alert("parsing [%s:%d]: '%s' expects <domain> as argument.\n", |
| 2162 | file, linenum, args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2163 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2164 | goto out; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2165 | } |
| 2166 | |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 2167 | if (*args[cur_arg + 1] != '.' || !strchr(args[cur_arg + 1] + 1, '.')) { |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2168 | /* rfc2109, 4.3.2 Rejecting Cookies */ |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 2169 | Warning("parsing [%s:%d]: domain '%s' contains no embedded" |
| 2170 | " dots nor does not start with a dot." |
| 2171 | " RFC forbids it, this configuration may not work properly.\n", |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2172 | file, linenum, args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 2173 | err_code |= ERR_WARN; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2174 | } |
| 2175 | |
| 2176 | err = invalid_domainchar(args[cur_arg + 1]); |
| 2177 | if (err) { |
| 2178 | Alert("parsing [%s:%d]: character '%c' is not permitted in domain name '%s'.\n", |
| 2179 | file, linenum, *err, args[cur_arg + 1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2180 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2181 | goto out; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2182 | } |
| 2183 | |
Willy Tarreau | 68a897b | 2009-12-03 23:28:34 +0100 | [diff] [blame] | 2184 | if (!curproxy->cookie_domain) { |
| 2185 | curproxy->cookie_domain = strdup(args[cur_arg + 1]); |
| 2186 | } else { |
| 2187 | /* one domain was already specified, add another one by |
| 2188 | * building the string which will be returned along with |
| 2189 | * the cookie. |
| 2190 | */ |
| 2191 | char *new_ptr; |
| 2192 | int new_len = strlen(curproxy->cookie_domain) + |
| 2193 | strlen("; domain=") + strlen(args[cur_arg + 1]) + 1; |
| 2194 | new_ptr = malloc(new_len); |
| 2195 | snprintf(new_ptr, new_len, "%s; domain=%s", curproxy->cookie_domain, args[cur_arg+1]); |
| 2196 | free(curproxy->cookie_domain); |
| 2197 | curproxy->cookie_domain = new_ptr; |
| 2198 | } |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 2199 | cur_arg++; |
| 2200 | } |
| 2201 | else if (!strcmp(args[cur_arg], "maxidle")) { |
| 2202 | unsigned int maxidle; |
| 2203 | const char *res; |
| 2204 | |
| 2205 | if (!*args[cur_arg + 1]) { |
| 2206 | Alert("parsing [%s:%d]: '%s' expects <idletime> in seconds as argument.\n", |
| 2207 | file, linenum, args[cur_arg]); |
| 2208 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2209 | goto out; |
| 2210 | } |
| 2211 | |
| 2212 | res = parse_time_err(args[cur_arg + 1], &maxidle, TIME_UNIT_S); |
| 2213 | if (res) { |
| 2214 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 2215 | file, linenum, *res, args[cur_arg]); |
| 2216 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2217 | goto out; |
| 2218 | } |
| 2219 | curproxy->cookie_maxidle = maxidle; |
| 2220 | cur_arg++; |
| 2221 | } |
| 2222 | else if (!strcmp(args[cur_arg], "maxlife")) { |
| 2223 | unsigned int maxlife; |
| 2224 | const char *res; |
| 2225 | |
| 2226 | if (!*args[cur_arg + 1]) { |
| 2227 | Alert("parsing [%s:%d]: '%s' expects <lifetime> in seconds as argument.\n", |
| 2228 | file, linenum, args[cur_arg]); |
| 2229 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2230 | goto out; |
| 2231 | } |
| 2232 | |
| 2233 | res = parse_time_err(args[cur_arg + 1], &maxlife, TIME_UNIT_S); |
| 2234 | if (res) { |
| 2235 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 2236 | file, linenum, *res, args[cur_arg]); |
| 2237 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2238 | goto out; |
| 2239 | } |
| 2240 | curproxy->cookie_maxlife = maxlife; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2241 | cur_arg++; |
| 2242 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2243 | else { |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 2244 | 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] | 2245 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2246 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2247 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2248 | } |
| 2249 | cur_arg++; |
| 2250 | } |
| 2251 | if (!POWEROF2(curproxy->options & (PR_O_COOK_RW|PR_O_COOK_IND))) { |
| 2252 | Alert("parsing [%s:%d] : cookie 'rewrite' and 'indirect' modes are incompatible.\n", |
| 2253 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2254 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2255 | } |
| 2256 | |
| 2257 | if (!POWEROF2(curproxy->options & (PR_O_COOK_RW|PR_O_COOK_INS|PR_O_COOK_PFX))) { |
| 2258 | Alert("parsing [%s:%d] : cookie 'rewrite', 'insert' and 'prefix' modes are incompatible.\n", |
| 2259 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2260 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2261 | } |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 2262 | |
| 2263 | if ((curproxy->options2 & PR_O2_COOK_PSV) && !(curproxy->options & (PR_O_COOK_INS|PR_O_COOK_IND))) { |
| 2264 | Alert("parsing [%s:%d] : cookie 'preserve' requires at least 'insert' or 'indirect'.\n", |
| 2265 | file, linenum); |
| 2266 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2267 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2268 | }/* end else if (!strcmp(args[0], "cookie")) */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2269 | else if (!strcmp(args[0], "persist")) { /* persist */ |
| 2270 | if (*(args[1]) == 0) { |
| 2271 | Alert("parsing [%s:%d] : missing persist method.\n", |
| 2272 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2273 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2274 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2275 | } |
| 2276 | |
| 2277 | if (!strncmp(args[1], "rdp-cookie", 10)) { |
| 2278 | curproxy->options2 |= PR_O2_RDPC_PRST; |
| 2279 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2280 | if (*(args[1] + 10) == '(') { /* cookie name */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2281 | const char *beg, *end; |
| 2282 | |
| 2283 | beg = args[1] + 11; |
| 2284 | end = strchr(beg, ')'); |
| 2285 | |
| 2286 | if (!end || end == beg) { |
| 2287 | Alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n", |
| 2288 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2289 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2290 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2291 | } |
| 2292 | |
| 2293 | free(curproxy->rdp_cookie_name); |
| 2294 | curproxy->rdp_cookie_name = my_strndup(beg, end - beg); |
| 2295 | curproxy->rdp_cookie_len = end-beg; |
| 2296 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2297 | else if (*(args[1] + 10) == '\0') { /* default cookie name 'msts' */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2298 | free(curproxy->rdp_cookie_name); |
| 2299 | curproxy->rdp_cookie_name = strdup("msts"); |
| 2300 | curproxy->rdp_cookie_len = strlen(curproxy->rdp_cookie_name); |
| 2301 | } |
| 2302 | else { /* syntax */ |
| 2303 | Alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n", |
| 2304 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2305 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2306 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2307 | } |
| 2308 | } |
| 2309 | else { |
| 2310 | Alert("parsing [%s:%d] : unknown persist method.\n", |
| 2311 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2312 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2313 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2314 | } |
| 2315 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2316 | else if (!strcmp(args[0], "appsession")) { /* cookie name */ |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2317 | int cur_arg; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2318 | |
Cyril Bonté | 3b7a369 | 2010-01-10 17:01:47 +0100 | [diff] [blame] | 2319 | if (curproxy == &defproxy) { |
| 2320 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2321 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2322 | goto out; |
| 2323 | } |
| 2324 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2325 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2326 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2327 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2328 | if (*(args[5]) == 0) { |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2329 | 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] | 2330 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2331 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2332 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2333 | } |
| 2334 | have_appsession = 1; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2335 | free(curproxy->appsession_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2336 | curproxy->appsession_name = strdup(args[1]); |
| 2337 | curproxy->appsession_name_len = strlen(curproxy->appsession_name); |
| 2338 | curproxy->appsession_len = atoi(args[3]); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 2339 | err = parse_time_err(args[5], &val, TIME_UNIT_MS); |
| 2340 | if (err) { |
| 2341 | Alert("parsing [%s:%d] : unexpected character '%c' in %s timeout.\n", |
| 2342 | file, linenum, *err, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2343 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2344 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 2345 | } |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 2346 | curproxy->timeout.appsession = val; |
Willy Tarreau | ee99136 | 2007-05-14 14:37:50 +0200 | [diff] [blame] | 2347 | |
Willy Tarreau | 51041c7 | 2007-09-09 21:56:53 +0200 | [diff] [blame] | 2348 | if (appsession_hash_init(&(curproxy->htbl_proxy), destroy) == 0) { |
| 2349 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2350 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2351 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2352 | } |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2353 | |
| 2354 | cur_arg = 6; |
| 2355 | curproxy->options2 &= ~PR_O2_AS_REQL; |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2356 | curproxy->options2 &= ~PR_O2_AS_M_ANY; |
| 2357 | curproxy->options2 |= PR_O2_AS_M_PP; |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2358 | while (*(args[cur_arg])) { |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2359 | if (!strcmp(args[cur_arg], "request-learn")) { |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2360 | curproxy->options2 |= PR_O2_AS_REQL; |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2361 | } else if (!strcmp(args[cur_arg], "prefix")) { |
| 2362 | curproxy->options2 |= PR_O2_AS_PFX; |
| 2363 | } else if (!strcmp(args[cur_arg], "mode")) { |
| 2364 | if (!*args[cur_arg + 1]) { |
| 2365 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 2366 | file, linenum, args[0], args[cur_arg]); |
| 2367 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2368 | goto out; |
| 2369 | } |
| 2370 | |
| 2371 | cur_arg++; |
| 2372 | if (!strcmp(args[cur_arg], "query-string")) { |
| 2373 | curproxy->options2 &= ~PR_O2_AS_M_ANY; |
| 2374 | curproxy->options2 |= PR_O2_AS_M_QS; |
| 2375 | } else if (!strcmp(args[cur_arg], "path-parameters")) { |
| 2376 | curproxy->options2 &= ~PR_O2_AS_M_ANY; |
| 2377 | curproxy->options2 |= PR_O2_AS_M_PP; |
| 2378 | } else { |
| 2379 | Alert("parsing [%s:%d] : unknown mode '%s'\n", file, linenum, args[cur_arg]); |
| 2380 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2381 | goto out; |
| 2382 | } |
| 2383 | } |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2384 | cur_arg++; |
| 2385 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2386 | } /* Url App Session */ |
| 2387 | else if (!strcmp(args[0], "capture")) { |
Willy Tarreau | 3b6b1a9 | 2009-07-23 13:24:23 +0200 | [diff] [blame] | 2388 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2389 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2390 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2391 | if (!strcmp(args[1], "cookie")) { /* name of a cookie to capture */ |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 2392 | if (curproxy == &defproxy) { |
| 2393 | Alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
| 2394 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2395 | goto out; |
| 2396 | } |
| 2397 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2398 | if (*(args[4]) == 0) { |
| 2399 | Alert("parsing [%s:%d] : '%s' expects 'cookie' <cookie_name> 'len' <len>.\n", |
| 2400 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2401 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2402 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2403 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2404 | free(curproxy->capture_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2405 | curproxy->capture_name = strdup(args[2]); |
| 2406 | curproxy->capture_namelen = strlen(curproxy->capture_name); |
| 2407 | curproxy->capture_len = atol(args[4]); |
| 2408 | if (curproxy->capture_len >= CAPTURE_LEN) { |
| 2409 | Warning("parsing [%s:%d] : truncating capture length to %d bytes.\n", |
| 2410 | file, linenum, CAPTURE_LEN - 1); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2411 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2412 | curproxy->capture_len = CAPTURE_LEN - 1; |
| 2413 | } |
| 2414 | curproxy->to_log |= LW_COOKIE; |
| 2415 | } |
| 2416 | else if (!strcmp(args[1], "request") && !strcmp(args[2], "header")) { |
| 2417 | struct cap_hdr *hdr; |
| 2418 | |
| 2419 | if (curproxy == &defproxy) { |
| 2420 | 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] | 2421 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2422 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2423 | } |
| 2424 | |
| 2425 | if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) { |
| 2426 | Alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n", |
| 2427 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2428 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2429 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2430 | } |
| 2431 | |
| 2432 | hdr = calloc(sizeof(struct cap_hdr), 1); |
| 2433 | hdr->next = curproxy->req_cap; |
| 2434 | hdr->name = strdup(args[3]); |
| 2435 | hdr->namelen = strlen(args[3]); |
| 2436 | hdr->len = atol(args[5]); |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 2437 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2438 | hdr->index = curproxy->nb_req_cap++; |
| 2439 | curproxy->req_cap = hdr; |
| 2440 | curproxy->to_log |= LW_REQHDR; |
| 2441 | } |
| 2442 | else if (!strcmp(args[1], "response") && !strcmp(args[2], "header")) { |
| 2443 | struct cap_hdr *hdr; |
| 2444 | |
| 2445 | if (curproxy == &defproxy) { |
| 2446 | 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] | 2447 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2448 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2449 | } |
| 2450 | |
| 2451 | if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) { |
| 2452 | Alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n", |
| 2453 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2454 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2455 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2456 | } |
| 2457 | hdr = calloc(sizeof(struct cap_hdr), 1); |
| 2458 | hdr->next = curproxy->rsp_cap; |
| 2459 | hdr->name = strdup(args[3]); |
| 2460 | hdr->namelen = strlen(args[3]); |
| 2461 | hdr->len = atol(args[5]); |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 2462 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2463 | hdr->index = curproxy->nb_rsp_cap++; |
| 2464 | curproxy->rsp_cap = hdr; |
| 2465 | curproxy->to_log |= LW_RSPHDR; |
| 2466 | } |
| 2467 | else { |
| 2468 | Alert("parsing [%s:%d] : '%s' expects 'cookie' or 'request header' or 'response header'.\n", |
| 2469 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2470 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2471 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2472 | } |
| 2473 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2474 | else if (!strcmp(args[0], "retries")) { /* connection retries */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2475 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2476 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2477 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2478 | if (*(args[1]) == 0) { |
| 2479 | Alert("parsing [%s:%d] : '%s' expects an integer argument (dispatch counts for one).\n", |
| 2480 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2481 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2482 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2483 | } |
| 2484 | curproxy->conn_retries = atol(args[1]); |
| 2485 | } |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2486 | 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] | 2487 | struct http_req_rule *rule; |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2488 | |
| 2489 | if (curproxy == &defproxy) { |
| 2490 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2491 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2492 | goto out; |
| 2493 | } |
| 2494 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 2495 | 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] | 2496 | Warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n", |
| 2497 | file, linenum, args[0]); |
| 2498 | err_code |= ERR_WARN; |
| 2499 | } |
| 2500 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 2501 | 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] | 2502 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 2503 | if (!rule) { |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2504 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2505 | goto out; |
| 2506 | } |
| 2507 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 2508 | err_code |= warnif_cond_requires_resp(rule->cond, file, linenum); |
| 2509 | LIST_ADDQ(&curproxy->http_req_rules, &rule->list); |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2510 | } |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 2511 | else if (!strcmp(args[0], "http-send-name-header")) { /* send server name in request header */ |
| 2512 | /* set the header name and length into the proxy structure */ |
| 2513 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 2514 | err_code |= ERR_WARN; |
| 2515 | |
| 2516 | if (!*args[1]) { |
| 2517 | Alert("parsing [%s:%d] : '%s' requires a header string.\n", |
| 2518 | file, linenum, args[0]); |
| 2519 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2520 | goto out; |
| 2521 | } |
| 2522 | |
| 2523 | /* set the desired header name */ |
| 2524 | free(curproxy->server_id_hdr_name); |
| 2525 | curproxy->server_id_hdr_name = strdup(args[1]); |
| 2526 | curproxy->server_id_hdr_len = strlen(curproxy->server_id_hdr_name); |
| 2527 | } |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2528 | else if (!strcmp(args[0], "block")) { /* early blocking based on ACLs */ |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2529 | if (curproxy == &defproxy) { |
| 2530 | 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] | 2531 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2532 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2533 | } |
| 2534 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2535 | if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) { |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2536 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 2537 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2538 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2539 | goto out; |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2540 | } |
| 2541 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 2542 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 1, &errmsg)) == NULL) { |
| 2543 | Alert("parsing [%s:%d] : error detected while parsing blocking condition : %s.\n", |
| 2544 | file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2545 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2546 | goto out; |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2547 | } |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2548 | |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2549 | LIST_ADDQ(&curproxy->block_cond, &cond->list); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 2550 | warnif_misplaced_block(curproxy, file, linenum, args[0]); |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2551 | } |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2552 | else if (!strcmp(args[0], "redirect")) { |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2553 | struct redirect_rule *rule; |
| 2554 | int cur_arg; |
| 2555 | int type = REDIRECT_TYPE_NONE; |
| 2556 | int code = 302; |
| 2557 | char *destination = NULL; |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2558 | char *cookie = NULL; |
| 2559 | int cookie_set = 0; |
Willy Tarreau | 79da469 | 2008-11-19 20:03:04 +0100 | [diff] [blame] | 2560 | unsigned int flags = REDIRECT_FLAG_NONE; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2561 | |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 2562 | if (curproxy == &defproxy) { |
| 2563 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2564 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2565 | goto out; |
| 2566 | } |
| 2567 | |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2568 | cur_arg = 1; |
| 2569 | while (*(args[cur_arg])) { |
| 2570 | if (!strcmp(args[cur_arg], "location")) { |
| 2571 | if (!*args[cur_arg + 1]) { |
| 2572 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 2573 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2574 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2575 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2576 | } |
| 2577 | |
| 2578 | type = REDIRECT_TYPE_LOCATION; |
| 2579 | cur_arg++; |
| 2580 | destination = args[cur_arg]; |
| 2581 | } |
| 2582 | else if (!strcmp(args[cur_arg], "prefix")) { |
| 2583 | if (!*args[cur_arg + 1]) { |
| 2584 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 2585 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2586 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2587 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2588 | } |
| 2589 | |
| 2590 | type = REDIRECT_TYPE_PREFIX; |
| 2591 | cur_arg++; |
| 2592 | destination = args[cur_arg]; |
| 2593 | } |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2594 | else if (!strcmp(args[cur_arg], "set-cookie")) { |
| 2595 | if (!*args[cur_arg + 1]) { |
| 2596 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 2597 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2598 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2599 | goto out; |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2600 | } |
| 2601 | |
| 2602 | cur_arg++; |
| 2603 | cookie = args[cur_arg]; |
| 2604 | cookie_set = 1; |
| 2605 | } |
| 2606 | else if (!strcmp(args[cur_arg], "clear-cookie")) { |
| 2607 | if (!*args[cur_arg + 1]) { |
| 2608 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 2609 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2610 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2611 | goto out; |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2612 | } |
| 2613 | |
| 2614 | cur_arg++; |
| 2615 | cookie = args[cur_arg]; |
| 2616 | cookie_set = 0; |
| 2617 | } |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2618 | else if (!strcmp(args[cur_arg],"code")) { |
| 2619 | if (!*args[cur_arg + 1]) { |
| 2620 | Alert("parsing [%s:%d] : '%s': missing HTTP code.\n", |
| 2621 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2622 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2623 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2624 | } |
| 2625 | cur_arg++; |
| 2626 | code = atol(args[cur_arg]); |
| 2627 | if (code < 301 || code > 303) { |
| 2628 | Alert("parsing [%s:%d] : '%s': unsupported HTTP code '%d'.\n", |
| 2629 | file, linenum, args[0], code); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2630 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2631 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2632 | } |
| 2633 | } |
Willy Tarreau | 79da469 | 2008-11-19 20:03:04 +0100 | [diff] [blame] | 2634 | else if (!strcmp(args[cur_arg],"drop-query")) { |
| 2635 | flags |= REDIRECT_FLAG_DROP_QS; |
| 2636 | } |
Willy Tarreau | 81e3b4f | 2010-01-10 00:42:19 +0100 | [diff] [blame] | 2637 | else if (!strcmp(args[cur_arg],"append-slash")) { |
| 2638 | flags |= REDIRECT_FLAG_APPEND_SLASH; |
| 2639 | } |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2640 | else if (strcmp(args[cur_arg], "if") == 0 || |
| 2641 | strcmp(args[cur_arg], "unless") == 0) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 2642 | cond = build_acl_cond(file, linenum, curproxy, (const char **)args + cur_arg, &errmsg); |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2643 | if (!cond) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 2644 | Alert("parsing [%s:%d] : '%s': error detected while parsing redirect condition : %s.\n", |
| 2645 | file, linenum, args[0], errmsg); |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2646 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2647 | goto out; |
| 2648 | } |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2649 | break; |
| 2650 | } |
| 2651 | else { |
Willy Tarreau | 81e3b4f | 2010-01-10 00:42:19 +0100 | [diff] [blame] | 2652 | 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] | 2653 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2654 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2655 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2656 | } |
| 2657 | cur_arg++; |
| 2658 | } |
| 2659 | |
| 2660 | if (type == REDIRECT_TYPE_NONE) { |
| 2661 | Alert("parsing [%s:%d] : '%s' expects a redirection type ('prefix' or 'location').\n", |
| 2662 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2663 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2664 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2665 | } |
| 2666 | |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2667 | rule = (struct redirect_rule *)calloc(1, sizeof(*rule)); |
| 2668 | rule->cond = cond; |
| 2669 | rule->rdr_str = strdup(destination); |
| 2670 | rule->rdr_len = strlen(destination); |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2671 | if (cookie) { |
| 2672 | /* 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] | 2673 | * a clear consists in appending "; path=/; Max-Age=0;" at the end. |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2674 | */ |
| 2675 | rule->cookie_len = strlen(cookie); |
William Turner | d986526 | 2010-03-01 13:30:34 -0500 | [diff] [blame] | 2676 | if (cookie_set) { |
| 2677 | rule->cookie_str = malloc(rule->cookie_len + 10); |
| 2678 | memcpy(rule->cookie_str, cookie, rule->cookie_len); |
| 2679 | memcpy(rule->cookie_str + rule->cookie_len, "; path=/;", 10); |
| 2680 | rule->cookie_len += 9; |
| 2681 | } else { |
| 2682 | rule->cookie_str = malloc(rule->cookie_len + 21); |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2683 | memcpy(rule->cookie_str, cookie, rule->cookie_len); |
William Turner | d986526 | 2010-03-01 13:30:34 -0500 | [diff] [blame] | 2684 | memcpy(rule->cookie_str + rule->cookie_len, "; path=/; Max-Age=0;", 21); |
| 2685 | rule->cookie_len += 20; |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2686 | } |
| 2687 | } |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2688 | rule->type = type; |
| 2689 | rule->code = code; |
Willy Tarreau | 79da469 | 2008-11-19 20:03:04 +0100 | [diff] [blame] | 2690 | rule->flags = flags; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2691 | LIST_INIT(&rule->list); |
| 2692 | LIST_ADDQ(&curproxy->redirect_rules, &rule->list); |
Willy Tarreau | 9d9ed01 | 2011-02-23 15:24:42 +0100 | [diff] [blame] | 2693 | err_code |= warnif_rule_after_use_backend(curproxy, file, linenum, args[0]); |
| 2694 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2695 | } |
Krzysztof Piotr Oledzki | 7b723ef | 2009-01-27 21:09:41 +0100 | [diff] [blame] | 2696 | else if (!strcmp(args[0], "use_backend")) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2697 | struct switching_rule *rule; |
| 2698 | |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2699 | if (curproxy == &defproxy) { |
| 2700 | 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] | 2701 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2702 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2703 | } |
| 2704 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2705 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2706 | err_code |= ERR_WARN; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2707 | |
| 2708 | if (*(args[1]) == 0) { |
| 2709 | 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] | 2710 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2711 | goto out; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2712 | } |
| 2713 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2714 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2715 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 2716 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2717 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2718 | goto out; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2719 | } |
| 2720 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 2721 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 2722 | Alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n", |
| 2723 | file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2724 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2725 | goto out; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2726 | } |
| 2727 | |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 2728 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
Willy Tarreau | a980263 | 2008-07-25 19:13:19 +0200 | [diff] [blame] | 2729 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2730 | rule = (struct switching_rule *)calloc(1, sizeof(*rule)); |
| 2731 | rule->cond = cond; |
| 2732 | rule->be.name = strdup(args[1]); |
| 2733 | LIST_INIT(&rule->list); |
| 2734 | LIST_ADDQ(&curproxy->switching_rules, &rule->list); |
| 2735 | } |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 2736 | else if (strcmp(args[0], "use-server") == 0) { |
| 2737 | struct server_rule *rule; |
| 2738 | |
| 2739 | if (curproxy == &defproxy) { |
| 2740 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2741 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2742 | goto out; |
| 2743 | } |
| 2744 | |
| 2745 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 2746 | err_code |= ERR_WARN; |
| 2747 | |
| 2748 | if (*(args[1]) == 0) { |
| 2749 | Alert("parsing [%s:%d] : '%s' expects a server name.\n", file, linenum, args[0]); |
| 2750 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2751 | goto out; |
| 2752 | } |
| 2753 | |
| 2754 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
| 2755 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 2756 | file, linenum, args[0]); |
| 2757 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2758 | goto out; |
| 2759 | } |
| 2760 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 2761 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 2762 | Alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n", |
| 2763 | file, linenum, errmsg); |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 2764 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2765 | goto out; |
| 2766 | } |
| 2767 | |
| 2768 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
| 2769 | |
| 2770 | rule = (struct server_rule *)calloc(1, sizeof(*rule)); |
| 2771 | rule->cond = cond; |
| 2772 | rule->srv.name = strdup(args[1]); |
| 2773 | LIST_INIT(&rule->list); |
| 2774 | LIST_ADDQ(&curproxy->server_rules, &rule->list); |
| 2775 | curproxy->be_req_ana |= AN_REQ_SRV_RULES; |
| 2776 | } |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 2777 | else if ((!strcmp(args[0], "force-persist")) || |
| 2778 | (!strcmp(args[0], "ignore-persist"))) { |
| 2779 | struct persist_rule *rule; |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2780 | |
| 2781 | if (curproxy == &defproxy) { |
| 2782 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2783 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2784 | goto out; |
| 2785 | } |
| 2786 | |
| 2787 | if (warnifnotcap(curproxy, PR_CAP_FE|PR_CAP_BE, file, linenum, args[0], NULL)) |
| 2788 | err_code |= ERR_WARN; |
| 2789 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2790 | if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) { |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2791 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 2792 | file, linenum, args[0]); |
| 2793 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2794 | goto out; |
| 2795 | } |
| 2796 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 2797 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 1, &errmsg)) == NULL) { |
| 2798 | Alert("parsing [%s:%d] : error detected while parsing a '%s' rule : %s.\n", |
| 2799 | file, linenum, args[0], errmsg); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2800 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2801 | goto out; |
| 2802 | } |
| 2803 | |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 2804 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2805 | |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 2806 | rule = (struct persist_rule *)calloc(1, sizeof(*rule)); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2807 | rule->cond = cond; |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 2808 | if (!strcmp(args[0], "force-persist")) { |
| 2809 | rule->type = PERSIST_TYPE_FORCE; |
| 2810 | } else { |
| 2811 | rule->type = PERSIST_TYPE_IGNORE; |
| 2812 | } |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2813 | LIST_INIT(&rule->list); |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 2814 | LIST_ADDQ(&curproxy->persist_rules, &rule->list); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2815 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2816 | else if (!strcmp(args[0], "stick-table")) { |
| 2817 | int myidx = 1; |
| 2818 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2819 | curproxy->table.id = curproxy->id; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2820 | curproxy->table.type = (unsigned int)-1; |
| 2821 | while (*args[myidx]) { |
| 2822 | const char *err; |
| 2823 | |
| 2824 | if (strcmp(args[myidx], "size") == 0) { |
| 2825 | myidx++; |
| 2826 | if (!*(args[myidx])) { |
| 2827 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 2828 | file, linenum, args[myidx-1]); |
| 2829 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2830 | goto out; |
| 2831 | } |
| 2832 | if ((err = parse_size_err(args[myidx], &curproxy->table.size))) { |
| 2833 | Alert("parsing [%s:%d] : stick-table: unexpected character '%c' in argument of '%s'.\n", |
| 2834 | file, linenum, *err, args[myidx-1]); |
| 2835 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2836 | goto out; |
| 2837 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 2838 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2839 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2840 | else if (strcmp(args[myidx], "peers") == 0) { |
| 2841 | myidx++; |
| 2842 | if (!*(args[myidx])) { |
| 2843 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 2844 | file, linenum, args[myidx-1]); |
| 2845 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2846 | goto out; |
| 2847 | } |
| 2848 | curproxy->table.peers.name = strdup(args[myidx++]); |
| 2849 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2850 | else if (strcmp(args[myidx], "expire") == 0) { |
| 2851 | myidx++; |
| 2852 | if (!*(args[myidx])) { |
| 2853 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 2854 | file, linenum, args[myidx-1]); |
| 2855 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2856 | goto out; |
| 2857 | } |
| 2858 | err = parse_time_err(args[myidx], &val, TIME_UNIT_MS); |
| 2859 | if (err) { |
| 2860 | Alert("parsing [%s:%d] : stick-table: unexpected character '%c' in argument of '%s'.\n", |
| 2861 | file, linenum, *err, args[myidx-1]); |
| 2862 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2863 | goto out; |
| 2864 | } |
| 2865 | curproxy->table.expire = val; |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 2866 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2867 | } |
| 2868 | else if (strcmp(args[myidx], "nopurge") == 0) { |
| 2869 | curproxy->table.nopurge = 1; |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 2870 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2871 | } |
| 2872 | else if (strcmp(args[myidx], "type") == 0) { |
| 2873 | myidx++; |
| 2874 | if (stktable_parse_type(args, &myidx, &curproxy->table.type, &curproxy->table.key_size) != 0) { |
| 2875 | Alert("parsing [%s:%d] : stick-table: unknown type '%s'.\n", |
| 2876 | file, linenum, args[myidx]); |
| 2877 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2878 | goto out; |
| 2879 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 2880 | /* myidx already points to next arg */ |
| 2881 | } |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 2882 | else if (strcmp(args[myidx], "store") == 0) { |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 2883 | int type, err; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 2884 | char *cw, *nw, *sa; |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 2885 | |
| 2886 | myidx++; |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 2887 | nw = args[myidx]; |
| 2888 | while (*nw) { |
| 2889 | /* the "store" keyword supports a comma-separated list */ |
| 2890 | cw = nw; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 2891 | sa = NULL; /* store arg */ |
| 2892 | while (*nw && *nw != ',') { |
| 2893 | if (*nw == '(') { |
| 2894 | *nw = 0; |
| 2895 | sa = ++nw; |
| 2896 | while (*nw != ')') { |
| 2897 | if (!*nw) { |
| 2898 | Alert("parsing [%s:%d] : %s: missing closing parenthesis after store option '%s'.\n", |
| 2899 | file, linenum, args[0], cw); |
| 2900 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2901 | goto out; |
| 2902 | } |
| 2903 | nw++; |
| 2904 | } |
| 2905 | *nw = '\0'; |
| 2906 | } |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 2907 | nw++; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 2908 | } |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 2909 | if (*nw) |
| 2910 | *nw++ = '\0'; |
| 2911 | type = stktable_get_data_type(cw); |
| 2912 | if (type < 0) { |
| 2913 | Alert("parsing [%s:%d] : %s: unknown store option '%s'.\n", |
| 2914 | file, linenum, args[0], cw); |
| 2915 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2916 | goto out; |
| 2917 | } |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 2918 | |
| 2919 | err = stktable_alloc_data_type(&curproxy->table, type, sa); |
| 2920 | switch (err) { |
| 2921 | case PE_NONE: break; |
| 2922 | case PE_EXIST: |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 2923 | Warning("parsing [%s:%d]: %s: store option '%s' already enabled, ignored.\n", |
| 2924 | file, linenum, args[0], cw); |
| 2925 | err_code |= ERR_WARN; |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 2926 | break; |
| 2927 | |
| 2928 | case PE_ARG_MISSING: |
| 2929 | Alert("parsing [%s:%d] : %s: missing argument to store option '%s'.\n", |
| 2930 | file, linenum, args[0], cw); |
| 2931 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2932 | goto out; |
| 2933 | |
| 2934 | case PE_ARG_NOT_USED: |
| 2935 | Alert("parsing [%s:%d] : %s: unexpected argument to store option '%s'.\n", |
| 2936 | file, linenum, args[0], cw); |
| 2937 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2938 | goto out; |
| 2939 | |
| 2940 | default: |
| 2941 | Alert("parsing [%s:%d] : %s: error when processing store option '%s'.\n", |
| 2942 | file, linenum, args[0], cw); |
| 2943 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2944 | goto out; |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 2945 | } |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 2946 | } |
| 2947 | myidx++; |
| 2948 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 2949 | else { |
| 2950 | Alert("parsing [%s:%d] : stick-table: unknown argument '%s'.\n", |
| 2951 | file, linenum, args[myidx]); |
| 2952 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2953 | goto out; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2954 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2955 | } |
| 2956 | |
| 2957 | if (!curproxy->table.size) { |
| 2958 | Alert("parsing [%s:%d] : stick-table: missing size.\n", |
| 2959 | file, linenum); |
| 2960 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2961 | goto out; |
| 2962 | } |
| 2963 | |
| 2964 | if (curproxy->table.type == (unsigned int)-1) { |
| 2965 | Alert("parsing [%s:%d] : stick-table: missing type.\n", |
| 2966 | file, linenum); |
| 2967 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2968 | goto out; |
| 2969 | } |
| 2970 | } |
| 2971 | else if (!strcmp(args[0], "stick")) { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2972 | struct sticking_rule *rule; |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 2973 | struct sample_expr *expr; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2974 | int myidx = 0; |
| 2975 | const char *name = NULL; |
| 2976 | int flags; |
| 2977 | |
| 2978 | if (curproxy == &defproxy) { |
| 2979 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2980 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2981 | goto out; |
| 2982 | } |
| 2983 | |
| 2984 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) { |
| 2985 | err_code |= ERR_WARN; |
| 2986 | goto out; |
| 2987 | } |
| 2988 | |
| 2989 | myidx++; |
| 2990 | if ((strcmp(args[myidx], "store") == 0) || |
| 2991 | (strcmp(args[myidx], "store-request") == 0)) { |
| 2992 | myidx++; |
| 2993 | flags = STK_IS_STORE; |
| 2994 | } |
| 2995 | else if (strcmp(args[myidx], "store-response") == 0) { |
| 2996 | myidx++; |
| 2997 | flags = STK_IS_STORE | STK_ON_RSP; |
| 2998 | } |
| 2999 | else if (strcmp(args[myidx], "match") == 0) { |
| 3000 | myidx++; |
| 3001 | flags = STK_IS_MATCH; |
| 3002 | } |
| 3003 | else if (strcmp(args[myidx], "on") == 0) { |
| 3004 | myidx++; |
| 3005 | flags = STK_IS_MATCH | STK_IS_STORE; |
| 3006 | } |
| 3007 | else { |
| 3008 | Alert("parsing [%s:%d] : '%s' expects 'on', 'match', or 'store'.\n", file, linenum, args[0]); |
| 3009 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3010 | goto out; |
| 3011 | } |
| 3012 | |
| 3013 | if (*(args[myidx]) == 0) { |
| 3014 | Alert("parsing [%s:%d] : '%s' expects a fetch method.\n", file, linenum, args[0]); |
| 3015 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3016 | goto out; |
| 3017 | } |
| 3018 | |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 3019 | expr = sample_parse_expr(args, &myidx, trash, sizeof(trash)); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3020 | if (!expr) { |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 3021 | Alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], trash); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3022 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3023 | goto out; |
| 3024 | } |
| 3025 | |
| 3026 | if (flags & STK_ON_RSP) { |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 3027 | if (!(expr->fetch->cap & SMP_CAP_RES)) { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3028 | Alert("parsing [%s:%d] : '%s': fetch method '%s' can not be used on response.\n", |
| 3029 | file, linenum, args[0], expr->fetch->kw); |
| 3030 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 3031 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3032 | goto out; |
| 3033 | } |
| 3034 | } else { |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 3035 | if (!(expr->fetch->cap & SMP_CAP_REQ)) { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3036 | Alert("parsing [%s:%d] : '%s': fetch method '%s' can not be used on request.\n", |
| 3037 | file, linenum, args[0], expr->fetch->kw); |
| 3038 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 3039 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3040 | goto out; |
| 3041 | } |
| 3042 | } |
| 3043 | |
| 3044 | if (strcmp(args[myidx], "table") == 0) { |
| 3045 | myidx++; |
| 3046 | name = args[myidx++]; |
| 3047 | } |
| 3048 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 3049 | if (strcmp(args[myidx], "if") == 0 || strcmp(args[myidx], "unless") == 0) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 3050 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + myidx, &errmsg)) == NULL) { |
| 3051 | Alert("parsing [%s:%d] : '%s': error detected while parsing sticking condition : %s.\n", |
| 3052 | file, linenum, args[0], errmsg); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3053 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 3054 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3055 | goto out; |
| 3056 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3057 | } |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 3058 | else if (*(args[myidx])) { |
| 3059 | Alert("parsing [%s:%d] : '%s': unknown keyword '%s'.\n", |
| 3060 | file, linenum, args[0], args[myidx]); |
| 3061 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 3062 | free(expr); |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 3063 | goto out; |
| 3064 | } |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 3065 | if (flags & STK_ON_RSP) |
| 3066 | err_code |= warnif_cond_requires_req(cond, file, linenum); |
| 3067 | else |
| 3068 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 3069 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3070 | rule = (struct sticking_rule *)calloc(1, sizeof(*rule)); |
| 3071 | rule->cond = cond; |
| 3072 | rule->expr = expr; |
| 3073 | rule->flags = flags; |
| 3074 | rule->table.name = name ? strdup(name) : NULL; |
| 3075 | LIST_INIT(&rule->list); |
| 3076 | if (flags & STK_ON_RSP) |
| 3077 | LIST_ADDQ(&curproxy->storersp_rules, &rule->list); |
| 3078 | else |
| 3079 | LIST_ADDQ(&curproxy->sticking_rules, &rule->list); |
| 3080 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3081 | else if (!strcmp(args[0], "stats")) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3082 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3083 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3084 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3085 | if (curproxy != &defproxy && curproxy->uri_auth == defproxy.uri_auth) |
| 3086 | curproxy->uri_auth = NULL; /* we must detach from the default config */ |
| 3087 | |
Krzysztof Piotr Oledzki | 260a3bb | 2010-01-06 16:25:05 +0100 | [diff] [blame] | 3088 | if (!*args[1]) { |
| 3089 | goto stats_error_parsing; |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3090 | } else if (!strcmp(args[1], "admin")) { |
| 3091 | struct stats_admin_rule *rule; |
| 3092 | |
| 3093 | if (curproxy == &defproxy) { |
| 3094 | Alert("parsing [%s:%d]: '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
| 3095 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3096 | goto out; |
| 3097 | } |
| 3098 | |
| 3099 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 3100 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3101 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3102 | goto out; |
| 3103 | } |
| 3104 | |
| 3105 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
| 3106 | Alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n", |
| 3107 | file, linenum, args[0], args[1]); |
| 3108 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3109 | goto out; |
| 3110 | } |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 3111 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 3112 | Alert("parsing [%s:%d] : error detected while parsing a '%s %s' rule : %s.\n", |
| 3113 | file, linenum, args[0], args[1], errmsg); |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3114 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3115 | goto out; |
| 3116 | } |
| 3117 | |
| 3118 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
| 3119 | |
| 3120 | rule = (struct stats_admin_rule *)calloc(1, sizeof(*rule)); |
| 3121 | rule->cond = cond; |
| 3122 | LIST_INIT(&rule->list); |
| 3123 | LIST_ADDQ(&curproxy->uri_auth->admin_rules, &rule->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3124 | } else if (!strcmp(args[1], "uri")) { |
| 3125 | if (*(args[2]) == 0) { |
| 3126 | Alert("parsing [%s:%d] : 'uri' needs an URI prefix.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3127 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3128 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3129 | } else if (!stats_set_uri(&curproxy->uri_auth, args[2])) { |
| 3130 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3131 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3132 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3133 | } |
| 3134 | } else if (!strcmp(args[1], "realm")) { |
| 3135 | if (*(args[2]) == 0) { |
| 3136 | Alert("parsing [%s:%d] : 'realm' needs an realm name.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3137 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3138 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3139 | } else if (!stats_set_realm(&curproxy->uri_auth, args[2])) { |
| 3140 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3141 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3142 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3143 | } |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 3144 | } else if (!strcmp(args[1], "refresh")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 3145 | unsigned interval; |
| 3146 | |
| 3147 | err = parse_time_err(args[2], &interval, TIME_UNIT_S); |
| 3148 | if (err) { |
| 3149 | Alert("parsing [%s:%d] : unexpected character '%c' in stats refresh interval.\n", |
| 3150 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3151 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3152 | goto out; |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 3153 | } else if (!stats_set_refresh(&curproxy->uri_auth, interval)) { |
| 3154 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3155 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3156 | goto out; |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 3157 | } |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3158 | } 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] | 3159 | struct http_req_rule *rule; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3160 | |
| 3161 | if (curproxy == &defproxy) { |
| 3162 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3163 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3164 | goto out; |
| 3165 | } |
| 3166 | |
| 3167 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 3168 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3169 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3170 | goto out; |
| 3171 | } |
| 3172 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3173 | if (!LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) && |
| 3174 | !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] | 3175 | Warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n", |
| 3176 | file, linenum, args[0]); |
| 3177 | err_code |= ERR_WARN; |
| 3178 | } |
| 3179 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3180 | 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] | 3181 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3182 | if (!rule) { |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3183 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3184 | goto out; |
| 3185 | } |
| 3186 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3187 | err_code |= warnif_cond_requires_resp(rule->cond, file, linenum); |
| 3188 | LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list); |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3189 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3190 | } else if (!strcmp(args[1], "auth")) { |
| 3191 | if (*(args[2]) == 0) { |
| 3192 | 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] | 3193 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3194 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3195 | } else if (!stats_add_auth(&curproxy->uri_auth, args[2])) { |
| 3196 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3197 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3198 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3199 | } |
| 3200 | } else if (!strcmp(args[1], "scope")) { |
| 3201 | if (*(args[2]) == 0) { |
| 3202 | Alert("parsing [%s:%d] : 'scope' needs a proxy name.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3203 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3204 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3205 | } else if (!stats_add_scope(&curproxy->uri_auth, args[2])) { |
| 3206 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3207 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3208 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3209 | } |
| 3210 | } else if (!strcmp(args[1], "enable")) { |
| 3211 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 3212 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3213 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3214 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3215 | } |
Krzysztof Oledzki | d9db927 | 2007-10-15 10:05:11 +0200 | [diff] [blame] | 3216 | } else if (!strcmp(args[1], "hide-version")) { |
| 3217 | if (!stats_set_flag(&curproxy->uri_auth, ST_HIDEVER)) { |
| 3218 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3219 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3220 | goto out; |
Krzysztof Oledzki | d9db927 | 2007-10-15 10:05:11 +0200 | [diff] [blame] | 3221 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3222 | } else if (!strcmp(args[1], "show-legends")) { |
| 3223 | if (!stats_set_flag(&curproxy->uri_auth, ST_SHLGNDS)) { |
| 3224 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3225 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3226 | goto out; |
| 3227 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3228 | } else if (!strcmp(args[1], "show-node")) { |
| 3229 | |
| 3230 | if (*args[2]) { |
| 3231 | int i; |
| 3232 | char c; |
| 3233 | |
| 3234 | for (i=0; args[2][i]; i++) { |
| 3235 | c = args[2][i]; |
Willy Tarreau | 88e0581 | 2010-03-03 00:16:00 +0100 | [diff] [blame] | 3236 | if (!isupper((unsigned char)c) && !islower((unsigned char)c) && |
| 3237 | !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.') |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3238 | break; |
| 3239 | } |
| 3240 | |
| 3241 | if (!i || args[2][i]) { |
| 3242 | Alert("parsing [%s:%d]: '%s %s' invalid node name - should be a string" |
| 3243 | "with digits(0-9), letters(A-Z, a-z), hyphen(-) or underscode(_).\n", |
| 3244 | file, linenum, args[0], args[1]); |
| 3245 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3246 | goto out; |
| 3247 | } |
| 3248 | } |
| 3249 | |
| 3250 | if (!stats_set_node(&curproxy->uri_auth, args[2])) { |
| 3251 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3252 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3253 | goto out; |
| 3254 | } |
| 3255 | } else if (!strcmp(args[1], "show-desc")) { |
| 3256 | char *desc = NULL; |
| 3257 | |
| 3258 | if (*args[2]) { |
| 3259 | int i, len=0; |
| 3260 | char *d; |
| 3261 | |
| 3262 | for(i=2; *args[i]; i++) |
| 3263 | len += strlen(args[i])+1; |
| 3264 | |
| 3265 | desc = d = (char *)calloc(1, len); |
| 3266 | |
| 3267 | d += sprintf(d, "%s", args[2]); |
| 3268 | for(i=3; *args[i]; i++) |
| 3269 | d += sprintf(d, " %s", args[i]); |
| 3270 | } |
| 3271 | |
| 3272 | if (!*args[2] && !global.desc) |
| 3273 | Warning("parsing [%s:%d]: '%s' requires a parameter or 'desc' to be set in the global section.\n", |
| 3274 | file, linenum, args[1]); |
| 3275 | else { |
| 3276 | if (!stats_set_desc(&curproxy->uri_auth, desc)) { |
| 3277 | free(desc); |
| 3278 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3279 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3280 | goto out; |
| 3281 | } |
| 3282 | free(desc); |
| 3283 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3284 | } else { |
Krzysztof Piotr Oledzki | 260a3bb | 2010-01-06 16:25:05 +0100 | [diff] [blame] | 3285 | stats_error_parsing: |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3286 | 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] | 3287 | 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] | 3288 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3289 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3290 | } |
| 3291 | } |
| 3292 | else if (!strcmp(args[0], "option")) { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3293 | int optnum; |
| 3294 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3295 | if (*(args[1]) == '\0') { |
| 3296 | Alert("parsing [%s:%d]: '%s' expects an option name.\n", |
| 3297 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3298 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3299 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3300 | } |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3301 | |
| 3302 | for (optnum = 0; cfg_opts[optnum].name; optnum++) { |
| 3303 | if (!strcmp(args[1], cfg_opts[optnum].name)) { |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 3304 | if (cfg_opts[optnum].cap == PR_CAP_NONE) { |
| 3305 | Alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n", |
| 3306 | file, linenum, cfg_opts[optnum].name); |
| 3307 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3308 | goto out; |
| 3309 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3310 | if (warnifnotcap(curproxy, cfg_opts[optnum].cap, file, linenum, args[1], NULL)) { |
| 3311 | err_code |= ERR_WARN; |
| 3312 | goto out; |
| 3313 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3314 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 3315 | curproxy->no_options &= ~cfg_opts[optnum].val; |
| 3316 | curproxy->options &= ~cfg_opts[optnum].val; |
| 3317 | |
| 3318 | switch (kwm) { |
| 3319 | case KWM_STD: |
| 3320 | curproxy->options |= cfg_opts[optnum].val; |
| 3321 | break; |
| 3322 | case KWM_NO: |
| 3323 | curproxy->no_options |= cfg_opts[optnum].val; |
| 3324 | break; |
| 3325 | case KWM_DEF: /* already cleared */ |
| 3326 | break; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 3327 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3328 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3329 | goto out; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3330 | } |
| 3331 | } |
| 3332 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 3333 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) { |
| 3334 | if (!strcmp(args[1], cfg_opts2[optnum].name)) { |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 3335 | if (cfg_opts2[optnum].cap == PR_CAP_NONE) { |
| 3336 | Alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n", |
| 3337 | file, linenum, cfg_opts2[optnum].name); |
| 3338 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3339 | goto out; |
| 3340 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3341 | if (warnifnotcap(curproxy, cfg_opts2[optnum].cap, file, linenum, args[1], NULL)) { |
| 3342 | err_code |= ERR_WARN; |
| 3343 | goto out; |
| 3344 | } |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 3345 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 3346 | curproxy->no_options2 &= ~cfg_opts2[optnum].val; |
| 3347 | curproxy->options2 &= ~cfg_opts2[optnum].val; |
| 3348 | |
| 3349 | switch (kwm) { |
| 3350 | case KWM_STD: |
| 3351 | curproxy->options2 |= cfg_opts2[optnum].val; |
| 3352 | break; |
| 3353 | case KWM_NO: |
| 3354 | curproxy->no_options2 |= cfg_opts2[optnum].val; |
| 3355 | break; |
| 3356 | case KWM_DEF: /* already cleared */ |
| 3357 | break; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 3358 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3359 | goto out; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 3360 | } |
| 3361 | } |
| 3362 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 3363 | if (kwm != KWM_STD) { |
| 3364 | 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] | 3365 | file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3366 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3367 | goto out; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3368 | } |
| 3369 | |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3370 | if (!strcmp(args[1], "httplog")) { |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 3371 | char *logformat; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3372 | /* generate a complete HTTP log */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 3373 | logformat = default_http_log_format; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3374 | if (*(args[2]) != '\0') { |
| 3375 | if (!strcmp(args[2], "clf")) { |
| 3376 | curproxy->options2 |= PR_O2_CLFLOG; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 3377 | logformat = clf_http_log_format; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3378 | } else { |
| 3379 | 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] | 3380 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3381 | goto out; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3382 | } |
| 3383 | } |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 3384 | parse_logformat_string(logformat, curproxy, &curproxy->logformat, curproxy->mode); |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3385 | } |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 3386 | else if (!strcmp(args[1], "tcplog")) { |
| 3387 | char *logformat; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3388 | /* generate a detailed TCP log */ |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 3389 | logformat = default_tcp_log_format; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 3390 | parse_logformat_string(logformat, curproxy, &curproxy->logformat, curproxy->mode); |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 3391 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3392 | else if (!strcmp(args[1], "tcpka")) { |
| 3393 | /* enable TCP keep-alives on client and server sessions */ |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3394 | 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] | 3395 | err_code |= ERR_WARN; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3396 | |
| 3397 | if (curproxy->cap & PR_CAP_FE) |
| 3398 | curproxy->options |= PR_O_TCP_CLI_KA; |
| 3399 | if (curproxy->cap & PR_CAP_BE) |
| 3400 | curproxy->options |= PR_O_TCP_SRV_KA; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3401 | } |
| 3402 | else if (!strcmp(args[1], "httpchk")) { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3403 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3404 | err_code |= ERR_WARN; |
| 3405 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3406 | /* use HTTP request to check servers' health */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3407 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 3408 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3409 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 3410 | curproxy->options2 |= PR_O2_HTTP_CHK; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3411 | if (!*args[2]) { /* no argument */ |
| 3412 | curproxy->check_req = strdup(DEF_CHECK_REQ); /* default request */ |
| 3413 | curproxy->check_len = strlen(DEF_CHECK_REQ); |
| 3414 | } else if (!*args[3]) { /* one argument : URI */ |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3415 | 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] | 3416 | curproxy->check_req = (char *)malloc(reqlen); |
| 3417 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3418 | "OPTIONS %s HTTP/1.0\r\n", args[2]); /* URI to use */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3419 | } else { /* more arguments : METHOD URI [HTTP_VER] */ |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3420 | int reqlen = strlen(args[2]) + strlen(args[3]) + 3 + strlen("\r\n"); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3421 | if (*args[4]) |
| 3422 | reqlen += strlen(args[4]); |
| 3423 | else |
| 3424 | reqlen += strlen("HTTP/1.0"); |
| 3425 | |
| 3426 | curproxy->check_req = (char *)malloc(reqlen); |
| 3427 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3428 | "%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] | 3429 | } |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 3430 | } |
| 3431 | else if (!strcmp(args[1], "ssl-hello-chk")) { |
| 3432 | /* use SSLv3 CLIENT HELLO to check servers' health */ |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3433 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3434 | err_code |= ERR_WARN; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3435 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3436 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 3437 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3438 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Willy Tarreau | 07a5490 | 2010-03-29 18:33:29 +0200 | [diff] [blame] | 3439 | curproxy->options2 |= PR_O2_SSL3_CHK; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3440 | } |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 3441 | else if (!strcmp(args[1], "smtpchk")) { |
| 3442 | /* use SMTP request to check servers' health */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3443 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 3444 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3445 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 3446 | curproxy->options2 |= PR_O2_SMTP_CHK; |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 3447 | |
| 3448 | if (!*args[2] || !*args[3]) { /* no argument or incomplete EHLO host */ |
| 3449 | curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */ |
| 3450 | curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ); |
| 3451 | } else { /* ESMTP EHLO, or SMTP HELO, and a hostname */ |
| 3452 | if (!strcmp(args[2], "EHLO") || !strcmp(args[2], "HELO")) { |
| 3453 | int reqlen = strlen(args[2]) + strlen(args[3]) + strlen(" \r\n") + 1; |
| 3454 | curproxy->check_req = (char *)malloc(reqlen); |
| 3455 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
| 3456 | "%s %s\r\n", args[2], args[3]); /* HELO hostname */ |
| 3457 | } else { |
| 3458 | /* this just hits the default for now, but you could potentially expand it to allow for other stuff |
| 3459 | though, it's unlikely you'd want to send anything other than an EHLO or HELO */ |
| 3460 | curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */ |
| 3461 | curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ); |
| 3462 | } |
| 3463 | } |
| 3464 | } |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 3465 | else if (!strcmp(args[1], "pgsql-check")) { |
| 3466 | /* use PostgreSQL request to check servers' health */ |
| 3467 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 3468 | err_code |= ERR_WARN; |
| 3469 | |
| 3470 | free(curproxy->check_req); |
| 3471 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3472 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 3473 | curproxy->options2 |= PR_O2_PGSQL_CHK; |
| 3474 | |
| 3475 | if (*(args[2])) { |
| 3476 | int cur_arg = 2; |
| 3477 | |
| 3478 | while (*(args[cur_arg])) { |
| 3479 | if (strcmp(args[cur_arg], "user") == 0) { |
| 3480 | char * packet; |
| 3481 | uint32_t packet_len; |
| 3482 | uint32_t pv; |
| 3483 | |
| 3484 | /* suboption header - needs additional argument for it */ |
| 3485 | if (*(args[cur_arg+1]) == 0) { |
| 3486 | Alert("parsing [%s:%d] : '%s %s %s' expects <username> as argument.\n", |
| 3487 | file, linenum, args[0], args[1], args[cur_arg]); |
| 3488 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3489 | goto out; |
| 3490 | } |
| 3491 | |
| 3492 | /* uint32_t + uint32_t + strlen("user")+1 + strlen(username)+1 + 1 */ |
| 3493 | packet_len = 4 + 4 + 5 + strlen(args[cur_arg + 1])+1 +1; |
| 3494 | pv = htonl(0x30000); /* protocol version 3.0 */ |
| 3495 | |
| 3496 | packet = (char*) calloc(1, packet_len); |
| 3497 | |
| 3498 | memcpy(packet + 4, &pv, 4); |
| 3499 | |
| 3500 | /* copy "user" */ |
| 3501 | memcpy(packet + 8, "user", 4); |
| 3502 | |
| 3503 | /* copy username */ |
| 3504 | memcpy(packet + 13, args[cur_arg+1], strlen(args[cur_arg+1])); |
| 3505 | |
| 3506 | free(curproxy->check_req); |
| 3507 | curproxy->check_req = packet; |
| 3508 | curproxy->check_len = packet_len; |
| 3509 | |
| 3510 | packet_len = htonl(packet_len); |
| 3511 | memcpy(packet, &packet_len, 4); |
| 3512 | cur_arg += 2; |
| 3513 | } else { |
| 3514 | /* unknown suboption - catchall */ |
| 3515 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'user'.\n", |
| 3516 | file, linenum, args[0], args[1]); |
| 3517 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3518 | goto out; |
| 3519 | } |
| 3520 | } /* end while loop */ |
| 3521 | } |
| 3522 | } |
| 3523 | |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 3524 | else if (!strcmp(args[1], "redis-check")) { |
| 3525 | /* use REDIS PING request to check servers' health */ |
| 3526 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 3527 | err_code |= ERR_WARN; |
| 3528 | |
| 3529 | free(curproxy->check_req); |
| 3530 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3531 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 3532 | curproxy->options2 |= PR_O2_REDIS_CHK; |
| 3533 | |
| 3534 | curproxy->check_req = (char *) malloc(sizeof(DEF_REDIS_CHECK_REQ) - 1); |
| 3535 | memcpy(curproxy->check_req, DEF_REDIS_CHECK_REQ, sizeof(DEF_REDIS_CHECK_REQ) - 1); |
| 3536 | curproxy->check_len = sizeof(DEF_REDIS_CHECK_REQ) - 1; |
| 3537 | } |
| 3538 | |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 3539 | else if (!strcmp(args[1], "mysql-check")) { |
| 3540 | /* use MYSQL request to check servers' health */ |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 3541 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 3542 | err_code |= ERR_WARN; |
| 3543 | |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 3544 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 3545 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3546 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 3547 | curproxy->options2 |= PR_O2_MYSQL_CHK; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 3548 | |
| 3549 | /* This is an exemple of an MySQL >=4.0 client Authentication packet kindly provided by Cyril Bonte. |
| 3550 | * const char mysql40_client_auth_pkt[] = { |
| 3551 | * "\x0e\x00\x00" // packet length |
| 3552 | * "\x01" // packet number |
| 3553 | * "\x00\x00" // client capabilities |
| 3554 | * "\x00\x00\x01" // max packet |
| 3555 | * "haproxy\x00" // username (null terminated string) |
| 3556 | * "\x00" // filler (always 0x00) |
| 3557 | * "\x01\x00\x00" // packet length |
| 3558 | * "\x00" // packet number |
| 3559 | * "\x01" // COM_QUIT command |
| 3560 | * }; |
| 3561 | */ |
| 3562 | |
| 3563 | if (*(args[2])) { |
| 3564 | int cur_arg = 2; |
| 3565 | |
| 3566 | while (*(args[cur_arg])) { |
| 3567 | if (strcmp(args[cur_arg], "user") == 0) { |
| 3568 | char *mysqluser; |
| 3569 | int packetlen, reqlen, userlen; |
| 3570 | |
| 3571 | /* suboption header - needs additional argument for it */ |
| 3572 | if (*(args[cur_arg+1]) == 0) { |
| 3573 | Alert("parsing [%s:%d] : '%s %s %s' expects <username> as argument.\n", |
| 3574 | file, linenum, args[0], args[1], args[cur_arg]); |
| 3575 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3576 | goto out; |
| 3577 | } |
| 3578 | mysqluser = args[cur_arg + 1]; |
| 3579 | userlen = strlen(mysqluser); |
| 3580 | packetlen = userlen + 7; |
| 3581 | reqlen = packetlen + 9; |
| 3582 | |
| 3583 | free(curproxy->check_req); |
| 3584 | curproxy->check_req = (char *)calloc(1, reqlen); |
| 3585 | curproxy->check_len = reqlen; |
| 3586 | |
| 3587 | snprintf(curproxy->check_req, 4, "%c%c%c", |
| 3588 | ((unsigned char) packetlen & 0xff), |
| 3589 | ((unsigned char) (packetlen >> 8) & 0xff), |
| 3590 | ((unsigned char) (packetlen >> 16) & 0xff)); |
| 3591 | |
| 3592 | curproxy->check_req[3] = 1; |
Hervé COMMOWICK | 212f778 | 2011-06-10 14:05:59 +0200 | [diff] [blame] | 3593 | curproxy->check_req[5] = 128; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 3594 | curproxy->check_req[8] = 1; |
| 3595 | memcpy(&curproxy->check_req[9], mysqluser, userlen); |
| 3596 | curproxy->check_req[9 + userlen + 1 + 1] = 1; |
| 3597 | curproxy->check_req[9 + userlen + 1 + 1 + 4] = 1; |
| 3598 | cur_arg += 2; |
| 3599 | } else { |
| 3600 | /* unknown suboption - catchall */ |
| 3601 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'user'.\n", |
| 3602 | file, linenum, args[0], args[1]); |
| 3603 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3604 | goto out; |
| 3605 | } |
| 3606 | } /* end while loop */ |
| 3607 | } |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 3608 | } |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 3609 | else if (!strcmp(args[1], "ldap-check")) { |
| 3610 | /* use LDAP request to check servers' health */ |
| 3611 | free(curproxy->check_req); |
| 3612 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3613 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 3614 | curproxy->options2 |= PR_O2_LDAP_CHK; |
| 3615 | |
| 3616 | curproxy->check_req = (char *) malloc(sizeof(DEF_LDAP_CHECK_REQ) - 1); |
| 3617 | memcpy(curproxy->check_req, DEF_LDAP_CHECK_REQ, sizeof(DEF_LDAP_CHECK_REQ) - 1); |
| 3618 | curproxy->check_len = sizeof(DEF_LDAP_CHECK_REQ) - 1; |
| 3619 | } |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3620 | else if (!strcmp(args[1], "forwardfor")) { |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3621 | int cur_arg; |
| 3622 | |
| 3623 | /* insert x-forwarded-for field, but not for the IP address listed as an except. |
| 3624 | * set default options (ie: bitfield, header name, etc) |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3625 | */ |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3626 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 3627 | curproxy->options |= PR_O_FWDFOR | PR_O_FF_ALWAYS; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3628 | |
| 3629 | free(curproxy->fwdfor_hdr_name); |
| 3630 | curproxy->fwdfor_hdr_name = strdup(DEF_XFORWARDFOR_HDR); |
| 3631 | curproxy->fwdfor_hdr_len = strlen(DEF_XFORWARDFOR_HDR); |
| 3632 | |
| 3633 | /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */ |
| 3634 | cur_arg = 2; |
| 3635 | while (*(args[cur_arg])) { |
| 3636 | if (!strcmp(args[cur_arg], "except")) { |
| 3637 | /* suboption except - needs additional argument for it */ |
| 3638 | if (!*(args[cur_arg+1]) || !str2net(args[cur_arg+1], &curproxy->except_net, &curproxy->except_mask)) { |
| 3639 | Alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n", |
| 3640 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3641 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3642 | goto out; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3643 | } |
| 3644 | /* flush useless bits */ |
| 3645 | curproxy->except_net.s_addr &= curproxy->except_mask.s_addr; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3646 | cur_arg += 2; |
| 3647 | } else if (!strcmp(args[cur_arg], "header")) { |
| 3648 | /* suboption header - needs additional argument for it */ |
| 3649 | if (*(args[cur_arg+1]) == 0) { |
| 3650 | Alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 3651 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3652 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3653 | goto out; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3654 | } |
| 3655 | free(curproxy->fwdfor_hdr_name); |
| 3656 | curproxy->fwdfor_hdr_name = strdup(args[cur_arg+1]); |
| 3657 | curproxy->fwdfor_hdr_len = strlen(curproxy->fwdfor_hdr_name); |
| 3658 | cur_arg += 2; |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 3659 | } else if (!strcmp(args[cur_arg], "if-none")) { |
| 3660 | curproxy->options &= ~PR_O_FF_ALWAYS; |
| 3661 | cur_arg += 1; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3662 | } else { |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3663 | /* unknown suboption - catchall */ |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 3664 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except', 'header' and 'if-none'.\n", |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3665 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3666 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3667 | goto out; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3668 | } |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3669 | } /* end while loop */ |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3670 | } |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 3671 | else if (!strcmp(args[1], "originalto")) { |
| 3672 | int cur_arg; |
| 3673 | |
| 3674 | /* insert x-original-to field, but not for the IP address listed as an except. |
| 3675 | * set default options (ie: bitfield, header name, etc) |
| 3676 | */ |
| 3677 | |
| 3678 | curproxy->options |= PR_O_ORGTO; |
| 3679 | |
| 3680 | free(curproxy->orgto_hdr_name); |
| 3681 | curproxy->orgto_hdr_name = strdup(DEF_XORIGINALTO_HDR); |
| 3682 | curproxy->orgto_hdr_len = strlen(DEF_XORIGINALTO_HDR); |
| 3683 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 3684 | /* loop to go through arguments - start at 2, since 0+1 = "option" "originalto" */ |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 3685 | cur_arg = 2; |
| 3686 | while (*(args[cur_arg])) { |
| 3687 | if (!strcmp(args[cur_arg], "except")) { |
| 3688 | /* suboption except - needs additional argument for it */ |
| 3689 | if (!*(args[cur_arg+1]) || !str2net(args[cur_arg+1], &curproxy->except_to, &curproxy->except_mask_to)) { |
| 3690 | Alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n", |
| 3691 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3692 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3693 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 3694 | } |
| 3695 | /* flush useless bits */ |
| 3696 | curproxy->except_to.s_addr &= curproxy->except_mask_to.s_addr; |
| 3697 | cur_arg += 2; |
| 3698 | } else if (!strcmp(args[cur_arg], "header")) { |
| 3699 | /* suboption header - needs additional argument for it */ |
| 3700 | if (*(args[cur_arg+1]) == 0) { |
| 3701 | Alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 3702 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3703 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3704 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 3705 | } |
| 3706 | free(curproxy->orgto_hdr_name); |
| 3707 | curproxy->orgto_hdr_name = strdup(args[cur_arg+1]); |
| 3708 | curproxy->orgto_hdr_len = strlen(curproxy->orgto_hdr_name); |
| 3709 | cur_arg += 2; |
| 3710 | } else { |
| 3711 | /* unknown suboption - catchall */ |
| 3712 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n", |
| 3713 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3714 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3715 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 3716 | } |
| 3717 | } /* end while loop */ |
| 3718 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3719 | else { |
| 3720 | Alert("parsing [%s:%d] : unknown option '%s'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3721 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3722 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3723 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3724 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3725 | } |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 3726 | else if (!strcmp(args[0], "default_backend")) { |
| 3727 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3728 | err_code |= ERR_WARN; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 3729 | |
| 3730 | if (*(args[1]) == 0) { |
| 3731 | 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] | 3732 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3733 | goto out; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 3734 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3735 | free(curproxy->defbe.name); |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 3736 | curproxy->defbe.name = strdup(args[1]); |
| 3737 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3738 | else if (!strcmp(args[0], "redispatch") || !strcmp(args[0], "redisp")) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3739 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3740 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3741 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3742 | Warning("parsing [%s:%d]: keyword '%s' is deprecated, please use 'option redispatch' instead.\n", |
| 3743 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3744 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3745 | /* enable reconnections to dispatch */ |
| 3746 | curproxy->options |= PR_O_REDISP; |
| 3747 | } |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 3748 | else if (!strcmp(args[0], "http-check")) { |
| 3749 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3750 | err_code |= ERR_WARN; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 3751 | |
| 3752 | if (strcmp(args[1], "disable-on-404") == 0) { |
| 3753 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 3754 | curproxy->options |= PR_O_DISABLE404; |
| 3755 | } |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 3756 | else if (strcmp(args[1], "send-state") == 0) { |
| 3757 | /* enable emission of the apparent state of a server in HTTP checks */ |
| 3758 | curproxy->options2 |= PR_O2_CHK_SNDST; |
| 3759 | } |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 3760 | else if (strcmp(args[1], "expect") == 0) { |
| 3761 | const char *ptr_arg; |
| 3762 | int cur_arg; |
| 3763 | |
| 3764 | if (curproxy->options2 & PR_O2_EXP_TYPE) { |
| 3765 | Alert("parsing [%s:%d] : '%s %s' already specified.\n", file, linenum, args[0], args[1]); |
| 3766 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3767 | goto out; |
| 3768 | } |
| 3769 | |
| 3770 | cur_arg = 2; |
| 3771 | /* consider exclamation marks, sole or at the beginning of a word */ |
| 3772 | while (*(ptr_arg = args[cur_arg])) { |
| 3773 | while (*ptr_arg == '!') { |
| 3774 | curproxy->options2 ^= PR_O2_EXP_INV; |
| 3775 | ptr_arg++; |
| 3776 | } |
| 3777 | if (*ptr_arg) |
| 3778 | break; |
| 3779 | cur_arg++; |
| 3780 | } |
| 3781 | /* now ptr_arg points to the beginning of a word past any possible |
| 3782 | * exclamation mark, and cur_arg is the argument which holds this word. |
| 3783 | */ |
| 3784 | if (strcmp(ptr_arg, "status") == 0) { |
| 3785 | if (!*(args[cur_arg + 1])) { |
| 3786 | Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 3787 | file, linenum, args[0], args[1], ptr_arg); |
| 3788 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3789 | goto out; |
| 3790 | } |
| 3791 | curproxy->options2 |= PR_O2_EXP_STS; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 3792 | free(curproxy->expect_str); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 3793 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
| 3794 | } |
| 3795 | else if (strcmp(ptr_arg, "string") == 0) { |
| 3796 | if (!*(args[cur_arg + 1])) { |
| 3797 | Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 3798 | file, linenum, args[0], args[1], ptr_arg); |
| 3799 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3800 | goto out; |
| 3801 | } |
| 3802 | curproxy->options2 |= PR_O2_EXP_STR; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 3803 | free(curproxy->expect_str); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 3804 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
| 3805 | } |
| 3806 | else if (strcmp(ptr_arg, "rstatus") == 0) { |
| 3807 | if (!*(args[cur_arg + 1])) { |
| 3808 | Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 3809 | file, linenum, args[0], args[1], ptr_arg); |
| 3810 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3811 | goto out; |
| 3812 | } |
| 3813 | curproxy->options2 |= PR_O2_EXP_RSTS; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 3814 | free(curproxy->expect_str); |
| 3815 | if (curproxy->expect_regex) regfree(curproxy->expect_regex); |
| 3816 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 3817 | curproxy->expect_regex = calloc(1, sizeof(regex_t)); |
| 3818 | if (regcomp(curproxy->expect_regex, args[cur_arg + 1], REG_EXTENDED) != 0) { |
| 3819 | Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s'.\n", |
| 3820 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1]); |
| 3821 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3822 | goto out; |
| 3823 | } |
| 3824 | } |
| 3825 | else if (strcmp(ptr_arg, "rstring") == 0) { |
| 3826 | if (!*(args[cur_arg + 1])) { |
| 3827 | Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 3828 | file, linenum, args[0], args[1], ptr_arg); |
| 3829 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3830 | goto out; |
| 3831 | } |
| 3832 | curproxy->options2 |= PR_O2_EXP_RSTR; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 3833 | free(curproxy->expect_str); |
| 3834 | if (curproxy->expect_regex) regfree(curproxy->expect_regex); |
| 3835 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 3836 | curproxy->expect_regex = calloc(1, sizeof(regex_t)); |
| 3837 | if (regcomp(curproxy->expect_regex, args[cur_arg + 1], REG_EXTENDED) != 0) { |
| 3838 | Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s'.\n", |
| 3839 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1]); |
| 3840 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3841 | goto out; |
| 3842 | } |
| 3843 | } |
| 3844 | else { |
| 3845 | Alert("parsing [%s:%d] : '%s %s' only supports [!] 'status', 'string', 'rstatus', 'rstring', found '%s'.\n", |
| 3846 | file, linenum, args[0], args[1], ptr_arg); |
| 3847 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3848 | goto out; |
| 3849 | } |
| 3850 | } |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 3851 | else { |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 3852 | Alert("parsing [%s:%d] : '%s' only supports 'disable-on-404', 'send-state', 'expect'.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3853 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3854 | goto out; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 3855 | } |
| 3856 | } |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3857 | else if (!strcmp(args[0], "monitor")) { |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3858 | if (curproxy == &defproxy) { |
| 3859 | 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] | 3860 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3861 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3862 | } |
| 3863 | |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3864 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3865 | err_code |= ERR_WARN; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3866 | |
| 3867 | if (strcmp(args[1], "fail") == 0) { |
| 3868 | /* add a condition to fail monitor requests */ |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 3869 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3870 | Alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n", |
| 3871 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3872 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3873 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3874 | } |
| 3875 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 3876 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 3877 | Alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition : %s.\n", |
| 3878 | file, linenum, args[0], args[1], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3879 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3880 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3881 | } |
| 3882 | LIST_ADDQ(&curproxy->mon_fail_cond, &cond->list); |
| 3883 | } |
| 3884 | else { |
| 3885 | 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] | 3886 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3887 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3888 | } |
| 3889 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3890 | #ifdef TPROXY |
| 3891 | else if (!strcmp(args[0], "transparent")) { |
| 3892 | /* enable transparent proxy connections */ |
| 3893 | curproxy->options |= PR_O_TRANSP; |
| 3894 | } |
| 3895 | #endif |
| 3896 | else if (!strcmp(args[0], "maxconn")) { /* maxconn */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3897 | 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] | 3898 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3899 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3900 | if (*(args[1]) == 0) { |
| 3901 | 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] | 3902 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3903 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3904 | } |
| 3905 | curproxy->maxconn = atol(args[1]); |
| 3906 | } |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 3907 | else if (!strcmp(args[0], "backlog")) { /* backlog */ |
| 3908 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3909 | err_code |= ERR_WARN; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 3910 | |
| 3911 | if (*(args[1]) == 0) { |
| 3912 | 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] | 3913 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3914 | goto out; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 3915 | } |
| 3916 | curproxy->backlog = atol(args[1]); |
| 3917 | } |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 3918 | else if (!strcmp(args[0], "fullconn")) { /* fullconn */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3919 | 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] | 3920 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3921 | |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 3922 | if (*(args[1]) == 0) { |
| 3923 | 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] | 3924 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3925 | goto out; |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 3926 | } |
| 3927 | curproxy->fullconn = atol(args[1]); |
| 3928 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3929 | else if (!strcmp(args[0], "grace")) { /* grace time (ms) */ |
| 3930 | if (*(args[1]) == 0) { |
| 3931 | 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] | 3932 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3933 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3934 | } |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 3935 | err = parse_time_err(args[1], &val, TIME_UNIT_MS); |
| 3936 | if (err) { |
| 3937 | Alert("parsing [%s:%d] : unexpected character '%c' in grace time.\n", |
| 3938 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3939 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3940 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 3941 | } |
| 3942 | curproxy->grace = val; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3943 | } |
| 3944 | else if (!strcmp(args[0], "dispatch")) { /* dispatch address */ |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 3945 | struct sockaddr_storage *sk; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3946 | if (curproxy == &defproxy) { |
| 3947 | 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] | 3948 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3949 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3950 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3951 | else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3952 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3953 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3954 | if (strchr(args[1], ':') == NULL) { |
| 3955 | 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] | 3956 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3957 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3958 | } |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 3959 | sk = str2sa(args[1]); |
| 3960 | if (!sk) { |
| 3961 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[1]); |
| 3962 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3963 | goto out; |
| 3964 | } |
| 3965 | curproxy->dispatch_addr = *sk; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3966 | curproxy->options |= PR_O_DISPATCH; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3967 | } |
| 3968 | else if (!strcmp(args[0], "balance")) { /* set balancing with optional algorithm */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3969 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3970 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3971 | |
Willy Tarreau | a93c74b | 2012-05-08 18:14:39 +0200 | [diff] [blame] | 3972 | if (backend_parse_balance((const char **)args + 1, &errmsg, curproxy) < 0) { |
| 3973 | Alert("parsing [%s:%d] : %s %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3974 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3975 | goto out; |
Willy Tarreau | 2fcb500 | 2007-05-08 13:35:26 +0200 | [diff] [blame] | 3976 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3977 | } |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 3978 | else if (!strcmp(args[0], "hash-type")) { /* set hashing method */ |
| 3979 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 3980 | err_code |= ERR_WARN; |
| 3981 | |
| 3982 | if (strcmp(args[1], "consistent") == 0) { /* use consistent hashing */ |
| 3983 | curproxy->lbprm.algo &= ~BE_LB_HASH_TYPE; |
| 3984 | curproxy->lbprm.algo |= BE_LB_HASH_CONS; |
| 3985 | } |
| 3986 | else if (strcmp(args[1], "map-based") == 0) { /* use map-based hashing */ |
| 3987 | curproxy->lbprm.algo &= ~BE_LB_HASH_TYPE; |
| 3988 | curproxy->lbprm.algo |= BE_LB_HASH_MAP; |
| 3989 | } |
Willy Tarreau | 798a39c | 2010-11-24 15:04:29 +0100 | [diff] [blame] | 3990 | else if (strcmp(args[1], "avalanche") == 0) { /* use full hash before map-based hashing */ |
| 3991 | curproxy->lbprm.algo &= ~BE_LB_HASH_TYPE; |
| 3992 | curproxy->lbprm.algo |= BE_LB_HASH_AVAL; |
| 3993 | } |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 3994 | else { |
Willy Tarreau | 798a39c | 2010-11-24 15:04:29 +0100 | [diff] [blame] | 3995 | 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] | 3996 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3997 | goto out; |
| 3998 | } |
| 3999 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4000 | 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] | 4001 | int cur_arg; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4002 | char *rport, *raddr; |
| 4003 | short realport = 0; |
| 4004 | int do_check = 0, defsrv = (*args[0] == 'd'); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4005 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4006 | if (!defsrv && curproxy == &defproxy) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4007 | 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] | 4008 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4009 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4010 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4011 | else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4012 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4013 | |
| 4014 | if (!*args[2]) { |
| 4015 | Alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n", |
| 4016 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4017 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4018 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4019 | } |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 4020 | |
| 4021 | err = invalid_char(args[1]); |
| 4022 | if (err) { |
| 4023 | Alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n", |
| 4024 | file, linenum, *err, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4025 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4026 | goto out; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 4027 | } |
| 4028 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4029 | if (!defsrv) { |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4030 | struct sockaddr_storage *sk; |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4031 | |
Krzysztof Piotr Oledzki | aff01ea | 2010-02-05 20:31:44 +0100 | [diff] [blame] | 4032 | if ((newsrv = (struct server *)calloc(1, sizeof(struct server))) == NULL) { |
| 4033 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 4034 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4035 | goto out; |
| 4036 | } |
| 4037 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4038 | /* the servers are linked backwards first */ |
| 4039 | newsrv->next = curproxy->srv; |
| 4040 | curproxy->srv = newsrv; |
| 4041 | newsrv->proxy = curproxy; |
| 4042 | newsrv->conf.file = file; |
| 4043 | newsrv->conf.line = linenum; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4044 | |
Simon Horman | af51495 | 2011-06-21 14:34:57 +0900 | [diff] [blame] | 4045 | LIST_INIT(&newsrv->actconns); |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4046 | LIST_INIT(&newsrv->pendconns); |
| 4047 | do_check = 0; |
| 4048 | newsrv->state = SRV_RUNNING; /* early server setup */ |
| 4049 | newsrv->last_change = now.tv_sec; |
| 4050 | newsrv->id = strdup(args[1]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4051 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4052 | /* several ways to check the port component : |
David du Colombier | 9842ff1 | 2011-03-17 10:40:28 +0100 | [diff] [blame] | 4053 | * - IP => port=+0, relative (IPv4 only) |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4054 | * - IP: => port=+0, relative |
| 4055 | * - IP:N => port=N, absolute |
| 4056 | * - IP:+N => port=+N, relative |
| 4057 | * - IP:-N => port=-N, relative |
| 4058 | */ |
| 4059 | raddr = strdup(args[2]); |
Willy Tarreau | fab5a43 | 2011-03-04 15:31:53 +0100 | [diff] [blame] | 4060 | rport = strrchr(raddr, ':'); |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4061 | if (rport) { |
| 4062 | *rport++ = 0; |
| 4063 | realport = atol(rport); |
| 4064 | if (!isdigit((unsigned char)*rport)) |
| 4065 | newsrv->state |= SRV_MAPPORTS; |
| 4066 | } else |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4067 | newsrv->state |= SRV_MAPPORTS; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4068 | |
Willy Tarreau | fab5a43 | 2011-03-04 15:31:53 +0100 | [diff] [blame] | 4069 | sk = str2ip(raddr); |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4070 | free(raddr); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4071 | if (!sk) { |
| 4072 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[2]); |
| 4073 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4074 | goto out; |
| 4075 | } |
| 4076 | newsrv->addr = *sk; |
Willy Tarreau | 26d8c59 | 2012-05-07 18:12:14 +0200 | [diff] [blame] | 4077 | newsrv->proto = protocol_by_family(newsrv->addr.ss_family); |
Willy Tarreau | d02394b | 2012-05-11 18:32:18 +0200 | [diff] [blame] | 4078 | newsrv->sock = &sock_raw; |
| 4079 | newsrv->sock_init_arg = NULL; |
Willy Tarreau | 26d8c59 | 2012-05-07 18:12:14 +0200 | [diff] [blame] | 4080 | |
| 4081 | if (!sk) { |
| 4082 | Alert("parsing [%s:%d] : Unknown protocol family %d '%s'\n", |
| 4083 | file, linenum, newsrv->addr.ss_family, args[2]); |
| 4084 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4085 | goto out; |
| 4086 | } |
Willy Tarreau | 86ad42c | 2011-08-27 12:29:07 +0200 | [diff] [blame] | 4087 | set_host_port(&newsrv->addr, realport); |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4088 | |
| 4089 | newsrv->check_port = curproxy->defsrv.check_port; |
| 4090 | newsrv->inter = curproxy->defsrv.inter; |
| 4091 | newsrv->fastinter = curproxy->defsrv.fastinter; |
| 4092 | newsrv->downinter = curproxy->defsrv.downinter; |
| 4093 | newsrv->rise = curproxy->defsrv.rise; |
| 4094 | newsrv->fall = curproxy->defsrv.fall; |
| 4095 | newsrv->maxqueue = curproxy->defsrv.maxqueue; |
| 4096 | newsrv->minconn = curproxy->defsrv.minconn; |
| 4097 | newsrv->maxconn = curproxy->defsrv.maxconn; |
| 4098 | newsrv->slowstart = curproxy->defsrv.slowstart; |
| 4099 | newsrv->onerror = curproxy->defsrv.onerror; |
| 4100 | newsrv->consecutive_errors_limit |
| 4101 | = curproxy->defsrv.consecutive_errors_limit; |
| 4102 | newsrv->uweight = newsrv->iweight |
| 4103 | = curproxy->defsrv.iweight; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4104 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4105 | newsrv->curfd = -1; /* no health-check in progress */ |
| 4106 | newsrv->health = newsrv->rise; /* up, but will fall down at first failure */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4107 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4108 | cur_arg = 3; |
| 4109 | } else { |
| 4110 | newsrv = &curproxy->defsrv; |
| 4111 | cur_arg = 1; |
| 4112 | } |
Willy Tarreau | 0f03c6f | 2007-03-25 20:46:19 +0200 | [diff] [blame] | 4113 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4114 | while (*args[cur_arg]) { |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4115 | if (!defsrv && !strcmp(args[cur_arg], "id")) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 4116 | struct eb32_node *node; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 4117 | |
| 4118 | if (!*args[cur_arg + 1]) { |
| 4119 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 4120 | file, linenum, args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4121 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4122 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 4123 | } |
| 4124 | |
| 4125 | newsrv->puid = atol(args[cur_arg + 1]); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 4126 | newsrv->conf.id.key = newsrv->puid; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 4127 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 4128 | if (newsrv->puid <= 0) { |
| 4129 | Alert("parsing [%s:%d]: custom id has to be > 0.\n", |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 4130 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4131 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4132 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 4133 | } |
| 4134 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 4135 | node = eb32_lookup(&curproxy->conf.used_server_id, newsrv->puid); |
| 4136 | if (node) { |
| 4137 | struct server *target = container_of(node, struct server, conf.id); |
| 4138 | Alert("parsing [%s:%d]: server %s reuses same custom id as server %s (declared at %s:%d).\n", |
| 4139 | file, linenum, newsrv->id, target->id, target->conf.file, target->conf.line); |
| 4140 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4141 | goto out; |
| 4142 | } |
| 4143 | eb32_insert(&curproxy->conf.used_server_id, &newsrv->conf.id); |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 4144 | cur_arg += 2; |
| 4145 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4146 | else if (!defsrv && !strcmp(args[cur_arg], "cookie")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4147 | newsrv->cookie = strdup(args[cur_arg + 1]); |
| 4148 | newsrv->cklen = strlen(args[cur_arg + 1]); |
| 4149 | cur_arg += 2; |
| 4150 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4151 | else if (!defsrv && !strcmp(args[cur_arg], "redir")) { |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 4152 | newsrv->rdr_pfx = strdup(args[cur_arg + 1]); |
| 4153 | newsrv->rdr_len = strlen(args[cur_arg + 1]); |
| 4154 | cur_arg += 2; |
| 4155 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4156 | else if (!strcmp(args[cur_arg], "rise")) { |
Krzysztof Piotr Oledzki | 08ff959 | 2009-09-27 16:17:31 +0200 | [diff] [blame] | 4157 | if (!*args[cur_arg + 1]) { |
| 4158 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 4159 | file, linenum, args[cur_arg]); |
| 4160 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4161 | goto out; |
| 4162 | } |
| 4163 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4164 | newsrv->rise = atol(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 08ff959 | 2009-09-27 16:17:31 +0200 | [diff] [blame] | 4165 | if (newsrv->rise <= 0) { |
| 4166 | Alert("parsing [%s:%d]: '%s' has to be > 0.\n", |
| 4167 | file, linenum, args[cur_arg]); |
| 4168 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4169 | goto out; |
| 4170 | } |
| 4171 | |
Willy Tarreau | 9683909 | 2010-03-29 10:02:24 +0200 | [diff] [blame] | 4172 | if (newsrv->health) |
| 4173 | newsrv->health = newsrv->rise; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4174 | cur_arg += 2; |
| 4175 | } |
| 4176 | else if (!strcmp(args[cur_arg], "fall")) { |
| 4177 | newsrv->fall = atol(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 08ff959 | 2009-09-27 16:17:31 +0200 | [diff] [blame] | 4178 | |
| 4179 | if (!*args[cur_arg + 1]) { |
| 4180 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 4181 | file, linenum, args[cur_arg]); |
| 4182 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4183 | goto out; |
| 4184 | } |
| 4185 | |
| 4186 | if (newsrv->fall <= 0) { |
| 4187 | Alert("parsing [%s:%d]: '%s' has to be > 0.\n", |
| 4188 | file, linenum, args[cur_arg]); |
| 4189 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4190 | goto out; |
| 4191 | } |
| 4192 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4193 | cur_arg += 2; |
| 4194 | } |
| 4195 | else if (!strcmp(args[cur_arg], "inter")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4196 | const char *err = parse_time_err(args[cur_arg + 1], &val, TIME_UNIT_MS); |
| 4197 | if (err) { |
| 4198 | Alert("parsing [%s:%d] : unexpected character '%c' in 'inter' argument of server %s.\n", |
| 4199 | file, linenum, *err, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4200 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4201 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4202 | } |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4203 | if (val <= 0) { |
| 4204 | Alert("parsing [%s:%d]: invalid value %d for argument '%s' of server %s.\n", |
| 4205 | file, linenum, val, args[cur_arg], newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4206 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4207 | goto out; |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4208 | } |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4209 | newsrv->inter = val; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4210 | cur_arg += 2; |
| 4211 | } |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 4212 | else if (!strcmp(args[cur_arg], "fastinter")) { |
| 4213 | const char *err = parse_time_err(args[cur_arg + 1], &val, TIME_UNIT_MS); |
| 4214 | if (err) { |
| 4215 | Alert("parsing [%s:%d]: unexpected character '%c' in 'fastinter' argument of server %s.\n", |
| 4216 | file, linenum, *err, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4217 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4218 | goto out; |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 4219 | } |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4220 | if (val <= 0) { |
| 4221 | Alert("parsing [%s:%d]: invalid value %d for argument '%s' of server %s.\n", |
| 4222 | file, linenum, val, args[cur_arg], newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4223 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4224 | goto out; |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4225 | } |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 4226 | newsrv->fastinter = val; |
| 4227 | cur_arg += 2; |
| 4228 | } |
| 4229 | else if (!strcmp(args[cur_arg], "downinter")) { |
| 4230 | const char *err = parse_time_err(args[cur_arg + 1], &val, TIME_UNIT_MS); |
| 4231 | if (err) { |
| 4232 | Alert("parsing [%s:%d]: unexpected character '%c' in 'downinter' argument of server %s.\n", |
| 4233 | file, linenum, *err, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4234 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4235 | goto out; |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 4236 | } |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4237 | if (val <= 0) { |
| 4238 | Alert("parsing [%s:%d]: invalid value %d for argument '%s' of server %s.\n", |
| 4239 | file, linenum, val, args[cur_arg], newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4240 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4241 | goto out; |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4242 | } |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 4243 | newsrv->downinter = val; |
| 4244 | cur_arg += 2; |
| 4245 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4246 | else if (!defsrv && !strcmp(args[cur_arg], "addr")) { |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4247 | struct sockaddr_storage *sk = str2sa(args[cur_arg + 1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4248 | if (!sk) { |
| 4249 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[cur_arg + 1]); |
| 4250 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4251 | goto out; |
| 4252 | } |
| 4253 | newsrv->check_addr = *sk; |
Willy Tarreau | 2ea3abb | 2007-03-25 16:45:16 +0200 | [diff] [blame] | 4254 | cur_arg += 2; |
| 4255 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4256 | else if (!strcmp(args[cur_arg], "port")) { |
| 4257 | newsrv->check_port = atol(args[cur_arg + 1]); |
| 4258 | cur_arg += 2; |
| 4259 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4260 | else if (!defsrv && !strcmp(args[cur_arg], "backup")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4261 | newsrv->state |= SRV_BACKUP; |
| 4262 | cur_arg ++; |
| 4263 | } |
Simon Horman | fa46168 | 2011-06-25 09:39:49 +0900 | [diff] [blame] | 4264 | else if (!defsrv && !strcmp(args[cur_arg], "non-stick")) { |
| 4265 | newsrv->state |= SRV_NON_STICK; |
| 4266 | cur_arg ++; |
| 4267 | } |
Willy Tarreau | 5ab04ec | 2011-03-20 10:32:26 +0100 | [diff] [blame] | 4268 | else if (!defsrv && !strcmp(args[cur_arg], "send-proxy")) { |
| 4269 | newsrv->state |= SRV_SEND_PROXY; |
| 4270 | cur_arg ++; |
| 4271 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4272 | else if (!strcmp(args[cur_arg], "weight")) { |
| 4273 | int w; |
| 4274 | w = atol(args[cur_arg + 1]); |
Willy Tarreau | 6704d67 | 2009-06-15 10:56:05 +0200 | [diff] [blame] | 4275 | if (w < 0 || w > 256) { |
| 4276 | 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] | 4277 | file, linenum, newsrv->id, w); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4278 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4279 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4280 | } |
Willy Tarreau | 975c50b | 2009-10-10 19:34:06 +0200 | [diff] [blame] | 4281 | newsrv->uweight = newsrv->iweight = w; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4282 | cur_arg += 2; |
| 4283 | } |
| 4284 | else if (!strcmp(args[cur_arg], "minconn")) { |
| 4285 | newsrv->minconn = atol(args[cur_arg + 1]); |
| 4286 | cur_arg += 2; |
| 4287 | } |
| 4288 | else if (!strcmp(args[cur_arg], "maxconn")) { |
| 4289 | newsrv->maxconn = atol(args[cur_arg + 1]); |
| 4290 | cur_arg += 2; |
| 4291 | } |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 4292 | else if (!strcmp(args[cur_arg], "maxqueue")) { |
| 4293 | newsrv->maxqueue = atol(args[cur_arg + 1]); |
| 4294 | cur_arg += 2; |
| 4295 | } |
Willy Tarreau | 9909fc1 | 2007-11-30 17:42:05 +0100 | [diff] [blame] | 4296 | else if (!strcmp(args[cur_arg], "slowstart")) { |
| 4297 | /* slowstart is stored in seconds */ |
Willy Tarreau | 3259e33 | 2007-12-03 01:51:45 +0100 | [diff] [blame] | 4298 | 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] | 4299 | if (err) { |
| 4300 | Alert("parsing [%s:%d] : unexpected character '%c' in 'slowstart' argument of server %s.\n", |
| 4301 | file, linenum, *err, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4302 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4303 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4304 | } |
Willy Tarreau | 4554bc1 | 2010-03-26 10:40:49 +0100 | [diff] [blame] | 4305 | if (val < 0) { |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4306 | Alert("parsing [%s:%d]: invalid value %d for argument '%s' of server %s.\n", |
| 4307 | file, linenum, val, args[cur_arg], newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4308 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4309 | goto out; |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4310 | } |
Willy Tarreau | 3259e33 | 2007-12-03 01:51:45 +0100 | [diff] [blame] | 4311 | newsrv->slowstart = (val + 999) / 1000; |
Willy Tarreau | 9909fc1 | 2007-11-30 17:42:05 +0100 | [diff] [blame] | 4312 | cur_arg += 2; |
| 4313 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4314 | else if (!defsrv && !strcmp(args[cur_arg], "track")) { |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4315 | |
| 4316 | if (!*args[cur_arg + 1]) { |
| 4317 | Alert("parsing [%s:%d]: 'track' expects [<proxy>/]<server> as argument.\n", |
| 4318 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4319 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4320 | goto out; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4321 | } |
| 4322 | |
| 4323 | newsrv->trackit = strdup(args[cur_arg + 1]); |
| 4324 | |
| 4325 | cur_arg += 2; |
| 4326 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4327 | else if (!defsrv && !strcmp(args[cur_arg], "check")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4328 | global.maxsock++; |
| 4329 | do_check = 1; |
| 4330 | cur_arg += 1; |
| 4331 | } |
Willy Tarreau | 9683909 | 2010-03-29 10:02:24 +0200 | [diff] [blame] | 4332 | else if (!defsrv && !strcmp(args[cur_arg], "disabled")) { |
| 4333 | newsrv->state |= SRV_MAINTAIN; |
| 4334 | newsrv->state &= ~SRV_RUNNING; |
| 4335 | newsrv->health = 0; |
| 4336 | cur_arg += 1; |
| 4337 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4338 | else if (!defsrv && !strcmp(args[cur_arg], "observe")) { |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 4339 | if (!strcmp(args[cur_arg + 1], "none")) |
| 4340 | newsrv->observe = HANA_OBS_NONE; |
| 4341 | else if (!strcmp(args[cur_arg + 1], "layer4")) |
| 4342 | newsrv->observe = HANA_OBS_LAYER4; |
| 4343 | else if (!strcmp(args[cur_arg + 1], "layer7")) { |
| 4344 | if (curproxy->mode != PR_MODE_HTTP) { |
| 4345 | Alert("parsing [%s:%d]: '%s' can only be used in http proxies.\n", |
| 4346 | file, linenum, args[cur_arg + 1]); |
| 4347 | err_code |= ERR_ALERT; |
| 4348 | } |
| 4349 | newsrv->observe = HANA_OBS_LAYER7; |
| 4350 | } |
| 4351 | else { |
| 4352 | Alert("parsing [%s:%d]: '%s' expects one of 'none', " |
Willy Tarreau | 53621e0 | 2010-10-22 14:53:40 +0200 | [diff] [blame] | 4353 | "'layer4', 'layer7' but got '%s'\n", |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 4354 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
| 4355 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4356 | goto out; |
| 4357 | } |
| 4358 | |
| 4359 | cur_arg += 2; |
| 4360 | } |
| 4361 | else if (!strcmp(args[cur_arg], "on-error")) { |
| 4362 | if (!strcmp(args[cur_arg + 1], "fastinter")) |
| 4363 | newsrv->onerror = HANA_ONERR_FASTINTER; |
| 4364 | else if (!strcmp(args[cur_arg + 1], "fail-check")) |
| 4365 | newsrv->onerror = HANA_ONERR_FAILCHK; |
| 4366 | else if (!strcmp(args[cur_arg + 1], "sudden-death")) |
| 4367 | newsrv->onerror = HANA_ONERR_SUDDTH; |
| 4368 | else if (!strcmp(args[cur_arg + 1], "mark-down")) |
| 4369 | newsrv->onerror = HANA_ONERR_MARKDWN; |
| 4370 | else { |
| 4371 | Alert("parsing [%s:%d]: '%s' expects one of 'fastinter', " |
Willy Tarreau | 53621e0 | 2010-10-22 14:53:40 +0200 | [diff] [blame] | 4372 | "'fail-check', 'sudden-death' or 'mark-down' but got '%s'\n", |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 4373 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
| 4374 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4375 | goto out; |
| 4376 | } |
| 4377 | |
| 4378 | cur_arg += 2; |
| 4379 | } |
Simon Horman | e0d1bfb | 2011-06-21 14:34:58 +0900 | [diff] [blame] | 4380 | else if (!strcmp(args[cur_arg], "on-marked-down")) { |
| 4381 | if (!strcmp(args[cur_arg + 1], "shutdown-sessions")) |
| 4382 | newsrv->onmarkeddown = HANA_ONMARKEDDOWN_SHUTDOWNSESSIONS; |
| 4383 | else { |
| 4384 | Alert("parsing [%s:%d]: '%s' expects 'shutdown-sessions' but got '%s'\n", |
| 4385 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
| 4386 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4387 | goto out; |
| 4388 | } |
| 4389 | |
| 4390 | cur_arg += 2; |
| 4391 | } |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 4392 | else if (!strcmp(args[cur_arg], "error-limit")) { |
| 4393 | if (!*args[cur_arg + 1]) { |
| 4394 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 4395 | file, linenum, args[cur_arg]); |
| 4396 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4397 | goto out; |
| 4398 | } |
| 4399 | |
| 4400 | newsrv->consecutive_errors_limit = atoi(args[cur_arg + 1]); |
| 4401 | |
| 4402 | if (newsrv->consecutive_errors_limit <= 0) { |
| 4403 | Alert("parsing [%s:%d]: %s has to be > 0.\n", |
| 4404 | file, linenum, args[cur_arg]); |
| 4405 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4406 | goto out; |
| 4407 | } |
Willy Tarreau | f53b25d | 2010-03-15 19:40:37 +0100 | [diff] [blame] | 4408 | cur_arg += 2; |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 4409 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4410 | 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] | 4411 | int port_low, port_high; |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4412 | struct sockaddr_storage *sk; |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4413 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4414 | if (!*args[cur_arg + 1]) { |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4415 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 4416 | 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] | 4417 | file, linenum, "source", "usesrc"); |
| 4418 | #else |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 4419 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>[-<port>]] as argument.\n", |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4420 | file, linenum, "source"); |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 4421 | #endif |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4422 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4423 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4424 | } |
| 4425 | newsrv->state |= SRV_BIND_SRC; |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4426 | sk = str2sa_range(args[cur_arg + 1], &port_low, &port_high); |
| 4427 | if (!sk) { |
| 4428 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[cur_arg + 1]); |
| 4429 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4430 | goto out; |
| 4431 | } |
| 4432 | newsrv->source_addr = *sk; |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 4433 | |
| 4434 | if (port_low != port_high) { |
| 4435 | int i; |
| 4436 | if (port_low <= 0 || port_low > 65535 || |
| 4437 | port_high <= 0 || port_high > 65535 || |
| 4438 | port_low > port_high) { |
| 4439 | Alert("parsing [%s:%d] : invalid source port range %d-%d.\n", |
| 4440 | file, linenum, port_low, port_high); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4441 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4442 | goto out; |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 4443 | } |
| 4444 | newsrv->sport_range = port_range_alloc_range(port_high - port_low + 1); |
| 4445 | for (i = 0; i < newsrv->sport_range->size; i++) |
| 4446 | newsrv->sport_range->ports[i] = port_low + i; |
| 4447 | } |
| 4448 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4449 | cur_arg += 2; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4450 | while (*(args[cur_arg])) { |
| 4451 | if (!strcmp(args[cur_arg], "usesrc")) { /* address to use outside */ |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4452 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) |
| 4453 | #if !defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4454 | if (newsrv->source_addr.sin_addr.s_addr == INADDR_ANY) { |
| 4455 | Alert("parsing [%s:%d] : '%s' requires an explicit '%s' address.\n", |
| 4456 | file, linenum, "usesrc", "source"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4457 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4458 | goto out; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4459 | } |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4460 | #endif |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4461 | if (!*args[cur_arg + 1]) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4462 | 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] | 4463 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4464 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4465 | goto out; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4466 | } |
| 4467 | if (!strcmp(args[cur_arg + 1], "client")) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4468 | newsrv->state &= ~SRV_TPROXY_MASK; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4469 | newsrv->state |= SRV_TPROXY_CLI; |
| 4470 | } else if (!strcmp(args[cur_arg + 1], "clientip")) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4471 | newsrv->state &= ~SRV_TPROXY_MASK; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4472 | newsrv->state |= SRV_TPROXY_CIP; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4473 | } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) { |
| 4474 | char *name, *end; |
| 4475 | |
| 4476 | name = args[cur_arg+1] + 7; |
| 4477 | while (isspace(*name)) |
| 4478 | name++; |
| 4479 | |
| 4480 | end = name; |
| 4481 | while (*end && !isspace(*end) && *end != ',' && *end != ')') |
| 4482 | end++; |
| 4483 | |
| 4484 | newsrv->state &= ~SRV_TPROXY_MASK; |
| 4485 | newsrv->state |= SRV_TPROXY_DYN; |
| 4486 | newsrv->bind_hdr_name = calloc(1, end - name + 1); |
| 4487 | newsrv->bind_hdr_len = end - name; |
| 4488 | memcpy(newsrv->bind_hdr_name, name, end - name); |
| 4489 | newsrv->bind_hdr_name[end-name] = '\0'; |
| 4490 | newsrv->bind_hdr_occ = -1; |
| 4491 | |
| 4492 | /* now look for an occurrence number */ |
| 4493 | while (isspace(*end)) |
| 4494 | end++; |
| 4495 | if (*end == ',') { |
| 4496 | end++; |
| 4497 | name = end; |
| 4498 | if (*end == '-') |
| 4499 | end++; |
| 4500 | while (isdigit(*end)) |
| 4501 | end++; |
| 4502 | newsrv->bind_hdr_occ = strl2ic(name, end-name); |
| 4503 | } |
| 4504 | |
| 4505 | if (newsrv->bind_hdr_occ < -MAX_HDR_HISTORY) { |
| 4506 | Alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative" |
| 4507 | " occurrences values smaller than %d.\n", |
| 4508 | file, linenum, MAX_HDR_HISTORY); |
| 4509 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4510 | goto out; |
| 4511 | } |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4512 | } else { |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4513 | struct sockaddr_storage *sk = str2sa(args[cur_arg + 1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4514 | if (!sk) { |
| 4515 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[cur_arg + 1]); |
| 4516 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4517 | goto out; |
| 4518 | } |
| 4519 | newsrv->tproxy_addr = *sk; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4520 | newsrv->state |= SRV_TPROXY_ADDR; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4521 | } |
| 4522 | global.last_checks |= LSTCHK_NETADM; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4523 | #if !defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4524 | global.last_checks |= LSTCHK_CTTPROXY; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4525 | #endif |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4526 | cur_arg += 2; |
| 4527 | continue; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4528 | #else /* no TPROXY support */ |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4529 | 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] | 4530 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4531 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4532 | goto out; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4533 | #endif /* defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) */ |
| 4534 | } /* "usesrc" */ |
| 4535 | |
| 4536 | if (!strcmp(args[cur_arg], "interface")) { /* specifically bind to this interface */ |
| 4537 | #ifdef SO_BINDTODEVICE |
| 4538 | if (!*args[cur_arg + 1]) { |
| 4539 | Alert("parsing [%s:%d] : '%s' : missing interface name.\n", |
| 4540 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4541 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4542 | goto out; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4543 | } |
| 4544 | if (newsrv->iface_name) |
| 4545 | free(newsrv->iface_name); |
| 4546 | |
| 4547 | newsrv->iface_name = strdup(args[cur_arg + 1]); |
| 4548 | newsrv->iface_len = strlen(newsrv->iface_name); |
| 4549 | global.last_checks |= LSTCHK_NETADM; |
| 4550 | #else |
| 4551 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 4552 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4553 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4554 | goto out; |
Willy Tarreau | 77074d5 | 2006-11-12 23:57:19 +0100 | [diff] [blame] | 4555 | #endif |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4556 | cur_arg += 2; |
| 4557 | continue; |
| 4558 | } |
| 4559 | /* this keyword in not an option of "source" */ |
| 4560 | break; |
| 4561 | } /* while */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4562 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4563 | 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] | 4564 | Alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n", |
| 4565 | file, linenum, "usesrc", "source"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4566 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4567 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 4568 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4569 | else { |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4570 | if (!defsrv) |
Simon Horman | e0d1bfb | 2011-06-21 14:34:58 +0900 | [diff] [blame] | 4571 | Alert("parsing [%s:%d] : server %s only supports options 'backup', 'cookie', 'redir', 'observer', 'on-error', 'on-marked-down', 'error-limit', 'check', 'disabled', 'track', 'id', 'inter', 'fastinter', 'downinter', 'rise', 'fall', 'addr', 'port', 'source', 'send-proxy', 'minconn', 'maxconn', 'maxqueue', 'slowstart' and 'weight'.\n", |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4572 | file, linenum, newsrv->id); |
| 4573 | else |
Krzysztof Piotr Oledzki | a9389b1 | 2010-01-05 16:44:17 +0100 | [diff] [blame] | 4574 | 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] | 4575 | file, linenum); |
| 4576 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4577 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4578 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4579 | } |
| 4580 | } |
| 4581 | |
| 4582 | if (do_check) { |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4583 | if (newsrv->trackit) { |
| 4584 | Alert("parsing [%s:%d]: unable to enable checks and tracking at the same time!\n", |
| 4585 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4586 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4587 | goto out; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4588 | } |
| 4589 | |
Willy Tarreau | 86ad42c | 2011-08-27 12:29:07 +0200 | [diff] [blame] | 4590 | /* try to get the port from check_addr if check_port not set */ |
| 4591 | if (!newsrv->check_port) |
| 4592 | newsrv->check_port = get_host_port(&newsrv->check_addr); |
Willy Tarreau | 0f03c6f | 2007-03-25 20:46:19 +0200 | [diff] [blame] | 4593 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4594 | if (!newsrv->check_port && !(newsrv->state & SRV_MAPPORTS)) |
| 4595 | newsrv->check_port = realport; /* by default */ |
| 4596 | if (!newsrv->check_port) { |
Willy Tarreau | ef00b50 | 2007-01-07 02:40:09 +0100 | [diff] [blame] | 4597 | /* not yet valid, because no port was set on |
| 4598 | * the server either. We'll check if we have |
| 4599 | * a known port on the first listener. |
| 4600 | */ |
Willy Tarreau | 86ad42c | 2011-08-27 12:29:07 +0200 | [diff] [blame] | 4601 | struct listener *l = curproxy->listen; |
| 4602 | while (l && !(newsrv->check_port = get_host_port(&l->addr))) |
| 4603 | l = l->next; |
Willy Tarreau | ef00b50 | 2007-01-07 02:40:09 +0100 | [diff] [blame] | 4604 | } |
| 4605 | if (!newsrv->check_port) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4606 | Alert("parsing [%s:%d] : server %s has neither service port nor check port. Check has been disabled.\n", |
| 4607 | file, linenum, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4608 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4609 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4610 | } |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 4611 | |
Cyril Bonté | c9f825f | 2010-03-17 18:56:31 +0100 | [diff] [blame] | 4612 | /* Allocate buffer for partial check results... */ |
Willy Tarreau | 43961d5 | 2010-10-04 20:39:20 +0200 | [diff] [blame] | 4613 | if ((newsrv->check_data = calloc(global.tune.chksize, sizeof(char))) == NULL) { |
Cyril Bonté | c9f825f | 2010-03-17 18:56:31 +0100 | [diff] [blame] | 4614 | Alert("parsing [%s:%d] : out of memory while allocating check buffer.\n", file, linenum); |
| 4615 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4616 | goto out; |
| 4617 | } |
| 4618 | |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 4619 | newsrv->check_status = HCHK_STATUS_INI; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4620 | newsrv->state |= SRV_CHECKED; |
| 4621 | } |
| 4622 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4623 | if (!defsrv) { |
| 4624 | if (newsrv->state & SRV_BACKUP) |
| 4625 | curproxy->srv_bck++; |
| 4626 | else |
| 4627 | curproxy->srv_act++; |
Willy Tarreau | b625a08 | 2007-11-26 01:15:43 +0100 | [diff] [blame] | 4628 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4629 | newsrv->prev_state = newsrv->state; |
| 4630 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 4631 | } |
| 4632 | |
| 4633 | else if (strcmp(args[0], "unique-id-format") == 0) { |
| 4634 | if (!*(args[1])) { |
| 4635 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 4636 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4637 | goto out; |
| 4638 | } |
| 4639 | parse_logformat_string(args[1], curproxy, &curproxy->format_unique_id, PR_MODE_HTTP); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4640 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 4641 | |
| 4642 | else if (strcmp(args[0], "unique-id-header") == 0) { |
| 4643 | if (!*(args[1])) { |
| 4644 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 4645 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4646 | goto out; |
| 4647 | } |
| 4648 | free(curproxy->header_unique_id); |
| 4649 | curproxy->header_unique_id = strdup(args[1]); |
| 4650 | } |
| 4651 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4652 | else if (strcmp(args[0], "log-format") == 0) { |
| 4653 | if (!*(args[1])) { |
| 4654 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 4655 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4656 | goto out; |
| 4657 | } |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 4658 | parse_logformat_string(args[1], curproxy, &curproxy->logformat, curproxy->mode); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4659 | } |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4660 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4661 | else if (!strcmp(args[0], "log") && kwm == KWM_NO) { |
| 4662 | /* delete previous herited or defined syslog servers */ |
| 4663 | struct logsrv *back; |
| 4664 | |
| 4665 | if (*(args[1]) != 0) { |
| 4666 | Alert("parsing [%s:%d]:%s : 'no log' does not expect arguments.\n", file, linenum, args[1]); |
| 4667 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4668 | goto out; |
| 4669 | } |
| 4670 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4671 | list_for_each_entry_safe(tmplogsrv, back, &curproxy->logsrvs, list) { |
| 4672 | LIST_DEL(&tmplogsrv->list); |
| 4673 | free(tmplogsrv); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4674 | } |
| 4675 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4676 | else if (!strcmp(args[0], "log")) { /* syslog server address */ |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4677 | struct logsrv *logsrv; |
| 4678 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4679 | if (*(args[1]) && *(args[2]) == 0 && !strcmp(args[1], "global")) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4680 | /* copy global.logrsvs linked list to the end of curproxy->logsrvs */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4681 | list_for_each_entry(tmplogsrv, &global.logsrvs, list) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4682 | struct logsrv *node = malloc(sizeof(struct logsrv)); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4683 | memcpy(node, tmplogsrv, sizeof(struct logsrv)); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4684 | LIST_INIT(&node->list); |
| 4685 | LIST_ADDQ(&curproxy->logsrvs, &node->list); |
| 4686 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4687 | } |
| 4688 | else if (*(args[1]) && *(args[2])) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4689 | |
| 4690 | logsrv = calloc(1, sizeof(struct logsrv)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4691 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4692 | logsrv->facility = get_log_facility(args[2]); |
| 4693 | if (logsrv->facility < 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4694 | Alert("parsing [%s:%d] : unknown log facility '%s'\n", file, linenum, args[2]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4695 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4696 | goto out; |
| 4697 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4698 | } |
| 4699 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4700 | logsrv->level = 7; /* max syslog level = debug */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4701 | if (*(args[3])) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4702 | logsrv->level = get_log_level(args[3]); |
| 4703 | if (logsrv->level < 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4704 | Alert("parsing [%s:%d] : unknown optional log level '%s'\n", file, linenum, args[3]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4705 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4706 | goto out; |
| 4707 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4708 | } |
| 4709 | } |
| 4710 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4711 | logsrv->minlvl = 0; /* limit syslog level to this level (emerg) */ |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 4712 | if (*(args[4])) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4713 | logsrv->minlvl = get_log_level(args[4]); |
| 4714 | if (logsrv->level < 0) { |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 4715 | Alert("parsing [%s:%d] : unknown optional minimum log level '%s'\n", file, linenum, args[4]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4716 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4717 | goto out; |
| 4718 | |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 4719 | } |
| 4720 | } |
| 4721 | |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 4722 | if (args[1][0] == '/') { |
David du Colombier | 11bcb6c | 2011-03-24 12:23:00 +0100 | [diff] [blame] | 4723 | struct sockaddr_storage *sk = (struct sockaddr_storage *)str2sun(args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4724 | if (!sk) { |
| 4725 | 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] | 4726 | args[1], (int)sizeof(((struct sockaddr_un *)sk)->sun_path) - 1); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4727 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4728 | goto out; |
| 4729 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4730 | logsrv->addr = *sk; |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 4731 | } else { |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4732 | struct sockaddr_storage *sk = str2sa(args[1]); |
David du Colombier | 11bcb6c | 2011-03-24 12:23:00 +0100 | [diff] [blame] | 4733 | if (!sk) { |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4734 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[1]); |
| 4735 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4736 | goto out; |
| 4737 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4738 | logsrv->addr = *sk; |
| 4739 | if (!get_host_port(&logsrv->addr)) |
| 4740 | set_host_port(&logsrv->addr, SYSLOG_PORT); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4741 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4742 | |
| 4743 | LIST_ADDQ(&curproxy->logsrvs, &logsrv->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4744 | } |
| 4745 | else { |
| 4746 | Alert("parsing [%s:%d] : 'log' expects either <address[:port]> and <facility> or 'global' as arguments.\n", |
| 4747 | file, linenum); |
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 | } |
| 4751 | } |
| 4752 | 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] | 4753 | int cur_arg; |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4754 | struct sockaddr_storage *sk; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4755 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4756 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4757 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4758 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4759 | if (!*args[1]) { |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4760 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optionally '%s' <addr>, and '%s' <name>.\n", |
| 4761 | file, linenum, "source", "usesrc", "interface"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4762 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4763 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4764 | } |
Willy Tarreau | 368480c | 2009-03-01 08:27:21 +0100 | [diff] [blame] | 4765 | |
| 4766 | /* we must first clear any optional default setting */ |
| 4767 | curproxy->options &= ~PR_O_TPXY_MASK; |
| 4768 | free(curproxy->iface_name); |
| 4769 | curproxy->iface_name = NULL; |
| 4770 | curproxy->iface_len = 0; |
| 4771 | |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4772 | sk = str2sa(args[1]); |
| 4773 | if (!sk) { |
| 4774 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[1]); |
| 4775 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4776 | goto out; |
| 4777 | } |
| 4778 | curproxy->source_addr = *sk; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4779 | curproxy->options |= PR_O_BIND_SRC; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4780 | |
| 4781 | cur_arg = 2; |
| 4782 | while (*(args[cur_arg])) { |
| 4783 | if (!strcmp(args[cur_arg], "usesrc")) { /* address to use outside */ |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4784 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) |
| 4785 | #if !defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4786 | if (curproxy->source_addr.sin_addr.s_addr == INADDR_ANY) { |
| 4787 | Alert("parsing [%s:%d] : '%s' requires an explicit 'source' address.\n", |
| 4788 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4789 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4790 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4791 | } |
| 4792 | #endif |
| 4793 | if (!*args[cur_arg + 1]) { |
| 4794 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n", |
| 4795 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4796 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4797 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4798 | } |
| 4799 | |
| 4800 | if (!strcmp(args[cur_arg + 1], "client")) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4801 | curproxy->options &= ~PR_O_TPXY_MASK; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4802 | curproxy->options |= PR_O_TPXY_CLI; |
| 4803 | } else if (!strcmp(args[cur_arg + 1], "clientip")) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4804 | curproxy->options &= ~PR_O_TPXY_MASK; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4805 | curproxy->options |= PR_O_TPXY_CIP; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4806 | } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) { |
| 4807 | char *name, *end; |
| 4808 | |
| 4809 | name = args[cur_arg+1] + 7; |
| 4810 | while (isspace(*name)) |
| 4811 | name++; |
| 4812 | |
| 4813 | end = name; |
| 4814 | while (*end && !isspace(*end) && *end != ',' && *end != ')') |
| 4815 | end++; |
| 4816 | |
| 4817 | curproxy->options &= ~PR_O_TPXY_MASK; |
| 4818 | curproxy->options |= PR_O_TPXY_DYN; |
| 4819 | curproxy->bind_hdr_name = calloc(1, end - name + 1); |
| 4820 | curproxy->bind_hdr_len = end - name; |
| 4821 | memcpy(curproxy->bind_hdr_name, name, end - name); |
| 4822 | curproxy->bind_hdr_name[end-name] = '\0'; |
| 4823 | curproxy->bind_hdr_occ = -1; |
| 4824 | |
| 4825 | /* now look for an occurrence number */ |
| 4826 | while (isspace(*end)) |
| 4827 | end++; |
| 4828 | if (*end == ',') { |
| 4829 | end++; |
| 4830 | name = end; |
| 4831 | if (*end == '-') |
| 4832 | end++; |
| 4833 | while (isdigit(*end)) |
| 4834 | end++; |
| 4835 | curproxy->bind_hdr_occ = strl2ic(name, end-name); |
| 4836 | } |
| 4837 | |
| 4838 | if (curproxy->bind_hdr_occ < -MAX_HDR_HISTORY) { |
| 4839 | Alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative" |
| 4840 | " occurrences values smaller than %d.\n", |
| 4841 | file, linenum, MAX_HDR_HISTORY); |
| 4842 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4843 | goto out; |
| 4844 | } |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4845 | } else { |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4846 | struct sockaddr_storage *sk = str2sa(args[cur_arg + 1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4847 | if (!sk) { |
| 4848 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[cur_arg + 1]); |
| 4849 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4850 | goto out; |
| 4851 | } |
| 4852 | curproxy->tproxy_addr = *sk; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4853 | curproxy->options |= PR_O_TPXY_ADDR; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4854 | } |
| 4855 | global.last_checks |= LSTCHK_NETADM; |
| 4856 | #if !defined(CONFIG_HAP_LINUX_TPROXY) |
| 4857 | global.last_checks |= LSTCHK_CTTPROXY; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4858 | #endif |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4859 | #else /* no TPROXY support */ |
| 4860 | 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] | 4861 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4862 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4863 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4864 | #endif |
| 4865 | cur_arg += 2; |
| 4866 | continue; |
Willy Tarreau | 77074d5 | 2006-11-12 23:57:19 +0100 | [diff] [blame] | 4867 | } |
| 4868 | |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4869 | if (!strcmp(args[cur_arg], "interface")) { /* specifically bind to this interface */ |
| 4870 | #ifdef SO_BINDTODEVICE |
| 4871 | if (!*args[cur_arg + 1]) { |
| 4872 | Alert("parsing [%s:%d] : '%s' : missing interface name.\n", |
| 4873 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4874 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4875 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4876 | } |
| 4877 | if (curproxy->iface_name) |
| 4878 | free(curproxy->iface_name); |
| 4879 | |
| 4880 | curproxy->iface_name = strdup(args[cur_arg + 1]); |
| 4881 | curproxy->iface_len = strlen(curproxy->iface_name); |
| 4882 | global.last_checks |= LSTCHK_NETADM; |
| 4883 | #else |
| 4884 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 4885 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4886 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4887 | goto out; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4888 | #endif |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4889 | cur_arg += 2; |
| 4890 | continue; |
| 4891 | } |
| 4892 | Alert("parsing [%s:%d] : '%s' only supports optional keywords '%s' and '%s'.\n", |
| 4893 | file, linenum, args[0], "inteface", "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4894 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4895 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 4896 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4897 | } |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 4898 | else if (!strcmp(args[0], "usesrc")) { /* address to use outside: needs "source" first */ |
| 4899 | Alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n", |
| 4900 | file, linenum, "usesrc", "source"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4901 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4902 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 4903 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4904 | 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] | 4905 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4906 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 4907 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4908 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4909 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4910 | } |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4911 | |
| 4912 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 4913 | SMP_OPT_DIR_REQ, ACT_REPLACE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4914 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4915 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4916 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4917 | } |
| 4918 | else if (!strcmp(args[0], "reqdel")) { /* delete request header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4919 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 4920 | SMP_OPT_DIR_REQ, ACT_REMOVE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4921 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4922 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4923 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4924 | } |
| 4925 | 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] | 4926 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 4927 | SMP_OPT_DIR_REQ, ACT_DENY, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4928 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4929 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4930 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4931 | } |
| 4932 | 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] | 4933 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 4934 | SMP_OPT_DIR_REQ, ACT_PASS, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4935 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4936 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4937 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4938 | } |
| 4939 | 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] | 4940 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 4941 | SMP_OPT_DIR_REQ, ACT_ALLOW, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4942 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4943 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4944 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4945 | } |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 4946 | 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] | 4947 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 4948 | SMP_OPT_DIR_REQ, ACT_TARPIT, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4949 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4950 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4951 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 4952 | } |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 4953 | 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] | 4954 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 4955 | SMP_OPT_DIR_REQ, ACT_SETBE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4956 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4957 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4958 | goto out; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 4959 | } |
| 4960 | 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] | 4961 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 4962 | SMP_OPT_DIR_REQ, ACT_SETBE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4963 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4964 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4965 | goto out; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 4966 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4967 | 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] | 4968 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4969 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 4970 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4971 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4972 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4973 | } |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4974 | |
| 4975 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 4976 | SMP_OPT_DIR_REQ, ACT_REPLACE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4977 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4978 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4979 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4980 | } |
| 4981 | 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] | 4982 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 4983 | SMP_OPT_DIR_REQ, ACT_REMOVE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4984 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4985 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4986 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4987 | } |
| 4988 | 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] | 4989 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 4990 | SMP_OPT_DIR_REQ, ACT_DENY, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4991 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4992 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4993 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4994 | } |
| 4995 | 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] | 4996 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 4997 | SMP_OPT_DIR_REQ, ACT_PASS, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4998 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4999 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5000 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5001 | } |
| 5002 | 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] | 5003 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5004 | SMP_OPT_DIR_REQ, ACT_ALLOW, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5005 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5006 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5007 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5008 | } |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 5009 | 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] | 5010 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5011 | SMP_OPT_DIR_REQ, ACT_TARPIT, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5012 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5013 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5014 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 5015 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5016 | else if (!strcmp(args[0], "reqadd")) { /* add request header */ |
Willy Tarreau | f4f0412 | 2010-01-28 18:10:50 +0100 | [diff] [blame] | 5017 | struct cond_wordlist *wl; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5018 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5019 | if (curproxy == &defproxy) { |
| 5020 | 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] | 5021 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5022 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5023 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5024 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5025 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5026 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5027 | if (*(args[1]) == 0) { |
| 5028 | 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] | 5029 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5030 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5031 | } |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5032 | |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 5033 | if ((strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0)) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 5034 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args+2, &errmsg)) == NULL) { |
| 5035 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 5036 | file, linenum, args[0], errmsg); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 5037 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5038 | goto out; |
| 5039 | } |
| 5040 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
| 5041 | } |
| 5042 | else if (*args[2]) { |
| 5043 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 5044 | file, linenum, args[0], args[2]); |
| 5045 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5046 | goto out; |
| 5047 | } |
| 5048 | |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5049 | wl = calloc(1, sizeof(*wl)); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 5050 | wl->cond = cond; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5051 | wl->s = strdup(args[1]); |
| 5052 | LIST_ADDQ(&curproxy->req_add, &wl->list); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 5053 | warnif_misplaced_reqadd(curproxy, file, linenum, args[0]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5054 | } |
| 5055 | 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] | 5056 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5057 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 5058 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5059 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5060 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5061 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5062 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5063 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5064 | SMP_OPT_DIR_RES, ACT_REPLACE, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5065 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5066 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5067 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5068 | } |
| 5069 | else if (!strcmp(args[0], "rspdel")) { /* delete response header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5070 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5071 | SMP_OPT_DIR_RES, ACT_REMOVE, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5072 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5073 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5074 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5075 | } |
| 5076 | else if (!strcmp(args[0], "rspdeny")) { /* block response header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5077 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5078 | SMP_OPT_DIR_RES, ACT_DENY, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5079 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5080 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5081 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5082 | } |
| 5083 | 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] | 5084 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5085 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 5086 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5087 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5088 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5089 | } |
| 5090 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5091 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5092 | SMP_OPT_DIR_RES, ACT_REPLACE, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5093 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5094 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5095 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5096 | } |
| 5097 | 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] | 5098 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5099 | SMP_OPT_DIR_RES, ACT_REMOVE, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5100 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5101 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5102 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5103 | } |
| 5104 | 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] | 5105 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5106 | SMP_OPT_DIR_RES, ACT_DENY, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5107 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5108 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5109 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5110 | } |
| 5111 | else if (!strcmp(args[0], "rspadd")) { /* add response header */ |
Willy Tarreau | f4f0412 | 2010-01-28 18:10:50 +0100 | [diff] [blame] | 5112 | struct cond_wordlist *wl; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5113 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5114 | if (curproxy == &defproxy) { |
| 5115 | 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] | 5116 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5117 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5118 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5119 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5120 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5121 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5122 | if (*(args[1]) == 0) { |
| 5123 | 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] | 5124 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5125 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5126 | } |
| 5127 | |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5128 | if ((strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0)) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 5129 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args+2, &errmsg)) == NULL) { |
| 5130 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 5131 | file, linenum, args[0], errmsg); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5132 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5133 | goto out; |
| 5134 | } |
| 5135 | err_code |= warnif_cond_requires_req(cond, file, linenum); |
| 5136 | } |
| 5137 | else if (*args[2]) { |
| 5138 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 5139 | file, linenum, args[0], args[2]); |
| 5140 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5141 | goto out; |
| 5142 | } |
| 5143 | |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5144 | wl = calloc(1, sizeof(*wl)); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5145 | wl->cond = cond; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5146 | wl->s = strdup(args[1]); |
| 5147 | LIST_ADDQ(&curproxy->rsp_add, &wl->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5148 | } |
| 5149 | else if (!strcmp(args[0], "errorloc") || |
| 5150 | !strcmp(args[0], "errorloc302") || |
| 5151 | !strcmp(args[0], "errorloc303")) { /* error location */ |
| 5152 | int errnum, errlen; |
| 5153 | char *err; |
| 5154 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5155 | 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] | 5156 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5157 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5158 | if (*(args[2]) == 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 5159 | 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] | 5160 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5161 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5162 | } |
| 5163 | |
| 5164 | errnum = atol(args[1]); |
| 5165 | if (!strcmp(args[0], "errorloc303")) { |
| 5166 | err = malloc(strlen(HTTP_303) + strlen(args[2]) + 5); |
| 5167 | errlen = sprintf(err, "%s%s\r\n\r\n", HTTP_303, args[2]); |
| 5168 | } else { |
| 5169 | err = malloc(strlen(HTTP_302) + strlen(args[2]) + 5); |
| 5170 | errlen = sprintf(err, "%s%s\r\n\r\n", HTTP_302, args[2]); |
| 5171 | } |
| 5172 | |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 5173 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) { |
| 5174 | if (http_err_codes[rc] == errnum) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 5175 | chunk_destroy(&curproxy->errmsg[rc]); |
| 5176 | chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 5177 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5178 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5179 | } |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 5180 | |
| 5181 | if (rc >= HTTP_ERR_SIZE) { |
| 5182 | Warning("parsing [%s:%d] : status code %d not handled, error relocation will be ignored.\n", |
| 5183 | file, linenum, errnum); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5184 | free(err); |
| 5185 | } |
| 5186 | } |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5187 | else if (!strcmp(args[0], "errorfile")) { /* error message from a file */ |
| 5188 | int errnum, errlen, fd; |
| 5189 | char *err; |
| 5190 | struct stat stat; |
| 5191 | |
| 5192 | 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] | 5193 | err_code |= ERR_WARN; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5194 | |
| 5195 | if (*(args[2]) == 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 5196 | 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] | 5197 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5198 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5199 | } |
| 5200 | |
| 5201 | fd = open(args[2], O_RDONLY); |
| 5202 | if ((fd < 0) || (fstat(fd, &stat) < 0)) { |
| 5203 | Alert("parsing [%s:%d] : error opening file <%s> for custom error message <%s>.\n", |
| 5204 | file, linenum, args[2], args[1]); |
| 5205 | if (fd >= 0) |
| 5206 | close(fd); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5207 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5208 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5209 | } |
| 5210 | |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 5211 | if (stat.st_size <= global.tune.bufsize) { |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5212 | errlen = stat.st_size; |
| 5213 | } else { |
| 5214 | 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] | 5215 | file, linenum, args[2], global.tune.bufsize); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5216 | err_code |= ERR_WARN; |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 5217 | errlen = global.tune.bufsize; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5218 | } |
| 5219 | |
| 5220 | err = malloc(errlen); /* malloc() must succeed during parsing */ |
| 5221 | errnum = read(fd, err, errlen); |
| 5222 | if (errnum != errlen) { |
| 5223 | Alert("parsing [%s:%d] : error reading file <%s> for custom error message <%s>.\n", |
| 5224 | file, linenum, args[2], args[1]); |
| 5225 | close(fd); |
| 5226 | free(err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5227 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5228 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5229 | } |
| 5230 | close(fd); |
| 5231 | |
| 5232 | errnum = atol(args[1]); |
| 5233 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) { |
| 5234 | if (http_err_codes[rc] == errnum) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 5235 | chunk_destroy(&curproxy->errmsg[rc]); |
| 5236 | chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen); |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5237 | break; |
| 5238 | } |
| 5239 | } |
| 5240 | |
| 5241 | if (rc >= HTTP_ERR_SIZE) { |
| 5242 | Warning("parsing [%s:%d] : status code %d not handled, error customization will be ignored.\n", |
| 5243 | file, linenum, errnum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5244 | err_code |= ERR_WARN; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5245 | free(err); |
| 5246 | } |
| 5247 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5248 | else { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 5249 | struct cfg_kw_list *kwl; |
| 5250 | int index; |
| 5251 | |
| 5252 | list_for_each_entry(kwl, &cfg_keywords.list, list) { |
| 5253 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 5254 | if (kwl->kw[index].section != CFG_LISTEN) |
| 5255 | continue; |
| 5256 | if (strcmp(kwl->kw[index].kw, args[0]) == 0) { |
| 5257 | /* prepare error message just in case */ |
| 5258 | snprintf(trash, sizeof(trash), |
| 5259 | "error near '%s' in %s section", args[0], cursection); |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 5260 | rc = kwl->kw[index].parse(args, CFG_LISTEN, curproxy, &defproxy, &errmsg); |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 5261 | if (rc < 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 5262 | Alert("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5263 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5264 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 5265 | } |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 5266 | else if (rc > 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 5267 | Warning("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5268 | err_code |= ERR_WARN; |
| 5269 | goto out; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 5270 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5271 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 5272 | } |
| 5273 | } |
| 5274 | } |
| 5275 | |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5276 | 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] | 5277 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5278 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5279 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5280 | out: |
Willy Tarreau | f4068b6 | 2012-05-08 17:37:49 +0200 | [diff] [blame] | 5281 | free(errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5282 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5283 | } |
| 5284 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5285 | int |
| 5286 | cfg_parse_users(const char *file, int linenum, char **args, int kwm) |
| 5287 | { |
| 5288 | |
| 5289 | int err_code = 0; |
| 5290 | const char *err; |
| 5291 | |
| 5292 | if (!strcmp(args[0], "userlist")) { /* new userlist */ |
| 5293 | struct userlist *newul; |
| 5294 | |
| 5295 | if (!*args[1]) { |
| 5296 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 5297 | file, linenum, args[0]); |
| 5298 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5299 | goto out; |
| 5300 | } |
| 5301 | |
| 5302 | err = invalid_char(args[1]); |
| 5303 | if (err) { |
| 5304 | Alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 5305 | file, linenum, *err, args[0], args[1]); |
| 5306 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5307 | goto out; |
| 5308 | } |
| 5309 | |
| 5310 | for (newul = userlist; newul; newul = newul->next) |
| 5311 | if (!strcmp(newul->name, args[1])) { |
| 5312 | Warning("parsing [%s:%d]: ignoring duplicated userlist '%s'.\n", |
| 5313 | file, linenum, args[1]); |
| 5314 | err_code |= ERR_WARN; |
| 5315 | goto out; |
| 5316 | } |
| 5317 | |
| 5318 | newul = (struct userlist *)calloc(1, sizeof(struct userlist)); |
| 5319 | if (!newul) { |
| 5320 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 5321 | err_code |= ERR_ALERT | ERR_ABORT; |
| 5322 | goto out; |
| 5323 | } |
| 5324 | |
| 5325 | newul->groupusers = calloc(MAX_AUTH_GROUPS, sizeof(char *)); |
| 5326 | newul->name = strdup(args[1]); |
| 5327 | |
| 5328 | if (!newul->groupusers | !newul->name) { |
| 5329 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 5330 | err_code |= ERR_ALERT | ERR_ABORT; |
| 5331 | goto out; |
| 5332 | } |
| 5333 | |
| 5334 | newul->next = userlist; |
| 5335 | userlist = newul; |
| 5336 | |
| 5337 | } else if (!strcmp(args[0], "group")) { /* new group */ |
| 5338 | int cur_arg, i; |
| 5339 | const char *err; |
| 5340 | |
| 5341 | if (!*args[1]) { |
| 5342 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 5343 | file, linenum, args[0]); |
| 5344 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5345 | goto out; |
| 5346 | } |
| 5347 | |
| 5348 | err = invalid_char(args[1]); |
| 5349 | if (err) { |
| 5350 | Alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 5351 | file, linenum, *err, args[0], args[1]); |
| 5352 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5353 | goto out; |
| 5354 | } |
| 5355 | |
| 5356 | for(i = 0; i < userlist->grpcnt; i++) |
| 5357 | if (!strcmp(userlist->groups[i], args[1])) { |
| 5358 | Warning("parsing [%s:%d]: ignoring duplicated group '%s' in userlist '%s'.\n", |
| 5359 | file, linenum, args[1], userlist->name); |
| 5360 | err_code |= ERR_ALERT; |
| 5361 | goto out; |
| 5362 | } |
| 5363 | |
| 5364 | if (userlist->grpcnt >= MAX_AUTH_GROUPS) { |
| 5365 | Alert("parsing [%s:%d]: too many groups (%u) in in userlist '%s' while adding group '%s'.\n", |
| 5366 | file, linenum, MAX_AUTH_GROUPS, userlist->name, args[1]); |
| 5367 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5368 | goto out; |
| 5369 | } |
| 5370 | |
| 5371 | cur_arg = 2; |
| 5372 | |
| 5373 | while (*args[cur_arg]) { |
| 5374 | if (!strcmp(args[cur_arg], "users")) { |
| 5375 | userlist->groupusers[userlist->grpcnt] = strdup(args[cur_arg + 1]); |
| 5376 | cur_arg += 2; |
| 5377 | continue; |
| 5378 | } else { |
| 5379 | Alert("parsing [%s:%d]: '%s' only supports 'users' option.\n", |
| 5380 | file, linenum, args[0]); |
| 5381 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5382 | goto out; |
| 5383 | } |
| 5384 | } |
| 5385 | |
| 5386 | userlist->groups[userlist->grpcnt++] = strdup(args[1]); |
| 5387 | } else if (!strcmp(args[0], "user")) { /* new user */ |
| 5388 | struct auth_users *newuser; |
| 5389 | int cur_arg; |
| 5390 | |
| 5391 | if (!*args[1]) { |
| 5392 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 5393 | file, linenum, args[0]); |
| 5394 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5395 | goto out; |
| 5396 | } |
| 5397 | |
| 5398 | for (newuser = userlist->users; newuser; newuser = newuser->next) |
| 5399 | if (!strcmp(newuser->user, args[1])) { |
| 5400 | Warning("parsing [%s:%d]: ignoring duplicated user '%s' in userlist '%s'.\n", |
| 5401 | file, linenum, args[1], userlist->name); |
| 5402 | err_code |= ERR_ALERT; |
| 5403 | goto out; |
| 5404 | } |
| 5405 | |
| 5406 | newuser = (struct auth_users *)calloc(1, sizeof(struct auth_users)); |
| 5407 | if (!newuser) { |
| 5408 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 5409 | err_code |= ERR_ALERT | ERR_ABORT; |
| 5410 | goto out; |
| 5411 | } |
| 5412 | |
| 5413 | newuser->user = strdup(args[1]); |
| 5414 | |
| 5415 | newuser->next = userlist->users; |
| 5416 | userlist->users = newuser; |
| 5417 | |
| 5418 | cur_arg = 2; |
| 5419 | |
| 5420 | while (*args[cur_arg]) { |
| 5421 | if (!strcmp(args[cur_arg], "password")) { |
| 5422 | #ifndef CONFIG_HAP_CRYPT |
| 5423 | Warning("parsing [%s:%d]: no crypt(3) support compiled, encrypted passwords will not work.\n", |
| 5424 | file, linenum); |
| 5425 | err_code |= ERR_ALERT; |
| 5426 | #endif |
| 5427 | newuser->pass = strdup(args[cur_arg + 1]); |
| 5428 | cur_arg += 2; |
| 5429 | continue; |
| 5430 | } else if (!strcmp(args[cur_arg], "insecure-password")) { |
| 5431 | newuser->pass = strdup(args[cur_arg + 1]); |
| 5432 | newuser->flags |= AU_O_INSECURE; |
| 5433 | cur_arg += 2; |
| 5434 | continue; |
| 5435 | } else if (!strcmp(args[cur_arg], "groups")) { |
Willy Tarreau | b4c06b7 | 2010-02-02 11:28:20 +0100 | [diff] [blame] | 5436 | newuser->u.groups = strdup(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5437 | cur_arg += 2; |
| 5438 | continue; |
| 5439 | } else { |
| 5440 | Alert("parsing [%s:%d]: '%s' only supports 'password', 'insecure-password' and 'groups' options.\n", |
| 5441 | file, linenum, args[0]); |
| 5442 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5443 | goto out; |
| 5444 | } |
| 5445 | } |
| 5446 | } else { |
| 5447 | Alert("parsing [%s:%d]: unknown keyword '%s' in '%s' section\n", file, linenum, args[0], "users"); |
| 5448 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5449 | } |
| 5450 | |
| 5451 | out: |
| 5452 | return err_code; |
| 5453 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5454 | |
| 5455 | /* |
| 5456 | * This function reads and parses the configuration file given in the argument. |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5457 | * Returns the error code, 0 if OK, or any combination of : |
| 5458 | * - ERR_ABORT: must abort ASAP |
| 5459 | * - ERR_FATAL: we can continue parsing but not start the service |
| 5460 | * - ERR_WARN: a warning has been emitted |
| 5461 | * - ERR_ALERT: an alert has been emitted |
| 5462 | * Only the two first ones can stop processing, the two others are just |
| 5463 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5464 | */ |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 5465 | int readcfgfile(const char *file) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5466 | { |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5467 | char thisline[LINESIZE]; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5468 | FILE *f; |
| 5469 | int linenum = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5470 | int confsect = CFG_NONE; |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5471 | int err_code = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5472 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5473 | if ((f=fopen(file,"r")) == NULL) |
| 5474 | return -1; |
| 5475 | |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5476 | while (fgets(thisline, sizeof(thisline), f) != NULL) { |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 5477 | int arg, kwm = KWM_STD; |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5478 | char *end; |
| 5479 | char *args[MAX_LINE_ARGS + 1]; |
| 5480 | char *line = thisline; |
| 5481 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5482 | linenum++; |
| 5483 | |
| 5484 | end = line + strlen(line); |
| 5485 | |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5486 | if (end-line == sizeof(thisline)-1 && *(end-1) != '\n') { |
| 5487 | /* Check if we reached the limit and the last char is not \n. |
| 5488 | * Watch out for the last line without the terminating '\n'! |
| 5489 | */ |
| 5490 | Alert("parsing [%s:%d]: line too long, limit: %d.\n", |
Willy Tarreau | 5e4a6f1 | 2009-04-11 19:42:49 +0200 | [diff] [blame] | 5491 | file, linenum, (int)sizeof(thisline)-1); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5492 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5493 | } |
| 5494 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5495 | /* skip leading spaces */ |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 5496 | while (isspace((unsigned char)*line)) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5497 | line++; |
| 5498 | |
| 5499 | arg = 0; |
| 5500 | args[arg] = line; |
| 5501 | |
| 5502 | while (*line && arg < MAX_LINE_ARGS) { |
| 5503 | /* first, we'll replace \\, \<space>, \#, \r, \n, \t, \xXX with their |
| 5504 | * C equivalent value. Other combinations left unchanged (eg: \1). |
| 5505 | */ |
| 5506 | if (*line == '\\') { |
| 5507 | int skip = 0; |
| 5508 | if (line[1] == ' ' || line[1] == '\\' || line[1] == '#') { |
| 5509 | *line = line[1]; |
| 5510 | skip = 1; |
| 5511 | } |
| 5512 | else if (line[1] == 'r') { |
| 5513 | *line = '\r'; |
| 5514 | skip = 1; |
| 5515 | } |
| 5516 | else if (line[1] == 'n') { |
| 5517 | *line = '\n'; |
| 5518 | skip = 1; |
| 5519 | } |
| 5520 | else if (line[1] == 't') { |
| 5521 | *line = '\t'; |
| 5522 | skip = 1; |
| 5523 | } |
| 5524 | else if (line[1] == 'x') { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5525 | if ((line + 3 < end) && ishex(line[2]) && ishex(line[3])) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5526 | unsigned char hex1, hex2; |
| 5527 | hex1 = toupper(line[2]) - '0'; |
| 5528 | hex2 = toupper(line[3]) - '0'; |
| 5529 | if (hex1 > 9) hex1 -= 'A' - '9' - 1; |
| 5530 | if (hex2 > 9) hex2 -= 'A' - '9' - 1; |
| 5531 | *line = (hex1<<4) + hex2; |
| 5532 | skip = 3; |
| 5533 | } |
| 5534 | else { |
| 5535 | 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] | 5536 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5537 | } |
| 5538 | } |
| 5539 | if (skip) { |
Cyril Bonté | dd1b01d | 2009-12-06 13:43:42 +0100 | [diff] [blame] | 5540 | memmove(line + 1, line + 1 + skip, end - (line + skip)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5541 | end -= skip; |
| 5542 | } |
| 5543 | line++; |
| 5544 | } |
| 5545 | else if (*line == '#' || *line == '\n' || *line == '\r') { |
| 5546 | /* end of string, end of loop */ |
| 5547 | *line = 0; |
| 5548 | break; |
| 5549 | } |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 5550 | else if (isspace((unsigned char)*line)) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5551 | /* a non-escaped space is an argument separator */ |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5552 | *line++ = '\0'; |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 5553 | while (isspace((unsigned char)*line)) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5554 | line++; |
| 5555 | args[++arg] = line; |
| 5556 | } |
| 5557 | else { |
| 5558 | line++; |
| 5559 | } |
| 5560 | } |
| 5561 | |
| 5562 | /* empty line */ |
| 5563 | if (!**args) |
| 5564 | continue; |
| 5565 | |
Willy Tarreau | 7bb651e | 2009-11-09 21:16:53 +0100 | [diff] [blame] | 5566 | if (*line) { |
| 5567 | /* we had to stop due to too many args. |
| 5568 | * Let's terminate the string, print the offending part then cut the |
| 5569 | * last arg. |
| 5570 | */ |
| 5571 | while (*line && *line != '#' && *line != '\n' && *line != '\r') |
| 5572 | line++; |
| 5573 | *line = '\0'; |
| 5574 | |
Krzysztof Piotr Oledzki | 500b8f0 | 2009-12-15 22:34:51 +0100 | [diff] [blame] | 5575 | 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] | 5576 | file, linenum, arg + 1, (long)(args[arg] - thisline + 1), args[arg]); |
Willy Tarreau | 7bb651e | 2009-11-09 21:16:53 +0100 | [diff] [blame] | 5577 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5578 | args[arg] = line; |
| 5579 | } |
| 5580 | |
Willy Tarreau | 540abe4 | 2007-05-02 20:50:16 +0200 | [diff] [blame] | 5581 | /* zero out remaining args and ensure that at least one entry |
| 5582 | * is zeroed out. |
| 5583 | */ |
| 5584 | while (++arg <= MAX_LINE_ARGS) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5585 | args[arg] = line; |
| 5586 | } |
| 5587 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 5588 | /* check for keyword modifiers "no" and "default" */ |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5589 | if (!strcmp(args[0], "no")) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5590 | char *tmp; |
| 5591 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 5592 | kwm = KWM_NO; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5593 | tmp = args[0]; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5594 | for (arg=0; *args[arg+1]; arg++) |
| 5595 | args[arg] = args[arg+1]; // shift args after inversion |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5596 | *tmp = '\0'; // fix the next arg to \0 |
| 5597 | args[arg] = tmp; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5598 | } |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 5599 | else if (!strcmp(args[0], "default")) { |
| 5600 | kwm = KWM_DEF; |
| 5601 | for (arg=0; *args[arg+1]; arg++) |
| 5602 | args[arg] = args[arg+1]; // shift args after inversion |
| 5603 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5604 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5605 | if (kwm != KWM_STD && strcmp(args[0], "option") != 0 && \ |
| 5606 | strcmp(args[0], "log") != 0) { |
| 5607 | Alert("parsing [%s:%d]: negation/default currently supported only for options and log.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5608 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5609 | } |
| 5610 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5611 | if (!strcmp(args[0], "listen") || |
| 5612 | !strcmp(args[0], "frontend") || |
| 5613 | !strcmp(args[0], "backend") || |
| 5614 | !strcmp(args[0], "ruleset") || |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5615 | !strcmp(args[0], "defaults")) { /* new proxy */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5616 | confsect = CFG_LISTEN; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 5617 | free(cursection); |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5618 | cursection = strdup(args[0]); |
| 5619 | } |
| 5620 | else if (!strcmp(args[0], "global")) { /* global config */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5621 | confsect = CFG_GLOBAL; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 5622 | free(cursection); |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5623 | cursection = strdup(args[0]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 5624 | } |
| 5625 | else if (!strcmp(args[0], "userlist")) { |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5626 | confsect = CFG_USERLIST; |
| 5627 | free(cursection); |
| 5628 | cursection = strdup(args[0]); |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5629 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 5630 | else if (!strcmp(args[0], "peers")) { |
| 5631 | confsect = CFG_PEERS; |
| 5632 | free(cursection); |
| 5633 | cursection = strdup(args[0]); |
| 5634 | } |
| 5635 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5636 | /* else it's a section keyword */ |
| 5637 | |
| 5638 | switch (confsect) { |
| 5639 | case CFG_LISTEN: |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5640 | err_code |= cfg_parse_listen(file, linenum, args, kwm); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5641 | break; |
| 5642 | case CFG_GLOBAL: |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5643 | err_code |= cfg_parse_global(file, linenum, args, kwm); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5644 | break; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5645 | case CFG_USERLIST: |
| 5646 | err_code |= cfg_parse_users(file, linenum, args, kwm); |
| 5647 | break; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 5648 | case CFG_PEERS: |
| 5649 | err_code |= cfg_parse_peers(file, linenum, args, kwm); |
| 5650 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5651 | default: |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5652 | 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] | 5653 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5654 | } |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5655 | |
| 5656 | if (err_code & ERR_ABORT) |
| 5657 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5658 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 5659 | free(cursection); |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5660 | cursection = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5661 | fclose(f); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5662 | return err_code; |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5663 | } |
| 5664 | |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 5665 | /* |
| 5666 | * Returns the error code, 0 if OK, or any combination of : |
| 5667 | * - ERR_ABORT: must abort ASAP |
| 5668 | * - ERR_FATAL: we can continue parsing but not start the service |
| 5669 | * - ERR_WARN: a warning has been emitted |
| 5670 | * - ERR_ALERT: an alert has been emitted |
| 5671 | * Only the two first ones can stop processing, the two others are just |
| 5672 | * indicators. |
| 5673 | */ |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5674 | int check_config_validity() |
| 5675 | { |
| 5676 | int cfgerr = 0; |
| 5677 | struct proxy *curproxy = NULL; |
| 5678 | struct server *newsrv = NULL; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5679 | struct userlist *curuserlist = NULL; |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 5680 | int err_code = 0; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 5681 | unsigned int next_pxid = 1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5682 | |
| 5683 | /* |
| 5684 | * Now, check for the integrity of all that we have collected. |
| 5685 | */ |
| 5686 | |
| 5687 | /* will be needed further to delay some tasks */ |
Willy Tarreau | b0b37bc | 2008-06-23 14:00:57 +0200 | [diff] [blame] | 5688 | tv_update_date(0,1); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5689 | |
Willy Tarreau | 55bc0f8 | 2009-03-15 14:51:53 +0100 | [diff] [blame] | 5690 | /* first, we will invert the proxy list order */ |
| 5691 | curproxy = NULL; |
| 5692 | while (proxy) { |
| 5693 | struct proxy *next; |
| 5694 | |
| 5695 | next = proxy->next; |
| 5696 | proxy->next = curproxy; |
| 5697 | curproxy = proxy; |
| 5698 | if (!next) |
| 5699 | break; |
| 5700 | proxy = next; |
| 5701 | } |
| 5702 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5703 | while (curproxy != NULL) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 5704 | struct switching_rule *rule; |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 5705 | struct server_rule *srule; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5706 | struct sticking_rule *mrule; |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 5707 | struct tcp_rule *trule; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 5708 | struct listener *listener; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 5709 | unsigned int next_id; |
| 5710 | |
| 5711 | if (!curproxy->uuid) { |
| 5712 | /* proxy ID not set, use automatic numbering with first |
| 5713 | * spare entry starting with next_pxid. |
| 5714 | */ |
| 5715 | next_pxid = get_next_id(&used_proxy_id, next_pxid); |
| 5716 | curproxy->conf.id.key = curproxy->uuid = next_pxid; |
| 5717 | eb32_insert(&used_proxy_id, &curproxy->conf.id); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 5718 | } |
Krzysztof Piotr Oledzki | df5cb9f | 2010-02-05 20:58:27 +0100 | [diff] [blame] | 5719 | next_pxid++; |
| 5720 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 5721 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5722 | if (curproxy->state == PR_STSTOPPED) { |
Willy Tarreau | da250db | 2008-10-12 12:07:48 +0200 | [diff] [blame] | 5723 | /* ensure we don't keep listeners uselessly bound */ |
| 5724 | stop_proxy(curproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5725 | curproxy = curproxy->next; |
| 5726 | continue; |
| 5727 | } |
| 5728 | |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 5729 | switch (curproxy->mode) { |
| 5730 | case PR_MODE_HEALTH: |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5731 | cfgerr += proxy_cfg_ensure_no_http(curproxy); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 5732 | if (!(curproxy->cap & PR_CAP_FE)) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5733 | Alert("config : %s '%s' cannot be in health mode as it has no frontend capability.\n", |
| 5734 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 5735 | cfgerr++; |
| 5736 | } |
| 5737 | |
| 5738 | if (curproxy->srv != NULL) |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5739 | Warning("config : servers will be ignored for %s '%s'.\n", |
| 5740 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 5741 | break; |
| 5742 | |
| 5743 | case PR_MODE_TCP: |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5744 | cfgerr += proxy_cfg_ensure_no_http(curproxy); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 5745 | break; |
| 5746 | |
| 5747 | case PR_MODE_HTTP: |
Willy Tarreau | a9fb083 | 2009-07-10 20:53:53 +0200 | [diff] [blame] | 5748 | curproxy->acl_requires |= ACL_USE_L7_ANY; |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 5749 | break; |
| 5750 | } |
| 5751 | |
| 5752 | if ((curproxy->cap & PR_CAP_FE) && (curproxy->listen == NULL)) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5753 | Alert("config : %s '%s' has no listen address. Please either specify a valid address on the <listen> line, or use the <bind> keyword.\n", |
| 5754 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5755 | cfgerr++; |
| 5756 | } |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 5757 | |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 5758 | if ((curproxy->cap & PR_CAP_BE) && (curproxy->mode != PR_MODE_HEALTH)) { |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 5759 | if (curproxy->lbprm.algo & BE_LB_KIND) { |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 5760 | if (curproxy->options & PR_O_TRANSP) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5761 | Alert("config : %s '%s' cannot use both transparent and balance mode.\n", |
| 5762 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 5763 | cfgerr++; |
| 5764 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5765 | #ifdef WE_DONT_SUPPORT_SERVERLESS_LISTENERS |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 5766 | else if (curproxy->srv == NULL) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5767 | Alert("config : %s '%s' needs at least 1 server in balance mode.\n", |
| 5768 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 5769 | cfgerr++; |
| 5770 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5771 | #endif |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 5772 | else if (curproxy->options & PR_O_DISPATCH) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5773 | Warning("config : dispatch address of %s '%s' will be ignored in balance mode.\n", |
| 5774 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 5775 | err_code |= ERR_WARN; |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 5776 | } |
| 5777 | } |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 5778 | else if (!(curproxy->options & (PR_O_TRANSP | PR_O_DISPATCH | PR_O_HTTP_PROXY))) { |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 5779 | /* If no LB algo is set in a backend, and we're not in |
| 5780 | * transparent mode, dispatch mode nor proxy mode, we |
| 5781 | * want to use balance roundrobin by default. |
| 5782 | */ |
| 5783 | curproxy->lbprm.algo &= ~BE_LB_ALGO; |
| 5784 | curproxy->lbprm.algo |= BE_LB_ALGO_RR; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5785 | } |
| 5786 | } |
Willy Tarreau | 193cf93 | 2007-09-17 10:17:23 +0200 | [diff] [blame] | 5787 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 5788 | if (curproxy->options & PR_O_DISPATCH) |
| 5789 | curproxy->options &= ~(PR_O_TRANSP | PR_O_HTTP_PROXY); |
| 5790 | else if (curproxy->options & PR_O_HTTP_PROXY) |
| 5791 | curproxy->options &= ~(PR_O_DISPATCH | PR_O_TRANSP); |
| 5792 | else if (curproxy->options & PR_O_TRANSP) |
| 5793 | curproxy->options &= ~(PR_O_DISPATCH | PR_O_HTTP_PROXY); |
Willy Tarreau | 8293658 | 2007-11-30 15:20:09 +0100 | [diff] [blame] | 5794 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 5795 | if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_HTTP_CHK) { |
| 5796 | if (curproxy->options & PR_O_DISABLE404) { |
| 5797 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n", |
| 5798 | "disable-on-404", proxy_type_str(curproxy), curproxy->id); |
| 5799 | err_code |= ERR_WARN; |
| 5800 | curproxy->options &= ~PR_O_DISABLE404; |
| 5801 | } |
| 5802 | if (curproxy->options2 & PR_O2_CHK_SNDST) { |
| 5803 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n", |
| 5804 | "send-state", proxy_type_str(curproxy), curproxy->id); |
| 5805 | err_code |= ERR_WARN; |
| 5806 | curproxy->options &= ~PR_O2_CHK_SNDST; |
| 5807 | } |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 5808 | } |
| 5809 | |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5810 | /* if a default backend was specified, let's find it */ |
| 5811 | if (curproxy->defbe.name) { |
| 5812 | struct proxy *target; |
| 5813 | |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 5814 | target = findproxy_mode(curproxy->defbe.name, curproxy->mode, PR_CAP_BE); |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 5815 | if (!target) { |
| 5816 | Alert("Proxy '%s': unable to find required default_backend: '%s'.\n", |
| 5817 | curproxy->id, curproxy->defbe.name); |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5818 | cfgerr++; |
| 5819 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 5820 | Alert("Proxy '%s': loop detected for default_backend: '%s'.\n", |
| 5821 | curproxy->id, curproxy->defbe.name); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 5822 | cfgerr++; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5823 | } else { |
| 5824 | free(curproxy->defbe.name); |
| 5825 | curproxy->defbe.be = target; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 5826 | /* we force the backend to be present on at least all of |
| 5827 | * the frontend's processes. |
| 5828 | */ |
| 5829 | target->bind_proc = curproxy->bind_proc ? |
| 5830 | (target->bind_proc | curproxy->bind_proc) : 0; |
Willy Tarreau | ff67813 | 2012-02-13 14:32:34 +0100 | [diff] [blame] | 5831 | |
| 5832 | /* Emit a warning if this proxy also has some servers */ |
| 5833 | if (curproxy->srv) { |
| 5834 | Warning("In proxy '%s', the 'default_backend' rule always has precedence over the servers, which will never be used.\n", |
| 5835 | curproxy->id); |
| 5836 | err_code |= ERR_WARN; |
| 5837 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5838 | } |
| 5839 | } |
| 5840 | |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5841 | /* find the target proxy in setbe */ |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5842 | if (curproxy->mode == PR_MODE_HTTP && curproxy->req_exp != NULL) { |
| 5843 | /* map jump target for ACT_SETBE in req_rep chain */ |
| 5844 | struct hdr_exp *exp; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5845 | for (exp = curproxy->req_exp; exp != NULL; exp = exp->next) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 5846 | struct proxy *target; |
| 5847 | |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5848 | if (exp->action != ACT_SETBE) |
| 5849 | continue; |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 5850 | |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 5851 | target = findproxy_mode(exp->replace, PR_MODE_HTTP, PR_CAP_BE); |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 5852 | if (!target) { |
| 5853 | Alert("Proxy '%s': unable to find required setbe: '%s'.\n", |
| 5854 | curproxy->id, exp->replace); |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5855 | cfgerr++; |
| 5856 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 5857 | Alert("Proxy '%s': loop detected for setbe: '%s'.\n", |
| 5858 | curproxy->id, exp->replace); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5859 | cfgerr++; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5860 | } else { |
| 5861 | free((void *)exp->replace); |
| 5862 | exp->replace = (const char *)target; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 5863 | /* we force the backend to be present on at least all of |
| 5864 | * the frontend's processes. |
| 5865 | */ |
| 5866 | target->bind_proc = curproxy->bind_proc ? |
| 5867 | (target->bind_proc | curproxy->bind_proc) : 0; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5868 | } |
| 5869 | } |
| 5870 | } |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 5871 | |
| 5872 | /* find the target proxy for 'use_backend' rules */ |
| 5873 | list_for_each_entry(rule, &curproxy->switching_rules, list) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 5874 | struct proxy *target; |
| 5875 | |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 5876 | target = findproxy_mode(rule->be.name, curproxy->mode, PR_CAP_BE); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 5877 | |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 5878 | if (!target) { |
| 5879 | Alert("Proxy '%s': unable to find required use_backend: '%s'.\n", |
| 5880 | curproxy->id, rule->be.name); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 5881 | cfgerr++; |
| 5882 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 5883 | Alert("Proxy '%s': loop detected for use_backend: '%s'.\n", |
| 5884 | curproxy->id, rule->be.name); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 5885 | cfgerr++; |
| 5886 | } else { |
| 5887 | free((void *)rule->be.name); |
| 5888 | rule->be.backend = target; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 5889 | /* we force the backend to be present on at least all of |
| 5890 | * the frontend's processes. |
| 5891 | */ |
| 5892 | target->bind_proc = curproxy->bind_proc ? |
| 5893 | (target->bind_proc | curproxy->bind_proc) : 0; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 5894 | } |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 5895 | } |
| 5896 | |
| 5897 | /* find the target proxy for 'use_backend' rules */ |
| 5898 | list_for_each_entry(srule, &curproxy->server_rules, list) { |
| 5899 | struct server *target = findserver(curproxy, srule->srv.name); |
| 5900 | |
| 5901 | if (!target) { |
| 5902 | Alert("config : %s '%s' : unable to find server '%s' referenced in a 'use-server' rule.\n", |
| 5903 | proxy_type_str(curproxy), curproxy->id, srule->srv.name); |
| 5904 | cfgerr++; |
| 5905 | continue; |
| 5906 | } |
| 5907 | free((void *)srule->srv.name); |
| 5908 | srule->srv.ptr = target; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 5909 | } |
| 5910 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5911 | /* find the target table for 'stick' rules */ |
| 5912 | list_for_each_entry(mrule, &curproxy->sticking_rules, list) { |
| 5913 | struct proxy *target; |
| 5914 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 5915 | curproxy->be_req_ana |= AN_REQ_STICKING_RULES; |
| 5916 | if (mrule->flags & STK_IS_STORE) |
| 5917 | curproxy->be_rsp_ana |= AN_RES_STORE_RULES; |
| 5918 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5919 | if (mrule->table.name) |
Willy Tarreau | c00cdc2 | 2010-06-06 16:48:26 +0200 | [diff] [blame] | 5920 | target = findproxy(mrule->table.name, 0); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5921 | else |
| 5922 | target = curproxy; |
| 5923 | |
| 5924 | if (!target) { |
| 5925 | Alert("Proxy '%s': unable to find stick-table '%s'.\n", |
| 5926 | curproxy->id, mrule->table.name); |
| 5927 | cfgerr++; |
| 5928 | } |
| 5929 | else if (target->table.size == 0) { |
| 5930 | Alert("Proxy '%s': stick-table '%s' used but not configured.\n", |
| 5931 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 5932 | cfgerr++; |
| 5933 | } |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 5934 | else if (!stktable_compatible_sample(mrule->expr, target->table.type)) { |
| 5935 | Alert("Proxy '%s': type of fetch not usable with type of stick-table '%s'.\n", |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5936 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 5937 | cfgerr++; |
| 5938 | } |
| 5939 | else { |
| 5940 | free((void *)mrule->table.name); |
| 5941 | mrule->table.t = &(target->table); |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 5942 | stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID, NULL); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5943 | } |
| 5944 | } |
| 5945 | |
| 5946 | /* find the target table for 'store response' rules */ |
| 5947 | list_for_each_entry(mrule, &curproxy->storersp_rules, list) { |
| 5948 | struct proxy *target; |
| 5949 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 5950 | curproxy->be_rsp_ana |= AN_RES_STORE_RULES; |
| 5951 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5952 | if (mrule->table.name) |
Willy Tarreau | c00cdc2 | 2010-06-06 16:48:26 +0200 | [diff] [blame] | 5953 | target = findproxy(mrule->table.name, 0); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5954 | else |
| 5955 | target = curproxy; |
| 5956 | |
| 5957 | if (!target) { |
| 5958 | Alert("Proxy '%s': unable to find store table '%s'.\n", |
| 5959 | curproxy->id, mrule->table.name); |
| 5960 | cfgerr++; |
| 5961 | } |
| 5962 | else if (target->table.size == 0) { |
| 5963 | Alert("Proxy '%s': stick-table '%s' used but not configured.\n", |
| 5964 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 5965 | cfgerr++; |
| 5966 | } |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 5967 | else if (!stktable_compatible_sample(mrule->expr, target->table.type)) { |
| 5968 | Alert("Proxy '%s': type of fetch not usable with type of stick-table '%s'.\n", |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5969 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 5970 | cfgerr++; |
| 5971 | } |
| 5972 | else { |
| 5973 | free((void *)mrule->table.name); |
| 5974 | mrule->table.t = &(target->table); |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 5975 | stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID, NULL); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5976 | } |
| 5977 | } |
| 5978 | |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 5979 | /* find the target table for 'tcp-request' layer 4 rules */ |
| 5980 | list_for_each_entry(trule, &curproxy->tcp_req.l4_rules, list) { |
| 5981 | struct proxy *target; |
| 5982 | |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 5983 | 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] | 5984 | continue; |
| 5985 | |
| 5986 | if (trule->act_prm.trk_ctr.table.n) |
| 5987 | target = findproxy(trule->act_prm.trk_ctr.table.n, 0); |
| 5988 | else |
| 5989 | target = curproxy; |
| 5990 | |
| 5991 | if (!target) { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 5992 | Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n", |
| 5993 | curproxy->id, trule->act_prm.trk_ctr.table.n, |
| 5994 | trule->action == TCP_ACT_TRK_SC1 ? 1 : 2); |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 5995 | cfgerr++; |
| 5996 | } |
| 5997 | else if (target->table.size == 0) { |
| 5998 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
| 5999 | curproxy->id, trule->act_prm.trk_ctr.table.n ? trule->act_prm.trk_ctr.table.n : curproxy->id); |
| 6000 | cfgerr++; |
| 6001 | } |
| 6002 | else if (trule->act_prm.trk_ctr.type != target->table.type) { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6003 | 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] | 6004 | curproxy->id, trule->act_prm.trk_ctr.table.n ? trule->act_prm.trk_ctr.table.n : curproxy->id); |
| 6005 | cfgerr++; |
| 6006 | } |
| 6007 | else { |
| 6008 | free(trule->act_prm.trk_ctr.table.n); |
| 6009 | trule->act_prm.trk_ctr.table.t = &target->table; |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6010 | /* 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] | 6011 | * to pass a list of counters to track and allocate them right here using |
| 6012 | * stktable_alloc_data_type(). |
| 6013 | */ |
| 6014 | } |
| 6015 | } |
| 6016 | |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 6017 | /* find the target table for 'tcp-request' layer 6 rules */ |
| 6018 | list_for_each_entry(trule, &curproxy->tcp_req.inspect_rules, list) { |
| 6019 | struct proxy *target; |
| 6020 | |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6021 | 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] | 6022 | continue; |
| 6023 | |
| 6024 | if (trule->act_prm.trk_ctr.table.n) |
| 6025 | target = findproxy(trule->act_prm.trk_ctr.table.n, 0); |
| 6026 | else |
| 6027 | target = curproxy; |
| 6028 | |
| 6029 | if (!target) { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6030 | Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n", |
| 6031 | curproxy->id, trule->act_prm.trk_ctr.table.n, |
| 6032 | trule->action == TCP_ACT_TRK_SC1 ? 1 : 2); |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 6033 | cfgerr++; |
| 6034 | } |
| 6035 | else if (target->table.size == 0) { |
| 6036 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
| 6037 | curproxy->id, trule->act_prm.trk_ctr.table.n ? trule->act_prm.trk_ctr.table.n : curproxy->id); |
| 6038 | cfgerr++; |
| 6039 | } |
| 6040 | else if (trule->act_prm.trk_ctr.type != target->table.type) { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6041 | 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] | 6042 | curproxy->id, trule->act_prm.trk_ctr.table.n ? trule->act_prm.trk_ctr.table.n : curproxy->id); |
| 6043 | cfgerr++; |
| 6044 | } |
| 6045 | else { |
| 6046 | free(trule->act_prm.trk_ctr.table.n); |
| 6047 | trule->act_prm.trk_ctr.table.t = &target->table; |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6048 | /* 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] | 6049 | * to pass a list of counters to track and allocate them right here using |
| 6050 | * stktable_alloc_data_type(). |
| 6051 | */ |
| 6052 | } |
| 6053 | } |
| 6054 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 6055 | if (curproxy->table.peers.name) { |
| 6056 | struct peers *curpeers = peers; |
| 6057 | |
| 6058 | for (curpeers = peers; curpeers; curpeers = curpeers->next) { |
| 6059 | if (strcmp(curpeers->id, curproxy->table.peers.name) == 0) { |
| 6060 | free((void *)curproxy->table.peers.name); |
| 6061 | curproxy->table.peers.p = peers; |
| 6062 | break; |
| 6063 | } |
| 6064 | } |
| 6065 | |
| 6066 | if (!curpeers) { |
| 6067 | Alert("Proxy '%s': unable to find sync peers '%s'.\n", |
| 6068 | curproxy->id, curproxy->table.peers.name); |
Willy Tarreau | d66bf96 | 2011-10-28 14:16:49 +0200 | [diff] [blame] | 6069 | free((void *)curproxy->table.peers.name); |
| 6070 | curproxy->table.peers.p = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 6071 | cfgerr++; |
| 6072 | } |
| 6073 | else if (!curpeers->peers_fe) { |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 6074 | Alert("Proxy '%s': unable to find local peer '%s' in peers section '%s'.\n", |
| 6075 | curproxy->id, localpeer, curpeers->id); |
Willy Tarreau | d66bf96 | 2011-10-28 14:16:49 +0200 | [diff] [blame] | 6076 | curproxy->table.peers.p = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 6077 | cfgerr++; |
| 6078 | } |
| 6079 | } |
| 6080 | |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 6081 | if (curproxy->uri_auth && !(curproxy->uri_auth->flags & ST_CONVDONE) && |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 6082 | !LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) && |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6083 | (curproxy->uri_auth->userlist || curproxy->uri_auth->auth_realm )) { |
| 6084 | Alert("%s '%s': stats 'auth'/'realm' and 'http-request' can't be used at the same time.\n", |
| 6085 | "proxy", curproxy->id); |
| 6086 | cfgerr++; |
| 6087 | goto out_uri_auth_compat; |
| 6088 | } |
| 6089 | |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 6090 | 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] | 6091 | const char *uri_auth_compat_req[10]; |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 6092 | struct http_req_rule *rule; |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6093 | int i = 0; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6094 | |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6095 | /* build the ACL condition from scratch. We're relying on anonymous ACLs for that */ |
| 6096 | uri_auth_compat_req[i++] = "auth"; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6097 | |
| 6098 | if (curproxy->uri_auth->auth_realm) { |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6099 | uri_auth_compat_req[i++] = "realm"; |
| 6100 | uri_auth_compat_req[i++] = curproxy->uri_auth->auth_realm; |
| 6101 | } |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6102 | |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6103 | uri_auth_compat_req[i++] = "unless"; |
| 6104 | uri_auth_compat_req[i++] = "{"; |
| 6105 | uri_auth_compat_req[i++] = "http_auth(.internal-stats-userlist)"; |
| 6106 | uri_auth_compat_req[i++] = "}"; |
| 6107 | uri_auth_compat_req[i++] = ""; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6108 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 6109 | rule = parse_http_req_cond(uri_auth_compat_req, "internal-stats-auth-compat", 0, curproxy); |
| 6110 | if (!rule) { |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6111 | cfgerr++; |
| 6112 | break; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6113 | } |
| 6114 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 6115 | LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list); |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6116 | |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6117 | if (curproxy->uri_auth->auth_realm) { |
| 6118 | free(curproxy->uri_auth->auth_realm); |
| 6119 | curproxy->uri_auth->auth_realm = NULL; |
| 6120 | } |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 6121 | |
| 6122 | curproxy->uri_auth->flags |= ST_CONVDONE; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6123 | } |
| 6124 | out_uri_auth_compat: |
| 6125 | |
Krzysztof Piotr Oledzki | f9423ae | 2010-01-29 19:26:18 +0100 | [diff] [blame] | 6126 | cfgerr += acl_find_targets(curproxy); |
| 6127 | |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 6128 | if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) && |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6129 | (((curproxy->cap & PR_CAP_FE) && !curproxy->timeout.client) || |
Willy Tarreau | d825eef | 2007-05-12 22:35:00 +0200 | [diff] [blame] | 6130 | ((curproxy->cap & PR_CAP_BE) && (curproxy->srv) && |
Willy Tarreau | ce887fd | 2012-05-12 12:50:00 +0200 | [diff] [blame] | 6131 | (!curproxy->timeout.connect || |
| 6132 | (!curproxy->timeout.server && (curproxy->mode == PR_MODE_HTTP || !curproxy->timeout.tunnel)))))) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6133 | Warning("config : missing timeouts for %s '%s'.\n" |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 6134 | " | While not properly invalid, you will certainly encounter various problems\n" |
| 6135 | " | 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] | 6136 | " | timeouts are set to a non-zero value: 'client', 'connect', 'server'.\n", |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6137 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6138 | err_code |= ERR_WARN; |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 6139 | } |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 6140 | |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6141 | /* Historically, the tarpit and queue timeouts were inherited from contimeout. |
| 6142 | * We must still support older configurations, so let's find out whether those |
| 6143 | * parameters have been set or must be copied from contimeouts. |
| 6144 | */ |
| 6145 | if (curproxy != &defproxy) { |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6146 | if (!curproxy->timeout.tarpit || |
| 6147 | curproxy->timeout.tarpit == defproxy.timeout.tarpit) { |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6148 | /* tarpit timeout not set. We search in the following order: |
| 6149 | * default.tarpit, curr.connect, default.connect. |
| 6150 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6151 | if (defproxy.timeout.tarpit) |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6152 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6153 | else if (curproxy->timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6154 | curproxy->timeout.tarpit = curproxy->timeout.connect; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6155 | else if (defproxy.timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6156 | curproxy->timeout.tarpit = defproxy.timeout.connect; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6157 | } |
| 6158 | if ((curproxy->cap & PR_CAP_BE) && |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6159 | (!curproxy->timeout.queue || |
| 6160 | curproxy->timeout.queue == defproxy.timeout.queue)) { |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6161 | /* queue timeout not set. We search in the following order: |
| 6162 | * default.queue, curr.connect, default.connect. |
| 6163 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6164 | if (defproxy.timeout.queue) |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6165 | curproxy->timeout.queue = defproxy.timeout.queue; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6166 | else if (curproxy->timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6167 | curproxy->timeout.queue = curproxy->timeout.connect; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6168 | else if (defproxy.timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6169 | curproxy->timeout.queue = defproxy.timeout.connect; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6170 | } |
| 6171 | } |
| 6172 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 6173 | if ((curproxy->options2 & PR_O2_CHK_ANY) == PR_O2_SSL3_CHK) { |
Willy Tarreau | 137325d | 2010-02-01 16:38:17 +0100 | [diff] [blame] | 6174 | curproxy->check_len = sizeof(sslv3_client_hello_pkt) - 1; |
| 6175 | curproxy->check_req = (char *)malloc(curproxy->check_len); |
| 6176 | memcpy(curproxy->check_req, sslv3_client_hello_pkt, curproxy->check_len); |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 6177 | } |
| 6178 | |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 6179 | /* The small pools required for the capture lists */ |
Willy Tarreau | 9a54e13 | 2012-03-24 08:33:05 +0100 | [diff] [blame] | 6180 | if (curproxy->nb_req_cap) { |
| 6181 | if (curproxy->mode == PR_MODE_HTTP) { |
| 6182 | curproxy->req_cap_pool = create_pool("ptrcap", |
| 6183 | curproxy->nb_req_cap * sizeof(char *), |
| 6184 | MEM_F_SHARED); |
| 6185 | } else { |
| 6186 | Warning("config : 'capture request header' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6187 | proxy_type_str(curproxy), curproxy->id); |
| 6188 | err_code |= ERR_WARN; |
| 6189 | curproxy->to_log &= ~LW_REQHDR; |
| 6190 | curproxy->nb_req_cap = 0; |
| 6191 | } |
| 6192 | } |
| 6193 | |
| 6194 | if (curproxy->nb_rsp_cap) { |
| 6195 | if (curproxy->mode == PR_MODE_HTTP) { |
| 6196 | curproxy->rsp_cap_pool = create_pool("ptrcap", |
| 6197 | curproxy->nb_rsp_cap * sizeof(char *), |
| 6198 | MEM_F_SHARED); |
| 6199 | } else { |
| 6200 | Warning("config : 'capture response header' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6201 | proxy_type_str(curproxy), curproxy->id); |
| 6202 | err_code |= ERR_WARN; |
| 6203 | curproxy->to_log &= ~LW_REQHDR; |
| 6204 | curproxy->nb_rsp_cap = 0; |
| 6205 | } |
| 6206 | } |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 6207 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6208 | /* first, we will invert the servers list order */ |
| 6209 | newsrv = NULL; |
| 6210 | while (curproxy->srv) { |
| 6211 | struct server *next; |
| 6212 | |
| 6213 | next = curproxy->srv->next; |
| 6214 | curproxy->srv->next = newsrv; |
| 6215 | newsrv = curproxy->srv; |
| 6216 | if (!next) |
| 6217 | break; |
| 6218 | curproxy->srv = next; |
| 6219 | } |
| 6220 | |
Willy Tarreau | dd70165 | 2010-05-25 23:03:02 +0200 | [diff] [blame] | 6221 | /* assign automatic UIDs to servers which don't have one yet */ |
| 6222 | next_id = 1; |
| 6223 | newsrv = curproxy->srv; |
| 6224 | while (newsrv != NULL) { |
| 6225 | if (!newsrv->puid) { |
| 6226 | /* server ID not set, use automatic numbering with first |
| 6227 | * spare entry starting with next_svid. |
| 6228 | */ |
| 6229 | next_id = get_next_id(&curproxy->conf.used_server_id, next_id); |
| 6230 | newsrv->conf.id.key = newsrv->puid = next_id; |
| 6231 | eb32_insert(&curproxy->conf.used_server_id, &newsrv->conf.id); |
| 6232 | } |
| 6233 | next_id++; |
| 6234 | newsrv = newsrv->next; |
| 6235 | } |
| 6236 | |
Willy Tarreau | 2069704 | 2007-11-15 23:26:18 +0100 | [diff] [blame] | 6237 | curproxy->lbprm.wmult = 1; /* default weight multiplier */ |
Willy Tarreau | 5dc2fa6 | 2007-11-19 19:10:18 +0100 | [diff] [blame] | 6238 | curproxy->lbprm.wdiv = 1; /* default weight divider */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6239 | |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 6240 | /* |
| 6241 | * If this server supports a maxconn parameter, it needs a dedicated |
| 6242 | * tasks to fill the emptied slots when a connection leaves. |
| 6243 | * Also, resolve deferred tracking dependency if needed. |
| 6244 | */ |
| 6245 | newsrv = curproxy->srv; |
| 6246 | while (newsrv != NULL) { |
| 6247 | if (newsrv->minconn > newsrv->maxconn) { |
| 6248 | /* Only 'minconn' was specified, or it was higher than or equal |
| 6249 | * to 'maxconn'. Let's turn this into maxconn and clean it, as |
| 6250 | * this will avoid further useless expensive computations. |
| 6251 | */ |
| 6252 | newsrv->maxconn = newsrv->minconn; |
| 6253 | } else if (newsrv->maxconn && !newsrv->minconn) { |
| 6254 | /* minconn was not specified, so we set it to maxconn */ |
| 6255 | newsrv->minconn = newsrv->maxconn; |
| 6256 | } |
| 6257 | |
| 6258 | if (newsrv->trackit) { |
| 6259 | struct proxy *px; |
| 6260 | struct server *srv; |
| 6261 | char *pname, *sname; |
| 6262 | |
| 6263 | pname = newsrv->trackit; |
| 6264 | sname = strrchr(pname, '/'); |
| 6265 | |
| 6266 | if (sname) |
| 6267 | *sname++ = '\0'; |
| 6268 | else { |
| 6269 | sname = pname; |
| 6270 | pname = NULL; |
| 6271 | } |
| 6272 | |
| 6273 | if (pname) { |
| 6274 | px = findproxy(pname, PR_CAP_BE); |
| 6275 | if (!px) { |
| 6276 | Alert("config : %s '%s', server '%s': unable to find required proxy '%s' for tracking.\n", |
| 6277 | proxy_type_str(curproxy), curproxy->id, |
| 6278 | newsrv->id, pname); |
| 6279 | cfgerr++; |
| 6280 | goto next_srv; |
| 6281 | } |
| 6282 | } else |
| 6283 | px = curproxy; |
| 6284 | |
| 6285 | srv = findserver(px, sname); |
| 6286 | if (!srv) { |
| 6287 | Alert("config : %s '%s', server '%s': unable to find required server '%s' for tracking.\n", |
| 6288 | proxy_type_str(curproxy), curproxy->id, |
| 6289 | newsrv->id, sname); |
| 6290 | cfgerr++; |
| 6291 | goto next_srv; |
| 6292 | } |
| 6293 | |
| 6294 | if (!(srv->state & SRV_CHECKED)) { |
| 6295 | Alert("config : %s '%s', server '%s': unable to use %s/%s for " |
| 6296 | "tracking as it does not have checks enabled.\n", |
| 6297 | proxy_type_str(curproxy), curproxy->id, |
| 6298 | newsrv->id, px->id, srv->id); |
| 6299 | cfgerr++; |
| 6300 | goto next_srv; |
| 6301 | } |
| 6302 | |
| 6303 | if (curproxy != px && |
| 6304 | (curproxy->options & PR_O_DISABLE404) != (px->options & PR_O_DISABLE404)) { |
| 6305 | Alert("config : %s '%s', server '%s': unable to use %s/%s for" |
| 6306 | "tracking: disable-on-404 option inconsistency.\n", |
| 6307 | proxy_type_str(curproxy), curproxy->id, |
| 6308 | newsrv->id, px->id, srv->id); |
| 6309 | cfgerr++; |
| 6310 | goto next_srv; |
| 6311 | } |
| 6312 | |
| 6313 | /* if the other server is forced disabled, we have to do the same here */ |
| 6314 | if (srv->state & SRV_MAINTAIN) { |
| 6315 | newsrv->state |= SRV_MAINTAIN; |
| 6316 | newsrv->state &= ~SRV_RUNNING; |
| 6317 | newsrv->health = 0; |
| 6318 | } |
| 6319 | |
| 6320 | newsrv->track = srv; |
| 6321 | newsrv->tracknext = srv->tracknext; |
| 6322 | srv->tracknext = newsrv; |
| 6323 | |
| 6324 | free(newsrv->trackit); |
| 6325 | newsrv->trackit = NULL; |
| 6326 | } |
| 6327 | next_srv: |
| 6328 | newsrv = newsrv->next; |
| 6329 | } |
| 6330 | |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6331 | /* We have to initialize the server lookup mechanism depending |
| 6332 | * on what LB algorithm was choosen. |
| 6333 | */ |
| 6334 | |
| 6335 | curproxy->lbprm.algo &= ~(BE_LB_LKUP | BE_LB_PROP_DYN); |
| 6336 | switch (curproxy->lbprm.algo & BE_LB_KIND) { |
| 6337 | case BE_LB_KIND_RR: |
Willy Tarreau | 9757a38 | 2009-10-03 12:56:50 +0200 | [diff] [blame] | 6338 | if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_RR_STATIC) { |
| 6339 | curproxy->lbprm.algo |= BE_LB_LKUP_MAP; |
| 6340 | init_server_map(curproxy); |
| 6341 | } else { |
| 6342 | curproxy->lbprm.algo |= BE_LB_LKUP_RRTREE | BE_LB_PROP_DYN; |
| 6343 | fwrr_init_server_groups(curproxy); |
| 6344 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6345 | break; |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 6346 | |
Willy Tarreau | 3ebb116 | 2012-02-13 16:57:44 +0100 | [diff] [blame] | 6347 | case BE_LB_KIND_CB: |
Willy Tarreau | f09c660 | 2012-02-13 17:12:08 +0100 | [diff] [blame] | 6348 | if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_CB_LC) { |
| 6349 | curproxy->lbprm.algo |= BE_LB_LKUP_LCTREE | BE_LB_PROP_DYN; |
| 6350 | fwlc_init_server_tree(curproxy); |
| 6351 | } else { |
| 6352 | curproxy->lbprm.algo |= BE_LB_LKUP_FSTREE | BE_LB_PROP_DYN; |
| 6353 | fas_init_server_tree(curproxy); |
| 6354 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6355 | break; |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 6356 | |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6357 | case BE_LB_KIND_HI: |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 6358 | if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS) { |
| 6359 | curproxy->lbprm.algo |= BE_LB_LKUP_CHTREE | BE_LB_PROP_DYN; |
| 6360 | chash_init_server_tree(curproxy); |
| 6361 | } else { |
| 6362 | curproxy->lbprm.algo |= BE_LB_LKUP_MAP; |
| 6363 | init_server_map(curproxy); |
| 6364 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6365 | break; |
| 6366 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6367 | |
| 6368 | if (curproxy->options & PR_O_LOGASAP) |
| 6369 | curproxy->to_log &= ~LW_BYTES; |
| 6370 | |
Willy Tarreau | e7ded1f | 2009-08-09 10:11:45 +0200 | [diff] [blame] | 6371 | if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) && |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6372 | (curproxy->cap & PR_CAP_FE) && curproxy->to_log && LIST_ISEMPTY(&curproxy->logsrvs)) { |
Willy Tarreau | e7ded1f | 2009-08-09 10:11:45 +0200 | [diff] [blame] | 6373 | Warning("config : log format ignored for %s '%s' since it has no log address.\n", |
| 6374 | proxy_type_str(curproxy), curproxy->id); |
| 6375 | err_code |= ERR_WARN; |
| 6376 | } |
| 6377 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 6378 | if (curproxy->mode != PR_MODE_HTTP) { |
| 6379 | int optnum; |
| 6380 | |
| 6381 | if (curproxy->options & PR_O_COOK_ANY) { |
| 6382 | Warning("config : 'cookie' statement ignored for %s '%s' as it requires HTTP mode.\n", |
| 6383 | proxy_type_str(curproxy), curproxy->id); |
| 6384 | err_code |= ERR_WARN; |
| 6385 | } |
| 6386 | |
| 6387 | if (curproxy->uri_auth) { |
| 6388 | Warning("config : 'stats' statement ignored for %s '%s' as it requires HTTP mode.\n", |
| 6389 | proxy_type_str(curproxy), curproxy->id); |
| 6390 | err_code |= ERR_WARN; |
| 6391 | curproxy->uri_auth = NULL; |
| 6392 | } |
| 6393 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 6394 | if (curproxy->options & (PR_O_FWDFOR | PR_O_FF_ALWAYS)) { |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 6395 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6396 | "forwardfor", proxy_type_str(curproxy), curproxy->id); |
| 6397 | err_code |= ERR_WARN; |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 6398 | curproxy->options &= ~(PR_O_FWDFOR | PR_O_FF_ALWAYS); |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 6399 | } |
| 6400 | |
| 6401 | if (curproxy->options & PR_O_ORGTO) { |
| 6402 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6403 | "originalto", proxy_type_str(curproxy), curproxy->id); |
| 6404 | err_code |= ERR_WARN; |
| 6405 | curproxy->options &= ~PR_O_ORGTO; |
| 6406 | } |
| 6407 | |
| 6408 | for (optnum = 0; cfg_opts[optnum].name; optnum++) { |
| 6409 | if (cfg_opts[optnum].mode == PR_MODE_HTTP && |
| 6410 | (curproxy->cap & cfg_opts[optnum].cap) && |
| 6411 | (curproxy->options & cfg_opts[optnum].val)) { |
| 6412 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6413 | cfg_opts[optnum].name, proxy_type_str(curproxy), curproxy->id); |
| 6414 | err_code |= ERR_WARN; |
| 6415 | curproxy->options &= ~cfg_opts[optnum].val; |
| 6416 | } |
| 6417 | } |
| 6418 | |
| 6419 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) { |
| 6420 | if (cfg_opts2[optnum].mode == PR_MODE_HTTP && |
| 6421 | (curproxy->cap & cfg_opts2[optnum].cap) && |
| 6422 | (curproxy->options2 & cfg_opts2[optnum].val)) { |
| 6423 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6424 | cfg_opts2[optnum].name, proxy_type_str(curproxy), curproxy->id); |
| 6425 | err_code |= ERR_WARN; |
| 6426 | curproxy->options2 &= ~cfg_opts2[optnum].val; |
| 6427 | } |
| 6428 | } |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6429 | |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 6430 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6431 | if (curproxy->bind_hdr_occ) { |
| 6432 | curproxy->bind_hdr_occ = 0; |
| 6433 | Warning("config : %s '%s' : ignoring use of header %s as source IP in non-HTTP mode.\n", |
| 6434 | proxy_type_str(curproxy), curproxy->id, curproxy->bind_hdr_name); |
| 6435 | err_code |= ERR_WARN; |
| 6436 | } |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 6437 | #endif |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 6438 | } |
| 6439 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6440 | /* |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 6441 | * ensure that we're not cross-dressing a TCP server into HTTP. |
| 6442 | */ |
| 6443 | newsrv = curproxy->srv; |
| 6444 | while (newsrv != NULL) { |
Willy Tarreau | 0cec331 | 2011-10-31 13:49:26 +0100 | [diff] [blame] | 6445 | if ((curproxy->mode != PR_MODE_HTTP) && newsrv->rdr_len) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6446 | Alert("config : %s '%s' : server cannot have cookie or redirect prefix in non-HTTP mode.\n", |
| 6447 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6448 | cfgerr++; |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 6449 | } |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6450 | |
Willy Tarreau | 0cec331 | 2011-10-31 13:49:26 +0100 | [diff] [blame] | 6451 | if ((curproxy->mode != PR_MODE_HTTP) && newsrv->cklen) { |
| 6452 | Warning("config : %s '%s' : ignoring cookie for server '%s' as HTTP mode is disabled.\n", |
| 6453 | proxy_type_str(curproxy), curproxy->id, newsrv->id); |
| 6454 | err_code |= ERR_WARN; |
| 6455 | } |
| 6456 | |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 6457 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6458 | if (curproxy->mode != PR_MODE_HTTP && newsrv->bind_hdr_occ) { |
| 6459 | newsrv->bind_hdr_occ = 0; |
| 6460 | Warning("config : %s '%s' : server %s cannot use header %s as source IP in non-HTTP mode.\n", |
| 6461 | proxy_type_str(curproxy), curproxy->id, newsrv->id, newsrv->bind_hdr_name); |
| 6462 | err_code |= ERR_WARN; |
| 6463 | } |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 6464 | #endif |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 6465 | newsrv = newsrv->next; |
| 6466 | } |
| 6467 | |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6468 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 6469 | curproxy->accept = frontend_accept; |
| 6470 | |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6471 | if (curproxy->tcp_req.inspect_delay || |
| 6472 | !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules)) |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 6473 | curproxy->fe_req_ana |= AN_REQ_INSPECT_FE; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6474 | |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 6475 | if (curproxy->mode == PR_MODE_HTTP) { |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6476 | 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] | 6477 | 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] | 6478 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6479 | |
| 6480 | /* both TCP and HTTP must check switching rules */ |
| 6481 | curproxy->fe_req_ana |= AN_REQ_SWITCHING_RULES; |
| 6482 | } |
| 6483 | |
| 6484 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 6485 | if (curproxy->tcp_req.inspect_delay || |
| 6486 | !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules)) |
| 6487 | curproxy->be_req_ana |= AN_REQ_INSPECT_BE; |
| 6488 | |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 6489 | if (!LIST_ISEMPTY(&curproxy->tcp_rep.inspect_rules)) |
| 6490 | curproxy->be_rsp_ana |= AN_RES_INSPECT; |
| 6491 | |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 6492 | if (curproxy->mode == PR_MODE_HTTP) { |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6493 | 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] | 6494 | 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] | 6495 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6496 | |
| 6497 | /* If the backend does requires RDP cookie persistence, we have to |
| 6498 | * enable the corresponding analyser. |
| 6499 | */ |
| 6500 | if (curproxy->options2 & PR_O2_RDPC_PRST) |
| 6501 | curproxy->be_req_ana |= AN_REQ_PRST_RDP_COOKIE; |
| 6502 | } |
| 6503 | |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 6504 | listener = NULL; |
| 6505 | while (curproxy->listen) { |
| 6506 | struct listener *next; |
| 6507 | |
| 6508 | next = curproxy->listen->next; |
| 6509 | curproxy->listen->next = listener; |
| 6510 | listener = curproxy->listen; |
| 6511 | |
| 6512 | if (!next) |
| 6513 | break; |
| 6514 | |
| 6515 | curproxy->listen = next; |
| 6516 | } |
| 6517 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 6518 | /* adjust this proxy's listeners */ |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6519 | next_id = 1; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 6520 | listener = curproxy->listen; |
| 6521 | while (listener) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6522 | if (!listener->luid) { |
| 6523 | /* listener ID not set, use automatic numbering with first |
| 6524 | * spare entry starting with next_luid. |
| 6525 | */ |
| 6526 | next_id = get_next_id(&curproxy->conf.used_listener_id, next_id); |
| 6527 | listener->conf.id.key = listener->luid = next_id; |
| 6528 | eb32_insert(&curproxy->conf.used_listener_id, &listener->conf.id); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6529 | } |
Krzysztof Piotr Oledzki | df5cb9f | 2010-02-05 20:58:27 +0100 | [diff] [blame] | 6530 | next_id++; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6531 | |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 6532 | /* enable separate counters */ |
| 6533 | if (curproxy->options2 & PR_O2_SOCKSTAT) { |
| 6534 | listener->counters = (struct licounters *)calloc(1, sizeof(struct licounters)); |
| 6535 | if (!listener->name) { |
| 6536 | sprintf(trash, "sock-%d", listener->luid); |
| 6537 | listener->name = strdup(trash); |
| 6538 | } |
| 6539 | } |
| 6540 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 6541 | if (curproxy->options & PR_O_TCP_NOLING) |
| 6542 | listener->options |= LI_O_NOLINGER; |
| 6543 | listener->maxconn = curproxy->maxconn; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 6544 | listener->backlog = curproxy->backlog; |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6545 | listener->timeout = &curproxy->timeout.client; |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 6546 | listener->accept = session_accept; |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 6547 | listener->frontend = curproxy; |
Willy Tarreau | 3bc1377 | 2008-12-07 11:50:35 +0100 | [diff] [blame] | 6548 | listener->handler = process_session; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6549 | listener->analysers |= curproxy->fe_req_ana; |
Willy Tarreau | 3bc1377 | 2008-12-07 11:50:35 +0100 | [diff] [blame] | 6550 | |
Willy Tarreau | 8a95691 | 2010-10-15 14:27:08 +0200 | [diff] [blame] | 6551 | if (listener->options & LI_O_ACC_PROXY) |
| 6552 | listener->analysers |= AN_REQ_DECODE_PROXY; |
| 6553 | |
Willy Tarreau | a5c0ab2 | 2010-05-31 10:30:33 +0200 | [diff] [blame] | 6554 | if (!LIST_ISEMPTY(&curproxy->tcp_req.l4_rules)) |
| 6555 | listener->options |= LI_O_TCP_RULES; |
| 6556 | |
Willy Tarreau | de3041d | 2010-05-31 10:56:17 +0200 | [diff] [blame] | 6557 | if (curproxy->mon_mask.s_addr) |
| 6558 | listener->options |= LI_O_CHK_MONNET; |
| 6559 | |
Willy Tarreau | 9ea05a7 | 2009-06-14 12:07:01 +0200 | [diff] [blame] | 6560 | /* smart accept mode is automatic in HTTP mode */ |
| 6561 | if ((curproxy->options2 & PR_O2_SMARTACC) || |
| 6562 | (curproxy->mode == PR_MODE_HTTP && |
| 6563 | !(curproxy->no_options2 & PR_O2_SMARTACC))) |
| 6564 | listener->options |= LI_O_NOQUICKACK; |
| 6565 | |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 6566 | /* We want the use_backend and default_backend rules to apply */ |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 6567 | listener = listener->next; |
| 6568 | } |
| 6569 | |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 6570 | /* Check multi-process mode compatibility for the current proxy */ |
| 6571 | if (global.nbproc > 1) { |
| 6572 | int nbproc = 0; |
| 6573 | if (curproxy->bind_proc) { |
| 6574 | int proc; |
| 6575 | for (proc = 0; proc < global.nbproc; proc++) { |
| 6576 | if (curproxy->bind_proc & (1 << proc)) { |
| 6577 | nbproc++; |
| 6578 | } |
| 6579 | } |
| 6580 | } else { |
| 6581 | nbproc = global.nbproc; |
| 6582 | } |
| 6583 | if (curproxy->table.peers.name) { |
| 6584 | Alert("Proxy '%s': peers can't be used in multi-process mode (nbproc > 1).\n", |
| 6585 | curproxy->id); |
| 6586 | cfgerr++; |
| 6587 | } |
| 6588 | if (nbproc > 1) { |
| 6589 | if (curproxy->uri_auth) { |
| 6590 | Warning("Proxy '%s': in multi-process mode, stats will be limited to process assigned to the current request.\n", |
| 6591 | curproxy->id); |
| 6592 | if (!LIST_ISEMPTY(&curproxy->uri_auth->admin_rules)) { |
| 6593 | Warning("Proxy '%s': stats admin will not work correctly in multi-process mode.\n", |
| 6594 | curproxy->id); |
| 6595 | } |
| 6596 | } |
| 6597 | if (curproxy->appsession_name) { |
| 6598 | Warning("Proxy '%s': appsession will not work correctly in multi-process mode.\n", |
| 6599 | curproxy->id); |
| 6600 | } |
| 6601 | if (!LIST_ISEMPTY(&curproxy->sticking_rules)) { |
| 6602 | Warning("Proxy '%s': sticking rules will not work correctly in multi-process mode.\n", |
| 6603 | curproxy->id); |
| 6604 | } |
| 6605 | } |
| 6606 | } |
Willy Tarreau | 918ff60 | 2011-07-25 16:33:49 +0200 | [diff] [blame] | 6607 | |
| 6608 | /* create the task associated with the proxy */ |
| 6609 | curproxy->task = task_new(); |
| 6610 | if (curproxy->task) { |
| 6611 | curproxy->task->context = curproxy; |
| 6612 | curproxy->task->process = manage_proxy; |
| 6613 | /* no need to queue, it will be done automatically if some |
| 6614 | * listener gets limited. |
| 6615 | */ |
| 6616 | curproxy->task->expire = TICK_ETERNITY; |
| 6617 | } else { |
| 6618 | Alert("Proxy '%s': no more memory when trying to allocate the management task\n", |
| 6619 | curproxy->id); |
| 6620 | cfgerr++; |
| 6621 | } |
| 6622 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6623 | curproxy = curproxy->next; |
| 6624 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 6625 | |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 6626 | /* Check multi-process mode compatibility */ |
| 6627 | if (global.nbproc > 1) { |
| 6628 | if (global.stats_fe) { |
| 6629 | Warning("stats socket will not work correctly in multi-process mode (nbproc > 1).\n"); |
| 6630 | } |
| 6631 | } |
| 6632 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6633 | for (curuserlist = userlist; curuserlist; curuserlist = curuserlist->next) { |
| 6634 | struct auth_users *curuser; |
| 6635 | int g; |
| 6636 | |
| 6637 | for (curuser = curuserlist->users; curuser; curuser = curuser->next) { |
| 6638 | unsigned int group_mask = 0; |
| 6639 | char *group = NULL; |
| 6640 | |
Willy Tarreau | b4c06b7 | 2010-02-02 11:28:20 +0100 | [diff] [blame] | 6641 | if (!curuser->u.groups) |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6642 | continue; |
| 6643 | |
Willy Tarreau | b4c06b7 | 2010-02-02 11:28:20 +0100 | [diff] [blame] | 6644 | while ((group = strtok(group?NULL:curuser->u.groups, ","))) { |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6645 | |
| 6646 | for (g = 0; g < curuserlist->grpcnt; g++) |
| 6647 | if (!strcmp(curuserlist->groups[g], group)) |
| 6648 | break; |
| 6649 | |
| 6650 | if (g == curuserlist->grpcnt) { |
| 6651 | Alert("userlist '%s': no such group '%s' specified in user '%s'\n", |
| 6652 | curuserlist->name, group, curuser->user); |
| 6653 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6654 | goto out; |
| 6655 | } |
| 6656 | |
| 6657 | group_mask |= (1 << g); |
| 6658 | } |
| 6659 | |
Willy Tarreau | b4c06b7 | 2010-02-02 11:28:20 +0100 | [diff] [blame] | 6660 | free(curuser->u.groups); |
| 6661 | curuser->u.group_mask = group_mask; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6662 | } |
| 6663 | |
| 6664 | for (g = 0; g < curuserlist->grpcnt; g++) { |
| 6665 | char *user = NULL; |
| 6666 | |
| 6667 | if (!curuserlist->groupusers[g]) |
| 6668 | continue; |
| 6669 | |
| 6670 | while ((user = strtok(user?NULL:curuserlist->groupusers[g], ","))) { |
| 6671 | for (curuser = curuserlist->users; curuser; curuser = curuser->next) |
| 6672 | if (!strcmp(curuser->user, user)) |
| 6673 | break; |
| 6674 | |
| 6675 | if (!curuser) { |
| 6676 | Alert("userlist '%s': no such user '%s' specified in group '%s'\n", |
| 6677 | curuserlist->name, user, curuserlist->groups[g]); |
| 6678 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6679 | goto out; |
| 6680 | } |
| 6681 | |
Willy Tarreau | b4c06b7 | 2010-02-02 11:28:20 +0100 | [diff] [blame] | 6682 | curuser->u.group_mask |= (1 << g); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6683 | } |
| 6684 | |
| 6685 | free(curuserlist->groupusers[g]); |
| 6686 | } |
| 6687 | |
| 6688 | free(curuserlist->groupusers); |
| 6689 | |
| 6690 | #ifdef DEBUG_AUTH |
| 6691 | for (g = 0; g < curuserlist->grpcnt; g++) { |
| 6692 | fprintf(stderr, "group %s, id %d, mask %08X, users:", curuserlist->groups[g], g , 1 << g); |
| 6693 | |
| 6694 | for (curuser = curuserlist->users; curuser; curuser = curuser->next) { |
Willy Tarreau | b950959 | 2012-05-10 23:25:35 +0200 | [diff] [blame] | 6695 | if (curuser->u.group_mask & (1 << g)) |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6696 | fprintf(stderr, " %s", curuser->user); |
| 6697 | } |
| 6698 | |
| 6699 | fprintf(stderr, "\n"); |
| 6700 | } |
| 6701 | #endif |
| 6702 | |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 6703 | } |
| 6704 | |
| 6705 | /* automatically compute fullconn if not set. We must not do it in the |
| 6706 | * loop above because cross-references are not yet fully resolved. |
| 6707 | */ |
| 6708 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 6709 | /* If <fullconn> is not set, let's set it to 10% of the sum of |
| 6710 | * the possible incoming frontend's maxconns. |
| 6711 | */ |
| 6712 | if (!curproxy->fullconn && (curproxy->cap & PR_CAP_BE)) { |
| 6713 | struct proxy *fe; |
| 6714 | int total = 0; |
| 6715 | |
| 6716 | /* sum up the number of maxconns of frontends which |
| 6717 | * reference this backend at least once or which are |
| 6718 | * the same one ('listen'). |
| 6719 | */ |
| 6720 | for (fe = proxy; fe; fe = fe->next) { |
| 6721 | struct switching_rule *rule; |
| 6722 | struct hdr_exp *exp; |
| 6723 | int found = 0; |
| 6724 | |
| 6725 | if (!(fe->cap & PR_CAP_FE)) |
| 6726 | continue; |
| 6727 | |
| 6728 | if (fe == curproxy) /* we're on a "listen" instance */ |
| 6729 | found = 1; |
| 6730 | |
| 6731 | if (fe->defbe.be == curproxy) /* "default_backend" */ |
| 6732 | found = 1; |
| 6733 | |
| 6734 | /* check if a "use_backend" rule matches */ |
| 6735 | if (!found) { |
| 6736 | list_for_each_entry(rule, &fe->switching_rules, list) { |
| 6737 | if (rule->be.backend == curproxy) { |
| 6738 | found = 1; |
| 6739 | break; |
| 6740 | } |
| 6741 | } |
| 6742 | } |
| 6743 | |
| 6744 | /* check if a "reqsetbe" rule matches */ |
| 6745 | for (exp = fe->req_exp; !found && exp; exp = exp->next) { |
| 6746 | if (exp->action == ACT_SETBE && |
| 6747 | (struct proxy *)exp->replace == curproxy) { |
| 6748 | found = 1; |
| 6749 | break; |
| 6750 | } |
| 6751 | } |
| 6752 | |
| 6753 | /* now we've checked all possible ways to reference a backend |
| 6754 | * from a frontend. |
| 6755 | */ |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 6756 | if (!found) |
| 6757 | continue; |
| 6758 | total += fe->maxconn; |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 6759 | } |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 6760 | /* we have the sum of the maxconns in <total>. We only |
| 6761 | * keep 10% of that sum to set the default fullconn, with |
| 6762 | * a hard minimum of 1 (to avoid a divide by zero). |
| 6763 | */ |
| 6764 | curproxy->fullconn = (total + 9) / 10; |
| 6765 | if (!curproxy->fullconn) |
| 6766 | curproxy->fullconn = 1; |
| 6767 | } |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6768 | } |
| 6769 | |
Willy Tarreau | 056f568 | 2010-06-06 15:51:11 +0200 | [diff] [blame] | 6770 | /* initialize stick-tables on backend capable proxies. This must not |
| 6771 | * be done earlier because the data size may be discovered while parsing |
| 6772 | * other proxies. |
| 6773 | */ |
| 6774 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) |
Willy Tarreau | c00cdc2 | 2010-06-06 16:48:26 +0200 | [diff] [blame] | 6775 | stktable_init(&curproxy->table); |
Willy Tarreau | 056f568 | 2010-06-06 15:51:11 +0200 | [diff] [blame] | 6776 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 6777 | /* |
| 6778 | * Recount currently required checks. |
| 6779 | */ |
| 6780 | |
| 6781 | for (curproxy=proxy; curproxy; curproxy=curproxy->next) { |
| 6782 | int optnum; |
| 6783 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 6784 | for (optnum = 0; cfg_opts[optnum].name; optnum++) |
| 6785 | if (curproxy->options & cfg_opts[optnum].val) |
| 6786 | global.last_checks |= cfg_opts[optnum].checks; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 6787 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 6788 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) |
| 6789 | if (curproxy->options2 & cfg_opts2[optnum].val) |
| 6790 | global.last_checks |= cfg_opts2[optnum].checks; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 6791 | } |
| 6792 | |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 6793 | if (peers) { |
| 6794 | struct peers *curpeers = peers, **last; |
| 6795 | struct peer *p, *pb; |
| 6796 | |
| 6797 | /* Remove all peers sections which don't have a valid listener. |
| 6798 | * This can happen when a peers section is never referenced and |
| 6799 | * does not contain a local peer. |
| 6800 | */ |
| 6801 | last = &peers; |
| 6802 | while (*last) { |
| 6803 | curpeers = *last; |
| 6804 | if (curpeers->peers_fe) { |
| 6805 | last = &curpeers->next; |
| 6806 | continue; |
| 6807 | } |
| 6808 | |
| 6809 | Warning("Removing incomplete section 'peers %s' (no peer named '%s').\n", |
| 6810 | curpeers->id, localpeer); |
| 6811 | |
| 6812 | p = curpeers->remote; |
| 6813 | while (p) { |
| 6814 | pb = p->next; |
| 6815 | free(p->id); |
| 6816 | free(p); |
| 6817 | p = pb; |
| 6818 | } |
| 6819 | |
| 6820 | /* Destroy and unlink this curpeers section. |
| 6821 | * Note: curpeers is backed up into *last. |
| 6822 | */ |
| 6823 | free(curpeers->id); |
| 6824 | curpeers = curpeers->next; |
| 6825 | free(*last); |
| 6826 | *last = curpeers; |
| 6827 | } |
| 6828 | } |
| 6829 | |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame] | 6830 | if (!global.tune.max_http_hdr) |
| 6831 | global.tune.max_http_hdr = MAX_HTTP_HDR; |
| 6832 | |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 6833 | pool2_hdr_idx = create_pool("hdr_idx", |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame] | 6834 | global.tune.max_http_hdr * sizeof(struct hdr_idx_elem), |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 6835 | MEM_F_SHARED); |
| 6836 | |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6837 | if (cfgerr > 0) |
| 6838 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6839 | out: |
| 6840 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6841 | } |
| 6842 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 6843 | /* |
| 6844 | * Registers the CFG keyword list <kwl> as a list of valid keywords for next |
| 6845 | * parsing sessions. |
| 6846 | */ |
| 6847 | void cfg_register_keywords(struct cfg_kw_list *kwl) |
| 6848 | { |
| 6849 | LIST_ADDQ(&cfg_keywords.list, &kwl->list); |
| 6850 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6851 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 6852 | /* |
| 6853 | * Unregisters the CFG keyword list <kwl> from the list of valid keywords. |
| 6854 | */ |
| 6855 | void cfg_unregister_keywords(struct cfg_kw_list *kwl) |
| 6856 | { |
| 6857 | LIST_DEL(&kwl->list); |
| 6858 | LIST_INIT(&kwl->list); |
| 6859 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6860 | |
| 6861 | /* |
| 6862 | * Local variables: |
| 6863 | * c-indent-level: 8 |
| 6864 | * c-basic-offset: 8 |
| 6865 | * End: |
| 6866 | */ |