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> |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 36 | #include <types/compression.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 37 | #include <types/global.h> |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 38 | #include <types/peers.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 39 | |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 40 | #include <proto/acl.h> |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 41 | #include <proto/auth.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 42 | #include <proto/backend.h> |
Willy Tarreau | c7e4238 | 2012-08-24 19:22:53 +0200 | [diff] [blame] | 43 | #include <proto/channel.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 44 | #include <proto/checks.h> |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 45 | #include <proto/compression.h> |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 46 | #include <proto/dumpstats.h> |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 47 | #include <proto/frontend.h> |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 48 | #include <proto/hdr_idx.h> |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 49 | #include <proto/lb_chash.h> |
Willy Tarreau | f09c660 | 2012-02-13 17:12:08 +0100 | [diff] [blame] | 50 | #include <proto/lb_fas.h> |
Willy Tarreau | f89c187 | 2009-10-01 11:19:37 +0200 | [diff] [blame] | 51 | #include <proto/lb_fwlc.h> |
| 52 | #include <proto/lb_fwrr.h> |
| 53 | #include <proto/lb_map.h> |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 54 | #include <proto/listener.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 55 | #include <proto/log.h> |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 56 | #include <proto/port_range.h> |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 57 | #include <proto/protocol.h> |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 58 | #include <proto/proto_tcp.h> |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 59 | #include <proto/proto_uxst.h> |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 60 | #include <proto/proto_http.h> |
Willy Tarreau | 2b5652f | 2006-12-31 17:46:05 +0100 | [diff] [blame] | 61 | #include <proto/proxy.h> |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 62 | #include <proto/peers.h> |
Willy Tarreau | cd3b094 | 2012-04-27 21:52:18 +0200 | [diff] [blame] | 63 | #include <proto/sample.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 64 | #include <proto/server.h> |
Willy Tarreau | 3bc1377 | 2008-12-07 11:50:35 +0100 | [diff] [blame] | 65 | #include <proto/session.h> |
Willy Tarreau | 75bf2c9 | 2012-08-20 17:01:35 +0200 | [diff] [blame] | 66 | #include <proto/raw_sock.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 67 | #include <proto/task.h> |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 68 | #include <proto/stick_table.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 69 | |
Emeric Brun | fc0421f | 2012-09-07 17:30:07 +0200 | [diff] [blame] | 70 | #ifdef USE_OPENSSL |
| 71 | #include <types/ssl_sock.h> |
| 72 | #include <proto/ssl_sock.h> |
| 73 | #include <proto/shctx.h> |
| 74 | #endif /*USE_OPENSSL */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 75 | |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 76 | /* This is the SSLv3 CLIENT HELLO packet used in conjunction with the |
| 77 | * ssl-hello-chk option to ensure that the remote server speaks SSL. |
| 78 | * |
| 79 | * Check RFC 2246 (TLSv1.0) sections A.3 and A.4 for details. |
| 80 | */ |
| 81 | const char sslv3_client_hello_pkt[] = { |
| 82 | "\x16" /* ContentType : 0x16 = Hanshake */ |
| 83 | "\x03\x00" /* ProtocolVersion : 0x0300 = SSLv3 */ |
| 84 | "\x00\x79" /* ContentLength : 0x79 bytes after this one */ |
| 85 | "\x01" /* HanshakeType : 0x01 = CLIENT HELLO */ |
| 86 | "\x00\x00\x75" /* HandshakeLength : 0x75 bytes after this one */ |
| 87 | "\x03\x00" /* Hello Version : 0x0300 = v3 */ |
| 88 | "\x00\x00\x00\x00" /* Unix GMT Time (s) : filled with <now> (@0x0B) */ |
| 89 | "HAPROXYSSLCHK\nHAPROXYSSLCHK\n" /* Random : must be exactly 28 bytes */ |
| 90 | "\x00" /* Session ID length : empty (no session ID) */ |
| 91 | "\x00\x4E" /* Cipher Suite Length : 78 bytes after this one */ |
| 92 | "\x00\x01" "\x00\x02" "\x00\x03" "\x00\x04" /* 39 most common ciphers : */ |
| 93 | "\x00\x05" "\x00\x06" "\x00\x07" "\x00\x08" /* 0x01...0x1B, 0x2F...0x3A */ |
| 94 | "\x00\x09" "\x00\x0A" "\x00\x0B" "\x00\x0C" /* This covers RSA/DH, */ |
| 95 | "\x00\x0D" "\x00\x0E" "\x00\x0F" "\x00\x10" /* various bit lengths, */ |
| 96 | "\x00\x11" "\x00\x12" "\x00\x13" "\x00\x14" /* SHA1/MD5, DES/3DES/AES... */ |
| 97 | "\x00\x15" "\x00\x16" "\x00\x17" "\x00\x18" |
| 98 | "\x00\x19" "\x00\x1A" "\x00\x1B" "\x00\x2F" |
| 99 | "\x00\x30" "\x00\x31" "\x00\x32" "\x00\x33" |
| 100 | "\x00\x34" "\x00\x35" "\x00\x36" "\x00\x37" |
| 101 | "\x00\x38" "\x00\x39" "\x00\x3A" |
| 102 | "\x01" /* Compression Length : 0x01 = 1 byte for types */ |
| 103 | "\x00" /* Compression Type : 0x00 = NULL compression */ |
| 104 | }; |
| 105 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 106 | /* various keyword modifiers */ |
| 107 | enum kw_mod { |
| 108 | KWM_STD = 0, /* normal */ |
| 109 | KWM_NO, /* "no" prefixed before the keyword */ |
| 110 | KWM_DEF, /* "default" prefixed before the keyword */ |
| 111 | }; |
| 112 | |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 113 | /* 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] | 114 | struct cfg_opt { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 115 | const char *name; |
| 116 | unsigned int val; |
| 117 | unsigned int cap; |
Willy Tarreau | 4fee4e9 | 2007-01-06 21:09:17 +0100 | [diff] [blame] | 118 | unsigned int checks; |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 119 | unsigned int mode; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 120 | }; |
| 121 | |
| 122 | /* proxy->options */ |
| 123 | static const struct cfg_opt cfg_opts[] = |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 124 | { |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 125 | { "abortonclose", PR_O_ABRT_CLOSE, PR_CAP_BE, 0, 0 }, |
| 126 | { "allbackups", PR_O_USE_ALL_BK, PR_CAP_BE, 0, 0 }, |
| 127 | { "checkcache", PR_O_CHK_CACHE, PR_CAP_BE, 0, PR_MODE_HTTP }, |
| 128 | { "clitcpka", PR_O_TCP_CLI_KA, PR_CAP_FE, 0, 0 }, |
| 129 | { "contstats", PR_O_CONTSTATS, PR_CAP_FE, 0, 0 }, |
| 130 | { "dontlognull", PR_O_NULLNOLOG, PR_CAP_FE, 0, 0 }, |
| 131 | { "forceclose", PR_O_FORCE_CLO, PR_CAP_FE | PR_CAP_BE, 0, PR_MODE_HTTP }, |
| 132 | { "http_proxy", PR_O_HTTP_PROXY, PR_CAP_FE | PR_CAP_BE, 0, PR_MODE_HTTP }, |
| 133 | { "httpclose", PR_O_HTTP_CLOSE, PR_CAP_FE | PR_CAP_BE, 0, PR_MODE_HTTP }, |
| 134 | { "keepalive", PR_O_KEEPALIVE, PR_CAP_NONE, 0, PR_MODE_HTTP }, |
| 135 | { "http-server-close", PR_O_SERVER_CLO, PR_CAP_FE | PR_CAP_BE, 0, PR_MODE_HTTP }, |
| 136 | { "logasap", PR_O_LOGASAP, PR_CAP_FE, 0, 0 }, |
| 137 | { "nolinger", PR_O_TCP_NOLING, PR_CAP_FE | PR_CAP_BE, 0, 0 }, |
| 138 | { "persist", PR_O_PERSIST, PR_CAP_BE, 0, 0 }, |
| 139 | { "redispatch", PR_O_REDISP, PR_CAP_BE, 0, 0 }, |
| 140 | { "srvtcpka", PR_O_TCP_SRV_KA, PR_CAP_BE, 0, 0 }, |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 141 | #ifdef TPROXY |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 142 | { "transparent", PR_O_TRANSP, PR_CAP_BE, 0, 0 }, |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 143 | #else |
| 144 | { "transparent", 0, 0, 0, 0 }, |
Willy Tarreau | 8f922fc | 2007-01-06 21:11:49 +0100 | [diff] [blame] | 145 | #endif |
| 146 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 147 | { NULL, 0, 0, 0, 0 } |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 148 | }; |
| 149 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 150 | /* proxy->options2 */ |
| 151 | static const struct cfg_opt cfg_opts2[] = |
| 152 | { |
| 153 | #ifdef CONFIG_HAP_LINUX_SPLICE |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 154 | { "splice-request", PR_O2_SPLIC_REQ, PR_CAP_FE|PR_CAP_BE, 0, 0 }, |
| 155 | { "splice-response", PR_O2_SPLIC_RTR, PR_CAP_FE|PR_CAP_BE, 0, 0 }, |
| 156 | { "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] | 157 | #else |
| 158 | { "splice-request", 0, 0, 0, 0 }, |
| 159 | { "splice-response", 0, 0, 0, 0 }, |
| 160 | { "splice-auto", 0, 0, 0, 0 }, |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 161 | #endif |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 162 | { "accept-invalid-http-request", PR_O2_REQBUG_OK, PR_CAP_FE, 0, PR_MODE_HTTP }, |
| 163 | { "accept-invalid-http-response", PR_O2_RSPBUG_OK, PR_CAP_BE, 0, PR_MODE_HTTP }, |
| 164 | { "dontlog-normal", PR_O2_NOLOGNORM, PR_CAP_FE, 0, 0 }, |
| 165 | { "log-separate-errors", PR_O2_LOGERRORS, PR_CAP_FE, 0, 0 }, |
| 166 | { "log-health-checks", PR_O2_LOGHCHKS, PR_CAP_BE, 0, 0 }, |
| 167 | { "socket-stats", PR_O2_SOCKSTAT, PR_CAP_FE, 0, 0 }, |
| 168 | { "tcp-smart-accept", PR_O2_SMARTACC, PR_CAP_FE, 0, 0 }, |
| 169 | { "tcp-smart-connect", PR_O2_SMARTCON, PR_CAP_BE, 0, 0 }, |
| 170 | { "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] | 171 | { "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] | 172 | { "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] | 173 | { "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] | 174 | { "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] | 175 | { NULL, 0, 0, 0 } |
| 176 | }; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 177 | |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 178 | static char *cursection = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 179 | static struct proxy defproxy; /* fake proxy used to assign default values on all instances */ |
| 180 | int cfg_maxpconn = DEFAULT_MAXCONN; /* # of simultaneous connections per proxy (-N) */ |
Willy Tarreau | 5af24ef | 2009-03-15 15:23:16 +0100 | [diff] [blame] | 181 | int cfg_maxconn = 0; /* # of simultaneous connections, (-n) */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 182 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 183 | /* List head of all known configuration keywords */ |
| 184 | static struct cfg_kw_list cfg_keywords = { |
| 185 | .list = LIST_HEAD_INIT(cfg_keywords.list) |
| 186 | }; |
| 187 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 188 | /* |
| 189 | * converts <str> to a list of listeners which are dynamically allocated. |
| 190 | * The format is "{addr|'*'}:port[-end][,{addr|'*'}:port[-end]]*", where : |
| 191 | * - <addr> can be empty or "*" to indicate INADDR_ANY ; |
| 192 | * - <port> is a numerical port from 1 to 65535 ; |
| 193 | * - <end> indicates to use the range from <port> to <end> instead (inclusive). |
| 194 | * 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] | 195 | * Function returns 1 for success or 0 if error. In case of errors, if <err> is |
| 196 | * not NULL, it must be a valid pointer to either NULL or a freeable area that |
| 197 | * will be replaced with an error message. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 198 | */ |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 199 | 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] | 200 | { |
| 201 | struct listener *l; |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 202 | char *next, *dupstr; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 203 | int port, end; |
| 204 | |
| 205 | next = dupstr = strdup(str); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 206 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 207 | while (next && *next) { |
| 208 | struct sockaddr_storage ss; |
| 209 | |
| 210 | str = next; |
| 211 | /* 1) look for the end of the first address */ |
Krzysztof Piotr Oledzki | 52d522b | 2009-01-27 16:57:08 +0100 | [diff] [blame] | 212 | if ((next = strchr(str, ',')) != NULL) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 213 | *next++ = 0; |
| 214 | } |
| 215 | |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 216 | if (*str == '/') { |
| 217 | /* sun_path during a soft_stop rename is <unix_bind_prefix><path>.<pid>.<bak|tmp> */ |
| 218 | /* so compute max path */ |
| 219 | int prefix_path_len = global.unix_bind.prefix ? strlen(global.unix_bind.prefix) : 0; |
| 220 | 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] | 221 | |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 222 | if (strlen(str) > max_path_len) { |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 223 | 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] | 224 | goto fail; |
| 225 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 226 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 227 | memset(&ss, 0, sizeof(ss)); |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 228 | ss.ss_family = AF_UNIX; |
| 229 | if (global.unix_bind.prefix) { |
| 230 | memcpy(((struct sockaddr_un *)&ss)->sun_path, global.unix_bind.prefix, prefix_path_len); |
| 231 | strcpy(((struct sockaddr_un *)&ss)->sun_path+prefix_path_len, str); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 232 | } |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 233 | else { |
| 234 | strcpy(((struct sockaddr_un *)&ss)->sun_path, str); |
| 235 | } |
| 236 | port = end = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 237 | } |
| 238 | else { |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 239 | struct sockaddr_storage *ss2; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 240 | |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 241 | ss2 = str2sa_range(str, &port, &end); |
| 242 | if (!ss2) { |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 243 | memprintf(err, "invalid listening address: '%s'\n", str); |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 244 | goto fail; |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 245 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 246 | |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 247 | if (!port) { |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 248 | memprintf(err, "missing port number: '%s'\n", str); |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 249 | goto fail; |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 250 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 251 | |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 252 | /* OK the address looks correct */ |
| 253 | ss = *ss2; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 254 | |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 255 | if (port < 1 || port > 65535) { |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 256 | memprintf(err, "invalid port '%d' specified for address '%s'.\n", port, str); |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 257 | goto fail; |
| 258 | } |
| 259 | |
| 260 | if (end < 1 || end > 65535) { |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 261 | memprintf(err, "invalid port '%d' specified for address '%s'.\n", end, str); |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 262 | goto fail; |
| 263 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | for (; port <= end; port++) { |
| 267 | l = (struct listener *)calloc(1, sizeof(struct listener)); |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 268 | LIST_ADDQ(&curproxy->conf.listeners, &l->by_fe); |
| 269 | LIST_ADDQ(&bind_conf->listeners, &l->by_bind); |
| 270 | l->frontend = curproxy; |
| 271 | l->bind_conf = bind_conf; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 272 | |
| 273 | l->fd = -1; |
| 274 | l->addr = ss; |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 275 | l->xprt = &raw_sock; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 276 | l->state = LI_INIT; |
| 277 | |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 278 | if (ss.ss_family == AF_INET) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 279 | ((struct sockaddr_in *)(&l->addr))->sin_port = htons(port); |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 280 | tcpv4_add_listener(l); |
| 281 | } |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 282 | else if (ss.ss_family == AF_INET6) { |
| 283 | ((struct sockaddr_in6 *)(&l->addr))->sin6_port = htons(port); |
| 284 | tcpv6_add_listener(l); |
| 285 | } |
| 286 | else { |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 287 | uxst_add_listener(l); |
| 288 | } |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 289 | |
Willy Tarreau | af7ad00 | 2010-08-31 15:39:26 +0200 | [diff] [blame] | 290 | jobs++; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 291 | listeners++; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 292 | } /* end for(port) */ |
| 293 | } /* end while(next) */ |
| 294 | free(dupstr); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 295 | return 1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 296 | fail: |
| 297 | free(dupstr); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 298 | return 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 299 | } |
| 300 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 301 | /* |
| 302 | * Sends a warning if proxy <proxy> does not have at least one of the |
| 303 | * capabilities in <cap>. An optionnal <hint> may be added at the end |
| 304 | * of the warning to help the user. Returns 1 if a warning was emitted |
| 305 | * or 0 if the condition is valid. |
| 306 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 307 | 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] | 308 | { |
| 309 | char *msg; |
| 310 | |
| 311 | switch (cap) { |
| 312 | case PR_CAP_BE: msg = "no backend"; break; |
| 313 | case PR_CAP_FE: msg = "no frontend"; break; |
| 314 | case PR_CAP_RS: msg = "no ruleset"; break; |
| 315 | case PR_CAP_BE|PR_CAP_FE: msg = "neither frontend nor backend"; break; |
| 316 | default: msg = "not enough"; break; |
| 317 | } |
| 318 | |
| 319 | if (!(proxy->cap & cap)) { |
| 320 | 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] | 321 | file, line, arg, proxy_type_str(proxy), proxy->id, msg, hint ? hint : ""); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 322 | return 1; |
| 323 | } |
| 324 | return 0; |
| 325 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 326 | |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 327 | /* Report a warning if a rule is placed after a 'block' rule. |
| 328 | * Return 1 if the warning has been emitted, otherwise 0. |
| 329 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 330 | 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] | 331 | { |
| 332 | if (!LIST_ISEMPTY(&proxy->block_cond)) { |
| 333 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'block' rule will still be processed before.\n", |
| 334 | file, line, arg); |
| 335 | return 1; |
| 336 | } |
| 337 | return 0; |
| 338 | } |
| 339 | |
| 340 | /* Report a warning if a rule is placed after a reqrewrite rule. |
| 341 | * Return 1 if the warning has been emitted, otherwise 0. |
| 342 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 343 | 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] | 344 | { |
| 345 | if (proxy->req_exp) { |
| 346 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'reqxxx' rule will still be processed before.\n", |
| 347 | file, line, arg); |
| 348 | return 1; |
| 349 | } |
| 350 | return 0; |
| 351 | } |
| 352 | |
| 353 | /* Report a warning if a rule is placed after a reqadd rule. |
| 354 | * Return 1 if the warning has been emitted, otherwise 0. |
| 355 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 356 | 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] | 357 | { |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 358 | if (!LIST_ISEMPTY(&proxy->req_add)) { |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 359 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'reqadd' rule will still be processed before.\n", |
| 360 | file, line, arg); |
| 361 | return 1; |
| 362 | } |
| 363 | return 0; |
| 364 | } |
| 365 | |
| 366 | /* Report a warning if a rule is placed after a redirect rule. |
| 367 | * Return 1 if the warning has been emitted, otherwise 0. |
| 368 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 369 | 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] | 370 | { |
| 371 | if (!LIST_ISEMPTY(&proxy->redirect_rules)) { |
| 372 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'redirect' rule will still be processed before.\n", |
| 373 | file, line, arg); |
| 374 | return 1; |
| 375 | } |
| 376 | return 0; |
| 377 | } |
| 378 | |
| 379 | /* Report a warning if a rule is placed after a 'use_backend' rule. |
| 380 | * Return 1 if the warning has been emitted, otherwise 0. |
| 381 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 382 | 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] | 383 | { |
| 384 | if (!LIST_ISEMPTY(&proxy->switching_rules)) { |
| 385 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'use_backend' rule will still be processed before.\n", |
| 386 | file, line, arg); |
| 387 | return 1; |
| 388 | } |
| 389 | return 0; |
| 390 | } |
| 391 | |
| 392 | /* report a warning if a block rule is dangerously placed */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 393 | 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] | 394 | { |
| 395 | return warnif_rule_after_reqxxx(proxy, file, line, arg) || |
| 396 | warnif_rule_after_reqadd(proxy, file, line, arg) || |
| 397 | warnif_rule_after_redirect(proxy, file, line, arg) || |
| 398 | warnif_rule_after_use_backend(proxy, file, line, arg); |
| 399 | } |
| 400 | |
| 401 | /* report a warning if a reqxxx rule is dangerously placed */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 402 | 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] | 403 | { |
| 404 | return warnif_rule_after_reqadd(proxy, file, line, arg) || |
| 405 | warnif_rule_after_redirect(proxy, file, line, arg) || |
| 406 | warnif_rule_after_use_backend(proxy, file, line, arg); |
| 407 | } |
| 408 | |
| 409 | /* report a warning if a reqadd rule is dangerously placed */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 410 | 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] | 411 | { |
| 412 | return warnif_rule_after_redirect(proxy, file, line, arg) || |
| 413 | warnif_rule_after_use_backend(proxy, file, line, arg); |
| 414 | } |
| 415 | |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 416 | /* Report it if a request ACL condition uses some response-only parameters. It |
| 417 | * returns either 0 or ERR_WARN so that its result can be or'ed with err_code. |
| 418 | * Note that <cond> may be NULL and then will be ignored. |
| 419 | */ |
| 420 | static int warnif_cond_requires_resp(const struct acl_cond *cond, const char *file, int line) |
| 421 | { |
| 422 | struct acl *acl; |
| 423 | |
| 424 | if (!cond || !(cond->requires & ACL_USE_RTR_ANY)) |
| 425 | return 0; |
| 426 | |
| 427 | acl = cond_find_require(cond, ACL_USE_RTR_ANY); |
| 428 | Warning("parsing [%s:%d] : acl '%s' involves some response-only criteria which will be ignored.\n", |
| 429 | file, line, acl ? acl->name : "(unknown)"); |
| 430 | return ERR_WARN; |
| 431 | } |
| 432 | |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 433 | /* Report it if a request ACL condition uses some request-only volatile parameters. |
| 434 | * It returns either 0 or ERR_WARN so that its result can be or'ed with err_code. |
| 435 | * Note that <cond> may be NULL and then will be ignored. |
| 436 | */ |
| 437 | static int warnif_cond_requires_req(const struct acl_cond *cond, const char *file, int line) |
| 438 | { |
| 439 | struct acl *acl; |
| 440 | |
| 441 | if (!cond || !(cond->requires & ACL_USE_REQ_VOLATILE)) |
| 442 | return 0; |
| 443 | |
| 444 | acl = cond_find_require(cond, ACL_USE_REQ_VOLATILE); |
| 445 | Warning("parsing [%s:%d] : acl '%s' involves some volatile request-only criteria which will be ignored.\n", |
| 446 | file, line, acl ? acl->name : "(unknown)"); |
| 447 | return ERR_WARN; |
| 448 | } |
| 449 | |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 450 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 451 | /* |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 452 | * parse a line in a <global> section. Returns the error code, 0 if OK, or |
| 453 | * any combination of : |
| 454 | * - ERR_ABORT: must abort ASAP |
| 455 | * - ERR_FATAL: we can continue parsing but not start the service |
| 456 | * - ERR_WARN: a warning has been emitted |
| 457 | * - ERR_ALERT: an alert has been emitted |
| 458 | * Only the two first ones can stop processing, the two others are just |
| 459 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 460 | */ |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 461 | 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] | 462 | { |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 463 | int err_code = 0; |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 464 | char *errmsg = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 465 | |
| 466 | if (!strcmp(args[0], "global")) { /* new section */ |
| 467 | /* no option, nothing special to do */ |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 468 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 469 | } |
Emeric Brun | c8e8d12 | 2012-10-02 18:42:10 +0200 | [diff] [blame] | 470 | else if (!strcmp(args[0], "ca-base")) { |
| 471 | #ifdef USE_OPENSSL |
| 472 | if (global.ca_base != NULL) { |
| 473 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 474 | err_code |= ERR_ALERT; |
| 475 | goto out; |
| 476 | } |
| 477 | if (*(args[1]) == 0) { |
| 478 | Alert("parsing [%s:%d] : '%s' expects a directory path as an argument.\n", file, linenum, args[0]); |
| 479 | err_code |= ERR_ALERT | ERR_FATAL; |
| 480 | goto out; |
| 481 | } |
| 482 | global.ca_base = strdup(args[1]); |
| 483 | #else |
| 484 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 485 | err_code |= ERR_ALERT | ERR_FATAL; |
| 486 | goto out; |
| 487 | #endif |
| 488 | } |
| 489 | else if (!strcmp(args[0], "crt-base")) { |
| 490 | #ifdef USE_OPENSSL |
| 491 | if (global.crt_base != NULL) { |
| 492 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 493 | err_code |= ERR_ALERT; |
| 494 | goto out; |
| 495 | } |
| 496 | if (*(args[1]) == 0) { |
| 497 | Alert("parsing [%s:%d] : '%s' expects a directory path as an argument.\n", file, linenum, args[0]); |
| 498 | err_code |= ERR_ALERT | ERR_FATAL; |
| 499 | goto out; |
| 500 | } |
| 501 | global.crt_base = strdup(args[1]); |
| 502 | #else |
| 503 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 504 | err_code |= ERR_ALERT | ERR_FATAL; |
| 505 | goto out; |
| 506 | #endif |
| 507 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 508 | else if (!strcmp(args[0], "daemon")) { |
| 509 | global.mode |= MODE_DAEMON; |
| 510 | } |
| 511 | else if (!strcmp(args[0], "debug")) { |
| 512 | global.mode |= MODE_DEBUG; |
| 513 | } |
| 514 | else if (!strcmp(args[0], "noepoll")) { |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 515 | global.tune.options &= ~GTUNE_USE_EPOLL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 516 | } |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 517 | else if (!strcmp(args[0], "nosepoll")) { |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 518 | global.tune.options &= ~GTUNE_USE_SEPOLL; |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 519 | } |
| 520 | else if (!strcmp(args[0], "nokqueue")) { |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 521 | global.tune.options &= ~GTUNE_USE_KQUEUE; |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 522 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 523 | else if (!strcmp(args[0], "nopoll")) { |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 524 | global.tune.options &= ~GTUNE_USE_POLL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 525 | } |
Willy Tarreau | 3ab68cf | 2009-01-25 16:03:28 +0100 | [diff] [blame] | 526 | else if (!strcmp(args[0], "nosplice")) { |
| 527 | global.tune.options &= ~GTUNE_USE_SPLICE; |
| 528 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 529 | else if (!strcmp(args[0], "quiet")) { |
| 530 | global.mode |= MODE_QUIET; |
| 531 | } |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 532 | else if (!strcmp(args[0], "tune.maxpollevents")) { |
| 533 | if (global.tune.maxpollevents != 0) { |
| 534 | 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] | 535 | err_code |= ERR_ALERT; |
| 536 | goto out; |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 537 | } |
| 538 | if (*(args[1]) == 0) { |
| 539 | 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] | 540 | err_code |= ERR_ALERT | ERR_FATAL; |
| 541 | goto out; |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 542 | } |
| 543 | global.tune.maxpollevents = atol(args[1]); |
| 544 | } |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 545 | else if (!strcmp(args[0], "tune.maxaccept")) { |
| 546 | if (global.tune.maxaccept != 0) { |
| 547 | 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] | 548 | err_code |= ERR_ALERT; |
| 549 | goto out; |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 550 | } |
| 551 | if (*(args[1]) == 0) { |
| 552 | 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] | 553 | err_code |= ERR_ALERT | ERR_FATAL; |
| 554 | goto out; |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 555 | } |
| 556 | global.tune.maxaccept = atol(args[1]); |
| 557 | } |
Willy Tarreau | 43961d5 | 2010-10-04 20:39:20 +0200 | [diff] [blame] | 558 | else if (!strcmp(args[0], "tune.chksize")) { |
| 559 | if (*(args[1]) == 0) { |
| 560 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 561 | err_code |= ERR_ALERT | ERR_FATAL; |
| 562 | goto out; |
| 563 | } |
| 564 | global.tune.chksize = atol(args[1]); |
| 565 | } |
Emeric Brun | fc32aca | 2012-09-03 12:10:29 +0200 | [diff] [blame] | 566 | #ifdef USE_OPENSSL |
| 567 | else if (!strcmp(args[0], "tune.sslcachesize")) { |
| 568 | if (*(args[1]) == 0) { |
| 569 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 570 | err_code |= ERR_ALERT | ERR_FATAL; |
| 571 | goto out; |
| 572 | } |
| 573 | global.tune.sslcachesize = atol(args[1]); |
| 574 | } |
| 575 | #endif |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 576 | else if (!strcmp(args[0], "tune.bufsize")) { |
| 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.bufsize = atol(args[1]); |
| 583 | if (global.tune.maxrewrite >= global.tune.bufsize / 2) |
| 584 | global.tune.maxrewrite = global.tune.bufsize / 2; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 585 | chunk_init(&trash, realloc(trash.str, global.tune.bufsize), global.tune.bufsize); |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 586 | } |
| 587 | else if (!strcmp(args[0], "tune.maxrewrite")) { |
| 588 | if (*(args[1]) == 0) { |
| 589 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 590 | err_code |= ERR_ALERT | ERR_FATAL; |
| 591 | goto out; |
| 592 | } |
| 593 | global.tune.maxrewrite = atol(args[1]); |
| 594 | if (global.tune.maxrewrite >= global.tune.bufsize / 2) |
| 595 | global.tune.maxrewrite = global.tune.bufsize / 2; |
| 596 | } |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 597 | else if (!strcmp(args[0], "tune.rcvbuf.client")) { |
| 598 | if (global.tune.client_rcvbuf != 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.client_rcvbuf = atol(args[1]); |
| 609 | } |
| 610 | else if (!strcmp(args[0], "tune.rcvbuf.server")) { |
| 611 | if (global.tune.server_rcvbuf != 0) { |
| 612 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 613 | err_code |= ERR_ALERT; |
| 614 | goto out; |
| 615 | } |
| 616 | if (*(args[1]) == 0) { |
| 617 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 618 | err_code |= ERR_ALERT | ERR_FATAL; |
| 619 | goto out; |
| 620 | } |
| 621 | global.tune.server_rcvbuf = atol(args[1]); |
| 622 | } |
| 623 | else if (!strcmp(args[0], "tune.sndbuf.client")) { |
| 624 | if (global.tune.client_sndbuf != 0) { |
| 625 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 626 | err_code |= ERR_ALERT; |
| 627 | goto out; |
| 628 | } |
| 629 | if (*(args[1]) == 0) { |
| 630 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 631 | err_code |= ERR_ALERT | ERR_FATAL; |
| 632 | goto out; |
| 633 | } |
| 634 | global.tune.client_sndbuf = atol(args[1]); |
| 635 | } |
| 636 | else if (!strcmp(args[0], "tune.sndbuf.server")) { |
| 637 | if (global.tune.server_sndbuf != 0) { |
| 638 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 639 | err_code |= ERR_ALERT; |
| 640 | goto out; |
| 641 | } |
| 642 | if (*(args[1]) == 0) { |
| 643 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 644 | err_code |= ERR_ALERT | ERR_FATAL; |
| 645 | goto out; |
| 646 | } |
| 647 | global.tune.server_sndbuf = atol(args[1]); |
| 648 | } |
Willy Tarreau | bd9a0a7 | 2011-10-23 21:14:29 +0200 | [diff] [blame] | 649 | else if (!strcmp(args[0], "tune.pipesize")) { |
| 650 | if (*(args[1]) == 0) { |
| 651 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 652 | err_code |= ERR_ALERT | ERR_FATAL; |
| 653 | goto out; |
| 654 | } |
| 655 | global.tune.pipesize = atol(args[1]); |
| 656 | } |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame] | 657 | else if (!strcmp(args[0], "tune.http.maxhdr")) { |
| 658 | if (*(args[1]) == 0) { |
| 659 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 660 | err_code |= ERR_ALERT | ERR_FATAL; |
| 661 | goto out; |
| 662 | } |
| 663 | global.tune.max_http_hdr = atol(args[1]); |
| 664 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 665 | else if (!strcmp(args[0], "uid")) { |
| 666 | if (global.uid != 0) { |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 667 | Alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 668 | err_code |= ERR_ALERT; |
| 669 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 670 | } |
| 671 | if (*(args[1]) == 0) { |
| 672 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 673 | err_code |= ERR_ALERT | ERR_FATAL; |
| 674 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 675 | } |
| 676 | global.uid = atol(args[1]); |
| 677 | } |
| 678 | else if (!strcmp(args[0], "gid")) { |
| 679 | if (global.gid != 0) { |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 680 | Alert("parsing [%s:%d] : group/gid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 681 | err_code |= ERR_ALERT; |
| 682 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 683 | } |
| 684 | if (*(args[1]) == 0) { |
| 685 | 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] | 686 | err_code |= ERR_ALERT | ERR_FATAL; |
| 687 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 688 | } |
| 689 | global.gid = atol(args[1]); |
| 690 | } |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 691 | /* user/group name handling */ |
| 692 | else if (!strcmp(args[0], "user")) { |
| 693 | struct passwd *ha_user; |
| 694 | if (global.uid != 0) { |
| 695 | Alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 696 | err_code |= ERR_ALERT; |
| 697 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 698 | } |
| 699 | errno = 0; |
| 700 | ha_user = getpwnam(args[1]); |
| 701 | if (ha_user != NULL) { |
| 702 | global.uid = (int)ha_user->pw_uid; |
| 703 | } |
| 704 | else { |
| 705 | 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] | 706 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 707 | } |
| 708 | } |
| 709 | else if (!strcmp(args[0], "group")) { |
| 710 | struct group *ha_group; |
| 711 | if (global.gid != 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 712 | 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] | 713 | err_code |= ERR_ALERT; |
| 714 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 715 | } |
| 716 | errno = 0; |
| 717 | ha_group = getgrnam(args[1]); |
| 718 | if (ha_group != NULL) { |
| 719 | global.gid = (int)ha_group->gr_gid; |
| 720 | } |
| 721 | else { |
| 722 | 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] | 723 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 724 | } |
| 725 | } |
| 726 | /* end of user/group name handling*/ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 727 | else if (!strcmp(args[0], "nbproc")) { |
| 728 | if (global.nbproc != 0) { |
| 729 | 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] | 730 | err_code |= ERR_ALERT; |
| 731 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 732 | } |
| 733 | if (*(args[1]) == 0) { |
| 734 | 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] | 735 | err_code |= ERR_ALERT | ERR_FATAL; |
| 736 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 737 | } |
| 738 | global.nbproc = atol(args[1]); |
| 739 | } |
| 740 | else if (!strcmp(args[0], "maxconn")) { |
| 741 | if (global.maxconn != 0) { |
| 742 | 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] | 743 | err_code |= ERR_ALERT; |
| 744 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 745 | } |
| 746 | if (*(args[1]) == 0) { |
| 747 | 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] | 748 | err_code |= ERR_ALERT | ERR_FATAL; |
| 749 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 750 | } |
| 751 | global.maxconn = atol(args[1]); |
| 752 | #ifdef SYSTEM_MAXCONN |
| 753 | if (global.maxconn > DEFAULT_MAXCONN && cfg_maxconn <= DEFAULT_MAXCONN) { |
| 754 | 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); |
| 755 | global.maxconn = DEFAULT_MAXCONN; |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 756 | err_code |= ERR_ALERT; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 757 | } |
| 758 | #endif /* SYSTEM_MAXCONN */ |
| 759 | } |
Willy Tarreau | 403edff | 2012-09-06 11:58:37 +0200 | [diff] [blame] | 760 | else if (!strcmp(args[0], "maxsslconn")) { |
| 761 | #ifdef USE_OPENSSL |
| 762 | if (*(args[1]) == 0) { |
| 763 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 764 | err_code |= ERR_ALERT | ERR_FATAL; |
| 765 | goto out; |
| 766 | } |
| 767 | global.maxsslconn = atol(args[1]); |
| 768 | #else |
Emeric Brun | 0914df8 | 2012-10-02 18:45:42 +0200 | [diff] [blame] | 769 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 770 | err_code |= ERR_ALERT | ERR_FATAL; |
| 771 | goto out; |
Willy Tarreau | 403edff | 2012-09-06 11:58:37 +0200 | [diff] [blame] | 772 | #endif |
| 773 | } |
Willy Tarreau | 81c25d0 | 2011-09-07 15:17:21 +0200 | [diff] [blame] | 774 | else if (!strcmp(args[0], "maxconnrate")) { |
| 775 | if (global.cps_lim != 0) { |
| 776 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 777 | err_code |= ERR_ALERT; |
| 778 | goto out; |
| 779 | } |
| 780 | if (*(args[1]) == 0) { |
| 781 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 782 | err_code |= ERR_ALERT | ERR_FATAL; |
| 783 | goto out; |
| 784 | } |
| 785 | global.cps_lim = atol(args[1]); |
| 786 | } |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 787 | else if (!strcmp(args[0], "maxpipes")) { |
| 788 | if (global.maxpipes != 0) { |
| 789 | 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] | 790 | err_code |= ERR_ALERT; |
| 791 | goto out; |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 792 | } |
| 793 | if (*(args[1]) == 0) { |
| 794 | 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] | 795 | err_code |= ERR_ALERT | ERR_FATAL; |
| 796 | goto out; |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 797 | } |
| 798 | global.maxpipes = atol(args[1]); |
| 799 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 800 | else if (!strcmp(args[0], "ulimit-n")) { |
| 801 | if (global.rlimit_nofile != 0) { |
| 802 | 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] | 803 | err_code |= ERR_ALERT; |
| 804 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 805 | } |
| 806 | if (*(args[1]) == 0) { |
| 807 | 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] | 808 | err_code |= ERR_ALERT | ERR_FATAL; |
| 809 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 810 | } |
| 811 | global.rlimit_nofile = atol(args[1]); |
| 812 | } |
| 813 | else if (!strcmp(args[0], "chroot")) { |
| 814 | if (global.chroot != NULL) { |
| 815 | 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] | 816 | err_code |= ERR_ALERT; |
| 817 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 818 | } |
| 819 | if (*(args[1]) == 0) { |
| 820 | 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] | 821 | err_code |= ERR_ALERT | ERR_FATAL; |
| 822 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 823 | } |
| 824 | global.chroot = strdup(args[1]); |
| 825 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 826 | else if (!strcmp(args[0], "description")) { |
| 827 | int i, len=0; |
| 828 | char *d; |
| 829 | |
| 830 | if (!*args[1]) { |
| 831 | Alert("parsing [%s:%d]: '%s' expects a string argument.\n", |
| 832 | file, linenum, args[0]); |
| 833 | err_code |= ERR_ALERT | ERR_FATAL; |
| 834 | goto out; |
| 835 | } |
| 836 | |
| 837 | for(i=1; *args[i]; i++) |
| 838 | len += strlen(args[i])+1; |
| 839 | |
| 840 | if (global.desc) |
| 841 | free(global.desc); |
| 842 | |
| 843 | global.desc = d = (char *)calloc(1, len); |
| 844 | |
| 845 | d += sprintf(d, "%s", args[1]); |
| 846 | for(i=2; *args[i]; i++) |
| 847 | d += sprintf(d, " %s", args[i]); |
| 848 | } |
| 849 | else if (!strcmp(args[0], "node")) { |
| 850 | int i; |
| 851 | char c; |
| 852 | |
| 853 | for (i=0; args[1][i]; i++) { |
| 854 | c = args[1][i]; |
Willy Tarreau | 88e0581 | 2010-03-03 00:16:00 +0100 | [diff] [blame] | 855 | if (!isupper((unsigned char)c) && !islower((unsigned char)c) && |
| 856 | !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.') |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 857 | break; |
| 858 | } |
| 859 | |
| 860 | if (!i || args[1][i]) { |
| 861 | Alert("parsing [%s:%d]: '%s' requires valid node name - non-empty string" |
| 862 | " with digits(0-9), letters(A-Z, a-z), dot(.), hyphen(-) or underscode(_).\n", |
| 863 | file, linenum, args[0]); |
| 864 | err_code |= ERR_ALERT | ERR_FATAL; |
| 865 | goto out; |
| 866 | } |
| 867 | |
| 868 | if (global.node) |
| 869 | free(global.node); |
| 870 | |
| 871 | global.node = strdup(args[1]); |
| 872 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 873 | else if (!strcmp(args[0], "pidfile")) { |
| 874 | if (global.pidfile != NULL) { |
| 875 | 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] | 876 | err_code |= ERR_ALERT; |
| 877 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 878 | } |
| 879 | if (*(args[1]) == 0) { |
| 880 | 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] | 881 | err_code |= ERR_ALERT | ERR_FATAL; |
| 882 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 883 | } |
| 884 | global.pidfile = strdup(args[1]); |
| 885 | } |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 886 | else if (!strcmp(args[0], "unix-bind")) { |
| 887 | int cur_arg = 1; |
| 888 | while (*(args[cur_arg])) { |
| 889 | if (!strcmp(args[cur_arg], "prefix")) { |
| 890 | if (global.unix_bind.prefix != NULL) { |
| 891 | Alert("parsing [%s:%d] : unix-bind '%s' already specified. Continuing.\n", file, linenum, args[cur_arg]); |
| 892 | err_code |= ERR_ALERT; |
| 893 | cur_arg += 2; |
| 894 | continue; |
| 895 | } |
| 896 | |
| 897 | if (*(args[cur_arg+1]) == 0) { |
| 898 | Alert("parsing [%s:%d] : unix_bind '%s' expects a path as an argument.\n", file, linenum, args[cur_arg]); |
| 899 | err_code |= ERR_ALERT | ERR_FATAL; |
| 900 | goto out; |
| 901 | } |
| 902 | global.unix_bind.prefix = strdup(args[cur_arg+1]); |
| 903 | cur_arg += 2; |
| 904 | continue; |
| 905 | } |
| 906 | |
| 907 | if (!strcmp(args[cur_arg], "mode")) { |
| 908 | |
| 909 | global.unix_bind.ux.mode = strtol(args[cur_arg + 1], NULL, 8); |
| 910 | cur_arg += 2; |
| 911 | continue; |
| 912 | } |
| 913 | |
| 914 | if (!strcmp(args[cur_arg], "uid")) { |
| 915 | |
| 916 | global.unix_bind.ux.uid = atol(args[cur_arg + 1 ]); |
| 917 | cur_arg += 2; |
| 918 | continue; |
| 919 | } |
| 920 | |
| 921 | if (!strcmp(args[cur_arg], "gid")) { |
| 922 | |
| 923 | global.unix_bind.ux.gid = atol(args[cur_arg + 1 ]); |
| 924 | cur_arg += 2; |
| 925 | continue; |
| 926 | } |
| 927 | |
| 928 | if (!strcmp(args[cur_arg], "user")) { |
| 929 | struct passwd *user; |
| 930 | |
| 931 | user = getpwnam(args[cur_arg + 1]); |
| 932 | if (!user) { |
| 933 | Alert("parsing [%s:%d] : '%s' : '%s' unknown user.\n", |
| 934 | file, linenum, args[0], args[cur_arg + 1 ]); |
| 935 | err_code |= ERR_ALERT | ERR_FATAL; |
| 936 | goto out; |
| 937 | } |
| 938 | |
| 939 | global.unix_bind.ux.uid = user->pw_uid; |
| 940 | cur_arg += 2; |
| 941 | continue; |
| 942 | } |
| 943 | |
| 944 | if (!strcmp(args[cur_arg], "group")) { |
| 945 | struct group *group; |
| 946 | |
| 947 | group = getgrnam(args[cur_arg + 1]); |
| 948 | if (!group) { |
| 949 | Alert("parsing [%s:%d] : '%s' : '%s' unknown group.\n", |
| 950 | file, linenum, args[0], args[cur_arg + 1 ]); |
| 951 | err_code |= ERR_ALERT | ERR_FATAL; |
| 952 | goto out; |
| 953 | } |
| 954 | |
| 955 | global.unix_bind.ux.gid = group->gr_gid; |
| 956 | cur_arg += 2; |
| 957 | continue; |
| 958 | } |
| 959 | |
Willy Tarreau | b48f958 | 2011-09-05 01:17:06 +0200 | [diff] [blame] | 960 | 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] | 961 | file, linenum, args[0]); |
| 962 | err_code |= ERR_ALERT | ERR_FATAL; |
| 963 | goto out; |
| 964 | } |
| 965 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 966 | else if (!strcmp(args[0], "log") && kwm == KWM_NO) { /* no log */ |
| 967 | /* delete previous herited or defined syslog servers */ |
| 968 | struct logsrv *back; |
| 969 | struct logsrv *tmp; |
| 970 | |
| 971 | if (*(args[1]) != 0) { |
| 972 | Alert("parsing [%s:%d]:%s : 'no log' does not expect arguments.\n", file, linenum, args[1]); |
| 973 | err_code |= ERR_ALERT | ERR_FATAL; |
| 974 | goto out; |
| 975 | } |
| 976 | |
| 977 | list_for_each_entry_safe(tmp, back, &global.logsrvs, list) { |
| 978 | LIST_DEL(&tmp->list); |
| 979 | free(tmp); |
| 980 | } |
| 981 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 982 | else if (!strcmp(args[0], "log")) { /* syslog server address */ |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 983 | struct logsrv *logsrv; |
| 984 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 985 | if (*(args[1]) == 0 || *(args[2]) == 0) { |
| 986 | 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] | 987 | err_code |= ERR_ALERT | ERR_FATAL; |
| 988 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 989 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 990 | |
| 991 | logsrv = calloc(1, sizeof(struct logsrv)); |
| 992 | |
| 993 | logsrv->facility = get_log_facility(args[2]); |
| 994 | if (logsrv->facility < 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 995 | 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] | 996 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 997 | logsrv->facility = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 998 | } |
| 999 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1000 | logsrv->level = 7; /* max syslog level = debug */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1001 | if (*(args[3])) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1002 | logsrv->level = get_log_level(args[3]); |
| 1003 | if (logsrv->level < 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1004 | 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] | 1005 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1006 | logsrv->level = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1007 | } |
| 1008 | } |
| 1009 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1010 | logsrv->minlvl = 0; /* limit syslog level to this level (emerg) */ |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 1011 | if (*(args[4])) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1012 | logsrv->minlvl = get_log_level(args[4]); |
| 1013 | if (logsrv->minlvl < 0) { |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 1014 | 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] | 1015 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1016 | logsrv->minlvl = 0; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 1017 | } |
| 1018 | } |
| 1019 | |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 1020 | if (args[1][0] == '/') { |
David du Colombier | 11bcb6c | 2011-03-24 12:23:00 +0100 | [diff] [blame] | 1021 | struct sockaddr_storage *sk = (struct sockaddr_storage *)str2sun(args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 1022 | if (!sk) { |
| 1023 | 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] | 1024 | args[1], (int)sizeof(((struct sockaddr_un *)&sk)->sun_path) - 1); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 1025 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1026 | free(logsrv); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 1027 | goto out; |
| 1028 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1029 | logsrv->addr = *sk; |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 1030 | } else { |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 1031 | struct sockaddr_storage *sk = str2sa(args[1]); |
David du Colombier | 11bcb6c | 2011-03-24 12:23:00 +0100 | [diff] [blame] | 1032 | if (!sk) { |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 1033 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[1]); |
| 1034 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1035 | free(logsrv); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 1036 | goto out; |
| 1037 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1038 | logsrv->addr = *sk; |
| 1039 | if (!get_host_port(&logsrv->addr)) |
| 1040 | set_host_port(&logsrv->addr, SYSLOG_PORT); |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 1041 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1042 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1043 | LIST_ADDQ(&global.logsrvs, &logsrv->list); |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1044 | } |
Joe Williams | df5b38f | 2010-12-29 17:05:48 +0100 | [diff] [blame] | 1045 | else if (!strcmp(args[0], "log-send-hostname")) { /* set the hostname in syslog header */ |
| 1046 | char *name; |
| 1047 | int len; |
| 1048 | |
| 1049 | if (global.log_send_hostname != NULL) { |
| 1050 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 1051 | err_code |= ERR_ALERT; |
| 1052 | goto out; |
| 1053 | } |
| 1054 | |
| 1055 | if (*(args[1])) |
| 1056 | name = args[1]; |
| 1057 | else |
| 1058 | name = hostname; |
| 1059 | |
| 1060 | len = strlen(name); |
| 1061 | |
| 1062 | /* We'll add a space after the name to respect the log format */ |
| 1063 | free(global.log_send_hostname); |
| 1064 | global.log_send_hostname = malloc(len + 2); |
| 1065 | snprintf(global.log_send_hostname, len + 2, "%s ", name); |
| 1066 | } |
Kevinm | 48936af | 2010-12-22 16:08:21 +0000 | [diff] [blame] | 1067 | else if (!strcmp(args[0], "log-tag")) { /* tag to report to syslog */ |
| 1068 | if (*(args[1]) == 0) { |
| 1069 | Alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]); |
| 1070 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1071 | goto out; |
| 1072 | } |
| 1073 | free(global.log_tag); |
| 1074 | global.log_tag = strdup(args[1]); |
| 1075 | } |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1076 | else if (!strcmp(args[0], "spread-checks")) { /* random time between checks (0-50) */ |
| 1077 | if (global.spread_checks != 0) { |
| 1078 | Alert("parsing [%s:%d]: spread-checks already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1079 | err_code |= ERR_ALERT; |
| 1080 | goto out; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1081 | } |
| 1082 | if (*(args[1]) == 0) { |
| 1083 | 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] | 1084 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1085 | goto out; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1086 | } |
| 1087 | global.spread_checks = atol(args[1]); |
| 1088 | if (global.spread_checks < 0 || global.spread_checks > 50) { |
| 1089 | 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] | 1090 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1091 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1092 | } |
| 1093 | else { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1094 | struct cfg_kw_list *kwl; |
| 1095 | int index; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1096 | int rc; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1097 | |
| 1098 | list_for_each_entry(kwl, &cfg_keywords.list, list) { |
| 1099 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 1100 | if (kwl->kw[index].section != CFG_GLOBAL) |
| 1101 | continue; |
| 1102 | if (strcmp(kwl->kw[index].kw, args[0]) == 0) { |
Willy Tarreau | 28a47d6 | 2012-09-18 20:02:48 +0200 | [diff] [blame] | 1103 | 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] | 1104 | if (rc < 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 1105 | Alert("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1106 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1107 | } |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1108 | else if (rc > 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 1109 | Warning("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1110 | err_code |= ERR_WARN; |
| 1111 | goto out; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1112 | } |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1113 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1114 | } |
| 1115 | } |
| 1116 | } |
| 1117 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1118 | 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] | 1119 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1120 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1121 | |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1122 | out: |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 1123 | free(errmsg); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1124 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1125 | } |
| 1126 | |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 1127 | void init_default_instance() |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1128 | { |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 1129 | init_new_proxy(&defproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1130 | defproxy.mode = PR_MODE_TCP; |
| 1131 | defproxy.state = PR_STNEW; |
| 1132 | defproxy.maxconn = cfg_maxpconn; |
| 1133 | defproxy.conn_retries = CONN_RETRIES; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1134 | |
| 1135 | defproxy.defsrv.inter = DEF_CHKINTR; |
| 1136 | defproxy.defsrv.fastinter = 0; |
| 1137 | defproxy.defsrv.downinter = 0; |
| 1138 | defproxy.defsrv.rise = DEF_RISETIME; |
| 1139 | defproxy.defsrv.fall = DEF_FALLTIME; |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 1140 | defproxy.defsrv.check.port = 0; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1141 | defproxy.defsrv.maxqueue = 0; |
| 1142 | defproxy.defsrv.minconn = 0; |
| 1143 | defproxy.defsrv.maxconn = 0; |
| 1144 | defproxy.defsrv.slowstart = 0; |
| 1145 | defproxy.defsrv.onerror = DEF_HANA_ONERR; |
| 1146 | defproxy.defsrv.consecutive_errors_limit = DEF_HANA_ERRLIMIT; |
| 1147 | defproxy.defsrv.uweight = defproxy.defsrv.iweight = 1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1148 | } |
| 1149 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1150 | |
| 1151 | static int create_cond_regex_rule(const char *file, int line, |
| 1152 | struct proxy *px, int dir, int action, int flags, |
| 1153 | const char *cmd, const char *reg, const char *repl, |
| 1154 | const char **cond_start) |
| 1155 | { |
| 1156 | regex_t *preg = NULL; |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 1157 | char *errmsg = NULL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1158 | const char *err; |
| 1159 | int err_code = 0; |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1160 | struct acl_cond *cond = NULL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1161 | |
| 1162 | if (px == &defproxy) { |
| 1163 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, line, cmd); |
| 1164 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1165 | goto err; |
| 1166 | } |
| 1167 | |
| 1168 | if (*reg == 0) { |
| 1169 | Alert("parsing [%s:%d] : '%s' expects <regex> as an argument.\n", file, line, cmd); |
| 1170 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1171 | goto err; |
| 1172 | } |
| 1173 | |
| 1174 | if (warnifnotcap(px, PR_CAP_RS, file, line, cmd, NULL)) |
| 1175 | err_code |= ERR_WARN; |
| 1176 | |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1177 | if (cond_start && |
| 1178 | (strcmp(*cond_start, "if") == 0 || strcmp(*cond_start, "unless") == 0)) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 1179 | if ((cond = build_acl_cond(file, line, px, cond_start, &errmsg)) == NULL) { |
| 1180 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 1181 | file, line, cmd, errmsg); |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1182 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1183 | goto err; |
| 1184 | } |
| 1185 | } |
| 1186 | else if (cond_start && **cond_start) { |
| 1187 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 1188 | file, line, cmd, *cond_start); |
| 1189 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1190 | goto err; |
| 1191 | } |
| 1192 | |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 1193 | if (dir == SMP_OPT_DIR_REQ) |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1194 | err_code |= warnif_cond_requires_resp(cond, file, line); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 1195 | else |
| 1196 | err_code |= warnif_cond_requires_req(cond, file, line); |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1197 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1198 | preg = calloc(1, sizeof(regex_t)); |
| 1199 | if (!preg) { |
| 1200 | Alert("parsing [%s:%d] : '%s' : not enough memory to build regex.\n", file, line, cmd); |
| 1201 | err_code = ERR_ALERT | ERR_FATAL; |
| 1202 | goto err; |
| 1203 | } |
| 1204 | |
| 1205 | if (regcomp(preg, reg, REG_EXTENDED | flags) != 0) { |
| 1206 | Alert("parsing [%s:%d] : '%s' : bad regular expression '%s'.\n", file, line, cmd, reg); |
| 1207 | err_code = ERR_ALERT | ERR_FATAL; |
| 1208 | goto err; |
| 1209 | } |
| 1210 | |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 1211 | 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] | 1212 | preg, action, repl ? strdup(repl) : NULL, cond); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1213 | if (repl && err) { |
| 1214 | Alert("parsing [%s:%d] : '%s' : invalid character or unterminated sequence in replacement string near '%c'.\n", |
| 1215 | file, line, cmd, *err); |
| 1216 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1217 | goto err; |
| 1218 | } |
| 1219 | |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 1220 | 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] | 1221 | err_code |= ERR_WARN; |
| 1222 | |
Willy Tarreau | f4068b6 | 2012-05-08 17:37:49 +0200 | [diff] [blame] | 1223 | free(errmsg); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1224 | return err_code; |
| 1225 | err: |
Willy Tarreau | f4068b6 | 2012-05-08 17:37:49 +0200 | [diff] [blame] | 1226 | free(errmsg); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1227 | free(preg); |
| 1228 | return err_code; |
| 1229 | } |
| 1230 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1231 | /* |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1232 | * Parse a line in a <listen>, <frontend>, <backend> or <ruleset> section. |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1233 | * Returns the error code, 0 if OK, or any combination of : |
| 1234 | * - ERR_ABORT: must abort ASAP |
| 1235 | * - ERR_FATAL: we can continue parsing but not start the service |
| 1236 | * - ERR_WARN: a warning has been emitted |
| 1237 | * - ERR_ALERT: an alert has been emitted |
| 1238 | * Only the two first ones can stop processing, the two others are just |
| 1239 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1240 | */ |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1241 | int cfg_parse_peers(const char *file, int linenum, char **args, int kwm) |
| 1242 | { |
| 1243 | static struct peers *curpeers = NULL; |
| 1244 | struct peer *newpeer = NULL; |
| 1245 | const char *err; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1246 | struct bind_conf *bind_conf; |
| 1247 | struct listener *l; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1248 | int err_code = 0; |
| 1249 | |
| 1250 | if (strcmp(args[0], "peers") == 0) { /* new peers section */ |
| 1251 | |
| 1252 | err = invalid_char(args[1]); |
| 1253 | if (err) { |
| 1254 | Alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 1255 | file, linenum, *err, args[0], args[1]); |
| 1256 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1257 | } |
| 1258 | |
| 1259 | for (curpeers = peers; curpeers != NULL; curpeers = curpeers->next) { |
| 1260 | /* |
| 1261 | * If there are two proxies with the same name only following |
| 1262 | * combinations are allowed: |
| 1263 | */ |
| 1264 | if (strcmp(curpeers->id, args[1]) == 0) { |
| 1265 | Warning("Parsing [%s:%d]: peers '%s' has same name as another peers (declared at %s:%d).\n", |
| 1266 | file, linenum, args[1], curpeers->conf.file, curpeers->conf.line); |
| 1267 | err_code |= ERR_WARN; |
| 1268 | } |
| 1269 | } |
| 1270 | |
| 1271 | if ((curpeers = (struct peers *)calloc(1, sizeof(struct peers))) == 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 | curpeers->next = peers; |
| 1278 | peers = curpeers; |
Willy Tarreau | 8113a5d | 2012-10-04 08:01:43 +0200 | [diff] [blame] | 1279 | curpeers->conf.file = strdup(file); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1280 | curpeers->conf.line = linenum; |
| 1281 | curpeers->last_change = now.tv_sec; |
| 1282 | curpeers->id = strdup(args[1]); |
| 1283 | } |
| 1284 | else if (strcmp(args[0], "peer") == 0) { /* peer definition */ |
| 1285 | char *rport, *raddr; |
| 1286 | short realport = 0; |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 1287 | struct sockaddr_storage *sk; |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 1288 | char *err_msg = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1289 | |
| 1290 | if (!*args[2]) { |
| 1291 | Alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n", |
| 1292 | file, linenum, args[0]); |
| 1293 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1294 | goto out; |
| 1295 | } |
| 1296 | |
| 1297 | err = invalid_char(args[1]); |
| 1298 | if (err) { |
| 1299 | Alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n", |
| 1300 | file, linenum, *err, args[1]); |
| 1301 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1302 | goto out; |
| 1303 | } |
| 1304 | |
| 1305 | if ((newpeer = (struct peer *)calloc(1, sizeof(struct peer))) == NULL) { |
| 1306 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1307 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1308 | goto out; |
| 1309 | } |
| 1310 | |
| 1311 | /* the peers are linked backwards first */ |
| 1312 | curpeers->count++; |
| 1313 | newpeer->next = curpeers->remote; |
| 1314 | curpeers->remote = newpeer; |
| 1315 | newpeer->peers = curpeers; |
Willy Tarreau | 8113a5d | 2012-10-04 08:01:43 +0200 | [diff] [blame] | 1316 | newpeer->conf.file = strdup(file); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1317 | newpeer->conf.line = linenum; |
| 1318 | |
| 1319 | newpeer->last_change = now.tv_sec; |
| 1320 | newpeer->id = strdup(args[1]); |
| 1321 | |
| 1322 | raddr = strdup(args[2]); |
Willy Tarreau | fab5a43 | 2011-03-04 15:31:53 +0100 | [diff] [blame] | 1323 | rport = strrchr(raddr, ':'); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1324 | if (rport) { |
| 1325 | *rport++ = 0; |
| 1326 | realport = atol(rport); |
| 1327 | } |
| 1328 | if (!realport) { |
| 1329 | Alert("parsing [%s:%d] : Missing or invalid port in '%s'\n", file, linenum, args[2]); |
| 1330 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1331 | goto out; |
| 1332 | } |
| 1333 | |
Willy Tarreau | fab5a43 | 2011-03-04 15:31:53 +0100 | [diff] [blame] | 1334 | sk = str2ip(raddr); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1335 | free(raddr); |
| 1336 | if (!sk) { |
| 1337 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[2]); |
| 1338 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1339 | goto out; |
| 1340 | } |
| 1341 | newpeer->addr = *sk; |
Willy Tarreau | 26d8c59 | 2012-05-07 18:12:14 +0200 | [diff] [blame] | 1342 | newpeer->proto = protocol_by_family(newpeer->addr.ss_family); |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 1343 | newpeer->xprt = &raw_sock; |
Willy Tarreau | d02394b | 2012-05-11 18:32:18 +0200 | [diff] [blame] | 1344 | newpeer->sock_init_arg = NULL; |
Willy Tarreau | 26d8c59 | 2012-05-07 18:12:14 +0200 | [diff] [blame] | 1345 | |
Willy Tarreau | 173e7fb | 2012-09-24 22:47:39 +0200 | [diff] [blame] | 1346 | if (!newpeer->proto) { |
Willy Tarreau | 26d8c59 | 2012-05-07 18:12:14 +0200 | [diff] [blame] | 1347 | Alert("parsing [%s:%d] : Unknown protocol family %d '%s'\n", |
| 1348 | file, linenum, newpeer->addr.ss_family, args[2]); |
| 1349 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1350 | goto out; |
| 1351 | } |
| 1352 | |
Willy Tarreau | 86ad42c | 2011-08-27 12:29:07 +0200 | [diff] [blame] | 1353 | set_host_port(&newpeer->addr, realport); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1354 | |
| 1355 | if (strcmp(newpeer->id, localpeer) == 0) { |
| 1356 | /* Current is local peer, it define a frontend */ |
| 1357 | newpeer->local = 1; |
| 1358 | |
| 1359 | if (!curpeers->peers_fe) { |
| 1360 | if ((curpeers->peers_fe = calloc(1, sizeof(struct proxy))) == NULL) { |
| 1361 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1362 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1363 | goto out; |
| 1364 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1365 | |
Willy Tarreau | 237250c | 2011-07-29 01:49:03 +0200 | [diff] [blame] | 1366 | init_new_proxy(curpeers->peers_fe); |
| 1367 | curpeers->peers_fe->parent = curpeers; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1368 | |
| 1369 | curpeers->peers_fe->last_change = now.tv_sec; |
| 1370 | curpeers->peers_fe->id = strdup(args[1]); |
| 1371 | curpeers->peers_fe->cap = PR_CAP_FE; |
Willy Tarreau | 3ae65a1 | 2011-09-07 17:40:39 +0200 | [diff] [blame] | 1372 | curpeers->peers_fe->maxconn = 0; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1373 | curpeers->peers_fe->conn_retries = CONN_RETRIES; |
| 1374 | curpeers->peers_fe->timeout.connect = 5000; |
| 1375 | curpeers->peers_fe->accept = peer_accept; |
| 1376 | 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] | 1377 | |
| 1378 | bind_conf = bind_conf_alloc(&curpeers->peers_fe->conf.bind, file, linenum, args[2]); |
| 1379 | |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 1380 | if (!str2listener(args[2], curpeers->peers_fe, bind_conf, file, linenum, &err_msg)) { |
| 1381 | if (err_msg && *err_msg) { |
| 1382 | indent_msg(&err_msg, 2); |
| 1383 | Alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], err_msg); |
| 1384 | } |
| 1385 | else |
| 1386 | Alert("parsing [%s:%d] : '%s %s' : error encountered while parsing listening address %s.\n", |
| 1387 | file, linenum, args[0], args[1], args[2]); |
| 1388 | free(err_msg); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1389 | err_code |= ERR_FATAL; |
| 1390 | goto out; |
| 1391 | } |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1392 | |
| 1393 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
| 1394 | l->maxconn = ((struct proxy *)curpeers->peers_fe)->maxconn; |
| 1395 | l->backlog = ((struct proxy *)curpeers->peers_fe)->backlog; |
| 1396 | l->timeout = &((struct proxy *)curpeers->peers_fe)->timeout.client; |
| 1397 | l->accept = session_accept; |
| 1398 | l->handler = process_session; |
| 1399 | l->analysers |= ((struct proxy *)curpeers->peers_fe)->fe_req_ana; |
| 1400 | l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */ |
| 1401 | global.maxsock += l->maxconn; |
| 1402 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1403 | } |
| 1404 | } |
| 1405 | } /* neither "peer" nor "peers" */ |
| 1406 | else if (*args[0] != 0) { |
| 1407 | Alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection); |
| 1408 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1409 | goto out; |
| 1410 | } |
| 1411 | |
| 1412 | out: |
| 1413 | return err_code; |
| 1414 | } |
| 1415 | |
| 1416 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 1417 | 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] | 1418 | { |
| 1419 | static struct proxy *curproxy = NULL; |
| 1420 | struct server *newsrv = NULL; |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 1421 | const char *err; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 1422 | int rc; |
| 1423 | unsigned val; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1424 | int err_code = 0; |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 1425 | struct acl_cond *cond = NULL; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 1426 | struct logsrv *tmplogsrv; |
Willy Tarreau | f4068b6 | 2012-05-08 17:37:49 +0200 | [diff] [blame] | 1427 | char *errmsg = NULL; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 1428 | struct bind_conf *bind_conf; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1429 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1430 | if (!strcmp(args[0], "listen")) |
| 1431 | rc = PR_CAP_LISTEN; |
| 1432 | else if (!strcmp(args[0], "frontend")) |
| 1433 | rc = PR_CAP_FE | PR_CAP_RS; |
| 1434 | else if (!strcmp(args[0], "backend")) |
| 1435 | rc = PR_CAP_BE | PR_CAP_RS; |
| 1436 | else if (!strcmp(args[0], "ruleset")) |
| 1437 | rc = PR_CAP_RS; |
| 1438 | else |
| 1439 | rc = PR_CAP_NONE; |
| 1440 | |
| 1441 | if (rc != PR_CAP_NONE) { /* new proxy */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1442 | if (!*args[1]) { |
| 1443 | Alert("parsing [%s:%d] : '%s' expects an <id> argument and\n" |
| 1444 | " optionnally supports [addr1]:port1[-end1]{,[addr]:port[-end]}...\n", |
| 1445 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1446 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1447 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1448 | } |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 1449 | |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 1450 | err = invalid_char(args[1]); |
| 1451 | if (err) { |
| 1452 | Alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 1453 | file, linenum, *err, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1454 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 1455 | } |
| 1456 | |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 1457 | for (curproxy = proxy; curproxy != NULL; curproxy = curproxy->next) { |
| 1458 | /* |
| 1459 | * If there are two proxies with the same name only following |
| 1460 | * combinations are allowed: |
| 1461 | * |
| 1462 | * listen backend frontend ruleset |
| 1463 | * listen - - - - |
| 1464 | * backend - - OK - |
| 1465 | * frontend - OK - - |
| 1466 | * ruleset - - - - |
| 1467 | */ |
| 1468 | |
| 1469 | if (!strcmp(curproxy->id, args[1]) && |
| 1470 | (rc!=(PR_CAP_FE|PR_CAP_RS) || curproxy->cap!=(PR_CAP_BE|PR_CAP_RS)) && |
| 1471 | (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] | 1472 | Warning("Parsing [%s:%d]: %s '%s' has same name as another %s (declared at %s:%d).\n", |
| 1473 | file, linenum, proxy_cap_str(rc), args[1], proxy_type_str(curproxy), |
| 1474 | curproxy->conf.file, curproxy->conf.line); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1475 | err_code |= ERR_WARN; |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 1476 | } |
| 1477 | } |
| 1478 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1479 | if ((curproxy = (struct proxy *)calloc(1, sizeof(struct proxy))) == NULL) { |
| 1480 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1481 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1482 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1483 | } |
Willy Tarreau | 5af24ef | 2009-03-15 15:23:16 +0100 | [diff] [blame] | 1484 | |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 1485 | init_new_proxy(curproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1486 | curproxy->next = proxy; |
| 1487 | proxy = curproxy; |
Willy Tarreau | 8113a5d | 2012-10-04 08:01:43 +0200 | [diff] [blame] | 1488 | curproxy->conf.file = strdup(file); |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 1489 | curproxy->conf.line = linenum; |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 1490 | curproxy->last_change = now.tv_sec; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1491 | curproxy->id = strdup(args[1]); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1492 | curproxy->cap = rc; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1493 | |
| 1494 | /* parse the listener address if any */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1495 | if ((curproxy->cap & PR_CAP_FE) && *args[2]) { |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1496 | struct listener *l; |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 1497 | char *err_msg = NULL; |
Willy Tarreau | 81a8117 | 2012-09-18 20:52:35 +0200 | [diff] [blame] | 1498 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1499 | bind_conf = bind_conf_alloc(&curproxy->conf.bind, file, linenum, args[2]); |
| 1500 | |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 1501 | if (!str2listener(args[2], curproxy, bind_conf, file, linenum, &err_msg)) { |
| 1502 | if (err_msg && *err_msg) { |
| 1503 | indent_msg(&err_msg, 2); |
| 1504 | Alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], err_msg); |
| 1505 | } |
| 1506 | else |
| 1507 | Alert("parsing [%s:%d] : '%s %s' : error encountered while parsing listening address '%s'.\n", |
| 1508 | file, linenum, args[0], args[1], args[2]); |
| 1509 | free(err_msg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1510 | err_code |= ERR_FATAL; |
| 1511 | goto out; |
| 1512 | } |
Willy Tarreau | 81a8117 | 2012-09-18 20:52:35 +0200 | [diff] [blame] | 1513 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1514 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
Willy Tarreau | c8b1109 | 2011-02-16 11:08:57 +0100 | [diff] [blame] | 1515 | global.maxsock++; |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 1516 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1517 | } |
| 1518 | |
| 1519 | /* set default values */ |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1520 | memcpy(&curproxy->defsrv, &defproxy.defsrv, sizeof(curproxy->defsrv)); |
Willy Tarreau | 7016020 | 2010-04-07 16:06:40 +0200 | [diff] [blame] | 1521 | curproxy->defsrv.id = "default-server"; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1522 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1523 | curproxy->state = defproxy.state; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1524 | curproxy->options = defproxy.options; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 1525 | curproxy->options2 = defproxy.options2; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 1526 | curproxy->no_options = defproxy.no_options; |
| 1527 | curproxy->no_options2 = defproxy.no_options2; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 1528 | curproxy->bind_proc = defproxy.bind_proc; |
Willy Tarreau | 3168223 | 2007-11-29 15:38:04 +0100 | [diff] [blame] | 1529 | curproxy->lbprm.algo = defproxy.lbprm.algo; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 1530 | curproxy->except_net = defproxy.except_net; |
| 1531 | curproxy->except_mask = defproxy.except_mask; |
Maik Broemme | 36db02e | 2009-05-08 17:02:07 +0200 | [diff] [blame] | 1532 | curproxy->except_to = defproxy.except_to; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 1533 | curproxy->except_mask_to = defproxy.except_mask_to; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1534 | |
Willy Tarreau | 79f5fe8 | 2008-08-23 08:18:21 +0200 | [diff] [blame] | 1535 | if (defproxy.fwdfor_hdr_len) { |
| 1536 | curproxy->fwdfor_hdr_len = defproxy.fwdfor_hdr_len; |
| 1537 | curproxy->fwdfor_hdr_name = strdup(defproxy.fwdfor_hdr_name); |
| 1538 | } |
| 1539 | |
Willy Tarreau | b86db34 | 2009-11-30 11:50:16 +0100 | [diff] [blame] | 1540 | if (defproxy.orgto_hdr_len) { |
| 1541 | curproxy->orgto_hdr_len = defproxy.orgto_hdr_len; |
| 1542 | curproxy->orgto_hdr_name = strdup(defproxy.orgto_hdr_name); |
| 1543 | } |
| 1544 | |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 1545 | if (defproxy.server_id_hdr_len) { |
| 1546 | curproxy->server_id_hdr_len = defproxy.server_id_hdr_len; |
| 1547 | curproxy->server_id_hdr_name = strdup(defproxy.server_id_hdr_name); |
| 1548 | } |
| 1549 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1550 | if (curproxy->cap & PR_CAP_FE) { |
| 1551 | curproxy->maxconn = defproxy.maxconn; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 1552 | curproxy->backlog = defproxy.backlog; |
Willy Tarreau | 13a34bd | 2009-05-10 18:52:49 +0200 | [diff] [blame] | 1553 | curproxy->fe_sps_lim = defproxy.fe_sps_lim; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1554 | |
| 1555 | /* initialize error relocations */ |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1556 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) |
| 1557 | chunk_dup(&curproxy->errmsg[rc], &defproxy.errmsg[rc]); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1558 | |
| 1559 | curproxy->to_log = defproxy.to_log & ~LW_COOKIE & ~LW_REQHDR & ~ LW_RSPHDR; |
| 1560 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1561 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1562 | if (curproxy->cap & PR_CAP_BE) { |
| 1563 | curproxy->fullconn = defproxy.fullconn; |
| 1564 | curproxy->conn_retries = defproxy.conn_retries; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1565 | |
Willy Tarreau | aa2f389 | 2010-10-22 16:15:31 +0200 | [diff] [blame] | 1566 | if (defproxy.check_req) { |
| 1567 | curproxy->check_req = calloc(1, defproxy.check_len); |
| 1568 | memcpy(curproxy->check_req, defproxy.check_req, defproxy.check_len); |
| 1569 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1570 | curproxy->check_len = defproxy.check_len; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1571 | |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 1572 | if (defproxy.expect_str) { |
| 1573 | curproxy->expect_str = strdup(defproxy.expect_str); |
| 1574 | if (defproxy.expect_regex) { |
| 1575 | /* note: this regex is known to be valid */ |
| 1576 | curproxy->expect_regex = calloc(1, sizeof(regex_t)); |
| 1577 | regcomp(curproxy->expect_regex, defproxy.expect_str, REG_EXTENDED); |
| 1578 | } |
| 1579 | } |
| 1580 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 1581 | curproxy->ck_opts = defproxy.ck_opts; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1582 | if (defproxy.cookie_name) |
| 1583 | curproxy->cookie_name = strdup(defproxy.cookie_name); |
| 1584 | curproxy->cookie_len = defproxy.cookie_len; |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 1585 | if (defproxy.cookie_domain) |
| 1586 | curproxy->cookie_domain = strdup(defproxy.cookie_domain); |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 1587 | |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 1588 | if (defproxy.cookie_maxidle) |
| 1589 | curproxy->cookie_maxidle = defproxy.cookie_maxidle; |
| 1590 | |
| 1591 | if (defproxy.cookie_maxlife) |
| 1592 | curproxy->cookie_maxlife = defproxy.cookie_maxlife; |
| 1593 | |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 1594 | if (defproxy.rdp_cookie_name) |
| 1595 | curproxy->rdp_cookie_name = strdup(defproxy.rdp_cookie_name); |
| 1596 | curproxy->rdp_cookie_len = defproxy.rdp_cookie_len; |
| 1597 | |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 1598 | if (defproxy.url_param_name) |
| 1599 | curproxy->url_param_name = strdup(defproxy.url_param_name); |
| 1600 | curproxy->url_param_len = defproxy.url_param_len; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 1601 | |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 1602 | if (defproxy.hh_name) |
| 1603 | curproxy->hh_name = strdup(defproxy.hh_name); |
| 1604 | curproxy->hh_len = defproxy.hh_len; |
| 1605 | curproxy->hh_match_domain = defproxy.hh_match_domain; |
| 1606 | |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 1607 | if (defproxy.iface_name) |
| 1608 | curproxy->iface_name = strdup(defproxy.iface_name); |
| 1609 | curproxy->iface_len = defproxy.iface_len; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1610 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1611 | |
Willy Tarreau | 3b6b1a9 | 2009-07-23 13:24:23 +0200 | [diff] [blame] | 1612 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1613 | if (defproxy.capture_name) |
| 1614 | curproxy->capture_name = strdup(defproxy.capture_name); |
| 1615 | curproxy->capture_namelen = defproxy.capture_namelen; |
| 1616 | curproxy->capture_len = defproxy.capture_len; |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 1617 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1618 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1619 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 1620 | curproxy->timeout.client = defproxy.timeout.client; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 1621 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | 036fae0 | 2008-01-06 13:24:40 +0100 | [diff] [blame] | 1622 | curproxy->timeout.httpreq = defproxy.timeout.httpreq; |
Willy Tarreau | b16a574 | 2010-01-10 14:46:16 +0100 | [diff] [blame] | 1623 | curproxy->timeout.httpka = defproxy.timeout.httpka; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1624 | curproxy->uri_auth = defproxy.uri_auth; |
| 1625 | curproxy->mon_net = defproxy.mon_net; |
| 1626 | curproxy->mon_mask = defproxy.mon_mask; |
| 1627 | if (defproxy.monitor_uri) |
| 1628 | curproxy->monitor_uri = strdup(defproxy.monitor_uri); |
| 1629 | curproxy->monitor_uri_len = defproxy.monitor_uri_len; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 1630 | if (defproxy.defbe.name) |
| 1631 | curproxy->defbe.name = strdup(defproxy.defbe.name); |
Willy Tarreau | 99a7ca2 | 2012-05-31 19:39:23 +0200 | [diff] [blame] | 1632 | |
| 1633 | /* get either a pointer to the logformat string or a copy of it */ |
| 1634 | curproxy->logformat_string = defproxy.logformat_string; |
| 1635 | if (curproxy->logformat_string && |
| 1636 | curproxy->logformat_string != default_http_log_format && |
| 1637 | curproxy->logformat_string != default_tcp_log_format && |
| 1638 | curproxy->logformat_string != clf_http_log_format) |
| 1639 | curproxy->logformat_string = strdup(curproxy->logformat_string); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1640 | } |
| 1641 | |
| 1642 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 1643 | curproxy->timeout.connect = defproxy.timeout.connect; |
| 1644 | curproxy->timeout.server = defproxy.timeout.server; |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 1645 | curproxy->timeout.check = defproxy.timeout.check; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 1646 | curproxy->timeout.queue = defproxy.timeout.queue; |
Willy Tarreau | 51c9bde | 2008-01-06 13:40:03 +0100 | [diff] [blame] | 1647 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | cd7afc0 | 2009-07-12 10:03:17 +0200 | [diff] [blame] | 1648 | curproxy->timeout.httpreq = defproxy.timeout.httpreq; |
Willy Tarreau | b16a574 | 2010-01-10 14:46:16 +0100 | [diff] [blame] | 1649 | curproxy->timeout.httpka = defproxy.timeout.httpka; |
Willy Tarreau | ce887fd | 2012-05-12 12:50:00 +0200 | [diff] [blame] | 1650 | curproxy->timeout.tunnel = defproxy.timeout.tunnel; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1651 | curproxy->source_addr = defproxy.source_addr; |
| 1652 | } |
| 1653 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1654 | curproxy->mode = defproxy.mode; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1655 | |
| 1656 | /* copy default logsrvs to curproxy */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 1657 | list_for_each_entry(tmplogsrv, &defproxy.logsrvs, list) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1658 | struct logsrv *node = malloc(sizeof(struct logsrv)); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 1659 | memcpy(node, tmplogsrv, sizeof(struct logsrv)); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1660 | LIST_INIT(&node->list); |
| 1661 | LIST_ADDQ(&curproxy->logsrvs, &node->list); |
| 1662 | } |
| 1663 | |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 1664 | curproxy->uniqueid_format_string = defproxy.uniqueid_format_string; |
| 1665 | if (curproxy->uniqueid_format_string) |
| 1666 | curproxy->uniqueid_format_string = strdup(curproxy->uniqueid_format_string); |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 1667 | |
| 1668 | /* copy default header unique id */ |
| 1669 | if (defproxy.header_unique_id) |
| 1670 | curproxy->header_unique_id = strdup(defproxy.header_unique_id); |
| 1671 | |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 1672 | /* default compression options */ |
| 1673 | if (defproxy.comp != NULL) { |
| 1674 | curproxy->comp = calloc(1, sizeof(struct comp)); |
| 1675 | curproxy->comp->algos = defproxy.comp->algos; |
| 1676 | curproxy->comp->types = defproxy.comp->types; |
| 1677 | } |
| 1678 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1679 | curproxy->grace = defproxy.grace; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1680 | curproxy->conf.used_listener_id = EB_ROOT; |
| 1681 | curproxy->conf.used_server_id = EB_ROOT; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 1682 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1683 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1684 | } |
| 1685 | else if (!strcmp(args[0], "defaults")) { /* use this one to assign default values */ |
| 1686 | /* some variables may have already been initialized earlier */ |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 1687 | /* FIXME-20070101: we should do this too at the end of the |
| 1688 | * config parsing to free all default values. |
| 1689 | */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1690 | free(defproxy.check_req); |
| 1691 | free(defproxy.cookie_name); |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 1692 | free(defproxy.rdp_cookie_name); |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 1693 | free(defproxy.cookie_domain); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1694 | free(defproxy.url_param_name); |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 1695 | free(defproxy.hh_name); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1696 | free(defproxy.capture_name); |
| 1697 | free(defproxy.monitor_uri); |
| 1698 | free(defproxy.defbe.name); |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 1699 | free(defproxy.iface_name); |
Willy Tarreau | 79f5fe8 | 2008-08-23 08:18:21 +0200 | [diff] [blame] | 1700 | free(defproxy.fwdfor_hdr_name); |
| 1701 | defproxy.fwdfor_hdr_len = 0; |
Willy Tarreau | b86db34 | 2009-11-30 11:50:16 +0100 | [diff] [blame] | 1702 | free(defproxy.orgto_hdr_name); |
| 1703 | defproxy.orgto_hdr_len = 0; |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 1704 | free(defproxy.server_id_hdr_name); |
| 1705 | defproxy.server_id_hdr_len = 0; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 1706 | free(defproxy.expect_str); |
| 1707 | if (defproxy.expect_regex) regfree(defproxy.expect_regex); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 1708 | |
Willy Tarreau | 39b0665 | 2012-06-01 10:58:06 +0200 | [diff] [blame] | 1709 | if (defproxy.logformat_string != default_http_log_format && |
| 1710 | defproxy.logformat_string != default_tcp_log_format && |
| 1711 | defproxy.logformat_string != clf_http_log_format) |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 1712 | free(defproxy.logformat_string); |
| 1713 | |
| 1714 | free(defproxy.uniqueid_format_string); |
| 1715 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1716 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1717 | chunk_destroy(&defproxy.errmsg[rc]); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 1718 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1719 | /* we cannot free uri_auth because it might already be used */ |
| 1720 | init_default_instance(); |
| 1721 | curproxy = &defproxy; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1722 | defproxy.cap = PR_CAP_LISTEN; /* all caps for now */ |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1723 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1724 | } |
| 1725 | else if (curproxy == NULL) { |
| 1726 | Alert("parsing [%s:%d] : 'listen' or 'defaults' expected.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1727 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1728 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1729 | } |
| 1730 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1731 | |
| 1732 | /* Now let's parse the proxy-specific keywords */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1733 | if (!strcmp(args[0], "bind")) { /* new listen addresses */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1734 | struct listener *l; |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1735 | int cur_arg; |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 1736 | char *err_msg = NULL; |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1737 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1738 | if (curproxy == &defproxy) { |
| 1739 | 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] | 1740 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1741 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1742 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1743 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1744 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1745 | |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 1746 | if ( *(args[1]) != '/' && strchr(args[1], ':') == NULL) { |
Willy Tarreau | d55c3fe | 2010-11-09 09:50:37 +0100 | [diff] [blame] | 1747 | 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] | 1748 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1749 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1750 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1751 | } |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 1752 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 1753 | bind_conf = bind_conf_alloc(&curproxy->conf.bind, file, linenum, args[1]); |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1754 | 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] | 1755 | |
| 1756 | /* NOTE: the following line might create several listeners if there |
| 1757 | * are comma-separated IPs or port ranges. So all further processing |
| 1758 | * will have to be applied to all listeners created after last_listen. |
| 1759 | */ |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 1760 | if (!str2listener(args[1], curproxy, bind_conf, file, linenum, &err_msg)) { |
| 1761 | if (err_msg && *err_msg) { |
| 1762 | indent_msg(&err_msg, 2); |
| 1763 | Alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], err_msg); |
| 1764 | } |
| 1765 | else |
| 1766 | Alert("parsing [%s:%d] : '%s' : error encountered while parsing listening address '%s'.\n", |
| 1767 | file, linenum, args[0], args[1]); |
| 1768 | free(err_msg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1769 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1770 | goto out; |
| 1771 | } |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1772 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1773 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
| 1774 | /* Set default global rights and owner for unix bind */ |
Willy Tarreau | c8b1109 | 2011-02-16 11:08:57 +0100 | [diff] [blame] | 1775 | global.maxsock++; |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 1776 | } |
| 1777 | |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1778 | cur_arg = 2; |
| 1779 | while (*(args[cur_arg])) { |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 1780 | static int bind_dumped; |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 1781 | struct bind_kw *kw; |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 1782 | char *err; |
| 1783 | |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 1784 | kw = bind_find_kw(args[cur_arg]); |
| 1785 | if (kw) { |
| 1786 | char *err = NULL; |
| 1787 | int code; |
| 1788 | |
| 1789 | if (!kw->parse) { |
Willy Tarreau | dda322d | 2012-09-18 16:34:09 +0200 | [diff] [blame] | 1790 | Alert("parsing [%s:%d] : '%s %s' : '%s' option is not implemented in this version (check build options).\n", |
| 1791 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 1792 | cur_arg += 1 + kw->skip ; |
| 1793 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1794 | goto out; |
| 1795 | } |
| 1796 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1797 | code = kw->parse(args, cur_arg, curproxy, bind_conf, &err); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 1798 | err_code |= code; |
| 1799 | |
| 1800 | if (code) { |
| 1801 | if (err && *err) { |
| 1802 | indent_msg(&err, 2); |
Willy Tarreau | dda322d | 2012-09-18 16:34:09 +0200 | [diff] [blame] | 1803 | 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] | 1804 | } |
| 1805 | else |
Willy Tarreau | dda322d | 2012-09-18 16:34:09 +0200 | [diff] [blame] | 1806 | Alert("parsing [%s:%d] : '%s %s' : error encountered while processing '%s'.\n", |
| 1807 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 1808 | if (code & ERR_FATAL) { |
| 1809 | free(err); |
| 1810 | cur_arg += 1 + kw->skip; |
| 1811 | goto out; |
| 1812 | } |
| 1813 | } |
| 1814 | free(err); |
| 1815 | cur_arg += 1 + kw->skip; |
| 1816 | continue; |
| 1817 | } |
| 1818 | |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 1819 | err = NULL; |
| 1820 | if (!bind_dumped) { |
| 1821 | bind_dump_kws(&err); |
| 1822 | indent_msg(&err, 4); |
| 1823 | bind_dumped = 1; |
| 1824 | } |
| 1825 | |
| 1826 | Alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'.%s%s\n", |
| 1827 | file, linenum, args[0], args[1], args[cur_arg], |
| 1828 | err ? " Registered keywords :" : "", err ? err : ""); |
| 1829 | free(err); |
| 1830 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1831 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1832 | goto out; |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 1833 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1834 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1835 | } |
| 1836 | else if (!strcmp(args[0], "monitor-net")) { /* set the range of IPs to ignore */ |
| 1837 | if (!*args[1] || !str2net(args[1], &curproxy->mon_net, &curproxy->mon_mask)) { |
| 1838 | Alert("parsing [%s:%d] : '%s' expects address[/mask].\n", |
| 1839 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1840 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1841 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1842 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1843 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1844 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1845 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1846 | /* flush useless bits */ |
| 1847 | curproxy->mon_net.s_addr &= curproxy->mon_mask.s_addr; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1848 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1849 | } |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 1850 | else if (!strcmp(args[0], "monitor-uri")) { /* set the URI to intercept */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1851 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1852 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1853 | |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 1854 | if (!*args[1]) { |
| 1855 | Alert("parsing [%s:%d] : '%s' expects an URI.\n", |
| 1856 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1857 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1858 | goto out; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 1859 | } |
| 1860 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1861 | free(curproxy->monitor_uri); |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 1862 | curproxy->monitor_uri_len = strlen(args[1]); |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 1863 | curproxy->monitor_uri = (char *)calloc(1, curproxy->monitor_uri_len + 1); |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 1864 | memcpy(curproxy->monitor_uri, args[1], curproxy->monitor_uri_len); |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 1865 | curproxy->monitor_uri[curproxy->monitor_uri_len] = '\0'; |
| 1866 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1867 | goto out; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 1868 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1869 | else if (!strcmp(args[0], "mode")) { /* sets the proxy mode */ |
| 1870 | if (!strcmp(args[1], "http")) curproxy->mode = PR_MODE_HTTP; |
| 1871 | else if (!strcmp(args[1], "tcp")) curproxy->mode = PR_MODE_TCP; |
| 1872 | else if (!strcmp(args[1], "health")) curproxy->mode = PR_MODE_HEALTH; |
| 1873 | else { |
| 1874 | 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] | 1875 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1876 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1877 | } |
| 1878 | } |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 1879 | else if (!strcmp(args[0], "id")) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1880 | struct eb32_node *node; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 1881 | |
| 1882 | if (curproxy == &defproxy) { |
| 1883 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", |
| 1884 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1885 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1886 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 1887 | } |
| 1888 | |
| 1889 | if (!*args[1]) { |
| 1890 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 1891 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1892 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1893 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 1894 | } |
| 1895 | |
| 1896 | curproxy->uuid = atol(args[1]); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1897 | curproxy->conf.id.key = curproxy->uuid; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 1898 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1899 | if (curproxy->uuid <= 0) { |
| 1900 | Alert("parsing [%s:%d]: custom id has to be > 0.\n", |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 1901 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1902 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1903 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 1904 | } |
| 1905 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1906 | node = eb32_lookup(&used_proxy_id, curproxy->uuid); |
| 1907 | if (node) { |
| 1908 | struct proxy *target = container_of(node, struct proxy, conf.id); |
| 1909 | Alert("parsing [%s:%d]: %s %s reuses same custom id as %s %s (declared at %s:%d).\n", |
| 1910 | file, linenum, proxy_type_str(curproxy), curproxy->id, |
| 1911 | proxy_type_str(target), target->id, target->conf.file, target->conf.line); |
| 1912 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1913 | goto out; |
| 1914 | } |
| 1915 | eb32_insert(&used_proxy_id, &curproxy->conf.id); |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 1916 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1917 | else if (!strcmp(args[0], "description")) { |
| 1918 | int i, len=0; |
| 1919 | char *d; |
| 1920 | |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 1921 | if (curproxy == &defproxy) { |
| 1922 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", |
| 1923 | file, linenum, args[0]); |
| 1924 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1925 | goto out; |
| 1926 | } |
| 1927 | |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1928 | if (!*args[1]) { |
| 1929 | Alert("parsing [%s:%d]: '%s' expects a string argument.\n", |
| 1930 | file, linenum, args[0]); |
| 1931 | return -1; |
| 1932 | } |
| 1933 | |
| 1934 | for(i=1; *args[i]; i++) |
| 1935 | len += strlen(args[i])+1; |
| 1936 | |
| 1937 | d = (char *)calloc(1, len); |
| 1938 | curproxy->desc = d; |
| 1939 | |
| 1940 | d += sprintf(d, "%s", args[1]); |
| 1941 | for(i=2; *args[i]; i++) |
| 1942 | d += sprintf(d, " %s", args[i]); |
| 1943 | |
| 1944 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1945 | else if (!strcmp(args[0], "disabled")) { /* disables this proxy */ |
| 1946 | curproxy->state = PR_STSTOPPED; |
| 1947 | } |
| 1948 | else if (!strcmp(args[0], "enabled")) { /* enables this proxy (used to revert a disabled default) */ |
| 1949 | curproxy->state = PR_STNEW; |
| 1950 | } |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 1951 | else if (!strcmp(args[0], "bind-process")) { /* enable this proxy only on some processes */ |
| 1952 | int cur_arg = 1; |
| 1953 | unsigned int set = 0; |
| 1954 | |
| 1955 | while (*args[cur_arg]) { |
| 1956 | int u; |
| 1957 | if (strcmp(args[cur_arg], "all") == 0) { |
| 1958 | set = 0; |
| 1959 | break; |
| 1960 | } |
| 1961 | else if (strcmp(args[cur_arg], "odd") == 0) { |
| 1962 | set |= 0x55555555; |
| 1963 | } |
| 1964 | else if (strcmp(args[cur_arg], "even") == 0) { |
| 1965 | set |= 0xAAAAAAAA; |
| 1966 | } |
| 1967 | else { |
| 1968 | u = str2uic(args[cur_arg]); |
| 1969 | if (u < 1 || u > 32) { |
| 1970 | Alert("parsing [%s:%d]: %s expects 'all', 'odd', 'even', or process numbers from 1 to 32.\n", |
| 1971 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1972 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1973 | goto out; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 1974 | } |
| 1975 | if (u > global.nbproc) { |
| 1976 | Warning("parsing [%s:%d]: %s references process number higher than global.nbproc.\n", |
| 1977 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1978 | err_code |= ERR_WARN; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 1979 | } |
| 1980 | set |= 1 << (u - 1); |
| 1981 | } |
| 1982 | cur_arg++; |
| 1983 | } |
| 1984 | curproxy->bind_proc = set; |
| 1985 | } |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 1986 | else if (!strcmp(args[0], "acl")) { /* add an ACL */ |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 1987 | if (curproxy == &defproxy) { |
| 1988 | 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] | 1989 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1990 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 1991 | } |
| 1992 | |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 1993 | err = invalid_char(args[1]); |
| 1994 | if (err) { |
| 1995 | Alert("parsing [%s:%d] : character '%c' is not permitted in acl name '%s'.\n", |
| 1996 | file, linenum, *err, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1997 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 1998 | } |
| 1999 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 2000 | if (parse_acl((const char **)args + 1, &curproxy->acl, &errmsg) == NULL) { |
| 2001 | Alert("parsing [%s:%d] : error detected while parsing ACL '%s' : %s.\n", |
| 2002 | file, linenum, args[1], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2003 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2004 | goto out; |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 2005 | } |
| 2006 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2007 | else if (!strcmp(args[0], "cookie")) { /* cookie name */ |
| 2008 | int cur_arg; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2009 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2010 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2011 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2012 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2013 | if (*(args[1]) == 0) { |
| 2014 | Alert("parsing [%s:%d] : '%s' expects <cookie_name> as argument.\n", |
| 2015 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2016 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2017 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2018 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2019 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2020 | curproxy->ck_opts = 0; |
Willy Tarreau | c63d4bb | 2010-10-23 11:37:27 +0200 | [diff] [blame] | 2021 | curproxy->cookie_maxidle = curproxy->cookie_maxlife = 0; |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 2022 | free(curproxy->cookie_domain); curproxy->cookie_domain = NULL; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2023 | free(curproxy->cookie_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2024 | curproxy->cookie_name = strdup(args[1]); |
| 2025 | curproxy->cookie_len = strlen(curproxy->cookie_name); |
Willy Tarreau | c63d4bb | 2010-10-23 11:37:27 +0200 | [diff] [blame] | 2026 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2027 | cur_arg = 2; |
| 2028 | while (*(args[cur_arg])) { |
| 2029 | if (!strcmp(args[cur_arg], "rewrite")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2030 | curproxy->ck_opts |= PR_CK_RW; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2031 | } |
| 2032 | else if (!strcmp(args[cur_arg], "indirect")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2033 | curproxy->ck_opts |= PR_CK_IND; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2034 | } |
| 2035 | else if (!strcmp(args[cur_arg], "insert")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2036 | curproxy->ck_opts |= PR_CK_INS; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2037 | } |
| 2038 | else if (!strcmp(args[cur_arg], "nocache")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2039 | curproxy->ck_opts |= PR_CK_NOC; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2040 | } |
| 2041 | else if (!strcmp(args[cur_arg], "postonly")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2042 | curproxy->ck_opts |= PR_CK_POST; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2043 | } |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 2044 | else if (!strcmp(args[cur_arg], "preserve")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2045 | curproxy->ck_opts |= PR_CK_PSV; |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 2046 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2047 | else if (!strcmp(args[cur_arg], "prefix")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2048 | curproxy->ck_opts |= PR_CK_PFX; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2049 | } |
Willy Tarreau | 4992dd2 | 2012-05-31 21:02:17 +0200 | [diff] [blame] | 2050 | else if (!strcmp(args[cur_arg], "httponly")) { |
| 2051 | curproxy->ck_opts |= PR_CK_HTTPONLY; |
| 2052 | } |
| 2053 | else if (!strcmp(args[cur_arg], "secure")) { |
| 2054 | curproxy->ck_opts |= PR_CK_SECURE; |
| 2055 | } |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2056 | else if (!strcmp(args[cur_arg], "domain")) { |
| 2057 | if (!*args[cur_arg + 1]) { |
| 2058 | Alert("parsing [%s:%d]: '%s' expects <domain> as argument.\n", |
| 2059 | file, linenum, args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2060 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2061 | goto out; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2062 | } |
| 2063 | |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 2064 | if (*args[cur_arg + 1] != '.' || !strchr(args[cur_arg + 1] + 1, '.')) { |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2065 | /* rfc2109, 4.3.2 Rejecting Cookies */ |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 2066 | Warning("parsing [%s:%d]: domain '%s' contains no embedded" |
| 2067 | " dots nor does not start with a dot." |
| 2068 | " RFC forbids it, this configuration may not work properly.\n", |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2069 | file, linenum, args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 2070 | err_code |= ERR_WARN; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2071 | } |
| 2072 | |
| 2073 | err = invalid_domainchar(args[cur_arg + 1]); |
| 2074 | if (err) { |
| 2075 | Alert("parsing [%s:%d]: character '%c' is not permitted in domain name '%s'.\n", |
| 2076 | file, linenum, *err, args[cur_arg + 1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2077 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2078 | goto out; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2079 | } |
| 2080 | |
Willy Tarreau | 68a897b | 2009-12-03 23:28:34 +0100 | [diff] [blame] | 2081 | if (!curproxy->cookie_domain) { |
| 2082 | curproxy->cookie_domain = strdup(args[cur_arg + 1]); |
| 2083 | } else { |
| 2084 | /* one domain was already specified, add another one by |
| 2085 | * building the string which will be returned along with |
| 2086 | * the cookie. |
| 2087 | */ |
| 2088 | char *new_ptr; |
| 2089 | int new_len = strlen(curproxy->cookie_domain) + |
| 2090 | strlen("; domain=") + strlen(args[cur_arg + 1]) + 1; |
| 2091 | new_ptr = malloc(new_len); |
| 2092 | snprintf(new_ptr, new_len, "%s; domain=%s", curproxy->cookie_domain, args[cur_arg+1]); |
| 2093 | free(curproxy->cookie_domain); |
| 2094 | curproxy->cookie_domain = new_ptr; |
| 2095 | } |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 2096 | cur_arg++; |
| 2097 | } |
| 2098 | else if (!strcmp(args[cur_arg], "maxidle")) { |
| 2099 | unsigned int maxidle; |
| 2100 | const char *res; |
| 2101 | |
| 2102 | if (!*args[cur_arg + 1]) { |
| 2103 | Alert("parsing [%s:%d]: '%s' expects <idletime> in seconds as argument.\n", |
| 2104 | file, linenum, args[cur_arg]); |
| 2105 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2106 | goto out; |
| 2107 | } |
| 2108 | |
| 2109 | res = parse_time_err(args[cur_arg + 1], &maxidle, TIME_UNIT_S); |
| 2110 | if (res) { |
| 2111 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 2112 | file, linenum, *res, args[cur_arg]); |
| 2113 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2114 | goto out; |
| 2115 | } |
| 2116 | curproxy->cookie_maxidle = maxidle; |
| 2117 | cur_arg++; |
| 2118 | } |
| 2119 | else if (!strcmp(args[cur_arg], "maxlife")) { |
| 2120 | unsigned int maxlife; |
| 2121 | const char *res; |
| 2122 | |
| 2123 | if (!*args[cur_arg + 1]) { |
| 2124 | Alert("parsing [%s:%d]: '%s' expects <lifetime> in seconds as argument.\n", |
| 2125 | file, linenum, args[cur_arg]); |
| 2126 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2127 | goto out; |
| 2128 | } |
| 2129 | |
| 2130 | res = parse_time_err(args[cur_arg + 1], &maxlife, TIME_UNIT_S); |
| 2131 | if (res) { |
| 2132 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 2133 | file, linenum, *res, args[cur_arg]); |
| 2134 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2135 | goto out; |
| 2136 | } |
| 2137 | curproxy->cookie_maxlife = maxlife; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2138 | cur_arg++; |
| 2139 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2140 | else { |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 2141 | 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] | 2142 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2143 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2144 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2145 | } |
| 2146 | cur_arg++; |
| 2147 | } |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2148 | if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_IND))) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2149 | Alert("parsing [%s:%d] : cookie 'rewrite' and 'indirect' modes are incompatible.\n", |
| 2150 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2151 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2152 | } |
| 2153 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2154 | 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] | 2155 | Alert("parsing [%s:%d] : cookie 'rewrite', 'insert' and 'prefix' modes are incompatible.\n", |
| 2156 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2157 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2158 | } |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 2159 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2160 | 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] | 2161 | Alert("parsing [%s:%d] : cookie 'preserve' requires at least 'insert' or 'indirect'.\n", |
| 2162 | file, linenum); |
| 2163 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2164 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2165 | }/* end else if (!strcmp(args[0], "cookie")) */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2166 | else if (!strcmp(args[0], "persist")) { /* persist */ |
| 2167 | if (*(args[1]) == 0) { |
| 2168 | Alert("parsing [%s:%d] : missing persist method.\n", |
| 2169 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2170 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2171 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2172 | } |
| 2173 | |
| 2174 | if (!strncmp(args[1], "rdp-cookie", 10)) { |
| 2175 | curproxy->options2 |= PR_O2_RDPC_PRST; |
| 2176 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2177 | if (*(args[1] + 10) == '(') { /* cookie name */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2178 | const char *beg, *end; |
| 2179 | |
| 2180 | beg = args[1] + 11; |
| 2181 | end = strchr(beg, ')'); |
| 2182 | |
| 2183 | if (!end || end == beg) { |
| 2184 | Alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n", |
| 2185 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2186 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2187 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2188 | } |
| 2189 | |
| 2190 | free(curproxy->rdp_cookie_name); |
| 2191 | curproxy->rdp_cookie_name = my_strndup(beg, end - beg); |
| 2192 | curproxy->rdp_cookie_len = end-beg; |
| 2193 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2194 | else if (*(args[1] + 10) == '\0') { /* default cookie name 'msts' */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2195 | free(curproxy->rdp_cookie_name); |
| 2196 | curproxy->rdp_cookie_name = strdup("msts"); |
| 2197 | curproxy->rdp_cookie_len = strlen(curproxy->rdp_cookie_name); |
| 2198 | } |
| 2199 | else { /* syntax */ |
| 2200 | Alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n", |
| 2201 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2202 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2203 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2204 | } |
| 2205 | } |
| 2206 | else { |
| 2207 | Alert("parsing [%s:%d] : unknown persist method.\n", |
| 2208 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2209 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2210 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2211 | } |
| 2212 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2213 | else if (!strcmp(args[0], "appsession")) { /* cookie name */ |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2214 | int cur_arg; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2215 | |
Cyril Bonté | 3b7a369 | 2010-01-10 17:01:47 +0100 | [diff] [blame] | 2216 | if (curproxy == &defproxy) { |
| 2217 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2218 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2219 | goto out; |
| 2220 | } |
| 2221 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2222 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2223 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2224 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2225 | if (*(args[5]) == 0) { |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2226 | 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] | 2227 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2228 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2229 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2230 | } |
| 2231 | have_appsession = 1; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2232 | free(curproxy->appsession_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2233 | curproxy->appsession_name = strdup(args[1]); |
| 2234 | curproxy->appsession_name_len = strlen(curproxy->appsession_name); |
| 2235 | curproxy->appsession_len = atoi(args[3]); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 2236 | err = parse_time_err(args[5], &val, TIME_UNIT_MS); |
| 2237 | if (err) { |
| 2238 | Alert("parsing [%s:%d] : unexpected character '%c' in %s timeout.\n", |
| 2239 | file, linenum, *err, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2240 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2241 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 2242 | } |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 2243 | curproxy->timeout.appsession = val; |
Willy Tarreau | ee99136 | 2007-05-14 14:37:50 +0200 | [diff] [blame] | 2244 | |
Willy Tarreau | 51041c7 | 2007-09-09 21:56:53 +0200 | [diff] [blame] | 2245 | if (appsession_hash_init(&(curproxy->htbl_proxy), destroy) == 0) { |
| 2246 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2247 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2248 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2249 | } |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2250 | |
| 2251 | cur_arg = 6; |
| 2252 | curproxy->options2 &= ~PR_O2_AS_REQL; |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2253 | curproxy->options2 &= ~PR_O2_AS_M_ANY; |
| 2254 | curproxy->options2 |= PR_O2_AS_M_PP; |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2255 | while (*(args[cur_arg])) { |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2256 | if (!strcmp(args[cur_arg], "request-learn")) { |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2257 | curproxy->options2 |= PR_O2_AS_REQL; |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2258 | } else if (!strcmp(args[cur_arg], "prefix")) { |
| 2259 | curproxy->options2 |= PR_O2_AS_PFX; |
| 2260 | } else if (!strcmp(args[cur_arg], "mode")) { |
| 2261 | if (!*args[cur_arg + 1]) { |
| 2262 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 2263 | file, linenum, args[0], args[cur_arg]); |
| 2264 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2265 | goto out; |
| 2266 | } |
| 2267 | |
| 2268 | cur_arg++; |
| 2269 | if (!strcmp(args[cur_arg], "query-string")) { |
| 2270 | curproxy->options2 &= ~PR_O2_AS_M_ANY; |
| 2271 | curproxy->options2 |= PR_O2_AS_M_QS; |
| 2272 | } else if (!strcmp(args[cur_arg], "path-parameters")) { |
| 2273 | curproxy->options2 &= ~PR_O2_AS_M_ANY; |
| 2274 | curproxy->options2 |= PR_O2_AS_M_PP; |
| 2275 | } else { |
| 2276 | Alert("parsing [%s:%d] : unknown mode '%s'\n", file, linenum, args[cur_arg]); |
| 2277 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2278 | goto out; |
| 2279 | } |
| 2280 | } |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2281 | cur_arg++; |
| 2282 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2283 | } /* Url App Session */ |
| 2284 | else if (!strcmp(args[0], "capture")) { |
Willy Tarreau | 3b6b1a9 | 2009-07-23 13:24:23 +0200 | [diff] [blame] | 2285 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2286 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2287 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2288 | if (!strcmp(args[1], "cookie")) { /* name of a cookie to capture */ |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 2289 | if (curproxy == &defproxy) { |
| 2290 | Alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
| 2291 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2292 | goto out; |
| 2293 | } |
| 2294 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2295 | if (*(args[4]) == 0) { |
| 2296 | Alert("parsing [%s:%d] : '%s' expects 'cookie' <cookie_name> 'len' <len>.\n", |
| 2297 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2298 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2299 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2300 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2301 | free(curproxy->capture_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2302 | curproxy->capture_name = strdup(args[2]); |
| 2303 | curproxy->capture_namelen = strlen(curproxy->capture_name); |
| 2304 | curproxy->capture_len = atol(args[4]); |
| 2305 | if (curproxy->capture_len >= CAPTURE_LEN) { |
| 2306 | Warning("parsing [%s:%d] : truncating capture length to %d bytes.\n", |
| 2307 | file, linenum, CAPTURE_LEN - 1); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2308 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2309 | curproxy->capture_len = CAPTURE_LEN - 1; |
| 2310 | } |
| 2311 | curproxy->to_log |= LW_COOKIE; |
| 2312 | } |
| 2313 | else if (!strcmp(args[1], "request") && !strcmp(args[2], "header")) { |
| 2314 | struct cap_hdr *hdr; |
| 2315 | |
| 2316 | if (curproxy == &defproxy) { |
| 2317 | 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] | 2318 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2319 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2320 | } |
| 2321 | |
| 2322 | if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) { |
| 2323 | Alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n", |
| 2324 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2325 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2326 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2327 | } |
| 2328 | |
| 2329 | hdr = calloc(sizeof(struct cap_hdr), 1); |
| 2330 | hdr->next = curproxy->req_cap; |
| 2331 | hdr->name = strdup(args[3]); |
| 2332 | hdr->namelen = strlen(args[3]); |
| 2333 | hdr->len = atol(args[5]); |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 2334 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2335 | hdr->index = curproxy->nb_req_cap++; |
| 2336 | curproxy->req_cap = hdr; |
| 2337 | curproxy->to_log |= LW_REQHDR; |
| 2338 | } |
| 2339 | else if (!strcmp(args[1], "response") && !strcmp(args[2], "header")) { |
| 2340 | struct cap_hdr *hdr; |
| 2341 | |
| 2342 | if (curproxy == &defproxy) { |
| 2343 | 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] | 2344 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2345 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2346 | } |
| 2347 | |
| 2348 | if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) { |
| 2349 | Alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n", |
| 2350 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2351 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2352 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2353 | } |
| 2354 | hdr = calloc(sizeof(struct cap_hdr), 1); |
| 2355 | hdr->next = curproxy->rsp_cap; |
| 2356 | hdr->name = strdup(args[3]); |
| 2357 | hdr->namelen = strlen(args[3]); |
| 2358 | hdr->len = atol(args[5]); |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 2359 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2360 | hdr->index = curproxy->nb_rsp_cap++; |
| 2361 | curproxy->rsp_cap = hdr; |
| 2362 | curproxy->to_log |= LW_RSPHDR; |
| 2363 | } |
| 2364 | else { |
| 2365 | Alert("parsing [%s:%d] : '%s' expects 'cookie' or 'request header' or 'response header'.\n", |
| 2366 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2367 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2368 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2369 | } |
| 2370 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2371 | else if (!strcmp(args[0], "retries")) { /* connection retries */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2372 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2373 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2374 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2375 | if (*(args[1]) == 0) { |
| 2376 | Alert("parsing [%s:%d] : '%s' expects an integer argument (dispatch counts for one).\n", |
| 2377 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2378 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2379 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2380 | } |
| 2381 | curproxy->conn_retries = atol(args[1]); |
| 2382 | } |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2383 | 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] | 2384 | struct http_req_rule *rule; |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2385 | |
| 2386 | if (curproxy == &defproxy) { |
| 2387 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2388 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2389 | goto out; |
| 2390 | } |
| 2391 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 2392 | 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] | 2393 | Warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n", |
| 2394 | file, linenum, args[0]); |
| 2395 | err_code |= ERR_WARN; |
| 2396 | } |
| 2397 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 2398 | 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] | 2399 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 2400 | if (!rule) { |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2401 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2402 | goto out; |
| 2403 | } |
| 2404 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 2405 | err_code |= warnif_cond_requires_resp(rule->cond, file, linenum); |
| 2406 | LIST_ADDQ(&curproxy->http_req_rules, &rule->list); |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2407 | } |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 2408 | else if (!strcmp(args[0], "http-send-name-header")) { /* send server name in request header */ |
| 2409 | /* set the header name and length into the proxy structure */ |
| 2410 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 2411 | err_code |= ERR_WARN; |
| 2412 | |
| 2413 | if (!*args[1]) { |
| 2414 | Alert("parsing [%s:%d] : '%s' requires a header string.\n", |
| 2415 | file, linenum, args[0]); |
| 2416 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2417 | goto out; |
| 2418 | } |
| 2419 | |
| 2420 | /* set the desired header name */ |
| 2421 | free(curproxy->server_id_hdr_name); |
| 2422 | curproxy->server_id_hdr_name = strdup(args[1]); |
| 2423 | curproxy->server_id_hdr_len = strlen(curproxy->server_id_hdr_name); |
| 2424 | } |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2425 | else if (!strcmp(args[0], "block")) { /* early blocking based on ACLs */ |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2426 | if (curproxy == &defproxy) { |
| 2427 | 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] | 2428 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2429 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2430 | } |
| 2431 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2432 | if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) { |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2433 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 2434 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2435 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2436 | goto out; |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2437 | } |
| 2438 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 2439 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 1, &errmsg)) == NULL) { |
| 2440 | Alert("parsing [%s:%d] : error detected while parsing blocking condition : %s.\n", |
| 2441 | file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2442 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2443 | goto out; |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2444 | } |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2445 | |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2446 | LIST_ADDQ(&curproxy->block_cond, &cond->list); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 2447 | warnif_misplaced_block(curproxy, file, linenum, args[0]); |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2448 | } |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2449 | else if (!strcmp(args[0], "redirect")) { |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2450 | struct redirect_rule *rule; |
| 2451 | int cur_arg; |
| 2452 | int type = REDIRECT_TYPE_NONE; |
| 2453 | int code = 302; |
| 2454 | char *destination = NULL; |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2455 | char *cookie = NULL; |
| 2456 | int cookie_set = 0; |
Willy Tarreau | 79da469 | 2008-11-19 20:03:04 +0100 | [diff] [blame] | 2457 | unsigned int flags = REDIRECT_FLAG_NONE; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2458 | |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 2459 | if (curproxy == &defproxy) { |
| 2460 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2461 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2462 | goto out; |
| 2463 | } |
| 2464 | |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2465 | cur_arg = 1; |
| 2466 | while (*(args[cur_arg])) { |
| 2467 | if (!strcmp(args[cur_arg], "location")) { |
| 2468 | if (!*args[cur_arg + 1]) { |
| 2469 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 2470 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2471 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2472 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2473 | } |
| 2474 | |
| 2475 | type = REDIRECT_TYPE_LOCATION; |
| 2476 | cur_arg++; |
| 2477 | destination = args[cur_arg]; |
| 2478 | } |
| 2479 | else if (!strcmp(args[cur_arg], "prefix")) { |
| 2480 | if (!*args[cur_arg + 1]) { |
| 2481 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 2482 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2483 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2484 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2485 | } |
| 2486 | |
| 2487 | type = REDIRECT_TYPE_PREFIX; |
| 2488 | cur_arg++; |
| 2489 | destination = args[cur_arg]; |
| 2490 | } |
Willy Tarreau | 2e1dca8 | 2012-09-12 08:43:15 +0200 | [diff] [blame] | 2491 | else if (!strcmp(args[cur_arg], "scheme")) { |
| 2492 | if (!*args[cur_arg + 1]) { |
| 2493 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 2494 | file, linenum, args[0], args[cur_arg]); |
| 2495 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2496 | goto out; |
| 2497 | } |
| 2498 | |
| 2499 | type = REDIRECT_TYPE_SCHEME; |
| 2500 | cur_arg++; |
| 2501 | destination = args[cur_arg]; |
| 2502 | } |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2503 | else if (!strcmp(args[cur_arg], "set-cookie")) { |
| 2504 | if (!*args[cur_arg + 1]) { |
| 2505 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 2506 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2507 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2508 | goto out; |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2509 | } |
| 2510 | |
| 2511 | cur_arg++; |
| 2512 | cookie = args[cur_arg]; |
| 2513 | cookie_set = 1; |
| 2514 | } |
| 2515 | else if (!strcmp(args[cur_arg], "clear-cookie")) { |
| 2516 | if (!*args[cur_arg + 1]) { |
| 2517 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 2518 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2519 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2520 | goto out; |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2521 | } |
| 2522 | |
| 2523 | cur_arg++; |
| 2524 | cookie = args[cur_arg]; |
| 2525 | cookie_set = 0; |
| 2526 | } |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2527 | else if (!strcmp(args[cur_arg],"code")) { |
| 2528 | if (!*args[cur_arg + 1]) { |
| 2529 | Alert("parsing [%s:%d] : '%s': missing HTTP code.\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 | cur_arg++; |
| 2535 | code = atol(args[cur_arg]); |
| 2536 | if (code < 301 || code > 303) { |
| 2537 | Alert("parsing [%s:%d] : '%s': unsupported HTTP code '%d'.\n", |
| 2538 | file, linenum, args[0], code); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2539 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2540 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2541 | } |
| 2542 | } |
Willy Tarreau | 79da469 | 2008-11-19 20:03:04 +0100 | [diff] [blame] | 2543 | else if (!strcmp(args[cur_arg],"drop-query")) { |
| 2544 | flags |= REDIRECT_FLAG_DROP_QS; |
| 2545 | } |
Willy Tarreau | 81e3b4f | 2010-01-10 00:42:19 +0100 | [diff] [blame] | 2546 | else if (!strcmp(args[cur_arg],"append-slash")) { |
| 2547 | flags |= REDIRECT_FLAG_APPEND_SLASH; |
| 2548 | } |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2549 | else if (strcmp(args[cur_arg], "if") == 0 || |
| 2550 | strcmp(args[cur_arg], "unless") == 0) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 2551 | 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] | 2552 | if (!cond) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 2553 | Alert("parsing [%s:%d] : '%s': error detected while parsing redirect condition : %s.\n", |
| 2554 | file, linenum, args[0], errmsg); |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2555 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2556 | goto out; |
| 2557 | } |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2558 | break; |
| 2559 | } |
| 2560 | else { |
Willy Tarreau | 2e1dca8 | 2012-09-12 08:43:15 +0200 | [diff] [blame] | 2561 | 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] | 2562 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2563 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2564 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2565 | } |
| 2566 | cur_arg++; |
| 2567 | } |
| 2568 | |
| 2569 | if (type == REDIRECT_TYPE_NONE) { |
| 2570 | Alert("parsing [%s:%d] : '%s' expects a redirection type ('prefix' or 'location').\n", |
| 2571 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2572 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2573 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2574 | } |
| 2575 | |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2576 | rule = (struct redirect_rule *)calloc(1, sizeof(*rule)); |
| 2577 | rule->cond = cond; |
| 2578 | rule->rdr_str = strdup(destination); |
| 2579 | rule->rdr_len = strlen(destination); |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2580 | if (cookie) { |
| 2581 | /* 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] | 2582 | * a clear consists in appending "; path=/; Max-Age=0;" at the end. |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2583 | */ |
| 2584 | rule->cookie_len = strlen(cookie); |
William Turner | d986526 | 2010-03-01 13:30:34 -0500 | [diff] [blame] | 2585 | if (cookie_set) { |
| 2586 | rule->cookie_str = malloc(rule->cookie_len + 10); |
| 2587 | memcpy(rule->cookie_str, cookie, rule->cookie_len); |
| 2588 | memcpy(rule->cookie_str + rule->cookie_len, "; path=/;", 10); |
| 2589 | rule->cookie_len += 9; |
| 2590 | } else { |
| 2591 | rule->cookie_str = malloc(rule->cookie_len + 21); |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2592 | memcpy(rule->cookie_str, cookie, rule->cookie_len); |
William Turner | d986526 | 2010-03-01 13:30:34 -0500 | [diff] [blame] | 2593 | memcpy(rule->cookie_str + rule->cookie_len, "; path=/; Max-Age=0;", 21); |
| 2594 | rule->cookie_len += 20; |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2595 | } |
| 2596 | } |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2597 | rule->type = type; |
| 2598 | rule->code = code; |
Willy Tarreau | 79da469 | 2008-11-19 20:03:04 +0100 | [diff] [blame] | 2599 | rule->flags = flags; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2600 | LIST_INIT(&rule->list); |
| 2601 | LIST_ADDQ(&curproxy->redirect_rules, &rule->list); |
Willy Tarreau | 9d9ed01 | 2011-02-23 15:24:42 +0100 | [diff] [blame] | 2602 | err_code |= warnif_rule_after_use_backend(curproxy, file, linenum, args[0]); |
| 2603 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2604 | } |
Krzysztof Piotr Oledzki | 7b723ef | 2009-01-27 21:09:41 +0100 | [diff] [blame] | 2605 | else if (!strcmp(args[0], "use_backend")) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2606 | struct switching_rule *rule; |
| 2607 | |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2608 | if (curproxy == &defproxy) { |
| 2609 | 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] | 2610 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2611 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2612 | } |
| 2613 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2614 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2615 | err_code |= ERR_WARN; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2616 | |
| 2617 | if (*(args[1]) == 0) { |
| 2618 | 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] | 2619 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2620 | goto out; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2621 | } |
| 2622 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2623 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2624 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 2625 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2626 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2627 | goto out; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2628 | } |
| 2629 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 2630 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 2631 | Alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n", |
| 2632 | file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2633 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2634 | goto out; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2635 | } |
| 2636 | |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 2637 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
Willy Tarreau | a980263 | 2008-07-25 19:13:19 +0200 | [diff] [blame] | 2638 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2639 | rule = (struct switching_rule *)calloc(1, sizeof(*rule)); |
| 2640 | rule->cond = cond; |
| 2641 | rule->be.name = strdup(args[1]); |
| 2642 | LIST_INIT(&rule->list); |
| 2643 | LIST_ADDQ(&curproxy->switching_rules, &rule->list); |
| 2644 | } |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 2645 | else if (strcmp(args[0], "use-server") == 0) { |
| 2646 | struct server_rule *rule; |
| 2647 | |
| 2648 | if (curproxy == &defproxy) { |
| 2649 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2650 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2651 | goto out; |
| 2652 | } |
| 2653 | |
| 2654 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 2655 | err_code |= ERR_WARN; |
| 2656 | |
| 2657 | if (*(args[1]) == 0) { |
| 2658 | Alert("parsing [%s:%d] : '%s' expects a server name.\n", file, linenum, args[0]); |
| 2659 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2660 | goto out; |
| 2661 | } |
| 2662 | |
| 2663 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
| 2664 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 2665 | file, linenum, args[0]); |
| 2666 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2667 | goto out; |
| 2668 | } |
| 2669 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 2670 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 2671 | Alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n", |
| 2672 | file, linenum, errmsg); |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 2673 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2674 | goto out; |
| 2675 | } |
| 2676 | |
| 2677 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
| 2678 | |
| 2679 | rule = (struct server_rule *)calloc(1, sizeof(*rule)); |
| 2680 | rule->cond = cond; |
| 2681 | rule->srv.name = strdup(args[1]); |
| 2682 | LIST_INIT(&rule->list); |
| 2683 | LIST_ADDQ(&curproxy->server_rules, &rule->list); |
| 2684 | curproxy->be_req_ana |= AN_REQ_SRV_RULES; |
| 2685 | } |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 2686 | else if ((!strcmp(args[0], "force-persist")) || |
| 2687 | (!strcmp(args[0], "ignore-persist"))) { |
| 2688 | struct persist_rule *rule; |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2689 | |
| 2690 | if (curproxy == &defproxy) { |
| 2691 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2692 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2693 | goto out; |
| 2694 | } |
| 2695 | |
| 2696 | if (warnifnotcap(curproxy, PR_CAP_FE|PR_CAP_BE, file, linenum, args[0], NULL)) |
| 2697 | err_code |= ERR_WARN; |
| 2698 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2699 | if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) { |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2700 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 2701 | file, linenum, args[0]); |
| 2702 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2703 | goto out; |
| 2704 | } |
| 2705 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 2706 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 1, &errmsg)) == NULL) { |
| 2707 | Alert("parsing [%s:%d] : error detected while parsing a '%s' rule : %s.\n", |
| 2708 | file, linenum, args[0], errmsg); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2709 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2710 | goto out; |
| 2711 | } |
| 2712 | |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 2713 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2714 | |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 2715 | rule = (struct persist_rule *)calloc(1, sizeof(*rule)); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2716 | rule->cond = cond; |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 2717 | if (!strcmp(args[0], "force-persist")) { |
| 2718 | rule->type = PERSIST_TYPE_FORCE; |
| 2719 | } else { |
| 2720 | rule->type = PERSIST_TYPE_IGNORE; |
| 2721 | } |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2722 | LIST_INIT(&rule->list); |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 2723 | LIST_ADDQ(&curproxy->persist_rules, &rule->list); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2724 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2725 | else if (!strcmp(args[0], "stick-table")) { |
| 2726 | int myidx = 1; |
| 2727 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2728 | curproxy->table.id = curproxy->id; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2729 | curproxy->table.type = (unsigned int)-1; |
| 2730 | while (*args[myidx]) { |
| 2731 | const char *err; |
| 2732 | |
| 2733 | if (strcmp(args[myidx], "size") == 0) { |
| 2734 | myidx++; |
| 2735 | if (!*(args[myidx])) { |
| 2736 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 2737 | file, linenum, args[myidx-1]); |
| 2738 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2739 | goto out; |
| 2740 | } |
| 2741 | if ((err = parse_size_err(args[myidx], &curproxy->table.size))) { |
| 2742 | Alert("parsing [%s:%d] : stick-table: unexpected character '%c' in argument of '%s'.\n", |
| 2743 | file, linenum, *err, args[myidx-1]); |
| 2744 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2745 | goto out; |
| 2746 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 2747 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2748 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2749 | else if (strcmp(args[myidx], "peers") == 0) { |
| 2750 | myidx++; |
| 2751 | if (!*(args[myidx])) { |
| 2752 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 2753 | file, linenum, args[myidx-1]); |
| 2754 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2755 | goto out; |
| 2756 | } |
| 2757 | curproxy->table.peers.name = strdup(args[myidx++]); |
| 2758 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2759 | else if (strcmp(args[myidx], "expire") == 0) { |
| 2760 | myidx++; |
| 2761 | if (!*(args[myidx])) { |
| 2762 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 2763 | file, linenum, args[myidx-1]); |
| 2764 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2765 | goto out; |
| 2766 | } |
| 2767 | err = parse_time_err(args[myidx], &val, TIME_UNIT_MS); |
| 2768 | if (err) { |
| 2769 | Alert("parsing [%s:%d] : stick-table: unexpected character '%c' in argument of '%s'.\n", |
| 2770 | file, linenum, *err, args[myidx-1]); |
| 2771 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2772 | goto out; |
| 2773 | } |
| 2774 | curproxy->table.expire = val; |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 2775 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2776 | } |
| 2777 | else if (strcmp(args[myidx], "nopurge") == 0) { |
| 2778 | curproxy->table.nopurge = 1; |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 2779 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2780 | } |
| 2781 | else if (strcmp(args[myidx], "type") == 0) { |
| 2782 | myidx++; |
| 2783 | if (stktable_parse_type(args, &myidx, &curproxy->table.type, &curproxy->table.key_size) != 0) { |
| 2784 | Alert("parsing [%s:%d] : stick-table: unknown type '%s'.\n", |
| 2785 | file, linenum, args[myidx]); |
| 2786 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2787 | goto out; |
| 2788 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 2789 | /* myidx already points to next arg */ |
| 2790 | } |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 2791 | else if (strcmp(args[myidx], "store") == 0) { |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 2792 | int type, err; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 2793 | char *cw, *nw, *sa; |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 2794 | |
| 2795 | myidx++; |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 2796 | nw = args[myidx]; |
| 2797 | while (*nw) { |
| 2798 | /* the "store" keyword supports a comma-separated list */ |
| 2799 | cw = nw; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 2800 | sa = NULL; /* store arg */ |
| 2801 | while (*nw && *nw != ',') { |
| 2802 | if (*nw == '(') { |
| 2803 | *nw = 0; |
| 2804 | sa = ++nw; |
| 2805 | while (*nw != ')') { |
| 2806 | if (!*nw) { |
| 2807 | Alert("parsing [%s:%d] : %s: missing closing parenthesis after store option '%s'.\n", |
| 2808 | file, linenum, args[0], cw); |
| 2809 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2810 | goto out; |
| 2811 | } |
| 2812 | nw++; |
| 2813 | } |
| 2814 | *nw = '\0'; |
| 2815 | } |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 2816 | nw++; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 2817 | } |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 2818 | if (*nw) |
| 2819 | *nw++ = '\0'; |
| 2820 | type = stktable_get_data_type(cw); |
| 2821 | if (type < 0) { |
| 2822 | Alert("parsing [%s:%d] : %s: unknown store option '%s'.\n", |
| 2823 | file, linenum, args[0], cw); |
| 2824 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2825 | goto out; |
| 2826 | } |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 2827 | |
| 2828 | err = stktable_alloc_data_type(&curproxy->table, type, sa); |
| 2829 | switch (err) { |
| 2830 | case PE_NONE: break; |
| 2831 | case PE_EXIST: |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 2832 | Warning("parsing [%s:%d]: %s: store option '%s' already enabled, ignored.\n", |
| 2833 | file, linenum, args[0], cw); |
| 2834 | err_code |= ERR_WARN; |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 2835 | break; |
| 2836 | |
| 2837 | case PE_ARG_MISSING: |
| 2838 | Alert("parsing [%s:%d] : %s: missing argument to store option '%s'.\n", |
| 2839 | file, linenum, args[0], cw); |
| 2840 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2841 | goto out; |
| 2842 | |
| 2843 | case PE_ARG_NOT_USED: |
| 2844 | Alert("parsing [%s:%d] : %s: unexpected argument to store option '%s'.\n", |
| 2845 | file, linenum, args[0], cw); |
| 2846 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2847 | goto out; |
| 2848 | |
| 2849 | default: |
| 2850 | Alert("parsing [%s:%d] : %s: error when processing store option '%s'.\n", |
| 2851 | file, linenum, args[0], cw); |
| 2852 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2853 | goto out; |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 2854 | } |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 2855 | } |
| 2856 | myidx++; |
| 2857 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 2858 | else { |
| 2859 | Alert("parsing [%s:%d] : stick-table: unknown argument '%s'.\n", |
| 2860 | file, linenum, args[myidx]); |
| 2861 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2862 | goto out; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2863 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2864 | } |
| 2865 | |
| 2866 | if (!curproxy->table.size) { |
| 2867 | Alert("parsing [%s:%d] : stick-table: missing size.\n", |
| 2868 | file, linenum); |
| 2869 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2870 | goto out; |
| 2871 | } |
| 2872 | |
| 2873 | if (curproxy->table.type == (unsigned int)-1) { |
| 2874 | Alert("parsing [%s:%d] : stick-table: missing type.\n", |
| 2875 | file, linenum); |
| 2876 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2877 | goto out; |
| 2878 | } |
| 2879 | } |
| 2880 | else if (!strcmp(args[0], "stick")) { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2881 | struct sticking_rule *rule; |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 2882 | struct sample_expr *expr; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2883 | int myidx = 0; |
| 2884 | const char *name = NULL; |
| 2885 | int flags; |
| 2886 | |
| 2887 | if (curproxy == &defproxy) { |
| 2888 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2889 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2890 | goto out; |
| 2891 | } |
| 2892 | |
| 2893 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) { |
| 2894 | err_code |= ERR_WARN; |
| 2895 | goto out; |
| 2896 | } |
| 2897 | |
| 2898 | myidx++; |
| 2899 | if ((strcmp(args[myidx], "store") == 0) || |
| 2900 | (strcmp(args[myidx], "store-request") == 0)) { |
| 2901 | myidx++; |
| 2902 | flags = STK_IS_STORE; |
| 2903 | } |
| 2904 | else if (strcmp(args[myidx], "store-response") == 0) { |
| 2905 | myidx++; |
| 2906 | flags = STK_IS_STORE | STK_ON_RSP; |
| 2907 | } |
| 2908 | else if (strcmp(args[myidx], "match") == 0) { |
| 2909 | myidx++; |
| 2910 | flags = STK_IS_MATCH; |
| 2911 | } |
| 2912 | else if (strcmp(args[myidx], "on") == 0) { |
| 2913 | myidx++; |
| 2914 | flags = STK_IS_MATCH | STK_IS_STORE; |
| 2915 | } |
| 2916 | else { |
| 2917 | Alert("parsing [%s:%d] : '%s' expects 'on', 'match', or 'store'.\n", file, linenum, args[0]); |
| 2918 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2919 | goto out; |
| 2920 | } |
| 2921 | |
| 2922 | if (*(args[myidx]) == 0) { |
| 2923 | Alert("parsing [%s:%d] : '%s' expects a fetch method.\n", file, linenum, args[0]); |
| 2924 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2925 | goto out; |
| 2926 | } |
| 2927 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2928 | expr = sample_parse_expr(args, &myidx, trash.str, trash.size); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2929 | if (!expr) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2930 | Alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], trash.str); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2931 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2932 | goto out; |
| 2933 | } |
| 2934 | |
| 2935 | if (flags & STK_ON_RSP) { |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 2936 | if (!(expr->fetch->cap & SMP_CAP_RES)) { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2937 | Alert("parsing [%s:%d] : '%s': fetch method '%s' can not be used on response.\n", |
| 2938 | file, linenum, args[0], expr->fetch->kw); |
| 2939 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 2940 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2941 | goto out; |
| 2942 | } |
| 2943 | } else { |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 2944 | if (!(expr->fetch->cap & SMP_CAP_REQ)) { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2945 | Alert("parsing [%s:%d] : '%s': fetch method '%s' can not be used on request.\n", |
| 2946 | file, linenum, args[0], expr->fetch->kw); |
| 2947 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 2948 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2949 | goto out; |
| 2950 | } |
| 2951 | } |
| 2952 | |
Willy Tarreau | 1b6c00c | 2012-10-05 22:41:26 +0200 | [diff] [blame] | 2953 | /* check if we need to allocate an hdr_idx struct for HTTP parsing */ |
| 2954 | if (expr->fetch->cap & SMP_CAP_L7) |
| 2955 | curproxy->acl_requires |= ACL_USE_L7_ANY; |
| 2956 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2957 | if (strcmp(args[myidx], "table") == 0) { |
| 2958 | myidx++; |
| 2959 | name = args[myidx++]; |
| 2960 | } |
| 2961 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2962 | if (strcmp(args[myidx], "if") == 0 || strcmp(args[myidx], "unless") == 0) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 2963 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + myidx, &errmsg)) == NULL) { |
| 2964 | Alert("parsing [%s:%d] : '%s': error detected while parsing sticking condition : %s.\n", |
| 2965 | file, linenum, args[0], errmsg); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2966 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 2967 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2968 | goto out; |
| 2969 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2970 | } |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2971 | else if (*(args[myidx])) { |
| 2972 | Alert("parsing [%s:%d] : '%s': unknown keyword '%s'.\n", |
| 2973 | file, linenum, args[0], args[myidx]); |
| 2974 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 2975 | free(expr); |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2976 | goto out; |
| 2977 | } |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 2978 | if (flags & STK_ON_RSP) |
| 2979 | err_code |= warnif_cond_requires_req(cond, file, linenum); |
| 2980 | else |
| 2981 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 2982 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2983 | rule = (struct sticking_rule *)calloc(1, sizeof(*rule)); |
| 2984 | rule->cond = cond; |
| 2985 | rule->expr = expr; |
| 2986 | rule->flags = flags; |
| 2987 | rule->table.name = name ? strdup(name) : NULL; |
| 2988 | LIST_INIT(&rule->list); |
| 2989 | if (flags & STK_ON_RSP) |
| 2990 | LIST_ADDQ(&curproxy->storersp_rules, &rule->list); |
| 2991 | else |
| 2992 | LIST_ADDQ(&curproxy->sticking_rules, &rule->list); |
| 2993 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2994 | else if (!strcmp(args[0], "stats")) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2995 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2996 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2997 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2998 | if (curproxy != &defproxy && curproxy->uri_auth == defproxy.uri_auth) |
| 2999 | curproxy->uri_auth = NULL; /* we must detach from the default config */ |
| 3000 | |
Krzysztof Piotr Oledzki | 260a3bb | 2010-01-06 16:25:05 +0100 | [diff] [blame] | 3001 | if (!*args[1]) { |
| 3002 | goto stats_error_parsing; |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3003 | } else if (!strcmp(args[1], "admin")) { |
| 3004 | struct stats_admin_rule *rule; |
| 3005 | |
| 3006 | if (curproxy == &defproxy) { |
| 3007 | Alert("parsing [%s:%d]: '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
| 3008 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3009 | goto out; |
| 3010 | } |
| 3011 | |
| 3012 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 3013 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3014 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3015 | goto out; |
| 3016 | } |
| 3017 | |
| 3018 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
| 3019 | Alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n", |
| 3020 | file, linenum, args[0], args[1]); |
| 3021 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3022 | goto out; |
| 3023 | } |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 3024 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 3025 | Alert("parsing [%s:%d] : error detected while parsing a '%s %s' rule : %s.\n", |
| 3026 | file, linenum, args[0], args[1], errmsg); |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3027 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3028 | goto out; |
| 3029 | } |
| 3030 | |
| 3031 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
| 3032 | |
| 3033 | rule = (struct stats_admin_rule *)calloc(1, sizeof(*rule)); |
| 3034 | rule->cond = cond; |
| 3035 | LIST_INIT(&rule->list); |
| 3036 | LIST_ADDQ(&curproxy->uri_auth->admin_rules, &rule->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3037 | } else if (!strcmp(args[1], "uri")) { |
| 3038 | if (*(args[2]) == 0) { |
| 3039 | Alert("parsing [%s:%d] : 'uri' needs an URI prefix.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3040 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3041 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3042 | } else if (!stats_set_uri(&curproxy->uri_auth, args[2])) { |
| 3043 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3044 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3045 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3046 | } |
| 3047 | } else if (!strcmp(args[1], "realm")) { |
| 3048 | if (*(args[2]) == 0) { |
| 3049 | Alert("parsing [%s:%d] : 'realm' needs an realm name.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3050 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3051 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3052 | } else if (!stats_set_realm(&curproxy->uri_auth, args[2])) { |
| 3053 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3054 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3055 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3056 | } |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 3057 | } else if (!strcmp(args[1], "refresh")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 3058 | unsigned interval; |
| 3059 | |
| 3060 | err = parse_time_err(args[2], &interval, TIME_UNIT_S); |
| 3061 | if (err) { |
| 3062 | Alert("parsing [%s:%d] : unexpected character '%c' in stats refresh interval.\n", |
| 3063 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3064 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3065 | goto out; |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 3066 | } else if (!stats_set_refresh(&curproxy->uri_auth, interval)) { |
| 3067 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3068 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3069 | goto out; |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 3070 | } |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3071 | } 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] | 3072 | struct http_req_rule *rule; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3073 | |
| 3074 | if (curproxy == &defproxy) { |
| 3075 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3076 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3077 | goto out; |
| 3078 | } |
| 3079 | |
| 3080 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 3081 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3082 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3083 | goto out; |
| 3084 | } |
| 3085 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3086 | if (!LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) && |
| 3087 | !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] | 3088 | Warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n", |
| 3089 | file, linenum, args[0]); |
| 3090 | err_code |= ERR_WARN; |
| 3091 | } |
| 3092 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3093 | 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] | 3094 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3095 | if (!rule) { |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3096 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3097 | goto out; |
| 3098 | } |
| 3099 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3100 | err_code |= warnif_cond_requires_resp(rule->cond, file, linenum); |
| 3101 | LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list); |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3102 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3103 | } else if (!strcmp(args[1], "auth")) { |
| 3104 | if (*(args[2]) == 0) { |
| 3105 | 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] | 3106 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3107 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3108 | } else if (!stats_add_auth(&curproxy->uri_auth, args[2])) { |
| 3109 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3110 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3111 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3112 | } |
| 3113 | } else if (!strcmp(args[1], "scope")) { |
| 3114 | if (*(args[2]) == 0) { |
| 3115 | Alert("parsing [%s:%d] : 'scope' needs a proxy name.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3116 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3117 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3118 | } else if (!stats_add_scope(&curproxy->uri_auth, args[2])) { |
| 3119 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3120 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3121 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3122 | } |
| 3123 | } else if (!strcmp(args[1], "enable")) { |
| 3124 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 3125 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3126 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3127 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3128 | } |
Krzysztof Oledzki | d9db927 | 2007-10-15 10:05:11 +0200 | [diff] [blame] | 3129 | } else if (!strcmp(args[1], "hide-version")) { |
| 3130 | if (!stats_set_flag(&curproxy->uri_auth, ST_HIDEVER)) { |
| 3131 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3132 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3133 | goto out; |
Krzysztof Oledzki | d9db927 | 2007-10-15 10:05:11 +0200 | [diff] [blame] | 3134 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3135 | } else if (!strcmp(args[1], "show-legends")) { |
| 3136 | if (!stats_set_flag(&curproxy->uri_auth, ST_SHLGNDS)) { |
| 3137 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3138 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3139 | goto out; |
| 3140 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3141 | } else if (!strcmp(args[1], "show-node")) { |
| 3142 | |
| 3143 | if (*args[2]) { |
| 3144 | int i; |
| 3145 | char c; |
| 3146 | |
| 3147 | for (i=0; args[2][i]; i++) { |
| 3148 | c = args[2][i]; |
Willy Tarreau | 88e0581 | 2010-03-03 00:16:00 +0100 | [diff] [blame] | 3149 | if (!isupper((unsigned char)c) && !islower((unsigned char)c) && |
| 3150 | !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.') |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3151 | break; |
| 3152 | } |
| 3153 | |
| 3154 | if (!i || args[2][i]) { |
| 3155 | Alert("parsing [%s:%d]: '%s %s' invalid node name - should be a string" |
| 3156 | "with digits(0-9), letters(A-Z, a-z), hyphen(-) or underscode(_).\n", |
| 3157 | file, linenum, args[0], args[1]); |
| 3158 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3159 | goto out; |
| 3160 | } |
| 3161 | } |
| 3162 | |
| 3163 | if (!stats_set_node(&curproxy->uri_auth, args[2])) { |
| 3164 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3165 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3166 | goto out; |
| 3167 | } |
| 3168 | } else if (!strcmp(args[1], "show-desc")) { |
| 3169 | char *desc = NULL; |
| 3170 | |
| 3171 | if (*args[2]) { |
| 3172 | int i, len=0; |
| 3173 | char *d; |
| 3174 | |
| 3175 | for(i=2; *args[i]; i++) |
| 3176 | len += strlen(args[i])+1; |
| 3177 | |
| 3178 | desc = d = (char *)calloc(1, len); |
| 3179 | |
| 3180 | d += sprintf(d, "%s", args[2]); |
| 3181 | for(i=3; *args[i]; i++) |
| 3182 | d += sprintf(d, " %s", args[i]); |
| 3183 | } |
| 3184 | |
| 3185 | if (!*args[2] && !global.desc) |
| 3186 | Warning("parsing [%s:%d]: '%s' requires a parameter or 'desc' to be set in the global section.\n", |
| 3187 | file, linenum, args[1]); |
| 3188 | else { |
| 3189 | if (!stats_set_desc(&curproxy->uri_auth, desc)) { |
| 3190 | free(desc); |
| 3191 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3192 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3193 | goto out; |
| 3194 | } |
| 3195 | free(desc); |
| 3196 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3197 | } else { |
Krzysztof Piotr Oledzki | 260a3bb | 2010-01-06 16:25:05 +0100 | [diff] [blame] | 3198 | stats_error_parsing: |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3199 | 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] | 3200 | 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] | 3201 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3202 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3203 | } |
| 3204 | } |
| 3205 | else if (!strcmp(args[0], "option")) { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3206 | int optnum; |
| 3207 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3208 | if (*(args[1]) == '\0') { |
| 3209 | Alert("parsing [%s:%d]: '%s' expects an option name.\n", |
| 3210 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3211 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3212 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3213 | } |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3214 | |
| 3215 | for (optnum = 0; cfg_opts[optnum].name; optnum++) { |
| 3216 | if (!strcmp(args[1], cfg_opts[optnum].name)) { |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 3217 | if (cfg_opts[optnum].cap == PR_CAP_NONE) { |
| 3218 | Alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n", |
| 3219 | file, linenum, cfg_opts[optnum].name); |
| 3220 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3221 | goto out; |
| 3222 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3223 | if (warnifnotcap(curproxy, cfg_opts[optnum].cap, file, linenum, args[1], NULL)) { |
| 3224 | err_code |= ERR_WARN; |
| 3225 | goto out; |
| 3226 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3227 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 3228 | curproxy->no_options &= ~cfg_opts[optnum].val; |
| 3229 | curproxy->options &= ~cfg_opts[optnum].val; |
| 3230 | |
| 3231 | switch (kwm) { |
| 3232 | case KWM_STD: |
| 3233 | curproxy->options |= cfg_opts[optnum].val; |
| 3234 | break; |
| 3235 | case KWM_NO: |
| 3236 | curproxy->no_options |= cfg_opts[optnum].val; |
| 3237 | break; |
| 3238 | case KWM_DEF: /* already cleared */ |
| 3239 | break; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 3240 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3241 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3242 | goto out; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3243 | } |
| 3244 | } |
| 3245 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 3246 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) { |
| 3247 | if (!strcmp(args[1], cfg_opts2[optnum].name)) { |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 3248 | if (cfg_opts2[optnum].cap == PR_CAP_NONE) { |
| 3249 | Alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n", |
| 3250 | file, linenum, cfg_opts2[optnum].name); |
| 3251 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3252 | goto out; |
| 3253 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3254 | if (warnifnotcap(curproxy, cfg_opts2[optnum].cap, file, linenum, args[1], NULL)) { |
| 3255 | err_code |= ERR_WARN; |
| 3256 | goto out; |
| 3257 | } |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 3258 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 3259 | curproxy->no_options2 &= ~cfg_opts2[optnum].val; |
| 3260 | curproxy->options2 &= ~cfg_opts2[optnum].val; |
| 3261 | |
| 3262 | switch (kwm) { |
| 3263 | case KWM_STD: |
| 3264 | curproxy->options2 |= cfg_opts2[optnum].val; |
| 3265 | break; |
| 3266 | case KWM_NO: |
| 3267 | curproxy->no_options2 |= cfg_opts2[optnum].val; |
| 3268 | break; |
| 3269 | case KWM_DEF: /* already cleared */ |
| 3270 | break; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 3271 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3272 | goto out; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 3273 | } |
| 3274 | } |
| 3275 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 3276 | if (kwm != KWM_STD) { |
| 3277 | 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] | 3278 | file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3279 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3280 | goto out; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3281 | } |
| 3282 | |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3283 | if (!strcmp(args[1], "httplog")) { |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 3284 | char *logformat; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3285 | /* generate a complete HTTP log */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 3286 | logformat = default_http_log_format; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3287 | if (*(args[2]) != '\0') { |
| 3288 | if (!strcmp(args[2], "clf")) { |
| 3289 | curproxy->options2 |= PR_O2_CLFLOG; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 3290 | logformat = clf_http_log_format; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3291 | } else { |
| 3292 | 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] | 3293 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3294 | goto out; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3295 | } |
| 3296 | } |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 3297 | if (curproxy->logformat_string != default_http_log_format && |
| 3298 | curproxy->logformat_string != default_tcp_log_format && |
| 3299 | curproxy->logformat_string != clf_http_log_format) |
| 3300 | free(curproxy->logformat_string); |
| 3301 | curproxy->logformat_string = logformat; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3302 | } |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 3303 | else if (!strcmp(args[1], "tcplog")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3304 | /* generate a detailed TCP log */ |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 3305 | if (curproxy->logformat_string != default_http_log_format && |
| 3306 | curproxy->logformat_string != default_tcp_log_format && |
| 3307 | curproxy->logformat_string != clf_http_log_format) |
| 3308 | free(curproxy->logformat_string); |
| 3309 | curproxy->logformat_string = default_tcp_log_format; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 3310 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3311 | else if (!strcmp(args[1], "tcpka")) { |
| 3312 | /* enable TCP keep-alives on client and server sessions */ |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3313 | 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] | 3314 | err_code |= ERR_WARN; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3315 | |
| 3316 | if (curproxy->cap & PR_CAP_FE) |
| 3317 | curproxy->options |= PR_O_TCP_CLI_KA; |
| 3318 | if (curproxy->cap & PR_CAP_BE) |
| 3319 | curproxy->options |= PR_O_TCP_SRV_KA; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3320 | } |
| 3321 | else if (!strcmp(args[1], "httpchk")) { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3322 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3323 | err_code |= ERR_WARN; |
| 3324 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3325 | /* use HTTP request to check servers' health */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3326 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 3327 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3328 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 3329 | curproxy->options2 |= PR_O2_HTTP_CHK; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3330 | if (!*args[2]) { /* no argument */ |
| 3331 | curproxy->check_req = strdup(DEF_CHECK_REQ); /* default request */ |
| 3332 | curproxy->check_len = strlen(DEF_CHECK_REQ); |
| 3333 | } else if (!*args[3]) { /* one argument : URI */ |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3334 | 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] | 3335 | curproxy->check_req = (char *)malloc(reqlen); |
| 3336 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3337 | "OPTIONS %s HTTP/1.0\r\n", args[2]); /* URI to use */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3338 | } else { /* more arguments : METHOD URI [HTTP_VER] */ |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3339 | int reqlen = strlen(args[2]) + strlen(args[3]) + 3 + strlen("\r\n"); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3340 | if (*args[4]) |
| 3341 | reqlen += strlen(args[4]); |
| 3342 | else |
| 3343 | reqlen += strlen("HTTP/1.0"); |
| 3344 | |
| 3345 | curproxy->check_req = (char *)malloc(reqlen); |
| 3346 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3347 | "%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] | 3348 | } |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 3349 | } |
| 3350 | else if (!strcmp(args[1], "ssl-hello-chk")) { |
| 3351 | /* use SSLv3 CLIENT HELLO to check servers' health */ |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3352 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3353 | err_code |= ERR_WARN; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3354 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3355 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 3356 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3357 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Willy Tarreau | 07a5490 | 2010-03-29 18:33:29 +0200 | [diff] [blame] | 3358 | curproxy->options2 |= PR_O2_SSL3_CHK; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3359 | } |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 3360 | else if (!strcmp(args[1], "smtpchk")) { |
| 3361 | /* use SMTP request to check servers' health */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3362 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 3363 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3364 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 3365 | curproxy->options2 |= PR_O2_SMTP_CHK; |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 3366 | |
| 3367 | if (!*args[2] || !*args[3]) { /* no argument or incomplete EHLO host */ |
| 3368 | curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */ |
| 3369 | curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ); |
| 3370 | } else { /* ESMTP EHLO, or SMTP HELO, and a hostname */ |
| 3371 | if (!strcmp(args[2], "EHLO") || !strcmp(args[2], "HELO")) { |
| 3372 | int reqlen = strlen(args[2]) + strlen(args[3]) + strlen(" \r\n") + 1; |
| 3373 | curproxy->check_req = (char *)malloc(reqlen); |
| 3374 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
| 3375 | "%s %s\r\n", args[2], args[3]); /* HELO hostname */ |
| 3376 | } else { |
| 3377 | /* this just hits the default for now, but you could potentially expand it to allow for other stuff |
| 3378 | though, it's unlikely you'd want to send anything other than an EHLO or HELO */ |
| 3379 | curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */ |
| 3380 | curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ); |
| 3381 | } |
| 3382 | } |
| 3383 | } |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 3384 | else if (!strcmp(args[1], "pgsql-check")) { |
| 3385 | /* use PostgreSQL request to check servers' health */ |
| 3386 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 3387 | err_code |= ERR_WARN; |
| 3388 | |
| 3389 | free(curproxy->check_req); |
| 3390 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3391 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 3392 | curproxy->options2 |= PR_O2_PGSQL_CHK; |
| 3393 | |
| 3394 | if (*(args[2])) { |
| 3395 | int cur_arg = 2; |
| 3396 | |
| 3397 | while (*(args[cur_arg])) { |
| 3398 | if (strcmp(args[cur_arg], "user") == 0) { |
| 3399 | char * packet; |
| 3400 | uint32_t packet_len; |
| 3401 | uint32_t pv; |
| 3402 | |
| 3403 | /* suboption header - needs additional argument for it */ |
| 3404 | if (*(args[cur_arg+1]) == 0) { |
| 3405 | Alert("parsing [%s:%d] : '%s %s %s' expects <username> as argument.\n", |
| 3406 | file, linenum, args[0], args[1], args[cur_arg]); |
| 3407 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3408 | goto out; |
| 3409 | } |
| 3410 | |
| 3411 | /* uint32_t + uint32_t + strlen("user")+1 + strlen(username)+1 + 1 */ |
| 3412 | packet_len = 4 + 4 + 5 + strlen(args[cur_arg + 1])+1 +1; |
| 3413 | pv = htonl(0x30000); /* protocol version 3.0 */ |
| 3414 | |
| 3415 | packet = (char*) calloc(1, packet_len); |
| 3416 | |
| 3417 | memcpy(packet + 4, &pv, 4); |
| 3418 | |
| 3419 | /* copy "user" */ |
| 3420 | memcpy(packet + 8, "user", 4); |
| 3421 | |
| 3422 | /* copy username */ |
| 3423 | memcpy(packet + 13, args[cur_arg+1], strlen(args[cur_arg+1])); |
| 3424 | |
| 3425 | free(curproxy->check_req); |
| 3426 | curproxy->check_req = packet; |
| 3427 | curproxy->check_len = packet_len; |
| 3428 | |
| 3429 | packet_len = htonl(packet_len); |
| 3430 | memcpy(packet, &packet_len, 4); |
| 3431 | cur_arg += 2; |
| 3432 | } else { |
| 3433 | /* unknown suboption - catchall */ |
| 3434 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'user'.\n", |
| 3435 | file, linenum, args[0], args[1]); |
| 3436 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3437 | goto out; |
| 3438 | } |
| 3439 | } /* end while loop */ |
| 3440 | } |
| 3441 | } |
| 3442 | |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 3443 | else if (!strcmp(args[1], "redis-check")) { |
| 3444 | /* use REDIS PING request to check servers' health */ |
| 3445 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 3446 | err_code |= ERR_WARN; |
| 3447 | |
| 3448 | free(curproxy->check_req); |
| 3449 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3450 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 3451 | curproxy->options2 |= PR_O2_REDIS_CHK; |
| 3452 | |
| 3453 | curproxy->check_req = (char *) malloc(sizeof(DEF_REDIS_CHECK_REQ) - 1); |
| 3454 | memcpy(curproxy->check_req, DEF_REDIS_CHECK_REQ, sizeof(DEF_REDIS_CHECK_REQ) - 1); |
| 3455 | curproxy->check_len = sizeof(DEF_REDIS_CHECK_REQ) - 1; |
| 3456 | } |
| 3457 | |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 3458 | else if (!strcmp(args[1], "mysql-check")) { |
| 3459 | /* use MYSQL request to check servers' health */ |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 3460 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 3461 | err_code |= ERR_WARN; |
| 3462 | |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 3463 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 3464 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3465 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 3466 | curproxy->options2 |= PR_O2_MYSQL_CHK; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 3467 | |
| 3468 | /* This is an exemple of an MySQL >=4.0 client Authentication packet kindly provided by Cyril Bonte. |
| 3469 | * const char mysql40_client_auth_pkt[] = { |
| 3470 | * "\x0e\x00\x00" // packet length |
| 3471 | * "\x01" // packet number |
| 3472 | * "\x00\x00" // client capabilities |
| 3473 | * "\x00\x00\x01" // max packet |
| 3474 | * "haproxy\x00" // username (null terminated string) |
| 3475 | * "\x00" // filler (always 0x00) |
| 3476 | * "\x01\x00\x00" // packet length |
| 3477 | * "\x00" // packet number |
| 3478 | * "\x01" // COM_QUIT command |
| 3479 | * }; |
| 3480 | */ |
| 3481 | |
| 3482 | if (*(args[2])) { |
| 3483 | int cur_arg = 2; |
| 3484 | |
| 3485 | while (*(args[cur_arg])) { |
| 3486 | if (strcmp(args[cur_arg], "user") == 0) { |
| 3487 | char *mysqluser; |
| 3488 | int packetlen, reqlen, userlen; |
| 3489 | |
| 3490 | /* suboption header - needs additional argument for it */ |
| 3491 | if (*(args[cur_arg+1]) == 0) { |
| 3492 | Alert("parsing [%s:%d] : '%s %s %s' expects <username> as argument.\n", |
| 3493 | file, linenum, args[0], args[1], args[cur_arg]); |
| 3494 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3495 | goto out; |
| 3496 | } |
| 3497 | mysqluser = args[cur_arg + 1]; |
| 3498 | userlen = strlen(mysqluser); |
| 3499 | packetlen = userlen + 7; |
| 3500 | reqlen = packetlen + 9; |
| 3501 | |
| 3502 | free(curproxy->check_req); |
| 3503 | curproxy->check_req = (char *)calloc(1, reqlen); |
| 3504 | curproxy->check_len = reqlen; |
| 3505 | |
| 3506 | snprintf(curproxy->check_req, 4, "%c%c%c", |
| 3507 | ((unsigned char) packetlen & 0xff), |
| 3508 | ((unsigned char) (packetlen >> 8) & 0xff), |
| 3509 | ((unsigned char) (packetlen >> 16) & 0xff)); |
| 3510 | |
| 3511 | curproxy->check_req[3] = 1; |
Hervé COMMOWICK | 212f778 | 2011-06-10 14:05:59 +0200 | [diff] [blame] | 3512 | curproxy->check_req[5] = 128; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 3513 | curproxy->check_req[8] = 1; |
| 3514 | memcpy(&curproxy->check_req[9], mysqluser, userlen); |
| 3515 | curproxy->check_req[9 + userlen + 1 + 1] = 1; |
| 3516 | curproxy->check_req[9 + userlen + 1 + 1 + 4] = 1; |
| 3517 | cur_arg += 2; |
| 3518 | } else { |
| 3519 | /* unknown suboption - catchall */ |
| 3520 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'user'.\n", |
| 3521 | file, linenum, args[0], args[1]); |
| 3522 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3523 | goto out; |
| 3524 | } |
| 3525 | } /* end while loop */ |
| 3526 | } |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 3527 | } |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 3528 | else if (!strcmp(args[1], "ldap-check")) { |
| 3529 | /* use LDAP request to check servers' health */ |
| 3530 | free(curproxy->check_req); |
| 3531 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3532 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 3533 | curproxy->options2 |= PR_O2_LDAP_CHK; |
| 3534 | |
| 3535 | curproxy->check_req = (char *) malloc(sizeof(DEF_LDAP_CHECK_REQ) - 1); |
| 3536 | memcpy(curproxy->check_req, DEF_LDAP_CHECK_REQ, sizeof(DEF_LDAP_CHECK_REQ) - 1); |
| 3537 | curproxy->check_len = sizeof(DEF_LDAP_CHECK_REQ) - 1; |
| 3538 | } |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3539 | else if (!strcmp(args[1], "forwardfor")) { |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3540 | int cur_arg; |
| 3541 | |
| 3542 | /* insert x-forwarded-for field, but not for the IP address listed as an except. |
| 3543 | * set default options (ie: bitfield, header name, etc) |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3544 | */ |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3545 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 3546 | curproxy->options |= PR_O_FWDFOR | PR_O_FF_ALWAYS; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3547 | |
| 3548 | free(curproxy->fwdfor_hdr_name); |
| 3549 | curproxy->fwdfor_hdr_name = strdup(DEF_XFORWARDFOR_HDR); |
| 3550 | curproxy->fwdfor_hdr_len = strlen(DEF_XFORWARDFOR_HDR); |
| 3551 | |
| 3552 | /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */ |
| 3553 | cur_arg = 2; |
| 3554 | while (*(args[cur_arg])) { |
| 3555 | if (!strcmp(args[cur_arg], "except")) { |
| 3556 | /* suboption except - needs additional argument for it */ |
| 3557 | if (!*(args[cur_arg+1]) || !str2net(args[cur_arg+1], &curproxy->except_net, &curproxy->except_mask)) { |
| 3558 | Alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n", |
| 3559 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3560 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3561 | goto out; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3562 | } |
| 3563 | /* flush useless bits */ |
| 3564 | curproxy->except_net.s_addr &= curproxy->except_mask.s_addr; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3565 | cur_arg += 2; |
| 3566 | } else if (!strcmp(args[cur_arg], "header")) { |
| 3567 | /* suboption header - needs additional argument for it */ |
| 3568 | if (*(args[cur_arg+1]) == 0) { |
| 3569 | Alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 3570 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3571 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3572 | goto out; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3573 | } |
| 3574 | free(curproxy->fwdfor_hdr_name); |
| 3575 | curproxy->fwdfor_hdr_name = strdup(args[cur_arg+1]); |
| 3576 | curproxy->fwdfor_hdr_len = strlen(curproxy->fwdfor_hdr_name); |
| 3577 | cur_arg += 2; |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 3578 | } else if (!strcmp(args[cur_arg], "if-none")) { |
| 3579 | curproxy->options &= ~PR_O_FF_ALWAYS; |
| 3580 | cur_arg += 1; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3581 | } else { |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3582 | /* unknown suboption - catchall */ |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 3583 | 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] | 3584 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3585 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3586 | goto out; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3587 | } |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3588 | } /* end while loop */ |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3589 | } |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 3590 | else if (!strcmp(args[1], "originalto")) { |
| 3591 | int cur_arg; |
| 3592 | |
| 3593 | /* insert x-original-to field, but not for the IP address listed as an except. |
| 3594 | * set default options (ie: bitfield, header name, etc) |
| 3595 | */ |
| 3596 | |
| 3597 | curproxy->options |= PR_O_ORGTO; |
| 3598 | |
| 3599 | free(curproxy->orgto_hdr_name); |
| 3600 | curproxy->orgto_hdr_name = strdup(DEF_XORIGINALTO_HDR); |
| 3601 | curproxy->orgto_hdr_len = strlen(DEF_XORIGINALTO_HDR); |
| 3602 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 3603 | /* 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] | 3604 | cur_arg = 2; |
| 3605 | while (*(args[cur_arg])) { |
| 3606 | if (!strcmp(args[cur_arg], "except")) { |
| 3607 | /* suboption except - needs additional argument for it */ |
| 3608 | if (!*(args[cur_arg+1]) || !str2net(args[cur_arg+1], &curproxy->except_to, &curproxy->except_mask_to)) { |
| 3609 | Alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n", |
| 3610 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3611 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3612 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 3613 | } |
| 3614 | /* flush useless bits */ |
| 3615 | curproxy->except_to.s_addr &= curproxy->except_mask_to.s_addr; |
| 3616 | cur_arg += 2; |
| 3617 | } else if (!strcmp(args[cur_arg], "header")) { |
| 3618 | /* suboption header - needs additional argument for it */ |
| 3619 | if (*(args[cur_arg+1]) == 0) { |
| 3620 | Alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 3621 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3622 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3623 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 3624 | } |
| 3625 | free(curproxy->orgto_hdr_name); |
| 3626 | curproxy->orgto_hdr_name = strdup(args[cur_arg+1]); |
| 3627 | curproxy->orgto_hdr_len = strlen(curproxy->orgto_hdr_name); |
| 3628 | cur_arg += 2; |
| 3629 | } else { |
| 3630 | /* unknown suboption - catchall */ |
| 3631 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n", |
| 3632 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3633 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3634 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 3635 | } |
| 3636 | } /* end while loop */ |
| 3637 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3638 | else { |
| 3639 | Alert("parsing [%s:%d] : unknown option '%s'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3640 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3641 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3642 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3643 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3644 | } |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 3645 | else if (!strcmp(args[0], "default_backend")) { |
| 3646 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3647 | err_code |= ERR_WARN; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 3648 | |
| 3649 | if (*(args[1]) == 0) { |
| 3650 | 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] | 3651 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3652 | goto out; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 3653 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3654 | free(curproxy->defbe.name); |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 3655 | curproxy->defbe.name = strdup(args[1]); |
| 3656 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3657 | else if (!strcmp(args[0], "redispatch") || !strcmp(args[0], "redisp")) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3658 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3659 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3660 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3661 | Warning("parsing [%s:%d]: keyword '%s' is deprecated, please use 'option redispatch' instead.\n", |
| 3662 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3663 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3664 | /* enable reconnections to dispatch */ |
| 3665 | curproxy->options |= PR_O_REDISP; |
| 3666 | } |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 3667 | else if (!strcmp(args[0], "http-check")) { |
| 3668 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3669 | err_code |= ERR_WARN; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 3670 | |
| 3671 | if (strcmp(args[1], "disable-on-404") == 0) { |
| 3672 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 3673 | curproxy->options |= PR_O_DISABLE404; |
| 3674 | } |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 3675 | else if (strcmp(args[1], "send-state") == 0) { |
| 3676 | /* enable emission of the apparent state of a server in HTTP checks */ |
| 3677 | curproxy->options2 |= PR_O2_CHK_SNDST; |
| 3678 | } |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 3679 | else if (strcmp(args[1], "expect") == 0) { |
| 3680 | const char *ptr_arg; |
| 3681 | int cur_arg; |
| 3682 | |
| 3683 | if (curproxy->options2 & PR_O2_EXP_TYPE) { |
| 3684 | Alert("parsing [%s:%d] : '%s %s' already specified.\n", file, linenum, args[0], args[1]); |
| 3685 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3686 | goto out; |
| 3687 | } |
| 3688 | |
| 3689 | cur_arg = 2; |
| 3690 | /* consider exclamation marks, sole or at the beginning of a word */ |
| 3691 | while (*(ptr_arg = args[cur_arg])) { |
| 3692 | while (*ptr_arg == '!') { |
| 3693 | curproxy->options2 ^= PR_O2_EXP_INV; |
| 3694 | ptr_arg++; |
| 3695 | } |
| 3696 | if (*ptr_arg) |
| 3697 | break; |
| 3698 | cur_arg++; |
| 3699 | } |
| 3700 | /* now ptr_arg points to the beginning of a word past any possible |
| 3701 | * exclamation mark, and cur_arg is the argument which holds this word. |
| 3702 | */ |
| 3703 | if (strcmp(ptr_arg, "status") == 0) { |
| 3704 | if (!*(args[cur_arg + 1])) { |
| 3705 | Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 3706 | file, linenum, args[0], args[1], ptr_arg); |
| 3707 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3708 | goto out; |
| 3709 | } |
| 3710 | curproxy->options2 |= PR_O2_EXP_STS; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 3711 | free(curproxy->expect_str); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 3712 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
| 3713 | } |
| 3714 | else if (strcmp(ptr_arg, "string") == 0) { |
| 3715 | if (!*(args[cur_arg + 1])) { |
| 3716 | Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 3717 | file, linenum, args[0], args[1], ptr_arg); |
| 3718 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3719 | goto out; |
| 3720 | } |
| 3721 | curproxy->options2 |= PR_O2_EXP_STR; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 3722 | free(curproxy->expect_str); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 3723 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
| 3724 | } |
| 3725 | else if (strcmp(ptr_arg, "rstatus") == 0) { |
| 3726 | if (!*(args[cur_arg + 1])) { |
| 3727 | Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 3728 | file, linenum, args[0], args[1], ptr_arg); |
| 3729 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3730 | goto out; |
| 3731 | } |
| 3732 | curproxy->options2 |= PR_O2_EXP_RSTS; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 3733 | free(curproxy->expect_str); |
| 3734 | if (curproxy->expect_regex) regfree(curproxy->expect_regex); |
| 3735 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 3736 | curproxy->expect_regex = calloc(1, sizeof(regex_t)); |
| 3737 | if (regcomp(curproxy->expect_regex, args[cur_arg + 1], REG_EXTENDED) != 0) { |
| 3738 | Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s'.\n", |
| 3739 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1]); |
| 3740 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3741 | goto out; |
| 3742 | } |
| 3743 | } |
| 3744 | else if (strcmp(ptr_arg, "rstring") == 0) { |
| 3745 | if (!*(args[cur_arg + 1])) { |
| 3746 | Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 3747 | file, linenum, args[0], args[1], ptr_arg); |
| 3748 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3749 | goto out; |
| 3750 | } |
| 3751 | curproxy->options2 |= PR_O2_EXP_RSTR; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 3752 | free(curproxy->expect_str); |
| 3753 | if (curproxy->expect_regex) regfree(curproxy->expect_regex); |
| 3754 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 3755 | curproxy->expect_regex = calloc(1, sizeof(regex_t)); |
| 3756 | if (regcomp(curproxy->expect_regex, args[cur_arg + 1], REG_EXTENDED) != 0) { |
| 3757 | Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s'.\n", |
| 3758 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1]); |
| 3759 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3760 | goto out; |
| 3761 | } |
| 3762 | } |
| 3763 | else { |
| 3764 | Alert("parsing [%s:%d] : '%s %s' only supports [!] 'status', 'string', 'rstatus', 'rstring', found '%s'.\n", |
| 3765 | file, linenum, args[0], args[1], ptr_arg); |
| 3766 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3767 | goto out; |
| 3768 | } |
| 3769 | } |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 3770 | else { |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 3771 | 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] | 3772 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3773 | goto out; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 3774 | } |
| 3775 | } |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3776 | else if (!strcmp(args[0], "monitor")) { |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3777 | if (curproxy == &defproxy) { |
| 3778 | 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] | 3779 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3780 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3781 | } |
| 3782 | |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3783 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3784 | err_code |= ERR_WARN; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3785 | |
| 3786 | if (strcmp(args[1], "fail") == 0) { |
| 3787 | /* add a condition to fail monitor requests */ |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 3788 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3789 | Alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n", |
| 3790 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3791 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3792 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3793 | } |
| 3794 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 3795 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 3796 | Alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition : %s.\n", |
| 3797 | file, linenum, args[0], args[1], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3798 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3799 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3800 | } |
| 3801 | LIST_ADDQ(&curproxy->mon_fail_cond, &cond->list); |
| 3802 | } |
| 3803 | else { |
| 3804 | 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] | 3805 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3806 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3807 | } |
| 3808 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3809 | #ifdef TPROXY |
| 3810 | else if (!strcmp(args[0], "transparent")) { |
| 3811 | /* enable transparent proxy connections */ |
| 3812 | curproxy->options |= PR_O_TRANSP; |
| 3813 | } |
| 3814 | #endif |
| 3815 | else if (!strcmp(args[0], "maxconn")) { /* maxconn */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3816 | 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] | 3817 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3818 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3819 | if (*(args[1]) == 0) { |
| 3820 | 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] | 3821 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3822 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3823 | } |
| 3824 | curproxy->maxconn = atol(args[1]); |
| 3825 | } |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 3826 | else if (!strcmp(args[0], "backlog")) { /* backlog */ |
| 3827 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3828 | err_code |= ERR_WARN; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 3829 | |
| 3830 | if (*(args[1]) == 0) { |
| 3831 | 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] | 3832 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3833 | goto out; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 3834 | } |
| 3835 | curproxy->backlog = atol(args[1]); |
| 3836 | } |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 3837 | else if (!strcmp(args[0], "fullconn")) { /* fullconn */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3838 | 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] | 3839 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3840 | |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 3841 | if (*(args[1]) == 0) { |
| 3842 | 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] | 3843 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3844 | goto out; |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 3845 | } |
| 3846 | curproxy->fullconn = atol(args[1]); |
| 3847 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3848 | else if (!strcmp(args[0], "grace")) { /* grace time (ms) */ |
| 3849 | if (*(args[1]) == 0) { |
| 3850 | 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] | 3851 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3852 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3853 | } |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 3854 | err = parse_time_err(args[1], &val, TIME_UNIT_MS); |
| 3855 | if (err) { |
| 3856 | Alert("parsing [%s:%d] : unexpected character '%c' in grace time.\n", |
| 3857 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3858 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3859 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 3860 | } |
| 3861 | curproxy->grace = val; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3862 | } |
| 3863 | else if (!strcmp(args[0], "dispatch")) { /* dispatch address */ |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 3864 | struct sockaddr_storage *sk; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3865 | if (curproxy == &defproxy) { |
| 3866 | 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] | 3867 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3868 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3869 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3870 | else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3871 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3872 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3873 | if (strchr(args[1], ':') == NULL) { |
| 3874 | 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] | 3875 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3876 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3877 | } |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 3878 | sk = str2sa(args[1]); |
| 3879 | if (!sk) { |
| 3880 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[1]); |
| 3881 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3882 | goto out; |
| 3883 | } |
| 3884 | curproxy->dispatch_addr = *sk; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3885 | curproxy->options |= PR_O_DISPATCH; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3886 | } |
| 3887 | else if (!strcmp(args[0], "balance")) { /* set balancing with optional algorithm */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3888 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3889 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3890 | |
Willy Tarreau | a93c74b | 2012-05-08 18:14:39 +0200 | [diff] [blame] | 3891 | if (backend_parse_balance((const char **)args + 1, &errmsg, curproxy) < 0) { |
| 3892 | Alert("parsing [%s:%d] : %s %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3893 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3894 | goto out; |
Willy Tarreau | 2fcb500 | 2007-05-08 13:35:26 +0200 | [diff] [blame] | 3895 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3896 | } |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 3897 | else if (!strcmp(args[0], "hash-type")) { /* set hashing method */ |
| 3898 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 3899 | err_code |= ERR_WARN; |
| 3900 | |
| 3901 | if (strcmp(args[1], "consistent") == 0) { /* use consistent hashing */ |
| 3902 | curproxy->lbprm.algo &= ~BE_LB_HASH_TYPE; |
| 3903 | curproxy->lbprm.algo |= BE_LB_HASH_CONS; |
| 3904 | } |
| 3905 | else if (strcmp(args[1], "map-based") == 0) { /* use map-based hashing */ |
| 3906 | curproxy->lbprm.algo &= ~BE_LB_HASH_TYPE; |
| 3907 | curproxy->lbprm.algo |= BE_LB_HASH_MAP; |
| 3908 | } |
Willy Tarreau | 798a39c | 2010-11-24 15:04:29 +0100 | [diff] [blame] | 3909 | else if (strcmp(args[1], "avalanche") == 0) { /* use full hash before map-based hashing */ |
| 3910 | curproxy->lbprm.algo &= ~BE_LB_HASH_TYPE; |
| 3911 | curproxy->lbprm.algo |= BE_LB_HASH_AVAL; |
| 3912 | } |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 3913 | else { |
Willy Tarreau | 798a39c | 2010-11-24 15:04:29 +0100 | [diff] [blame] | 3914 | 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] | 3915 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3916 | goto out; |
| 3917 | } |
| 3918 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3919 | 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] | 3920 | int cur_arg; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3921 | char *rport, *raddr; |
| 3922 | short realport = 0; |
| 3923 | int do_check = 0, defsrv = (*args[0] == 'd'); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3924 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3925 | if (!defsrv && curproxy == &defproxy) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3926 | 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] | 3927 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3928 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3929 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3930 | else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3931 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3932 | |
| 3933 | if (!*args[2]) { |
| 3934 | Alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n", |
| 3935 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3936 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3937 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3938 | } |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 3939 | |
| 3940 | err = invalid_char(args[1]); |
| 3941 | if (err) { |
| 3942 | Alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n", |
| 3943 | file, linenum, *err, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3944 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3945 | goto out; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 3946 | } |
| 3947 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3948 | if (!defsrv) { |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 3949 | struct sockaddr_storage *sk; |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 3950 | |
Krzysztof Piotr Oledzki | aff01ea | 2010-02-05 20:31:44 +0100 | [diff] [blame] | 3951 | if ((newsrv = (struct server *)calloc(1, sizeof(struct server))) == NULL) { |
| 3952 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 3953 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3954 | goto out; |
| 3955 | } |
| 3956 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3957 | /* the servers are linked backwards first */ |
| 3958 | newsrv->next = curproxy->srv; |
| 3959 | curproxy->srv = newsrv; |
| 3960 | newsrv->proxy = curproxy; |
Willy Tarreau | 8113a5d | 2012-10-04 08:01:43 +0200 | [diff] [blame] | 3961 | newsrv->conf.file = strdup(file); |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3962 | newsrv->conf.line = linenum; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3963 | |
Simon Horman | af51495 | 2011-06-21 14:34:57 +0900 | [diff] [blame] | 3964 | LIST_INIT(&newsrv->actconns); |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3965 | LIST_INIT(&newsrv->pendconns); |
| 3966 | do_check = 0; |
| 3967 | newsrv->state = SRV_RUNNING; /* early server setup */ |
| 3968 | newsrv->last_change = now.tv_sec; |
| 3969 | newsrv->id = strdup(args[1]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3970 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3971 | /* several ways to check the port component : |
David du Colombier | 9842ff1 | 2011-03-17 10:40:28 +0100 | [diff] [blame] | 3972 | * - IP => port=+0, relative (IPv4 only) |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3973 | * - IP: => port=+0, relative |
| 3974 | * - IP:N => port=N, absolute |
| 3975 | * - IP:+N => port=+N, relative |
| 3976 | * - IP:-N => port=-N, relative |
| 3977 | */ |
| 3978 | raddr = strdup(args[2]); |
Willy Tarreau | fab5a43 | 2011-03-04 15:31:53 +0100 | [diff] [blame] | 3979 | rport = strrchr(raddr, ':'); |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3980 | if (rport) { |
| 3981 | *rport++ = 0; |
| 3982 | realport = atol(rport); |
| 3983 | if (!isdigit((unsigned char)*rport)) |
| 3984 | newsrv->state |= SRV_MAPPORTS; |
| 3985 | } else |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3986 | newsrv->state |= SRV_MAPPORTS; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3987 | |
Willy Tarreau | fab5a43 | 2011-03-04 15:31:53 +0100 | [diff] [blame] | 3988 | sk = str2ip(raddr); |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3989 | free(raddr); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 3990 | if (!sk) { |
| 3991 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[2]); |
| 3992 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3993 | goto out; |
| 3994 | } |
| 3995 | newsrv->addr = *sk; |
Willy Tarreau | f4288ee | 2012-09-28 18:13:10 +0200 | [diff] [blame] | 3996 | newsrv->proto = newsrv->check.proto = protocol_by_family(newsrv->addr.ss_family); |
| 3997 | newsrv->xprt = newsrv->check.xprt = &raw_sock; |
Willy Tarreau | 26d8c59 | 2012-05-07 18:12:14 +0200 | [diff] [blame] | 3998 | |
Willy Tarreau | 173e7fb | 2012-09-24 22:47:39 +0200 | [diff] [blame] | 3999 | if (!newsrv->proto) { |
Willy Tarreau | 26d8c59 | 2012-05-07 18:12:14 +0200 | [diff] [blame] | 4000 | Alert("parsing [%s:%d] : Unknown protocol family %d '%s'\n", |
| 4001 | file, linenum, newsrv->addr.ss_family, args[2]); |
| 4002 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4003 | goto out; |
| 4004 | } |
Willy Tarreau | 86ad42c | 2011-08-27 12:29:07 +0200 | [diff] [blame] | 4005 | set_host_port(&newsrv->addr, realport); |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4006 | |
Willy Tarreau | f4288ee | 2012-09-28 18:13:10 +0200 | [diff] [blame] | 4007 | newsrv->check.use_ssl = curproxy->defsrv.check.use_ssl; |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 4008 | newsrv->check.port = curproxy->defsrv.check.port; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4009 | newsrv->inter = curproxy->defsrv.inter; |
| 4010 | newsrv->fastinter = curproxy->defsrv.fastinter; |
| 4011 | newsrv->downinter = curproxy->defsrv.downinter; |
| 4012 | newsrv->rise = curproxy->defsrv.rise; |
| 4013 | newsrv->fall = curproxy->defsrv.fall; |
| 4014 | newsrv->maxqueue = curproxy->defsrv.maxqueue; |
| 4015 | newsrv->minconn = curproxy->defsrv.minconn; |
| 4016 | newsrv->maxconn = curproxy->defsrv.maxconn; |
| 4017 | newsrv->slowstart = curproxy->defsrv.slowstart; |
| 4018 | newsrv->onerror = curproxy->defsrv.onerror; |
| 4019 | newsrv->consecutive_errors_limit |
| 4020 | = curproxy->defsrv.consecutive_errors_limit; |
Emeric Brun | 01f8e2f | 2012-05-18 16:02:00 +0200 | [diff] [blame] | 4021 | #ifdef OPENSSL |
| 4022 | newsrv->use_ssl = curproxy->defsrv.use_ssl; |
| 4023 | #endif |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4024 | newsrv->uweight = newsrv->iweight |
| 4025 | = curproxy->defsrv.iweight; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4026 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4027 | newsrv->health = newsrv->rise; /* up, but will fall down at first failure */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4028 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4029 | cur_arg = 3; |
| 4030 | } else { |
| 4031 | newsrv = &curproxy->defsrv; |
| 4032 | cur_arg = 1; |
| 4033 | } |
Willy Tarreau | 0f03c6f | 2007-03-25 20:46:19 +0200 | [diff] [blame] | 4034 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4035 | while (*args[cur_arg]) { |
Willy Tarreau | dff5543 | 2012-10-10 17:51:05 +0200 | [diff] [blame] | 4036 | if (!defsrv && !strcmp(args[cur_arg], "cookie")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4037 | newsrv->cookie = strdup(args[cur_arg + 1]); |
| 4038 | newsrv->cklen = strlen(args[cur_arg + 1]); |
| 4039 | cur_arg += 2; |
| 4040 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4041 | else if (!defsrv && !strcmp(args[cur_arg], "redir")) { |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 4042 | newsrv->rdr_pfx = strdup(args[cur_arg + 1]); |
| 4043 | newsrv->rdr_len = strlen(args[cur_arg + 1]); |
| 4044 | cur_arg += 2; |
| 4045 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4046 | else if (!strcmp(args[cur_arg], "rise")) { |
Krzysztof Piotr Oledzki | 08ff959 | 2009-09-27 16:17:31 +0200 | [diff] [blame] | 4047 | if (!*args[cur_arg + 1]) { |
| 4048 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 4049 | file, linenum, args[cur_arg]); |
| 4050 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4051 | goto out; |
| 4052 | } |
| 4053 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4054 | newsrv->rise = atol(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 08ff959 | 2009-09-27 16:17:31 +0200 | [diff] [blame] | 4055 | if (newsrv->rise <= 0) { |
| 4056 | Alert("parsing [%s:%d]: '%s' has to be > 0.\n", |
| 4057 | file, linenum, args[cur_arg]); |
| 4058 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4059 | goto out; |
| 4060 | } |
| 4061 | |
Willy Tarreau | 9683909 | 2010-03-29 10:02:24 +0200 | [diff] [blame] | 4062 | if (newsrv->health) |
| 4063 | newsrv->health = newsrv->rise; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4064 | cur_arg += 2; |
| 4065 | } |
| 4066 | else if (!strcmp(args[cur_arg], "fall")) { |
| 4067 | newsrv->fall = atol(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 08ff959 | 2009-09-27 16:17:31 +0200 | [diff] [blame] | 4068 | |
| 4069 | if (!*args[cur_arg + 1]) { |
| 4070 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 4071 | file, linenum, args[cur_arg]); |
| 4072 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4073 | goto out; |
| 4074 | } |
| 4075 | |
| 4076 | if (newsrv->fall <= 0) { |
| 4077 | Alert("parsing [%s:%d]: '%s' has to be > 0.\n", |
| 4078 | file, linenum, args[cur_arg]); |
| 4079 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4080 | goto out; |
| 4081 | } |
| 4082 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4083 | cur_arg += 2; |
| 4084 | } |
| 4085 | else if (!strcmp(args[cur_arg], "inter")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4086 | const char *err = parse_time_err(args[cur_arg + 1], &val, TIME_UNIT_MS); |
| 4087 | if (err) { |
| 4088 | Alert("parsing [%s:%d] : unexpected character '%c' in 'inter' argument of server %s.\n", |
| 4089 | file, linenum, *err, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4090 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4091 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4092 | } |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4093 | if (val <= 0) { |
| 4094 | Alert("parsing [%s:%d]: invalid value %d for argument '%s' of server %s.\n", |
| 4095 | file, linenum, val, args[cur_arg], newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4096 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4097 | goto out; |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4098 | } |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4099 | newsrv->inter = val; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4100 | cur_arg += 2; |
| 4101 | } |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 4102 | else if (!strcmp(args[cur_arg], "fastinter")) { |
| 4103 | const char *err = parse_time_err(args[cur_arg + 1], &val, TIME_UNIT_MS); |
| 4104 | if (err) { |
| 4105 | Alert("parsing [%s:%d]: unexpected character '%c' in 'fastinter' argument of server %s.\n", |
| 4106 | file, linenum, *err, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4107 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4108 | goto out; |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 4109 | } |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4110 | if (val <= 0) { |
| 4111 | Alert("parsing [%s:%d]: invalid value %d for argument '%s' of server %s.\n", |
| 4112 | file, linenum, val, args[cur_arg], newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4113 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4114 | goto out; |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4115 | } |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 4116 | newsrv->fastinter = val; |
| 4117 | cur_arg += 2; |
| 4118 | } |
| 4119 | else if (!strcmp(args[cur_arg], "downinter")) { |
| 4120 | const char *err = parse_time_err(args[cur_arg + 1], &val, TIME_UNIT_MS); |
| 4121 | if (err) { |
| 4122 | Alert("parsing [%s:%d]: unexpected character '%c' in 'downinter' argument of server %s.\n", |
| 4123 | file, linenum, *err, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4124 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4125 | goto out; |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 4126 | } |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4127 | if (val <= 0) { |
| 4128 | Alert("parsing [%s:%d]: invalid value %d for argument '%s' of server %s.\n", |
| 4129 | file, linenum, val, args[cur_arg], newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4130 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4131 | goto out; |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4132 | } |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 4133 | newsrv->downinter = val; |
| 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], "addr")) { |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4137 | struct sockaddr_storage *sk = str2sa(args[cur_arg + 1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4138 | if (!sk) { |
| 4139 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[cur_arg + 1]); |
| 4140 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4141 | goto out; |
| 4142 | } |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 4143 | newsrv->check.addr = *sk; |
Willy Tarreau | 2ea3abb | 2007-03-25 16:45:16 +0200 | [diff] [blame] | 4144 | cur_arg += 2; |
| 4145 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4146 | else if (!strcmp(args[cur_arg], "port")) { |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 4147 | newsrv->check.port = atol(args[cur_arg + 1]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4148 | cur_arg += 2; |
| 4149 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4150 | else if (!defsrv && !strcmp(args[cur_arg], "backup")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4151 | newsrv->state |= SRV_BACKUP; |
| 4152 | cur_arg ++; |
| 4153 | } |
Simon Horman | fa46168 | 2011-06-25 09:39:49 +0900 | [diff] [blame] | 4154 | else if (!defsrv && !strcmp(args[cur_arg], "non-stick")) { |
| 4155 | newsrv->state |= SRV_NON_STICK; |
| 4156 | cur_arg ++; |
| 4157 | } |
Willy Tarreau | 5ab04ec | 2011-03-20 10:32:26 +0100 | [diff] [blame] | 4158 | else if (!defsrv && !strcmp(args[cur_arg], "send-proxy")) { |
| 4159 | newsrv->state |= SRV_SEND_PROXY; |
| 4160 | cur_arg ++; |
| 4161 | } |
Willy Tarreau | 6c16adc | 2012-10-05 00:04:16 +0200 | [diff] [blame] | 4162 | else if (!defsrv && !strcmp(args[cur_arg], "check-send-proxy")) { |
| 4163 | newsrv->check.send_proxy = 1; |
| 4164 | cur_arg ++; |
| 4165 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4166 | else if (!strcmp(args[cur_arg], "weight")) { |
| 4167 | int w; |
| 4168 | w = atol(args[cur_arg + 1]); |
Willy Tarreau | 6704d67 | 2009-06-15 10:56:05 +0200 | [diff] [blame] | 4169 | if (w < 0 || w > 256) { |
| 4170 | 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] | 4171 | file, linenum, newsrv->id, w); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4172 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4173 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4174 | } |
Willy Tarreau | 975c50b | 2009-10-10 19:34:06 +0200 | [diff] [blame] | 4175 | newsrv->uweight = newsrv->iweight = w; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4176 | cur_arg += 2; |
| 4177 | } |
| 4178 | else if (!strcmp(args[cur_arg], "minconn")) { |
| 4179 | newsrv->minconn = atol(args[cur_arg + 1]); |
| 4180 | cur_arg += 2; |
| 4181 | } |
| 4182 | else if (!strcmp(args[cur_arg], "maxconn")) { |
| 4183 | newsrv->maxconn = atol(args[cur_arg + 1]); |
| 4184 | cur_arg += 2; |
| 4185 | } |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 4186 | else if (!strcmp(args[cur_arg], "maxqueue")) { |
| 4187 | newsrv->maxqueue = atol(args[cur_arg + 1]); |
| 4188 | cur_arg += 2; |
| 4189 | } |
Willy Tarreau | 9909fc1 | 2007-11-30 17:42:05 +0100 | [diff] [blame] | 4190 | else if (!strcmp(args[cur_arg], "slowstart")) { |
| 4191 | /* slowstart is stored in seconds */ |
Willy Tarreau | 3259e33 | 2007-12-03 01:51:45 +0100 | [diff] [blame] | 4192 | 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] | 4193 | if (err) { |
| 4194 | Alert("parsing [%s:%d] : unexpected character '%c' in 'slowstart' argument of server %s.\n", |
| 4195 | file, linenum, *err, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4196 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4197 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4198 | } |
Willy Tarreau | 4554bc1 | 2010-03-26 10:40:49 +0100 | [diff] [blame] | 4199 | if (val < 0) { |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4200 | Alert("parsing [%s:%d]: invalid value %d for argument '%s' of server %s.\n", |
| 4201 | file, linenum, val, args[cur_arg], newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4202 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4203 | goto out; |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4204 | } |
Willy Tarreau | 3259e33 | 2007-12-03 01:51:45 +0100 | [diff] [blame] | 4205 | newsrv->slowstart = (val + 999) / 1000; |
Willy Tarreau | 9909fc1 | 2007-11-30 17:42:05 +0100 | [diff] [blame] | 4206 | cur_arg += 2; |
| 4207 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4208 | else if (!defsrv && !strcmp(args[cur_arg], "track")) { |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4209 | |
| 4210 | if (!*args[cur_arg + 1]) { |
| 4211 | Alert("parsing [%s:%d]: 'track' expects [<proxy>/]<server> as argument.\n", |
| 4212 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4213 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4214 | goto out; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4215 | } |
| 4216 | |
| 4217 | newsrv->trackit = strdup(args[cur_arg + 1]); |
| 4218 | |
| 4219 | cur_arg += 2; |
| 4220 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4221 | else if (!defsrv && !strcmp(args[cur_arg], "check")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4222 | global.maxsock++; |
| 4223 | do_check = 1; |
| 4224 | cur_arg += 1; |
| 4225 | } |
Willy Tarreau | 9683909 | 2010-03-29 10:02:24 +0200 | [diff] [blame] | 4226 | else if (!defsrv && !strcmp(args[cur_arg], "disabled")) { |
| 4227 | newsrv->state |= SRV_MAINTAIN; |
| 4228 | newsrv->state &= ~SRV_RUNNING; |
| 4229 | newsrv->health = 0; |
| 4230 | cur_arg += 1; |
Emeric Brun | c0ff492 | 2012-09-28 19:37:02 +0200 | [diff] [blame] | 4231 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4232 | else if (!defsrv && !strcmp(args[cur_arg], "observe")) { |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 4233 | if (!strcmp(args[cur_arg + 1], "none")) |
| 4234 | newsrv->observe = HANA_OBS_NONE; |
| 4235 | else if (!strcmp(args[cur_arg + 1], "layer4")) |
| 4236 | newsrv->observe = HANA_OBS_LAYER4; |
| 4237 | else if (!strcmp(args[cur_arg + 1], "layer7")) { |
| 4238 | if (curproxy->mode != PR_MODE_HTTP) { |
| 4239 | Alert("parsing [%s:%d]: '%s' can only be used in http proxies.\n", |
| 4240 | file, linenum, args[cur_arg + 1]); |
| 4241 | err_code |= ERR_ALERT; |
| 4242 | } |
| 4243 | newsrv->observe = HANA_OBS_LAYER7; |
| 4244 | } |
| 4245 | else { |
| 4246 | Alert("parsing [%s:%d]: '%s' expects one of 'none', " |
Willy Tarreau | 53621e0 | 2010-10-22 14:53:40 +0200 | [diff] [blame] | 4247 | "'layer4', 'layer7' but got '%s'\n", |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 4248 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
| 4249 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4250 | goto out; |
| 4251 | } |
| 4252 | |
| 4253 | cur_arg += 2; |
| 4254 | } |
| 4255 | else if (!strcmp(args[cur_arg], "on-error")) { |
| 4256 | if (!strcmp(args[cur_arg + 1], "fastinter")) |
| 4257 | newsrv->onerror = HANA_ONERR_FASTINTER; |
| 4258 | else if (!strcmp(args[cur_arg + 1], "fail-check")) |
| 4259 | newsrv->onerror = HANA_ONERR_FAILCHK; |
| 4260 | else if (!strcmp(args[cur_arg + 1], "sudden-death")) |
| 4261 | newsrv->onerror = HANA_ONERR_SUDDTH; |
| 4262 | else if (!strcmp(args[cur_arg + 1], "mark-down")) |
| 4263 | newsrv->onerror = HANA_ONERR_MARKDWN; |
| 4264 | else { |
| 4265 | Alert("parsing [%s:%d]: '%s' expects one of 'fastinter', " |
Willy Tarreau | 53621e0 | 2010-10-22 14:53:40 +0200 | [diff] [blame] | 4266 | "'fail-check', 'sudden-death' or 'mark-down' but got '%s'\n", |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 4267 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
| 4268 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4269 | goto out; |
| 4270 | } |
| 4271 | |
| 4272 | cur_arg += 2; |
| 4273 | } |
Simon Horman | e0d1bfb | 2011-06-21 14:34:58 +0900 | [diff] [blame] | 4274 | else if (!strcmp(args[cur_arg], "on-marked-down")) { |
| 4275 | if (!strcmp(args[cur_arg + 1], "shutdown-sessions")) |
| 4276 | newsrv->onmarkeddown = HANA_ONMARKEDDOWN_SHUTDOWNSESSIONS; |
| 4277 | else { |
| 4278 | Alert("parsing [%s:%d]: '%s' expects 'shutdown-sessions' but got '%s'\n", |
| 4279 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
| 4280 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4281 | goto out; |
| 4282 | } |
| 4283 | |
| 4284 | cur_arg += 2; |
| 4285 | } |
Justin Karneges | eb2c24a | 2012-05-24 15:28:52 -0700 | [diff] [blame] | 4286 | else if (!strcmp(args[cur_arg], "on-marked-up")) { |
| 4287 | if (!strcmp(args[cur_arg + 1], "shutdown-backup-sessions")) |
| 4288 | newsrv->onmarkedup = HANA_ONMARKEDUP_SHUTDOWNBACKUPSESSIONS; |
| 4289 | else { |
| 4290 | Alert("parsing [%s:%d]: '%s' expects 'shutdown-backup-sessions' but got '%s'\n", |
| 4291 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
| 4292 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4293 | goto out; |
| 4294 | } |
| 4295 | |
| 4296 | cur_arg += 2; |
| 4297 | } |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 4298 | else if (!strcmp(args[cur_arg], "error-limit")) { |
| 4299 | if (!*args[cur_arg + 1]) { |
| 4300 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 4301 | file, linenum, args[cur_arg]); |
| 4302 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4303 | goto out; |
| 4304 | } |
| 4305 | |
| 4306 | newsrv->consecutive_errors_limit = atoi(args[cur_arg + 1]); |
| 4307 | |
| 4308 | if (newsrv->consecutive_errors_limit <= 0) { |
| 4309 | Alert("parsing [%s:%d]: %s has to be > 0.\n", |
| 4310 | file, linenum, args[cur_arg]); |
| 4311 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4312 | goto out; |
| 4313 | } |
Willy Tarreau | f53b25d | 2010-03-15 19:40:37 +0100 | [diff] [blame] | 4314 | cur_arg += 2; |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 4315 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4316 | 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] | 4317 | int port_low, port_high; |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4318 | struct sockaddr_storage *sk; |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4319 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4320 | if (!*args[cur_arg + 1]) { |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4321 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 4322 | 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] | 4323 | file, linenum, "source", "usesrc"); |
| 4324 | #else |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 4325 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>[-<port>]] as argument.\n", |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4326 | file, linenum, "source"); |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 4327 | #endif |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4328 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4329 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4330 | } |
| 4331 | newsrv->state |= SRV_BIND_SRC; |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4332 | sk = str2sa_range(args[cur_arg + 1], &port_low, &port_high); |
| 4333 | if (!sk) { |
| 4334 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[cur_arg + 1]); |
| 4335 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4336 | goto out; |
| 4337 | } |
| 4338 | newsrv->source_addr = *sk; |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 4339 | |
| 4340 | if (port_low != port_high) { |
| 4341 | int i; |
| 4342 | if (port_low <= 0 || port_low > 65535 || |
| 4343 | port_high <= 0 || port_high > 65535 || |
| 4344 | port_low > port_high) { |
| 4345 | Alert("parsing [%s:%d] : invalid source port range %d-%d.\n", |
| 4346 | file, linenum, port_low, port_high); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4347 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4348 | goto out; |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 4349 | } |
| 4350 | newsrv->sport_range = port_range_alloc_range(port_high - port_low + 1); |
| 4351 | for (i = 0; i < newsrv->sport_range->size; i++) |
| 4352 | newsrv->sport_range->ports[i] = port_low + i; |
| 4353 | } |
| 4354 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4355 | cur_arg += 2; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4356 | while (*(args[cur_arg])) { |
| 4357 | if (!strcmp(args[cur_arg], "usesrc")) { /* address to use outside */ |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4358 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) |
| 4359 | #if !defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4360 | if (newsrv->source_addr.sin_addr.s_addr == INADDR_ANY) { |
| 4361 | Alert("parsing [%s:%d] : '%s' requires an explicit '%s' address.\n", |
| 4362 | file, linenum, "usesrc", "source"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4363 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4364 | goto out; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4365 | } |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4366 | #endif |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4367 | if (!*args[cur_arg + 1]) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4368 | 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] | 4369 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4370 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4371 | goto out; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4372 | } |
| 4373 | if (!strcmp(args[cur_arg + 1], "client")) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4374 | newsrv->state &= ~SRV_TPROXY_MASK; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4375 | newsrv->state |= SRV_TPROXY_CLI; |
| 4376 | } else if (!strcmp(args[cur_arg + 1], "clientip")) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4377 | newsrv->state &= ~SRV_TPROXY_MASK; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4378 | newsrv->state |= SRV_TPROXY_CIP; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4379 | } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) { |
| 4380 | char *name, *end; |
| 4381 | |
| 4382 | name = args[cur_arg+1] + 7; |
| 4383 | while (isspace(*name)) |
| 4384 | name++; |
| 4385 | |
| 4386 | end = name; |
| 4387 | while (*end && !isspace(*end) && *end != ',' && *end != ')') |
| 4388 | end++; |
| 4389 | |
| 4390 | newsrv->state &= ~SRV_TPROXY_MASK; |
| 4391 | newsrv->state |= SRV_TPROXY_DYN; |
| 4392 | newsrv->bind_hdr_name = calloc(1, end - name + 1); |
| 4393 | newsrv->bind_hdr_len = end - name; |
| 4394 | memcpy(newsrv->bind_hdr_name, name, end - name); |
| 4395 | newsrv->bind_hdr_name[end-name] = '\0'; |
| 4396 | newsrv->bind_hdr_occ = -1; |
| 4397 | |
| 4398 | /* now look for an occurrence number */ |
| 4399 | while (isspace(*end)) |
| 4400 | end++; |
| 4401 | if (*end == ',') { |
| 4402 | end++; |
| 4403 | name = end; |
| 4404 | if (*end == '-') |
| 4405 | end++; |
| 4406 | while (isdigit(*end)) |
| 4407 | end++; |
| 4408 | newsrv->bind_hdr_occ = strl2ic(name, end-name); |
| 4409 | } |
| 4410 | |
| 4411 | if (newsrv->bind_hdr_occ < -MAX_HDR_HISTORY) { |
| 4412 | Alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative" |
| 4413 | " occurrences values smaller than %d.\n", |
| 4414 | file, linenum, MAX_HDR_HISTORY); |
| 4415 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4416 | goto out; |
| 4417 | } |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4418 | } else { |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4419 | struct sockaddr_storage *sk = str2sa(args[cur_arg + 1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4420 | if (!sk) { |
| 4421 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[cur_arg + 1]); |
| 4422 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4423 | goto out; |
| 4424 | } |
| 4425 | newsrv->tproxy_addr = *sk; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4426 | newsrv->state |= SRV_TPROXY_ADDR; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4427 | } |
| 4428 | global.last_checks |= LSTCHK_NETADM; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4429 | #if !defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4430 | global.last_checks |= LSTCHK_CTTPROXY; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4431 | #endif |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4432 | cur_arg += 2; |
| 4433 | continue; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4434 | #else /* no TPROXY support */ |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4435 | 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] | 4436 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4437 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4438 | goto out; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4439 | #endif /* defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) */ |
| 4440 | } /* "usesrc" */ |
| 4441 | |
| 4442 | if (!strcmp(args[cur_arg], "interface")) { /* specifically bind to this interface */ |
| 4443 | #ifdef SO_BINDTODEVICE |
| 4444 | if (!*args[cur_arg + 1]) { |
| 4445 | Alert("parsing [%s:%d] : '%s' : missing interface name.\n", |
| 4446 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4447 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4448 | goto out; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4449 | } |
| 4450 | if (newsrv->iface_name) |
| 4451 | free(newsrv->iface_name); |
| 4452 | |
| 4453 | newsrv->iface_name = strdup(args[cur_arg + 1]); |
| 4454 | newsrv->iface_len = strlen(newsrv->iface_name); |
| 4455 | global.last_checks |= LSTCHK_NETADM; |
| 4456 | #else |
| 4457 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 4458 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4459 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4460 | goto out; |
Willy Tarreau | 77074d5 | 2006-11-12 23:57:19 +0100 | [diff] [blame] | 4461 | #endif |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4462 | cur_arg += 2; |
| 4463 | continue; |
| 4464 | } |
| 4465 | /* this keyword in not an option of "source" */ |
| 4466 | break; |
| 4467 | } /* while */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4468 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4469 | 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] | 4470 | Alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n", |
| 4471 | file, linenum, "usesrc", "source"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4472 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4473 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 4474 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4475 | else { |
Willy Tarreau | d0d6059 | 2012-10-10 08:57:40 +0200 | [diff] [blame] | 4476 | static int srv_dumped; |
| 4477 | struct srv_kw *kw; |
| 4478 | char *err; |
| 4479 | |
| 4480 | kw = srv_find_kw(args[cur_arg]); |
| 4481 | if (kw) { |
| 4482 | char *err = NULL; |
| 4483 | int code; |
| 4484 | |
| 4485 | if (!kw->parse) { |
| 4486 | Alert("parsing [%s:%d] : '%s %s' : '%s' option is not implemented in this version (check build options).\n", |
| 4487 | file, linenum, args[0], args[1], args[cur_arg]); |
| 4488 | cur_arg += 1 + kw->skip ; |
| 4489 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4490 | goto out; |
| 4491 | } |
| 4492 | |
| 4493 | if (defsrv && !kw->default_ok) { |
| 4494 | Alert("parsing [%s:%d] : '%s %s' : '%s' option is not accepted in default-server sections.\n", |
| 4495 | file, linenum, args[0], args[1], args[cur_arg]); |
| 4496 | cur_arg += 1 + kw->skip ; |
| 4497 | err_code |= ERR_ALERT; |
| 4498 | continue; |
| 4499 | } |
| 4500 | |
| 4501 | code = kw->parse(args, &cur_arg, curproxy, newsrv, &err); |
| 4502 | err_code |= code; |
| 4503 | |
| 4504 | if (code) { |
| 4505 | if (err && *err) { |
| 4506 | indent_msg(&err, 2); |
| 4507 | Alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], err); |
| 4508 | } |
| 4509 | else |
| 4510 | Alert("parsing [%s:%d] : '%s %s' : error encountered while processing '%s'.\n", |
| 4511 | file, linenum, args[0], args[1], args[cur_arg]); |
| 4512 | if (code & ERR_FATAL) { |
| 4513 | free(err); |
| 4514 | cur_arg += 1 + kw->skip; |
| 4515 | goto out; |
| 4516 | } |
| 4517 | } |
| 4518 | free(err); |
| 4519 | cur_arg += 1 + kw->skip; |
| 4520 | continue; |
| 4521 | } |
| 4522 | |
| 4523 | err = NULL; |
| 4524 | if (!srv_dumped) { |
| 4525 | srv_dump_kws(&err); |
| 4526 | indent_msg(&err, 4); |
| 4527 | srv_dumped = 1; |
| 4528 | } |
| 4529 | |
| 4530 | Alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'.%s%s\n", |
| 4531 | file, linenum, args[0], args[1], args[cur_arg], |
| 4532 | err ? " Registered keywords :" : "", err ? err : ""); |
| 4533 | free(err); |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4534 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4535 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4536 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4537 | } |
| 4538 | } |
| 4539 | |
| 4540 | if (do_check) { |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4541 | if (newsrv->trackit) { |
| 4542 | Alert("parsing [%s:%d]: unable to enable checks and tracking at the same time!\n", |
| 4543 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4544 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4545 | goto out; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4546 | } |
| 4547 | |
Willy Tarreau | f4288ee | 2012-09-28 18:13:10 +0200 | [diff] [blame] | 4548 | /* If neither a port nor an addr was specified and no check transport |
| 4549 | * layer is forced, then the transport layer used by the checks is the |
| 4550 | * same as for the production traffic. Otherwise we use raw_sock by |
| 4551 | * default, unless one is specified. |
| 4552 | */ |
Willy Tarreau | 6c16adc | 2012-10-05 00:04:16 +0200 | [diff] [blame] | 4553 | if (!newsrv->check.port && !is_addr(&newsrv->check.addr)) { |
Willy Tarreau | 7151633 | 2012-10-10 23:01:14 +0200 | [diff] [blame] | 4554 | #ifdef USE_OPENSSL |
Willy Tarreau | f4288ee | 2012-09-28 18:13:10 +0200 | [diff] [blame] | 4555 | newsrv->check.use_ssl |= newsrv->use_ssl; |
Willy Tarreau | 7151633 | 2012-10-10 23:01:14 +0200 | [diff] [blame] | 4556 | #endif |
Willy Tarreau | 6c16adc | 2012-10-05 00:04:16 +0200 | [diff] [blame] | 4557 | newsrv->check.send_proxy |= (newsrv->state & SRV_SEND_PROXY); |
| 4558 | } |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 4559 | /* try to get the port from check.addr if check.port not set */ |
| 4560 | if (!newsrv->check.port) |
| 4561 | newsrv->check.port = get_host_port(&newsrv->check.addr); |
Willy Tarreau | 0f03c6f | 2007-03-25 20:46:19 +0200 | [diff] [blame] | 4562 | |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 4563 | if (!newsrv->check.port && !(newsrv->state & SRV_MAPPORTS)) |
| 4564 | newsrv->check.port = realport; /* by default */ |
| 4565 | if (!newsrv->check.port) { |
Willy Tarreau | ef00b50 | 2007-01-07 02:40:09 +0100 | [diff] [blame] | 4566 | /* not yet valid, because no port was set on |
| 4567 | * the server either. We'll check if we have |
| 4568 | * a known port on the first listener. |
| 4569 | */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 4570 | struct listener *l; |
| 4571 | |
| 4572 | list_for_each_entry(l, &curproxy->conf.listeners, by_fe) { |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 4573 | newsrv->check.port = get_host_port(&l->addr); |
| 4574 | if (newsrv->check.port) |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 4575 | break; |
| 4576 | } |
Willy Tarreau | ef00b50 | 2007-01-07 02:40:09 +0100 | [diff] [blame] | 4577 | } |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 4578 | if (!newsrv->check.port) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4579 | Alert("parsing [%s:%d] : server %s has neither service port nor check port. Check has been disabled.\n", |
| 4580 | file, linenum, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4581 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4582 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4583 | } |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 4584 | |
Willy Tarreau | 1ae1b7b | 2012-09-28 15:28:30 +0200 | [diff] [blame] | 4585 | /* Allocate buffer for check requests... */ |
| 4586 | if ((newsrv->check.bi = calloc(sizeof(struct buffer) + global.tune.chksize, sizeof(char))) == NULL) { |
Cyril Bonté | c9f825f | 2010-03-17 18:56:31 +0100 | [diff] [blame] | 4587 | Alert("parsing [%s:%d] : out of memory while allocating check buffer.\n", file, linenum); |
| 4588 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4589 | goto out; |
| 4590 | } |
Willy Tarreau | 1ae1b7b | 2012-09-28 15:28:30 +0200 | [diff] [blame] | 4591 | newsrv->check.bi->size = global.tune.chksize; |
| 4592 | |
| 4593 | /* Allocate buffer for check responses... */ |
| 4594 | if ((newsrv->check.bo = calloc(sizeof(struct buffer) + global.tune.chksize, sizeof(char))) == NULL) { |
| 4595 | Alert("parsing [%s:%d] : out of memory while allocating check buffer.\n", file, linenum); |
| 4596 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4597 | goto out; |
| 4598 | } |
| 4599 | newsrv->check.bo->size = global.tune.chksize; |
Cyril Bonté | c9f825f | 2010-03-17 18:56:31 +0100 | [diff] [blame] | 4600 | |
Willy Tarreau | da92e2f | 2012-07-06 09:40:59 +0200 | [diff] [blame] | 4601 | /* Allocate buffer for partial check results... */ |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 4602 | if ((newsrv->check.conn = calloc(1, sizeof(struct connection))) == NULL) { |
Willy Tarreau | da92e2f | 2012-07-06 09:40:59 +0200 | [diff] [blame] | 4603 | Alert("parsing [%s:%d] : out of memory while allocating check connection.\n", file, linenum); |
| 4604 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4605 | goto out; |
| 4606 | } |
| 4607 | |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 4608 | newsrv->check.conn->t.sock.fd = -1; /* no check in progress yet */ |
| 4609 | newsrv->check.status = HCHK_STATUS_INI; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4610 | newsrv->state |= SRV_CHECKED; |
| 4611 | } |
| 4612 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4613 | if (!defsrv) { |
| 4614 | if (newsrv->state & SRV_BACKUP) |
| 4615 | curproxy->srv_bck++; |
| 4616 | else |
| 4617 | curproxy->srv_act++; |
Willy Tarreau | b625a08 | 2007-11-26 01:15:43 +0100 | [diff] [blame] | 4618 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4619 | newsrv->prev_state = newsrv->state; |
| 4620 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 4621 | } |
| 4622 | |
| 4623 | else if (strcmp(args[0], "unique-id-format") == 0) { |
| 4624 | if (!*(args[1])) { |
| 4625 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 4626 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4627 | goto out; |
| 4628 | } |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 4629 | free(curproxy->uniqueid_format_string); |
| 4630 | curproxy->uniqueid_format_string = strdup(args[1]); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4631 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 4632 | |
| 4633 | else if (strcmp(args[0], "unique-id-header") == 0) { |
| 4634 | if (!*(args[1])) { |
| 4635 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 4636 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4637 | goto out; |
| 4638 | } |
| 4639 | free(curproxy->header_unique_id); |
| 4640 | curproxy->header_unique_id = strdup(args[1]); |
| 4641 | } |
| 4642 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4643 | else if (strcmp(args[0], "log-format") == 0) { |
| 4644 | if (!*(args[1])) { |
| 4645 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 4646 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4647 | goto out; |
| 4648 | } |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 4649 | |
| 4650 | if (curproxy->logformat_string != default_http_log_format && |
| 4651 | curproxy->logformat_string != default_tcp_log_format && |
| 4652 | curproxy->logformat_string != clf_http_log_format) |
| 4653 | free(curproxy->logformat_string); |
| 4654 | curproxy->logformat_string = strdup(args[1]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4655 | } |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4656 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4657 | else if (!strcmp(args[0], "log") && kwm == KWM_NO) { |
| 4658 | /* delete previous herited or defined syslog servers */ |
| 4659 | struct logsrv *back; |
| 4660 | |
| 4661 | if (*(args[1]) != 0) { |
| 4662 | Alert("parsing [%s:%d]:%s : 'no log' does not expect arguments.\n", file, linenum, args[1]); |
| 4663 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4664 | goto out; |
| 4665 | } |
| 4666 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4667 | list_for_each_entry_safe(tmplogsrv, back, &curproxy->logsrvs, list) { |
| 4668 | LIST_DEL(&tmplogsrv->list); |
| 4669 | free(tmplogsrv); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4670 | } |
| 4671 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4672 | else if (!strcmp(args[0], "log")) { /* syslog server address */ |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4673 | struct logsrv *logsrv; |
| 4674 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4675 | if (*(args[1]) && *(args[2]) == 0 && !strcmp(args[1], "global")) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4676 | /* copy global.logrsvs linked list to the end of curproxy->logsrvs */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4677 | list_for_each_entry(tmplogsrv, &global.logsrvs, list) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4678 | struct logsrv *node = malloc(sizeof(struct logsrv)); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4679 | memcpy(node, tmplogsrv, sizeof(struct logsrv)); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4680 | LIST_INIT(&node->list); |
| 4681 | LIST_ADDQ(&curproxy->logsrvs, &node->list); |
| 4682 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4683 | } |
| 4684 | else if (*(args[1]) && *(args[2])) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4685 | |
| 4686 | logsrv = calloc(1, sizeof(struct logsrv)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4687 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4688 | logsrv->facility = get_log_facility(args[2]); |
| 4689 | if (logsrv->facility < 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4690 | 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] | 4691 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4692 | goto out; |
| 4693 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4694 | } |
| 4695 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4696 | logsrv->level = 7; /* max syslog level = debug */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4697 | if (*(args[3])) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4698 | logsrv->level = get_log_level(args[3]); |
| 4699 | if (logsrv->level < 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4700 | 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] | 4701 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4702 | goto out; |
| 4703 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4704 | } |
| 4705 | } |
| 4706 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4707 | logsrv->minlvl = 0; /* limit syslog level to this level (emerg) */ |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 4708 | if (*(args[4])) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4709 | logsrv->minlvl = get_log_level(args[4]); |
| 4710 | if (logsrv->level < 0) { |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 4711 | 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] | 4712 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4713 | goto out; |
| 4714 | |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 4715 | } |
| 4716 | } |
| 4717 | |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 4718 | if (args[1][0] == '/') { |
David du Colombier | 11bcb6c | 2011-03-24 12:23:00 +0100 | [diff] [blame] | 4719 | struct sockaddr_storage *sk = (struct sockaddr_storage *)str2sun(args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4720 | if (!sk) { |
| 4721 | 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] | 4722 | args[1], (int)sizeof(((struct sockaddr_un *)sk)->sun_path) - 1); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4723 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4724 | goto out; |
| 4725 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4726 | logsrv->addr = *sk; |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 4727 | } else { |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4728 | struct sockaddr_storage *sk = str2sa(args[1]); |
David du Colombier | 11bcb6c | 2011-03-24 12:23:00 +0100 | [diff] [blame] | 4729 | if (!sk) { |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4730 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[1]); |
| 4731 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4732 | goto out; |
| 4733 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4734 | logsrv->addr = *sk; |
| 4735 | if (!get_host_port(&logsrv->addr)) |
| 4736 | set_host_port(&logsrv->addr, SYSLOG_PORT); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4737 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4738 | |
| 4739 | LIST_ADDQ(&curproxy->logsrvs, &logsrv->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4740 | } |
| 4741 | else { |
| 4742 | Alert("parsing [%s:%d] : 'log' expects either <address[:port]> and <facility> or 'global' as arguments.\n", |
| 4743 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4744 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4745 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4746 | } |
| 4747 | } |
| 4748 | 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] | 4749 | int cur_arg; |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4750 | struct sockaddr_storage *sk; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4751 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4752 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4753 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4754 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4755 | if (!*args[1]) { |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4756 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optionally '%s' <addr>, and '%s' <name>.\n", |
| 4757 | file, linenum, "source", "usesrc", "interface"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4758 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4759 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4760 | } |
Willy Tarreau | 368480c | 2009-03-01 08:27:21 +0100 | [diff] [blame] | 4761 | |
| 4762 | /* we must first clear any optional default setting */ |
| 4763 | curproxy->options &= ~PR_O_TPXY_MASK; |
| 4764 | free(curproxy->iface_name); |
| 4765 | curproxy->iface_name = NULL; |
| 4766 | curproxy->iface_len = 0; |
| 4767 | |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4768 | sk = str2sa(args[1]); |
| 4769 | if (!sk) { |
| 4770 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[1]); |
| 4771 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4772 | goto out; |
| 4773 | } |
| 4774 | curproxy->source_addr = *sk; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4775 | curproxy->options |= PR_O_BIND_SRC; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4776 | |
| 4777 | cur_arg = 2; |
| 4778 | while (*(args[cur_arg])) { |
| 4779 | if (!strcmp(args[cur_arg], "usesrc")) { /* address to use outside */ |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4780 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) |
| 4781 | #if !defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4782 | if (curproxy->source_addr.sin_addr.s_addr == INADDR_ANY) { |
| 4783 | Alert("parsing [%s:%d] : '%s' requires an explicit 'source' address.\n", |
| 4784 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4785 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4786 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4787 | } |
| 4788 | #endif |
| 4789 | if (!*args[cur_arg + 1]) { |
| 4790 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n", |
| 4791 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4792 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4793 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4794 | } |
| 4795 | |
| 4796 | if (!strcmp(args[cur_arg + 1], "client")) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4797 | curproxy->options &= ~PR_O_TPXY_MASK; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4798 | curproxy->options |= PR_O_TPXY_CLI; |
| 4799 | } else if (!strcmp(args[cur_arg + 1], "clientip")) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4800 | curproxy->options &= ~PR_O_TPXY_MASK; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4801 | curproxy->options |= PR_O_TPXY_CIP; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4802 | } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) { |
| 4803 | char *name, *end; |
| 4804 | |
| 4805 | name = args[cur_arg+1] + 7; |
| 4806 | while (isspace(*name)) |
| 4807 | name++; |
| 4808 | |
| 4809 | end = name; |
| 4810 | while (*end && !isspace(*end) && *end != ',' && *end != ')') |
| 4811 | end++; |
| 4812 | |
| 4813 | curproxy->options &= ~PR_O_TPXY_MASK; |
| 4814 | curproxy->options |= PR_O_TPXY_DYN; |
| 4815 | curproxy->bind_hdr_name = calloc(1, end - name + 1); |
| 4816 | curproxy->bind_hdr_len = end - name; |
| 4817 | memcpy(curproxy->bind_hdr_name, name, end - name); |
| 4818 | curproxy->bind_hdr_name[end-name] = '\0'; |
| 4819 | curproxy->bind_hdr_occ = -1; |
| 4820 | |
| 4821 | /* now look for an occurrence number */ |
| 4822 | while (isspace(*end)) |
| 4823 | end++; |
| 4824 | if (*end == ',') { |
| 4825 | end++; |
| 4826 | name = end; |
| 4827 | if (*end == '-') |
| 4828 | end++; |
| 4829 | while (isdigit(*end)) |
| 4830 | end++; |
| 4831 | curproxy->bind_hdr_occ = strl2ic(name, end-name); |
| 4832 | } |
| 4833 | |
| 4834 | if (curproxy->bind_hdr_occ < -MAX_HDR_HISTORY) { |
| 4835 | Alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative" |
| 4836 | " occurrences values smaller than %d.\n", |
| 4837 | file, linenum, MAX_HDR_HISTORY); |
| 4838 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4839 | goto out; |
| 4840 | } |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4841 | } else { |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4842 | struct sockaddr_storage *sk = str2sa(args[cur_arg + 1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4843 | if (!sk) { |
| 4844 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[cur_arg + 1]); |
| 4845 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4846 | goto out; |
| 4847 | } |
| 4848 | curproxy->tproxy_addr = *sk; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4849 | curproxy->options |= PR_O_TPXY_ADDR; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4850 | } |
| 4851 | global.last_checks |= LSTCHK_NETADM; |
| 4852 | #if !defined(CONFIG_HAP_LINUX_TPROXY) |
| 4853 | global.last_checks |= LSTCHK_CTTPROXY; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4854 | #endif |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4855 | #else /* no TPROXY support */ |
| 4856 | 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] | 4857 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4858 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4859 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4860 | #endif |
| 4861 | cur_arg += 2; |
| 4862 | continue; |
Willy Tarreau | 77074d5 | 2006-11-12 23:57:19 +0100 | [diff] [blame] | 4863 | } |
| 4864 | |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4865 | if (!strcmp(args[cur_arg], "interface")) { /* specifically bind to this interface */ |
| 4866 | #ifdef SO_BINDTODEVICE |
| 4867 | if (!*args[cur_arg + 1]) { |
| 4868 | Alert("parsing [%s:%d] : '%s' : missing interface name.\n", |
| 4869 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4870 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4871 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4872 | } |
| 4873 | if (curproxy->iface_name) |
| 4874 | free(curproxy->iface_name); |
| 4875 | |
| 4876 | curproxy->iface_name = strdup(args[cur_arg + 1]); |
| 4877 | curproxy->iface_len = strlen(curproxy->iface_name); |
| 4878 | global.last_checks |= LSTCHK_NETADM; |
| 4879 | #else |
| 4880 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 4881 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4882 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4883 | goto out; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4884 | #endif |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4885 | cur_arg += 2; |
| 4886 | continue; |
| 4887 | } |
| 4888 | Alert("parsing [%s:%d] : '%s' only supports optional keywords '%s' and '%s'.\n", |
Willy Tarreau | 3631d41 | 2012-09-25 16:31:00 +0200 | [diff] [blame] | 4889 | file, linenum, args[0], "interface", "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4890 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4891 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 4892 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4893 | } |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 4894 | else if (!strcmp(args[0], "usesrc")) { /* address to use outside: needs "source" first */ |
| 4895 | Alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n", |
| 4896 | file, linenum, "usesrc", "source"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4897 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4898 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 4899 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4900 | 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] | 4901 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4902 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 4903 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4904 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4905 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4906 | } |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4907 | |
| 4908 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 4909 | SMP_OPT_DIR_REQ, ACT_REPLACE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4910 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4911 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4912 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4913 | } |
| 4914 | else if (!strcmp(args[0], "reqdel")) { /* delete request header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4915 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 4916 | SMP_OPT_DIR_REQ, ACT_REMOVE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4917 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4918 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4919 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4920 | } |
| 4921 | 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] | 4922 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 4923 | SMP_OPT_DIR_REQ, ACT_DENY, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4924 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4925 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4926 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4927 | } |
| 4928 | 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] | 4929 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 4930 | SMP_OPT_DIR_REQ, ACT_PASS, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4931 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4932 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4933 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4934 | } |
| 4935 | 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] | 4936 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 4937 | SMP_OPT_DIR_REQ, ACT_ALLOW, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4938 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4939 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4940 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4941 | } |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 4942 | 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] | 4943 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 4944 | SMP_OPT_DIR_REQ, ACT_TARPIT, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4945 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4946 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4947 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 4948 | } |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 4949 | 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] | 4950 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 4951 | SMP_OPT_DIR_REQ, ACT_SETBE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4952 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4953 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4954 | goto out; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 4955 | } |
| 4956 | 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] | 4957 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 4958 | SMP_OPT_DIR_REQ, ACT_SETBE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4959 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4960 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4961 | goto out; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 4962 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4963 | 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] | 4964 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4965 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 4966 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4967 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4968 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4969 | } |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4970 | |
| 4971 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 4972 | SMP_OPT_DIR_REQ, ACT_REPLACE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4973 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4974 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4975 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4976 | } |
| 4977 | 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] | 4978 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 4979 | SMP_OPT_DIR_REQ, ACT_REMOVE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4980 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4981 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4982 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4983 | } |
| 4984 | 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] | 4985 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 4986 | SMP_OPT_DIR_REQ, ACT_DENY, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4987 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4988 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4989 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4990 | } |
| 4991 | 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] | 4992 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 4993 | SMP_OPT_DIR_REQ, ACT_PASS, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4994 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4995 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4996 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4997 | } |
| 4998 | 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] | 4999 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5000 | SMP_OPT_DIR_REQ, ACT_ALLOW, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5001 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5002 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5003 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5004 | } |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 5005 | 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] | 5006 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5007 | SMP_OPT_DIR_REQ, ACT_TARPIT, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5008 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5009 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5010 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 5011 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5012 | else if (!strcmp(args[0], "reqadd")) { /* add request header */ |
Willy Tarreau | f4f0412 | 2010-01-28 18:10:50 +0100 | [diff] [blame] | 5013 | struct cond_wordlist *wl; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5014 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5015 | if (curproxy == &defproxy) { |
| 5016 | 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] | 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 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5021 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5022 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5023 | if (*(args[1]) == 0) { |
| 5024 | 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] | 5025 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5026 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5027 | } |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5028 | |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 5029 | if ((strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0)) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 5030 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args+2, &errmsg)) == NULL) { |
| 5031 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 5032 | file, linenum, args[0], errmsg); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 5033 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5034 | goto out; |
| 5035 | } |
| 5036 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
| 5037 | } |
| 5038 | else if (*args[2]) { |
| 5039 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 5040 | file, linenum, args[0], args[2]); |
| 5041 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5042 | goto out; |
| 5043 | } |
| 5044 | |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5045 | wl = calloc(1, sizeof(*wl)); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 5046 | wl->cond = cond; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5047 | wl->s = strdup(args[1]); |
| 5048 | LIST_ADDQ(&curproxy->req_add, &wl->list); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 5049 | warnif_misplaced_reqadd(curproxy, file, linenum, args[0]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5050 | } |
| 5051 | 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] | 5052 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5053 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 5054 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5055 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5056 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5057 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5058 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5059 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5060 | SMP_OPT_DIR_RES, ACT_REPLACE, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5061 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5062 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5063 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5064 | } |
| 5065 | else if (!strcmp(args[0], "rspdel")) { /* delete response header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5066 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5067 | SMP_OPT_DIR_RES, ACT_REMOVE, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5068 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5069 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5070 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5071 | } |
| 5072 | else if (!strcmp(args[0], "rspdeny")) { /* block response header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5073 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5074 | SMP_OPT_DIR_RES, ACT_DENY, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5075 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5076 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5077 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5078 | } |
| 5079 | 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] | 5080 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5081 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 5082 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5083 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5084 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5085 | } |
| 5086 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5087 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5088 | SMP_OPT_DIR_RES, ACT_REPLACE, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5089 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5090 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5091 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5092 | } |
| 5093 | 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] | 5094 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5095 | SMP_OPT_DIR_RES, ACT_REMOVE, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5096 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5097 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5098 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5099 | } |
| 5100 | 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] | 5101 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5102 | SMP_OPT_DIR_RES, ACT_DENY, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5103 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5104 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5105 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5106 | } |
| 5107 | else if (!strcmp(args[0], "rspadd")) { /* add response header */ |
Willy Tarreau | f4f0412 | 2010-01-28 18:10:50 +0100 | [diff] [blame] | 5108 | struct cond_wordlist *wl; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5109 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5110 | if (curproxy == &defproxy) { |
| 5111 | 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] | 5112 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5113 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5114 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5115 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5116 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5117 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5118 | if (*(args[1]) == 0) { |
| 5119 | 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] | 5120 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5121 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5122 | } |
| 5123 | |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5124 | if ((strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0)) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 5125 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args+2, &errmsg)) == NULL) { |
| 5126 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 5127 | file, linenum, args[0], errmsg); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5128 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5129 | goto out; |
| 5130 | } |
| 5131 | err_code |= warnif_cond_requires_req(cond, file, linenum); |
| 5132 | } |
| 5133 | else if (*args[2]) { |
| 5134 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 5135 | file, linenum, args[0], args[2]); |
| 5136 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5137 | goto out; |
| 5138 | } |
| 5139 | |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5140 | wl = calloc(1, sizeof(*wl)); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5141 | wl->cond = cond; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5142 | wl->s = strdup(args[1]); |
| 5143 | LIST_ADDQ(&curproxy->rsp_add, &wl->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5144 | } |
| 5145 | else if (!strcmp(args[0], "errorloc") || |
| 5146 | !strcmp(args[0], "errorloc302") || |
| 5147 | !strcmp(args[0], "errorloc303")) { /* error location */ |
| 5148 | int errnum, errlen; |
| 5149 | char *err; |
| 5150 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5151 | 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] | 5152 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5153 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5154 | if (*(args[2]) == 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 5155 | 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] | 5156 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5157 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5158 | } |
| 5159 | |
| 5160 | errnum = atol(args[1]); |
| 5161 | if (!strcmp(args[0], "errorloc303")) { |
| 5162 | err = malloc(strlen(HTTP_303) + strlen(args[2]) + 5); |
| 5163 | errlen = sprintf(err, "%s%s\r\n\r\n", HTTP_303, args[2]); |
| 5164 | } else { |
| 5165 | err = malloc(strlen(HTTP_302) + strlen(args[2]) + 5); |
| 5166 | errlen = sprintf(err, "%s%s\r\n\r\n", HTTP_302, args[2]); |
| 5167 | } |
| 5168 | |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 5169 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) { |
| 5170 | if (http_err_codes[rc] == errnum) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 5171 | chunk_destroy(&curproxy->errmsg[rc]); |
| 5172 | chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 5173 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5174 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5175 | } |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 5176 | |
| 5177 | if (rc >= HTTP_ERR_SIZE) { |
| 5178 | Warning("parsing [%s:%d] : status code %d not handled, error relocation will be ignored.\n", |
| 5179 | file, linenum, errnum); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5180 | free(err); |
| 5181 | } |
| 5182 | } |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5183 | else if (!strcmp(args[0], "errorfile")) { /* error message from a file */ |
| 5184 | int errnum, errlen, fd; |
| 5185 | char *err; |
| 5186 | struct stat stat; |
| 5187 | |
| 5188 | 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] | 5189 | err_code |= ERR_WARN; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5190 | |
| 5191 | if (*(args[2]) == 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 5192 | 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] | 5193 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5194 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5195 | } |
| 5196 | |
| 5197 | fd = open(args[2], O_RDONLY); |
| 5198 | if ((fd < 0) || (fstat(fd, &stat) < 0)) { |
| 5199 | Alert("parsing [%s:%d] : error opening file <%s> for custom error message <%s>.\n", |
| 5200 | file, linenum, args[2], args[1]); |
| 5201 | if (fd >= 0) |
| 5202 | close(fd); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5203 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5204 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5205 | } |
| 5206 | |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 5207 | if (stat.st_size <= global.tune.bufsize) { |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5208 | errlen = stat.st_size; |
| 5209 | } else { |
| 5210 | 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] | 5211 | file, linenum, args[2], global.tune.bufsize); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5212 | err_code |= ERR_WARN; |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 5213 | errlen = global.tune.bufsize; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5214 | } |
| 5215 | |
| 5216 | err = malloc(errlen); /* malloc() must succeed during parsing */ |
| 5217 | errnum = read(fd, err, errlen); |
| 5218 | if (errnum != errlen) { |
| 5219 | Alert("parsing [%s:%d] : error reading file <%s> for custom error message <%s>.\n", |
| 5220 | file, linenum, args[2], args[1]); |
| 5221 | close(fd); |
| 5222 | free(err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5223 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5224 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5225 | } |
| 5226 | close(fd); |
| 5227 | |
| 5228 | errnum = atol(args[1]); |
| 5229 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) { |
| 5230 | if (http_err_codes[rc] == errnum) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 5231 | chunk_destroy(&curproxy->errmsg[rc]); |
| 5232 | chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen); |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5233 | break; |
| 5234 | } |
| 5235 | } |
| 5236 | |
| 5237 | if (rc >= HTTP_ERR_SIZE) { |
| 5238 | Warning("parsing [%s:%d] : status code %d not handled, error customization will be ignored.\n", |
| 5239 | file, linenum, errnum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5240 | err_code |= ERR_WARN; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5241 | free(err); |
| 5242 | } |
| 5243 | } |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5244 | else if (!strcmp(args[0], "compression")) { |
| 5245 | struct comp *comp; |
| 5246 | if (curproxy->comp == NULL) { |
| 5247 | comp = calloc(1, sizeof(struct comp)); |
| 5248 | curproxy->comp = comp; |
| 5249 | } else { |
| 5250 | comp = curproxy->comp; |
| 5251 | } |
| 5252 | |
| 5253 | if (!strcmp(args[1], "algo")) { |
| 5254 | int cur_arg; |
| 5255 | cur_arg = 2; |
| 5256 | if (!*args[cur_arg]) { |
| 5257 | Alert("parsing [%s:%d] : '%s' expects <algorithm>\n", |
| 5258 | file, linenum, args[0]); |
| 5259 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5260 | goto out; |
| 5261 | } |
| 5262 | while (*(args[cur_arg])) { |
| 5263 | if (comp_append_algo(comp, args[cur_arg]) < 0) { |
| 5264 | Alert("parsing [%s:%d] : '%s' : '%s' is not a supported algorithm.\n", |
| 5265 | file, linenum, args[0], args[cur_arg]); |
| 5266 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5267 | goto out; |
| 5268 | } |
| 5269 | cur_arg ++; |
| 5270 | continue; |
| 5271 | } |
| 5272 | } |
Willy Tarreau | 70737d1 | 2012-10-27 00:34:28 +0200 | [diff] [blame] | 5273 | else if (!strcmp(args[1], "offload")) { |
| 5274 | comp->offload = 1; |
| 5275 | } |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5276 | else if (!strcmp(args[1], "type")) { |
| 5277 | int cur_arg; |
| 5278 | cur_arg = 2; |
| 5279 | if (!*args[cur_arg]) { |
| 5280 | Alert("parsing [%s:%d] : '%s' expects <type>\n", |
| 5281 | file, linenum, args[0]); |
| 5282 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5283 | goto out; |
| 5284 | } |
| 5285 | while (*(args[cur_arg])) { |
| 5286 | comp_append_type(comp, args[cur_arg]); |
| 5287 | cur_arg ++; |
| 5288 | continue; |
| 5289 | } |
| 5290 | } |
| 5291 | else { |
Willy Tarreau | 70737d1 | 2012-10-27 00:34:28 +0200 | [diff] [blame] | 5292 | Alert("parsing [%s:%d] : '%s' expects 'algo', 'type' or 'offload'\n", |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5293 | file, linenum, args[0]); |
| 5294 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5295 | goto out; |
| 5296 | } |
| 5297 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5298 | else { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 5299 | struct cfg_kw_list *kwl; |
| 5300 | int index; |
| 5301 | |
| 5302 | list_for_each_entry(kwl, &cfg_keywords.list, list) { |
| 5303 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 5304 | if (kwl->kw[index].section != CFG_LISTEN) |
| 5305 | continue; |
| 5306 | if (strcmp(kwl->kw[index].kw, args[0]) == 0) { |
| 5307 | /* prepare error message just in case */ |
Willy Tarreau | 28a47d6 | 2012-09-18 20:02:48 +0200 | [diff] [blame] | 5308 | 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] | 5309 | if (rc < 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 5310 | Alert("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5311 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5312 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 5313 | } |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 5314 | else if (rc > 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 5315 | Warning("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5316 | err_code |= ERR_WARN; |
| 5317 | goto out; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 5318 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5319 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 5320 | } |
| 5321 | } |
| 5322 | } |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5323 | |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5324 | 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] | 5325 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5326 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5327 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5328 | out: |
Willy Tarreau | f4068b6 | 2012-05-08 17:37:49 +0200 | [diff] [blame] | 5329 | free(errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5330 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5331 | } |
| 5332 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5333 | int |
| 5334 | cfg_parse_users(const char *file, int linenum, char **args, int kwm) |
| 5335 | { |
| 5336 | |
| 5337 | int err_code = 0; |
| 5338 | const char *err; |
| 5339 | |
| 5340 | if (!strcmp(args[0], "userlist")) { /* new userlist */ |
| 5341 | struct userlist *newul; |
| 5342 | |
| 5343 | if (!*args[1]) { |
| 5344 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 5345 | file, linenum, args[0]); |
| 5346 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5347 | goto out; |
| 5348 | } |
| 5349 | |
| 5350 | err = invalid_char(args[1]); |
| 5351 | if (err) { |
| 5352 | Alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 5353 | file, linenum, *err, args[0], args[1]); |
| 5354 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5355 | goto out; |
| 5356 | } |
| 5357 | |
| 5358 | for (newul = userlist; newul; newul = newul->next) |
| 5359 | if (!strcmp(newul->name, args[1])) { |
| 5360 | Warning("parsing [%s:%d]: ignoring duplicated userlist '%s'.\n", |
| 5361 | file, linenum, args[1]); |
| 5362 | err_code |= ERR_WARN; |
| 5363 | goto out; |
| 5364 | } |
| 5365 | |
| 5366 | newul = (struct userlist *)calloc(1, sizeof(struct userlist)); |
| 5367 | if (!newul) { |
| 5368 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 5369 | err_code |= ERR_ALERT | ERR_ABORT; |
| 5370 | goto out; |
| 5371 | } |
| 5372 | |
| 5373 | newul->groupusers = calloc(MAX_AUTH_GROUPS, sizeof(char *)); |
| 5374 | newul->name = strdup(args[1]); |
| 5375 | |
| 5376 | if (!newul->groupusers | !newul->name) { |
| 5377 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 5378 | err_code |= ERR_ALERT | ERR_ABORT; |
| 5379 | goto out; |
| 5380 | } |
| 5381 | |
| 5382 | newul->next = userlist; |
| 5383 | userlist = newul; |
| 5384 | |
| 5385 | } else if (!strcmp(args[0], "group")) { /* new group */ |
| 5386 | int cur_arg, i; |
| 5387 | const char *err; |
| 5388 | |
| 5389 | if (!*args[1]) { |
| 5390 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 5391 | file, linenum, args[0]); |
| 5392 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5393 | goto out; |
| 5394 | } |
| 5395 | |
| 5396 | err = invalid_char(args[1]); |
| 5397 | if (err) { |
| 5398 | Alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 5399 | file, linenum, *err, args[0], args[1]); |
| 5400 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5401 | goto out; |
| 5402 | } |
| 5403 | |
| 5404 | for(i = 0; i < userlist->grpcnt; i++) |
| 5405 | if (!strcmp(userlist->groups[i], args[1])) { |
| 5406 | Warning("parsing [%s:%d]: ignoring duplicated group '%s' in userlist '%s'.\n", |
| 5407 | file, linenum, args[1], userlist->name); |
| 5408 | err_code |= ERR_ALERT; |
| 5409 | goto out; |
| 5410 | } |
| 5411 | |
| 5412 | if (userlist->grpcnt >= MAX_AUTH_GROUPS) { |
| 5413 | Alert("parsing [%s:%d]: too many groups (%u) in in userlist '%s' while adding group '%s'.\n", |
| 5414 | file, linenum, MAX_AUTH_GROUPS, userlist->name, args[1]); |
| 5415 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5416 | goto out; |
| 5417 | } |
| 5418 | |
| 5419 | cur_arg = 2; |
| 5420 | |
| 5421 | while (*args[cur_arg]) { |
| 5422 | if (!strcmp(args[cur_arg], "users")) { |
| 5423 | userlist->groupusers[userlist->grpcnt] = strdup(args[cur_arg + 1]); |
| 5424 | cur_arg += 2; |
| 5425 | continue; |
| 5426 | } else { |
| 5427 | Alert("parsing [%s:%d]: '%s' only supports 'users' option.\n", |
| 5428 | file, linenum, args[0]); |
| 5429 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5430 | goto out; |
| 5431 | } |
| 5432 | } |
| 5433 | |
| 5434 | userlist->groups[userlist->grpcnt++] = strdup(args[1]); |
| 5435 | } else if (!strcmp(args[0], "user")) { /* new user */ |
| 5436 | struct auth_users *newuser; |
| 5437 | int cur_arg; |
| 5438 | |
| 5439 | if (!*args[1]) { |
| 5440 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 5441 | file, linenum, args[0]); |
| 5442 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5443 | goto out; |
| 5444 | } |
| 5445 | |
| 5446 | for (newuser = userlist->users; newuser; newuser = newuser->next) |
| 5447 | if (!strcmp(newuser->user, args[1])) { |
| 5448 | Warning("parsing [%s:%d]: ignoring duplicated user '%s' in userlist '%s'.\n", |
| 5449 | file, linenum, args[1], userlist->name); |
| 5450 | err_code |= ERR_ALERT; |
| 5451 | goto out; |
| 5452 | } |
| 5453 | |
| 5454 | newuser = (struct auth_users *)calloc(1, sizeof(struct auth_users)); |
| 5455 | if (!newuser) { |
| 5456 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 5457 | err_code |= ERR_ALERT | ERR_ABORT; |
| 5458 | goto out; |
| 5459 | } |
| 5460 | |
| 5461 | newuser->user = strdup(args[1]); |
| 5462 | |
| 5463 | newuser->next = userlist->users; |
| 5464 | userlist->users = newuser; |
| 5465 | |
| 5466 | cur_arg = 2; |
| 5467 | |
| 5468 | while (*args[cur_arg]) { |
| 5469 | if (!strcmp(args[cur_arg], "password")) { |
| 5470 | #ifndef CONFIG_HAP_CRYPT |
| 5471 | Warning("parsing [%s:%d]: no crypt(3) support compiled, encrypted passwords will not work.\n", |
| 5472 | file, linenum); |
| 5473 | err_code |= ERR_ALERT; |
| 5474 | #endif |
| 5475 | newuser->pass = strdup(args[cur_arg + 1]); |
| 5476 | cur_arg += 2; |
| 5477 | continue; |
| 5478 | } else if (!strcmp(args[cur_arg], "insecure-password")) { |
| 5479 | newuser->pass = strdup(args[cur_arg + 1]); |
| 5480 | newuser->flags |= AU_O_INSECURE; |
| 5481 | cur_arg += 2; |
| 5482 | continue; |
| 5483 | } else if (!strcmp(args[cur_arg], "groups")) { |
Willy Tarreau | b4c06b7 | 2010-02-02 11:28:20 +0100 | [diff] [blame] | 5484 | newuser->u.groups = strdup(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5485 | cur_arg += 2; |
| 5486 | continue; |
| 5487 | } else { |
| 5488 | Alert("parsing [%s:%d]: '%s' only supports 'password', 'insecure-password' and 'groups' options.\n", |
| 5489 | file, linenum, args[0]); |
| 5490 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5491 | goto out; |
| 5492 | } |
| 5493 | } |
| 5494 | } else { |
| 5495 | Alert("parsing [%s:%d]: unknown keyword '%s' in '%s' section\n", file, linenum, args[0], "users"); |
| 5496 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5497 | } |
| 5498 | |
| 5499 | out: |
| 5500 | return err_code; |
| 5501 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5502 | |
| 5503 | /* |
| 5504 | * This function reads and parses the configuration file given in the argument. |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5505 | * Returns the error code, 0 if OK, or any combination of : |
| 5506 | * - ERR_ABORT: must abort ASAP |
| 5507 | * - ERR_FATAL: we can continue parsing but not start the service |
| 5508 | * - ERR_WARN: a warning has been emitted |
| 5509 | * - ERR_ALERT: an alert has been emitted |
| 5510 | * Only the two first ones can stop processing, the two others are just |
| 5511 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5512 | */ |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 5513 | int readcfgfile(const char *file) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5514 | { |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5515 | char thisline[LINESIZE]; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5516 | FILE *f; |
| 5517 | int linenum = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5518 | int confsect = CFG_NONE; |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5519 | int err_code = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5520 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5521 | if ((f=fopen(file,"r")) == NULL) |
| 5522 | return -1; |
| 5523 | |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5524 | while (fgets(thisline, sizeof(thisline), f) != NULL) { |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 5525 | int arg, kwm = KWM_STD; |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5526 | char *end; |
| 5527 | char *args[MAX_LINE_ARGS + 1]; |
| 5528 | char *line = thisline; |
| 5529 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5530 | linenum++; |
| 5531 | |
| 5532 | end = line + strlen(line); |
| 5533 | |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5534 | if (end-line == sizeof(thisline)-1 && *(end-1) != '\n') { |
| 5535 | /* Check if we reached the limit and the last char is not \n. |
| 5536 | * Watch out for the last line without the terminating '\n'! |
| 5537 | */ |
| 5538 | Alert("parsing [%s:%d]: line too long, limit: %d.\n", |
Willy Tarreau | 5e4a6f1 | 2009-04-11 19:42:49 +0200 | [diff] [blame] | 5539 | file, linenum, (int)sizeof(thisline)-1); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5540 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5541 | } |
| 5542 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5543 | /* skip leading spaces */ |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 5544 | while (isspace((unsigned char)*line)) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5545 | line++; |
| 5546 | |
| 5547 | arg = 0; |
| 5548 | args[arg] = line; |
| 5549 | |
| 5550 | while (*line && arg < MAX_LINE_ARGS) { |
| 5551 | /* first, we'll replace \\, \<space>, \#, \r, \n, \t, \xXX with their |
| 5552 | * C equivalent value. Other combinations left unchanged (eg: \1). |
| 5553 | */ |
| 5554 | if (*line == '\\') { |
| 5555 | int skip = 0; |
| 5556 | if (line[1] == ' ' || line[1] == '\\' || line[1] == '#') { |
| 5557 | *line = line[1]; |
| 5558 | skip = 1; |
| 5559 | } |
| 5560 | else if (line[1] == 'r') { |
| 5561 | *line = '\r'; |
| 5562 | skip = 1; |
| 5563 | } |
| 5564 | else if (line[1] == 'n') { |
| 5565 | *line = '\n'; |
| 5566 | skip = 1; |
| 5567 | } |
| 5568 | else if (line[1] == 't') { |
| 5569 | *line = '\t'; |
| 5570 | skip = 1; |
| 5571 | } |
| 5572 | else if (line[1] == 'x') { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5573 | if ((line + 3 < end) && ishex(line[2]) && ishex(line[3])) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5574 | unsigned char hex1, hex2; |
| 5575 | hex1 = toupper(line[2]) - '0'; |
| 5576 | hex2 = toupper(line[3]) - '0'; |
| 5577 | if (hex1 > 9) hex1 -= 'A' - '9' - 1; |
| 5578 | if (hex2 > 9) hex2 -= 'A' - '9' - 1; |
| 5579 | *line = (hex1<<4) + hex2; |
| 5580 | skip = 3; |
| 5581 | } |
| 5582 | else { |
| 5583 | 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] | 5584 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5585 | } |
| 5586 | } |
| 5587 | if (skip) { |
Cyril Bonté | dd1b01d | 2009-12-06 13:43:42 +0100 | [diff] [blame] | 5588 | memmove(line + 1, line + 1 + skip, end - (line + skip)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5589 | end -= skip; |
| 5590 | } |
| 5591 | line++; |
| 5592 | } |
| 5593 | else if (*line == '#' || *line == '\n' || *line == '\r') { |
| 5594 | /* end of string, end of loop */ |
| 5595 | *line = 0; |
| 5596 | break; |
| 5597 | } |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 5598 | else if (isspace((unsigned char)*line)) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5599 | /* a non-escaped space is an argument separator */ |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5600 | *line++ = '\0'; |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 5601 | while (isspace((unsigned char)*line)) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5602 | line++; |
| 5603 | args[++arg] = line; |
| 5604 | } |
| 5605 | else { |
| 5606 | line++; |
| 5607 | } |
| 5608 | } |
| 5609 | |
| 5610 | /* empty line */ |
| 5611 | if (!**args) |
| 5612 | continue; |
| 5613 | |
Willy Tarreau | 7bb651e | 2009-11-09 21:16:53 +0100 | [diff] [blame] | 5614 | if (*line) { |
| 5615 | /* we had to stop due to too many args. |
| 5616 | * Let's terminate the string, print the offending part then cut the |
| 5617 | * last arg. |
| 5618 | */ |
| 5619 | while (*line && *line != '#' && *line != '\n' && *line != '\r') |
| 5620 | line++; |
| 5621 | *line = '\0'; |
| 5622 | |
Krzysztof Piotr Oledzki | 500b8f0 | 2009-12-15 22:34:51 +0100 | [diff] [blame] | 5623 | 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] | 5624 | file, linenum, arg + 1, (long)(args[arg] - thisline + 1), args[arg]); |
Willy Tarreau | 7bb651e | 2009-11-09 21:16:53 +0100 | [diff] [blame] | 5625 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5626 | args[arg] = line; |
| 5627 | } |
| 5628 | |
Willy Tarreau | 540abe4 | 2007-05-02 20:50:16 +0200 | [diff] [blame] | 5629 | /* zero out remaining args and ensure that at least one entry |
| 5630 | * is zeroed out. |
| 5631 | */ |
| 5632 | while (++arg <= MAX_LINE_ARGS) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5633 | args[arg] = line; |
| 5634 | } |
| 5635 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 5636 | /* check for keyword modifiers "no" and "default" */ |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5637 | if (!strcmp(args[0], "no")) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5638 | char *tmp; |
| 5639 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 5640 | kwm = KWM_NO; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5641 | tmp = args[0]; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5642 | for (arg=0; *args[arg+1]; arg++) |
| 5643 | args[arg] = args[arg+1]; // shift args after inversion |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5644 | *tmp = '\0'; // fix the next arg to \0 |
| 5645 | args[arg] = tmp; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5646 | } |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 5647 | else if (!strcmp(args[0], "default")) { |
| 5648 | kwm = KWM_DEF; |
| 5649 | for (arg=0; *args[arg+1]; arg++) |
| 5650 | args[arg] = args[arg+1]; // shift args after inversion |
| 5651 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5652 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5653 | if (kwm != KWM_STD && strcmp(args[0], "option") != 0 && \ |
| 5654 | strcmp(args[0], "log") != 0) { |
| 5655 | 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] | 5656 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5657 | } |
| 5658 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5659 | if (!strcmp(args[0], "listen") || |
| 5660 | !strcmp(args[0], "frontend") || |
| 5661 | !strcmp(args[0], "backend") || |
| 5662 | !strcmp(args[0], "ruleset") || |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5663 | !strcmp(args[0], "defaults")) { /* new proxy */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5664 | confsect = CFG_LISTEN; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 5665 | free(cursection); |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5666 | cursection = strdup(args[0]); |
| 5667 | } |
| 5668 | else if (!strcmp(args[0], "global")) { /* global config */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5669 | confsect = CFG_GLOBAL; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 5670 | free(cursection); |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5671 | cursection = strdup(args[0]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 5672 | } |
| 5673 | else if (!strcmp(args[0], "userlist")) { |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5674 | confsect = CFG_USERLIST; |
| 5675 | free(cursection); |
| 5676 | cursection = strdup(args[0]); |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5677 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 5678 | else if (!strcmp(args[0], "peers")) { |
| 5679 | confsect = CFG_PEERS; |
| 5680 | free(cursection); |
| 5681 | cursection = strdup(args[0]); |
| 5682 | } |
| 5683 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5684 | /* else it's a section keyword */ |
| 5685 | |
| 5686 | switch (confsect) { |
| 5687 | case CFG_LISTEN: |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5688 | err_code |= cfg_parse_listen(file, linenum, args, kwm); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5689 | break; |
| 5690 | case CFG_GLOBAL: |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5691 | err_code |= cfg_parse_global(file, linenum, args, kwm); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5692 | break; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5693 | case CFG_USERLIST: |
| 5694 | err_code |= cfg_parse_users(file, linenum, args, kwm); |
| 5695 | break; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 5696 | case CFG_PEERS: |
| 5697 | err_code |= cfg_parse_peers(file, linenum, args, kwm); |
| 5698 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5699 | default: |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5700 | 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] | 5701 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5702 | } |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5703 | |
| 5704 | if (err_code & ERR_ABORT) |
| 5705 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5706 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 5707 | free(cursection); |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5708 | cursection = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5709 | fclose(f); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5710 | return err_code; |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5711 | } |
| 5712 | |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 5713 | /* |
| 5714 | * Returns the error code, 0 if OK, or any combination of : |
| 5715 | * - ERR_ABORT: must abort ASAP |
| 5716 | * - ERR_FATAL: we can continue parsing but not start the service |
| 5717 | * - ERR_WARN: a warning has been emitted |
| 5718 | * - ERR_ALERT: an alert has been emitted |
| 5719 | * Only the two first ones can stop processing, the two others are just |
| 5720 | * indicators. |
| 5721 | */ |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5722 | int check_config_validity() |
| 5723 | { |
| 5724 | int cfgerr = 0; |
| 5725 | struct proxy *curproxy = NULL; |
| 5726 | struct server *newsrv = NULL; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5727 | struct userlist *curuserlist = NULL; |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 5728 | int err_code = 0; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 5729 | unsigned int next_pxid = 1; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 5730 | struct bind_conf *bind_conf; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5731 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 5732 | bind_conf = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5733 | /* |
| 5734 | * Now, check for the integrity of all that we have collected. |
| 5735 | */ |
| 5736 | |
| 5737 | /* will be needed further to delay some tasks */ |
Willy Tarreau | b0b37bc | 2008-06-23 14:00:57 +0200 | [diff] [blame] | 5738 | tv_update_date(0,1); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5739 | |
Willy Tarreau | 55bc0f8 | 2009-03-15 14:51:53 +0100 | [diff] [blame] | 5740 | /* first, we will invert the proxy list order */ |
| 5741 | curproxy = NULL; |
| 5742 | while (proxy) { |
| 5743 | struct proxy *next; |
| 5744 | |
| 5745 | next = proxy->next; |
| 5746 | proxy->next = curproxy; |
| 5747 | curproxy = proxy; |
| 5748 | if (!next) |
| 5749 | break; |
| 5750 | proxy = next; |
| 5751 | } |
| 5752 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5753 | while (curproxy != NULL) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 5754 | struct switching_rule *rule; |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 5755 | struct server_rule *srule; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5756 | struct sticking_rule *mrule; |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 5757 | struct tcp_rule *trule; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 5758 | struct listener *listener; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 5759 | unsigned int next_id; |
| 5760 | |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 5761 | if (curproxy->uuid < 0) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 5762 | /* proxy ID not set, use automatic numbering with first |
| 5763 | * spare entry starting with next_pxid. |
| 5764 | */ |
| 5765 | next_pxid = get_next_id(&used_proxy_id, next_pxid); |
| 5766 | curproxy->conf.id.key = curproxy->uuid = next_pxid; |
| 5767 | eb32_insert(&used_proxy_id, &curproxy->conf.id); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 5768 | } |
Krzysztof Piotr Oledzki | df5cb9f | 2010-02-05 20:58:27 +0100 | [diff] [blame] | 5769 | next_pxid++; |
| 5770 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 5771 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5772 | if (curproxy->state == PR_STSTOPPED) { |
Willy Tarreau | da250db | 2008-10-12 12:07:48 +0200 | [diff] [blame] | 5773 | /* ensure we don't keep listeners uselessly bound */ |
| 5774 | stop_proxy(curproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5775 | curproxy = curproxy->next; |
| 5776 | continue; |
| 5777 | } |
| 5778 | |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 5779 | switch (curproxy->mode) { |
| 5780 | case PR_MODE_HEALTH: |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5781 | cfgerr += proxy_cfg_ensure_no_http(curproxy); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 5782 | if (!(curproxy->cap & PR_CAP_FE)) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5783 | Alert("config : %s '%s' cannot be in health mode as it has no frontend capability.\n", |
| 5784 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 5785 | cfgerr++; |
| 5786 | } |
| 5787 | |
| 5788 | if (curproxy->srv != NULL) |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5789 | Warning("config : servers will be ignored for %s '%s'.\n", |
| 5790 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 5791 | break; |
| 5792 | |
| 5793 | case PR_MODE_TCP: |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5794 | cfgerr += proxy_cfg_ensure_no_http(curproxy); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 5795 | break; |
| 5796 | |
| 5797 | case PR_MODE_HTTP: |
Willy Tarreau | a9fb083 | 2009-07-10 20:53:53 +0200 | [diff] [blame] | 5798 | curproxy->acl_requires |= ACL_USE_L7_ANY; |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 5799 | break; |
| 5800 | } |
| 5801 | |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 5802 | if ((curproxy->cap & PR_CAP_BE) && (curproxy->mode != PR_MODE_HEALTH)) { |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 5803 | if (curproxy->lbprm.algo & BE_LB_KIND) { |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 5804 | if (curproxy->options & PR_O_TRANSP) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5805 | Alert("config : %s '%s' cannot use both transparent and balance mode.\n", |
| 5806 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 5807 | cfgerr++; |
| 5808 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5809 | #ifdef WE_DONT_SUPPORT_SERVERLESS_LISTENERS |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 5810 | else if (curproxy->srv == NULL) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5811 | Alert("config : %s '%s' needs at least 1 server in balance mode.\n", |
| 5812 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 5813 | cfgerr++; |
| 5814 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5815 | #endif |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 5816 | else if (curproxy->options & PR_O_DISPATCH) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5817 | Warning("config : dispatch address of %s '%s' will be ignored in balance mode.\n", |
| 5818 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 5819 | err_code |= ERR_WARN; |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 5820 | } |
| 5821 | } |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 5822 | 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] | 5823 | /* If no LB algo is set in a backend, and we're not in |
| 5824 | * transparent mode, dispatch mode nor proxy mode, we |
| 5825 | * want to use balance roundrobin by default. |
| 5826 | */ |
| 5827 | curproxy->lbprm.algo &= ~BE_LB_ALGO; |
| 5828 | curproxy->lbprm.algo |= BE_LB_ALGO_RR; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5829 | } |
| 5830 | } |
Willy Tarreau | 193cf93 | 2007-09-17 10:17:23 +0200 | [diff] [blame] | 5831 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 5832 | if (curproxy->options & PR_O_DISPATCH) |
| 5833 | curproxy->options &= ~(PR_O_TRANSP | PR_O_HTTP_PROXY); |
| 5834 | else if (curproxy->options & PR_O_HTTP_PROXY) |
| 5835 | curproxy->options &= ~(PR_O_DISPATCH | PR_O_TRANSP); |
| 5836 | else if (curproxy->options & PR_O_TRANSP) |
| 5837 | curproxy->options &= ~(PR_O_DISPATCH | PR_O_HTTP_PROXY); |
Willy Tarreau | 8293658 | 2007-11-30 15:20:09 +0100 | [diff] [blame] | 5838 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 5839 | if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_HTTP_CHK) { |
| 5840 | if (curproxy->options & PR_O_DISABLE404) { |
| 5841 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n", |
| 5842 | "disable-on-404", proxy_type_str(curproxy), curproxy->id); |
| 5843 | err_code |= ERR_WARN; |
| 5844 | curproxy->options &= ~PR_O_DISABLE404; |
| 5845 | } |
| 5846 | if (curproxy->options2 & PR_O2_CHK_SNDST) { |
| 5847 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n", |
| 5848 | "send-state", proxy_type_str(curproxy), curproxy->id); |
| 5849 | err_code |= ERR_WARN; |
| 5850 | curproxy->options &= ~PR_O2_CHK_SNDST; |
| 5851 | } |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 5852 | } |
| 5853 | |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5854 | /* if a default backend was specified, let's find it */ |
| 5855 | if (curproxy->defbe.name) { |
| 5856 | struct proxy *target; |
| 5857 | |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 5858 | target = findproxy_mode(curproxy->defbe.name, curproxy->mode, PR_CAP_BE); |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 5859 | if (!target) { |
| 5860 | Alert("Proxy '%s': unable to find required default_backend: '%s'.\n", |
| 5861 | curproxy->id, curproxy->defbe.name); |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5862 | cfgerr++; |
| 5863 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 5864 | Alert("Proxy '%s': loop detected for default_backend: '%s'.\n", |
| 5865 | curproxy->id, curproxy->defbe.name); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 5866 | cfgerr++; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5867 | } else { |
| 5868 | free(curproxy->defbe.name); |
| 5869 | curproxy->defbe.be = target; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 5870 | /* we force the backend to be present on at least all of |
| 5871 | * the frontend's processes. |
| 5872 | */ |
| 5873 | target->bind_proc = curproxy->bind_proc ? |
| 5874 | (target->bind_proc | curproxy->bind_proc) : 0; |
Willy Tarreau | ff67813 | 2012-02-13 14:32:34 +0100 | [diff] [blame] | 5875 | |
| 5876 | /* Emit a warning if this proxy also has some servers */ |
| 5877 | if (curproxy->srv) { |
| 5878 | Warning("In proxy '%s', the 'default_backend' rule always has precedence over the servers, which will never be used.\n", |
| 5879 | curproxy->id); |
| 5880 | err_code |= ERR_WARN; |
| 5881 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5882 | } |
| 5883 | } |
| 5884 | |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5885 | /* find the target proxy in setbe */ |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5886 | if (curproxy->mode == PR_MODE_HTTP && curproxy->req_exp != NULL) { |
| 5887 | /* map jump target for ACT_SETBE in req_rep chain */ |
| 5888 | struct hdr_exp *exp; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5889 | for (exp = curproxy->req_exp; exp != NULL; exp = exp->next) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 5890 | struct proxy *target; |
| 5891 | |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5892 | if (exp->action != ACT_SETBE) |
| 5893 | continue; |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 5894 | |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 5895 | target = findproxy_mode(exp->replace, PR_MODE_HTTP, PR_CAP_BE); |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 5896 | if (!target) { |
| 5897 | Alert("Proxy '%s': unable to find required setbe: '%s'.\n", |
| 5898 | curproxy->id, exp->replace); |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5899 | cfgerr++; |
| 5900 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 5901 | Alert("Proxy '%s': loop detected for setbe: '%s'.\n", |
| 5902 | curproxy->id, exp->replace); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5903 | cfgerr++; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5904 | } else { |
| 5905 | free((void *)exp->replace); |
| 5906 | exp->replace = (const char *)target; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 5907 | /* we force the backend to be present on at least all of |
| 5908 | * the frontend's processes. |
| 5909 | */ |
| 5910 | target->bind_proc = curproxy->bind_proc ? |
| 5911 | (target->bind_proc | curproxy->bind_proc) : 0; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5912 | } |
| 5913 | } |
| 5914 | } |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 5915 | |
| 5916 | /* find the target proxy for 'use_backend' rules */ |
| 5917 | list_for_each_entry(rule, &curproxy->switching_rules, list) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 5918 | struct proxy *target; |
| 5919 | |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 5920 | target = findproxy_mode(rule->be.name, curproxy->mode, PR_CAP_BE); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 5921 | |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 5922 | if (!target) { |
| 5923 | Alert("Proxy '%s': unable to find required use_backend: '%s'.\n", |
| 5924 | curproxy->id, rule->be.name); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 5925 | cfgerr++; |
| 5926 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 5927 | Alert("Proxy '%s': loop detected for use_backend: '%s'.\n", |
| 5928 | curproxy->id, rule->be.name); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 5929 | cfgerr++; |
| 5930 | } else { |
| 5931 | free((void *)rule->be.name); |
| 5932 | rule->be.backend = target; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 5933 | /* we force the backend to be present on at least all of |
| 5934 | * the frontend's processes. |
| 5935 | */ |
| 5936 | target->bind_proc = curproxy->bind_proc ? |
| 5937 | (target->bind_proc | curproxy->bind_proc) : 0; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 5938 | } |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 5939 | } |
| 5940 | |
| 5941 | /* find the target proxy for 'use_backend' rules */ |
| 5942 | list_for_each_entry(srule, &curproxy->server_rules, list) { |
| 5943 | struct server *target = findserver(curproxy, srule->srv.name); |
| 5944 | |
| 5945 | if (!target) { |
| 5946 | Alert("config : %s '%s' : unable to find server '%s' referenced in a 'use-server' rule.\n", |
| 5947 | proxy_type_str(curproxy), curproxy->id, srule->srv.name); |
| 5948 | cfgerr++; |
| 5949 | continue; |
| 5950 | } |
| 5951 | free((void *)srule->srv.name); |
| 5952 | srule->srv.ptr = target; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 5953 | } |
| 5954 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5955 | /* find the target table for 'stick' rules */ |
| 5956 | list_for_each_entry(mrule, &curproxy->sticking_rules, list) { |
| 5957 | struct proxy *target; |
| 5958 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 5959 | curproxy->be_req_ana |= AN_REQ_STICKING_RULES; |
| 5960 | if (mrule->flags & STK_IS_STORE) |
| 5961 | curproxy->be_rsp_ana |= AN_RES_STORE_RULES; |
| 5962 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5963 | if (mrule->table.name) |
Willy Tarreau | c00cdc2 | 2010-06-06 16:48:26 +0200 | [diff] [blame] | 5964 | target = findproxy(mrule->table.name, 0); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5965 | else |
| 5966 | target = curproxy; |
| 5967 | |
| 5968 | if (!target) { |
| 5969 | Alert("Proxy '%s': unable to find stick-table '%s'.\n", |
| 5970 | curproxy->id, mrule->table.name); |
| 5971 | cfgerr++; |
| 5972 | } |
| 5973 | else if (target->table.size == 0) { |
| 5974 | Alert("Proxy '%s': stick-table '%s' used but not configured.\n", |
| 5975 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 5976 | cfgerr++; |
| 5977 | } |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 5978 | else if (!stktable_compatible_sample(mrule->expr, target->table.type)) { |
| 5979 | 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] | 5980 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 5981 | cfgerr++; |
| 5982 | } |
| 5983 | else { |
| 5984 | free((void *)mrule->table.name); |
| 5985 | mrule->table.t = &(target->table); |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 5986 | stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID, NULL); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5987 | } |
| 5988 | } |
| 5989 | |
| 5990 | /* find the target table for 'store response' rules */ |
| 5991 | list_for_each_entry(mrule, &curproxy->storersp_rules, list) { |
| 5992 | struct proxy *target; |
| 5993 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 5994 | curproxy->be_rsp_ana |= AN_RES_STORE_RULES; |
| 5995 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5996 | if (mrule->table.name) |
Willy Tarreau | c00cdc2 | 2010-06-06 16:48:26 +0200 | [diff] [blame] | 5997 | target = findproxy(mrule->table.name, 0); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5998 | else |
| 5999 | target = curproxy; |
| 6000 | |
| 6001 | if (!target) { |
| 6002 | Alert("Proxy '%s': unable to find store table '%s'.\n", |
| 6003 | curproxy->id, mrule->table.name); |
| 6004 | cfgerr++; |
| 6005 | } |
| 6006 | else if (target->table.size == 0) { |
| 6007 | Alert("Proxy '%s': stick-table '%s' used but not configured.\n", |
| 6008 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 6009 | cfgerr++; |
| 6010 | } |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 6011 | else if (!stktable_compatible_sample(mrule->expr, target->table.type)) { |
| 6012 | 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] | 6013 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 6014 | cfgerr++; |
| 6015 | } |
| 6016 | else { |
| 6017 | free((void *)mrule->table.name); |
| 6018 | mrule->table.t = &(target->table); |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 6019 | stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID, NULL); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6020 | } |
| 6021 | } |
| 6022 | |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 6023 | /* find the target table for 'tcp-request' layer 4 rules */ |
| 6024 | list_for_each_entry(trule, &curproxy->tcp_req.l4_rules, list) { |
| 6025 | struct proxy *target; |
| 6026 | |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6027 | 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] | 6028 | continue; |
| 6029 | |
| 6030 | if (trule->act_prm.trk_ctr.table.n) |
| 6031 | target = findproxy(trule->act_prm.trk_ctr.table.n, 0); |
| 6032 | else |
| 6033 | target = curproxy; |
| 6034 | |
| 6035 | if (!target) { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6036 | Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n", |
| 6037 | curproxy->id, trule->act_prm.trk_ctr.table.n, |
| 6038 | trule->action == TCP_ACT_TRK_SC1 ? 1 : 2); |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 6039 | cfgerr++; |
| 6040 | } |
| 6041 | else if (target->table.size == 0) { |
| 6042 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
| 6043 | curproxy->id, trule->act_prm.trk_ctr.table.n ? trule->act_prm.trk_ctr.table.n : curproxy->id); |
| 6044 | cfgerr++; |
| 6045 | } |
| 6046 | else if (trule->act_prm.trk_ctr.type != target->table.type) { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6047 | 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] | 6048 | curproxy->id, trule->act_prm.trk_ctr.table.n ? trule->act_prm.trk_ctr.table.n : curproxy->id); |
| 6049 | cfgerr++; |
| 6050 | } |
| 6051 | else { |
| 6052 | free(trule->act_prm.trk_ctr.table.n); |
| 6053 | trule->act_prm.trk_ctr.table.t = &target->table; |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6054 | /* 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] | 6055 | * to pass a list of counters to track and allocate them right here using |
| 6056 | * stktable_alloc_data_type(). |
| 6057 | */ |
| 6058 | } |
| 6059 | } |
| 6060 | |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 6061 | /* find the target table for 'tcp-request' layer 6 rules */ |
| 6062 | list_for_each_entry(trule, &curproxy->tcp_req.inspect_rules, list) { |
| 6063 | struct proxy *target; |
| 6064 | |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6065 | 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] | 6066 | continue; |
| 6067 | |
| 6068 | if (trule->act_prm.trk_ctr.table.n) |
| 6069 | target = findproxy(trule->act_prm.trk_ctr.table.n, 0); |
| 6070 | else |
| 6071 | target = curproxy; |
| 6072 | |
| 6073 | if (!target) { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6074 | Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n", |
| 6075 | curproxy->id, trule->act_prm.trk_ctr.table.n, |
| 6076 | trule->action == TCP_ACT_TRK_SC1 ? 1 : 2); |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 6077 | cfgerr++; |
| 6078 | } |
| 6079 | else if (target->table.size == 0) { |
| 6080 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
| 6081 | curproxy->id, trule->act_prm.trk_ctr.table.n ? trule->act_prm.trk_ctr.table.n : curproxy->id); |
| 6082 | cfgerr++; |
| 6083 | } |
| 6084 | else if (trule->act_prm.trk_ctr.type != target->table.type) { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6085 | 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] | 6086 | curproxy->id, trule->act_prm.trk_ctr.table.n ? trule->act_prm.trk_ctr.table.n : curproxy->id); |
| 6087 | cfgerr++; |
| 6088 | } |
| 6089 | else { |
| 6090 | free(trule->act_prm.trk_ctr.table.n); |
| 6091 | trule->act_prm.trk_ctr.table.t = &target->table; |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6092 | /* 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] | 6093 | * to pass a list of counters to track and allocate them right here using |
| 6094 | * stktable_alloc_data_type(). |
| 6095 | */ |
| 6096 | } |
| 6097 | } |
| 6098 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 6099 | if (curproxy->table.peers.name) { |
| 6100 | struct peers *curpeers = peers; |
| 6101 | |
| 6102 | for (curpeers = peers; curpeers; curpeers = curpeers->next) { |
| 6103 | if (strcmp(curpeers->id, curproxy->table.peers.name) == 0) { |
| 6104 | free((void *)curproxy->table.peers.name); |
| 6105 | curproxy->table.peers.p = peers; |
| 6106 | break; |
| 6107 | } |
| 6108 | } |
| 6109 | |
| 6110 | if (!curpeers) { |
| 6111 | Alert("Proxy '%s': unable to find sync peers '%s'.\n", |
| 6112 | curproxy->id, curproxy->table.peers.name); |
Willy Tarreau | d66bf96 | 2011-10-28 14:16:49 +0200 | [diff] [blame] | 6113 | free((void *)curproxy->table.peers.name); |
| 6114 | curproxy->table.peers.p = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 6115 | cfgerr++; |
| 6116 | } |
| 6117 | else if (!curpeers->peers_fe) { |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 6118 | Alert("Proxy '%s': unable to find local peer '%s' in peers section '%s'.\n", |
| 6119 | curproxy->id, localpeer, curpeers->id); |
Willy Tarreau | d66bf96 | 2011-10-28 14:16:49 +0200 | [diff] [blame] | 6120 | curproxy->table.peers.p = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 6121 | cfgerr++; |
| 6122 | } |
| 6123 | } |
| 6124 | |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 6125 | if (curproxy->uri_auth && !(curproxy->uri_auth->flags & ST_CONVDONE) && |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 6126 | !LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) && |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6127 | (curproxy->uri_auth->userlist || curproxy->uri_auth->auth_realm )) { |
| 6128 | Alert("%s '%s': stats 'auth'/'realm' and 'http-request' can't be used at the same time.\n", |
| 6129 | "proxy", curproxy->id); |
| 6130 | cfgerr++; |
| 6131 | goto out_uri_auth_compat; |
| 6132 | } |
| 6133 | |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 6134 | 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] | 6135 | const char *uri_auth_compat_req[10]; |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 6136 | struct http_req_rule *rule; |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6137 | int i = 0; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6138 | |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6139 | /* build the ACL condition from scratch. We're relying on anonymous ACLs for that */ |
| 6140 | uri_auth_compat_req[i++] = "auth"; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6141 | |
| 6142 | if (curproxy->uri_auth->auth_realm) { |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6143 | uri_auth_compat_req[i++] = "realm"; |
| 6144 | uri_auth_compat_req[i++] = curproxy->uri_auth->auth_realm; |
| 6145 | } |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6146 | |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6147 | uri_auth_compat_req[i++] = "unless"; |
| 6148 | uri_auth_compat_req[i++] = "{"; |
| 6149 | uri_auth_compat_req[i++] = "http_auth(.internal-stats-userlist)"; |
| 6150 | uri_auth_compat_req[i++] = "}"; |
| 6151 | uri_auth_compat_req[i++] = ""; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6152 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 6153 | rule = parse_http_req_cond(uri_auth_compat_req, "internal-stats-auth-compat", 0, curproxy); |
| 6154 | if (!rule) { |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6155 | cfgerr++; |
| 6156 | break; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6157 | } |
| 6158 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 6159 | LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list); |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6160 | |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6161 | if (curproxy->uri_auth->auth_realm) { |
| 6162 | free(curproxy->uri_auth->auth_realm); |
| 6163 | curproxy->uri_auth->auth_realm = NULL; |
| 6164 | } |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 6165 | |
| 6166 | curproxy->uri_auth->flags |= ST_CONVDONE; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6167 | } |
| 6168 | out_uri_auth_compat: |
| 6169 | |
Krzysztof Piotr Oledzki | f9423ae | 2010-01-29 19:26:18 +0100 | [diff] [blame] | 6170 | cfgerr += acl_find_targets(curproxy); |
| 6171 | |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 6172 | if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) && |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6173 | (((curproxy->cap & PR_CAP_FE) && !curproxy->timeout.client) || |
Willy Tarreau | d825eef | 2007-05-12 22:35:00 +0200 | [diff] [blame] | 6174 | ((curproxy->cap & PR_CAP_BE) && (curproxy->srv) && |
Willy Tarreau | ce887fd | 2012-05-12 12:50:00 +0200 | [diff] [blame] | 6175 | (!curproxy->timeout.connect || |
| 6176 | (!curproxy->timeout.server && (curproxy->mode == PR_MODE_HTTP || !curproxy->timeout.tunnel)))))) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6177 | Warning("config : missing timeouts for %s '%s'.\n" |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 6178 | " | While not properly invalid, you will certainly encounter various problems\n" |
| 6179 | " | 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] | 6180 | " | timeouts are set to a non-zero value: 'client', 'connect', 'server'.\n", |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6181 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6182 | err_code |= ERR_WARN; |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 6183 | } |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 6184 | |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6185 | /* Historically, the tarpit and queue timeouts were inherited from contimeout. |
| 6186 | * We must still support older configurations, so let's find out whether those |
| 6187 | * parameters have been set or must be copied from contimeouts. |
| 6188 | */ |
| 6189 | if (curproxy != &defproxy) { |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6190 | if (!curproxy->timeout.tarpit || |
| 6191 | curproxy->timeout.tarpit == defproxy.timeout.tarpit) { |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6192 | /* tarpit timeout not set. We search in the following order: |
| 6193 | * default.tarpit, curr.connect, default.connect. |
| 6194 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6195 | if (defproxy.timeout.tarpit) |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6196 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6197 | else if (curproxy->timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6198 | curproxy->timeout.tarpit = curproxy->timeout.connect; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6199 | else if (defproxy.timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6200 | curproxy->timeout.tarpit = defproxy.timeout.connect; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6201 | } |
| 6202 | if ((curproxy->cap & PR_CAP_BE) && |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6203 | (!curproxy->timeout.queue || |
| 6204 | curproxy->timeout.queue == defproxy.timeout.queue)) { |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6205 | /* queue timeout not set. We search in the following order: |
| 6206 | * default.queue, curr.connect, default.connect. |
| 6207 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6208 | if (defproxy.timeout.queue) |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6209 | curproxy->timeout.queue = defproxy.timeout.queue; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6210 | else if (curproxy->timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6211 | curproxy->timeout.queue = curproxy->timeout.connect; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6212 | else if (defproxy.timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6213 | curproxy->timeout.queue = defproxy.timeout.connect; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6214 | } |
| 6215 | } |
| 6216 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 6217 | if ((curproxy->options2 & PR_O2_CHK_ANY) == PR_O2_SSL3_CHK) { |
Willy Tarreau | 137325d | 2010-02-01 16:38:17 +0100 | [diff] [blame] | 6218 | curproxy->check_len = sizeof(sslv3_client_hello_pkt) - 1; |
| 6219 | curproxy->check_req = (char *)malloc(curproxy->check_len); |
| 6220 | memcpy(curproxy->check_req, sslv3_client_hello_pkt, curproxy->check_len); |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 6221 | } |
| 6222 | |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 6223 | /* The small pools required for the capture lists */ |
Willy Tarreau | 9a54e13 | 2012-03-24 08:33:05 +0100 | [diff] [blame] | 6224 | if (curproxy->nb_req_cap) { |
| 6225 | if (curproxy->mode == PR_MODE_HTTP) { |
| 6226 | curproxy->req_cap_pool = create_pool("ptrcap", |
| 6227 | curproxy->nb_req_cap * sizeof(char *), |
| 6228 | MEM_F_SHARED); |
| 6229 | } else { |
| 6230 | Warning("config : 'capture request header' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6231 | proxy_type_str(curproxy), curproxy->id); |
| 6232 | err_code |= ERR_WARN; |
| 6233 | curproxy->to_log &= ~LW_REQHDR; |
| 6234 | curproxy->nb_req_cap = 0; |
| 6235 | } |
| 6236 | } |
| 6237 | |
| 6238 | if (curproxy->nb_rsp_cap) { |
| 6239 | if (curproxy->mode == PR_MODE_HTTP) { |
| 6240 | curproxy->rsp_cap_pool = create_pool("ptrcap", |
| 6241 | curproxy->nb_rsp_cap * sizeof(char *), |
| 6242 | MEM_F_SHARED); |
| 6243 | } else { |
| 6244 | Warning("config : 'capture response header' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6245 | proxy_type_str(curproxy), curproxy->id); |
| 6246 | err_code |= ERR_WARN; |
| 6247 | curproxy->to_log &= ~LW_REQHDR; |
| 6248 | curproxy->nb_rsp_cap = 0; |
| 6249 | } |
| 6250 | } |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 6251 | |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 6252 | /* compile the log format */ |
Willy Tarreau | 99a7ca2 | 2012-05-31 19:39:23 +0200 | [diff] [blame] | 6253 | if (!(curproxy->cap & PR_CAP_FE)) { |
| 6254 | if (curproxy->logformat_string != default_http_log_format && |
| 6255 | curproxy->logformat_string != default_tcp_log_format && |
| 6256 | curproxy->logformat_string != clf_http_log_format) |
| 6257 | free(curproxy->logformat_string); |
| 6258 | curproxy->logformat_string = NULL; |
| 6259 | } |
| 6260 | |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 6261 | if (curproxy->logformat_string) |
| 6262 | parse_logformat_string(curproxy->logformat_string, curproxy, &curproxy->logformat, curproxy->mode); |
| 6263 | |
| 6264 | if (curproxy->uniqueid_format_string) |
| 6265 | parse_logformat_string(curproxy->uniqueid_format_string, curproxy, &curproxy->format_unique_id, PR_MODE_HTTP); |
| 6266 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6267 | /* first, we will invert the servers list order */ |
| 6268 | newsrv = NULL; |
| 6269 | while (curproxy->srv) { |
| 6270 | struct server *next; |
| 6271 | |
| 6272 | next = curproxy->srv->next; |
| 6273 | curproxy->srv->next = newsrv; |
| 6274 | newsrv = curproxy->srv; |
| 6275 | if (!next) |
| 6276 | break; |
| 6277 | curproxy->srv = next; |
| 6278 | } |
| 6279 | |
Willy Tarreau | dd70165 | 2010-05-25 23:03:02 +0200 | [diff] [blame] | 6280 | /* assign automatic UIDs to servers which don't have one yet */ |
| 6281 | next_id = 1; |
| 6282 | newsrv = curproxy->srv; |
| 6283 | while (newsrv != NULL) { |
| 6284 | if (!newsrv->puid) { |
| 6285 | /* server ID not set, use automatic numbering with first |
| 6286 | * spare entry starting with next_svid. |
| 6287 | */ |
| 6288 | next_id = get_next_id(&curproxy->conf.used_server_id, next_id); |
| 6289 | newsrv->conf.id.key = newsrv->puid = next_id; |
| 6290 | eb32_insert(&curproxy->conf.used_server_id, &newsrv->conf.id); |
| 6291 | } |
| 6292 | next_id++; |
| 6293 | newsrv = newsrv->next; |
| 6294 | } |
| 6295 | |
Willy Tarreau | 2069704 | 2007-11-15 23:26:18 +0100 | [diff] [blame] | 6296 | curproxy->lbprm.wmult = 1; /* default weight multiplier */ |
Willy Tarreau | 5dc2fa6 | 2007-11-19 19:10:18 +0100 | [diff] [blame] | 6297 | curproxy->lbprm.wdiv = 1; /* default weight divider */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6298 | |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 6299 | /* |
| 6300 | * If this server supports a maxconn parameter, it needs a dedicated |
| 6301 | * tasks to fill the emptied slots when a connection leaves. |
| 6302 | * Also, resolve deferred tracking dependency if needed. |
| 6303 | */ |
| 6304 | newsrv = curproxy->srv; |
| 6305 | while (newsrv != NULL) { |
| 6306 | if (newsrv->minconn > newsrv->maxconn) { |
| 6307 | /* Only 'minconn' was specified, or it was higher than or equal |
| 6308 | * to 'maxconn'. Let's turn this into maxconn and clean it, as |
| 6309 | * this will avoid further useless expensive computations. |
| 6310 | */ |
| 6311 | newsrv->maxconn = newsrv->minconn; |
| 6312 | } else if (newsrv->maxconn && !newsrv->minconn) { |
| 6313 | /* minconn was not specified, so we set it to maxconn */ |
| 6314 | newsrv->minconn = newsrv->maxconn; |
| 6315 | } |
| 6316 | |
Emeric Brun | 01f8e2f | 2012-05-18 16:02:00 +0200 | [diff] [blame] | 6317 | #ifdef USE_OPENSSL |
Emeric Brun | 94324a4 | 2012-10-11 14:00:19 +0200 | [diff] [blame] | 6318 | if (newsrv->use_ssl || newsrv->check.use_ssl) |
| 6319 | cfgerr += ssl_sock_prepare_srv_ctx(newsrv, curproxy); |
Emeric Brun | 01f8e2f | 2012-05-18 16:02:00 +0200 | [diff] [blame] | 6320 | #endif /* USE_OPENSSL */ |
Emeric Brun | 94324a4 | 2012-10-11 14:00:19 +0200 | [diff] [blame] | 6321 | |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 6322 | if (newsrv->trackit) { |
| 6323 | struct proxy *px; |
| 6324 | struct server *srv; |
| 6325 | char *pname, *sname; |
| 6326 | |
| 6327 | pname = newsrv->trackit; |
| 6328 | sname = strrchr(pname, '/'); |
| 6329 | |
| 6330 | if (sname) |
| 6331 | *sname++ = '\0'; |
| 6332 | else { |
| 6333 | sname = pname; |
| 6334 | pname = NULL; |
| 6335 | } |
| 6336 | |
| 6337 | if (pname) { |
| 6338 | px = findproxy(pname, PR_CAP_BE); |
| 6339 | if (!px) { |
| 6340 | Alert("config : %s '%s', server '%s': unable to find required proxy '%s' for tracking.\n", |
| 6341 | proxy_type_str(curproxy), curproxy->id, |
| 6342 | newsrv->id, pname); |
| 6343 | cfgerr++; |
| 6344 | goto next_srv; |
| 6345 | } |
| 6346 | } else |
| 6347 | px = curproxy; |
| 6348 | |
| 6349 | srv = findserver(px, sname); |
| 6350 | if (!srv) { |
| 6351 | Alert("config : %s '%s', server '%s': unable to find required server '%s' for tracking.\n", |
| 6352 | proxy_type_str(curproxy), curproxy->id, |
| 6353 | newsrv->id, sname); |
| 6354 | cfgerr++; |
| 6355 | goto next_srv; |
| 6356 | } |
| 6357 | |
| 6358 | if (!(srv->state & SRV_CHECKED)) { |
| 6359 | Alert("config : %s '%s', server '%s': unable to use %s/%s for " |
| 6360 | "tracking as it does not have checks enabled.\n", |
| 6361 | proxy_type_str(curproxy), curproxy->id, |
| 6362 | newsrv->id, px->id, srv->id); |
| 6363 | cfgerr++; |
| 6364 | goto next_srv; |
| 6365 | } |
| 6366 | |
| 6367 | if (curproxy != px && |
| 6368 | (curproxy->options & PR_O_DISABLE404) != (px->options & PR_O_DISABLE404)) { |
| 6369 | Alert("config : %s '%s', server '%s': unable to use %s/%s for" |
| 6370 | "tracking: disable-on-404 option inconsistency.\n", |
| 6371 | proxy_type_str(curproxy), curproxy->id, |
| 6372 | newsrv->id, px->id, srv->id); |
| 6373 | cfgerr++; |
| 6374 | goto next_srv; |
| 6375 | } |
| 6376 | |
| 6377 | /* if the other server is forced disabled, we have to do the same here */ |
| 6378 | if (srv->state & SRV_MAINTAIN) { |
| 6379 | newsrv->state |= SRV_MAINTAIN; |
| 6380 | newsrv->state &= ~SRV_RUNNING; |
| 6381 | newsrv->health = 0; |
| 6382 | } |
| 6383 | |
| 6384 | newsrv->track = srv; |
| 6385 | newsrv->tracknext = srv->tracknext; |
| 6386 | srv->tracknext = newsrv; |
| 6387 | |
| 6388 | free(newsrv->trackit); |
| 6389 | newsrv->trackit = NULL; |
| 6390 | } |
| 6391 | next_srv: |
| 6392 | newsrv = newsrv->next; |
| 6393 | } |
| 6394 | |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6395 | /* We have to initialize the server lookup mechanism depending |
| 6396 | * on what LB algorithm was choosen. |
| 6397 | */ |
| 6398 | |
| 6399 | curproxy->lbprm.algo &= ~(BE_LB_LKUP | BE_LB_PROP_DYN); |
| 6400 | switch (curproxy->lbprm.algo & BE_LB_KIND) { |
| 6401 | case BE_LB_KIND_RR: |
Willy Tarreau | 9757a38 | 2009-10-03 12:56:50 +0200 | [diff] [blame] | 6402 | if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_RR_STATIC) { |
| 6403 | curproxy->lbprm.algo |= BE_LB_LKUP_MAP; |
| 6404 | init_server_map(curproxy); |
| 6405 | } else { |
| 6406 | curproxy->lbprm.algo |= BE_LB_LKUP_RRTREE | BE_LB_PROP_DYN; |
| 6407 | fwrr_init_server_groups(curproxy); |
| 6408 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6409 | break; |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 6410 | |
Willy Tarreau | 3ebb116 | 2012-02-13 16:57:44 +0100 | [diff] [blame] | 6411 | case BE_LB_KIND_CB: |
Willy Tarreau | f09c660 | 2012-02-13 17:12:08 +0100 | [diff] [blame] | 6412 | if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_CB_LC) { |
| 6413 | curproxy->lbprm.algo |= BE_LB_LKUP_LCTREE | BE_LB_PROP_DYN; |
| 6414 | fwlc_init_server_tree(curproxy); |
| 6415 | } else { |
| 6416 | curproxy->lbprm.algo |= BE_LB_LKUP_FSTREE | BE_LB_PROP_DYN; |
| 6417 | fas_init_server_tree(curproxy); |
| 6418 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6419 | break; |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 6420 | |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6421 | case BE_LB_KIND_HI: |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 6422 | if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS) { |
| 6423 | curproxy->lbprm.algo |= BE_LB_LKUP_CHTREE | BE_LB_PROP_DYN; |
| 6424 | chash_init_server_tree(curproxy); |
| 6425 | } else { |
| 6426 | curproxy->lbprm.algo |= BE_LB_LKUP_MAP; |
| 6427 | init_server_map(curproxy); |
| 6428 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6429 | break; |
| 6430 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6431 | |
| 6432 | if (curproxy->options & PR_O_LOGASAP) |
| 6433 | curproxy->to_log &= ~LW_BYTES; |
| 6434 | |
Willy Tarreau | e7ded1f | 2009-08-09 10:11:45 +0200 | [diff] [blame] | 6435 | if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) && |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6436 | (curproxy->cap & PR_CAP_FE) && curproxy->to_log && LIST_ISEMPTY(&curproxy->logsrvs)) { |
Willy Tarreau | e7ded1f | 2009-08-09 10:11:45 +0200 | [diff] [blame] | 6437 | Warning("config : log format ignored for %s '%s' since it has no log address.\n", |
| 6438 | proxy_type_str(curproxy), curproxy->id); |
| 6439 | err_code |= ERR_WARN; |
| 6440 | } |
| 6441 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 6442 | if (curproxy->mode != PR_MODE_HTTP) { |
| 6443 | int optnum; |
| 6444 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 6445 | if (curproxy->uri_auth) { |
| 6446 | Warning("config : 'stats' statement ignored for %s '%s' as it requires HTTP mode.\n", |
| 6447 | proxy_type_str(curproxy), curproxy->id); |
| 6448 | err_code |= ERR_WARN; |
| 6449 | curproxy->uri_auth = NULL; |
| 6450 | } |
| 6451 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 6452 | if (curproxy->options & (PR_O_FWDFOR | PR_O_FF_ALWAYS)) { |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 6453 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6454 | "forwardfor", proxy_type_str(curproxy), curproxy->id); |
| 6455 | err_code |= ERR_WARN; |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 6456 | curproxy->options &= ~(PR_O_FWDFOR | PR_O_FF_ALWAYS); |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 6457 | } |
| 6458 | |
| 6459 | if (curproxy->options & PR_O_ORGTO) { |
| 6460 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6461 | "originalto", proxy_type_str(curproxy), curproxy->id); |
| 6462 | err_code |= ERR_WARN; |
| 6463 | curproxy->options &= ~PR_O_ORGTO; |
| 6464 | } |
| 6465 | |
| 6466 | for (optnum = 0; cfg_opts[optnum].name; optnum++) { |
| 6467 | if (cfg_opts[optnum].mode == PR_MODE_HTTP && |
| 6468 | (curproxy->cap & cfg_opts[optnum].cap) && |
| 6469 | (curproxy->options & cfg_opts[optnum].val)) { |
| 6470 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6471 | cfg_opts[optnum].name, proxy_type_str(curproxy), curproxy->id); |
| 6472 | err_code |= ERR_WARN; |
| 6473 | curproxy->options &= ~cfg_opts[optnum].val; |
| 6474 | } |
| 6475 | } |
| 6476 | |
| 6477 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) { |
| 6478 | if (cfg_opts2[optnum].mode == PR_MODE_HTTP && |
| 6479 | (curproxy->cap & cfg_opts2[optnum].cap) && |
| 6480 | (curproxy->options2 & cfg_opts2[optnum].val)) { |
| 6481 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6482 | cfg_opts2[optnum].name, proxy_type_str(curproxy), curproxy->id); |
| 6483 | err_code |= ERR_WARN; |
| 6484 | curproxy->options2 &= ~cfg_opts2[optnum].val; |
| 6485 | } |
| 6486 | } |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6487 | |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 6488 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6489 | if (curproxy->bind_hdr_occ) { |
| 6490 | curproxy->bind_hdr_occ = 0; |
| 6491 | Warning("config : %s '%s' : ignoring use of header %s as source IP in non-HTTP mode.\n", |
| 6492 | proxy_type_str(curproxy), curproxy->id, curproxy->bind_hdr_name); |
| 6493 | err_code |= ERR_WARN; |
| 6494 | } |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 6495 | #endif |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 6496 | } |
| 6497 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6498 | /* |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 6499 | * ensure that we're not cross-dressing a TCP server into HTTP. |
| 6500 | */ |
| 6501 | newsrv = curproxy->srv; |
| 6502 | while (newsrv != NULL) { |
Willy Tarreau | 0cec331 | 2011-10-31 13:49:26 +0100 | [diff] [blame] | 6503 | if ((curproxy->mode != PR_MODE_HTTP) && newsrv->rdr_len) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6504 | Alert("config : %s '%s' : server cannot have cookie or redirect prefix in non-HTTP mode.\n", |
| 6505 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6506 | cfgerr++; |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 6507 | } |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6508 | |
Willy Tarreau | 0cec331 | 2011-10-31 13:49:26 +0100 | [diff] [blame] | 6509 | if ((curproxy->mode != PR_MODE_HTTP) && newsrv->cklen) { |
| 6510 | Warning("config : %s '%s' : ignoring cookie for server '%s' as HTTP mode is disabled.\n", |
| 6511 | proxy_type_str(curproxy), curproxy->id, newsrv->id); |
| 6512 | err_code |= ERR_WARN; |
| 6513 | } |
| 6514 | |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 6515 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6516 | if (curproxy->mode != PR_MODE_HTTP && newsrv->bind_hdr_occ) { |
| 6517 | newsrv->bind_hdr_occ = 0; |
| 6518 | Warning("config : %s '%s' : server %s cannot use header %s as source IP in non-HTTP mode.\n", |
| 6519 | proxy_type_str(curproxy), curproxy->id, newsrv->id, newsrv->bind_hdr_name); |
| 6520 | err_code |= ERR_WARN; |
| 6521 | } |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 6522 | #endif |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 6523 | newsrv = newsrv->next; |
| 6524 | } |
| 6525 | |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6526 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 6527 | if (!curproxy->accept) |
| 6528 | curproxy->accept = frontend_accept; |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 6529 | |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6530 | if (curproxy->tcp_req.inspect_delay || |
| 6531 | !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules)) |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 6532 | curproxy->fe_req_ana |= AN_REQ_INSPECT_FE; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6533 | |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 6534 | if (curproxy->mode == PR_MODE_HTTP) { |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6535 | 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] | 6536 | 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] | 6537 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6538 | |
| 6539 | /* both TCP and HTTP must check switching rules */ |
| 6540 | curproxy->fe_req_ana |= AN_REQ_SWITCHING_RULES; |
| 6541 | } |
| 6542 | |
| 6543 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 6544 | if (curproxy->tcp_req.inspect_delay || |
| 6545 | !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules)) |
| 6546 | curproxy->be_req_ana |= AN_REQ_INSPECT_BE; |
| 6547 | |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 6548 | if (!LIST_ISEMPTY(&curproxy->tcp_rep.inspect_rules)) |
| 6549 | curproxy->be_rsp_ana |= AN_RES_INSPECT; |
| 6550 | |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 6551 | if (curproxy->mode == PR_MODE_HTTP) { |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6552 | 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] | 6553 | 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] | 6554 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6555 | |
| 6556 | /* If the backend does requires RDP cookie persistence, we have to |
| 6557 | * enable the corresponding analyser. |
| 6558 | */ |
| 6559 | if (curproxy->options2 & PR_O2_RDPC_PRST) |
| 6560 | curproxy->be_req_ana |= AN_REQ_PRST_RDP_COOKIE; |
| 6561 | } |
| 6562 | |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 6563 | /* Configure SSL for each bind line. |
| 6564 | * Note: if configuration fails at some point, the ->ctx member |
| 6565 | * remains NULL so that listeners can later detach. |
| 6566 | */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6567 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
| 6568 | if (!bind_conf->is_ssl) |
| 6569 | continue; |
| 6570 | #ifdef USE_OPENSSL |
| 6571 | if (!bind_conf->default_ctx) { |
Emeric Brun | fc0421f | 2012-09-07 17:30:07 +0200 | [diff] [blame] | 6572 | 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] | 6573 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 6574 | cfgerr++; |
| 6575 | continue; |
| 6576 | } |
| 6577 | |
Emeric Brun | 4b3091e | 2012-09-24 15:48:52 +0200 | [diff] [blame] | 6578 | if (shared_context_init(global.tune.sslcachesize, (global.nbproc > 1) ? 1 : 0) < 0) { |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 6579 | Alert("Unable to allocate SSL session cache.\n"); |
| 6580 | cfgerr++; |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 6581 | continue; |
| 6582 | } |
| 6583 | |
Emeric Brun | fc0421f | 2012-09-07 17:30:07 +0200 | [diff] [blame] | 6584 | /* initialize all certificate contexts */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6585 | cfgerr += ssl_sock_prepare_all_ctx(bind_conf, curproxy); |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 6586 | #endif /* USE_OPENSSL */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6587 | } |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 6588 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 6589 | /* adjust this proxy's listeners */ |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6590 | next_id = 1; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 6591 | list_for_each_entry(listener, &curproxy->conf.listeners, by_fe) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6592 | if (!listener->luid) { |
| 6593 | /* listener ID not set, use automatic numbering with first |
| 6594 | * spare entry starting with next_luid. |
| 6595 | */ |
| 6596 | next_id = get_next_id(&curproxy->conf.used_listener_id, next_id); |
| 6597 | listener->conf.id.key = listener->luid = next_id; |
| 6598 | eb32_insert(&curproxy->conf.used_listener_id, &listener->conf.id); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6599 | } |
Krzysztof Piotr Oledzki | df5cb9f | 2010-02-05 20:58:27 +0100 | [diff] [blame] | 6600 | next_id++; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6601 | |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 6602 | /* enable separate counters */ |
| 6603 | if (curproxy->options2 & PR_O2_SOCKSTAT) { |
| 6604 | listener->counters = (struct licounters *)calloc(1, sizeof(struct licounters)); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6605 | if (!listener->name) |
| 6606 | memprintf(&listener->name, "sock-%d", listener->luid); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 6607 | } |
Willy Tarreau | 81796be | 2012-09-22 19:11:47 +0200 | [diff] [blame] | 6608 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 6609 | if (curproxy->options & PR_O_TCP_NOLING) |
| 6610 | listener->options |= LI_O_NOLINGER; |
Willy Tarreau | 32368ce | 2012-09-06 11:10:55 +0200 | [diff] [blame] | 6611 | if (!listener->maxconn) |
| 6612 | listener->maxconn = curproxy->maxconn; |
| 6613 | if (!listener->backlog) |
| 6614 | listener->backlog = curproxy->backlog; |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6615 | listener->timeout = &curproxy->timeout.client; |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 6616 | listener->accept = session_accept; |
Willy Tarreau | 3bc1377 | 2008-12-07 11:50:35 +0100 | [diff] [blame] | 6617 | listener->handler = process_session; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6618 | listener->analysers |= curproxy->fe_req_ana; |
Willy Tarreau | 3bc1377 | 2008-12-07 11:50:35 +0100 | [diff] [blame] | 6619 | |
Willy Tarreau | a5c0ab2 | 2010-05-31 10:30:33 +0200 | [diff] [blame] | 6620 | if (!LIST_ISEMPTY(&curproxy->tcp_req.l4_rules)) |
| 6621 | listener->options |= LI_O_TCP_RULES; |
| 6622 | |
Willy Tarreau | de3041d | 2010-05-31 10:56:17 +0200 | [diff] [blame] | 6623 | if (curproxy->mon_mask.s_addr) |
| 6624 | listener->options |= LI_O_CHK_MONNET; |
| 6625 | |
Willy Tarreau | 9ea05a7 | 2009-06-14 12:07:01 +0200 | [diff] [blame] | 6626 | /* smart accept mode is automatic in HTTP mode */ |
| 6627 | if ((curproxy->options2 & PR_O2_SMARTACC) || |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6628 | ((curproxy->mode == PR_MODE_HTTP || listener->bind_conf->is_ssl) && |
Willy Tarreau | 9ea05a7 | 2009-06-14 12:07:01 +0200 | [diff] [blame] | 6629 | !(curproxy->no_options2 & PR_O2_SMARTACC))) |
| 6630 | listener->options |= LI_O_NOQUICKACK; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 6631 | } |
| 6632 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6633 | /* Release unused SSL configs */ |
| 6634 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
| 6635 | if (bind_conf->is_ssl) |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 6636 | continue; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6637 | #ifdef USE_OPENSSL |
| 6638 | ssl_sock_free_all_ctx(bind_conf); |
Emeric Brun | fb510ea | 2012-10-05 12:00:26 +0200 | [diff] [blame] | 6639 | free(bind_conf->ca_file); |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6640 | free(bind_conf->ciphers); |
Emeric Brun | 2b58d04 | 2012-09-20 17:10:03 +0200 | [diff] [blame] | 6641 | free(bind_conf->ecdhe); |
Emeric Brun | fb510ea | 2012-10-05 12:00:26 +0200 | [diff] [blame] | 6642 | free(bind_conf->crl_file); |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 6643 | #endif /* USE_OPENSSL */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6644 | } |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 6645 | |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 6646 | /* Check multi-process mode compatibility for the current proxy */ |
| 6647 | if (global.nbproc > 1) { |
| 6648 | int nbproc = 0; |
| 6649 | if (curproxy->bind_proc) { |
| 6650 | int proc; |
| 6651 | for (proc = 0; proc < global.nbproc; proc++) { |
| 6652 | if (curproxy->bind_proc & (1 << proc)) { |
| 6653 | nbproc++; |
| 6654 | } |
| 6655 | } |
| 6656 | } else { |
| 6657 | nbproc = global.nbproc; |
| 6658 | } |
| 6659 | if (curproxy->table.peers.name) { |
| 6660 | Alert("Proxy '%s': peers can't be used in multi-process mode (nbproc > 1).\n", |
| 6661 | curproxy->id); |
| 6662 | cfgerr++; |
| 6663 | } |
| 6664 | if (nbproc > 1) { |
| 6665 | if (curproxy->uri_auth) { |
| 6666 | Warning("Proxy '%s': in multi-process mode, stats will be limited to process assigned to the current request.\n", |
| 6667 | curproxy->id); |
| 6668 | if (!LIST_ISEMPTY(&curproxy->uri_auth->admin_rules)) { |
| 6669 | Warning("Proxy '%s': stats admin will not work correctly in multi-process mode.\n", |
| 6670 | curproxy->id); |
| 6671 | } |
| 6672 | } |
| 6673 | if (curproxy->appsession_name) { |
| 6674 | Warning("Proxy '%s': appsession will not work correctly in multi-process mode.\n", |
| 6675 | curproxy->id); |
| 6676 | } |
| 6677 | if (!LIST_ISEMPTY(&curproxy->sticking_rules)) { |
| 6678 | Warning("Proxy '%s': sticking rules will not work correctly in multi-process mode.\n", |
| 6679 | curproxy->id); |
| 6680 | } |
| 6681 | } |
| 6682 | } |
Willy Tarreau | 918ff60 | 2011-07-25 16:33:49 +0200 | [diff] [blame] | 6683 | |
| 6684 | /* create the task associated with the proxy */ |
| 6685 | curproxy->task = task_new(); |
| 6686 | if (curproxy->task) { |
| 6687 | curproxy->task->context = curproxy; |
| 6688 | curproxy->task->process = manage_proxy; |
| 6689 | /* no need to queue, it will be done automatically if some |
| 6690 | * listener gets limited. |
| 6691 | */ |
| 6692 | curproxy->task->expire = TICK_ETERNITY; |
| 6693 | } else { |
| 6694 | Alert("Proxy '%s': no more memory when trying to allocate the management task\n", |
| 6695 | curproxy->id); |
| 6696 | cfgerr++; |
| 6697 | } |
| 6698 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6699 | curproxy = curproxy->next; |
| 6700 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 6701 | |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 6702 | /* Check multi-process mode compatibility */ |
| 6703 | if (global.nbproc > 1) { |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 6704 | if (global.stats_fe && !global.stats_fe->bind_proc) { |
| 6705 | Warning("stats socket will not work as expected in multi-process mode (nbproc > 1), you should force process binding using 'stats bind-process'.\n"); |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 6706 | } |
| 6707 | } |
| 6708 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6709 | for (curuserlist = userlist; curuserlist; curuserlist = curuserlist->next) { |
| 6710 | struct auth_users *curuser; |
| 6711 | int g; |
| 6712 | |
| 6713 | for (curuser = curuserlist->users; curuser; curuser = curuser->next) { |
| 6714 | unsigned int group_mask = 0; |
| 6715 | char *group = NULL; |
| 6716 | |
Willy Tarreau | b4c06b7 | 2010-02-02 11:28:20 +0100 | [diff] [blame] | 6717 | if (!curuser->u.groups) |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6718 | continue; |
| 6719 | |
Willy Tarreau | b4c06b7 | 2010-02-02 11:28:20 +0100 | [diff] [blame] | 6720 | while ((group = strtok(group?NULL:curuser->u.groups, ","))) { |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6721 | |
| 6722 | for (g = 0; g < curuserlist->grpcnt; g++) |
| 6723 | if (!strcmp(curuserlist->groups[g], group)) |
| 6724 | break; |
| 6725 | |
| 6726 | if (g == curuserlist->grpcnt) { |
| 6727 | Alert("userlist '%s': no such group '%s' specified in user '%s'\n", |
| 6728 | curuserlist->name, group, curuser->user); |
| 6729 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6730 | goto out; |
| 6731 | } |
| 6732 | |
| 6733 | group_mask |= (1 << g); |
| 6734 | } |
| 6735 | |
Willy Tarreau | b4c06b7 | 2010-02-02 11:28:20 +0100 | [diff] [blame] | 6736 | free(curuser->u.groups); |
| 6737 | curuser->u.group_mask = group_mask; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6738 | } |
| 6739 | |
| 6740 | for (g = 0; g < curuserlist->grpcnt; g++) { |
| 6741 | char *user = NULL; |
| 6742 | |
| 6743 | if (!curuserlist->groupusers[g]) |
| 6744 | continue; |
| 6745 | |
| 6746 | while ((user = strtok(user?NULL:curuserlist->groupusers[g], ","))) { |
| 6747 | for (curuser = curuserlist->users; curuser; curuser = curuser->next) |
| 6748 | if (!strcmp(curuser->user, user)) |
| 6749 | break; |
| 6750 | |
| 6751 | if (!curuser) { |
| 6752 | Alert("userlist '%s': no such user '%s' specified in group '%s'\n", |
| 6753 | curuserlist->name, user, curuserlist->groups[g]); |
| 6754 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6755 | goto out; |
| 6756 | } |
| 6757 | |
Willy Tarreau | b4c06b7 | 2010-02-02 11:28:20 +0100 | [diff] [blame] | 6758 | curuser->u.group_mask |= (1 << g); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6759 | } |
| 6760 | |
| 6761 | free(curuserlist->groupusers[g]); |
| 6762 | } |
| 6763 | |
| 6764 | free(curuserlist->groupusers); |
| 6765 | |
| 6766 | #ifdef DEBUG_AUTH |
| 6767 | for (g = 0; g < curuserlist->grpcnt; g++) { |
| 6768 | fprintf(stderr, "group %s, id %d, mask %08X, users:", curuserlist->groups[g], g , 1 << g); |
| 6769 | |
| 6770 | for (curuser = curuserlist->users; curuser; curuser = curuser->next) { |
Willy Tarreau | b950959 | 2012-05-10 23:25:35 +0200 | [diff] [blame] | 6771 | if (curuser->u.group_mask & (1 << g)) |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6772 | fprintf(stderr, " %s", curuser->user); |
| 6773 | } |
| 6774 | |
| 6775 | fprintf(stderr, "\n"); |
| 6776 | } |
| 6777 | #endif |
| 6778 | |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 6779 | } |
| 6780 | |
| 6781 | /* automatically compute fullconn if not set. We must not do it in the |
| 6782 | * loop above because cross-references are not yet fully resolved. |
| 6783 | */ |
| 6784 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 6785 | /* If <fullconn> is not set, let's set it to 10% of the sum of |
| 6786 | * the possible incoming frontend's maxconns. |
| 6787 | */ |
| 6788 | if (!curproxy->fullconn && (curproxy->cap & PR_CAP_BE)) { |
| 6789 | struct proxy *fe; |
| 6790 | int total = 0; |
| 6791 | |
| 6792 | /* sum up the number of maxconns of frontends which |
| 6793 | * reference this backend at least once or which are |
| 6794 | * the same one ('listen'). |
| 6795 | */ |
| 6796 | for (fe = proxy; fe; fe = fe->next) { |
| 6797 | struct switching_rule *rule; |
| 6798 | struct hdr_exp *exp; |
| 6799 | int found = 0; |
| 6800 | |
| 6801 | if (!(fe->cap & PR_CAP_FE)) |
| 6802 | continue; |
| 6803 | |
| 6804 | if (fe == curproxy) /* we're on a "listen" instance */ |
| 6805 | found = 1; |
| 6806 | |
| 6807 | if (fe->defbe.be == curproxy) /* "default_backend" */ |
| 6808 | found = 1; |
| 6809 | |
| 6810 | /* check if a "use_backend" rule matches */ |
| 6811 | if (!found) { |
| 6812 | list_for_each_entry(rule, &fe->switching_rules, list) { |
| 6813 | if (rule->be.backend == curproxy) { |
| 6814 | found = 1; |
| 6815 | break; |
| 6816 | } |
| 6817 | } |
| 6818 | } |
| 6819 | |
| 6820 | /* check if a "reqsetbe" rule matches */ |
| 6821 | for (exp = fe->req_exp; !found && exp; exp = exp->next) { |
| 6822 | if (exp->action == ACT_SETBE && |
| 6823 | (struct proxy *)exp->replace == curproxy) { |
| 6824 | found = 1; |
| 6825 | break; |
| 6826 | } |
| 6827 | } |
| 6828 | |
| 6829 | /* now we've checked all possible ways to reference a backend |
| 6830 | * from a frontend. |
| 6831 | */ |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 6832 | if (!found) |
| 6833 | continue; |
| 6834 | total += fe->maxconn; |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 6835 | } |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 6836 | /* we have the sum of the maxconns in <total>. We only |
| 6837 | * keep 10% of that sum to set the default fullconn, with |
| 6838 | * a hard minimum of 1 (to avoid a divide by zero). |
| 6839 | */ |
| 6840 | curproxy->fullconn = (total + 9) / 10; |
| 6841 | if (!curproxy->fullconn) |
| 6842 | curproxy->fullconn = 1; |
| 6843 | } |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6844 | } |
| 6845 | |
Willy Tarreau | 056f568 | 2010-06-06 15:51:11 +0200 | [diff] [blame] | 6846 | /* initialize stick-tables on backend capable proxies. This must not |
| 6847 | * be done earlier because the data size may be discovered while parsing |
| 6848 | * other proxies. |
| 6849 | */ |
| 6850 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) |
Willy Tarreau | c00cdc2 | 2010-06-06 16:48:26 +0200 | [diff] [blame] | 6851 | stktable_init(&curproxy->table); |
Willy Tarreau | 056f568 | 2010-06-06 15:51:11 +0200 | [diff] [blame] | 6852 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 6853 | /* |
| 6854 | * Recount currently required checks. |
| 6855 | */ |
| 6856 | |
| 6857 | for (curproxy=proxy; curproxy; curproxy=curproxy->next) { |
| 6858 | int optnum; |
| 6859 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 6860 | for (optnum = 0; cfg_opts[optnum].name; optnum++) |
| 6861 | if (curproxy->options & cfg_opts[optnum].val) |
| 6862 | global.last_checks |= cfg_opts[optnum].checks; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 6863 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 6864 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) |
| 6865 | if (curproxy->options2 & cfg_opts2[optnum].val) |
| 6866 | global.last_checks |= cfg_opts2[optnum].checks; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 6867 | } |
| 6868 | |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 6869 | if (peers) { |
| 6870 | struct peers *curpeers = peers, **last; |
| 6871 | struct peer *p, *pb; |
| 6872 | |
| 6873 | /* Remove all peers sections which don't have a valid listener. |
| 6874 | * This can happen when a peers section is never referenced and |
| 6875 | * does not contain a local peer. |
| 6876 | */ |
| 6877 | last = &peers; |
| 6878 | while (*last) { |
| 6879 | curpeers = *last; |
| 6880 | if (curpeers->peers_fe) { |
| 6881 | last = &curpeers->next; |
| 6882 | continue; |
| 6883 | } |
| 6884 | |
| 6885 | Warning("Removing incomplete section 'peers %s' (no peer named '%s').\n", |
| 6886 | curpeers->id, localpeer); |
| 6887 | |
| 6888 | p = curpeers->remote; |
| 6889 | while (p) { |
| 6890 | pb = p->next; |
| 6891 | free(p->id); |
| 6892 | free(p); |
| 6893 | p = pb; |
| 6894 | } |
| 6895 | |
| 6896 | /* Destroy and unlink this curpeers section. |
| 6897 | * Note: curpeers is backed up into *last. |
| 6898 | */ |
| 6899 | free(curpeers->id); |
| 6900 | curpeers = curpeers->next; |
| 6901 | free(*last); |
| 6902 | *last = curpeers; |
| 6903 | } |
| 6904 | } |
| 6905 | |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame] | 6906 | if (!global.tune.max_http_hdr) |
| 6907 | global.tune.max_http_hdr = MAX_HTTP_HDR; |
| 6908 | |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 6909 | pool2_hdr_idx = create_pool("hdr_idx", |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame] | 6910 | global.tune.max_http_hdr * sizeof(struct hdr_idx_elem), |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 6911 | MEM_F_SHARED); |
| 6912 | |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6913 | if (cfgerr > 0) |
| 6914 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6915 | out: |
| 6916 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6917 | } |
| 6918 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 6919 | /* |
| 6920 | * Registers the CFG keyword list <kwl> as a list of valid keywords for next |
| 6921 | * parsing sessions. |
| 6922 | */ |
| 6923 | void cfg_register_keywords(struct cfg_kw_list *kwl) |
| 6924 | { |
| 6925 | LIST_ADDQ(&cfg_keywords.list, &kwl->list); |
| 6926 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6927 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 6928 | /* |
| 6929 | * Unregisters the CFG keyword list <kwl> from the list of valid keywords. |
| 6930 | */ |
| 6931 | void cfg_unregister_keywords(struct cfg_kw_list *kwl) |
| 6932 | { |
| 6933 | LIST_DEL(&kwl->list); |
| 6934 | LIST_INIT(&kwl->list); |
| 6935 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6936 | |
| 6937 | /* |
| 6938 | * Local variables: |
| 6939 | * c-indent-level: 8 |
| 6940 | * c-basic-offset: 8 |
| 6941 | * End: |
| 6942 | */ |