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 | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 26 | #include <common/cfgparse.h> |
Willy Tarreau | c7e4238 | 2012-08-24 19:22:53 +0200 | [diff] [blame] | 27 | #include <common/chunk.h> |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 28 | #include <common/config.h> |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 29 | #include <common/errors.h> |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 30 | #include <common/memory.h> |
| 31 | #include <common/standard.h> |
| 32 | #include <common/time.h> |
| 33 | #include <common/uri_auth.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 34 | |
| 35 | #include <types/capture.h> |
| 36 | #include <types/global.h> |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 37 | #include <types/peers.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 38 | |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 39 | #include <proto/acl.h> |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 40 | #include <proto/auth.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 41 | #include <proto/backend.h> |
Willy Tarreau | c7e4238 | 2012-08-24 19:22:53 +0200 | [diff] [blame] | 42 | #include <proto/channel.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 43 | #include <proto/checks.h> |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 44 | #include <proto/dumpstats.h> |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 45 | #include <proto/frontend.h> |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 46 | #include <proto/hdr_idx.h> |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 47 | #include <proto/lb_chash.h> |
Willy Tarreau | f09c660 | 2012-02-13 17:12:08 +0100 | [diff] [blame] | 48 | #include <proto/lb_fas.h> |
Willy Tarreau | f89c187 | 2009-10-01 11:19:37 +0200 | [diff] [blame] | 49 | #include <proto/lb_fwlc.h> |
| 50 | #include <proto/lb_fwrr.h> |
| 51 | #include <proto/lb_map.h> |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 52 | #include <proto/listener.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 | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 55 | #include <proto/protocol.h> |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 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 | 75bf2c9 | 2012-08-20 17:01:35 +0200 | [diff] [blame] | 64 | #include <proto/raw_sock.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 | |
Emeric Brun | fc0421f | 2012-09-07 17:30:07 +0200 | [diff] [blame] | 68 | #ifdef USE_OPENSSL |
| 69 | #include <types/ssl_sock.h> |
| 70 | #include <proto/ssl_sock.h> |
| 71 | #include <proto/shctx.h> |
| 72 | #endif /*USE_OPENSSL */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 73 | |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 74 | /* This is the SSLv3 CLIENT HELLO packet used in conjunction with the |
| 75 | * ssl-hello-chk option to ensure that the remote server speaks SSL. |
| 76 | * |
| 77 | * Check RFC 2246 (TLSv1.0) sections A.3 and A.4 for details. |
| 78 | */ |
| 79 | const char sslv3_client_hello_pkt[] = { |
| 80 | "\x16" /* ContentType : 0x16 = Hanshake */ |
| 81 | "\x03\x00" /* ProtocolVersion : 0x0300 = SSLv3 */ |
| 82 | "\x00\x79" /* ContentLength : 0x79 bytes after this one */ |
| 83 | "\x01" /* HanshakeType : 0x01 = CLIENT HELLO */ |
| 84 | "\x00\x00\x75" /* HandshakeLength : 0x75 bytes after this one */ |
| 85 | "\x03\x00" /* Hello Version : 0x0300 = v3 */ |
| 86 | "\x00\x00\x00\x00" /* Unix GMT Time (s) : filled with <now> (@0x0B) */ |
| 87 | "HAPROXYSSLCHK\nHAPROXYSSLCHK\n" /* Random : must be exactly 28 bytes */ |
| 88 | "\x00" /* Session ID length : empty (no session ID) */ |
| 89 | "\x00\x4E" /* Cipher Suite Length : 78 bytes after this one */ |
| 90 | "\x00\x01" "\x00\x02" "\x00\x03" "\x00\x04" /* 39 most common ciphers : */ |
| 91 | "\x00\x05" "\x00\x06" "\x00\x07" "\x00\x08" /* 0x01...0x1B, 0x2F...0x3A */ |
| 92 | "\x00\x09" "\x00\x0A" "\x00\x0B" "\x00\x0C" /* This covers RSA/DH, */ |
| 93 | "\x00\x0D" "\x00\x0E" "\x00\x0F" "\x00\x10" /* various bit lengths, */ |
| 94 | "\x00\x11" "\x00\x12" "\x00\x13" "\x00\x14" /* SHA1/MD5, DES/3DES/AES... */ |
| 95 | "\x00\x15" "\x00\x16" "\x00\x17" "\x00\x18" |
| 96 | "\x00\x19" "\x00\x1A" "\x00\x1B" "\x00\x2F" |
| 97 | "\x00\x30" "\x00\x31" "\x00\x32" "\x00\x33" |
| 98 | "\x00\x34" "\x00\x35" "\x00\x36" "\x00\x37" |
| 99 | "\x00\x38" "\x00\x39" "\x00\x3A" |
| 100 | "\x01" /* Compression Length : 0x01 = 1 byte for types */ |
| 101 | "\x00" /* Compression Type : 0x00 = NULL compression */ |
| 102 | }; |
| 103 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 104 | /* various keyword modifiers */ |
| 105 | enum kw_mod { |
| 106 | KWM_STD = 0, /* normal */ |
| 107 | KWM_NO, /* "no" prefixed before the keyword */ |
| 108 | KWM_DEF, /* "default" prefixed before the keyword */ |
| 109 | }; |
| 110 | |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 111 | /* 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] | 112 | struct cfg_opt { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 113 | const char *name; |
| 114 | unsigned int val; |
| 115 | unsigned int cap; |
Willy Tarreau | 4fee4e9 | 2007-01-06 21:09:17 +0100 | [diff] [blame] | 116 | unsigned int checks; |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 117 | unsigned int mode; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 118 | }; |
| 119 | |
| 120 | /* proxy->options */ |
| 121 | static const struct cfg_opt cfg_opts[] = |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 122 | { |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 123 | { "abortonclose", PR_O_ABRT_CLOSE, PR_CAP_BE, 0, 0 }, |
| 124 | { "allbackups", PR_O_USE_ALL_BK, PR_CAP_BE, 0, 0 }, |
| 125 | { "checkcache", PR_O_CHK_CACHE, PR_CAP_BE, 0, PR_MODE_HTTP }, |
| 126 | { "clitcpka", PR_O_TCP_CLI_KA, PR_CAP_FE, 0, 0 }, |
| 127 | { "contstats", PR_O_CONTSTATS, PR_CAP_FE, 0, 0 }, |
| 128 | { "dontlognull", PR_O_NULLNOLOG, PR_CAP_FE, 0, 0 }, |
| 129 | { "forceclose", PR_O_FORCE_CLO, PR_CAP_FE | PR_CAP_BE, 0, PR_MODE_HTTP }, |
| 130 | { "http_proxy", PR_O_HTTP_PROXY, PR_CAP_FE | PR_CAP_BE, 0, PR_MODE_HTTP }, |
| 131 | { "httpclose", PR_O_HTTP_CLOSE, PR_CAP_FE | PR_CAP_BE, 0, PR_MODE_HTTP }, |
| 132 | { "keepalive", PR_O_KEEPALIVE, PR_CAP_NONE, 0, PR_MODE_HTTP }, |
| 133 | { "http-server-close", PR_O_SERVER_CLO, PR_CAP_FE | PR_CAP_BE, 0, PR_MODE_HTTP }, |
| 134 | { "logasap", PR_O_LOGASAP, PR_CAP_FE, 0, 0 }, |
| 135 | { "nolinger", PR_O_TCP_NOLING, PR_CAP_FE | PR_CAP_BE, 0, 0 }, |
| 136 | { "persist", PR_O_PERSIST, PR_CAP_BE, 0, 0 }, |
| 137 | { "redispatch", PR_O_REDISP, PR_CAP_BE, 0, 0 }, |
| 138 | { "srvtcpka", PR_O_TCP_SRV_KA, PR_CAP_BE, 0, 0 }, |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 139 | #ifdef TPROXY |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 140 | { "transparent", PR_O_TRANSP, PR_CAP_BE, 0, 0 }, |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 141 | #else |
| 142 | { "transparent", 0, 0, 0, 0 }, |
Willy Tarreau | 8f922fc | 2007-01-06 21:11:49 +0100 | [diff] [blame] | 143 | #endif |
| 144 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 145 | { NULL, 0, 0, 0, 0 } |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 146 | }; |
| 147 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 148 | /* proxy->options2 */ |
| 149 | static const struct cfg_opt cfg_opts2[] = |
| 150 | { |
| 151 | #ifdef CONFIG_HAP_LINUX_SPLICE |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 152 | { "splice-request", PR_O2_SPLIC_REQ, PR_CAP_FE|PR_CAP_BE, 0, 0 }, |
| 153 | { "splice-response", PR_O2_SPLIC_RTR, PR_CAP_FE|PR_CAP_BE, 0, 0 }, |
| 154 | { "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] | 155 | #else |
| 156 | { "splice-request", 0, 0, 0, 0 }, |
| 157 | { "splice-response", 0, 0, 0, 0 }, |
| 158 | { "splice-auto", 0, 0, 0, 0 }, |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 159 | #endif |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 160 | { "accept-invalid-http-request", PR_O2_REQBUG_OK, PR_CAP_FE, 0, PR_MODE_HTTP }, |
| 161 | { "accept-invalid-http-response", PR_O2_RSPBUG_OK, PR_CAP_BE, 0, PR_MODE_HTTP }, |
| 162 | { "dontlog-normal", PR_O2_NOLOGNORM, PR_CAP_FE, 0, 0 }, |
| 163 | { "log-separate-errors", PR_O2_LOGERRORS, PR_CAP_FE, 0, 0 }, |
| 164 | { "log-health-checks", PR_O2_LOGHCHKS, PR_CAP_BE, 0, 0 }, |
| 165 | { "socket-stats", PR_O2_SOCKSTAT, PR_CAP_FE, 0, 0 }, |
| 166 | { "tcp-smart-accept", PR_O2_SMARTACC, PR_CAP_FE, 0, 0 }, |
| 167 | { "tcp-smart-connect", PR_O2_SMARTCON, PR_CAP_BE, 0, 0 }, |
| 168 | { "independant-streams", PR_O2_INDEPSTR, PR_CAP_FE|PR_CAP_BE, 0, 0 }, |
Jamie Gloudon | 801a0a3 | 2012-08-25 00:18:33 -0400 | [diff] [blame] | 169 | { "independent-streams", PR_O2_INDEPSTR, PR_CAP_FE|PR_CAP_BE, 0, 0 }, |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 170 | { "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] | 171 | { "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] | 172 | { "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] | 173 | { NULL, 0, 0, 0 } |
| 174 | }; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 175 | |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 176 | static char *cursection = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 177 | static struct proxy defproxy; /* fake proxy used to assign default values on all instances */ |
| 178 | int cfg_maxpconn = DEFAULT_MAXCONN; /* # of simultaneous connections per proxy (-N) */ |
Willy Tarreau | 5af24ef | 2009-03-15 15:23:16 +0100 | [diff] [blame] | 179 | int cfg_maxconn = 0; /* # of simultaneous connections, (-n) */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 180 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 181 | /* List head of all known configuration keywords */ |
| 182 | static struct cfg_kw_list cfg_keywords = { |
| 183 | .list = LIST_HEAD_INIT(cfg_keywords.list) |
| 184 | }; |
| 185 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 186 | /* |
| 187 | * converts <str> to a list of listeners which are dynamically allocated. |
| 188 | * The format is "{addr|'*'}:port[-end][,{addr|'*'}:port[-end]]*", where : |
| 189 | * - <addr> can be empty or "*" to indicate INADDR_ANY ; |
| 190 | * - <port> is a numerical port from 1 to 65535 ; |
| 191 | * - <end> indicates to use the range from <port> to <end> instead (inclusive). |
| 192 | * This can be repeated as many times as necessary, separated by a coma. |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 193 | * Function returns 1 for success or 0 if error. In case of errors, if <err> is |
| 194 | * not NULL, it must be a valid pointer to either NULL or a freeable area that |
| 195 | * will be replaced with an error message. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 196 | */ |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 197 | int str2listener(char *str, struct proxy *curproxy, struct bind_conf *bind_conf, const char *file, int line, char **err) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 198 | { |
| 199 | struct listener *l; |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 200 | char *next, *dupstr; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 201 | int port, end; |
| 202 | |
| 203 | next = dupstr = strdup(str); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 204 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 205 | while (next && *next) { |
| 206 | struct sockaddr_storage ss; |
| 207 | |
| 208 | str = next; |
| 209 | /* 1) look for the end of the first address */ |
Krzysztof Piotr Oledzki | 52d522b | 2009-01-27 16:57:08 +0100 | [diff] [blame] | 210 | if ((next = strchr(str, ',')) != NULL) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 211 | *next++ = 0; |
| 212 | } |
| 213 | |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 214 | if (*str == '/') { |
| 215 | /* sun_path during a soft_stop rename is <unix_bind_prefix><path>.<pid>.<bak|tmp> */ |
| 216 | /* so compute max path */ |
| 217 | int prefix_path_len = global.unix_bind.prefix ? strlen(global.unix_bind.prefix) : 0; |
| 218 | 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] | 219 | |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 220 | if (strlen(str) > max_path_len) { |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 221 | memprintf(err, "socket path '%s' too long (max %d)\n", str, max_path_len); |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 222 | goto fail; |
| 223 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 224 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 225 | memset(&ss, 0, sizeof(ss)); |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 226 | ss.ss_family = AF_UNIX; |
| 227 | if (global.unix_bind.prefix) { |
| 228 | memcpy(((struct sockaddr_un *)&ss)->sun_path, global.unix_bind.prefix, prefix_path_len); |
| 229 | strcpy(((struct sockaddr_un *)&ss)->sun_path+prefix_path_len, str); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 230 | } |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 231 | else { |
| 232 | strcpy(((struct sockaddr_un *)&ss)->sun_path, str); |
| 233 | } |
| 234 | port = end = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 235 | } |
| 236 | else { |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 237 | struct sockaddr_storage *ss2; |
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 | ss2 = str2sa_range(str, &port, &end); |
| 240 | if (!ss2) { |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 241 | memprintf(err, "invalid listening address: '%s'\n", str); |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 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 | if (!port) { |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 246 | memprintf(err, "missing port number: '%s'\n", str); |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 247 | goto fail; |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 248 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 249 | |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 250 | /* OK the address looks correct */ |
| 251 | ss = *ss2; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 252 | |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 253 | if (port < 1 || port > 65535) { |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 254 | memprintf(err, "invalid port '%d' specified for address '%s'.\n", port, str); |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 255 | goto fail; |
| 256 | } |
| 257 | |
| 258 | if (end < 1 || end > 65535) { |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 259 | memprintf(err, "invalid port '%d' specified for address '%s'.\n", end, str); |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 260 | goto fail; |
| 261 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | for (; port <= end; port++) { |
| 265 | l = (struct listener *)calloc(1, sizeof(struct listener)); |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 266 | LIST_ADDQ(&curproxy->conf.listeners, &l->by_fe); |
| 267 | LIST_ADDQ(&bind_conf->listeners, &l->by_bind); |
| 268 | l->frontend = curproxy; |
| 269 | l->bind_conf = bind_conf; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 270 | |
| 271 | l->fd = -1; |
| 272 | l->addr = ss; |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 273 | l->xprt = &raw_sock; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 274 | l->state = LI_INIT; |
| 275 | |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 276 | if (ss.ss_family == AF_INET) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 277 | ((struct sockaddr_in *)(&l->addr))->sin_port = htons(port); |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 278 | tcpv4_add_listener(l); |
| 279 | } |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 280 | else if (ss.ss_family == AF_INET6) { |
| 281 | ((struct sockaddr_in6 *)(&l->addr))->sin6_port = htons(port); |
| 282 | tcpv6_add_listener(l); |
| 283 | } |
| 284 | else { |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 285 | uxst_add_listener(l); |
| 286 | } |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 287 | |
Willy Tarreau | af7ad00 | 2010-08-31 15:39:26 +0200 | [diff] [blame] | 288 | jobs++; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 289 | listeners++; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 290 | } /* end for(port) */ |
| 291 | } /* end while(next) */ |
| 292 | free(dupstr); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 293 | return 1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 294 | fail: |
| 295 | free(dupstr); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 296 | return 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 297 | } |
| 298 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 299 | /* |
| 300 | * Sends a warning if proxy <proxy> does not have at least one of the |
| 301 | * capabilities in <cap>. An optionnal <hint> may be added at the end |
| 302 | * of the warning to help the user. Returns 1 if a warning was emitted |
| 303 | * or 0 if the condition is valid. |
| 304 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 305 | 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] | 306 | { |
| 307 | char *msg; |
| 308 | |
| 309 | switch (cap) { |
| 310 | case PR_CAP_BE: msg = "no backend"; break; |
| 311 | case PR_CAP_FE: msg = "no frontend"; break; |
| 312 | case PR_CAP_RS: msg = "no ruleset"; break; |
| 313 | case PR_CAP_BE|PR_CAP_FE: msg = "neither frontend nor backend"; break; |
| 314 | default: msg = "not enough"; break; |
| 315 | } |
| 316 | |
| 317 | if (!(proxy->cap & cap)) { |
| 318 | 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] | 319 | file, line, arg, proxy_type_str(proxy), proxy->id, msg, hint ? hint : ""); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 320 | return 1; |
| 321 | } |
| 322 | return 0; |
| 323 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 324 | |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 325 | /* Report a warning if a rule is placed after a 'block' rule. |
| 326 | * Return 1 if the warning has been emitted, otherwise 0. |
| 327 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 328 | 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] | 329 | { |
| 330 | if (!LIST_ISEMPTY(&proxy->block_cond)) { |
| 331 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'block' rule will still be processed before.\n", |
| 332 | file, line, arg); |
| 333 | return 1; |
| 334 | } |
| 335 | return 0; |
| 336 | } |
| 337 | |
| 338 | /* Report a warning if a rule is placed after a reqrewrite rule. |
| 339 | * Return 1 if the warning has been emitted, otherwise 0. |
| 340 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 341 | 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] | 342 | { |
| 343 | if (proxy->req_exp) { |
| 344 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'reqxxx' rule will still be processed before.\n", |
| 345 | file, line, arg); |
| 346 | return 1; |
| 347 | } |
| 348 | return 0; |
| 349 | } |
| 350 | |
| 351 | /* Report a warning if a rule is placed after a reqadd rule. |
| 352 | * Return 1 if the warning has been emitted, otherwise 0. |
| 353 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 354 | 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] | 355 | { |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 356 | if (!LIST_ISEMPTY(&proxy->req_add)) { |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 357 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'reqadd' rule will still be processed before.\n", |
| 358 | file, line, arg); |
| 359 | return 1; |
| 360 | } |
| 361 | return 0; |
| 362 | } |
| 363 | |
| 364 | /* Report a warning if a rule is placed after a redirect rule. |
| 365 | * Return 1 if the warning has been emitted, otherwise 0. |
| 366 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 367 | 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] | 368 | { |
| 369 | if (!LIST_ISEMPTY(&proxy->redirect_rules)) { |
| 370 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'redirect' rule will still be processed before.\n", |
| 371 | file, line, arg); |
| 372 | return 1; |
| 373 | } |
| 374 | return 0; |
| 375 | } |
| 376 | |
| 377 | /* Report a warning if a rule is placed after a 'use_backend' rule. |
| 378 | * Return 1 if the warning has been emitted, otherwise 0. |
| 379 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 380 | 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] | 381 | { |
| 382 | if (!LIST_ISEMPTY(&proxy->switching_rules)) { |
| 383 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'use_backend' rule will still be processed before.\n", |
| 384 | file, line, arg); |
| 385 | return 1; |
| 386 | } |
| 387 | return 0; |
| 388 | } |
| 389 | |
| 390 | /* report a warning if a block rule is dangerously placed */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 391 | 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] | 392 | { |
| 393 | return warnif_rule_after_reqxxx(proxy, file, line, arg) || |
| 394 | warnif_rule_after_reqadd(proxy, file, line, arg) || |
| 395 | warnif_rule_after_redirect(proxy, file, line, arg) || |
| 396 | warnif_rule_after_use_backend(proxy, file, line, arg); |
| 397 | } |
| 398 | |
| 399 | /* report a warning if a reqxxx rule is dangerously placed */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 400 | 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] | 401 | { |
| 402 | return warnif_rule_after_reqadd(proxy, file, line, arg) || |
| 403 | warnif_rule_after_redirect(proxy, file, line, arg) || |
| 404 | warnif_rule_after_use_backend(proxy, file, line, arg); |
| 405 | } |
| 406 | |
| 407 | /* report a warning if a reqadd rule is dangerously placed */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 408 | 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] | 409 | { |
| 410 | return warnif_rule_after_redirect(proxy, file, line, arg) || |
| 411 | warnif_rule_after_use_backend(proxy, file, line, arg); |
| 412 | } |
| 413 | |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 414 | /* Report it if a request ACL condition uses some response-only parameters. It |
| 415 | * returns either 0 or ERR_WARN so that its result can be or'ed with err_code. |
| 416 | * Note that <cond> may be NULL and then will be ignored. |
| 417 | */ |
| 418 | static int warnif_cond_requires_resp(const struct acl_cond *cond, const char *file, int line) |
| 419 | { |
| 420 | struct acl *acl; |
| 421 | |
| 422 | if (!cond || !(cond->requires & ACL_USE_RTR_ANY)) |
| 423 | return 0; |
| 424 | |
| 425 | acl = cond_find_require(cond, ACL_USE_RTR_ANY); |
| 426 | Warning("parsing [%s:%d] : acl '%s' involves some response-only criteria which will be ignored.\n", |
| 427 | file, line, acl ? acl->name : "(unknown)"); |
| 428 | return ERR_WARN; |
| 429 | } |
| 430 | |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 431 | /* Report it if a request ACL condition uses some request-only volatile parameters. |
| 432 | * It returns either 0 or ERR_WARN so that its result can be or'ed with err_code. |
| 433 | * Note that <cond> may be NULL and then will be ignored. |
| 434 | */ |
| 435 | static int warnif_cond_requires_req(const struct acl_cond *cond, const char *file, int line) |
| 436 | { |
| 437 | struct acl *acl; |
| 438 | |
| 439 | if (!cond || !(cond->requires & ACL_USE_REQ_VOLATILE)) |
| 440 | return 0; |
| 441 | |
| 442 | acl = cond_find_require(cond, ACL_USE_REQ_VOLATILE); |
| 443 | Warning("parsing [%s:%d] : acl '%s' involves some volatile request-only criteria which will be ignored.\n", |
| 444 | file, line, acl ? acl->name : "(unknown)"); |
| 445 | return ERR_WARN; |
| 446 | } |
| 447 | |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 448 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 449 | /* |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 450 | * parse a line in a <global> section. Returns the error code, 0 if OK, or |
| 451 | * any combination of : |
| 452 | * - ERR_ABORT: must abort ASAP |
| 453 | * - ERR_FATAL: we can continue parsing but not start the service |
| 454 | * - ERR_WARN: a warning has been emitted |
| 455 | * - ERR_ALERT: an alert has been emitted |
| 456 | * Only the two first ones can stop processing, the two others are just |
| 457 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 458 | */ |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 459 | 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] | 460 | { |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 461 | int err_code = 0; |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 462 | char *errmsg = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 463 | |
| 464 | if (!strcmp(args[0], "global")) { /* new section */ |
| 465 | /* no option, nothing special to do */ |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 466 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 467 | } |
Emeric Brun | c8e8d12 | 2012-10-02 18:42:10 +0200 | [diff] [blame] | 468 | else if (!strcmp(args[0], "ca-base")) { |
| 469 | #ifdef USE_OPENSSL |
| 470 | if (global.ca_base != NULL) { |
| 471 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 472 | err_code |= ERR_ALERT; |
| 473 | goto out; |
| 474 | } |
| 475 | if (*(args[1]) == 0) { |
| 476 | Alert("parsing [%s:%d] : '%s' expects a directory path as an argument.\n", file, linenum, args[0]); |
| 477 | err_code |= ERR_ALERT | ERR_FATAL; |
| 478 | goto out; |
| 479 | } |
| 480 | global.ca_base = strdup(args[1]); |
| 481 | #else |
| 482 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 483 | err_code |= ERR_ALERT | ERR_FATAL; |
| 484 | goto out; |
| 485 | #endif |
| 486 | } |
| 487 | else if (!strcmp(args[0], "crt-base")) { |
| 488 | #ifdef USE_OPENSSL |
| 489 | if (global.crt_base != NULL) { |
| 490 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 491 | err_code |= ERR_ALERT; |
| 492 | goto out; |
| 493 | } |
| 494 | if (*(args[1]) == 0) { |
| 495 | Alert("parsing [%s:%d] : '%s' expects a directory path as an argument.\n", file, linenum, args[0]); |
| 496 | err_code |= ERR_ALERT | ERR_FATAL; |
| 497 | goto out; |
| 498 | } |
| 499 | global.crt_base = strdup(args[1]); |
| 500 | #else |
| 501 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 502 | err_code |= ERR_ALERT | ERR_FATAL; |
| 503 | goto out; |
| 504 | #endif |
| 505 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 506 | else if (!strcmp(args[0], "daemon")) { |
| 507 | global.mode |= MODE_DAEMON; |
| 508 | } |
| 509 | else if (!strcmp(args[0], "debug")) { |
| 510 | global.mode |= MODE_DEBUG; |
| 511 | } |
| 512 | else if (!strcmp(args[0], "noepoll")) { |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 513 | global.tune.options &= ~GTUNE_USE_EPOLL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 514 | } |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 515 | else if (!strcmp(args[0], "nosepoll")) { |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 516 | global.tune.options &= ~GTUNE_USE_SEPOLL; |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 517 | } |
| 518 | else if (!strcmp(args[0], "nokqueue")) { |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 519 | global.tune.options &= ~GTUNE_USE_KQUEUE; |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 520 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 521 | else if (!strcmp(args[0], "nopoll")) { |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 522 | global.tune.options &= ~GTUNE_USE_POLL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 523 | } |
Willy Tarreau | 3ab68cf | 2009-01-25 16:03:28 +0100 | [diff] [blame] | 524 | else if (!strcmp(args[0], "nosplice")) { |
| 525 | global.tune.options &= ~GTUNE_USE_SPLICE; |
| 526 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 527 | else if (!strcmp(args[0], "quiet")) { |
| 528 | global.mode |= MODE_QUIET; |
| 529 | } |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 530 | else if (!strcmp(args[0], "tune.maxpollevents")) { |
| 531 | if (global.tune.maxpollevents != 0) { |
| 532 | 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] | 533 | err_code |= ERR_ALERT; |
| 534 | goto out; |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 535 | } |
| 536 | if (*(args[1]) == 0) { |
| 537 | 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] | 538 | err_code |= ERR_ALERT | ERR_FATAL; |
| 539 | goto out; |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 540 | } |
| 541 | global.tune.maxpollevents = atol(args[1]); |
| 542 | } |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 543 | else if (!strcmp(args[0], "tune.maxaccept")) { |
| 544 | if (global.tune.maxaccept != 0) { |
| 545 | 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] | 546 | err_code |= ERR_ALERT; |
| 547 | goto out; |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 548 | } |
| 549 | if (*(args[1]) == 0) { |
| 550 | 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] | 551 | err_code |= ERR_ALERT | ERR_FATAL; |
| 552 | goto out; |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 553 | } |
| 554 | global.tune.maxaccept = atol(args[1]); |
| 555 | } |
Willy Tarreau | 43961d5 | 2010-10-04 20:39:20 +0200 | [diff] [blame] | 556 | else if (!strcmp(args[0], "tune.chksize")) { |
| 557 | if (*(args[1]) == 0) { |
| 558 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 559 | err_code |= ERR_ALERT | ERR_FATAL; |
| 560 | goto out; |
| 561 | } |
| 562 | global.tune.chksize = atol(args[1]); |
| 563 | } |
Emeric Brun | fc32aca | 2012-09-03 12:10:29 +0200 | [diff] [blame] | 564 | #ifdef USE_OPENSSL |
| 565 | else if (!strcmp(args[0], "tune.sslcachesize")) { |
| 566 | if (*(args[1]) == 0) { |
| 567 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 568 | err_code |= ERR_ALERT | ERR_FATAL; |
| 569 | goto out; |
| 570 | } |
| 571 | global.tune.sslcachesize = atol(args[1]); |
| 572 | } |
| 573 | #endif |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 574 | else if (!strcmp(args[0], "tune.bufsize")) { |
| 575 | if (*(args[1]) == 0) { |
| 576 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 577 | err_code |= ERR_ALERT | ERR_FATAL; |
| 578 | goto out; |
| 579 | } |
| 580 | global.tune.bufsize = atol(args[1]); |
| 581 | if (global.tune.maxrewrite >= global.tune.bufsize / 2) |
| 582 | global.tune.maxrewrite = global.tune.bufsize / 2; |
David du Colombier | 7af4605 | 2012-05-16 14:16:48 +0200 | [diff] [blame] | 583 | trashlen = global.tune.bufsize; |
| 584 | trash = realloc(trash, trashlen); |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 585 | } |
| 586 | else if (!strcmp(args[0], "tune.maxrewrite")) { |
| 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.maxrewrite = atol(args[1]); |
| 593 | if (global.tune.maxrewrite >= global.tune.bufsize / 2) |
| 594 | global.tune.maxrewrite = global.tune.bufsize / 2; |
| 595 | } |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 596 | else if (!strcmp(args[0], "tune.rcvbuf.client")) { |
| 597 | if (global.tune.client_rcvbuf != 0) { |
| 598 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 599 | err_code |= ERR_ALERT; |
| 600 | goto out; |
| 601 | } |
| 602 | if (*(args[1]) == 0) { |
| 603 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 604 | err_code |= ERR_ALERT | ERR_FATAL; |
| 605 | goto out; |
| 606 | } |
| 607 | global.tune.client_rcvbuf = atol(args[1]); |
| 608 | } |
| 609 | else if (!strcmp(args[0], "tune.rcvbuf.server")) { |
| 610 | if (global.tune.server_rcvbuf != 0) { |
| 611 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 612 | err_code |= ERR_ALERT; |
| 613 | goto out; |
| 614 | } |
| 615 | if (*(args[1]) == 0) { |
| 616 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 617 | err_code |= ERR_ALERT | ERR_FATAL; |
| 618 | goto out; |
| 619 | } |
| 620 | global.tune.server_rcvbuf = atol(args[1]); |
| 621 | } |
| 622 | else if (!strcmp(args[0], "tune.sndbuf.client")) { |
| 623 | if (global.tune.client_sndbuf != 0) { |
| 624 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 625 | err_code |= ERR_ALERT; |
| 626 | goto out; |
| 627 | } |
| 628 | if (*(args[1]) == 0) { |
| 629 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 630 | err_code |= ERR_ALERT | ERR_FATAL; |
| 631 | goto out; |
| 632 | } |
| 633 | global.tune.client_sndbuf = atol(args[1]); |
| 634 | } |
| 635 | else if (!strcmp(args[0], "tune.sndbuf.server")) { |
| 636 | if (global.tune.server_sndbuf != 0) { |
| 637 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 638 | err_code |= ERR_ALERT; |
| 639 | goto out; |
| 640 | } |
| 641 | if (*(args[1]) == 0) { |
| 642 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 643 | err_code |= ERR_ALERT | ERR_FATAL; |
| 644 | goto out; |
| 645 | } |
| 646 | global.tune.server_sndbuf = atol(args[1]); |
| 647 | } |
Willy Tarreau | bd9a0a7 | 2011-10-23 21:14:29 +0200 | [diff] [blame] | 648 | else if (!strcmp(args[0], "tune.pipesize")) { |
| 649 | if (*(args[1]) == 0) { |
| 650 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 651 | err_code |= ERR_ALERT | ERR_FATAL; |
| 652 | goto out; |
| 653 | } |
| 654 | global.tune.pipesize = atol(args[1]); |
| 655 | } |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame] | 656 | else if (!strcmp(args[0], "tune.http.maxhdr")) { |
| 657 | if (*(args[1]) == 0) { |
| 658 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 659 | err_code |= ERR_ALERT | ERR_FATAL; |
| 660 | goto out; |
| 661 | } |
| 662 | global.tune.max_http_hdr = atol(args[1]); |
| 663 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 664 | else if (!strcmp(args[0], "uid")) { |
| 665 | if (global.uid != 0) { |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 666 | Alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 667 | err_code |= ERR_ALERT; |
| 668 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 669 | } |
| 670 | if (*(args[1]) == 0) { |
| 671 | 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] | 672 | err_code |= ERR_ALERT | ERR_FATAL; |
| 673 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 674 | } |
| 675 | global.uid = atol(args[1]); |
| 676 | } |
| 677 | else if (!strcmp(args[0], "gid")) { |
| 678 | if (global.gid != 0) { |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 679 | Alert("parsing [%s:%d] : group/gid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 680 | err_code |= ERR_ALERT; |
| 681 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 682 | } |
| 683 | if (*(args[1]) == 0) { |
| 684 | 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] | 685 | err_code |= ERR_ALERT | ERR_FATAL; |
| 686 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 687 | } |
| 688 | global.gid = atol(args[1]); |
| 689 | } |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 690 | /* user/group name handling */ |
| 691 | else if (!strcmp(args[0], "user")) { |
| 692 | struct passwd *ha_user; |
| 693 | if (global.uid != 0) { |
| 694 | Alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 695 | err_code |= ERR_ALERT; |
| 696 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 697 | } |
| 698 | errno = 0; |
| 699 | ha_user = getpwnam(args[1]); |
| 700 | if (ha_user != NULL) { |
| 701 | global.uid = (int)ha_user->pw_uid; |
| 702 | } |
| 703 | else { |
| 704 | 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] | 705 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 706 | } |
| 707 | } |
| 708 | else if (!strcmp(args[0], "group")) { |
| 709 | struct group *ha_group; |
| 710 | if (global.gid != 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 711 | 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] | 712 | err_code |= ERR_ALERT; |
| 713 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 714 | } |
| 715 | errno = 0; |
| 716 | ha_group = getgrnam(args[1]); |
| 717 | if (ha_group != NULL) { |
| 718 | global.gid = (int)ha_group->gr_gid; |
| 719 | } |
| 720 | else { |
| 721 | 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] | 722 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 723 | } |
| 724 | } |
| 725 | /* end of user/group name handling*/ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 726 | else if (!strcmp(args[0], "nbproc")) { |
| 727 | if (global.nbproc != 0) { |
| 728 | 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] | 729 | err_code |= ERR_ALERT; |
| 730 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 731 | } |
| 732 | if (*(args[1]) == 0) { |
| 733 | 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] | 734 | err_code |= ERR_ALERT | ERR_FATAL; |
| 735 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 736 | } |
| 737 | global.nbproc = atol(args[1]); |
| 738 | } |
| 739 | else if (!strcmp(args[0], "maxconn")) { |
| 740 | if (global.maxconn != 0) { |
| 741 | 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] | 742 | err_code |= ERR_ALERT; |
| 743 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 744 | } |
| 745 | if (*(args[1]) == 0) { |
| 746 | 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] | 747 | err_code |= ERR_ALERT | ERR_FATAL; |
| 748 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 749 | } |
| 750 | global.maxconn = atol(args[1]); |
| 751 | #ifdef SYSTEM_MAXCONN |
| 752 | if (global.maxconn > DEFAULT_MAXCONN && cfg_maxconn <= DEFAULT_MAXCONN) { |
| 753 | 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); |
| 754 | global.maxconn = DEFAULT_MAXCONN; |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 755 | err_code |= ERR_ALERT; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 756 | } |
| 757 | #endif /* SYSTEM_MAXCONN */ |
| 758 | } |
Willy Tarreau | 403edff | 2012-09-06 11:58:37 +0200 | [diff] [blame] | 759 | else if (!strcmp(args[0], "maxsslconn")) { |
| 760 | #ifdef USE_OPENSSL |
| 761 | if (*(args[1]) == 0) { |
| 762 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 763 | err_code |= ERR_ALERT | ERR_FATAL; |
| 764 | goto out; |
| 765 | } |
| 766 | global.maxsslconn = atol(args[1]); |
| 767 | #else |
Emeric Brun | 0914df8 | 2012-10-02 18:45:42 +0200 | [diff] [blame] | 768 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 769 | err_code |= ERR_ALERT | ERR_FATAL; |
| 770 | goto out; |
Willy Tarreau | 403edff | 2012-09-06 11:58:37 +0200 | [diff] [blame] | 771 | #endif |
| 772 | } |
Willy Tarreau | 81c25d0 | 2011-09-07 15:17:21 +0200 | [diff] [blame] | 773 | else if (!strcmp(args[0], "maxconnrate")) { |
| 774 | if (global.cps_lim != 0) { |
| 775 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 776 | err_code |= ERR_ALERT; |
| 777 | goto out; |
| 778 | } |
| 779 | if (*(args[1]) == 0) { |
| 780 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 781 | err_code |= ERR_ALERT | ERR_FATAL; |
| 782 | goto out; |
| 783 | } |
| 784 | global.cps_lim = atol(args[1]); |
| 785 | } |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 786 | else if (!strcmp(args[0], "maxpipes")) { |
| 787 | if (global.maxpipes != 0) { |
| 788 | 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] | 789 | err_code |= ERR_ALERT; |
| 790 | goto out; |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 791 | } |
| 792 | if (*(args[1]) == 0) { |
| 793 | 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] | 794 | err_code |= ERR_ALERT | ERR_FATAL; |
| 795 | goto out; |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 796 | } |
| 797 | global.maxpipes = atol(args[1]); |
| 798 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 799 | else if (!strcmp(args[0], "ulimit-n")) { |
| 800 | if (global.rlimit_nofile != 0) { |
| 801 | 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] | 802 | err_code |= ERR_ALERT; |
| 803 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 804 | } |
| 805 | if (*(args[1]) == 0) { |
| 806 | 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] | 807 | err_code |= ERR_ALERT | ERR_FATAL; |
| 808 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 809 | } |
| 810 | global.rlimit_nofile = atol(args[1]); |
| 811 | } |
| 812 | else if (!strcmp(args[0], "chroot")) { |
| 813 | if (global.chroot != NULL) { |
| 814 | 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] | 815 | err_code |= ERR_ALERT; |
| 816 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 817 | } |
| 818 | if (*(args[1]) == 0) { |
| 819 | 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] | 820 | err_code |= ERR_ALERT | ERR_FATAL; |
| 821 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 822 | } |
| 823 | global.chroot = strdup(args[1]); |
| 824 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 825 | else if (!strcmp(args[0], "description")) { |
| 826 | int i, len=0; |
| 827 | char *d; |
| 828 | |
| 829 | if (!*args[1]) { |
| 830 | Alert("parsing [%s:%d]: '%s' expects a string argument.\n", |
| 831 | file, linenum, args[0]); |
| 832 | err_code |= ERR_ALERT | ERR_FATAL; |
| 833 | goto out; |
| 834 | } |
| 835 | |
| 836 | for(i=1; *args[i]; i++) |
| 837 | len += strlen(args[i])+1; |
| 838 | |
| 839 | if (global.desc) |
| 840 | free(global.desc); |
| 841 | |
| 842 | global.desc = d = (char *)calloc(1, len); |
| 843 | |
| 844 | d += sprintf(d, "%s", args[1]); |
| 845 | for(i=2; *args[i]; i++) |
| 846 | d += sprintf(d, " %s", args[i]); |
| 847 | } |
| 848 | else if (!strcmp(args[0], "node")) { |
| 849 | int i; |
| 850 | char c; |
| 851 | |
| 852 | for (i=0; args[1][i]; i++) { |
| 853 | c = args[1][i]; |
Willy Tarreau | 88e0581 | 2010-03-03 00:16:00 +0100 | [diff] [blame] | 854 | if (!isupper((unsigned char)c) && !islower((unsigned char)c) && |
| 855 | !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.') |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 856 | break; |
| 857 | } |
| 858 | |
| 859 | if (!i || args[1][i]) { |
| 860 | Alert("parsing [%s:%d]: '%s' requires valid node name - non-empty string" |
| 861 | " with digits(0-9), letters(A-Z, a-z), dot(.), hyphen(-) or underscode(_).\n", |
| 862 | file, linenum, args[0]); |
| 863 | err_code |= ERR_ALERT | ERR_FATAL; |
| 864 | goto out; |
| 865 | } |
| 866 | |
| 867 | if (global.node) |
| 868 | free(global.node); |
| 869 | |
| 870 | global.node = strdup(args[1]); |
| 871 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 872 | else if (!strcmp(args[0], "pidfile")) { |
| 873 | if (global.pidfile != NULL) { |
| 874 | 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] | 875 | err_code |= ERR_ALERT; |
| 876 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 877 | } |
| 878 | if (*(args[1]) == 0) { |
| 879 | 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] | 880 | err_code |= ERR_ALERT | ERR_FATAL; |
| 881 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 882 | } |
| 883 | global.pidfile = strdup(args[1]); |
| 884 | } |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 885 | else if (!strcmp(args[0], "unix-bind")) { |
| 886 | int cur_arg = 1; |
| 887 | while (*(args[cur_arg])) { |
| 888 | if (!strcmp(args[cur_arg], "prefix")) { |
| 889 | if (global.unix_bind.prefix != NULL) { |
| 890 | Alert("parsing [%s:%d] : unix-bind '%s' already specified. Continuing.\n", file, linenum, args[cur_arg]); |
| 891 | err_code |= ERR_ALERT; |
| 892 | cur_arg += 2; |
| 893 | continue; |
| 894 | } |
| 895 | |
| 896 | if (*(args[cur_arg+1]) == 0) { |
| 897 | Alert("parsing [%s:%d] : unix_bind '%s' expects a path as an argument.\n", file, linenum, args[cur_arg]); |
| 898 | err_code |= ERR_ALERT | ERR_FATAL; |
| 899 | goto out; |
| 900 | } |
| 901 | global.unix_bind.prefix = strdup(args[cur_arg+1]); |
| 902 | cur_arg += 2; |
| 903 | continue; |
| 904 | } |
| 905 | |
| 906 | if (!strcmp(args[cur_arg], "mode")) { |
| 907 | |
| 908 | global.unix_bind.ux.mode = strtol(args[cur_arg + 1], NULL, 8); |
| 909 | cur_arg += 2; |
| 910 | continue; |
| 911 | } |
| 912 | |
| 913 | if (!strcmp(args[cur_arg], "uid")) { |
| 914 | |
| 915 | global.unix_bind.ux.uid = atol(args[cur_arg + 1 ]); |
| 916 | cur_arg += 2; |
| 917 | continue; |
| 918 | } |
| 919 | |
| 920 | if (!strcmp(args[cur_arg], "gid")) { |
| 921 | |
| 922 | global.unix_bind.ux.gid = atol(args[cur_arg + 1 ]); |
| 923 | cur_arg += 2; |
| 924 | continue; |
| 925 | } |
| 926 | |
| 927 | if (!strcmp(args[cur_arg], "user")) { |
| 928 | struct passwd *user; |
| 929 | |
| 930 | user = getpwnam(args[cur_arg + 1]); |
| 931 | if (!user) { |
| 932 | Alert("parsing [%s:%d] : '%s' : '%s' unknown user.\n", |
| 933 | file, linenum, args[0], args[cur_arg + 1 ]); |
| 934 | err_code |= ERR_ALERT | ERR_FATAL; |
| 935 | goto out; |
| 936 | } |
| 937 | |
| 938 | global.unix_bind.ux.uid = user->pw_uid; |
| 939 | cur_arg += 2; |
| 940 | continue; |
| 941 | } |
| 942 | |
| 943 | if (!strcmp(args[cur_arg], "group")) { |
| 944 | struct group *group; |
| 945 | |
| 946 | group = getgrnam(args[cur_arg + 1]); |
| 947 | if (!group) { |
| 948 | Alert("parsing [%s:%d] : '%s' : '%s' unknown group.\n", |
| 949 | file, linenum, args[0], args[cur_arg + 1 ]); |
| 950 | err_code |= ERR_ALERT | ERR_FATAL; |
| 951 | goto out; |
| 952 | } |
| 953 | |
| 954 | global.unix_bind.ux.gid = group->gr_gid; |
| 955 | cur_arg += 2; |
| 956 | continue; |
| 957 | } |
| 958 | |
Willy Tarreau | b48f958 | 2011-09-05 01:17:06 +0200 | [diff] [blame] | 959 | 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] | 960 | file, linenum, args[0]); |
| 961 | err_code |= ERR_ALERT | ERR_FATAL; |
| 962 | goto out; |
| 963 | } |
| 964 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 965 | else if (!strcmp(args[0], "log") && kwm == KWM_NO) { /* no log */ |
| 966 | /* delete previous herited or defined syslog servers */ |
| 967 | struct logsrv *back; |
| 968 | struct logsrv *tmp; |
| 969 | |
| 970 | if (*(args[1]) != 0) { |
| 971 | Alert("parsing [%s:%d]:%s : 'no log' does not expect arguments.\n", file, linenum, args[1]); |
| 972 | err_code |= ERR_ALERT | ERR_FATAL; |
| 973 | goto out; |
| 974 | } |
| 975 | |
| 976 | list_for_each_entry_safe(tmp, back, &global.logsrvs, list) { |
| 977 | LIST_DEL(&tmp->list); |
| 978 | free(tmp); |
| 979 | } |
| 980 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 981 | else if (!strcmp(args[0], "log")) { /* syslog server address */ |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 982 | struct logsrv *logsrv; |
| 983 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 984 | if (*(args[1]) == 0 || *(args[2]) == 0) { |
| 985 | 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] | 986 | err_code |= ERR_ALERT | ERR_FATAL; |
| 987 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 988 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 989 | |
| 990 | logsrv = calloc(1, sizeof(struct logsrv)); |
| 991 | |
| 992 | logsrv->facility = get_log_facility(args[2]); |
| 993 | if (logsrv->facility < 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 994 | 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] | 995 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 996 | logsrv->facility = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 997 | } |
| 998 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 999 | logsrv->level = 7; /* max syslog level = debug */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1000 | if (*(args[3])) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1001 | logsrv->level = get_log_level(args[3]); |
| 1002 | if (logsrv->level < 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1003 | 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] | 1004 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1005 | logsrv->level = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1006 | } |
| 1007 | } |
| 1008 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1009 | logsrv->minlvl = 0; /* limit syslog level to this level (emerg) */ |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 1010 | if (*(args[4])) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1011 | logsrv->minlvl = get_log_level(args[4]); |
| 1012 | if (logsrv->minlvl < 0) { |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 1013 | 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] | 1014 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1015 | logsrv->minlvl = 0; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 1016 | } |
| 1017 | } |
| 1018 | |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 1019 | if (args[1][0] == '/') { |
David du Colombier | 11bcb6c | 2011-03-24 12:23:00 +0100 | [diff] [blame] | 1020 | struct sockaddr_storage *sk = (struct sockaddr_storage *)str2sun(args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 1021 | if (!sk) { |
| 1022 | 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] | 1023 | args[1], (int)sizeof(((struct sockaddr_un *)&sk)->sun_path) - 1); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 1024 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1025 | free(logsrv); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 1026 | goto out; |
| 1027 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1028 | logsrv->addr = *sk; |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 1029 | } else { |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 1030 | struct sockaddr_storage *sk = str2sa(args[1]); |
David du Colombier | 11bcb6c | 2011-03-24 12:23:00 +0100 | [diff] [blame] | 1031 | if (!sk) { |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 1032 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[1]); |
| 1033 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1034 | free(logsrv); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 1035 | goto out; |
| 1036 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1037 | logsrv->addr = *sk; |
| 1038 | if (!get_host_port(&logsrv->addr)) |
| 1039 | set_host_port(&logsrv->addr, SYSLOG_PORT); |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 1040 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1041 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1042 | LIST_ADDQ(&global.logsrvs, &logsrv->list); |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1043 | } |
Joe Williams | df5b38f | 2010-12-29 17:05:48 +0100 | [diff] [blame] | 1044 | else if (!strcmp(args[0], "log-send-hostname")) { /* set the hostname in syslog header */ |
| 1045 | char *name; |
| 1046 | int len; |
| 1047 | |
| 1048 | if (global.log_send_hostname != NULL) { |
| 1049 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 1050 | err_code |= ERR_ALERT; |
| 1051 | goto out; |
| 1052 | } |
| 1053 | |
| 1054 | if (*(args[1])) |
| 1055 | name = args[1]; |
| 1056 | else |
| 1057 | name = hostname; |
| 1058 | |
| 1059 | len = strlen(name); |
| 1060 | |
| 1061 | /* We'll add a space after the name to respect the log format */ |
| 1062 | free(global.log_send_hostname); |
| 1063 | global.log_send_hostname = malloc(len + 2); |
| 1064 | snprintf(global.log_send_hostname, len + 2, "%s ", name); |
| 1065 | } |
Kevinm | 48936af | 2010-12-22 16:08:21 +0000 | [diff] [blame] | 1066 | else if (!strcmp(args[0], "log-tag")) { /* tag to report to syslog */ |
| 1067 | if (*(args[1]) == 0) { |
| 1068 | Alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]); |
| 1069 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1070 | goto out; |
| 1071 | } |
| 1072 | free(global.log_tag); |
| 1073 | global.log_tag = strdup(args[1]); |
| 1074 | } |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1075 | else if (!strcmp(args[0], "spread-checks")) { /* random time between checks (0-50) */ |
| 1076 | if (global.spread_checks != 0) { |
| 1077 | Alert("parsing [%s:%d]: spread-checks already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1078 | err_code |= ERR_ALERT; |
| 1079 | goto out; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1080 | } |
| 1081 | if (*(args[1]) == 0) { |
| 1082 | 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] | 1083 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1084 | goto out; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1085 | } |
| 1086 | global.spread_checks = atol(args[1]); |
| 1087 | if (global.spread_checks < 0 || global.spread_checks > 50) { |
| 1088 | 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] | 1089 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1090 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1091 | } |
| 1092 | else { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1093 | struct cfg_kw_list *kwl; |
| 1094 | int index; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1095 | int rc; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1096 | |
| 1097 | list_for_each_entry(kwl, &cfg_keywords.list, list) { |
| 1098 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 1099 | if (kwl->kw[index].section != CFG_GLOBAL) |
| 1100 | continue; |
| 1101 | if (strcmp(kwl->kw[index].kw, args[0]) == 0) { |
| 1102 | /* prepare error message just in case */ |
David du Colombier | 7af4605 | 2012-05-16 14:16:48 +0200 | [diff] [blame] | 1103 | snprintf(trash, trashlen, |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1104 | "error near '%s' in '%s' section", args[0], "global"); |
Willy Tarreau | 28a47d6 | 2012-09-18 20:02:48 +0200 | [diff] [blame] | 1105 | rc = kwl->kw[index].parse(args, CFG_GLOBAL, NULL, NULL, file, linenum, &errmsg); |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1106 | if (rc < 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 1107 | Alert("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1108 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1109 | } |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1110 | else if (rc > 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 1111 | Warning("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1112 | err_code |= ERR_WARN; |
| 1113 | goto out; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1114 | } |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1115 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1116 | } |
| 1117 | } |
| 1118 | } |
| 1119 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1120 | 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] | 1121 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1122 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1123 | |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1124 | out: |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 1125 | free(errmsg); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1126 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1127 | } |
| 1128 | |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 1129 | void init_default_instance() |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1130 | { |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 1131 | init_new_proxy(&defproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1132 | defproxy.mode = PR_MODE_TCP; |
| 1133 | defproxy.state = PR_STNEW; |
| 1134 | defproxy.maxconn = cfg_maxpconn; |
| 1135 | defproxy.conn_retries = CONN_RETRIES; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1136 | |
| 1137 | defproxy.defsrv.inter = DEF_CHKINTR; |
| 1138 | defproxy.defsrv.fastinter = 0; |
| 1139 | defproxy.defsrv.downinter = 0; |
| 1140 | defproxy.defsrv.rise = DEF_RISETIME; |
| 1141 | defproxy.defsrv.fall = DEF_FALLTIME; |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 1142 | defproxy.defsrv.check.port = 0; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1143 | defproxy.defsrv.maxqueue = 0; |
| 1144 | defproxy.defsrv.minconn = 0; |
| 1145 | defproxy.defsrv.maxconn = 0; |
| 1146 | defproxy.defsrv.slowstart = 0; |
| 1147 | defproxy.defsrv.onerror = DEF_HANA_ONERR; |
| 1148 | defproxy.defsrv.consecutive_errors_limit = DEF_HANA_ERRLIMIT; |
| 1149 | defproxy.defsrv.uweight = defproxy.defsrv.iweight = 1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1150 | } |
| 1151 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1152 | |
| 1153 | static int create_cond_regex_rule(const char *file, int line, |
| 1154 | struct proxy *px, int dir, int action, int flags, |
| 1155 | const char *cmd, const char *reg, const char *repl, |
| 1156 | const char **cond_start) |
| 1157 | { |
| 1158 | regex_t *preg = NULL; |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 1159 | char *errmsg = NULL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1160 | const char *err; |
| 1161 | int err_code = 0; |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1162 | struct acl_cond *cond = NULL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1163 | |
| 1164 | if (px == &defproxy) { |
| 1165 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, line, cmd); |
| 1166 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1167 | goto err; |
| 1168 | } |
| 1169 | |
| 1170 | if (*reg == 0) { |
| 1171 | Alert("parsing [%s:%d] : '%s' expects <regex> as an argument.\n", file, line, cmd); |
| 1172 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1173 | goto err; |
| 1174 | } |
| 1175 | |
| 1176 | if (warnifnotcap(px, PR_CAP_RS, file, line, cmd, NULL)) |
| 1177 | err_code |= ERR_WARN; |
| 1178 | |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1179 | if (cond_start && |
| 1180 | (strcmp(*cond_start, "if") == 0 || strcmp(*cond_start, "unless") == 0)) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 1181 | if ((cond = build_acl_cond(file, line, px, cond_start, &errmsg)) == NULL) { |
| 1182 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 1183 | file, line, cmd, errmsg); |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1184 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1185 | goto err; |
| 1186 | } |
| 1187 | } |
| 1188 | else if (cond_start && **cond_start) { |
| 1189 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 1190 | file, line, cmd, *cond_start); |
| 1191 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1192 | goto err; |
| 1193 | } |
| 1194 | |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 1195 | if (dir == SMP_OPT_DIR_REQ) |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1196 | err_code |= warnif_cond_requires_resp(cond, file, line); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 1197 | else |
| 1198 | err_code |= warnif_cond_requires_req(cond, file, line); |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1199 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1200 | preg = calloc(1, sizeof(regex_t)); |
| 1201 | if (!preg) { |
| 1202 | Alert("parsing [%s:%d] : '%s' : not enough memory to build regex.\n", file, line, cmd); |
| 1203 | err_code = ERR_ALERT | ERR_FATAL; |
| 1204 | goto err; |
| 1205 | } |
| 1206 | |
| 1207 | if (regcomp(preg, reg, REG_EXTENDED | flags) != 0) { |
| 1208 | Alert("parsing [%s:%d] : '%s' : bad regular expression '%s'.\n", file, line, cmd, reg); |
| 1209 | err_code = ERR_ALERT | ERR_FATAL; |
| 1210 | goto err; |
| 1211 | } |
| 1212 | |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 1213 | 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] | 1214 | preg, action, repl ? strdup(repl) : NULL, cond); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1215 | if (repl && err) { |
| 1216 | Alert("parsing [%s:%d] : '%s' : invalid character or unterminated sequence in replacement string near '%c'.\n", |
| 1217 | file, line, cmd, *err); |
| 1218 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1219 | goto err; |
| 1220 | } |
| 1221 | |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 1222 | 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] | 1223 | err_code |= ERR_WARN; |
| 1224 | |
Willy Tarreau | f4068b6 | 2012-05-08 17:37:49 +0200 | [diff] [blame] | 1225 | free(errmsg); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1226 | return err_code; |
| 1227 | err: |
Willy Tarreau | f4068b6 | 2012-05-08 17:37:49 +0200 | [diff] [blame] | 1228 | free(errmsg); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1229 | free(preg); |
| 1230 | return err_code; |
| 1231 | } |
| 1232 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1233 | /* |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1234 | * Parse a line in a <listen>, <frontend>, <backend> or <ruleset> section. |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1235 | * Returns the error code, 0 if OK, or any combination of : |
| 1236 | * - ERR_ABORT: must abort ASAP |
| 1237 | * - ERR_FATAL: we can continue parsing but not start the service |
| 1238 | * - ERR_WARN: a warning has been emitted |
| 1239 | * - ERR_ALERT: an alert has been emitted |
| 1240 | * Only the two first ones can stop processing, the two others are just |
| 1241 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1242 | */ |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1243 | int cfg_parse_peers(const char *file, int linenum, char **args, int kwm) |
| 1244 | { |
| 1245 | static struct peers *curpeers = NULL; |
| 1246 | struct peer *newpeer = NULL; |
| 1247 | const char *err; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1248 | struct bind_conf *bind_conf; |
| 1249 | struct listener *l; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1250 | int err_code = 0; |
| 1251 | |
| 1252 | if (strcmp(args[0], "peers") == 0) { /* new peers section */ |
| 1253 | |
| 1254 | err = invalid_char(args[1]); |
| 1255 | if (err) { |
| 1256 | Alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 1257 | file, linenum, *err, args[0], args[1]); |
| 1258 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1259 | } |
| 1260 | |
| 1261 | for (curpeers = peers; curpeers != NULL; curpeers = curpeers->next) { |
| 1262 | /* |
| 1263 | * If there are two proxies with the same name only following |
| 1264 | * combinations are allowed: |
| 1265 | */ |
| 1266 | if (strcmp(curpeers->id, args[1]) == 0) { |
| 1267 | Warning("Parsing [%s:%d]: peers '%s' has same name as another peers (declared at %s:%d).\n", |
| 1268 | file, linenum, args[1], curpeers->conf.file, curpeers->conf.line); |
| 1269 | err_code |= ERR_WARN; |
| 1270 | } |
| 1271 | } |
| 1272 | |
| 1273 | if ((curpeers = (struct peers *)calloc(1, sizeof(struct peers))) == NULL) { |
| 1274 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1275 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1276 | goto out; |
| 1277 | } |
| 1278 | |
| 1279 | curpeers->next = peers; |
| 1280 | peers = curpeers; |
Willy Tarreau | 8113a5d | 2012-10-04 08:01:43 +0200 | [diff] [blame] | 1281 | curpeers->conf.file = strdup(file); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1282 | curpeers->conf.line = linenum; |
| 1283 | curpeers->last_change = now.tv_sec; |
| 1284 | curpeers->id = strdup(args[1]); |
| 1285 | } |
| 1286 | else if (strcmp(args[0], "peer") == 0) { /* peer definition */ |
| 1287 | char *rport, *raddr; |
| 1288 | short realport = 0; |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 1289 | struct sockaddr_storage *sk; |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 1290 | char *err_msg = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1291 | |
| 1292 | if (!*args[2]) { |
| 1293 | Alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n", |
| 1294 | file, linenum, args[0]); |
| 1295 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1296 | goto out; |
| 1297 | } |
| 1298 | |
| 1299 | err = invalid_char(args[1]); |
| 1300 | if (err) { |
| 1301 | Alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n", |
| 1302 | file, linenum, *err, args[1]); |
| 1303 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1304 | goto out; |
| 1305 | } |
| 1306 | |
| 1307 | if ((newpeer = (struct peer *)calloc(1, sizeof(struct peer))) == NULL) { |
| 1308 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1309 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1310 | goto out; |
| 1311 | } |
| 1312 | |
| 1313 | /* the peers are linked backwards first */ |
| 1314 | curpeers->count++; |
| 1315 | newpeer->next = curpeers->remote; |
| 1316 | curpeers->remote = newpeer; |
| 1317 | newpeer->peers = curpeers; |
Willy Tarreau | 8113a5d | 2012-10-04 08:01:43 +0200 | [diff] [blame] | 1318 | newpeer->conf.file = strdup(file); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1319 | newpeer->conf.line = linenum; |
| 1320 | |
| 1321 | newpeer->last_change = now.tv_sec; |
| 1322 | newpeer->id = strdup(args[1]); |
| 1323 | |
| 1324 | raddr = strdup(args[2]); |
Willy Tarreau | fab5a43 | 2011-03-04 15:31:53 +0100 | [diff] [blame] | 1325 | rport = strrchr(raddr, ':'); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1326 | if (rport) { |
| 1327 | *rport++ = 0; |
| 1328 | realport = atol(rport); |
| 1329 | } |
| 1330 | if (!realport) { |
| 1331 | Alert("parsing [%s:%d] : Missing or invalid port in '%s'\n", file, linenum, args[2]); |
| 1332 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1333 | goto out; |
| 1334 | } |
| 1335 | |
Willy Tarreau | fab5a43 | 2011-03-04 15:31:53 +0100 | [diff] [blame] | 1336 | sk = str2ip(raddr); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1337 | free(raddr); |
| 1338 | if (!sk) { |
| 1339 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[2]); |
| 1340 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1341 | goto out; |
| 1342 | } |
| 1343 | newpeer->addr = *sk; |
Willy Tarreau | 26d8c59 | 2012-05-07 18:12:14 +0200 | [diff] [blame] | 1344 | newpeer->proto = protocol_by_family(newpeer->addr.ss_family); |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 1345 | newpeer->xprt = &raw_sock; |
Willy Tarreau | d02394b | 2012-05-11 18:32:18 +0200 | [diff] [blame] | 1346 | newpeer->sock_init_arg = NULL; |
Willy Tarreau | 26d8c59 | 2012-05-07 18:12:14 +0200 | [diff] [blame] | 1347 | |
Willy Tarreau | 173e7fb | 2012-09-24 22:47:39 +0200 | [diff] [blame] | 1348 | if (!newpeer->proto) { |
Willy Tarreau | 26d8c59 | 2012-05-07 18:12:14 +0200 | [diff] [blame] | 1349 | Alert("parsing [%s:%d] : Unknown protocol family %d '%s'\n", |
| 1350 | file, linenum, newpeer->addr.ss_family, args[2]); |
| 1351 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1352 | goto out; |
| 1353 | } |
| 1354 | |
Willy Tarreau | 86ad42c | 2011-08-27 12:29:07 +0200 | [diff] [blame] | 1355 | set_host_port(&newpeer->addr, realport); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1356 | |
| 1357 | if (strcmp(newpeer->id, localpeer) == 0) { |
| 1358 | /* Current is local peer, it define a frontend */ |
| 1359 | newpeer->local = 1; |
| 1360 | |
| 1361 | if (!curpeers->peers_fe) { |
| 1362 | if ((curpeers->peers_fe = calloc(1, sizeof(struct proxy))) == NULL) { |
| 1363 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1364 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1365 | goto out; |
| 1366 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1367 | |
Willy Tarreau | 237250c | 2011-07-29 01:49:03 +0200 | [diff] [blame] | 1368 | init_new_proxy(curpeers->peers_fe); |
| 1369 | curpeers->peers_fe->parent = curpeers; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1370 | |
| 1371 | curpeers->peers_fe->last_change = now.tv_sec; |
| 1372 | curpeers->peers_fe->id = strdup(args[1]); |
| 1373 | curpeers->peers_fe->cap = PR_CAP_FE; |
Willy Tarreau | 3ae65a1 | 2011-09-07 17:40:39 +0200 | [diff] [blame] | 1374 | curpeers->peers_fe->maxconn = 0; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1375 | curpeers->peers_fe->conn_retries = CONN_RETRIES; |
| 1376 | curpeers->peers_fe->timeout.connect = 5000; |
| 1377 | curpeers->peers_fe->accept = peer_accept; |
| 1378 | curpeers->peers_fe->options2 |= PR_O2_INDEPSTR | PR_O2_SMARTCON | PR_O2_SMARTACC; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1379 | |
| 1380 | bind_conf = bind_conf_alloc(&curpeers->peers_fe->conf.bind, file, linenum, args[2]); |
| 1381 | |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 1382 | if (!str2listener(args[2], curpeers->peers_fe, bind_conf, file, linenum, &err_msg)) { |
| 1383 | if (err_msg && *err_msg) { |
| 1384 | indent_msg(&err_msg, 2); |
| 1385 | Alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], err_msg); |
| 1386 | } |
| 1387 | else |
| 1388 | Alert("parsing [%s:%d] : '%s %s' : error encountered while parsing listening address %s.\n", |
| 1389 | file, linenum, args[0], args[1], args[2]); |
| 1390 | free(err_msg); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1391 | err_code |= ERR_FATAL; |
| 1392 | goto out; |
| 1393 | } |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1394 | |
| 1395 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
| 1396 | l->maxconn = ((struct proxy *)curpeers->peers_fe)->maxconn; |
| 1397 | l->backlog = ((struct proxy *)curpeers->peers_fe)->backlog; |
| 1398 | l->timeout = &((struct proxy *)curpeers->peers_fe)->timeout.client; |
| 1399 | l->accept = session_accept; |
| 1400 | l->handler = process_session; |
| 1401 | l->analysers |= ((struct proxy *)curpeers->peers_fe)->fe_req_ana; |
| 1402 | l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */ |
| 1403 | global.maxsock += l->maxconn; |
| 1404 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1405 | } |
| 1406 | } |
| 1407 | } /* neither "peer" nor "peers" */ |
| 1408 | else if (*args[0] != 0) { |
| 1409 | Alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection); |
| 1410 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1411 | goto out; |
| 1412 | } |
| 1413 | |
| 1414 | out: |
| 1415 | return err_code; |
| 1416 | } |
| 1417 | |
| 1418 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 1419 | 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] | 1420 | { |
| 1421 | static struct proxy *curproxy = NULL; |
| 1422 | struct server *newsrv = NULL; |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 1423 | const char *err; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 1424 | int rc; |
| 1425 | unsigned val; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1426 | int err_code = 0; |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 1427 | struct acl_cond *cond = NULL; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 1428 | struct logsrv *tmplogsrv; |
Willy Tarreau | f4068b6 | 2012-05-08 17:37:49 +0200 | [diff] [blame] | 1429 | char *errmsg = NULL; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 1430 | struct bind_conf *bind_conf; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1431 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1432 | if (!strcmp(args[0], "listen")) |
| 1433 | rc = PR_CAP_LISTEN; |
| 1434 | else if (!strcmp(args[0], "frontend")) |
| 1435 | rc = PR_CAP_FE | PR_CAP_RS; |
| 1436 | else if (!strcmp(args[0], "backend")) |
| 1437 | rc = PR_CAP_BE | PR_CAP_RS; |
| 1438 | else if (!strcmp(args[0], "ruleset")) |
| 1439 | rc = PR_CAP_RS; |
| 1440 | else |
| 1441 | rc = PR_CAP_NONE; |
| 1442 | |
| 1443 | if (rc != PR_CAP_NONE) { /* new proxy */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1444 | if (!*args[1]) { |
| 1445 | Alert("parsing [%s:%d] : '%s' expects an <id> argument and\n" |
| 1446 | " optionnally supports [addr1]:port1[-end1]{,[addr]:port[-end]}...\n", |
| 1447 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1448 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1449 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1450 | } |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 1451 | |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 1452 | err = invalid_char(args[1]); |
| 1453 | if (err) { |
| 1454 | Alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 1455 | file, linenum, *err, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1456 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 1457 | } |
| 1458 | |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 1459 | for (curproxy = proxy; curproxy != NULL; curproxy = curproxy->next) { |
| 1460 | /* |
| 1461 | * If there are two proxies with the same name only following |
| 1462 | * combinations are allowed: |
| 1463 | * |
| 1464 | * listen backend frontend ruleset |
| 1465 | * listen - - - - |
| 1466 | * backend - - OK - |
| 1467 | * frontend - OK - - |
| 1468 | * ruleset - - - - |
| 1469 | */ |
| 1470 | |
| 1471 | if (!strcmp(curproxy->id, args[1]) && |
| 1472 | (rc!=(PR_CAP_FE|PR_CAP_RS) || curproxy->cap!=(PR_CAP_BE|PR_CAP_RS)) && |
| 1473 | (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] | 1474 | Warning("Parsing [%s:%d]: %s '%s' has same name as another %s (declared at %s:%d).\n", |
| 1475 | file, linenum, proxy_cap_str(rc), args[1], proxy_type_str(curproxy), |
| 1476 | curproxy->conf.file, curproxy->conf.line); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1477 | err_code |= ERR_WARN; |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 1478 | } |
| 1479 | } |
| 1480 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1481 | if ((curproxy = (struct proxy *)calloc(1, sizeof(struct proxy))) == NULL) { |
| 1482 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1483 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1484 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1485 | } |
Willy Tarreau | 5af24ef | 2009-03-15 15:23:16 +0100 | [diff] [blame] | 1486 | |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 1487 | init_new_proxy(curproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1488 | curproxy->next = proxy; |
| 1489 | proxy = curproxy; |
Willy Tarreau | 8113a5d | 2012-10-04 08:01:43 +0200 | [diff] [blame] | 1490 | curproxy->conf.file = strdup(file); |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 1491 | curproxy->conf.line = linenum; |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 1492 | curproxy->last_change = now.tv_sec; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1493 | curproxy->id = strdup(args[1]); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1494 | curproxy->cap = rc; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1495 | |
| 1496 | /* parse the listener address if any */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1497 | if ((curproxy->cap & PR_CAP_FE) && *args[2]) { |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1498 | struct listener *l; |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 1499 | char *err_msg = NULL; |
Willy Tarreau | 81a8117 | 2012-09-18 20:52:35 +0200 | [diff] [blame] | 1500 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1501 | bind_conf = bind_conf_alloc(&curproxy->conf.bind, file, linenum, args[2]); |
| 1502 | |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 1503 | if (!str2listener(args[2], curproxy, bind_conf, file, linenum, &err_msg)) { |
| 1504 | if (err_msg && *err_msg) { |
| 1505 | indent_msg(&err_msg, 2); |
| 1506 | Alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], err_msg); |
| 1507 | } |
| 1508 | else |
| 1509 | Alert("parsing [%s:%d] : '%s %s' : error encountered while parsing listening address '%s'.\n", |
| 1510 | file, linenum, args[0], args[1], args[2]); |
| 1511 | free(err_msg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1512 | err_code |= ERR_FATAL; |
| 1513 | goto out; |
| 1514 | } |
Willy Tarreau | 81a8117 | 2012-09-18 20:52:35 +0200 | [diff] [blame] | 1515 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1516 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
Willy Tarreau | c8b1109 | 2011-02-16 11:08:57 +0100 | [diff] [blame] | 1517 | global.maxsock++; |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 1518 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1519 | } |
| 1520 | |
| 1521 | /* set default values */ |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1522 | memcpy(&curproxy->defsrv, &defproxy.defsrv, sizeof(curproxy->defsrv)); |
Willy Tarreau | 7016020 | 2010-04-07 16:06:40 +0200 | [diff] [blame] | 1523 | curproxy->defsrv.id = "default-server"; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1524 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1525 | curproxy->state = defproxy.state; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1526 | curproxy->options = defproxy.options; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 1527 | curproxy->options2 = defproxy.options2; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 1528 | curproxy->no_options = defproxy.no_options; |
| 1529 | curproxy->no_options2 = defproxy.no_options2; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 1530 | curproxy->bind_proc = defproxy.bind_proc; |
Willy Tarreau | 3168223 | 2007-11-29 15:38:04 +0100 | [diff] [blame] | 1531 | curproxy->lbprm.algo = defproxy.lbprm.algo; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 1532 | curproxy->except_net = defproxy.except_net; |
| 1533 | curproxy->except_mask = defproxy.except_mask; |
Maik Broemme | 36db02e | 2009-05-08 17:02:07 +0200 | [diff] [blame] | 1534 | curproxy->except_to = defproxy.except_to; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 1535 | curproxy->except_mask_to = defproxy.except_mask_to; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1536 | |
Willy Tarreau | 79f5fe8 | 2008-08-23 08:18:21 +0200 | [diff] [blame] | 1537 | if (defproxy.fwdfor_hdr_len) { |
| 1538 | curproxy->fwdfor_hdr_len = defproxy.fwdfor_hdr_len; |
| 1539 | curproxy->fwdfor_hdr_name = strdup(defproxy.fwdfor_hdr_name); |
| 1540 | } |
| 1541 | |
Willy Tarreau | b86db34 | 2009-11-30 11:50:16 +0100 | [diff] [blame] | 1542 | if (defproxy.orgto_hdr_len) { |
| 1543 | curproxy->orgto_hdr_len = defproxy.orgto_hdr_len; |
| 1544 | curproxy->orgto_hdr_name = strdup(defproxy.orgto_hdr_name); |
| 1545 | } |
| 1546 | |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 1547 | if (defproxy.server_id_hdr_len) { |
| 1548 | curproxy->server_id_hdr_len = defproxy.server_id_hdr_len; |
| 1549 | curproxy->server_id_hdr_name = strdup(defproxy.server_id_hdr_name); |
| 1550 | } |
| 1551 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1552 | if (curproxy->cap & PR_CAP_FE) { |
| 1553 | curproxy->maxconn = defproxy.maxconn; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 1554 | curproxy->backlog = defproxy.backlog; |
Willy Tarreau | 13a34bd | 2009-05-10 18:52:49 +0200 | [diff] [blame] | 1555 | curproxy->fe_sps_lim = defproxy.fe_sps_lim; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1556 | |
| 1557 | /* initialize error relocations */ |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1558 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) |
| 1559 | chunk_dup(&curproxy->errmsg[rc], &defproxy.errmsg[rc]); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1560 | |
| 1561 | curproxy->to_log = defproxy.to_log & ~LW_COOKIE & ~LW_REQHDR & ~ LW_RSPHDR; |
| 1562 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1563 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1564 | if (curproxy->cap & PR_CAP_BE) { |
| 1565 | curproxy->fullconn = defproxy.fullconn; |
| 1566 | curproxy->conn_retries = defproxy.conn_retries; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1567 | |
Willy Tarreau | aa2f389 | 2010-10-22 16:15:31 +0200 | [diff] [blame] | 1568 | if (defproxy.check_req) { |
| 1569 | curproxy->check_req = calloc(1, defproxy.check_len); |
| 1570 | memcpy(curproxy->check_req, defproxy.check_req, defproxy.check_len); |
| 1571 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1572 | curproxy->check_len = defproxy.check_len; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1573 | |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 1574 | if (defproxy.expect_str) { |
| 1575 | curproxy->expect_str = strdup(defproxy.expect_str); |
| 1576 | if (defproxy.expect_regex) { |
| 1577 | /* note: this regex is known to be valid */ |
| 1578 | curproxy->expect_regex = calloc(1, sizeof(regex_t)); |
| 1579 | regcomp(curproxy->expect_regex, defproxy.expect_str, REG_EXTENDED); |
| 1580 | } |
| 1581 | } |
| 1582 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 1583 | curproxy->ck_opts = defproxy.ck_opts; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1584 | if (defproxy.cookie_name) |
| 1585 | curproxy->cookie_name = strdup(defproxy.cookie_name); |
| 1586 | curproxy->cookie_len = defproxy.cookie_len; |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 1587 | if (defproxy.cookie_domain) |
| 1588 | curproxy->cookie_domain = strdup(defproxy.cookie_domain); |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 1589 | |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 1590 | if (defproxy.cookie_maxidle) |
| 1591 | curproxy->cookie_maxidle = defproxy.cookie_maxidle; |
| 1592 | |
| 1593 | if (defproxy.cookie_maxlife) |
| 1594 | curproxy->cookie_maxlife = defproxy.cookie_maxlife; |
| 1595 | |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 1596 | if (defproxy.rdp_cookie_name) |
| 1597 | curproxy->rdp_cookie_name = strdup(defproxy.rdp_cookie_name); |
| 1598 | curproxy->rdp_cookie_len = defproxy.rdp_cookie_len; |
| 1599 | |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 1600 | if (defproxy.url_param_name) |
| 1601 | curproxy->url_param_name = strdup(defproxy.url_param_name); |
| 1602 | curproxy->url_param_len = defproxy.url_param_len; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 1603 | |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 1604 | if (defproxy.hh_name) |
| 1605 | curproxy->hh_name = strdup(defproxy.hh_name); |
| 1606 | curproxy->hh_len = defproxy.hh_len; |
| 1607 | curproxy->hh_match_domain = defproxy.hh_match_domain; |
| 1608 | |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 1609 | if (defproxy.iface_name) |
| 1610 | curproxy->iface_name = strdup(defproxy.iface_name); |
| 1611 | curproxy->iface_len = defproxy.iface_len; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1612 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1613 | |
Willy Tarreau | 3b6b1a9 | 2009-07-23 13:24:23 +0200 | [diff] [blame] | 1614 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1615 | if (defproxy.capture_name) |
| 1616 | curproxy->capture_name = strdup(defproxy.capture_name); |
| 1617 | curproxy->capture_namelen = defproxy.capture_namelen; |
| 1618 | curproxy->capture_len = defproxy.capture_len; |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 1619 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1620 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1621 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 1622 | curproxy->timeout.client = defproxy.timeout.client; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 1623 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | 036fae0 | 2008-01-06 13:24:40 +0100 | [diff] [blame] | 1624 | curproxy->timeout.httpreq = defproxy.timeout.httpreq; |
Willy Tarreau | b16a574 | 2010-01-10 14:46:16 +0100 | [diff] [blame] | 1625 | curproxy->timeout.httpka = defproxy.timeout.httpka; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1626 | curproxy->uri_auth = defproxy.uri_auth; |
| 1627 | curproxy->mon_net = defproxy.mon_net; |
| 1628 | curproxy->mon_mask = defproxy.mon_mask; |
| 1629 | if (defproxy.monitor_uri) |
| 1630 | curproxy->monitor_uri = strdup(defproxy.monitor_uri); |
| 1631 | curproxy->monitor_uri_len = defproxy.monitor_uri_len; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 1632 | if (defproxy.defbe.name) |
| 1633 | curproxy->defbe.name = strdup(defproxy.defbe.name); |
Willy Tarreau | 99a7ca2 | 2012-05-31 19:39:23 +0200 | [diff] [blame] | 1634 | |
| 1635 | /* get either a pointer to the logformat string or a copy of it */ |
| 1636 | curproxy->logformat_string = defproxy.logformat_string; |
| 1637 | if (curproxy->logformat_string && |
| 1638 | curproxy->logformat_string != default_http_log_format && |
| 1639 | curproxy->logformat_string != default_tcp_log_format && |
| 1640 | curproxy->logformat_string != clf_http_log_format) |
| 1641 | curproxy->logformat_string = strdup(curproxy->logformat_string); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1642 | } |
| 1643 | |
| 1644 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 1645 | curproxy->timeout.connect = defproxy.timeout.connect; |
| 1646 | curproxy->timeout.server = defproxy.timeout.server; |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 1647 | curproxy->timeout.check = defproxy.timeout.check; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 1648 | curproxy->timeout.queue = defproxy.timeout.queue; |
Willy Tarreau | 51c9bde | 2008-01-06 13:40:03 +0100 | [diff] [blame] | 1649 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | cd7afc0 | 2009-07-12 10:03:17 +0200 | [diff] [blame] | 1650 | curproxy->timeout.httpreq = defproxy.timeout.httpreq; |
Willy Tarreau | b16a574 | 2010-01-10 14:46:16 +0100 | [diff] [blame] | 1651 | curproxy->timeout.httpka = defproxy.timeout.httpka; |
Willy Tarreau | ce887fd | 2012-05-12 12:50:00 +0200 | [diff] [blame] | 1652 | curproxy->timeout.tunnel = defproxy.timeout.tunnel; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1653 | curproxy->source_addr = defproxy.source_addr; |
| 1654 | } |
| 1655 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1656 | curproxy->mode = defproxy.mode; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1657 | |
| 1658 | /* copy default logsrvs to curproxy */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 1659 | list_for_each_entry(tmplogsrv, &defproxy.logsrvs, list) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1660 | struct logsrv *node = malloc(sizeof(struct logsrv)); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 1661 | memcpy(node, tmplogsrv, sizeof(struct logsrv)); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1662 | LIST_INIT(&node->list); |
| 1663 | LIST_ADDQ(&curproxy->logsrvs, &node->list); |
| 1664 | } |
| 1665 | |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 1666 | curproxy->uniqueid_format_string = defproxy.uniqueid_format_string; |
| 1667 | if (curproxy->uniqueid_format_string) |
| 1668 | curproxy->uniqueid_format_string = strdup(curproxy->uniqueid_format_string); |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 1669 | |
| 1670 | /* copy default header unique id */ |
| 1671 | if (defproxy.header_unique_id) |
| 1672 | curproxy->header_unique_id = strdup(defproxy.header_unique_id); |
| 1673 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1674 | curproxy->grace = defproxy.grace; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1675 | curproxy->conf.used_listener_id = EB_ROOT; |
| 1676 | curproxy->conf.used_server_id = EB_ROOT; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 1677 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1678 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1679 | } |
| 1680 | else if (!strcmp(args[0], "defaults")) { /* use this one to assign default values */ |
| 1681 | /* some variables may have already been initialized earlier */ |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 1682 | /* FIXME-20070101: we should do this too at the end of the |
| 1683 | * config parsing to free all default values. |
| 1684 | */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1685 | free(defproxy.check_req); |
| 1686 | free(defproxy.cookie_name); |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 1687 | free(defproxy.rdp_cookie_name); |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 1688 | free(defproxy.cookie_domain); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1689 | free(defproxy.url_param_name); |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 1690 | free(defproxy.hh_name); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1691 | free(defproxy.capture_name); |
| 1692 | free(defproxy.monitor_uri); |
| 1693 | free(defproxy.defbe.name); |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 1694 | free(defproxy.iface_name); |
Willy Tarreau | 79f5fe8 | 2008-08-23 08:18:21 +0200 | [diff] [blame] | 1695 | free(defproxy.fwdfor_hdr_name); |
| 1696 | defproxy.fwdfor_hdr_len = 0; |
Willy Tarreau | b86db34 | 2009-11-30 11:50:16 +0100 | [diff] [blame] | 1697 | free(defproxy.orgto_hdr_name); |
| 1698 | defproxy.orgto_hdr_len = 0; |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 1699 | free(defproxy.server_id_hdr_name); |
| 1700 | defproxy.server_id_hdr_len = 0; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 1701 | free(defproxy.expect_str); |
| 1702 | if (defproxy.expect_regex) regfree(defproxy.expect_regex); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 1703 | |
Willy Tarreau | 39b0665 | 2012-06-01 10:58:06 +0200 | [diff] [blame] | 1704 | if (defproxy.logformat_string != default_http_log_format && |
| 1705 | defproxy.logformat_string != default_tcp_log_format && |
| 1706 | defproxy.logformat_string != clf_http_log_format) |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 1707 | free(defproxy.logformat_string); |
| 1708 | |
| 1709 | free(defproxy.uniqueid_format_string); |
| 1710 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1711 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1712 | chunk_destroy(&defproxy.errmsg[rc]); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 1713 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1714 | /* we cannot free uri_auth because it might already be used */ |
| 1715 | init_default_instance(); |
| 1716 | curproxy = &defproxy; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1717 | defproxy.cap = PR_CAP_LISTEN; /* all caps for now */ |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1718 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1719 | } |
| 1720 | else if (curproxy == NULL) { |
| 1721 | Alert("parsing [%s:%d] : 'listen' or 'defaults' expected.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1722 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1723 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1724 | } |
| 1725 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1726 | |
| 1727 | /* Now let's parse the proxy-specific keywords */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1728 | if (!strcmp(args[0], "bind")) { /* new listen addresses */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1729 | struct listener *l; |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1730 | int cur_arg; |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 1731 | char *err_msg = NULL; |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1732 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1733 | if (curproxy == &defproxy) { |
| 1734 | 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] | 1735 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1736 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1737 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1738 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1739 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1740 | |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 1741 | if ( *(args[1]) != '/' && strchr(args[1], ':') == NULL) { |
Willy Tarreau | d55c3fe | 2010-11-09 09:50:37 +0100 | [diff] [blame] | 1742 | 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] | 1743 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1744 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1745 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1746 | } |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 1747 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 1748 | bind_conf = bind_conf_alloc(&curproxy->conf.bind, file, linenum, args[1]); |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1749 | memcpy(&bind_conf->ux, &global.unix_bind.ux, sizeof(global.unix_bind.ux)); |
Willy Tarreau | 8a95691 | 2010-10-15 14:27:08 +0200 | [diff] [blame] | 1750 | |
| 1751 | /* NOTE: the following line might create several listeners if there |
| 1752 | * are comma-separated IPs or port ranges. So all further processing |
| 1753 | * will have to be applied to all listeners created after last_listen. |
| 1754 | */ |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 1755 | if (!str2listener(args[1], curproxy, bind_conf, file, linenum, &err_msg)) { |
| 1756 | if (err_msg && *err_msg) { |
| 1757 | indent_msg(&err_msg, 2); |
| 1758 | Alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], err_msg); |
| 1759 | } |
| 1760 | else |
| 1761 | Alert("parsing [%s:%d] : '%s' : error encountered while parsing listening address '%s'.\n", |
| 1762 | file, linenum, args[0], args[1]); |
| 1763 | free(err_msg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1764 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1765 | goto out; |
| 1766 | } |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1767 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1768 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
| 1769 | /* Set default global rights and owner for unix bind */ |
Willy Tarreau | c8b1109 | 2011-02-16 11:08:57 +0100 | [diff] [blame] | 1770 | global.maxsock++; |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 1771 | } |
| 1772 | |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1773 | cur_arg = 2; |
| 1774 | while (*(args[cur_arg])) { |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 1775 | static int bind_dumped; |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 1776 | struct bind_kw *kw; |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 1777 | char *err; |
| 1778 | |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 1779 | kw = bind_find_kw(args[cur_arg]); |
| 1780 | if (kw) { |
| 1781 | char *err = NULL; |
| 1782 | int code; |
| 1783 | |
| 1784 | if (!kw->parse) { |
Willy Tarreau | dda322d | 2012-09-18 16:34:09 +0200 | [diff] [blame] | 1785 | Alert("parsing [%s:%d] : '%s %s' : '%s' option is not implemented in this version (check build options).\n", |
| 1786 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 1787 | cur_arg += 1 + kw->skip ; |
| 1788 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1789 | goto out; |
| 1790 | } |
| 1791 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1792 | code = kw->parse(args, cur_arg, curproxy, bind_conf, &err); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 1793 | err_code |= code; |
| 1794 | |
| 1795 | if (code) { |
| 1796 | if (err && *err) { |
| 1797 | indent_msg(&err, 2); |
Willy Tarreau | dda322d | 2012-09-18 16:34:09 +0200 | [diff] [blame] | 1798 | Alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], err); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 1799 | } |
| 1800 | else |
Willy Tarreau | dda322d | 2012-09-18 16:34:09 +0200 | [diff] [blame] | 1801 | Alert("parsing [%s:%d] : '%s %s' : error encountered while processing '%s'.\n", |
| 1802 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 1803 | if (code & ERR_FATAL) { |
| 1804 | free(err); |
| 1805 | cur_arg += 1 + kw->skip; |
| 1806 | goto out; |
| 1807 | } |
| 1808 | } |
| 1809 | free(err); |
| 1810 | cur_arg += 1 + kw->skip; |
| 1811 | continue; |
| 1812 | } |
| 1813 | |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 1814 | err = NULL; |
| 1815 | if (!bind_dumped) { |
| 1816 | bind_dump_kws(&err); |
| 1817 | indent_msg(&err, 4); |
| 1818 | bind_dumped = 1; |
| 1819 | } |
| 1820 | |
| 1821 | Alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'.%s%s\n", |
| 1822 | file, linenum, args[0], args[1], args[cur_arg], |
| 1823 | err ? " Registered keywords :" : "", err ? err : ""); |
| 1824 | free(err); |
| 1825 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1826 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1827 | goto out; |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 1828 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1829 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1830 | } |
| 1831 | else if (!strcmp(args[0], "monitor-net")) { /* set the range of IPs to ignore */ |
| 1832 | if (!*args[1] || !str2net(args[1], &curproxy->mon_net, &curproxy->mon_mask)) { |
| 1833 | Alert("parsing [%s:%d] : '%s' expects address[/mask].\n", |
| 1834 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1835 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1836 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1837 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1838 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1839 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1840 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1841 | /* flush useless bits */ |
| 1842 | curproxy->mon_net.s_addr &= curproxy->mon_mask.s_addr; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1843 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1844 | } |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 1845 | else if (!strcmp(args[0], "monitor-uri")) { /* set the URI to intercept */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1846 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1847 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1848 | |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 1849 | if (!*args[1]) { |
| 1850 | Alert("parsing [%s:%d] : '%s' expects an URI.\n", |
| 1851 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1852 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1853 | goto out; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 1854 | } |
| 1855 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1856 | free(curproxy->monitor_uri); |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 1857 | curproxy->monitor_uri_len = strlen(args[1]); |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 1858 | curproxy->monitor_uri = (char *)calloc(1, curproxy->monitor_uri_len + 1); |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 1859 | memcpy(curproxy->monitor_uri, args[1], curproxy->monitor_uri_len); |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 1860 | curproxy->monitor_uri[curproxy->monitor_uri_len] = '\0'; |
| 1861 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1862 | goto out; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 1863 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1864 | else if (!strcmp(args[0], "mode")) { /* sets the proxy mode */ |
| 1865 | if (!strcmp(args[1], "http")) curproxy->mode = PR_MODE_HTTP; |
| 1866 | else if (!strcmp(args[1], "tcp")) curproxy->mode = PR_MODE_TCP; |
| 1867 | else if (!strcmp(args[1], "health")) curproxy->mode = PR_MODE_HEALTH; |
| 1868 | else { |
| 1869 | 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] | 1870 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1871 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1872 | } |
| 1873 | } |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 1874 | else if (!strcmp(args[0], "id")) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1875 | struct eb32_node *node; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 1876 | |
| 1877 | if (curproxy == &defproxy) { |
| 1878 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", |
| 1879 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1880 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1881 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 1882 | } |
| 1883 | |
| 1884 | if (!*args[1]) { |
| 1885 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 1886 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1887 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1888 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 1889 | } |
| 1890 | |
| 1891 | curproxy->uuid = atol(args[1]); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1892 | curproxy->conf.id.key = curproxy->uuid; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 1893 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1894 | if (curproxy->uuid <= 0) { |
| 1895 | Alert("parsing [%s:%d]: custom id has to be > 0.\n", |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 1896 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1897 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1898 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 1899 | } |
| 1900 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1901 | node = eb32_lookup(&used_proxy_id, curproxy->uuid); |
| 1902 | if (node) { |
| 1903 | struct proxy *target = container_of(node, struct proxy, conf.id); |
| 1904 | Alert("parsing [%s:%d]: %s %s reuses same custom id as %s %s (declared at %s:%d).\n", |
| 1905 | file, linenum, proxy_type_str(curproxy), curproxy->id, |
| 1906 | proxy_type_str(target), target->id, target->conf.file, target->conf.line); |
| 1907 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1908 | goto out; |
| 1909 | } |
| 1910 | eb32_insert(&used_proxy_id, &curproxy->conf.id); |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 1911 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1912 | else if (!strcmp(args[0], "description")) { |
| 1913 | int i, len=0; |
| 1914 | char *d; |
| 1915 | |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 1916 | if (curproxy == &defproxy) { |
| 1917 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", |
| 1918 | file, linenum, args[0]); |
| 1919 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1920 | goto out; |
| 1921 | } |
| 1922 | |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1923 | if (!*args[1]) { |
| 1924 | Alert("parsing [%s:%d]: '%s' expects a string argument.\n", |
| 1925 | file, linenum, args[0]); |
| 1926 | return -1; |
| 1927 | } |
| 1928 | |
| 1929 | for(i=1; *args[i]; i++) |
| 1930 | len += strlen(args[i])+1; |
| 1931 | |
| 1932 | d = (char *)calloc(1, len); |
| 1933 | curproxy->desc = d; |
| 1934 | |
| 1935 | d += sprintf(d, "%s", args[1]); |
| 1936 | for(i=2; *args[i]; i++) |
| 1937 | d += sprintf(d, " %s", args[i]); |
| 1938 | |
| 1939 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1940 | else if (!strcmp(args[0], "disabled")) { /* disables this proxy */ |
| 1941 | curproxy->state = PR_STSTOPPED; |
| 1942 | } |
| 1943 | else if (!strcmp(args[0], "enabled")) { /* enables this proxy (used to revert a disabled default) */ |
| 1944 | curproxy->state = PR_STNEW; |
| 1945 | } |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 1946 | else if (!strcmp(args[0], "bind-process")) { /* enable this proxy only on some processes */ |
| 1947 | int cur_arg = 1; |
| 1948 | unsigned int set = 0; |
| 1949 | |
| 1950 | while (*args[cur_arg]) { |
| 1951 | int u; |
| 1952 | if (strcmp(args[cur_arg], "all") == 0) { |
| 1953 | set = 0; |
| 1954 | break; |
| 1955 | } |
| 1956 | else if (strcmp(args[cur_arg], "odd") == 0) { |
| 1957 | set |= 0x55555555; |
| 1958 | } |
| 1959 | else if (strcmp(args[cur_arg], "even") == 0) { |
| 1960 | set |= 0xAAAAAAAA; |
| 1961 | } |
| 1962 | else { |
| 1963 | u = str2uic(args[cur_arg]); |
| 1964 | if (u < 1 || u > 32) { |
| 1965 | Alert("parsing [%s:%d]: %s expects 'all', 'odd', 'even', or process numbers from 1 to 32.\n", |
| 1966 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1967 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1968 | goto out; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 1969 | } |
| 1970 | if (u > global.nbproc) { |
| 1971 | Warning("parsing [%s:%d]: %s references process number higher than global.nbproc.\n", |
| 1972 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1973 | err_code |= ERR_WARN; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 1974 | } |
| 1975 | set |= 1 << (u - 1); |
| 1976 | } |
| 1977 | cur_arg++; |
| 1978 | } |
| 1979 | curproxy->bind_proc = set; |
| 1980 | } |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 1981 | else if (!strcmp(args[0], "acl")) { /* add an ACL */ |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 1982 | if (curproxy == &defproxy) { |
| 1983 | 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] | 1984 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1985 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 1986 | } |
| 1987 | |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 1988 | err = invalid_char(args[1]); |
| 1989 | if (err) { |
| 1990 | Alert("parsing [%s:%d] : character '%c' is not permitted in acl name '%s'.\n", |
| 1991 | file, linenum, *err, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1992 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 1993 | } |
| 1994 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 1995 | if (parse_acl((const char **)args + 1, &curproxy->acl, &errmsg) == NULL) { |
| 1996 | Alert("parsing [%s:%d] : error detected while parsing ACL '%s' : %s.\n", |
| 1997 | file, linenum, args[1], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1998 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1999 | goto out; |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 2000 | } |
| 2001 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2002 | else if (!strcmp(args[0], "cookie")) { /* cookie name */ |
| 2003 | int cur_arg; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2004 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2005 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2006 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2007 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2008 | if (*(args[1]) == 0) { |
| 2009 | Alert("parsing [%s:%d] : '%s' expects <cookie_name> as argument.\n", |
| 2010 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2011 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2012 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2013 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2014 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2015 | curproxy->ck_opts = 0; |
Willy Tarreau | c63d4bb | 2010-10-23 11:37:27 +0200 | [diff] [blame] | 2016 | curproxy->cookie_maxidle = curproxy->cookie_maxlife = 0; |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 2017 | free(curproxy->cookie_domain); curproxy->cookie_domain = NULL; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2018 | free(curproxy->cookie_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2019 | curproxy->cookie_name = strdup(args[1]); |
| 2020 | curproxy->cookie_len = strlen(curproxy->cookie_name); |
Willy Tarreau | c63d4bb | 2010-10-23 11:37:27 +0200 | [diff] [blame] | 2021 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2022 | cur_arg = 2; |
| 2023 | while (*(args[cur_arg])) { |
| 2024 | if (!strcmp(args[cur_arg], "rewrite")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2025 | curproxy->ck_opts |= PR_CK_RW; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2026 | } |
| 2027 | else if (!strcmp(args[cur_arg], "indirect")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2028 | curproxy->ck_opts |= PR_CK_IND; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2029 | } |
| 2030 | else if (!strcmp(args[cur_arg], "insert")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2031 | curproxy->ck_opts |= PR_CK_INS; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2032 | } |
| 2033 | else if (!strcmp(args[cur_arg], "nocache")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2034 | curproxy->ck_opts |= PR_CK_NOC; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2035 | } |
| 2036 | else if (!strcmp(args[cur_arg], "postonly")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2037 | curproxy->ck_opts |= PR_CK_POST; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2038 | } |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 2039 | else if (!strcmp(args[cur_arg], "preserve")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2040 | curproxy->ck_opts |= PR_CK_PSV; |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 2041 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2042 | else if (!strcmp(args[cur_arg], "prefix")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2043 | curproxy->ck_opts |= PR_CK_PFX; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2044 | } |
Willy Tarreau | 4992dd2 | 2012-05-31 21:02:17 +0200 | [diff] [blame] | 2045 | else if (!strcmp(args[cur_arg], "httponly")) { |
| 2046 | curproxy->ck_opts |= PR_CK_HTTPONLY; |
| 2047 | } |
| 2048 | else if (!strcmp(args[cur_arg], "secure")) { |
| 2049 | curproxy->ck_opts |= PR_CK_SECURE; |
| 2050 | } |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2051 | else if (!strcmp(args[cur_arg], "domain")) { |
| 2052 | if (!*args[cur_arg + 1]) { |
| 2053 | Alert("parsing [%s:%d]: '%s' expects <domain> as argument.\n", |
| 2054 | file, linenum, args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2055 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2056 | goto out; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2057 | } |
| 2058 | |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 2059 | if (*args[cur_arg + 1] != '.' || !strchr(args[cur_arg + 1] + 1, '.')) { |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2060 | /* rfc2109, 4.3.2 Rejecting Cookies */ |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 2061 | Warning("parsing [%s:%d]: domain '%s' contains no embedded" |
| 2062 | " dots nor does not start with a dot." |
| 2063 | " RFC forbids it, this configuration may not work properly.\n", |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2064 | file, linenum, args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 2065 | err_code |= ERR_WARN; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2066 | } |
| 2067 | |
| 2068 | err = invalid_domainchar(args[cur_arg + 1]); |
| 2069 | if (err) { |
| 2070 | Alert("parsing [%s:%d]: character '%c' is not permitted in domain name '%s'.\n", |
| 2071 | file, linenum, *err, args[cur_arg + 1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2072 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2073 | goto out; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2074 | } |
| 2075 | |
Willy Tarreau | 68a897b | 2009-12-03 23:28:34 +0100 | [diff] [blame] | 2076 | if (!curproxy->cookie_domain) { |
| 2077 | curproxy->cookie_domain = strdup(args[cur_arg + 1]); |
| 2078 | } else { |
| 2079 | /* one domain was already specified, add another one by |
| 2080 | * building the string which will be returned along with |
| 2081 | * the cookie. |
| 2082 | */ |
| 2083 | char *new_ptr; |
| 2084 | int new_len = strlen(curproxy->cookie_domain) + |
| 2085 | strlen("; domain=") + strlen(args[cur_arg + 1]) + 1; |
| 2086 | new_ptr = malloc(new_len); |
| 2087 | snprintf(new_ptr, new_len, "%s; domain=%s", curproxy->cookie_domain, args[cur_arg+1]); |
| 2088 | free(curproxy->cookie_domain); |
| 2089 | curproxy->cookie_domain = new_ptr; |
| 2090 | } |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 2091 | cur_arg++; |
| 2092 | } |
| 2093 | else if (!strcmp(args[cur_arg], "maxidle")) { |
| 2094 | unsigned int maxidle; |
| 2095 | const char *res; |
| 2096 | |
| 2097 | if (!*args[cur_arg + 1]) { |
| 2098 | Alert("parsing [%s:%d]: '%s' expects <idletime> in seconds as argument.\n", |
| 2099 | file, linenum, args[cur_arg]); |
| 2100 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2101 | goto out; |
| 2102 | } |
| 2103 | |
| 2104 | res = parse_time_err(args[cur_arg + 1], &maxidle, TIME_UNIT_S); |
| 2105 | if (res) { |
| 2106 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 2107 | file, linenum, *res, args[cur_arg]); |
| 2108 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2109 | goto out; |
| 2110 | } |
| 2111 | curproxy->cookie_maxidle = maxidle; |
| 2112 | cur_arg++; |
| 2113 | } |
| 2114 | else if (!strcmp(args[cur_arg], "maxlife")) { |
| 2115 | unsigned int maxlife; |
| 2116 | const char *res; |
| 2117 | |
| 2118 | if (!*args[cur_arg + 1]) { |
| 2119 | Alert("parsing [%s:%d]: '%s' expects <lifetime> in seconds as argument.\n", |
| 2120 | file, linenum, args[cur_arg]); |
| 2121 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2122 | goto out; |
| 2123 | } |
| 2124 | |
| 2125 | res = parse_time_err(args[cur_arg + 1], &maxlife, TIME_UNIT_S); |
| 2126 | if (res) { |
| 2127 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 2128 | file, linenum, *res, args[cur_arg]); |
| 2129 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2130 | goto out; |
| 2131 | } |
| 2132 | curproxy->cookie_maxlife = maxlife; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2133 | cur_arg++; |
| 2134 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2135 | else { |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 2136 | 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] | 2137 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2138 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2139 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2140 | } |
| 2141 | cur_arg++; |
| 2142 | } |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2143 | if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_IND))) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2144 | Alert("parsing [%s:%d] : cookie 'rewrite' and 'indirect' modes are incompatible.\n", |
| 2145 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2146 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2147 | } |
| 2148 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2149 | if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_INS|PR_CK_PFX))) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2150 | Alert("parsing [%s:%d] : cookie 'rewrite', 'insert' and 'prefix' modes are incompatible.\n", |
| 2151 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2152 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2153 | } |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 2154 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2155 | if ((curproxy->ck_opts & (PR_CK_PSV | PR_CK_INS | PR_CK_IND)) == PR_CK_PSV) { |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 2156 | Alert("parsing [%s:%d] : cookie 'preserve' requires at least 'insert' or 'indirect'.\n", |
| 2157 | file, linenum); |
| 2158 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2159 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2160 | }/* end else if (!strcmp(args[0], "cookie")) */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2161 | else if (!strcmp(args[0], "persist")) { /* persist */ |
| 2162 | if (*(args[1]) == 0) { |
| 2163 | Alert("parsing [%s:%d] : missing persist method.\n", |
| 2164 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2165 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2166 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2167 | } |
| 2168 | |
| 2169 | if (!strncmp(args[1], "rdp-cookie", 10)) { |
| 2170 | curproxy->options2 |= PR_O2_RDPC_PRST; |
| 2171 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2172 | if (*(args[1] + 10) == '(') { /* cookie name */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2173 | const char *beg, *end; |
| 2174 | |
| 2175 | beg = args[1] + 11; |
| 2176 | end = strchr(beg, ')'); |
| 2177 | |
| 2178 | if (!end || end == beg) { |
| 2179 | Alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n", |
| 2180 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2181 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2182 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2183 | } |
| 2184 | |
| 2185 | free(curproxy->rdp_cookie_name); |
| 2186 | curproxy->rdp_cookie_name = my_strndup(beg, end - beg); |
| 2187 | curproxy->rdp_cookie_len = end-beg; |
| 2188 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2189 | else if (*(args[1] + 10) == '\0') { /* default cookie name 'msts' */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2190 | free(curproxy->rdp_cookie_name); |
| 2191 | curproxy->rdp_cookie_name = strdup("msts"); |
| 2192 | curproxy->rdp_cookie_len = strlen(curproxy->rdp_cookie_name); |
| 2193 | } |
| 2194 | else { /* syntax */ |
| 2195 | Alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n", |
| 2196 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2197 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2198 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2199 | } |
| 2200 | } |
| 2201 | else { |
| 2202 | Alert("parsing [%s:%d] : unknown persist method.\n", |
| 2203 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2204 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2205 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2206 | } |
| 2207 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2208 | else if (!strcmp(args[0], "appsession")) { /* cookie name */ |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2209 | int cur_arg; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2210 | |
Cyril Bonté | 3b7a369 | 2010-01-10 17:01:47 +0100 | [diff] [blame] | 2211 | if (curproxy == &defproxy) { |
| 2212 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2213 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2214 | goto out; |
| 2215 | } |
| 2216 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2217 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2218 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2219 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2220 | if (*(args[5]) == 0) { |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2221 | 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] | 2222 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2223 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2224 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2225 | } |
| 2226 | have_appsession = 1; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2227 | free(curproxy->appsession_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2228 | curproxy->appsession_name = strdup(args[1]); |
| 2229 | curproxy->appsession_name_len = strlen(curproxy->appsession_name); |
| 2230 | curproxy->appsession_len = atoi(args[3]); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 2231 | err = parse_time_err(args[5], &val, TIME_UNIT_MS); |
| 2232 | if (err) { |
| 2233 | Alert("parsing [%s:%d] : unexpected character '%c' in %s timeout.\n", |
| 2234 | file, linenum, *err, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2235 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2236 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 2237 | } |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 2238 | curproxy->timeout.appsession = val; |
Willy Tarreau | ee99136 | 2007-05-14 14:37:50 +0200 | [diff] [blame] | 2239 | |
Willy Tarreau | 51041c7 | 2007-09-09 21:56:53 +0200 | [diff] [blame] | 2240 | if (appsession_hash_init(&(curproxy->htbl_proxy), destroy) == 0) { |
| 2241 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2242 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2243 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2244 | } |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2245 | |
| 2246 | cur_arg = 6; |
| 2247 | curproxy->options2 &= ~PR_O2_AS_REQL; |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2248 | curproxy->options2 &= ~PR_O2_AS_M_ANY; |
| 2249 | curproxy->options2 |= PR_O2_AS_M_PP; |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2250 | while (*(args[cur_arg])) { |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2251 | if (!strcmp(args[cur_arg], "request-learn")) { |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2252 | curproxy->options2 |= PR_O2_AS_REQL; |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2253 | } else if (!strcmp(args[cur_arg], "prefix")) { |
| 2254 | curproxy->options2 |= PR_O2_AS_PFX; |
| 2255 | } else if (!strcmp(args[cur_arg], "mode")) { |
| 2256 | if (!*args[cur_arg + 1]) { |
| 2257 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 2258 | file, linenum, args[0], args[cur_arg]); |
| 2259 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2260 | goto out; |
| 2261 | } |
| 2262 | |
| 2263 | cur_arg++; |
| 2264 | if (!strcmp(args[cur_arg], "query-string")) { |
| 2265 | curproxy->options2 &= ~PR_O2_AS_M_ANY; |
| 2266 | curproxy->options2 |= PR_O2_AS_M_QS; |
| 2267 | } else if (!strcmp(args[cur_arg], "path-parameters")) { |
| 2268 | curproxy->options2 &= ~PR_O2_AS_M_ANY; |
| 2269 | curproxy->options2 |= PR_O2_AS_M_PP; |
| 2270 | } else { |
| 2271 | Alert("parsing [%s:%d] : unknown mode '%s'\n", file, linenum, args[cur_arg]); |
| 2272 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2273 | goto out; |
| 2274 | } |
| 2275 | } |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2276 | cur_arg++; |
| 2277 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2278 | } /* Url App Session */ |
| 2279 | else if (!strcmp(args[0], "capture")) { |
Willy Tarreau | 3b6b1a9 | 2009-07-23 13:24:23 +0200 | [diff] [blame] | 2280 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2281 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2282 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2283 | if (!strcmp(args[1], "cookie")) { /* name of a cookie to capture */ |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 2284 | if (curproxy == &defproxy) { |
| 2285 | Alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
| 2286 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2287 | goto out; |
| 2288 | } |
| 2289 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2290 | if (*(args[4]) == 0) { |
| 2291 | Alert("parsing [%s:%d] : '%s' expects 'cookie' <cookie_name> 'len' <len>.\n", |
| 2292 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2293 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2294 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2295 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2296 | free(curproxy->capture_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2297 | curproxy->capture_name = strdup(args[2]); |
| 2298 | curproxy->capture_namelen = strlen(curproxy->capture_name); |
| 2299 | curproxy->capture_len = atol(args[4]); |
| 2300 | if (curproxy->capture_len >= CAPTURE_LEN) { |
| 2301 | Warning("parsing [%s:%d] : truncating capture length to %d bytes.\n", |
| 2302 | file, linenum, CAPTURE_LEN - 1); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2303 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2304 | curproxy->capture_len = CAPTURE_LEN - 1; |
| 2305 | } |
| 2306 | curproxy->to_log |= LW_COOKIE; |
| 2307 | } |
| 2308 | else if (!strcmp(args[1], "request") && !strcmp(args[2], "header")) { |
| 2309 | struct cap_hdr *hdr; |
| 2310 | |
| 2311 | if (curproxy == &defproxy) { |
| 2312 | 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] | 2313 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2314 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2315 | } |
| 2316 | |
| 2317 | if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) { |
| 2318 | Alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n", |
| 2319 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2320 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2321 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2322 | } |
| 2323 | |
| 2324 | hdr = calloc(sizeof(struct cap_hdr), 1); |
| 2325 | hdr->next = curproxy->req_cap; |
| 2326 | hdr->name = strdup(args[3]); |
| 2327 | hdr->namelen = strlen(args[3]); |
| 2328 | hdr->len = atol(args[5]); |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 2329 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2330 | hdr->index = curproxy->nb_req_cap++; |
| 2331 | curproxy->req_cap = hdr; |
| 2332 | curproxy->to_log |= LW_REQHDR; |
| 2333 | } |
| 2334 | else if (!strcmp(args[1], "response") && !strcmp(args[2], "header")) { |
| 2335 | struct cap_hdr *hdr; |
| 2336 | |
| 2337 | if (curproxy == &defproxy) { |
| 2338 | 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] | 2339 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2340 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2341 | } |
| 2342 | |
| 2343 | if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) { |
| 2344 | Alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n", |
| 2345 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2346 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2347 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2348 | } |
| 2349 | hdr = calloc(sizeof(struct cap_hdr), 1); |
| 2350 | hdr->next = curproxy->rsp_cap; |
| 2351 | hdr->name = strdup(args[3]); |
| 2352 | hdr->namelen = strlen(args[3]); |
| 2353 | hdr->len = atol(args[5]); |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 2354 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2355 | hdr->index = curproxy->nb_rsp_cap++; |
| 2356 | curproxy->rsp_cap = hdr; |
| 2357 | curproxy->to_log |= LW_RSPHDR; |
| 2358 | } |
| 2359 | else { |
| 2360 | Alert("parsing [%s:%d] : '%s' expects 'cookie' or 'request header' or 'response header'.\n", |
| 2361 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2362 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2363 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2364 | } |
| 2365 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2366 | else if (!strcmp(args[0], "retries")) { /* connection retries */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2367 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2368 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2369 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2370 | if (*(args[1]) == 0) { |
| 2371 | Alert("parsing [%s:%d] : '%s' expects an integer argument (dispatch counts for one).\n", |
| 2372 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2373 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2374 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2375 | } |
| 2376 | curproxy->conn_retries = atol(args[1]); |
| 2377 | } |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2378 | 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] | 2379 | struct http_req_rule *rule; |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2380 | |
| 2381 | if (curproxy == &defproxy) { |
| 2382 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2383 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2384 | goto out; |
| 2385 | } |
| 2386 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 2387 | 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] | 2388 | Warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n", |
| 2389 | file, linenum, args[0]); |
| 2390 | err_code |= ERR_WARN; |
| 2391 | } |
| 2392 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 2393 | 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] | 2394 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 2395 | if (!rule) { |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2396 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2397 | goto out; |
| 2398 | } |
| 2399 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 2400 | err_code |= warnif_cond_requires_resp(rule->cond, file, linenum); |
| 2401 | LIST_ADDQ(&curproxy->http_req_rules, &rule->list); |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2402 | } |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 2403 | else if (!strcmp(args[0], "http-send-name-header")) { /* send server name in request header */ |
| 2404 | /* set the header name and length into the proxy structure */ |
| 2405 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 2406 | err_code |= ERR_WARN; |
| 2407 | |
| 2408 | if (!*args[1]) { |
| 2409 | Alert("parsing [%s:%d] : '%s' requires a header string.\n", |
| 2410 | file, linenum, args[0]); |
| 2411 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2412 | goto out; |
| 2413 | } |
| 2414 | |
| 2415 | /* set the desired header name */ |
| 2416 | free(curproxy->server_id_hdr_name); |
| 2417 | curproxy->server_id_hdr_name = strdup(args[1]); |
| 2418 | curproxy->server_id_hdr_len = strlen(curproxy->server_id_hdr_name); |
| 2419 | } |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2420 | else if (!strcmp(args[0], "block")) { /* early blocking based on ACLs */ |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2421 | if (curproxy == &defproxy) { |
| 2422 | 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] | 2423 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2424 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2425 | } |
| 2426 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2427 | if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) { |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2428 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 2429 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2430 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2431 | goto out; |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2432 | } |
| 2433 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 2434 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 1, &errmsg)) == NULL) { |
| 2435 | Alert("parsing [%s:%d] : error detected while parsing blocking condition : %s.\n", |
| 2436 | file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2437 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2438 | goto out; |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2439 | } |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2440 | |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2441 | LIST_ADDQ(&curproxy->block_cond, &cond->list); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 2442 | warnif_misplaced_block(curproxy, file, linenum, args[0]); |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2443 | } |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2444 | else if (!strcmp(args[0], "redirect")) { |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2445 | struct redirect_rule *rule; |
| 2446 | int cur_arg; |
| 2447 | int type = REDIRECT_TYPE_NONE; |
| 2448 | int code = 302; |
| 2449 | char *destination = NULL; |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2450 | char *cookie = NULL; |
| 2451 | int cookie_set = 0; |
Willy Tarreau | 79da469 | 2008-11-19 20:03:04 +0100 | [diff] [blame] | 2452 | unsigned int flags = REDIRECT_FLAG_NONE; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2453 | |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 2454 | if (curproxy == &defproxy) { |
| 2455 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2456 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2457 | goto out; |
| 2458 | } |
| 2459 | |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2460 | cur_arg = 1; |
| 2461 | while (*(args[cur_arg])) { |
| 2462 | if (!strcmp(args[cur_arg], "location")) { |
| 2463 | if (!*args[cur_arg + 1]) { |
| 2464 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 2465 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2466 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2467 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2468 | } |
| 2469 | |
| 2470 | type = REDIRECT_TYPE_LOCATION; |
| 2471 | cur_arg++; |
| 2472 | destination = args[cur_arg]; |
| 2473 | } |
| 2474 | else if (!strcmp(args[cur_arg], "prefix")) { |
| 2475 | if (!*args[cur_arg + 1]) { |
| 2476 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 2477 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2478 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2479 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2480 | } |
| 2481 | |
| 2482 | type = REDIRECT_TYPE_PREFIX; |
| 2483 | cur_arg++; |
| 2484 | destination = args[cur_arg]; |
| 2485 | } |
Willy Tarreau | 2e1dca8 | 2012-09-12 08:43:15 +0200 | [diff] [blame] | 2486 | else if (!strcmp(args[cur_arg], "scheme")) { |
| 2487 | if (!*args[cur_arg + 1]) { |
| 2488 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 2489 | file, linenum, args[0], args[cur_arg]); |
| 2490 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2491 | goto out; |
| 2492 | } |
| 2493 | |
| 2494 | type = REDIRECT_TYPE_SCHEME; |
| 2495 | cur_arg++; |
| 2496 | destination = args[cur_arg]; |
| 2497 | } |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2498 | else if (!strcmp(args[cur_arg], "set-cookie")) { |
| 2499 | if (!*args[cur_arg + 1]) { |
| 2500 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 2501 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2502 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2503 | goto out; |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2504 | } |
| 2505 | |
| 2506 | cur_arg++; |
| 2507 | cookie = args[cur_arg]; |
| 2508 | cookie_set = 1; |
| 2509 | } |
| 2510 | else if (!strcmp(args[cur_arg], "clear-cookie")) { |
| 2511 | if (!*args[cur_arg + 1]) { |
| 2512 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 2513 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2514 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2515 | goto out; |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2516 | } |
| 2517 | |
| 2518 | cur_arg++; |
| 2519 | cookie = args[cur_arg]; |
| 2520 | cookie_set = 0; |
| 2521 | } |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2522 | else if (!strcmp(args[cur_arg],"code")) { |
| 2523 | if (!*args[cur_arg + 1]) { |
| 2524 | Alert("parsing [%s:%d] : '%s': missing HTTP code.\n", |
| 2525 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2526 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2527 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2528 | } |
| 2529 | cur_arg++; |
| 2530 | code = atol(args[cur_arg]); |
| 2531 | if (code < 301 || code > 303) { |
| 2532 | Alert("parsing [%s:%d] : '%s': unsupported HTTP code '%d'.\n", |
| 2533 | file, linenum, args[0], code); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2534 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2535 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2536 | } |
| 2537 | } |
Willy Tarreau | 79da469 | 2008-11-19 20:03:04 +0100 | [diff] [blame] | 2538 | else if (!strcmp(args[cur_arg],"drop-query")) { |
| 2539 | flags |= REDIRECT_FLAG_DROP_QS; |
| 2540 | } |
Willy Tarreau | 81e3b4f | 2010-01-10 00:42:19 +0100 | [diff] [blame] | 2541 | else if (!strcmp(args[cur_arg],"append-slash")) { |
| 2542 | flags |= REDIRECT_FLAG_APPEND_SLASH; |
| 2543 | } |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2544 | else if (strcmp(args[cur_arg], "if") == 0 || |
| 2545 | strcmp(args[cur_arg], "unless") == 0) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 2546 | 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] | 2547 | if (!cond) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 2548 | Alert("parsing [%s:%d] : '%s': error detected while parsing redirect condition : %s.\n", |
| 2549 | file, linenum, args[0], errmsg); |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2550 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2551 | goto out; |
| 2552 | } |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2553 | break; |
| 2554 | } |
| 2555 | else { |
Willy Tarreau | 2e1dca8 | 2012-09-12 08:43:15 +0200 | [diff] [blame] | 2556 | Alert("parsing [%s:%d] : '%s' expects 'code', 'prefix', 'location', 'scheme', 'set-cookie', 'clear-cookie', 'drop-query' or 'append-slash' (was '%s').\n", |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2557 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2558 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2559 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2560 | } |
| 2561 | cur_arg++; |
| 2562 | } |
| 2563 | |
| 2564 | if (type == REDIRECT_TYPE_NONE) { |
| 2565 | Alert("parsing [%s:%d] : '%s' expects a redirection type ('prefix' or 'location').\n", |
| 2566 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2567 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2568 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2569 | } |
| 2570 | |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2571 | rule = (struct redirect_rule *)calloc(1, sizeof(*rule)); |
| 2572 | rule->cond = cond; |
| 2573 | rule->rdr_str = strdup(destination); |
| 2574 | rule->rdr_len = strlen(destination); |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2575 | if (cookie) { |
| 2576 | /* 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] | 2577 | * a clear consists in appending "; path=/; Max-Age=0;" at the end. |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2578 | */ |
| 2579 | rule->cookie_len = strlen(cookie); |
William Turner | d986526 | 2010-03-01 13:30:34 -0500 | [diff] [blame] | 2580 | if (cookie_set) { |
| 2581 | rule->cookie_str = malloc(rule->cookie_len + 10); |
| 2582 | memcpy(rule->cookie_str, cookie, rule->cookie_len); |
| 2583 | memcpy(rule->cookie_str + rule->cookie_len, "; path=/;", 10); |
| 2584 | rule->cookie_len += 9; |
| 2585 | } else { |
| 2586 | rule->cookie_str = malloc(rule->cookie_len + 21); |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2587 | memcpy(rule->cookie_str, cookie, rule->cookie_len); |
William Turner | d986526 | 2010-03-01 13:30:34 -0500 | [diff] [blame] | 2588 | memcpy(rule->cookie_str + rule->cookie_len, "; path=/; Max-Age=0;", 21); |
| 2589 | rule->cookie_len += 20; |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2590 | } |
| 2591 | } |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2592 | rule->type = type; |
| 2593 | rule->code = code; |
Willy Tarreau | 79da469 | 2008-11-19 20:03:04 +0100 | [diff] [blame] | 2594 | rule->flags = flags; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2595 | LIST_INIT(&rule->list); |
| 2596 | LIST_ADDQ(&curproxy->redirect_rules, &rule->list); |
Willy Tarreau | 9d9ed01 | 2011-02-23 15:24:42 +0100 | [diff] [blame] | 2597 | err_code |= warnif_rule_after_use_backend(curproxy, file, linenum, args[0]); |
| 2598 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2599 | } |
Krzysztof Piotr Oledzki | 7b723ef | 2009-01-27 21:09:41 +0100 | [diff] [blame] | 2600 | else if (!strcmp(args[0], "use_backend")) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2601 | struct switching_rule *rule; |
| 2602 | |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2603 | if (curproxy == &defproxy) { |
| 2604 | 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] | 2605 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2606 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2607 | } |
| 2608 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2609 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2610 | err_code |= ERR_WARN; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2611 | |
| 2612 | if (*(args[1]) == 0) { |
| 2613 | 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] | 2614 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2615 | goto out; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2616 | } |
| 2617 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2618 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2619 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 2620 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2621 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2622 | goto out; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2623 | } |
| 2624 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 2625 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 2626 | Alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n", |
| 2627 | file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2628 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2629 | goto out; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2630 | } |
| 2631 | |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 2632 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
Willy Tarreau | a980263 | 2008-07-25 19:13:19 +0200 | [diff] [blame] | 2633 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2634 | rule = (struct switching_rule *)calloc(1, sizeof(*rule)); |
| 2635 | rule->cond = cond; |
| 2636 | rule->be.name = strdup(args[1]); |
| 2637 | LIST_INIT(&rule->list); |
| 2638 | LIST_ADDQ(&curproxy->switching_rules, &rule->list); |
| 2639 | } |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 2640 | else if (strcmp(args[0], "use-server") == 0) { |
| 2641 | struct server_rule *rule; |
| 2642 | |
| 2643 | if (curproxy == &defproxy) { |
| 2644 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2645 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2646 | goto out; |
| 2647 | } |
| 2648 | |
| 2649 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 2650 | err_code |= ERR_WARN; |
| 2651 | |
| 2652 | if (*(args[1]) == 0) { |
| 2653 | Alert("parsing [%s:%d] : '%s' expects a server name.\n", file, linenum, args[0]); |
| 2654 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2655 | goto out; |
| 2656 | } |
| 2657 | |
| 2658 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
| 2659 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 2660 | file, linenum, args[0]); |
| 2661 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2662 | goto out; |
| 2663 | } |
| 2664 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 2665 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 2666 | Alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n", |
| 2667 | file, linenum, errmsg); |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 2668 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2669 | goto out; |
| 2670 | } |
| 2671 | |
| 2672 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
| 2673 | |
| 2674 | rule = (struct server_rule *)calloc(1, sizeof(*rule)); |
| 2675 | rule->cond = cond; |
| 2676 | rule->srv.name = strdup(args[1]); |
| 2677 | LIST_INIT(&rule->list); |
| 2678 | LIST_ADDQ(&curproxy->server_rules, &rule->list); |
| 2679 | curproxy->be_req_ana |= AN_REQ_SRV_RULES; |
| 2680 | } |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 2681 | else if ((!strcmp(args[0], "force-persist")) || |
| 2682 | (!strcmp(args[0], "ignore-persist"))) { |
| 2683 | struct persist_rule *rule; |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2684 | |
| 2685 | if (curproxy == &defproxy) { |
| 2686 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2687 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2688 | goto out; |
| 2689 | } |
| 2690 | |
| 2691 | if (warnifnotcap(curproxy, PR_CAP_FE|PR_CAP_BE, file, linenum, args[0], NULL)) |
| 2692 | err_code |= ERR_WARN; |
| 2693 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2694 | if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) { |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2695 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 2696 | file, linenum, args[0]); |
| 2697 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2698 | goto out; |
| 2699 | } |
| 2700 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 2701 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 1, &errmsg)) == NULL) { |
| 2702 | Alert("parsing [%s:%d] : error detected while parsing a '%s' rule : %s.\n", |
| 2703 | file, linenum, args[0], errmsg); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2704 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2705 | goto out; |
| 2706 | } |
| 2707 | |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 2708 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2709 | |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 2710 | rule = (struct persist_rule *)calloc(1, sizeof(*rule)); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2711 | rule->cond = cond; |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 2712 | if (!strcmp(args[0], "force-persist")) { |
| 2713 | rule->type = PERSIST_TYPE_FORCE; |
| 2714 | } else { |
| 2715 | rule->type = PERSIST_TYPE_IGNORE; |
| 2716 | } |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2717 | LIST_INIT(&rule->list); |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 2718 | LIST_ADDQ(&curproxy->persist_rules, &rule->list); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2719 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2720 | else if (!strcmp(args[0], "stick-table")) { |
| 2721 | int myidx = 1; |
| 2722 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2723 | curproxy->table.id = curproxy->id; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2724 | curproxy->table.type = (unsigned int)-1; |
| 2725 | while (*args[myidx]) { |
| 2726 | const char *err; |
| 2727 | |
| 2728 | if (strcmp(args[myidx], "size") == 0) { |
| 2729 | myidx++; |
| 2730 | if (!*(args[myidx])) { |
| 2731 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 2732 | file, linenum, args[myidx-1]); |
| 2733 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2734 | goto out; |
| 2735 | } |
| 2736 | if ((err = parse_size_err(args[myidx], &curproxy->table.size))) { |
| 2737 | Alert("parsing [%s:%d] : stick-table: unexpected character '%c' in argument of '%s'.\n", |
| 2738 | file, linenum, *err, args[myidx-1]); |
| 2739 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2740 | goto out; |
| 2741 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 2742 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2743 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2744 | else if (strcmp(args[myidx], "peers") == 0) { |
| 2745 | myidx++; |
| 2746 | if (!*(args[myidx])) { |
| 2747 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 2748 | file, linenum, args[myidx-1]); |
| 2749 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2750 | goto out; |
| 2751 | } |
| 2752 | curproxy->table.peers.name = strdup(args[myidx++]); |
| 2753 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2754 | else if (strcmp(args[myidx], "expire") == 0) { |
| 2755 | myidx++; |
| 2756 | if (!*(args[myidx])) { |
| 2757 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 2758 | file, linenum, args[myidx-1]); |
| 2759 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2760 | goto out; |
| 2761 | } |
| 2762 | err = parse_time_err(args[myidx], &val, TIME_UNIT_MS); |
| 2763 | if (err) { |
| 2764 | Alert("parsing [%s:%d] : stick-table: unexpected character '%c' in argument of '%s'.\n", |
| 2765 | file, linenum, *err, args[myidx-1]); |
| 2766 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2767 | goto out; |
| 2768 | } |
| 2769 | curproxy->table.expire = val; |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 2770 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2771 | } |
| 2772 | else if (strcmp(args[myidx], "nopurge") == 0) { |
| 2773 | curproxy->table.nopurge = 1; |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 2774 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2775 | } |
| 2776 | else if (strcmp(args[myidx], "type") == 0) { |
| 2777 | myidx++; |
| 2778 | if (stktable_parse_type(args, &myidx, &curproxy->table.type, &curproxy->table.key_size) != 0) { |
| 2779 | Alert("parsing [%s:%d] : stick-table: unknown type '%s'.\n", |
| 2780 | file, linenum, args[myidx]); |
| 2781 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2782 | goto out; |
| 2783 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 2784 | /* myidx already points to next arg */ |
| 2785 | } |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 2786 | else if (strcmp(args[myidx], "store") == 0) { |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 2787 | int type, err; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 2788 | char *cw, *nw, *sa; |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 2789 | |
| 2790 | myidx++; |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 2791 | nw = args[myidx]; |
| 2792 | while (*nw) { |
| 2793 | /* the "store" keyword supports a comma-separated list */ |
| 2794 | cw = nw; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 2795 | sa = NULL; /* store arg */ |
| 2796 | while (*nw && *nw != ',') { |
| 2797 | if (*nw == '(') { |
| 2798 | *nw = 0; |
| 2799 | sa = ++nw; |
| 2800 | while (*nw != ')') { |
| 2801 | if (!*nw) { |
| 2802 | Alert("parsing [%s:%d] : %s: missing closing parenthesis after store option '%s'.\n", |
| 2803 | file, linenum, args[0], cw); |
| 2804 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2805 | goto out; |
| 2806 | } |
| 2807 | nw++; |
| 2808 | } |
| 2809 | *nw = '\0'; |
| 2810 | } |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 2811 | nw++; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 2812 | } |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 2813 | if (*nw) |
| 2814 | *nw++ = '\0'; |
| 2815 | type = stktable_get_data_type(cw); |
| 2816 | if (type < 0) { |
| 2817 | Alert("parsing [%s:%d] : %s: unknown store option '%s'.\n", |
| 2818 | file, linenum, args[0], cw); |
| 2819 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2820 | goto out; |
| 2821 | } |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 2822 | |
| 2823 | err = stktable_alloc_data_type(&curproxy->table, type, sa); |
| 2824 | switch (err) { |
| 2825 | case PE_NONE: break; |
| 2826 | case PE_EXIST: |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 2827 | Warning("parsing [%s:%d]: %s: store option '%s' already enabled, ignored.\n", |
| 2828 | file, linenum, args[0], cw); |
| 2829 | err_code |= ERR_WARN; |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 2830 | break; |
| 2831 | |
| 2832 | case PE_ARG_MISSING: |
| 2833 | Alert("parsing [%s:%d] : %s: missing argument to store option '%s'.\n", |
| 2834 | file, linenum, args[0], cw); |
| 2835 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2836 | goto out; |
| 2837 | |
| 2838 | case PE_ARG_NOT_USED: |
| 2839 | Alert("parsing [%s:%d] : %s: unexpected argument to store option '%s'.\n", |
| 2840 | file, linenum, args[0], cw); |
| 2841 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2842 | goto out; |
| 2843 | |
| 2844 | default: |
| 2845 | Alert("parsing [%s:%d] : %s: error when processing store option '%s'.\n", |
| 2846 | file, linenum, args[0], cw); |
| 2847 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2848 | goto out; |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 2849 | } |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 2850 | } |
| 2851 | myidx++; |
| 2852 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 2853 | else { |
| 2854 | Alert("parsing [%s:%d] : stick-table: unknown argument '%s'.\n", |
| 2855 | file, linenum, args[myidx]); |
| 2856 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2857 | goto out; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2858 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2859 | } |
| 2860 | |
| 2861 | if (!curproxy->table.size) { |
| 2862 | Alert("parsing [%s:%d] : stick-table: missing size.\n", |
| 2863 | file, linenum); |
| 2864 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2865 | goto out; |
| 2866 | } |
| 2867 | |
| 2868 | if (curproxy->table.type == (unsigned int)-1) { |
| 2869 | Alert("parsing [%s:%d] : stick-table: missing type.\n", |
| 2870 | file, linenum); |
| 2871 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2872 | goto out; |
| 2873 | } |
| 2874 | } |
| 2875 | else if (!strcmp(args[0], "stick")) { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2876 | struct sticking_rule *rule; |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 2877 | struct sample_expr *expr; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2878 | int myidx = 0; |
| 2879 | const char *name = NULL; |
| 2880 | int flags; |
| 2881 | |
| 2882 | if (curproxy == &defproxy) { |
| 2883 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2884 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2885 | goto out; |
| 2886 | } |
| 2887 | |
| 2888 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) { |
| 2889 | err_code |= ERR_WARN; |
| 2890 | goto out; |
| 2891 | } |
| 2892 | |
| 2893 | myidx++; |
| 2894 | if ((strcmp(args[myidx], "store") == 0) || |
| 2895 | (strcmp(args[myidx], "store-request") == 0)) { |
| 2896 | myidx++; |
| 2897 | flags = STK_IS_STORE; |
| 2898 | } |
| 2899 | else if (strcmp(args[myidx], "store-response") == 0) { |
| 2900 | myidx++; |
| 2901 | flags = STK_IS_STORE | STK_ON_RSP; |
| 2902 | } |
| 2903 | else if (strcmp(args[myidx], "match") == 0) { |
| 2904 | myidx++; |
| 2905 | flags = STK_IS_MATCH; |
| 2906 | } |
| 2907 | else if (strcmp(args[myidx], "on") == 0) { |
| 2908 | myidx++; |
| 2909 | flags = STK_IS_MATCH | STK_IS_STORE; |
| 2910 | } |
| 2911 | else { |
| 2912 | Alert("parsing [%s:%d] : '%s' expects 'on', 'match', or 'store'.\n", file, linenum, args[0]); |
| 2913 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2914 | goto out; |
| 2915 | } |
| 2916 | |
| 2917 | if (*(args[myidx]) == 0) { |
| 2918 | Alert("parsing [%s:%d] : '%s' expects a fetch method.\n", file, linenum, args[0]); |
| 2919 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2920 | goto out; |
| 2921 | } |
| 2922 | |
David du Colombier | 7af4605 | 2012-05-16 14:16:48 +0200 | [diff] [blame] | 2923 | expr = sample_parse_expr(args, &myidx, trash, trashlen); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2924 | if (!expr) { |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 2925 | Alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], trash); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2926 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2927 | goto out; |
| 2928 | } |
| 2929 | |
| 2930 | if (flags & STK_ON_RSP) { |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 2931 | if (!(expr->fetch->cap & SMP_CAP_RES)) { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2932 | Alert("parsing [%s:%d] : '%s': fetch method '%s' can not be used on response.\n", |
| 2933 | file, linenum, args[0], expr->fetch->kw); |
| 2934 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 2935 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2936 | goto out; |
| 2937 | } |
| 2938 | } else { |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 2939 | if (!(expr->fetch->cap & SMP_CAP_REQ)) { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2940 | Alert("parsing [%s:%d] : '%s': fetch method '%s' can not be used on request.\n", |
| 2941 | file, linenum, args[0], expr->fetch->kw); |
| 2942 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 2943 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2944 | goto out; |
| 2945 | } |
| 2946 | } |
| 2947 | |
| 2948 | if (strcmp(args[myidx], "table") == 0) { |
| 2949 | myidx++; |
| 2950 | name = args[myidx++]; |
| 2951 | } |
| 2952 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2953 | if (strcmp(args[myidx], "if") == 0 || strcmp(args[myidx], "unless") == 0) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 2954 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + myidx, &errmsg)) == NULL) { |
| 2955 | Alert("parsing [%s:%d] : '%s': error detected while parsing sticking condition : %s.\n", |
| 2956 | file, linenum, args[0], errmsg); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2957 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 2958 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2959 | goto out; |
| 2960 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2961 | } |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2962 | else if (*(args[myidx])) { |
| 2963 | Alert("parsing [%s:%d] : '%s': unknown keyword '%s'.\n", |
| 2964 | file, linenum, args[0], args[myidx]); |
| 2965 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 2966 | free(expr); |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2967 | goto out; |
| 2968 | } |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 2969 | if (flags & STK_ON_RSP) |
| 2970 | err_code |= warnif_cond_requires_req(cond, file, linenum); |
| 2971 | else |
| 2972 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 2973 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2974 | rule = (struct sticking_rule *)calloc(1, sizeof(*rule)); |
| 2975 | rule->cond = cond; |
| 2976 | rule->expr = expr; |
| 2977 | rule->flags = flags; |
| 2978 | rule->table.name = name ? strdup(name) : NULL; |
| 2979 | LIST_INIT(&rule->list); |
| 2980 | if (flags & STK_ON_RSP) |
| 2981 | LIST_ADDQ(&curproxy->storersp_rules, &rule->list); |
| 2982 | else |
| 2983 | LIST_ADDQ(&curproxy->sticking_rules, &rule->list); |
| 2984 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2985 | else if (!strcmp(args[0], "stats")) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2986 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2987 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2988 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2989 | if (curproxy != &defproxy && curproxy->uri_auth == defproxy.uri_auth) |
| 2990 | curproxy->uri_auth = NULL; /* we must detach from the default config */ |
| 2991 | |
Krzysztof Piotr Oledzki | 260a3bb | 2010-01-06 16:25:05 +0100 | [diff] [blame] | 2992 | if (!*args[1]) { |
| 2993 | goto stats_error_parsing; |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 2994 | } else if (!strcmp(args[1], "admin")) { |
| 2995 | struct stats_admin_rule *rule; |
| 2996 | |
| 2997 | if (curproxy == &defproxy) { |
| 2998 | Alert("parsing [%s:%d]: '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
| 2999 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3000 | goto out; |
| 3001 | } |
| 3002 | |
| 3003 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 3004 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3005 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3006 | goto out; |
| 3007 | } |
| 3008 | |
| 3009 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
| 3010 | Alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n", |
| 3011 | file, linenum, args[0], args[1]); |
| 3012 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3013 | goto out; |
| 3014 | } |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 3015 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 3016 | Alert("parsing [%s:%d] : error detected while parsing a '%s %s' rule : %s.\n", |
| 3017 | file, linenum, args[0], args[1], errmsg); |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3018 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3019 | goto out; |
| 3020 | } |
| 3021 | |
| 3022 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
| 3023 | |
| 3024 | rule = (struct stats_admin_rule *)calloc(1, sizeof(*rule)); |
| 3025 | rule->cond = cond; |
| 3026 | LIST_INIT(&rule->list); |
| 3027 | LIST_ADDQ(&curproxy->uri_auth->admin_rules, &rule->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3028 | } else if (!strcmp(args[1], "uri")) { |
| 3029 | if (*(args[2]) == 0) { |
| 3030 | Alert("parsing [%s:%d] : 'uri' needs an URI prefix.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3031 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3032 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3033 | } else if (!stats_set_uri(&curproxy->uri_auth, args[2])) { |
| 3034 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3035 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3036 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3037 | } |
| 3038 | } else if (!strcmp(args[1], "realm")) { |
| 3039 | if (*(args[2]) == 0) { |
| 3040 | Alert("parsing [%s:%d] : 'realm' needs an realm name.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3041 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3042 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3043 | } else if (!stats_set_realm(&curproxy->uri_auth, args[2])) { |
| 3044 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3045 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3046 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3047 | } |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 3048 | } else if (!strcmp(args[1], "refresh")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 3049 | unsigned interval; |
| 3050 | |
| 3051 | err = parse_time_err(args[2], &interval, TIME_UNIT_S); |
| 3052 | if (err) { |
| 3053 | Alert("parsing [%s:%d] : unexpected character '%c' in stats refresh interval.\n", |
| 3054 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3055 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3056 | goto out; |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 3057 | } else if (!stats_set_refresh(&curproxy->uri_auth, interval)) { |
| 3058 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3059 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3060 | goto out; |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 3061 | } |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3062 | } 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] | 3063 | struct http_req_rule *rule; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3064 | |
| 3065 | if (curproxy == &defproxy) { |
| 3066 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3067 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3068 | goto out; |
| 3069 | } |
| 3070 | |
| 3071 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 3072 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3073 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3074 | goto out; |
| 3075 | } |
| 3076 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3077 | if (!LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) && |
| 3078 | !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] | 3079 | Warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n", |
| 3080 | file, linenum, args[0]); |
| 3081 | err_code |= ERR_WARN; |
| 3082 | } |
| 3083 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3084 | 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] | 3085 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3086 | if (!rule) { |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3087 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3088 | goto out; |
| 3089 | } |
| 3090 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3091 | err_code |= warnif_cond_requires_resp(rule->cond, file, linenum); |
| 3092 | LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list); |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3093 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3094 | } else if (!strcmp(args[1], "auth")) { |
| 3095 | if (*(args[2]) == 0) { |
| 3096 | 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] | 3097 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3098 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3099 | } else if (!stats_add_auth(&curproxy->uri_auth, args[2])) { |
| 3100 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3101 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3102 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3103 | } |
| 3104 | } else if (!strcmp(args[1], "scope")) { |
| 3105 | if (*(args[2]) == 0) { |
| 3106 | Alert("parsing [%s:%d] : 'scope' needs a proxy name.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3107 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3108 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3109 | } else if (!stats_add_scope(&curproxy->uri_auth, args[2])) { |
| 3110 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3111 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3112 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3113 | } |
| 3114 | } else if (!strcmp(args[1], "enable")) { |
| 3115 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 3116 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3117 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3118 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3119 | } |
Krzysztof Oledzki | d9db927 | 2007-10-15 10:05:11 +0200 | [diff] [blame] | 3120 | } else if (!strcmp(args[1], "hide-version")) { |
| 3121 | if (!stats_set_flag(&curproxy->uri_auth, ST_HIDEVER)) { |
| 3122 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3123 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3124 | goto out; |
Krzysztof Oledzki | d9db927 | 2007-10-15 10:05:11 +0200 | [diff] [blame] | 3125 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3126 | } else if (!strcmp(args[1], "show-legends")) { |
| 3127 | if (!stats_set_flag(&curproxy->uri_auth, ST_SHLGNDS)) { |
| 3128 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3129 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3130 | goto out; |
| 3131 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3132 | } else if (!strcmp(args[1], "show-node")) { |
| 3133 | |
| 3134 | if (*args[2]) { |
| 3135 | int i; |
| 3136 | char c; |
| 3137 | |
| 3138 | for (i=0; args[2][i]; i++) { |
| 3139 | c = args[2][i]; |
Willy Tarreau | 88e0581 | 2010-03-03 00:16:00 +0100 | [diff] [blame] | 3140 | if (!isupper((unsigned char)c) && !islower((unsigned char)c) && |
| 3141 | !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.') |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3142 | break; |
| 3143 | } |
| 3144 | |
| 3145 | if (!i || args[2][i]) { |
| 3146 | Alert("parsing [%s:%d]: '%s %s' invalid node name - should be a string" |
| 3147 | "with digits(0-9), letters(A-Z, a-z), hyphen(-) or underscode(_).\n", |
| 3148 | file, linenum, args[0], args[1]); |
| 3149 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3150 | goto out; |
| 3151 | } |
| 3152 | } |
| 3153 | |
| 3154 | if (!stats_set_node(&curproxy->uri_auth, args[2])) { |
| 3155 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3156 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3157 | goto out; |
| 3158 | } |
| 3159 | } else if (!strcmp(args[1], "show-desc")) { |
| 3160 | char *desc = NULL; |
| 3161 | |
| 3162 | if (*args[2]) { |
| 3163 | int i, len=0; |
| 3164 | char *d; |
| 3165 | |
| 3166 | for(i=2; *args[i]; i++) |
| 3167 | len += strlen(args[i])+1; |
| 3168 | |
| 3169 | desc = d = (char *)calloc(1, len); |
| 3170 | |
| 3171 | d += sprintf(d, "%s", args[2]); |
| 3172 | for(i=3; *args[i]; i++) |
| 3173 | d += sprintf(d, " %s", args[i]); |
| 3174 | } |
| 3175 | |
| 3176 | if (!*args[2] && !global.desc) |
| 3177 | Warning("parsing [%s:%d]: '%s' requires a parameter or 'desc' to be set in the global section.\n", |
| 3178 | file, linenum, args[1]); |
| 3179 | else { |
| 3180 | if (!stats_set_desc(&curproxy->uri_auth, desc)) { |
| 3181 | free(desc); |
| 3182 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3183 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3184 | goto out; |
| 3185 | } |
| 3186 | free(desc); |
| 3187 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3188 | } else { |
Krzysztof Piotr Oledzki | 260a3bb | 2010-01-06 16:25:05 +0100 | [diff] [blame] | 3189 | stats_error_parsing: |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3190 | 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] | 3191 | 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] | 3192 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3193 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3194 | } |
| 3195 | } |
| 3196 | else if (!strcmp(args[0], "option")) { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3197 | int optnum; |
| 3198 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3199 | if (*(args[1]) == '\0') { |
| 3200 | Alert("parsing [%s:%d]: '%s' expects an option name.\n", |
| 3201 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3202 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3203 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3204 | } |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3205 | |
| 3206 | for (optnum = 0; cfg_opts[optnum].name; optnum++) { |
| 3207 | if (!strcmp(args[1], cfg_opts[optnum].name)) { |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 3208 | if (cfg_opts[optnum].cap == PR_CAP_NONE) { |
| 3209 | Alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n", |
| 3210 | file, linenum, cfg_opts[optnum].name); |
| 3211 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3212 | goto out; |
| 3213 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3214 | if (warnifnotcap(curproxy, cfg_opts[optnum].cap, file, linenum, args[1], NULL)) { |
| 3215 | err_code |= ERR_WARN; |
| 3216 | goto out; |
| 3217 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3218 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 3219 | curproxy->no_options &= ~cfg_opts[optnum].val; |
| 3220 | curproxy->options &= ~cfg_opts[optnum].val; |
| 3221 | |
| 3222 | switch (kwm) { |
| 3223 | case KWM_STD: |
| 3224 | curproxy->options |= cfg_opts[optnum].val; |
| 3225 | break; |
| 3226 | case KWM_NO: |
| 3227 | curproxy->no_options |= cfg_opts[optnum].val; |
| 3228 | break; |
| 3229 | case KWM_DEF: /* already cleared */ |
| 3230 | break; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 3231 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3232 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3233 | goto out; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3234 | } |
| 3235 | } |
| 3236 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 3237 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) { |
| 3238 | if (!strcmp(args[1], cfg_opts2[optnum].name)) { |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 3239 | if (cfg_opts2[optnum].cap == PR_CAP_NONE) { |
| 3240 | Alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n", |
| 3241 | file, linenum, cfg_opts2[optnum].name); |
| 3242 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3243 | goto out; |
| 3244 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3245 | if (warnifnotcap(curproxy, cfg_opts2[optnum].cap, file, linenum, args[1], NULL)) { |
| 3246 | err_code |= ERR_WARN; |
| 3247 | goto out; |
| 3248 | } |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 3249 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 3250 | curproxy->no_options2 &= ~cfg_opts2[optnum].val; |
| 3251 | curproxy->options2 &= ~cfg_opts2[optnum].val; |
| 3252 | |
| 3253 | switch (kwm) { |
| 3254 | case KWM_STD: |
| 3255 | curproxy->options2 |= cfg_opts2[optnum].val; |
| 3256 | break; |
| 3257 | case KWM_NO: |
| 3258 | curproxy->no_options2 |= cfg_opts2[optnum].val; |
| 3259 | break; |
| 3260 | case KWM_DEF: /* already cleared */ |
| 3261 | break; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 3262 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3263 | goto out; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 3264 | } |
| 3265 | } |
| 3266 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 3267 | if (kwm != KWM_STD) { |
| 3268 | 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] | 3269 | file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3270 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3271 | goto out; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3272 | } |
| 3273 | |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3274 | if (!strcmp(args[1], "httplog")) { |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 3275 | char *logformat; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3276 | /* generate a complete HTTP log */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 3277 | logformat = default_http_log_format; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3278 | if (*(args[2]) != '\0') { |
| 3279 | if (!strcmp(args[2], "clf")) { |
| 3280 | curproxy->options2 |= PR_O2_CLFLOG; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 3281 | logformat = clf_http_log_format; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3282 | } else { |
| 3283 | 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] | 3284 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3285 | goto out; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3286 | } |
| 3287 | } |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 3288 | if (curproxy->logformat_string != default_http_log_format && |
| 3289 | curproxy->logformat_string != default_tcp_log_format && |
| 3290 | curproxy->logformat_string != clf_http_log_format) |
| 3291 | free(curproxy->logformat_string); |
| 3292 | curproxy->logformat_string = logformat; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3293 | } |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 3294 | else if (!strcmp(args[1], "tcplog")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3295 | /* generate a detailed TCP log */ |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 3296 | if (curproxy->logformat_string != default_http_log_format && |
| 3297 | curproxy->logformat_string != default_tcp_log_format && |
| 3298 | curproxy->logformat_string != clf_http_log_format) |
| 3299 | free(curproxy->logformat_string); |
| 3300 | curproxy->logformat_string = default_tcp_log_format; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 3301 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3302 | else if (!strcmp(args[1], "tcpka")) { |
| 3303 | /* enable TCP keep-alives on client and server sessions */ |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3304 | 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] | 3305 | err_code |= ERR_WARN; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3306 | |
| 3307 | if (curproxy->cap & PR_CAP_FE) |
| 3308 | curproxy->options |= PR_O_TCP_CLI_KA; |
| 3309 | if (curproxy->cap & PR_CAP_BE) |
| 3310 | curproxy->options |= PR_O_TCP_SRV_KA; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3311 | } |
| 3312 | else if (!strcmp(args[1], "httpchk")) { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3313 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3314 | err_code |= ERR_WARN; |
| 3315 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3316 | /* use HTTP request to check servers' health */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3317 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 3318 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3319 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 3320 | curproxy->options2 |= PR_O2_HTTP_CHK; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3321 | if (!*args[2]) { /* no argument */ |
| 3322 | curproxy->check_req = strdup(DEF_CHECK_REQ); /* default request */ |
| 3323 | curproxy->check_len = strlen(DEF_CHECK_REQ); |
| 3324 | } else if (!*args[3]) { /* one argument : URI */ |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3325 | 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] | 3326 | curproxy->check_req = (char *)malloc(reqlen); |
| 3327 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3328 | "OPTIONS %s HTTP/1.0\r\n", args[2]); /* URI to use */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3329 | } else { /* more arguments : METHOD URI [HTTP_VER] */ |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3330 | int reqlen = strlen(args[2]) + strlen(args[3]) + 3 + strlen("\r\n"); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3331 | if (*args[4]) |
| 3332 | reqlen += strlen(args[4]); |
| 3333 | else |
| 3334 | reqlen += strlen("HTTP/1.0"); |
| 3335 | |
| 3336 | curproxy->check_req = (char *)malloc(reqlen); |
| 3337 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3338 | "%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] | 3339 | } |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 3340 | } |
| 3341 | else if (!strcmp(args[1], "ssl-hello-chk")) { |
| 3342 | /* use SSLv3 CLIENT HELLO to check servers' health */ |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3343 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3344 | err_code |= ERR_WARN; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3345 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3346 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 3347 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3348 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Willy Tarreau | 07a5490 | 2010-03-29 18:33:29 +0200 | [diff] [blame] | 3349 | curproxy->options2 |= PR_O2_SSL3_CHK; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3350 | } |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 3351 | else if (!strcmp(args[1], "smtpchk")) { |
| 3352 | /* use SMTP request to check servers' health */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3353 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 3354 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3355 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 3356 | curproxy->options2 |= PR_O2_SMTP_CHK; |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 3357 | |
| 3358 | if (!*args[2] || !*args[3]) { /* no argument or incomplete EHLO host */ |
| 3359 | curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */ |
| 3360 | curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ); |
| 3361 | } else { /* ESMTP EHLO, or SMTP HELO, and a hostname */ |
| 3362 | if (!strcmp(args[2], "EHLO") || !strcmp(args[2], "HELO")) { |
| 3363 | int reqlen = strlen(args[2]) + strlen(args[3]) + strlen(" \r\n") + 1; |
| 3364 | curproxy->check_req = (char *)malloc(reqlen); |
| 3365 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
| 3366 | "%s %s\r\n", args[2], args[3]); /* HELO hostname */ |
| 3367 | } else { |
| 3368 | /* this just hits the default for now, but you could potentially expand it to allow for other stuff |
| 3369 | though, it's unlikely you'd want to send anything other than an EHLO or HELO */ |
| 3370 | curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */ |
| 3371 | curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ); |
| 3372 | } |
| 3373 | } |
| 3374 | } |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 3375 | else if (!strcmp(args[1], "pgsql-check")) { |
| 3376 | /* use PostgreSQL request to check servers' health */ |
| 3377 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 3378 | err_code |= ERR_WARN; |
| 3379 | |
| 3380 | free(curproxy->check_req); |
| 3381 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3382 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 3383 | curproxy->options2 |= PR_O2_PGSQL_CHK; |
| 3384 | |
| 3385 | if (*(args[2])) { |
| 3386 | int cur_arg = 2; |
| 3387 | |
| 3388 | while (*(args[cur_arg])) { |
| 3389 | if (strcmp(args[cur_arg], "user") == 0) { |
| 3390 | char * packet; |
| 3391 | uint32_t packet_len; |
| 3392 | uint32_t pv; |
| 3393 | |
| 3394 | /* suboption header - needs additional argument for it */ |
| 3395 | if (*(args[cur_arg+1]) == 0) { |
| 3396 | Alert("parsing [%s:%d] : '%s %s %s' expects <username> as argument.\n", |
| 3397 | file, linenum, args[0], args[1], args[cur_arg]); |
| 3398 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3399 | goto out; |
| 3400 | } |
| 3401 | |
| 3402 | /* uint32_t + uint32_t + strlen("user")+1 + strlen(username)+1 + 1 */ |
| 3403 | packet_len = 4 + 4 + 5 + strlen(args[cur_arg + 1])+1 +1; |
| 3404 | pv = htonl(0x30000); /* protocol version 3.0 */ |
| 3405 | |
| 3406 | packet = (char*) calloc(1, packet_len); |
| 3407 | |
| 3408 | memcpy(packet + 4, &pv, 4); |
| 3409 | |
| 3410 | /* copy "user" */ |
| 3411 | memcpy(packet + 8, "user", 4); |
| 3412 | |
| 3413 | /* copy username */ |
| 3414 | memcpy(packet + 13, args[cur_arg+1], strlen(args[cur_arg+1])); |
| 3415 | |
| 3416 | free(curproxy->check_req); |
| 3417 | curproxy->check_req = packet; |
| 3418 | curproxy->check_len = packet_len; |
| 3419 | |
| 3420 | packet_len = htonl(packet_len); |
| 3421 | memcpy(packet, &packet_len, 4); |
| 3422 | cur_arg += 2; |
| 3423 | } else { |
| 3424 | /* unknown suboption - catchall */ |
| 3425 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'user'.\n", |
| 3426 | file, linenum, args[0], args[1]); |
| 3427 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3428 | goto out; |
| 3429 | } |
| 3430 | } /* end while loop */ |
| 3431 | } |
| 3432 | } |
| 3433 | |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 3434 | else if (!strcmp(args[1], "redis-check")) { |
| 3435 | /* use REDIS PING request to check servers' health */ |
| 3436 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 3437 | err_code |= ERR_WARN; |
| 3438 | |
| 3439 | free(curproxy->check_req); |
| 3440 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3441 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 3442 | curproxy->options2 |= PR_O2_REDIS_CHK; |
| 3443 | |
| 3444 | curproxy->check_req = (char *) malloc(sizeof(DEF_REDIS_CHECK_REQ) - 1); |
| 3445 | memcpy(curproxy->check_req, DEF_REDIS_CHECK_REQ, sizeof(DEF_REDIS_CHECK_REQ) - 1); |
| 3446 | curproxy->check_len = sizeof(DEF_REDIS_CHECK_REQ) - 1; |
| 3447 | } |
| 3448 | |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 3449 | else if (!strcmp(args[1], "mysql-check")) { |
| 3450 | /* use MYSQL request to check servers' health */ |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 3451 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 3452 | err_code |= ERR_WARN; |
| 3453 | |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 3454 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 3455 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3456 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 3457 | curproxy->options2 |= PR_O2_MYSQL_CHK; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 3458 | |
| 3459 | /* This is an exemple of an MySQL >=4.0 client Authentication packet kindly provided by Cyril Bonte. |
| 3460 | * const char mysql40_client_auth_pkt[] = { |
| 3461 | * "\x0e\x00\x00" // packet length |
| 3462 | * "\x01" // packet number |
| 3463 | * "\x00\x00" // client capabilities |
| 3464 | * "\x00\x00\x01" // max packet |
| 3465 | * "haproxy\x00" // username (null terminated string) |
| 3466 | * "\x00" // filler (always 0x00) |
| 3467 | * "\x01\x00\x00" // packet length |
| 3468 | * "\x00" // packet number |
| 3469 | * "\x01" // COM_QUIT command |
| 3470 | * }; |
| 3471 | */ |
| 3472 | |
| 3473 | if (*(args[2])) { |
| 3474 | int cur_arg = 2; |
| 3475 | |
| 3476 | while (*(args[cur_arg])) { |
| 3477 | if (strcmp(args[cur_arg], "user") == 0) { |
| 3478 | char *mysqluser; |
| 3479 | int packetlen, reqlen, userlen; |
| 3480 | |
| 3481 | /* suboption header - needs additional argument for it */ |
| 3482 | if (*(args[cur_arg+1]) == 0) { |
| 3483 | Alert("parsing [%s:%d] : '%s %s %s' expects <username> as argument.\n", |
| 3484 | file, linenum, args[0], args[1], args[cur_arg]); |
| 3485 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3486 | goto out; |
| 3487 | } |
| 3488 | mysqluser = args[cur_arg + 1]; |
| 3489 | userlen = strlen(mysqluser); |
| 3490 | packetlen = userlen + 7; |
| 3491 | reqlen = packetlen + 9; |
| 3492 | |
| 3493 | free(curproxy->check_req); |
| 3494 | curproxy->check_req = (char *)calloc(1, reqlen); |
| 3495 | curproxy->check_len = reqlen; |
| 3496 | |
| 3497 | snprintf(curproxy->check_req, 4, "%c%c%c", |
| 3498 | ((unsigned char) packetlen & 0xff), |
| 3499 | ((unsigned char) (packetlen >> 8) & 0xff), |
| 3500 | ((unsigned char) (packetlen >> 16) & 0xff)); |
| 3501 | |
| 3502 | curproxy->check_req[3] = 1; |
Hervé COMMOWICK | 212f778 | 2011-06-10 14:05:59 +0200 | [diff] [blame] | 3503 | curproxy->check_req[5] = 128; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 3504 | curproxy->check_req[8] = 1; |
| 3505 | memcpy(&curproxy->check_req[9], mysqluser, userlen); |
| 3506 | curproxy->check_req[9 + userlen + 1 + 1] = 1; |
| 3507 | curproxy->check_req[9 + userlen + 1 + 1 + 4] = 1; |
| 3508 | cur_arg += 2; |
| 3509 | } else { |
| 3510 | /* unknown suboption - catchall */ |
| 3511 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'user'.\n", |
| 3512 | file, linenum, args[0], args[1]); |
| 3513 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3514 | goto out; |
| 3515 | } |
| 3516 | } /* end while loop */ |
| 3517 | } |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 3518 | } |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 3519 | else if (!strcmp(args[1], "ldap-check")) { |
| 3520 | /* use LDAP request to check servers' health */ |
| 3521 | free(curproxy->check_req); |
| 3522 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3523 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 3524 | curproxy->options2 |= PR_O2_LDAP_CHK; |
| 3525 | |
| 3526 | curproxy->check_req = (char *) malloc(sizeof(DEF_LDAP_CHECK_REQ) - 1); |
| 3527 | memcpy(curproxy->check_req, DEF_LDAP_CHECK_REQ, sizeof(DEF_LDAP_CHECK_REQ) - 1); |
| 3528 | curproxy->check_len = sizeof(DEF_LDAP_CHECK_REQ) - 1; |
| 3529 | } |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3530 | else if (!strcmp(args[1], "forwardfor")) { |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3531 | int cur_arg; |
| 3532 | |
| 3533 | /* insert x-forwarded-for field, but not for the IP address listed as an except. |
| 3534 | * set default options (ie: bitfield, header name, etc) |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3535 | */ |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3536 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 3537 | curproxy->options |= PR_O_FWDFOR | PR_O_FF_ALWAYS; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3538 | |
| 3539 | free(curproxy->fwdfor_hdr_name); |
| 3540 | curproxy->fwdfor_hdr_name = strdup(DEF_XFORWARDFOR_HDR); |
| 3541 | curproxy->fwdfor_hdr_len = strlen(DEF_XFORWARDFOR_HDR); |
| 3542 | |
| 3543 | /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */ |
| 3544 | cur_arg = 2; |
| 3545 | while (*(args[cur_arg])) { |
| 3546 | if (!strcmp(args[cur_arg], "except")) { |
| 3547 | /* suboption except - needs additional argument for it */ |
| 3548 | if (!*(args[cur_arg+1]) || !str2net(args[cur_arg+1], &curproxy->except_net, &curproxy->except_mask)) { |
| 3549 | Alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n", |
| 3550 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3551 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3552 | goto out; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3553 | } |
| 3554 | /* flush useless bits */ |
| 3555 | curproxy->except_net.s_addr &= curproxy->except_mask.s_addr; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3556 | cur_arg += 2; |
| 3557 | } else if (!strcmp(args[cur_arg], "header")) { |
| 3558 | /* suboption header - needs additional argument for it */ |
| 3559 | if (*(args[cur_arg+1]) == 0) { |
| 3560 | Alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 3561 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3562 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3563 | goto out; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3564 | } |
| 3565 | free(curproxy->fwdfor_hdr_name); |
| 3566 | curproxy->fwdfor_hdr_name = strdup(args[cur_arg+1]); |
| 3567 | curproxy->fwdfor_hdr_len = strlen(curproxy->fwdfor_hdr_name); |
| 3568 | cur_arg += 2; |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 3569 | } else if (!strcmp(args[cur_arg], "if-none")) { |
| 3570 | curproxy->options &= ~PR_O_FF_ALWAYS; |
| 3571 | cur_arg += 1; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3572 | } else { |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3573 | /* unknown suboption - catchall */ |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 3574 | 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] | 3575 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3576 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3577 | goto out; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3578 | } |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3579 | } /* end while loop */ |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3580 | } |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 3581 | else if (!strcmp(args[1], "originalto")) { |
| 3582 | int cur_arg; |
| 3583 | |
| 3584 | /* insert x-original-to field, but not for the IP address listed as an except. |
| 3585 | * set default options (ie: bitfield, header name, etc) |
| 3586 | */ |
| 3587 | |
| 3588 | curproxy->options |= PR_O_ORGTO; |
| 3589 | |
| 3590 | free(curproxy->orgto_hdr_name); |
| 3591 | curproxy->orgto_hdr_name = strdup(DEF_XORIGINALTO_HDR); |
| 3592 | curproxy->orgto_hdr_len = strlen(DEF_XORIGINALTO_HDR); |
| 3593 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 3594 | /* 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] | 3595 | cur_arg = 2; |
| 3596 | while (*(args[cur_arg])) { |
| 3597 | if (!strcmp(args[cur_arg], "except")) { |
| 3598 | /* suboption except - needs additional argument for it */ |
| 3599 | if (!*(args[cur_arg+1]) || !str2net(args[cur_arg+1], &curproxy->except_to, &curproxy->except_mask_to)) { |
| 3600 | Alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n", |
| 3601 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3602 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3603 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 3604 | } |
| 3605 | /* flush useless bits */ |
| 3606 | curproxy->except_to.s_addr &= curproxy->except_mask_to.s_addr; |
| 3607 | cur_arg += 2; |
| 3608 | } else if (!strcmp(args[cur_arg], "header")) { |
| 3609 | /* suboption header - needs additional argument for it */ |
| 3610 | if (*(args[cur_arg+1]) == 0) { |
| 3611 | Alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 3612 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3613 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3614 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 3615 | } |
| 3616 | free(curproxy->orgto_hdr_name); |
| 3617 | curproxy->orgto_hdr_name = strdup(args[cur_arg+1]); |
| 3618 | curproxy->orgto_hdr_len = strlen(curproxy->orgto_hdr_name); |
| 3619 | cur_arg += 2; |
| 3620 | } else { |
| 3621 | /* unknown suboption - catchall */ |
| 3622 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n", |
| 3623 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3624 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3625 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 3626 | } |
| 3627 | } /* end while loop */ |
| 3628 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3629 | else { |
| 3630 | Alert("parsing [%s:%d] : unknown option '%s'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3631 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3632 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3633 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3634 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3635 | } |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 3636 | else if (!strcmp(args[0], "default_backend")) { |
| 3637 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3638 | err_code |= ERR_WARN; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 3639 | |
| 3640 | if (*(args[1]) == 0) { |
| 3641 | 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] | 3642 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3643 | goto out; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 3644 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3645 | free(curproxy->defbe.name); |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 3646 | curproxy->defbe.name = strdup(args[1]); |
| 3647 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3648 | else if (!strcmp(args[0], "redispatch") || !strcmp(args[0], "redisp")) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3649 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3650 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3651 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3652 | Warning("parsing [%s:%d]: keyword '%s' is deprecated, please use 'option redispatch' instead.\n", |
| 3653 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3654 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3655 | /* enable reconnections to dispatch */ |
| 3656 | curproxy->options |= PR_O_REDISP; |
| 3657 | } |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 3658 | else if (!strcmp(args[0], "http-check")) { |
| 3659 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3660 | err_code |= ERR_WARN; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 3661 | |
| 3662 | if (strcmp(args[1], "disable-on-404") == 0) { |
| 3663 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 3664 | curproxy->options |= PR_O_DISABLE404; |
| 3665 | } |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 3666 | else if (strcmp(args[1], "send-state") == 0) { |
| 3667 | /* enable emission of the apparent state of a server in HTTP checks */ |
| 3668 | curproxy->options2 |= PR_O2_CHK_SNDST; |
| 3669 | } |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 3670 | else if (strcmp(args[1], "expect") == 0) { |
| 3671 | const char *ptr_arg; |
| 3672 | int cur_arg; |
| 3673 | |
| 3674 | if (curproxy->options2 & PR_O2_EXP_TYPE) { |
| 3675 | Alert("parsing [%s:%d] : '%s %s' already specified.\n", file, linenum, args[0], args[1]); |
| 3676 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3677 | goto out; |
| 3678 | } |
| 3679 | |
| 3680 | cur_arg = 2; |
| 3681 | /* consider exclamation marks, sole or at the beginning of a word */ |
| 3682 | while (*(ptr_arg = args[cur_arg])) { |
| 3683 | while (*ptr_arg == '!') { |
| 3684 | curproxy->options2 ^= PR_O2_EXP_INV; |
| 3685 | ptr_arg++; |
| 3686 | } |
| 3687 | if (*ptr_arg) |
| 3688 | break; |
| 3689 | cur_arg++; |
| 3690 | } |
| 3691 | /* now ptr_arg points to the beginning of a word past any possible |
| 3692 | * exclamation mark, and cur_arg is the argument which holds this word. |
| 3693 | */ |
| 3694 | if (strcmp(ptr_arg, "status") == 0) { |
| 3695 | if (!*(args[cur_arg + 1])) { |
| 3696 | Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 3697 | file, linenum, args[0], args[1], ptr_arg); |
| 3698 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3699 | goto out; |
| 3700 | } |
| 3701 | curproxy->options2 |= PR_O2_EXP_STS; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 3702 | free(curproxy->expect_str); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 3703 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
| 3704 | } |
| 3705 | else if (strcmp(ptr_arg, "string") == 0) { |
| 3706 | if (!*(args[cur_arg + 1])) { |
| 3707 | Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 3708 | file, linenum, args[0], args[1], ptr_arg); |
| 3709 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3710 | goto out; |
| 3711 | } |
| 3712 | curproxy->options2 |= PR_O2_EXP_STR; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 3713 | free(curproxy->expect_str); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 3714 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
| 3715 | } |
| 3716 | else if (strcmp(ptr_arg, "rstatus") == 0) { |
| 3717 | if (!*(args[cur_arg + 1])) { |
| 3718 | Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 3719 | file, linenum, args[0], args[1], ptr_arg); |
| 3720 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3721 | goto out; |
| 3722 | } |
| 3723 | curproxy->options2 |= PR_O2_EXP_RSTS; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 3724 | free(curproxy->expect_str); |
| 3725 | if (curproxy->expect_regex) regfree(curproxy->expect_regex); |
| 3726 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 3727 | curproxy->expect_regex = calloc(1, sizeof(regex_t)); |
| 3728 | if (regcomp(curproxy->expect_regex, args[cur_arg + 1], REG_EXTENDED) != 0) { |
| 3729 | Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s'.\n", |
| 3730 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1]); |
| 3731 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3732 | goto out; |
| 3733 | } |
| 3734 | } |
| 3735 | else if (strcmp(ptr_arg, "rstring") == 0) { |
| 3736 | if (!*(args[cur_arg + 1])) { |
| 3737 | Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 3738 | file, linenum, args[0], args[1], ptr_arg); |
| 3739 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3740 | goto out; |
| 3741 | } |
| 3742 | curproxy->options2 |= PR_O2_EXP_RSTR; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 3743 | free(curproxy->expect_str); |
| 3744 | if (curproxy->expect_regex) regfree(curproxy->expect_regex); |
| 3745 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 3746 | curproxy->expect_regex = calloc(1, sizeof(regex_t)); |
| 3747 | if (regcomp(curproxy->expect_regex, args[cur_arg + 1], REG_EXTENDED) != 0) { |
| 3748 | Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s'.\n", |
| 3749 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1]); |
| 3750 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3751 | goto out; |
| 3752 | } |
| 3753 | } |
| 3754 | else { |
| 3755 | Alert("parsing [%s:%d] : '%s %s' only supports [!] 'status', 'string', 'rstatus', 'rstring', found '%s'.\n", |
| 3756 | file, linenum, args[0], args[1], ptr_arg); |
| 3757 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3758 | goto out; |
| 3759 | } |
| 3760 | } |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 3761 | else { |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 3762 | 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] | 3763 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3764 | goto out; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 3765 | } |
| 3766 | } |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3767 | else if (!strcmp(args[0], "monitor")) { |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3768 | if (curproxy == &defproxy) { |
| 3769 | 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] | 3770 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3771 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3772 | } |
| 3773 | |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3774 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3775 | err_code |= ERR_WARN; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3776 | |
| 3777 | if (strcmp(args[1], "fail") == 0) { |
| 3778 | /* add a condition to fail monitor requests */ |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 3779 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3780 | Alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n", |
| 3781 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3782 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3783 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3784 | } |
| 3785 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 3786 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 3787 | Alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition : %s.\n", |
| 3788 | file, linenum, args[0], args[1], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3789 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3790 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3791 | } |
| 3792 | LIST_ADDQ(&curproxy->mon_fail_cond, &cond->list); |
| 3793 | } |
| 3794 | else { |
| 3795 | 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] | 3796 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3797 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3798 | } |
| 3799 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3800 | #ifdef TPROXY |
| 3801 | else if (!strcmp(args[0], "transparent")) { |
| 3802 | /* enable transparent proxy connections */ |
| 3803 | curproxy->options |= PR_O_TRANSP; |
| 3804 | } |
| 3805 | #endif |
| 3806 | else if (!strcmp(args[0], "maxconn")) { /* maxconn */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3807 | 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] | 3808 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3809 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3810 | if (*(args[1]) == 0) { |
| 3811 | 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] | 3812 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3813 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3814 | } |
| 3815 | curproxy->maxconn = atol(args[1]); |
| 3816 | } |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 3817 | else if (!strcmp(args[0], "backlog")) { /* backlog */ |
| 3818 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3819 | err_code |= ERR_WARN; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 3820 | |
| 3821 | if (*(args[1]) == 0) { |
| 3822 | 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] | 3823 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3824 | goto out; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 3825 | } |
| 3826 | curproxy->backlog = atol(args[1]); |
| 3827 | } |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 3828 | else if (!strcmp(args[0], "fullconn")) { /* fullconn */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3829 | 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] | 3830 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3831 | |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 3832 | if (*(args[1]) == 0) { |
| 3833 | 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] | 3834 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3835 | goto out; |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 3836 | } |
| 3837 | curproxy->fullconn = atol(args[1]); |
| 3838 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3839 | else if (!strcmp(args[0], "grace")) { /* grace time (ms) */ |
| 3840 | if (*(args[1]) == 0) { |
| 3841 | 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] | 3842 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3843 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3844 | } |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 3845 | err = parse_time_err(args[1], &val, TIME_UNIT_MS); |
| 3846 | if (err) { |
| 3847 | Alert("parsing [%s:%d] : unexpected character '%c' in grace time.\n", |
| 3848 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3849 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3850 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 3851 | } |
| 3852 | curproxy->grace = val; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3853 | } |
| 3854 | else if (!strcmp(args[0], "dispatch")) { /* dispatch address */ |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 3855 | struct sockaddr_storage *sk; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3856 | if (curproxy == &defproxy) { |
| 3857 | 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] | 3858 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3859 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3860 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3861 | else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3862 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3863 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3864 | if (strchr(args[1], ':') == NULL) { |
| 3865 | 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] | 3866 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3867 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3868 | } |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 3869 | sk = str2sa(args[1]); |
| 3870 | if (!sk) { |
| 3871 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[1]); |
| 3872 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3873 | goto out; |
| 3874 | } |
| 3875 | curproxy->dispatch_addr = *sk; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3876 | curproxy->options |= PR_O_DISPATCH; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3877 | } |
| 3878 | else if (!strcmp(args[0], "balance")) { /* set balancing with optional algorithm */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3879 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3880 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3881 | |
Willy Tarreau | a93c74b | 2012-05-08 18:14:39 +0200 | [diff] [blame] | 3882 | if (backend_parse_balance((const char **)args + 1, &errmsg, curproxy) < 0) { |
| 3883 | Alert("parsing [%s:%d] : %s %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3884 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3885 | goto out; |
Willy Tarreau | 2fcb500 | 2007-05-08 13:35:26 +0200 | [diff] [blame] | 3886 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3887 | } |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 3888 | else if (!strcmp(args[0], "hash-type")) { /* set hashing method */ |
| 3889 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 3890 | err_code |= ERR_WARN; |
| 3891 | |
| 3892 | if (strcmp(args[1], "consistent") == 0) { /* use consistent hashing */ |
| 3893 | curproxy->lbprm.algo &= ~BE_LB_HASH_TYPE; |
| 3894 | curproxy->lbprm.algo |= BE_LB_HASH_CONS; |
| 3895 | } |
| 3896 | else if (strcmp(args[1], "map-based") == 0) { /* use map-based hashing */ |
| 3897 | curproxy->lbprm.algo &= ~BE_LB_HASH_TYPE; |
| 3898 | curproxy->lbprm.algo |= BE_LB_HASH_MAP; |
| 3899 | } |
Willy Tarreau | 798a39c | 2010-11-24 15:04:29 +0100 | [diff] [blame] | 3900 | else if (strcmp(args[1], "avalanche") == 0) { /* use full hash before map-based hashing */ |
| 3901 | curproxy->lbprm.algo &= ~BE_LB_HASH_TYPE; |
| 3902 | curproxy->lbprm.algo |= BE_LB_HASH_AVAL; |
| 3903 | } |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 3904 | else { |
Willy Tarreau | 798a39c | 2010-11-24 15:04:29 +0100 | [diff] [blame] | 3905 | 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] | 3906 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3907 | goto out; |
| 3908 | } |
| 3909 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3910 | 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] | 3911 | int cur_arg; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3912 | char *rport, *raddr; |
| 3913 | short realport = 0; |
| 3914 | int do_check = 0, defsrv = (*args[0] == 'd'); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3915 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3916 | if (!defsrv && curproxy == &defproxy) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3917 | 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] | 3918 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3919 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3920 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3921 | else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3922 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3923 | |
| 3924 | if (!*args[2]) { |
| 3925 | Alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n", |
| 3926 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3927 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3928 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3929 | } |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 3930 | |
| 3931 | err = invalid_char(args[1]); |
| 3932 | if (err) { |
| 3933 | Alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n", |
| 3934 | file, linenum, *err, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3935 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3936 | goto out; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 3937 | } |
| 3938 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3939 | if (!defsrv) { |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 3940 | struct sockaddr_storage *sk; |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 3941 | |
Krzysztof Piotr Oledzki | aff01ea | 2010-02-05 20:31:44 +0100 | [diff] [blame] | 3942 | if ((newsrv = (struct server *)calloc(1, sizeof(struct server))) == NULL) { |
| 3943 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 3944 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3945 | goto out; |
| 3946 | } |
| 3947 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3948 | /* the servers are linked backwards first */ |
| 3949 | newsrv->next = curproxy->srv; |
| 3950 | curproxy->srv = newsrv; |
| 3951 | newsrv->proxy = curproxy; |
Willy Tarreau | 8113a5d | 2012-10-04 08:01:43 +0200 | [diff] [blame] | 3952 | newsrv->conf.file = strdup(file); |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3953 | newsrv->conf.line = linenum; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3954 | |
Simon Horman | af51495 | 2011-06-21 14:34:57 +0900 | [diff] [blame] | 3955 | LIST_INIT(&newsrv->actconns); |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3956 | LIST_INIT(&newsrv->pendconns); |
| 3957 | do_check = 0; |
| 3958 | newsrv->state = SRV_RUNNING; /* early server setup */ |
| 3959 | newsrv->last_change = now.tv_sec; |
| 3960 | newsrv->id = strdup(args[1]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3961 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3962 | /* several ways to check the port component : |
David du Colombier | 9842ff1 | 2011-03-17 10:40:28 +0100 | [diff] [blame] | 3963 | * - IP => port=+0, relative (IPv4 only) |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3964 | * - IP: => port=+0, relative |
| 3965 | * - IP:N => port=N, absolute |
| 3966 | * - IP:+N => port=+N, relative |
| 3967 | * - IP:-N => port=-N, relative |
| 3968 | */ |
| 3969 | raddr = strdup(args[2]); |
Willy Tarreau | fab5a43 | 2011-03-04 15:31:53 +0100 | [diff] [blame] | 3970 | rport = strrchr(raddr, ':'); |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3971 | if (rport) { |
| 3972 | *rport++ = 0; |
| 3973 | realport = atol(rport); |
| 3974 | if (!isdigit((unsigned char)*rport)) |
| 3975 | newsrv->state |= SRV_MAPPORTS; |
| 3976 | } else |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3977 | newsrv->state |= SRV_MAPPORTS; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3978 | |
Willy Tarreau | fab5a43 | 2011-03-04 15:31:53 +0100 | [diff] [blame] | 3979 | sk = str2ip(raddr); |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3980 | free(raddr); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 3981 | if (!sk) { |
| 3982 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[2]); |
| 3983 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3984 | goto out; |
| 3985 | } |
| 3986 | newsrv->addr = *sk; |
Willy Tarreau | f4288ee | 2012-09-28 18:13:10 +0200 | [diff] [blame] | 3987 | newsrv->proto = newsrv->check.proto = protocol_by_family(newsrv->addr.ss_family); |
| 3988 | newsrv->xprt = newsrv->check.xprt = &raw_sock; |
Willy Tarreau | 26d8c59 | 2012-05-07 18:12:14 +0200 | [diff] [blame] | 3989 | |
Willy Tarreau | 173e7fb | 2012-09-24 22:47:39 +0200 | [diff] [blame] | 3990 | if (!newsrv->proto) { |
Willy Tarreau | 26d8c59 | 2012-05-07 18:12:14 +0200 | [diff] [blame] | 3991 | Alert("parsing [%s:%d] : Unknown protocol family %d '%s'\n", |
| 3992 | file, linenum, newsrv->addr.ss_family, args[2]); |
| 3993 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3994 | goto out; |
| 3995 | } |
Willy Tarreau | 86ad42c | 2011-08-27 12:29:07 +0200 | [diff] [blame] | 3996 | set_host_port(&newsrv->addr, realport); |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3997 | |
Willy Tarreau | f4288ee | 2012-09-28 18:13:10 +0200 | [diff] [blame] | 3998 | newsrv->check.use_ssl = curproxy->defsrv.check.use_ssl; |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 3999 | newsrv->check.port = curproxy->defsrv.check.port; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4000 | newsrv->inter = curproxy->defsrv.inter; |
| 4001 | newsrv->fastinter = curproxy->defsrv.fastinter; |
| 4002 | newsrv->downinter = curproxy->defsrv.downinter; |
| 4003 | newsrv->rise = curproxy->defsrv.rise; |
| 4004 | newsrv->fall = curproxy->defsrv.fall; |
| 4005 | newsrv->maxqueue = curproxy->defsrv.maxqueue; |
| 4006 | newsrv->minconn = curproxy->defsrv.minconn; |
| 4007 | newsrv->maxconn = curproxy->defsrv.maxconn; |
| 4008 | newsrv->slowstart = curproxy->defsrv.slowstart; |
| 4009 | newsrv->onerror = curproxy->defsrv.onerror; |
| 4010 | newsrv->consecutive_errors_limit |
| 4011 | = curproxy->defsrv.consecutive_errors_limit; |
Emeric Brun | 01f8e2f | 2012-05-18 16:02:00 +0200 | [diff] [blame] | 4012 | #ifdef OPENSSL |
| 4013 | newsrv->use_ssl = curproxy->defsrv.use_ssl; |
| 4014 | #endif |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4015 | newsrv->uweight = newsrv->iweight |
| 4016 | = curproxy->defsrv.iweight; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4017 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4018 | newsrv->health = newsrv->rise; /* up, but will fall down at first failure */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4019 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4020 | cur_arg = 3; |
| 4021 | } else { |
| 4022 | newsrv = &curproxy->defsrv; |
| 4023 | cur_arg = 1; |
| 4024 | } |
Willy Tarreau | 0f03c6f | 2007-03-25 20:46:19 +0200 | [diff] [blame] | 4025 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4026 | while (*args[cur_arg]) { |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4027 | if (!defsrv && !strcmp(args[cur_arg], "id")) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 4028 | struct eb32_node *node; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 4029 | |
| 4030 | if (!*args[cur_arg + 1]) { |
| 4031 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 4032 | file, linenum, args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4033 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4034 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 4035 | } |
| 4036 | |
| 4037 | newsrv->puid = atol(args[cur_arg + 1]); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 4038 | newsrv->conf.id.key = newsrv->puid; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 4039 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 4040 | if (newsrv->puid <= 0) { |
| 4041 | Alert("parsing [%s:%d]: custom id has to be > 0.\n", |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 4042 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4043 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4044 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 4045 | } |
| 4046 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 4047 | node = eb32_lookup(&curproxy->conf.used_server_id, newsrv->puid); |
| 4048 | if (node) { |
| 4049 | struct server *target = container_of(node, struct server, conf.id); |
| 4050 | Alert("parsing [%s:%d]: server %s reuses same custom id as server %s (declared at %s:%d).\n", |
| 4051 | file, linenum, newsrv->id, target->id, target->conf.file, target->conf.line); |
| 4052 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4053 | goto out; |
| 4054 | } |
| 4055 | eb32_insert(&curproxy->conf.used_server_id, &newsrv->conf.id); |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 4056 | cur_arg += 2; |
| 4057 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4058 | else if (!defsrv && !strcmp(args[cur_arg], "cookie")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4059 | newsrv->cookie = strdup(args[cur_arg + 1]); |
| 4060 | newsrv->cklen = strlen(args[cur_arg + 1]); |
| 4061 | cur_arg += 2; |
| 4062 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4063 | else if (!defsrv && !strcmp(args[cur_arg], "redir")) { |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 4064 | newsrv->rdr_pfx = strdup(args[cur_arg + 1]); |
| 4065 | newsrv->rdr_len = strlen(args[cur_arg + 1]); |
| 4066 | cur_arg += 2; |
| 4067 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4068 | else if (!strcmp(args[cur_arg], "rise")) { |
Krzysztof Piotr Oledzki | 08ff959 | 2009-09-27 16:17:31 +0200 | [diff] [blame] | 4069 | if (!*args[cur_arg + 1]) { |
| 4070 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 4071 | file, linenum, args[cur_arg]); |
| 4072 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4073 | goto out; |
| 4074 | } |
| 4075 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4076 | newsrv->rise = atol(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 08ff959 | 2009-09-27 16:17:31 +0200 | [diff] [blame] | 4077 | if (newsrv->rise <= 0) { |
| 4078 | Alert("parsing [%s:%d]: '%s' has to be > 0.\n", |
| 4079 | file, linenum, args[cur_arg]); |
| 4080 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4081 | goto out; |
| 4082 | } |
| 4083 | |
Willy Tarreau | 9683909 | 2010-03-29 10:02:24 +0200 | [diff] [blame] | 4084 | if (newsrv->health) |
| 4085 | newsrv->health = newsrv->rise; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4086 | cur_arg += 2; |
| 4087 | } |
| 4088 | else if (!strcmp(args[cur_arg], "fall")) { |
| 4089 | newsrv->fall = atol(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 08ff959 | 2009-09-27 16:17:31 +0200 | [diff] [blame] | 4090 | |
| 4091 | if (!*args[cur_arg + 1]) { |
| 4092 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 4093 | file, linenum, args[cur_arg]); |
| 4094 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4095 | goto out; |
| 4096 | } |
| 4097 | |
| 4098 | if (newsrv->fall <= 0) { |
| 4099 | Alert("parsing [%s:%d]: '%s' has to be > 0.\n", |
| 4100 | file, linenum, args[cur_arg]); |
| 4101 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4102 | goto out; |
| 4103 | } |
| 4104 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4105 | cur_arg += 2; |
| 4106 | } |
| 4107 | else if (!strcmp(args[cur_arg], "inter")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4108 | const char *err = parse_time_err(args[cur_arg + 1], &val, TIME_UNIT_MS); |
| 4109 | if (err) { |
| 4110 | Alert("parsing [%s:%d] : unexpected character '%c' in 'inter' argument of server %s.\n", |
| 4111 | file, linenum, *err, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4112 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4113 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4114 | } |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4115 | if (val <= 0) { |
| 4116 | Alert("parsing [%s:%d]: invalid value %d for argument '%s' of server %s.\n", |
| 4117 | file, linenum, val, args[cur_arg], newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4118 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4119 | goto out; |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4120 | } |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4121 | newsrv->inter = val; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4122 | cur_arg += 2; |
| 4123 | } |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 4124 | else if (!strcmp(args[cur_arg], "fastinter")) { |
| 4125 | const char *err = parse_time_err(args[cur_arg + 1], &val, TIME_UNIT_MS); |
| 4126 | if (err) { |
| 4127 | Alert("parsing [%s:%d]: unexpected character '%c' in 'fastinter' argument of server %s.\n", |
| 4128 | file, linenum, *err, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4129 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4130 | goto out; |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 4131 | } |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4132 | if (val <= 0) { |
| 4133 | Alert("parsing [%s:%d]: invalid value %d for argument '%s' of server %s.\n", |
| 4134 | file, linenum, val, args[cur_arg], newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4135 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4136 | goto out; |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4137 | } |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 4138 | newsrv->fastinter = val; |
| 4139 | cur_arg += 2; |
| 4140 | } |
Emeric Brun | 8694b9a | 2012-10-05 14:39:07 +0200 | [diff] [blame] | 4141 | else if (!strcmp(args[cur_arg], "force-sslv3")) { |
| 4142 | #ifdef USE_OPENSSL |
| 4143 | newsrv->ssl_ctx.options |= SRV_SSL_O_USE_SSLV3; |
| 4144 | cur_arg += 1; |
| 4145 | #else /* USE_OPENSSL */ |
| 4146 | Alert("parsing [%s:%d]: '%s' option not implemented.\n", |
| 4147 | file, linenum, args[cur_arg]); |
| 4148 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4149 | goto out; |
| 4150 | #endif /* USE_OPENSSL */ |
| 4151 | } |
| 4152 | else if (!strcmp(args[cur_arg], "force-tlsv10")) { |
| 4153 | #ifdef USE_OPENSSL |
| 4154 | newsrv->ssl_ctx.options |= SRV_SSL_O_USE_TLSV10; |
| 4155 | cur_arg += 1; |
| 4156 | #else /* USE_OPENSSL */ |
| 4157 | Alert("parsing [%s:%d]: '%s' option not implemented.\n", |
| 4158 | file, linenum, args[cur_arg]); |
| 4159 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4160 | goto out; |
| 4161 | #endif /* USE_OPENSSL */ |
| 4162 | } |
| 4163 | else if (!strcmp(args[cur_arg], "force-tlsv11")) { |
| 4164 | #ifdef USE_OPENSSL |
| 4165 | #if SSL_OP_NO_TLSv1_1 |
| 4166 | newsrv->ssl_ctx.options |= SRV_SSL_O_USE_TLSV11; |
| 4167 | cur_arg += 1; |
| 4168 | #else |
| 4169 | Alert("parsing [%s:%d]: '%s' library does not support protocol TLSv1.1.\n", |
| 4170 | file, linenum, args[cur_arg]); |
| 4171 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4172 | goto out; |
| 4173 | #endif |
| 4174 | #else /* USE_OPENSSL */ |
| 4175 | Alert("parsing [%s:%d]: '%s' option not implemented.\n", |
| 4176 | file, linenum, args[cur_arg]); |
| 4177 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4178 | goto out; |
| 4179 | #endif /* USE_OPENSSL */ |
| 4180 | } |
| 4181 | else if (!strcmp(args[cur_arg], "force-tlsv12")) { |
| 4182 | #ifdef USE_OPENSSL |
| 4183 | #if SSL_OP_NO_TLSv1_2 |
| 4184 | newsrv->ssl_ctx.options |= SRV_SSL_O_USE_TLSV12; |
| 4185 | cur_arg += 1; |
| 4186 | #else |
| 4187 | Alert("parsing [%s:%d]: '%s' library does not support protocol TLSv1.2.\n", |
| 4188 | file, linenum, args[cur_arg]); |
| 4189 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4190 | goto out; |
| 4191 | #endif |
| 4192 | #else /* USE_OPENSSL */ |
| 4193 | Alert("parsing [%s:%d]: '%s' option not implemented.\n", |
| 4194 | file, linenum, args[cur_arg]); |
| 4195 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4196 | goto out; |
| 4197 | #endif /* USE_OPENSSL */ |
| 4198 | } |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 4199 | else if (!strcmp(args[cur_arg], "downinter")) { |
| 4200 | const char *err = parse_time_err(args[cur_arg + 1], &val, TIME_UNIT_MS); |
| 4201 | if (err) { |
| 4202 | Alert("parsing [%s:%d]: unexpected character '%c' in 'downinter' argument of server %s.\n", |
| 4203 | file, linenum, *err, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4204 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4205 | goto out; |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 4206 | } |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4207 | if (val <= 0) { |
| 4208 | Alert("parsing [%s:%d]: invalid value %d for argument '%s' of server %s.\n", |
| 4209 | file, linenum, val, args[cur_arg], newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4210 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4211 | goto out; |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4212 | } |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 4213 | newsrv->downinter = val; |
| 4214 | cur_arg += 2; |
| 4215 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4216 | else if (!defsrv && !strcmp(args[cur_arg], "addr")) { |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4217 | struct sockaddr_storage *sk = str2sa(args[cur_arg + 1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4218 | if (!sk) { |
| 4219 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[cur_arg + 1]); |
| 4220 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4221 | goto out; |
| 4222 | } |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 4223 | newsrv->check.addr = *sk; |
Willy Tarreau | 2ea3abb | 2007-03-25 16:45:16 +0200 | [diff] [blame] | 4224 | cur_arg += 2; |
| 4225 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4226 | else if (!strcmp(args[cur_arg], "port")) { |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 4227 | newsrv->check.port = atol(args[cur_arg + 1]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4228 | cur_arg += 2; |
| 4229 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4230 | else if (!defsrv && !strcmp(args[cur_arg], "backup")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4231 | newsrv->state |= SRV_BACKUP; |
| 4232 | cur_arg ++; |
| 4233 | } |
Simon Horman | fa46168 | 2011-06-25 09:39:49 +0900 | [diff] [blame] | 4234 | else if (!defsrv && !strcmp(args[cur_arg], "non-stick")) { |
| 4235 | newsrv->state |= SRV_NON_STICK; |
| 4236 | cur_arg ++; |
| 4237 | } |
Willy Tarreau | 5ab04ec | 2011-03-20 10:32:26 +0100 | [diff] [blame] | 4238 | else if (!defsrv && !strcmp(args[cur_arg], "send-proxy")) { |
| 4239 | newsrv->state |= SRV_SEND_PROXY; |
| 4240 | cur_arg ++; |
| 4241 | } |
Willy Tarreau | 6c16adc | 2012-10-05 00:04:16 +0200 | [diff] [blame] | 4242 | else if (!defsrv && !strcmp(args[cur_arg], "check-send-proxy")) { |
| 4243 | newsrv->check.send_proxy = 1; |
| 4244 | cur_arg ++; |
| 4245 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4246 | else if (!strcmp(args[cur_arg], "weight")) { |
| 4247 | int w; |
| 4248 | w = atol(args[cur_arg + 1]); |
Willy Tarreau | 6704d67 | 2009-06-15 10:56:05 +0200 | [diff] [blame] | 4249 | if (w < 0 || w > 256) { |
| 4250 | 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] | 4251 | file, linenum, newsrv->id, w); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4252 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4253 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4254 | } |
Willy Tarreau | 975c50b | 2009-10-10 19:34:06 +0200 | [diff] [blame] | 4255 | newsrv->uweight = newsrv->iweight = w; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4256 | cur_arg += 2; |
| 4257 | } |
| 4258 | else if (!strcmp(args[cur_arg], "minconn")) { |
| 4259 | newsrv->minconn = atol(args[cur_arg + 1]); |
| 4260 | cur_arg += 2; |
| 4261 | } |
| 4262 | else if (!strcmp(args[cur_arg], "maxconn")) { |
| 4263 | newsrv->maxconn = atol(args[cur_arg + 1]); |
| 4264 | cur_arg += 2; |
| 4265 | } |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 4266 | else if (!strcmp(args[cur_arg], "maxqueue")) { |
| 4267 | newsrv->maxqueue = atol(args[cur_arg + 1]); |
| 4268 | cur_arg += 2; |
| 4269 | } |
Willy Tarreau | 9909fc1 | 2007-11-30 17:42:05 +0100 | [diff] [blame] | 4270 | else if (!strcmp(args[cur_arg], "slowstart")) { |
| 4271 | /* slowstart is stored in seconds */ |
Willy Tarreau | 3259e33 | 2007-12-03 01:51:45 +0100 | [diff] [blame] | 4272 | 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] | 4273 | if (err) { |
| 4274 | Alert("parsing [%s:%d] : unexpected character '%c' in 'slowstart' argument of server %s.\n", |
| 4275 | file, linenum, *err, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4276 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4277 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4278 | } |
Willy Tarreau | 4554bc1 | 2010-03-26 10:40:49 +0100 | [diff] [blame] | 4279 | if (val < 0) { |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4280 | Alert("parsing [%s:%d]: invalid value %d for argument '%s' of server %s.\n", |
| 4281 | file, linenum, val, args[cur_arg], newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4282 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4283 | goto out; |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4284 | } |
Willy Tarreau | 3259e33 | 2007-12-03 01:51:45 +0100 | [diff] [blame] | 4285 | newsrv->slowstart = (val + 999) / 1000; |
Willy Tarreau | 9909fc1 | 2007-11-30 17:42:05 +0100 | [diff] [blame] | 4286 | cur_arg += 2; |
| 4287 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4288 | else if (!defsrv && !strcmp(args[cur_arg], "track")) { |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4289 | |
| 4290 | if (!*args[cur_arg + 1]) { |
| 4291 | Alert("parsing [%s:%d]: 'track' expects [<proxy>/]<server> as argument.\n", |
| 4292 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4293 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4294 | goto out; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4295 | } |
| 4296 | |
| 4297 | newsrv->trackit = strdup(args[cur_arg + 1]); |
| 4298 | |
| 4299 | cur_arg += 2; |
| 4300 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4301 | else if (!defsrv && !strcmp(args[cur_arg], "check")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4302 | global.maxsock++; |
| 4303 | do_check = 1; |
| 4304 | cur_arg += 1; |
| 4305 | } |
Willy Tarreau | 9683909 | 2010-03-29 10:02:24 +0200 | [diff] [blame] | 4306 | else if (!defsrv && !strcmp(args[cur_arg], "disabled")) { |
| 4307 | newsrv->state |= SRV_MAINTAIN; |
| 4308 | newsrv->state &= ~SRV_RUNNING; |
| 4309 | newsrv->health = 0; |
| 4310 | cur_arg += 1; |
| 4311 | } |
Emeric Brun | 01f8e2f | 2012-05-18 16:02:00 +0200 | [diff] [blame] | 4312 | else if (!strcmp(args[cur_arg], "ssl")) { |
| 4313 | #ifdef USE_OPENSSL |
| 4314 | newsrv->use_ssl = 1; |
| 4315 | cur_arg += 1; |
Emeric Brun | 76d8895 | 2012-10-05 15:47:31 +0200 | [diff] [blame^] | 4316 | |
| 4317 | if (global.connect_default_ciphers && !newsrv->ssl_ctx.ciphers) |
| 4318 | newsrv->ssl_ctx.ciphers = strdup(global.connect_default_ciphers); |
Emeric Brun | 01f8e2f | 2012-05-18 16:02:00 +0200 | [diff] [blame] | 4319 | #else /* USE_OPENSSL */ |
| 4320 | Alert("parsing [%s:%d]: '%s' option not implemented.\n", |
| 4321 | file, linenum, args[cur_arg]); |
| 4322 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4323 | goto out; |
| 4324 | #endif /* USE_OPENSSL */ |
| 4325 | } |
Willy Tarreau | 763a95b | 2012-10-04 23:15:39 +0200 | [diff] [blame] | 4326 | else if (!strcmp(args[cur_arg], "check-ssl")) { |
| 4327 | #ifdef USE_OPENSSL |
| 4328 | newsrv->check.use_ssl = 1; |
| 4329 | cur_arg += 1; |
Emeric Brun | 76d8895 | 2012-10-05 15:47:31 +0200 | [diff] [blame^] | 4330 | |
| 4331 | if (global.connect_default_ciphers && !newsrv->ssl_ctx.ciphers) |
| 4332 | newsrv->ssl_ctx.ciphers = strdup(global.connect_default_ciphers); |
Willy Tarreau | 763a95b | 2012-10-04 23:15:39 +0200 | [diff] [blame] | 4333 | #else /* USE_OPENSSL */ |
| 4334 | Alert("parsing [%s:%d]: '%s' option not implemented.\n", |
| 4335 | file, linenum, args[cur_arg]); |
| 4336 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4337 | goto out; |
| 4338 | #endif /* USE_OPENSSL */ |
| 4339 | } |
Willy Tarreau | d7aacbf | 2012-09-03 23:34:19 +0200 | [diff] [blame] | 4340 | else if (!strcmp(args[cur_arg], "ciphers")) { /* use this SSL cipher suite */ |
| 4341 | #ifdef USE_OPENSSL |
| 4342 | if (!*args[cur_arg + 1]) { |
| 4343 | Alert("parsing [%s:%d] : '%s' : '%s' : missing cipher suite.\n", |
| 4344 | file, linenum, args[0], args[cur_arg]); |
| 4345 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4346 | goto out; |
| 4347 | } |
| 4348 | |
Emeric Brun | 76d8895 | 2012-10-05 15:47:31 +0200 | [diff] [blame^] | 4349 | free(newsrv->ssl_ctx.ciphers); |
Willy Tarreau | d7aacbf | 2012-09-03 23:34:19 +0200 | [diff] [blame] | 4350 | newsrv->ssl_ctx.ciphers = strdup(args[cur_arg + 1]); |
| 4351 | |
| 4352 | cur_arg += 2; |
| 4353 | continue; |
| 4354 | #else |
| 4355 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 4356 | file, linenum, args[0], args[cur_arg]); |
| 4357 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4358 | goto out; |
| 4359 | #endif |
| 4360 | } |
Emeric Brun | 9b3009b | 2012-10-05 11:55:06 +0200 | [diff] [blame] | 4361 | else if (!strcmp(args[cur_arg], "no-sslv3")) { |
Willy Tarreau | c230b8b | 2012-09-03 23:55:16 +0200 | [diff] [blame] | 4362 | #ifdef USE_OPENSSL |
Emeric Brun | 8967549 | 2012-10-05 13:48:26 +0200 | [diff] [blame] | 4363 | newsrv->ssl_ctx.options |= SRV_SSL_O_NO_SSLV3; |
Willy Tarreau | c230b8b | 2012-09-03 23:55:16 +0200 | [diff] [blame] | 4364 | cur_arg += 1; |
| 4365 | #else /* USE_OPENSSL */ |
| 4366 | Alert("parsing [%s:%d]: '%s' option not implemented.\n", |
| 4367 | file, linenum, args[cur_arg]); |
| 4368 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4369 | goto out; |
| 4370 | #endif /* USE_OPENSSL */ |
| 4371 | } |
Emeric Brun | 9b3009b | 2012-10-05 11:55:06 +0200 | [diff] [blame] | 4372 | else if (!strcmp(args[cur_arg], "no-tlsv10")) { |
Willy Tarreau | c230b8b | 2012-09-03 23:55:16 +0200 | [diff] [blame] | 4373 | #ifdef USE_OPENSSL |
Emeric Brun | 8967549 | 2012-10-05 13:48:26 +0200 | [diff] [blame] | 4374 | newsrv->ssl_ctx.options |= SRV_SSL_O_NO_TLSV10; |
Willy Tarreau | c230b8b | 2012-09-03 23:55:16 +0200 | [diff] [blame] | 4375 | cur_arg += 1; |
| 4376 | #else /* USE_OPENSSL */ |
| 4377 | Alert("parsing [%s:%d]: '%s' option not implemented.\n", |
| 4378 | file, linenum, args[cur_arg]); |
| 4379 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4380 | goto out; |
| 4381 | #endif /* USE_OPENSSL */ |
| 4382 | } |
Emeric Brun | 9b3009b | 2012-10-05 11:55:06 +0200 | [diff] [blame] | 4383 | else if (!strcmp(args[cur_arg], "no-tlsv11")) { |
Emeric Brun | c0ff492 | 2012-09-28 19:37:02 +0200 | [diff] [blame] | 4384 | #ifdef USE_OPENSSL |
Emeric Brun | 8967549 | 2012-10-05 13:48:26 +0200 | [diff] [blame] | 4385 | newsrv->ssl_ctx.options |= SRV_SSL_O_NO_TLSV11; |
Emeric Brun | c0ff492 | 2012-09-28 19:37:02 +0200 | [diff] [blame] | 4386 | cur_arg += 1; |
| 4387 | #else /* USE_OPENSSL */ |
| 4388 | Alert("parsing [%s:%d]: '%s' option not implemented.\n", |
| 4389 | file, linenum, args[cur_arg]); |
| 4390 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4391 | goto out; |
| 4392 | #endif /* USE_OPENSSL */ |
| 4393 | } |
Emeric Brun | 9b3009b | 2012-10-05 11:55:06 +0200 | [diff] [blame] | 4394 | else if (!strcmp(args[cur_arg], "no-tlsv12")) { |
Emeric Brun | c0ff492 | 2012-09-28 19:37:02 +0200 | [diff] [blame] | 4395 | #ifdef USE_OPENSSL |
Emeric Brun | 8967549 | 2012-10-05 13:48:26 +0200 | [diff] [blame] | 4396 | newsrv->ssl_ctx.options |= SRV_SSL_O_NO_TLSV12; |
Emeric Brun | c0ff492 | 2012-09-28 19:37:02 +0200 | [diff] [blame] | 4397 | cur_arg += 1; |
| 4398 | #else /* USE_OPENSSL */ |
| 4399 | Alert("parsing [%s:%d]: '%s' option not implemented.\n", |
| 4400 | file, linenum, args[cur_arg]); |
| 4401 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4402 | goto out; |
| 4403 | #endif /* USE_OPENSSL */ |
| 4404 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4405 | else if (!defsrv && !strcmp(args[cur_arg], "observe")) { |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 4406 | if (!strcmp(args[cur_arg + 1], "none")) |
| 4407 | newsrv->observe = HANA_OBS_NONE; |
| 4408 | else if (!strcmp(args[cur_arg + 1], "layer4")) |
| 4409 | newsrv->observe = HANA_OBS_LAYER4; |
| 4410 | else if (!strcmp(args[cur_arg + 1], "layer7")) { |
| 4411 | if (curproxy->mode != PR_MODE_HTTP) { |
| 4412 | Alert("parsing [%s:%d]: '%s' can only be used in http proxies.\n", |
| 4413 | file, linenum, args[cur_arg + 1]); |
| 4414 | err_code |= ERR_ALERT; |
| 4415 | } |
| 4416 | newsrv->observe = HANA_OBS_LAYER7; |
| 4417 | } |
| 4418 | else { |
| 4419 | Alert("parsing [%s:%d]: '%s' expects one of 'none', " |
Willy Tarreau | 53621e0 | 2010-10-22 14:53:40 +0200 | [diff] [blame] | 4420 | "'layer4', 'layer7' but got '%s'\n", |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 4421 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
| 4422 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4423 | goto out; |
| 4424 | } |
| 4425 | |
| 4426 | cur_arg += 2; |
| 4427 | } |
| 4428 | else if (!strcmp(args[cur_arg], "on-error")) { |
| 4429 | if (!strcmp(args[cur_arg + 1], "fastinter")) |
| 4430 | newsrv->onerror = HANA_ONERR_FASTINTER; |
| 4431 | else if (!strcmp(args[cur_arg + 1], "fail-check")) |
| 4432 | newsrv->onerror = HANA_ONERR_FAILCHK; |
| 4433 | else if (!strcmp(args[cur_arg + 1], "sudden-death")) |
| 4434 | newsrv->onerror = HANA_ONERR_SUDDTH; |
| 4435 | else if (!strcmp(args[cur_arg + 1], "mark-down")) |
| 4436 | newsrv->onerror = HANA_ONERR_MARKDWN; |
| 4437 | else { |
| 4438 | Alert("parsing [%s:%d]: '%s' expects one of 'fastinter', " |
Willy Tarreau | 53621e0 | 2010-10-22 14:53:40 +0200 | [diff] [blame] | 4439 | "'fail-check', 'sudden-death' or 'mark-down' but got '%s'\n", |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 4440 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
| 4441 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4442 | goto out; |
| 4443 | } |
| 4444 | |
| 4445 | cur_arg += 2; |
| 4446 | } |
Simon Horman | e0d1bfb | 2011-06-21 14:34:58 +0900 | [diff] [blame] | 4447 | else if (!strcmp(args[cur_arg], "on-marked-down")) { |
| 4448 | if (!strcmp(args[cur_arg + 1], "shutdown-sessions")) |
| 4449 | newsrv->onmarkeddown = HANA_ONMARKEDDOWN_SHUTDOWNSESSIONS; |
| 4450 | else { |
| 4451 | Alert("parsing [%s:%d]: '%s' expects 'shutdown-sessions' but got '%s'\n", |
| 4452 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
| 4453 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4454 | goto out; |
| 4455 | } |
| 4456 | |
| 4457 | cur_arg += 2; |
| 4458 | } |
Justin Karneges | eb2c24a | 2012-05-24 15:28:52 -0700 | [diff] [blame] | 4459 | else if (!strcmp(args[cur_arg], "on-marked-up")) { |
| 4460 | if (!strcmp(args[cur_arg + 1], "shutdown-backup-sessions")) |
| 4461 | newsrv->onmarkedup = HANA_ONMARKEDUP_SHUTDOWNBACKUPSESSIONS; |
| 4462 | else { |
| 4463 | Alert("parsing [%s:%d]: '%s' expects 'shutdown-backup-sessions' but got '%s'\n", |
| 4464 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
| 4465 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4466 | goto out; |
| 4467 | } |
| 4468 | |
| 4469 | cur_arg += 2; |
| 4470 | } |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 4471 | else if (!strcmp(args[cur_arg], "error-limit")) { |
| 4472 | if (!*args[cur_arg + 1]) { |
| 4473 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 4474 | file, linenum, args[cur_arg]); |
| 4475 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4476 | goto out; |
| 4477 | } |
| 4478 | |
| 4479 | newsrv->consecutive_errors_limit = atoi(args[cur_arg + 1]); |
| 4480 | |
| 4481 | if (newsrv->consecutive_errors_limit <= 0) { |
| 4482 | Alert("parsing [%s:%d]: %s has to be > 0.\n", |
| 4483 | file, linenum, args[cur_arg]); |
| 4484 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4485 | goto out; |
| 4486 | } |
Willy Tarreau | f53b25d | 2010-03-15 19:40:37 +0100 | [diff] [blame] | 4487 | cur_arg += 2; |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 4488 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4489 | 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] | 4490 | int port_low, port_high; |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4491 | struct sockaddr_storage *sk; |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4492 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4493 | if (!*args[cur_arg + 1]) { |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4494 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 4495 | 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] | 4496 | file, linenum, "source", "usesrc"); |
| 4497 | #else |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 4498 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>[-<port>]] as argument.\n", |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4499 | file, linenum, "source"); |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 4500 | #endif |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4501 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4502 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4503 | } |
| 4504 | newsrv->state |= SRV_BIND_SRC; |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4505 | sk = str2sa_range(args[cur_arg + 1], &port_low, &port_high); |
| 4506 | if (!sk) { |
| 4507 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[cur_arg + 1]); |
| 4508 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4509 | goto out; |
| 4510 | } |
| 4511 | newsrv->source_addr = *sk; |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 4512 | |
| 4513 | if (port_low != port_high) { |
| 4514 | int i; |
| 4515 | if (port_low <= 0 || port_low > 65535 || |
| 4516 | port_high <= 0 || port_high > 65535 || |
| 4517 | port_low > port_high) { |
| 4518 | Alert("parsing [%s:%d] : invalid source port range %d-%d.\n", |
| 4519 | file, linenum, port_low, port_high); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4520 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4521 | goto out; |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 4522 | } |
| 4523 | newsrv->sport_range = port_range_alloc_range(port_high - port_low + 1); |
| 4524 | for (i = 0; i < newsrv->sport_range->size; i++) |
| 4525 | newsrv->sport_range->ports[i] = port_low + i; |
| 4526 | } |
| 4527 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4528 | cur_arg += 2; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4529 | while (*(args[cur_arg])) { |
| 4530 | if (!strcmp(args[cur_arg], "usesrc")) { /* address to use outside */ |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4531 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) |
| 4532 | #if !defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4533 | if (newsrv->source_addr.sin_addr.s_addr == INADDR_ANY) { |
| 4534 | Alert("parsing [%s:%d] : '%s' requires an explicit '%s' address.\n", |
| 4535 | file, linenum, "usesrc", "source"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4536 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4537 | goto out; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4538 | } |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4539 | #endif |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4540 | if (!*args[cur_arg + 1]) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4541 | 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] | 4542 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4543 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4544 | goto out; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4545 | } |
| 4546 | if (!strcmp(args[cur_arg + 1], "client")) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4547 | newsrv->state &= ~SRV_TPROXY_MASK; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4548 | newsrv->state |= SRV_TPROXY_CLI; |
| 4549 | } else if (!strcmp(args[cur_arg + 1], "clientip")) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4550 | newsrv->state &= ~SRV_TPROXY_MASK; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4551 | newsrv->state |= SRV_TPROXY_CIP; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4552 | } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) { |
| 4553 | char *name, *end; |
| 4554 | |
| 4555 | name = args[cur_arg+1] + 7; |
| 4556 | while (isspace(*name)) |
| 4557 | name++; |
| 4558 | |
| 4559 | end = name; |
| 4560 | while (*end && !isspace(*end) && *end != ',' && *end != ')') |
| 4561 | end++; |
| 4562 | |
| 4563 | newsrv->state &= ~SRV_TPROXY_MASK; |
| 4564 | newsrv->state |= SRV_TPROXY_DYN; |
| 4565 | newsrv->bind_hdr_name = calloc(1, end - name + 1); |
| 4566 | newsrv->bind_hdr_len = end - name; |
| 4567 | memcpy(newsrv->bind_hdr_name, name, end - name); |
| 4568 | newsrv->bind_hdr_name[end-name] = '\0'; |
| 4569 | newsrv->bind_hdr_occ = -1; |
| 4570 | |
| 4571 | /* now look for an occurrence number */ |
| 4572 | while (isspace(*end)) |
| 4573 | end++; |
| 4574 | if (*end == ',') { |
| 4575 | end++; |
| 4576 | name = end; |
| 4577 | if (*end == '-') |
| 4578 | end++; |
| 4579 | while (isdigit(*end)) |
| 4580 | end++; |
| 4581 | newsrv->bind_hdr_occ = strl2ic(name, end-name); |
| 4582 | } |
| 4583 | |
| 4584 | if (newsrv->bind_hdr_occ < -MAX_HDR_HISTORY) { |
| 4585 | Alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative" |
| 4586 | " occurrences values smaller than %d.\n", |
| 4587 | file, linenum, MAX_HDR_HISTORY); |
| 4588 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4589 | goto out; |
| 4590 | } |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4591 | } else { |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4592 | struct sockaddr_storage *sk = str2sa(args[cur_arg + 1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4593 | if (!sk) { |
| 4594 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[cur_arg + 1]); |
| 4595 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4596 | goto out; |
| 4597 | } |
| 4598 | newsrv->tproxy_addr = *sk; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4599 | newsrv->state |= SRV_TPROXY_ADDR; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4600 | } |
| 4601 | global.last_checks |= LSTCHK_NETADM; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4602 | #if !defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4603 | global.last_checks |= LSTCHK_CTTPROXY; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4604 | #endif |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4605 | cur_arg += 2; |
| 4606 | continue; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4607 | #else /* no TPROXY support */ |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4608 | 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] | 4609 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4610 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4611 | goto out; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4612 | #endif /* defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) */ |
| 4613 | } /* "usesrc" */ |
| 4614 | |
| 4615 | if (!strcmp(args[cur_arg], "interface")) { /* specifically bind to this interface */ |
| 4616 | #ifdef SO_BINDTODEVICE |
| 4617 | if (!*args[cur_arg + 1]) { |
| 4618 | Alert("parsing [%s:%d] : '%s' : missing interface name.\n", |
| 4619 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4620 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4621 | goto out; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4622 | } |
| 4623 | if (newsrv->iface_name) |
| 4624 | free(newsrv->iface_name); |
| 4625 | |
| 4626 | newsrv->iface_name = strdup(args[cur_arg + 1]); |
| 4627 | newsrv->iface_len = strlen(newsrv->iface_name); |
| 4628 | global.last_checks |= LSTCHK_NETADM; |
| 4629 | #else |
| 4630 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 4631 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4632 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4633 | goto out; |
Willy Tarreau | 77074d5 | 2006-11-12 23:57:19 +0100 | [diff] [blame] | 4634 | #endif |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4635 | cur_arg += 2; |
| 4636 | continue; |
| 4637 | } |
| 4638 | /* this keyword in not an option of "source" */ |
| 4639 | break; |
| 4640 | } /* while */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4641 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4642 | 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] | 4643 | Alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n", |
| 4644 | file, linenum, "usesrc", "source"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4645 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4646 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 4647 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4648 | else { |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4649 | if (!defsrv) |
Simon Horman | e0d1bfb | 2011-06-21 14:34:58 +0900 | [diff] [blame] | 4650 | 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] | 4651 | file, linenum, newsrv->id); |
| 4652 | else |
Krzysztof Piotr Oledzki | a9389b1 | 2010-01-05 16:44:17 +0100 | [diff] [blame] | 4653 | 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] | 4654 | file, linenum); |
| 4655 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4656 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4657 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4658 | } |
| 4659 | } |
| 4660 | |
| 4661 | if (do_check) { |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4662 | if (newsrv->trackit) { |
| 4663 | Alert("parsing [%s:%d]: unable to enable checks and tracking at the same time!\n", |
| 4664 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4665 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4666 | goto out; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4667 | } |
| 4668 | |
Willy Tarreau | f4288ee | 2012-09-28 18:13:10 +0200 | [diff] [blame] | 4669 | /* If neither a port nor an addr was specified and no check transport |
| 4670 | * layer is forced, then the transport layer used by the checks is the |
| 4671 | * same as for the production traffic. Otherwise we use raw_sock by |
| 4672 | * default, unless one is specified. |
| 4673 | */ |
Baptiste Assmann | e6baecf | 2012-10-05 11:48:04 +0200 | [diff] [blame] | 4674 | #ifdef USE_OPENSSL |
Willy Tarreau | 6c16adc | 2012-10-05 00:04:16 +0200 | [diff] [blame] | 4675 | if (!newsrv->check.port && !is_addr(&newsrv->check.addr)) { |
Willy Tarreau | f4288ee | 2012-09-28 18:13:10 +0200 | [diff] [blame] | 4676 | newsrv->check.use_ssl |= newsrv->use_ssl; |
Willy Tarreau | 6c16adc | 2012-10-05 00:04:16 +0200 | [diff] [blame] | 4677 | newsrv->check.send_proxy |= (newsrv->state & SRV_SEND_PROXY); |
| 4678 | } |
Baptiste Assmann | e6baecf | 2012-10-05 11:48:04 +0200 | [diff] [blame] | 4679 | #endif |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 4680 | /* try to get the port from check.addr if check.port not set */ |
| 4681 | if (!newsrv->check.port) |
| 4682 | newsrv->check.port = get_host_port(&newsrv->check.addr); |
Willy Tarreau | 0f03c6f | 2007-03-25 20:46:19 +0200 | [diff] [blame] | 4683 | |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 4684 | if (!newsrv->check.port && !(newsrv->state & SRV_MAPPORTS)) |
| 4685 | newsrv->check.port = realport; /* by default */ |
| 4686 | if (!newsrv->check.port) { |
Willy Tarreau | ef00b50 | 2007-01-07 02:40:09 +0100 | [diff] [blame] | 4687 | /* not yet valid, because no port was set on |
| 4688 | * the server either. We'll check if we have |
| 4689 | * a known port on the first listener. |
| 4690 | */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 4691 | struct listener *l; |
| 4692 | |
| 4693 | list_for_each_entry(l, &curproxy->conf.listeners, by_fe) { |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 4694 | newsrv->check.port = get_host_port(&l->addr); |
| 4695 | if (newsrv->check.port) |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 4696 | break; |
| 4697 | } |
Willy Tarreau | ef00b50 | 2007-01-07 02:40:09 +0100 | [diff] [blame] | 4698 | } |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 4699 | if (!newsrv->check.port) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4700 | Alert("parsing [%s:%d] : server %s has neither service port nor check port. Check has been disabled.\n", |
| 4701 | file, linenum, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4702 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4703 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4704 | } |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 4705 | |
Willy Tarreau | 1ae1b7b | 2012-09-28 15:28:30 +0200 | [diff] [blame] | 4706 | /* Allocate buffer for check requests... */ |
| 4707 | if ((newsrv->check.bi = calloc(sizeof(struct buffer) + global.tune.chksize, sizeof(char))) == NULL) { |
Cyril Bonté | c9f825f | 2010-03-17 18:56:31 +0100 | [diff] [blame] | 4708 | Alert("parsing [%s:%d] : out of memory while allocating check buffer.\n", file, linenum); |
| 4709 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4710 | goto out; |
| 4711 | } |
Willy Tarreau | 1ae1b7b | 2012-09-28 15:28:30 +0200 | [diff] [blame] | 4712 | newsrv->check.bi->size = global.tune.chksize; |
| 4713 | |
| 4714 | /* Allocate buffer for check responses... */ |
| 4715 | if ((newsrv->check.bo = calloc(sizeof(struct buffer) + global.tune.chksize, sizeof(char))) == NULL) { |
| 4716 | Alert("parsing [%s:%d] : out of memory while allocating check buffer.\n", file, linenum); |
| 4717 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4718 | goto out; |
| 4719 | } |
| 4720 | newsrv->check.bo->size = global.tune.chksize; |
Cyril Bonté | c9f825f | 2010-03-17 18:56:31 +0100 | [diff] [blame] | 4721 | |
Willy Tarreau | da92e2f | 2012-07-06 09:40:59 +0200 | [diff] [blame] | 4722 | /* Allocate buffer for partial check results... */ |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 4723 | if ((newsrv->check.conn = calloc(1, sizeof(struct connection))) == NULL) { |
Willy Tarreau | da92e2f | 2012-07-06 09:40:59 +0200 | [diff] [blame] | 4724 | Alert("parsing [%s:%d] : out of memory while allocating check connection.\n", file, linenum); |
| 4725 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4726 | goto out; |
| 4727 | } |
| 4728 | |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 4729 | newsrv->check.conn->t.sock.fd = -1; /* no check in progress yet */ |
| 4730 | newsrv->check.status = HCHK_STATUS_INI; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4731 | newsrv->state |= SRV_CHECKED; |
| 4732 | } |
| 4733 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4734 | if (!defsrv) { |
| 4735 | if (newsrv->state & SRV_BACKUP) |
| 4736 | curproxy->srv_bck++; |
| 4737 | else |
| 4738 | curproxy->srv_act++; |
Willy Tarreau | b625a08 | 2007-11-26 01:15:43 +0100 | [diff] [blame] | 4739 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4740 | newsrv->prev_state = newsrv->state; |
| 4741 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 4742 | } |
| 4743 | |
| 4744 | else if (strcmp(args[0], "unique-id-format") == 0) { |
| 4745 | if (!*(args[1])) { |
| 4746 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 4747 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4748 | goto out; |
| 4749 | } |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 4750 | free(curproxy->uniqueid_format_string); |
| 4751 | curproxy->uniqueid_format_string = strdup(args[1]); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4752 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 4753 | |
| 4754 | else if (strcmp(args[0], "unique-id-header") == 0) { |
| 4755 | if (!*(args[1])) { |
| 4756 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 4757 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4758 | goto out; |
| 4759 | } |
| 4760 | free(curproxy->header_unique_id); |
| 4761 | curproxy->header_unique_id = strdup(args[1]); |
| 4762 | } |
| 4763 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4764 | else if (strcmp(args[0], "log-format") == 0) { |
| 4765 | if (!*(args[1])) { |
| 4766 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 4767 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4768 | goto out; |
| 4769 | } |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 4770 | |
| 4771 | if (curproxy->logformat_string != default_http_log_format && |
| 4772 | curproxy->logformat_string != default_tcp_log_format && |
| 4773 | curproxy->logformat_string != clf_http_log_format) |
| 4774 | free(curproxy->logformat_string); |
| 4775 | curproxy->logformat_string = strdup(args[1]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4776 | } |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4777 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4778 | else if (!strcmp(args[0], "log") && kwm == KWM_NO) { |
| 4779 | /* delete previous herited or defined syslog servers */ |
| 4780 | struct logsrv *back; |
| 4781 | |
| 4782 | if (*(args[1]) != 0) { |
| 4783 | Alert("parsing [%s:%d]:%s : 'no log' does not expect arguments.\n", file, linenum, args[1]); |
| 4784 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4785 | goto out; |
| 4786 | } |
| 4787 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4788 | list_for_each_entry_safe(tmplogsrv, back, &curproxy->logsrvs, list) { |
| 4789 | LIST_DEL(&tmplogsrv->list); |
| 4790 | free(tmplogsrv); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4791 | } |
| 4792 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4793 | else if (!strcmp(args[0], "log")) { /* syslog server address */ |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4794 | struct logsrv *logsrv; |
| 4795 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4796 | if (*(args[1]) && *(args[2]) == 0 && !strcmp(args[1], "global")) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4797 | /* copy global.logrsvs linked list to the end of curproxy->logsrvs */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4798 | list_for_each_entry(tmplogsrv, &global.logsrvs, list) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4799 | struct logsrv *node = malloc(sizeof(struct logsrv)); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4800 | memcpy(node, tmplogsrv, sizeof(struct logsrv)); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4801 | LIST_INIT(&node->list); |
| 4802 | LIST_ADDQ(&curproxy->logsrvs, &node->list); |
| 4803 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4804 | } |
| 4805 | else if (*(args[1]) && *(args[2])) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4806 | |
| 4807 | logsrv = calloc(1, sizeof(struct logsrv)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4808 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4809 | logsrv->facility = get_log_facility(args[2]); |
| 4810 | if (logsrv->facility < 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4811 | 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] | 4812 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4813 | goto out; |
| 4814 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4815 | } |
| 4816 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4817 | logsrv->level = 7; /* max syslog level = debug */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4818 | if (*(args[3])) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4819 | logsrv->level = get_log_level(args[3]); |
| 4820 | if (logsrv->level < 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4821 | 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] | 4822 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4823 | goto out; |
| 4824 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4825 | } |
| 4826 | } |
| 4827 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4828 | logsrv->minlvl = 0; /* limit syslog level to this level (emerg) */ |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 4829 | if (*(args[4])) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4830 | logsrv->minlvl = get_log_level(args[4]); |
| 4831 | if (logsrv->level < 0) { |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 4832 | 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] | 4833 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4834 | goto out; |
| 4835 | |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 4836 | } |
| 4837 | } |
| 4838 | |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 4839 | if (args[1][0] == '/') { |
David du Colombier | 11bcb6c | 2011-03-24 12:23:00 +0100 | [diff] [blame] | 4840 | struct sockaddr_storage *sk = (struct sockaddr_storage *)str2sun(args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4841 | if (!sk) { |
| 4842 | 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] | 4843 | args[1], (int)sizeof(((struct sockaddr_un *)sk)->sun_path) - 1); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4844 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4845 | goto out; |
| 4846 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4847 | logsrv->addr = *sk; |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 4848 | } else { |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4849 | struct sockaddr_storage *sk = str2sa(args[1]); |
David du Colombier | 11bcb6c | 2011-03-24 12:23:00 +0100 | [diff] [blame] | 4850 | if (!sk) { |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4851 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[1]); |
| 4852 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4853 | goto out; |
| 4854 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4855 | logsrv->addr = *sk; |
| 4856 | if (!get_host_port(&logsrv->addr)) |
| 4857 | set_host_port(&logsrv->addr, SYSLOG_PORT); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4858 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4859 | |
| 4860 | LIST_ADDQ(&curproxy->logsrvs, &logsrv->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4861 | } |
| 4862 | else { |
| 4863 | Alert("parsing [%s:%d] : 'log' expects either <address[:port]> and <facility> or 'global' as arguments.\n", |
| 4864 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4865 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4866 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4867 | } |
| 4868 | } |
| 4869 | 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] | 4870 | int cur_arg; |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4871 | struct sockaddr_storage *sk; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4872 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4873 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4874 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4875 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4876 | if (!*args[1]) { |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4877 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optionally '%s' <addr>, and '%s' <name>.\n", |
| 4878 | file, linenum, "source", "usesrc", "interface"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4879 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4880 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4881 | } |
Willy Tarreau | 368480c | 2009-03-01 08:27:21 +0100 | [diff] [blame] | 4882 | |
| 4883 | /* we must first clear any optional default setting */ |
| 4884 | curproxy->options &= ~PR_O_TPXY_MASK; |
| 4885 | free(curproxy->iface_name); |
| 4886 | curproxy->iface_name = NULL; |
| 4887 | curproxy->iface_len = 0; |
| 4888 | |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4889 | sk = str2sa(args[1]); |
| 4890 | if (!sk) { |
| 4891 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[1]); |
| 4892 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4893 | goto out; |
| 4894 | } |
| 4895 | curproxy->source_addr = *sk; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4896 | curproxy->options |= PR_O_BIND_SRC; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4897 | |
| 4898 | cur_arg = 2; |
| 4899 | while (*(args[cur_arg])) { |
| 4900 | if (!strcmp(args[cur_arg], "usesrc")) { /* address to use outside */ |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4901 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) |
| 4902 | #if !defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4903 | if (curproxy->source_addr.sin_addr.s_addr == INADDR_ANY) { |
| 4904 | Alert("parsing [%s:%d] : '%s' requires an explicit 'source' address.\n", |
| 4905 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4906 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4907 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4908 | } |
| 4909 | #endif |
| 4910 | if (!*args[cur_arg + 1]) { |
| 4911 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n", |
| 4912 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4913 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4914 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4915 | } |
| 4916 | |
| 4917 | if (!strcmp(args[cur_arg + 1], "client")) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4918 | curproxy->options &= ~PR_O_TPXY_MASK; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4919 | curproxy->options |= PR_O_TPXY_CLI; |
| 4920 | } else if (!strcmp(args[cur_arg + 1], "clientip")) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4921 | curproxy->options &= ~PR_O_TPXY_MASK; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4922 | curproxy->options |= PR_O_TPXY_CIP; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4923 | } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) { |
| 4924 | char *name, *end; |
| 4925 | |
| 4926 | name = args[cur_arg+1] + 7; |
| 4927 | while (isspace(*name)) |
| 4928 | name++; |
| 4929 | |
| 4930 | end = name; |
| 4931 | while (*end && !isspace(*end) && *end != ',' && *end != ')') |
| 4932 | end++; |
| 4933 | |
| 4934 | curproxy->options &= ~PR_O_TPXY_MASK; |
| 4935 | curproxy->options |= PR_O_TPXY_DYN; |
| 4936 | curproxy->bind_hdr_name = calloc(1, end - name + 1); |
| 4937 | curproxy->bind_hdr_len = end - name; |
| 4938 | memcpy(curproxy->bind_hdr_name, name, end - name); |
| 4939 | curproxy->bind_hdr_name[end-name] = '\0'; |
| 4940 | curproxy->bind_hdr_occ = -1; |
| 4941 | |
| 4942 | /* now look for an occurrence number */ |
| 4943 | while (isspace(*end)) |
| 4944 | end++; |
| 4945 | if (*end == ',') { |
| 4946 | end++; |
| 4947 | name = end; |
| 4948 | if (*end == '-') |
| 4949 | end++; |
| 4950 | while (isdigit(*end)) |
| 4951 | end++; |
| 4952 | curproxy->bind_hdr_occ = strl2ic(name, end-name); |
| 4953 | } |
| 4954 | |
| 4955 | if (curproxy->bind_hdr_occ < -MAX_HDR_HISTORY) { |
| 4956 | Alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative" |
| 4957 | " occurrences values smaller than %d.\n", |
| 4958 | file, linenum, MAX_HDR_HISTORY); |
| 4959 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4960 | goto out; |
| 4961 | } |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4962 | } else { |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4963 | struct sockaddr_storage *sk = str2sa(args[cur_arg + 1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4964 | if (!sk) { |
| 4965 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[cur_arg + 1]); |
| 4966 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4967 | goto out; |
| 4968 | } |
| 4969 | curproxy->tproxy_addr = *sk; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4970 | curproxy->options |= PR_O_TPXY_ADDR; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4971 | } |
| 4972 | global.last_checks |= LSTCHK_NETADM; |
| 4973 | #if !defined(CONFIG_HAP_LINUX_TPROXY) |
| 4974 | global.last_checks |= LSTCHK_CTTPROXY; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4975 | #endif |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4976 | #else /* no TPROXY support */ |
| 4977 | 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] | 4978 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4979 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4980 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4981 | #endif |
| 4982 | cur_arg += 2; |
| 4983 | continue; |
Willy Tarreau | 77074d5 | 2006-11-12 23:57:19 +0100 | [diff] [blame] | 4984 | } |
| 4985 | |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4986 | if (!strcmp(args[cur_arg], "interface")) { /* specifically bind to this interface */ |
| 4987 | #ifdef SO_BINDTODEVICE |
| 4988 | if (!*args[cur_arg + 1]) { |
| 4989 | Alert("parsing [%s:%d] : '%s' : missing interface name.\n", |
| 4990 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4991 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4992 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4993 | } |
| 4994 | if (curproxy->iface_name) |
| 4995 | free(curproxy->iface_name); |
| 4996 | |
| 4997 | curproxy->iface_name = strdup(args[cur_arg + 1]); |
| 4998 | curproxy->iface_len = strlen(curproxy->iface_name); |
| 4999 | global.last_checks |= LSTCHK_NETADM; |
| 5000 | #else |
| 5001 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 5002 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5003 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5004 | goto out; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 5005 | #endif |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5006 | cur_arg += 2; |
| 5007 | continue; |
| 5008 | } |
| 5009 | Alert("parsing [%s:%d] : '%s' only supports optional keywords '%s' and '%s'.\n", |
Willy Tarreau | 3631d41 | 2012-09-25 16:31:00 +0200 | [diff] [blame] | 5010 | file, linenum, args[0], "interface", "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5011 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5012 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 5013 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5014 | } |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 5015 | else if (!strcmp(args[0], "usesrc")) { /* address to use outside: needs "source" first */ |
| 5016 | Alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n", |
| 5017 | file, linenum, "usesrc", "source"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5018 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5019 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 5020 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5021 | 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] | 5022 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5023 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 5024 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5025 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5026 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5027 | } |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5028 | |
| 5029 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5030 | SMP_OPT_DIR_REQ, ACT_REPLACE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5031 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5032 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5033 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5034 | } |
| 5035 | else if (!strcmp(args[0], "reqdel")) { /* delete request header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5036 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5037 | SMP_OPT_DIR_REQ, ACT_REMOVE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5038 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5039 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5040 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5041 | } |
| 5042 | 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] | 5043 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5044 | SMP_OPT_DIR_REQ, ACT_DENY, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5045 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5046 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5047 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5048 | } |
| 5049 | 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] | 5050 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5051 | SMP_OPT_DIR_REQ, ACT_PASS, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5052 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5053 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5054 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5055 | } |
| 5056 | 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] | 5057 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5058 | SMP_OPT_DIR_REQ, ACT_ALLOW, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5059 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5060 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5061 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5062 | } |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 5063 | 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] | 5064 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5065 | SMP_OPT_DIR_REQ, ACT_TARPIT, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5066 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5067 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5068 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 5069 | } |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5070 | 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] | 5071 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5072 | SMP_OPT_DIR_REQ, ACT_SETBE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5073 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5074 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5075 | goto out; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5076 | } |
| 5077 | 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] | 5078 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5079 | SMP_OPT_DIR_REQ, ACT_SETBE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5080 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5081 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5082 | goto out; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5083 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5084 | 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] | 5085 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5086 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 5087 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5088 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5089 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5090 | } |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5091 | |
| 5092 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5093 | SMP_OPT_DIR_REQ, ACT_REPLACE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5094 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5095 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5096 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5097 | } |
| 5098 | 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] | 5099 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5100 | SMP_OPT_DIR_REQ, ACT_REMOVE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5101 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5102 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5103 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5104 | } |
| 5105 | 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] | 5106 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5107 | SMP_OPT_DIR_REQ, ACT_DENY, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5108 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5109 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5110 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5111 | } |
| 5112 | 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] | 5113 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5114 | SMP_OPT_DIR_REQ, ACT_PASS, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5115 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5116 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5117 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5118 | } |
| 5119 | 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] | 5120 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5121 | SMP_OPT_DIR_REQ, ACT_ALLOW, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5122 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5123 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5124 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5125 | } |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 5126 | 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] | 5127 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5128 | SMP_OPT_DIR_REQ, ACT_TARPIT, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5129 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5130 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5131 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 5132 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5133 | else if (!strcmp(args[0], "reqadd")) { /* add request header */ |
Willy Tarreau | f4f0412 | 2010-01-28 18:10:50 +0100 | [diff] [blame] | 5134 | struct cond_wordlist *wl; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5135 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5136 | if (curproxy == &defproxy) { |
| 5137 | 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] | 5138 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5139 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5140 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5141 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5142 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5143 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5144 | if (*(args[1]) == 0) { |
| 5145 | 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] | 5146 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5147 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5148 | } |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5149 | |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 5150 | if ((strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0)) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 5151 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args+2, &errmsg)) == NULL) { |
| 5152 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 5153 | file, linenum, args[0], errmsg); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 5154 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5155 | goto out; |
| 5156 | } |
| 5157 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
| 5158 | } |
| 5159 | else if (*args[2]) { |
| 5160 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 5161 | file, linenum, args[0], args[2]); |
| 5162 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5163 | goto out; |
| 5164 | } |
| 5165 | |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5166 | wl = calloc(1, sizeof(*wl)); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 5167 | wl->cond = cond; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5168 | wl->s = strdup(args[1]); |
| 5169 | LIST_ADDQ(&curproxy->req_add, &wl->list); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 5170 | warnif_misplaced_reqadd(curproxy, file, linenum, args[0]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5171 | } |
| 5172 | 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] | 5173 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5174 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 5175 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5176 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5177 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5178 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5179 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5180 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5181 | SMP_OPT_DIR_RES, ACT_REPLACE, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5182 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5183 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5184 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5185 | } |
| 5186 | else if (!strcmp(args[0], "rspdel")) { /* delete response header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5187 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5188 | SMP_OPT_DIR_RES, ACT_REMOVE, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5189 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5190 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5191 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5192 | } |
| 5193 | else if (!strcmp(args[0], "rspdeny")) { /* block response header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5194 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5195 | SMP_OPT_DIR_RES, ACT_DENY, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5196 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5197 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5198 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5199 | } |
| 5200 | 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] | 5201 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5202 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 5203 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5204 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5205 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5206 | } |
| 5207 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5208 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5209 | SMP_OPT_DIR_RES, ACT_REPLACE, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5210 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5211 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5212 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5213 | } |
| 5214 | 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] | 5215 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5216 | SMP_OPT_DIR_RES, ACT_REMOVE, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5217 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5218 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5219 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5220 | } |
| 5221 | 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] | 5222 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5223 | SMP_OPT_DIR_RES, ACT_DENY, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5224 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5225 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5226 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5227 | } |
| 5228 | else if (!strcmp(args[0], "rspadd")) { /* add response header */ |
Willy Tarreau | f4f0412 | 2010-01-28 18:10:50 +0100 | [diff] [blame] | 5229 | struct cond_wordlist *wl; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5230 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5231 | if (curproxy == &defproxy) { |
| 5232 | 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] | 5233 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5234 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5235 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5236 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5237 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5238 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5239 | if (*(args[1]) == 0) { |
| 5240 | 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] | 5241 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5242 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5243 | } |
| 5244 | |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5245 | if ((strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0)) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 5246 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args+2, &errmsg)) == NULL) { |
| 5247 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 5248 | file, linenum, args[0], errmsg); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5249 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5250 | goto out; |
| 5251 | } |
| 5252 | err_code |= warnif_cond_requires_req(cond, file, linenum); |
| 5253 | } |
| 5254 | else if (*args[2]) { |
| 5255 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 5256 | file, linenum, args[0], args[2]); |
| 5257 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5258 | goto out; |
| 5259 | } |
| 5260 | |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5261 | wl = calloc(1, sizeof(*wl)); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5262 | wl->cond = cond; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5263 | wl->s = strdup(args[1]); |
| 5264 | LIST_ADDQ(&curproxy->rsp_add, &wl->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5265 | } |
| 5266 | else if (!strcmp(args[0], "errorloc") || |
| 5267 | !strcmp(args[0], "errorloc302") || |
| 5268 | !strcmp(args[0], "errorloc303")) { /* error location */ |
| 5269 | int errnum, errlen; |
| 5270 | char *err; |
| 5271 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5272 | 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] | 5273 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5274 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5275 | if (*(args[2]) == 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 5276 | 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] | 5277 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5278 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5279 | } |
| 5280 | |
| 5281 | errnum = atol(args[1]); |
| 5282 | if (!strcmp(args[0], "errorloc303")) { |
| 5283 | err = malloc(strlen(HTTP_303) + strlen(args[2]) + 5); |
| 5284 | errlen = sprintf(err, "%s%s\r\n\r\n", HTTP_303, args[2]); |
| 5285 | } else { |
| 5286 | err = malloc(strlen(HTTP_302) + strlen(args[2]) + 5); |
| 5287 | errlen = sprintf(err, "%s%s\r\n\r\n", HTTP_302, args[2]); |
| 5288 | } |
| 5289 | |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 5290 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) { |
| 5291 | if (http_err_codes[rc] == errnum) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 5292 | chunk_destroy(&curproxy->errmsg[rc]); |
| 5293 | chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 5294 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5295 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5296 | } |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 5297 | |
| 5298 | if (rc >= HTTP_ERR_SIZE) { |
| 5299 | Warning("parsing [%s:%d] : status code %d not handled, error relocation will be ignored.\n", |
| 5300 | file, linenum, errnum); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5301 | free(err); |
| 5302 | } |
| 5303 | } |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5304 | else if (!strcmp(args[0], "errorfile")) { /* error message from a file */ |
| 5305 | int errnum, errlen, fd; |
| 5306 | char *err; |
| 5307 | struct stat stat; |
| 5308 | |
| 5309 | 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] | 5310 | err_code |= ERR_WARN; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5311 | |
| 5312 | if (*(args[2]) == 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 5313 | 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] | 5314 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5315 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5316 | } |
| 5317 | |
| 5318 | fd = open(args[2], O_RDONLY); |
| 5319 | if ((fd < 0) || (fstat(fd, &stat) < 0)) { |
| 5320 | Alert("parsing [%s:%d] : error opening file <%s> for custom error message <%s>.\n", |
| 5321 | file, linenum, args[2], args[1]); |
| 5322 | if (fd >= 0) |
| 5323 | close(fd); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5324 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5325 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5326 | } |
| 5327 | |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 5328 | if (stat.st_size <= global.tune.bufsize) { |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5329 | errlen = stat.st_size; |
| 5330 | } else { |
| 5331 | 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] | 5332 | file, linenum, args[2], global.tune.bufsize); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5333 | err_code |= ERR_WARN; |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 5334 | errlen = global.tune.bufsize; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5335 | } |
| 5336 | |
| 5337 | err = malloc(errlen); /* malloc() must succeed during parsing */ |
| 5338 | errnum = read(fd, err, errlen); |
| 5339 | if (errnum != errlen) { |
| 5340 | Alert("parsing [%s:%d] : error reading file <%s> for custom error message <%s>.\n", |
| 5341 | file, linenum, args[2], args[1]); |
| 5342 | close(fd); |
| 5343 | free(err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5344 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5345 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5346 | } |
| 5347 | close(fd); |
| 5348 | |
| 5349 | errnum = atol(args[1]); |
| 5350 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) { |
| 5351 | if (http_err_codes[rc] == errnum) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 5352 | chunk_destroy(&curproxy->errmsg[rc]); |
| 5353 | chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen); |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5354 | break; |
| 5355 | } |
| 5356 | } |
| 5357 | |
| 5358 | if (rc >= HTTP_ERR_SIZE) { |
| 5359 | Warning("parsing [%s:%d] : status code %d not handled, error customization will be ignored.\n", |
| 5360 | file, linenum, errnum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5361 | err_code |= ERR_WARN; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5362 | free(err); |
| 5363 | } |
| 5364 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5365 | else { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 5366 | struct cfg_kw_list *kwl; |
| 5367 | int index; |
| 5368 | |
| 5369 | list_for_each_entry(kwl, &cfg_keywords.list, list) { |
| 5370 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 5371 | if (kwl->kw[index].section != CFG_LISTEN) |
| 5372 | continue; |
| 5373 | if (strcmp(kwl->kw[index].kw, args[0]) == 0) { |
| 5374 | /* prepare error message just in case */ |
David du Colombier | 7af4605 | 2012-05-16 14:16:48 +0200 | [diff] [blame] | 5375 | snprintf(trash, trashlen, |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 5376 | "error near '%s' in %s section", args[0], cursection); |
Willy Tarreau | 28a47d6 | 2012-09-18 20:02:48 +0200 | [diff] [blame] | 5377 | rc = kwl->kw[index].parse(args, CFG_LISTEN, curproxy, &defproxy, file, linenum, &errmsg); |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 5378 | if (rc < 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 5379 | Alert("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5380 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5381 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 5382 | } |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 5383 | else if (rc > 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 5384 | Warning("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5385 | err_code |= ERR_WARN; |
| 5386 | goto out; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 5387 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5388 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 5389 | } |
| 5390 | } |
| 5391 | } |
| 5392 | |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5393 | 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] | 5394 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5395 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5396 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5397 | out: |
Willy Tarreau | f4068b6 | 2012-05-08 17:37:49 +0200 | [diff] [blame] | 5398 | free(errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5399 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5400 | } |
| 5401 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5402 | int |
| 5403 | cfg_parse_users(const char *file, int linenum, char **args, int kwm) |
| 5404 | { |
| 5405 | |
| 5406 | int err_code = 0; |
| 5407 | const char *err; |
| 5408 | |
| 5409 | if (!strcmp(args[0], "userlist")) { /* new userlist */ |
| 5410 | struct userlist *newul; |
| 5411 | |
| 5412 | if (!*args[1]) { |
| 5413 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 5414 | file, linenum, args[0]); |
| 5415 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5416 | goto out; |
| 5417 | } |
| 5418 | |
| 5419 | err = invalid_char(args[1]); |
| 5420 | if (err) { |
| 5421 | Alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 5422 | file, linenum, *err, args[0], args[1]); |
| 5423 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5424 | goto out; |
| 5425 | } |
| 5426 | |
| 5427 | for (newul = userlist; newul; newul = newul->next) |
| 5428 | if (!strcmp(newul->name, args[1])) { |
| 5429 | Warning("parsing [%s:%d]: ignoring duplicated userlist '%s'.\n", |
| 5430 | file, linenum, args[1]); |
| 5431 | err_code |= ERR_WARN; |
| 5432 | goto out; |
| 5433 | } |
| 5434 | |
| 5435 | newul = (struct userlist *)calloc(1, sizeof(struct userlist)); |
| 5436 | if (!newul) { |
| 5437 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 5438 | err_code |= ERR_ALERT | ERR_ABORT; |
| 5439 | goto out; |
| 5440 | } |
| 5441 | |
| 5442 | newul->groupusers = calloc(MAX_AUTH_GROUPS, sizeof(char *)); |
| 5443 | newul->name = strdup(args[1]); |
| 5444 | |
| 5445 | if (!newul->groupusers | !newul->name) { |
| 5446 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 5447 | err_code |= ERR_ALERT | ERR_ABORT; |
| 5448 | goto out; |
| 5449 | } |
| 5450 | |
| 5451 | newul->next = userlist; |
| 5452 | userlist = newul; |
| 5453 | |
| 5454 | } else if (!strcmp(args[0], "group")) { /* new group */ |
| 5455 | int cur_arg, i; |
| 5456 | const char *err; |
| 5457 | |
| 5458 | if (!*args[1]) { |
| 5459 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 5460 | file, linenum, args[0]); |
| 5461 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5462 | goto out; |
| 5463 | } |
| 5464 | |
| 5465 | err = invalid_char(args[1]); |
| 5466 | if (err) { |
| 5467 | Alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 5468 | file, linenum, *err, args[0], args[1]); |
| 5469 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5470 | goto out; |
| 5471 | } |
| 5472 | |
| 5473 | for(i = 0; i < userlist->grpcnt; i++) |
| 5474 | if (!strcmp(userlist->groups[i], args[1])) { |
| 5475 | Warning("parsing [%s:%d]: ignoring duplicated group '%s' in userlist '%s'.\n", |
| 5476 | file, linenum, args[1], userlist->name); |
| 5477 | err_code |= ERR_ALERT; |
| 5478 | goto out; |
| 5479 | } |
| 5480 | |
| 5481 | if (userlist->grpcnt >= MAX_AUTH_GROUPS) { |
| 5482 | Alert("parsing [%s:%d]: too many groups (%u) in in userlist '%s' while adding group '%s'.\n", |
| 5483 | file, linenum, MAX_AUTH_GROUPS, userlist->name, args[1]); |
| 5484 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5485 | goto out; |
| 5486 | } |
| 5487 | |
| 5488 | cur_arg = 2; |
| 5489 | |
| 5490 | while (*args[cur_arg]) { |
| 5491 | if (!strcmp(args[cur_arg], "users")) { |
| 5492 | userlist->groupusers[userlist->grpcnt] = strdup(args[cur_arg + 1]); |
| 5493 | cur_arg += 2; |
| 5494 | continue; |
| 5495 | } else { |
| 5496 | Alert("parsing [%s:%d]: '%s' only supports 'users' option.\n", |
| 5497 | file, linenum, args[0]); |
| 5498 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5499 | goto out; |
| 5500 | } |
| 5501 | } |
| 5502 | |
| 5503 | userlist->groups[userlist->grpcnt++] = strdup(args[1]); |
| 5504 | } else if (!strcmp(args[0], "user")) { /* new user */ |
| 5505 | struct auth_users *newuser; |
| 5506 | int cur_arg; |
| 5507 | |
| 5508 | if (!*args[1]) { |
| 5509 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 5510 | file, linenum, args[0]); |
| 5511 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5512 | goto out; |
| 5513 | } |
| 5514 | |
| 5515 | for (newuser = userlist->users; newuser; newuser = newuser->next) |
| 5516 | if (!strcmp(newuser->user, args[1])) { |
| 5517 | Warning("parsing [%s:%d]: ignoring duplicated user '%s' in userlist '%s'.\n", |
| 5518 | file, linenum, args[1], userlist->name); |
| 5519 | err_code |= ERR_ALERT; |
| 5520 | goto out; |
| 5521 | } |
| 5522 | |
| 5523 | newuser = (struct auth_users *)calloc(1, sizeof(struct auth_users)); |
| 5524 | if (!newuser) { |
| 5525 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 5526 | err_code |= ERR_ALERT | ERR_ABORT; |
| 5527 | goto out; |
| 5528 | } |
| 5529 | |
| 5530 | newuser->user = strdup(args[1]); |
| 5531 | |
| 5532 | newuser->next = userlist->users; |
| 5533 | userlist->users = newuser; |
| 5534 | |
| 5535 | cur_arg = 2; |
| 5536 | |
| 5537 | while (*args[cur_arg]) { |
| 5538 | if (!strcmp(args[cur_arg], "password")) { |
| 5539 | #ifndef CONFIG_HAP_CRYPT |
| 5540 | Warning("parsing [%s:%d]: no crypt(3) support compiled, encrypted passwords will not work.\n", |
| 5541 | file, linenum); |
| 5542 | err_code |= ERR_ALERT; |
| 5543 | #endif |
| 5544 | newuser->pass = strdup(args[cur_arg + 1]); |
| 5545 | cur_arg += 2; |
| 5546 | continue; |
| 5547 | } else if (!strcmp(args[cur_arg], "insecure-password")) { |
| 5548 | newuser->pass = strdup(args[cur_arg + 1]); |
| 5549 | newuser->flags |= AU_O_INSECURE; |
| 5550 | cur_arg += 2; |
| 5551 | continue; |
| 5552 | } else if (!strcmp(args[cur_arg], "groups")) { |
Willy Tarreau | b4c06b7 | 2010-02-02 11:28:20 +0100 | [diff] [blame] | 5553 | newuser->u.groups = strdup(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5554 | cur_arg += 2; |
| 5555 | continue; |
| 5556 | } else { |
| 5557 | Alert("parsing [%s:%d]: '%s' only supports 'password', 'insecure-password' and 'groups' options.\n", |
| 5558 | file, linenum, args[0]); |
| 5559 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5560 | goto out; |
| 5561 | } |
| 5562 | } |
| 5563 | } else { |
| 5564 | Alert("parsing [%s:%d]: unknown keyword '%s' in '%s' section\n", file, linenum, args[0], "users"); |
| 5565 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5566 | } |
| 5567 | |
| 5568 | out: |
| 5569 | return err_code; |
| 5570 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5571 | |
| 5572 | /* |
| 5573 | * This function reads and parses the configuration file given in the argument. |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5574 | * Returns the error code, 0 if OK, or any combination of : |
| 5575 | * - ERR_ABORT: must abort ASAP |
| 5576 | * - ERR_FATAL: we can continue parsing but not start the service |
| 5577 | * - ERR_WARN: a warning has been emitted |
| 5578 | * - ERR_ALERT: an alert has been emitted |
| 5579 | * Only the two first ones can stop processing, the two others are just |
| 5580 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5581 | */ |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 5582 | int readcfgfile(const char *file) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5583 | { |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5584 | char thisline[LINESIZE]; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5585 | FILE *f; |
| 5586 | int linenum = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5587 | int confsect = CFG_NONE; |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5588 | int err_code = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5589 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5590 | if ((f=fopen(file,"r")) == NULL) |
| 5591 | return -1; |
| 5592 | |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5593 | while (fgets(thisline, sizeof(thisline), f) != NULL) { |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 5594 | int arg, kwm = KWM_STD; |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5595 | char *end; |
| 5596 | char *args[MAX_LINE_ARGS + 1]; |
| 5597 | char *line = thisline; |
| 5598 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5599 | linenum++; |
| 5600 | |
| 5601 | end = line + strlen(line); |
| 5602 | |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5603 | if (end-line == sizeof(thisline)-1 && *(end-1) != '\n') { |
| 5604 | /* Check if we reached the limit and the last char is not \n. |
| 5605 | * Watch out for the last line without the terminating '\n'! |
| 5606 | */ |
| 5607 | Alert("parsing [%s:%d]: line too long, limit: %d.\n", |
Willy Tarreau | 5e4a6f1 | 2009-04-11 19:42:49 +0200 | [diff] [blame] | 5608 | file, linenum, (int)sizeof(thisline)-1); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5609 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5610 | } |
| 5611 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5612 | /* skip leading spaces */ |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 5613 | while (isspace((unsigned char)*line)) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5614 | line++; |
| 5615 | |
| 5616 | arg = 0; |
| 5617 | args[arg] = line; |
| 5618 | |
| 5619 | while (*line && arg < MAX_LINE_ARGS) { |
| 5620 | /* first, we'll replace \\, \<space>, \#, \r, \n, \t, \xXX with their |
| 5621 | * C equivalent value. Other combinations left unchanged (eg: \1). |
| 5622 | */ |
| 5623 | if (*line == '\\') { |
| 5624 | int skip = 0; |
| 5625 | if (line[1] == ' ' || line[1] == '\\' || line[1] == '#') { |
| 5626 | *line = line[1]; |
| 5627 | skip = 1; |
| 5628 | } |
| 5629 | else if (line[1] == 'r') { |
| 5630 | *line = '\r'; |
| 5631 | skip = 1; |
| 5632 | } |
| 5633 | else if (line[1] == 'n') { |
| 5634 | *line = '\n'; |
| 5635 | skip = 1; |
| 5636 | } |
| 5637 | else if (line[1] == 't') { |
| 5638 | *line = '\t'; |
| 5639 | skip = 1; |
| 5640 | } |
| 5641 | else if (line[1] == 'x') { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5642 | if ((line + 3 < end) && ishex(line[2]) && ishex(line[3])) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5643 | unsigned char hex1, hex2; |
| 5644 | hex1 = toupper(line[2]) - '0'; |
| 5645 | hex2 = toupper(line[3]) - '0'; |
| 5646 | if (hex1 > 9) hex1 -= 'A' - '9' - 1; |
| 5647 | if (hex2 > 9) hex2 -= 'A' - '9' - 1; |
| 5648 | *line = (hex1<<4) + hex2; |
| 5649 | skip = 3; |
| 5650 | } |
| 5651 | else { |
| 5652 | 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] | 5653 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5654 | } |
| 5655 | } |
| 5656 | if (skip) { |
Cyril Bonté | dd1b01d | 2009-12-06 13:43:42 +0100 | [diff] [blame] | 5657 | memmove(line + 1, line + 1 + skip, end - (line + skip)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5658 | end -= skip; |
| 5659 | } |
| 5660 | line++; |
| 5661 | } |
| 5662 | else if (*line == '#' || *line == '\n' || *line == '\r') { |
| 5663 | /* end of string, end of loop */ |
| 5664 | *line = 0; |
| 5665 | break; |
| 5666 | } |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 5667 | else if (isspace((unsigned char)*line)) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5668 | /* a non-escaped space is an argument separator */ |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5669 | *line++ = '\0'; |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 5670 | while (isspace((unsigned char)*line)) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5671 | line++; |
| 5672 | args[++arg] = line; |
| 5673 | } |
| 5674 | else { |
| 5675 | line++; |
| 5676 | } |
| 5677 | } |
| 5678 | |
| 5679 | /* empty line */ |
| 5680 | if (!**args) |
| 5681 | continue; |
| 5682 | |
Willy Tarreau | 7bb651e | 2009-11-09 21:16:53 +0100 | [diff] [blame] | 5683 | if (*line) { |
| 5684 | /* we had to stop due to too many args. |
| 5685 | * Let's terminate the string, print the offending part then cut the |
| 5686 | * last arg. |
| 5687 | */ |
| 5688 | while (*line && *line != '#' && *line != '\n' && *line != '\r') |
| 5689 | line++; |
| 5690 | *line = '\0'; |
| 5691 | |
Krzysztof Piotr Oledzki | 500b8f0 | 2009-12-15 22:34:51 +0100 | [diff] [blame] | 5692 | 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] | 5693 | file, linenum, arg + 1, (long)(args[arg] - thisline + 1), args[arg]); |
Willy Tarreau | 7bb651e | 2009-11-09 21:16:53 +0100 | [diff] [blame] | 5694 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5695 | args[arg] = line; |
| 5696 | } |
| 5697 | |
Willy Tarreau | 540abe4 | 2007-05-02 20:50:16 +0200 | [diff] [blame] | 5698 | /* zero out remaining args and ensure that at least one entry |
| 5699 | * is zeroed out. |
| 5700 | */ |
| 5701 | while (++arg <= MAX_LINE_ARGS) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5702 | args[arg] = line; |
| 5703 | } |
| 5704 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 5705 | /* check for keyword modifiers "no" and "default" */ |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5706 | if (!strcmp(args[0], "no")) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5707 | char *tmp; |
| 5708 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 5709 | kwm = KWM_NO; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5710 | tmp = args[0]; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5711 | for (arg=0; *args[arg+1]; arg++) |
| 5712 | args[arg] = args[arg+1]; // shift args after inversion |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5713 | *tmp = '\0'; // fix the next arg to \0 |
| 5714 | args[arg] = tmp; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5715 | } |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 5716 | else if (!strcmp(args[0], "default")) { |
| 5717 | kwm = KWM_DEF; |
| 5718 | for (arg=0; *args[arg+1]; arg++) |
| 5719 | args[arg] = args[arg+1]; // shift args after inversion |
| 5720 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5721 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5722 | if (kwm != KWM_STD && strcmp(args[0], "option") != 0 && \ |
| 5723 | strcmp(args[0], "log") != 0) { |
| 5724 | 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] | 5725 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5726 | } |
| 5727 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5728 | if (!strcmp(args[0], "listen") || |
| 5729 | !strcmp(args[0], "frontend") || |
| 5730 | !strcmp(args[0], "backend") || |
| 5731 | !strcmp(args[0], "ruleset") || |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5732 | !strcmp(args[0], "defaults")) { /* new proxy */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5733 | confsect = CFG_LISTEN; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 5734 | free(cursection); |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5735 | cursection = strdup(args[0]); |
| 5736 | } |
| 5737 | else if (!strcmp(args[0], "global")) { /* global config */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5738 | confsect = CFG_GLOBAL; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 5739 | free(cursection); |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5740 | cursection = strdup(args[0]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 5741 | } |
| 5742 | else if (!strcmp(args[0], "userlist")) { |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5743 | confsect = CFG_USERLIST; |
| 5744 | free(cursection); |
| 5745 | cursection = strdup(args[0]); |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5746 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 5747 | else if (!strcmp(args[0], "peers")) { |
| 5748 | confsect = CFG_PEERS; |
| 5749 | free(cursection); |
| 5750 | cursection = strdup(args[0]); |
| 5751 | } |
| 5752 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5753 | /* else it's a section keyword */ |
| 5754 | |
| 5755 | switch (confsect) { |
| 5756 | case CFG_LISTEN: |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5757 | err_code |= cfg_parse_listen(file, linenum, args, kwm); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5758 | break; |
| 5759 | case CFG_GLOBAL: |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5760 | err_code |= cfg_parse_global(file, linenum, args, kwm); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5761 | break; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5762 | case CFG_USERLIST: |
| 5763 | err_code |= cfg_parse_users(file, linenum, args, kwm); |
| 5764 | break; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 5765 | case CFG_PEERS: |
| 5766 | err_code |= cfg_parse_peers(file, linenum, args, kwm); |
| 5767 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5768 | default: |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5769 | 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] | 5770 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5771 | } |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5772 | |
| 5773 | if (err_code & ERR_ABORT) |
| 5774 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5775 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 5776 | free(cursection); |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5777 | cursection = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5778 | fclose(f); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5779 | return err_code; |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5780 | } |
| 5781 | |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 5782 | /* |
| 5783 | * Returns the error code, 0 if OK, or any combination of : |
| 5784 | * - ERR_ABORT: must abort ASAP |
| 5785 | * - ERR_FATAL: we can continue parsing but not start the service |
| 5786 | * - ERR_WARN: a warning has been emitted |
| 5787 | * - ERR_ALERT: an alert has been emitted |
| 5788 | * Only the two first ones can stop processing, the two others are just |
| 5789 | * indicators. |
| 5790 | */ |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5791 | int check_config_validity() |
| 5792 | { |
| 5793 | int cfgerr = 0; |
| 5794 | struct proxy *curproxy = NULL; |
| 5795 | struct server *newsrv = NULL; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5796 | struct userlist *curuserlist = NULL; |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 5797 | int err_code = 0; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 5798 | unsigned int next_pxid = 1; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 5799 | struct bind_conf *bind_conf; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5800 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 5801 | bind_conf = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5802 | /* |
| 5803 | * Now, check for the integrity of all that we have collected. |
| 5804 | */ |
| 5805 | |
| 5806 | /* will be needed further to delay some tasks */ |
Willy Tarreau | b0b37bc | 2008-06-23 14:00:57 +0200 | [diff] [blame] | 5807 | tv_update_date(0,1); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5808 | |
Willy Tarreau | 55bc0f8 | 2009-03-15 14:51:53 +0100 | [diff] [blame] | 5809 | /* first, we will invert the proxy list order */ |
| 5810 | curproxy = NULL; |
| 5811 | while (proxy) { |
| 5812 | struct proxy *next; |
| 5813 | |
| 5814 | next = proxy->next; |
| 5815 | proxy->next = curproxy; |
| 5816 | curproxy = proxy; |
| 5817 | if (!next) |
| 5818 | break; |
| 5819 | proxy = next; |
| 5820 | } |
| 5821 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5822 | while (curproxy != NULL) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 5823 | struct switching_rule *rule; |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 5824 | struct server_rule *srule; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5825 | struct sticking_rule *mrule; |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 5826 | struct tcp_rule *trule; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 5827 | struct listener *listener; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 5828 | unsigned int next_id; |
| 5829 | |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 5830 | if (curproxy->uuid < 0) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 5831 | /* proxy ID not set, use automatic numbering with first |
| 5832 | * spare entry starting with next_pxid. |
| 5833 | */ |
| 5834 | next_pxid = get_next_id(&used_proxy_id, next_pxid); |
| 5835 | curproxy->conf.id.key = curproxy->uuid = next_pxid; |
| 5836 | eb32_insert(&used_proxy_id, &curproxy->conf.id); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 5837 | } |
Krzysztof Piotr Oledzki | df5cb9f | 2010-02-05 20:58:27 +0100 | [diff] [blame] | 5838 | next_pxid++; |
| 5839 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 5840 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5841 | if (curproxy->state == PR_STSTOPPED) { |
Willy Tarreau | da250db | 2008-10-12 12:07:48 +0200 | [diff] [blame] | 5842 | /* ensure we don't keep listeners uselessly bound */ |
| 5843 | stop_proxy(curproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5844 | curproxy = curproxy->next; |
| 5845 | continue; |
| 5846 | } |
| 5847 | |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 5848 | switch (curproxy->mode) { |
| 5849 | case PR_MODE_HEALTH: |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5850 | cfgerr += proxy_cfg_ensure_no_http(curproxy); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 5851 | if (!(curproxy->cap & PR_CAP_FE)) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5852 | Alert("config : %s '%s' cannot be in health mode as it has no frontend capability.\n", |
| 5853 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 5854 | cfgerr++; |
| 5855 | } |
| 5856 | |
| 5857 | if (curproxy->srv != NULL) |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5858 | Warning("config : servers will be ignored for %s '%s'.\n", |
| 5859 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 5860 | break; |
| 5861 | |
| 5862 | case PR_MODE_TCP: |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5863 | cfgerr += proxy_cfg_ensure_no_http(curproxy); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 5864 | break; |
| 5865 | |
| 5866 | case PR_MODE_HTTP: |
Willy Tarreau | a9fb083 | 2009-07-10 20:53:53 +0200 | [diff] [blame] | 5867 | curproxy->acl_requires |= ACL_USE_L7_ANY; |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 5868 | break; |
| 5869 | } |
| 5870 | |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 5871 | if ((curproxy->cap & PR_CAP_BE) && (curproxy->mode != PR_MODE_HEALTH)) { |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 5872 | if (curproxy->lbprm.algo & BE_LB_KIND) { |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 5873 | if (curproxy->options & PR_O_TRANSP) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5874 | Alert("config : %s '%s' cannot use both transparent and balance mode.\n", |
| 5875 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 5876 | cfgerr++; |
| 5877 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5878 | #ifdef WE_DONT_SUPPORT_SERVERLESS_LISTENERS |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 5879 | else if (curproxy->srv == NULL) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5880 | Alert("config : %s '%s' needs at least 1 server in balance mode.\n", |
| 5881 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 5882 | cfgerr++; |
| 5883 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5884 | #endif |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 5885 | else if (curproxy->options & PR_O_DISPATCH) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5886 | Warning("config : dispatch address of %s '%s' will be ignored in balance mode.\n", |
| 5887 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 5888 | err_code |= ERR_WARN; |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 5889 | } |
| 5890 | } |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 5891 | 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] | 5892 | /* If no LB algo is set in a backend, and we're not in |
| 5893 | * transparent mode, dispatch mode nor proxy mode, we |
| 5894 | * want to use balance roundrobin by default. |
| 5895 | */ |
| 5896 | curproxy->lbprm.algo &= ~BE_LB_ALGO; |
| 5897 | curproxy->lbprm.algo |= BE_LB_ALGO_RR; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5898 | } |
| 5899 | } |
Willy Tarreau | 193cf93 | 2007-09-17 10:17:23 +0200 | [diff] [blame] | 5900 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 5901 | if (curproxy->options & PR_O_DISPATCH) |
| 5902 | curproxy->options &= ~(PR_O_TRANSP | PR_O_HTTP_PROXY); |
| 5903 | else if (curproxy->options & PR_O_HTTP_PROXY) |
| 5904 | curproxy->options &= ~(PR_O_DISPATCH | PR_O_TRANSP); |
| 5905 | else if (curproxy->options & PR_O_TRANSP) |
| 5906 | curproxy->options &= ~(PR_O_DISPATCH | PR_O_HTTP_PROXY); |
Willy Tarreau | 8293658 | 2007-11-30 15:20:09 +0100 | [diff] [blame] | 5907 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 5908 | if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_HTTP_CHK) { |
| 5909 | if (curproxy->options & PR_O_DISABLE404) { |
| 5910 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n", |
| 5911 | "disable-on-404", proxy_type_str(curproxy), curproxy->id); |
| 5912 | err_code |= ERR_WARN; |
| 5913 | curproxy->options &= ~PR_O_DISABLE404; |
| 5914 | } |
| 5915 | if (curproxy->options2 & PR_O2_CHK_SNDST) { |
| 5916 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n", |
| 5917 | "send-state", proxy_type_str(curproxy), curproxy->id); |
| 5918 | err_code |= ERR_WARN; |
| 5919 | curproxy->options &= ~PR_O2_CHK_SNDST; |
| 5920 | } |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 5921 | } |
| 5922 | |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5923 | /* if a default backend was specified, let's find it */ |
| 5924 | if (curproxy->defbe.name) { |
| 5925 | struct proxy *target; |
| 5926 | |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 5927 | target = findproxy_mode(curproxy->defbe.name, curproxy->mode, PR_CAP_BE); |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 5928 | if (!target) { |
| 5929 | Alert("Proxy '%s': unable to find required default_backend: '%s'.\n", |
| 5930 | curproxy->id, curproxy->defbe.name); |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5931 | cfgerr++; |
| 5932 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 5933 | Alert("Proxy '%s': loop detected for default_backend: '%s'.\n", |
| 5934 | curproxy->id, curproxy->defbe.name); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 5935 | cfgerr++; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5936 | } else { |
| 5937 | free(curproxy->defbe.name); |
| 5938 | curproxy->defbe.be = target; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 5939 | /* we force the backend to be present on at least all of |
| 5940 | * the frontend's processes. |
| 5941 | */ |
| 5942 | target->bind_proc = curproxy->bind_proc ? |
| 5943 | (target->bind_proc | curproxy->bind_proc) : 0; |
Willy Tarreau | ff67813 | 2012-02-13 14:32:34 +0100 | [diff] [blame] | 5944 | |
| 5945 | /* Emit a warning if this proxy also has some servers */ |
| 5946 | if (curproxy->srv) { |
| 5947 | Warning("In proxy '%s', the 'default_backend' rule always has precedence over the servers, which will never be used.\n", |
| 5948 | curproxy->id); |
| 5949 | err_code |= ERR_WARN; |
| 5950 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5951 | } |
| 5952 | } |
| 5953 | |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5954 | /* find the target proxy in setbe */ |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5955 | if (curproxy->mode == PR_MODE_HTTP && curproxy->req_exp != NULL) { |
| 5956 | /* map jump target for ACT_SETBE in req_rep chain */ |
| 5957 | struct hdr_exp *exp; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5958 | for (exp = curproxy->req_exp; exp != NULL; exp = exp->next) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 5959 | struct proxy *target; |
| 5960 | |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5961 | if (exp->action != ACT_SETBE) |
| 5962 | continue; |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 5963 | |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 5964 | target = findproxy_mode(exp->replace, PR_MODE_HTTP, PR_CAP_BE); |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 5965 | if (!target) { |
| 5966 | Alert("Proxy '%s': unable to find required setbe: '%s'.\n", |
| 5967 | curproxy->id, exp->replace); |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5968 | cfgerr++; |
| 5969 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 5970 | Alert("Proxy '%s': loop detected for setbe: '%s'.\n", |
| 5971 | curproxy->id, exp->replace); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5972 | cfgerr++; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5973 | } else { |
| 5974 | free((void *)exp->replace); |
| 5975 | exp->replace = (const char *)target; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 5976 | /* we force the backend to be present on at least all of |
| 5977 | * the frontend's processes. |
| 5978 | */ |
| 5979 | target->bind_proc = curproxy->bind_proc ? |
| 5980 | (target->bind_proc | curproxy->bind_proc) : 0; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5981 | } |
| 5982 | } |
| 5983 | } |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 5984 | |
| 5985 | /* find the target proxy for 'use_backend' rules */ |
| 5986 | list_for_each_entry(rule, &curproxy->switching_rules, list) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 5987 | struct proxy *target; |
| 5988 | |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 5989 | target = findproxy_mode(rule->be.name, curproxy->mode, PR_CAP_BE); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 5990 | |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 5991 | if (!target) { |
| 5992 | Alert("Proxy '%s': unable to find required use_backend: '%s'.\n", |
| 5993 | curproxy->id, rule->be.name); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 5994 | cfgerr++; |
| 5995 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 5996 | Alert("Proxy '%s': loop detected for use_backend: '%s'.\n", |
| 5997 | curproxy->id, rule->be.name); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 5998 | cfgerr++; |
| 5999 | } else { |
| 6000 | free((void *)rule->be.name); |
| 6001 | rule->be.backend = target; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 6002 | /* we force the backend to be present on at least all of |
| 6003 | * the frontend's processes. |
| 6004 | */ |
| 6005 | target->bind_proc = curproxy->bind_proc ? |
| 6006 | (target->bind_proc | curproxy->bind_proc) : 0; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6007 | } |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 6008 | } |
| 6009 | |
| 6010 | /* find the target proxy for 'use_backend' rules */ |
| 6011 | list_for_each_entry(srule, &curproxy->server_rules, list) { |
| 6012 | struct server *target = findserver(curproxy, srule->srv.name); |
| 6013 | |
| 6014 | if (!target) { |
| 6015 | Alert("config : %s '%s' : unable to find server '%s' referenced in a 'use-server' rule.\n", |
| 6016 | proxy_type_str(curproxy), curproxy->id, srule->srv.name); |
| 6017 | cfgerr++; |
| 6018 | continue; |
| 6019 | } |
| 6020 | free((void *)srule->srv.name); |
| 6021 | srule->srv.ptr = target; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6022 | } |
| 6023 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6024 | /* find the target table for 'stick' rules */ |
| 6025 | list_for_each_entry(mrule, &curproxy->sticking_rules, list) { |
| 6026 | struct proxy *target; |
| 6027 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 6028 | curproxy->be_req_ana |= AN_REQ_STICKING_RULES; |
| 6029 | if (mrule->flags & STK_IS_STORE) |
| 6030 | curproxy->be_rsp_ana |= AN_RES_STORE_RULES; |
| 6031 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6032 | if (mrule->table.name) |
Willy Tarreau | c00cdc2 | 2010-06-06 16:48:26 +0200 | [diff] [blame] | 6033 | target = findproxy(mrule->table.name, 0); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6034 | else |
| 6035 | target = curproxy; |
| 6036 | |
| 6037 | if (!target) { |
| 6038 | Alert("Proxy '%s': unable to find stick-table '%s'.\n", |
| 6039 | curproxy->id, mrule->table.name); |
| 6040 | cfgerr++; |
| 6041 | } |
| 6042 | else if (target->table.size == 0) { |
| 6043 | Alert("Proxy '%s': stick-table '%s' used but not configured.\n", |
| 6044 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 6045 | cfgerr++; |
| 6046 | } |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 6047 | else if (!stktable_compatible_sample(mrule->expr, target->table.type)) { |
| 6048 | 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] | 6049 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 6050 | cfgerr++; |
| 6051 | } |
| 6052 | else { |
| 6053 | free((void *)mrule->table.name); |
| 6054 | mrule->table.t = &(target->table); |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 6055 | stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID, NULL); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6056 | } |
| 6057 | } |
| 6058 | |
| 6059 | /* find the target table for 'store response' rules */ |
| 6060 | list_for_each_entry(mrule, &curproxy->storersp_rules, list) { |
| 6061 | struct proxy *target; |
| 6062 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 6063 | curproxy->be_rsp_ana |= AN_RES_STORE_RULES; |
| 6064 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6065 | if (mrule->table.name) |
Willy Tarreau | c00cdc2 | 2010-06-06 16:48:26 +0200 | [diff] [blame] | 6066 | target = findproxy(mrule->table.name, 0); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6067 | else |
| 6068 | target = curproxy; |
| 6069 | |
| 6070 | if (!target) { |
| 6071 | Alert("Proxy '%s': unable to find store table '%s'.\n", |
| 6072 | curproxy->id, mrule->table.name); |
| 6073 | cfgerr++; |
| 6074 | } |
| 6075 | else if (target->table.size == 0) { |
| 6076 | Alert("Proxy '%s': stick-table '%s' used but not configured.\n", |
| 6077 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 6078 | cfgerr++; |
| 6079 | } |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 6080 | else if (!stktable_compatible_sample(mrule->expr, target->table.type)) { |
| 6081 | 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] | 6082 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 6083 | cfgerr++; |
| 6084 | } |
| 6085 | else { |
| 6086 | free((void *)mrule->table.name); |
| 6087 | mrule->table.t = &(target->table); |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 6088 | stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID, NULL); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6089 | } |
| 6090 | } |
| 6091 | |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 6092 | /* find the target table for 'tcp-request' layer 4 rules */ |
| 6093 | list_for_each_entry(trule, &curproxy->tcp_req.l4_rules, list) { |
| 6094 | struct proxy *target; |
| 6095 | |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6096 | 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] | 6097 | continue; |
| 6098 | |
| 6099 | if (trule->act_prm.trk_ctr.table.n) |
| 6100 | target = findproxy(trule->act_prm.trk_ctr.table.n, 0); |
| 6101 | else |
| 6102 | target = curproxy; |
| 6103 | |
| 6104 | if (!target) { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6105 | Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n", |
| 6106 | curproxy->id, trule->act_prm.trk_ctr.table.n, |
| 6107 | trule->action == TCP_ACT_TRK_SC1 ? 1 : 2); |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 6108 | cfgerr++; |
| 6109 | } |
| 6110 | else if (target->table.size == 0) { |
| 6111 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
| 6112 | curproxy->id, trule->act_prm.trk_ctr.table.n ? trule->act_prm.trk_ctr.table.n : curproxy->id); |
| 6113 | cfgerr++; |
| 6114 | } |
| 6115 | else if (trule->act_prm.trk_ctr.type != target->table.type) { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6116 | 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] | 6117 | curproxy->id, trule->act_prm.trk_ctr.table.n ? trule->act_prm.trk_ctr.table.n : curproxy->id); |
| 6118 | cfgerr++; |
| 6119 | } |
| 6120 | else { |
| 6121 | free(trule->act_prm.trk_ctr.table.n); |
| 6122 | trule->act_prm.trk_ctr.table.t = &target->table; |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6123 | /* 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] | 6124 | * to pass a list of counters to track and allocate them right here using |
| 6125 | * stktable_alloc_data_type(). |
| 6126 | */ |
| 6127 | } |
| 6128 | } |
| 6129 | |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 6130 | /* find the target table for 'tcp-request' layer 6 rules */ |
| 6131 | list_for_each_entry(trule, &curproxy->tcp_req.inspect_rules, list) { |
| 6132 | struct proxy *target; |
| 6133 | |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6134 | 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] | 6135 | continue; |
| 6136 | |
| 6137 | if (trule->act_prm.trk_ctr.table.n) |
| 6138 | target = findproxy(trule->act_prm.trk_ctr.table.n, 0); |
| 6139 | else |
| 6140 | target = curproxy; |
| 6141 | |
| 6142 | if (!target) { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6143 | Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n", |
| 6144 | curproxy->id, trule->act_prm.trk_ctr.table.n, |
| 6145 | trule->action == TCP_ACT_TRK_SC1 ? 1 : 2); |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 6146 | cfgerr++; |
| 6147 | } |
| 6148 | else if (target->table.size == 0) { |
| 6149 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
| 6150 | curproxy->id, trule->act_prm.trk_ctr.table.n ? trule->act_prm.trk_ctr.table.n : curproxy->id); |
| 6151 | cfgerr++; |
| 6152 | } |
| 6153 | else if (trule->act_prm.trk_ctr.type != target->table.type) { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6154 | 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] | 6155 | curproxy->id, trule->act_prm.trk_ctr.table.n ? trule->act_prm.trk_ctr.table.n : curproxy->id); |
| 6156 | cfgerr++; |
| 6157 | } |
| 6158 | else { |
| 6159 | free(trule->act_prm.trk_ctr.table.n); |
| 6160 | trule->act_prm.trk_ctr.table.t = &target->table; |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6161 | /* 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] | 6162 | * to pass a list of counters to track and allocate them right here using |
| 6163 | * stktable_alloc_data_type(). |
| 6164 | */ |
| 6165 | } |
| 6166 | } |
| 6167 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 6168 | if (curproxy->table.peers.name) { |
| 6169 | struct peers *curpeers = peers; |
| 6170 | |
| 6171 | for (curpeers = peers; curpeers; curpeers = curpeers->next) { |
| 6172 | if (strcmp(curpeers->id, curproxy->table.peers.name) == 0) { |
| 6173 | free((void *)curproxy->table.peers.name); |
| 6174 | curproxy->table.peers.p = peers; |
| 6175 | break; |
| 6176 | } |
| 6177 | } |
| 6178 | |
| 6179 | if (!curpeers) { |
| 6180 | Alert("Proxy '%s': unable to find sync peers '%s'.\n", |
| 6181 | curproxy->id, curproxy->table.peers.name); |
Willy Tarreau | d66bf96 | 2011-10-28 14:16:49 +0200 | [diff] [blame] | 6182 | free((void *)curproxy->table.peers.name); |
| 6183 | curproxy->table.peers.p = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 6184 | cfgerr++; |
| 6185 | } |
| 6186 | else if (!curpeers->peers_fe) { |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 6187 | Alert("Proxy '%s': unable to find local peer '%s' in peers section '%s'.\n", |
| 6188 | curproxy->id, localpeer, curpeers->id); |
Willy Tarreau | d66bf96 | 2011-10-28 14:16:49 +0200 | [diff] [blame] | 6189 | curproxy->table.peers.p = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 6190 | cfgerr++; |
| 6191 | } |
| 6192 | } |
| 6193 | |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 6194 | if (curproxy->uri_auth && !(curproxy->uri_auth->flags & ST_CONVDONE) && |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 6195 | !LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) && |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6196 | (curproxy->uri_auth->userlist || curproxy->uri_auth->auth_realm )) { |
| 6197 | Alert("%s '%s': stats 'auth'/'realm' and 'http-request' can't be used at the same time.\n", |
| 6198 | "proxy", curproxy->id); |
| 6199 | cfgerr++; |
| 6200 | goto out_uri_auth_compat; |
| 6201 | } |
| 6202 | |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 6203 | 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] | 6204 | const char *uri_auth_compat_req[10]; |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 6205 | struct http_req_rule *rule; |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6206 | int i = 0; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6207 | |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6208 | /* build the ACL condition from scratch. We're relying on anonymous ACLs for that */ |
| 6209 | uri_auth_compat_req[i++] = "auth"; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6210 | |
| 6211 | if (curproxy->uri_auth->auth_realm) { |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6212 | uri_auth_compat_req[i++] = "realm"; |
| 6213 | uri_auth_compat_req[i++] = curproxy->uri_auth->auth_realm; |
| 6214 | } |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6215 | |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6216 | uri_auth_compat_req[i++] = "unless"; |
| 6217 | uri_auth_compat_req[i++] = "{"; |
| 6218 | uri_auth_compat_req[i++] = "http_auth(.internal-stats-userlist)"; |
| 6219 | uri_auth_compat_req[i++] = "}"; |
| 6220 | uri_auth_compat_req[i++] = ""; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6221 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 6222 | rule = parse_http_req_cond(uri_auth_compat_req, "internal-stats-auth-compat", 0, curproxy); |
| 6223 | if (!rule) { |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6224 | cfgerr++; |
| 6225 | break; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6226 | } |
| 6227 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 6228 | LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list); |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6229 | |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6230 | if (curproxy->uri_auth->auth_realm) { |
| 6231 | free(curproxy->uri_auth->auth_realm); |
| 6232 | curproxy->uri_auth->auth_realm = NULL; |
| 6233 | } |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 6234 | |
| 6235 | curproxy->uri_auth->flags |= ST_CONVDONE; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6236 | } |
| 6237 | out_uri_auth_compat: |
| 6238 | |
Krzysztof Piotr Oledzki | f9423ae | 2010-01-29 19:26:18 +0100 | [diff] [blame] | 6239 | cfgerr += acl_find_targets(curproxy); |
| 6240 | |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 6241 | if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) && |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6242 | (((curproxy->cap & PR_CAP_FE) && !curproxy->timeout.client) || |
Willy Tarreau | d825eef | 2007-05-12 22:35:00 +0200 | [diff] [blame] | 6243 | ((curproxy->cap & PR_CAP_BE) && (curproxy->srv) && |
Willy Tarreau | ce887fd | 2012-05-12 12:50:00 +0200 | [diff] [blame] | 6244 | (!curproxy->timeout.connect || |
| 6245 | (!curproxy->timeout.server && (curproxy->mode == PR_MODE_HTTP || !curproxy->timeout.tunnel)))))) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6246 | Warning("config : missing timeouts for %s '%s'.\n" |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 6247 | " | While not properly invalid, you will certainly encounter various problems\n" |
| 6248 | " | 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] | 6249 | " | timeouts are set to a non-zero value: 'client', 'connect', 'server'.\n", |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6250 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6251 | err_code |= ERR_WARN; |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 6252 | } |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 6253 | |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6254 | /* Historically, the tarpit and queue timeouts were inherited from contimeout. |
| 6255 | * We must still support older configurations, so let's find out whether those |
| 6256 | * parameters have been set or must be copied from contimeouts. |
| 6257 | */ |
| 6258 | if (curproxy != &defproxy) { |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6259 | if (!curproxy->timeout.tarpit || |
| 6260 | curproxy->timeout.tarpit == defproxy.timeout.tarpit) { |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6261 | /* tarpit timeout not set. We search in the following order: |
| 6262 | * default.tarpit, curr.connect, default.connect. |
| 6263 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6264 | if (defproxy.timeout.tarpit) |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6265 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6266 | else if (curproxy->timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6267 | curproxy->timeout.tarpit = curproxy->timeout.connect; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6268 | else if (defproxy.timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6269 | curproxy->timeout.tarpit = defproxy.timeout.connect; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6270 | } |
| 6271 | if ((curproxy->cap & PR_CAP_BE) && |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6272 | (!curproxy->timeout.queue || |
| 6273 | curproxy->timeout.queue == defproxy.timeout.queue)) { |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6274 | /* queue timeout not set. We search in the following order: |
| 6275 | * default.queue, curr.connect, default.connect. |
| 6276 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6277 | if (defproxy.timeout.queue) |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6278 | curproxy->timeout.queue = defproxy.timeout.queue; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6279 | else if (curproxy->timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6280 | curproxy->timeout.queue = curproxy->timeout.connect; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6281 | else if (defproxy.timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6282 | curproxy->timeout.queue = defproxy.timeout.connect; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6283 | } |
| 6284 | } |
| 6285 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 6286 | if ((curproxy->options2 & PR_O2_CHK_ANY) == PR_O2_SSL3_CHK) { |
Willy Tarreau | 137325d | 2010-02-01 16:38:17 +0100 | [diff] [blame] | 6287 | curproxy->check_len = sizeof(sslv3_client_hello_pkt) - 1; |
| 6288 | curproxy->check_req = (char *)malloc(curproxy->check_len); |
| 6289 | memcpy(curproxy->check_req, sslv3_client_hello_pkt, curproxy->check_len); |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 6290 | } |
| 6291 | |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 6292 | /* The small pools required for the capture lists */ |
Willy Tarreau | 9a54e13 | 2012-03-24 08:33:05 +0100 | [diff] [blame] | 6293 | if (curproxy->nb_req_cap) { |
| 6294 | if (curproxy->mode == PR_MODE_HTTP) { |
| 6295 | curproxy->req_cap_pool = create_pool("ptrcap", |
| 6296 | curproxy->nb_req_cap * sizeof(char *), |
| 6297 | MEM_F_SHARED); |
| 6298 | } else { |
| 6299 | Warning("config : 'capture request header' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6300 | proxy_type_str(curproxy), curproxy->id); |
| 6301 | err_code |= ERR_WARN; |
| 6302 | curproxy->to_log &= ~LW_REQHDR; |
| 6303 | curproxy->nb_req_cap = 0; |
| 6304 | } |
| 6305 | } |
| 6306 | |
| 6307 | if (curproxy->nb_rsp_cap) { |
| 6308 | if (curproxy->mode == PR_MODE_HTTP) { |
| 6309 | curproxy->rsp_cap_pool = create_pool("ptrcap", |
| 6310 | curproxy->nb_rsp_cap * sizeof(char *), |
| 6311 | MEM_F_SHARED); |
| 6312 | } else { |
| 6313 | Warning("config : 'capture response header' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6314 | proxy_type_str(curproxy), curproxy->id); |
| 6315 | err_code |= ERR_WARN; |
| 6316 | curproxy->to_log &= ~LW_REQHDR; |
| 6317 | curproxy->nb_rsp_cap = 0; |
| 6318 | } |
| 6319 | } |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 6320 | |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 6321 | /* compile the log format */ |
Willy Tarreau | 99a7ca2 | 2012-05-31 19:39:23 +0200 | [diff] [blame] | 6322 | if (!(curproxy->cap & PR_CAP_FE)) { |
| 6323 | if (curproxy->logformat_string != default_http_log_format && |
| 6324 | curproxy->logformat_string != default_tcp_log_format && |
| 6325 | curproxy->logformat_string != clf_http_log_format) |
| 6326 | free(curproxy->logformat_string); |
| 6327 | curproxy->logformat_string = NULL; |
| 6328 | } |
| 6329 | |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 6330 | if (curproxy->logformat_string) |
| 6331 | parse_logformat_string(curproxy->logformat_string, curproxy, &curproxy->logformat, curproxy->mode); |
| 6332 | |
| 6333 | if (curproxy->uniqueid_format_string) |
| 6334 | parse_logformat_string(curproxy->uniqueid_format_string, curproxy, &curproxy->format_unique_id, PR_MODE_HTTP); |
| 6335 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6336 | /* first, we will invert the servers list order */ |
| 6337 | newsrv = NULL; |
| 6338 | while (curproxy->srv) { |
| 6339 | struct server *next; |
| 6340 | |
| 6341 | next = curproxy->srv->next; |
| 6342 | curproxy->srv->next = newsrv; |
| 6343 | newsrv = curproxy->srv; |
| 6344 | if (!next) |
| 6345 | break; |
| 6346 | curproxy->srv = next; |
| 6347 | } |
| 6348 | |
Willy Tarreau | dd70165 | 2010-05-25 23:03:02 +0200 | [diff] [blame] | 6349 | /* assign automatic UIDs to servers which don't have one yet */ |
| 6350 | next_id = 1; |
| 6351 | newsrv = curproxy->srv; |
| 6352 | while (newsrv != NULL) { |
| 6353 | if (!newsrv->puid) { |
| 6354 | /* server ID not set, use automatic numbering with first |
| 6355 | * spare entry starting with next_svid. |
| 6356 | */ |
| 6357 | next_id = get_next_id(&curproxy->conf.used_server_id, next_id); |
| 6358 | newsrv->conf.id.key = newsrv->puid = next_id; |
| 6359 | eb32_insert(&curproxy->conf.used_server_id, &newsrv->conf.id); |
| 6360 | } |
| 6361 | next_id++; |
| 6362 | newsrv = newsrv->next; |
| 6363 | } |
| 6364 | |
Willy Tarreau | 2069704 | 2007-11-15 23:26:18 +0100 | [diff] [blame] | 6365 | curproxy->lbprm.wmult = 1; /* default weight multiplier */ |
Willy Tarreau | 5dc2fa6 | 2007-11-19 19:10:18 +0100 | [diff] [blame] | 6366 | curproxy->lbprm.wdiv = 1; /* default weight divider */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6367 | |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 6368 | /* |
| 6369 | * If this server supports a maxconn parameter, it needs a dedicated |
| 6370 | * tasks to fill the emptied slots when a connection leaves. |
| 6371 | * Also, resolve deferred tracking dependency if needed. |
| 6372 | */ |
| 6373 | newsrv = curproxy->srv; |
| 6374 | while (newsrv != NULL) { |
| 6375 | if (newsrv->minconn > newsrv->maxconn) { |
| 6376 | /* Only 'minconn' was specified, or it was higher than or equal |
| 6377 | * to 'maxconn'. Let's turn this into maxconn and clean it, as |
| 6378 | * this will avoid further useless expensive computations. |
| 6379 | */ |
| 6380 | newsrv->maxconn = newsrv->minconn; |
| 6381 | } else if (newsrv->maxconn && !newsrv->minconn) { |
| 6382 | /* minconn was not specified, so we set it to maxconn */ |
| 6383 | newsrv->minconn = newsrv->maxconn; |
| 6384 | } |
| 6385 | |
Emeric Brun | 01f8e2f | 2012-05-18 16:02:00 +0200 | [diff] [blame] | 6386 | #ifdef USE_OPENSSL |
| 6387 | #ifndef SSL_OP_NO_COMPRESSION /* needs OpenSSL >= 0.9.9 */ |
| 6388 | #define SSL_OP_NO_COMPRESSION 0 |
| 6389 | #endif |
| 6390 | #ifndef SSL_MODE_RELEASE_BUFFERS /* needs OpenSSL >= 1.0.0 */ |
| 6391 | #define SSL_MODE_RELEASE_BUFFERS 0 |
| 6392 | #endif |
| 6393 | #ifndef SSL_OP_NO_COMPRESSION /* needs OpenSSL >= 0.9.9 */ |
| 6394 | #define SSL_OP_NO_COMPRESSION 0 |
| 6395 | #endif |
Emeric Brun | c0ff492 | 2012-09-28 19:37:02 +0200 | [diff] [blame] | 6396 | #ifndef SSL_OP_NO_TLSv1_1 /* needs OpenSSL >= 1.0.1 */ |
| 6397 | #define SSL_OP_NO_TLSv1_1 0 |
| 6398 | #endif |
| 6399 | #ifndef SSL_OP_NO_TLSv1_2 /* needs OpenSSL >= 1.0.1 */ |
| 6400 | #define SSL_OP_NO_TLSv1_2 0 |
| 6401 | #endif |
Willy Tarreau | f4288ee | 2012-09-28 18:13:10 +0200 | [diff] [blame] | 6402 | if (newsrv->use_ssl || newsrv->check.use_ssl) { |
Emeric Brun | 01f8e2f | 2012-05-18 16:02:00 +0200 | [diff] [blame] | 6403 | int ssloptions = |
| 6404 | SSL_OP_ALL | /* all known workarounds for bugs */ |
| 6405 | SSL_OP_NO_SSLv2 | |
| 6406 | SSL_OP_NO_COMPRESSION; |
| 6407 | int sslmode = |
| 6408 | SSL_MODE_ENABLE_PARTIAL_WRITE | |
| 6409 | SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER | |
| 6410 | SSL_MODE_RELEASE_BUFFERS; |
| 6411 | |
| 6412 | /* Initiate SSL context for current server */ |
| 6413 | newsrv->ssl_ctx.reused_sess = NULL; |
Willy Tarreau | f4288ee | 2012-09-28 18:13:10 +0200 | [diff] [blame] | 6414 | if (newsrv->use_ssl) |
| 6415 | newsrv->xprt = &ssl_sock; |
Willy Tarreau | f150317 | 2012-09-28 19:39:36 +0200 | [diff] [blame] | 6416 | if (newsrv->check.use_ssl) |
| 6417 | newsrv->check.xprt = &ssl_sock; |
Emeric Brun | 01f8e2f | 2012-05-18 16:02:00 +0200 | [diff] [blame] | 6418 | newsrv->ssl_ctx.ctx = SSL_CTX_new(SSLv23_client_method()); |
| 6419 | if(!newsrv->ssl_ctx.ctx) { |
| 6420 | |
| 6421 | Alert("config : %s '%s', server '%s': unable to allocate ssl context.\n", |
| 6422 | proxy_type_str(curproxy), curproxy->id, |
| 6423 | newsrv->id); |
| 6424 | cfgerr++; |
| 6425 | goto next_srv; |
| 6426 | } |
| 6427 | |
Emeric Brun | 8967549 | 2012-10-05 13:48:26 +0200 | [diff] [blame] | 6428 | if (newsrv->ssl_ctx.options & SRV_SSL_O_NO_SSLV3) |
Willy Tarreau | c230b8b | 2012-09-03 23:55:16 +0200 | [diff] [blame] | 6429 | ssloptions |= SSL_OP_NO_SSLv3; |
Emeric Brun | 8967549 | 2012-10-05 13:48:26 +0200 | [diff] [blame] | 6430 | if (newsrv->ssl_ctx.options & SRV_SSL_O_NO_TLSV10) |
Willy Tarreau | c230b8b | 2012-09-03 23:55:16 +0200 | [diff] [blame] | 6431 | ssloptions |= SSL_OP_NO_TLSv1; |
Emeric Brun | 8967549 | 2012-10-05 13:48:26 +0200 | [diff] [blame] | 6432 | if (newsrv->ssl_ctx.options & SRV_SSL_O_NO_TLSV11) |
Emeric Brun | c0ff492 | 2012-09-28 19:37:02 +0200 | [diff] [blame] | 6433 | ssloptions |= SSL_OP_NO_TLSv1_1; |
Emeric Brun | 8967549 | 2012-10-05 13:48:26 +0200 | [diff] [blame] | 6434 | if (newsrv->ssl_ctx.options & SRV_SSL_O_NO_TLSV12) |
Emeric Brun | c0ff492 | 2012-09-28 19:37:02 +0200 | [diff] [blame] | 6435 | ssloptions |= SSL_OP_NO_TLSv1_2; |
Emeric Brun | 8694b9a | 2012-10-05 14:39:07 +0200 | [diff] [blame] | 6436 | if (newsrv->ssl_ctx.options & SRV_SSL_O_USE_SSLV3) |
| 6437 | SSL_CTX_set_ssl_version(newsrv->ssl_ctx.ctx, SSLv3_client_method()); |
| 6438 | if (newsrv->ssl_ctx.options & SRV_SSL_O_USE_TLSV10) |
| 6439 | SSL_CTX_set_ssl_version(newsrv->ssl_ctx.ctx, TLSv1_client_method()); |
| 6440 | #if SSL_OP_NO_TLSv1_1 |
| 6441 | if (newsrv->ssl_ctx.options & SRV_SSL_O_USE_TLSV11) |
| 6442 | SSL_CTX_set_ssl_version(newsrv->ssl_ctx.ctx, TLSv1_1_client_method()); |
| 6443 | #endif |
| 6444 | #if SSL_OP_NO_TLSv1_2 |
| 6445 | if (newsrv->ssl_ctx.options & SRV_SSL_O_USE_TLSV12) |
| 6446 | SSL_CTX_set_ssl_version(newsrv->ssl_ctx.ctx, TLSv1_2_client_method()); |
| 6447 | #endif |
| 6448 | |
Emeric Brun | 01f8e2f | 2012-05-18 16:02:00 +0200 | [diff] [blame] | 6449 | SSL_CTX_set_options(newsrv->ssl_ctx.ctx, ssloptions); |
| 6450 | SSL_CTX_set_mode(newsrv->ssl_ctx.ctx, sslmode); |
| 6451 | SSL_CTX_set_verify(newsrv->ssl_ctx.ctx, SSL_VERIFY_NONE, NULL); |
| 6452 | SSL_CTX_set_session_cache_mode(newsrv->ssl_ctx.ctx, SSL_SESS_CACHE_OFF); |
Willy Tarreau | d7aacbf | 2012-09-03 23:34:19 +0200 | [diff] [blame] | 6453 | if (newsrv->ssl_ctx.ciphers && |
| 6454 | !SSL_CTX_set_cipher_list(newsrv->ssl_ctx.ctx, newsrv->ssl_ctx.ciphers)) { |
| 6455 | Alert("Proxy '%s', server '%s' [%s:%d] : unable to set SSL cipher list to '%s'.\n", |
| 6456 | curproxy->id, newsrv->id, |
| 6457 | newsrv->conf.file, newsrv->conf.line, newsrv->ssl_ctx.ciphers); |
| 6458 | cfgerr++; |
| 6459 | goto next_srv; |
| 6460 | } |
Emeric Brun | 01f8e2f | 2012-05-18 16:02:00 +0200 | [diff] [blame] | 6461 | } |
| 6462 | #endif /* USE_OPENSSL */ |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 6463 | if (newsrv->trackit) { |
| 6464 | struct proxy *px; |
| 6465 | struct server *srv; |
| 6466 | char *pname, *sname; |
| 6467 | |
| 6468 | pname = newsrv->trackit; |
| 6469 | sname = strrchr(pname, '/'); |
| 6470 | |
| 6471 | if (sname) |
| 6472 | *sname++ = '\0'; |
| 6473 | else { |
| 6474 | sname = pname; |
| 6475 | pname = NULL; |
| 6476 | } |
| 6477 | |
| 6478 | if (pname) { |
| 6479 | px = findproxy(pname, PR_CAP_BE); |
| 6480 | if (!px) { |
| 6481 | Alert("config : %s '%s', server '%s': unable to find required proxy '%s' for tracking.\n", |
| 6482 | proxy_type_str(curproxy), curproxy->id, |
| 6483 | newsrv->id, pname); |
| 6484 | cfgerr++; |
| 6485 | goto next_srv; |
| 6486 | } |
| 6487 | } else |
| 6488 | px = curproxy; |
| 6489 | |
| 6490 | srv = findserver(px, sname); |
| 6491 | if (!srv) { |
| 6492 | Alert("config : %s '%s', server '%s': unable to find required server '%s' for tracking.\n", |
| 6493 | proxy_type_str(curproxy), curproxy->id, |
| 6494 | newsrv->id, sname); |
| 6495 | cfgerr++; |
| 6496 | goto next_srv; |
| 6497 | } |
| 6498 | |
| 6499 | if (!(srv->state & SRV_CHECKED)) { |
| 6500 | Alert("config : %s '%s', server '%s': unable to use %s/%s for " |
| 6501 | "tracking as it does not have checks enabled.\n", |
| 6502 | proxy_type_str(curproxy), curproxy->id, |
| 6503 | newsrv->id, px->id, srv->id); |
| 6504 | cfgerr++; |
| 6505 | goto next_srv; |
| 6506 | } |
| 6507 | |
| 6508 | if (curproxy != px && |
| 6509 | (curproxy->options & PR_O_DISABLE404) != (px->options & PR_O_DISABLE404)) { |
| 6510 | Alert("config : %s '%s', server '%s': unable to use %s/%s for" |
| 6511 | "tracking: disable-on-404 option inconsistency.\n", |
| 6512 | proxy_type_str(curproxy), curproxy->id, |
| 6513 | newsrv->id, px->id, srv->id); |
| 6514 | cfgerr++; |
| 6515 | goto next_srv; |
| 6516 | } |
| 6517 | |
| 6518 | /* if the other server is forced disabled, we have to do the same here */ |
| 6519 | if (srv->state & SRV_MAINTAIN) { |
| 6520 | newsrv->state |= SRV_MAINTAIN; |
| 6521 | newsrv->state &= ~SRV_RUNNING; |
| 6522 | newsrv->health = 0; |
| 6523 | } |
| 6524 | |
| 6525 | newsrv->track = srv; |
| 6526 | newsrv->tracknext = srv->tracknext; |
| 6527 | srv->tracknext = newsrv; |
| 6528 | |
| 6529 | free(newsrv->trackit); |
| 6530 | newsrv->trackit = NULL; |
| 6531 | } |
| 6532 | next_srv: |
| 6533 | newsrv = newsrv->next; |
| 6534 | } |
| 6535 | |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6536 | /* We have to initialize the server lookup mechanism depending |
| 6537 | * on what LB algorithm was choosen. |
| 6538 | */ |
| 6539 | |
| 6540 | curproxy->lbprm.algo &= ~(BE_LB_LKUP | BE_LB_PROP_DYN); |
| 6541 | switch (curproxy->lbprm.algo & BE_LB_KIND) { |
| 6542 | case BE_LB_KIND_RR: |
Willy Tarreau | 9757a38 | 2009-10-03 12:56:50 +0200 | [diff] [blame] | 6543 | if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_RR_STATIC) { |
| 6544 | curproxy->lbprm.algo |= BE_LB_LKUP_MAP; |
| 6545 | init_server_map(curproxy); |
| 6546 | } else { |
| 6547 | curproxy->lbprm.algo |= BE_LB_LKUP_RRTREE | BE_LB_PROP_DYN; |
| 6548 | fwrr_init_server_groups(curproxy); |
| 6549 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6550 | break; |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 6551 | |
Willy Tarreau | 3ebb116 | 2012-02-13 16:57:44 +0100 | [diff] [blame] | 6552 | case BE_LB_KIND_CB: |
Willy Tarreau | f09c660 | 2012-02-13 17:12:08 +0100 | [diff] [blame] | 6553 | if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_CB_LC) { |
| 6554 | curproxy->lbprm.algo |= BE_LB_LKUP_LCTREE | BE_LB_PROP_DYN; |
| 6555 | fwlc_init_server_tree(curproxy); |
| 6556 | } else { |
| 6557 | curproxy->lbprm.algo |= BE_LB_LKUP_FSTREE | BE_LB_PROP_DYN; |
| 6558 | fas_init_server_tree(curproxy); |
| 6559 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6560 | break; |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 6561 | |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6562 | case BE_LB_KIND_HI: |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 6563 | if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS) { |
| 6564 | curproxy->lbprm.algo |= BE_LB_LKUP_CHTREE | BE_LB_PROP_DYN; |
| 6565 | chash_init_server_tree(curproxy); |
| 6566 | } else { |
| 6567 | curproxy->lbprm.algo |= BE_LB_LKUP_MAP; |
| 6568 | init_server_map(curproxy); |
| 6569 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6570 | break; |
| 6571 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6572 | |
| 6573 | if (curproxy->options & PR_O_LOGASAP) |
| 6574 | curproxy->to_log &= ~LW_BYTES; |
| 6575 | |
Willy Tarreau | e7ded1f | 2009-08-09 10:11:45 +0200 | [diff] [blame] | 6576 | if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) && |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6577 | (curproxy->cap & PR_CAP_FE) && curproxy->to_log && LIST_ISEMPTY(&curproxy->logsrvs)) { |
Willy Tarreau | e7ded1f | 2009-08-09 10:11:45 +0200 | [diff] [blame] | 6578 | Warning("config : log format ignored for %s '%s' since it has no log address.\n", |
| 6579 | proxy_type_str(curproxy), curproxy->id); |
| 6580 | err_code |= ERR_WARN; |
| 6581 | } |
| 6582 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 6583 | if (curproxy->mode != PR_MODE_HTTP) { |
| 6584 | int optnum; |
| 6585 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 6586 | if (curproxy->uri_auth) { |
| 6587 | Warning("config : 'stats' statement ignored for %s '%s' as it requires HTTP mode.\n", |
| 6588 | proxy_type_str(curproxy), curproxy->id); |
| 6589 | err_code |= ERR_WARN; |
| 6590 | curproxy->uri_auth = NULL; |
| 6591 | } |
| 6592 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 6593 | if (curproxy->options & (PR_O_FWDFOR | PR_O_FF_ALWAYS)) { |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 6594 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6595 | "forwardfor", proxy_type_str(curproxy), curproxy->id); |
| 6596 | err_code |= ERR_WARN; |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 6597 | curproxy->options &= ~(PR_O_FWDFOR | PR_O_FF_ALWAYS); |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 6598 | } |
| 6599 | |
| 6600 | if (curproxy->options & PR_O_ORGTO) { |
| 6601 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6602 | "originalto", proxy_type_str(curproxy), curproxy->id); |
| 6603 | err_code |= ERR_WARN; |
| 6604 | curproxy->options &= ~PR_O_ORGTO; |
| 6605 | } |
| 6606 | |
| 6607 | for (optnum = 0; cfg_opts[optnum].name; optnum++) { |
| 6608 | if (cfg_opts[optnum].mode == PR_MODE_HTTP && |
| 6609 | (curproxy->cap & cfg_opts[optnum].cap) && |
| 6610 | (curproxy->options & cfg_opts[optnum].val)) { |
| 6611 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6612 | cfg_opts[optnum].name, proxy_type_str(curproxy), curproxy->id); |
| 6613 | err_code |= ERR_WARN; |
| 6614 | curproxy->options &= ~cfg_opts[optnum].val; |
| 6615 | } |
| 6616 | } |
| 6617 | |
| 6618 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) { |
| 6619 | if (cfg_opts2[optnum].mode == PR_MODE_HTTP && |
| 6620 | (curproxy->cap & cfg_opts2[optnum].cap) && |
| 6621 | (curproxy->options2 & cfg_opts2[optnum].val)) { |
| 6622 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6623 | cfg_opts2[optnum].name, proxy_type_str(curproxy), curproxy->id); |
| 6624 | err_code |= ERR_WARN; |
| 6625 | curproxy->options2 &= ~cfg_opts2[optnum].val; |
| 6626 | } |
| 6627 | } |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6628 | |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 6629 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6630 | if (curproxy->bind_hdr_occ) { |
| 6631 | curproxy->bind_hdr_occ = 0; |
| 6632 | Warning("config : %s '%s' : ignoring use of header %s as source IP in non-HTTP mode.\n", |
| 6633 | proxy_type_str(curproxy), curproxy->id, curproxy->bind_hdr_name); |
| 6634 | err_code |= ERR_WARN; |
| 6635 | } |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 6636 | #endif |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 6637 | } |
| 6638 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6639 | /* |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 6640 | * ensure that we're not cross-dressing a TCP server into HTTP. |
| 6641 | */ |
| 6642 | newsrv = curproxy->srv; |
| 6643 | while (newsrv != NULL) { |
Willy Tarreau | 0cec331 | 2011-10-31 13:49:26 +0100 | [diff] [blame] | 6644 | if ((curproxy->mode != PR_MODE_HTTP) && newsrv->rdr_len) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6645 | Alert("config : %s '%s' : server cannot have cookie or redirect prefix in non-HTTP mode.\n", |
| 6646 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6647 | cfgerr++; |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 6648 | } |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6649 | |
Willy Tarreau | 0cec331 | 2011-10-31 13:49:26 +0100 | [diff] [blame] | 6650 | if ((curproxy->mode != PR_MODE_HTTP) && newsrv->cklen) { |
| 6651 | Warning("config : %s '%s' : ignoring cookie for server '%s' as HTTP mode is disabled.\n", |
| 6652 | proxy_type_str(curproxy), curproxy->id, newsrv->id); |
| 6653 | err_code |= ERR_WARN; |
| 6654 | } |
| 6655 | |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 6656 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6657 | if (curproxy->mode != PR_MODE_HTTP && newsrv->bind_hdr_occ) { |
| 6658 | newsrv->bind_hdr_occ = 0; |
| 6659 | Warning("config : %s '%s' : server %s cannot use header %s as source IP in non-HTTP mode.\n", |
| 6660 | proxy_type_str(curproxy), curproxy->id, newsrv->id, newsrv->bind_hdr_name); |
| 6661 | err_code |= ERR_WARN; |
| 6662 | } |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 6663 | #endif |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 6664 | newsrv = newsrv->next; |
| 6665 | } |
| 6666 | |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6667 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 6668 | if (!curproxy->accept) |
| 6669 | curproxy->accept = frontend_accept; |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 6670 | |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6671 | if (curproxy->tcp_req.inspect_delay || |
| 6672 | !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules)) |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 6673 | curproxy->fe_req_ana |= AN_REQ_INSPECT_FE; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6674 | |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 6675 | if (curproxy->mode == PR_MODE_HTTP) { |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6676 | 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] | 6677 | 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] | 6678 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6679 | |
| 6680 | /* both TCP and HTTP must check switching rules */ |
| 6681 | curproxy->fe_req_ana |= AN_REQ_SWITCHING_RULES; |
| 6682 | } |
| 6683 | |
| 6684 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 6685 | if (curproxy->tcp_req.inspect_delay || |
| 6686 | !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules)) |
| 6687 | curproxy->be_req_ana |= AN_REQ_INSPECT_BE; |
| 6688 | |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 6689 | if (!LIST_ISEMPTY(&curproxy->tcp_rep.inspect_rules)) |
| 6690 | curproxy->be_rsp_ana |= AN_RES_INSPECT; |
| 6691 | |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 6692 | if (curproxy->mode == PR_MODE_HTTP) { |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6693 | 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] | 6694 | 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] | 6695 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6696 | |
| 6697 | /* If the backend does requires RDP cookie persistence, we have to |
| 6698 | * enable the corresponding analyser. |
| 6699 | */ |
| 6700 | if (curproxy->options2 & PR_O2_RDPC_PRST) |
| 6701 | curproxy->be_req_ana |= AN_REQ_PRST_RDP_COOKIE; |
| 6702 | } |
| 6703 | |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 6704 | /* Configure SSL for each bind line. |
| 6705 | * Note: if configuration fails at some point, the ->ctx member |
| 6706 | * remains NULL so that listeners can later detach. |
| 6707 | */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6708 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
| 6709 | if (!bind_conf->is_ssl) |
| 6710 | continue; |
| 6711 | #ifdef USE_OPENSSL |
| 6712 | if (!bind_conf->default_ctx) { |
Emeric Brun | fc0421f | 2012-09-07 17:30:07 +0200 | [diff] [blame] | 6713 | Alert("Proxy '%s': no SSL certificate specified for bind '%s' at [%s:%d] (use 'crt').\n", |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6714 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 6715 | cfgerr++; |
| 6716 | continue; |
| 6717 | } |
| 6718 | |
Emeric Brun | 4b3091e | 2012-09-24 15:48:52 +0200 | [diff] [blame] | 6719 | if (shared_context_init(global.tune.sslcachesize, (global.nbproc > 1) ? 1 : 0) < 0) { |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 6720 | Alert("Unable to allocate SSL session cache.\n"); |
| 6721 | cfgerr++; |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 6722 | continue; |
| 6723 | } |
| 6724 | |
Emeric Brun | fc0421f | 2012-09-07 17:30:07 +0200 | [diff] [blame] | 6725 | /* initialize all certificate contexts */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6726 | cfgerr += ssl_sock_prepare_all_ctx(bind_conf, curproxy); |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 6727 | #endif /* USE_OPENSSL */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6728 | } |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 6729 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 6730 | /* adjust this proxy's listeners */ |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6731 | next_id = 1; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 6732 | list_for_each_entry(listener, &curproxy->conf.listeners, by_fe) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6733 | if (!listener->luid) { |
| 6734 | /* listener ID not set, use automatic numbering with first |
| 6735 | * spare entry starting with next_luid. |
| 6736 | */ |
| 6737 | next_id = get_next_id(&curproxy->conf.used_listener_id, next_id); |
| 6738 | listener->conf.id.key = listener->luid = next_id; |
| 6739 | eb32_insert(&curproxy->conf.used_listener_id, &listener->conf.id); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6740 | } |
Krzysztof Piotr Oledzki | df5cb9f | 2010-02-05 20:58:27 +0100 | [diff] [blame] | 6741 | next_id++; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6742 | |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 6743 | /* enable separate counters */ |
| 6744 | if (curproxy->options2 & PR_O2_SOCKSTAT) { |
| 6745 | listener->counters = (struct licounters *)calloc(1, sizeof(struct licounters)); |
| 6746 | if (!listener->name) { |
| 6747 | sprintf(trash, "sock-%d", listener->luid); |
| 6748 | listener->name = strdup(trash); |
| 6749 | } |
| 6750 | } |
Willy Tarreau | 81796be | 2012-09-22 19:11:47 +0200 | [diff] [blame] | 6751 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 6752 | if (curproxy->options & PR_O_TCP_NOLING) |
| 6753 | listener->options |= LI_O_NOLINGER; |
Willy Tarreau | 32368ce | 2012-09-06 11:10:55 +0200 | [diff] [blame] | 6754 | if (!listener->maxconn) |
| 6755 | listener->maxconn = curproxy->maxconn; |
| 6756 | if (!listener->backlog) |
| 6757 | listener->backlog = curproxy->backlog; |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6758 | listener->timeout = &curproxy->timeout.client; |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 6759 | listener->accept = session_accept; |
Willy Tarreau | 3bc1377 | 2008-12-07 11:50:35 +0100 | [diff] [blame] | 6760 | listener->handler = process_session; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6761 | listener->analysers |= curproxy->fe_req_ana; |
Willy Tarreau | 3bc1377 | 2008-12-07 11:50:35 +0100 | [diff] [blame] | 6762 | |
Willy Tarreau | a5c0ab2 | 2010-05-31 10:30:33 +0200 | [diff] [blame] | 6763 | if (!LIST_ISEMPTY(&curproxy->tcp_req.l4_rules)) |
| 6764 | listener->options |= LI_O_TCP_RULES; |
| 6765 | |
Willy Tarreau | de3041d | 2010-05-31 10:56:17 +0200 | [diff] [blame] | 6766 | if (curproxy->mon_mask.s_addr) |
| 6767 | listener->options |= LI_O_CHK_MONNET; |
| 6768 | |
Willy Tarreau | 9ea05a7 | 2009-06-14 12:07:01 +0200 | [diff] [blame] | 6769 | /* smart accept mode is automatic in HTTP mode */ |
| 6770 | if ((curproxy->options2 & PR_O2_SMARTACC) || |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6771 | ((curproxy->mode == PR_MODE_HTTP || listener->bind_conf->is_ssl) && |
Willy Tarreau | 9ea05a7 | 2009-06-14 12:07:01 +0200 | [diff] [blame] | 6772 | !(curproxy->no_options2 & PR_O2_SMARTACC))) |
| 6773 | listener->options |= LI_O_NOQUICKACK; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 6774 | } |
| 6775 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6776 | /* Release unused SSL configs */ |
| 6777 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
| 6778 | if (bind_conf->is_ssl) |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 6779 | continue; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6780 | #ifdef USE_OPENSSL |
| 6781 | ssl_sock_free_all_ctx(bind_conf); |
Emeric Brun | fb510ea | 2012-10-05 12:00:26 +0200 | [diff] [blame] | 6782 | free(bind_conf->ca_file); |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6783 | free(bind_conf->ciphers); |
Emeric Brun | 2b58d04 | 2012-09-20 17:10:03 +0200 | [diff] [blame] | 6784 | free(bind_conf->ecdhe); |
Emeric Brun | fb510ea | 2012-10-05 12:00:26 +0200 | [diff] [blame] | 6785 | free(bind_conf->crl_file); |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 6786 | #endif /* USE_OPENSSL */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6787 | } |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 6788 | |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 6789 | /* Check multi-process mode compatibility for the current proxy */ |
| 6790 | if (global.nbproc > 1) { |
| 6791 | int nbproc = 0; |
| 6792 | if (curproxy->bind_proc) { |
| 6793 | int proc; |
| 6794 | for (proc = 0; proc < global.nbproc; proc++) { |
| 6795 | if (curproxy->bind_proc & (1 << proc)) { |
| 6796 | nbproc++; |
| 6797 | } |
| 6798 | } |
| 6799 | } else { |
| 6800 | nbproc = global.nbproc; |
| 6801 | } |
| 6802 | if (curproxy->table.peers.name) { |
| 6803 | Alert("Proxy '%s': peers can't be used in multi-process mode (nbproc > 1).\n", |
| 6804 | curproxy->id); |
| 6805 | cfgerr++; |
| 6806 | } |
| 6807 | if (nbproc > 1) { |
| 6808 | if (curproxy->uri_auth) { |
| 6809 | Warning("Proxy '%s': in multi-process mode, stats will be limited to process assigned to the current request.\n", |
| 6810 | curproxy->id); |
| 6811 | if (!LIST_ISEMPTY(&curproxy->uri_auth->admin_rules)) { |
| 6812 | Warning("Proxy '%s': stats admin will not work correctly in multi-process mode.\n", |
| 6813 | curproxy->id); |
| 6814 | } |
| 6815 | } |
| 6816 | if (curproxy->appsession_name) { |
| 6817 | Warning("Proxy '%s': appsession will not work correctly in multi-process mode.\n", |
| 6818 | curproxy->id); |
| 6819 | } |
| 6820 | if (!LIST_ISEMPTY(&curproxy->sticking_rules)) { |
| 6821 | Warning("Proxy '%s': sticking rules will not work correctly in multi-process mode.\n", |
| 6822 | curproxy->id); |
| 6823 | } |
| 6824 | } |
| 6825 | } |
Willy Tarreau | 918ff60 | 2011-07-25 16:33:49 +0200 | [diff] [blame] | 6826 | |
| 6827 | /* create the task associated with the proxy */ |
| 6828 | curproxy->task = task_new(); |
| 6829 | if (curproxy->task) { |
| 6830 | curproxy->task->context = curproxy; |
| 6831 | curproxy->task->process = manage_proxy; |
| 6832 | /* no need to queue, it will be done automatically if some |
| 6833 | * listener gets limited. |
| 6834 | */ |
| 6835 | curproxy->task->expire = TICK_ETERNITY; |
| 6836 | } else { |
| 6837 | Alert("Proxy '%s': no more memory when trying to allocate the management task\n", |
| 6838 | curproxy->id); |
| 6839 | cfgerr++; |
| 6840 | } |
| 6841 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6842 | curproxy = curproxy->next; |
| 6843 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 6844 | |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 6845 | /* Check multi-process mode compatibility */ |
| 6846 | if (global.nbproc > 1) { |
| 6847 | if (global.stats_fe) { |
| 6848 | Warning("stats socket will not work correctly in multi-process mode (nbproc > 1).\n"); |
| 6849 | } |
| 6850 | } |
| 6851 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6852 | for (curuserlist = userlist; curuserlist; curuserlist = curuserlist->next) { |
| 6853 | struct auth_users *curuser; |
| 6854 | int g; |
| 6855 | |
| 6856 | for (curuser = curuserlist->users; curuser; curuser = curuser->next) { |
| 6857 | unsigned int group_mask = 0; |
| 6858 | char *group = NULL; |
| 6859 | |
Willy Tarreau | b4c06b7 | 2010-02-02 11:28:20 +0100 | [diff] [blame] | 6860 | if (!curuser->u.groups) |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6861 | continue; |
| 6862 | |
Willy Tarreau | b4c06b7 | 2010-02-02 11:28:20 +0100 | [diff] [blame] | 6863 | while ((group = strtok(group?NULL:curuser->u.groups, ","))) { |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6864 | |
| 6865 | for (g = 0; g < curuserlist->grpcnt; g++) |
| 6866 | if (!strcmp(curuserlist->groups[g], group)) |
| 6867 | break; |
| 6868 | |
| 6869 | if (g == curuserlist->grpcnt) { |
| 6870 | Alert("userlist '%s': no such group '%s' specified in user '%s'\n", |
| 6871 | curuserlist->name, group, curuser->user); |
| 6872 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6873 | goto out; |
| 6874 | } |
| 6875 | |
| 6876 | group_mask |= (1 << g); |
| 6877 | } |
| 6878 | |
Willy Tarreau | b4c06b7 | 2010-02-02 11:28:20 +0100 | [diff] [blame] | 6879 | free(curuser->u.groups); |
| 6880 | curuser->u.group_mask = group_mask; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6881 | } |
| 6882 | |
| 6883 | for (g = 0; g < curuserlist->grpcnt; g++) { |
| 6884 | char *user = NULL; |
| 6885 | |
| 6886 | if (!curuserlist->groupusers[g]) |
| 6887 | continue; |
| 6888 | |
| 6889 | while ((user = strtok(user?NULL:curuserlist->groupusers[g], ","))) { |
| 6890 | for (curuser = curuserlist->users; curuser; curuser = curuser->next) |
| 6891 | if (!strcmp(curuser->user, user)) |
| 6892 | break; |
| 6893 | |
| 6894 | if (!curuser) { |
| 6895 | Alert("userlist '%s': no such user '%s' specified in group '%s'\n", |
| 6896 | curuserlist->name, user, curuserlist->groups[g]); |
| 6897 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6898 | goto out; |
| 6899 | } |
| 6900 | |
Willy Tarreau | b4c06b7 | 2010-02-02 11:28:20 +0100 | [diff] [blame] | 6901 | curuser->u.group_mask |= (1 << g); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6902 | } |
| 6903 | |
| 6904 | free(curuserlist->groupusers[g]); |
| 6905 | } |
| 6906 | |
| 6907 | free(curuserlist->groupusers); |
| 6908 | |
| 6909 | #ifdef DEBUG_AUTH |
| 6910 | for (g = 0; g < curuserlist->grpcnt; g++) { |
| 6911 | fprintf(stderr, "group %s, id %d, mask %08X, users:", curuserlist->groups[g], g , 1 << g); |
| 6912 | |
| 6913 | for (curuser = curuserlist->users; curuser; curuser = curuser->next) { |
Willy Tarreau | b950959 | 2012-05-10 23:25:35 +0200 | [diff] [blame] | 6914 | if (curuser->u.group_mask & (1 << g)) |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6915 | fprintf(stderr, " %s", curuser->user); |
| 6916 | } |
| 6917 | |
| 6918 | fprintf(stderr, "\n"); |
| 6919 | } |
| 6920 | #endif |
| 6921 | |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 6922 | } |
| 6923 | |
| 6924 | /* automatically compute fullconn if not set. We must not do it in the |
| 6925 | * loop above because cross-references are not yet fully resolved. |
| 6926 | */ |
| 6927 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 6928 | /* If <fullconn> is not set, let's set it to 10% of the sum of |
| 6929 | * the possible incoming frontend's maxconns. |
| 6930 | */ |
| 6931 | if (!curproxy->fullconn && (curproxy->cap & PR_CAP_BE)) { |
| 6932 | struct proxy *fe; |
| 6933 | int total = 0; |
| 6934 | |
| 6935 | /* sum up the number of maxconns of frontends which |
| 6936 | * reference this backend at least once or which are |
| 6937 | * the same one ('listen'). |
| 6938 | */ |
| 6939 | for (fe = proxy; fe; fe = fe->next) { |
| 6940 | struct switching_rule *rule; |
| 6941 | struct hdr_exp *exp; |
| 6942 | int found = 0; |
| 6943 | |
| 6944 | if (!(fe->cap & PR_CAP_FE)) |
| 6945 | continue; |
| 6946 | |
| 6947 | if (fe == curproxy) /* we're on a "listen" instance */ |
| 6948 | found = 1; |
| 6949 | |
| 6950 | if (fe->defbe.be == curproxy) /* "default_backend" */ |
| 6951 | found = 1; |
| 6952 | |
| 6953 | /* check if a "use_backend" rule matches */ |
| 6954 | if (!found) { |
| 6955 | list_for_each_entry(rule, &fe->switching_rules, list) { |
| 6956 | if (rule->be.backend == curproxy) { |
| 6957 | found = 1; |
| 6958 | break; |
| 6959 | } |
| 6960 | } |
| 6961 | } |
| 6962 | |
| 6963 | /* check if a "reqsetbe" rule matches */ |
| 6964 | for (exp = fe->req_exp; !found && exp; exp = exp->next) { |
| 6965 | if (exp->action == ACT_SETBE && |
| 6966 | (struct proxy *)exp->replace == curproxy) { |
| 6967 | found = 1; |
| 6968 | break; |
| 6969 | } |
| 6970 | } |
| 6971 | |
| 6972 | /* now we've checked all possible ways to reference a backend |
| 6973 | * from a frontend. |
| 6974 | */ |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 6975 | if (!found) |
| 6976 | continue; |
| 6977 | total += fe->maxconn; |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 6978 | } |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 6979 | /* we have the sum of the maxconns in <total>. We only |
| 6980 | * keep 10% of that sum to set the default fullconn, with |
| 6981 | * a hard minimum of 1 (to avoid a divide by zero). |
| 6982 | */ |
| 6983 | curproxy->fullconn = (total + 9) / 10; |
| 6984 | if (!curproxy->fullconn) |
| 6985 | curproxy->fullconn = 1; |
| 6986 | } |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6987 | } |
| 6988 | |
Willy Tarreau | 056f568 | 2010-06-06 15:51:11 +0200 | [diff] [blame] | 6989 | /* initialize stick-tables on backend capable proxies. This must not |
| 6990 | * be done earlier because the data size may be discovered while parsing |
| 6991 | * other proxies. |
| 6992 | */ |
| 6993 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) |
Willy Tarreau | c00cdc2 | 2010-06-06 16:48:26 +0200 | [diff] [blame] | 6994 | stktable_init(&curproxy->table); |
Willy Tarreau | 056f568 | 2010-06-06 15:51:11 +0200 | [diff] [blame] | 6995 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 6996 | /* |
| 6997 | * Recount currently required checks. |
| 6998 | */ |
| 6999 | |
| 7000 | for (curproxy=proxy; curproxy; curproxy=curproxy->next) { |
| 7001 | int optnum; |
| 7002 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 7003 | for (optnum = 0; cfg_opts[optnum].name; optnum++) |
| 7004 | if (curproxy->options & cfg_opts[optnum].val) |
| 7005 | global.last_checks |= cfg_opts[optnum].checks; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7006 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 7007 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) |
| 7008 | if (curproxy->options2 & cfg_opts2[optnum].val) |
| 7009 | global.last_checks |= cfg_opts2[optnum].checks; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7010 | } |
| 7011 | |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 7012 | if (peers) { |
| 7013 | struct peers *curpeers = peers, **last; |
| 7014 | struct peer *p, *pb; |
| 7015 | |
| 7016 | /* Remove all peers sections which don't have a valid listener. |
| 7017 | * This can happen when a peers section is never referenced and |
| 7018 | * does not contain a local peer. |
| 7019 | */ |
| 7020 | last = &peers; |
| 7021 | while (*last) { |
| 7022 | curpeers = *last; |
| 7023 | if (curpeers->peers_fe) { |
| 7024 | last = &curpeers->next; |
| 7025 | continue; |
| 7026 | } |
| 7027 | |
| 7028 | Warning("Removing incomplete section 'peers %s' (no peer named '%s').\n", |
| 7029 | curpeers->id, localpeer); |
| 7030 | |
| 7031 | p = curpeers->remote; |
| 7032 | while (p) { |
| 7033 | pb = p->next; |
| 7034 | free(p->id); |
| 7035 | free(p); |
| 7036 | p = pb; |
| 7037 | } |
| 7038 | |
| 7039 | /* Destroy and unlink this curpeers section. |
| 7040 | * Note: curpeers is backed up into *last. |
| 7041 | */ |
| 7042 | free(curpeers->id); |
| 7043 | curpeers = curpeers->next; |
| 7044 | free(*last); |
| 7045 | *last = curpeers; |
| 7046 | } |
| 7047 | } |
| 7048 | |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame] | 7049 | if (!global.tune.max_http_hdr) |
| 7050 | global.tune.max_http_hdr = MAX_HTTP_HDR; |
| 7051 | |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 7052 | pool2_hdr_idx = create_pool("hdr_idx", |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame] | 7053 | global.tune.max_http_hdr * sizeof(struct hdr_idx_elem), |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 7054 | MEM_F_SHARED); |
| 7055 | |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 7056 | if (cfgerr > 0) |
| 7057 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7058 | out: |
| 7059 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7060 | } |
| 7061 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 7062 | /* |
| 7063 | * Registers the CFG keyword list <kwl> as a list of valid keywords for next |
| 7064 | * parsing sessions. |
| 7065 | */ |
| 7066 | void cfg_register_keywords(struct cfg_kw_list *kwl) |
| 7067 | { |
| 7068 | LIST_ADDQ(&cfg_keywords.list, &kwl->list); |
| 7069 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7070 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 7071 | /* |
| 7072 | * Unregisters the CFG keyword list <kwl> from the list of valid keywords. |
| 7073 | */ |
| 7074 | void cfg_unregister_keywords(struct cfg_kw_list *kwl) |
| 7075 | { |
| 7076 | LIST_DEL(&kwl->list); |
| 7077 | LIST_INIT(&kwl->list); |
| 7078 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7079 | |
| 7080 | /* |
| 7081 | * Local variables: |
| 7082 | * c-indent-level: 8 |
| 7083 | * c-basic-offset: 8 |
| 7084 | * End: |
| 7085 | */ |