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 | c578891 | 2012-08-24 18:12:41 +0200 | [diff] [blame] | 273 | l->data = &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 | } |
| 468 | else if (!strcmp(args[0], "daemon")) { |
| 469 | global.mode |= MODE_DAEMON; |
| 470 | } |
| 471 | else if (!strcmp(args[0], "debug")) { |
| 472 | global.mode |= MODE_DEBUG; |
| 473 | } |
| 474 | else if (!strcmp(args[0], "noepoll")) { |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 475 | global.tune.options &= ~GTUNE_USE_EPOLL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 476 | } |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 477 | else if (!strcmp(args[0], "nosepoll")) { |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 478 | global.tune.options &= ~GTUNE_USE_SEPOLL; |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 479 | } |
| 480 | else if (!strcmp(args[0], "nokqueue")) { |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 481 | global.tune.options &= ~GTUNE_USE_KQUEUE; |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 482 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 483 | else if (!strcmp(args[0], "nopoll")) { |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 484 | global.tune.options &= ~GTUNE_USE_POLL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 485 | } |
Willy Tarreau | 3ab68cf | 2009-01-25 16:03:28 +0100 | [diff] [blame] | 486 | else if (!strcmp(args[0], "nosplice")) { |
| 487 | global.tune.options &= ~GTUNE_USE_SPLICE; |
| 488 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 489 | else if (!strcmp(args[0], "quiet")) { |
| 490 | global.mode |= MODE_QUIET; |
| 491 | } |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 492 | else if (!strcmp(args[0], "tune.maxpollevents")) { |
| 493 | if (global.tune.maxpollevents != 0) { |
| 494 | 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] | 495 | err_code |= ERR_ALERT; |
| 496 | goto out; |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 497 | } |
| 498 | if (*(args[1]) == 0) { |
| 499 | 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] | 500 | err_code |= ERR_ALERT | ERR_FATAL; |
| 501 | goto out; |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 502 | } |
| 503 | global.tune.maxpollevents = atol(args[1]); |
| 504 | } |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 505 | else if (!strcmp(args[0], "tune.maxaccept")) { |
| 506 | if (global.tune.maxaccept != 0) { |
| 507 | 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] | 508 | err_code |= ERR_ALERT; |
| 509 | goto out; |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 510 | } |
| 511 | if (*(args[1]) == 0) { |
| 512 | 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] | 513 | err_code |= ERR_ALERT | ERR_FATAL; |
| 514 | goto out; |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 515 | } |
| 516 | global.tune.maxaccept = atol(args[1]); |
| 517 | } |
Willy Tarreau | 43961d5 | 2010-10-04 20:39:20 +0200 | [diff] [blame] | 518 | else if (!strcmp(args[0], "tune.chksize")) { |
| 519 | if (*(args[1]) == 0) { |
| 520 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 521 | err_code |= ERR_ALERT | ERR_FATAL; |
| 522 | goto out; |
| 523 | } |
| 524 | global.tune.chksize = atol(args[1]); |
| 525 | } |
Emeric Brun | fc32aca | 2012-09-03 12:10:29 +0200 | [diff] [blame] | 526 | #ifdef USE_OPENSSL |
| 527 | else if (!strcmp(args[0], "tune.sslcachesize")) { |
| 528 | if (*(args[1]) == 0) { |
| 529 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 530 | err_code |= ERR_ALERT | ERR_FATAL; |
| 531 | goto out; |
| 532 | } |
| 533 | global.tune.sslcachesize = atol(args[1]); |
| 534 | } |
| 535 | #endif |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 536 | else if (!strcmp(args[0], "tune.bufsize")) { |
| 537 | if (*(args[1]) == 0) { |
| 538 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 539 | err_code |= ERR_ALERT | ERR_FATAL; |
| 540 | goto out; |
| 541 | } |
| 542 | global.tune.bufsize = atol(args[1]); |
| 543 | if (global.tune.maxrewrite >= global.tune.bufsize / 2) |
| 544 | global.tune.maxrewrite = global.tune.bufsize / 2; |
David du Colombier | 7af4605 | 2012-05-16 14:16:48 +0200 | [diff] [blame] | 545 | trashlen = global.tune.bufsize; |
| 546 | trash = realloc(trash, trashlen); |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 547 | } |
| 548 | else if (!strcmp(args[0], "tune.maxrewrite")) { |
| 549 | if (*(args[1]) == 0) { |
| 550 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 551 | err_code |= ERR_ALERT | ERR_FATAL; |
| 552 | goto out; |
| 553 | } |
| 554 | global.tune.maxrewrite = atol(args[1]); |
| 555 | if (global.tune.maxrewrite >= global.tune.bufsize / 2) |
| 556 | global.tune.maxrewrite = global.tune.bufsize / 2; |
| 557 | } |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 558 | else if (!strcmp(args[0], "tune.rcvbuf.client")) { |
| 559 | if (global.tune.client_rcvbuf != 0) { |
| 560 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 561 | err_code |= ERR_ALERT; |
| 562 | goto out; |
| 563 | } |
| 564 | if (*(args[1]) == 0) { |
| 565 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 566 | err_code |= ERR_ALERT | ERR_FATAL; |
| 567 | goto out; |
| 568 | } |
| 569 | global.tune.client_rcvbuf = atol(args[1]); |
| 570 | } |
| 571 | else if (!strcmp(args[0], "tune.rcvbuf.server")) { |
| 572 | if (global.tune.server_rcvbuf != 0) { |
| 573 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 574 | err_code |= ERR_ALERT; |
| 575 | goto out; |
| 576 | } |
| 577 | if (*(args[1]) == 0) { |
| 578 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 579 | err_code |= ERR_ALERT | ERR_FATAL; |
| 580 | goto out; |
| 581 | } |
| 582 | global.tune.server_rcvbuf = atol(args[1]); |
| 583 | } |
| 584 | else if (!strcmp(args[0], "tune.sndbuf.client")) { |
| 585 | if (global.tune.client_sndbuf != 0) { |
| 586 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 587 | err_code |= ERR_ALERT; |
| 588 | goto out; |
| 589 | } |
| 590 | if (*(args[1]) == 0) { |
| 591 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 592 | err_code |= ERR_ALERT | ERR_FATAL; |
| 593 | goto out; |
| 594 | } |
| 595 | global.tune.client_sndbuf = atol(args[1]); |
| 596 | } |
| 597 | else if (!strcmp(args[0], "tune.sndbuf.server")) { |
| 598 | if (global.tune.server_sndbuf != 0) { |
| 599 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 600 | err_code |= ERR_ALERT; |
| 601 | goto out; |
| 602 | } |
| 603 | if (*(args[1]) == 0) { |
| 604 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 605 | err_code |= ERR_ALERT | ERR_FATAL; |
| 606 | goto out; |
| 607 | } |
| 608 | global.tune.server_sndbuf = atol(args[1]); |
| 609 | } |
Willy Tarreau | bd9a0a7 | 2011-10-23 21:14:29 +0200 | [diff] [blame] | 610 | else if (!strcmp(args[0], "tune.pipesize")) { |
| 611 | if (*(args[1]) == 0) { |
| 612 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 613 | err_code |= ERR_ALERT | ERR_FATAL; |
| 614 | goto out; |
| 615 | } |
| 616 | global.tune.pipesize = atol(args[1]); |
| 617 | } |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame] | 618 | else if (!strcmp(args[0], "tune.http.maxhdr")) { |
| 619 | if (*(args[1]) == 0) { |
| 620 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 621 | err_code |= ERR_ALERT | ERR_FATAL; |
| 622 | goto out; |
| 623 | } |
| 624 | global.tune.max_http_hdr = atol(args[1]); |
| 625 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 626 | else if (!strcmp(args[0], "uid")) { |
| 627 | if (global.uid != 0) { |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 628 | Alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 629 | err_code |= ERR_ALERT; |
| 630 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 631 | } |
| 632 | if (*(args[1]) == 0) { |
| 633 | 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] | 634 | err_code |= ERR_ALERT | ERR_FATAL; |
| 635 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 636 | } |
| 637 | global.uid = atol(args[1]); |
| 638 | } |
| 639 | else if (!strcmp(args[0], "gid")) { |
| 640 | if (global.gid != 0) { |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 641 | Alert("parsing [%s:%d] : group/gid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 642 | err_code |= ERR_ALERT; |
| 643 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 644 | } |
| 645 | if (*(args[1]) == 0) { |
| 646 | 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] | 647 | err_code |= ERR_ALERT | ERR_FATAL; |
| 648 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 649 | } |
| 650 | global.gid = atol(args[1]); |
| 651 | } |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 652 | /* user/group name handling */ |
| 653 | else if (!strcmp(args[0], "user")) { |
| 654 | struct passwd *ha_user; |
| 655 | if (global.uid != 0) { |
| 656 | Alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 657 | err_code |= ERR_ALERT; |
| 658 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 659 | } |
| 660 | errno = 0; |
| 661 | ha_user = getpwnam(args[1]); |
| 662 | if (ha_user != NULL) { |
| 663 | global.uid = (int)ha_user->pw_uid; |
| 664 | } |
| 665 | else { |
| 666 | 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] | 667 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 668 | } |
| 669 | } |
| 670 | else if (!strcmp(args[0], "group")) { |
| 671 | struct group *ha_group; |
| 672 | if (global.gid != 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 673 | 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] | 674 | err_code |= ERR_ALERT; |
| 675 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 676 | } |
| 677 | errno = 0; |
| 678 | ha_group = getgrnam(args[1]); |
| 679 | if (ha_group != NULL) { |
| 680 | global.gid = (int)ha_group->gr_gid; |
| 681 | } |
| 682 | else { |
| 683 | 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] | 684 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 685 | } |
| 686 | } |
| 687 | /* end of user/group name handling*/ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 688 | else if (!strcmp(args[0], "nbproc")) { |
| 689 | if (global.nbproc != 0) { |
| 690 | 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] | 691 | err_code |= ERR_ALERT; |
| 692 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 693 | } |
| 694 | if (*(args[1]) == 0) { |
| 695 | 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] | 696 | err_code |= ERR_ALERT | ERR_FATAL; |
| 697 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 698 | } |
| 699 | global.nbproc = atol(args[1]); |
| 700 | } |
| 701 | else if (!strcmp(args[0], "maxconn")) { |
| 702 | if (global.maxconn != 0) { |
| 703 | 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] | 704 | err_code |= ERR_ALERT; |
| 705 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 706 | } |
| 707 | if (*(args[1]) == 0) { |
| 708 | 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] | 709 | err_code |= ERR_ALERT | ERR_FATAL; |
| 710 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 711 | } |
| 712 | global.maxconn = atol(args[1]); |
| 713 | #ifdef SYSTEM_MAXCONN |
| 714 | if (global.maxconn > DEFAULT_MAXCONN && cfg_maxconn <= DEFAULT_MAXCONN) { |
| 715 | 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); |
| 716 | global.maxconn = DEFAULT_MAXCONN; |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 717 | err_code |= ERR_ALERT; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 718 | } |
| 719 | #endif /* SYSTEM_MAXCONN */ |
| 720 | } |
Willy Tarreau | 403edff | 2012-09-06 11:58:37 +0200 | [diff] [blame] | 721 | else if (!strcmp(args[0], "maxsslconn")) { |
| 722 | #ifdef USE_OPENSSL |
| 723 | if (*(args[1]) == 0) { |
| 724 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 725 | err_code |= ERR_ALERT | ERR_FATAL; |
| 726 | goto out; |
| 727 | } |
| 728 | global.maxsslconn = atol(args[1]); |
| 729 | #else |
| 730 | if (*(args[1]) == 0) { |
| 731 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 732 | err_code |= ERR_ALERT | ERR_FATAL; |
| 733 | goto out; |
| 734 | } |
| 735 | #endif |
| 736 | } |
Willy Tarreau | 81c25d0 | 2011-09-07 15:17:21 +0200 | [diff] [blame] | 737 | else if (!strcmp(args[0], "maxconnrate")) { |
| 738 | if (global.cps_lim != 0) { |
| 739 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 740 | err_code |= ERR_ALERT; |
| 741 | goto out; |
| 742 | } |
| 743 | if (*(args[1]) == 0) { |
| 744 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 745 | err_code |= ERR_ALERT | ERR_FATAL; |
| 746 | goto out; |
| 747 | } |
| 748 | global.cps_lim = atol(args[1]); |
| 749 | } |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 750 | else if (!strcmp(args[0], "maxpipes")) { |
| 751 | if (global.maxpipes != 0) { |
| 752 | 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] | 753 | err_code |= ERR_ALERT; |
| 754 | goto out; |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 755 | } |
| 756 | if (*(args[1]) == 0) { |
| 757 | 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] | 758 | err_code |= ERR_ALERT | ERR_FATAL; |
| 759 | goto out; |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 760 | } |
| 761 | global.maxpipes = atol(args[1]); |
| 762 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 763 | else if (!strcmp(args[0], "ulimit-n")) { |
| 764 | if (global.rlimit_nofile != 0) { |
| 765 | 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] | 766 | err_code |= ERR_ALERT; |
| 767 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 768 | } |
| 769 | if (*(args[1]) == 0) { |
| 770 | 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] | 771 | err_code |= ERR_ALERT | ERR_FATAL; |
| 772 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 773 | } |
| 774 | global.rlimit_nofile = atol(args[1]); |
| 775 | } |
| 776 | else if (!strcmp(args[0], "chroot")) { |
| 777 | if (global.chroot != NULL) { |
| 778 | 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] | 779 | err_code |= ERR_ALERT; |
| 780 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 781 | } |
| 782 | if (*(args[1]) == 0) { |
| 783 | 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] | 784 | err_code |= ERR_ALERT | ERR_FATAL; |
| 785 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 786 | } |
| 787 | global.chroot = strdup(args[1]); |
| 788 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 789 | else if (!strcmp(args[0], "description")) { |
| 790 | int i, len=0; |
| 791 | char *d; |
| 792 | |
| 793 | if (!*args[1]) { |
| 794 | Alert("parsing [%s:%d]: '%s' expects a string argument.\n", |
| 795 | file, linenum, args[0]); |
| 796 | err_code |= ERR_ALERT | ERR_FATAL; |
| 797 | goto out; |
| 798 | } |
| 799 | |
| 800 | for(i=1; *args[i]; i++) |
| 801 | len += strlen(args[i])+1; |
| 802 | |
| 803 | if (global.desc) |
| 804 | free(global.desc); |
| 805 | |
| 806 | global.desc = d = (char *)calloc(1, len); |
| 807 | |
| 808 | d += sprintf(d, "%s", args[1]); |
| 809 | for(i=2; *args[i]; i++) |
| 810 | d += sprintf(d, " %s", args[i]); |
| 811 | } |
| 812 | else if (!strcmp(args[0], "node")) { |
| 813 | int i; |
| 814 | char c; |
| 815 | |
| 816 | for (i=0; args[1][i]; i++) { |
| 817 | c = args[1][i]; |
Willy Tarreau | 88e0581 | 2010-03-03 00:16:00 +0100 | [diff] [blame] | 818 | if (!isupper((unsigned char)c) && !islower((unsigned char)c) && |
| 819 | !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.') |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 820 | break; |
| 821 | } |
| 822 | |
| 823 | if (!i || args[1][i]) { |
| 824 | Alert("parsing [%s:%d]: '%s' requires valid node name - non-empty string" |
| 825 | " with digits(0-9), letters(A-Z, a-z), dot(.), hyphen(-) or underscode(_).\n", |
| 826 | file, linenum, args[0]); |
| 827 | err_code |= ERR_ALERT | ERR_FATAL; |
| 828 | goto out; |
| 829 | } |
| 830 | |
| 831 | if (global.node) |
| 832 | free(global.node); |
| 833 | |
| 834 | global.node = strdup(args[1]); |
| 835 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 836 | else if (!strcmp(args[0], "pidfile")) { |
| 837 | if (global.pidfile != NULL) { |
| 838 | 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] | 839 | err_code |= ERR_ALERT; |
| 840 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 841 | } |
| 842 | if (*(args[1]) == 0) { |
| 843 | 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] | 844 | err_code |= ERR_ALERT | ERR_FATAL; |
| 845 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 846 | } |
| 847 | global.pidfile = strdup(args[1]); |
| 848 | } |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 849 | else if (!strcmp(args[0], "unix-bind")) { |
| 850 | int cur_arg = 1; |
| 851 | while (*(args[cur_arg])) { |
| 852 | if (!strcmp(args[cur_arg], "prefix")) { |
| 853 | if (global.unix_bind.prefix != NULL) { |
| 854 | Alert("parsing [%s:%d] : unix-bind '%s' already specified. Continuing.\n", file, linenum, args[cur_arg]); |
| 855 | err_code |= ERR_ALERT; |
| 856 | cur_arg += 2; |
| 857 | continue; |
| 858 | } |
| 859 | |
| 860 | if (*(args[cur_arg+1]) == 0) { |
| 861 | Alert("parsing [%s:%d] : unix_bind '%s' expects a path as an argument.\n", file, linenum, args[cur_arg]); |
| 862 | err_code |= ERR_ALERT | ERR_FATAL; |
| 863 | goto out; |
| 864 | } |
| 865 | global.unix_bind.prefix = strdup(args[cur_arg+1]); |
| 866 | cur_arg += 2; |
| 867 | continue; |
| 868 | } |
| 869 | |
| 870 | if (!strcmp(args[cur_arg], "mode")) { |
| 871 | |
| 872 | global.unix_bind.ux.mode = strtol(args[cur_arg + 1], NULL, 8); |
| 873 | cur_arg += 2; |
| 874 | continue; |
| 875 | } |
| 876 | |
| 877 | if (!strcmp(args[cur_arg], "uid")) { |
| 878 | |
| 879 | global.unix_bind.ux.uid = atol(args[cur_arg + 1 ]); |
| 880 | cur_arg += 2; |
| 881 | continue; |
| 882 | } |
| 883 | |
| 884 | if (!strcmp(args[cur_arg], "gid")) { |
| 885 | |
| 886 | global.unix_bind.ux.gid = atol(args[cur_arg + 1 ]); |
| 887 | cur_arg += 2; |
| 888 | continue; |
| 889 | } |
| 890 | |
| 891 | if (!strcmp(args[cur_arg], "user")) { |
| 892 | struct passwd *user; |
| 893 | |
| 894 | user = getpwnam(args[cur_arg + 1]); |
| 895 | if (!user) { |
| 896 | Alert("parsing [%s:%d] : '%s' : '%s' unknown user.\n", |
| 897 | file, linenum, args[0], args[cur_arg + 1 ]); |
| 898 | err_code |= ERR_ALERT | ERR_FATAL; |
| 899 | goto out; |
| 900 | } |
| 901 | |
| 902 | global.unix_bind.ux.uid = user->pw_uid; |
| 903 | cur_arg += 2; |
| 904 | continue; |
| 905 | } |
| 906 | |
| 907 | if (!strcmp(args[cur_arg], "group")) { |
| 908 | struct group *group; |
| 909 | |
| 910 | group = getgrnam(args[cur_arg + 1]); |
| 911 | if (!group) { |
| 912 | Alert("parsing [%s:%d] : '%s' : '%s' unknown group.\n", |
| 913 | file, linenum, args[0], args[cur_arg + 1 ]); |
| 914 | err_code |= ERR_ALERT | ERR_FATAL; |
| 915 | goto out; |
| 916 | } |
| 917 | |
| 918 | global.unix_bind.ux.gid = group->gr_gid; |
| 919 | cur_arg += 2; |
| 920 | continue; |
| 921 | } |
| 922 | |
Willy Tarreau | b48f958 | 2011-09-05 01:17:06 +0200 | [diff] [blame] | 923 | 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] | 924 | file, linenum, args[0]); |
| 925 | err_code |= ERR_ALERT | ERR_FATAL; |
| 926 | goto out; |
| 927 | } |
| 928 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 929 | else if (!strcmp(args[0], "log") && kwm == KWM_NO) { /* no log */ |
| 930 | /* delete previous herited or defined syslog servers */ |
| 931 | struct logsrv *back; |
| 932 | struct logsrv *tmp; |
| 933 | |
| 934 | if (*(args[1]) != 0) { |
| 935 | Alert("parsing [%s:%d]:%s : 'no log' does not expect arguments.\n", file, linenum, args[1]); |
| 936 | err_code |= ERR_ALERT | ERR_FATAL; |
| 937 | goto out; |
| 938 | } |
| 939 | |
| 940 | list_for_each_entry_safe(tmp, back, &global.logsrvs, list) { |
| 941 | LIST_DEL(&tmp->list); |
| 942 | free(tmp); |
| 943 | } |
| 944 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 945 | else if (!strcmp(args[0], "log")) { /* syslog server address */ |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 946 | struct logsrv *logsrv; |
| 947 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 948 | if (*(args[1]) == 0 || *(args[2]) == 0) { |
| 949 | 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] | 950 | err_code |= ERR_ALERT | ERR_FATAL; |
| 951 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 952 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 953 | |
| 954 | logsrv = calloc(1, sizeof(struct logsrv)); |
| 955 | |
| 956 | logsrv->facility = get_log_facility(args[2]); |
| 957 | if (logsrv->facility < 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 958 | 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] | 959 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 960 | logsrv->facility = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 961 | } |
| 962 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 963 | logsrv->level = 7; /* max syslog level = debug */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 964 | if (*(args[3])) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 965 | logsrv->level = get_log_level(args[3]); |
| 966 | if (logsrv->level < 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 967 | 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] | 968 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 969 | logsrv->level = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 970 | } |
| 971 | } |
| 972 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 973 | logsrv->minlvl = 0; /* limit syslog level to this level (emerg) */ |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 974 | if (*(args[4])) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 975 | logsrv->minlvl = get_log_level(args[4]); |
| 976 | if (logsrv->minlvl < 0) { |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 977 | 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] | 978 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 979 | logsrv->minlvl = 0; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 980 | } |
| 981 | } |
| 982 | |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 983 | if (args[1][0] == '/') { |
David du Colombier | 11bcb6c | 2011-03-24 12:23:00 +0100 | [diff] [blame] | 984 | struct sockaddr_storage *sk = (struct sockaddr_storage *)str2sun(args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 985 | if (!sk) { |
| 986 | 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] | 987 | args[1], (int)sizeof(((struct sockaddr_un *)&sk)->sun_path) - 1); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 988 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 989 | free(logsrv); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 990 | goto out; |
| 991 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 992 | logsrv->addr = *sk; |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 993 | } else { |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 994 | struct sockaddr_storage *sk = str2sa(args[1]); |
David du Colombier | 11bcb6c | 2011-03-24 12:23:00 +0100 | [diff] [blame] | 995 | if (!sk) { |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 996 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[1]); |
| 997 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 998 | free(logsrv); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 999 | goto out; |
| 1000 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1001 | logsrv->addr = *sk; |
| 1002 | if (!get_host_port(&logsrv->addr)) |
| 1003 | set_host_port(&logsrv->addr, SYSLOG_PORT); |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 1004 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1005 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1006 | LIST_ADDQ(&global.logsrvs, &logsrv->list); |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1007 | } |
Joe Williams | df5b38f | 2010-12-29 17:05:48 +0100 | [diff] [blame] | 1008 | else if (!strcmp(args[0], "log-send-hostname")) { /* set the hostname in syslog header */ |
| 1009 | char *name; |
| 1010 | int len; |
| 1011 | |
| 1012 | if (global.log_send_hostname != NULL) { |
| 1013 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 1014 | err_code |= ERR_ALERT; |
| 1015 | goto out; |
| 1016 | } |
| 1017 | |
| 1018 | if (*(args[1])) |
| 1019 | name = args[1]; |
| 1020 | else |
| 1021 | name = hostname; |
| 1022 | |
| 1023 | len = strlen(name); |
| 1024 | |
| 1025 | /* We'll add a space after the name to respect the log format */ |
| 1026 | free(global.log_send_hostname); |
| 1027 | global.log_send_hostname = malloc(len + 2); |
| 1028 | snprintf(global.log_send_hostname, len + 2, "%s ", name); |
| 1029 | } |
Kevinm | 48936af | 2010-12-22 16:08:21 +0000 | [diff] [blame] | 1030 | else if (!strcmp(args[0], "log-tag")) { /* tag to report to syslog */ |
| 1031 | if (*(args[1]) == 0) { |
| 1032 | Alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]); |
| 1033 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1034 | goto out; |
| 1035 | } |
| 1036 | free(global.log_tag); |
| 1037 | global.log_tag = strdup(args[1]); |
| 1038 | } |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1039 | else if (!strcmp(args[0], "spread-checks")) { /* random time between checks (0-50) */ |
| 1040 | if (global.spread_checks != 0) { |
| 1041 | Alert("parsing [%s:%d]: spread-checks already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1042 | err_code |= ERR_ALERT; |
| 1043 | goto out; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1044 | } |
| 1045 | if (*(args[1]) == 0) { |
| 1046 | 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] | 1047 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1048 | goto out; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1049 | } |
| 1050 | global.spread_checks = atol(args[1]); |
| 1051 | if (global.spread_checks < 0 || global.spread_checks > 50) { |
| 1052 | 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] | 1053 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1054 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1055 | } |
| 1056 | else { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1057 | struct cfg_kw_list *kwl; |
| 1058 | int index; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1059 | int rc; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1060 | |
| 1061 | list_for_each_entry(kwl, &cfg_keywords.list, list) { |
| 1062 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 1063 | if (kwl->kw[index].section != CFG_GLOBAL) |
| 1064 | continue; |
| 1065 | if (strcmp(kwl->kw[index].kw, args[0]) == 0) { |
| 1066 | /* prepare error message just in case */ |
David du Colombier | 7af4605 | 2012-05-16 14:16:48 +0200 | [diff] [blame] | 1067 | snprintf(trash, trashlen, |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1068 | "error near '%s' in '%s' section", args[0], "global"); |
Willy Tarreau | 28a47d6 | 2012-09-18 20:02:48 +0200 | [diff] [blame] | 1069 | 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] | 1070 | if (rc < 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 1071 | Alert("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1072 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1073 | } |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1074 | else if (rc > 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 1075 | Warning("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1076 | err_code |= ERR_WARN; |
| 1077 | goto out; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1078 | } |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1079 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1080 | } |
| 1081 | } |
| 1082 | } |
| 1083 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1084 | 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] | 1085 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1086 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1087 | |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1088 | out: |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 1089 | free(errmsg); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1090 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1091 | } |
| 1092 | |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 1093 | void init_default_instance() |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1094 | { |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 1095 | init_new_proxy(&defproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1096 | defproxy.mode = PR_MODE_TCP; |
| 1097 | defproxy.state = PR_STNEW; |
| 1098 | defproxy.maxconn = cfg_maxpconn; |
| 1099 | defproxy.conn_retries = CONN_RETRIES; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1100 | |
| 1101 | defproxy.defsrv.inter = DEF_CHKINTR; |
| 1102 | defproxy.defsrv.fastinter = 0; |
| 1103 | defproxy.defsrv.downinter = 0; |
| 1104 | defproxy.defsrv.rise = DEF_RISETIME; |
| 1105 | defproxy.defsrv.fall = DEF_FALLTIME; |
| 1106 | defproxy.defsrv.check_port = 0; |
| 1107 | defproxy.defsrv.maxqueue = 0; |
| 1108 | defproxy.defsrv.minconn = 0; |
| 1109 | defproxy.defsrv.maxconn = 0; |
| 1110 | defproxy.defsrv.slowstart = 0; |
| 1111 | defproxy.defsrv.onerror = DEF_HANA_ONERR; |
| 1112 | defproxy.defsrv.consecutive_errors_limit = DEF_HANA_ERRLIMIT; |
| 1113 | defproxy.defsrv.uweight = defproxy.defsrv.iweight = 1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1114 | } |
| 1115 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1116 | |
| 1117 | static int create_cond_regex_rule(const char *file, int line, |
| 1118 | struct proxy *px, int dir, int action, int flags, |
| 1119 | const char *cmd, const char *reg, const char *repl, |
| 1120 | const char **cond_start) |
| 1121 | { |
| 1122 | regex_t *preg = NULL; |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 1123 | char *errmsg = NULL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1124 | const char *err; |
| 1125 | int err_code = 0; |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1126 | struct acl_cond *cond = NULL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1127 | |
| 1128 | if (px == &defproxy) { |
| 1129 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, line, cmd); |
| 1130 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1131 | goto err; |
| 1132 | } |
| 1133 | |
| 1134 | if (*reg == 0) { |
| 1135 | Alert("parsing [%s:%d] : '%s' expects <regex> as an argument.\n", file, line, cmd); |
| 1136 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1137 | goto err; |
| 1138 | } |
| 1139 | |
| 1140 | if (warnifnotcap(px, PR_CAP_RS, file, line, cmd, NULL)) |
| 1141 | err_code |= ERR_WARN; |
| 1142 | |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1143 | if (cond_start && |
| 1144 | (strcmp(*cond_start, "if") == 0 || strcmp(*cond_start, "unless") == 0)) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 1145 | if ((cond = build_acl_cond(file, line, px, cond_start, &errmsg)) == NULL) { |
| 1146 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 1147 | file, line, cmd, errmsg); |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1148 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1149 | goto err; |
| 1150 | } |
| 1151 | } |
| 1152 | else if (cond_start && **cond_start) { |
| 1153 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 1154 | file, line, cmd, *cond_start); |
| 1155 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1156 | goto err; |
| 1157 | } |
| 1158 | |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 1159 | if (dir == SMP_OPT_DIR_REQ) |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1160 | err_code |= warnif_cond_requires_resp(cond, file, line); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 1161 | else |
| 1162 | err_code |= warnif_cond_requires_req(cond, file, line); |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1163 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1164 | preg = calloc(1, sizeof(regex_t)); |
| 1165 | if (!preg) { |
| 1166 | Alert("parsing [%s:%d] : '%s' : not enough memory to build regex.\n", file, line, cmd); |
| 1167 | err_code = ERR_ALERT | ERR_FATAL; |
| 1168 | goto err; |
| 1169 | } |
| 1170 | |
| 1171 | if (regcomp(preg, reg, REG_EXTENDED | flags) != 0) { |
| 1172 | Alert("parsing [%s:%d] : '%s' : bad regular expression '%s'.\n", file, line, cmd, reg); |
| 1173 | err_code = ERR_ALERT | ERR_FATAL; |
| 1174 | goto err; |
| 1175 | } |
| 1176 | |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 1177 | 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] | 1178 | preg, action, repl ? strdup(repl) : NULL, cond); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1179 | if (repl && err) { |
| 1180 | Alert("parsing [%s:%d] : '%s' : invalid character or unterminated sequence in replacement string near '%c'.\n", |
| 1181 | file, line, cmd, *err); |
| 1182 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1183 | goto err; |
| 1184 | } |
| 1185 | |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 1186 | 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] | 1187 | err_code |= ERR_WARN; |
| 1188 | |
Willy Tarreau | f4068b6 | 2012-05-08 17:37:49 +0200 | [diff] [blame] | 1189 | free(errmsg); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1190 | return err_code; |
| 1191 | err: |
Willy Tarreau | f4068b6 | 2012-05-08 17:37:49 +0200 | [diff] [blame] | 1192 | free(errmsg); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1193 | free(preg); |
| 1194 | return err_code; |
| 1195 | } |
| 1196 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1197 | /* |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1198 | * Parse a line in a <listen>, <frontend>, <backend> or <ruleset> section. |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1199 | * Returns the error code, 0 if OK, or any combination of : |
| 1200 | * - ERR_ABORT: must abort ASAP |
| 1201 | * - ERR_FATAL: we can continue parsing but not start the service |
| 1202 | * - ERR_WARN: a warning has been emitted |
| 1203 | * - ERR_ALERT: an alert has been emitted |
| 1204 | * Only the two first ones can stop processing, the two others are just |
| 1205 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1206 | */ |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1207 | int cfg_parse_peers(const char *file, int linenum, char **args, int kwm) |
| 1208 | { |
| 1209 | static struct peers *curpeers = NULL; |
| 1210 | struct peer *newpeer = NULL; |
| 1211 | const char *err; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1212 | struct bind_conf *bind_conf; |
| 1213 | struct listener *l; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1214 | int err_code = 0; |
| 1215 | |
| 1216 | if (strcmp(args[0], "peers") == 0) { /* new peers section */ |
| 1217 | |
| 1218 | err = invalid_char(args[1]); |
| 1219 | if (err) { |
| 1220 | Alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 1221 | file, linenum, *err, args[0], args[1]); |
| 1222 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1223 | } |
| 1224 | |
| 1225 | for (curpeers = peers; curpeers != NULL; curpeers = curpeers->next) { |
| 1226 | /* |
| 1227 | * If there are two proxies with the same name only following |
| 1228 | * combinations are allowed: |
| 1229 | */ |
| 1230 | if (strcmp(curpeers->id, args[1]) == 0) { |
| 1231 | Warning("Parsing [%s:%d]: peers '%s' has same name as another peers (declared at %s:%d).\n", |
| 1232 | file, linenum, args[1], curpeers->conf.file, curpeers->conf.line); |
| 1233 | err_code |= ERR_WARN; |
| 1234 | } |
| 1235 | } |
| 1236 | |
| 1237 | if ((curpeers = (struct peers *)calloc(1, sizeof(struct peers))) == NULL) { |
| 1238 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1239 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1240 | goto out; |
| 1241 | } |
| 1242 | |
| 1243 | curpeers->next = peers; |
| 1244 | peers = curpeers; |
| 1245 | curpeers->conf.file = file; |
| 1246 | curpeers->conf.line = linenum; |
| 1247 | curpeers->last_change = now.tv_sec; |
| 1248 | curpeers->id = strdup(args[1]); |
| 1249 | } |
| 1250 | else if (strcmp(args[0], "peer") == 0) { /* peer definition */ |
| 1251 | char *rport, *raddr; |
| 1252 | short realport = 0; |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 1253 | struct sockaddr_storage *sk; |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 1254 | char *err_msg = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1255 | |
| 1256 | if (!*args[2]) { |
| 1257 | Alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n", |
| 1258 | file, linenum, args[0]); |
| 1259 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1260 | goto out; |
| 1261 | } |
| 1262 | |
| 1263 | err = invalid_char(args[1]); |
| 1264 | if (err) { |
| 1265 | Alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n", |
| 1266 | file, linenum, *err, args[1]); |
| 1267 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1268 | goto out; |
| 1269 | } |
| 1270 | |
| 1271 | if ((newpeer = (struct peer *)calloc(1, sizeof(struct peer))) == NULL) { |
| 1272 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1273 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1274 | goto out; |
| 1275 | } |
| 1276 | |
| 1277 | /* the peers are linked backwards first */ |
| 1278 | curpeers->count++; |
| 1279 | newpeer->next = curpeers->remote; |
| 1280 | curpeers->remote = newpeer; |
| 1281 | newpeer->peers = curpeers; |
| 1282 | newpeer->conf.file = file; |
| 1283 | newpeer->conf.line = linenum; |
| 1284 | |
| 1285 | newpeer->last_change = now.tv_sec; |
| 1286 | newpeer->id = strdup(args[1]); |
| 1287 | |
| 1288 | raddr = strdup(args[2]); |
Willy Tarreau | fab5a43 | 2011-03-04 15:31:53 +0100 | [diff] [blame] | 1289 | rport = strrchr(raddr, ':'); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1290 | if (rport) { |
| 1291 | *rport++ = 0; |
| 1292 | realport = atol(rport); |
| 1293 | } |
| 1294 | if (!realport) { |
| 1295 | Alert("parsing [%s:%d] : Missing or invalid port in '%s'\n", file, linenum, args[2]); |
| 1296 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1297 | goto out; |
| 1298 | } |
| 1299 | |
Willy Tarreau | fab5a43 | 2011-03-04 15:31:53 +0100 | [diff] [blame] | 1300 | sk = str2ip(raddr); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1301 | free(raddr); |
| 1302 | if (!sk) { |
| 1303 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[2]); |
| 1304 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1305 | goto out; |
| 1306 | } |
| 1307 | newpeer->addr = *sk; |
Willy Tarreau | 26d8c59 | 2012-05-07 18:12:14 +0200 | [diff] [blame] | 1308 | newpeer->proto = protocol_by_family(newpeer->addr.ss_family); |
Willy Tarreau | c578891 | 2012-08-24 18:12:41 +0200 | [diff] [blame] | 1309 | newpeer->data = &raw_sock; |
Willy Tarreau | d02394b | 2012-05-11 18:32:18 +0200 | [diff] [blame] | 1310 | newpeer->sock_init_arg = NULL; |
Willy Tarreau | 26d8c59 | 2012-05-07 18:12:14 +0200 | [diff] [blame] | 1311 | |
Willy Tarreau | 173e7fb | 2012-09-24 22:47:39 +0200 | [diff] [blame] | 1312 | if (!newpeer->proto) { |
Willy Tarreau | 26d8c59 | 2012-05-07 18:12:14 +0200 | [diff] [blame] | 1313 | Alert("parsing [%s:%d] : Unknown protocol family %d '%s'\n", |
| 1314 | file, linenum, newpeer->addr.ss_family, args[2]); |
| 1315 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1316 | goto out; |
| 1317 | } |
| 1318 | |
Willy Tarreau | 86ad42c | 2011-08-27 12:29:07 +0200 | [diff] [blame] | 1319 | set_host_port(&newpeer->addr, realport); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1320 | |
| 1321 | if (strcmp(newpeer->id, localpeer) == 0) { |
| 1322 | /* Current is local peer, it define a frontend */ |
| 1323 | newpeer->local = 1; |
| 1324 | |
| 1325 | if (!curpeers->peers_fe) { |
| 1326 | if ((curpeers->peers_fe = calloc(1, sizeof(struct proxy))) == NULL) { |
| 1327 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1328 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1329 | goto out; |
| 1330 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1331 | |
Willy Tarreau | 237250c | 2011-07-29 01:49:03 +0200 | [diff] [blame] | 1332 | init_new_proxy(curpeers->peers_fe); |
| 1333 | curpeers->peers_fe->parent = curpeers; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1334 | |
| 1335 | curpeers->peers_fe->last_change = now.tv_sec; |
| 1336 | curpeers->peers_fe->id = strdup(args[1]); |
| 1337 | curpeers->peers_fe->cap = PR_CAP_FE; |
Willy Tarreau | 3ae65a1 | 2011-09-07 17:40:39 +0200 | [diff] [blame] | 1338 | curpeers->peers_fe->maxconn = 0; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1339 | curpeers->peers_fe->conn_retries = CONN_RETRIES; |
| 1340 | curpeers->peers_fe->timeout.connect = 5000; |
| 1341 | curpeers->peers_fe->accept = peer_accept; |
| 1342 | 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] | 1343 | |
| 1344 | bind_conf = bind_conf_alloc(&curpeers->peers_fe->conf.bind, file, linenum, args[2]); |
| 1345 | |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 1346 | if (!str2listener(args[2], curpeers->peers_fe, bind_conf, file, linenum, &err_msg)) { |
| 1347 | if (err_msg && *err_msg) { |
| 1348 | indent_msg(&err_msg, 2); |
| 1349 | Alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], err_msg); |
| 1350 | } |
| 1351 | else |
| 1352 | Alert("parsing [%s:%d] : '%s %s' : error encountered while parsing listening address %s.\n", |
| 1353 | file, linenum, args[0], args[1], args[2]); |
| 1354 | free(err_msg); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1355 | err_code |= ERR_FATAL; |
| 1356 | goto out; |
| 1357 | } |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1358 | |
| 1359 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
| 1360 | l->maxconn = ((struct proxy *)curpeers->peers_fe)->maxconn; |
| 1361 | l->backlog = ((struct proxy *)curpeers->peers_fe)->backlog; |
| 1362 | l->timeout = &((struct proxy *)curpeers->peers_fe)->timeout.client; |
| 1363 | l->accept = session_accept; |
| 1364 | l->handler = process_session; |
| 1365 | l->analysers |= ((struct proxy *)curpeers->peers_fe)->fe_req_ana; |
| 1366 | l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */ |
| 1367 | global.maxsock += l->maxconn; |
| 1368 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1369 | } |
| 1370 | } |
| 1371 | } /* neither "peer" nor "peers" */ |
| 1372 | else if (*args[0] != 0) { |
| 1373 | Alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection); |
| 1374 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1375 | goto out; |
| 1376 | } |
| 1377 | |
| 1378 | out: |
| 1379 | return err_code; |
| 1380 | } |
| 1381 | |
| 1382 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 1383 | 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] | 1384 | { |
| 1385 | static struct proxy *curproxy = NULL; |
| 1386 | struct server *newsrv = NULL; |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 1387 | const char *err; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 1388 | int rc; |
| 1389 | unsigned val; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1390 | int err_code = 0; |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 1391 | struct acl_cond *cond = NULL; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 1392 | struct logsrv *tmplogsrv; |
Willy Tarreau | f4068b6 | 2012-05-08 17:37:49 +0200 | [diff] [blame] | 1393 | char *errmsg = NULL; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 1394 | struct bind_conf *bind_conf; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1395 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1396 | if (!strcmp(args[0], "listen")) |
| 1397 | rc = PR_CAP_LISTEN; |
| 1398 | else if (!strcmp(args[0], "frontend")) |
| 1399 | rc = PR_CAP_FE | PR_CAP_RS; |
| 1400 | else if (!strcmp(args[0], "backend")) |
| 1401 | rc = PR_CAP_BE | PR_CAP_RS; |
| 1402 | else if (!strcmp(args[0], "ruleset")) |
| 1403 | rc = PR_CAP_RS; |
| 1404 | else |
| 1405 | rc = PR_CAP_NONE; |
| 1406 | |
| 1407 | if (rc != PR_CAP_NONE) { /* new proxy */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1408 | if (!*args[1]) { |
| 1409 | Alert("parsing [%s:%d] : '%s' expects an <id> argument and\n" |
| 1410 | " optionnally supports [addr1]:port1[-end1]{,[addr]:port[-end]}...\n", |
| 1411 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1412 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1413 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1414 | } |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 1415 | |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 1416 | err = invalid_char(args[1]); |
| 1417 | if (err) { |
| 1418 | Alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 1419 | file, linenum, *err, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1420 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 1421 | } |
| 1422 | |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 1423 | for (curproxy = proxy; curproxy != NULL; curproxy = curproxy->next) { |
| 1424 | /* |
| 1425 | * If there are two proxies with the same name only following |
| 1426 | * combinations are allowed: |
| 1427 | * |
| 1428 | * listen backend frontend ruleset |
| 1429 | * listen - - - - |
| 1430 | * backend - - OK - |
| 1431 | * frontend - OK - - |
| 1432 | * ruleset - - - - |
| 1433 | */ |
| 1434 | |
| 1435 | if (!strcmp(curproxy->id, args[1]) && |
| 1436 | (rc!=(PR_CAP_FE|PR_CAP_RS) || curproxy->cap!=(PR_CAP_BE|PR_CAP_RS)) && |
| 1437 | (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] | 1438 | Warning("Parsing [%s:%d]: %s '%s' has same name as another %s (declared at %s:%d).\n", |
| 1439 | file, linenum, proxy_cap_str(rc), args[1], proxy_type_str(curproxy), |
| 1440 | curproxy->conf.file, curproxy->conf.line); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1441 | err_code |= ERR_WARN; |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 1442 | } |
| 1443 | } |
| 1444 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1445 | if ((curproxy = (struct proxy *)calloc(1, sizeof(struct proxy))) == NULL) { |
| 1446 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1447 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1448 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1449 | } |
Willy Tarreau | 5af24ef | 2009-03-15 15:23:16 +0100 | [diff] [blame] | 1450 | |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 1451 | init_new_proxy(curproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1452 | curproxy->next = proxy; |
| 1453 | proxy = curproxy; |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 1454 | curproxy->conf.file = file; |
| 1455 | curproxy->conf.line = linenum; |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 1456 | curproxy->last_change = now.tv_sec; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1457 | curproxy->id = strdup(args[1]); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1458 | curproxy->cap = rc; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1459 | |
| 1460 | /* parse the listener address if any */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1461 | if ((curproxy->cap & PR_CAP_FE) && *args[2]) { |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1462 | struct listener *l; |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 1463 | char *err_msg = NULL; |
Willy Tarreau | 81a8117 | 2012-09-18 20:52:35 +0200 | [diff] [blame] | 1464 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1465 | bind_conf = bind_conf_alloc(&curproxy->conf.bind, file, linenum, args[2]); |
| 1466 | |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 1467 | if (!str2listener(args[2], curproxy, bind_conf, file, linenum, &err_msg)) { |
| 1468 | if (err_msg && *err_msg) { |
| 1469 | indent_msg(&err_msg, 2); |
| 1470 | Alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], err_msg); |
| 1471 | } |
| 1472 | else |
| 1473 | Alert("parsing [%s:%d] : '%s %s' : error encountered while parsing listening address '%s'.\n", |
| 1474 | file, linenum, args[0], args[1], args[2]); |
| 1475 | free(err_msg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1476 | err_code |= ERR_FATAL; |
| 1477 | goto out; |
| 1478 | } |
Willy Tarreau | 81a8117 | 2012-09-18 20:52:35 +0200 | [diff] [blame] | 1479 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1480 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
Willy Tarreau | c8b1109 | 2011-02-16 11:08:57 +0100 | [diff] [blame] | 1481 | global.maxsock++; |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 1482 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1483 | } |
| 1484 | |
| 1485 | /* set default values */ |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1486 | memcpy(&curproxy->defsrv, &defproxy.defsrv, sizeof(curproxy->defsrv)); |
Willy Tarreau | 7016020 | 2010-04-07 16:06:40 +0200 | [diff] [blame] | 1487 | curproxy->defsrv.id = "default-server"; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1488 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1489 | curproxy->state = defproxy.state; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1490 | curproxy->options = defproxy.options; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 1491 | curproxy->options2 = defproxy.options2; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 1492 | curproxy->no_options = defproxy.no_options; |
| 1493 | curproxy->no_options2 = defproxy.no_options2; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 1494 | curproxy->bind_proc = defproxy.bind_proc; |
Willy Tarreau | 3168223 | 2007-11-29 15:38:04 +0100 | [diff] [blame] | 1495 | curproxy->lbprm.algo = defproxy.lbprm.algo; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 1496 | curproxy->except_net = defproxy.except_net; |
| 1497 | curproxy->except_mask = defproxy.except_mask; |
Maik Broemme | 36db02e | 2009-05-08 17:02:07 +0200 | [diff] [blame] | 1498 | curproxy->except_to = defproxy.except_to; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 1499 | curproxy->except_mask_to = defproxy.except_mask_to; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1500 | |
Willy Tarreau | 79f5fe8 | 2008-08-23 08:18:21 +0200 | [diff] [blame] | 1501 | if (defproxy.fwdfor_hdr_len) { |
| 1502 | curproxy->fwdfor_hdr_len = defproxy.fwdfor_hdr_len; |
| 1503 | curproxy->fwdfor_hdr_name = strdup(defproxy.fwdfor_hdr_name); |
| 1504 | } |
| 1505 | |
Willy Tarreau | b86db34 | 2009-11-30 11:50:16 +0100 | [diff] [blame] | 1506 | if (defproxy.orgto_hdr_len) { |
| 1507 | curproxy->orgto_hdr_len = defproxy.orgto_hdr_len; |
| 1508 | curproxy->orgto_hdr_name = strdup(defproxy.orgto_hdr_name); |
| 1509 | } |
| 1510 | |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 1511 | if (defproxy.server_id_hdr_len) { |
| 1512 | curproxy->server_id_hdr_len = defproxy.server_id_hdr_len; |
| 1513 | curproxy->server_id_hdr_name = strdup(defproxy.server_id_hdr_name); |
| 1514 | } |
| 1515 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1516 | if (curproxy->cap & PR_CAP_FE) { |
| 1517 | curproxy->maxconn = defproxy.maxconn; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 1518 | curproxy->backlog = defproxy.backlog; |
Willy Tarreau | 13a34bd | 2009-05-10 18:52:49 +0200 | [diff] [blame] | 1519 | curproxy->fe_sps_lim = defproxy.fe_sps_lim; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1520 | |
| 1521 | /* initialize error relocations */ |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1522 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) |
| 1523 | chunk_dup(&curproxy->errmsg[rc], &defproxy.errmsg[rc]); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1524 | |
| 1525 | curproxy->to_log = defproxy.to_log & ~LW_COOKIE & ~LW_REQHDR & ~ LW_RSPHDR; |
| 1526 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1527 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1528 | if (curproxy->cap & PR_CAP_BE) { |
| 1529 | curproxy->fullconn = defproxy.fullconn; |
| 1530 | curproxy->conn_retries = defproxy.conn_retries; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1531 | |
Willy Tarreau | aa2f389 | 2010-10-22 16:15:31 +0200 | [diff] [blame] | 1532 | if (defproxy.check_req) { |
| 1533 | curproxy->check_req = calloc(1, defproxy.check_len); |
| 1534 | memcpy(curproxy->check_req, defproxy.check_req, defproxy.check_len); |
| 1535 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1536 | curproxy->check_len = defproxy.check_len; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1537 | |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 1538 | if (defproxy.expect_str) { |
| 1539 | curproxy->expect_str = strdup(defproxy.expect_str); |
| 1540 | if (defproxy.expect_regex) { |
| 1541 | /* note: this regex is known to be valid */ |
| 1542 | curproxy->expect_regex = calloc(1, sizeof(regex_t)); |
| 1543 | regcomp(curproxy->expect_regex, defproxy.expect_str, REG_EXTENDED); |
| 1544 | } |
| 1545 | } |
| 1546 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 1547 | curproxy->ck_opts = defproxy.ck_opts; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1548 | if (defproxy.cookie_name) |
| 1549 | curproxy->cookie_name = strdup(defproxy.cookie_name); |
| 1550 | curproxy->cookie_len = defproxy.cookie_len; |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 1551 | if (defproxy.cookie_domain) |
| 1552 | curproxy->cookie_domain = strdup(defproxy.cookie_domain); |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 1553 | |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 1554 | if (defproxy.cookie_maxidle) |
| 1555 | curproxy->cookie_maxidle = defproxy.cookie_maxidle; |
| 1556 | |
| 1557 | if (defproxy.cookie_maxlife) |
| 1558 | curproxy->cookie_maxlife = defproxy.cookie_maxlife; |
| 1559 | |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 1560 | if (defproxy.rdp_cookie_name) |
| 1561 | curproxy->rdp_cookie_name = strdup(defproxy.rdp_cookie_name); |
| 1562 | curproxy->rdp_cookie_len = defproxy.rdp_cookie_len; |
| 1563 | |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 1564 | if (defproxy.url_param_name) |
| 1565 | curproxy->url_param_name = strdup(defproxy.url_param_name); |
| 1566 | curproxy->url_param_len = defproxy.url_param_len; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 1567 | |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 1568 | if (defproxy.hh_name) |
| 1569 | curproxy->hh_name = strdup(defproxy.hh_name); |
| 1570 | curproxy->hh_len = defproxy.hh_len; |
| 1571 | curproxy->hh_match_domain = defproxy.hh_match_domain; |
| 1572 | |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 1573 | if (defproxy.iface_name) |
| 1574 | curproxy->iface_name = strdup(defproxy.iface_name); |
| 1575 | curproxy->iface_len = defproxy.iface_len; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1576 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1577 | |
Willy Tarreau | 3b6b1a9 | 2009-07-23 13:24:23 +0200 | [diff] [blame] | 1578 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1579 | if (defproxy.capture_name) |
| 1580 | curproxy->capture_name = strdup(defproxy.capture_name); |
| 1581 | curproxy->capture_namelen = defproxy.capture_namelen; |
| 1582 | curproxy->capture_len = defproxy.capture_len; |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 1583 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1584 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1585 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 1586 | curproxy->timeout.client = defproxy.timeout.client; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 1587 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | 036fae0 | 2008-01-06 13:24:40 +0100 | [diff] [blame] | 1588 | curproxy->timeout.httpreq = defproxy.timeout.httpreq; |
Willy Tarreau | b16a574 | 2010-01-10 14:46:16 +0100 | [diff] [blame] | 1589 | curproxy->timeout.httpka = defproxy.timeout.httpka; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1590 | curproxy->uri_auth = defproxy.uri_auth; |
| 1591 | curproxy->mon_net = defproxy.mon_net; |
| 1592 | curproxy->mon_mask = defproxy.mon_mask; |
| 1593 | if (defproxy.monitor_uri) |
| 1594 | curproxy->monitor_uri = strdup(defproxy.monitor_uri); |
| 1595 | curproxy->monitor_uri_len = defproxy.monitor_uri_len; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 1596 | if (defproxy.defbe.name) |
| 1597 | curproxy->defbe.name = strdup(defproxy.defbe.name); |
Willy Tarreau | 99a7ca2 | 2012-05-31 19:39:23 +0200 | [diff] [blame] | 1598 | |
| 1599 | /* get either a pointer to the logformat string or a copy of it */ |
| 1600 | curproxy->logformat_string = defproxy.logformat_string; |
| 1601 | if (curproxy->logformat_string && |
| 1602 | curproxy->logformat_string != default_http_log_format && |
| 1603 | curproxy->logformat_string != default_tcp_log_format && |
| 1604 | curproxy->logformat_string != clf_http_log_format) |
| 1605 | curproxy->logformat_string = strdup(curproxy->logformat_string); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1606 | } |
| 1607 | |
| 1608 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 1609 | curproxy->timeout.connect = defproxy.timeout.connect; |
| 1610 | curproxy->timeout.server = defproxy.timeout.server; |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 1611 | curproxy->timeout.check = defproxy.timeout.check; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 1612 | curproxy->timeout.queue = defproxy.timeout.queue; |
Willy Tarreau | 51c9bde | 2008-01-06 13:40:03 +0100 | [diff] [blame] | 1613 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | cd7afc0 | 2009-07-12 10:03:17 +0200 | [diff] [blame] | 1614 | curproxy->timeout.httpreq = defproxy.timeout.httpreq; |
Willy Tarreau | b16a574 | 2010-01-10 14:46:16 +0100 | [diff] [blame] | 1615 | curproxy->timeout.httpka = defproxy.timeout.httpka; |
Willy Tarreau | ce887fd | 2012-05-12 12:50:00 +0200 | [diff] [blame] | 1616 | curproxy->timeout.tunnel = defproxy.timeout.tunnel; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1617 | curproxy->source_addr = defproxy.source_addr; |
| 1618 | } |
| 1619 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1620 | curproxy->mode = defproxy.mode; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1621 | |
| 1622 | /* copy default logsrvs to curproxy */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 1623 | list_for_each_entry(tmplogsrv, &defproxy.logsrvs, list) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1624 | struct logsrv *node = malloc(sizeof(struct logsrv)); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 1625 | memcpy(node, tmplogsrv, sizeof(struct logsrv)); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1626 | LIST_INIT(&node->list); |
| 1627 | LIST_ADDQ(&curproxy->logsrvs, &node->list); |
| 1628 | } |
| 1629 | |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 1630 | curproxy->uniqueid_format_string = defproxy.uniqueid_format_string; |
| 1631 | if (curproxy->uniqueid_format_string) |
| 1632 | curproxy->uniqueid_format_string = strdup(curproxy->uniqueid_format_string); |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 1633 | |
| 1634 | /* copy default header unique id */ |
| 1635 | if (defproxy.header_unique_id) |
| 1636 | curproxy->header_unique_id = strdup(defproxy.header_unique_id); |
| 1637 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1638 | curproxy->grace = defproxy.grace; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1639 | curproxy->conf.used_listener_id = EB_ROOT; |
| 1640 | curproxy->conf.used_server_id = EB_ROOT; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 1641 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1642 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1643 | } |
| 1644 | else if (!strcmp(args[0], "defaults")) { /* use this one to assign default values */ |
| 1645 | /* some variables may have already been initialized earlier */ |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 1646 | /* FIXME-20070101: we should do this too at the end of the |
| 1647 | * config parsing to free all default values. |
| 1648 | */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1649 | free(defproxy.check_req); |
| 1650 | free(defproxy.cookie_name); |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 1651 | free(defproxy.rdp_cookie_name); |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 1652 | free(defproxy.cookie_domain); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1653 | free(defproxy.url_param_name); |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 1654 | free(defproxy.hh_name); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1655 | free(defproxy.capture_name); |
| 1656 | free(defproxy.monitor_uri); |
| 1657 | free(defproxy.defbe.name); |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 1658 | free(defproxy.iface_name); |
Willy Tarreau | 79f5fe8 | 2008-08-23 08:18:21 +0200 | [diff] [blame] | 1659 | free(defproxy.fwdfor_hdr_name); |
| 1660 | defproxy.fwdfor_hdr_len = 0; |
Willy Tarreau | b86db34 | 2009-11-30 11:50:16 +0100 | [diff] [blame] | 1661 | free(defproxy.orgto_hdr_name); |
| 1662 | defproxy.orgto_hdr_len = 0; |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 1663 | free(defproxy.server_id_hdr_name); |
| 1664 | defproxy.server_id_hdr_len = 0; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 1665 | free(defproxy.expect_str); |
| 1666 | if (defproxy.expect_regex) regfree(defproxy.expect_regex); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 1667 | |
Willy Tarreau | 39b0665 | 2012-06-01 10:58:06 +0200 | [diff] [blame] | 1668 | if (defproxy.logformat_string != default_http_log_format && |
| 1669 | defproxy.logformat_string != default_tcp_log_format && |
| 1670 | defproxy.logformat_string != clf_http_log_format) |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 1671 | free(defproxy.logformat_string); |
| 1672 | |
| 1673 | free(defproxy.uniqueid_format_string); |
| 1674 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1675 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1676 | chunk_destroy(&defproxy.errmsg[rc]); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 1677 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1678 | /* we cannot free uri_auth because it might already be used */ |
| 1679 | init_default_instance(); |
| 1680 | curproxy = &defproxy; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1681 | defproxy.cap = PR_CAP_LISTEN; /* all caps for now */ |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1682 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1683 | } |
| 1684 | else if (curproxy == NULL) { |
| 1685 | Alert("parsing [%s:%d] : 'listen' or 'defaults' expected.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1686 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1687 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1688 | } |
| 1689 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1690 | |
| 1691 | /* Now let's parse the proxy-specific keywords */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1692 | if (!strcmp(args[0], "bind")) { /* new listen addresses */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1693 | struct listener *l; |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1694 | int cur_arg; |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 1695 | char *err_msg = NULL; |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1696 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1697 | if (curproxy == &defproxy) { |
| 1698 | 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] | 1699 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1700 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1701 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1702 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1703 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1704 | |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 1705 | if ( *(args[1]) != '/' && strchr(args[1], ':') == NULL) { |
Willy Tarreau | d55c3fe | 2010-11-09 09:50:37 +0100 | [diff] [blame] | 1706 | 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] | 1707 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1708 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1709 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1710 | } |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 1711 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 1712 | bind_conf = bind_conf_alloc(&curproxy->conf.bind, file, linenum, args[1]); |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1713 | 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] | 1714 | |
| 1715 | /* NOTE: the following line might create several listeners if there |
| 1716 | * are comma-separated IPs or port ranges. So all further processing |
| 1717 | * will have to be applied to all listeners created after last_listen. |
| 1718 | */ |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 1719 | if (!str2listener(args[1], curproxy, bind_conf, file, linenum, &err_msg)) { |
| 1720 | if (err_msg && *err_msg) { |
| 1721 | indent_msg(&err_msg, 2); |
| 1722 | Alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], err_msg); |
| 1723 | } |
| 1724 | else |
| 1725 | Alert("parsing [%s:%d] : '%s' : error encountered while parsing listening address '%s'.\n", |
| 1726 | file, linenum, args[0], args[1]); |
| 1727 | free(err_msg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1728 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1729 | goto out; |
| 1730 | } |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1731 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1732 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
| 1733 | /* Set default global rights and owner for unix bind */ |
Willy Tarreau | c8b1109 | 2011-02-16 11:08:57 +0100 | [diff] [blame] | 1734 | global.maxsock++; |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 1735 | } |
| 1736 | |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1737 | cur_arg = 2; |
| 1738 | while (*(args[cur_arg])) { |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 1739 | static int bind_dumped; |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 1740 | struct bind_kw *kw; |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 1741 | char *err; |
| 1742 | |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 1743 | kw = bind_find_kw(args[cur_arg]); |
| 1744 | if (kw) { |
| 1745 | char *err = NULL; |
| 1746 | int code; |
| 1747 | |
| 1748 | if (!kw->parse) { |
Willy Tarreau | dda322d | 2012-09-18 16:34:09 +0200 | [diff] [blame] | 1749 | Alert("parsing [%s:%d] : '%s %s' : '%s' option is not implemented in this version (check build options).\n", |
| 1750 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 1751 | cur_arg += 1 + kw->skip ; |
| 1752 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1753 | goto out; |
| 1754 | } |
| 1755 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1756 | code = kw->parse(args, cur_arg, curproxy, bind_conf, &err); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 1757 | err_code |= code; |
| 1758 | |
| 1759 | if (code) { |
| 1760 | if (err && *err) { |
| 1761 | indent_msg(&err, 2); |
Willy Tarreau | dda322d | 2012-09-18 16:34:09 +0200 | [diff] [blame] | 1762 | 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] | 1763 | } |
| 1764 | else |
Willy Tarreau | dda322d | 2012-09-18 16:34:09 +0200 | [diff] [blame] | 1765 | Alert("parsing [%s:%d] : '%s %s' : error encountered while processing '%s'.\n", |
| 1766 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 1767 | if (code & ERR_FATAL) { |
| 1768 | free(err); |
| 1769 | cur_arg += 1 + kw->skip; |
| 1770 | goto out; |
| 1771 | } |
| 1772 | } |
| 1773 | free(err); |
| 1774 | cur_arg += 1 + kw->skip; |
| 1775 | continue; |
| 1776 | } |
| 1777 | |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 1778 | err = NULL; |
| 1779 | if (!bind_dumped) { |
| 1780 | bind_dump_kws(&err); |
| 1781 | indent_msg(&err, 4); |
| 1782 | bind_dumped = 1; |
| 1783 | } |
| 1784 | |
| 1785 | Alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'.%s%s\n", |
| 1786 | file, linenum, args[0], args[1], args[cur_arg], |
| 1787 | err ? " Registered keywords :" : "", err ? err : ""); |
| 1788 | free(err); |
| 1789 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1790 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1791 | goto out; |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 1792 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1793 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1794 | } |
| 1795 | else if (!strcmp(args[0], "monitor-net")) { /* set the range of IPs to ignore */ |
| 1796 | if (!*args[1] || !str2net(args[1], &curproxy->mon_net, &curproxy->mon_mask)) { |
| 1797 | Alert("parsing [%s:%d] : '%s' expects address[/mask].\n", |
| 1798 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1799 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1800 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1801 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1802 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1803 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1804 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1805 | /* flush useless bits */ |
| 1806 | curproxy->mon_net.s_addr &= curproxy->mon_mask.s_addr; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1807 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1808 | } |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 1809 | else if (!strcmp(args[0], "monitor-uri")) { /* set the URI to intercept */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1810 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1811 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1812 | |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 1813 | if (!*args[1]) { |
| 1814 | Alert("parsing [%s:%d] : '%s' expects an URI.\n", |
| 1815 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1816 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1817 | goto out; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 1818 | } |
| 1819 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1820 | free(curproxy->monitor_uri); |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 1821 | curproxy->monitor_uri_len = strlen(args[1]); |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 1822 | curproxy->monitor_uri = (char *)calloc(1, curproxy->monitor_uri_len + 1); |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 1823 | memcpy(curproxy->monitor_uri, args[1], curproxy->monitor_uri_len); |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 1824 | curproxy->monitor_uri[curproxy->monitor_uri_len] = '\0'; |
| 1825 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1826 | goto out; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 1827 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1828 | else if (!strcmp(args[0], "mode")) { /* sets the proxy mode */ |
| 1829 | if (!strcmp(args[1], "http")) curproxy->mode = PR_MODE_HTTP; |
| 1830 | else if (!strcmp(args[1], "tcp")) curproxy->mode = PR_MODE_TCP; |
| 1831 | else if (!strcmp(args[1], "health")) curproxy->mode = PR_MODE_HEALTH; |
| 1832 | else { |
| 1833 | 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] | 1834 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1835 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1836 | } |
| 1837 | } |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 1838 | else if (!strcmp(args[0], "id")) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1839 | struct eb32_node *node; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 1840 | |
| 1841 | if (curproxy == &defproxy) { |
| 1842 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", |
| 1843 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1844 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1845 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 1846 | } |
| 1847 | |
| 1848 | if (!*args[1]) { |
| 1849 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 1850 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1851 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1852 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 1853 | } |
| 1854 | |
| 1855 | curproxy->uuid = atol(args[1]); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1856 | curproxy->conf.id.key = curproxy->uuid; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 1857 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1858 | if (curproxy->uuid <= 0) { |
| 1859 | Alert("parsing [%s:%d]: custom id has to be > 0.\n", |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 1860 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1861 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1862 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 1863 | } |
| 1864 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1865 | node = eb32_lookup(&used_proxy_id, curproxy->uuid); |
| 1866 | if (node) { |
| 1867 | struct proxy *target = container_of(node, struct proxy, conf.id); |
| 1868 | Alert("parsing [%s:%d]: %s %s reuses same custom id as %s %s (declared at %s:%d).\n", |
| 1869 | file, linenum, proxy_type_str(curproxy), curproxy->id, |
| 1870 | proxy_type_str(target), target->id, target->conf.file, target->conf.line); |
| 1871 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1872 | goto out; |
| 1873 | } |
| 1874 | eb32_insert(&used_proxy_id, &curproxy->conf.id); |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 1875 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1876 | else if (!strcmp(args[0], "description")) { |
| 1877 | int i, len=0; |
| 1878 | char *d; |
| 1879 | |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 1880 | if (curproxy == &defproxy) { |
| 1881 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", |
| 1882 | file, linenum, args[0]); |
| 1883 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1884 | goto out; |
| 1885 | } |
| 1886 | |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1887 | if (!*args[1]) { |
| 1888 | Alert("parsing [%s:%d]: '%s' expects a string argument.\n", |
| 1889 | file, linenum, args[0]); |
| 1890 | return -1; |
| 1891 | } |
| 1892 | |
| 1893 | for(i=1; *args[i]; i++) |
| 1894 | len += strlen(args[i])+1; |
| 1895 | |
| 1896 | d = (char *)calloc(1, len); |
| 1897 | curproxy->desc = d; |
| 1898 | |
| 1899 | d += sprintf(d, "%s", args[1]); |
| 1900 | for(i=2; *args[i]; i++) |
| 1901 | d += sprintf(d, " %s", args[i]); |
| 1902 | |
| 1903 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1904 | else if (!strcmp(args[0], "disabled")) { /* disables this proxy */ |
| 1905 | curproxy->state = PR_STSTOPPED; |
| 1906 | } |
| 1907 | else if (!strcmp(args[0], "enabled")) { /* enables this proxy (used to revert a disabled default) */ |
| 1908 | curproxy->state = PR_STNEW; |
| 1909 | } |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 1910 | else if (!strcmp(args[0], "bind-process")) { /* enable this proxy only on some processes */ |
| 1911 | int cur_arg = 1; |
| 1912 | unsigned int set = 0; |
| 1913 | |
| 1914 | while (*args[cur_arg]) { |
| 1915 | int u; |
| 1916 | if (strcmp(args[cur_arg], "all") == 0) { |
| 1917 | set = 0; |
| 1918 | break; |
| 1919 | } |
| 1920 | else if (strcmp(args[cur_arg], "odd") == 0) { |
| 1921 | set |= 0x55555555; |
| 1922 | } |
| 1923 | else if (strcmp(args[cur_arg], "even") == 0) { |
| 1924 | set |= 0xAAAAAAAA; |
| 1925 | } |
| 1926 | else { |
| 1927 | u = str2uic(args[cur_arg]); |
| 1928 | if (u < 1 || u > 32) { |
| 1929 | Alert("parsing [%s:%d]: %s expects 'all', 'odd', 'even', or process numbers from 1 to 32.\n", |
| 1930 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1931 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1932 | goto out; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 1933 | } |
| 1934 | if (u > global.nbproc) { |
| 1935 | Warning("parsing [%s:%d]: %s references process number higher than global.nbproc.\n", |
| 1936 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1937 | err_code |= ERR_WARN; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 1938 | } |
| 1939 | set |= 1 << (u - 1); |
| 1940 | } |
| 1941 | cur_arg++; |
| 1942 | } |
| 1943 | curproxy->bind_proc = set; |
| 1944 | } |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 1945 | else if (!strcmp(args[0], "acl")) { /* add an ACL */ |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 1946 | if (curproxy == &defproxy) { |
| 1947 | 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] | 1948 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1949 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 1950 | } |
| 1951 | |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 1952 | err = invalid_char(args[1]); |
| 1953 | if (err) { |
| 1954 | Alert("parsing [%s:%d] : character '%c' is not permitted in acl name '%s'.\n", |
| 1955 | file, linenum, *err, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1956 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 1957 | } |
| 1958 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 1959 | if (parse_acl((const char **)args + 1, &curproxy->acl, &errmsg) == NULL) { |
| 1960 | Alert("parsing [%s:%d] : error detected while parsing ACL '%s' : %s.\n", |
| 1961 | file, linenum, args[1], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1962 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1963 | goto out; |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 1964 | } |
| 1965 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1966 | else if (!strcmp(args[0], "cookie")) { /* cookie name */ |
| 1967 | int cur_arg; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1968 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1969 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1970 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1971 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1972 | if (*(args[1]) == 0) { |
| 1973 | Alert("parsing [%s:%d] : '%s' expects <cookie_name> as argument.\n", |
| 1974 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1975 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1976 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1977 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1978 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 1979 | curproxy->ck_opts = 0; |
Willy Tarreau | c63d4bb | 2010-10-23 11:37:27 +0200 | [diff] [blame] | 1980 | curproxy->cookie_maxidle = curproxy->cookie_maxlife = 0; |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 1981 | free(curproxy->cookie_domain); curproxy->cookie_domain = NULL; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1982 | free(curproxy->cookie_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1983 | curproxy->cookie_name = strdup(args[1]); |
| 1984 | curproxy->cookie_len = strlen(curproxy->cookie_name); |
Willy Tarreau | c63d4bb | 2010-10-23 11:37:27 +0200 | [diff] [blame] | 1985 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1986 | cur_arg = 2; |
| 1987 | while (*(args[cur_arg])) { |
| 1988 | if (!strcmp(args[cur_arg], "rewrite")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 1989 | curproxy->ck_opts |= PR_CK_RW; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1990 | } |
| 1991 | else if (!strcmp(args[cur_arg], "indirect")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 1992 | curproxy->ck_opts |= PR_CK_IND; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1993 | } |
| 1994 | else if (!strcmp(args[cur_arg], "insert")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 1995 | curproxy->ck_opts |= PR_CK_INS; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1996 | } |
| 1997 | else if (!strcmp(args[cur_arg], "nocache")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 1998 | curproxy->ck_opts |= PR_CK_NOC; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1999 | } |
| 2000 | else if (!strcmp(args[cur_arg], "postonly")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2001 | curproxy->ck_opts |= PR_CK_POST; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2002 | } |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 2003 | else if (!strcmp(args[cur_arg], "preserve")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2004 | curproxy->ck_opts |= PR_CK_PSV; |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 2005 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2006 | else if (!strcmp(args[cur_arg], "prefix")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2007 | curproxy->ck_opts |= PR_CK_PFX; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2008 | } |
Willy Tarreau | 4992dd2 | 2012-05-31 21:02:17 +0200 | [diff] [blame] | 2009 | else if (!strcmp(args[cur_arg], "httponly")) { |
| 2010 | curproxy->ck_opts |= PR_CK_HTTPONLY; |
| 2011 | } |
| 2012 | else if (!strcmp(args[cur_arg], "secure")) { |
| 2013 | curproxy->ck_opts |= PR_CK_SECURE; |
| 2014 | } |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2015 | else if (!strcmp(args[cur_arg], "domain")) { |
| 2016 | if (!*args[cur_arg + 1]) { |
| 2017 | Alert("parsing [%s:%d]: '%s' expects <domain> as argument.\n", |
| 2018 | file, linenum, args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2019 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2020 | goto out; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2021 | } |
| 2022 | |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 2023 | if (*args[cur_arg + 1] != '.' || !strchr(args[cur_arg + 1] + 1, '.')) { |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2024 | /* rfc2109, 4.3.2 Rejecting Cookies */ |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 2025 | Warning("parsing [%s:%d]: domain '%s' contains no embedded" |
| 2026 | " dots nor does not start with a dot." |
| 2027 | " RFC forbids it, this configuration may not work properly.\n", |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2028 | file, linenum, args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 2029 | err_code |= ERR_WARN; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2030 | } |
| 2031 | |
| 2032 | err = invalid_domainchar(args[cur_arg + 1]); |
| 2033 | if (err) { |
| 2034 | Alert("parsing [%s:%d]: character '%c' is not permitted in domain name '%s'.\n", |
| 2035 | file, linenum, *err, args[cur_arg + 1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2036 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2037 | goto out; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2038 | } |
| 2039 | |
Willy Tarreau | 68a897b | 2009-12-03 23:28:34 +0100 | [diff] [blame] | 2040 | if (!curproxy->cookie_domain) { |
| 2041 | curproxy->cookie_domain = strdup(args[cur_arg + 1]); |
| 2042 | } else { |
| 2043 | /* one domain was already specified, add another one by |
| 2044 | * building the string which will be returned along with |
| 2045 | * the cookie. |
| 2046 | */ |
| 2047 | char *new_ptr; |
| 2048 | int new_len = strlen(curproxy->cookie_domain) + |
| 2049 | strlen("; domain=") + strlen(args[cur_arg + 1]) + 1; |
| 2050 | new_ptr = malloc(new_len); |
| 2051 | snprintf(new_ptr, new_len, "%s; domain=%s", curproxy->cookie_domain, args[cur_arg+1]); |
| 2052 | free(curproxy->cookie_domain); |
| 2053 | curproxy->cookie_domain = new_ptr; |
| 2054 | } |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 2055 | cur_arg++; |
| 2056 | } |
| 2057 | else if (!strcmp(args[cur_arg], "maxidle")) { |
| 2058 | unsigned int maxidle; |
| 2059 | const char *res; |
| 2060 | |
| 2061 | if (!*args[cur_arg + 1]) { |
| 2062 | Alert("parsing [%s:%d]: '%s' expects <idletime> in seconds as argument.\n", |
| 2063 | file, linenum, args[cur_arg]); |
| 2064 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2065 | goto out; |
| 2066 | } |
| 2067 | |
| 2068 | res = parse_time_err(args[cur_arg + 1], &maxidle, TIME_UNIT_S); |
| 2069 | if (res) { |
| 2070 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 2071 | file, linenum, *res, args[cur_arg]); |
| 2072 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2073 | goto out; |
| 2074 | } |
| 2075 | curproxy->cookie_maxidle = maxidle; |
| 2076 | cur_arg++; |
| 2077 | } |
| 2078 | else if (!strcmp(args[cur_arg], "maxlife")) { |
| 2079 | unsigned int maxlife; |
| 2080 | const char *res; |
| 2081 | |
| 2082 | if (!*args[cur_arg + 1]) { |
| 2083 | Alert("parsing [%s:%d]: '%s' expects <lifetime> in seconds as argument.\n", |
| 2084 | file, linenum, args[cur_arg]); |
| 2085 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2086 | goto out; |
| 2087 | } |
| 2088 | |
| 2089 | res = parse_time_err(args[cur_arg + 1], &maxlife, TIME_UNIT_S); |
| 2090 | if (res) { |
| 2091 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 2092 | file, linenum, *res, args[cur_arg]); |
| 2093 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2094 | goto out; |
| 2095 | } |
| 2096 | curproxy->cookie_maxlife = maxlife; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2097 | cur_arg++; |
| 2098 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2099 | else { |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 2100 | 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] | 2101 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2102 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2103 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2104 | } |
| 2105 | cur_arg++; |
| 2106 | } |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2107 | if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_IND))) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2108 | Alert("parsing [%s:%d] : cookie 'rewrite' and 'indirect' modes are incompatible.\n", |
| 2109 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2110 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2111 | } |
| 2112 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2113 | 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] | 2114 | Alert("parsing [%s:%d] : cookie 'rewrite', 'insert' and 'prefix' modes are incompatible.\n", |
| 2115 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2116 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2117 | } |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 2118 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2119 | 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] | 2120 | Alert("parsing [%s:%d] : cookie 'preserve' requires at least 'insert' or 'indirect'.\n", |
| 2121 | file, linenum); |
| 2122 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2123 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2124 | }/* end else if (!strcmp(args[0], "cookie")) */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2125 | else if (!strcmp(args[0], "persist")) { /* persist */ |
| 2126 | if (*(args[1]) == 0) { |
| 2127 | Alert("parsing [%s:%d] : missing persist method.\n", |
| 2128 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2129 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2130 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2131 | } |
| 2132 | |
| 2133 | if (!strncmp(args[1], "rdp-cookie", 10)) { |
| 2134 | curproxy->options2 |= PR_O2_RDPC_PRST; |
| 2135 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2136 | if (*(args[1] + 10) == '(') { /* cookie name */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2137 | const char *beg, *end; |
| 2138 | |
| 2139 | beg = args[1] + 11; |
| 2140 | end = strchr(beg, ')'); |
| 2141 | |
| 2142 | if (!end || end == beg) { |
| 2143 | Alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n", |
| 2144 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2145 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2146 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2147 | } |
| 2148 | |
| 2149 | free(curproxy->rdp_cookie_name); |
| 2150 | curproxy->rdp_cookie_name = my_strndup(beg, end - beg); |
| 2151 | curproxy->rdp_cookie_len = end-beg; |
| 2152 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2153 | else if (*(args[1] + 10) == '\0') { /* default cookie name 'msts' */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2154 | free(curproxy->rdp_cookie_name); |
| 2155 | curproxy->rdp_cookie_name = strdup("msts"); |
| 2156 | curproxy->rdp_cookie_len = strlen(curproxy->rdp_cookie_name); |
| 2157 | } |
| 2158 | else { /* syntax */ |
| 2159 | Alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n", |
| 2160 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2161 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2162 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2163 | } |
| 2164 | } |
| 2165 | else { |
| 2166 | Alert("parsing [%s:%d] : unknown persist method.\n", |
| 2167 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2168 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2169 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2170 | } |
| 2171 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2172 | else if (!strcmp(args[0], "appsession")) { /* cookie name */ |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2173 | int cur_arg; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2174 | |
Cyril Bonté | 3b7a369 | 2010-01-10 17:01:47 +0100 | [diff] [blame] | 2175 | if (curproxy == &defproxy) { |
| 2176 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2177 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2178 | goto out; |
| 2179 | } |
| 2180 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2181 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2182 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2183 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2184 | if (*(args[5]) == 0) { |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2185 | 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] | 2186 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2187 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2188 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2189 | } |
| 2190 | have_appsession = 1; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2191 | free(curproxy->appsession_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2192 | curproxy->appsession_name = strdup(args[1]); |
| 2193 | curproxy->appsession_name_len = strlen(curproxy->appsession_name); |
| 2194 | curproxy->appsession_len = atoi(args[3]); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 2195 | err = parse_time_err(args[5], &val, TIME_UNIT_MS); |
| 2196 | if (err) { |
| 2197 | Alert("parsing [%s:%d] : unexpected character '%c' in %s timeout.\n", |
| 2198 | file, linenum, *err, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2199 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2200 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 2201 | } |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 2202 | curproxy->timeout.appsession = val; |
Willy Tarreau | ee99136 | 2007-05-14 14:37:50 +0200 | [diff] [blame] | 2203 | |
Willy Tarreau | 51041c7 | 2007-09-09 21:56:53 +0200 | [diff] [blame] | 2204 | if (appsession_hash_init(&(curproxy->htbl_proxy), destroy) == 0) { |
| 2205 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2206 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2207 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2208 | } |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2209 | |
| 2210 | cur_arg = 6; |
| 2211 | curproxy->options2 &= ~PR_O2_AS_REQL; |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2212 | curproxy->options2 &= ~PR_O2_AS_M_ANY; |
| 2213 | curproxy->options2 |= PR_O2_AS_M_PP; |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2214 | while (*(args[cur_arg])) { |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2215 | if (!strcmp(args[cur_arg], "request-learn")) { |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2216 | curproxy->options2 |= PR_O2_AS_REQL; |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2217 | } else if (!strcmp(args[cur_arg], "prefix")) { |
| 2218 | curproxy->options2 |= PR_O2_AS_PFX; |
| 2219 | } else if (!strcmp(args[cur_arg], "mode")) { |
| 2220 | if (!*args[cur_arg + 1]) { |
| 2221 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 2222 | file, linenum, args[0], args[cur_arg]); |
| 2223 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2224 | goto out; |
| 2225 | } |
| 2226 | |
| 2227 | cur_arg++; |
| 2228 | if (!strcmp(args[cur_arg], "query-string")) { |
| 2229 | curproxy->options2 &= ~PR_O2_AS_M_ANY; |
| 2230 | curproxy->options2 |= PR_O2_AS_M_QS; |
| 2231 | } else if (!strcmp(args[cur_arg], "path-parameters")) { |
| 2232 | curproxy->options2 &= ~PR_O2_AS_M_ANY; |
| 2233 | curproxy->options2 |= PR_O2_AS_M_PP; |
| 2234 | } else { |
| 2235 | Alert("parsing [%s:%d] : unknown mode '%s'\n", file, linenum, args[cur_arg]); |
| 2236 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2237 | goto out; |
| 2238 | } |
| 2239 | } |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2240 | cur_arg++; |
| 2241 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2242 | } /* Url App Session */ |
| 2243 | else if (!strcmp(args[0], "capture")) { |
Willy Tarreau | 3b6b1a9 | 2009-07-23 13:24:23 +0200 | [diff] [blame] | 2244 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2245 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2246 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2247 | if (!strcmp(args[1], "cookie")) { /* name of a cookie to capture */ |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 2248 | if (curproxy == &defproxy) { |
| 2249 | Alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
| 2250 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2251 | goto out; |
| 2252 | } |
| 2253 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2254 | if (*(args[4]) == 0) { |
| 2255 | Alert("parsing [%s:%d] : '%s' expects 'cookie' <cookie_name> 'len' <len>.\n", |
| 2256 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2257 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2258 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2259 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2260 | free(curproxy->capture_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2261 | curproxy->capture_name = strdup(args[2]); |
| 2262 | curproxy->capture_namelen = strlen(curproxy->capture_name); |
| 2263 | curproxy->capture_len = atol(args[4]); |
| 2264 | if (curproxy->capture_len >= CAPTURE_LEN) { |
| 2265 | Warning("parsing [%s:%d] : truncating capture length to %d bytes.\n", |
| 2266 | file, linenum, CAPTURE_LEN - 1); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2267 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2268 | curproxy->capture_len = CAPTURE_LEN - 1; |
| 2269 | } |
| 2270 | curproxy->to_log |= LW_COOKIE; |
| 2271 | } |
| 2272 | else if (!strcmp(args[1], "request") && !strcmp(args[2], "header")) { |
| 2273 | struct cap_hdr *hdr; |
| 2274 | |
| 2275 | if (curproxy == &defproxy) { |
| 2276 | 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] | 2277 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2278 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2279 | } |
| 2280 | |
| 2281 | if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) { |
| 2282 | Alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n", |
| 2283 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2284 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2285 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2286 | } |
| 2287 | |
| 2288 | hdr = calloc(sizeof(struct cap_hdr), 1); |
| 2289 | hdr->next = curproxy->req_cap; |
| 2290 | hdr->name = strdup(args[3]); |
| 2291 | hdr->namelen = strlen(args[3]); |
| 2292 | hdr->len = atol(args[5]); |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 2293 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2294 | hdr->index = curproxy->nb_req_cap++; |
| 2295 | curproxy->req_cap = hdr; |
| 2296 | curproxy->to_log |= LW_REQHDR; |
| 2297 | } |
| 2298 | else if (!strcmp(args[1], "response") && !strcmp(args[2], "header")) { |
| 2299 | struct cap_hdr *hdr; |
| 2300 | |
| 2301 | if (curproxy == &defproxy) { |
| 2302 | 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] | 2303 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2304 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2305 | } |
| 2306 | |
| 2307 | if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) { |
| 2308 | Alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n", |
| 2309 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2310 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2311 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2312 | } |
| 2313 | hdr = calloc(sizeof(struct cap_hdr), 1); |
| 2314 | hdr->next = curproxy->rsp_cap; |
| 2315 | hdr->name = strdup(args[3]); |
| 2316 | hdr->namelen = strlen(args[3]); |
| 2317 | hdr->len = atol(args[5]); |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 2318 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2319 | hdr->index = curproxy->nb_rsp_cap++; |
| 2320 | curproxy->rsp_cap = hdr; |
| 2321 | curproxy->to_log |= LW_RSPHDR; |
| 2322 | } |
| 2323 | else { |
| 2324 | Alert("parsing [%s:%d] : '%s' expects 'cookie' or 'request header' or 'response header'.\n", |
| 2325 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2326 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2327 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2328 | } |
| 2329 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2330 | else if (!strcmp(args[0], "retries")) { /* connection retries */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2331 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2332 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2333 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2334 | if (*(args[1]) == 0) { |
| 2335 | Alert("parsing [%s:%d] : '%s' expects an integer argument (dispatch counts for one).\n", |
| 2336 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2337 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2338 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2339 | } |
| 2340 | curproxy->conn_retries = atol(args[1]); |
| 2341 | } |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2342 | 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] | 2343 | struct http_req_rule *rule; |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2344 | |
| 2345 | if (curproxy == &defproxy) { |
| 2346 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2347 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2348 | goto out; |
| 2349 | } |
| 2350 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 2351 | 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] | 2352 | Warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n", |
| 2353 | file, linenum, args[0]); |
| 2354 | err_code |= ERR_WARN; |
| 2355 | } |
| 2356 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 2357 | 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] | 2358 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 2359 | if (!rule) { |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2360 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2361 | goto out; |
| 2362 | } |
| 2363 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 2364 | err_code |= warnif_cond_requires_resp(rule->cond, file, linenum); |
| 2365 | LIST_ADDQ(&curproxy->http_req_rules, &rule->list); |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2366 | } |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 2367 | else if (!strcmp(args[0], "http-send-name-header")) { /* send server name in request header */ |
| 2368 | /* set the header name and length into the proxy structure */ |
| 2369 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 2370 | err_code |= ERR_WARN; |
| 2371 | |
| 2372 | if (!*args[1]) { |
| 2373 | Alert("parsing [%s:%d] : '%s' requires a header string.\n", |
| 2374 | file, linenum, args[0]); |
| 2375 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2376 | goto out; |
| 2377 | } |
| 2378 | |
| 2379 | /* set the desired header name */ |
| 2380 | free(curproxy->server_id_hdr_name); |
| 2381 | curproxy->server_id_hdr_name = strdup(args[1]); |
| 2382 | curproxy->server_id_hdr_len = strlen(curproxy->server_id_hdr_name); |
| 2383 | } |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2384 | else if (!strcmp(args[0], "block")) { /* early blocking based on ACLs */ |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2385 | if (curproxy == &defproxy) { |
| 2386 | 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] | 2387 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2388 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2389 | } |
| 2390 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2391 | if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) { |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2392 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 2393 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2394 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2395 | goto out; |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2396 | } |
| 2397 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 2398 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 1, &errmsg)) == NULL) { |
| 2399 | Alert("parsing [%s:%d] : error detected while parsing blocking condition : %s.\n", |
| 2400 | file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2401 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2402 | goto out; |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2403 | } |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2404 | |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2405 | LIST_ADDQ(&curproxy->block_cond, &cond->list); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 2406 | warnif_misplaced_block(curproxy, file, linenum, args[0]); |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2407 | } |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2408 | else if (!strcmp(args[0], "redirect")) { |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2409 | struct redirect_rule *rule; |
| 2410 | int cur_arg; |
| 2411 | int type = REDIRECT_TYPE_NONE; |
| 2412 | int code = 302; |
| 2413 | char *destination = NULL; |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2414 | char *cookie = NULL; |
| 2415 | int cookie_set = 0; |
Willy Tarreau | 79da469 | 2008-11-19 20:03:04 +0100 | [diff] [blame] | 2416 | unsigned int flags = REDIRECT_FLAG_NONE; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2417 | |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 2418 | if (curproxy == &defproxy) { |
| 2419 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2420 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2421 | goto out; |
| 2422 | } |
| 2423 | |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2424 | cur_arg = 1; |
| 2425 | while (*(args[cur_arg])) { |
| 2426 | if (!strcmp(args[cur_arg], "location")) { |
| 2427 | if (!*args[cur_arg + 1]) { |
| 2428 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 2429 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2430 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2431 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2432 | } |
| 2433 | |
| 2434 | type = REDIRECT_TYPE_LOCATION; |
| 2435 | cur_arg++; |
| 2436 | destination = args[cur_arg]; |
| 2437 | } |
| 2438 | else if (!strcmp(args[cur_arg], "prefix")) { |
| 2439 | if (!*args[cur_arg + 1]) { |
| 2440 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 2441 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2442 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2443 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2444 | } |
| 2445 | |
| 2446 | type = REDIRECT_TYPE_PREFIX; |
| 2447 | cur_arg++; |
| 2448 | destination = args[cur_arg]; |
| 2449 | } |
Willy Tarreau | 2e1dca8 | 2012-09-12 08:43:15 +0200 | [diff] [blame] | 2450 | else if (!strcmp(args[cur_arg], "scheme")) { |
| 2451 | if (!*args[cur_arg + 1]) { |
| 2452 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 2453 | file, linenum, args[0], args[cur_arg]); |
| 2454 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2455 | goto out; |
| 2456 | } |
| 2457 | |
| 2458 | type = REDIRECT_TYPE_SCHEME; |
| 2459 | cur_arg++; |
| 2460 | destination = args[cur_arg]; |
| 2461 | } |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2462 | else if (!strcmp(args[cur_arg], "set-cookie")) { |
| 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 | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2468 | } |
| 2469 | |
| 2470 | cur_arg++; |
| 2471 | cookie = args[cur_arg]; |
| 2472 | cookie_set = 1; |
| 2473 | } |
| 2474 | else if (!strcmp(args[cur_arg], "clear-cookie")) { |
| 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 | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2480 | } |
| 2481 | |
| 2482 | cur_arg++; |
| 2483 | cookie = args[cur_arg]; |
| 2484 | cookie_set = 0; |
| 2485 | } |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2486 | else if (!strcmp(args[cur_arg],"code")) { |
| 2487 | if (!*args[cur_arg + 1]) { |
| 2488 | Alert("parsing [%s:%d] : '%s': missing HTTP code.\n", |
| 2489 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2490 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2491 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2492 | } |
| 2493 | cur_arg++; |
| 2494 | code = atol(args[cur_arg]); |
| 2495 | if (code < 301 || code > 303) { |
| 2496 | Alert("parsing [%s:%d] : '%s': unsupported HTTP code '%d'.\n", |
| 2497 | file, linenum, args[0], code); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2498 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2499 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2500 | } |
| 2501 | } |
Willy Tarreau | 79da469 | 2008-11-19 20:03:04 +0100 | [diff] [blame] | 2502 | else if (!strcmp(args[cur_arg],"drop-query")) { |
| 2503 | flags |= REDIRECT_FLAG_DROP_QS; |
| 2504 | } |
Willy Tarreau | 81e3b4f | 2010-01-10 00:42:19 +0100 | [diff] [blame] | 2505 | else if (!strcmp(args[cur_arg],"append-slash")) { |
| 2506 | flags |= REDIRECT_FLAG_APPEND_SLASH; |
| 2507 | } |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2508 | else if (strcmp(args[cur_arg], "if") == 0 || |
| 2509 | strcmp(args[cur_arg], "unless") == 0) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 2510 | 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] | 2511 | if (!cond) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 2512 | Alert("parsing [%s:%d] : '%s': error detected while parsing redirect condition : %s.\n", |
| 2513 | file, linenum, args[0], errmsg); |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2514 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2515 | goto out; |
| 2516 | } |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2517 | break; |
| 2518 | } |
| 2519 | else { |
Willy Tarreau | 2e1dca8 | 2012-09-12 08:43:15 +0200 | [diff] [blame] | 2520 | 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] | 2521 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2522 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2523 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2524 | } |
| 2525 | cur_arg++; |
| 2526 | } |
| 2527 | |
| 2528 | if (type == REDIRECT_TYPE_NONE) { |
| 2529 | Alert("parsing [%s:%d] : '%s' expects a redirection type ('prefix' or 'location').\n", |
| 2530 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2531 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2532 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2533 | } |
| 2534 | |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2535 | rule = (struct redirect_rule *)calloc(1, sizeof(*rule)); |
| 2536 | rule->cond = cond; |
| 2537 | rule->rdr_str = strdup(destination); |
| 2538 | rule->rdr_len = strlen(destination); |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2539 | if (cookie) { |
| 2540 | /* 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] | 2541 | * a clear consists in appending "; path=/; Max-Age=0;" at the end. |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2542 | */ |
| 2543 | rule->cookie_len = strlen(cookie); |
William Turner | d986526 | 2010-03-01 13:30:34 -0500 | [diff] [blame] | 2544 | if (cookie_set) { |
| 2545 | rule->cookie_str = malloc(rule->cookie_len + 10); |
| 2546 | memcpy(rule->cookie_str, cookie, rule->cookie_len); |
| 2547 | memcpy(rule->cookie_str + rule->cookie_len, "; path=/;", 10); |
| 2548 | rule->cookie_len += 9; |
| 2549 | } else { |
| 2550 | rule->cookie_str = malloc(rule->cookie_len + 21); |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2551 | memcpy(rule->cookie_str, cookie, rule->cookie_len); |
William Turner | d986526 | 2010-03-01 13:30:34 -0500 | [diff] [blame] | 2552 | memcpy(rule->cookie_str + rule->cookie_len, "; path=/; Max-Age=0;", 21); |
| 2553 | rule->cookie_len += 20; |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2554 | } |
| 2555 | } |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2556 | rule->type = type; |
| 2557 | rule->code = code; |
Willy Tarreau | 79da469 | 2008-11-19 20:03:04 +0100 | [diff] [blame] | 2558 | rule->flags = flags; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2559 | LIST_INIT(&rule->list); |
| 2560 | LIST_ADDQ(&curproxy->redirect_rules, &rule->list); |
Willy Tarreau | 9d9ed01 | 2011-02-23 15:24:42 +0100 | [diff] [blame] | 2561 | err_code |= warnif_rule_after_use_backend(curproxy, file, linenum, args[0]); |
| 2562 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2563 | } |
Krzysztof Piotr Oledzki | 7b723ef | 2009-01-27 21:09:41 +0100 | [diff] [blame] | 2564 | else if (!strcmp(args[0], "use_backend")) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2565 | struct switching_rule *rule; |
| 2566 | |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2567 | if (curproxy == &defproxy) { |
| 2568 | 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] | 2569 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2570 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2571 | } |
| 2572 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2573 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2574 | err_code |= ERR_WARN; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2575 | |
| 2576 | if (*(args[1]) == 0) { |
| 2577 | 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] | 2578 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2579 | goto out; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2580 | } |
| 2581 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2582 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2583 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 2584 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2585 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2586 | goto out; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2587 | } |
| 2588 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 2589 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 2590 | Alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n", |
| 2591 | file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2592 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2593 | goto out; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2594 | } |
| 2595 | |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 2596 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
Willy Tarreau | a980263 | 2008-07-25 19:13:19 +0200 | [diff] [blame] | 2597 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2598 | rule = (struct switching_rule *)calloc(1, sizeof(*rule)); |
| 2599 | rule->cond = cond; |
| 2600 | rule->be.name = strdup(args[1]); |
| 2601 | LIST_INIT(&rule->list); |
| 2602 | LIST_ADDQ(&curproxy->switching_rules, &rule->list); |
| 2603 | } |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 2604 | else if (strcmp(args[0], "use-server") == 0) { |
| 2605 | struct server_rule *rule; |
| 2606 | |
| 2607 | if (curproxy == &defproxy) { |
| 2608 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2609 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2610 | goto out; |
| 2611 | } |
| 2612 | |
| 2613 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 2614 | err_code |= ERR_WARN; |
| 2615 | |
| 2616 | if (*(args[1]) == 0) { |
| 2617 | Alert("parsing [%s:%d] : '%s' expects a server name.\n", file, linenum, args[0]); |
| 2618 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2619 | goto out; |
| 2620 | } |
| 2621 | |
| 2622 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
| 2623 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 2624 | file, linenum, args[0]); |
| 2625 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2626 | goto out; |
| 2627 | } |
| 2628 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 2629 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 2630 | Alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n", |
| 2631 | file, linenum, errmsg); |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 2632 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2633 | goto out; |
| 2634 | } |
| 2635 | |
| 2636 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
| 2637 | |
| 2638 | rule = (struct server_rule *)calloc(1, sizeof(*rule)); |
| 2639 | rule->cond = cond; |
| 2640 | rule->srv.name = strdup(args[1]); |
| 2641 | LIST_INIT(&rule->list); |
| 2642 | LIST_ADDQ(&curproxy->server_rules, &rule->list); |
| 2643 | curproxy->be_req_ana |= AN_REQ_SRV_RULES; |
| 2644 | } |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 2645 | else if ((!strcmp(args[0], "force-persist")) || |
| 2646 | (!strcmp(args[0], "ignore-persist"))) { |
| 2647 | struct persist_rule *rule; |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2648 | |
| 2649 | if (curproxy == &defproxy) { |
| 2650 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2651 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2652 | goto out; |
| 2653 | } |
| 2654 | |
| 2655 | if (warnifnotcap(curproxy, PR_CAP_FE|PR_CAP_BE, file, linenum, args[0], NULL)) |
| 2656 | err_code |= ERR_WARN; |
| 2657 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2658 | if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) { |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 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 + 1, &errmsg)) == NULL) { |
| 2666 | Alert("parsing [%s:%d] : error detected while parsing a '%s' rule : %s.\n", |
| 2667 | file, linenum, args[0], errmsg); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2668 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2669 | goto out; |
| 2670 | } |
| 2671 | |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 2672 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2673 | |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 2674 | rule = (struct persist_rule *)calloc(1, sizeof(*rule)); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2675 | rule->cond = cond; |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 2676 | if (!strcmp(args[0], "force-persist")) { |
| 2677 | rule->type = PERSIST_TYPE_FORCE; |
| 2678 | } else { |
| 2679 | rule->type = PERSIST_TYPE_IGNORE; |
| 2680 | } |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2681 | LIST_INIT(&rule->list); |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 2682 | LIST_ADDQ(&curproxy->persist_rules, &rule->list); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2683 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2684 | else if (!strcmp(args[0], "stick-table")) { |
| 2685 | int myidx = 1; |
| 2686 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2687 | curproxy->table.id = curproxy->id; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2688 | curproxy->table.type = (unsigned int)-1; |
| 2689 | while (*args[myidx]) { |
| 2690 | const char *err; |
| 2691 | |
| 2692 | if (strcmp(args[myidx], "size") == 0) { |
| 2693 | myidx++; |
| 2694 | if (!*(args[myidx])) { |
| 2695 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 2696 | file, linenum, args[myidx-1]); |
| 2697 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2698 | goto out; |
| 2699 | } |
| 2700 | if ((err = parse_size_err(args[myidx], &curproxy->table.size))) { |
| 2701 | Alert("parsing [%s:%d] : stick-table: unexpected character '%c' in argument of '%s'.\n", |
| 2702 | file, linenum, *err, args[myidx-1]); |
| 2703 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2704 | goto out; |
| 2705 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 2706 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2707 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2708 | else if (strcmp(args[myidx], "peers") == 0) { |
| 2709 | myidx++; |
| 2710 | if (!*(args[myidx])) { |
| 2711 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 2712 | file, linenum, args[myidx-1]); |
| 2713 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2714 | goto out; |
| 2715 | } |
| 2716 | curproxy->table.peers.name = strdup(args[myidx++]); |
| 2717 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2718 | else if (strcmp(args[myidx], "expire") == 0) { |
| 2719 | myidx++; |
| 2720 | if (!*(args[myidx])) { |
| 2721 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 2722 | file, linenum, args[myidx-1]); |
| 2723 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2724 | goto out; |
| 2725 | } |
| 2726 | err = parse_time_err(args[myidx], &val, TIME_UNIT_MS); |
| 2727 | if (err) { |
| 2728 | Alert("parsing [%s:%d] : stick-table: unexpected character '%c' in argument of '%s'.\n", |
| 2729 | file, linenum, *err, args[myidx-1]); |
| 2730 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2731 | goto out; |
| 2732 | } |
| 2733 | curproxy->table.expire = val; |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 2734 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2735 | } |
| 2736 | else if (strcmp(args[myidx], "nopurge") == 0) { |
| 2737 | curproxy->table.nopurge = 1; |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 2738 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2739 | } |
| 2740 | else if (strcmp(args[myidx], "type") == 0) { |
| 2741 | myidx++; |
| 2742 | if (stktable_parse_type(args, &myidx, &curproxy->table.type, &curproxy->table.key_size) != 0) { |
| 2743 | Alert("parsing [%s:%d] : stick-table: unknown type '%s'.\n", |
| 2744 | file, linenum, args[myidx]); |
| 2745 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2746 | goto out; |
| 2747 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 2748 | /* myidx already points to next arg */ |
| 2749 | } |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 2750 | else if (strcmp(args[myidx], "store") == 0) { |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 2751 | int type, err; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 2752 | char *cw, *nw, *sa; |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 2753 | |
| 2754 | myidx++; |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 2755 | nw = args[myidx]; |
| 2756 | while (*nw) { |
| 2757 | /* the "store" keyword supports a comma-separated list */ |
| 2758 | cw = nw; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 2759 | sa = NULL; /* store arg */ |
| 2760 | while (*nw && *nw != ',') { |
| 2761 | if (*nw == '(') { |
| 2762 | *nw = 0; |
| 2763 | sa = ++nw; |
| 2764 | while (*nw != ')') { |
| 2765 | if (!*nw) { |
| 2766 | Alert("parsing [%s:%d] : %s: missing closing parenthesis after store option '%s'.\n", |
| 2767 | file, linenum, args[0], cw); |
| 2768 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2769 | goto out; |
| 2770 | } |
| 2771 | nw++; |
| 2772 | } |
| 2773 | *nw = '\0'; |
| 2774 | } |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 2775 | nw++; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 2776 | } |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 2777 | if (*nw) |
| 2778 | *nw++ = '\0'; |
| 2779 | type = stktable_get_data_type(cw); |
| 2780 | if (type < 0) { |
| 2781 | Alert("parsing [%s:%d] : %s: unknown store option '%s'.\n", |
| 2782 | file, linenum, args[0], cw); |
| 2783 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2784 | goto out; |
| 2785 | } |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 2786 | |
| 2787 | err = stktable_alloc_data_type(&curproxy->table, type, sa); |
| 2788 | switch (err) { |
| 2789 | case PE_NONE: break; |
| 2790 | case PE_EXIST: |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 2791 | Warning("parsing [%s:%d]: %s: store option '%s' already enabled, ignored.\n", |
| 2792 | file, linenum, args[0], cw); |
| 2793 | err_code |= ERR_WARN; |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 2794 | break; |
| 2795 | |
| 2796 | case PE_ARG_MISSING: |
| 2797 | Alert("parsing [%s:%d] : %s: missing argument to store option '%s'.\n", |
| 2798 | file, linenum, args[0], cw); |
| 2799 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2800 | goto out; |
| 2801 | |
| 2802 | case PE_ARG_NOT_USED: |
| 2803 | Alert("parsing [%s:%d] : %s: unexpected argument to store option '%s'.\n", |
| 2804 | file, linenum, args[0], cw); |
| 2805 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2806 | goto out; |
| 2807 | |
| 2808 | default: |
| 2809 | Alert("parsing [%s:%d] : %s: error when processing store option '%s'.\n", |
| 2810 | file, linenum, args[0], cw); |
| 2811 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2812 | goto out; |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 2813 | } |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 2814 | } |
| 2815 | myidx++; |
| 2816 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 2817 | else { |
| 2818 | Alert("parsing [%s:%d] : stick-table: unknown argument '%s'.\n", |
| 2819 | file, linenum, args[myidx]); |
| 2820 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2821 | goto out; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2822 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2823 | } |
| 2824 | |
| 2825 | if (!curproxy->table.size) { |
| 2826 | Alert("parsing [%s:%d] : stick-table: missing size.\n", |
| 2827 | file, linenum); |
| 2828 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2829 | goto out; |
| 2830 | } |
| 2831 | |
| 2832 | if (curproxy->table.type == (unsigned int)-1) { |
| 2833 | Alert("parsing [%s:%d] : stick-table: missing type.\n", |
| 2834 | file, linenum); |
| 2835 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2836 | goto out; |
| 2837 | } |
| 2838 | } |
| 2839 | else if (!strcmp(args[0], "stick")) { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2840 | struct sticking_rule *rule; |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 2841 | struct sample_expr *expr; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2842 | int myidx = 0; |
| 2843 | const char *name = NULL; |
| 2844 | int flags; |
| 2845 | |
| 2846 | if (curproxy == &defproxy) { |
| 2847 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2848 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2849 | goto out; |
| 2850 | } |
| 2851 | |
| 2852 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) { |
| 2853 | err_code |= ERR_WARN; |
| 2854 | goto out; |
| 2855 | } |
| 2856 | |
| 2857 | myidx++; |
| 2858 | if ((strcmp(args[myidx], "store") == 0) || |
| 2859 | (strcmp(args[myidx], "store-request") == 0)) { |
| 2860 | myidx++; |
| 2861 | flags = STK_IS_STORE; |
| 2862 | } |
| 2863 | else if (strcmp(args[myidx], "store-response") == 0) { |
| 2864 | myidx++; |
| 2865 | flags = STK_IS_STORE | STK_ON_RSP; |
| 2866 | } |
| 2867 | else if (strcmp(args[myidx], "match") == 0) { |
| 2868 | myidx++; |
| 2869 | flags = STK_IS_MATCH; |
| 2870 | } |
| 2871 | else if (strcmp(args[myidx], "on") == 0) { |
| 2872 | myidx++; |
| 2873 | flags = STK_IS_MATCH | STK_IS_STORE; |
| 2874 | } |
| 2875 | else { |
| 2876 | Alert("parsing [%s:%d] : '%s' expects 'on', 'match', or 'store'.\n", file, linenum, args[0]); |
| 2877 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2878 | goto out; |
| 2879 | } |
| 2880 | |
| 2881 | if (*(args[myidx]) == 0) { |
| 2882 | Alert("parsing [%s:%d] : '%s' expects a fetch method.\n", file, linenum, args[0]); |
| 2883 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2884 | goto out; |
| 2885 | } |
| 2886 | |
David du Colombier | 7af4605 | 2012-05-16 14:16:48 +0200 | [diff] [blame] | 2887 | expr = sample_parse_expr(args, &myidx, trash, trashlen); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2888 | if (!expr) { |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 2889 | Alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], trash); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2890 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2891 | goto out; |
| 2892 | } |
| 2893 | |
| 2894 | if (flags & STK_ON_RSP) { |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 2895 | if (!(expr->fetch->cap & SMP_CAP_RES)) { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2896 | Alert("parsing [%s:%d] : '%s': fetch method '%s' can not be used on response.\n", |
| 2897 | file, linenum, args[0], expr->fetch->kw); |
| 2898 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 2899 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2900 | goto out; |
| 2901 | } |
| 2902 | } else { |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 2903 | if (!(expr->fetch->cap & SMP_CAP_REQ)) { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2904 | Alert("parsing [%s:%d] : '%s': fetch method '%s' can not be used on request.\n", |
| 2905 | file, linenum, args[0], expr->fetch->kw); |
| 2906 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 2907 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2908 | goto out; |
| 2909 | } |
| 2910 | } |
| 2911 | |
| 2912 | if (strcmp(args[myidx], "table") == 0) { |
| 2913 | myidx++; |
| 2914 | name = args[myidx++]; |
| 2915 | } |
| 2916 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2917 | if (strcmp(args[myidx], "if") == 0 || strcmp(args[myidx], "unless") == 0) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 2918 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + myidx, &errmsg)) == NULL) { |
| 2919 | Alert("parsing [%s:%d] : '%s': error detected while parsing sticking condition : %s.\n", |
| 2920 | file, linenum, args[0], errmsg); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2921 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 2922 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2923 | goto out; |
| 2924 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2925 | } |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2926 | else if (*(args[myidx])) { |
| 2927 | Alert("parsing [%s:%d] : '%s': unknown keyword '%s'.\n", |
| 2928 | file, linenum, args[0], args[myidx]); |
| 2929 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 2930 | free(expr); |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2931 | goto out; |
| 2932 | } |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 2933 | if (flags & STK_ON_RSP) |
| 2934 | err_code |= warnif_cond_requires_req(cond, file, linenum); |
| 2935 | else |
| 2936 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 2937 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2938 | rule = (struct sticking_rule *)calloc(1, sizeof(*rule)); |
| 2939 | rule->cond = cond; |
| 2940 | rule->expr = expr; |
| 2941 | rule->flags = flags; |
| 2942 | rule->table.name = name ? strdup(name) : NULL; |
| 2943 | LIST_INIT(&rule->list); |
| 2944 | if (flags & STK_ON_RSP) |
| 2945 | LIST_ADDQ(&curproxy->storersp_rules, &rule->list); |
| 2946 | else |
| 2947 | LIST_ADDQ(&curproxy->sticking_rules, &rule->list); |
| 2948 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2949 | else if (!strcmp(args[0], "stats")) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2950 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2951 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2952 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2953 | if (curproxy != &defproxy && curproxy->uri_auth == defproxy.uri_auth) |
| 2954 | curproxy->uri_auth = NULL; /* we must detach from the default config */ |
| 2955 | |
Krzysztof Piotr Oledzki | 260a3bb | 2010-01-06 16:25:05 +0100 | [diff] [blame] | 2956 | if (!*args[1]) { |
| 2957 | goto stats_error_parsing; |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 2958 | } else if (!strcmp(args[1], "admin")) { |
| 2959 | struct stats_admin_rule *rule; |
| 2960 | |
| 2961 | if (curproxy == &defproxy) { |
| 2962 | Alert("parsing [%s:%d]: '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
| 2963 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2964 | goto out; |
| 2965 | } |
| 2966 | |
| 2967 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 2968 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 2969 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2970 | goto out; |
| 2971 | } |
| 2972 | |
| 2973 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
| 2974 | Alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n", |
| 2975 | file, linenum, args[0], args[1]); |
| 2976 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2977 | goto out; |
| 2978 | } |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 2979 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 2980 | Alert("parsing [%s:%d] : error detected while parsing a '%s %s' rule : %s.\n", |
| 2981 | file, linenum, args[0], args[1], errmsg); |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 2982 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2983 | goto out; |
| 2984 | } |
| 2985 | |
| 2986 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
| 2987 | |
| 2988 | rule = (struct stats_admin_rule *)calloc(1, sizeof(*rule)); |
| 2989 | rule->cond = cond; |
| 2990 | LIST_INIT(&rule->list); |
| 2991 | LIST_ADDQ(&curproxy->uri_auth->admin_rules, &rule->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2992 | } else if (!strcmp(args[1], "uri")) { |
| 2993 | if (*(args[2]) == 0) { |
| 2994 | Alert("parsing [%s:%d] : 'uri' needs an URI prefix.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2995 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2996 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2997 | } else if (!stats_set_uri(&curproxy->uri_auth, args[2])) { |
| 2998 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2999 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3000 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3001 | } |
| 3002 | } else if (!strcmp(args[1], "realm")) { |
| 3003 | if (*(args[2]) == 0) { |
| 3004 | Alert("parsing [%s:%d] : 'realm' needs an realm name.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3005 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3006 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3007 | } else if (!stats_set_realm(&curproxy->uri_auth, args[2])) { |
| 3008 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3009 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3010 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3011 | } |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 3012 | } else if (!strcmp(args[1], "refresh")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 3013 | unsigned interval; |
| 3014 | |
| 3015 | err = parse_time_err(args[2], &interval, TIME_UNIT_S); |
| 3016 | if (err) { |
| 3017 | Alert("parsing [%s:%d] : unexpected character '%c' in stats refresh interval.\n", |
| 3018 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3019 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3020 | goto out; |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 3021 | } else if (!stats_set_refresh(&curproxy->uri_auth, interval)) { |
| 3022 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3023 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3024 | goto out; |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 3025 | } |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3026 | } 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] | 3027 | struct http_req_rule *rule; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3028 | |
| 3029 | if (curproxy == &defproxy) { |
| 3030 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3031 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3032 | goto out; |
| 3033 | } |
| 3034 | |
| 3035 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 3036 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3037 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3038 | goto out; |
| 3039 | } |
| 3040 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3041 | if (!LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) && |
| 3042 | !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] | 3043 | Warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n", |
| 3044 | file, linenum, args[0]); |
| 3045 | err_code |= ERR_WARN; |
| 3046 | } |
| 3047 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3048 | 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] | 3049 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3050 | if (!rule) { |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3051 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3052 | goto out; |
| 3053 | } |
| 3054 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3055 | err_code |= warnif_cond_requires_resp(rule->cond, file, linenum); |
| 3056 | LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list); |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3057 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3058 | } else if (!strcmp(args[1], "auth")) { |
| 3059 | if (*(args[2]) == 0) { |
| 3060 | 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] | 3061 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3062 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3063 | } else if (!stats_add_auth(&curproxy->uri_auth, args[2])) { |
| 3064 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3065 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3066 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3067 | } |
| 3068 | } else if (!strcmp(args[1], "scope")) { |
| 3069 | if (*(args[2]) == 0) { |
| 3070 | Alert("parsing [%s:%d] : 'scope' needs a proxy name.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3071 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3072 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3073 | } else if (!stats_add_scope(&curproxy->uri_auth, args[2])) { |
| 3074 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3075 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3076 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3077 | } |
| 3078 | } else if (!strcmp(args[1], "enable")) { |
| 3079 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 3080 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3081 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3082 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3083 | } |
Krzysztof Oledzki | d9db927 | 2007-10-15 10:05:11 +0200 | [diff] [blame] | 3084 | } else if (!strcmp(args[1], "hide-version")) { |
| 3085 | if (!stats_set_flag(&curproxy->uri_auth, ST_HIDEVER)) { |
| 3086 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3087 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3088 | goto out; |
Krzysztof Oledzki | d9db927 | 2007-10-15 10:05:11 +0200 | [diff] [blame] | 3089 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3090 | } else if (!strcmp(args[1], "show-legends")) { |
| 3091 | if (!stats_set_flag(&curproxy->uri_auth, ST_SHLGNDS)) { |
| 3092 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3093 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3094 | goto out; |
| 3095 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3096 | } else if (!strcmp(args[1], "show-node")) { |
| 3097 | |
| 3098 | if (*args[2]) { |
| 3099 | int i; |
| 3100 | char c; |
| 3101 | |
| 3102 | for (i=0; args[2][i]; i++) { |
| 3103 | c = args[2][i]; |
Willy Tarreau | 88e0581 | 2010-03-03 00:16:00 +0100 | [diff] [blame] | 3104 | if (!isupper((unsigned char)c) && !islower((unsigned char)c) && |
| 3105 | !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.') |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3106 | break; |
| 3107 | } |
| 3108 | |
| 3109 | if (!i || args[2][i]) { |
| 3110 | Alert("parsing [%s:%d]: '%s %s' invalid node name - should be a string" |
| 3111 | "with digits(0-9), letters(A-Z, a-z), hyphen(-) or underscode(_).\n", |
| 3112 | file, linenum, args[0], args[1]); |
| 3113 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3114 | goto out; |
| 3115 | } |
| 3116 | } |
| 3117 | |
| 3118 | if (!stats_set_node(&curproxy->uri_auth, args[2])) { |
| 3119 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3120 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3121 | goto out; |
| 3122 | } |
| 3123 | } else if (!strcmp(args[1], "show-desc")) { |
| 3124 | char *desc = NULL; |
| 3125 | |
| 3126 | if (*args[2]) { |
| 3127 | int i, len=0; |
| 3128 | char *d; |
| 3129 | |
| 3130 | for(i=2; *args[i]; i++) |
| 3131 | len += strlen(args[i])+1; |
| 3132 | |
| 3133 | desc = d = (char *)calloc(1, len); |
| 3134 | |
| 3135 | d += sprintf(d, "%s", args[2]); |
| 3136 | for(i=3; *args[i]; i++) |
| 3137 | d += sprintf(d, " %s", args[i]); |
| 3138 | } |
| 3139 | |
| 3140 | if (!*args[2] && !global.desc) |
| 3141 | Warning("parsing [%s:%d]: '%s' requires a parameter or 'desc' to be set in the global section.\n", |
| 3142 | file, linenum, args[1]); |
| 3143 | else { |
| 3144 | if (!stats_set_desc(&curproxy->uri_auth, desc)) { |
| 3145 | free(desc); |
| 3146 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3147 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3148 | goto out; |
| 3149 | } |
| 3150 | free(desc); |
| 3151 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3152 | } else { |
Krzysztof Piotr Oledzki | 260a3bb | 2010-01-06 16:25:05 +0100 | [diff] [blame] | 3153 | stats_error_parsing: |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3154 | 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] | 3155 | 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] | 3156 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3157 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3158 | } |
| 3159 | } |
| 3160 | else if (!strcmp(args[0], "option")) { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3161 | int optnum; |
| 3162 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3163 | if (*(args[1]) == '\0') { |
| 3164 | Alert("parsing [%s:%d]: '%s' expects an option name.\n", |
| 3165 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3166 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3167 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3168 | } |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3169 | |
| 3170 | for (optnum = 0; cfg_opts[optnum].name; optnum++) { |
| 3171 | if (!strcmp(args[1], cfg_opts[optnum].name)) { |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 3172 | if (cfg_opts[optnum].cap == PR_CAP_NONE) { |
| 3173 | Alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n", |
| 3174 | file, linenum, cfg_opts[optnum].name); |
| 3175 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3176 | goto out; |
| 3177 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3178 | if (warnifnotcap(curproxy, cfg_opts[optnum].cap, file, linenum, args[1], NULL)) { |
| 3179 | err_code |= ERR_WARN; |
| 3180 | goto out; |
| 3181 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3182 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 3183 | curproxy->no_options &= ~cfg_opts[optnum].val; |
| 3184 | curproxy->options &= ~cfg_opts[optnum].val; |
| 3185 | |
| 3186 | switch (kwm) { |
| 3187 | case KWM_STD: |
| 3188 | curproxy->options |= cfg_opts[optnum].val; |
| 3189 | break; |
| 3190 | case KWM_NO: |
| 3191 | curproxy->no_options |= cfg_opts[optnum].val; |
| 3192 | break; |
| 3193 | case KWM_DEF: /* already cleared */ |
| 3194 | break; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 3195 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3196 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3197 | goto out; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3198 | } |
| 3199 | } |
| 3200 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 3201 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) { |
| 3202 | if (!strcmp(args[1], cfg_opts2[optnum].name)) { |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 3203 | if (cfg_opts2[optnum].cap == PR_CAP_NONE) { |
| 3204 | Alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n", |
| 3205 | file, linenum, cfg_opts2[optnum].name); |
| 3206 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3207 | goto out; |
| 3208 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3209 | if (warnifnotcap(curproxy, cfg_opts2[optnum].cap, file, linenum, args[1], NULL)) { |
| 3210 | err_code |= ERR_WARN; |
| 3211 | goto out; |
| 3212 | } |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 3213 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 3214 | curproxy->no_options2 &= ~cfg_opts2[optnum].val; |
| 3215 | curproxy->options2 &= ~cfg_opts2[optnum].val; |
| 3216 | |
| 3217 | switch (kwm) { |
| 3218 | case KWM_STD: |
| 3219 | curproxy->options2 |= cfg_opts2[optnum].val; |
| 3220 | break; |
| 3221 | case KWM_NO: |
| 3222 | curproxy->no_options2 |= cfg_opts2[optnum].val; |
| 3223 | break; |
| 3224 | case KWM_DEF: /* already cleared */ |
| 3225 | break; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 3226 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3227 | goto out; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 3228 | } |
| 3229 | } |
| 3230 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 3231 | if (kwm != KWM_STD) { |
| 3232 | 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] | 3233 | file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3234 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3235 | goto out; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3236 | } |
| 3237 | |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3238 | if (!strcmp(args[1], "httplog")) { |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 3239 | char *logformat; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3240 | /* generate a complete HTTP log */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 3241 | logformat = default_http_log_format; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3242 | if (*(args[2]) != '\0') { |
| 3243 | if (!strcmp(args[2], "clf")) { |
| 3244 | curproxy->options2 |= PR_O2_CLFLOG; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 3245 | logformat = clf_http_log_format; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3246 | } else { |
| 3247 | 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] | 3248 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3249 | goto out; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3250 | } |
| 3251 | } |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 3252 | if (curproxy->logformat_string != default_http_log_format && |
| 3253 | curproxy->logformat_string != default_tcp_log_format && |
| 3254 | curproxy->logformat_string != clf_http_log_format) |
| 3255 | free(curproxy->logformat_string); |
| 3256 | curproxy->logformat_string = logformat; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3257 | } |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 3258 | else if (!strcmp(args[1], "tcplog")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3259 | /* generate a detailed TCP log */ |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 3260 | if (curproxy->logformat_string != default_http_log_format && |
| 3261 | curproxy->logformat_string != default_tcp_log_format && |
| 3262 | curproxy->logformat_string != clf_http_log_format) |
| 3263 | free(curproxy->logformat_string); |
| 3264 | curproxy->logformat_string = default_tcp_log_format; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 3265 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3266 | else if (!strcmp(args[1], "tcpka")) { |
| 3267 | /* enable TCP keep-alives on client and server sessions */ |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3268 | 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] | 3269 | err_code |= ERR_WARN; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3270 | |
| 3271 | if (curproxy->cap & PR_CAP_FE) |
| 3272 | curproxy->options |= PR_O_TCP_CLI_KA; |
| 3273 | if (curproxy->cap & PR_CAP_BE) |
| 3274 | curproxy->options |= PR_O_TCP_SRV_KA; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3275 | } |
| 3276 | else if (!strcmp(args[1], "httpchk")) { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3277 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3278 | err_code |= ERR_WARN; |
| 3279 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3280 | /* use HTTP request to check servers' health */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3281 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 3282 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3283 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 3284 | curproxy->options2 |= PR_O2_HTTP_CHK; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3285 | if (!*args[2]) { /* no argument */ |
| 3286 | curproxy->check_req = strdup(DEF_CHECK_REQ); /* default request */ |
| 3287 | curproxy->check_len = strlen(DEF_CHECK_REQ); |
| 3288 | } else if (!*args[3]) { /* one argument : URI */ |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3289 | 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] | 3290 | curproxy->check_req = (char *)malloc(reqlen); |
| 3291 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3292 | "OPTIONS %s HTTP/1.0\r\n", args[2]); /* URI to use */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3293 | } else { /* more arguments : METHOD URI [HTTP_VER] */ |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3294 | int reqlen = strlen(args[2]) + strlen(args[3]) + 3 + strlen("\r\n"); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3295 | if (*args[4]) |
| 3296 | reqlen += strlen(args[4]); |
| 3297 | else |
| 3298 | reqlen += strlen("HTTP/1.0"); |
| 3299 | |
| 3300 | curproxy->check_req = (char *)malloc(reqlen); |
| 3301 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3302 | "%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] | 3303 | } |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 3304 | } |
| 3305 | else if (!strcmp(args[1], "ssl-hello-chk")) { |
| 3306 | /* use SSLv3 CLIENT HELLO to check servers' health */ |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3307 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3308 | err_code |= ERR_WARN; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3309 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3310 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 3311 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3312 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Willy Tarreau | 07a5490 | 2010-03-29 18:33:29 +0200 | [diff] [blame] | 3313 | curproxy->options2 |= PR_O2_SSL3_CHK; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3314 | } |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 3315 | else if (!strcmp(args[1], "smtpchk")) { |
| 3316 | /* use SMTP 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_SMTP_CHK; |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 3321 | |
| 3322 | if (!*args[2] || !*args[3]) { /* no argument or incomplete EHLO host */ |
| 3323 | curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */ |
| 3324 | curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ); |
| 3325 | } else { /* ESMTP EHLO, or SMTP HELO, and a hostname */ |
| 3326 | if (!strcmp(args[2], "EHLO") || !strcmp(args[2], "HELO")) { |
| 3327 | int reqlen = strlen(args[2]) + strlen(args[3]) + strlen(" \r\n") + 1; |
| 3328 | curproxy->check_req = (char *)malloc(reqlen); |
| 3329 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
| 3330 | "%s %s\r\n", args[2], args[3]); /* HELO hostname */ |
| 3331 | } else { |
| 3332 | /* this just hits the default for now, but you could potentially expand it to allow for other stuff |
| 3333 | though, it's unlikely you'd want to send anything other than an EHLO or HELO */ |
| 3334 | curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */ |
| 3335 | curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ); |
| 3336 | } |
| 3337 | } |
| 3338 | } |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 3339 | else if (!strcmp(args[1], "pgsql-check")) { |
| 3340 | /* use PostgreSQL request to check servers' health */ |
| 3341 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 3342 | err_code |= ERR_WARN; |
| 3343 | |
| 3344 | free(curproxy->check_req); |
| 3345 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3346 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 3347 | curproxy->options2 |= PR_O2_PGSQL_CHK; |
| 3348 | |
| 3349 | if (*(args[2])) { |
| 3350 | int cur_arg = 2; |
| 3351 | |
| 3352 | while (*(args[cur_arg])) { |
| 3353 | if (strcmp(args[cur_arg], "user") == 0) { |
| 3354 | char * packet; |
| 3355 | uint32_t packet_len; |
| 3356 | uint32_t pv; |
| 3357 | |
| 3358 | /* suboption header - needs additional argument for it */ |
| 3359 | if (*(args[cur_arg+1]) == 0) { |
| 3360 | Alert("parsing [%s:%d] : '%s %s %s' expects <username> as argument.\n", |
| 3361 | file, linenum, args[0], args[1], args[cur_arg]); |
| 3362 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3363 | goto out; |
| 3364 | } |
| 3365 | |
| 3366 | /* uint32_t + uint32_t + strlen("user")+1 + strlen(username)+1 + 1 */ |
| 3367 | packet_len = 4 + 4 + 5 + strlen(args[cur_arg + 1])+1 +1; |
| 3368 | pv = htonl(0x30000); /* protocol version 3.0 */ |
| 3369 | |
| 3370 | packet = (char*) calloc(1, packet_len); |
| 3371 | |
| 3372 | memcpy(packet + 4, &pv, 4); |
| 3373 | |
| 3374 | /* copy "user" */ |
| 3375 | memcpy(packet + 8, "user", 4); |
| 3376 | |
| 3377 | /* copy username */ |
| 3378 | memcpy(packet + 13, args[cur_arg+1], strlen(args[cur_arg+1])); |
| 3379 | |
| 3380 | free(curproxy->check_req); |
| 3381 | curproxy->check_req = packet; |
| 3382 | curproxy->check_len = packet_len; |
| 3383 | |
| 3384 | packet_len = htonl(packet_len); |
| 3385 | memcpy(packet, &packet_len, 4); |
| 3386 | cur_arg += 2; |
| 3387 | } else { |
| 3388 | /* unknown suboption - catchall */ |
| 3389 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'user'.\n", |
| 3390 | file, linenum, args[0], args[1]); |
| 3391 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3392 | goto out; |
| 3393 | } |
| 3394 | } /* end while loop */ |
| 3395 | } |
| 3396 | } |
| 3397 | |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 3398 | else if (!strcmp(args[1], "redis-check")) { |
| 3399 | /* use REDIS PING request to check servers' health */ |
| 3400 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 3401 | err_code |= ERR_WARN; |
| 3402 | |
| 3403 | free(curproxy->check_req); |
| 3404 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3405 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 3406 | curproxy->options2 |= PR_O2_REDIS_CHK; |
| 3407 | |
| 3408 | curproxy->check_req = (char *) malloc(sizeof(DEF_REDIS_CHECK_REQ) - 1); |
| 3409 | memcpy(curproxy->check_req, DEF_REDIS_CHECK_REQ, sizeof(DEF_REDIS_CHECK_REQ) - 1); |
| 3410 | curproxy->check_len = sizeof(DEF_REDIS_CHECK_REQ) - 1; |
| 3411 | } |
| 3412 | |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 3413 | else if (!strcmp(args[1], "mysql-check")) { |
| 3414 | /* use MYSQL request to check servers' health */ |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 3415 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 3416 | err_code |= ERR_WARN; |
| 3417 | |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 3418 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 3419 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3420 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 3421 | curproxy->options2 |= PR_O2_MYSQL_CHK; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 3422 | |
| 3423 | /* This is an exemple of an MySQL >=4.0 client Authentication packet kindly provided by Cyril Bonte. |
| 3424 | * const char mysql40_client_auth_pkt[] = { |
| 3425 | * "\x0e\x00\x00" // packet length |
| 3426 | * "\x01" // packet number |
| 3427 | * "\x00\x00" // client capabilities |
| 3428 | * "\x00\x00\x01" // max packet |
| 3429 | * "haproxy\x00" // username (null terminated string) |
| 3430 | * "\x00" // filler (always 0x00) |
| 3431 | * "\x01\x00\x00" // packet length |
| 3432 | * "\x00" // packet number |
| 3433 | * "\x01" // COM_QUIT command |
| 3434 | * }; |
| 3435 | */ |
| 3436 | |
| 3437 | if (*(args[2])) { |
| 3438 | int cur_arg = 2; |
| 3439 | |
| 3440 | while (*(args[cur_arg])) { |
| 3441 | if (strcmp(args[cur_arg], "user") == 0) { |
| 3442 | char *mysqluser; |
| 3443 | int packetlen, reqlen, userlen; |
| 3444 | |
| 3445 | /* suboption header - needs additional argument for it */ |
| 3446 | if (*(args[cur_arg+1]) == 0) { |
| 3447 | Alert("parsing [%s:%d] : '%s %s %s' expects <username> as argument.\n", |
| 3448 | file, linenum, args[0], args[1], args[cur_arg]); |
| 3449 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3450 | goto out; |
| 3451 | } |
| 3452 | mysqluser = args[cur_arg + 1]; |
| 3453 | userlen = strlen(mysqluser); |
| 3454 | packetlen = userlen + 7; |
| 3455 | reqlen = packetlen + 9; |
| 3456 | |
| 3457 | free(curproxy->check_req); |
| 3458 | curproxy->check_req = (char *)calloc(1, reqlen); |
| 3459 | curproxy->check_len = reqlen; |
| 3460 | |
| 3461 | snprintf(curproxy->check_req, 4, "%c%c%c", |
| 3462 | ((unsigned char) packetlen & 0xff), |
| 3463 | ((unsigned char) (packetlen >> 8) & 0xff), |
| 3464 | ((unsigned char) (packetlen >> 16) & 0xff)); |
| 3465 | |
| 3466 | curproxy->check_req[3] = 1; |
Hervé COMMOWICK | 212f778 | 2011-06-10 14:05:59 +0200 | [diff] [blame] | 3467 | curproxy->check_req[5] = 128; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 3468 | curproxy->check_req[8] = 1; |
| 3469 | memcpy(&curproxy->check_req[9], mysqluser, userlen); |
| 3470 | curproxy->check_req[9 + userlen + 1 + 1] = 1; |
| 3471 | curproxy->check_req[9 + userlen + 1 + 1 + 4] = 1; |
| 3472 | cur_arg += 2; |
| 3473 | } else { |
| 3474 | /* unknown suboption - catchall */ |
| 3475 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'user'.\n", |
| 3476 | file, linenum, args[0], args[1]); |
| 3477 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3478 | goto out; |
| 3479 | } |
| 3480 | } /* end while loop */ |
| 3481 | } |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 3482 | } |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 3483 | else if (!strcmp(args[1], "ldap-check")) { |
| 3484 | /* use LDAP request to check servers' health */ |
| 3485 | free(curproxy->check_req); |
| 3486 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3487 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 3488 | curproxy->options2 |= PR_O2_LDAP_CHK; |
| 3489 | |
| 3490 | curproxy->check_req = (char *) malloc(sizeof(DEF_LDAP_CHECK_REQ) - 1); |
| 3491 | memcpy(curproxy->check_req, DEF_LDAP_CHECK_REQ, sizeof(DEF_LDAP_CHECK_REQ) - 1); |
| 3492 | curproxy->check_len = sizeof(DEF_LDAP_CHECK_REQ) - 1; |
| 3493 | } |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3494 | else if (!strcmp(args[1], "forwardfor")) { |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3495 | int cur_arg; |
| 3496 | |
| 3497 | /* insert x-forwarded-for field, but not for the IP address listed as an except. |
| 3498 | * set default options (ie: bitfield, header name, etc) |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3499 | */ |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3500 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 3501 | curproxy->options |= PR_O_FWDFOR | PR_O_FF_ALWAYS; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3502 | |
| 3503 | free(curproxy->fwdfor_hdr_name); |
| 3504 | curproxy->fwdfor_hdr_name = strdup(DEF_XFORWARDFOR_HDR); |
| 3505 | curproxy->fwdfor_hdr_len = strlen(DEF_XFORWARDFOR_HDR); |
| 3506 | |
| 3507 | /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */ |
| 3508 | cur_arg = 2; |
| 3509 | while (*(args[cur_arg])) { |
| 3510 | if (!strcmp(args[cur_arg], "except")) { |
| 3511 | /* suboption except - needs additional argument for it */ |
| 3512 | if (!*(args[cur_arg+1]) || !str2net(args[cur_arg+1], &curproxy->except_net, &curproxy->except_mask)) { |
| 3513 | Alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n", |
| 3514 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3515 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3516 | goto out; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3517 | } |
| 3518 | /* flush useless bits */ |
| 3519 | curproxy->except_net.s_addr &= curproxy->except_mask.s_addr; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3520 | cur_arg += 2; |
| 3521 | } else if (!strcmp(args[cur_arg], "header")) { |
| 3522 | /* suboption header - needs additional argument for it */ |
| 3523 | if (*(args[cur_arg+1]) == 0) { |
| 3524 | Alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 3525 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3526 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3527 | goto out; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3528 | } |
| 3529 | free(curproxy->fwdfor_hdr_name); |
| 3530 | curproxy->fwdfor_hdr_name = strdup(args[cur_arg+1]); |
| 3531 | curproxy->fwdfor_hdr_len = strlen(curproxy->fwdfor_hdr_name); |
| 3532 | cur_arg += 2; |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 3533 | } else if (!strcmp(args[cur_arg], "if-none")) { |
| 3534 | curproxy->options &= ~PR_O_FF_ALWAYS; |
| 3535 | cur_arg += 1; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3536 | } else { |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3537 | /* unknown suboption - catchall */ |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 3538 | 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] | 3539 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3540 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3541 | goto out; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3542 | } |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3543 | } /* end while loop */ |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3544 | } |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 3545 | else if (!strcmp(args[1], "originalto")) { |
| 3546 | int cur_arg; |
| 3547 | |
| 3548 | /* insert x-original-to field, but not for the IP address listed as an except. |
| 3549 | * set default options (ie: bitfield, header name, etc) |
| 3550 | */ |
| 3551 | |
| 3552 | curproxy->options |= PR_O_ORGTO; |
| 3553 | |
| 3554 | free(curproxy->orgto_hdr_name); |
| 3555 | curproxy->orgto_hdr_name = strdup(DEF_XORIGINALTO_HDR); |
| 3556 | curproxy->orgto_hdr_len = strlen(DEF_XORIGINALTO_HDR); |
| 3557 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 3558 | /* 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] | 3559 | cur_arg = 2; |
| 3560 | while (*(args[cur_arg])) { |
| 3561 | if (!strcmp(args[cur_arg], "except")) { |
| 3562 | /* suboption except - needs additional argument for it */ |
| 3563 | if (!*(args[cur_arg+1]) || !str2net(args[cur_arg+1], &curproxy->except_to, &curproxy->except_mask_to)) { |
| 3564 | Alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n", |
| 3565 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3566 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3567 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 3568 | } |
| 3569 | /* flush useless bits */ |
| 3570 | curproxy->except_to.s_addr &= curproxy->except_mask_to.s_addr; |
| 3571 | cur_arg += 2; |
| 3572 | } else if (!strcmp(args[cur_arg], "header")) { |
| 3573 | /* suboption header - needs additional argument for it */ |
| 3574 | if (*(args[cur_arg+1]) == 0) { |
| 3575 | Alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 3576 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3577 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3578 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 3579 | } |
| 3580 | free(curproxy->orgto_hdr_name); |
| 3581 | curproxy->orgto_hdr_name = strdup(args[cur_arg+1]); |
| 3582 | curproxy->orgto_hdr_len = strlen(curproxy->orgto_hdr_name); |
| 3583 | cur_arg += 2; |
| 3584 | } else { |
| 3585 | /* unknown suboption - catchall */ |
| 3586 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n", |
| 3587 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3588 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3589 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 3590 | } |
| 3591 | } /* end while loop */ |
| 3592 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3593 | else { |
| 3594 | Alert("parsing [%s:%d] : unknown option '%s'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3595 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3596 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3597 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3598 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3599 | } |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 3600 | else if (!strcmp(args[0], "default_backend")) { |
| 3601 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3602 | err_code |= ERR_WARN; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 3603 | |
| 3604 | if (*(args[1]) == 0) { |
| 3605 | 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] | 3606 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3607 | goto out; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 3608 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3609 | free(curproxy->defbe.name); |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 3610 | curproxy->defbe.name = strdup(args[1]); |
| 3611 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3612 | else if (!strcmp(args[0], "redispatch") || !strcmp(args[0], "redisp")) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3613 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3614 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3615 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3616 | Warning("parsing [%s:%d]: keyword '%s' is deprecated, please use 'option redispatch' instead.\n", |
| 3617 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3618 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3619 | /* enable reconnections to dispatch */ |
| 3620 | curproxy->options |= PR_O_REDISP; |
| 3621 | } |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 3622 | else if (!strcmp(args[0], "http-check")) { |
| 3623 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3624 | err_code |= ERR_WARN; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 3625 | |
| 3626 | if (strcmp(args[1], "disable-on-404") == 0) { |
| 3627 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 3628 | curproxy->options |= PR_O_DISABLE404; |
| 3629 | } |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 3630 | else if (strcmp(args[1], "send-state") == 0) { |
| 3631 | /* enable emission of the apparent state of a server in HTTP checks */ |
| 3632 | curproxy->options2 |= PR_O2_CHK_SNDST; |
| 3633 | } |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 3634 | else if (strcmp(args[1], "expect") == 0) { |
| 3635 | const char *ptr_arg; |
| 3636 | int cur_arg; |
| 3637 | |
| 3638 | if (curproxy->options2 & PR_O2_EXP_TYPE) { |
| 3639 | Alert("parsing [%s:%d] : '%s %s' already specified.\n", file, linenum, args[0], args[1]); |
| 3640 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3641 | goto out; |
| 3642 | } |
| 3643 | |
| 3644 | cur_arg = 2; |
| 3645 | /* consider exclamation marks, sole or at the beginning of a word */ |
| 3646 | while (*(ptr_arg = args[cur_arg])) { |
| 3647 | while (*ptr_arg == '!') { |
| 3648 | curproxy->options2 ^= PR_O2_EXP_INV; |
| 3649 | ptr_arg++; |
| 3650 | } |
| 3651 | if (*ptr_arg) |
| 3652 | break; |
| 3653 | cur_arg++; |
| 3654 | } |
| 3655 | /* now ptr_arg points to the beginning of a word past any possible |
| 3656 | * exclamation mark, and cur_arg is the argument which holds this word. |
| 3657 | */ |
| 3658 | if (strcmp(ptr_arg, "status") == 0) { |
| 3659 | if (!*(args[cur_arg + 1])) { |
| 3660 | Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 3661 | file, linenum, args[0], args[1], ptr_arg); |
| 3662 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3663 | goto out; |
| 3664 | } |
| 3665 | curproxy->options2 |= PR_O2_EXP_STS; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 3666 | free(curproxy->expect_str); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 3667 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
| 3668 | } |
| 3669 | else if (strcmp(ptr_arg, "string") == 0) { |
| 3670 | if (!*(args[cur_arg + 1])) { |
| 3671 | Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 3672 | file, linenum, args[0], args[1], ptr_arg); |
| 3673 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3674 | goto out; |
| 3675 | } |
| 3676 | curproxy->options2 |= PR_O2_EXP_STR; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 3677 | free(curproxy->expect_str); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 3678 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
| 3679 | } |
| 3680 | else if (strcmp(ptr_arg, "rstatus") == 0) { |
| 3681 | if (!*(args[cur_arg + 1])) { |
| 3682 | Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 3683 | file, linenum, args[0], args[1], ptr_arg); |
| 3684 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3685 | goto out; |
| 3686 | } |
| 3687 | curproxy->options2 |= PR_O2_EXP_RSTS; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 3688 | free(curproxy->expect_str); |
| 3689 | if (curproxy->expect_regex) regfree(curproxy->expect_regex); |
| 3690 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 3691 | curproxy->expect_regex = calloc(1, sizeof(regex_t)); |
| 3692 | if (regcomp(curproxy->expect_regex, args[cur_arg + 1], REG_EXTENDED) != 0) { |
| 3693 | Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s'.\n", |
| 3694 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1]); |
| 3695 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3696 | goto out; |
| 3697 | } |
| 3698 | } |
| 3699 | else if (strcmp(ptr_arg, "rstring") == 0) { |
| 3700 | if (!*(args[cur_arg + 1])) { |
| 3701 | Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 3702 | file, linenum, args[0], args[1], ptr_arg); |
| 3703 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3704 | goto out; |
| 3705 | } |
| 3706 | curproxy->options2 |= PR_O2_EXP_RSTR; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 3707 | free(curproxy->expect_str); |
| 3708 | if (curproxy->expect_regex) regfree(curproxy->expect_regex); |
| 3709 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 3710 | curproxy->expect_regex = calloc(1, sizeof(regex_t)); |
| 3711 | if (regcomp(curproxy->expect_regex, args[cur_arg + 1], REG_EXTENDED) != 0) { |
| 3712 | Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s'.\n", |
| 3713 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1]); |
| 3714 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3715 | goto out; |
| 3716 | } |
| 3717 | } |
| 3718 | else { |
| 3719 | Alert("parsing [%s:%d] : '%s %s' only supports [!] 'status', 'string', 'rstatus', 'rstring', found '%s'.\n", |
| 3720 | file, linenum, args[0], args[1], ptr_arg); |
| 3721 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3722 | goto out; |
| 3723 | } |
| 3724 | } |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 3725 | else { |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 3726 | 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] | 3727 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3728 | goto out; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 3729 | } |
| 3730 | } |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3731 | else if (!strcmp(args[0], "monitor")) { |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3732 | if (curproxy == &defproxy) { |
| 3733 | 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] | 3734 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3735 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3736 | } |
| 3737 | |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3738 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3739 | err_code |= ERR_WARN; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3740 | |
| 3741 | if (strcmp(args[1], "fail") == 0) { |
| 3742 | /* add a condition to fail monitor requests */ |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 3743 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3744 | Alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n", |
| 3745 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3746 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3747 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3748 | } |
| 3749 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 3750 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 3751 | Alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition : %s.\n", |
| 3752 | file, linenum, args[0], args[1], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3753 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3754 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3755 | } |
| 3756 | LIST_ADDQ(&curproxy->mon_fail_cond, &cond->list); |
| 3757 | } |
| 3758 | else { |
| 3759 | 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] | 3760 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3761 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3762 | } |
| 3763 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3764 | #ifdef TPROXY |
| 3765 | else if (!strcmp(args[0], "transparent")) { |
| 3766 | /* enable transparent proxy connections */ |
| 3767 | curproxy->options |= PR_O_TRANSP; |
| 3768 | } |
| 3769 | #endif |
| 3770 | else if (!strcmp(args[0], "maxconn")) { /* maxconn */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3771 | 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] | 3772 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3773 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3774 | if (*(args[1]) == 0) { |
| 3775 | 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] | 3776 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3777 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3778 | } |
| 3779 | curproxy->maxconn = atol(args[1]); |
| 3780 | } |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 3781 | else if (!strcmp(args[0], "backlog")) { /* backlog */ |
| 3782 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3783 | err_code |= ERR_WARN; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 3784 | |
| 3785 | if (*(args[1]) == 0) { |
| 3786 | 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] | 3787 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3788 | goto out; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 3789 | } |
| 3790 | curproxy->backlog = atol(args[1]); |
| 3791 | } |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 3792 | else if (!strcmp(args[0], "fullconn")) { /* fullconn */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3793 | 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] | 3794 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3795 | |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 3796 | if (*(args[1]) == 0) { |
| 3797 | 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] | 3798 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3799 | goto out; |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 3800 | } |
| 3801 | curproxy->fullconn = atol(args[1]); |
| 3802 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3803 | else if (!strcmp(args[0], "grace")) { /* grace time (ms) */ |
| 3804 | if (*(args[1]) == 0) { |
| 3805 | 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] | 3806 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3807 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3808 | } |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 3809 | err = parse_time_err(args[1], &val, TIME_UNIT_MS); |
| 3810 | if (err) { |
| 3811 | Alert("parsing [%s:%d] : unexpected character '%c' in grace time.\n", |
| 3812 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3813 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3814 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 3815 | } |
| 3816 | curproxy->grace = val; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3817 | } |
| 3818 | else if (!strcmp(args[0], "dispatch")) { /* dispatch address */ |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 3819 | struct sockaddr_storage *sk; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3820 | if (curproxy == &defproxy) { |
| 3821 | 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] | 3822 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3823 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3824 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3825 | else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3826 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3827 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3828 | if (strchr(args[1], ':') == NULL) { |
| 3829 | 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] | 3830 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3831 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3832 | } |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 3833 | sk = str2sa(args[1]); |
| 3834 | if (!sk) { |
| 3835 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[1]); |
| 3836 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3837 | goto out; |
| 3838 | } |
| 3839 | curproxy->dispatch_addr = *sk; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3840 | curproxy->options |= PR_O_DISPATCH; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3841 | } |
| 3842 | else if (!strcmp(args[0], "balance")) { /* set balancing with optional algorithm */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3843 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3844 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3845 | |
Willy Tarreau | a93c74b | 2012-05-08 18:14:39 +0200 | [diff] [blame] | 3846 | if (backend_parse_balance((const char **)args + 1, &errmsg, curproxy) < 0) { |
| 3847 | Alert("parsing [%s:%d] : %s %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3848 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3849 | goto out; |
Willy Tarreau | 2fcb500 | 2007-05-08 13:35:26 +0200 | [diff] [blame] | 3850 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3851 | } |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 3852 | else if (!strcmp(args[0], "hash-type")) { /* set hashing method */ |
| 3853 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 3854 | err_code |= ERR_WARN; |
| 3855 | |
| 3856 | if (strcmp(args[1], "consistent") == 0) { /* use consistent hashing */ |
| 3857 | curproxy->lbprm.algo &= ~BE_LB_HASH_TYPE; |
| 3858 | curproxy->lbprm.algo |= BE_LB_HASH_CONS; |
| 3859 | } |
| 3860 | else if (strcmp(args[1], "map-based") == 0) { /* use map-based hashing */ |
| 3861 | curproxy->lbprm.algo &= ~BE_LB_HASH_TYPE; |
| 3862 | curproxy->lbprm.algo |= BE_LB_HASH_MAP; |
| 3863 | } |
Willy Tarreau | 798a39c | 2010-11-24 15:04:29 +0100 | [diff] [blame] | 3864 | else if (strcmp(args[1], "avalanche") == 0) { /* use full hash before map-based hashing */ |
| 3865 | curproxy->lbprm.algo &= ~BE_LB_HASH_TYPE; |
| 3866 | curproxy->lbprm.algo |= BE_LB_HASH_AVAL; |
| 3867 | } |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 3868 | else { |
Willy Tarreau | 798a39c | 2010-11-24 15:04:29 +0100 | [diff] [blame] | 3869 | 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] | 3870 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3871 | goto out; |
| 3872 | } |
| 3873 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3874 | 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] | 3875 | int cur_arg; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3876 | char *rport, *raddr; |
| 3877 | short realport = 0; |
| 3878 | int do_check = 0, defsrv = (*args[0] == 'd'); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3879 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3880 | if (!defsrv && curproxy == &defproxy) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3881 | 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] | 3882 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3883 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3884 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3885 | else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3886 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3887 | |
| 3888 | if (!*args[2]) { |
| 3889 | Alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n", |
| 3890 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3891 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3892 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3893 | } |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 3894 | |
| 3895 | err = invalid_char(args[1]); |
| 3896 | if (err) { |
| 3897 | Alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n", |
| 3898 | file, linenum, *err, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3899 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3900 | goto out; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 3901 | } |
| 3902 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3903 | if (!defsrv) { |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 3904 | struct sockaddr_storage *sk; |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 3905 | |
Krzysztof Piotr Oledzki | aff01ea | 2010-02-05 20:31:44 +0100 | [diff] [blame] | 3906 | if ((newsrv = (struct server *)calloc(1, sizeof(struct server))) == NULL) { |
| 3907 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 3908 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3909 | goto out; |
| 3910 | } |
| 3911 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3912 | /* the servers are linked backwards first */ |
| 3913 | newsrv->next = curproxy->srv; |
| 3914 | curproxy->srv = newsrv; |
| 3915 | newsrv->proxy = curproxy; |
| 3916 | newsrv->conf.file = file; |
| 3917 | newsrv->conf.line = linenum; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3918 | |
Simon Horman | af51495 | 2011-06-21 14:34:57 +0900 | [diff] [blame] | 3919 | LIST_INIT(&newsrv->actconns); |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3920 | LIST_INIT(&newsrv->pendconns); |
| 3921 | do_check = 0; |
| 3922 | newsrv->state = SRV_RUNNING; /* early server setup */ |
| 3923 | newsrv->last_change = now.tv_sec; |
| 3924 | newsrv->id = strdup(args[1]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3925 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3926 | /* several ways to check the port component : |
David du Colombier | 9842ff1 | 2011-03-17 10:40:28 +0100 | [diff] [blame] | 3927 | * - IP => port=+0, relative (IPv4 only) |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3928 | * - IP: => port=+0, relative |
| 3929 | * - IP:N => port=N, absolute |
| 3930 | * - IP:+N => port=+N, relative |
| 3931 | * - IP:-N => port=-N, relative |
| 3932 | */ |
| 3933 | raddr = strdup(args[2]); |
Willy Tarreau | fab5a43 | 2011-03-04 15:31:53 +0100 | [diff] [blame] | 3934 | rport = strrchr(raddr, ':'); |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3935 | if (rport) { |
| 3936 | *rport++ = 0; |
| 3937 | realport = atol(rport); |
| 3938 | if (!isdigit((unsigned char)*rport)) |
| 3939 | newsrv->state |= SRV_MAPPORTS; |
| 3940 | } else |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3941 | newsrv->state |= SRV_MAPPORTS; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3942 | |
Willy Tarreau | fab5a43 | 2011-03-04 15:31:53 +0100 | [diff] [blame] | 3943 | sk = str2ip(raddr); |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3944 | free(raddr); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 3945 | if (!sk) { |
| 3946 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[2]); |
| 3947 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3948 | goto out; |
| 3949 | } |
| 3950 | newsrv->addr = *sk; |
Willy Tarreau | 26d8c59 | 2012-05-07 18:12:14 +0200 | [diff] [blame] | 3951 | newsrv->proto = protocol_by_family(newsrv->addr.ss_family); |
Willy Tarreau | c578891 | 2012-08-24 18:12:41 +0200 | [diff] [blame] | 3952 | newsrv->data = &raw_sock; |
Willy Tarreau | 26d8c59 | 2012-05-07 18:12:14 +0200 | [diff] [blame] | 3953 | |
Willy Tarreau | 173e7fb | 2012-09-24 22:47:39 +0200 | [diff] [blame] | 3954 | if (!newsrv->proto) { |
Willy Tarreau | 26d8c59 | 2012-05-07 18:12:14 +0200 | [diff] [blame] | 3955 | Alert("parsing [%s:%d] : Unknown protocol family %d '%s'\n", |
| 3956 | file, linenum, newsrv->addr.ss_family, args[2]); |
| 3957 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3958 | goto out; |
| 3959 | } |
Willy Tarreau | 86ad42c | 2011-08-27 12:29:07 +0200 | [diff] [blame] | 3960 | set_host_port(&newsrv->addr, realport); |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3961 | |
| 3962 | newsrv->check_port = curproxy->defsrv.check_port; |
| 3963 | newsrv->inter = curproxy->defsrv.inter; |
| 3964 | newsrv->fastinter = curproxy->defsrv.fastinter; |
| 3965 | newsrv->downinter = curproxy->defsrv.downinter; |
| 3966 | newsrv->rise = curproxy->defsrv.rise; |
| 3967 | newsrv->fall = curproxy->defsrv.fall; |
| 3968 | newsrv->maxqueue = curproxy->defsrv.maxqueue; |
| 3969 | newsrv->minconn = curproxy->defsrv.minconn; |
| 3970 | newsrv->maxconn = curproxy->defsrv.maxconn; |
| 3971 | newsrv->slowstart = curproxy->defsrv.slowstart; |
| 3972 | newsrv->onerror = curproxy->defsrv.onerror; |
| 3973 | newsrv->consecutive_errors_limit |
| 3974 | = curproxy->defsrv.consecutive_errors_limit; |
Emeric Brun | 01f8e2f | 2012-05-18 16:02:00 +0200 | [diff] [blame] | 3975 | #ifdef OPENSSL |
| 3976 | newsrv->use_ssl = curproxy->defsrv.use_ssl; |
| 3977 | #endif |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3978 | newsrv->uweight = newsrv->iweight |
| 3979 | = curproxy->defsrv.iweight; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3980 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3981 | newsrv->curfd = -1; /* no health-check in progress */ |
| 3982 | newsrv->health = newsrv->rise; /* up, but will fall down at first failure */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3983 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3984 | cur_arg = 3; |
| 3985 | } else { |
| 3986 | newsrv = &curproxy->defsrv; |
| 3987 | cur_arg = 1; |
| 3988 | } |
Willy Tarreau | 0f03c6f | 2007-03-25 20:46:19 +0200 | [diff] [blame] | 3989 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3990 | while (*args[cur_arg]) { |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3991 | if (!defsrv && !strcmp(args[cur_arg], "id")) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 3992 | struct eb32_node *node; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3993 | |
| 3994 | if (!*args[cur_arg + 1]) { |
| 3995 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 3996 | file, linenum, args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3997 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3998 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3999 | } |
| 4000 | |
| 4001 | newsrv->puid = atol(args[cur_arg + 1]); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 4002 | newsrv->conf.id.key = newsrv->puid; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 4003 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 4004 | if (newsrv->puid <= 0) { |
| 4005 | Alert("parsing [%s:%d]: custom id has to be > 0.\n", |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 4006 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4007 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4008 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 4009 | } |
| 4010 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 4011 | node = eb32_lookup(&curproxy->conf.used_server_id, newsrv->puid); |
| 4012 | if (node) { |
| 4013 | struct server *target = container_of(node, struct server, conf.id); |
| 4014 | Alert("parsing [%s:%d]: server %s reuses same custom id as server %s (declared at %s:%d).\n", |
| 4015 | file, linenum, newsrv->id, target->id, target->conf.file, target->conf.line); |
| 4016 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4017 | goto out; |
| 4018 | } |
| 4019 | eb32_insert(&curproxy->conf.used_server_id, &newsrv->conf.id); |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 4020 | cur_arg += 2; |
| 4021 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4022 | else if (!defsrv && !strcmp(args[cur_arg], "cookie")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4023 | newsrv->cookie = strdup(args[cur_arg + 1]); |
| 4024 | newsrv->cklen = strlen(args[cur_arg + 1]); |
| 4025 | cur_arg += 2; |
| 4026 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4027 | else if (!defsrv && !strcmp(args[cur_arg], "redir")) { |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 4028 | newsrv->rdr_pfx = strdup(args[cur_arg + 1]); |
| 4029 | newsrv->rdr_len = strlen(args[cur_arg + 1]); |
| 4030 | cur_arg += 2; |
| 4031 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4032 | else if (!strcmp(args[cur_arg], "rise")) { |
Krzysztof Piotr Oledzki | 08ff959 | 2009-09-27 16:17:31 +0200 | [diff] [blame] | 4033 | if (!*args[cur_arg + 1]) { |
| 4034 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 4035 | file, linenum, args[cur_arg]); |
| 4036 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4037 | goto out; |
| 4038 | } |
| 4039 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4040 | newsrv->rise = atol(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 08ff959 | 2009-09-27 16:17:31 +0200 | [diff] [blame] | 4041 | if (newsrv->rise <= 0) { |
| 4042 | Alert("parsing [%s:%d]: '%s' has to be > 0.\n", |
| 4043 | file, linenum, args[cur_arg]); |
| 4044 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4045 | goto out; |
| 4046 | } |
| 4047 | |
Willy Tarreau | 9683909 | 2010-03-29 10:02:24 +0200 | [diff] [blame] | 4048 | if (newsrv->health) |
| 4049 | newsrv->health = newsrv->rise; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4050 | cur_arg += 2; |
| 4051 | } |
| 4052 | else if (!strcmp(args[cur_arg], "fall")) { |
| 4053 | newsrv->fall = atol(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 08ff959 | 2009-09-27 16:17:31 +0200 | [diff] [blame] | 4054 | |
| 4055 | if (!*args[cur_arg + 1]) { |
| 4056 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 4057 | file, linenum, args[cur_arg]); |
| 4058 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4059 | goto out; |
| 4060 | } |
| 4061 | |
| 4062 | if (newsrv->fall <= 0) { |
| 4063 | Alert("parsing [%s:%d]: '%s' has to be > 0.\n", |
| 4064 | file, linenum, args[cur_arg]); |
| 4065 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4066 | goto out; |
| 4067 | } |
| 4068 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4069 | cur_arg += 2; |
| 4070 | } |
| 4071 | else if (!strcmp(args[cur_arg], "inter")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4072 | const char *err = parse_time_err(args[cur_arg + 1], &val, TIME_UNIT_MS); |
| 4073 | if (err) { |
| 4074 | Alert("parsing [%s:%d] : unexpected character '%c' in 'inter' argument of server %s.\n", |
| 4075 | file, linenum, *err, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4076 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4077 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4078 | } |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4079 | if (val <= 0) { |
| 4080 | Alert("parsing [%s:%d]: invalid value %d for argument '%s' of server %s.\n", |
| 4081 | file, linenum, val, args[cur_arg], newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4082 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4083 | goto out; |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4084 | } |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4085 | newsrv->inter = val; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4086 | cur_arg += 2; |
| 4087 | } |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 4088 | else if (!strcmp(args[cur_arg], "fastinter")) { |
| 4089 | const char *err = parse_time_err(args[cur_arg + 1], &val, TIME_UNIT_MS); |
| 4090 | if (err) { |
| 4091 | Alert("parsing [%s:%d]: unexpected character '%c' in 'fastinter' argument of server %s.\n", |
| 4092 | file, linenum, *err, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4093 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4094 | goto out; |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 4095 | } |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4096 | if (val <= 0) { |
| 4097 | Alert("parsing [%s:%d]: invalid value %d for argument '%s' of server %s.\n", |
| 4098 | file, linenum, val, args[cur_arg], newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4099 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4100 | goto out; |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4101 | } |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 4102 | newsrv->fastinter = val; |
| 4103 | cur_arg += 2; |
| 4104 | } |
| 4105 | else if (!strcmp(args[cur_arg], "downinter")) { |
| 4106 | const char *err = parse_time_err(args[cur_arg + 1], &val, TIME_UNIT_MS); |
| 4107 | if (err) { |
| 4108 | Alert("parsing [%s:%d]: unexpected character '%c' in 'downinter' argument of server %s.\n", |
| 4109 | file, linenum, *err, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4110 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4111 | goto out; |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 4112 | } |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4113 | if (val <= 0) { |
| 4114 | Alert("parsing [%s:%d]: invalid value %d for argument '%s' of server %s.\n", |
| 4115 | file, linenum, val, args[cur_arg], newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4116 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4117 | goto out; |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4118 | } |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 4119 | newsrv->downinter = val; |
| 4120 | cur_arg += 2; |
| 4121 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4122 | else if (!defsrv && !strcmp(args[cur_arg], "addr")) { |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4123 | struct sockaddr_storage *sk = str2sa(args[cur_arg + 1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4124 | if (!sk) { |
| 4125 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[cur_arg + 1]); |
| 4126 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4127 | goto out; |
| 4128 | } |
| 4129 | newsrv->check_addr = *sk; |
Willy Tarreau | 2ea3abb | 2007-03-25 16:45:16 +0200 | [diff] [blame] | 4130 | cur_arg += 2; |
| 4131 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4132 | else if (!strcmp(args[cur_arg], "port")) { |
| 4133 | newsrv->check_port = atol(args[cur_arg + 1]); |
| 4134 | cur_arg += 2; |
| 4135 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4136 | else if (!defsrv && !strcmp(args[cur_arg], "backup")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4137 | newsrv->state |= SRV_BACKUP; |
| 4138 | cur_arg ++; |
| 4139 | } |
Simon Horman | fa46168 | 2011-06-25 09:39:49 +0900 | [diff] [blame] | 4140 | else if (!defsrv && !strcmp(args[cur_arg], "non-stick")) { |
| 4141 | newsrv->state |= SRV_NON_STICK; |
| 4142 | cur_arg ++; |
| 4143 | } |
Willy Tarreau | 5ab04ec | 2011-03-20 10:32:26 +0100 | [diff] [blame] | 4144 | else if (!defsrv && !strcmp(args[cur_arg], "send-proxy")) { |
| 4145 | newsrv->state |= SRV_SEND_PROXY; |
| 4146 | cur_arg ++; |
| 4147 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4148 | else if (!strcmp(args[cur_arg], "weight")) { |
| 4149 | int w; |
| 4150 | w = atol(args[cur_arg + 1]); |
Willy Tarreau | 6704d67 | 2009-06-15 10:56:05 +0200 | [diff] [blame] | 4151 | if (w < 0 || w > 256) { |
| 4152 | 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] | 4153 | file, linenum, newsrv->id, w); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4154 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4155 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4156 | } |
Willy Tarreau | 975c50b | 2009-10-10 19:34:06 +0200 | [diff] [blame] | 4157 | newsrv->uweight = newsrv->iweight = w; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4158 | cur_arg += 2; |
| 4159 | } |
| 4160 | else if (!strcmp(args[cur_arg], "minconn")) { |
| 4161 | newsrv->minconn = atol(args[cur_arg + 1]); |
| 4162 | cur_arg += 2; |
| 4163 | } |
| 4164 | else if (!strcmp(args[cur_arg], "maxconn")) { |
| 4165 | newsrv->maxconn = atol(args[cur_arg + 1]); |
| 4166 | cur_arg += 2; |
| 4167 | } |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 4168 | else if (!strcmp(args[cur_arg], "maxqueue")) { |
| 4169 | newsrv->maxqueue = atol(args[cur_arg + 1]); |
| 4170 | cur_arg += 2; |
| 4171 | } |
Willy Tarreau | 9909fc1 | 2007-11-30 17:42:05 +0100 | [diff] [blame] | 4172 | else if (!strcmp(args[cur_arg], "slowstart")) { |
| 4173 | /* slowstart is stored in seconds */ |
Willy Tarreau | 3259e33 | 2007-12-03 01:51:45 +0100 | [diff] [blame] | 4174 | 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] | 4175 | if (err) { |
| 4176 | Alert("parsing [%s:%d] : unexpected character '%c' in 'slowstart' argument of server %s.\n", |
| 4177 | file, linenum, *err, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4178 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4179 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4180 | } |
Willy Tarreau | 4554bc1 | 2010-03-26 10:40:49 +0100 | [diff] [blame] | 4181 | if (val < 0) { |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4182 | Alert("parsing [%s:%d]: invalid value %d for argument '%s' of server %s.\n", |
| 4183 | file, linenum, val, args[cur_arg], newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4184 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4185 | goto out; |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4186 | } |
Willy Tarreau | 3259e33 | 2007-12-03 01:51:45 +0100 | [diff] [blame] | 4187 | newsrv->slowstart = (val + 999) / 1000; |
Willy Tarreau | 9909fc1 | 2007-11-30 17:42:05 +0100 | [diff] [blame] | 4188 | cur_arg += 2; |
| 4189 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4190 | else if (!defsrv && !strcmp(args[cur_arg], "track")) { |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4191 | |
| 4192 | if (!*args[cur_arg + 1]) { |
| 4193 | Alert("parsing [%s:%d]: 'track' expects [<proxy>/]<server> as argument.\n", |
| 4194 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4195 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4196 | goto out; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4197 | } |
| 4198 | |
| 4199 | newsrv->trackit = strdup(args[cur_arg + 1]); |
| 4200 | |
| 4201 | cur_arg += 2; |
| 4202 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4203 | else if (!defsrv && !strcmp(args[cur_arg], "check")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4204 | global.maxsock++; |
| 4205 | do_check = 1; |
| 4206 | cur_arg += 1; |
| 4207 | } |
Willy Tarreau | 9683909 | 2010-03-29 10:02:24 +0200 | [diff] [blame] | 4208 | else if (!defsrv && !strcmp(args[cur_arg], "disabled")) { |
| 4209 | newsrv->state |= SRV_MAINTAIN; |
| 4210 | newsrv->state &= ~SRV_RUNNING; |
| 4211 | newsrv->health = 0; |
| 4212 | cur_arg += 1; |
| 4213 | } |
Emeric Brun | 01f8e2f | 2012-05-18 16:02:00 +0200 | [diff] [blame] | 4214 | else if (!strcmp(args[cur_arg], "ssl")) { |
| 4215 | #ifdef USE_OPENSSL |
| 4216 | newsrv->use_ssl = 1; |
| 4217 | cur_arg += 1; |
| 4218 | #else /* USE_OPENSSL */ |
| 4219 | Alert("parsing [%s:%d]: '%s' option not implemented.\n", |
| 4220 | file, linenum, args[cur_arg]); |
| 4221 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4222 | goto out; |
| 4223 | #endif /* USE_OPENSSL */ |
| 4224 | } |
Willy Tarreau | d7aacbf | 2012-09-03 23:34:19 +0200 | [diff] [blame] | 4225 | else if (!strcmp(args[cur_arg], "ciphers")) { /* use this SSL cipher suite */ |
| 4226 | #ifdef USE_OPENSSL |
| 4227 | if (!*args[cur_arg + 1]) { |
| 4228 | Alert("parsing [%s:%d] : '%s' : '%s' : missing cipher suite.\n", |
| 4229 | file, linenum, args[0], args[cur_arg]); |
| 4230 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4231 | goto out; |
| 4232 | } |
| 4233 | |
| 4234 | newsrv->ssl_ctx.ciphers = strdup(args[cur_arg + 1]); |
| 4235 | |
| 4236 | cur_arg += 2; |
| 4237 | continue; |
| 4238 | #else |
| 4239 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 4240 | file, linenum, args[0], args[cur_arg]); |
| 4241 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4242 | goto out; |
| 4243 | #endif |
| 4244 | } |
Willy Tarreau | c230b8b | 2012-09-03 23:55:16 +0200 | [diff] [blame] | 4245 | else if (!strcmp(args[cur_arg], "nosslv3")) { |
| 4246 | #ifdef USE_OPENSSL |
| 4247 | newsrv->ssl_ctx.nosslv3 = 1; |
| 4248 | cur_arg += 1; |
| 4249 | #else /* USE_OPENSSL */ |
| 4250 | Alert("parsing [%s:%d]: '%s' option not implemented.\n", |
| 4251 | file, linenum, args[cur_arg]); |
| 4252 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4253 | goto out; |
| 4254 | #endif /* USE_OPENSSL */ |
| 4255 | } |
| 4256 | else if (!strcmp(args[cur_arg], "notlsv1")) { |
| 4257 | #ifdef USE_OPENSSL |
| 4258 | newsrv->ssl_ctx.notlsv1 = 1; |
| 4259 | cur_arg += 1; |
| 4260 | #else /* USE_OPENSSL */ |
| 4261 | Alert("parsing [%s:%d]: '%s' option not implemented.\n", |
| 4262 | file, linenum, args[cur_arg]); |
| 4263 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4264 | goto out; |
| 4265 | #endif /* USE_OPENSSL */ |
| 4266 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4267 | else if (!defsrv && !strcmp(args[cur_arg], "observe")) { |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 4268 | if (!strcmp(args[cur_arg + 1], "none")) |
| 4269 | newsrv->observe = HANA_OBS_NONE; |
| 4270 | else if (!strcmp(args[cur_arg + 1], "layer4")) |
| 4271 | newsrv->observe = HANA_OBS_LAYER4; |
| 4272 | else if (!strcmp(args[cur_arg + 1], "layer7")) { |
| 4273 | if (curproxy->mode != PR_MODE_HTTP) { |
| 4274 | Alert("parsing [%s:%d]: '%s' can only be used in http proxies.\n", |
| 4275 | file, linenum, args[cur_arg + 1]); |
| 4276 | err_code |= ERR_ALERT; |
| 4277 | } |
| 4278 | newsrv->observe = HANA_OBS_LAYER7; |
| 4279 | } |
| 4280 | else { |
| 4281 | Alert("parsing [%s:%d]: '%s' expects one of 'none', " |
Willy Tarreau | 53621e0 | 2010-10-22 14:53:40 +0200 | [diff] [blame] | 4282 | "'layer4', 'layer7' but got '%s'\n", |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 4283 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
| 4284 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4285 | goto out; |
| 4286 | } |
| 4287 | |
| 4288 | cur_arg += 2; |
| 4289 | } |
| 4290 | else if (!strcmp(args[cur_arg], "on-error")) { |
| 4291 | if (!strcmp(args[cur_arg + 1], "fastinter")) |
| 4292 | newsrv->onerror = HANA_ONERR_FASTINTER; |
| 4293 | else if (!strcmp(args[cur_arg + 1], "fail-check")) |
| 4294 | newsrv->onerror = HANA_ONERR_FAILCHK; |
| 4295 | else if (!strcmp(args[cur_arg + 1], "sudden-death")) |
| 4296 | newsrv->onerror = HANA_ONERR_SUDDTH; |
| 4297 | else if (!strcmp(args[cur_arg + 1], "mark-down")) |
| 4298 | newsrv->onerror = HANA_ONERR_MARKDWN; |
| 4299 | else { |
| 4300 | Alert("parsing [%s:%d]: '%s' expects one of 'fastinter', " |
Willy Tarreau | 53621e0 | 2010-10-22 14:53:40 +0200 | [diff] [blame] | 4301 | "'fail-check', 'sudden-death' or 'mark-down' but got '%s'\n", |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 4302 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
| 4303 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4304 | goto out; |
| 4305 | } |
| 4306 | |
| 4307 | cur_arg += 2; |
| 4308 | } |
Simon Horman | e0d1bfb | 2011-06-21 14:34:58 +0900 | [diff] [blame] | 4309 | else if (!strcmp(args[cur_arg], "on-marked-down")) { |
| 4310 | if (!strcmp(args[cur_arg + 1], "shutdown-sessions")) |
| 4311 | newsrv->onmarkeddown = HANA_ONMARKEDDOWN_SHUTDOWNSESSIONS; |
| 4312 | else { |
| 4313 | Alert("parsing [%s:%d]: '%s' expects 'shutdown-sessions' but got '%s'\n", |
| 4314 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
| 4315 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4316 | goto out; |
| 4317 | } |
| 4318 | |
| 4319 | cur_arg += 2; |
| 4320 | } |
Justin Karneges | eb2c24a | 2012-05-24 15:28:52 -0700 | [diff] [blame] | 4321 | else if (!strcmp(args[cur_arg], "on-marked-up")) { |
| 4322 | if (!strcmp(args[cur_arg + 1], "shutdown-backup-sessions")) |
| 4323 | newsrv->onmarkedup = HANA_ONMARKEDUP_SHUTDOWNBACKUPSESSIONS; |
| 4324 | else { |
| 4325 | Alert("parsing [%s:%d]: '%s' expects 'shutdown-backup-sessions' but got '%s'\n", |
| 4326 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
| 4327 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4328 | goto out; |
| 4329 | } |
| 4330 | |
| 4331 | cur_arg += 2; |
| 4332 | } |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 4333 | else if (!strcmp(args[cur_arg], "error-limit")) { |
| 4334 | if (!*args[cur_arg + 1]) { |
| 4335 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 4336 | file, linenum, args[cur_arg]); |
| 4337 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4338 | goto out; |
| 4339 | } |
| 4340 | |
| 4341 | newsrv->consecutive_errors_limit = atoi(args[cur_arg + 1]); |
| 4342 | |
| 4343 | if (newsrv->consecutive_errors_limit <= 0) { |
| 4344 | Alert("parsing [%s:%d]: %s has to be > 0.\n", |
| 4345 | file, linenum, args[cur_arg]); |
| 4346 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4347 | goto out; |
| 4348 | } |
Willy Tarreau | f53b25d | 2010-03-15 19:40:37 +0100 | [diff] [blame] | 4349 | cur_arg += 2; |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 4350 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4351 | 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] | 4352 | int port_low, port_high; |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4353 | struct sockaddr_storage *sk; |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4354 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4355 | if (!*args[cur_arg + 1]) { |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4356 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 4357 | 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] | 4358 | file, linenum, "source", "usesrc"); |
| 4359 | #else |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 4360 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>[-<port>]] as argument.\n", |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4361 | file, linenum, "source"); |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 4362 | #endif |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4363 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4364 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4365 | } |
| 4366 | newsrv->state |= SRV_BIND_SRC; |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4367 | sk = str2sa_range(args[cur_arg + 1], &port_low, &port_high); |
| 4368 | if (!sk) { |
| 4369 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[cur_arg + 1]); |
| 4370 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4371 | goto out; |
| 4372 | } |
| 4373 | newsrv->source_addr = *sk; |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 4374 | |
| 4375 | if (port_low != port_high) { |
| 4376 | int i; |
| 4377 | if (port_low <= 0 || port_low > 65535 || |
| 4378 | port_high <= 0 || port_high > 65535 || |
| 4379 | port_low > port_high) { |
| 4380 | Alert("parsing [%s:%d] : invalid source port range %d-%d.\n", |
| 4381 | file, linenum, port_low, port_high); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4382 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4383 | goto out; |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 4384 | } |
| 4385 | newsrv->sport_range = port_range_alloc_range(port_high - port_low + 1); |
| 4386 | for (i = 0; i < newsrv->sport_range->size; i++) |
| 4387 | newsrv->sport_range->ports[i] = port_low + i; |
| 4388 | } |
| 4389 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4390 | cur_arg += 2; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4391 | while (*(args[cur_arg])) { |
| 4392 | if (!strcmp(args[cur_arg], "usesrc")) { /* address to use outside */ |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4393 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) |
| 4394 | #if !defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4395 | if (newsrv->source_addr.sin_addr.s_addr == INADDR_ANY) { |
| 4396 | Alert("parsing [%s:%d] : '%s' requires an explicit '%s' address.\n", |
| 4397 | file, linenum, "usesrc", "source"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4398 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4399 | goto out; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4400 | } |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4401 | #endif |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4402 | if (!*args[cur_arg + 1]) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4403 | 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] | 4404 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4405 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4406 | goto out; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4407 | } |
| 4408 | if (!strcmp(args[cur_arg + 1], "client")) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4409 | newsrv->state &= ~SRV_TPROXY_MASK; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4410 | newsrv->state |= SRV_TPROXY_CLI; |
| 4411 | } else if (!strcmp(args[cur_arg + 1], "clientip")) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4412 | newsrv->state &= ~SRV_TPROXY_MASK; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4413 | newsrv->state |= SRV_TPROXY_CIP; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4414 | } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) { |
| 4415 | char *name, *end; |
| 4416 | |
| 4417 | name = args[cur_arg+1] + 7; |
| 4418 | while (isspace(*name)) |
| 4419 | name++; |
| 4420 | |
| 4421 | end = name; |
| 4422 | while (*end && !isspace(*end) && *end != ',' && *end != ')') |
| 4423 | end++; |
| 4424 | |
| 4425 | newsrv->state &= ~SRV_TPROXY_MASK; |
| 4426 | newsrv->state |= SRV_TPROXY_DYN; |
| 4427 | newsrv->bind_hdr_name = calloc(1, end - name + 1); |
| 4428 | newsrv->bind_hdr_len = end - name; |
| 4429 | memcpy(newsrv->bind_hdr_name, name, end - name); |
| 4430 | newsrv->bind_hdr_name[end-name] = '\0'; |
| 4431 | newsrv->bind_hdr_occ = -1; |
| 4432 | |
| 4433 | /* now look for an occurrence number */ |
| 4434 | while (isspace(*end)) |
| 4435 | end++; |
| 4436 | if (*end == ',') { |
| 4437 | end++; |
| 4438 | name = end; |
| 4439 | if (*end == '-') |
| 4440 | end++; |
| 4441 | while (isdigit(*end)) |
| 4442 | end++; |
| 4443 | newsrv->bind_hdr_occ = strl2ic(name, end-name); |
| 4444 | } |
| 4445 | |
| 4446 | if (newsrv->bind_hdr_occ < -MAX_HDR_HISTORY) { |
| 4447 | Alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative" |
| 4448 | " occurrences values smaller than %d.\n", |
| 4449 | file, linenum, MAX_HDR_HISTORY); |
| 4450 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4451 | goto out; |
| 4452 | } |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4453 | } else { |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4454 | struct sockaddr_storage *sk = str2sa(args[cur_arg + 1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4455 | if (!sk) { |
| 4456 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[cur_arg + 1]); |
| 4457 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4458 | goto out; |
| 4459 | } |
| 4460 | newsrv->tproxy_addr = *sk; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4461 | newsrv->state |= SRV_TPROXY_ADDR; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4462 | } |
| 4463 | global.last_checks |= LSTCHK_NETADM; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4464 | #if !defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4465 | global.last_checks |= LSTCHK_CTTPROXY; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4466 | #endif |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4467 | cur_arg += 2; |
| 4468 | continue; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4469 | #else /* no TPROXY support */ |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4470 | 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] | 4471 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4472 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4473 | goto out; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4474 | #endif /* defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) */ |
| 4475 | } /* "usesrc" */ |
| 4476 | |
| 4477 | if (!strcmp(args[cur_arg], "interface")) { /* specifically bind to this interface */ |
| 4478 | #ifdef SO_BINDTODEVICE |
| 4479 | if (!*args[cur_arg + 1]) { |
| 4480 | Alert("parsing [%s:%d] : '%s' : missing interface name.\n", |
| 4481 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4482 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4483 | goto out; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4484 | } |
| 4485 | if (newsrv->iface_name) |
| 4486 | free(newsrv->iface_name); |
| 4487 | |
| 4488 | newsrv->iface_name = strdup(args[cur_arg + 1]); |
| 4489 | newsrv->iface_len = strlen(newsrv->iface_name); |
| 4490 | global.last_checks |= LSTCHK_NETADM; |
| 4491 | #else |
| 4492 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 4493 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4494 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4495 | goto out; |
Willy Tarreau | 77074d5 | 2006-11-12 23:57:19 +0100 | [diff] [blame] | 4496 | #endif |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4497 | cur_arg += 2; |
| 4498 | continue; |
| 4499 | } |
| 4500 | /* this keyword in not an option of "source" */ |
| 4501 | break; |
| 4502 | } /* while */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4503 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4504 | 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] | 4505 | Alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n", |
| 4506 | file, linenum, "usesrc", "source"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4507 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4508 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 4509 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4510 | else { |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4511 | if (!defsrv) |
Simon Horman | e0d1bfb | 2011-06-21 14:34:58 +0900 | [diff] [blame] | 4512 | 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] | 4513 | file, linenum, newsrv->id); |
| 4514 | else |
Krzysztof Piotr Oledzki | a9389b1 | 2010-01-05 16:44:17 +0100 | [diff] [blame] | 4515 | 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] | 4516 | file, linenum); |
| 4517 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4518 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4519 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4520 | } |
| 4521 | } |
| 4522 | |
| 4523 | if (do_check) { |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4524 | if (newsrv->trackit) { |
| 4525 | Alert("parsing [%s:%d]: unable to enable checks and tracking at the same time!\n", |
| 4526 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4527 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4528 | goto out; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4529 | } |
| 4530 | |
Willy Tarreau | 86ad42c | 2011-08-27 12:29:07 +0200 | [diff] [blame] | 4531 | /* try to get the port from check_addr if check_port not set */ |
| 4532 | if (!newsrv->check_port) |
| 4533 | newsrv->check_port = get_host_port(&newsrv->check_addr); |
Willy Tarreau | 0f03c6f | 2007-03-25 20:46:19 +0200 | [diff] [blame] | 4534 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4535 | if (!newsrv->check_port && !(newsrv->state & SRV_MAPPORTS)) |
| 4536 | newsrv->check_port = realport; /* by default */ |
| 4537 | if (!newsrv->check_port) { |
Willy Tarreau | ef00b50 | 2007-01-07 02:40:09 +0100 | [diff] [blame] | 4538 | /* not yet valid, because no port was set on |
| 4539 | * the server either. We'll check if we have |
| 4540 | * a known port on the first listener. |
| 4541 | */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 4542 | struct listener *l; |
| 4543 | |
| 4544 | list_for_each_entry(l, &curproxy->conf.listeners, by_fe) { |
| 4545 | newsrv->check_port = get_host_port(&l->addr); |
| 4546 | if (newsrv->check_port) |
| 4547 | break; |
| 4548 | } |
Willy Tarreau | ef00b50 | 2007-01-07 02:40:09 +0100 | [diff] [blame] | 4549 | } |
| 4550 | if (!newsrv->check_port) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4551 | Alert("parsing [%s:%d] : server %s has neither service port nor check port. Check has been disabled.\n", |
| 4552 | file, linenum, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4553 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4554 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4555 | } |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 4556 | |
Cyril Bonté | c9f825f | 2010-03-17 18:56:31 +0100 | [diff] [blame] | 4557 | /* Allocate buffer for partial check results... */ |
Willy Tarreau | 43961d5 | 2010-10-04 20:39:20 +0200 | [diff] [blame] | 4558 | if ((newsrv->check_data = calloc(global.tune.chksize, sizeof(char))) == NULL) { |
Cyril Bonté | c9f825f | 2010-03-17 18:56:31 +0100 | [diff] [blame] | 4559 | Alert("parsing [%s:%d] : out of memory while allocating check buffer.\n", file, linenum); |
| 4560 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4561 | goto out; |
| 4562 | } |
| 4563 | |
Willy Tarreau | da92e2f | 2012-07-06 09:40:59 +0200 | [diff] [blame] | 4564 | /* Allocate buffer for partial check results... */ |
| 4565 | if ((newsrv->check_conn = calloc(1, sizeof(struct connection))) == NULL) { |
| 4566 | Alert("parsing [%s:%d] : out of memory while allocating check connection.\n", file, linenum); |
| 4567 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4568 | goto out; |
| 4569 | } |
| 4570 | |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 4571 | newsrv->check_status = HCHK_STATUS_INI; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4572 | newsrv->state |= SRV_CHECKED; |
| 4573 | } |
| 4574 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4575 | if (!defsrv) { |
| 4576 | if (newsrv->state & SRV_BACKUP) |
| 4577 | curproxy->srv_bck++; |
| 4578 | else |
| 4579 | curproxy->srv_act++; |
Willy Tarreau | b625a08 | 2007-11-26 01:15:43 +0100 | [diff] [blame] | 4580 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4581 | newsrv->prev_state = newsrv->state; |
| 4582 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 4583 | } |
| 4584 | |
| 4585 | else if (strcmp(args[0], "unique-id-format") == 0) { |
| 4586 | if (!*(args[1])) { |
| 4587 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 4588 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4589 | goto out; |
| 4590 | } |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 4591 | free(curproxy->uniqueid_format_string); |
| 4592 | curproxy->uniqueid_format_string = strdup(args[1]); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4593 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 4594 | |
| 4595 | else if (strcmp(args[0], "unique-id-header") == 0) { |
| 4596 | if (!*(args[1])) { |
| 4597 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 4598 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4599 | goto out; |
| 4600 | } |
| 4601 | free(curproxy->header_unique_id); |
| 4602 | curproxy->header_unique_id = strdup(args[1]); |
| 4603 | } |
| 4604 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4605 | else if (strcmp(args[0], "log-format") == 0) { |
| 4606 | if (!*(args[1])) { |
| 4607 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 4608 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4609 | goto out; |
| 4610 | } |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 4611 | |
| 4612 | if (curproxy->logformat_string != default_http_log_format && |
| 4613 | curproxy->logformat_string != default_tcp_log_format && |
| 4614 | curproxy->logformat_string != clf_http_log_format) |
| 4615 | free(curproxy->logformat_string); |
| 4616 | curproxy->logformat_string = strdup(args[1]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4617 | } |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4618 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4619 | else if (!strcmp(args[0], "log") && kwm == KWM_NO) { |
| 4620 | /* delete previous herited or defined syslog servers */ |
| 4621 | struct logsrv *back; |
| 4622 | |
| 4623 | if (*(args[1]) != 0) { |
| 4624 | Alert("parsing [%s:%d]:%s : 'no log' does not expect arguments.\n", file, linenum, args[1]); |
| 4625 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4626 | goto out; |
| 4627 | } |
| 4628 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4629 | list_for_each_entry_safe(tmplogsrv, back, &curproxy->logsrvs, list) { |
| 4630 | LIST_DEL(&tmplogsrv->list); |
| 4631 | free(tmplogsrv); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4632 | } |
| 4633 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4634 | else if (!strcmp(args[0], "log")) { /* syslog server address */ |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4635 | struct logsrv *logsrv; |
| 4636 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4637 | if (*(args[1]) && *(args[2]) == 0 && !strcmp(args[1], "global")) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4638 | /* copy global.logrsvs linked list to the end of curproxy->logsrvs */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4639 | list_for_each_entry(tmplogsrv, &global.logsrvs, list) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4640 | struct logsrv *node = malloc(sizeof(struct logsrv)); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4641 | memcpy(node, tmplogsrv, sizeof(struct logsrv)); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4642 | LIST_INIT(&node->list); |
| 4643 | LIST_ADDQ(&curproxy->logsrvs, &node->list); |
| 4644 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4645 | } |
| 4646 | else if (*(args[1]) && *(args[2])) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4647 | |
| 4648 | logsrv = calloc(1, sizeof(struct logsrv)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4649 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4650 | logsrv->facility = get_log_facility(args[2]); |
| 4651 | if (logsrv->facility < 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4652 | 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] | 4653 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4654 | goto out; |
| 4655 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4656 | } |
| 4657 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4658 | logsrv->level = 7; /* max syslog level = debug */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4659 | if (*(args[3])) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4660 | logsrv->level = get_log_level(args[3]); |
| 4661 | if (logsrv->level < 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4662 | 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] | 4663 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4664 | goto out; |
| 4665 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4666 | } |
| 4667 | } |
| 4668 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4669 | logsrv->minlvl = 0; /* limit syslog level to this level (emerg) */ |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 4670 | if (*(args[4])) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4671 | logsrv->minlvl = get_log_level(args[4]); |
| 4672 | if (logsrv->level < 0) { |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 4673 | 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] | 4674 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4675 | goto out; |
| 4676 | |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 4677 | } |
| 4678 | } |
| 4679 | |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 4680 | if (args[1][0] == '/') { |
David du Colombier | 11bcb6c | 2011-03-24 12:23:00 +0100 | [diff] [blame] | 4681 | struct sockaddr_storage *sk = (struct sockaddr_storage *)str2sun(args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4682 | if (!sk) { |
| 4683 | 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] | 4684 | args[1], (int)sizeof(((struct sockaddr_un *)sk)->sun_path) - 1); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4685 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4686 | goto out; |
| 4687 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4688 | logsrv->addr = *sk; |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 4689 | } else { |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4690 | struct sockaddr_storage *sk = str2sa(args[1]); |
David du Colombier | 11bcb6c | 2011-03-24 12:23:00 +0100 | [diff] [blame] | 4691 | if (!sk) { |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4692 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[1]); |
| 4693 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4694 | goto out; |
| 4695 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4696 | logsrv->addr = *sk; |
| 4697 | if (!get_host_port(&logsrv->addr)) |
| 4698 | set_host_port(&logsrv->addr, SYSLOG_PORT); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4699 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4700 | |
| 4701 | LIST_ADDQ(&curproxy->logsrvs, &logsrv->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4702 | } |
| 4703 | else { |
| 4704 | Alert("parsing [%s:%d] : 'log' expects either <address[:port]> and <facility> or 'global' as arguments.\n", |
| 4705 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4706 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4707 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4708 | } |
| 4709 | } |
| 4710 | 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] | 4711 | int cur_arg; |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4712 | struct sockaddr_storage *sk; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4713 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4714 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4715 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4716 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4717 | if (!*args[1]) { |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4718 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optionally '%s' <addr>, and '%s' <name>.\n", |
| 4719 | file, linenum, "source", "usesrc", "interface"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4720 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4721 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4722 | } |
Willy Tarreau | 368480c | 2009-03-01 08:27:21 +0100 | [diff] [blame] | 4723 | |
| 4724 | /* we must first clear any optional default setting */ |
| 4725 | curproxy->options &= ~PR_O_TPXY_MASK; |
| 4726 | free(curproxy->iface_name); |
| 4727 | curproxy->iface_name = NULL; |
| 4728 | curproxy->iface_len = 0; |
| 4729 | |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4730 | sk = str2sa(args[1]); |
| 4731 | if (!sk) { |
| 4732 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[1]); |
| 4733 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4734 | goto out; |
| 4735 | } |
| 4736 | curproxy->source_addr = *sk; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4737 | curproxy->options |= PR_O_BIND_SRC; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4738 | |
| 4739 | cur_arg = 2; |
| 4740 | while (*(args[cur_arg])) { |
| 4741 | if (!strcmp(args[cur_arg], "usesrc")) { /* address to use outside */ |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4742 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) |
| 4743 | #if !defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4744 | if (curproxy->source_addr.sin_addr.s_addr == INADDR_ANY) { |
| 4745 | Alert("parsing [%s:%d] : '%s' requires an explicit 'source' address.\n", |
| 4746 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4747 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4748 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4749 | } |
| 4750 | #endif |
| 4751 | if (!*args[cur_arg + 1]) { |
| 4752 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n", |
| 4753 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4754 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4755 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4756 | } |
| 4757 | |
| 4758 | if (!strcmp(args[cur_arg + 1], "client")) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4759 | curproxy->options &= ~PR_O_TPXY_MASK; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4760 | curproxy->options |= PR_O_TPXY_CLI; |
| 4761 | } else if (!strcmp(args[cur_arg + 1], "clientip")) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4762 | curproxy->options &= ~PR_O_TPXY_MASK; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4763 | curproxy->options |= PR_O_TPXY_CIP; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4764 | } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) { |
| 4765 | char *name, *end; |
| 4766 | |
| 4767 | name = args[cur_arg+1] + 7; |
| 4768 | while (isspace(*name)) |
| 4769 | name++; |
| 4770 | |
| 4771 | end = name; |
| 4772 | while (*end && !isspace(*end) && *end != ',' && *end != ')') |
| 4773 | end++; |
| 4774 | |
| 4775 | curproxy->options &= ~PR_O_TPXY_MASK; |
| 4776 | curproxy->options |= PR_O_TPXY_DYN; |
| 4777 | curproxy->bind_hdr_name = calloc(1, end - name + 1); |
| 4778 | curproxy->bind_hdr_len = end - name; |
| 4779 | memcpy(curproxy->bind_hdr_name, name, end - name); |
| 4780 | curproxy->bind_hdr_name[end-name] = '\0'; |
| 4781 | curproxy->bind_hdr_occ = -1; |
| 4782 | |
| 4783 | /* now look for an occurrence number */ |
| 4784 | while (isspace(*end)) |
| 4785 | end++; |
| 4786 | if (*end == ',') { |
| 4787 | end++; |
| 4788 | name = end; |
| 4789 | if (*end == '-') |
| 4790 | end++; |
| 4791 | while (isdigit(*end)) |
| 4792 | end++; |
| 4793 | curproxy->bind_hdr_occ = strl2ic(name, end-name); |
| 4794 | } |
| 4795 | |
| 4796 | if (curproxy->bind_hdr_occ < -MAX_HDR_HISTORY) { |
| 4797 | Alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative" |
| 4798 | " occurrences values smaller than %d.\n", |
| 4799 | file, linenum, MAX_HDR_HISTORY); |
| 4800 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4801 | goto out; |
| 4802 | } |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4803 | } else { |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4804 | struct sockaddr_storage *sk = str2sa(args[cur_arg + 1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4805 | if (!sk) { |
| 4806 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[cur_arg + 1]); |
| 4807 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4808 | goto out; |
| 4809 | } |
| 4810 | curproxy->tproxy_addr = *sk; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4811 | curproxy->options |= PR_O_TPXY_ADDR; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4812 | } |
| 4813 | global.last_checks |= LSTCHK_NETADM; |
| 4814 | #if !defined(CONFIG_HAP_LINUX_TPROXY) |
| 4815 | global.last_checks |= LSTCHK_CTTPROXY; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4816 | #endif |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4817 | #else /* no TPROXY support */ |
| 4818 | 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] | 4819 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4820 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4821 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4822 | #endif |
| 4823 | cur_arg += 2; |
| 4824 | continue; |
Willy Tarreau | 77074d5 | 2006-11-12 23:57:19 +0100 | [diff] [blame] | 4825 | } |
| 4826 | |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4827 | if (!strcmp(args[cur_arg], "interface")) { /* specifically bind to this interface */ |
| 4828 | #ifdef SO_BINDTODEVICE |
| 4829 | if (!*args[cur_arg + 1]) { |
| 4830 | Alert("parsing [%s:%d] : '%s' : missing interface name.\n", |
| 4831 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4832 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4833 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4834 | } |
| 4835 | if (curproxy->iface_name) |
| 4836 | free(curproxy->iface_name); |
| 4837 | |
| 4838 | curproxy->iface_name = strdup(args[cur_arg + 1]); |
| 4839 | curproxy->iface_len = strlen(curproxy->iface_name); |
| 4840 | global.last_checks |= LSTCHK_NETADM; |
| 4841 | #else |
| 4842 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 4843 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4844 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4845 | goto out; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4846 | #endif |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4847 | cur_arg += 2; |
| 4848 | continue; |
| 4849 | } |
| 4850 | Alert("parsing [%s:%d] : '%s' only supports optional keywords '%s' and '%s'.\n", |
| 4851 | file, linenum, args[0], "inteface", "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4852 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4853 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 4854 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4855 | } |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 4856 | else if (!strcmp(args[0], "usesrc")) { /* address to use outside: needs "source" first */ |
| 4857 | Alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n", |
| 4858 | file, linenum, "usesrc", "source"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4859 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4860 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 4861 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4862 | 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] | 4863 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4864 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 4865 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4866 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4867 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4868 | } |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4869 | |
| 4870 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 4871 | SMP_OPT_DIR_REQ, ACT_REPLACE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4872 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4873 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4874 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4875 | } |
| 4876 | else if (!strcmp(args[0], "reqdel")) { /* delete request header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4877 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 4878 | SMP_OPT_DIR_REQ, ACT_REMOVE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4879 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4880 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4881 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4882 | } |
| 4883 | 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] | 4884 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 4885 | SMP_OPT_DIR_REQ, ACT_DENY, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4886 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4887 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4888 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4889 | } |
| 4890 | 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] | 4891 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 4892 | SMP_OPT_DIR_REQ, ACT_PASS, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4893 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4894 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4895 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4896 | } |
| 4897 | 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] | 4898 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 4899 | SMP_OPT_DIR_REQ, ACT_ALLOW, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4900 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4901 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4902 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4903 | } |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 4904 | 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] | 4905 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 4906 | SMP_OPT_DIR_REQ, ACT_TARPIT, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4907 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4908 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4909 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 4910 | } |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 4911 | 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] | 4912 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 4913 | SMP_OPT_DIR_REQ, ACT_SETBE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4914 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4915 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4916 | goto out; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 4917 | } |
| 4918 | 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] | 4919 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 4920 | SMP_OPT_DIR_REQ, ACT_SETBE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4921 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4922 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4923 | goto out; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 4924 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4925 | 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] | 4926 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4927 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 4928 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4929 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4930 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4931 | } |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4932 | |
| 4933 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 4934 | SMP_OPT_DIR_REQ, ACT_REPLACE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4935 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4936 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4937 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4938 | } |
| 4939 | else if (!strcmp(args[0], "reqidel")) { /* delete request header from a regex ignoring case */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4940 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 4941 | SMP_OPT_DIR_REQ, ACT_REMOVE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4942 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4943 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4944 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4945 | } |
| 4946 | 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] | 4947 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 4948 | SMP_OPT_DIR_REQ, ACT_DENY, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4949 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4950 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4951 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4952 | } |
| 4953 | 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] | 4954 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 4955 | SMP_OPT_DIR_REQ, ACT_PASS, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4956 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4957 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4958 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4959 | } |
| 4960 | 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] | 4961 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 4962 | SMP_OPT_DIR_REQ, ACT_ALLOW, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4963 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4964 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4965 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4966 | } |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 4967 | 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] | 4968 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 4969 | SMP_OPT_DIR_REQ, ACT_TARPIT, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4970 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4971 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4972 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 4973 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4974 | else if (!strcmp(args[0], "reqadd")) { /* add request header */ |
Willy Tarreau | f4f0412 | 2010-01-28 18:10:50 +0100 | [diff] [blame] | 4975 | struct cond_wordlist *wl; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 4976 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4977 | if (curproxy == &defproxy) { |
| 4978 | 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] | 4979 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4980 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4981 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4982 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4983 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4984 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4985 | if (*(args[1]) == 0) { |
| 4986 | 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] | 4987 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4988 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4989 | } |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 4990 | |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 4991 | if ((strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0)) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 4992 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args+2, &errmsg)) == NULL) { |
| 4993 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 4994 | file, linenum, args[0], errmsg); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 4995 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4996 | goto out; |
| 4997 | } |
| 4998 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
| 4999 | } |
| 5000 | else if (*args[2]) { |
| 5001 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 5002 | file, linenum, args[0], args[2]); |
| 5003 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5004 | goto out; |
| 5005 | } |
| 5006 | |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5007 | wl = calloc(1, sizeof(*wl)); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 5008 | wl->cond = cond; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5009 | wl->s = strdup(args[1]); |
| 5010 | LIST_ADDQ(&curproxy->req_add, &wl->list); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 5011 | warnif_misplaced_reqadd(curproxy, file, linenum, args[0]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5012 | } |
| 5013 | 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] | 5014 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5015 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 5016 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5017 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5018 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5019 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5020 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5021 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5022 | SMP_OPT_DIR_RES, ACT_REPLACE, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5023 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5024 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5025 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5026 | } |
| 5027 | else if (!strcmp(args[0], "rspdel")) { /* delete response header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5028 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5029 | SMP_OPT_DIR_RES, ACT_REMOVE, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5030 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5031 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5032 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5033 | } |
| 5034 | else if (!strcmp(args[0], "rspdeny")) { /* block response header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5035 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5036 | SMP_OPT_DIR_RES, ACT_DENY, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5037 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5038 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5039 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5040 | } |
| 5041 | 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] | 5042 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5043 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 5044 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5045 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5046 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5047 | } |
| 5048 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5049 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5050 | SMP_OPT_DIR_RES, ACT_REPLACE, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5051 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5052 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5053 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5054 | } |
| 5055 | 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] | 5056 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5057 | SMP_OPT_DIR_RES, ACT_REMOVE, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5058 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5059 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5060 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5061 | } |
| 5062 | 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] | 5063 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5064 | SMP_OPT_DIR_RES, ACT_DENY, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5065 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5066 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5067 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5068 | } |
| 5069 | else if (!strcmp(args[0], "rspadd")) { /* add response header */ |
Willy Tarreau | f4f0412 | 2010-01-28 18:10:50 +0100 | [diff] [blame] | 5070 | struct cond_wordlist *wl; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5071 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5072 | if (curproxy == &defproxy) { |
| 5073 | 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] | 5074 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5075 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5076 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5077 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5078 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5079 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5080 | if (*(args[1]) == 0) { |
| 5081 | 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] | 5082 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5083 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5084 | } |
| 5085 | |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5086 | if ((strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0)) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 5087 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args+2, &errmsg)) == NULL) { |
| 5088 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 5089 | file, linenum, args[0], errmsg); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5090 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5091 | goto out; |
| 5092 | } |
| 5093 | err_code |= warnif_cond_requires_req(cond, file, linenum); |
| 5094 | } |
| 5095 | else if (*args[2]) { |
| 5096 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 5097 | file, linenum, args[0], args[2]); |
| 5098 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5099 | goto out; |
| 5100 | } |
| 5101 | |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5102 | wl = calloc(1, sizeof(*wl)); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5103 | wl->cond = cond; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5104 | wl->s = strdup(args[1]); |
| 5105 | LIST_ADDQ(&curproxy->rsp_add, &wl->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5106 | } |
| 5107 | else if (!strcmp(args[0], "errorloc") || |
| 5108 | !strcmp(args[0], "errorloc302") || |
| 5109 | !strcmp(args[0], "errorloc303")) { /* error location */ |
| 5110 | int errnum, errlen; |
| 5111 | char *err; |
| 5112 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5113 | 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] | 5114 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5115 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5116 | if (*(args[2]) == 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 5117 | 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] | 5118 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5119 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5120 | } |
| 5121 | |
| 5122 | errnum = atol(args[1]); |
| 5123 | if (!strcmp(args[0], "errorloc303")) { |
| 5124 | err = malloc(strlen(HTTP_303) + strlen(args[2]) + 5); |
| 5125 | errlen = sprintf(err, "%s%s\r\n\r\n", HTTP_303, args[2]); |
| 5126 | } else { |
| 5127 | err = malloc(strlen(HTTP_302) + strlen(args[2]) + 5); |
| 5128 | errlen = sprintf(err, "%s%s\r\n\r\n", HTTP_302, args[2]); |
| 5129 | } |
| 5130 | |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 5131 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) { |
| 5132 | if (http_err_codes[rc] == errnum) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 5133 | chunk_destroy(&curproxy->errmsg[rc]); |
| 5134 | chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 5135 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5136 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5137 | } |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 5138 | |
| 5139 | if (rc >= HTTP_ERR_SIZE) { |
| 5140 | Warning("parsing [%s:%d] : status code %d not handled, error relocation will be ignored.\n", |
| 5141 | file, linenum, errnum); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5142 | free(err); |
| 5143 | } |
| 5144 | } |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5145 | else if (!strcmp(args[0], "errorfile")) { /* error message from a file */ |
| 5146 | int errnum, errlen, fd; |
| 5147 | char *err; |
| 5148 | struct stat stat; |
| 5149 | |
| 5150 | 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] | 5151 | err_code |= ERR_WARN; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5152 | |
| 5153 | if (*(args[2]) == 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 5154 | 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] | 5155 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5156 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5157 | } |
| 5158 | |
| 5159 | fd = open(args[2], O_RDONLY); |
| 5160 | if ((fd < 0) || (fstat(fd, &stat) < 0)) { |
| 5161 | Alert("parsing [%s:%d] : error opening file <%s> for custom error message <%s>.\n", |
| 5162 | file, linenum, args[2], args[1]); |
| 5163 | if (fd >= 0) |
| 5164 | close(fd); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5165 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5166 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5167 | } |
| 5168 | |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 5169 | if (stat.st_size <= global.tune.bufsize) { |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5170 | errlen = stat.st_size; |
| 5171 | } else { |
| 5172 | 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] | 5173 | file, linenum, args[2], global.tune.bufsize); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5174 | err_code |= ERR_WARN; |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 5175 | errlen = global.tune.bufsize; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5176 | } |
| 5177 | |
| 5178 | err = malloc(errlen); /* malloc() must succeed during parsing */ |
| 5179 | errnum = read(fd, err, errlen); |
| 5180 | if (errnum != errlen) { |
| 5181 | Alert("parsing [%s:%d] : error reading file <%s> for custom error message <%s>.\n", |
| 5182 | file, linenum, args[2], args[1]); |
| 5183 | close(fd); |
| 5184 | free(err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5185 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5186 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5187 | } |
| 5188 | close(fd); |
| 5189 | |
| 5190 | errnum = atol(args[1]); |
| 5191 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) { |
| 5192 | if (http_err_codes[rc] == errnum) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 5193 | chunk_destroy(&curproxy->errmsg[rc]); |
| 5194 | chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen); |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5195 | break; |
| 5196 | } |
| 5197 | } |
| 5198 | |
| 5199 | if (rc >= HTTP_ERR_SIZE) { |
| 5200 | Warning("parsing [%s:%d] : status code %d not handled, error customization will be ignored.\n", |
| 5201 | file, linenum, errnum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5202 | err_code |= ERR_WARN; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5203 | free(err); |
| 5204 | } |
| 5205 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5206 | else { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 5207 | struct cfg_kw_list *kwl; |
| 5208 | int index; |
| 5209 | |
| 5210 | list_for_each_entry(kwl, &cfg_keywords.list, list) { |
| 5211 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 5212 | if (kwl->kw[index].section != CFG_LISTEN) |
| 5213 | continue; |
| 5214 | if (strcmp(kwl->kw[index].kw, args[0]) == 0) { |
| 5215 | /* prepare error message just in case */ |
David du Colombier | 7af4605 | 2012-05-16 14:16:48 +0200 | [diff] [blame] | 5216 | snprintf(trash, trashlen, |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 5217 | "error near '%s' in %s section", args[0], cursection); |
Willy Tarreau | 28a47d6 | 2012-09-18 20:02:48 +0200 | [diff] [blame] | 5218 | 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] | 5219 | if (rc < 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 5220 | Alert("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5221 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5222 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 5223 | } |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 5224 | else if (rc > 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 5225 | Warning("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5226 | err_code |= ERR_WARN; |
| 5227 | goto out; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 5228 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5229 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 5230 | } |
| 5231 | } |
| 5232 | } |
| 5233 | |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5234 | 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] | 5235 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5236 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5237 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5238 | out: |
Willy Tarreau | f4068b6 | 2012-05-08 17:37:49 +0200 | [diff] [blame] | 5239 | free(errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5240 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5241 | } |
| 5242 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5243 | int |
| 5244 | cfg_parse_users(const char *file, int linenum, char **args, int kwm) |
| 5245 | { |
| 5246 | |
| 5247 | int err_code = 0; |
| 5248 | const char *err; |
| 5249 | |
| 5250 | if (!strcmp(args[0], "userlist")) { /* new userlist */ |
| 5251 | struct userlist *newul; |
| 5252 | |
| 5253 | if (!*args[1]) { |
| 5254 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 5255 | file, linenum, args[0]); |
| 5256 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5257 | goto out; |
| 5258 | } |
| 5259 | |
| 5260 | err = invalid_char(args[1]); |
| 5261 | if (err) { |
| 5262 | Alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 5263 | file, linenum, *err, args[0], args[1]); |
| 5264 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5265 | goto out; |
| 5266 | } |
| 5267 | |
| 5268 | for (newul = userlist; newul; newul = newul->next) |
| 5269 | if (!strcmp(newul->name, args[1])) { |
| 5270 | Warning("parsing [%s:%d]: ignoring duplicated userlist '%s'.\n", |
| 5271 | file, linenum, args[1]); |
| 5272 | err_code |= ERR_WARN; |
| 5273 | goto out; |
| 5274 | } |
| 5275 | |
| 5276 | newul = (struct userlist *)calloc(1, sizeof(struct userlist)); |
| 5277 | if (!newul) { |
| 5278 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 5279 | err_code |= ERR_ALERT | ERR_ABORT; |
| 5280 | goto out; |
| 5281 | } |
| 5282 | |
| 5283 | newul->groupusers = calloc(MAX_AUTH_GROUPS, sizeof(char *)); |
| 5284 | newul->name = strdup(args[1]); |
| 5285 | |
| 5286 | if (!newul->groupusers | !newul->name) { |
| 5287 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 5288 | err_code |= ERR_ALERT | ERR_ABORT; |
| 5289 | goto out; |
| 5290 | } |
| 5291 | |
| 5292 | newul->next = userlist; |
| 5293 | userlist = newul; |
| 5294 | |
| 5295 | } else if (!strcmp(args[0], "group")) { /* new group */ |
| 5296 | int cur_arg, i; |
| 5297 | const char *err; |
| 5298 | |
| 5299 | if (!*args[1]) { |
| 5300 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 5301 | file, linenum, args[0]); |
| 5302 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5303 | goto out; |
| 5304 | } |
| 5305 | |
| 5306 | err = invalid_char(args[1]); |
| 5307 | if (err) { |
| 5308 | Alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 5309 | file, linenum, *err, args[0], args[1]); |
| 5310 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5311 | goto out; |
| 5312 | } |
| 5313 | |
| 5314 | for(i = 0; i < userlist->grpcnt; i++) |
| 5315 | if (!strcmp(userlist->groups[i], args[1])) { |
| 5316 | Warning("parsing [%s:%d]: ignoring duplicated group '%s' in userlist '%s'.\n", |
| 5317 | file, linenum, args[1], userlist->name); |
| 5318 | err_code |= ERR_ALERT; |
| 5319 | goto out; |
| 5320 | } |
| 5321 | |
| 5322 | if (userlist->grpcnt >= MAX_AUTH_GROUPS) { |
| 5323 | Alert("parsing [%s:%d]: too many groups (%u) in in userlist '%s' while adding group '%s'.\n", |
| 5324 | file, linenum, MAX_AUTH_GROUPS, userlist->name, args[1]); |
| 5325 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5326 | goto out; |
| 5327 | } |
| 5328 | |
| 5329 | cur_arg = 2; |
| 5330 | |
| 5331 | while (*args[cur_arg]) { |
| 5332 | if (!strcmp(args[cur_arg], "users")) { |
| 5333 | userlist->groupusers[userlist->grpcnt] = strdup(args[cur_arg + 1]); |
| 5334 | cur_arg += 2; |
| 5335 | continue; |
| 5336 | } else { |
| 5337 | Alert("parsing [%s:%d]: '%s' only supports 'users' option.\n", |
| 5338 | file, linenum, args[0]); |
| 5339 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5340 | goto out; |
| 5341 | } |
| 5342 | } |
| 5343 | |
| 5344 | userlist->groups[userlist->grpcnt++] = strdup(args[1]); |
| 5345 | } else if (!strcmp(args[0], "user")) { /* new user */ |
| 5346 | struct auth_users *newuser; |
| 5347 | int cur_arg; |
| 5348 | |
| 5349 | if (!*args[1]) { |
| 5350 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 5351 | file, linenum, args[0]); |
| 5352 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5353 | goto out; |
| 5354 | } |
| 5355 | |
| 5356 | for (newuser = userlist->users; newuser; newuser = newuser->next) |
| 5357 | if (!strcmp(newuser->user, args[1])) { |
| 5358 | Warning("parsing [%s:%d]: ignoring duplicated user '%s' in userlist '%s'.\n", |
| 5359 | file, linenum, args[1], userlist->name); |
| 5360 | err_code |= ERR_ALERT; |
| 5361 | goto out; |
| 5362 | } |
| 5363 | |
| 5364 | newuser = (struct auth_users *)calloc(1, sizeof(struct auth_users)); |
| 5365 | if (!newuser) { |
| 5366 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 5367 | err_code |= ERR_ALERT | ERR_ABORT; |
| 5368 | goto out; |
| 5369 | } |
| 5370 | |
| 5371 | newuser->user = strdup(args[1]); |
| 5372 | |
| 5373 | newuser->next = userlist->users; |
| 5374 | userlist->users = newuser; |
| 5375 | |
| 5376 | cur_arg = 2; |
| 5377 | |
| 5378 | while (*args[cur_arg]) { |
| 5379 | if (!strcmp(args[cur_arg], "password")) { |
| 5380 | #ifndef CONFIG_HAP_CRYPT |
| 5381 | Warning("parsing [%s:%d]: no crypt(3) support compiled, encrypted passwords will not work.\n", |
| 5382 | file, linenum); |
| 5383 | err_code |= ERR_ALERT; |
| 5384 | #endif |
| 5385 | newuser->pass = strdup(args[cur_arg + 1]); |
| 5386 | cur_arg += 2; |
| 5387 | continue; |
| 5388 | } else if (!strcmp(args[cur_arg], "insecure-password")) { |
| 5389 | newuser->pass = strdup(args[cur_arg + 1]); |
| 5390 | newuser->flags |= AU_O_INSECURE; |
| 5391 | cur_arg += 2; |
| 5392 | continue; |
| 5393 | } else if (!strcmp(args[cur_arg], "groups")) { |
Willy Tarreau | b4c06b7 | 2010-02-02 11:28:20 +0100 | [diff] [blame] | 5394 | newuser->u.groups = strdup(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5395 | cur_arg += 2; |
| 5396 | continue; |
| 5397 | } else { |
| 5398 | Alert("parsing [%s:%d]: '%s' only supports 'password', 'insecure-password' and 'groups' options.\n", |
| 5399 | file, linenum, args[0]); |
| 5400 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5401 | goto out; |
| 5402 | } |
| 5403 | } |
| 5404 | } else { |
| 5405 | Alert("parsing [%s:%d]: unknown keyword '%s' in '%s' section\n", file, linenum, args[0], "users"); |
| 5406 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5407 | } |
| 5408 | |
| 5409 | out: |
| 5410 | return err_code; |
| 5411 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5412 | |
| 5413 | /* |
| 5414 | * This function reads and parses the configuration file given in the argument. |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5415 | * Returns the error code, 0 if OK, or any combination of : |
| 5416 | * - ERR_ABORT: must abort ASAP |
| 5417 | * - ERR_FATAL: we can continue parsing but not start the service |
| 5418 | * - ERR_WARN: a warning has been emitted |
| 5419 | * - ERR_ALERT: an alert has been emitted |
| 5420 | * Only the two first ones can stop processing, the two others are just |
| 5421 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5422 | */ |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 5423 | int readcfgfile(const char *file) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5424 | { |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5425 | char thisline[LINESIZE]; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5426 | FILE *f; |
| 5427 | int linenum = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5428 | int confsect = CFG_NONE; |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5429 | int err_code = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5430 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5431 | if ((f=fopen(file,"r")) == NULL) |
| 5432 | return -1; |
| 5433 | |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5434 | while (fgets(thisline, sizeof(thisline), f) != NULL) { |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 5435 | int arg, kwm = KWM_STD; |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5436 | char *end; |
| 5437 | char *args[MAX_LINE_ARGS + 1]; |
| 5438 | char *line = thisline; |
| 5439 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5440 | linenum++; |
| 5441 | |
| 5442 | end = line + strlen(line); |
| 5443 | |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5444 | if (end-line == sizeof(thisline)-1 && *(end-1) != '\n') { |
| 5445 | /* Check if we reached the limit and the last char is not \n. |
| 5446 | * Watch out for the last line without the terminating '\n'! |
| 5447 | */ |
| 5448 | Alert("parsing [%s:%d]: line too long, limit: %d.\n", |
Willy Tarreau | 5e4a6f1 | 2009-04-11 19:42:49 +0200 | [diff] [blame] | 5449 | file, linenum, (int)sizeof(thisline)-1); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5450 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5451 | } |
| 5452 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5453 | /* skip leading spaces */ |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 5454 | while (isspace((unsigned char)*line)) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5455 | line++; |
| 5456 | |
| 5457 | arg = 0; |
| 5458 | args[arg] = line; |
| 5459 | |
| 5460 | while (*line && arg < MAX_LINE_ARGS) { |
| 5461 | /* first, we'll replace \\, \<space>, \#, \r, \n, \t, \xXX with their |
| 5462 | * C equivalent value. Other combinations left unchanged (eg: \1). |
| 5463 | */ |
| 5464 | if (*line == '\\') { |
| 5465 | int skip = 0; |
| 5466 | if (line[1] == ' ' || line[1] == '\\' || line[1] == '#') { |
| 5467 | *line = line[1]; |
| 5468 | skip = 1; |
| 5469 | } |
| 5470 | else if (line[1] == 'r') { |
| 5471 | *line = '\r'; |
| 5472 | skip = 1; |
| 5473 | } |
| 5474 | else if (line[1] == 'n') { |
| 5475 | *line = '\n'; |
| 5476 | skip = 1; |
| 5477 | } |
| 5478 | else if (line[1] == 't') { |
| 5479 | *line = '\t'; |
| 5480 | skip = 1; |
| 5481 | } |
| 5482 | else if (line[1] == 'x') { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5483 | if ((line + 3 < end) && ishex(line[2]) && ishex(line[3])) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5484 | unsigned char hex1, hex2; |
| 5485 | hex1 = toupper(line[2]) - '0'; |
| 5486 | hex2 = toupper(line[3]) - '0'; |
| 5487 | if (hex1 > 9) hex1 -= 'A' - '9' - 1; |
| 5488 | if (hex2 > 9) hex2 -= 'A' - '9' - 1; |
| 5489 | *line = (hex1<<4) + hex2; |
| 5490 | skip = 3; |
| 5491 | } |
| 5492 | else { |
| 5493 | 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] | 5494 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5495 | } |
| 5496 | } |
| 5497 | if (skip) { |
Cyril Bonté | dd1b01d | 2009-12-06 13:43:42 +0100 | [diff] [blame] | 5498 | memmove(line + 1, line + 1 + skip, end - (line + skip)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5499 | end -= skip; |
| 5500 | } |
| 5501 | line++; |
| 5502 | } |
| 5503 | else if (*line == '#' || *line == '\n' || *line == '\r') { |
| 5504 | /* end of string, end of loop */ |
| 5505 | *line = 0; |
| 5506 | break; |
| 5507 | } |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 5508 | else if (isspace((unsigned char)*line)) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5509 | /* a non-escaped space is an argument separator */ |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5510 | *line++ = '\0'; |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 5511 | while (isspace((unsigned char)*line)) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5512 | line++; |
| 5513 | args[++arg] = line; |
| 5514 | } |
| 5515 | else { |
| 5516 | line++; |
| 5517 | } |
| 5518 | } |
| 5519 | |
| 5520 | /* empty line */ |
| 5521 | if (!**args) |
| 5522 | continue; |
| 5523 | |
Willy Tarreau | 7bb651e | 2009-11-09 21:16:53 +0100 | [diff] [blame] | 5524 | if (*line) { |
| 5525 | /* we had to stop due to too many args. |
| 5526 | * Let's terminate the string, print the offending part then cut the |
| 5527 | * last arg. |
| 5528 | */ |
| 5529 | while (*line && *line != '#' && *line != '\n' && *line != '\r') |
| 5530 | line++; |
| 5531 | *line = '\0'; |
| 5532 | |
Krzysztof Piotr Oledzki | 500b8f0 | 2009-12-15 22:34:51 +0100 | [diff] [blame] | 5533 | 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] | 5534 | file, linenum, arg + 1, (long)(args[arg] - thisline + 1), args[arg]); |
Willy Tarreau | 7bb651e | 2009-11-09 21:16:53 +0100 | [diff] [blame] | 5535 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5536 | args[arg] = line; |
| 5537 | } |
| 5538 | |
Willy Tarreau | 540abe4 | 2007-05-02 20:50:16 +0200 | [diff] [blame] | 5539 | /* zero out remaining args and ensure that at least one entry |
| 5540 | * is zeroed out. |
| 5541 | */ |
| 5542 | while (++arg <= MAX_LINE_ARGS) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5543 | args[arg] = line; |
| 5544 | } |
| 5545 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 5546 | /* check for keyword modifiers "no" and "default" */ |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5547 | if (!strcmp(args[0], "no")) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5548 | char *tmp; |
| 5549 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 5550 | kwm = KWM_NO; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5551 | tmp = args[0]; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5552 | for (arg=0; *args[arg+1]; arg++) |
| 5553 | args[arg] = args[arg+1]; // shift args after inversion |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5554 | *tmp = '\0'; // fix the next arg to \0 |
| 5555 | args[arg] = tmp; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5556 | } |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 5557 | else if (!strcmp(args[0], "default")) { |
| 5558 | kwm = KWM_DEF; |
| 5559 | for (arg=0; *args[arg+1]; arg++) |
| 5560 | args[arg] = args[arg+1]; // shift args after inversion |
| 5561 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5562 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5563 | if (kwm != KWM_STD && strcmp(args[0], "option") != 0 && \ |
| 5564 | strcmp(args[0], "log") != 0) { |
| 5565 | 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] | 5566 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5567 | } |
| 5568 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5569 | if (!strcmp(args[0], "listen") || |
| 5570 | !strcmp(args[0], "frontend") || |
| 5571 | !strcmp(args[0], "backend") || |
| 5572 | !strcmp(args[0], "ruleset") || |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5573 | !strcmp(args[0], "defaults")) { /* new proxy */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5574 | confsect = CFG_LISTEN; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 5575 | free(cursection); |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5576 | cursection = strdup(args[0]); |
| 5577 | } |
| 5578 | else if (!strcmp(args[0], "global")) { /* global config */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5579 | confsect = CFG_GLOBAL; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 5580 | free(cursection); |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5581 | cursection = strdup(args[0]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 5582 | } |
| 5583 | else if (!strcmp(args[0], "userlist")) { |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5584 | confsect = CFG_USERLIST; |
| 5585 | free(cursection); |
| 5586 | cursection = strdup(args[0]); |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5587 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 5588 | else if (!strcmp(args[0], "peers")) { |
| 5589 | confsect = CFG_PEERS; |
| 5590 | free(cursection); |
| 5591 | cursection = strdup(args[0]); |
| 5592 | } |
| 5593 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5594 | /* else it's a section keyword */ |
| 5595 | |
| 5596 | switch (confsect) { |
| 5597 | case CFG_LISTEN: |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5598 | err_code |= cfg_parse_listen(file, linenum, args, kwm); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5599 | break; |
| 5600 | case CFG_GLOBAL: |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5601 | err_code |= cfg_parse_global(file, linenum, args, kwm); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5602 | break; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5603 | case CFG_USERLIST: |
| 5604 | err_code |= cfg_parse_users(file, linenum, args, kwm); |
| 5605 | break; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 5606 | case CFG_PEERS: |
| 5607 | err_code |= cfg_parse_peers(file, linenum, args, kwm); |
| 5608 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5609 | default: |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5610 | 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] | 5611 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5612 | } |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5613 | |
| 5614 | if (err_code & ERR_ABORT) |
| 5615 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5616 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 5617 | free(cursection); |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5618 | cursection = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5619 | fclose(f); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5620 | return err_code; |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5621 | } |
| 5622 | |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 5623 | /* |
| 5624 | * Returns the error code, 0 if OK, or any combination of : |
| 5625 | * - ERR_ABORT: must abort ASAP |
| 5626 | * - ERR_FATAL: we can continue parsing but not start the service |
| 5627 | * - ERR_WARN: a warning has been emitted |
| 5628 | * - ERR_ALERT: an alert has been emitted |
| 5629 | * Only the two first ones can stop processing, the two others are just |
| 5630 | * indicators. |
| 5631 | */ |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5632 | int check_config_validity() |
| 5633 | { |
| 5634 | int cfgerr = 0; |
| 5635 | struct proxy *curproxy = NULL; |
| 5636 | struct server *newsrv = NULL; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5637 | struct userlist *curuserlist = NULL; |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 5638 | int err_code = 0; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 5639 | unsigned int next_pxid = 1; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 5640 | struct bind_conf *bind_conf; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5641 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 5642 | bind_conf = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5643 | /* |
| 5644 | * Now, check for the integrity of all that we have collected. |
| 5645 | */ |
| 5646 | |
| 5647 | /* will be needed further to delay some tasks */ |
Willy Tarreau | b0b37bc | 2008-06-23 14:00:57 +0200 | [diff] [blame] | 5648 | tv_update_date(0,1); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5649 | |
Willy Tarreau | 55bc0f8 | 2009-03-15 14:51:53 +0100 | [diff] [blame] | 5650 | /* first, we will invert the proxy list order */ |
| 5651 | curproxy = NULL; |
| 5652 | while (proxy) { |
| 5653 | struct proxy *next; |
| 5654 | |
| 5655 | next = proxy->next; |
| 5656 | proxy->next = curproxy; |
| 5657 | curproxy = proxy; |
| 5658 | if (!next) |
| 5659 | break; |
| 5660 | proxy = next; |
| 5661 | } |
| 5662 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5663 | while (curproxy != NULL) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 5664 | struct switching_rule *rule; |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 5665 | struct server_rule *srule; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5666 | struct sticking_rule *mrule; |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 5667 | struct tcp_rule *trule; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 5668 | struct listener *listener; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 5669 | unsigned int next_id; |
| 5670 | |
| 5671 | if (!curproxy->uuid) { |
| 5672 | /* proxy ID not set, use automatic numbering with first |
| 5673 | * spare entry starting with next_pxid. |
| 5674 | */ |
| 5675 | next_pxid = get_next_id(&used_proxy_id, next_pxid); |
| 5676 | curproxy->conf.id.key = curproxy->uuid = next_pxid; |
| 5677 | eb32_insert(&used_proxy_id, &curproxy->conf.id); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 5678 | } |
Krzysztof Piotr Oledzki | df5cb9f | 2010-02-05 20:58:27 +0100 | [diff] [blame] | 5679 | next_pxid++; |
| 5680 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 5681 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5682 | if (curproxy->state == PR_STSTOPPED) { |
Willy Tarreau | da250db | 2008-10-12 12:07:48 +0200 | [diff] [blame] | 5683 | /* ensure we don't keep listeners uselessly bound */ |
| 5684 | stop_proxy(curproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5685 | curproxy = curproxy->next; |
| 5686 | continue; |
| 5687 | } |
| 5688 | |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 5689 | switch (curproxy->mode) { |
| 5690 | case PR_MODE_HEALTH: |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5691 | cfgerr += proxy_cfg_ensure_no_http(curproxy); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 5692 | if (!(curproxy->cap & PR_CAP_FE)) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5693 | Alert("config : %s '%s' cannot be in health mode as it has no frontend capability.\n", |
| 5694 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 5695 | cfgerr++; |
| 5696 | } |
| 5697 | |
| 5698 | if (curproxy->srv != NULL) |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5699 | Warning("config : servers will be ignored for %s '%s'.\n", |
| 5700 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 5701 | break; |
| 5702 | |
| 5703 | case PR_MODE_TCP: |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5704 | cfgerr += proxy_cfg_ensure_no_http(curproxy); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 5705 | break; |
| 5706 | |
| 5707 | case PR_MODE_HTTP: |
Willy Tarreau | a9fb083 | 2009-07-10 20:53:53 +0200 | [diff] [blame] | 5708 | curproxy->acl_requires |= ACL_USE_L7_ANY; |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 5709 | break; |
| 5710 | } |
| 5711 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 5712 | if ((curproxy->cap & PR_CAP_FE) && LIST_ISEMPTY(&curproxy->conf.listeners)) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5713 | Alert("config : %s '%s' has no listen address. Please either specify a valid address on the <listen> line, or use the <bind> keyword.\n", |
| 5714 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5715 | cfgerr++; |
| 5716 | } |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 5717 | |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 5718 | if ((curproxy->cap & PR_CAP_BE) && (curproxy->mode != PR_MODE_HEALTH)) { |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 5719 | if (curproxy->lbprm.algo & BE_LB_KIND) { |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 5720 | if (curproxy->options & PR_O_TRANSP) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5721 | Alert("config : %s '%s' cannot use both transparent and balance mode.\n", |
| 5722 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 5723 | cfgerr++; |
| 5724 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5725 | #ifdef WE_DONT_SUPPORT_SERVERLESS_LISTENERS |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 5726 | else if (curproxy->srv == NULL) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5727 | Alert("config : %s '%s' needs at least 1 server in balance mode.\n", |
| 5728 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 5729 | cfgerr++; |
| 5730 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5731 | #endif |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 5732 | else if (curproxy->options & PR_O_DISPATCH) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5733 | Warning("config : dispatch address of %s '%s' will be ignored in balance mode.\n", |
| 5734 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 5735 | err_code |= ERR_WARN; |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 5736 | } |
| 5737 | } |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 5738 | 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] | 5739 | /* If no LB algo is set in a backend, and we're not in |
| 5740 | * transparent mode, dispatch mode nor proxy mode, we |
| 5741 | * want to use balance roundrobin by default. |
| 5742 | */ |
| 5743 | curproxy->lbprm.algo &= ~BE_LB_ALGO; |
| 5744 | curproxy->lbprm.algo |= BE_LB_ALGO_RR; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5745 | } |
| 5746 | } |
Willy Tarreau | 193cf93 | 2007-09-17 10:17:23 +0200 | [diff] [blame] | 5747 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 5748 | if (curproxy->options & PR_O_DISPATCH) |
| 5749 | curproxy->options &= ~(PR_O_TRANSP | PR_O_HTTP_PROXY); |
| 5750 | else if (curproxy->options & PR_O_HTTP_PROXY) |
| 5751 | curproxy->options &= ~(PR_O_DISPATCH | PR_O_TRANSP); |
| 5752 | else if (curproxy->options & PR_O_TRANSP) |
| 5753 | curproxy->options &= ~(PR_O_DISPATCH | PR_O_HTTP_PROXY); |
Willy Tarreau | 8293658 | 2007-11-30 15:20:09 +0100 | [diff] [blame] | 5754 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 5755 | if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_HTTP_CHK) { |
| 5756 | if (curproxy->options & PR_O_DISABLE404) { |
| 5757 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n", |
| 5758 | "disable-on-404", proxy_type_str(curproxy), curproxy->id); |
| 5759 | err_code |= ERR_WARN; |
| 5760 | curproxy->options &= ~PR_O_DISABLE404; |
| 5761 | } |
| 5762 | if (curproxy->options2 & PR_O2_CHK_SNDST) { |
| 5763 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n", |
| 5764 | "send-state", proxy_type_str(curproxy), curproxy->id); |
| 5765 | err_code |= ERR_WARN; |
| 5766 | curproxy->options &= ~PR_O2_CHK_SNDST; |
| 5767 | } |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 5768 | } |
| 5769 | |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5770 | /* if a default backend was specified, let's find it */ |
| 5771 | if (curproxy->defbe.name) { |
| 5772 | struct proxy *target; |
| 5773 | |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 5774 | target = findproxy_mode(curproxy->defbe.name, curproxy->mode, PR_CAP_BE); |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 5775 | if (!target) { |
| 5776 | Alert("Proxy '%s': unable to find required default_backend: '%s'.\n", |
| 5777 | curproxy->id, curproxy->defbe.name); |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5778 | cfgerr++; |
| 5779 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 5780 | Alert("Proxy '%s': loop detected for default_backend: '%s'.\n", |
| 5781 | curproxy->id, curproxy->defbe.name); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 5782 | cfgerr++; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5783 | } else { |
| 5784 | free(curproxy->defbe.name); |
| 5785 | curproxy->defbe.be = target; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 5786 | /* we force the backend to be present on at least all of |
| 5787 | * the frontend's processes. |
| 5788 | */ |
| 5789 | target->bind_proc = curproxy->bind_proc ? |
| 5790 | (target->bind_proc | curproxy->bind_proc) : 0; |
Willy Tarreau | ff67813 | 2012-02-13 14:32:34 +0100 | [diff] [blame] | 5791 | |
| 5792 | /* Emit a warning if this proxy also has some servers */ |
| 5793 | if (curproxy->srv) { |
| 5794 | Warning("In proxy '%s', the 'default_backend' rule always has precedence over the servers, which will never be used.\n", |
| 5795 | curproxy->id); |
| 5796 | err_code |= ERR_WARN; |
| 5797 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5798 | } |
| 5799 | } |
| 5800 | |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5801 | /* find the target proxy in setbe */ |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5802 | if (curproxy->mode == PR_MODE_HTTP && curproxy->req_exp != NULL) { |
| 5803 | /* map jump target for ACT_SETBE in req_rep chain */ |
| 5804 | struct hdr_exp *exp; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5805 | for (exp = curproxy->req_exp; exp != NULL; exp = exp->next) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 5806 | struct proxy *target; |
| 5807 | |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5808 | if (exp->action != ACT_SETBE) |
| 5809 | continue; |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 5810 | |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 5811 | target = findproxy_mode(exp->replace, PR_MODE_HTTP, PR_CAP_BE); |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 5812 | if (!target) { |
| 5813 | Alert("Proxy '%s': unable to find required setbe: '%s'.\n", |
| 5814 | curproxy->id, exp->replace); |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5815 | cfgerr++; |
| 5816 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 5817 | Alert("Proxy '%s': loop detected for setbe: '%s'.\n", |
| 5818 | curproxy->id, exp->replace); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5819 | cfgerr++; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5820 | } else { |
| 5821 | free((void *)exp->replace); |
| 5822 | exp->replace = (const char *)target; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 5823 | /* we force the backend to be present on at least all of |
| 5824 | * the frontend's processes. |
| 5825 | */ |
| 5826 | target->bind_proc = curproxy->bind_proc ? |
| 5827 | (target->bind_proc | curproxy->bind_proc) : 0; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5828 | } |
| 5829 | } |
| 5830 | } |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 5831 | |
| 5832 | /* find the target proxy for 'use_backend' rules */ |
| 5833 | list_for_each_entry(rule, &curproxy->switching_rules, list) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 5834 | struct proxy *target; |
| 5835 | |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 5836 | target = findproxy_mode(rule->be.name, curproxy->mode, PR_CAP_BE); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 5837 | |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 5838 | if (!target) { |
| 5839 | Alert("Proxy '%s': unable to find required use_backend: '%s'.\n", |
| 5840 | curproxy->id, rule->be.name); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 5841 | cfgerr++; |
| 5842 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 5843 | Alert("Proxy '%s': loop detected for use_backend: '%s'.\n", |
| 5844 | curproxy->id, rule->be.name); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 5845 | cfgerr++; |
| 5846 | } else { |
| 5847 | free((void *)rule->be.name); |
| 5848 | rule->be.backend = target; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 5849 | /* we force the backend to be present on at least all of |
| 5850 | * the frontend's processes. |
| 5851 | */ |
| 5852 | target->bind_proc = curproxy->bind_proc ? |
| 5853 | (target->bind_proc | curproxy->bind_proc) : 0; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 5854 | } |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 5855 | } |
| 5856 | |
| 5857 | /* find the target proxy for 'use_backend' rules */ |
| 5858 | list_for_each_entry(srule, &curproxy->server_rules, list) { |
| 5859 | struct server *target = findserver(curproxy, srule->srv.name); |
| 5860 | |
| 5861 | if (!target) { |
| 5862 | Alert("config : %s '%s' : unable to find server '%s' referenced in a 'use-server' rule.\n", |
| 5863 | proxy_type_str(curproxy), curproxy->id, srule->srv.name); |
| 5864 | cfgerr++; |
| 5865 | continue; |
| 5866 | } |
| 5867 | free((void *)srule->srv.name); |
| 5868 | srule->srv.ptr = target; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 5869 | } |
| 5870 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5871 | /* find the target table for 'stick' rules */ |
| 5872 | list_for_each_entry(mrule, &curproxy->sticking_rules, list) { |
| 5873 | struct proxy *target; |
| 5874 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 5875 | curproxy->be_req_ana |= AN_REQ_STICKING_RULES; |
| 5876 | if (mrule->flags & STK_IS_STORE) |
| 5877 | curproxy->be_rsp_ana |= AN_RES_STORE_RULES; |
| 5878 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5879 | if (mrule->table.name) |
Willy Tarreau | c00cdc2 | 2010-06-06 16:48:26 +0200 | [diff] [blame] | 5880 | target = findproxy(mrule->table.name, 0); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5881 | else |
| 5882 | target = curproxy; |
| 5883 | |
| 5884 | if (!target) { |
| 5885 | Alert("Proxy '%s': unable to find stick-table '%s'.\n", |
| 5886 | curproxy->id, mrule->table.name); |
| 5887 | cfgerr++; |
| 5888 | } |
| 5889 | else if (target->table.size == 0) { |
| 5890 | Alert("Proxy '%s': stick-table '%s' used but not configured.\n", |
| 5891 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 5892 | cfgerr++; |
| 5893 | } |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 5894 | else if (!stktable_compatible_sample(mrule->expr, target->table.type)) { |
| 5895 | 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] | 5896 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 5897 | cfgerr++; |
| 5898 | } |
| 5899 | else { |
| 5900 | free((void *)mrule->table.name); |
| 5901 | mrule->table.t = &(target->table); |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 5902 | stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID, NULL); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5903 | } |
| 5904 | } |
| 5905 | |
| 5906 | /* find the target table for 'store response' rules */ |
| 5907 | list_for_each_entry(mrule, &curproxy->storersp_rules, list) { |
| 5908 | struct proxy *target; |
| 5909 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 5910 | curproxy->be_rsp_ana |= AN_RES_STORE_RULES; |
| 5911 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5912 | if (mrule->table.name) |
Willy Tarreau | c00cdc2 | 2010-06-06 16:48:26 +0200 | [diff] [blame] | 5913 | target = findproxy(mrule->table.name, 0); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5914 | else |
| 5915 | target = curproxy; |
| 5916 | |
| 5917 | if (!target) { |
| 5918 | Alert("Proxy '%s': unable to find store table '%s'.\n", |
| 5919 | curproxy->id, mrule->table.name); |
| 5920 | cfgerr++; |
| 5921 | } |
| 5922 | else if (target->table.size == 0) { |
| 5923 | Alert("Proxy '%s': stick-table '%s' used but not configured.\n", |
| 5924 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 5925 | cfgerr++; |
| 5926 | } |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 5927 | else if (!stktable_compatible_sample(mrule->expr, target->table.type)) { |
| 5928 | 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] | 5929 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 5930 | cfgerr++; |
| 5931 | } |
| 5932 | else { |
| 5933 | free((void *)mrule->table.name); |
| 5934 | mrule->table.t = &(target->table); |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 5935 | stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID, NULL); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5936 | } |
| 5937 | } |
| 5938 | |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 5939 | /* find the target table for 'tcp-request' layer 4 rules */ |
| 5940 | list_for_each_entry(trule, &curproxy->tcp_req.l4_rules, list) { |
| 5941 | struct proxy *target; |
| 5942 | |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 5943 | 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] | 5944 | continue; |
| 5945 | |
| 5946 | if (trule->act_prm.trk_ctr.table.n) |
| 5947 | target = findproxy(trule->act_prm.trk_ctr.table.n, 0); |
| 5948 | else |
| 5949 | target = curproxy; |
| 5950 | |
| 5951 | if (!target) { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 5952 | Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n", |
| 5953 | curproxy->id, trule->act_prm.trk_ctr.table.n, |
| 5954 | trule->action == TCP_ACT_TRK_SC1 ? 1 : 2); |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 5955 | cfgerr++; |
| 5956 | } |
| 5957 | else if (target->table.size == 0) { |
| 5958 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
| 5959 | curproxy->id, trule->act_prm.trk_ctr.table.n ? trule->act_prm.trk_ctr.table.n : curproxy->id); |
| 5960 | cfgerr++; |
| 5961 | } |
| 5962 | else if (trule->act_prm.trk_ctr.type != target->table.type) { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 5963 | 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] | 5964 | curproxy->id, trule->act_prm.trk_ctr.table.n ? trule->act_prm.trk_ctr.table.n : curproxy->id); |
| 5965 | cfgerr++; |
| 5966 | } |
| 5967 | else { |
| 5968 | free(trule->act_prm.trk_ctr.table.n); |
| 5969 | trule->act_prm.trk_ctr.table.t = &target->table; |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 5970 | /* 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] | 5971 | * to pass a list of counters to track and allocate them right here using |
| 5972 | * stktable_alloc_data_type(). |
| 5973 | */ |
| 5974 | } |
| 5975 | } |
| 5976 | |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 5977 | /* find the target table for 'tcp-request' layer 6 rules */ |
| 5978 | list_for_each_entry(trule, &curproxy->tcp_req.inspect_rules, list) { |
| 5979 | struct proxy *target; |
| 5980 | |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 5981 | 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] | 5982 | continue; |
| 5983 | |
| 5984 | if (trule->act_prm.trk_ctr.table.n) |
| 5985 | target = findproxy(trule->act_prm.trk_ctr.table.n, 0); |
| 5986 | else |
| 5987 | target = curproxy; |
| 5988 | |
| 5989 | if (!target) { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 5990 | Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n", |
| 5991 | curproxy->id, trule->act_prm.trk_ctr.table.n, |
| 5992 | trule->action == TCP_ACT_TRK_SC1 ? 1 : 2); |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 5993 | cfgerr++; |
| 5994 | } |
| 5995 | else if (target->table.size == 0) { |
| 5996 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
| 5997 | curproxy->id, trule->act_prm.trk_ctr.table.n ? trule->act_prm.trk_ctr.table.n : curproxy->id); |
| 5998 | cfgerr++; |
| 5999 | } |
| 6000 | else if (trule->act_prm.trk_ctr.type != target->table.type) { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6001 | 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] | 6002 | curproxy->id, trule->act_prm.trk_ctr.table.n ? trule->act_prm.trk_ctr.table.n : curproxy->id); |
| 6003 | cfgerr++; |
| 6004 | } |
| 6005 | else { |
| 6006 | free(trule->act_prm.trk_ctr.table.n); |
| 6007 | trule->act_prm.trk_ctr.table.t = &target->table; |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6008 | /* 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] | 6009 | * to pass a list of counters to track and allocate them right here using |
| 6010 | * stktable_alloc_data_type(). |
| 6011 | */ |
| 6012 | } |
| 6013 | } |
| 6014 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 6015 | if (curproxy->table.peers.name) { |
| 6016 | struct peers *curpeers = peers; |
| 6017 | |
| 6018 | for (curpeers = peers; curpeers; curpeers = curpeers->next) { |
| 6019 | if (strcmp(curpeers->id, curproxy->table.peers.name) == 0) { |
| 6020 | free((void *)curproxy->table.peers.name); |
| 6021 | curproxy->table.peers.p = peers; |
| 6022 | break; |
| 6023 | } |
| 6024 | } |
| 6025 | |
| 6026 | if (!curpeers) { |
| 6027 | Alert("Proxy '%s': unable to find sync peers '%s'.\n", |
| 6028 | curproxy->id, curproxy->table.peers.name); |
Willy Tarreau | d66bf96 | 2011-10-28 14:16:49 +0200 | [diff] [blame] | 6029 | free((void *)curproxy->table.peers.name); |
| 6030 | curproxy->table.peers.p = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 6031 | cfgerr++; |
| 6032 | } |
| 6033 | else if (!curpeers->peers_fe) { |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 6034 | Alert("Proxy '%s': unable to find local peer '%s' in peers section '%s'.\n", |
| 6035 | curproxy->id, localpeer, curpeers->id); |
Willy Tarreau | d66bf96 | 2011-10-28 14:16:49 +0200 | [diff] [blame] | 6036 | curproxy->table.peers.p = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 6037 | cfgerr++; |
| 6038 | } |
| 6039 | } |
| 6040 | |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 6041 | if (curproxy->uri_auth && !(curproxy->uri_auth->flags & ST_CONVDONE) && |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 6042 | !LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) && |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6043 | (curproxy->uri_auth->userlist || curproxy->uri_auth->auth_realm )) { |
| 6044 | Alert("%s '%s': stats 'auth'/'realm' and 'http-request' can't be used at the same time.\n", |
| 6045 | "proxy", curproxy->id); |
| 6046 | cfgerr++; |
| 6047 | goto out_uri_auth_compat; |
| 6048 | } |
| 6049 | |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 6050 | 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] | 6051 | const char *uri_auth_compat_req[10]; |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 6052 | struct http_req_rule *rule; |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6053 | int i = 0; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6054 | |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6055 | /* build the ACL condition from scratch. We're relying on anonymous ACLs for that */ |
| 6056 | uri_auth_compat_req[i++] = "auth"; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6057 | |
| 6058 | if (curproxy->uri_auth->auth_realm) { |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6059 | uri_auth_compat_req[i++] = "realm"; |
| 6060 | uri_auth_compat_req[i++] = curproxy->uri_auth->auth_realm; |
| 6061 | } |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6062 | |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6063 | uri_auth_compat_req[i++] = "unless"; |
| 6064 | uri_auth_compat_req[i++] = "{"; |
| 6065 | uri_auth_compat_req[i++] = "http_auth(.internal-stats-userlist)"; |
| 6066 | uri_auth_compat_req[i++] = "}"; |
| 6067 | uri_auth_compat_req[i++] = ""; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6068 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 6069 | rule = parse_http_req_cond(uri_auth_compat_req, "internal-stats-auth-compat", 0, curproxy); |
| 6070 | if (!rule) { |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6071 | cfgerr++; |
| 6072 | break; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6073 | } |
| 6074 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 6075 | LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list); |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6076 | |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6077 | if (curproxy->uri_auth->auth_realm) { |
| 6078 | free(curproxy->uri_auth->auth_realm); |
| 6079 | curproxy->uri_auth->auth_realm = NULL; |
| 6080 | } |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 6081 | |
| 6082 | curproxy->uri_auth->flags |= ST_CONVDONE; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6083 | } |
| 6084 | out_uri_auth_compat: |
| 6085 | |
Krzysztof Piotr Oledzki | f9423ae | 2010-01-29 19:26:18 +0100 | [diff] [blame] | 6086 | cfgerr += acl_find_targets(curproxy); |
| 6087 | |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 6088 | if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) && |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6089 | (((curproxy->cap & PR_CAP_FE) && !curproxy->timeout.client) || |
Willy Tarreau | d825eef | 2007-05-12 22:35:00 +0200 | [diff] [blame] | 6090 | ((curproxy->cap & PR_CAP_BE) && (curproxy->srv) && |
Willy Tarreau | ce887fd | 2012-05-12 12:50:00 +0200 | [diff] [blame] | 6091 | (!curproxy->timeout.connect || |
| 6092 | (!curproxy->timeout.server && (curproxy->mode == PR_MODE_HTTP || !curproxy->timeout.tunnel)))))) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6093 | Warning("config : missing timeouts for %s '%s'.\n" |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 6094 | " | While not properly invalid, you will certainly encounter various problems\n" |
| 6095 | " | 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] | 6096 | " | timeouts are set to a non-zero value: 'client', 'connect', 'server'.\n", |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6097 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6098 | err_code |= ERR_WARN; |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 6099 | } |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 6100 | |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6101 | /* Historically, the tarpit and queue timeouts were inherited from contimeout. |
| 6102 | * We must still support older configurations, so let's find out whether those |
| 6103 | * parameters have been set or must be copied from contimeouts. |
| 6104 | */ |
| 6105 | if (curproxy != &defproxy) { |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6106 | if (!curproxy->timeout.tarpit || |
| 6107 | curproxy->timeout.tarpit == defproxy.timeout.tarpit) { |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6108 | /* tarpit timeout not set. We search in the following order: |
| 6109 | * default.tarpit, curr.connect, default.connect. |
| 6110 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6111 | if (defproxy.timeout.tarpit) |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6112 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6113 | else if (curproxy->timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6114 | curproxy->timeout.tarpit = curproxy->timeout.connect; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6115 | else if (defproxy.timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6116 | curproxy->timeout.tarpit = defproxy.timeout.connect; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6117 | } |
| 6118 | if ((curproxy->cap & PR_CAP_BE) && |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6119 | (!curproxy->timeout.queue || |
| 6120 | curproxy->timeout.queue == defproxy.timeout.queue)) { |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6121 | /* queue timeout not set. We search in the following order: |
| 6122 | * default.queue, curr.connect, default.connect. |
| 6123 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6124 | if (defproxy.timeout.queue) |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6125 | curproxy->timeout.queue = defproxy.timeout.queue; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6126 | else if (curproxy->timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6127 | curproxy->timeout.queue = curproxy->timeout.connect; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6128 | else if (defproxy.timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6129 | curproxy->timeout.queue = defproxy.timeout.connect; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6130 | } |
| 6131 | } |
| 6132 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 6133 | if ((curproxy->options2 & PR_O2_CHK_ANY) == PR_O2_SSL3_CHK) { |
Willy Tarreau | 137325d | 2010-02-01 16:38:17 +0100 | [diff] [blame] | 6134 | curproxy->check_len = sizeof(sslv3_client_hello_pkt) - 1; |
| 6135 | curproxy->check_req = (char *)malloc(curproxy->check_len); |
| 6136 | memcpy(curproxy->check_req, sslv3_client_hello_pkt, curproxy->check_len); |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 6137 | } |
| 6138 | |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 6139 | /* The small pools required for the capture lists */ |
Willy Tarreau | 9a54e13 | 2012-03-24 08:33:05 +0100 | [diff] [blame] | 6140 | if (curproxy->nb_req_cap) { |
| 6141 | if (curproxy->mode == PR_MODE_HTTP) { |
| 6142 | curproxy->req_cap_pool = create_pool("ptrcap", |
| 6143 | curproxy->nb_req_cap * sizeof(char *), |
| 6144 | MEM_F_SHARED); |
| 6145 | } else { |
| 6146 | Warning("config : 'capture request header' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6147 | proxy_type_str(curproxy), curproxy->id); |
| 6148 | err_code |= ERR_WARN; |
| 6149 | curproxy->to_log &= ~LW_REQHDR; |
| 6150 | curproxy->nb_req_cap = 0; |
| 6151 | } |
| 6152 | } |
| 6153 | |
| 6154 | if (curproxy->nb_rsp_cap) { |
| 6155 | if (curproxy->mode == PR_MODE_HTTP) { |
| 6156 | curproxy->rsp_cap_pool = create_pool("ptrcap", |
| 6157 | curproxy->nb_rsp_cap * sizeof(char *), |
| 6158 | MEM_F_SHARED); |
| 6159 | } else { |
| 6160 | Warning("config : 'capture response header' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6161 | proxy_type_str(curproxy), curproxy->id); |
| 6162 | err_code |= ERR_WARN; |
| 6163 | curproxy->to_log &= ~LW_REQHDR; |
| 6164 | curproxy->nb_rsp_cap = 0; |
| 6165 | } |
| 6166 | } |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 6167 | |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 6168 | /* compile the log format */ |
Willy Tarreau | 99a7ca2 | 2012-05-31 19:39:23 +0200 | [diff] [blame] | 6169 | if (!(curproxy->cap & PR_CAP_FE)) { |
| 6170 | if (curproxy->logformat_string != default_http_log_format && |
| 6171 | curproxy->logformat_string != default_tcp_log_format && |
| 6172 | curproxy->logformat_string != clf_http_log_format) |
| 6173 | free(curproxy->logformat_string); |
| 6174 | curproxy->logformat_string = NULL; |
| 6175 | } |
| 6176 | |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 6177 | if (curproxy->logformat_string) |
| 6178 | parse_logformat_string(curproxy->logformat_string, curproxy, &curproxy->logformat, curproxy->mode); |
| 6179 | |
| 6180 | if (curproxy->uniqueid_format_string) |
| 6181 | parse_logformat_string(curproxy->uniqueid_format_string, curproxy, &curproxy->format_unique_id, PR_MODE_HTTP); |
| 6182 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6183 | /* first, we will invert the servers list order */ |
| 6184 | newsrv = NULL; |
| 6185 | while (curproxy->srv) { |
| 6186 | struct server *next; |
| 6187 | |
| 6188 | next = curproxy->srv->next; |
| 6189 | curproxy->srv->next = newsrv; |
| 6190 | newsrv = curproxy->srv; |
| 6191 | if (!next) |
| 6192 | break; |
| 6193 | curproxy->srv = next; |
| 6194 | } |
| 6195 | |
Willy Tarreau | dd70165 | 2010-05-25 23:03:02 +0200 | [diff] [blame] | 6196 | /* assign automatic UIDs to servers which don't have one yet */ |
| 6197 | next_id = 1; |
| 6198 | newsrv = curproxy->srv; |
| 6199 | while (newsrv != NULL) { |
| 6200 | if (!newsrv->puid) { |
| 6201 | /* server ID not set, use automatic numbering with first |
| 6202 | * spare entry starting with next_svid. |
| 6203 | */ |
| 6204 | next_id = get_next_id(&curproxy->conf.used_server_id, next_id); |
| 6205 | newsrv->conf.id.key = newsrv->puid = next_id; |
| 6206 | eb32_insert(&curproxy->conf.used_server_id, &newsrv->conf.id); |
| 6207 | } |
| 6208 | next_id++; |
| 6209 | newsrv = newsrv->next; |
| 6210 | } |
| 6211 | |
Willy Tarreau | 2069704 | 2007-11-15 23:26:18 +0100 | [diff] [blame] | 6212 | curproxy->lbprm.wmult = 1; /* default weight multiplier */ |
Willy Tarreau | 5dc2fa6 | 2007-11-19 19:10:18 +0100 | [diff] [blame] | 6213 | curproxy->lbprm.wdiv = 1; /* default weight divider */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6214 | |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 6215 | /* |
| 6216 | * If this server supports a maxconn parameter, it needs a dedicated |
| 6217 | * tasks to fill the emptied slots when a connection leaves. |
| 6218 | * Also, resolve deferred tracking dependency if needed. |
| 6219 | */ |
| 6220 | newsrv = curproxy->srv; |
| 6221 | while (newsrv != NULL) { |
| 6222 | if (newsrv->minconn > newsrv->maxconn) { |
| 6223 | /* Only 'minconn' was specified, or it was higher than or equal |
| 6224 | * to 'maxconn'. Let's turn this into maxconn and clean it, as |
| 6225 | * this will avoid further useless expensive computations. |
| 6226 | */ |
| 6227 | newsrv->maxconn = newsrv->minconn; |
| 6228 | } else if (newsrv->maxconn && !newsrv->minconn) { |
| 6229 | /* minconn was not specified, so we set it to maxconn */ |
| 6230 | newsrv->minconn = newsrv->maxconn; |
| 6231 | } |
| 6232 | |
Emeric Brun | 01f8e2f | 2012-05-18 16:02:00 +0200 | [diff] [blame] | 6233 | #ifdef USE_OPENSSL |
| 6234 | #ifndef SSL_OP_NO_COMPRESSION /* needs OpenSSL >= 0.9.9 */ |
| 6235 | #define SSL_OP_NO_COMPRESSION 0 |
| 6236 | #endif |
| 6237 | #ifndef SSL_MODE_RELEASE_BUFFERS /* needs OpenSSL >= 1.0.0 */ |
| 6238 | #define SSL_MODE_RELEASE_BUFFERS 0 |
| 6239 | #endif |
| 6240 | #ifndef SSL_OP_NO_COMPRESSION /* needs OpenSSL >= 0.9.9 */ |
| 6241 | #define SSL_OP_NO_COMPRESSION 0 |
| 6242 | #endif |
| 6243 | if (newsrv->use_ssl) { |
| 6244 | int ssloptions = |
| 6245 | SSL_OP_ALL | /* all known workarounds for bugs */ |
| 6246 | SSL_OP_NO_SSLv2 | |
| 6247 | SSL_OP_NO_COMPRESSION; |
| 6248 | int sslmode = |
| 6249 | SSL_MODE_ENABLE_PARTIAL_WRITE | |
| 6250 | SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER | |
| 6251 | SSL_MODE_RELEASE_BUFFERS; |
| 6252 | |
| 6253 | /* Initiate SSL context for current server */ |
| 6254 | newsrv->ssl_ctx.reused_sess = NULL; |
| 6255 | newsrv->data = &ssl_sock; |
| 6256 | newsrv->ssl_ctx.ctx = SSL_CTX_new(SSLv23_client_method()); |
| 6257 | if(!newsrv->ssl_ctx.ctx) { |
| 6258 | |
| 6259 | Alert("config : %s '%s', server '%s': unable to allocate ssl context.\n", |
| 6260 | proxy_type_str(curproxy), curproxy->id, |
| 6261 | newsrv->id); |
| 6262 | cfgerr++; |
| 6263 | goto next_srv; |
| 6264 | } |
| 6265 | |
Willy Tarreau | c230b8b | 2012-09-03 23:55:16 +0200 | [diff] [blame] | 6266 | if (newsrv->ssl_ctx.nosslv3) |
| 6267 | ssloptions |= SSL_OP_NO_SSLv3; |
| 6268 | if (newsrv->ssl_ctx.notlsv1) |
| 6269 | ssloptions |= SSL_OP_NO_TLSv1; |
Emeric Brun | 01f8e2f | 2012-05-18 16:02:00 +0200 | [diff] [blame] | 6270 | SSL_CTX_set_options(newsrv->ssl_ctx.ctx, ssloptions); |
| 6271 | SSL_CTX_set_mode(newsrv->ssl_ctx.ctx, sslmode); |
| 6272 | SSL_CTX_set_verify(newsrv->ssl_ctx.ctx, SSL_VERIFY_NONE, NULL); |
| 6273 | 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] | 6274 | if (newsrv->ssl_ctx.ciphers && |
| 6275 | !SSL_CTX_set_cipher_list(newsrv->ssl_ctx.ctx, newsrv->ssl_ctx.ciphers)) { |
| 6276 | Alert("Proxy '%s', server '%s' [%s:%d] : unable to set SSL cipher list to '%s'.\n", |
| 6277 | curproxy->id, newsrv->id, |
| 6278 | newsrv->conf.file, newsrv->conf.line, newsrv->ssl_ctx.ciphers); |
| 6279 | cfgerr++; |
| 6280 | goto next_srv; |
| 6281 | } |
Emeric Brun | 01f8e2f | 2012-05-18 16:02:00 +0200 | [diff] [blame] | 6282 | } |
| 6283 | #endif /* USE_OPENSSL */ |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 6284 | if (newsrv->trackit) { |
| 6285 | struct proxy *px; |
| 6286 | struct server *srv; |
| 6287 | char *pname, *sname; |
| 6288 | |
| 6289 | pname = newsrv->trackit; |
| 6290 | sname = strrchr(pname, '/'); |
| 6291 | |
| 6292 | if (sname) |
| 6293 | *sname++ = '\0'; |
| 6294 | else { |
| 6295 | sname = pname; |
| 6296 | pname = NULL; |
| 6297 | } |
| 6298 | |
| 6299 | if (pname) { |
| 6300 | px = findproxy(pname, PR_CAP_BE); |
| 6301 | if (!px) { |
| 6302 | Alert("config : %s '%s', server '%s': unable to find required proxy '%s' for tracking.\n", |
| 6303 | proxy_type_str(curproxy), curproxy->id, |
| 6304 | newsrv->id, pname); |
| 6305 | cfgerr++; |
| 6306 | goto next_srv; |
| 6307 | } |
| 6308 | } else |
| 6309 | px = curproxy; |
| 6310 | |
| 6311 | srv = findserver(px, sname); |
| 6312 | if (!srv) { |
| 6313 | Alert("config : %s '%s', server '%s': unable to find required server '%s' for tracking.\n", |
| 6314 | proxy_type_str(curproxy), curproxy->id, |
| 6315 | newsrv->id, sname); |
| 6316 | cfgerr++; |
| 6317 | goto next_srv; |
| 6318 | } |
| 6319 | |
| 6320 | if (!(srv->state & SRV_CHECKED)) { |
| 6321 | Alert("config : %s '%s', server '%s': unable to use %s/%s for " |
| 6322 | "tracking as it does not have checks enabled.\n", |
| 6323 | proxy_type_str(curproxy), curproxy->id, |
| 6324 | newsrv->id, px->id, srv->id); |
| 6325 | cfgerr++; |
| 6326 | goto next_srv; |
| 6327 | } |
| 6328 | |
| 6329 | if (curproxy != px && |
| 6330 | (curproxy->options & PR_O_DISABLE404) != (px->options & PR_O_DISABLE404)) { |
| 6331 | Alert("config : %s '%s', server '%s': unable to use %s/%s for" |
| 6332 | "tracking: disable-on-404 option inconsistency.\n", |
| 6333 | proxy_type_str(curproxy), curproxy->id, |
| 6334 | newsrv->id, px->id, srv->id); |
| 6335 | cfgerr++; |
| 6336 | goto next_srv; |
| 6337 | } |
| 6338 | |
| 6339 | /* if the other server is forced disabled, we have to do the same here */ |
| 6340 | if (srv->state & SRV_MAINTAIN) { |
| 6341 | newsrv->state |= SRV_MAINTAIN; |
| 6342 | newsrv->state &= ~SRV_RUNNING; |
| 6343 | newsrv->health = 0; |
| 6344 | } |
| 6345 | |
| 6346 | newsrv->track = srv; |
| 6347 | newsrv->tracknext = srv->tracknext; |
| 6348 | srv->tracknext = newsrv; |
| 6349 | |
| 6350 | free(newsrv->trackit); |
| 6351 | newsrv->trackit = NULL; |
| 6352 | } |
| 6353 | next_srv: |
| 6354 | newsrv = newsrv->next; |
| 6355 | } |
| 6356 | |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6357 | /* We have to initialize the server lookup mechanism depending |
| 6358 | * on what LB algorithm was choosen. |
| 6359 | */ |
| 6360 | |
| 6361 | curproxy->lbprm.algo &= ~(BE_LB_LKUP | BE_LB_PROP_DYN); |
| 6362 | switch (curproxy->lbprm.algo & BE_LB_KIND) { |
| 6363 | case BE_LB_KIND_RR: |
Willy Tarreau | 9757a38 | 2009-10-03 12:56:50 +0200 | [diff] [blame] | 6364 | if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_RR_STATIC) { |
| 6365 | curproxy->lbprm.algo |= BE_LB_LKUP_MAP; |
| 6366 | init_server_map(curproxy); |
| 6367 | } else { |
| 6368 | curproxy->lbprm.algo |= BE_LB_LKUP_RRTREE | BE_LB_PROP_DYN; |
| 6369 | fwrr_init_server_groups(curproxy); |
| 6370 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6371 | break; |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 6372 | |
Willy Tarreau | 3ebb116 | 2012-02-13 16:57:44 +0100 | [diff] [blame] | 6373 | case BE_LB_KIND_CB: |
Willy Tarreau | f09c660 | 2012-02-13 17:12:08 +0100 | [diff] [blame] | 6374 | if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_CB_LC) { |
| 6375 | curproxy->lbprm.algo |= BE_LB_LKUP_LCTREE | BE_LB_PROP_DYN; |
| 6376 | fwlc_init_server_tree(curproxy); |
| 6377 | } else { |
| 6378 | curproxy->lbprm.algo |= BE_LB_LKUP_FSTREE | BE_LB_PROP_DYN; |
| 6379 | fas_init_server_tree(curproxy); |
| 6380 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6381 | break; |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 6382 | |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6383 | case BE_LB_KIND_HI: |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 6384 | if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS) { |
| 6385 | curproxy->lbprm.algo |= BE_LB_LKUP_CHTREE | BE_LB_PROP_DYN; |
| 6386 | chash_init_server_tree(curproxy); |
| 6387 | } else { |
| 6388 | curproxy->lbprm.algo |= BE_LB_LKUP_MAP; |
| 6389 | init_server_map(curproxy); |
| 6390 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6391 | break; |
| 6392 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6393 | |
| 6394 | if (curproxy->options & PR_O_LOGASAP) |
| 6395 | curproxy->to_log &= ~LW_BYTES; |
| 6396 | |
Willy Tarreau | e7ded1f | 2009-08-09 10:11:45 +0200 | [diff] [blame] | 6397 | if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) && |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6398 | (curproxy->cap & PR_CAP_FE) && curproxy->to_log && LIST_ISEMPTY(&curproxy->logsrvs)) { |
Willy Tarreau | e7ded1f | 2009-08-09 10:11:45 +0200 | [diff] [blame] | 6399 | Warning("config : log format ignored for %s '%s' since it has no log address.\n", |
| 6400 | proxy_type_str(curproxy), curproxy->id); |
| 6401 | err_code |= ERR_WARN; |
| 6402 | } |
| 6403 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 6404 | if (curproxy->mode != PR_MODE_HTTP) { |
| 6405 | int optnum; |
| 6406 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 6407 | if (curproxy->uri_auth) { |
| 6408 | Warning("config : 'stats' statement ignored for %s '%s' as it requires HTTP mode.\n", |
| 6409 | proxy_type_str(curproxy), curproxy->id); |
| 6410 | err_code |= ERR_WARN; |
| 6411 | curproxy->uri_auth = NULL; |
| 6412 | } |
| 6413 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 6414 | if (curproxy->options & (PR_O_FWDFOR | PR_O_FF_ALWAYS)) { |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 6415 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6416 | "forwardfor", proxy_type_str(curproxy), curproxy->id); |
| 6417 | err_code |= ERR_WARN; |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 6418 | curproxy->options &= ~(PR_O_FWDFOR | PR_O_FF_ALWAYS); |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 6419 | } |
| 6420 | |
| 6421 | if (curproxy->options & PR_O_ORGTO) { |
| 6422 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6423 | "originalto", proxy_type_str(curproxy), curproxy->id); |
| 6424 | err_code |= ERR_WARN; |
| 6425 | curproxy->options &= ~PR_O_ORGTO; |
| 6426 | } |
| 6427 | |
| 6428 | for (optnum = 0; cfg_opts[optnum].name; optnum++) { |
| 6429 | if (cfg_opts[optnum].mode == PR_MODE_HTTP && |
| 6430 | (curproxy->cap & cfg_opts[optnum].cap) && |
| 6431 | (curproxy->options & cfg_opts[optnum].val)) { |
| 6432 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6433 | cfg_opts[optnum].name, proxy_type_str(curproxy), curproxy->id); |
| 6434 | err_code |= ERR_WARN; |
| 6435 | curproxy->options &= ~cfg_opts[optnum].val; |
| 6436 | } |
| 6437 | } |
| 6438 | |
| 6439 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) { |
| 6440 | if (cfg_opts2[optnum].mode == PR_MODE_HTTP && |
| 6441 | (curproxy->cap & cfg_opts2[optnum].cap) && |
| 6442 | (curproxy->options2 & cfg_opts2[optnum].val)) { |
| 6443 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6444 | cfg_opts2[optnum].name, proxy_type_str(curproxy), curproxy->id); |
| 6445 | err_code |= ERR_WARN; |
| 6446 | curproxy->options2 &= ~cfg_opts2[optnum].val; |
| 6447 | } |
| 6448 | } |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6449 | |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 6450 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6451 | if (curproxy->bind_hdr_occ) { |
| 6452 | curproxy->bind_hdr_occ = 0; |
| 6453 | Warning("config : %s '%s' : ignoring use of header %s as source IP in non-HTTP mode.\n", |
| 6454 | proxy_type_str(curproxy), curproxy->id, curproxy->bind_hdr_name); |
| 6455 | err_code |= ERR_WARN; |
| 6456 | } |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 6457 | #endif |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 6458 | } |
| 6459 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6460 | /* |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 6461 | * ensure that we're not cross-dressing a TCP server into HTTP. |
| 6462 | */ |
| 6463 | newsrv = curproxy->srv; |
| 6464 | while (newsrv != NULL) { |
Willy Tarreau | 0cec331 | 2011-10-31 13:49:26 +0100 | [diff] [blame] | 6465 | if ((curproxy->mode != PR_MODE_HTTP) && newsrv->rdr_len) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6466 | Alert("config : %s '%s' : server cannot have cookie or redirect prefix in non-HTTP mode.\n", |
| 6467 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6468 | cfgerr++; |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 6469 | } |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6470 | |
Willy Tarreau | 0cec331 | 2011-10-31 13:49:26 +0100 | [diff] [blame] | 6471 | if ((curproxy->mode != PR_MODE_HTTP) && newsrv->cklen) { |
| 6472 | Warning("config : %s '%s' : ignoring cookie for server '%s' as HTTP mode is disabled.\n", |
| 6473 | proxy_type_str(curproxy), curproxy->id, newsrv->id); |
| 6474 | err_code |= ERR_WARN; |
| 6475 | } |
| 6476 | |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 6477 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6478 | if (curproxy->mode != PR_MODE_HTTP && newsrv->bind_hdr_occ) { |
| 6479 | newsrv->bind_hdr_occ = 0; |
| 6480 | Warning("config : %s '%s' : server %s cannot use header %s as source IP in non-HTTP mode.\n", |
| 6481 | proxy_type_str(curproxy), curproxy->id, newsrv->id, newsrv->bind_hdr_name); |
| 6482 | err_code |= ERR_WARN; |
| 6483 | } |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 6484 | #endif |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 6485 | newsrv = newsrv->next; |
| 6486 | } |
| 6487 | |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6488 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 6489 | curproxy->accept = frontend_accept; |
| 6490 | |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6491 | if (curproxy->tcp_req.inspect_delay || |
| 6492 | !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules)) |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 6493 | curproxy->fe_req_ana |= AN_REQ_INSPECT_FE; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6494 | |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 6495 | if (curproxy->mode == PR_MODE_HTTP) { |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6496 | 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] | 6497 | 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] | 6498 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6499 | |
| 6500 | /* both TCP and HTTP must check switching rules */ |
| 6501 | curproxy->fe_req_ana |= AN_REQ_SWITCHING_RULES; |
| 6502 | } |
| 6503 | |
| 6504 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 6505 | if (curproxy->tcp_req.inspect_delay || |
| 6506 | !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules)) |
| 6507 | curproxy->be_req_ana |= AN_REQ_INSPECT_BE; |
| 6508 | |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 6509 | if (!LIST_ISEMPTY(&curproxy->tcp_rep.inspect_rules)) |
| 6510 | curproxy->be_rsp_ana |= AN_RES_INSPECT; |
| 6511 | |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 6512 | if (curproxy->mode == PR_MODE_HTTP) { |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6513 | 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] | 6514 | 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] | 6515 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6516 | |
| 6517 | /* If the backend does requires RDP cookie persistence, we have to |
| 6518 | * enable the corresponding analyser. |
| 6519 | */ |
| 6520 | if (curproxy->options2 & PR_O2_RDPC_PRST) |
| 6521 | curproxy->be_req_ana |= AN_REQ_PRST_RDP_COOKIE; |
| 6522 | } |
| 6523 | |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 6524 | /* Configure SSL for each bind line. |
| 6525 | * Note: if configuration fails at some point, the ->ctx member |
| 6526 | * remains NULL so that listeners can later detach. |
| 6527 | */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6528 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
| 6529 | if (!bind_conf->is_ssl) |
| 6530 | continue; |
| 6531 | #ifdef USE_OPENSSL |
| 6532 | if (!bind_conf->default_ctx) { |
Emeric Brun | fc0421f | 2012-09-07 17:30:07 +0200 | [diff] [blame] | 6533 | 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] | 6534 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 6535 | cfgerr++; |
| 6536 | continue; |
| 6537 | } |
| 6538 | |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 6539 | if (shared_context_init(global.tune.sslcachesize) < 0) { |
| 6540 | Alert("Unable to allocate SSL session cache.\n"); |
| 6541 | cfgerr++; |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 6542 | continue; |
| 6543 | } |
| 6544 | |
Emeric Brun | fc0421f | 2012-09-07 17:30:07 +0200 | [diff] [blame] | 6545 | /* initialize all certificate contexts */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6546 | cfgerr += ssl_sock_prepare_all_ctx(bind_conf, curproxy); |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 6547 | #endif /* USE_OPENSSL */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6548 | } |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 6549 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 6550 | /* adjust this proxy's listeners */ |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6551 | next_id = 1; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 6552 | list_for_each_entry(listener, &curproxy->conf.listeners, by_fe) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6553 | if (!listener->luid) { |
| 6554 | /* listener ID not set, use automatic numbering with first |
| 6555 | * spare entry starting with next_luid. |
| 6556 | */ |
| 6557 | next_id = get_next_id(&curproxy->conf.used_listener_id, next_id); |
| 6558 | listener->conf.id.key = listener->luid = next_id; |
| 6559 | eb32_insert(&curproxy->conf.used_listener_id, &listener->conf.id); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6560 | } |
Krzysztof Piotr Oledzki | df5cb9f | 2010-02-05 20:58:27 +0100 | [diff] [blame] | 6561 | next_id++; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6562 | |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 6563 | /* enable separate counters */ |
| 6564 | if (curproxy->options2 & PR_O2_SOCKSTAT) { |
| 6565 | listener->counters = (struct licounters *)calloc(1, sizeof(struct licounters)); |
| 6566 | if (!listener->name) { |
| 6567 | sprintf(trash, "sock-%d", listener->luid); |
| 6568 | listener->name = strdup(trash); |
| 6569 | } |
| 6570 | } |
Willy Tarreau | 81796be | 2012-09-22 19:11:47 +0200 | [diff] [blame] | 6571 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 6572 | if (curproxy->options & PR_O_TCP_NOLING) |
| 6573 | listener->options |= LI_O_NOLINGER; |
Willy Tarreau | 32368ce | 2012-09-06 11:10:55 +0200 | [diff] [blame] | 6574 | if (!listener->maxconn) |
| 6575 | listener->maxconn = curproxy->maxconn; |
| 6576 | if (!listener->backlog) |
| 6577 | listener->backlog = curproxy->backlog; |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6578 | listener->timeout = &curproxy->timeout.client; |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 6579 | listener->accept = session_accept; |
Willy Tarreau | 3bc1377 | 2008-12-07 11:50:35 +0100 | [diff] [blame] | 6580 | listener->handler = process_session; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6581 | listener->analysers |= curproxy->fe_req_ana; |
Willy Tarreau | 3bc1377 | 2008-12-07 11:50:35 +0100 | [diff] [blame] | 6582 | |
Willy Tarreau | a5c0ab2 | 2010-05-31 10:30:33 +0200 | [diff] [blame] | 6583 | if (!LIST_ISEMPTY(&curproxy->tcp_req.l4_rules)) |
| 6584 | listener->options |= LI_O_TCP_RULES; |
| 6585 | |
Willy Tarreau | de3041d | 2010-05-31 10:56:17 +0200 | [diff] [blame] | 6586 | if (curproxy->mon_mask.s_addr) |
| 6587 | listener->options |= LI_O_CHK_MONNET; |
| 6588 | |
Willy Tarreau | 9ea05a7 | 2009-06-14 12:07:01 +0200 | [diff] [blame] | 6589 | /* smart accept mode is automatic in HTTP mode */ |
| 6590 | if ((curproxy->options2 & PR_O2_SMARTACC) || |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6591 | ((curproxy->mode == PR_MODE_HTTP || listener->bind_conf->is_ssl) && |
Willy Tarreau | 9ea05a7 | 2009-06-14 12:07:01 +0200 | [diff] [blame] | 6592 | !(curproxy->no_options2 & PR_O2_SMARTACC))) |
| 6593 | listener->options |= LI_O_NOQUICKACK; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 6594 | } |
| 6595 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6596 | /* Release unused SSL configs */ |
| 6597 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
| 6598 | if (bind_conf->is_ssl) |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 6599 | continue; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6600 | #ifdef USE_OPENSSL |
| 6601 | ssl_sock_free_all_ctx(bind_conf); |
| 6602 | free(bind_conf->ciphers); |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 6603 | #endif /* USE_OPENSSL */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6604 | } |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 6605 | |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 6606 | /* Check multi-process mode compatibility for the current proxy */ |
| 6607 | if (global.nbproc > 1) { |
| 6608 | int nbproc = 0; |
| 6609 | if (curproxy->bind_proc) { |
| 6610 | int proc; |
| 6611 | for (proc = 0; proc < global.nbproc; proc++) { |
| 6612 | if (curproxy->bind_proc & (1 << proc)) { |
| 6613 | nbproc++; |
| 6614 | } |
| 6615 | } |
| 6616 | } else { |
| 6617 | nbproc = global.nbproc; |
| 6618 | } |
| 6619 | if (curproxy->table.peers.name) { |
| 6620 | Alert("Proxy '%s': peers can't be used in multi-process mode (nbproc > 1).\n", |
| 6621 | curproxy->id); |
| 6622 | cfgerr++; |
| 6623 | } |
| 6624 | if (nbproc > 1) { |
| 6625 | if (curproxy->uri_auth) { |
| 6626 | Warning("Proxy '%s': in multi-process mode, stats will be limited to process assigned to the current request.\n", |
| 6627 | curproxy->id); |
| 6628 | if (!LIST_ISEMPTY(&curproxy->uri_auth->admin_rules)) { |
| 6629 | Warning("Proxy '%s': stats admin will not work correctly in multi-process mode.\n", |
| 6630 | curproxy->id); |
| 6631 | } |
| 6632 | } |
| 6633 | if (curproxy->appsession_name) { |
| 6634 | Warning("Proxy '%s': appsession will not work correctly in multi-process mode.\n", |
| 6635 | curproxy->id); |
| 6636 | } |
| 6637 | if (!LIST_ISEMPTY(&curproxy->sticking_rules)) { |
| 6638 | Warning("Proxy '%s': sticking rules will not work correctly in multi-process mode.\n", |
| 6639 | curproxy->id); |
| 6640 | } |
| 6641 | } |
| 6642 | } |
Willy Tarreau | 918ff60 | 2011-07-25 16:33:49 +0200 | [diff] [blame] | 6643 | |
| 6644 | /* create the task associated with the proxy */ |
| 6645 | curproxy->task = task_new(); |
| 6646 | if (curproxy->task) { |
| 6647 | curproxy->task->context = curproxy; |
| 6648 | curproxy->task->process = manage_proxy; |
| 6649 | /* no need to queue, it will be done automatically if some |
| 6650 | * listener gets limited. |
| 6651 | */ |
| 6652 | curproxy->task->expire = TICK_ETERNITY; |
| 6653 | } else { |
| 6654 | Alert("Proxy '%s': no more memory when trying to allocate the management task\n", |
| 6655 | curproxy->id); |
| 6656 | cfgerr++; |
| 6657 | } |
| 6658 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6659 | curproxy = curproxy->next; |
| 6660 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 6661 | |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 6662 | /* Check multi-process mode compatibility */ |
| 6663 | if (global.nbproc > 1) { |
| 6664 | if (global.stats_fe) { |
| 6665 | Warning("stats socket will not work correctly in multi-process mode (nbproc > 1).\n"); |
| 6666 | } |
| 6667 | } |
| 6668 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6669 | for (curuserlist = userlist; curuserlist; curuserlist = curuserlist->next) { |
| 6670 | struct auth_users *curuser; |
| 6671 | int g; |
| 6672 | |
| 6673 | for (curuser = curuserlist->users; curuser; curuser = curuser->next) { |
| 6674 | unsigned int group_mask = 0; |
| 6675 | char *group = NULL; |
| 6676 | |
Willy Tarreau | b4c06b7 | 2010-02-02 11:28:20 +0100 | [diff] [blame] | 6677 | if (!curuser->u.groups) |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6678 | continue; |
| 6679 | |
Willy Tarreau | b4c06b7 | 2010-02-02 11:28:20 +0100 | [diff] [blame] | 6680 | while ((group = strtok(group?NULL:curuser->u.groups, ","))) { |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6681 | |
| 6682 | for (g = 0; g < curuserlist->grpcnt; g++) |
| 6683 | if (!strcmp(curuserlist->groups[g], group)) |
| 6684 | break; |
| 6685 | |
| 6686 | if (g == curuserlist->grpcnt) { |
| 6687 | Alert("userlist '%s': no such group '%s' specified in user '%s'\n", |
| 6688 | curuserlist->name, group, curuser->user); |
| 6689 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6690 | goto out; |
| 6691 | } |
| 6692 | |
| 6693 | group_mask |= (1 << g); |
| 6694 | } |
| 6695 | |
Willy Tarreau | b4c06b7 | 2010-02-02 11:28:20 +0100 | [diff] [blame] | 6696 | free(curuser->u.groups); |
| 6697 | curuser->u.group_mask = group_mask; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6698 | } |
| 6699 | |
| 6700 | for (g = 0; g < curuserlist->grpcnt; g++) { |
| 6701 | char *user = NULL; |
| 6702 | |
| 6703 | if (!curuserlist->groupusers[g]) |
| 6704 | continue; |
| 6705 | |
| 6706 | while ((user = strtok(user?NULL:curuserlist->groupusers[g], ","))) { |
| 6707 | for (curuser = curuserlist->users; curuser; curuser = curuser->next) |
| 6708 | if (!strcmp(curuser->user, user)) |
| 6709 | break; |
| 6710 | |
| 6711 | if (!curuser) { |
| 6712 | Alert("userlist '%s': no such user '%s' specified in group '%s'\n", |
| 6713 | curuserlist->name, user, curuserlist->groups[g]); |
| 6714 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6715 | goto out; |
| 6716 | } |
| 6717 | |
Willy Tarreau | b4c06b7 | 2010-02-02 11:28:20 +0100 | [diff] [blame] | 6718 | curuser->u.group_mask |= (1 << g); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6719 | } |
| 6720 | |
| 6721 | free(curuserlist->groupusers[g]); |
| 6722 | } |
| 6723 | |
| 6724 | free(curuserlist->groupusers); |
| 6725 | |
| 6726 | #ifdef DEBUG_AUTH |
| 6727 | for (g = 0; g < curuserlist->grpcnt; g++) { |
| 6728 | fprintf(stderr, "group %s, id %d, mask %08X, users:", curuserlist->groups[g], g , 1 << g); |
| 6729 | |
| 6730 | for (curuser = curuserlist->users; curuser; curuser = curuser->next) { |
Willy Tarreau | b950959 | 2012-05-10 23:25:35 +0200 | [diff] [blame] | 6731 | if (curuser->u.group_mask & (1 << g)) |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6732 | fprintf(stderr, " %s", curuser->user); |
| 6733 | } |
| 6734 | |
| 6735 | fprintf(stderr, "\n"); |
| 6736 | } |
| 6737 | #endif |
| 6738 | |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 6739 | } |
| 6740 | |
| 6741 | /* automatically compute fullconn if not set. We must not do it in the |
| 6742 | * loop above because cross-references are not yet fully resolved. |
| 6743 | */ |
| 6744 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 6745 | /* If <fullconn> is not set, let's set it to 10% of the sum of |
| 6746 | * the possible incoming frontend's maxconns. |
| 6747 | */ |
| 6748 | if (!curproxy->fullconn && (curproxy->cap & PR_CAP_BE)) { |
| 6749 | struct proxy *fe; |
| 6750 | int total = 0; |
| 6751 | |
| 6752 | /* sum up the number of maxconns of frontends which |
| 6753 | * reference this backend at least once or which are |
| 6754 | * the same one ('listen'). |
| 6755 | */ |
| 6756 | for (fe = proxy; fe; fe = fe->next) { |
| 6757 | struct switching_rule *rule; |
| 6758 | struct hdr_exp *exp; |
| 6759 | int found = 0; |
| 6760 | |
| 6761 | if (!(fe->cap & PR_CAP_FE)) |
| 6762 | continue; |
| 6763 | |
| 6764 | if (fe == curproxy) /* we're on a "listen" instance */ |
| 6765 | found = 1; |
| 6766 | |
| 6767 | if (fe->defbe.be == curproxy) /* "default_backend" */ |
| 6768 | found = 1; |
| 6769 | |
| 6770 | /* check if a "use_backend" rule matches */ |
| 6771 | if (!found) { |
| 6772 | list_for_each_entry(rule, &fe->switching_rules, list) { |
| 6773 | if (rule->be.backend == curproxy) { |
| 6774 | found = 1; |
| 6775 | break; |
| 6776 | } |
| 6777 | } |
| 6778 | } |
| 6779 | |
| 6780 | /* check if a "reqsetbe" rule matches */ |
| 6781 | for (exp = fe->req_exp; !found && exp; exp = exp->next) { |
| 6782 | if (exp->action == ACT_SETBE && |
| 6783 | (struct proxy *)exp->replace == curproxy) { |
| 6784 | found = 1; |
| 6785 | break; |
| 6786 | } |
| 6787 | } |
| 6788 | |
| 6789 | /* now we've checked all possible ways to reference a backend |
| 6790 | * from a frontend. |
| 6791 | */ |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 6792 | if (!found) |
| 6793 | continue; |
| 6794 | total += fe->maxconn; |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 6795 | } |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 6796 | /* we have the sum of the maxconns in <total>. We only |
| 6797 | * keep 10% of that sum to set the default fullconn, with |
| 6798 | * a hard minimum of 1 (to avoid a divide by zero). |
| 6799 | */ |
| 6800 | curproxy->fullconn = (total + 9) / 10; |
| 6801 | if (!curproxy->fullconn) |
| 6802 | curproxy->fullconn = 1; |
| 6803 | } |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6804 | } |
| 6805 | |
Willy Tarreau | 056f568 | 2010-06-06 15:51:11 +0200 | [diff] [blame] | 6806 | /* initialize stick-tables on backend capable proxies. This must not |
| 6807 | * be done earlier because the data size may be discovered while parsing |
| 6808 | * other proxies. |
| 6809 | */ |
| 6810 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) |
Willy Tarreau | c00cdc2 | 2010-06-06 16:48:26 +0200 | [diff] [blame] | 6811 | stktable_init(&curproxy->table); |
Willy Tarreau | 056f568 | 2010-06-06 15:51:11 +0200 | [diff] [blame] | 6812 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 6813 | /* |
| 6814 | * Recount currently required checks. |
| 6815 | */ |
| 6816 | |
| 6817 | for (curproxy=proxy; curproxy; curproxy=curproxy->next) { |
| 6818 | int optnum; |
| 6819 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 6820 | for (optnum = 0; cfg_opts[optnum].name; optnum++) |
| 6821 | if (curproxy->options & cfg_opts[optnum].val) |
| 6822 | global.last_checks |= cfg_opts[optnum].checks; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 6823 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 6824 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) |
| 6825 | if (curproxy->options2 & cfg_opts2[optnum].val) |
| 6826 | global.last_checks |= cfg_opts2[optnum].checks; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 6827 | } |
| 6828 | |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 6829 | if (peers) { |
| 6830 | struct peers *curpeers = peers, **last; |
| 6831 | struct peer *p, *pb; |
| 6832 | |
| 6833 | /* Remove all peers sections which don't have a valid listener. |
| 6834 | * This can happen when a peers section is never referenced and |
| 6835 | * does not contain a local peer. |
| 6836 | */ |
| 6837 | last = &peers; |
| 6838 | while (*last) { |
| 6839 | curpeers = *last; |
| 6840 | if (curpeers->peers_fe) { |
| 6841 | last = &curpeers->next; |
| 6842 | continue; |
| 6843 | } |
| 6844 | |
| 6845 | Warning("Removing incomplete section 'peers %s' (no peer named '%s').\n", |
| 6846 | curpeers->id, localpeer); |
| 6847 | |
| 6848 | p = curpeers->remote; |
| 6849 | while (p) { |
| 6850 | pb = p->next; |
| 6851 | free(p->id); |
| 6852 | free(p); |
| 6853 | p = pb; |
| 6854 | } |
| 6855 | |
| 6856 | /* Destroy and unlink this curpeers section. |
| 6857 | * Note: curpeers is backed up into *last. |
| 6858 | */ |
| 6859 | free(curpeers->id); |
| 6860 | curpeers = curpeers->next; |
| 6861 | free(*last); |
| 6862 | *last = curpeers; |
| 6863 | } |
| 6864 | } |
| 6865 | |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame] | 6866 | if (!global.tune.max_http_hdr) |
| 6867 | global.tune.max_http_hdr = MAX_HTTP_HDR; |
| 6868 | |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 6869 | pool2_hdr_idx = create_pool("hdr_idx", |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame] | 6870 | global.tune.max_http_hdr * sizeof(struct hdr_idx_elem), |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 6871 | MEM_F_SHARED); |
| 6872 | |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6873 | if (cfgerr > 0) |
| 6874 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6875 | out: |
| 6876 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6877 | } |
| 6878 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 6879 | /* |
| 6880 | * Registers the CFG keyword list <kwl> as a list of valid keywords for next |
| 6881 | * parsing sessions. |
| 6882 | */ |
| 6883 | void cfg_register_keywords(struct cfg_kw_list *kwl) |
| 6884 | { |
| 6885 | LIST_ADDQ(&cfg_keywords.list, &kwl->list); |
| 6886 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6887 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 6888 | /* |
| 6889 | * Unregisters the CFG keyword list <kwl> from the list of valid keywords. |
| 6890 | */ |
| 6891 | void cfg_unregister_keywords(struct cfg_kw_list *kwl) |
| 6892 | { |
| 6893 | LIST_DEL(&kwl->list); |
| 6894 | LIST_INIT(&kwl->list); |
| 6895 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6896 | |
| 6897 | /* |
| 6898 | * Local variables: |
| 6899 | * c-indent-level: 8 |
| 6900 | * c-basic-offset: 8 |
| 6901 | * End: |
| 6902 | */ |