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> |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 38 | #include <types/obj_type.h> |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 39 | #include <types/peers.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 40 | |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 41 | #include <proto/acl.h> |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 42 | #include <proto/auth.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 43 | #include <proto/backend.h> |
Willy Tarreau | c7e4238 | 2012-08-24 19:22:53 +0200 | [diff] [blame] | 44 | #include <proto/channel.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 45 | #include <proto/checks.h> |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 46 | #include <proto/compression.h> |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 47 | #include <proto/dumpstats.h> |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 48 | #include <proto/frontend.h> |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 49 | #include <proto/hdr_idx.h> |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 50 | #include <proto/lb_chash.h> |
Willy Tarreau | f09c660 | 2012-02-13 17:12:08 +0100 | [diff] [blame] | 51 | #include <proto/lb_fas.h> |
Willy Tarreau | f89c187 | 2009-10-01 11:19:37 +0200 | [diff] [blame] | 52 | #include <proto/lb_fwlc.h> |
| 53 | #include <proto/lb_fwrr.h> |
| 54 | #include <proto/lb_map.h> |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 55 | #include <proto/listener.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 56 | #include <proto/log.h> |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 57 | #include <proto/port_range.h> |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 58 | #include <proto/protocol.h> |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 59 | #include <proto/proto_tcp.h> |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 60 | #include <proto/proto_uxst.h> |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 61 | #include <proto/proto_http.h> |
Willy Tarreau | 2b5652f | 2006-12-31 17:46:05 +0100 | [diff] [blame] | 62 | #include <proto/proxy.h> |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 63 | #include <proto/peers.h> |
Willy Tarreau | cd3b094 | 2012-04-27 21:52:18 +0200 | [diff] [blame] | 64 | #include <proto/sample.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 65 | #include <proto/server.h> |
Willy Tarreau | 3bc1377 | 2008-12-07 11:50:35 +0100 | [diff] [blame] | 66 | #include <proto/session.h> |
Willy Tarreau | 75bf2c9 | 2012-08-20 17:01:35 +0200 | [diff] [blame] | 67 | #include <proto/raw_sock.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 68 | #include <proto/task.h> |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 69 | #include <proto/stick_table.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 70 | |
Emeric Brun | fc0421f | 2012-09-07 17:30:07 +0200 | [diff] [blame] | 71 | #ifdef USE_OPENSSL |
| 72 | #include <types/ssl_sock.h> |
| 73 | #include <proto/ssl_sock.h> |
| 74 | #include <proto/shctx.h> |
| 75 | #endif /*USE_OPENSSL */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 76 | |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 77 | /* This is the SSLv3 CLIENT HELLO packet used in conjunction with the |
| 78 | * ssl-hello-chk option to ensure that the remote server speaks SSL. |
| 79 | * |
| 80 | * Check RFC 2246 (TLSv1.0) sections A.3 and A.4 for details. |
| 81 | */ |
| 82 | const char sslv3_client_hello_pkt[] = { |
| 83 | "\x16" /* ContentType : 0x16 = Hanshake */ |
| 84 | "\x03\x00" /* ProtocolVersion : 0x0300 = SSLv3 */ |
| 85 | "\x00\x79" /* ContentLength : 0x79 bytes after this one */ |
| 86 | "\x01" /* HanshakeType : 0x01 = CLIENT HELLO */ |
| 87 | "\x00\x00\x75" /* HandshakeLength : 0x75 bytes after this one */ |
| 88 | "\x03\x00" /* Hello Version : 0x0300 = v3 */ |
| 89 | "\x00\x00\x00\x00" /* Unix GMT Time (s) : filled with <now> (@0x0B) */ |
| 90 | "HAPROXYSSLCHK\nHAPROXYSSLCHK\n" /* Random : must be exactly 28 bytes */ |
| 91 | "\x00" /* Session ID length : empty (no session ID) */ |
| 92 | "\x00\x4E" /* Cipher Suite Length : 78 bytes after this one */ |
| 93 | "\x00\x01" "\x00\x02" "\x00\x03" "\x00\x04" /* 39 most common ciphers : */ |
| 94 | "\x00\x05" "\x00\x06" "\x00\x07" "\x00\x08" /* 0x01...0x1B, 0x2F...0x3A */ |
| 95 | "\x00\x09" "\x00\x0A" "\x00\x0B" "\x00\x0C" /* This covers RSA/DH, */ |
| 96 | "\x00\x0D" "\x00\x0E" "\x00\x0F" "\x00\x10" /* various bit lengths, */ |
| 97 | "\x00\x11" "\x00\x12" "\x00\x13" "\x00\x14" /* SHA1/MD5, DES/3DES/AES... */ |
| 98 | "\x00\x15" "\x00\x16" "\x00\x17" "\x00\x18" |
| 99 | "\x00\x19" "\x00\x1A" "\x00\x1B" "\x00\x2F" |
| 100 | "\x00\x30" "\x00\x31" "\x00\x32" "\x00\x33" |
| 101 | "\x00\x34" "\x00\x35" "\x00\x36" "\x00\x37" |
| 102 | "\x00\x38" "\x00\x39" "\x00\x3A" |
| 103 | "\x01" /* Compression Length : 0x01 = 1 byte for types */ |
| 104 | "\x00" /* Compression Type : 0x00 = NULL compression */ |
| 105 | }; |
| 106 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 107 | /* various keyword modifiers */ |
| 108 | enum kw_mod { |
| 109 | KWM_STD = 0, /* normal */ |
| 110 | KWM_NO, /* "no" prefixed before the keyword */ |
| 111 | KWM_DEF, /* "default" prefixed before the keyword */ |
| 112 | }; |
| 113 | |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 114 | /* 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] | 115 | struct cfg_opt { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 116 | const char *name; |
| 117 | unsigned int val; |
| 118 | unsigned int cap; |
Willy Tarreau | 4fee4e9 | 2007-01-06 21:09:17 +0100 | [diff] [blame] | 119 | unsigned int checks; |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 120 | unsigned int mode; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 121 | }; |
| 122 | |
| 123 | /* proxy->options */ |
| 124 | static const struct cfg_opt cfg_opts[] = |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 125 | { |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 126 | { "abortonclose", PR_O_ABRT_CLOSE, PR_CAP_BE, 0, 0 }, |
| 127 | { "allbackups", PR_O_USE_ALL_BK, PR_CAP_BE, 0, 0 }, |
| 128 | { "checkcache", PR_O_CHK_CACHE, PR_CAP_BE, 0, PR_MODE_HTTP }, |
| 129 | { "clitcpka", PR_O_TCP_CLI_KA, PR_CAP_FE, 0, 0 }, |
| 130 | { "contstats", PR_O_CONTSTATS, PR_CAP_FE, 0, 0 }, |
| 131 | { "dontlognull", PR_O_NULLNOLOG, PR_CAP_FE, 0, 0 }, |
| 132 | { "forceclose", PR_O_FORCE_CLO, PR_CAP_FE | PR_CAP_BE, 0, PR_MODE_HTTP }, |
| 133 | { "http_proxy", PR_O_HTTP_PROXY, PR_CAP_FE | PR_CAP_BE, 0, PR_MODE_HTTP }, |
| 134 | { "httpclose", PR_O_HTTP_CLOSE, PR_CAP_FE | PR_CAP_BE, 0, PR_MODE_HTTP }, |
| 135 | { "keepalive", PR_O_KEEPALIVE, PR_CAP_NONE, 0, PR_MODE_HTTP }, |
| 136 | { "http-server-close", PR_O_SERVER_CLO, PR_CAP_FE | PR_CAP_BE, 0, PR_MODE_HTTP }, |
| 137 | { "logasap", PR_O_LOGASAP, PR_CAP_FE, 0, 0 }, |
| 138 | { "nolinger", PR_O_TCP_NOLING, PR_CAP_FE | PR_CAP_BE, 0, 0 }, |
| 139 | { "persist", PR_O_PERSIST, PR_CAP_BE, 0, 0 }, |
| 140 | { "redispatch", PR_O_REDISP, PR_CAP_BE, 0, 0 }, |
| 141 | { "srvtcpka", PR_O_TCP_SRV_KA, PR_CAP_BE, 0, 0 }, |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 142 | #ifdef TPROXY |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 143 | { "transparent", PR_O_TRANSP, PR_CAP_BE, 0, 0 }, |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 144 | #else |
| 145 | { "transparent", 0, 0, 0, 0 }, |
Willy Tarreau | 8f922fc | 2007-01-06 21:11:49 +0100 | [diff] [blame] | 146 | #endif |
| 147 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 148 | { NULL, 0, 0, 0, 0 } |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 149 | }; |
| 150 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 151 | /* proxy->options2 */ |
| 152 | static const struct cfg_opt cfg_opts2[] = |
| 153 | { |
| 154 | #ifdef CONFIG_HAP_LINUX_SPLICE |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 155 | { "splice-request", PR_O2_SPLIC_REQ, PR_CAP_FE|PR_CAP_BE, 0, 0 }, |
| 156 | { "splice-response", PR_O2_SPLIC_RTR, PR_CAP_FE|PR_CAP_BE, 0, 0 }, |
| 157 | { "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] | 158 | #else |
| 159 | { "splice-request", 0, 0, 0, 0 }, |
| 160 | { "splice-response", 0, 0, 0, 0 }, |
| 161 | { "splice-auto", 0, 0, 0, 0 }, |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 162 | #endif |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 163 | { "accept-invalid-http-request", PR_O2_REQBUG_OK, PR_CAP_FE, 0, PR_MODE_HTTP }, |
| 164 | { "accept-invalid-http-response", PR_O2_RSPBUG_OK, PR_CAP_BE, 0, PR_MODE_HTTP }, |
| 165 | { "dontlog-normal", PR_O2_NOLOGNORM, PR_CAP_FE, 0, 0 }, |
| 166 | { "log-separate-errors", PR_O2_LOGERRORS, PR_CAP_FE, 0, 0 }, |
| 167 | { "log-health-checks", PR_O2_LOGHCHKS, PR_CAP_BE, 0, 0 }, |
| 168 | { "socket-stats", PR_O2_SOCKSTAT, PR_CAP_FE, 0, 0 }, |
| 169 | { "tcp-smart-accept", PR_O2_SMARTACC, PR_CAP_FE, 0, 0 }, |
| 170 | { "tcp-smart-connect", PR_O2_SMARTCON, PR_CAP_BE, 0, 0 }, |
| 171 | { "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] | 172 | { "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] | 173 | { "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] | 174 | { "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] | 175 | { "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] | 176 | { NULL, 0, 0, 0 } |
| 177 | }; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 178 | |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 179 | static char *cursection = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 180 | static struct proxy defproxy; /* fake proxy used to assign default values on all instances */ |
| 181 | int cfg_maxpconn = DEFAULT_MAXCONN; /* # of simultaneous connections per proxy (-N) */ |
Willy Tarreau | 5af24ef | 2009-03-15 15:23:16 +0100 | [diff] [blame] | 182 | int cfg_maxconn = 0; /* # of simultaneous connections, (-n) */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 183 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 184 | /* List head of all known configuration keywords */ |
| 185 | static struct cfg_kw_list cfg_keywords = { |
| 186 | .list = LIST_HEAD_INIT(cfg_keywords.list) |
| 187 | }; |
| 188 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 189 | /* |
| 190 | * converts <str> to a list of listeners which are dynamically allocated. |
| 191 | * The format is "{addr|'*'}:port[-end][,{addr|'*'}:port[-end]]*", where : |
| 192 | * - <addr> can be empty or "*" to indicate INADDR_ANY ; |
| 193 | * - <port> is a numerical port from 1 to 65535 ; |
| 194 | * - <end> indicates to use the range from <port> to <end> instead (inclusive). |
| 195 | * 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] | 196 | * Function returns 1 for success or 0 if error. In case of errors, if <err> is |
| 197 | * not NULL, it must be a valid pointer to either NULL or a freeable area that |
| 198 | * will be replaced with an error message. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 199 | */ |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 200 | 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] | 201 | { |
| 202 | struct listener *l; |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 203 | char *next, *dupstr; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 204 | int port, end; |
| 205 | |
| 206 | next = dupstr = strdup(str); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 207 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 208 | while (next && *next) { |
| 209 | struct sockaddr_storage ss; |
| 210 | |
| 211 | str = next; |
| 212 | /* 1) look for the end of the first address */ |
Krzysztof Piotr Oledzki | 52d522b | 2009-01-27 16:57:08 +0100 | [diff] [blame] | 213 | if ((next = strchr(str, ',')) != NULL) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 214 | *next++ = 0; |
| 215 | } |
| 216 | |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 217 | if (*str == '/') { |
| 218 | /* sun_path during a soft_stop rename is <unix_bind_prefix><path>.<pid>.<bak|tmp> */ |
| 219 | /* so compute max path */ |
| 220 | int prefix_path_len = global.unix_bind.prefix ? strlen(global.unix_bind.prefix) : 0; |
| 221 | 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] | 222 | |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 223 | if (strlen(str) > max_path_len) { |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 224 | 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] | 225 | goto fail; |
| 226 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 227 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 228 | memset(&ss, 0, sizeof(ss)); |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 229 | ss.ss_family = AF_UNIX; |
| 230 | if (global.unix_bind.prefix) { |
| 231 | memcpy(((struct sockaddr_un *)&ss)->sun_path, global.unix_bind.prefix, prefix_path_len); |
| 232 | strcpy(((struct sockaddr_un *)&ss)->sun_path+prefix_path_len, str); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 233 | } |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 234 | else { |
| 235 | strcpy(((struct sockaddr_un *)&ss)->sun_path, str); |
| 236 | } |
| 237 | port = end = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 238 | } |
| 239 | else { |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 240 | struct sockaddr_storage *ss2; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 241 | |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 242 | ss2 = str2sa_range(str, &port, &end); |
| 243 | if (!ss2) { |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 244 | memprintf(err, "invalid listening address: '%s'\n", str); |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 245 | goto fail; |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 246 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 247 | |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 248 | if (!port) { |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 249 | memprintf(err, "missing port number: '%s'\n", str); |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 250 | goto fail; |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 251 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 252 | |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 253 | /* OK the address looks correct */ |
| 254 | ss = *ss2; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 255 | |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 256 | if (port < 1 || port > 65535) { |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 257 | memprintf(err, "invalid port '%d' specified for address '%s'.\n", port, str); |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 258 | goto fail; |
| 259 | } |
| 260 | |
| 261 | if (end < 1 || end > 65535) { |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 262 | memprintf(err, "invalid port '%d' specified for address '%s'.\n", end, str); |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 263 | goto fail; |
| 264 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | for (; port <= end; port++) { |
| 268 | l = (struct listener *)calloc(1, sizeof(struct listener)); |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 269 | l->obj_type = OBJ_TYPE_LISTENER; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 270 | LIST_ADDQ(&curproxy->conf.listeners, &l->by_fe); |
| 271 | LIST_ADDQ(&bind_conf->listeners, &l->by_bind); |
| 272 | l->frontend = curproxy; |
| 273 | l->bind_conf = bind_conf; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 274 | |
| 275 | l->fd = -1; |
| 276 | l->addr = ss; |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 277 | l->xprt = &raw_sock; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 278 | l->state = LI_INIT; |
| 279 | |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 280 | if (ss.ss_family == AF_INET) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 281 | ((struct sockaddr_in *)(&l->addr))->sin_port = htons(port); |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 282 | tcpv4_add_listener(l); |
| 283 | } |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 284 | else if (ss.ss_family == AF_INET6) { |
| 285 | ((struct sockaddr_in6 *)(&l->addr))->sin6_port = htons(port); |
| 286 | tcpv6_add_listener(l); |
| 287 | } |
| 288 | else { |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 289 | uxst_add_listener(l); |
| 290 | } |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 291 | |
Willy Tarreau | af7ad00 | 2010-08-31 15:39:26 +0200 | [diff] [blame] | 292 | jobs++; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 293 | listeners++; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 294 | } /* end for(port) */ |
| 295 | } /* end while(next) */ |
| 296 | free(dupstr); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 297 | return 1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 298 | fail: |
| 299 | free(dupstr); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 300 | return 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 301 | } |
| 302 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 303 | /* |
| 304 | * Sends a warning if proxy <proxy> does not have at least one of the |
| 305 | * capabilities in <cap>. An optionnal <hint> may be added at the end |
| 306 | * of the warning to help the user. Returns 1 if a warning was emitted |
| 307 | * or 0 if the condition is valid. |
| 308 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 309 | 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] | 310 | { |
| 311 | char *msg; |
| 312 | |
| 313 | switch (cap) { |
| 314 | case PR_CAP_BE: msg = "no backend"; break; |
| 315 | case PR_CAP_FE: msg = "no frontend"; break; |
| 316 | case PR_CAP_RS: msg = "no ruleset"; break; |
| 317 | case PR_CAP_BE|PR_CAP_FE: msg = "neither frontend nor backend"; break; |
| 318 | default: msg = "not enough"; break; |
| 319 | } |
| 320 | |
| 321 | if (!(proxy->cap & cap)) { |
| 322 | 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] | 323 | file, line, arg, proxy_type_str(proxy), proxy->id, msg, hint ? hint : ""); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 324 | return 1; |
| 325 | } |
| 326 | return 0; |
| 327 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 328 | |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 329 | /* Report a warning if a rule is placed after a 'block' rule. |
| 330 | * Return 1 if the warning has been emitted, otherwise 0. |
| 331 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 332 | 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] | 333 | { |
| 334 | if (!LIST_ISEMPTY(&proxy->block_cond)) { |
| 335 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'block' rule will still be processed before.\n", |
| 336 | file, line, arg); |
| 337 | return 1; |
| 338 | } |
| 339 | return 0; |
| 340 | } |
| 341 | |
| 342 | /* Report a warning if a rule is placed after a reqrewrite rule. |
| 343 | * Return 1 if the warning has been emitted, otherwise 0. |
| 344 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 345 | 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] | 346 | { |
| 347 | if (proxy->req_exp) { |
| 348 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'reqxxx' rule will still be processed before.\n", |
| 349 | file, line, arg); |
| 350 | return 1; |
| 351 | } |
| 352 | return 0; |
| 353 | } |
| 354 | |
| 355 | /* Report a warning if a rule is placed after a reqadd rule. |
| 356 | * Return 1 if the warning has been emitted, otherwise 0. |
| 357 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 358 | 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] | 359 | { |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 360 | if (!LIST_ISEMPTY(&proxy->req_add)) { |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 361 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'reqadd' rule will still be processed before.\n", |
| 362 | file, line, arg); |
| 363 | return 1; |
| 364 | } |
| 365 | return 0; |
| 366 | } |
| 367 | |
| 368 | /* Report a warning if a rule is placed after a redirect rule. |
| 369 | * Return 1 if the warning has been emitted, otherwise 0. |
| 370 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 371 | 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] | 372 | { |
| 373 | if (!LIST_ISEMPTY(&proxy->redirect_rules)) { |
| 374 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'redirect' rule will still be processed before.\n", |
| 375 | file, line, arg); |
| 376 | return 1; |
| 377 | } |
| 378 | return 0; |
| 379 | } |
| 380 | |
| 381 | /* Report a warning if a rule is placed after a 'use_backend' rule. |
| 382 | * Return 1 if the warning has been emitted, otherwise 0. |
| 383 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 384 | 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] | 385 | { |
| 386 | if (!LIST_ISEMPTY(&proxy->switching_rules)) { |
| 387 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'use_backend' rule will still be processed before.\n", |
| 388 | file, line, arg); |
| 389 | return 1; |
| 390 | } |
| 391 | return 0; |
| 392 | } |
| 393 | |
| 394 | /* report a warning if a block rule is dangerously placed */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 395 | 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] | 396 | { |
| 397 | return warnif_rule_after_reqxxx(proxy, file, line, arg) || |
| 398 | warnif_rule_after_reqadd(proxy, file, line, arg) || |
| 399 | warnif_rule_after_redirect(proxy, file, line, arg) || |
| 400 | warnif_rule_after_use_backend(proxy, file, line, arg); |
| 401 | } |
| 402 | |
| 403 | /* report a warning if a reqxxx rule is dangerously placed */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 404 | 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] | 405 | { |
| 406 | return warnif_rule_after_reqadd(proxy, file, line, arg) || |
| 407 | warnif_rule_after_redirect(proxy, file, line, arg) || |
| 408 | warnif_rule_after_use_backend(proxy, file, line, arg); |
| 409 | } |
| 410 | |
| 411 | /* report a warning if a reqadd rule is dangerously placed */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 412 | 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] | 413 | { |
| 414 | return warnif_rule_after_redirect(proxy, file, line, arg) || |
| 415 | warnif_rule_after_use_backend(proxy, file, line, arg); |
| 416 | } |
| 417 | |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 418 | /* Report it if a request ACL condition uses some response-only parameters. It |
| 419 | * returns either 0 or ERR_WARN so that its result can be or'ed with err_code. |
| 420 | * Note that <cond> may be NULL and then will be ignored. |
| 421 | */ |
| 422 | static int warnif_cond_requires_resp(const struct acl_cond *cond, const char *file, int line) |
| 423 | { |
| 424 | struct acl *acl; |
| 425 | |
| 426 | if (!cond || !(cond->requires & ACL_USE_RTR_ANY)) |
| 427 | return 0; |
| 428 | |
| 429 | acl = cond_find_require(cond, ACL_USE_RTR_ANY); |
| 430 | Warning("parsing [%s:%d] : acl '%s' involves some response-only criteria which will be ignored.\n", |
| 431 | file, line, acl ? acl->name : "(unknown)"); |
| 432 | return ERR_WARN; |
| 433 | } |
| 434 | |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 435 | /* Report it if a request ACL condition uses some request-only volatile parameters. |
| 436 | * It returns either 0 or ERR_WARN so that its result can be or'ed with err_code. |
| 437 | * Note that <cond> may be NULL and then will be ignored. |
| 438 | */ |
| 439 | static int warnif_cond_requires_req(const struct acl_cond *cond, const char *file, int line) |
| 440 | { |
| 441 | struct acl *acl; |
| 442 | |
| 443 | if (!cond || !(cond->requires & ACL_USE_REQ_VOLATILE)) |
| 444 | return 0; |
| 445 | |
| 446 | acl = cond_find_require(cond, ACL_USE_REQ_VOLATILE); |
| 447 | Warning("parsing [%s:%d] : acl '%s' involves some volatile request-only criteria which will be ignored.\n", |
| 448 | file, line, acl ? acl->name : "(unknown)"); |
| 449 | return ERR_WARN; |
| 450 | } |
| 451 | |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 452 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 453 | /* |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 454 | * parse a line in a <global> section. Returns the error code, 0 if OK, or |
| 455 | * any combination of : |
| 456 | * - ERR_ABORT: must abort ASAP |
| 457 | * - ERR_FATAL: we can continue parsing but not start the service |
| 458 | * - ERR_WARN: a warning has been emitted |
| 459 | * - ERR_ALERT: an alert has been emitted |
| 460 | * Only the two first ones can stop processing, the two others are just |
| 461 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 462 | */ |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 463 | 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] | 464 | { |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 465 | int err_code = 0; |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 466 | char *errmsg = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 467 | |
| 468 | if (!strcmp(args[0], "global")) { /* new section */ |
| 469 | /* no option, nothing special to do */ |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 470 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 471 | } |
Emeric Brun | c8e8d12 | 2012-10-02 18:42:10 +0200 | [diff] [blame] | 472 | else if (!strcmp(args[0], "ca-base")) { |
| 473 | #ifdef USE_OPENSSL |
| 474 | if (global.ca_base != NULL) { |
| 475 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 476 | err_code |= ERR_ALERT; |
| 477 | goto out; |
| 478 | } |
| 479 | if (*(args[1]) == 0) { |
| 480 | Alert("parsing [%s:%d] : '%s' expects a directory path as an argument.\n", file, linenum, args[0]); |
| 481 | err_code |= ERR_ALERT | ERR_FATAL; |
| 482 | goto out; |
| 483 | } |
| 484 | global.ca_base = strdup(args[1]); |
| 485 | #else |
| 486 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 487 | err_code |= ERR_ALERT | ERR_FATAL; |
| 488 | goto out; |
| 489 | #endif |
| 490 | } |
| 491 | else if (!strcmp(args[0], "crt-base")) { |
| 492 | #ifdef USE_OPENSSL |
| 493 | if (global.crt_base != NULL) { |
| 494 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 495 | err_code |= ERR_ALERT; |
| 496 | goto out; |
| 497 | } |
| 498 | if (*(args[1]) == 0) { |
| 499 | Alert("parsing [%s:%d] : '%s' expects a directory path as an argument.\n", file, linenum, args[0]); |
| 500 | err_code |= ERR_ALERT | ERR_FATAL; |
| 501 | goto out; |
| 502 | } |
| 503 | global.crt_base = strdup(args[1]); |
| 504 | #else |
| 505 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 506 | err_code |= ERR_ALERT | ERR_FATAL; |
| 507 | goto out; |
| 508 | #endif |
| 509 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 510 | else if (!strcmp(args[0], "daemon")) { |
| 511 | global.mode |= MODE_DAEMON; |
| 512 | } |
| 513 | else if (!strcmp(args[0], "debug")) { |
| 514 | global.mode |= MODE_DEBUG; |
| 515 | } |
| 516 | else if (!strcmp(args[0], "noepoll")) { |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 517 | global.tune.options &= ~GTUNE_USE_EPOLL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 518 | } |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 519 | else if (!strcmp(args[0], "nokqueue")) { |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 520 | global.tune.options &= ~GTUNE_USE_KQUEUE; |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 521 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 522 | else if (!strcmp(args[0], "nopoll")) { |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 523 | global.tune.options &= ~GTUNE_USE_POLL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 524 | } |
Willy Tarreau | 3ab68cf | 2009-01-25 16:03:28 +0100 | [diff] [blame] | 525 | else if (!strcmp(args[0], "nosplice")) { |
| 526 | global.tune.options &= ~GTUNE_USE_SPLICE; |
| 527 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 528 | else if (!strcmp(args[0], "quiet")) { |
| 529 | global.mode |= MODE_QUIET; |
| 530 | } |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 531 | else if (!strcmp(args[0], "tune.maxpollevents")) { |
| 532 | if (global.tune.maxpollevents != 0) { |
| 533 | 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] | 534 | err_code |= ERR_ALERT; |
| 535 | goto out; |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 536 | } |
| 537 | if (*(args[1]) == 0) { |
| 538 | 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] | 539 | err_code |= ERR_ALERT | ERR_FATAL; |
| 540 | goto out; |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 541 | } |
| 542 | global.tune.maxpollevents = atol(args[1]); |
| 543 | } |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 544 | else if (!strcmp(args[0], "tune.maxaccept")) { |
| 545 | if (global.tune.maxaccept != 0) { |
| 546 | 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] | 547 | err_code |= ERR_ALERT; |
| 548 | goto out; |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 549 | } |
| 550 | if (*(args[1]) == 0) { |
| 551 | 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] | 552 | err_code |= ERR_ALERT | ERR_FATAL; |
| 553 | goto out; |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 554 | } |
| 555 | global.tune.maxaccept = atol(args[1]); |
| 556 | } |
Willy Tarreau | 43961d5 | 2010-10-04 20:39:20 +0200 | [diff] [blame] | 557 | else if (!strcmp(args[0], "tune.chksize")) { |
| 558 | if (*(args[1]) == 0) { |
| 559 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 560 | err_code |= ERR_ALERT | ERR_FATAL; |
| 561 | goto out; |
| 562 | } |
| 563 | global.tune.chksize = atol(args[1]); |
| 564 | } |
Emeric Brun | fc32aca | 2012-09-03 12:10:29 +0200 | [diff] [blame] | 565 | #ifdef USE_OPENSSL |
Willy Tarreau | 6ec58db | 2012-11-16 16:32:15 +0100 | [diff] [blame] | 566 | else if (!strcmp(args[0], "tune.ssl.cachesize")) { |
Emeric Brun | fc32aca | 2012-09-03 12:10:29 +0200 | [diff] [blame] | 567 | if (*(args[1]) == 0) { |
| 568 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 569 | err_code |= ERR_ALERT | ERR_FATAL; |
| 570 | goto out; |
| 571 | } |
| 572 | global.tune.sslcachesize = atol(args[1]); |
| 573 | } |
Emeric Brun | 4f65bff | 2012-11-16 15:11:00 +0100 | [diff] [blame] | 574 | else if (!strcmp(args[0], "tune.ssl.lifetime")) { |
| 575 | unsigned int ssllifetime; |
| 576 | const char *res; |
| 577 | |
| 578 | if (*(args[1]) == 0) { |
| 579 | Alert("parsing [%s:%d] : '%s' expects ssl sessions <lifetime> in seconds as argument.\n", file, linenum, args[0]); |
| 580 | err_code |= ERR_ALERT | ERR_FATAL; |
| 581 | goto out; |
| 582 | } |
| 583 | |
| 584 | res = parse_time_err(args[1], &ssllifetime, TIME_UNIT_S); |
| 585 | if (res) { |
| 586 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 587 | file, linenum, *res, args[0]); |
| 588 | err_code |= ERR_ALERT | ERR_FATAL; |
| 589 | goto out; |
| 590 | } |
| 591 | |
| 592 | global.tune.ssllifetime = ssllifetime; |
| 593 | } |
Emeric Brun | fc32aca | 2012-09-03 12:10:29 +0200 | [diff] [blame] | 594 | #endif |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 595 | else if (!strcmp(args[0], "tune.bufsize")) { |
| 596 | if (*(args[1]) == 0) { |
| 597 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 598 | err_code |= ERR_ALERT | ERR_FATAL; |
| 599 | goto out; |
| 600 | } |
| 601 | global.tune.bufsize = atol(args[1]); |
| 602 | if (global.tune.maxrewrite >= global.tune.bufsize / 2) |
| 603 | global.tune.maxrewrite = global.tune.bufsize / 2; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 604 | chunk_init(&trash, realloc(trash.str, global.tune.bufsize), global.tune.bufsize); |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 605 | } |
| 606 | else if (!strcmp(args[0], "tune.maxrewrite")) { |
| 607 | if (*(args[1]) == 0) { |
| 608 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 609 | err_code |= ERR_ALERT | ERR_FATAL; |
| 610 | goto out; |
| 611 | } |
| 612 | global.tune.maxrewrite = atol(args[1]); |
| 613 | if (global.tune.maxrewrite >= global.tune.bufsize / 2) |
| 614 | global.tune.maxrewrite = global.tune.bufsize / 2; |
| 615 | } |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 616 | else if (!strcmp(args[0], "tune.rcvbuf.client")) { |
| 617 | if (global.tune.client_rcvbuf != 0) { |
| 618 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 619 | err_code |= ERR_ALERT; |
| 620 | goto out; |
| 621 | } |
| 622 | if (*(args[1]) == 0) { |
| 623 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 624 | err_code |= ERR_ALERT | ERR_FATAL; |
| 625 | goto out; |
| 626 | } |
| 627 | global.tune.client_rcvbuf = atol(args[1]); |
| 628 | } |
| 629 | else if (!strcmp(args[0], "tune.rcvbuf.server")) { |
| 630 | if (global.tune.server_rcvbuf != 0) { |
| 631 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 632 | err_code |= ERR_ALERT; |
| 633 | goto out; |
| 634 | } |
| 635 | if (*(args[1]) == 0) { |
| 636 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 637 | err_code |= ERR_ALERT | ERR_FATAL; |
| 638 | goto out; |
| 639 | } |
| 640 | global.tune.server_rcvbuf = atol(args[1]); |
| 641 | } |
| 642 | else if (!strcmp(args[0], "tune.sndbuf.client")) { |
| 643 | if (global.tune.client_sndbuf != 0) { |
| 644 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 645 | err_code |= ERR_ALERT; |
| 646 | goto out; |
| 647 | } |
| 648 | if (*(args[1]) == 0) { |
| 649 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 650 | err_code |= ERR_ALERT | ERR_FATAL; |
| 651 | goto out; |
| 652 | } |
| 653 | global.tune.client_sndbuf = atol(args[1]); |
| 654 | } |
| 655 | else if (!strcmp(args[0], "tune.sndbuf.server")) { |
| 656 | if (global.tune.server_sndbuf != 0) { |
| 657 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 658 | err_code |= ERR_ALERT; |
| 659 | goto out; |
| 660 | } |
| 661 | if (*(args[1]) == 0) { |
| 662 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 663 | err_code |= ERR_ALERT | ERR_FATAL; |
| 664 | goto out; |
| 665 | } |
| 666 | global.tune.server_sndbuf = atol(args[1]); |
| 667 | } |
Willy Tarreau | bd9a0a7 | 2011-10-23 21:14:29 +0200 | [diff] [blame] | 668 | else if (!strcmp(args[0], "tune.pipesize")) { |
| 669 | if (*(args[1]) == 0) { |
| 670 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 671 | err_code |= ERR_ALERT | ERR_FATAL; |
| 672 | goto out; |
| 673 | } |
| 674 | global.tune.pipesize = atol(args[1]); |
| 675 | } |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 676 | else if (!strcmp(args[0], "tune.http.cookielen")) { |
| 677 | if (*(args[1]) == 0) { |
| 678 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 679 | err_code |= ERR_ALERT | ERR_FATAL; |
| 680 | goto out; |
| 681 | } |
| 682 | global.tune.cookie_len = atol(args[1]) + 1; |
| 683 | } |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame] | 684 | else if (!strcmp(args[0], "tune.http.maxhdr")) { |
| 685 | if (*(args[1]) == 0) { |
| 686 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 687 | err_code |= ERR_ALERT | ERR_FATAL; |
| 688 | goto out; |
| 689 | } |
| 690 | global.tune.max_http_hdr = atol(args[1]); |
| 691 | } |
William Lallemand | a509e4c | 2012-11-07 16:54:34 +0100 | [diff] [blame] | 692 | else if (!strcmp(args[0], "tune.zlib.memlevel")) { |
| 693 | #ifdef USE_ZLIB |
| 694 | if (*args[1]) { |
| 695 | global.tune.zlibmemlevel = atoi(args[1]); |
| 696 | if (global.tune.zlibmemlevel < 1 || global.tune.zlibmemlevel > 9) { |
| 697 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n", |
| 698 | file, linenum, args[0]); |
| 699 | err_code |= ERR_ALERT | ERR_FATAL; |
| 700 | goto out; |
| 701 | } |
| 702 | } else { |
| 703 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n", |
| 704 | file, linenum, args[0]); |
| 705 | err_code |= ERR_ALERT | ERR_FATAL; |
| 706 | goto out; |
| 707 | } |
| 708 | #else |
| 709 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 710 | err_code |= ERR_ALERT | ERR_FATAL; |
| 711 | goto out; |
| 712 | #endif |
| 713 | } |
| 714 | else if (!strcmp(args[0], "tune.zlib.windowsize")) { |
| 715 | #ifdef USE_ZLIB |
| 716 | if (*args[1]) { |
| 717 | global.tune.zlibwindowsize = atoi(args[1]); |
| 718 | if (global.tune.zlibwindowsize < 8 || global.tune.zlibwindowsize > 15) { |
| 719 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 8 and 15\n", |
| 720 | file, linenum, args[0]); |
| 721 | err_code |= ERR_ALERT | ERR_FATAL; |
| 722 | goto out; |
| 723 | } |
| 724 | } else { |
| 725 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 8 and 15\n", |
| 726 | file, linenum, args[0]); |
| 727 | err_code |= ERR_ALERT | ERR_FATAL; |
| 728 | goto out; |
| 729 | } |
| 730 | #else |
| 731 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 732 | err_code |= ERR_ALERT | ERR_FATAL; |
| 733 | goto out; |
| 734 | #endif |
| 735 | } |
William Lallemand | f374783 | 2012-11-09 12:33:10 +0100 | [diff] [blame] | 736 | else if (!strcmp(args[0], "tune.comp.maxlevel")) { |
| 737 | if (*args[1]) { |
| 738 | global.tune.comp_maxlevel = atoi(args[1]); |
| 739 | if (global.tune.comp_maxlevel < 1 || global.tune.comp_maxlevel > 9) { |
| 740 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n", |
| 741 | file, linenum, args[0]); |
| 742 | err_code |= ERR_ALERT | ERR_FATAL; |
| 743 | goto out; |
| 744 | } |
| 745 | } else { |
| 746 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n", |
| 747 | file, linenum, args[0]); |
| 748 | err_code |= ERR_ALERT | ERR_FATAL; |
| 749 | goto out; |
| 750 | } |
| 751 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 752 | else if (!strcmp(args[0], "uid")) { |
| 753 | if (global.uid != 0) { |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 754 | Alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 755 | err_code |= ERR_ALERT; |
| 756 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 757 | } |
| 758 | if (*(args[1]) == 0) { |
| 759 | 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] | 760 | err_code |= ERR_ALERT | ERR_FATAL; |
| 761 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 762 | } |
| 763 | global.uid = atol(args[1]); |
| 764 | } |
| 765 | else if (!strcmp(args[0], "gid")) { |
| 766 | if (global.gid != 0) { |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 767 | Alert("parsing [%s:%d] : group/gid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 768 | err_code |= ERR_ALERT; |
| 769 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 770 | } |
| 771 | if (*(args[1]) == 0) { |
| 772 | 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] | 773 | err_code |= ERR_ALERT | ERR_FATAL; |
| 774 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 775 | } |
| 776 | global.gid = atol(args[1]); |
| 777 | } |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 778 | /* user/group name handling */ |
| 779 | else if (!strcmp(args[0], "user")) { |
| 780 | struct passwd *ha_user; |
| 781 | if (global.uid != 0) { |
| 782 | Alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 783 | err_code |= ERR_ALERT; |
| 784 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 785 | } |
| 786 | errno = 0; |
| 787 | ha_user = getpwnam(args[1]); |
| 788 | if (ha_user != NULL) { |
| 789 | global.uid = (int)ha_user->pw_uid; |
| 790 | } |
| 791 | else { |
| 792 | 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] | 793 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 794 | } |
| 795 | } |
| 796 | else if (!strcmp(args[0], "group")) { |
| 797 | struct group *ha_group; |
| 798 | if (global.gid != 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 799 | 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] | 800 | err_code |= ERR_ALERT; |
| 801 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 802 | } |
| 803 | errno = 0; |
| 804 | ha_group = getgrnam(args[1]); |
| 805 | if (ha_group != NULL) { |
| 806 | global.gid = (int)ha_group->gr_gid; |
| 807 | } |
| 808 | else { |
| 809 | 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] | 810 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 811 | } |
| 812 | } |
| 813 | /* end of user/group name handling*/ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 814 | else if (!strcmp(args[0], "nbproc")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 815 | if (*(args[1]) == 0) { |
| 816 | 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] | 817 | err_code |= ERR_ALERT | ERR_FATAL; |
| 818 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 819 | } |
| 820 | global.nbproc = atol(args[1]); |
| 821 | } |
| 822 | else if (!strcmp(args[0], "maxconn")) { |
| 823 | if (global.maxconn != 0) { |
| 824 | 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] | 825 | err_code |= ERR_ALERT; |
| 826 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 827 | } |
| 828 | if (*(args[1]) == 0) { |
| 829 | 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] | 830 | err_code |= ERR_ALERT | ERR_FATAL; |
| 831 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 832 | } |
| 833 | global.maxconn = atol(args[1]); |
| 834 | #ifdef SYSTEM_MAXCONN |
| 835 | if (global.maxconn > DEFAULT_MAXCONN && cfg_maxconn <= DEFAULT_MAXCONN) { |
| 836 | 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); |
| 837 | global.maxconn = DEFAULT_MAXCONN; |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 838 | err_code |= ERR_ALERT; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 839 | } |
| 840 | #endif /* SYSTEM_MAXCONN */ |
| 841 | } |
Willy Tarreau | 403edff | 2012-09-06 11:58:37 +0200 | [diff] [blame] | 842 | else if (!strcmp(args[0], "maxsslconn")) { |
| 843 | #ifdef USE_OPENSSL |
| 844 | if (*(args[1]) == 0) { |
| 845 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 846 | err_code |= ERR_ALERT | ERR_FATAL; |
| 847 | goto out; |
| 848 | } |
| 849 | global.maxsslconn = atol(args[1]); |
| 850 | #else |
Emeric Brun | 0914df8 | 2012-10-02 18:45:42 +0200 | [diff] [blame] | 851 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 852 | err_code |= ERR_ALERT | ERR_FATAL; |
| 853 | goto out; |
Willy Tarreau | 403edff | 2012-09-06 11:58:37 +0200 | [diff] [blame] | 854 | #endif |
| 855 | } |
Willy Tarreau | 81c25d0 | 2011-09-07 15:17:21 +0200 | [diff] [blame] | 856 | else if (!strcmp(args[0], "maxconnrate")) { |
| 857 | if (global.cps_lim != 0) { |
| 858 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 859 | err_code |= ERR_ALERT; |
| 860 | goto out; |
| 861 | } |
| 862 | if (*(args[1]) == 0) { |
| 863 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 864 | err_code |= ERR_ALERT | ERR_FATAL; |
| 865 | goto out; |
| 866 | } |
| 867 | global.cps_lim = atol(args[1]); |
| 868 | } |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 869 | else if (!strcmp(args[0], "maxcomprate")) { |
| 870 | if (*(args[1]) == 0) { |
| 871 | Alert("parsing [%s:%d] : '%s' expects an integer argument in kb/s.\n", file, linenum, args[0]); |
| 872 | err_code |= ERR_ALERT | ERR_FATAL; |
| 873 | goto out; |
| 874 | } |
| 875 | global.comp_rate_lim = atoi(args[1]) * 1024; |
| 876 | } |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 877 | else if (!strcmp(args[0], "maxpipes")) { |
| 878 | if (global.maxpipes != 0) { |
| 879 | 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] | 880 | err_code |= ERR_ALERT; |
| 881 | goto out; |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 882 | } |
| 883 | if (*(args[1]) == 0) { |
| 884 | 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] | 885 | err_code |= ERR_ALERT | ERR_FATAL; |
| 886 | goto out; |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 887 | } |
| 888 | global.maxpipes = atol(args[1]); |
| 889 | } |
William Lallemand | 9d5f548 | 2012-11-07 16:12:57 +0100 | [diff] [blame] | 890 | else if (!strcmp(args[0], "maxzlibmem")) { |
| 891 | if (*(args[1]) == 0) { |
| 892 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 893 | err_code |= ERR_ALERT | ERR_FATAL; |
| 894 | goto out; |
| 895 | } |
William Lallemand | e3a7d99 | 2012-11-20 11:25:20 +0100 | [diff] [blame] | 896 | global.maxzlibmem = atol(args[1]) * 1024L * 1024L; |
William Lallemand | 9d5f548 | 2012-11-07 16:12:57 +0100 | [diff] [blame] | 897 | } |
William Lallemand | 072a2bf | 2012-11-20 17:01:01 +0100 | [diff] [blame] | 898 | else if (!strcmp(args[0], "maxcompcpuusage")) { |
| 899 | if (*(args[1]) == 0) { |
| 900 | Alert("parsing [%s:%d] : '%s' expects an integer argument between 0 and 100.\n", file, linenum, args[0]); |
| 901 | err_code |= ERR_ALERT | ERR_FATAL; |
| 902 | goto out; |
| 903 | } |
| 904 | compress_min_idle = 100 - atoi(args[1]); |
| 905 | if (compress_min_idle < 0 || compress_min_idle > 100) { |
| 906 | Alert("parsing [%s:%d] : '%s' expects an integer argument between 0 and 100.\n", file, linenum, args[0]); |
| 907 | err_code |= ERR_ALERT | ERR_FATAL; |
| 908 | goto out; |
| 909 | } |
| 910 | } |
| 911 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 912 | else if (!strcmp(args[0], "ulimit-n")) { |
| 913 | if (global.rlimit_nofile != 0) { |
| 914 | 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] | 915 | err_code |= ERR_ALERT; |
| 916 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 917 | } |
| 918 | if (*(args[1]) == 0) { |
| 919 | 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] | 920 | err_code |= ERR_ALERT | ERR_FATAL; |
| 921 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 922 | } |
| 923 | global.rlimit_nofile = atol(args[1]); |
| 924 | } |
| 925 | else if (!strcmp(args[0], "chroot")) { |
| 926 | if (global.chroot != NULL) { |
| 927 | 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] | 928 | err_code |= ERR_ALERT; |
| 929 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 930 | } |
| 931 | if (*(args[1]) == 0) { |
| 932 | 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] | 933 | err_code |= ERR_ALERT | ERR_FATAL; |
| 934 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 935 | } |
| 936 | global.chroot = strdup(args[1]); |
| 937 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 938 | else if (!strcmp(args[0], "description")) { |
| 939 | int i, len=0; |
| 940 | char *d; |
| 941 | |
| 942 | if (!*args[1]) { |
| 943 | Alert("parsing [%s:%d]: '%s' expects a string argument.\n", |
| 944 | file, linenum, args[0]); |
| 945 | err_code |= ERR_ALERT | ERR_FATAL; |
| 946 | goto out; |
| 947 | } |
| 948 | |
| 949 | for(i=1; *args[i]; i++) |
| 950 | len += strlen(args[i])+1; |
| 951 | |
| 952 | if (global.desc) |
| 953 | free(global.desc); |
| 954 | |
| 955 | global.desc = d = (char *)calloc(1, len); |
| 956 | |
| 957 | d += sprintf(d, "%s", args[1]); |
| 958 | for(i=2; *args[i]; i++) |
| 959 | d += sprintf(d, " %s", args[i]); |
| 960 | } |
| 961 | else if (!strcmp(args[0], "node")) { |
| 962 | int i; |
| 963 | char c; |
| 964 | |
| 965 | for (i=0; args[1][i]; i++) { |
| 966 | c = args[1][i]; |
Willy Tarreau | 88e0581 | 2010-03-03 00:16:00 +0100 | [diff] [blame] | 967 | if (!isupper((unsigned char)c) && !islower((unsigned char)c) && |
| 968 | !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.') |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 969 | break; |
| 970 | } |
| 971 | |
| 972 | if (!i || args[1][i]) { |
| 973 | Alert("parsing [%s:%d]: '%s' requires valid node name - non-empty string" |
| 974 | " with digits(0-9), letters(A-Z, a-z), dot(.), hyphen(-) or underscode(_).\n", |
| 975 | file, linenum, args[0]); |
| 976 | err_code |= ERR_ALERT | ERR_FATAL; |
| 977 | goto out; |
| 978 | } |
| 979 | |
| 980 | if (global.node) |
| 981 | free(global.node); |
| 982 | |
| 983 | global.node = strdup(args[1]); |
| 984 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 985 | else if (!strcmp(args[0], "pidfile")) { |
| 986 | if (global.pidfile != NULL) { |
| 987 | 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] | 988 | err_code |= ERR_ALERT; |
| 989 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 990 | } |
| 991 | if (*(args[1]) == 0) { |
| 992 | 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] | 993 | err_code |= ERR_ALERT | ERR_FATAL; |
| 994 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 995 | } |
| 996 | global.pidfile = strdup(args[1]); |
| 997 | } |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 998 | else if (!strcmp(args[0], "unix-bind")) { |
| 999 | int cur_arg = 1; |
| 1000 | while (*(args[cur_arg])) { |
| 1001 | if (!strcmp(args[cur_arg], "prefix")) { |
| 1002 | if (global.unix_bind.prefix != NULL) { |
| 1003 | Alert("parsing [%s:%d] : unix-bind '%s' already specified. Continuing.\n", file, linenum, args[cur_arg]); |
| 1004 | err_code |= ERR_ALERT; |
| 1005 | cur_arg += 2; |
| 1006 | continue; |
| 1007 | } |
| 1008 | |
| 1009 | if (*(args[cur_arg+1]) == 0) { |
| 1010 | Alert("parsing [%s:%d] : unix_bind '%s' expects a path as an argument.\n", file, linenum, args[cur_arg]); |
| 1011 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1012 | goto out; |
| 1013 | } |
| 1014 | global.unix_bind.prefix = strdup(args[cur_arg+1]); |
| 1015 | cur_arg += 2; |
| 1016 | continue; |
| 1017 | } |
| 1018 | |
| 1019 | if (!strcmp(args[cur_arg], "mode")) { |
| 1020 | |
| 1021 | global.unix_bind.ux.mode = strtol(args[cur_arg + 1], NULL, 8); |
| 1022 | cur_arg += 2; |
| 1023 | continue; |
| 1024 | } |
| 1025 | |
| 1026 | if (!strcmp(args[cur_arg], "uid")) { |
| 1027 | |
| 1028 | global.unix_bind.ux.uid = atol(args[cur_arg + 1 ]); |
| 1029 | cur_arg += 2; |
| 1030 | continue; |
| 1031 | } |
| 1032 | |
| 1033 | if (!strcmp(args[cur_arg], "gid")) { |
| 1034 | |
| 1035 | global.unix_bind.ux.gid = atol(args[cur_arg + 1 ]); |
| 1036 | cur_arg += 2; |
| 1037 | continue; |
| 1038 | } |
| 1039 | |
| 1040 | if (!strcmp(args[cur_arg], "user")) { |
| 1041 | struct passwd *user; |
| 1042 | |
| 1043 | user = getpwnam(args[cur_arg + 1]); |
| 1044 | if (!user) { |
| 1045 | Alert("parsing [%s:%d] : '%s' : '%s' unknown user.\n", |
| 1046 | file, linenum, args[0], args[cur_arg + 1 ]); |
| 1047 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1048 | goto out; |
| 1049 | } |
| 1050 | |
| 1051 | global.unix_bind.ux.uid = user->pw_uid; |
| 1052 | cur_arg += 2; |
| 1053 | continue; |
| 1054 | } |
| 1055 | |
| 1056 | if (!strcmp(args[cur_arg], "group")) { |
| 1057 | struct group *group; |
| 1058 | |
| 1059 | group = getgrnam(args[cur_arg + 1]); |
| 1060 | if (!group) { |
| 1061 | Alert("parsing [%s:%d] : '%s' : '%s' unknown group.\n", |
| 1062 | file, linenum, args[0], args[cur_arg + 1 ]); |
| 1063 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1064 | goto out; |
| 1065 | } |
| 1066 | |
| 1067 | global.unix_bind.ux.gid = group->gr_gid; |
| 1068 | cur_arg += 2; |
| 1069 | continue; |
| 1070 | } |
| 1071 | |
Willy Tarreau | b48f958 | 2011-09-05 01:17:06 +0200 | [diff] [blame] | 1072 | 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] | 1073 | file, linenum, args[0]); |
| 1074 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1075 | goto out; |
| 1076 | } |
| 1077 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1078 | else if (!strcmp(args[0], "log") && kwm == KWM_NO) { /* no log */ |
| 1079 | /* delete previous herited or defined syslog servers */ |
| 1080 | struct logsrv *back; |
| 1081 | struct logsrv *tmp; |
| 1082 | |
| 1083 | if (*(args[1]) != 0) { |
| 1084 | Alert("parsing [%s:%d]:%s : 'no log' does not expect arguments.\n", file, linenum, args[1]); |
| 1085 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1086 | goto out; |
| 1087 | } |
| 1088 | |
| 1089 | list_for_each_entry_safe(tmp, back, &global.logsrvs, list) { |
| 1090 | LIST_DEL(&tmp->list); |
| 1091 | free(tmp); |
| 1092 | } |
| 1093 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1094 | else if (!strcmp(args[0], "log")) { /* syslog server address */ |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1095 | struct logsrv *logsrv; |
| 1096 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1097 | if (*(args[1]) == 0 || *(args[2]) == 0) { |
| 1098 | 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] | 1099 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1100 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1101 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1102 | |
| 1103 | logsrv = calloc(1, sizeof(struct logsrv)); |
| 1104 | |
| 1105 | logsrv->facility = get_log_facility(args[2]); |
| 1106 | if (logsrv->facility < 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1107 | 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] | 1108 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1109 | logsrv->facility = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1110 | } |
| 1111 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1112 | logsrv->level = 7; /* max syslog level = debug */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1113 | if (*(args[3])) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1114 | logsrv->level = get_log_level(args[3]); |
| 1115 | if (logsrv->level < 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1116 | 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] | 1117 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1118 | logsrv->level = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1119 | } |
| 1120 | } |
| 1121 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1122 | logsrv->minlvl = 0; /* limit syslog level to this level (emerg) */ |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 1123 | if (*(args[4])) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1124 | logsrv->minlvl = get_log_level(args[4]); |
| 1125 | if (logsrv->minlvl < 0) { |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 1126 | 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] | 1127 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1128 | logsrv->minlvl = 0; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 1129 | } |
| 1130 | } |
| 1131 | |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 1132 | if (args[1][0] == '/') { |
David du Colombier | 11bcb6c | 2011-03-24 12:23:00 +0100 | [diff] [blame] | 1133 | struct sockaddr_storage *sk = (struct sockaddr_storage *)str2sun(args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 1134 | if (!sk) { |
| 1135 | 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] | 1136 | args[1], (int)sizeof(((struct sockaddr_un *)&sk)->sun_path) - 1); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 1137 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1138 | free(logsrv); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 1139 | goto out; |
| 1140 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1141 | logsrv->addr = *sk; |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 1142 | } else { |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 1143 | struct sockaddr_storage *sk = str2sa(args[1]); |
David du Colombier | 11bcb6c | 2011-03-24 12:23:00 +0100 | [diff] [blame] | 1144 | if (!sk) { |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 1145 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[1]); |
| 1146 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1147 | free(logsrv); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 1148 | goto out; |
| 1149 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1150 | logsrv->addr = *sk; |
| 1151 | if (!get_host_port(&logsrv->addr)) |
| 1152 | set_host_port(&logsrv->addr, SYSLOG_PORT); |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 1153 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1154 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1155 | LIST_ADDQ(&global.logsrvs, &logsrv->list); |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1156 | } |
Joe Williams | df5b38f | 2010-12-29 17:05:48 +0100 | [diff] [blame] | 1157 | else if (!strcmp(args[0], "log-send-hostname")) { /* set the hostname in syslog header */ |
| 1158 | char *name; |
| 1159 | int len; |
| 1160 | |
| 1161 | if (global.log_send_hostname != NULL) { |
| 1162 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 1163 | err_code |= ERR_ALERT; |
| 1164 | goto out; |
| 1165 | } |
| 1166 | |
| 1167 | if (*(args[1])) |
| 1168 | name = args[1]; |
| 1169 | else |
| 1170 | name = hostname; |
| 1171 | |
| 1172 | len = strlen(name); |
| 1173 | |
| 1174 | /* We'll add a space after the name to respect the log format */ |
| 1175 | free(global.log_send_hostname); |
| 1176 | global.log_send_hostname = malloc(len + 2); |
| 1177 | snprintf(global.log_send_hostname, len + 2, "%s ", name); |
| 1178 | } |
Kevinm | 48936af | 2010-12-22 16:08:21 +0000 | [diff] [blame] | 1179 | else if (!strcmp(args[0], "log-tag")) { /* tag to report to syslog */ |
| 1180 | if (*(args[1]) == 0) { |
| 1181 | Alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]); |
| 1182 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1183 | goto out; |
| 1184 | } |
| 1185 | free(global.log_tag); |
| 1186 | global.log_tag = strdup(args[1]); |
| 1187 | } |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1188 | else if (!strcmp(args[0], "spread-checks")) { /* random time between checks (0-50) */ |
| 1189 | if (global.spread_checks != 0) { |
| 1190 | Alert("parsing [%s:%d]: spread-checks already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1191 | err_code |= ERR_ALERT; |
| 1192 | goto out; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1193 | } |
| 1194 | if (*(args[1]) == 0) { |
| 1195 | 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] | 1196 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1197 | goto out; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1198 | } |
| 1199 | global.spread_checks = atol(args[1]); |
| 1200 | if (global.spread_checks < 0 || global.spread_checks > 50) { |
| 1201 | 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] | 1202 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1203 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1204 | } |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1205 | else if (strcmp(args[0], "cpu-map") == 0) { /* map a process list to a CPU set */ |
| 1206 | #ifdef USE_CPU_AFFINITY |
| 1207 | int cur_arg, i; |
| 1208 | unsigned int proc = 0; |
| 1209 | unsigned long cpus = 0; |
| 1210 | |
| 1211 | if (strcmp(args[1], "all") == 0) |
| 1212 | proc = 0xFFFFFFFF; |
| 1213 | else if (strcmp(args[1], "odd") == 0) |
| 1214 | proc = 0x55555555; |
| 1215 | else if (strcmp(args[1], "even") == 0) |
| 1216 | proc = 0xAAAAAAAA; |
| 1217 | else { |
| 1218 | proc = atoi(args[1]); |
| 1219 | if (proc >= 1 && proc <= 32) |
| 1220 | proc = 1 << (proc - 1); |
| 1221 | } |
| 1222 | |
| 1223 | if (!proc || !*args[2]) { |
| 1224 | Alert("parsing [%s:%d]: %s expects a process number including 'all', 'odd', 'even', or a number from 1 to 32, followed by a list of CPU ranges with numbers from 0 to 31.\n", |
| 1225 | file, linenum, args[0]); |
| 1226 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1227 | goto out; |
| 1228 | } |
| 1229 | |
| 1230 | cur_arg = 2; |
| 1231 | while (*args[cur_arg]) { |
| 1232 | unsigned int low, high; |
| 1233 | |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 1234 | if (isdigit((int)*args[cur_arg])) { |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1235 | char *dash = strchr(args[cur_arg], '-'); |
| 1236 | |
| 1237 | low = high = str2uic(args[cur_arg]); |
| 1238 | if (dash) |
| 1239 | high = str2uic(dash + 1); |
| 1240 | |
| 1241 | if (high < low) { |
| 1242 | unsigned int swap = low; |
| 1243 | low = high; |
| 1244 | high = swap; |
| 1245 | } |
| 1246 | |
| 1247 | if (low < 0 || high >= sizeof(long) * 8) { |
| 1248 | Alert("parsing [%s:%d]: %s supports CPU numbers from 0 to %d.\n", |
| 1249 | file, linenum, args[0], (int)(sizeof(long) * 8 - 1)); |
| 1250 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1251 | goto out; |
| 1252 | } |
| 1253 | |
| 1254 | while (low <= high) |
| 1255 | cpus |= 1UL << low++; |
| 1256 | } |
| 1257 | else { |
| 1258 | Alert("parsing [%s:%d]: %s : '%s' is not a CPU range.\n", |
| 1259 | file, linenum, args[0], args[cur_arg]); |
| 1260 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1261 | goto out; |
| 1262 | } |
| 1263 | cur_arg++; |
| 1264 | } |
| 1265 | for (i = 0; i < 32; i++) |
| 1266 | if (proc & (1 << i)) |
| 1267 | global.cpu_map[i] = cpus; |
| 1268 | #else |
| 1269 | Alert("parsing [%s:%d] : '%s' is not enabled, please check build options for USE_CPU_AFFINITY.\n", file, linenum, args[0]); |
| 1270 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1271 | goto out; |
| 1272 | #endif |
| 1273 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1274 | else { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1275 | struct cfg_kw_list *kwl; |
| 1276 | int index; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1277 | int rc; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1278 | |
| 1279 | list_for_each_entry(kwl, &cfg_keywords.list, list) { |
| 1280 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 1281 | if (kwl->kw[index].section != CFG_GLOBAL) |
| 1282 | continue; |
| 1283 | if (strcmp(kwl->kw[index].kw, args[0]) == 0) { |
Willy Tarreau | 28a47d6 | 2012-09-18 20:02:48 +0200 | [diff] [blame] | 1284 | 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] | 1285 | if (rc < 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 1286 | Alert("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1287 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1288 | } |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1289 | else if (rc > 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 1290 | Warning("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1291 | err_code |= ERR_WARN; |
| 1292 | goto out; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1293 | } |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1294 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1295 | } |
| 1296 | } |
| 1297 | } |
| 1298 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1299 | 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] | 1300 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1301 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1302 | |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1303 | out: |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 1304 | free(errmsg); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1305 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1306 | } |
| 1307 | |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 1308 | void init_default_instance() |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1309 | { |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 1310 | init_new_proxy(&defproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1311 | defproxy.mode = PR_MODE_TCP; |
| 1312 | defproxy.state = PR_STNEW; |
| 1313 | defproxy.maxconn = cfg_maxpconn; |
| 1314 | defproxy.conn_retries = CONN_RETRIES; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1315 | |
| 1316 | defproxy.defsrv.inter = DEF_CHKINTR; |
| 1317 | defproxy.defsrv.fastinter = 0; |
| 1318 | defproxy.defsrv.downinter = 0; |
| 1319 | defproxy.defsrv.rise = DEF_RISETIME; |
| 1320 | defproxy.defsrv.fall = DEF_FALLTIME; |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 1321 | defproxy.defsrv.check.port = 0; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1322 | defproxy.defsrv.maxqueue = 0; |
| 1323 | defproxy.defsrv.minconn = 0; |
| 1324 | defproxy.defsrv.maxconn = 0; |
| 1325 | defproxy.defsrv.slowstart = 0; |
| 1326 | defproxy.defsrv.onerror = DEF_HANA_ONERR; |
| 1327 | defproxy.defsrv.consecutive_errors_limit = DEF_HANA_ERRLIMIT; |
| 1328 | defproxy.defsrv.uweight = defproxy.defsrv.iweight = 1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1329 | } |
| 1330 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1331 | |
| 1332 | static int create_cond_regex_rule(const char *file, int line, |
| 1333 | struct proxy *px, int dir, int action, int flags, |
| 1334 | const char *cmd, const char *reg, const char *repl, |
| 1335 | const char **cond_start) |
| 1336 | { |
| 1337 | regex_t *preg = NULL; |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 1338 | char *errmsg = NULL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1339 | const char *err; |
| 1340 | int err_code = 0; |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1341 | struct acl_cond *cond = NULL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1342 | |
| 1343 | if (px == &defproxy) { |
| 1344 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, line, cmd); |
| 1345 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1346 | goto err; |
| 1347 | } |
| 1348 | |
| 1349 | if (*reg == 0) { |
| 1350 | Alert("parsing [%s:%d] : '%s' expects <regex> as an argument.\n", file, line, cmd); |
| 1351 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1352 | goto err; |
| 1353 | } |
| 1354 | |
| 1355 | if (warnifnotcap(px, PR_CAP_RS, file, line, cmd, NULL)) |
| 1356 | err_code |= ERR_WARN; |
| 1357 | |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1358 | if (cond_start && |
| 1359 | (strcmp(*cond_start, "if") == 0 || strcmp(*cond_start, "unless") == 0)) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 1360 | if ((cond = build_acl_cond(file, line, px, cond_start, &errmsg)) == NULL) { |
| 1361 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 1362 | file, line, cmd, errmsg); |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1363 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1364 | goto err; |
| 1365 | } |
| 1366 | } |
| 1367 | else if (cond_start && **cond_start) { |
| 1368 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 1369 | file, line, cmd, *cond_start); |
| 1370 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1371 | goto err; |
| 1372 | } |
| 1373 | |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 1374 | if (dir == SMP_OPT_DIR_REQ) |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1375 | err_code |= warnif_cond_requires_resp(cond, file, line); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 1376 | else |
| 1377 | err_code |= warnif_cond_requires_req(cond, file, line); |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1378 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1379 | preg = calloc(1, sizeof(regex_t)); |
| 1380 | if (!preg) { |
| 1381 | Alert("parsing [%s:%d] : '%s' : not enough memory to build regex.\n", file, line, cmd); |
| 1382 | err_code = ERR_ALERT | ERR_FATAL; |
| 1383 | goto err; |
| 1384 | } |
| 1385 | |
| 1386 | if (regcomp(preg, reg, REG_EXTENDED | flags) != 0) { |
| 1387 | Alert("parsing [%s:%d] : '%s' : bad regular expression '%s'.\n", file, line, cmd, reg); |
| 1388 | err_code = ERR_ALERT | ERR_FATAL; |
| 1389 | goto err; |
| 1390 | } |
| 1391 | |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 1392 | 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] | 1393 | preg, action, repl ? strdup(repl) : NULL, cond); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1394 | if (repl && err) { |
| 1395 | Alert("parsing [%s:%d] : '%s' : invalid character or unterminated sequence in replacement string near '%c'.\n", |
| 1396 | file, line, cmd, *err); |
| 1397 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1398 | goto err; |
| 1399 | } |
| 1400 | |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 1401 | 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] | 1402 | err_code |= ERR_WARN; |
| 1403 | |
Willy Tarreau | f4068b6 | 2012-05-08 17:37:49 +0200 | [diff] [blame] | 1404 | free(errmsg); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1405 | return err_code; |
| 1406 | err: |
Willy Tarreau | f4068b6 | 2012-05-08 17:37:49 +0200 | [diff] [blame] | 1407 | free(errmsg); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1408 | free(preg); |
| 1409 | return err_code; |
| 1410 | } |
| 1411 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1412 | /* |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1413 | * Parse a line in a <listen>, <frontend>, <backend> or <ruleset> section. |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1414 | * Returns the error code, 0 if OK, or any combination of : |
| 1415 | * - ERR_ABORT: must abort ASAP |
| 1416 | * - ERR_FATAL: we can continue parsing but not start the service |
| 1417 | * - ERR_WARN: a warning has been emitted |
| 1418 | * - ERR_ALERT: an alert has been emitted |
| 1419 | * Only the two first ones can stop processing, the two others are just |
| 1420 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1421 | */ |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1422 | int cfg_parse_peers(const char *file, int linenum, char **args, int kwm) |
| 1423 | { |
| 1424 | static struct peers *curpeers = NULL; |
| 1425 | struct peer *newpeer = NULL; |
| 1426 | const char *err; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1427 | struct bind_conf *bind_conf; |
| 1428 | struct listener *l; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1429 | int err_code = 0; |
| 1430 | |
| 1431 | if (strcmp(args[0], "peers") == 0) { /* new peers section */ |
| 1432 | |
| 1433 | err = invalid_char(args[1]); |
| 1434 | if (err) { |
| 1435 | Alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 1436 | file, linenum, *err, args[0], args[1]); |
| 1437 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1438 | } |
| 1439 | |
| 1440 | for (curpeers = peers; curpeers != NULL; curpeers = curpeers->next) { |
| 1441 | /* |
| 1442 | * If there are two proxies with the same name only following |
| 1443 | * combinations are allowed: |
| 1444 | */ |
| 1445 | if (strcmp(curpeers->id, args[1]) == 0) { |
| 1446 | Warning("Parsing [%s:%d]: peers '%s' has same name as another peers (declared at %s:%d).\n", |
| 1447 | file, linenum, args[1], curpeers->conf.file, curpeers->conf.line); |
| 1448 | err_code |= ERR_WARN; |
| 1449 | } |
| 1450 | } |
| 1451 | |
| 1452 | if ((curpeers = (struct peers *)calloc(1, sizeof(struct peers))) == NULL) { |
| 1453 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1454 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1455 | goto out; |
| 1456 | } |
| 1457 | |
| 1458 | curpeers->next = peers; |
| 1459 | peers = curpeers; |
Willy Tarreau | 8113a5d | 2012-10-04 08:01:43 +0200 | [diff] [blame] | 1460 | curpeers->conf.file = strdup(file); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1461 | curpeers->conf.line = linenum; |
| 1462 | curpeers->last_change = now.tv_sec; |
| 1463 | curpeers->id = strdup(args[1]); |
| 1464 | } |
| 1465 | else if (strcmp(args[0], "peer") == 0) { /* peer definition */ |
| 1466 | char *rport, *raddr; |
| 1467 | short realport = 0; |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 1468 | struct sockaddr_storage *sk; |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 1469 | char *err_msg = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1470 | |
| 1471 | if (!*args[2]) { |
| 1472 | Alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n", |
| 1473 | file, linenum, args[0]); |
| 1474 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1475 | goto out; |
| 1476 | } |
| 1477 | |
| 1478 | err = invalid_char(args[1]); |
| 1479 | if (err) { |
| 1480 | Alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n", |
| 1481 | file, linenum, *err, args[1]); |
| 1482 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1483 | goto out; |
| 1484 | } |
| 1485 | |
| 1486 | if ((newpeer = (struct peer *)calloc(1, sizeof(struct peer))) == NULL) { |
| 1487 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1488 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1489 | goto out; |
| 1490 | } |
| 1491 | |
| 1492 | /* the peers are linked backwards first */ |
| 1493 | curpeers->count++; |
| 1494 | newpeer->next = curpeers->remote; |
| 1495 | curpeers->remote = newpeer; |
| 1496 | newpeer->peers = curpeers; |
Willy Tarreau | 8113a5d | 2012-10-04 08:01:43 +0200 | [diff] [blame] | 1497 | newpeer->conf.file = strdup(file); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1498 | newpeer->conf.line = linenum; |
| 1499 | |
| 1500 | newpeer->last_change = now.tv_sec; |
| 1501 | newpeer->id = strdup(args[1]); |
| 1502 | |
| 1503 | raddr = strdup(args[2]); |
Willy Tarreau | fab5a43 | 2011-03-04 15:31:53 +0100 | [diff] [blame] | 1504 | rport = strrchr(raddr, ':'); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1505 | if (rport) { |
| 1506 | *rport++ = 0; |
| 1507 | realport = atol(rport); |
| 1508 | } |
| 1509 | if (!realport) { |
| 1510 | Alert("parsing [%s:%d] : Missing or invalid port in '%s'\n", file, linenum, args[2]); |
| 1511 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1512 | goto out; |
| 1513 | } |
| 1514 | |
Willy Tarreau | fab5a43 | 2011-03-04 15:31:53 +0100 | [diff] [blame] | 1515 | sk = str2ip(raddr); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1516 | free(raddr); |
| 1517 | if (!sk) { |
| 1518 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[2]); |
| 1519 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1520 | goto out; |
| 1521 | } |
| 1522 | newpeer->addr = *sk; |
Willy Tarreau | 26d8c59 | 2012-05-07 18:12:14 +0200 | [diff] [blame] | 1523 | newpeer->proto = protocol_by_family(newpeer->addr.ss_family); |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 1524 | newpeer->xprt = &raw_sock; |
Willy Tarreau | d02394b | 2012-05-11 18:32:18 +0200 | [diff] [blame] | 1525 | newpeer->sock_init_arg = NULL; |
Willy Tarreau | 26d8c59 | 2012-05-07 18:12:14 +0200 | [diff] [blame] | 1526 | |
Willy Tarreau | 173e7fb | 2012-09-24 22:47:39 +0200 | [diff] [blame] | 1527 | if (!newpeer->proto) { |
Willy Tarreau | 26d8c59 | 2012-05-07 18:12:14 +0200 | [diff] [blame] | 1528 | Alert("parsing [%s:%d] : Unknown protocol family %d '%s'\n", |
| 1529 | file, linenum, newpeer->addr.ss_family, args[2]); |
| 1530 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1531 | goto out; |
| 1532 | } |
| 1533 | |
Willy Tarreau | 86ad42c | 2011-08-27 12:29:07 +0200 | [diff] [blame] | 1534 | set_host_port(&newpeer->addr, realport); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1535 | |
| 1536 | if (strcmp(newpeer->id, localpeer) == 0) { |
| 1537 | /* Current is local peer, it define a frontend */ |
| 1538 | newpeer->local = 1; |
| 1539 | |
| 1540 | if (!curpeers->peers_fe) { |
| 1541 | if ((curpeers->peers_fe = calloc(1, sizeof(struct proxy))) == NULL) { |
| 1542 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1543 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1544 | goto out; |
| 1545 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1546 | |
Willy Tarreau | 237250c | 2011-07-29 01:49:03 +0200 | [diff] [blame] | 1547 | init_new_proxy(curpeers->peers_fe); |
| 1548 | curpeers->peers_fe->parent = curpeers; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1549 | |
| 1550 | curpeers->peers_fe->last_change = now.tv_sec; |
| 1551 | curpeers->peers_fe->id = strdup(args[1]); |
| 1552 | curpeers->peers_fe->cap = PR_CAP_FE; |
Willy Tarreau | 3ae65a1 | 2011-09-07 17:40:39 +0200 | [diff] [blame] | 1553 | curpeers->peers_fe->maxconn = 0; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1554 | curpeers->peers_fe->conn_retries = CONN_RETRIES; |
| 1555 | curpeers->peers_fe->timeout.connect = 5000; |
| 1556 | curpeers->peers_fe->accept = peer_accept; |
| 1557 | 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] | 1558 | |
| 1559 | bind_conf = bind_conf_alloc(&curpeers->peers_fe->conf.bind, file, linenum, args[2]); |
| 1560 | |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 1561 | if (!str2listener(args[2], curpeers->peers_fe, bind_conf, file, linenum, &err_msg)) { |
| 1562 | if (err_msg && *err_msg) { |
| 1563 | indent_msg(&err_msg, 2); |
| 1564 | Alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], err_msg); |
| 1565 | } |
| 1566 | else |
| 1567 | Alert("parsing [%s:%d] : '%s %s' : error encountered while parsing listening address %s.\n", |
| 1568 | file, linenum, args[0], args[1], args[2]); |
| 1569 | free(err_msg); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1570 | err_code |= ERR_FATAL; |
| 1571 | goto out; |
| 1572 | } |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1573 | |
| 1574 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
| 1575 | l->maxconn = ((struct proxy *)curpeers->peers_fe)->maxconn; |
| 1576 | l->backlog = ((struct proxy *)curpeers->peers_fe)->backlog; |
| 1577 | l->timeout = &((struct proxy *)curpeers->peers_fe)->timeout.client; |
| 1578 | l->accept = session_accept; |
| 1579 | l->handler = process_session; |
| 1580 | l->analysers |= ((struct proxy *)curpeers->peers_fe)->fe_req_ana; |
| 1581 | l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */ |
| 1582 | global.maxsock += l->maxconn; |
| 1583 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1584 | } |
| 1585 | } |
| 1586 | } /* neither "peer" nor "peers" */ |
| 1587 | else if (*args[0] != 0) { |
| 1588 | Alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection); |
| 1589 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1590 | goto out; |
| 1591 | } |
| 1592 | |
| 1593 | out: |
| 1594 | return err_code; |
| 1595 | } |
| 1596 | |
| 1597 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 1598 | 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] | 1599 | { |
| 1600 | static struct proxy *curproxy = NULL; |
| 1601 | struct server *newsrv = NULL; |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 1602 | const char *err; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 1603 | int rc; |
| 1604 | unsigned val; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1605 | int err_code = 0; |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 1606 | struct acl_cond *cond = NULL; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 1607 | struct logsrv *tmplogsrv; |
Willy Tarreau | f4068b6 | 2012-05-08 17:37:49 +0200 | [diff] [blame] | 1608 | char *errmsg = NULL; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 1609 | struct bind_conf *bind_conf; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1610 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1611 | if (!strcmp(args[0], "listen")) |
| 1612 | rc = PR_CAP_LISTEN; |
| 1613 | else if (!strcmp(args[0], "frontend")) |
| 1614 | rc = PR_CAP_FE | PR_CAP_RS; |
| 1615 | else if (!strcmp(args[0], "backend")) |
| 1616 | rc = PR_CAP_BE | PR_CAP_RS; |
| 1617 | else if (!strcmp(args[0], "ruleset")) |
| 1618 | rc = PR_CAP_RS; |
| 1619 | else |
| 1620 | rc = PR_CAP_NONE; |
| 1621 | |
| 1622 | if (rc != PR_CAP_NONE) { /* new proxy */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1623 | if (!*args[1]) { |
| 1624 | Alert("parsing [%s:%d] : '%s' expects an <id> argument and\n" |
| 1625 | " optionnally supports [addr1]:port1[-end1]{,[addr]:port[-end]}...\n", |
| 1626 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1627 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1628 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1629 | } |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 1630 | |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 1631 | err = invalid_char(args[1]); |
| 1632 | if (err) { |
| 1633 | Alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 1634 | file, linenum, *err, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1635 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 1636 | } |
| 1637 | |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 1638 | for (curproxy = proxy; curproxy != NULL; curproxy = curproxy->next) { |
| 1639 | /* |
| 1640 | * If there are two proxies with the same name only following |
| 1641 | * combinations are allowed: |
| 1642 | * |
| 1643 | * listen backend frontend ruleset |
| 1644 | * listen - - - - |
| 1645 | * backend - - OK - |
| 1646 | * frontend - OK - - |
| 1647 | * ruleset - - - - |
| 1648 | */ |
| 1649 | |
| 1650 | if (!strcmp(curproxy->id, args[1]) && |
| 1651 | (rc!=(PR_CAP_FE|PR_CAP_RS) || curproxy->cap!=(PR_CAP_BE|PR_CAP_RS)) && |
| 1652 | (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] | 1653 | Warning("Parsing [%s:%d]: %s '%s' has same name as another %s (declared at %s:%d).\n", |
| 1654 | file, linenum, proxy_cap_str(rc), args[1], proxy_type_str(curproxy), |
| 1655 | curproxy->conf.file, curproxy->conf.line); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1656 | err_code |= ERR_WARN; |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 1657 | } |
| 1658 | } |
| 1659 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1660 | if ((curproxy = (struct proxy *)calloc(1, sizeof(struct proxy))) == NULL) { |
| 1661 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1662 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1663 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1664 | } |
Willy Tarreau | 5af24ef | 2009-03-15 15:23:16 +0100 | [diff] [blame] | 1665 | |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 1666 | init_new_proxy(curproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1667 | curproxy->next = proxy; |
| 1668 | proxy = curproxy; |
Willy Tarreau | 8113a5d | 2012-10-04 08:01:43 +0200 | [diff] [blame] | 1669 | curproxy->conf.file = strdup(file); |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 1670 | curproxy->conf.line = linenum; |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 1671 | curproxy->last_change = now.tv_sec; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1672 | curproxy->id = strdup(args[1]); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1673 | curproxy->cap = rc; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1674 | |
| 1675 | /* parse the listener address if any */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1676 | if ((curproxy->cap & PR_CAP_FE) && *args[2]) { |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1677 | struct listener *l; |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 1678 | char *err_msg = NULL; |
Willy Tarreau | 81a8117 | 2012-09-18 20:52:35 +0200 | [diff] [blame] | 1679 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1680 | bind_conf = bind_conf_alloc(&curproxy->conf.bind, file, linenum, args[2]); |
| 1681 | |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 1682 | if (!str2listener(args[2], curproxy, bind_conf, file, linenum, &err_msg)) { |
| 1683 | if (err_msg && *err_msg) { |
| 1684 | indent_msg(&err_msg, 2); |
| 1685 | Alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], err_msg); |
| 1686 | } |
| 1687 | else |
| 1688 | Alert("parsing [%s:%d] : '%s %s' : error encountered while parsing listening address '%s'.\n", |
| 1689 | file, linenum, args[0], args[1], args[2]); |
| 1690 | free(err_msg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1691 | err_code |= ERR_FATAL; |
| 1692 | goto out; |
| 1693 | } |
Willy Tarreau | 81a8117 | 2012-09-18 20:52:35 +0200 | [diff] [blame] | 1694 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1695 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
Willy Tarreau | c8b1109 | 2011-02-16 11:08:57 +0100 | [diff] [blame] | 1696 | global.maxsock++; |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 1697 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1698 | } |
| 1699 | |
| 1700 | /* set default values */ |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1701 | memcpy(&curproxy->defsrv, &defproxy.defsrv, sizeof(curproxy->defsrv)); |
Willy Tarreau | 7016020 | 2010-04-07 16:06:40 +0200 | [diff] [blame] | 1702 | curproxy->defsrv.id = "default-server"; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1703 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1704 | curproxy->state = defproxy.state; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1705 | curproxy->options = defproxy.options; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 1706 | curproxy->options2 = defproxy.options2; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 1707 | curproxy->no_options = defproxy.no_options; |
| 1708 | curproxy->no_options2 = defproxy.no_options2; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 1709 | curproxy->bind_proc = defproxy.bind_proc; |
Willy Tarreau | 3168223 | 2007-11-29 15:38:04 +0100 | [diff] [blame] | 1710 | curproxy->lbprm.algo = defproxy.lbprm.algo; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 1711 | curproxy->except_net = defproxy.except_net; |
| 1712 | curproxy->except_mask = defproxy.except_mask; |
Maik Broemme | 36db02e | 2009-05-08 17:02:07 +0200 | [diff] [blame] | 1713 | curproxy->except_to = defproxy.except_to; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 1714 | curproxy->except_mask_to = defproxy.except_mask_to; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1715 | |
Willy Tarreau | 79f5fe8 | 2008-08-23 08:18:21 +0200 | [diff] [blame] | 1716 | if (defproxy.fwdfor_hdr_len) { |
| 1717 | curproxy->fwdfor_hdr_len = defproxy.fwdfor_hdr_len; |
| 1718 | curproxy->fwdfor_hdr_name = strdup(defproxy.fwdfor_hdr_name); |
| 1719 | } |
| 1720 | |
Willy Tarreau | b86db34 | 2009-11-30 11:50:16 +0100 | [diff] [blame] | 1721 | if (defproxy.orgto_hdr_len) { |
| 1722 | curproxy->orgto_hdr_len = defproxy.orgto_hdr_len; |
| 1723 | curproxy->orgto_hdr_name = strdup(defproxy.orgto_hdr_name); |
| 1724 | } |
| 1725 | |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 1726 | if (defproxy.server_id_hdr_len) { |
| 1727 | curproxy->server_id_hdr_len = defproxy.server_id_hdr_len; |
| 1728 | curproxy->server_id_hdr_name = strdup(defproxy.server_id_hdr_name); |
| 1729 | } |
| 1730 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1731 | if (curproxy->cap & PR_CAP_FE) { |
| 1732 | curproxy->maxconn = defproxy.maxconn; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 1733 | curproxy->backlog = defproxy.backlog; |
Willy Tarreau | 13a34bd | 2009-05-10 18:52:49 +0200 | [diff] [blame] | 1734 | curproxy->fe_sps_lim = defproxy.fe_sps_lim; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1735 | |
| 1736 | /* initialize error relocations */ |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1737 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) |
| 1738 | chunk_dup(&curproxy->errmsg[rc], &defproxy.errmsg[rc]); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1739 | |
| 1740 | curproxy->to_log = defproxy.to_log & ~LW_COOKIE & ~LW_REQHDR & ~ LW_RSPHDR; |
| 1741 | } |
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 (curproxy->cap & PR_CAP_BE) { |
| 1744 | curproxy->fullconn = defproxy.fullconn; |
| 1745 | curproxy->conn_retries = defproxy.conn_retries; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1746 | |
Willy Tarreau | aa2f389 | 2010-10-22 16:15:31 +0200 | [diff] [blame] | 1747 | if (defproxy.check_req) { |
| 1748 | curproxy->check_req = calloc(1, defproxy.check_len); |
| 1749 | memcpy(curproxy->check_req, defproxy.check_req, defproxy.check_len); |
| 1750 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1751 | curproxy->check_len = defproxy.check_len; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1752 | |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 1753 | if (defproxy.expect_str) { |
| 1754 | curproxy->expect_str = strdup(defproxy.expect_str); |
| 1755 | if (defproxy.expect_regex) { |
| 1756 | /* note: this regex is known to be valid */ |
| 1757 | curproxy->expect_regex = calloc(1, sizeof(regex_t)); |
| 1758 | regcomp(curproxy->expect_regex, defproxy.expect_str, REG_EXTENDED); |
| 1759 | } |
| 1760 | } |
| 1761 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 1762 | curproxy->ck_opts = defproxy.ck_opts; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1763 | if (defproxy.cookie_name) |
| 1764 | curproxy->cookie_name = strdup(defproxy.cookie_name); |
| 1765 | curproxy->cookie_len = defproxy.cookie_len; |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 1766 | if (defproxy.cookie_domain) |
| 1767 | curproxy->cookie_domain = strdup(defproxy.cookie_domain); |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 1768 | |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 1769 | if (defproxy.cookie_maxidle) |
| 1770 | curproxy->cookie_maxidle = defproxy.cookie_maxidle; |
| 1771 | |
| 1772 | if (defproxy.cookie_maxlife) |
| 1773 | curproxy->cookie_maxlife = defproxy.cookie_maxlife; |
| 1774 | |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 1775 | if (defproxy.rdp_cookie_name) |
| 1776 | curproxy->rdp_cookie_name = strdup(defproxy.rdp_cookie_name); |
| 1777 | curproxy->rdp_cookie_len = defproxy.rdp_cookie_len; |
| 1778 | |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 1779 | if (defproxy.url_param_name) |
| 1780 | curproxy->url_param_name = strdup(defproxy.url_param_name); |
| 1781 | curproxy->url_param_len = defproxy.url_param_len; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 1782 | |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 1783 | if (defproxy.hh_name) |
| 1784 | curproxy->hh_name = strdup(defproxy.hh_name); |
| 1785 | curproxy->hh_len = defproxy.hh_len; |
| 1786 | curproxy->hh_match_domain = defproxy.hh_match_domain; |
| 1787 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 1788 | if (defproxy.conn_src.iface_name) |
| 1789 | curproxy->conn_src.iface_name = strdup(defproxy.conn_src.iface_name); |
| 1790 | curproxy->conn_src.iface_len = defproxy.conn_src.iface_len; |
| 1791 | curproxy->conn_src.opts = defproxy.conn_src.opts & ~CO_SRC_TPROXY_MASK; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1792 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1793 | |
Willy Tarreau | 3b6b1a9 | 2009-07-23 13:24:23 +0200 | [diff] [blame] | 1794 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1795 | if (defproxy.capture_name) |
| 1796 | curproxy->capture_name = strdup(defproxy.capture_name); |
| 1797 | curproxy->capture_namelen = defproxy.capture_namelen; |
| 1798 | curproxy->capture_len = defproxy.capture_len; |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 1799 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1800 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1801 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 1802 | curproxy->timeout.client = defproxy.timeout.client; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 1803 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | 036fae0 | 2008-01-06 13:24:40 +0100 | [diff] [blame] | 1804 | curproxy->timeout.httpreq = defproxy.timeout.httpreq; |
Willy Tarreau | b16a574 | 2010-01-10 14:46:16 +0100 | [diff] [blame] | 1805 | curproxy->timeout.httpka = defproxy.timeout.httpka; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1806 | curproxy->uri_auth = defproxy.uri_auth; |
| 1807 | curproxy->mon_net = defproxy.mon_net; |
| 1808 | curproxy->mon_mask = defproxy.mon_mask; |
| 1809 | if (defproxy.monitor_uri) |
| 1810 | curproxy->monitor_uri = strdup(defproxy.monitor_uri); |
| 1811 | curproxy->monitor_uri_len = defproxy.monitor_uri_len; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 1812 | if (defproxy.defbe.name) |
| 1813 | curproxy->defbe.name = strdup(defproxy.defbe.name); |
Willy Tarreau | 99a7ca2 | 2012-05-31 19:39:23 +0200 | [diff] [blame] | 1814 | |
| 1815 | /* get either a pointer to the logformat string or a copy of it */ |
| 1816 | curproxy->logformat_string = defproxy.logformat_string; |
| 1817 | if (curproxy->logformat_string && |
| 1818 | curproxy->logformat_string != default_http_log_format && |
| 1819 | curproxy->logformat_string != default_tcp_log_format && |
| 1820 | curproxy->logformat_string != clf_http_log_format) |
| 1821 | curproxy->logformat_string = strdup(curproxy->logformat_string); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1822 | } |
| 1823 | |
| 1824 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 1825 | curproxy->timeout.connect = defproxy.timeout.connect; |
| 1826 | curproxy->timeout.server = defproxy.timeout.server; |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 1827 | curproxy->timeout.check = defproxy.timeout.check; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 1828 | curproxy->timeout.queue = defproxy.timeout.queue; |
Willy Tarreau | 51c9bde | 2008-01-06 13:40:03 +0100 | [diff] [blame] | 1829 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | cd7afc0 | 2009-07-12 10:03:17 +0200 | [diff] [blame] | 1830 | curproxy->timeout.httpreq = defproxy.timeout.httpreq; |
Willy Tarreau | b16a574 | 2010-01-10 14:46:16 +0100 | [diff] [blame] | 1831 | curproxy->timeout.httpka = defproxy.timeout.httpka; |
Willy Tarreau | ce887fd | 2012-05-12 12:50:00 +0200 | [diff] [blame] | 1832 | curproxy->timeout.tunnel = defproxy.timeout.tunnel; |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 1833 | curproxy->conn_src.source_addr = defproxy.conn_src.source_addr; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1834 | } |
| 1835 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1836 | curproxy->mode = defproxy.mode; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1837 | |
| 1838 | /* copy default logsrvs to curproxy */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 1839 | list_for_each_entry(tmplogsrv, &defproxy.logsrvs, list) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1840 | struct logsrv *node = malloc(sizeof(struct logsrv)); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 1841 | memcpy(node, tmplogsrv, sizeof(struct logsrv)); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1842 | LIST_INIT(&node->list); |
| 1843 | LIST_ADDQ(&curproxy->logsrvs, &node->list); |
| 1844 | } |
| 1845 | |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 1846 | curproxy->uniqueid_format_string = defproxy.uniqueid_format_string; |
| 1847 | if (curproxy->uniqueid_format_string) |
| 1848 | curproxy->uniqueid_format_string = strdup(curproxy->uniqueid_format_string); |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 1849 | |
| 1850 | /* copy default header unique id */ |
| 1851 | if (defproxy.header_unique_id) |
| 1852 | curproxy->header_unique_id = strdup(defproxy.header_unique_id); |
| 1853 | |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 1854 | /* default compression options */ |
| 1855 | if (defproxy.comp != NULL) { |
| 1856 | curproxy->comp = calloc(1, sizeof(struct comp)); |
| 1857 | curproxy->comp->algos = defproxy.comp->algos; |
| 1858 | curproxy->comp->types = defproxy.comp->types; |
| 1859 | } |
| 1860 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1861 | curproxy->grace = defproxy.grace; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1862 | curproxy->conf.used_listener_id = EB_ROOT; |
| 1863 | curproxy->conf.used_server_id = EB_ROOT; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 1864 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1865 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1866 | } |
| 1867 | else if (!strcmp(args[0], "defaults")) { /* use this one to assign default values */ |
| 1868 | /* some variables may have already been initialized earlier */ |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 1869 | /* FIXME-20070101: we should do this too at the end of the |
| 1870 | * config parsing to free all default values. |
| 1871 | */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1872 | free(defproxy.check_req); |
| 1873 | free(defproxy.cookie_name); |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 1874 | free(defproxy.rdp_cookie_name); |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 1875 | free(defproxy.cookie_domain); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1876 | free(defproxy.url_param_name); |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 1877 | free(defproxy.hh_name); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1878 | free(defproxy.capture_name); |
| 1879 | free(defproxy.monitor_uri); |
| 1880 | free(defproxy.defbe.name); |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 1881 | free(defproxy.conn_src.iface_name); |
Willy Tarreau | 79f5fe8 | 2008-08-23 08:18:21 +0200 | [diff] [blame] | 1882 | free(defproxy.fwdfor_hdr_name); |
| 1883 | defproxy.fwdfor_hdr_len = 0; |
Willy Tarreau | b86db34 | 2009-11-30 11:50:16 +0100 | [diff] [blame] | 1884 | free(defproxy.orgto_hdr_name); |
| 1885 | defproxy.orgto_hdr_len = 0; |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 1886 | free(defproxy.server_id_hdr_name); |
| 1887 | defproxy.server_id_hdr_len = 0; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 1888 | free(defproxy.expect_str); |
| 1889 | if (defproxy.expect_regex) regfree(defproxy.expect_regex); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 1890 | |
Willy Tarreau | 39b0665 | 2012-06-01 10:58:06 +0200 | [diff] [blame] | 1891 | if (defproxy.logformat_string != default_http_log_format && |
| 1892 | defproxy.logformat_string != default_tcp_log_format && |
| 1893 | defproxy.logformat_string != clf_http_log_format) |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 1894 | free(defproxy.logformat_string); |
| 1895 | |
| 1896 | free(defproxy.uniqueid_format_string); |
| 1897 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1898 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1899 | chunk_destroy(&defproxy.errmsg[rc]); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 1900 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1901 | /* we cannot free uri_auth because it might already be used */ |
| 1902 | init_default_instance(); |
| 1903 | curproxy = &defproxy; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1904 | defproxy.cap = PR_CAP_LISTEN; /* all caps for now */ |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1905 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1906 | } |
| 1907 | else if (curproxy == NULL) { |
| 1908 | Alert("parsing [%s:%d] : 'listen' or 'defaults' expected.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1909 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1910 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1911 | } |
| 1912 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1913 | |
| 1914 | /* Now let's parse the proxy-specific keywords */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1915 | if (!strcmp(args[0], "bind")) { /* new listen addresses */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1916 | struct listener *l; |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1917 | int cur_arg; |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 1918 | char *err_msg = NULL; |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1919 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1920 | if (curproxy == &defproxy) { |
| 1921 | 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] | 1922 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1923 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1924 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1925 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1926 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1927 | |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 1928 | if ( *(args[1]) != '/' && strchr(args[1], ':') == NULL) { |
Willy Tarreau | d55c3fe | 2010-11-09 09:50:37 +0100 | [diff] [blame] | 1929 | 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] | 1930 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1931 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1932 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1933 | } |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 1934 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 1935 | bind_conf = bind_conf_alloc(&curproxy->conf.bind, file, linenum, args[1]); |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1936 | 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] | 1937 | |
| 1938 | /* NOTE: the following line might create several listeners if there |
| 1939 | * are comma-separated IPs or port ranges. So all further processing |
| 1940 | * will have to be applied to all listeners created after last_listen. |
| 1941 | */ |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 1942 | if (!str2listener(args[1], curproxy, bind_conf, file, linenum, &err_msg)) { |
| 1943 | if (err_msg && *err_msg) { |
| 1944 | indent_msg(&err_msg, 2); |
| 1945 | Alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], err_msg); |
| 1946 | } |
| 1947 | else |
| 1948 | Alert("parsing [%s:%d] : '%s' : error encountered while parsing listening address '%s'.\n", |
| 1949 | file, linenum, args[0], args[1]); |
| 1950 | free(err_msg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1951 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1952 | goto out; |
| 1953 | } |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1954 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1955 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
| 1956 | /* Set default global rights and owner for unix bind */ |
Willy Tarreau | c8b1109 | 2011-02-16 11:08:57 +0100 | [diff] [blame] | 1957 | global.maxsock++; |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 1958 | } |
| 1959 | |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1960 | cur_arg = 2; |
| 1961 | while (*(args[cur_arg])) { |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 1962 | static int bind_dumped; |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 1963 | struct bind_kw *kw; |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 1964 | char *err; |
| 1965 | |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 1966 | kw = bind_find_kw(args[cur_arg]); |
| 1967 | if (kw) { |
| 1968 | char *err = NULL; |
| 1969 | int code; |
| 1970 | |
| 1971 | if (!kw->parse) { |
Willy Tarreau | dda322d | 2012-09-18 16:34:09 +0200 | [diff] [blame] | 1972 | Alert("parsing [%s:%d] : '%s %s' : '%s' option is not implemented in this version (check build options).\n", |
| 1973 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 1974 | cur_arg += 1 + kw->skip ; |
| 1975 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1976 | goto out; |
| 1977 | } |
| 1978 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1979 | code = kw->parse(args, cur_arg, curproxy, bind_conf, &err); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 1980 | err_code |= code; |
| 1981 | |
| 1982 | if (code) { |
| 1983 | if (err && *err) { |
| 1984 | indent_msg(&err, 2); |
Willy Tarreau | dda322d | 2012-09-18 16:34:09 +0200 | [diff] [blame] | 1985 | 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] | 1986 | } |
| 1987 | else |
Willy Tarreau | dda322d | 2012-09-18 16:34:09 +0200 | [diff] [blame] | 1988 | Alert("parsing [%s:%d] : '%s %s' : error encountered while processing '%s'.\n", |
| 1989 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 1990 | if (code & ERR_FATAL) { |
| 1991 | free(err); |
| 1992 | cur_arg += 1 + kw->skip; |
| 1993 | goto out; |
| 1994 | } |
| 1995 | } |
| 1996 | free(err); |
| 1997 | cur_arg += 1 + kw->skip; |
| 1998 | continue; |
| 1999 | } |
| 2000 | |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 2001 | err = NULL; |
| 2002 | if (!bind_dumped) { |
| 2003 | bind_dump_kws(&err); |
| 2004 | indent_msg(&err, 4); |
| 2005 | bind_dumped = 1; |
| 2006 | } |
| 2007 | |
| 2008 | Alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'.%s%s\n", |
| 2009 | file, linenum, args[0], args[1], args[cur_arg], |
| 2010 | err ? " Registered keywords :" : "", err ? err : ""); |
| 2011 | free(err); |
| 2012 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2013 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2014 | goto out; |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 2015 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2016 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2017 | } |
| 2018 | else if (!strcmp(args[0], "monitor-net")) { /* set the range of IPs to ignore */ |
| 2019 | if (!*args[1] || !str2net(args[1], &curproxy->mon_net, &curproxy->mon_mask)) { |
| 2020 | Alert("parsing [%s:%d] : '%s' expects address[/mask].\n", |
| 2021 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2022 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2023 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2024 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2025 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2026 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2027 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2028 | /* flush useless bits */ |
| 2029 | curproxy->mon_net.s_addr &= curproxy->mon_mask.s_addr; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2030 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2031 | } |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2032 | else if (!strcmp(args[0], "monitor-uri")) { /* set the URI to intercept */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2033 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2034 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2035 | |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2036 | if (!*args[1]) { |
| 2037 | Alert("parsing [%s:%d] : '%s' expects an URI.\n", |
| 2038 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2039 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2040 | goto out; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2041 | } |
| 2042 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2043 | free(curproxy->monitor_uri); |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 2044 | curproxy->monitor_uri_len = strlen(args[1]); |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2045 | curproxy->monitor_uri = (char *)calloc(1, curproxy->monitor_uri_len + 1); |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 2046 | memcpy(curproxy->monitor_uri, args[1], curproxy->monitor_uri_len); |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2047 | curproxy->monitor_uri[curproxy->monitor_uri_len] = '\0'; |
| 2048 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2049 | goto out; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2050 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2051 | else if (!strcmp(args[0], "mode")) { /* sets the proxy mode */ |
| 2052 | if (!strcmp(args[1], "http")) curproxy->mode = PR_MODE_HTTP; |
| 2053 | else if (!strcmp(args[1], "tcp")) curproxy->mode = PR_MODE_TCP; |
| 2054 | else if (!strcmp(args[1], "health")) curproxy->mode = PR_MODE_HEALTH; |
| 2055 | else { |
| 2056 | 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] | 2057 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2058 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2059 | } |
| 2060 | } |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2061 | else if (!strcmp(args[0], "id")) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2062 | struct eb32_node *node; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2063 | |
| 2064 | if (curproxy == &defproxy) { |
| 2065 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", |
| 2066 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2067 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2068 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2069 | } |
| 2070 | |
| 2071 | if (!*args[1]) { |
| 2072 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 2073 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2074 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2075 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2076 | } |
| 2077 | |
| 2078 | curproxy->uuid = atol(args[1]); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2079 | curproxy->conf.id.key = curproxy->uuid; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2080 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2081 | if (curproxy->uuid <= 0) { |
| 2082 | Alert("parsing [%s:%d]: custom id has to be > 0.\n", |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2083 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2084 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2085 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2086 | } |
| 2087 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2088 | node = eb32_lookup(&used_proxy_id, curproxy->uuid); |
| 2089 | if (node) { |
| 2090 | struct proxy *target = container_of(node, struct proxy, conf.id); |
| 2091 | Alert("parsing [%s:%d]: %s %s reuses same custom id as %s %s (declared at %s:%d).\n", |
| 2092 | file, linenum, proxy_type_str(curproxy), curproxy->id, |
| 2093 | proxy_type_str(target), target->id, target->conf.file, target->conf.line); |
| 2094 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2095 | goto out; |
| 2096 | } |
| 2097 | eb32_insert(&used_proxy_id, &curproxy->conf.id); |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2098 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 2099 | else if (!strcmp(args[0], "description")) { |
| 2100 | int i, len=0; |
| 2101 | char *d; |
| 2102 | |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 2103 | if (curproxy == &defproxy) { |
| 2104 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", |
| 2105 | file, linenum, args[0]); |
| 2106 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2107 | goto out; |
| 2108 | } |
| 2109 | |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 2110 | if (!*args[1]) { |
| 2111 | Alert("parsing [%s:%d]: '%s' expects a string argument.\n", |
| 2112 | file, linenum, args[0]); |
| 2113 | return -1; |
| 2114 | } |
| 2115 | |
| 2116 | for(i=1; *args[i]; i++) |
| 2117 | len += strlen(args[i])+1; |
| 2118 | |
| 2119 | d = (char *)calloc(1, len); |
| 2120 | curproxy->desc = d; |
| 2121 | |
| 2122 | d += sprintf(d, "%s", args[1]); |
| 2123 | for(i=2; *args[i]; i++) |
| 2124 | d += sprintf(d, " %s", args[i]); |
| 2125 | |
| 2126 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2127 | else if (!strcmp(args[0], "disabled")) { /* disables this proxy */ |
| 2128 | curproxy->state = PR_STSTOPPED; |
| 2129 | } |
| 2130 | else if (!strcmp(args[0], "enabled")) { /* enables this proxy (used to revert a disabled default) */ |
| 2131 | curproxy->state = PR_STNEW; |
| 2132 | } |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2133 | else if (!strcmp(args[0], "bind-process")) { /* enable this proxy only on some processes */ |
| 2134 | int cur_arg = 1; |
| 2135 | unsigned int set = 0; |
| 2136 | |
| 2137 | while (*args[cur_arg]) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 2138 | unsigned int low, high; |
| 2139 | |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2140 | if (strcmp(args[cur_arg], "all") == 0) { |
| 2141 | set = 0; |
| 2142 | break; |
| 2143 | } |
| 2144 | else if (strcmp(args[cur_arg], "odd") == 0) { |
| 2145 | set |= 0x55555555; |
| 2146 | } |
| 2147 | else if (strcmp(args[cur_arg], "even") == 0) { |
| 2148 | set |= 0xAAAAAAAA; |
| 2149 | } |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 2150 | else if (isdigit((int)*args[cur_arg])) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 2151 | char *dash = strchr(args[cur_arg], '-'); |
| 2152 | |
| 2153 | low = high = str2uic(args[cur_arg]); |
| 2154 | if (dash) |
| 2155 | high = str2uic(dash + 1); |
| 2156 | |
| 2157 | if (high < low) { |
| 2158 | unsigned int swap = low; |
| 2159 | low = high; |
| 2160 | high = swap; |
| 2161 | } |
| 2162 | |
| 2163 | if (low < 1 || high > 32) { |
| 2164 | Alert("parsing [%s:%d]: %s supports process numbers from 1 to 32.\n", |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2165 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2166 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2167 | goto out; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2168 | } |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 2169 | |
| 2170 | if (high > global.nbproc) { |
| 2171 | Warning("parsing [%s:%d]: %s references process number %d which is higher than global.nbproc (%d).\n", |
| 2172 | file, linenum, args[0], high, global.nbproc); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2173 | err_code |= ERR_WARN; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2174 | } |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 2175 | while (low <= high) |
| 2176 | set |= 1 << (low++ - 1); |
| 2177 | } |
| 2178 | else { |
| 2179 | Alert("parsing [%s:%d]: %s expects 'all', 'odd', 'even', or a list of process ranges with numbers from 1 to 32.\n", |
| 2180 | file, linenum, args[0]); |
| 2181 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2182 | goto out; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2183 | } |
| 2184 | cur_arg++; |
| 2185 | } |
| 2186 | curproxy->bind_proc = set; |
| 2187 | } |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 2188 | else if (!strcmp(args[0], "acl")) { /* add an ACL */ |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2189 | if (curproxy == &defproxy) { |
| 2190 | 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] | 2191 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2192 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2193 | } |
| 2194 | |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 2195 | err = invalid_char(args[1]); |
| 2196 | if (err) { |
| 2197 | Alert("parsing [%s:%d] : character '%c' is not permitted in acl name '%s'.\n", |
| 2198 | file, linenum, *err, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2199 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 2200 | } |
| 2201 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 2202 | if (parse_acl((const char **)args + 1, &curproxy->acl, &errmsg) == NULL) { |
| 2203 | Alert("parsing [%s:%d] : error detected while parsing ACL '%s' : %s.\n", |
| 2204 | file, linenum, args[1], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2205 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2206 | goto out; |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 2207 | } |
| 2208 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2209 | else if (!strcmp(args[0], "cookie")) { /* cookie name */ |
| 2210 | int cur_arg; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2211 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2212 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2213 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2214 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2215 | if (*(args[1]) == 0) { |
| 2216 | Alert("parsing [%s:%d] : '%s' expects <cookie_name> as argument.\n", |
| 2217 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2218 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2219 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2220 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2221 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2222 | curproxy->ck_opts = 0; |
Willy Tarreau | c63d4bb | 2010-10-23 11:37:27 +0200 | [diff] [blame] | 2223 | curproxy->cookie_maxidle = curproxy->cookie_maxlife = 0; |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 2224 | free(curproxy->cookie_domain); curproxy->cookie_domain = NULL; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2225 | free(curproxy->cookie_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2226 | curproxy->cookie_name = strdup(args[1]); |
| 2227 | curproxy->cookie_len = strlen(curproxy->cookie_name); |
Willy Tarreau | c63d4bb | 2010-10-23 11:37:27 +0200 | [diff] [blame] | 2228 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2229 | cur_arg = 2; |
| 2230 | while (*(args[cur_arg])) { |
| 2231 | if (!strcmp(args[cur_arg], "rewrite")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2232 | curproxy->ck_opts |= PR_CK_RW; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2233 | } |
| 2234 | else if (!strcmp(args[cur_arg], "indirect")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2235 | curproxy->ck_opts |= PR_CK_IND; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2236 | } |
| 2237 | else if (!strcmp(args[cur_arg], "insert")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2238 | curproxy->ck_opts |= PR_CK_INS; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2239 | } |
| 2240 | else if (!strcmp(args[cur_arg], "nocache")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2241 | curproxy->ck_opts |= PR_CK_NOC; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2242 | } |
| 2243 | else if (!strcmp(args[cur_arg], "postonly")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2244 | curproxy->ck_opts |= PR_CK_POST; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2245 | } |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 2246 | else if (!strcmp(args[cur_arg], "preserve")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2247 | curproxy->ck_opts |= PR_CK_PSV; |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 2248 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2249 | else if (!strcmp(args[cur_arg], "prefix")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2250 | curproxy->ck_opts |= PR_CK_PFX; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2251 | } |
Willy Tarreau | 4992dd2 | 2012-05-31 21:02:17 +0200 | [diff] [blame] | 2252 | else if (!strcmp(args[cur_arg], "httponly")) { |
| 2253 | curproxy->ck_opts |= PR_CK_HTTPONLY; |
| 2254 | } |
| 2255 | else if (!strcmp(args[cur_arg], "secure")) { |
| 2256 | curproxy->ck_opts |= PR_CK_SECURE; |
| 2257 | } |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2258 | else if (!strcmp(args[cur_arg], "domain")) { |
| 2259 | if (!*args[cur_arg + 1]) { |
| 2260 | Alert("parsing [%s:%d]: '%s' expects <domain> as argument.\n", |
| 2261 | file, linenum, args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2262 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2263 | goto out; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2264 | } |
| 2265 | |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 2266 | if (*args[cur_arg + 1] != '.' || !strchr(args[cur_arg + 1] + 1, '.')) { |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2267 | /* rfc2109, 4.3.2 Rejecting Cookies */ |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 2268 | Warning("parsing [%s:%d]: domain '%s' contains no embedded" |
| 2269 | " dots nor does not start with a dot." |
| 2270 | " RFC forbids it, this configuration may not work properly.\n", |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2271 | file, linenum, args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 2272 | err_code |= ERR_WARN; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2273 | } |
| 2274 | |
| 2275 | err = invalid_domainchar(args[cur_arg + 1]); |
| 2276 | if (err) { |
| 2277 | Alert("parsing [%s:%d]: character '%c' is not permitted in domain name '%s'.\n", |
| 2278 | file, linenum, *err, args[cur_arg + 1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2279 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2280 | goto out; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2281 | } |
| 2282 | |
Willy Tarreau | 68a897b | 2009-12-03 23:28:34 +0100 | [diff] [blame] | 2283 | if (!curproxy->cookie_domain) { |
| 2284 | curproxy->cookie_domain = strdup(args[cur_arg + 1]); |
| 2285 | } else { |
| 2286 | /* one domain was already specified, add another one by |
| 2287 | * building the string which will be returned along with |
| 2288 | * the cookie. |
| 2289 | */ |
| 2290 | char *new_ptr; |
| 2291 | int new_len = strlen(curproxy->cookie_domain) + |
| 2292 | strlen("; domain=") + strlen(args[cur_arg + 1]) + 1; |
| 2293 | new_ptr = malloc(new_len); |
| 2294 | snprintf(new_ptr, new_len, "%s; domain=%s", curproxy->cookie_domain, args[cur_arg+1]); |
| 2295 | free(curproxy->cookie_domain); |
| 2296 | curproxy->cookie_domain = new_ptr; |
| 2297 | } |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 2298 | cur_arg++; |
| 2299 | } |
| 2300 | else if (!strcmp(args[cur_arg], "maxidle")) { |
| 2301 | unsigned int maxidle; |
| 2302 | const char *res; |
| 2303 | |
| 2304 | if (!*args[cur_arg + 1]) { |
| 2305 | Alert("parsing [%s:%d]: '%s' expects <idletime> in seconds as argument.\n", |
| 2306 | file, linenum, args[cur_arg]); |
| 2307 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2308 | goto out; |
| 2309 | } |
| 2310 | |
| 2311 | res = parse_time_err(args[cur_arg + 1], &maxidle, TIME_UNIT_S); |
| 2312 | if (res) { |
| 2313 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 2314 | file, linenum, *res, args[cur_arg]); |
| 2315 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2316 | goto out; |
| 2317 | } |
| 2318 | curproxy->cookie_maxidle = maxidle; |
| 2319 | cur_arg++; |
| 2320 | } |
| 2321 | else if (!strcmp(args[cur_arg], "maxlife")) { |
| 2322 | unsigned int maxlife; |
| 2323 | const char *res; |
| 2324 | |
| 2325 | if (!*args[cur_arg + 1]) { |
| 2326 | Alert("parsing [%s:%d]: '%s' expects <lifetime> in seconds as argument.\n", |
| 2327 | file, linenum, args[cur_arg]); |
| 2328 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2329 | goto out; |
| 2330 | } |
| 2331 | |
| 2332 | res = parse_time_err(args[cur_arg + 1], &maxlife, TIME_UNIT_S); |
| 2333 | if (res) { |
| 2334 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 2335 | file, linenum, *res, args[cur_arg]); |
| 2336 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2337 | goto out; |
| 2338 | } |
| 2339 | curproxy->cookie_maxlife = maxlife; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2340 | cur_arg++; |
| 2341 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2342 | else { |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 2343 | 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] | 2344 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2345 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2346 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2347 | } |
| 2348 | cur_arg++; |
| 2349 | } |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2350 | if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_IND))) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2351 | Alert("parsing [%s:%d] : cookie 'rewrite' and 'indirect' modes are incompatible.\n", |
| 2352 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2353 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2354 | } |
| 2355 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2356 | 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] | 2357 | Alert("parsing [%s:%d] : cookie 'rewrite', 'insert' and 'prefix' modes are incompatible.\n", |
| 2358 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2359 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2360 | } |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 2361 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2362 | 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] | 2363 | Alert("parsing [%s:%d] : cookie 'preserve' requires at least 'insert' or 'indirect'.\n", |
| 2364 | file, linenum); |
| 2365 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2366 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2367 | }/* end else if (!strcmp(args[0], "cookie")) */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2368 | else if (!strcmp(args[0], "persist")) { /* persist */ |
| 2369 | if (*(args[1]) == 0) { |
| 2370 | Alert("parsing [%s:%d] : missing persist method.\n", |
| 2371 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2372 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2373 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2374 | } |
| 2375 | |
| 2376 | if (!strncmp(args[1], "rdp-cookie", 10)) { |
| 2377 | curproxy->options2 |= PR_O2_RDPC_PRST; |
| 2378 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2379 | if (*(args[1] + 10) == '(') { /* cookie name */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2380 | const char *beg, *end; |
| 2381 | |
| 2382 | beg = args[1] + 11; |
| 2383 | end = strchr(beg, ')'); |
| 2384 | |
| 2385 | if (!end || end == beg) { |
| 2386 | Alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n", |
| 2387 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2388 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2389 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2390 | } |
| 2391 | |
| 2392 | free(curproxy->rdp_cookie_name); |
| 2393 | curproxy->rdp_cookie_name = my_strndup(beg, end - beg); |
| 2394 | curproxy->rdp_cookie_len = end-beg; |
| 2395 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2396 | else if (*(args[1] + 10) == '\0') { /* default cookie name 'msts' */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2397 | free(curproxy->rdp_cookie_name); |
| 2398 | curproxy->rdp_cookie_name = strdup("msts"); |
| 2399 | curproxy->rdp_cookie_len = strlen(curproxy->rdp_cookie_name); |
| 2400 | } |
| 2401 | else { /* syntax */ |
| 2402 | Alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n", |
| 2403 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2404 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2405 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2406 | } |
| 2407 | } |
| 2408 | else { |
| 2409 | Alert("parsing [%s:%d] : unknown persist method.\n", |
| 2410 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2411 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2412 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2413 | } |
| 2414 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2415 | else if (!strcmp(args[0], "appsession")) { /* cookie name */ |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2416 | int cur_arg; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2417 | |
Cyril Bonté | 3b7a369 | 2010-01-10 17:01:47 +0100 | [diff] [blame] | 2418 | if (curproxy == &defproxy) { |
| 2419 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2420 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2421 | goto out; |
| 2422 | } |
| 2423 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2424 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2425 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2426 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2427 | if (*(args[5]) == 0) { |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2428 | 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] | 2429 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2430 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2431 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2432 | } |
| 2433 | have_appsession = 1; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2434 | free(curproxy->appsession_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2435 | curproxy->appsession_name = strdup(args[1]); |
| 2436 | curproxy->appsession_name_len = strlen(curproxy->appsession_name); |
| 2437 | curproxy->appsession_len = atoi(args[3]); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 2438 | err = parse_time_err(args[5], &val, TIME_UNIT_MS); |
| 2439 | if (err) { |
| 2440 | Alert("parsing [%s:%d] : unexpected character '%c' in %s timeout.\n", |
| 2441 | file, linenum, *err, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2442 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2443 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 2444 | } |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 2445 | curproxy->timeout.appsession = val; |
Willy Tarreau | ee99136 | 2007-05-14 14:37:50 +0200 | [diff] [blame] | 2446 | |
Willy Tarreau | 51041c7 | 2007-09-09 21:56:53 +0200 | [diff] [blame] | 2447 | if (appsession_hash_init(&(curproxy->htbl_proxy), destroy) == 0) { |
| 2448 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2449 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2450 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2451 | } |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2452 | |
| 2453 | cur_arg = 6; |
| 2454 | curproxy->options2 &= ~PR_O2_AS_REQL; |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2455 | curproxy->options2 &= ~PR_O2_AS_M_ANY; |
| 2456 | curproxy->options2 |= PR_O2_AS_M_PP; |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2457 | while (*(args[cur_arg])) { |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2458 | if (!strcmp(args[cur_arg], "request-learn")) { |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2459 | curproxy->options2 |= PR_O2_AS_REQL; |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2460 | } else if (!strcmp(args[cur_arg], "prefix")) { |
| 2461 | curproxy->options2 |= PR_O2_AS_PFX; |
| 2462 | } else if (!strcmp(args[cur_arg], "mode")) { |
| 2463 | if (!*args[cur_arg + 1]) { |
| 2464 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 2465 | file, linenum, args[0], args[cur_arg]); |
| 2466 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2467 | goto out; |
| 2468 | } |
| 2469 | |
| 2470 | cur_arg++; |
| 2471 | if (!strcmp(args[cur_arg], "query-string")) { |
| 2472 | curproxy->options2 &= ~PR_O2_AS_M_ANY; |
| 2473 | curproxy->options2 |= PR_O2_AS_M_QS; |
| 2474 | } else if (!strcmp(args[cur_arg], "path-parameters")) { |
| 2475 | curproxy->options2 &= ~PR_O2_AS_M_ANY; |
| 2476 | curproxy->options2 |= PR_O2_AS_M_PP; |
| 2477 | } else { |
| 2478 | Alert("parsing [%s:%d] : unknown mode '%s'\n", file, linenum, args[cur_arg]); |
| 2479 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2480 | goto out; |
| 2481 | } |
| 2482 | } |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2483 | cur_arg++; |
| 2484 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2485 | } /* Url App Session */ |
| 2486 | else if (!strcmp(args[0], "capture")) { |
Willy Tarreau | 3b6b1a9 | 2009-07-23 13:24:23 +0200 | [diff] [blame] | 2487 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2488 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2489 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2490 | if (!strcmp(args[1], "cookie")) { /* name of a cookie to capture */ |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 2491 | if (curproxy == &defproxy) { |
| 2492 | Alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
| 2493 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2494 | goto out; |
| 2495 | } |
| 2496 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2497 | if (*(args[4]) == 0) { |
| 2498 | Alert("parsing [%s:%d] : '%s' expects 'cookie' <cookie_name> 'len' <len>.\n", |
| 2499 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2500 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2501 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2502 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2503 | free(curproxy->capture_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2504 | curproxy->capture_name = strdup(args[2]); |
| 2505 | curproxy->capture_namelen = strlen(curproxy->capture_name); |
| 2506 | curproxy->capture_len = atol(args[4]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2507 | curproxy->to_log |= LW_COOKIE; |
| 2508 | } |
| 2509 | else if (!strcmp(args[1], "request") && !strcmp(args[2], "header")) { |
| 2510 | struct cap_hdr *hdr; |
| 2511 | |
| 2512 | if (curproxy == &defproxy) { |
| 2513 | 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] | 2514 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2515 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2516 | } |
| 2517 | |
| 2518 | if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) { |
| 2519 | Alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n", |
| 2520 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2521 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2522 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2523 | } |
| 2524 | |
| 2525 | hdr = calloc(sizeof(struct cap_hdr), 1); |
| 2526 | hdr->next = curproxy->req_cap; |
| 2527 | hdr->name = strdup(args[3]); |
| 2528 | hdr->namelen = strlen(args[3]); |
| 2529 | hdr->len = atol(args[5]); |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 2530 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2531 | hdr->index = curproxy->nb_req_cap++; |
| 2532 | curproxy->req_cap = hdr; |
| 2533 | curproxy->to_log |= LW_REQHDR; |
| 2534 | } |
| 2535 | else if (!strcmp(args[1], "response") && !strcmp(args[2], "header")) { |
| 2536 | struct cap_hdr *hdr; |
| 2537 | |
| 2538 | if (curproxy == &defproxy) { |
| 2539 | 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] | 2540 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2541 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2542 | } |
| 2543 | |
| 2544 | if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) { |
| 2545 | Alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n", |
| 2546 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2547 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2548 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2549 | } |
| 2550 | hdr = calloc(sizeof(struct cap_hdr), 1); |
| 2551 | hdr->next = curproxy->rsp_cap; |
| 2552 | hdr->name = strdup(args[3]); |
| 2553 | hdr->namelen = strlen(args[3]); |
| 2554 | hdr->len = atol(args[5]); |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 2555 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2556 | hdr->index = curproxy->nb_rsp_cap++; |
| 2557 | curproxy->rsp_cap = hdr; |
| 2558 | curproxy->to_log |= LW_RSPHDR; |
| 2559 | } |
| 2560 | else { |
| 2561 | Alert("parsing [%s:%d] : '%s' expects 'cookie' or 'request header' or 'response header'.\n", |
| 2562 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2563 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2564 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2565 | } |
| 2566 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2567 | else if (!strcmp(args[0], "retries")) { /* connection retries */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2568 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2569 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2570 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2571 | if (*(args[1]) == 0) { |
| 2572 | Alert("parsing [%s:%d] : '%s' expects an integer argument (dispatch counts for one).\n", |
| 2573 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2574 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2575 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2576 | } |
| 2577 | curproxy->conn_retries = atol(args[1]); |
| 2578 | } |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2579 | 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] | 2580 | struct http_req_rule *rule; |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2581 | |
| 2582 | if (curproxy == &defproxy) { |
| 2583 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2584 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2585 | goto out; |
| 2586 | } |
| 2587 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 2588 | 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] | 2589 | Warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n", |
| 2590 | file, linenum, args[0]); |
| 2591 | err_code |= ERR_WARN; |
| 2592 | } |
| 2593 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 2594 | 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] | 2595 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 2596 | if (!rule) { |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2597 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2598 | goto out; |
| 2599 | } |
| 2600 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 2601 | err_code |= warnif_cond_requires_resp(rule->cond, file, linenum); |
| 2602 | LIST_ADDQ(&curproxy->http_req_rules, &rule->list); |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2603 | } |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 2604 | else if (!strcmp(args[0], "http-send-name-header")) { /* send server name in request header */ |
| 2605 | /* set the header name and length into the proxy structure */ |
| 2606 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 2607 | err_code |= ERR_WARN; |
| 2608 | |
| 2609 | if (!*args[1]) { |
| 2610 | Alert("parsing [%s:%d] : '%s' requires a header string.\n", |
| 2611 | file, linenum, args[0]); |
| 2612 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2613 | goto out; |
| 2614 | } |
| 2615 | |
| 2616 | /* set the desired header name */ |
| 2617 | free(curproxy->server_id_hdr_name); |
| 2618 | curproxy->server_id_hdr_name = strdup(args[1]); |
| 2619 | curproxy->server_id_hdr_len = strlen(curproxy->server_id_hdr_name); |
| 2620 | } |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2621 | else if (!strcmp(args[0], "block")) { /* early blocking based on ACLs */ |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2622 | if (curproxy == &defproxy) { |
| 2623 | 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] | 2624 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2625 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2626 | } |
| 2627 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2628 | if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) { |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2629 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 2630 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2631 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2632 | goto out; |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2633 | } |
| 2634 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 2635 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 1, &errmsg)) == NULL) { |
| 2636 | Alert("parsing [%s:%d] : error detected while parsing blocking condition : %s.\n", |
| 2637 | file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2638 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2639 | goto out; |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2640 | } |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2641 | |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2642 | LIST_ADDQ(&curproxy->block_cond, &cond->list); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 2643 | warnif_misplaced_block(curproxy, file, linenum, args[0]); |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2644 | } |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2645 | else if (!strcmp(args[0], "redirect")) { |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2646 | struct redirect_rule *rule; |
| 2647 | int cur_arg; |
| 2648 | int type = REDIRECT_TYPE_NONE; |
| 2649 | int code = 302; |
| 2650 | char *destination = NULL; |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2651 | char *cookie = NULL; |
| 2652 | int cookie_set = 0; |
Willy Tarreau | 79da469 | 2008-11-19 20:03:04 +0100 | [diff] [blame] | 2653 | unsigned int flags = REDIRECT_FLAG_NONE; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2654 | |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 2655 | if (curproxy == &defproxy) { |
| 2656 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2657 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2658 | goto out; |
| 2659 | } |
| 2660 | |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2661 | cur_arg = 1; |
| 2662 | while (*(args[cur_arg])) { |
| 2663 | if (!strcmp(args[cur_arg], "location")) { |
| 2664 | if (!*args[cur_arg + 1]) { |
| 2665 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 2666 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2667 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2668 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2669 | } |
| 2670 | |
| 2671 | type = REDIRECT_TYPE_LOCATION; |
| 2672 | cur_arg++; |
| 2673 | destination = args[cur_arg]; |
| 2674 | } |
| 2675 | else if (!strcmp(args[cur_arg], "prefix")) { |
| 2676 | if (!*args[cur_arg + 1]) { |
| 2677 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 2678 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2679 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2680 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2681 | } |
| 2682 | |
| 2683 | type = REDIRECT_TYPE_PREFIX; |
| 2684 | cur_arg++; |
| 2685 | destination = args[cur_arg]; |
| 2686 | } |
Willy Tarreau | 2e1dca8 | 2012-09-12 08:43:15 +0200 | [diff] [blame] | 2687 | else if (!strcmp(args[cur_arg], "scheme")) { |
| 2688 | if (!*args[cur_arg + 1]) { |
| 2689 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 2690 | file, linenum, args[0], args[cur_arg]); |
| 2691 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2692 | goto out; |
| 2693 | } |
| 2694 | |
| 2695 | type = REDIRECT_TYPE_SCHEME; |
| 2696 | cur_arg++; |
| 2697 | destination = args[cur_arg]; |
| 2698 | } |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2699 | else if (!strcmp(args[cur_arg], "set-cookie")) { |
| 2700 | if (!*args[cur_arg + 1]) { |
| 2701 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 2702 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2703 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2704 | goto out; |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2705 | } |
| 2706 | |
| 2707 | cur_arg++; |
| 2708 | cookie = args[cur_arg]; |
| 2709 | cookie_set = 1; |
| 2710 | } |
| 2711 | else if (!strcmp(args[cur_arg], "clear-cookie")) { |
| 2712 | if (!*args[cur_arg + 1]) { |
| 2713 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 2714 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2715 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2716 | goto out; |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2717 | } |
| 2718 | |
| 2719 | cur_arg++; |
| 2720 | cookie = args[cur_arg]; |
| 2721 | cookie_set = 0; |
| 2722 | } |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2723 | else if (!strcmp(args[cur_arg],"code")) { |
| 2724 | if (!*args[cur_arg + 1]) { |
| 2725 | Alert("parsing [%s:%d] : '%s': missing HTTP code.\n", |
| 2726 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2727 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2728 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2729 | } |
| 2730 | cur_arg++; |
| 2731 | code = atol(args[cur_arg]); |
| 2732 | if (code < 301 || code > 303) { |
| 2733 | Alert("parsing [%s:%d] : '%s': unsupported HTTP code '%d'.\n", |
| 2734 | file, linenum, args[0], code); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2735 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2736 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2737 | } |
| 2738 | } |
Willy Tarreau | 79da469 | 2008-11-19 20:03:04 +0100 | [diff] [blame] | 2739 | else if (!strcmp(args[cur_arg],"drop-query")) { |
| 2740 | flags |= REDIRECT_FLAG_DROP_QS; |
| 2741 | } |
Willy Tarreau | 81e3b4f | 2010-01-10 00:42:19 +0100 | [diff] [blame] | 2742 | else if (!strcmp(args[cur_arg],"append-slash")) { |
| 2743 | flags |= REDIRECT_FLAG_APPEND_SLASH; |
| 2744 | } |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2745 | else if (strcmp(args[cur_arg], "if") == 0 || |
| 2746 | strcmp(args[cur_arg], "unless") == 0) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 2747 | 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] | 2748 | if (!cond) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 2749 | Alert("parsing [%s:%d] : '%s': error detected while parsing redirect condition : %s.\n", |
| 2750 | file, linenum, args[0], errmsg); |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2751 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2752 | goto out; |
| 2753 | } |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2754 | break; |
| 2755 | } |
| 2756 | else { |
Willy Tarreau | 2e1dca8 | 2012-09-12 08:43:15 +0200 | [diff] [blame] | 2757 | 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] | 2758 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2759 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2760 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2761 | } |
| 2762 | cur_arg++; |
| 2763 | } |
| 2764 | |
| 2765 | if (type == REDIRECT_TYPE_NONE) { |
| 2766 | Alert("parsing [%s:%d] : '%s' expects a redirection type ('prefix' or 'location').\n", |
| 2767 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2768 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2769 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2770 | } |
| 2771 | |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2772 | rule = (struct redirect_rule *)calloc(1, sizeof(*rule)); |
| 2773 | rule->cond = cond; |
| 2774 | rule->rdr_str = strdup(destination); |
| 2775 | rule->rdr_len = strlen(destination); |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2776 | if (cookie) { |
| 2777 | /* 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] | 2778 | * a clear consists in appending "; path=/; Max-Age=0;" at the end. |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2779 | */ |
| 2780 | rule->cookie_len = strlen(cookie); |
William Turner | d986526 | 2010-03-01 13:30:34 -0500 | [diff] [blame] | 2781 | if (cookie_set) { |
| 2782 | rule->cookie_str = malloc(rule->cookie_len + 10); |
| 2783 | memcpy(rule->cookie_str, cookie, rule->cookie_len); |
| 2784 | memcpy(rule->cookie_str + rule->cookie_len, "; path=/;", 10); |
| 2785 | rule->cookie_len += 9; |
| 2786 | } else { |
| 2787 | rule->cookie_str = malloc(rule->cookie_len + 21); |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2788 | memcpy(rule->cookie_str, cookie, rule->cookie_len); |
William Turner | d986526 | 2010-03-01 13:30:34 -0500 | [diff] [blame] | 2789 | memcpy(rule->cookie_str + rule->cookie_len, "; path=/; Max-Age=0;", 21); |
| 2790 | rule->cookie_len += 20; |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2791 | } |
| 2792 | } |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2793 | rule->type = type; |
| 2794 | rule->code = code; |
Willy Tarreau | 79da469 | 2008-11-19 20:03:04 +0100 | [diff] [blame] | 2795 | rule->flags = flags; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2796 | LIST_INIT(&rule->list); |
| 2797 | LIST_ADDQ(&curproxy->redirect_rules, &rule->list); |
Willy Tarreau | 9d9ed01 | 2011-02-23 15:24:42 +0100 | [diff] [blame] | 2798 | err_code |= warnif_rule_after_use_backend(curproxy, file, linenum, args[0]); |
| 2799 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2800 | } |
Krzysztof Piotr Oledzki | 7b723ef | 2009-01-27 21:09:41 +0100 | [diff] [blame] | 2801 | else if (!strcmp(args[0], "use_backend")) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2802 | struct switching_rule *rule; |
| 2803 | |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2804 | if (curproxy == &defproxy) { |
| 2805 | 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] | 2806 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2807 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2808 | } |
| 2809 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2810 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2811 | err_code |= ERR_WARN; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2812 | |
| 2813 | if (*(args[1]) == 0) { |
| 2814 | 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] | 2815 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2816 | goto out; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2817 | } |
| 2818 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2819 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2820 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 2821 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2822 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2823 | goto out; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2824 | } |
| 2825 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 2826 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 2827 | Alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n", |
| 2828 | file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2829 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2830 | goto out; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2831 | } |
| 2832 | |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 2833 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
Willy Tarreau | a980263 | 2008-07-25 19:13:19 +0200 | [diff] [blame] | 2834 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2835 | rule = (struct switching_rule *)calloc(1, sizeof(*rule)); |
| 2836 | rule->cond = cond; |
| 2837 | rule->be.name = strdup(args[1]); |
| 2838 | LIST_INIT(&rule->list); |
| 2839 | LIST_ADDQ(&curproxy->switching_rules, &rule->list); |
| 2840 | } |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 2841 | else if (strcmp(args[0], "use-server") == 0) { |
| 2842 | struct server_rule *rule; |
| 2843 | |
| 2844 | if (curproxy == &defproxy) { |
| 2845 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2846 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2847 | goto out; |
| 2848 | } |
| 2849 | |
| 2850 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 2851 | err_code |= ERR_WARN; |
| 2852 | |
| 2853 | if (*(args[1]) == 0) { |
| 2854 | Alert("parsing [%s:%d] : '%s' expects a server name.\n", file, linenum, args[0]); |
| 2855 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2856 | goto out; |
| 2857 | } |
| 2858 | |
| 2859 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
| 2860 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 2861 | file, linenum, args[0]); |
| 2862 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2863 | goto out; |
| 2864 | } |
| 2865 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 2866 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 2867 | Alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n", |
| 2868 | file, linenum, errmsg); |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 2869 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2870 | goto out; |
| 2871 | } |
| 2872 | |
| 2873 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
| 2874 | |
| 2875 | rule = (struct server_rule *)calloc(1, sizeof(*rule)); |
| 2876 | rule->cond = cond; |
| 2877 | rule->srv.name = strdup(args[1]); |
| 2878 | LIST_INIT(&rule->list); |
| 2879 | LIST_ADDQ(&curproxy->server_rules, &rule->list); |
| 2880 | curproxy->be_req_ana |= AN_REQ_SRV_RULES; |
| 2881 | } |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 2882 | else if ((!strcmp(args[0], "force-persist")) || |
| 2883 | (!strcmp(args[0], "ignore-persist"))) { |
| 2884 | struct persist_rule *rule; |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2885 | |
| 2886 | if (curproxy == &defproxy) { |
| 2887 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2888 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2889 | goto out; |
| 2890 | } |
| 2891 | |
| 2892 | if (warnifnotcap(curproxy, PR_CAP_FE|PR_CAP_BE, file, linenum, args[0], NULL)) |
| 2893 | err_code |= ERR_WARN; |
| 2894 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2895 | if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) { |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2896 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 2897 | file, linenum, args[0]); |
| 2898 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2899 | goto out; |
| 2900 | } |
| 2901 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 2902 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 1, &errmsg)) == NULL) { |
| 2903 | Alert("parsing [%s:%d] : error detected while parsing a '%s' rule : %s.\n", |
| 2904 | file, linenum, args[0], errmsg); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2905 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2906 | goto out; |
| 2907 | } |
| 2908 | |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 2909 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2910 | |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 2911 | rule = (struct persist_rule *)calloc(1, sizeof(*rule)); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2912 | rule->cond = cond; |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 2913 | if (!strcmp(args[0], "force-persist")) { |
| 2914 | rule->type = PERSIST_TYPE_FORCE; |
| 2915 | } else { |
| 2916 | rule->type = PERSIST_TYPE_IGNORE; |
| 2917 | } |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2918 | LIST_INIT(&rule->list); |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 2919 | LIST_ADDQ(&curproxy->persist_rules, &rule->list); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2920 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2921 | else if (!strcmp(args[0], "stick-table")) { |
| 2922 | int myidx = 1; |
| 2923 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2924 | curproxy->table.id = curproxy->id; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2925 | curproxy->table.type = (unsigned int)-1; |
| 2926 | while (*args[myidx]) { |
| 2927 | const char *err; |
| 2928 | |
| 2929 | if (strcmp(args[myidx], "size") == 0) { |
| 2930 | myidx++; |
| 2931 | if (!*(args[myidx])) { |
| 2932 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 2933 | file, linenum, args[myidx-1]); |
| 2934 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2935 | goto out; |
| 2936 | } |
| 2937 | if ((err = parse_size_err(args[myidx], &curproxy->table.size))) { |
| 2938 | Alert("parsing [%s:%d] : stick-table: unexpected character '%c' in argument of '%s'.\n", |
| 2939 | file, linenum, *err, args[myidx-1]); |
| 2940 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2941 | goto out; |
| 2942 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 2943 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2944 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2945 | else if (strcmp(args[myidx], "peers") == 0) { |
| 2946 | myidx++; |
| 2947 | if (!*(args[myidx])) { |
| 2948 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 2949 | file, linenum, args[myidx-1]); |
| 2950 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2951 | goto out; |
| 2952 | } |
| 2953 | curproxy->table.peers.name = strdup(args[myidx++]); |
| 2954 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2955 | else if (strcmp(args[myidx], "expire") == 0) { |
| 2956 | myidx++; |
| 2957 | if (!*(args[myidx])) { |
| 2958 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 2959 | file, linenum, args[myidx-1]); |
| 2960 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2961 | goto out; |
| 2962 | } |
| 2963 | err = parse_time_err(args[myidx], &val, TIME_UNIT_MS); |
| 2964 | if (err) { |
| 2965 | Alert("parsing [%s:%d] : stick-table: unexpected character '%c' in argument of '%s'.\n", |
| 2966 | file, linenum, *err, args[myidx-1]); |
| 2967 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2968 | goto out; |
| 2969 | } |
| 2970 | curproxy->table.expire = val; |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 2971 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2972 | } |
| 2973 | else if (strcmp(args[myidx], "nopurge") == 0) { |
| 2974 | curproxy->table.nopurge = 1; |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 2975 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2976 | } |
| 2977 | else if (strcmp(args[myidx], "type") == 0) { |
| 2978 | myidx++; |
| 2979 | if (stktable_parse_type(args, &myidx, &curproxy->table.type, &curproxy->table.key_size) != 0) { |
| 2980 | Alert("parsing [%s:%d] : stick-table: unknown type '%s'.\n", |
| 2981 | file, linenum, args[myidx]); |
| 2982 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2983 | goto out; |
| 2984 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 2985 | /* myidx already points to next arg */ |
| 2986 | } |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 2987 | else if (strcmp(args[myidx], "store") == 0) { |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 2988 | int type, err; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 2989 | char *cw, *nw, *sa; |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 2990 | |
| 2991 | myidx++; |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 2992 | nw = args[myidx]; |
| 2993 | while (*nw) { |
| 2994 | /* the "store" keyword supports a comma-separated list */ |
| 2995 | cw = nw; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 2996 | sa = NULL; /* store arg */ |
| 2997 | while (*nw && *nw != ',') { |
| 2998 | if (*nw == '(') { |
| 2999 | *nw = 0; |
| 3000 | sa = ++nw; |
| 3001 | while (*nw != ')') { |
| 3002 | if (!*nw) { |
| 3003 | Alert("parsing [%s:%d] : %s: missing closing parenthesis after store option '%s'.\n", |
| 3004 | file, linenum, args[0], cw); |
| 3005 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3006 | goto out; |
| 3007 | } |
| 3008 | nw++; |
| 3009 | } |
| 3010 | *nw = '\0'; |
| 3011 | } |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 3012 | nw++; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 3013 | } |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 3014 | if (*nw) |
| 3015 | *nw++ = '\0'; |
| 3016 | type = stktable_get_data_type(cw); |
| 3017 | if (type < 0) { |
| 3018 | Alert("parsing [%s:%d] : %s: unknown store option '%s'.\n", |
| 3019 | file, linenum, args[0], cw); |
| 3020 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3021 | goto out; |
| 3022 | } |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 3023 | |
| 3024 | err = stktable_alloc_data_type(&curproxy->table, type, sa); |
| 3025 | switch (err) { |
| 3026 | case PE_NONE: break; |
| 3027 | case PE_EXIST: |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 3028 | Warning("parsing [%s:%d]: %s: store option '%s' already enabled, ignored.\n", |
| 3029 | file, linenum, args[0], cw); |
| 3030 | err_code |= ERR_WARN; |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 3031 | break; |
| 3032 | |
| 3033 | case PE_ARG_MISSING: |
| 3034 | Alert("parsing [%s:%d] : %s: missing argument to store option '%s'.\n", |
| 3035 | file, linenum, args[0], cw); |
| 3036 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3037 | goto out; |
| 3038 | |
| 3039 | case PE_ARG_NOT_USED: |
| 3040 | Alert("parsing [%s:%d] : %s: unexpected argument to store option '%s'.\n", |
| 3041 | file, linenum, args[0], cw); |
| 3042 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3043 | goto out; |
| 3044 | |
| 3045 | default: |
| 3046 | Alert("parsing [%s:%d] : %s: error when processing store option '%s'.\n", |
| 3047 | file, linenum, args[0], cw); |
| 3048 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3049 | goto out; |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 3050 | } |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 3051 | } |
| 3052 | myidx++; |
| 3053 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 3054 | else { |
| 3055 | Alert("parsing [%s:%d] : stick-table: unknown argument '%s'.\n", |
| 3056 | file, linenum, args[myidx]); |
| 3057 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3058 | goto out; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3059 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3060 | } |
| 3061 | |
| 3062 | if (!curproxy->table.size) { |
| 3063 | Alert("parsing [%s:%d] : stick-table: missing size.\n", |
| 3064 | file, linenum); |
| 3065 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3066 | goto out; |
| 3067 | } |
| 3068 | |
| 3069 | if (curproxy->table.type == (unsigned int)-1) { |
| 3070 | Alert("parsing [%s:%d] : stick-table: missing type.\n", |
| 3071 | file, linenum); |
| 3072 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3073 | goto out; |
| 3074 | } |
| 3075 | } |
| 3076 | else if (!strcmp(args[0], "stick")) { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3077 | struct sticking_rule *rule; |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 3078 | struct sample_expr *expr; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3079 | int myidx = 0; |
| 3080 | const char *name = NULL; |
| 3081 | int flags; |
| 3082 | |
| 3083 | if (curproxy == &defproxy) { |
| 3084 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3085 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3086 | goto out; |
| 3087 | } |
| 3088 | |
| 3089 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) { |
| 3090 | err_code |= ERR_WARN; |
| 3091 | goto out; |
| 3092 | } |
| 3093 | |
| 3094 | myidx++; |
| 3095 | if ((strcmp(args[myidx], "store") == 0) || |
| 3096 | (strcmp(args[myidx], "store-request") == 0)) { |
| 3097 | myidx++; |
| 3098 | flags = STK_IS_STORE; |
| 3099 | } |
| 3100 | else if (strcmp(args[myidx], "store-response") == 0) { |
| 3101 | myidx++; |
| 3102 | flags = STK_IS_STORE | STK_ON_RSP; |
| 3103 | } |
| 3104 | else if (strcmp(args[myidx], "match") == 0) { |
| 3105 | myidx++; |
| 3106 | flags = STK_IS_MATCH; |
| 3107 | } |
| 3108 | else if (strcmp(args[myidx], "on") == 0) { |
| 3109 | myidx++; |
| 3110 | flags = STK_IS_MATCH | STK_IS_STORE; |
| 3111 | } |
| 3112 | else { |
| 3113 | Alert("parsing [%s:%d] : '%s' expects 'on', 'match', or 'store'.\n", file, linenum, args[0]); |
| 3114 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3115 | goto out; |
| 3116 | } |
| 3117 | |
| 3118 | if (*(args[myidx]) == 0) { |
| 3119 | Alert("parsing [%s:%d] : '%s' expects a fetch method.\n", file, linenum, args[0]); |
| 3120 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3121 | goto out; |
| 3122 | } |
| 3123 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3124 | expr = sample_parse_expr(args, &myidx, trash.str, trash.size); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3125 | if (!expr) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3126 | 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] | 3127 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3128 | goto out; |
| 3129 | } |
| 3130 | |
| 3131 | if (flags & STK_ON_RSP) { |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 3132 | if (!(expr->fetch->cap & SMP_CAP_RES)) { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3133 | Alert("parsing [%s:%d] : '%s': fetch method '%s' can not be used on response.\n", |
| 3134 | file, linenum, args[0], expr->fetch->kw); |
| 3135 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 3136 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3137 | goto out; |
| 3138 | } |
| 3139 | } else { |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 3140 | if (!(expr->fetch->cap & SMP_CAP_REQ)) { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3141 | Alert("parsing [%s:%d] : '%s': fetch method '%s' can not be used on request.\n", |
| 3142 | file, linenum, args[0], expr->fetch->kw); |
| 3143 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 3144 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3145 | goto out; |
| 3146 | } |
| 3147 | } |
| 3148 | |
Willy Tarreau | 1b6c00c | 2012-10-05 22:41:26 +0200 | [diff] [blame] | 3149 | /* check if we need to allocate an hdr_idx struct for HTTP parsing */ |
| 3150 | if (expr->fetch->cap & SMP_CAP_L7) |
| 3151 | curproxy->acl_requires |= ACL_USE_L7_ANY; |
| 3152 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3153 | if (strcmp(args[myidx], "table") == 0) { |
| 3154 | myidx++; |
| 3155 | name = args[myidx++]; |
| 3156 | } |
| 3157 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 3158 | if (strcmp(args[myidx], "if") == 0 || strcmp(args[myidx], "unless") == 0) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 3159 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + myidx, &errmsg)) == NULL) { |
| 3160 | Alert("parsing [%s:%d] : '%s': error detected while parsing sticking condition : %s.\n", |
| 3161 | file, linenum, args[0], errmsg); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3162 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 3163 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3164 | goto out; |
| 3165 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3166 | } |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 3167 | else if (*(args[myidx])) { |
| 3168 | Alert("parsing [%s:%d] : '%s': unknown keyword '%s'.\n", |
| 3169 | file, linenum, args[0], args[myidx]); |
| 3170 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 3171 | free(expr); |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 3172 | goto out; |
| 3173 | } |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 3174 | if (flags & STK_ON_RSP) |
| 3175 | err_code |= warnif_cond_requires_req(cond, file, linenum); |
| 3176 | else |
| 3177 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 3178 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3179 | rule = (struct sticking_rule *)calloc(1, sizeof(*rule)); |
| 3180 | rule->cond = cond; |
| 3181 | rule->expr = expr; |
| 3182 | rule->flags = flags; |
| 3183 | rule->table.name = name ? strdup(name) : NULL; |
| 3184 | LIST_INIT(&rule->list); |
| 3185 | if (flags & STK_ON_RSP) |
| 3186 | LIST_ADDQ(&curproxy->storersp_rules, &rule->list); |
| 3187 | else |
| 3188 | LIST_ADDQ(&curproxy->sticking_rules, &rule->list); |
| 3189 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3190 | else if (!strcmp(args[0], "stats")) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3191 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3192 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3193 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3194 | if (curproxy != &defproxy && curproxy->uri_auth == defproxy.uri_auth) |
| 3195 | curproxy->uri_auth = NULL; /* we must detach from the default config */ |
| 3196 | |
Krzysztof Piotr Oledzki | 260a3bb | 2010-01-06 16:25:05 +0100 | [diff] [blame] | 3197 | if (!*args[1]) { |
| 3198 | goto stats_error_parsing; |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3199 | } else if (!strcmp(args[1], "admin")) { |
| 3200 | struct stats_admin_rule *rule; |
| 3201 | |
| 3202 | if (curproxy == &defproxy) { |
| 3203 | Alert("parsing [%s:%d]: '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
| 3204 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3205 | goto out; |
| 3206 | } |
| 3207 | |
| 3208 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 3209 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3210 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3211 | goto out; |
| 3212 | } |
| 3213 | |
| 3214 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
| 3215 | Alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n", |
| 3216 | file, linenum, args[0], args[1]); |
| 3217 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3218 | goto out; |
| 3219 | } |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 3220 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 3221 | Alert("parsing [%s:%d] : error detected while parsing a '%s %s' rule : %s.\n", |
| 3222 | file, linenum, args[0], args[1], errmsg); |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3223 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3224 | goto out; |
| 3225 | } |
| 3226 | |
| 3227 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
| 3228 | |
| 3229 | rule = (struct stats_admin_rule *)calloc(1, sizeof(*rule)); |
| 3230 | rule->cond = cond; |
| 3231 | LIST_INIT(&rule->list); |
| 3232 | LIST_ADDQ(&curproxy->uri_auth->admin_rules, &rule->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3233 | } else if (!strcmp(args[1], "uri")) { |
| 3234 | if (*(args[2]) == 0) { |
| 3235 | Alert("parsing [%s:%d] : 'uri' needs an URI prefix.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3236 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3237 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3238 | } else if (!stats_set_uri(&curproxy->uri_auth, args[2])) { |
| 3239 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3240 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3241 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3242 | } |
| 3243 | } else if (!strcmp(args[1], "realm")) { |
| 3244 | if (*(args[2]) == 0) { |
| 3245 | Alert("parsing [%s:%d] : 'realm' needs an realm name.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3246 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3247 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3248 | } else if (!stats_set_realm(&curproxy->uri_auth, args[2])) { |
| 3249 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3250 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3251 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3252 | } |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 3253 | } else if (!strcmp(args[1], "refresh")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 3254 | unsigned interval; |
| 3255 | |
| 3256 | err = parse_time_err(args[2], &interval, TIME_UNIT_S); |
| 3257 | if (err) { |
| 3258 | Alert("parsing [%s:%d] : unexpected character '%c' in stats refresh interval.\n", |
| 3259 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3260 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3261 | goto out; |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 3262 | } else if (!stats_set_refresh(&curproxy->uri_auth, interval)) { |
| 3263 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3264 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3265 | goto out; |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 3266 | } |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3267 | } 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] | 3268 | struct http_req_rule *rule; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3269 | |
| 3270 | if (curproxy == &defproxy) { |
| 3271 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3272 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3273 | goto out; |
| 3274 | } |
| 3275 | |
| 3276 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 3277 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3278 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3279 | goto out; |
| 3280 | } |
| 3281 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3282 | if (!LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) && |
| 3283 | !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] | 3284 | Warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n", |
| 3285 | file, linenum, args[0]); |
| 3286 | err_code |= ERR_WARN; |
| 3287 | } |
| 3288 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3289 | 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] | 3290 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3291 | if (!rule) { |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3292 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3293 | goto out; |
| 3294 | } |
| 3295 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3296 | err_code |= warnif_cond_requires_resp(rule->cond, file, linenum); |
| 3297 | LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list); |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3298 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3299 | } else if (!strcmp(args[1], "auth")) { |
| 3300 | if (*(args[2]) == 0) { |
| 3301 | 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] | 3302 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3303 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3304 | } else if (!stats_add_auth(&curproxy->uri_auth, args[2])) { |
| 3305 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3306 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3307 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3308 | } |
| 3309 | } else if (!strcmp(args[1], "scope")) { |
| 3310 | if (*(args[2]) == 0) { |
| 3311 | Alert("parsing [%s:%d] : 'scope' needs a proxy name.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3312 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3313 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3314 | } else if (!stats_add_scope(&curproxy->uri_auth, args[2])) { |
| 3315 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3316 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3317 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3318 | } |
| 3319 | } else if (!strcmp(args[1], "enable")) { |
| 3320 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 3321 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3322 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3323 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3324 | } |
Krzysztof Oledzki | d9db927 | 2007-10-15 10:05:11 +0200 | [diff] [blame] | 3325 | } else if (!strcmp(args[1], "hide-version")) { |
| 3326 | if (!stats_set_flag(&curproxy->uri_auth, ST_HIDEVER)) { |
| 3327 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3328 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3329 | goto out; |
Krzysztof Oledzki | d9db927 | 2007-10-15 10:05:11 +0200 | [diff] [blame] | 3330 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3331 | } else if (!strcmp(args[1], "show-legends")) { |
| 3332 | if (!stats_set_flag(&curproxy->uri_auth, ST_SHLGNDS)) { |
| 3333 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3334 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3335 | goto out; |
| 3336 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3337 | } else if (!strcmp(args[1], "show-node")) { |
| 3338 | |
| 3339 | if (*args[2]) { |
| 3340 | int i; |
| 3341 | char c; |
| 3342 | |
| 3343 | for (i=0; args[2][i]; i++) { |
| 3344 | c = args[2][i]; |
Willy Tarreau | 88e0581 | 2010-03-03 00:16:00 +0100 | [diff] [blame] | 3345 | if (!isupper((unsigned char)c) && !islower((unsigned char)c) && |
| 3346 | !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.') |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3347 | break; |
| 3348 | } |
| 3349 | |
| 3350 | if (!i || args[2][i]) { |
| 3351 | Alert("parsing [%s:%d]: '%s %s' invalid node name - should be a string" |
| 3352 | "with digits(0-9), letters(A-Z, a-z), hyphen(-) or underscode(_).\n", |
| 3353 | file, linenum, args[0], args[1]); |
| 3354 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3355 | goto out; |
| 3356 | } |
| 3357 | } |
| 3358 | |
| 3359 | if (!stats_set_node(&curproxy->uri_auth, args[2])) { |
| 3360 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3361 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3362 | goto out; |
| 3363 | } |
| 3364 | } else if (!strcmp(args[1], "show-desc")) { |
| 3365 | char *desc = NULL; |
| 3366 | |
| 3367 | if (*args[2]) { |
| 3368 | int i, len=0; |
| 3369 | char *d; |
| 3370 | |
| 3371 | for(i=2; *args[i]; i++) |
| 3372 | len += strlen(args[i])+1; |
| 3373 | |
| 3374 | desc = d = (char *)calloc(1, len); |
| 3375 | |
| 3376 | d += sprintf(d, "%s", args[2]); |
| 3377 | for(i=3; *args[i]; i++) |
| 3378 | d += sprintf(d, " %s", args[i]); |
| 3379 | } |
| 3380 | |
| 3381 | if (!*args[2] && !global.desc) |
| 3382 | Warning("parsing [%s:%d]: '%s' requires a parameter or 'desc' to be set in the global section.\n", |
| 3383 | file, linenum, args[1]); |
| 3384 | else { |
| 3385 | if (!stats_set_desc(&curproxy->uri_auth, desc)) { |
| 3386 | free(desc); |
| 3387 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3388 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3389 | goto out; |
| 3390 | } |
| 3391 | free(desc); |
| 3392 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3393 | } else { |
Krzysztof Piotr Oledzki | 260a3bb | 2010-01-06 16:25:05 +0100 | [diff] [blame] | 3394 | stats_error_parsing: |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3395 | 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] | 3396 | 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] | 3397 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3398 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3399 | } |
| 3400 | } |
| 3401 | else if (!strcmp(args[0], "option")) { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3402 | int optnum; |
| 3403 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3404 | if (*(args[1]) == '\0') { |
| 3405 | Alert("parsing [%s:%d]: '%s' expects an option name.\n", |
| 3406 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3407 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3408 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3409 | } |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3410 | |
| 3411 | for (optnum = 0; cfg_opts[optnum].name; optnum++) { |
| 3412 | if (!strcmp(args[1], cfg_opts[optnum].name)) { |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 3413 | if (cfg_opts[optnum].cap == PR_CAP_NONE) { |
| 3414 | Alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n", |
| 3415 | file, linenum, cfg_opts[optnum].name); |
| 3416 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3417 | goto out; |
| 3418 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3419 | if (warnifnotcap(curproxy, cfg_opts[optnum].cap, file, linenum, args[1], NULL)) { |
| 3420 | err_code |= ERR_WARN; |
| 3421 | goto out; |
| 3422 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3423 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 3424 | curproxy->no_options &= ~cfg_opts[optnum].val; |
| 3425 | curproxy->options &= ~cfg_opts[optnum].val; |
| 3426 | |
| 3427 | switch (kwm) { |
| 3428 | case KWM_STD: |
| 3429 | curproxy->options |= cfg_opts[optnum].val; |
| 3430 | break; |
| 3431 | case KWM_NO: |
| 3432 | curproxy->no_options |= cfg_opts[optnum].val; |
| 3433 | break; |
| 3434 | case KWM_DEF: /* already cleared */ |
| 3435 | break; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 3436 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3437 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3438 | goto out; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3439 | } |
| 3440 | } |
| 3441 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 3442 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) { |
| 3443 | if (!strcmp(args[1], cfg_opts2[optnum].name)) { |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 3444 | if (cfg_opts2[optnum].cap == PR_CAP_NONE) { |
| 3445 | Alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n", |
| 3446 | file, linenum, cfg_opts2[optnum].name); |
| 3447 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3448 | goto out; |
| 3449 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3450 | if (warnifnotcap(curproxy, cfg_opts2[optnum].cap, file, linenum, args[1], NULL)) { |
| 3451 | err_code |= ERR_WARN; |
| 3452 | goto out; |
| 3453 | } |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 3454 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 3455 | curproxy->no_options2 &= ~cfg_opts2[optnum].val; |
| 3456 | curproxy->options2 &= ~cfg_opts2[optnum].val; |
| 3457 | |
| 3458 | switch (kwm) { |
| 3459 | case KWM_STD: |
| 3460 | curproxy->options2 |= cfg_opts2[optnum].val; |
| 3461 | break; |
| 3462 | case KWM_NO: |
| 3463 | curproxy->no_options2 |= cfg_opts2[optnum].val; |
| 3464 | break; |
| 3465 | case KWM_DEF: /* already cleared */ |
| 3466 | break; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 3467 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3468 | goto out; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 3469 | } |
| 3470 | } |
| 3471 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 3472 | if (kwm != KWM_STD) { |
| 3473 | 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] | 3474 | file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3475 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3476 | goto out; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3477 | } |
| 3478 | |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3479 | if (!strcmp(args[1], "httplog")) { |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 3480 | char *logformat; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3481 | /* generate a complete HTTP log */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 3482 | logformat = default_http_log_format; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3483 | if (*(args[2]) != '\0') { |
| 3484 | if (!strcmp(args[2], "clf")) { |
| 3485 | curproxy->options2 |= PR_O2_CLFLOG; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 3486 | logformat = clf_http_log_format; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3487 | } else { |
| 3488 | 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] | 3489 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3490 | goto out; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3491 | } |
| 3492 | } |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 3493 | if (curproxy->logformat_string != default_http_log_format && |
| 3494 | curproxy->logformat_string != default_tcp_log_format && |
| 3495 | curproxy->logformat_string != clf_http_log_format) |
| 3496 | free(curproxy->logformat_string); |
| 3497 | curproxy->logformat_string = logformat; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3498 | } |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 3499 | else if (!strcmp(args[1], "tcplog")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3500 | /* generate a detailed TCP log */ |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 3501 | if (curproxy->logformat_string != default_http_log_format && |
| 3502 | curproxy->logformat_string != default_tcp_log_format && |
| 3503 | curproxy->logformat_string != clf_http_log_format) |
| 3504 | free(curproxy->logformat_string); |
| 3505 | curproxy->logformat_string = default_tcp_log_format; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 3506 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3507 | else if (!strcmp(args[1], "tcpka")) { |
| 3508 | /* enable TCP keep-alives on client and server sessions */ |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3509 | 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] | 3510 | err_code |= ERR_WARN; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3511 | |
| 3512 | if (curproxy->cap & PR_CAP_FE) |
| 3513 | curproxy->options |= PR_O_TCP_CLI_KA; |
| 3514 | if (curproxy->cap & PR_CAP_BE) |
| 3515 | curproxy->options |= PR_O_TCP_SRV_KA; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3516 | } |
| 3517 | else if (!strcmp(args[1], "httpchk")) { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3518 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3519 | err_code |= ERR_WARN; |
| 3520 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3521 | /* use HTTP request to check servers' health */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3522 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 3523 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3524 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 3525 | curproxy->options2 |= PR_O2_HTTP_CHK; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3526 | if (!*args[2]) { /* no argument */ |
| 3527 | curproxy->check_req = strdup(DEF_CHECK_REQ); /* default request */ |
| 3528 | curproxy->check_len = strlen(DEF_CHECK_REQ); |
| 3529 | } else if (!*args[3]) { /* one argument : URI */ |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3530 | 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] | 3531 | curproxy->check_req = (char *)malloc(reqlen); |
| 3532 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3533 | "OPTIONS %s HTTP/1.0\r\n", args[2]); /* URI to use */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3534 | } else { /* more arguments : METHOD URI [HTTP_VER] */ |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3535 | int reqlen = strlen(args[2]) + strlen(args[3]) + 3 + strlen("\r\n"); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3536 | if (*args[4]) |
| 3537 | reqlen += strlen(args[4]); |
| 3538 | else |
| 3539 | reqlen += strlen("HTTP/1.0"); |
| 3540 | |
| 3541 | curproxy->check_req = (char *)malloc(reqlen); |
| 3542 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3543 | "%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] | 3544 | } |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 3545 | } |
| 3546 | else if (!strcmp(args[1], "ssl-hello-chk")) { |
| 3547 | /* use SSLv3 CLIENT HELLO to check servers' health */ |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3548 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3549 | err_code |= ERR_WARN; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3550 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3551 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 3552 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3553 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Willy Tarreau | 07a5490 | 2010-03-29 18:33:29 +0200 | [diff] [blame] | 3554 | curproxy->options2 |= PR_O2_SSL3_CHK; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3555 | } |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 3556 | else if (!strcmp(args[1], "smtpchk")) { |
| 3557 | /* use SMTP request to check servers' health */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3558 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 3559 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3560 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 3561 | curproxy->options2 |= PR_O2_SMTP_CHK; |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 3562 | |
| 3563 | if (!*args[2] || !*args[3]) { /* no argument or incomplete EHLO host */ |
| 3564 | curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */ |
| 3565 | curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ); |
| 3566 | } else { /* ESMTP EHLO, or SMTP HELO, and a hostname */ |
| 3567 | if (!strcmp(args[2], "EHLO") || !strcmp(args[2], "HELO")) { |
| 3568 | int reqlen = strlen(args[2]) + strlen(args[3]) + strlen(" \r\n") + 1; |
| 3569 | curproxy->check_req = (char *)malloc(reqlen); |
| 3570 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
| 3571 | "%s %s\r\n", args[2], args[3]); /* HELO hostname */ |
| 3572 | } else { |
| 3573 | /* this just hits the default for now, but you could potentially expand it to allow for other stuff |
| 3574 | though, it's unlikely you'd want to send anything other than an EHLO or HELO */ |
| 3575 | curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */ |
| 3576 | curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ); |
| 3577 | } |
| 3578 | } |
| 3579 | } |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 3580 | else if (!strcmp(args[1], "pgsql-check")) { |
| 3581 | /* use PostgreSQL request to check servers' health */ |
| 3582 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 3583 | err_code |= ERR_WARN; |
| 3584 | |
| 3585 | free(curproxy->check_req); |
| 3586 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3587 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 3588 | curproxy->options2 |= PR_O2_PGSQL_CHK; |
| 3589 | |
| 3590 | if (*(args[2])) { |
| 3591 | int cur_arg = 2; |
| 3592 | |
| 3593 | while (*(args[cur_arg])) { |
| 3594 | if (strcmp(args[cur_arg], "user") == 0) { |
| 3595 | char * packet; |
| 3596 | uint32_t packet_len; |
| 3597 | uint32_t pv; |
| 3598 | |
| 3599 | /* suboption header - needs additional argument for it */ |
| 3600 | if (*(args[cur_arg+1]) == 0) { |
| 3601 | Alert("parsing [%s:%d] : '%s %s %s' expects <username> as argument.\n", |
| 3602 | file, linenum, args[0], args[1], args[cur_arg]); |
| 3603 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3604 | goto out; |
| 3605 | } |
| 3606 | |
| 3607 | /* uint32_t + uint32_t + strlen("user")+1 + strlen(username)+1 + 1 */ |
| 3608 | packet_len = 4 + 4 + 5 + strlen(args[cur_arg + 1])+1 +1; |
| 3609 | pv = htonl(0x30000); /* protocol version 3.0 */ |
| 3610 | |
| 3611 | packet = (char*) calloc(1, packet_len); |
| 3612 | |
| 3613 | memcpy(packet + 4, &pv, 4); |
| 3614 | |
| 3615 | /* copy "user" */ |
| 3616 | memcpy(packet + 8, "user", 4); |
| 3617 | |
| 3618 | /* copy username */ |
| 3619 | memcpy(packet + 13, args[cur_arg+1], strlen(args[cur_arg+1])); |
| 3620 | |
| 3621 | free(curproxy->check_req); |
| 3622 | curproxy->check_req = packet; |
| 3623 | curproxy->check_len = packet_len; |
| 3624 | |
| 3625 | packet_len = htonl(packet_len); |
| 3626 | memcpy(packet, &packet_len, 4); |
| 3627 | cur_arg += 2; |
| 3628 | } else { |
| 3629 | /* unknown suboption - catchall */ |
| 3630 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'user'.\n", |
| 3631 | file, linenum, args[0], args[1]); |
| 3632 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3633 | goto out; |
| 3634 | } |
| 3635 | } /* end while loop */ |
| 3636 | } |
| 3637 | } |
| 3638 | |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 3639 | else if (!strcmp(args[1], "redis-check")) { |
| 3640 | /* use REDIS PING request to check servers' health */ |
| 3641 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 3642 | err_code |= ERR_WARN; |
| 3643 | |
| 3644 | free(curproxy->check_req); |
| 3645 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3646 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 3647 | curproxy->options2 |= PR_O2_REDIS_CHK; |
| 3648 | |
| 3649 | curproxy->check_req = (char *) malloc(sizeof(DEF_REDIS_CHECK_REQ) - 1); |
| 3650 | memcpy(curproxy->check_req, DEF_REDIS_CHECK_REQ, sizeof(DEF_REDIS_CHECK_REQ) - 1); |
| 3651 | curproxy->check_len = sizeof(DEF_REDIS_CHECK_REQ) - 1; |
| 3652 | } |
| 3653 | |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 3654 | else if (!strcmp(args[1], "mysql-check")) { |
| 3655 | /* use MYSQL request to check servers' health */ |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 3656 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 3657 | err_code |= ERR_WARN; |
| 3658 | |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 3659 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 3660 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3661 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 3662 | curproxy->options2 |= PR_O2_MYSQL_CHK; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 3663 | |
| 3664 | /* This is an exemple of an MySQL >=4.0 client Authentication packet kindly provided by Cyril Bonte. |
| 3665 | * const char mysql40_client_auth_pkt[] = { |
| 3666 | * "\x0e\x00\x00" // packet length |
| 3667 | * "\x01" // packet number |
| 3668 | * "\x00\x00" // client capabilities |
| 3669 | * "\x00\x00\x01" // max packet |
| 3670 | * "haproxy\x00" // username (null terminated string) |
| 3671 | * "\x00" // filler (always 0x00) |
| 3672 | * "\x01\x00\x00" // packet length |
| 3673 | * "\x00" // packet number |
| 3674 | * "\x01" // COM_QUIT command |
| 3675 | * }; |
| 3676 | */ |
| 3677 | |
| 3678 | if (*(args[2])) { |
| 3679 | int cur_arg = 2; |
| 3680 | |
| 3681 | while (*(args[cur_arg])) { |
| 3682 | if (strcmp(args[cur_arg], "user") == 0) { |
| 3683 | char *mysqluser; |
| 3684 | int packetlen, reqlen, userlen; |
| 3685 | |
| 3686 | /* suboption header - needs additional argument for it */ |
| 3687 | if (*(args[cur_arg+1]) == 0) { |
| 3688 | Alert("parsing [%s:%d] : '%s %s %s' expects <username> as argument.\n", |
| 3689 | file, linenum, args[0], args[1], args[cur_arg]); |
| 3690 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3691 | goto out; |
| 3692 | } |
| 3693 | mysqluser = args[cur_arg + 1]; |
| 3694 | userlen = strlen(mysqluser); |
| 3695 | packetlen = userlen + 7; |
| 3696 | reqlen = packetlen + 9; |
| 3697 | |
| 3698 | free(curproxy->check_req); |
| 3699 | curproxy->check_req = (char *)calloc(1, reqlen); |
| 3700 | curproxy->check_len = reqlen; |
| 3701 | |
| 3702 | snprintf(curproxy->check_req, 4, "%c%c%c", |
| 3703 | ((unsigned char) packetlen & 0xff), |
| 3704 | ((unsigned char) (packetlen >> 8) & 0xff), |
| 3705 | ((unsigned char) (packetlen >> 16) & 0xff)); |
| 3706 | |
| 3707 | curproxy->check_req[3] = 1; |
Hervé COMMOWICK | 212f778 | 2011-06-10 14:05:59 +0200 | [diff] [blame] | 3708 | curproxy->check_req[5] = 128; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 3709 | curproxy->check_req[8] = 1; |
| 3710 | memcpy(&curproxy->check_req[9], mysqluser, userlen); |
| 3711 | curproxy->check_req[9 + userlen + 1 + 1] = 1; |
| 3712 | curproxy->check_req[9 + userlen + 1 + 1 + 4] = 1; |
| 3713 | cur_arg += 2; |
| 3714 | } else { |
| 3715 | /* unknown suboption - catchall */ |
| 3716 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'user'.\n", |
| 3717 | file, linenum, args[0], args[1]); |
| 3718 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3719 | goto out; |
| 3720 | } |
| 3721 | } /* end while loop */ |
| 3722 | } |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 3723 | } |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 3724 | else if (!strcmp(args[1], "ldap-check")) { |
| 3725 | /* use LDAP request to check servers' health */ |
| 3726 | free(curproxy->check_req); |
| 3727 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3728 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 3729 | curproxy->options2 |= PR_O2_LDAP_CHK; |
| 3730 | |
| 3731 | curproxy->check_req = (char *) malloc(sizeof(DEF_LDAP_CHECK_REQ) - 1); |
| 3732 | memcpy(curproxy->check_req, DEF_LDAP_CHECK_REQ, sizeof(DEF_LDAP_CHECK_REQ) - 1); |
| 3733 | curproxy->check_len = sizeof(DEF_LDAP_CHECK_REQ) - 1; |
| 3734 | } |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3735 | else if (!strcmp(args[1], "forwardfor")) { |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3736 | int cur_arg; |
| 3737 | |
| 3738 | /* insert x-forwarded-for field, but not for the IP address listed as an except. |
| 3739 | * set default options (ie: bitfield, header name, etc) |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3740 | */ |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3741 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 3742 | curproxy->options |= PR_O_FWDFOR | PR_O_FF_ALWAYS; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3743 | |
| 3744 | free(curproxy->fwdfor_hdr_name); |
| 3745 | curproxy->fwdfor_hdr_name = strdup(DEF_XFORWARDFOR_HDR); |
| 3746 | curproxy->fwdfor_hdr_len = strlen(DEF_XFORWARDFOR_HDR); |
| 3747 | |
| 3748 | /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */ |
| 3749 | cur_arg = 2; |
| 3750 | while (*(args[cur_arg])) { |
| 3751 | if (!strcmp(args[cur_arg], "except")) { |
| 3752 | /* suboption except - needs additional argument for it */ |
| 3753 | if (!*(args[cur_arg+1]) || !str2net(args[cur_arg+1], &curproxy->except_net, &curproxy->except_mask)) { |
| 3754 | Alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n", |
| 3755 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3756 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3757 | goto out; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3758 | } |
| 3759 | /* flush useless bits */ |
| 3760 | curproxy->except_net.s_addr &= curproxy->except_mask.s_addr; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3761 | cur_arg += 2; |
| 3762 | } else if (!strcmp(args[cur_arg], "header")) { |
| 3763 | /* suboption header - needs additional argument for it */ |
| 3764 | if (*(args[cur_arg+1]) == 0) { |
| 3765 | Alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 3766 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3767 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3768 | goto out; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3769 | } |
| 3770 | free(curproxy->fwdfor_hdr_name); |
| 3771 | curproxy->fwdfor_hdr_name = strdup(args[cur_arg+1]); |
| 3772 | curproxy->fwdfor_hdr_len = strlen(curproxy->fwdfor_hdr_name); |
| 3773 | cur_arg += 2; |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 3774 | } else if (!strcmp(args[cur_arg], "if-none")) { |
| 3775 | curproxy->options &= ~PR_O_FF_ALWAYS; |
| 3776 | cur_arg += 1; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3777 | } else { |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3778 | /* unknown suboption - catchall */ |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 3779 | 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] | 3780 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3781 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3782 | goto out; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3783 | } |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3784 | } /* end while loop */ |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3785 | } |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 3786 | else if (!strcmp(args[1], "originalto")) { |
| 3787 | int cur_arg; |
| 3788 | |
| 3789 | /* insert x-original-to field, but not for the IP address listed as an except. |
| 3790 | * set default options (ie: bitfield, header name, etc) |
| 3791 | */ |
| 3792 | |
| 3793 | curproxy->options |= PR_O_ORGTO; |
| 3794 | |
| 3795 | free(curproxy->orgto_hdr_name); |
| 3796 | curproxy->orgto_hdr_name = strdup(DEF_XORIGINALTO_HDR); |
| 3797 | curproxy->orgto_hdr_len = strlen(DEF_XORIGINALTO_HDR); |
| 3798 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 3799 | /* 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] | 3800 | cur_arg = 2; |
| 3801 | while (*(args[cur_arg])) { |
| 3802 | if (!strcmp(args[cur_arg], "except")) { |
| 3803 | /* suboption except - needs additional argument for it */ |
| 3804 | if (!*(args[cur_arg+1]) || !str2net(args[cur_arg+1], &curproxy->except_to, &curproxy->except_mask_to)) { |
| 3805 | Alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n", |
| 3806 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3807 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3808 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 3809 | } |
| 3810 | /* flush useless bits */ |
| 3811 | curproxy->except_to.s_addr &= curproxy->except_mask_to.s_addr; |
| 3812 | cur_arg += 2; |
| 3813 | } else if (!strcmp(args[cur_arg], "header")) { |
| 3814 | /* suboption header - needs additional argument for it */ |
| 3815 | if (*(args[cur_arg+1]) == 0) { |
| 3816 | Alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 3817 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3818 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3819 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 3820 | } |
| 3821 | free(curproxy->orgto_hdr_name); |
| 3822 | curproxy->orgto_hdr_name = strdup(args[cur_arg+1]); |
| 3823 | curproxy->orgto_hdr_len = strlen(curproxy->orgto_hdr_name); |
| 3824 | cur_arg += 2; |
| 3825 | } else { |
| 3826 | /* unknown suboption - catchall */ |
| 3827 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n", |
| 3828 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3829 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3830 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 3831 | } |
| 3832 | } /* end while loop */ |
| 3833 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3834 | else { |
| 3835 | Alert("parsing [%s:%d] : unknown option '%s'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3836 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3837 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3838 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3839 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3840 | } |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 3841 | else if (!strcmp(args[0], "default_backend")) { |
| 3842 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3843 | err_code |= ERR_WARN; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 3844 | |
| 3845 | if (*(args[1]) == 0) { |
| 3846 | 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] | 3847 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3848 | goto out; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 3849 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3850 | free(curproxy->defbe.name); |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 3851 | curproxy->defbe.name = strdup(args[1]); |
| 3852 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3853 | else if (!strcmp(args[0], "redispatch") || !strcmp(args[0], "redisp")) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3854 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3855 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3856 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3857 | Warning("parsing [%s:%d]: keyword '%s' is deprecated, please use 'option redispatch' instead.\n", |
| 3858 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3859 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3860 | /* enable reconnections to dispatch */ |
| 3861 | curproxy->options |= PR_O_REDISP; |
| 3862 | } |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 3863 | else if (!strcmp(args[0], "http-check")) { |
| 3864 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3865 | err_code |= ERR_WARN; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 3866 | |
| 3867 | if (strcmp(args[1], "disable-on-404") == 0) { |
| 3868 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 3869 | curproxy->options |= PR_O_DISABLE404; |
| 3870 | } |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 3871 | else if (strcmp(args[1], "send-state") == 0) { |
| 3872 | /* enable emission of the apparent state of a server in HTTP checks */ |
| 3873 | curproxy->options2 |= PR_O2_CHK_SNDST; |
| 3874 | } |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 3875 | else if (strcmp(args[1], "expect") == 0) { |
| 3876 | const char *ptr_arg; |
| 3877 | int cur_arg; |
| 3878 | |
| 3879 | if (curproxy->options2 & PR_O2_EXP_TYPE) { |
| 3880 | Alert("parsing [%s:%d] : '%s %s' already specified.\n", file, linenum, args[0], args[1]); |
| 3881 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3882 | goto out; |
| 3883 | } |
| 3884 | |
| 3885 | cur_arg = 2; |
| 3886 | /* consider exclamation marks, sole or at the beginning of a word */ |
| 3887 | while (*(ptr_arg = args[cur_arg])) { |
| 3888 | while (*ptr_arg == '!') { |
| 3889 | curproxy->options2 ^= PR_O2_EXP_INV; |
| 3890 | ptr_arg++; |
| 3891 | } |
| 3892 | if (*ptr_arg) |
| 3893 | break; |
| 3894 | cur_arg++; |
| 3895 | } |
| 3896 | /* now ptr_arg points to the beginning of a word past any possible |
| 3897 | * exclamation mark, and cur_arg is the argument which holds this word. |
| 3898 | */ |
| 3899 | if (strcmp(ptr_arg, "status") == 0) { |
| 3900 | if (!*(args[cur_arg + 1])) { |
| 3901 | Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 3902 | file, linenum, args[0], args[1], ptr_arg); |
| 3903 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3904 | goto out; |
| 3905 | } |
| 3906 | curproxy->options2 |= PR_O2_EXP_STS; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 3907 | free(curproxy->expect_str); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 3908 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
| 3909 | } |
| 3910 | else if (strcmp(ptr_arg, "string") == 0) { |
| 3911 | if (!*(args[cur_arg + 1])) { |
| 3912 | Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 3913 | file, linenum, args[0], args[1], ptr_arg); |
| 3914 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3915 | goto out; |
| 3916 | } |
| 3917 | curproxy->options2 |= PR_O2_EXP_STR; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 3918 | free(curproxy->expect_str); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 3919 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
| 3920 | } |
| 3921 | else if (strcmp(ptr_arg, "rstatus") == 0) { |
| 3922 | if (!*(args[cur_arg + 1])) { |
| 3923 | Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 3924 | file, linenum, args[0], args[1], ptr_arg); |
| 3925 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3926 | goto out; |
| 3927 | } |
| 3928 | curproxy->options2 |= PR_O2_EXP_RSTS; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 3929 | free(curproxy->expect_str); |
| 3930 | if (curproxy->expect_regex) regfree(curproxy->expect_regex); |
| 3931 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 3932 | curproxy->expect_regex = calloc(1, sizeof(regex_t)); |
| 3933 | if (regcomp(curproxy->expect_regex, args[cur_arg + 1], REG_EXTENDED) != 0) { |
| 3934 | Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s'.\n", |
| 3935 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1]); |
| 3936 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3937 | goto out; |
| 3938 | } |
| 3939 | } |
| 3940 | else if (strcmp(ptr_arg, "rstring") == 0) { |
| 3941 | if (!*(args[cur_arg + 1])) { |
| 3942 | Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 3943 | file, linenum, args[0], args[1], ptr_arg); |
| 3944 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3945 | goto out; |
| 3946 | } |
| 3947 | curproxy->options2 |= PR_O2_EXP_RSTR; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 3948 | free(curproxy->expect_str); |
| 3949 | if (curproxy->expect_regex) regfree(curproxy->expect_regex); |
| 3950 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 3951 | curproxy->expect_regex = calloc(1, sizeof(regex_t)); |
| 3952 | if (regcomp(curproxy->expect_regex, args[cur_arg + 1], REG_EXTENDED) != 0) { |
| 3953 | Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s'.\n", |
| 3954 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1]); |
| 3955 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3956 | goto out; |
| 3957 | } |
| 3958 | } |
| 3959 | else { |
| 3960 | Alert("parsing [%s:%d] : '%s %s' only supports [!] 'status', 'string', 'rstatus', 'rstring', found '%s'.\n", |
| 3961 | file, linenum, args[0], args[1], ptr_arg); |
| 3962 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3963 | goto out; |
| 3964 | } |
| 3965 | } |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 3966 | else { |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 3967 | 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] | 3968 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3969 | goto out; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 3970 | } |
| 3971 | } |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3972 | else if (!strcmp(args[0], "monitor")) { |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3973 | if (curproxy == &defproxy) { |
| 3974 | 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] | 3975 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3976 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3977 | } |
| 3978 | |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3979 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3980 | err_code |= ERR_WARN; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3981 | |
| 3982 | if (strcmp(args[1], "fail") == 0) { |
| 3983 | /* add a condition to fail monitor requests */ |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 3984 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3985 | Alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n", |
| 3986 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3987 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3988 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3989 | } |
| 3990 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 3991 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 3992 | Alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition : %s.\n", |
| 3993 | file, linenum, args[0], args[1], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3994 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3995 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3996 | } |
| 3997 | LIST_ADDQ(&curproxy->mon_fail_cond, &cond->list); |
| 3998 | } |
| 3999 | else { |
| 4000 | 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] | 4001 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4002 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 4003 | } |
| 4004 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4005 | #ifdef TPROXY |
| 4006 | else if (!strcmp(args[0], "transparent")) { |
| 4007 | /* enable transparent proxy connections */ |
| 4008 | curproxy->options |= PR_O_TRANSP; |
| 4009 | } |
| 4010 | #endif |
| 4011 | else if (!strcmp(args[0], "maxconn")) { /* maxconn */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4012 | 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] | 4013 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4014 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4015 | if (*(args[1]) == 0) { |
| 4016 | 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] | 4017 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4018 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4019 | } |
| 4020 | curproxy->maxconn = atol(args[1]); |
| 4021 | } |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 4022 | else if (!strcmp(args[0], "backlog")) { /* backlog */ |
| 4023 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4024 | err_code |= ERR_WARN; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 4025 | |
| 4026 | if (*(args[1]) == 0) { |
| 4027 | 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] | 4028 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4029 | goto out; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 4030 | } |
| 4031 | curproxy->backlog = atol(args[1]); |
| 4032 | } |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 4033 | else if (!strcmp(args[0], "fullconn")) { /* fullconn */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4034 | 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] | 4035 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4036 | |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 4037 | if (*(args[1]) == 0) { |
| 4038 | 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] | 4039 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4040 | goto out; |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 4041 | } |
| 4042 | curproxy->fullconn = atol(args[1]); |
| 4043 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4044 | else if (!strcmp(args[0], "grace")) { /* grace time (ms) */ |
| 4045 | if (*(args[1]) == 0) { |
| 4046 | 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] | 4047 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4048 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4049 | } |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4050 | err = parse_time_err(args[1], &val, TIME_UNIT_MS); |
| 4051 | if (err) { |
| 4052 | Alert("parsing [%s:%d] : unexpected character '%c' in grace time.\n", |
| 4053 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4054 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4055 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4056 | } |
| 4057 | curproxy->grace = val; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4058 | } |
| 4059 | else if (!strcmp(args[0], "dispatch")) { /* dispatch address */ |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4060 | struct sockaddr_storage *sk; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4061 | if (curproxy == &defproxy) { |
| 4062 | 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] | 4063 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4064 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4065 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4066 | else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4067 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4068 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4069 | if (strchr(args[1], ':') == NULL) { |
| 4070 | 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] | 4071 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4072 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4073 | } |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4074 | sk = str2sa(args[1]); |
| 4075 | if (!sk) { |
| 4076 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[1]); |
| 4077 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4078 | goto out; |
| 4079 | } |
| 4080 | curproxy->dispatch_addr = *sk; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4081 | curproxy->options |= PR_O_DISPATCH; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4082 | } |
| 4083 | else if (!strcmp(args[0], "balance")) { /* set balancing with optional algorithm */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4084 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4085 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4086 | |
Willy Tarreau | a93c74b | 2012-05-08 18:14:39 +0200 | [diff] [blame] | 4087 | if (backend_parse_balance((const char **)args + 1, &errmsg, curproxy) < 0) { |
| 4088 | Alert("parsing [%s:%d] : %s %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4089 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4090 | goto out; |
Willy Tarreau | 2fcb500 | 2007-05-08 13:35:26 +0200 | [diff] [blame] | 4091 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4092 | } |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 4093 | else if (!strcmp(args[0], "hash-type")) { /* set hashing method */ |
| 4094 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 4095 | err_code |= ERR_WARN; |
| 4096 | |
| 4097 | if (strcmp(args[1], "consistent") == 0) { /* use consistent hashing */ |
| 4098 | curproxy->lbprm.algo &= ~BE_LB_HASH_TYPE; |
| 4099 | curproxy->lbprm.algo |= BE_LB_HASH_CONS; |
| 4100 | } |
| 4101 | else if (strcmp(args[1], "map-based") == 0) { /* use map-based hashing */ |
| 4102 | curproxy->lbprm.algo &= ~BE_LB_HASH_TYPE; |
| 4103 | curproxy->lbprm.algo |= BE_LB_HASH_MAP; |
| 4104 | } |
Willy Tarreau | 798a39c | 2010-11-24 15:04:29 +0100 | [diff] [blame] | 4105 | else if (strcmp(args[1], "avalanche") == 0) { /* use full hash before map-based hashing */ |
| 4106 | curproxy->lbprm.algo &= ~BE_LB_HASH_TYPE; |
| 4107 | curproxy->lbprm.algo |= BE_LB_HASH_AVAL; |
| 4108 | } |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 4109 | else { |
Willy Tarreau | 798a39c | 2010-11-24 15:04:29 +0100 | [diff] [blame] | 4110 | 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] | 4111 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4112 | goto out; |
| 4113 | } |
| 4114 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4115 | 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] | 4116 | int cur_arg; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4117 | char *rport, *raddr; |
| 4118 | short realport = 0; |
| 4119 | int do_check = 0, defsrv = (*args[0] == 'd'); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4120 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4121 | if (!defsrv && curproxy == &defproxy) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4122 | 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] | 4123 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4124 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4125 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4126 | else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4127 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4128 | |
| 4129 | if (!*args[2]) { |
| 4130 | Alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n", |
| 4131 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4132 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4133 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4134 | } |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 4135 | |
| 4136 | err = invalid_char(args[1]); |
| 4137 | if (err) { |
| 4138 | Alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n", |
| 4139 | file, linenum, *err, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4140 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4141 | goto out; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 4142 | } |
| 4143 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4144 | if (!defsrv) { |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4145 | struct sockaddr_storage *sk; |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4146 | |
Krzysztof Piotr Oledzki | aff01ea | 2010-02-05 20:31:44 +0100 | [diff] [blame] | 4147 | if ((newsrv = (struct server *)calloc(1, sizeof(struct server))) == NULL) { |
| 4148 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 4149 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4150 | goto out; |
| 4151 | } |
| 4152 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4153 | /* the servers are linked backwards first */ |
| 4154 | newsrv->next = curproxy->srv; |
| 4155 | curproxy->srv = newsrv; |
| 4156 | newsrv->proxy = curproxy; |
Willy Tarreau | 8113a5d | 2012-10-04 08:01:43 +0200 | [diff] [blame] | 4157 | newsrv->conf.file = strdup(file); |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4158 | newsrv->conf.line = linenum; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4159 | |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 4160 | newsrv->obj_type = OBJ_TYPE_SERVER; |
Simon Horman | af51495 | 2011-06-21 14:34:57 +0900 | [diff] [blame] | 4161 | LIST_INIT(&newsrv->actconns); |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4162 | LIST_INIT(&newsrv->pendconns); |
| 4163 | do_check = 0; |
| 4164 | newsrv->state = SRV_RUNNING; /* early server setup */ |
| 4165 | newsrv->last_change = now.tv_sec; |
| 4166 | newsrv->id = strdup(args[1]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4167 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4168 | /* several ways to check the port component : |
David du Colombier | 9842ff1 | 2011-03-17 10:40:28 +0100 | [diff] [blame] | 4169 | * - IP => port=+0, relative (IPv4 only) |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4170 | * - IP: => port=+0, relative |
| 4171 | * - IP:N => port=N, absolute |
| 4172 | * - IP:+N => port=+N, relative |
| 4173 | * - IP:-N => port=-N, relative |
| 4174 | */ |
| 4175 | raddr = strdup(args[2]); |
Willy Tarreau | fab5a43 | 2011-03-04 15:31:53 +0100 | [diff] [blame] | 4176 | rport = strrchr(raddr, ':'); |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4177 | if (rport) { |
| 4178 | *rport++ = 0; |
| 4179 | realport = atol(rport); |
| 4180 | if (!isdigit((unsigned char)*rport)) |
| 4181 | newsrv->state |= SRV_MAPPORTS; |
| 4182 | } else |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4183 | newsrv->state |= SRV_MAPPORTS; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4184 | |
Willy Tarreau | fab5a43 | 2011-03-04 15:31:53 +0100 | [diff] [blame] | 4185 | sk = str2ip(raddr); |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4186 | free(raddr); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4187 | if (!sk) { |
| 4188 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[2]); |
| 4189 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4190 | goto out; |
| 4191 | } |
| 4192 | newsrv->addr = *sk; |
Willy Tarreau | f4288ee | 2012-09-28 18:13:10 +0200 | [diff] [blame] | 4193 | newsrv->proto = newsrv->check.proto = protocol_by_family(newsrv->addr.ss_family); |
| 4194 | newsrv->xprt = newsrv->check.xprt = &raw_sock; |
Willy Tarreau | 26d8c59 | 2012-05-07 18:12:14 +0200 | [diff] [blame] | 4195 | |
Willy Tarreau | 173e7fb | 2012-09-24 22:47:39 +0200 | [diff] [blame] | 4196 | if (!newsrv->proto) { |
Willy Tarreau | 26d8c59 | 2012-05-07 18:12:14 +0200 | [diff] [blame] | 4197 | Alert("parsing [%s:%d] : Unknown protocol family %d '%s'\n", |
| 4198 | file, linenum, newsrv->addr.ss_family, args[2]); |
| 4199 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4200 | goto out; |
| 4201 | } |
Willy Tarreau | 86ad42c | 2011-08-27 12:29:07 +0200 | [diff] [blame] | 4202 | set_host_port(&newsrv->addr, realport); |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4203 | |
Willy Tarreau | f4288ee | 2012-09-28 18:13:10 +0200 | [diff] [blame] | 4204 | newsrv->check.use_ssl = curproxy->defsrv.check.use_ssl; |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 4205 | newsrv->check.port = curproxy->defsrv.check.port; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4206 | newsrv->inter = curproxy->defsrv.inter; |
| 4207 | newsrv->fastinter = curproxy->defsrv.fastinter; |
| 4208 | newsrv->downinter = curproxy->defsrv.downinter; |
| 4209 | newsrv->rise = curproxy->defsrv.rise; |
| 4210 | newsrv->fall = curproxy->defsrv.fall; |
| 4211 | newsrv->maxqueue = curproxy->defsrv.maxqueue; |
| 4212 | newsrv->minconn = curproxy->defsrv.minconn; |
| 4213 | newsrv->maxconn = curproxy->defsrv.maxconn; |
| 4214 | newsrv->slowstart = curproxy->defsrv.slowstart; |
| 4215 | newsrv->onerror = curproxy->defsrv.onerror; |
| 4216 | newsrv->consecutive_errors_limit |
| 4217 | = curproxy->defsrv.consecutive_errors_limit; |
Emeric Brun | 01f8e2f | 2012-05-18 16:02:00 +0200 | [diff] [blame] | 4218 | #ifdef OPENSSL |
| 4219 | newsrv->use_ssl = curproxy->defsrv.use_ssl; |
| 4220 | #endif |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4221 | newsrv->uweight = newsrv->iweight |
| 4222 | = curproxy->defsrv.iweight; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4223 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4224 | newsrv->health = newsrv->rise; /* up, but will fall down at first failure */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4225 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4226 | cur_arg = 3; |
| 4227 | } else { |
| 4228 | newsrv = &curproxy->defsrv; |
| 4229 | cur_arg = 1; |
| 4230 | } |
Willy Tarreau | 0f03c6f | 2007-03-25 20:46:19 +0200 | [diff] [blame] | 4231 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4232 | while (*args[cur_arg]) { |
Willy Tarreau | dff5543 | 2012-10-10 17:51:05 +0200 | [diff] [blame] | 4233 | if (!defsrv && !strcmp(args[cur_arg], "cookie")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4234 | newsrv->cookie = strdup(args[cur_arg + 1]); |
| 4235 | newsrv->cklen = strlen(args[cur_arg + 1]); |
| 4236 | cur_arg += 2; |
| 4237 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4238 | else if (!defsrv && !strcmp(args[cur_arg], "redir")) { |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 4239 | newsrv->rdr_pfx = strdup(args[cur_arg + 1]); |
| 4240 | newsrv->rdr_len = strlen(args[cur_arg + 1]); |
| 4241 | cur_arg += 2; |
| 4242 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4243 | else if (!strcmp(args[cur_arg], "rise")) { |
Krzysztof Piotr Oledzki | 08ff959 | 2009-09-27 16:17:31 +0200 | [diff] [blame] | 4244 | if (!*args[cur_arg + 1]) { |
| 4245 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 4246 | file, linenum, args[cur_arg]); |
| 4247 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4248 | goto out; |
| 4249 | } |
| 4250 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4251 | newsrv->rise = atol(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 08ff959 | 2009-09-27 16:17:31 +0200 | [diff] [blame] | 4252 | if (newsrv->rise <= 0) { |
| 4253 | Alert("parsing [%s:%d]: '%s' has to be > 0.\n", |
| 4254 | file, linenum, args[cur_arg]); |
| 4255 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4256 | goto out; |
| 4257 | } |
| 4258 | |
Willy Tarreau | 9683909 | 2010-03-29 10:02:24 +0200 | [diff] [blame] | 4259 | if (newsrv->health) |
| 4260 | newsrv->health = newsrv->rise; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4261 | cur_arg += 2; |
| 4262 | } |
| 4263 | else if (!strcmp(args[cur_arg], "fall")) { |
| 4264 | newsrv->fall = atol(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 08ff959 | 2009-09-27 16:17:31 +0200 | [diff] [blame] | 4265 | |
| 4266 | if (!*args[cur_arg + 1]) { |
| 4267 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 4268 | file, linenum, args[cur_arg]); |
| 4269 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4270 | goto out; |
| 4271 | } |
| 4272 | |
| 4273 | if (newsrv->fall <= 0) { |
| 4274 | Alert("parsing [%s:%d]: '%s' has to be > 0.\n", |
| 4275 | file, linenum, args[cur_arg]); |
| 4276 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4277 | goto out; |
| 4278 | } |
| 4279 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4280 | cur_arg += 2; |
| 4281 | } |
| 4282 | else if (!strcmp(args[cur_arg], "inter")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4283 | const char *err = parse_time_err(args[cur_arg + 1], &val, TIME_UNIT_MS); |
| 4284 | if (err) { |
| 4285 | Alert("parsing [%s:%d] : unexpected character '%c' in 'inter' argument of server %s.\n", |
| 4286 | file, linenum, *err, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4287 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4288 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4289 | } |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4290 | if (val <= 0) { |
| 4291 | Alert("parsing [%s:%d]: invalid value %d for argument '%s' of server %s.\n", |
| 4292 | file, linenum, val, args[cur_arg], newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4293 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4294 | goto out; |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4295 | } |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4296 | newsrv->inter = val; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4297 | cur_arg += 2; |
| 4298 | } |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 4299 | else if (!strcmp(args[cur_arg], "fastinter")) { |
| 4300 | const char *err = parse_time_err(args[cur_arg + 1], &val, TIME_UNIT_MS); |
| 4301 | if (err) { |
| 4302 | Alert("parsing [%s:%d]: unexpected character '%c' in 'fastinter' argument of server %s.\n", |
| 4303 | file, linenum, *err, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4304 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4305 | goto out; |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 4306 | } |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4307 | if (val <= 0) { |
| 4308 | Alert("parsing [%s:%d]: invalid value %d for argument '%s' of server %s.\n", |
| 4309 | file, linenum, val, args[cur_arg], newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4310 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4311 | goto out; |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4312 | } |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 4313 | newsrv->fastinter = val; |
| 4314 | cur_arg += 2; |
| 4315 | } |
| 4316 | else if (!strcmp(args[cur_arg], "downinter")) { |
| 4317 | const char *err = parse_time_err(args[cur_arg + 1], &val, TIME_UNIT_MS); |
| 4318 | if (err) { |
| 4319 | Alert("parsing [%s:%d]: unexpected character '%c' in 'downinter' argument of server %s.\n", |
| 4320 | file, linenum, *err, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4321 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4322 | goto out; |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 4323 | } |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4324 | if (val <= 0) { |
| 4325 | Alert("parsing [%s:%d]: invalid value %d for argument '%s' of server %s.\n", |
| 4326 | file, linenum, val, args[cur_arg], newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4327 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4328 | goto out; |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4329 | } |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 4330 | newsrv->downinter = val; |
| 4331 | cur_arg += 2; |
| 4332 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4333 | else if (!defsrv && !strcmp(args[cur_arg], "addr")) { |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4334 | struct sockaddr_storage *sk = str2sa(args[cur_arg + 1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4335 | if (!sk) { |
| 4336 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[cur_arg + 1]); |
| 4337 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4338 | goto out; |
| 4339 | } |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 4340 | newsrv->check.addr = *sk; |
Willy Tarreau | 2ea3abb | 2007-03-25 16:45:16 +0200 | [diff] [blame] | 4341 | cur_arg += 2; |
| 4342 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4343 | else if (!strcmp(args[cur_arg], "port")) { |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 4344 | newsrv->check.port = atol(args[cur_arg + 1]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4345 | cur_arg += 2; |
| 4346 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4347 | else if (!defsrv && !strcmp(args[cur_arg], "backup")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4348 | newsrv->state |= SRV_BACKUP; |
| 4349 | cur_arg ++; |
| 4350 | } |
Simon Horman | fa46168 | 2011-06-25 09:39:49 +0900 | [diff] [blame] | 4351 | else if (!defsrv && !strcmp(args[cur_arg], "non-stick")) { |
| 4352 | newsrv->state |= SRV_NON_STICK; |
| 4353 | cur_arg ++; |
| 4354 | } |
Willy Tarreau | 5ab04ec | 2011-03-20 10:32:26 +0100 | [diff] [blame] | 4355 | else if (!defsrv && !strcmp(args[cur_arg], "send-proxy")) { |
| 4356 | newsrv->state |= SRV_SEND_PROXY; |
| 4357 | cur_arg ++; |
| 4358 | } |
Willy Tarreau | 6c16adc | 2012-10-05 00:04:16 +0200 | [diff] [blame] | 4359 | else if (!defsrv && !strcmp(args[cur_arg], "check-send-proxy")) { |
| 4360 | newsrv->check.send_proxy = 1; |
| 4361 | cur_arg ++; |
| 4362 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4363 | else if (!strcmp(args[cur_arg], "weight")) { |
| 4364 | int w; |
| 4365 | w = atol(args[cur_arg + 1]); |
Willy Tarreau | 6704d67 | 2009-06-15 10:56:05 +0200 | [diff] [blame] | 4366 | if (w < 0 || w > 256) { |
| 4367 | 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] | 4368 | file, linenum, newsrv->id, w); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4369 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4370 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4371 | } |
Willy Tarreau | 975c50b | 2009-10-10 19:34:06 +0200 | [diff] [blame] | 4372 | newsrv->uweight = newsrv->iweight = w; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4373 | cur_arg += 2; |
| 4374 | } |
| 4375 | else if (!strcmp(args[cur_arg], "minconn")) { |
| 4376 | newsrv->minconn = atol(args[cur_arg + 1]); |
| 4377 | cur_arg += 2; |
| 4378 | } |
| 4379 | else if (!strcmp(args[cur_arg], "maxconn")) { |
| 4380 | newsrv->maxconn = atol(args[cur_arg + 1]); |
| 4381 | cur_arg += 2; |
| 4382 | } |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 4383 | else if (!strcmp(args[cur_arg], "maxqueue")) { |
| 4384 | newsrv->maxqueue = atol(args[cur_arg + 1]); |
| 4385 | cur_arg += 2; |
| 4386 | } |
Willy Tarreau | 9909fc1 | 2007-11-30 17:42:05 +0100 | [diff] [blame] | 4387 | else if (!strcmp(args[cur_arg], "slowstart")) { |
| 4388 | /* slowstart is stored in seconds */ |
Willy Tarreau | 3259e33 | 2007-12-03 01:51:45 +0100 | [diff] [blame] | 4389 | 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] | 4390 | if (err) { |
| 4391 | Alert("parsing [%s:%d] : unexpected character '%c' in 'slowstart' argument of server %s.\n", |
| 4392 | file, linenum, *err, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4393 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4394 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4395 | } |
Willy Tarreau | 4554bc1 | 2010-03-26 10:40:49 +0100 | [diff] [blame] | 4396 | if (val < 0) { |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4397 | Alert("parsing [%s:%d]: invalid value %d for argument '%s' of server %s.\n", |
| 4398 | file, linenum, val, args[cur_arg], newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4399 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4400 | goto out; |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4401 | } |
Willy Tarreau | 3259e33 | 2007-12-03 01:51:45 +0100 | [diff] [blame] | 4402 | newsrv->slowstart = (val + 999) / 1000; |
Willy Tarreau | 9909fc1 | 2007-11-30 17:42:05 +0100 | [diff] [blame] | 4403 | cur_arg += 2; |
| 4404 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4405 | else if (!defsrv && !strcmp(args[cur_arg], "track")) { |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4406 | |
| 4407 | if (!*args[cur_arg + 1]) { |
| 4408 | Alert("parsing [%s:%d]: 'track' expects [<proxy>/]<server> as argument.\n", |
| 4409 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4410 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4411 | goto out; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4412 | } |
| 4413 | |
| 4414 | newsrv->trackit = strdup(args[cur_arg + 1]); |
| 4415 | |
| 4416 | cur_arg += 2; |
| 4417 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4418 | else if (!defsrv && !strcmp(args[cur_arg], "check")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4419 | global.maxsock++; |
| 4420 | do_check = 1; |
| 4421 | cur_arg += 1; |
| 4422 | } |
Willy Tarreau | 9683909 | 2010-03-29 10:02:24 +0200 | [diff] [blame] | 4423 | else if (!defsrv && !strcmp(args[cur_arg], "disabled")) { |
| 4424 | newsrv->state |= SRV_MAINTAIN; |
| 4425 | newsrv->state &= ~SRV_RUNNING; |
| 4426 | newsrv->health = 0; |
| 4427 | cur_arg += 1; |
Emeric Brun | c0ff492 | 2012-09-28 19:37:02 +0200 | [diff] [blame] | 4428 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4429 | else if (!defsrv && !strcmp(args[cur_arg], "observe")) { |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 4430 | if (!strcmp(args[cur_arg + 1], "none")) |
| 4431 | newsrv->observe = HANA_OBS_NONE; |
| 4432 | else if (!strcmp(args[cur_arg + 1], "layer4")) |
| 4433 | newsrv->observe = HANA_OBS_LAYER4; |
| 4434 | else if (!strcmp(args[cur_arg + 1], "layer7")) { |
| 4435 | if (curproxy->mode != PR_MODE_HTTP) { |
| 4436 | Alert("parsing [%s:%d]: '%s' can only be used in http proxies.\n", |
| 4437 | file, linenum, args[cur_arg + 1]); |
| 4438 | err_code |= ERR_ALERT; |
| 4439 | } |
| 4440 | newsrv->observe = HANA_OBS_LAYER7; |
| 4441 | } |
| 4442 | else { |
| 4443 | Alert("parsing [%s:%d]: '%s' expects one of 'none', " |
Willy Tarreau | 53621e0 | 2010-10-22 14:53:40 +0200 | [diff] [blame] | 4444 | "'layer4', 'layer7' but got '%s'\n", |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 4445 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
| 4446 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4447 | goto out; |
| 4448 | } |
| 4449 | |
| 4450 | cur_arg += 2; |
| 4451 | } |
| 4452 | else if (!strcmp(args[cur_arg], "on-error")) { |
| 4453 | if (!strcmp(args[cur_arg + 1], "fastinter")) |
| 4454 | newsrv->onerror = HANA_ONERR_FASTINTER; |
| 4455 | else if (!strcmp(args[cur_arg + 1], "fail-check")) |
| 4456 | newsrv->onerror = HANA_ONERR_FAILCHK; |
| 4457 | else if (!strcmp(args[cur_arg + 1], "sudden-death")) |
| 4458 | newsrv->onerror = HANA_ONERR_SUDDTH; |
| 4459 | else if (!strcmp(args[cur_arg + 1], "mark-down")) |
| 4460 | newsrv->onerror = HANA_ONERR_MARKDWN; |
| 4461 | else { |
| 4462 | Alert("parsing [%s:%d]: '%s' expects one of 'fastinter', " |
Willy Tarreau | 53621e0 | 2010-10-22 14:53:40 +0200 | [diff] [blame] | 4463 | "'fail-check', 'sudden-death' or 'mark-down' but got '%s'\n", |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 4464 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
| 4465 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4466 | goto out; |
| 4467 | } |
| 4468 | |
| 4469 | cur_arg += 2; |
| 4470 | } |
Simon Horman | e0d1bfb | 2011-06-21 14:34:58 +0900 | [diff] [blame] | 4471 | else if (!strcmp(args[cur_arg], "on-marked-down")) { |
| 4472 | if (!strcmp(args[cur_arg + 1], "shutdown-sessions")) |
| 4473 | newsrv->onmarkeddown = HANA_ONMARKEDDOWN_SHUTDOWNSESSIONS; |
| 4474 | else { |
| 4475 | Alert("parsing [%s:%d]: '%s' expects 'shutdown-sessions' but got '%s'\n", |
| 4476 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
| 4477 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4478 | goto out; |
| 4479 | } |
| 4480 | |
| 4481 | cur_arg += 2; |
| 4482 | } |
Justin Karneges | eb2c24a | 2012-05-24 15:28:52 -0700 | [diff] [blame] | 4483 | else if (!strcmp(args[cur_arg], "on-marked-up")) { |
| 4484 | if (!strcmp(args[cur_arg + 1], "shutdown-backup-sessions")) |
| 4485 | newsrv->onmarkedup = HANA_ONMARKEDUP_SHUTDOWNBACKUPSESSIONS; |
| 4486 | else { |
| 4487 | Alert("parsing [%s:%d]: '%s' expects 'shutdown-backup-sessions' but got '%s'\n", |
| 4488 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
| 4489 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4490 | goto out; |
| 4491 | } |
| 4492 | |
| 4493 | cur_arg += 2; |
| 4494 | } |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 4495 | else if (!strcmp(args[cur_arg], "error-limit")) { |
| 4496 | if (!*args[cur_arg + 1]) { |
| 4497 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 4498 | file, linenum, args[cur_arg]); |
| 4499 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4500 | goto out; |
| 4501 | } |
| 4502 | |
| 4503 | newsrv->consecutive_errors_limit = atoi(args[cur_arg + 1]); |
| 4504 | |
| 4505 | if (newsrv->consecutive_errors_limit <= 0) { |
| 4506 | Alert("parsing [%s:%d]: %s has to be > 0.\n", |
| 4507 | file, linenum, args[cur_arg]); |
| 4508 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4509 | goto out; |
| 4510 | } |
Willy Tarreau | f53b25d | 2010-03-15 19:40:37 +0100 | [diff] [blame] | 4511 | cur_arg += 2; |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 4512 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4513 | 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] | 4514 | int port_low, port_high; |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4515 | struct sockaddr_storage *sk; |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4516 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4517 | if (!*args[cur_arg + 1]) { |
Willy Tarreau | eb37faa | 2012-12-08 23:21:19 +0100 | [diff] [blame] | 4518 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>[-<port>]], and optionally '%s' <addr>, and '%s' <name> as argument.\n", |
| 4519 | file, linenum, "source", "usesrc", "interface"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4520 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4521 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4522 | } |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4523 | newsrv->conn_src.opts |= CO_SRC_BIND; |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4524 | sk = str2sa_range(args[cur_arg + 1], &port_low, &port_high); |
| 4525 | if (!sk) { |
| 4526 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[cur_arg + 1]); |
| 4527 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4528 | goto out; |
| 4529 | } |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4530 | newsrv->conn_src.source_addr = *sk; |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 4531 | |
| 4532 | if (port_low != port_high) { |
| 4533 | int i; |
| 4534 | if (port_low <= 0 || port_low > 65535 || |
| 4535 | port_high <= 0 || port_high > 65535 || |
| 4536 | port_low > port_high) { |
| 4537 | Alert("parsing [%s:%d] : invalid source port range %d-%d.\n", |
| 4538 | file, linenum, port_low, port_high); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4539 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4540 | goto out; |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 4541 | } |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4542 | newsrv->conn_src.sport_range = port_range_alloc_range(port_high - port_low + 1); |
| 4543 | for (i = 0; i < newsrv->conn_src.sport_range->size; i++) |
| 4544 | newsrv->conn_src.sport_range->ports[i] = port_low + i; |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 4545 | } |
| 4546 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4547 | cur_arg += 2; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4548 | while (*(args[cur_arg])) { |
| 4549 | if (!strcmp(args[cur_arg], "usesrc")) { /* address to use outside */ |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4550 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) |
| 4551 | #if !defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4552 | if (!is_addr(&newsrv->conn_src.source_addr)) { |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4553 | Alert("parsing [%s:%d] : '%s' requires an explicit '%s' address.\n", |
| 4554 | file, linenum, "usesrc", "source"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4555 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4556 | goto out; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4557 | } |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4558 | #endif |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4559 | if (!*args[cur_arg + 1]) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4560 | 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] | 4561 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4562 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4563 | goto out; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4564 | } |
| 4565 | if (!strcmp(args[cur_arg + 1], "client")) { |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4566 | newsrv->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 4567 | newsrv->conn_src.opts |= CO_SRC_TPROXY_CLI; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4568 | } else if (!strcmp(args[cur_arg + 1], "clientip")) { |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4569 | newsrv->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 4570 | newsrv->conn_src.opts |= CO_SRC_TPROXY_CIP; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4571 | } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) { |
| 4572 | char *name, *end; |
| 4573 | |
| 4574 | name = args[cur_arg+1] + 7; |
| 4575 | while (isspace(*name)) |
| 4576 | name++; |
| 4577 | |
| 4578 | end = name; |
| 4579 | while (*end && !isspace(*end) && *end != ',' && *end != ')') |
| 4580 | end++; |
| 4581 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4582 | newsrv->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 4583 | newsrv->conn_src.opts |= CO_SRC_TPROXY_DYN; |
| 4584 | newsrv->conn_src.bind_hdr_name = calloc(1, end - name + 1); |
| 4585 | newsrv->conn_src.bind_hdr_len = end - name; |
| 4586 | memcpy(newsrv->conn_src.bind_hdr_name, name, end - name); |
| 4587 | newsrv->conn_src.bind_hdr_name[end-name] = '\0'; |
| 4588 | newsrv->conn_src.bind_hdr_occ = -1; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4589 | |
| 4590 | /* now look for an occurrence number */ |
| 4591 | while (isspace(*end)) |
| 4592 | end++; |
| 4593 | if (*end == ',') { |
| 4594 | end++; |
| 4595 | name = end; |
| 4596 | if (*end == '-') |
| 4597 | end++; |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 4598 | while (isdigit((int)*end)) |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4599 | end++; |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4600 | newsrv->conn_src.bind_hdr_occ = strl2ic(name, end-name); |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4601 | } |
| 4602 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4603 | if (newsrv->conn_src.bind_hdr_occ < -MAX_HDR_HISTORY) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4604 | Alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative" |
| 4605 | " occurrences values smaller than %d.\n", |
| 4606 | file, linenum, MAX_HDR_HISTORY); |
| 4607 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4608 | goto out; |
| 4609 | } |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4610 | } else { |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4611 | struct sockaddr_storage *sk = str2sa(args[cur_arg + 1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4612 | if (!sk) { |
| 4613 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[cur_arg + 1]); |
| 4614 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4615 | goto out; |
| 4616 | } |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4617 | newsrv->conn_src.tproxy_addr = *sk; |
| 4618 | newsrv->conn_src.opts |= CO_SRC_TPROXY_ADDR; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4619 | } |
| 4620 | global.last_checks |= LSTCHK_NETADM; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4621 | #if !defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4622 | global.last_checks |= LSTCHK_CTTPROXY; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4623 | #endif |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4624 | cur_arg += 2; |
| 4625 | continue; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4626 | #else /* no TPROXY support */ |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4627 | 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] | 4628 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4629 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4630 | goto out; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4631 | #endif /* defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) */ |
| 4632 | } /* "usesrc" */ |
| 4633 | |
| 4634 | if (!strcmp(args[cur_arg], "interface")) { /* specifically bind to this interface */ |
| 4635 | #ifdef SO_BINDTODEVICE |
| 4636 | if (!*args[cur_arg + 1]) { |
| 4637 | Alert("parsing [%s:%d] : '%s' : missing interface name.\n", |
| 4638 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4639 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4640 | goto out; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4641 | } |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4642 | free(newsrv->conn_src.iface_name); |
| 4643 | newsrv->conn_src.iface_name = strdup(args[cur_arg + 1]); |
| 4644 | newsrv->conn_src.iface_len = strlen(newsrv->conn_src.iface_name); |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4645 | global.last_checks |= LSTCHK_NETADM; |
| 4646 | #else |
| 4647 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 4648 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4649 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4650 | goto out; |
Willy Tarreau | 77074d5 | 2006-11-12 23:57:19 +0100 | [diff] [blame] | 4651 | #endif |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4652 | cur_arg += 2; |
| 4653 | continue; |
| 4654 | } |
| 4655 | /* this keyword in not an option of "source" */ |
| 4656 | break; |
| 4657 | } /* while */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4658 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4659 | 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] | 4660 | Alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n", |
| 4661 | file, linenum, "usesrc", "source"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4662 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4663 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 4664 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4665 | else { |
Willy Tarreau | d0d6059 | 2012-10-10 08:57:40 +0200 | [diff] [blame] | 4666 | static int srv_dumped; |
| 4667 | struct srv_kw *kw; |
| 4668 | char *err; |
| 4669 | |
| 4670 | kw = srv_find_kw(args[cur_arg]); |
| 4671 | if (kw) { |
| 4672 | char *err = NULL; |
| 4673 | int code; |
| 4674 | |
| 4675 | if (!kw->parse) { |
| 4676 | Alert("parsing [%s:%d] : '%s %s' : '%s' option is not implemented in this version (check build options).\n", |
| 4677 | file, linenum, args[0], args[1], args[cur_arg]); |
| 4678 | cur_arg += 1 + kw->skip ; |
| 4679 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4680 | goto out; |
| 4681 | } |
| 4682 | |
| 4683 | if (defsrv && !kw->default_ok) { |
| 4684 | Alert("parsing [%s:%d] : '%s %s' : '%s' option is not accepted in default-server sections.\n", |
| 4685 | file, linenum, args[0], args[1], args[cur_arg]); |
| 4686 | cur_arg += 1 + kw->skip ; |
| 4687 | err_code |= ERR_ALERT; |
| 4688 | continue; |
| 4689 | } |
| 4690 | |
| 4691 | code = kw->parse(args, &cur_arg, curproxy, newsrv, &err); |
| 4692 | err_code |= code; |
| 4693 | |
| 4694 | if (code) { |
| 4695 | if (err && *err) { |
| 4696 | indent_msg(&err, 2); |
| 4697 | Alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], err); |
| 4698 | } |
| 4699 | else |
| 4700 | Alert("parsing [%s:%d] : '%s %s' : error encountered while processing '%s'.\n", |
| 4701 | file, linenum, args[0], args[1], args[cur_arg]); |
| 4702 | if (code & ERR_FATAL) { |
| 4703 | free(err); |
| 4704 | cur_arg += 1 + kw->skip; |
| 4705 | goto out; |
| 4706 | } |
| 4707 | } |
| 4708 | free(err); |
| 4709 | cur_arg += 1 + kw->skip; |
| 4710 | continue; |
| 4711 | } |
| 4712 | |
| 4713 | err = NULL; |
| 4714 | if (!srv_dumped) { |
| 4715 | srv_dump_kws(&err); |
| 4716 | indent_msg(&err, 4); |
| 4717 | srv_dumped = 1; |
| 4718 | } |
| 4719 | |
| 4720 | Alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'.%s%s\n", |
| 4721 | file, linenum, args[0], args[1], args[cur_arg], |
| 4722 | err ? " Registered keywords :" : "", err ? err : ""); |
| 4723 | free(err); |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4724 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4725 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4726 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4727 | } |
| 4728 | } |
| 4729 | |
| 4730 | if (do_check) { |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4731 | if (newsrv->trackit) { |
| 4732 | Alert("parsing [%s:%d]: unable to enable checks and tracking at the same time!\n", |
| 4733 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4734 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4735 | goto out; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4736 | } |
| 4737 | |
Willy Tarreau | f4288ee | 2012-09-28 18:13:10 +0200 | [diff] [blame] | 4738 | /* If neither a port nor an addr was specified and no check transport |
| 4739 | * layer is forced, then the transport layer used by the checks is the |
| 4740 | * same as for the production traffic. Otherwise we use raw_sock by |
| 4741 | * default, unless one is specified. |
| 4742 | */ |
Willy Tarreau | 6c16adc | 2012-10-05 00:04:16 +0200 | [diff] [blame] | 4743 | if (!newsrv->check.port && !is_addr(&newsrv->check.addr)) { |
Willy Tarreau | 7151633 | 2012-10-10 23:01:14 +0200 | [diff] [blame] | 4744 | #ifdef USE_OPENSSL |
Willy Tarreau | f4288ee | 2012-09-28 18:13:10 +0200 | [diff] [blame] | 4745 | newsrv->check.use_ssl |= newsrv->use_ssl; |
Willy Tarreau | 7151633 | 2012-10-10 23:01:14 +0200 | [diff] [blame] | 4746 | #endif |
Willy Tarreau | 6c16adc | 2012-10-05 00:04:16 +0200 | [diff] [blame] | 4747 | newsrv->check.send_proxy |= (newsrv->state & SRV_SEND_PROXY); |
| 4748 | } |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 4749 | /* try to get the port from check.addr if check.port not set */ |
| 4750 | if (!newsrv->check.port) |
| 4751 | newsrv->check.port = get_host_port(&newsrv->check.addr); |
Willy Tarreau | 0f03c6f | 2007-03-25 20:46:19 +0200 | [diff] [blame] | 4752 | |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 4753 | if (!newsrv->check.port && !(newsrv->state & SRV_MAPPORTS)) |
| 4754 | newsrv->check.port = realport; /* by default */ |
| 4755 | if (!newsrv->check.port) { |
Willy Tarreau | ef00b50 | 2007-01-07 02:40:09 +0100 | [diff] [blame] | 4756 | /* not yet valid, because no port was set on |
| 4757 | * the server either. We'll check if we have |
| 4758 | * a known port on the first listener. |
| 4759 | */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 4760 | struct listener *l; |
| 4761 | |
| 4762 | list_for_each_entry(l, &curproxy->conf.listeners, by_fe) { |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 4763 | newsrv->check.port = get_host_port(&l->addr); |
| 4764 | if (newsrv->check.port) |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 4765 | break; |
| 4766 | } |
Willy Tarreau | ef00b50 | 2007-01-07 02:40:09 +0100 | [diff] [blame] | 4767 | } |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 4768 | if (!newsrv->check.port) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4769 | Alert("parsing [%s:%d] : server %s has neither service port nor check port. Check has been disabled.\n", |
| 4770 | file, linenum, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4771 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4772 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4773 | } |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 4774 | |
Willy Tarreau | 1ae1b7b | 2012-09-28 15:28:30 +0200 | [diff] [blame] | 4775 | /* Allocate buffer for check requests... */ |
| 4776 | 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] | 4777 | Alert("parsing [%s:%d] : out of memory while allocating check buffer.\n", file, linenum); |
| 4778 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4779 | goto out; |
| 4780 | } |
Willy Tarreau | 1ae1b7b | 2012-09-28 15:28:30 +0200 | [diff] [blame] | 4781 | newsrv->check.bi->size = global.tune.chksize; |
| 4782 | |
| 4783 | /* Allocate buffer for check responses... */ |
| 4784 | if ((newsrv->check.bo = calloc(sizeof(struct buffer) + global.tune.chksize, sizeof(char))) == NULL) { |
| 4785 | Alert("parsing [%s:%d] : out of memory while allocating check buffer.\n", file, linenum); |
| 4786 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4787 | goto out; |
| 4788 | } |
| 4789 | newsrv->check.bo->size = global.tune.chksize; |
Cyril Bonté | c9f825f | 2010-03-17 18:56:31 +0100 | [diff] [blame] | 4790 | |
Willy Tarreau | da92e2f | 2012-07-06 09:40:59 +0200 | [diff] [blame] | 4791 | /* Allocate buffer for partial check results... */ |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 4792 | if ((newsrv->check.conn = calloc(1, sizeof(struct connection))) == NULL) { |
Willy Tarreau | da92e2f | 2012-07-06 09:40:59 +0200 | [diff] [blame] | 4793 | Alert("parsing [%s:%d] : out of memory while allocating check connection.\n", file, linenum); |
| 4794 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4795 | goto out; |
| 4796 | } |
| 4797 | |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 4798 | newsrv->check.conn->t.sock.fd = -1; /* no check in progress yet */ |
| 4799 | newsrv->check.status = HCHK_STATUS_INI; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4800 | newsrv->state |= SRV_CHECKED; |
| 4801 | } |
| 4802 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4803 | if (!defsrv) { |
| 4804 | if (newsrv->state & SRV_BACKUP) |
| 4805 | curproxy->srv_bck++; |
| 4806 | else |
| 4807 | curproxy->srv_act++; |
Willy Tarreau | b625a08 | 2007-11-26 01:15:43 +0100 | [diff] [blame] | 4808 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4809 | newsrv->prev_state = newsrv->state; |
| 4810 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 4811 | } |
| 4812 | |
| 4813 | else if (strcmp(args[0], "unique-id-format") == 0) { |
| 4814 | if (!*(args[1])) { |
| 4815 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 4816 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4817 | goto out; |
| 4818 | } |
William Lallemand | 3203ff4 | 2012-11-11 17:30:56 +0100 | [diff] [blame] | 4819 | if (*(args[2])) { |
| 4820 | Alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]); |
| 4821 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4822 | goto out; |
| 4823 | } |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 4824 | free(curproxy->uniqueid_format_string); |
| 4825 | curproxy->uniqueid_format_string = strdup(args[1]); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4826 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 4827 | |
| 4828 | else if (strcmp(args[0], "unique-id-header") == 0) { |
| 4829 | if (!*(args[1])) { |
| 4830 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 4831 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4832 | goto out; |
| 4833 | } |
| 4834 | free(curproxy->header_unique_id); |
| 4835 | curproxy->header_unique_id = strdup(args[1]); |
| 4836 | } |
| 4837 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4838 | else if (strcmp(args[0], "log-format") == 0) { |
| 4839 | if (!*(args[1])) { |
| 4840 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 4841 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4842 | goto out; |
| 4843 | } |
William Lallemand | 3203ff4 | 2012-11-11 17:30:56 +0100 | [diff] [blame] | 4844 | if (*(args[2])) { |
| 4845 | Alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]); |
| 4846 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4847 | goto out; |
| 4848 | } |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 4849 | |
| 4850 | if (curproxy->logformat_string != default_http_log_format && |
| 4851 | curproxy->logformat_string != default_tcp_log_format && |
| 4852 | curproxy->logformat_string != clf_http_log_format) |
| 4853 | free(curproxy->logformat_string); |
| 4854 | curproxy->logformat_string = strdup(args[1]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4855 | } |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4856 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4857 | else if (!strcmp(args[0], "log") && kwm == KWM_NO) { |
| 4858 | /* delete previous herited or defined syslog servers */ |
| 4859 | struct logsrv *back; |
| 4860 | |
| 4861 | if (*(args[1]) != 0) { |
| 4862 | Alert("parsing [%s:%d]:%s : 'no log' does not expect arguments.\n", file, linenum, args[1]); |
| 4863 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4864 | goto out; |
| 4865 | } |
| 4866 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4867 | list_for_each_entry_safe(tmplogsrv, back, &curproxy->logsrvs, list) { |
| 4868 | LIST_DEL(&tmplogsrv->list); |
| 4869 | free(tmplogsrv); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4870 | } |
| 4871 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4872 | else if (!strcmp(args[0], "log")) { /* syslog server address */ |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4873 | struct logsrv *logsrv; |
| 4874 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4875 | if (*(args[1]) && *(args[2]) == 0 && !strcmp(args[1], "global")) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4876 | /* copy global.logrsvs linked list to the end of curproxy->logsrvs */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4877 | list_for_each_entry(tmplogsrv, &global.logsrvs, list) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4878 | struct logsrv *node = malloc(sizeof(struct logsrv)); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4879 | memcpy(node, tmplogsrv, sizeof(struct logsrv)); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4880 | LIST_INIT(&node->list); |
| 4881 | LIST_ADDQ(&curproxy->logsrvs, &node->list); |
| 4882 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4883 | } |
| 4884 | else if (*(args[1]) && *(args[2])) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4885 | |
| 4886 | logsrv = calloc(1, sizeof(struct logsrv)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4887 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4888 | logsrv->facility = get_log_facility(args[2]); |
| 4889 | if (logsrv->facility < 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4890 | 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] | 4891 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4892 | goto out; |
| 4893 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4894 | } |
| 4895 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4896 | logsrv->level = 7; /* max syslog level = debug */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4897 | if (*(args[3])) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4898 | logsrv->level = get_log_level(args[3]); |
| 4899 | if (logsrv->level < 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4900 | 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] | 4901 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4902 | goto out; |
| 4903 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4904 | } |
| 4905 | } |
| 4906 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4907 | logsrv->minlvl = 0; /* limit syslog level to this level (emerg) */ |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 4908 | if (*(args[4])) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4909 | logsrv->minlvl = get_log_level(args[4]); |
| 4910 | if (logsrv->level < 0) { |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 4911 | 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] | 4912 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4913 | goto out; |
| 4914 | |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 4915 | } |
| 4916 | } |
| 4917 | |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 4918 | if (args[1][0] == '/') { |
David du Colombier | 11bcb6c | 2011-03-24 12:23:00 +0100 | [diff] [blame] | 4919 | struct sockaddr_storage *sk = (struct sockaddr_storage *)str2sun(args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4920 | if (!sk) { |
| 4921 | 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] | 4922 | args[1], (int)sizeof(((struct sockaddr_un *)sk)->sun_path) - 1); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4923 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4924 | goto out; |
| 4925 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4926 | logsrv->addr = *sk; |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 4927 | } else { |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4928 | struct sockaddr_storage *sk = str2sa(args[1]); |
David du Colombier | 11bcb6c | 2011-03-24 12:23:00 +0100 | [diff] [blame] | 4929 | if (!sk) { |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4930 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[1]); |
| 4931 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4932 | goto out; |
| 4933 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4934 | logsrv->addr = *sk; |
| 4935 | if (!get_host_port(&logsrv->addr)) |
| 4936 | set_host_port(&logsrv->addr, SYSLOG_PORT); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4937 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4938 | |
| 4939 | LIST_ADDQ(&curproxy->logsrvs, &logsrv->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4940 | } |
| 4941 | else { |
| 4942 | Alert("parsing [%s:%d] : 'log' expects either <address[:port]> and <facility> or 'global' as arguments.\n", |
| 4943 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4944 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4945 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4946 | } |
| 4947 | } |
| 4948 | 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] | 4949 | int cur_arg; |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4950 | struct sockaddr_storage *sk; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4951 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4952 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4953 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4954 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4955 | if (!*args[1]) { |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4956 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optionally '%s' <addr>, and '%s' <name>.\n", |
| 4957 | file, linenum, "source", "usesrc", "interface"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4958 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4959 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4960 | } |
Willy Tarreau | 368480c | 2009-03-01 08:27:21 +0100 | [diff] [blame] | 4961 | |
| 4962 | /* we must first clear any optional default setting */ |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4963 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 4964 | free(curproxy->conn_src.iface_name); |
| 4965 | curproxy->conn_src.iface_name = NULL; |
| 4966 | curproxy->conn_src.iface_len = 0; |
Willy Tarreau | 368480c | 2009-03-01 08:27:21 +0100 | [diff] [blame] | 4967 | |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4968 | sk = str2sa(args[1]); |
| 4969 | if (!sk) { |
| 4970 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[1]); |
| 4971 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4972 | goto out; |
| 4973 | } |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4974 | curproxy->conn_src.source_addr = *sk; |
| 4975 | curproxy->conn_src.opts |= CO_SRC_BIND; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4976 | |
| 4977 | cur_arg = 2; |
| 4978 | while (*(args[cur_arg])) { |
| 4979 | if (!strcmp(args[cur_arg], "usesrc")) { /* address to use outside */ |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4980 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) |
| 4981 | #if !defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4982 | if (!is_addr(&curproxy->conn_src.source_addr)) { |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4983 | Alert("parsing [%s:%d] : '%s' requires an explicit 'source' address.\n", |
| 4984 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4985 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4986 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4987 | } |
| 4988 | #endif |
| 4989 | if (!*args[cur_arg + 1]) { |
| 4990 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n", |
| 4991 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4992 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4993 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4994 | } |
| 4995 | |
| 4996 | if (!strcmp(args[cur_arg + 1], "client")) { |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4997 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 4998 | curproxy->conn_src.opts |= CO_SRC_TPROXY_CLI; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4999 | } else if (!strcmp(args[cur_arg + 1], "clientip")) { |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 5000 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 5001 | curproxy->conn_src.opts |= CO_SRC_TPROXY_CIP; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 5002 | } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) { |
| 5003 | char *name, *end; |
| 5004 | |
| 5005 | name = args[cur_arg+1] + 7; |
| 5006 | while (isspace(*name)) |
| 5007 | name++; |
| 5008 | |
| 5009 | end = name; |
| 5010 | while (*end && !isspace(*end) && *end != ',' && *end != ')') |
| 5011 | end++; |
| 5012 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 5013 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 5014 | curproxy->conn_src.opts |= CO_SRC_TPROXY_DYN; |
| 5015 | curproxy->conn_src.bind_hdr_name = calloc(1, end - name + 1); |
| 5016 | curproxy->conn_src.bind_hdr_len = end - name; |
| 5017 | memcpy(curproxy->conn_src.bind_hdr_name, name, end - name); |
| 5018 | curproxy->conn_src.bind_hdr_name[end-name] = '\0'; |
| 5019 | curproxy->conn_src.bind_hdr_occ = -1; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 5020 | |
| 5021 | /* now look for an occurrence number */ |
| 5022 | while (isspace(*end)) |
| 5023 | end++; |
| 5024 | if (*end == ',') { |
| 5025 | end++; |
| 5026 | name = end; |
| 5027 | if (*end == '-') |
| 5028 | end++; |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 5029 | while (isdigit((int)*end)) |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 5030 | end++; |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 5031 | curproxy->conn_src.bind_hdr_occ = strl2ic(name, end-name); |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 5032 | } |
| 5033 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 5034 | if (curproxy->conn_src.bind_hdr_occ < -MAX_HDR_HISTORY) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 5035 | Alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative" |
| 5036 | " occurrences values smaller than %d.\n", |
| 5037 | file, linenum, MAX_HDR_HISTORY); |
| 5038 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5039 | goto out; |
| 5040 | } |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5041 | } else { |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 5042 | struct sockaddr_storage *sk = str2sa(args[cur_arg + 1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 5043 | if (!sk) { |
| 5044 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[cur_arg + 1]); |
| 5045 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5046 | goto out; |
| 5047 | } |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 5048 | curproxy->conn_src.tproxy_addr = *sk; |
| 5049 | curproxy->conn_src.opts |= CO_SRC_TPROXY_ADDR; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5050 | } |
| 5051 | global.last_checks |= LSTCHK_NETADM; |
| 5052 | #if !defined(CONFIG_HAP_LINUX_TPROXY) |
| 5053 | global.last_checks |= LSTCHK_CTTPROXY; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 5054 | #endif |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5055 | #else /* no TPROXY support */ |
| 5056 | 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] | 5057 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5058 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5059 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5060 | #endif |
| 5061 | cur_arg += 2; |
| 5062 | continue; |
Willy Tarreau | 77074d5 | 2006-11-12 23:57:19 +0100 | [diff] [blame] | 5063 | } |
| 5064 | |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5065 | if (!strcmp(args[cur_arg], "interface")) { /* specifically bind to this interface */ |
| 5066 | #ifdef SO_BINDTODEVICE |
| 5067 | if (!*args[cur_arg + 1]) { |
| 5068 | Alert("parsing [%s:%d] : '%s' : missing interface name.\n", |
| 5069 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5070 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5071 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5072 | } |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 5073 | free(curproxy->conn_src.iface_name); |
| 5074 | curproxy->conn_src.iface_name = strdup(args[cur_arg + 1]); |
| 5075 | curproxy->conn_src.iface_len = strlen(curproxy->conn_src.iface_name); |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5076 | global.last_checks |= LSTCHK_NETADM; |
| 5077 | #else |
| 5078 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 5079 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5080 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5081 | goto out; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 5082 | #endif |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5083 | cur_arg += 2; |
| 5084 | continue; |
| 5085 | } |
| 5086 | 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] | 5087 | file, linenum, args[0], "interface", "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5088 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5089 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 5090 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5091 | } |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 5092 | else if (!strcmp(args[0], "usesrc")) { /* address to use outside: needs "source" first */ |
| 5093 | Alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n", |
| 5094 | file, linenum, "usesrc", "source"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5095 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5096 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 5097 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5098 | 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] | 5099 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5100 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 5101 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5102 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5103 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5104 | } |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5105 | |
| 5106 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5107 | SMP_OPT_DIR_REQ, ACT_REPLACE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5108 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5109 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5110 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5111 | } |
| 5112 | else if (!strcmp(args[0], "reqdel")) { /* delete request header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5113 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5114 | SMP_OPT_DIR_REQ, ACT_REMOVE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5115 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5116 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5117 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5118 | } |
| 5119 | else if (!strcmp(args[0], "reqdeny")) { /* deny a request if a header matches this regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5120 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5121 | SMP_OPT_DIR_REQ, ACT_DENY, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5122 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5123 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5124 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5125 | } |
| 5126 | 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] | 5127 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5128 | SMP_OPT_DIR_REQ, ACT_PASS, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5129 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5130 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5131 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5132 | } |
| 5133 | 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] | 5134 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5135 | SMP_OPT_DIR_REQ, ACT_ALLOW, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5136 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5137 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5138 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5139 | } |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 5140 | 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] | 5141 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5142 | SMP_OPT_DIR_REQ, ACT_TARPIT, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5143 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5144 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5145 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 5146 | } |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5147 | 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] | 5148 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5149 | SMP_OPT_DIR_REQ, ACT_SETBE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5150 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5151 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5152 | goto out; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5153 | } |
| 5154 | 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] | 5155 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5156 | SMP_OPT_DIR_REQ, ACT_SETBE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5157 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5158 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5159 | goto out; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5160 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5161 | 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] | 5162 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5163 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 5164 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5165 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5166 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5167 | } |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5168 | |
| 5169 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5170 | SMP_OPT_DIR_REQ, ACT_REPLACE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5171 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5172 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5173 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5174 | } |
| 5175 | 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] | 5176 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5177 | SMP_OPT_DIR_REQ, ACT_REMOVE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5178 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5179 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5180 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5181 | } |
| 5182 | 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] | 5183 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5184 | SMP_OPT_DIR_REQ, ACT_DENY, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5185 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5186 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5187 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5188 | } |
| 5189 | 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] | 5190 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5191 | SMP_OPT_DIR_REQ, ACT_PASS, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5192 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5193 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5194 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5195 | } |
| 5196 | 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] | 5197 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5198 | SMP_OPT_DIR_REQ, ACT_ALLOW, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5199 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5200 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5201 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5202 | } |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 5203 | 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] | 5204 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5205 | SMP_OPT_DIR_REQ, ACT_TARPIT, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5206 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5207 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5208 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 5209 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5210 | else if (!strcmp(args[0], "reqadd")) { /* add request header */ |
Willy Tarreau | f4f0412 | 2010-01-28 18:10:50 +0100 | [diff] [blame] | 5211 | struct cond_wordlist *wl; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5212 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5213 | if (curproxy == &defproxy) { |
| 5214 | 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] | 5215 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5216 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5217 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5218 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5219 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5220 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5221 | if (*(args[1]) == 0) { |
| 5222 | 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] | 5223 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5224 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5225 | } |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5226 | |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 5227 | if ((strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0)) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 5228 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args+2, &errmsg)) == NULL) { |
| 5229 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 5230 | file, linenum, args[0], errmsg); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 5231 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5232 | goto out; |
| 5233 | } |
| 5234 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
| 5235 | } |
| 5236 | else if (*args[2]) { |
| 5237 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 5238 | file, linenum, args[0], args[2]); |
| 5239 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5240 | goto out; |
| 5241 | } |
| 5242 | |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5243 | wl = calloc(1, sizeof(*wl)); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 5244 | wl->cond = cond; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5245 | wl->s = strdup(args[1]); |
| 5246 | LIST_ADDQ(&curproxy->req_add, &wl->list); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 5247 | warnif_misplaced_reqadd(curproxy, file, linenum, args[0]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5248 | } |
| 5249 | 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] | 5250 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5251 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 5252 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5253 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5254 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5255 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5256 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5257 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5258 | SMP_OPT_DIR_RES, ACT_REPLACE, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5259 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5260 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5261 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5262 | } |
| 5263 | else if (!strcmp(args[0], "rspdel")) { /* delete response header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5264 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5265 | SMP_OPT_DIR_RES, ACT_REMOVE, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5266 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5267 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5268 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5269 | } |
| 5270 | else if (!strcmp(args[0], "rspdeny")) { /* block response header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5271 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5272 | SMP_OPT_DIR_RES, ACT_DENY, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5273 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5274 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5275 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5276 | } |
| 5277 | 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] | 5278 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5279 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 5280 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5281 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5282 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5283 | } |
| 5284 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5285 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5286 | SMP_OPT_DIR_RES, ACT_REPLACE, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5287 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5288 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5289 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5290 | } |
| 5291 | 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] | 5292 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5293 | SMP_OPT_DIR_RES, ACT_REMOVE, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5294 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5295 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5296 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5297 | } |
| 5298 | 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] | 5299 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5300 | SMP_OPT_DIR_RES, ACT_DENY, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5301 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5302 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5303 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5304 | } |
| 5305 | else if (!strcmp(args[0], "rspadd")) { /* add response header */ |
Willy Tarreau | f4f0412 | 2010-01-28 18:10:50 +0100 | [diff] [blame] | 5306 | struct cond_wordlist *wl; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5307 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5308 | if (curproxy == &defproxy) { |
| 5309 | 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] | 5310 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5311 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5312 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5313 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5314 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5315 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5316 | if (*(args[1]) == 0) { |
| 5317 | 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] | 5318 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5319 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5320 | } |
| 5321 | |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5322 | if ((strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0)) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 5323 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args+2, &errmsg)) == NULL) { |
| 5324 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 5325 | file, linenum, args[0], errmsg); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5326 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5327 | goto out; |
| 5328 | } |
| 5329 | err_code |= warnif_cond_requires_req(cond, file, linenum); |
| 5330 | } |
| 5331 | else if (*args[2]) { |
| 5332 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 5333 | file, linenum, args[0], args[2]); |
| 5334 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5335 | goto out; |
| 5336 | } |
| 5337 | |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5338 | wl = calloc(1, sizeof(*wl)); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5339 | wl->cond = cond; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5340 | wl->s = strdup(args[1]); |
| 5341 | LIST_ADDQ(&curproxy->rsp_add, &wl->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5342 | } |
| 5343 | else if (!strcmp(args[0], "errorloc") || |
| 5344 | !strcmp(args[0], "errorloc302") || |
| 5345 | !strcmp(args[0], "errorloc303")) { /* error location */ |
| 5346 | int errnum, errlen; |
| 5347 | char *err; |
| 5348 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5349 | 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] | 5350 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5351 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5352 | if (*(args[2]) == 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 5353 | 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] | 5354 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5355 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5356 | } |
| 5357 | |
| 5358 | errnum = atol(args[1]); |
| 5359 | if (!strcmp(args[0], "errorloc303")) { |
| 5360 | err = malloc(strlen(HTTP_303) + strlen(args[2]) + 5); |
| 5361 | errlen = sprintf(err, "%s%s\r\n\r\n", HTTP_303, args[2]); |
| 5362 | } else { |
| 5363 | err = malloc(strlen(HTTP_302) + strlen(args[2]) + 5); |
| 5364 | errlen = sprintf(err, "%s%s\r\n\r\n", HTTP_302, args[2]); |
| 5365 | } |
| 5366 | |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 5367 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) { |
| 5368 | if (http_err_codes[rc] == errnum) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 5369 | chunk_destroy(&curproxy->errmsg[rc]); |
| 5370 | chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 5371 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5372 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5373 | } |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 5374 | |
| 5375 | if (rc >= HTTP_ERR_SIZE) { |
| 5376 | Warning("parsing [%s:%d] : status code %d not handled, error relocation will be ignored.\n", |
| 5377 | file, linenum, errnum); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5378 | free(err); |
| 5379 | } |
| 5380 | } |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5381 | else if (!strcmp(args[0], "errorfile")) { /* error message from a file */ |
| 5382 | int errnum, errlen, fd; |
| 5383 | char *err; |
| 5384 | struct stat stat; |
| 5385 | |
| 5386 | 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] | 5387 | err_code |= ERR_WARN; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5388 | |
| 5389 | if (*(args[2]) == 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 5390 | 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] | 5391 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5392 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5393 | } |
| 5394 | |
| 5395 | fd = open(args[2], O_RDONLY); |
| 5396 | if ((fd < 0) || (fstat(fd, &stat) < 0)) { |
| 5397 | Alert("parsing [%s:%d] : error opening file <%s> for custom error message <%s>.\n", |
| 5398 | file, linenum, args[2], args[1]); |
| 5399 | if (fd >= 0) |
| 5400 | close(fd); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5401 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5402 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5403 | } |
| 5404 | |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 5405 | if (stat.st_size <= global.tune.bufsize) { |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5406 | errlen = stat.st_size; |
| 5407 | } else { |
| 5408 | 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] | 5409 | file, linenum, args[2], global.tune.bufsize); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5410 | err_code |= ERR_WARN; |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 5411 | errlen = global.tune.bufsize; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5412 | } |
| 5413 | |
| 5414 | err = malloc(errlen); /* malloc() must succeed during parsing */ |
| 5415 | errnum = read(fd, err, errlen); |
| 5416 | if (errnum != errlen) { |
| 5417 | Alert("parsing [%s:%d] : error reading file <%s> for custom error message <%s>.\n", |
| 5418 | file, linenum, args[2], args[1]); |
| 5419 | close(fd); |
| 5420 | free(err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5421 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5422 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5423 | } |
| 5424 | close(fd); |
| 5425 | |
| 5426 | errnum = atol(args[1]); |
| 5427 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) { |
| 5428 | if (http_err_codes[rc] == errnum) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 5429 | chunk_destroy(&curproxy->errmsg[rc]); |
| 5430 | chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen); |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5431 | break; |
| 5432 | } |
| 5433 | } |
| 5434 | |
| 5435 | if (rc >= HTTP_ERR_SIZE) { |
| 5436 | Warning("parsing [%s:%d] : status code %d not handled, error customization will be ignored.\n", |
| 5437 | file, linenum, errnum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5438 | err_code |= ERR_WARN; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5439 | free(err); |
| 5440 | } |
| 5441 | } |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5442 | else if (!strcmp(args[0], "compression")) { |
| 5443 | struct comp *comp; |
| 5444 | if (curproxy->comp == NULL) { |
| 5445 | comp = calloc(1, sizeof(struct comp)); |
| 5446 | curproxy->comp = comp; |
| 5447 | } else { |
| 5448 | comp = curproxy->comp; |
| 5449 | } |
| 5450 | |
| 5451 | if (!strcmp(args[1], "algo")) { |
| 5452 | int cur_arg; |
William Lallemand | 8b52bb3 | 2012-11-16 18:06:41 +0100 | [diff] [blame] | 5453 | struct comp_ctx *ctx; |
William Lallemand | 552df67 | 2012-11-07 13:21:47 +0100 | [diff] [blame] | 5454 | |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5455 | cur_arg = 2; |
| 5456 | if (!*args[cur_arg]) { |
| 5457 | Alert("parsing [%s:%d] : '%s' expects <algorithm>\n", |
| 5458 | file, linenum, args[0]); |
| 5459 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5460 | goto out; |
| 5461 | } |
| 5462 | while (*(args[cur_arg])) { |
| 5463 | if (comp_append_algo(comp, args[cur_arg]) < 0) { |
| 5464 | Alert("parsing [%s:%d] : '%s' : '%s' is not a supported algorithm.\n", |
| 5465 | file, linenum, args[0], args[cur_arg]); |
| 5466 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5467 | goto out; |
| 5468 | } |
William Lallemand | 552df67 | 2012-11-07 13:21:47 +0100 | [diff] [blame] | 5469 | if (curproxy->comp->algos->init(&ctx, 9) == 0) { |
| 5470 | curproxy->comp->algos->end(&ctx); |
| 5471 | } else { |
| 5472 | Alert("parsing [%s:%d] : '%s' : Can't init '%s' algorithm.\n", |
| 5473 | file, linenum, args[0], args[cur_arg]); |
| 5474 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5475 | goto out; |
| 5476 | } |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5477 | cur_arg ++; |
| 5478 | continue; |
| 5479 | } |
| 5480 | } |
Willy Tarreau | 70737d1 | 2012-10-27 00:34:28 +0200 | [diff] [blame] | 5481 | else if (!strcmp(args[1], "offload")) { |
| 5482 | comp->offload = 1; |
| 5483 | } |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5484 | else if (!strcmp(args[1], "type")) { |
| 5485 | int cur_arg; |
| 5486 | cur_arg = 2; |
| 5487 | if (!*args[cur_arg]) { |
| 5488 | Alert("parsing [%s:%d] : '%s' expects <type>\n", |
| 5489 | file, linenum, args[0]); |
| 5490 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5491 | goto out; |
| 5492 | } |
| 5493 | while (*(args[cur_arg])) { |
| 5494 | comp_append_type(comp, args[cur_arg]); |
| 5495 | cur_arg ++; |
| 5496 | continue; |
| 5497 | } |
| 5498 | } |
| 5499 | else { |
Willy Tarreau | 70737d1 | 2012-10-27 00:34:28 +0200 | [diff] [blame] | 5500 | Alert("parsing [%s:%d] : '%s' expects 'algo', 'type' or 'offload'\n", |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5501 | file, linenum, args[0]); |
| 5502 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5503 | goto out; |
| 5504 | } |
| 5505 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5506 | else { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 5507 | struct cfg_kw_list *kwl; |
| 5508 | int index; |
| 5509 | |
| 5510 | list_for_each_entry(kwl, &cfg_keywords.list, list) { |
| 5511 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 5512 | if (kwl->kw[index].section != CFG_LISTEN) |
| 5513 | continue; |
| 5514 | if (strcmp(kwl->kw[index].kw, args[0]) == 0) { |
| 5515 | /* prepare error message just in case */ |
Willy Tarreau | 28a47d6 | 2012-09-18 20:02:48 +0200 | [diff] [blame] | 5516 | 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] | 5517 | if (rc < 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 5518 | Alert("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5519 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5520 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 5521 | } |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 5522 | else if (rc > 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 5523 | Warning("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5524 | err_code |= ERR_WARN; |
| 5525 | goto out; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 5526 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5527 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 5528 | } |
| 5529 | } |
| 5530 | } |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5531 | |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5532 | 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] | 5533 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5534 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5535 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5536 | out: |
Willy Tarreau | f4068b6 | 2012-05-08 17:37:49 +0200 | [diff] [blame] | 5537 | free(errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5538 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5539 | } |
| 5540 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5541 | int |
| 5542 | cfg_parse_users(const char *file, int linenum, char **args, int kwm) |
| 5543 | { |
| 5544 | |
| 5545 | int err_code = 0; |
| 5546 | const char *err; |
| 5547 | |
| 5548 | if (!strcmp(args[0], "userlist")) { /* new userlist */ |
| 5549 | struct userlist *newul; |
| 5550 | |
| 5551 | if (!*args[1]) { |
| 5552 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 5553 | file, linenum, args[0]); |
| 5554 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5555 | goto out; |
| 5556 | } |
| 5557 | |
| 5558 | err = invalid_char(args[1]); |
| 5559 | if (err) { |
| 5560 | Alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 5561 | file, linenum, *err, args[0], args[1]); |
| 5562 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5563 | goto out; |
| 5564 | } |
| 5565 | |
| 5566 | for (newul = userlist; newul; newul = newul->next) |
| 5567 | if (!strcmp(newul->name, args[1])) { |
| 5568 | Warning("parsing [%s:%d]: ignoring duplicated userlist '%s'.\n", |
| 5569 | file, linenum, args[1]); |
| 5570 | err_code |= ERR_WARN; |
| 5571 | goto out; |
| 5572 | } |
| 5573 | |
| 5574 | newul = (struct userlist *)calloc(1, sizeof(struct userlist)); |
| 5575 | if (!newul) { |
| 5576 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 5577 | err_code |= ERR_ALERT | ERR_ABORT; |
| 5578 | goto out; |
| 5579 | } |
| 5580 | |
| 5581 | newul->groupusers = calloc(MAX_AUTH_GROUPS, sizeof(char *)); |
| 5582 | newul->name = strdup(args[1]); |
| 5583 | |
| 5584 | if (!newul->groupusers | !newul->name) { |
| 5585 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 5586 | err_code |= ERR_ALERT | ERR_ABORT; |
| 5587 | goto out; |
| 5588 | } |
| 5589 | |
| 5590 | newul->next = userlist; |
| 5591 | userlist = newul; |
| 5592 | |
| 5593 | } else if (!strcmp(args[0], "group")) { /* new group */ |
| 5594 | int cur_arg, i; |
| 5595 | const char *err; |
| 5596 | |
| 5597 | if (!*args[1]) { |
| 5598 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 5599 | file, linenum, args[0]); |
| 5600 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5601 | goto out; |
| 5602 | } |
| 5603 | |
| 5604 | err = invalid_char(args[1]); |
| 5605 | if (err) { |
| 5606 | Alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 5607 | file, linenum, *err, args[0], args[1]); |
| 5608 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5609 | goto out; |
| 5610 | } |
| 5611 | |
| 5612 | for(i = 0; i < userlist->grpcnt; i++) |
| 5613 | if (!strcmp(userlist->groups[i], args[1])) { |
| 5614 | Warning("parsing [%s:%d]: ignoring duplicated group '%s' in userlist '%s'.\n", |
| 5615 | file, linenum, args[1], userlist->name); |
| 5616 | err_code |= ERR_ALERT; |
| 5617 | goto out; |
| 5618 | } |
| 5619 | |
| 5620 | if (userlist->grpcnt >= MAX_AUTH_GROUPS) { |
| 5621 | Alert("parsing [%s:%d]: too many groups (%u) in in userlist '%s' while adding group '%s'.\n", |
| 5622 | file, linenum, MAX_AUTH_GROUPS, userlist->name, args[1]); |
| 5623 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5624 | goto out; |
| 5625 | } |
| 5626 | |
| 5627 | cur_arg = 2; |
| 5628 | |
| 5629 | while (*args[cur_arg]) { |
| 5630 | if (!strcmp(args[cur_arg], "users")) { |
| 5631 | userlist->groupusers[userlist->grpcnt] = strdup(args[cur_arg + 1]); |
| 5632 | cur_arg += 2; |
| 5633 | continue; |
| 5634 | } else { |
| 5635 | Alert("parsing [%s:%d]: '%s' only supports 'users' option.\n", |
| 5636 | file, linenum, args[0]); |
| 5637 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5638 | goto out; |
| 5639 | } |
| 5640 | } |
| 5641 | |
| 5642 | userlist->groups[userlist->grpcnt++] = strdup(args[1]); |
| 5643 | } else if (!strcmp(args[0], "user")) { /* new user */ |
| 5644 | struct auth_users *newuser; |
| 5645 | int cur_arg; |
| 5646 | |
| 5647 | if (!*args[1]) { |
| 5648 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 5649 | file, linenum, args[0]); |
| 5650 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5651 | goto out; |
| 5652 | } |
| 5653 | |
| 5654 | for (newuser = userlist->users; newuser; newuser = newuser->next) |
| 5655 | if (!strcmp(newuser->user, args[1])) { |
| 5656 | Warning("parsing [%s:%d]: ignoring duplicated user '%s' in userlist '%s'.\n", |
| 5657 | file, linenum, args[1], userlist->name); |
| 5658 | err_code |= ERR_ALERT; |
| 5659 | goto out; |
| 5660 | } |
| 5661 | |
| 5662 | newuser = (struct auth_users *)calloc(1, sizeof(struct auth_users)); |
| 5663 | if (!newuser) { |
| 5664 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 5665 | err_code |= ERR_ALERT | ERR_ABORT; |
| 5666 | goto out; |
| 5667 | } |
| 5668 | |
| 5669 | newuser->user = strdup(args[1]); |
| 5670 | |
| 5671 | newuser->next = userlist->users; |
| 5672 | userlist->users = newuser; |
| 5673 | |
| 5674 | cur_arg = 2; |
| 5675 | |
| 5676 | while (*args[cur_arg]) { |
| 5677 | if (!strcmp(args[cur_arg], "password")) { |
| 5678 | #ifndef CONFIG_HAP_CRYPT |
| 5679 | Warning("parsing [%s:%d]: no crypt(3) support compiled, encrypted passwords will not work.\n", |
| 5680 | file, linenum); |
| 5681 | err_code |= ERR_ALERT; |
| 5682 | #endif |
| 5683 | newuser->pass = strdup(args[cur_arg + 1]); |
| 5684 | cur_arg += 2; |
| 5685 | continue; |
| 5686 | } else if (!strcmp(args[cur_arg], "insecure-password")) { |
| 5687 | newuser->pass = strdup(args[cur_arg + 1]); |
| 5688 | newuser->flags |= AU_O_INSECURE; |
| 5689 | cur_arg += 2; |
| 5690 | continue; |
| 5691 | } else if (!strcmp(args[cur_arg], "groups")) { |
Willy Tarreau | b4c06b7 | 2010-02-02 11:28:20 +0100 | [diff] [blame] | 5692 | newuser->u.groups = strdup(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5693 | cur_arg += 2; |
| 5694 | continue; |
| 5695 | } else { |
| 5696 | Alert("parsing [%s:%d]: '%s' only supports 'password', 'insecure-password' and 'groups' options.\n", |
| 5697 | file, linenum, args[0]); |
| 5698 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5699 | goto out; |
| 5700 | } |
| 5701 | } |
| 5702 | } else { |
| 5703 | Alert("parsing [%s:%d]: unknown keyword '%s' in '%s' section\n", file, linenum, args[0], "users"); |
| 5704 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5705 | } |
| 5706 | |
| 5707 | out: |
| 5708 | return err_code; |
| 5709 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5710 | |
| 5711 | /* |
| 5712 | * This function reads and parses the configuration file given in the argument. |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5713 | * Returns the error code, 0 if OK, or any combination of : |
| 5714 | * - ERR_ABORT: must abort ASAP |
| 5715 | * - ERR_FATAL: we can continue parsing but not start the service |
| 5716 | * - ERR_WARN: a warning has been emitted |
| 5717 | * - ERR_ALERT: an alert has been emitted |
| 5718 | * Only the two first ones can stop processing, the two others are just |
| 5719 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5720 | */ |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 5721 | int readcfgfile(const char *file) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5722 | { |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5723 | char thisline[LINESIZE]; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5724 | FILE *f; |
| 5725 | int linenum = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5726 | int confsect = CFG_NONE; |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5727 | int err_code = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5728 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5729 | if ((f=fopen(file,"r")) == NULL) |
| 5730 | return -1; |
| 5731 | |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5732 | while (fgets(thisline, sizeof(thisline), f) != NULL) { |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 5733 | int arg, kwm = KWM_STD; |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5734 | char *end; |
| 5735 | char *args[MAX_LINE_ARGS + 1]; |
| 5736 | char *line = thisline; |
| 5737 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5738 | linenum++; |
| 5739 | |
| 5740 | end = line + strlen(line); |
| 5741 | |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5742 | if (end-line == sizeof(thisline)-1 && *(end-1) != '\n') { |
| 5743 | /* Check if we reached the limit and the last char is not \n. |
| 5744 | * Watch out for the last line without the terminating '\n'! |
| 5745 | */ |
| 5746 | Alert("parsing [%s:%d]: line too long, limit: %d.\n", |
Willy Tarreau | 5e4a6f1 | 2009-04-11 19:42:49 +0200 | [diff] [blame] | 5747 | file, linenum, (int)sizeof(thisline)-1); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5748 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5749 | } |
| 5750 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5751 | /* skip leading spaces */ |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 5752 | while (isspace((unsigned char)*line)) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5753 | line++; |
| 5754 | |
| 5755 | arg = 0; |
| 5756 | args[arg] = line; |
| 5757 | |
| 5758 | while (*line && arg < MAX_LINE_ARGS) { |
| 5759 | /* first, we'll replace \\, \<space>, \#, \r, \n, \t, \xXX with their |
| 5760 | * C equivalent value. Other combinations left unchanged (eg: \1). |
| 5761 | */ |
| 5762 | if (*line == '\\') { |
| 5763 | int skip = 0; |
| 5764 | if (line[1] == ' ' || line[1] == '\\' || line[1] == '#') { |
| 5765 | *line = line[1]; |
| 5766 | skip = 1; |
| 5767 | } |
| 5768 | else if (line[1] == 'r') { |
| 5769 | *line = '\r'; |
| 5770 | skip = 1; |
| 5771 | } |
| 5772 | else if (line[1] == 'n') { |
| 5773 | *line = '\n'; |
| 5774 | skip = 1; |
| 5775 | } |
| 5776 | else if (line[1] == 't') { |
| 5777 | *line = '\t'; |
| 5778 | skip = 1; |
| 5779 | } |
| 5780 | else if (line[1] == 'x') { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5781 | if ((line + 3 < end) && ishex(line[2]) && ishex(line[3])) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5782 | unsigned char hex1, hex2; |
| 5783 | hex1 = toupper(line[2]) - '0'; |
| 5784 | hex2 = toupper(line[3]) - '0'; |
| 5785 | if (hex1 > 9) hex1 -= 'A' - '9' - 1; |
| 5786 | if (hex2 > 9) hex2 -= 'A' - '9' - 1; |
| 5787 | *line = (hex1<<4) + hex2; |
| 5788 | skip = 3; |
| 5789 | } |
| 5790 | else { |
| 5791 | 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] | 5792 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5793 | } |
| 5794 | } |
| 5795 | if (skip) { |
Cyril Bonté | dd1b01d | 2009-12-06 13:43:42 +0100 | [diff] [blame] | 5796 | memmove(line + 1, line + 1 + skip, end - (line + skip)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5797 | end -= skip; |
| 5798 | } |
| 5799 | line++; |
| 5800 | } |
| 5801 | else if (*line == '#' || *line == '\n' || *line == '\r') { |
| 5802 | /* end of string, end of loop */ |
| 5803 | *line = 0; |
| 5804 | break; |
| 5805 | } |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 5806 | else if (isspace((unsigned char)*line)) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5807 | /* a non-escaped space is an argument separator */ |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5808 | *line++ = '\0'; |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 5809 | while (isspace((unsigned char)*line)) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5810 | line++; |
| 5811 | args[++arg] = line; |
| 5812 | } |
| 5813 | else { |
| 5814 | line++; |
| 5815 | } |
| 5816 | } |
| 5817 | |
| 5818 | /* empty line */ |
| 5819 | if (!**args) |
| 5820 | continue; |
| 5821 | |
Willy Tarreau | 7bb651e | 2009-11-09 21:16:53 +0100 | [diff] [blame] | 5822 | if (*line) { |
| 5823 | /* we had to stop due to too many args. |
| 5824 | * Let's terminate the string, print the offending part then cut the |
| 5825 | * last arg. |
| 5826 | */ |
| 5827 | while (*line && *line != '#' && *line != '\n' && *line != '\r') |
| 5828 | line++; |
| 5829 | *line = '\0'; |
| 5830 | |
Krzysztof Piotr Oledzki | 500b8f0 | 2009-12-15 22:34:51 +0100 | [diff] [blame] | 5831 | 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] | 5832 | file, linenum, arg + 1, (long)(args[arg] - thisline + 1), args[arg]); |
Willy Tarreau | 7bb651e | 2009-11-09 21:16:53 +0100 | [diff] [blame] | 5833 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5834 | args[arg] = line; |
| 5835 | } |
| 5836 | |
Willy Tarreau | 540abe4 | 2007-05-02 20:50:16 +0200 | [diff] [blame] | 5837 | /* zero out remaining args and ensure that at least one entry |
| 5838 | * is zeroed out. |
| 5839 | */ |
| 5840 | while (++arg <= MAX_LINE_ARGS) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5841 | args[arg] = line; |
| 5842 | } |
| 5843 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 5844 | /* check for keyword modifiers "no" and "default" */ |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5845 | if (!strcmp(args[0], "no")) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5846 | char *tmp; |
| 5847 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 5848 | kwm = KWM_NO; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5849 | tmp = args[0]; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5850 | for (arg=0; *args[arg+1]; arg++) |
| 5851 | args[arg] = args[arg+1]; // shift args after inversion |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5852 | *tmp = '\0'; // fix the next arg to \0 |
| 5853 | args[arg] = tmp; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5854 | } |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 5855 | else if (!strcmp(args[0], "default")) { |
| 5856 | kwm = KWM_DEF; |
| 5857 | for (arg=0; *args[arg+1]; arg++) |
| 5858 | args[arg] = args[arg+1]; // shift args after inversion |
| 5859 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5860 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5861 | if (kwm != KWM_STD && strcmp(args[0], "option") != 0 && \ |
| 5862 | strcmp(args[0], "log") != 0) { |
| 5863 | 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] | 5864 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5865 | } |
| 5866 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5867 | if (!strcmp(args[0], "listen") || |
| 5868 | !strcmp(args[0], "frontend") || |
| 5869 | !strcmp(args[0], "backend") || |
| 5870 | !strcmp(args[0], "ruleset") || |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5871 | !strcmp(args[0], "defaults")) { /* new proxy */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5872 | confsect = CFG_LISTEN; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 5873 | free(cursection); |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5874 | cursection = strdup(args[0]); |
| 5875 | } |
| 5876 | else if (!strcmp(args[0], "global")) { /* global config */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5877 | confsect = CFG_GLOBAL; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 5878 | free(cursection); |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5879 | cursection = strdup(args[0]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 5880 | } |
| 5881 | else if (!strcmp(args[0], "userlist")) { |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5882 | confsect = CFG_USERLIST; |
| 5883 | free(cursection); |
| 5884 | cursection = strdup(args[0]); |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5885 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 5886 | else if (!strcmp(args[0], "peers")) { |
| 5887 | confsect = CFG_PEERS; |
| 5888 | free(cursection); |
| 5889 | cursection = strdup(args[0]); |
| 5890 | } |
| 5891 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5892 | /* else it's a section keyword */ |
| 5893 | |
| 5894 | switch (confsect) { |
| 5895 | case CFG_LISTEN: |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5896 | err_code |= cfg_parse_listen(file, linenum, args, kwm); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5897 | break; |
| 5898 | case CFG_GLOBAL: |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5899 | err_code |= cfg_parse_global(file, linenum, args, kwm); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5900 | break; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5901 | case CFG_USERLIST: |
| 5902 | err_code |= cfg_parse_users(file, linenum, args, kwm); |
| 5903 | break; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 5904 | case CFG_PEERS: |
| 5905 | err_code |= cfg_parse_peers(file, linenum, args, kwm); |
| 5906 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5907 | default: |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5908 | 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] | 5909 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5910 | } |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5911 | |
| 5912 | if (err_code & ERR_ABORT) |
| 5913 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5914 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 5915 | free(cursection); |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5916 | cursection = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5917 | fclose(f); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5918 | return err_code; |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5919 | } |
| 5920 | |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 5921 | /* |
| 5922 | * Returns the error code, 0 if OK, or any combination of : |
| 5923 | * - ERR_ABORT: must abort ASAP |
| 5924 | * - ERR_FATAL: we can continue parsing but not start the service |
| 5925 | * - ERR_WARN: a warning has been emitted |
| 5926 | * - ERR_ALERT: an alert has been emitted |
| 5927 | * Only the two first ones can stop processing, the two others are just |
| 5928 | * indicators. |
| 5929 | */ |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5930 | int check_config_validity() |
| 5931 | { |
| 5932 | int cfgerr = 0; |
| 5933 | struct proxy *curproxy = NULL; |
| 5934 | struct server *newsrv = NULL; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5935 | struct userlist *curuserlist = NULL; |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 5936 | int err_code = 0; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 5937 | unsigned int next_pxid = 1; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 5938 | struct bind_conf *bind_conf; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5939 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 5940 | bind_conf = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5941 | /* |
| 5942 | * Now, check for the integrity of all that we have collected. |
| 5943 | */ |
| 5944 | |
| 5945 | /* will be needed further to delay some tasks */ |
Willy Tarreau | b0b37bc | 2008-06-23 14:00:57 +0200 | [diff] [blame] | 5946 | tv_update_date(0,1); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5947 | |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 5948 | if (!global.tune.max_http_hdr) |
| 5949 | global.tune.max_http_hdr = MAX_HTTP_HDR; |
| 5950 | |
| 5951 | if (!global.tune.cookie_len) |
| 5952 | global.tune.cookie_len = CAPTURE_LEN; |
| 5953 | |
| 5954 | pool2_capture = create_pool("capture", global.tune.cookie_len, MEM_F_SHARED); |
| 5955 | |
Willy Tarreau | 55bc0f8 | 2009-03-15 14:51:53 +0100 | [diff] [blame] | 5956 | /* first, we will invert the proxy list order */ |
| 5957 | curproxy = NULL; |
| 5958 | while (proxy) { |
| 5959 | struct proxy *next; |
| 5960 | |
| 5961 | next = proxy->next; |
| 5962 | proxy->next = curproxy; |
| 5963 | curproxy = proxy; |
| 5964 | if (!next) |
| 5965 | break; |
| 5966 | proxy = next; |
| 5967 | } |
| 5968 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5969 | while (curproxy != NULL) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 5970 | struct switching_rule *rule; |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 5971 | struct server_rule *srule; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5972 | struct sticking_rule *mrule; |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 5973 | struct tcp_rule *trule; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 5974 | struct listener *listener; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 5975 | unsigned int next_id; |
Willy Tarreau | 16a2147 | 2012-11-19 12:39:59 +0100 | [diff] [blame] | 5976 | int nbproc; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 5977 | |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 5978 | if (curproxy->uuid < 0) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 5979 | /* proxy ID not set, use automatic numbering with first |
| 5980 | * spare entry starting with next_pxid. |
| 5981 | */ |
| 5982 | next_pxid = get_next_id(&used_proxy_id, next_pxid); |
| 5983 | curproxy->conf.id.key = curproxy->uuid = next_pxid; |
| 5984 | eb32_insert(&used_proxy_id, &curproxy->conf.id); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 5985 | } |
Krzysztof Piotr Oledzki | df5cb9f | 2010-02-05 20:58:27 +0100 | [diff] [blame] | 5986 | next_pxid++; |
| 5987 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 5988 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5989 | if (curproxy->state == PR_STSTOPPED) { |
Willy Tarreau | da250db | 2008-10-12 12:07:48 +0200 | [diff] [blame] | 5990 | /* ensure we don't keep listeners uselessly bound */ |
| 5991 | stop_proxy(curproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5992 | curproxy = curproxy->next; |
| 5993 | continue; |
| 5994 | } |
| 5995 | |
Willy Tarreau | 16a2147 | 2012-11-19 12:39:59 +0100 | [diff] [blame] | 5996 | /* number of processes this proxy is bound to */ |
| 5997 | nbproc = curproxy->bind_proc ? popcount(curproxy->bind_proc) : global.nbproc; |
| 5998 | |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 5999 | switch (curproxy->mode) { |
| 6000 | case PR_MODE_HEALTH: |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6001 | cfgerr += proxy_cfg_ensure_no_http(curproxy); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 6002 | if (!(curproxy->cap & PR_CAP_FE)) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6003 | Alert("config : %s '%s' cannot be in health mode as it has no frontend capability.\n", |
| 6004 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 6005 | cfgerr++; |
| 6006 | } |
| 6007 | |
| 6008 | if (curproxy->srv != NULL) |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6009 | Warning("config : servers will be ignored for %s '%s'.\n", |
| 6010 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 6011 | break; |
| 6012 | |
| 6013 | case PR_MODE_TCP: |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6014 | cfgerr += proxy_cfg_ensure_no_http(curproxy); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 6015 | break; |
| 6016 | |
| 6017 | case PR_MODE_HTTP: |
Willy Tarreau | a9fb083 | 2009-07-10 20:53:53 +0200 | [diff] [blame] | 6018 | curproxy->acl_requires |= ACL_USE_L7_ANY; |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 6019 | break; |
| 6020 | } |
| 6021 | |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 6022 | if ((curproxy->cap & PR_CAP_BE) && (curproxy->mode != PR_MODE_HEALTH)) { |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6023 | if (curproxy->lbprm.algo & BE_LB_KIND) { |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 6024 | if (curproxy->options & PR_O_TRANSP) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6025 | Alert("config : %s '%s' cannot use both transparent and balance mode.\n", |
| 6026 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 6027 | cfgerr++; |
| 6028 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6029 | #ifdef WE_DONT_SUPPORT_SERVERLESS_LISTENERS |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 6030 | else if (curproxy->srv == NULL) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6031 | Alert("config : %s '%s' needs at least 1 server in balance mode.\n", |
| 6032 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 6033 | cfgerr++; |
| 6034 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6035 | #endif |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 6036 | else if (curproxy->options & PR_O_DISPATCH) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6037 | Warning("config : dispatch address of %s '%s' will be ignored in balance mode.\n", |
| 6038 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6039 | err_code |= ERR_WARN; |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 6040 | } |
| 6041 | } |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 6042 | 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] | 6043 | /* If no LB algo is set in a backend, and we're not in |
| 6044 | * transparent mode, dispatch mode nor proxy mode, we |
| 6045 | * want to use balance roundrobin by default. |
| 6046 | */ |
| 6047 | curproxy->lbprm.algo &= ~BE_LB_ALGO; |
| 6048 | curproxy->lbprm.algo |= BE_LB_ALGO_RR; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6049 | } |
| 6050 | } |
Willy Tarreau | 193cf93 | 2007-09-17 10:17:23 +0200 | [diff] [blame] | 6051 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 6052 | if (curproxy->options & PR_O_DISPATCH) |
| 6053 | curproxy->options &= ~(PR_O_TRANSP | PR_O_HTTP_PROXY); |
| 6054 | else if (curproxy->options & PR_O_HTTP_PROXY) |
| 6055 | curproxy->options &= ~(PR_O_DISPATCH | PR_O_TRANSP); |
| 6056 | else if (curproxy->options & PR_O_TRANSP) |
| 6057 | curproxy->options &= ~(PR_O_DISPATCH | PR_O_HTTP_PROXY); |
Willy Tarreau | 8293658 | 2007-11-30 15:20:09 +0100 | [diff] [blame] | 6058 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 6059 | if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_HTTP_CHK) { |
| 6060 | if (curproxy->options & PR_O_DISABLE404) { |
| 6061 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n", |
| 6062 | "disable-on-404", proxy_type_str(curproxy), curproxy->id); |
| 6063 | err_code |= ERR_WARN; |
| 6064 | curproxy->options &= ~PR_O_DISABLE404; |
| 6065 | } |
| 6066 | if (curproxy->options2 & PR_O2_CHK_SNDST) { |
| 6067 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n", |
| 6068 | "send-state", proxy_type_str(curproxy), curproxy->id); |
| 6069 | err_code |= ERR_WARN; |
| 6070 | curproxy->options &= ~PR_O2_CHK_SNDST; |
| 6071 | } |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 6072 | } |
| 6073 | |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 6074 | /* if a default backend was specified, let's find it */ |
| 6075 | if (curproxy->defbe.name) { |
| 6076 | struct proxy *target; |
| 6077 | |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 6078 | target = findproxy_mode(curproxy->defbe.name, curproxy->mode, PR_CAP_BE); |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6079 | if (!target) { |
| 6080 | Alert("Proxy '%s': unable to find required default_backend: '%s'.\n", |
| 6081 | curproxy->id, curproxy->defbe.name); |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 6082 | cfgerr++; |
| 6083 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6084 | Alert("Proxy '%s': loop detected for default_backend: '%s'.\n", |
| 6085 | curproxy->id, curproxy->defbe.name); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6086 | cfgerr++; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 6087 | } else { |
| 6088 | free(curproxy->defbe.name); |
| 6089 | curproxy->defbe.be = target; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 6090 | /* we force the backend to be present on at least all of |
| 6091 | * the frontend's processes. |
| 6092 | */ |
| 6093 | target->bind_proc = curproxy->bind_proc ? |
| 6094 | (target->bind_proc | curproxy->bind_proc) : 0; |
Willy Tarreau | ff67813 | 2012-02-13 14:32:34 +0100 | [diff] [blame] | 6095 | |
| 6096 | /* Emit a warning if this proxy also has some servers */ |
| 6097 | if (curproxy->srv) { |
| 6098 | Warning("In proxy '%s', the 'default_backend' rule always has precedence over the servers, which will never be used.\n", |
| 6099 | curproxy->id); |
| 6100 | err_code |= ERR_WARN; |
| 6101 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6102 | } |
| 6103 | } |
| 6104 | |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 6105 | /* find the target proxy in setbe */ |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 6106 | if (curproxy->mode == PR_MODE_HTTP && curproxy->req_exp != NULL) { |
| 6107 | /* map jump target for ACT_SETBE in req_rep chain */ |
| 6108 | struct hdr_exp *exp; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 6109 | for (exp = curproxy->req_exp; exp != NULL; exp = exp->next) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6110 | struct proxy *target; |
| 6111 | |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 6112 | if (exp->action != ACT_SETBE) |
| 6113 | continue; |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6114 | |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 6115 | target = findproxy_mode(exp->replace, PR_MODE_HTTP, PR_CAP_BE); |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6116 | if (!target) { |
| 6117 | Alert("Proxy '%s': unable to find required setbe: '%s'.\n", |
| 6118 | curproxy->id, exp->replace); |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 6119 | cfgerr++; |
| 6120 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6121 | Alert("Proxy '%s': loop detected for setbe: '%s'.\n", |
| 6122 | curproxy->id, exp->replace); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 6123 | cfgerr++; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 6124 | } else { |
| 6125 | free((void *)exp->replace); |
| 6126 | exp->replace = (const char *)target; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 6127 | /* we force the backend to be present on at least all of |
| 6128 | * the frontend's processes. |
| 6129 | */ |
| 6130 | target->bind_proc = curproxy->bind_proc ? |
| 6131 | (target->bind_proc | curproxy->bind_proc) : 0; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 6132 | } |
| 6133 | } |
| 6134 | } |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6135 | |
| 6136 | /* find the target proxy for 'use_backend' rules */ |
| 6137 | list_for_each_entry(rule, &curproxy->switching_rules, list) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6138 | struct proxy *target; |
| 6139 | |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 6140 | target = findproxy_mode(rule->be.name, curproxy->mode, PR_CAP_BE); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6141 | |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6142 | if (!target) { |
| 6143 | Alert("Proxy '%s': unable to find required use_backend: '%s'.\n", |
| 6144 | curproxy->id, rule->be.name); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6145 | cfgerr++; |
| 6146 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6147 | Alert("Proxy '%s': loop detected for use_backend: '%s'.\n", |
| 6148 | curproxy->id, rule->be.name); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6149 | cfgerr++; |
| 6150 | } else { |
| 6151 | free((void *)rule->be.name); |
| 6152 | rule->be.backend = target; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 6153 | /* we force the backend to be present on at least all of |
| 6154 | * the frontend's processes. |
| 6155 | */ |
| 6156 | target->bind_proc = curproxy->bind_proc ? |
| 6157 | (target->bind_proc | curproxy->bind_proc) : 0; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6158 | } |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 6159 | } |
| 6160 | |
| 6161 | /* find the target proxy for 'use_backend' rules */ |
| 6162 | list_for_each_entry(srule, &curproxy->server_rules, list) { |
| 6163 | struct server *target = findserver(curproxy, srule->srv.name); |
| 6164 | |
| 6165 | if (!target) { |
| 6166 | Alert("config : %s '%s' : unable to find server '%s' referenced in a 'use-server' rule.\n", |
| 6167 | proxy_type_str(curproxy), curproxy->id, srule->srv.name); |
| 6168 | cfgerr++; |
| 6169 | continue; |
| 6170 | } |
| 6171 | free((void *)srule->srv.name); |
| 6172 | srule->srv.ptr = target; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6173 | } |
| 6174 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6175 | /* find the target table for 'stick' rules */ |
| 6176 | list_for_each_entry(mrule, &curproxy->sticking_rules, list) { |
| 6177 | struct proxy *target; |
| 6178 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 6179 | curproxy->be_req_ana |= AN_REQ_STICKING_RULES; |
| 6180 | if (mrule->flags & STK_IS_STORE) |
| 6181 | curproxy->be_rsp_ana |= AN_RES_STORE_RULES; |
| 6182 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6183 | if (mrule->table.name) |
Willy Tarreau | c00cdc2 | 2010-06-06 16:48:26 +0200 | [diff] [blame] | 6184 | target = findproxy(mrule->table.name, 0); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6185 | else |
| 6186 | target = curproxy; |
| 6187 | |
| 6188 | if (!target) { |
| 6189 | Alert("Proxy '%s': unable to find stick-table '%s'.\n", |
| 6190 | curproxy->id, mrule->table.name); |
| 6191 | cfgerr++; |
| 6192 | } |
| 6193 | else if (target->table.size == 0) { |
| 6194 | Alert("Proxy '%s': stick-table '%s' used but not configured.\n", |
| 6195 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 6196 | cfgerr++; |
| 6197 | } |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 6198 | else if (!stktable_compatible_sample(mrule->expr, target->table.type)) { |
| 6199 | 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] | 6200 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 6201 | cfgerr++; |
| 6202 | } |
| 6203 | else { |
| 6204 | free((void *)mrule->table.name); |
| 6205 | mrule->table.t = &(target->table); |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 6206 | stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID, NULL); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6207 | } |
| 6208 | } |
| 6209 | |
| 6210 | /* find the target table for 'store response' rules */ |
| 6211 | list_for_each_entry(mrule, &curproxy->storersp_rules, list) { |
| 6212 | struct proxy *target; |
| 6213 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 6214 | curproxy->be_rsp_ana |= AN_RES_STORE_RULES; |
| 6215 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6216 | if (mrule->table.name) |
Willy Tarreau | c00cdc2 | 2010-06-06 16:48:26 +0200 | [diff] [blame] | 6217 | target = findproxy(mrule->table.name, 0); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6218 | else |
| 6219 | target = curproxy; |
| 6220 | |
| 6221 | if (!target) { |
| 6222 | Alert("Proxy '%s': unable to find store table '%s'.\n", |
| 6223 | curproxy->id, mrule->table.name); |
| 6224 | cfgerr++; |
| 6225 | } |
| 6226 | else if (target->table.size == 0) { |
| 6227 | Alert("Proxy '%s': stick-table '%s' used but not configured.\n", |
| 6228 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 6229 | cfgerr++; |
| 6230 | } |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 6231 | else if (!stktable_compatible_sample(mrule->expr, target->table.type)) { |
| 6232 | 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] | 6233 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 6234 | cfgerr++; |
| 6235 | } |
| 6236 | else { |
| 6237 | free((void *)mrule->table.name); |
| 6238 | mrule->table.t = &(target->table); |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 6239 | stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID, NULL); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6240 | } |
| 6241 | } |
| 6242 | |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 6243 | /* find the target table for 'tcp-request' layer 4 rules */ |
| 6244 | list_for_each_entry(trule, &curproxy->tcp_req.l4_rules, list) { |
| 6245 | struct proxy *target; |
| 6246 | |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6247 | 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] | 6248 | continue; |
| 6249 | |
| 6250 | if (trule->act_prm.trk_ctr.table.n) |
| 6251 | target = findproxy(trule->act_prm.trk_ctr.table.n, 0); |
| 6252 | else |
| 6253 | target = curproxy; |
| 6254 | |
| 6255 | if (!target) { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6256 | Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n", |
| 6257 | curproxy->id, trule->act_prm.trk_ctr.table.n, |
| 6258 | trule->action == TCP_ACT_TRK_SC1 ? 1 : 2); |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 6259 | cfgerr++; |
| 6260 | } |
| 6261 | else if (target->table.size == 0) { |
| 6262 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
| 6263 | curproxy->id, trule->act_prm.trk_ctr.table.n ? trule->act_prm.trk_ctr.table.n : curproxy->id); |
| 6264 | cfgerr++; |
| 6265 | } |
Willy Tarreau | 5f53de7 | 2012-12-12 00:25:44 +0100 | [diff] [blame] | 6266 | else if (!stktable_compatible_sample(trule->act_prm.trk_ctr.expr, target->table.type)) { |
| 6267 | Alert("Proxy '%s': stick-table '%s' uses a type incompatible with the 'track-sc%d' rule.\n", |
| 6268 | curproxy->id, trule->act_prm.trk_ctr.table.n ? trule->act_prm.trk_ctr.table.n : curproxy->id, |
| 6269 | trule->action == TCP_ACT_TRK_SC1 ? 1 : 2); |
| 6270 | cfgerr++; |
| 6271 | } |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 6272 | else { |
| 6273 | free(trule->act_prm.trk_ctr.table.n); |
| 6274 | trule->act_prm.trk_ctr.table.t = &target->table; |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6275 | /* 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] | 6276 | * to pass a list of counters to track and allocate them right here using |
| 6277 | * stktable_alloc_data_type(). |
| 6278 | */ |
| 6279 | } |
| 6280 | } |
| 6281 | |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 6282 | /* find the target table for 'tcp-request' layer 6 rules */ |
| 6283 | list_for_each_entry(trule, &curproxy->tcp_req.inspect_rules, list) { |
| 6284 | struct proxy *target; |
| 6285 | |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6286 | 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] | 6287 | continue; |
| 6288 | |
| 6289 | if (trule->act_prm.trk_ctr.table.n) |
| 6290 | target = findproxy(trule->act_prm.trk_ctr.table.n, 0); |
| 6291 | else |
| 6292 | target = curproxy; |
| 6293 | |
| 6294 | if (!target) { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6295 | Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n", |
| 6296 | curproxy->id, trule->act_prm.trk_ctr.table.n, |
| 6297 | trule->action == TCP_ACT_TRK_SC1 ? 1 : 2); |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 6298 | cfgerr++; |
| 6299 | } |
| 6300 | else if (target->table.size == 0) { |
| 6301 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
| 6302 | curproxy->id, trule->act_prm.trk_ctr.table.n ? trule->act_prm.trk_ctr.table.n : curproxy->id); |
| 6303 | cfgerr++; |
| 6304 | } |
Willy Tarreau | 5f53de7 | 2012-12-12 00:25:44 +0100 | [diff] [blame] | 6305 | else if (!stktable_compatible_sample(trule->act_prm.trk_ctr.expr, target->table.type)) { |
| 6306 | Alert("Proxy '%s': stick-table '%s' uses a type incompatible with the 'track-sc%d' rule.\n", |
| 6307 | curproxy->id, trule->act_prm.trk_ctr.table.n ? trule->act_prm.trk_ctr.table.n : curproxy->id, |
| 6308 | trule->action == TCP_ACT_TRK_SC1 ? 1 : 2); |
| 6309 | cfgerr++; |
| 6310 | } |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 6311 | else { |
| 6312 | free(trule->act_prm.trk_ctr.table.n); |
| 6313 | trule->act_prm.trk_ctr.table.t = &target->table; |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6314 | /* 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] | 6315 | * to pass a list of counters to track and allocate them right here using |
| 6316 | * stktable_alloc_data_type(). |
| 6317 | */ |
| 6318 | } |
| 6319 | } |
| 6320 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 6321 | if (curproxy->table.peers.name) { |
| 6322 | struct peers *curpeers = peers; |
| 6323 | |
| 6324 | for (curpeers = peers; curpeers; curpeers = curpeers->next) { |
| 6325 | if (strcmp(curpeers->id, curproxy->table.peers.name) == 0) { |
| 6326 | free((void *)curproxy->table.peers.name); |
| 6327 | curproxy->table.peers.p = peers; |
| 6328 | break; |
| 6329 | } |
| 6330 | } |
| 6331 | |
| 6332 | if (!curpeers) { |
| 6333 | Alert("Proxy '%s': unable to find sync peers '%s'.\n", |
| 6334 | curproxy->id, curproxy->table.peers.name); |
Willy Tarreau | d66bf96 | 2011-10-28 14:16:49 +0200 | [diff] [blame] | 6335 | free((void *)curproxy->table.peers.name); |
| 6336 | curproxy->table.peers.p = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 6337 | cfgerr++; |
| 6338 | } |
| 6339 | else if (!curpeers->peers_fe) { |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 6340 | Alert("Proxy '%s': unable to find local peer '%s' in peers section '%s'.\n", |
| 6341 | curproxy->id, localpeer, curpeers->id); |
Willy Tarreau | d66bf96 | 2011-10-28 14:16:49 +0200 | [diff] [blame] | 6342 | curproxy->table.peers.p = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 6343 | cfgerr++; |
| 6344 | } |
| 6345 | } |
| 6346 | |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 6347 | if (curproxy->uri_auth && !(curproxy->uri_auth->flags & ST_CONVDONE) && |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 6348 | !LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) && |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6349 | (curproxy->uri_auth->userlist || curproxy->uri_auth->auth_realm )) { |
| 6350 | Alert("%s '%s': stats 'auth'/'realm' and 'http-request' can't be used at the same time.\n", |
| 6351 | "proxy", curproxy->id); |
| 6352 | cfgerr++; |
| 6353 | goto out_uri_auth_compat; |
| 6354 | } |
| 6355 | |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 6356 | 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] | 6357 | const char *uri_auth_compat_req[10]; |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 6358 | struct http_req_rule *rule; |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6359 | int i = 0; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6360 | |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6361 | /* build the ACL condition from scratch. We're relying on anonymous ACLs for that */ |
| 6362 | uri_auth_compat_req[i++] = "auth"; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6363 | |
| 6364 | if (curproxy->uri_auth->auth_realm) { |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6365 | uri_auth_compat_req[i++] = "realm"; |
| 6366 | uri_auth_compat_req[i++] = curproxy->uri_auth->auth_realm; |
| 6367 | } |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6368 | |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6369 | uri_auth_compat_req[i++] = "unless"; |
| 6370 | uri_auth_compat_req[i++] = "{"; |
| 6371 | uri_auth_compat_req[i++] = "http_auth(.internal-stats-userlist)"; |
| 6372 | uri_auth_compat_req[i++] = "}"; |
| 6373 | uri_auth_compat_req[i++] = ""; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6374 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 6375 | rule = parse_http_req_cond(uri_auth_compat_req, "internal-stats-auth-compat", 0, curproxy); |
| 6376 | if (!rule) { |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6377 | cfgerr++; |
| 6378 | break; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6379 | } |
| 6380 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 6381 | LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list); |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6382 | |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6383 | if (curproxy->uri_auth->auth_realm) { |
| 6384 | free(curproxy->uri_auth->auth_realm); |
| 6385 | curproxy->uri_auth->auth_realm = NULL; |
| 6386 | } |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 6387 | |
| 6388 | curproxy->uri_auth->flags |= ST_CONVDONE; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6389 | } |
| 6390 | out_uri_auth_compat: |
| 6391 | |
Krzysztof Piotr Oledzki | f9423ae | 2010-01-29 19:26:18 +0100 | [diff] [blame] | 6392 | cfgerr += acl_find_targets(curproxy); |
| 6393 | |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 6394 | if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) && |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6395 | (((curproxy->cap & PR_CAP_FE) && !curproxy->timeout.client) || |
Willy Tarreau | d825eef | 2007-05-12 22:35:00 +0200 | [diff] [blame] | 6396 | ((curproxy->cap & PR_CAP_BE) && (curproxy->srv) && |
Willy Tarreau | ce887fd | 2012-05-12 12:50:00 +0200 | [diff] [blame] | 6397 | (!curproxy->timeout.connect || |
| 6398 | (!curproxy->timeout.server && (curproxy->mode == PR_MODE_HTTP || !curproxy->timeout.tunnel)))))) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6399 | Warning("config : missing timeouts for %s '%s'.\n" |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 6400 | " | While not properly invalid, you will certainly encounter various problems\n" |
| 6401 | " | 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] | 6402 | " | timeouts are set to a non-zero value: 'client', 'connect', 'server'.\n", |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6403 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6404 | err_code |= ERR_WARN; |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 6405 | } |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 6406 | |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6407 | /* Historically, the tarpit and queue timeouts were inherited from contimeout. |
| 6408 | * We must still support older configurations, so let's find out whether those |
| 6409 | * parameters have been set or must be copied from contimeouts. |
| 6410 | */ |
| 6411 | if (curproxy != &defproxy) { |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6412 | if (!curproxy->timeout.tarpit || |
| 6413 | curproxy->timeout.tarpit == defproxy.timeout.tarpit) { |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6414 | /* tarpit timeout not set. We search in the following order: |
| 6415 | * default.tarpit, curr.connect, default.connect. |
| 6416 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6417 | if (defproxy.timeout.tarpit) |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6418 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6419 | else if (curproxy->timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6420 | curproxy->timeout.tarpit = curproxy->timeout.connect; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6421 | else if (defproxy.timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6422 | curproxy->timeout.tarpit = defproxy.timeout.connect; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6423 | } |
| 6424 | if ((curproxy->cap & PR_CAP_BE) && |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6425 | (!curproxy->timeout.queue || |
| 6426 | curproxy->timeout.queue == defproxy.timeout.queue)) { |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6427 | /* queue timeout not set. We search in the following order: |
| 6428 | * default.queue, curr.connect, default.connect. |
| 6429 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6430 | if (defproxy.timeout.queue) |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6431 | curproxy->timeout.queue = defproxy.timeout.queue; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6432 | else if (curproxy->timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6433 | curproxy->timeout.queue = curproxy->timeout.connect; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6434 | else if (defproxy.timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6435 | curproxy->timeout.queue = defproxy.timeout.connect; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6436 | } |
| 6437 | } |
| 6438 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 6439 | if ((curproxy->options2 & PR_O2_CHK_ANY) == PR_O2_SSL3_CHK) { |
Willy Tarreau | 137325d | 2010-02-01 16:38:17 +0100 | [diff] [blame] | 6440 | curproxy->check_len = sizeof(sslv3_client_hello_pkt) - 1; |
| 6441 | curproxy->check_req = (char *)malloc(curproxy->check_len); |
| 6442 | memcpy(curproxy->check_req, sslv3_client_hello_pkt, curproxy->check_len); |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 6443 | } |
| 6444 | |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 6445 | /* ensure that cookie capture length is not too large */ |
| 6446 | if (curproxy->capture_len >= global.tune.cookie_len) { |
| 6447 | Warning("config : truncating capture length to %d bytes for %s '%s'.\n", |
| 6448 | global.tune.cookie_len - 1, proxy_type_str(curproxy), curproxy->id); |
| 6449 | err_code |= ERR_WARN; |
| 6450 | curproxy->capture_len = global.tune.cookie_len - 1; |
| 6451 | } |
| 6452 | |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 6453 | /* The small pools required for the capture lists */ |
Willy Tarreau | 9a54e13 | 2012-03-24 08:33:05 +0100 | [diff] [blame] | 6454 | if (curproxy->nb_req_cap) { |
| 6455 | if (curproxy->mode == PR_MODE_HTTP) { |
| 6456 | curproxy->req_cap_pool = create_pool("ptrcap", |
| 6457 | curproxy->nb_req_cap * sizeof(char *), |
| 6458 | MEM_F_SHARED); |
| 6459 | } else { |
| 6460 | Warning("config : 'capture request header' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6461 | proxy_type_str(curproxy), curproxy->id); |
| 6462 | err_code |= ERR_WARN; |
| 6463 | curproxy->to_log &= ~LW_REQHDR; |
| 6464 | curproxy->nb_req_cap = 0; |
| 6465 | } |
| 6466 | } |
| 6467 | |
| 6468 | if (curproxy->nb_rsp_cap) { |
| 6469 | if (curproxy->mode == PR_MODE_HTTP) { |
| 6470 | curproxy->rsp_cap_pool = create_pool("ptrcap", |
| 6471 | curproxy->nb_rsp_cap * sizeof(char *), |
| 6472 | MEM_F_SHARED); |
| 6473 | } else { |
| 6474 | Warning("config : 'capture response header' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6475 | proxy_type_str(curproxy), curproxy->id); |
| 6476 | err_code |= ERR_WARN; |
| 6477 | curproxy->to_log &= ~LW_REQHDR; |
| 6478 | curproxy->nb_rsp_cap = 0; |
| 6479 | } |
| 6480 | } |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 6481 | |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 6482 | /* compile the log format */ |
Willy Tarreau | 99a7ca2 | 2012-05-31 19:39:23 +0200 | [diff] [blame] | 6483 | if (!(curproxy->cap & PR_CAP_FE)) { |
| 6484 | if (curproxy->logformat_string != default_http_log_format && |
| 6485 | curproxy->logformat_string != default_tcp_log_format && |
| 6486 | curproxy->logformat_string != clf_http_log_format) |
| 6487 | free(curproxy->logformat_string); |
| 6488 | curproxy->logformat_string = NULL; |
| 6489 | } |
| 6490 | |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 6491 | if (curproxy->logformat_string) |
| 6492 | parse_logformat_string(curproxy->logformat_string, curproxy, &curproxy->logformat, curproxy->mode); |
| 6493 | |
| 6494 | if (curproxy->uniqueid_format_string) |
| 6495 | parse_logformat_string(curproxy->uniqueid_format_string, curproxy, &curproxy->format_unique_id, PR_MODE_HTTP); |
| 6496 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6497 | /* first, we will invert the servers list order */ |
| 6498 | newsrv = NULL; |
| 6499 | while (curproxy->srv) { |
| 6500 | struct server *next; |
| 6501 | |
| 6502 | next = curproxy->srv->next; |
| 6503 | curproxy->srv->next = newsrv; |
| 6504 | newsrv = curproxy->srv; |
| 6505 | if (!next) |
| 6506 | break; |
| 6507 | curproxy->srv = next; |
| 6508 | } |
| 6509 | |
Willy Tarreau | dd70165 | 2010-05-25 23:03:02 +0200 | [diff] [blame] | 6510 | /* assign automatic UIDs to servers which don't have one yet */ |
| 6511 | next_id = 1; |
| 6512 | newsrv = curproxy->srv; |
| 6513 | while (newsrv != NULL) { |
| 6514 | if (!newsrv->puid) { |
| 6515 | /* server ID not set, use automatic numbering with first |
| 6516 | * spare entry starting with next_svid. |
| 6517 | */ |
| 6518 | next_id = get_next_id(&curproxy->conf.used_server_id, next_id); |
| 6519 | newsrv->conf.id.key = newsrv->puid = next_id; |
| 6520 | eb32_insert(&curproxy->conf.used_server_id, &newsrv->conf.id); |
| 6521 | } |
| 6522 | next_id++; |
| 6523 | newsrv = newsrv->next; |
| 6524 | } |
| 6525 | |
Willy Tarreau | 2069704 | 2007-11-15 23:26:18 +0100 | [diff] [blame] | 6526 | curproxy->lbprm.wmult = 1; /* default weight multiplier */ |
Willy Tarreau | 5dc2fa6 | 2007-11-19 19:10:18 +0100 | [diff] [blame] | 6527 | curproxy->lbprm.wdiv = 1; /* default weight divider */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6528 | |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 6529 | /* |
| 6530 | * If this server supports a maxconn parameter, it needs a dedicated |
| 6531 | * tasks to fill the emptied slots when a connection leaves. |
| 6532 | * Also, resolve deferred tracking dependency if needed. |
| 6533 | */ |
| 6534 | newsrv = curproxy->srv; |
| 6535 | while (newsrv != NULL) { |
| 6536 | if (newsrv->minconn > newsrv->maxconn) { |
| 6537 | /* Only 'minconn' was specified, or it was higher than or equal |
| 6538 | * to 'maxconn'. Let's turn this into maxconn and clean it, as |
| 6539 | * this will avoid further useless expensive computations. |
| 6540 | */ |
| 6541 | newsrv->maxconn = newsrv->minconn; |
| 6542 | } else if (newsrv->maxconn && !newsrv->minconn) { |
| 6543 | /* minconn was not specified, so we set it to maxconn */ |
| 6544 | newsrv->minconn = newsrv->maxconn; |
| 6545 | } |
| 6546 | |
Emeric Brun | 01f8e2f | 2012-05-18 16:02:00 +0200 | [diff] [blame] | 6547 | #ifdef USE_OPENSSL |
Emeric Brun | 94324a4 | 2012-10-11 14:00:19 +0200 | [diff] [blame] | 6548 | if (newsrv->use_ssl || newsrv->check.use_ssl) |
| 6549 | cfgerr += ssl_sock_prepare_srv_ctx(newsrv, curproxy); |
Emeric Brun | 01f8e2f | 2012-05-18 16:02:00 +0200 | [diff] [blame] | 6550 | #endif /* USE_OPENSSL */ |
Emeric Brun | 94324a4 | 2012-10-11 14:00:19 +0200 | [diff] [blame] | 6551 | |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 6552 | if (newsrv->trackit) { |
| 6553 | struct proxy *px; |
| 6554 | struct server *srv; |
| 6555 | char *pname, *sname; |
| 6556 | |
| 6557 | pname = newsrv->trackit; |
| 6558 | sname = strrchr(pname, '/'); |
| 6559 | |
| 6560 | if (sname) |
| 6561 | *sname++ = '\0'; |
| 6562 | else { |
| 6563 | sname = pname; |
| 6564 | pname = NULL; |
| 6565 | } |
| 6566 | |
| 6567 | if (pname) { |
| 6568 | px = findproxy(pname, PR_CAP_BE); |
| 6569 | if (!px) { |
| 6570 | Alert("config : %s '%s', server '%s': unable to find required proxy '%s' for tracking.\n", |
| 6571 | proxy_type_str(curproxy), curproxy->id, |
| 6572 | newsrv->id, pname); |
| 6573 | cfgerr++; |
| 6574 | goto next_srv; |
| 6575 | } |
| 6576 | } else |
| 6577 | px = curproxy; |
| 6578 | |
| 6579 | srv = findserver(px, sname); |
| 6580 | if (!srv) { |
| 6581 | Alert("config : %s '%s', server '%s': unable to find required server '%s' for tracking.\n", |
| 6582 | proxy_type_str(curproxy), curproxy->id, |
| 6583 | newsrv->id, sname); |
| 6584 | cfgerr++; |
| 6585 | goto next_srv; |
| 6586 | } |
| 6587 | |
| 6588 | if (!(srv->state & SRV_CHECKED)) { |
| 6589 | Alert("config : %s '%s', server '%s': unable to use %s/%s for " |
| 6590 | "tracking as it does not have checks enabled.\n", |
| 6591 | proxy_type_str(curproxy), curproxy->id, |
| 6592 | newsrv->id, px->id, srv->id); |
| 6593 | cfgerr++; |
| 6594 | goto next_srv; |
| 6595 | } |
| 6596 | |
| 6597 | if (curproxy != px && |
| 6598 | (curproxy->options & PR_O_DISABLE404) != (px->options & PR_O_DISABLE404)) { |
| 6599 | Alert("config : %s '%s', server '%s': unable to use %s/%s for" |
| 6600 | "tracking: disable-on-404 option inconsistency.\n", |
| 6601 | proxy_type_str(curproxy), curproxy->id, |
| 6602 | newsrv->id, px->id, srv->id); |
| 6603 | cfgerr++; |
| 6604 | goto next_srv; |
| 6605 | } |
| 6606 | |
| 6607 | /* if the other server is forced disabled, we have to do the same here */ |
| 6608 | if (srv->state & SRV_MAINTAIN) { |
| 6609 | newsrv->state |= SRV_MAINTAIN; |
| 6610 | newsrv->state &= ~SRV_RUNNING; |
| 6611 | newsrv->health = 0; |
| 6612 | } |
| 6613 | |
| 6614 | newsrv->track = srv; |
| 6615 | newsrv->tracknext = srv->tracknext; |
| 6616 | srv->tracknext = newsrv; |
| 6617 | |
| 6618 | free(newsrv->trackit); |
| 6619 | newsrv->trackit = NULL; |
| 6620 | } |
| 6621 | next_srv: |
| 6622 | newsrv = newsrv->next; |
| 6623 | } |
| 6624 | |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6625 | /* We have to initialize the server lookup mechanism depending |
| 6626 | * on what LB algorithm was choosen. |
| 6627 | */ |
| 6628 | |
| 6629 | curproxy->lbprm.algo &= ~(BE_LB_LKUP | BE_LB_PROP_DYN); |
| 6630 | switch (curproxy->lbprm.algo & BE_LB_KIND) { |
| 6631 | case BE_LB_KIND_RR: |
Willy Tarreau | 9757a38 | 2009-10-03 12:56:50 +0200 | [diff] [blame] | 6632 | if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_RR_STATIC) { |
| 6633 | curproxy->lbprm.algo |= BE_LB_LKUP_MAP; |
| 6634 | init_server_map(curproxy); |
| 6635 | } else { |
| 6636 | curproxy->lbprm.algo |= BE_LB_LKUP_RRTREE | BE_LB_PROP_DYN; |
| 6637 | fwrr_init_server_groups(curproxy); |
| 6638 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6639 | break; |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 6640 | |
Willy Tarreau | 3ebb116 | 2012-02-13 16:57:44 +0100 | [diff] [blame] | 6641 | case BE_LB_KIND_CB: |
Willy Tarreau | f09c660 | 2012-02-13 17:12:08 +0100 | [diff] [blame] | 6642 | if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_CB_LC) { |
| 6643 | curproxy->lbprm.algo |= BE_LB_LKUP_LCTREE | BE_LB_PROP_DYN; |
| 6644 | fwlc_init_server_tree(curproxy); |
| 6645 | } else { |
| 6646 | curproxy->lbprm.algo |= BE_LB_LKUP_FSTREE | BE_LB_PROP_DYN; |
| 6647 | fas_init_server_tree(curproxy); |
| 6648 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6649 | break; |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 6650 | |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6651 | case BE_LB_KIND_HI: |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 6652 | if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS) { |
| 6653 | curproxy->lbprm.algo |= BE_LB_LKUP_CHTREE | BE_LB_PROP_DYN; |
| 6654 | chash_init_server_tree(curproxy); |
| 6655 | } else { |
| 6656 | curproxy->lbprm.algo |= BE_LB_LKUP_MAP; |
| 6657 | init_server_map(curproxy); |
| 6658 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6659 | break; |
| 6660 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6661 | |
| 6662 | if (curproxy->options & PR_O_LOGASAP) |
| 6663 | curproxy->to_log &= ~LW_BYTES; |
| 6664 | |
Willy Tarreau | e7ded1f | 2009-08-09 10:11:45 +0200 | [diff] [blame] | 6665 | if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) && |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6666 | (curproxy->cap & PR_CAP_FE) && curproxy->to_log && LIST_ISEMPTY(&curproxy->logsrvs)) { |
Willy Tarreau | e7ded1f | 2009-08-09 10:11:45 +0200 | [diff] [blame] | 6667 | Warning("config : log format ignored for %s '%s' since it has no log address.\n", |
| 6668 | proxy_type_str(curproxy), curproxy->id); |
| 6669 | err_code |= ERR_WARN; |
| 6670 | } |
| 6671 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 6672 | if (curproxy->mode != PR_MODE_HTTP) { |
| 6673 | int optnum; |
| 6674 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 6675 | if (curproxy->uri_auth) { |
| 6676 | Warning("config : 'stats' statement ignored for %s '%s' as it requires HTTP mode.\n", |
| 6677 | proxy_type_str(curproxy), curproxy->id); |
| 6678 | err_code |= ERR_WARN; |
| 6679 | curproxy->uri_auth = NULL; |
| 6680 | } |
| 6681 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 6682 | if (curproxy->options & (PR_O_FWDFOR | PR_O_FF_ALWAYS)) { |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 6683 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6684 | "forwardfor", proxy_type_str(curproxy), curproxy->id); |
| 6685 | err_code |= ERR_WARN; |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 6686 | curproxy->options &= ~(PR_O_FWDFOR | PR_O_FF_ALWAYS); |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 6687 | } |
| 6688 | |
| 6689 | if (curproxy->options & PR_O_ORGTO) { |
| 6690 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6691 | "originalto", proxy_type_str(curproxy), curproxy->id); |
| 6692 | err_code |= ERR_WARN; |
| 6693 | curproxy->options &= ~PR_O_ORGTO; |
| 6694 | } |
| 6695 | |
| 6696 | for (optnum = 0; cfg_opts[optnum].name; optnum++) { |
| 6697 | if (cfg_opts[optnum].mode == PR_MODE_HTTP && |
| 6698 | (curproxy->cap & cfg_opts[optnum].cap) && |
| 6699 | (curproxy->options & cfg_opts[optnum].val)) { |
| 6700 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6701 | cfg_opts[optnum].name, proxy_type_str(curproxy), curproxy->id); |
| 6702 | err_code |= ERR_WARN; |
| 6703 | curproxy->options &= ~cfg_opts[optnum].val; |
| 6704 | } |
| 6705 | } |
| 6706 | |
| 6707 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) { |
| 6708 | if (cfg_opts2[optnum].mode == PR_MODE_HTTP && |
| 6709 | (curproxy->cap & cfg_opts2[optnum].cap) && |
| 6710 | (curproxy->options2 & cfg_opts2[optnum].val)) { |
| 6711 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6712 | cfg_opts2[optnum].name, proxy_type_str(curproxy), curproxy->id); |
| 6713 | err_code |= ERR_WARN; |
| 6714 | curproxy->options2 &= ~cfg_opts2[optnum].val; |
| 6715 | } |
| 6716 | } |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6717 | |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 6718 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6719 | if (curproxy->conn_src.bind_hdr_occ) { |
| 6720 | curproxy->conn_src.bind_hdr_occ = 0; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6721 | Warning("config : %s '%s' : ignoring use of header %s as source IP in non-HTTP mode.\n", |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6722 | proxy_type_str(curproxy), curproxy->id, curproxy->conn_src.bind_hdr_name); |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6723 | err_code |= ERR_WARN; |
| 6724 | } |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 6725 | #endif |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 6726 | } |
| 6727 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6728 | /* |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 6729 | * ensure that we're not cross-dressing a TCP server into HTTP. |
| 6730 | */ |
| 6731 | newsrv = curproxy->srv; |
| 6732 | while (newsrv != NULL) { |
Willy Tarreau | 0cec331 | 2011-10-31 13:49:26 +0100 | [diff] [blame] | 6733 | if ((curproxy->mode != PR_MODE_HTTP) && newsrv->rdr_len) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6734 | Alert("config : %s '%s' : server cannot have cookie or redirect prefix in non-HTTP mode.\n", |
| 6735 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6736 | cfgerr++; |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 6737 | } |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6738 | |
Willy Tarreau | 0cec331 | 2011-10-31 13:49:26 +0100 | [diff] [blame] | 6739 | if ((curproxy->mode != PR_MODE_HTTP) && newsrv->cklen) { |
| 6740 | Warning("config : %s '%s' : ignoring cookie for server '%s' as HTTP mode is disabled.\n", |
| 6741 | proxy_type_str(curproxy), curproxy->id, newsrv->id); |
| 6742 | err_code |= ERR_WARN; |
| 6743 | } |
| 6744 | |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 6745 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6746 | if (curproxy->mode != PR_MODE_HTTP && newsrv->conn_src.bind_hdr_occ) { |
| 6747 | newsrv->conn_src.bind_hdr_occ = 0; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6748 | Warning("config : %s '%s' : server %s cannot use header %s as source IP in non-HTTP mode.\n", |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6749 | proxy_type_str(curproxy), curproxy->id, newsrv->id, newsrv->conn_src.bind_hdr_name); |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6750 | err_code |= ERR_WARN; |
| 6751 | } |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 6752 | #endif |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 6753 | newsrv = newsrv->next; |
| 6754 | } |
| 6755 | |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6756 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 6757 | if (!curproxy->accept) |
| 6758 | curproxy->accept = frontend_accept; |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 6759 | |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6760 | if (curproxy->tcp_req.inspect_delay || |
| 6761 | !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules)) |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 6762 | curproxy->fe_req_ana |= AN_REQ_INSPECT_FE; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6763 | |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 6764 | if (curproxy->mode == PR_MODE_HTTP) { |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6765 | 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] | 6766 | 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] | 6767 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6768 | |
| 6769 | /* both TCP and HTTP must check switching rules */ |
| 6770 | curproxy->fe_req_ana |= AN_REQ_SWITCHING_RULES; |
| 6771 | } |
| 6772 | |
| 6773 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 6774 | if (curproxy->tcp_req.inspect_delay || |
| 6775 | !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules)) |
| 6776 | curproxy->be_req_ana |= AN_REQ_INSPECT_BE; |
| 6777 | |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 6778 | if (!LIST_ISEMPTY(&curproxy->tcp_rep.inspect_rules)) |
| 6779 | curproxy->be_rsp_ana |= AN_RES_INSPECT; |
| 6780 | |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 6781 | if (curproxy->mode == PR_MODE_HTTP) { |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6782 | 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] | 6783 | 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] | 6784 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6785 | |
| 6786 | /* If the backend does requires RDP cookie persistence, we have to |
| 6787 | * enable the corresponding analyser. |
| 6788 | */ |
| 6789 | if (curproxy->options2 & PR_O2_RDPC_PRST) |
| 6790 | curproxy->be_req_ana |= AN_REQ_PRST_RDP_COOKIE; |
| 6791 | } |
| 6792 | |
Emeric Brun | c52962f | 2012-11-15 18:28:02 +0100 | [diff] [blame] | 6793 | #ifdef USE_OPENSSL |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 6794 | /* Configure SSL for each bind line. |
| 6795 | * Note: if configuration fails at some point, the ->ctx member |
| 6796 | * remains NULL so that listeners can later detach. |
| 6797 | */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6798 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
Emeric Brun | c52962f | 2012-11-15 18:28:02 +0100 | [diff] [blame] | 6799 | if (!bind_conf->is_ssl) { |
| 6800 | if (bind_conf->default_ctx) { |
| 6801 | Warning("Proxy '%s': A certificate was specified but SSL was not enabled on bind '%s' at [%s:%d] (use 'ssl').\n", |
| 6802 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
| 6803 | } |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6804 | continue; |
Emeric Brun | c52962f | 2012-11-15 18:28:02 +0100 | [diff] [blame] | 6805 | } |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6806 | if (!bind_conf->default_ctx) { |
Emeric Brun | fc0421f | 2012-09-07 17:30:07 +0200 | [diff] [blame] | 6807 | 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] | 6808 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 6809 | cfgerr++; |
| 6810 | continue; |
| 6811 | } |
| 6812 | |
Emeric Brun | 4b3091e | 2012-09-24 15:48:52 +0200 | [diff] [blame] | 6813 | 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] | 6814 | Alert("Unable to allocate SSL session cache.\n"); |
| 6815 | cfgerr++; |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 6816 | continue; |
| 6817 | } |
| 6818 | |
Emeric Brun | fc0421f | 2012-09-07 17:30:07 +0200 | [diff] [blame] | 6819 | /* initialize all certificate contexts */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6820 | cfgerr += ssl_sock_prepare_all_ctx(bind_conf, curproxy); |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6821 | } |
Emeric Brun | c52962f | 2012-11-15 18:28:02 +0100 | [diff] [blame] | 6822 | #endif /* USE_OPENSSL */ |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 6823 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 6824 | /* adjust this proxy's listeners */ |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6825 | next_id = 1; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 6826 | list_for_each_entry(listener, &curproxy->conf.listeners, by_fe) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6827 | if (!listener->luid) { |
| 6828 | /* listener ID not set, use automatic numbering with first |
| 6829 | * spare entry starting with next_luid. |
| 6830 | */ |
| 6831 | next_id = get_next_id(&curproxy->conf.used_listener_id, next_id); |
| 6832 | listener->conf.id.key = listener->luid = next_id; |
| 6833 | eb32_insert(&curproxy->conf.used_listener_id, &listener->conf.id); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6834 | } |
Krzysztof Piotr Oledzki | df5cb9f | 2010-02-05 20:58:27 +0100 | [diff] [blame] | 6835 | next_id++; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6836 | |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 6837 | /* enable separate counters */ |
| 6838 | if (curproxy->options2 & PR_O2_SOCKSTAT) { |
| 6839 | listener->counters = (struct licounters *)calloc(1, sizeof(struct licounters)); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6840 | if (!listener->name) |
| 6841 | memprintf(&listener->name, "sock-%d", listener->luid); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 6842 | } |
Willy Tarreau | 81796be | 2012-09-22 19:11:47 +0200 | [diff] [blame] | 6843 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 6844 | if (curproxy->options & PR_O_TCP_NOLING) |
| 6845 | listener->options |= LI_O_NOLINGER; |
Willy Tarreau | 32368ce | 2012-09-06 11:10:55 +0200 | [diff] [blame] | 6846 | if (!listener->maxconn) |
| 6847 | listener->maxconn = curproxy->maxconn; |
| 6848 | if (!listener->backlog) |
| 6849 | listener->backlog = curproxy->backlog; |
Willy Tarreau | 16a2147 | 2012-11-19 12:39:59 +0100 | [diff] [blame] | 6850 | if (!listener->maxaccept) |
| 6851 | listener->maxaccept = global.tune.maxaccept ? global.tune.maxaccept : 64; |
| 6852 | |
| 6853 | /* we want to have an optimal behaviour on single process mode to |
| 6854 | * maximize the work at once, but in multi-process we want to keep |
| 6855 | * some fairness between processes, so we target half of the max |
| 6856 | * number of events to be balanced over all the processes the proxy |
| 6857 | * is bound to. Rememeber that maxaccept = -1 must be kept as it is |
| 6858 | * used to disable the limit. |
| 6859 | */ |
| 6860 | if (listener->maxaccept > 0) { |
| 6861 | if (nbproc > 1) |
| 6862 | listener->maxaccept = (listener->maxaccept + 1) / 2; |
| 6863 | listener->maxaccept = (listener->maxaccept + nbproc - 1) / nbproc; |
| 6864 | } |
| 6865 | |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6866 | listener->timeout = &curproxy->timeout.client; |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 6867 | listener->accept = session_accept; |
Willy Tarreau | 3bc1377 | 2008-12-07 11:50:35 +0100 | [diff] [blame] | 6868 | listener->handler = process_session; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6869 | listener->analysers |= curproxy->fe_req_ana; |
Willy Tarreau | 3bc1377 | 2008-12-07 11:50:35 +0100 | [diff] [blame] | 6870 | |
Willy Tarreau | a5c0ab2 | 2010-05-31 10:30:33 +0200 | [diff] [blame] | 6871 | if (!LIST_ISEMPTY(&curproxy->tcp_req.l4_rules)) |
| 6872 | listener->options |= LI_O_TCP_RULES; |
| 6873 | |
Willy Tarreau | de3041d | 2010-05-31 10:56:17 +0200 | [diff] [blame] | 6874 | if (curproxy->mon_mask.s_addr) |
| 6875 | listener->options |= LI_O_CHK_MONNET; |
| 6876 | |
Willy Tarreau | 9ea05a7 | 2009-06-14 12:07:01 +0200 | [diff] [blame] | 6877 | /* smart accept mode is automatic in HTTP mode */ |
| 6878 | if ((curproxy->options2 & PR_O2_SMARTACC) || |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6879 | ((curproxy->mode == PR_MODE_HTTP || listener->bind_conf->is_ssl) && |
Willy Tarreau | 9ea05a7 | 2009-06-14 12:07:01 +0200 | [diff] [blame] | 6880 | !(curproxy->no_options2 & PR_O2_SMARTACC))) |
| 6881 | listener->options |= LI_O_NOQUICKACK; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 6882 | } |
| 6883 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6884 | /* Release unused SSL configs */ |
| 6885 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
| 6886 | if (bind_conf->is_ssl) |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 6887 | continue; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6888 | #ifdef USE_OPENSSL |
| 6889 | ssl_sock_free_all_ctx(bind_conf); |
Emeric Brun | fb510ea | 2012-10-05 12:00:26 +0200 | [diff] [blame] | 6890 | free(bind_conf->ca_file); |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6891 | free(bind_conf->ciphers); |
Emeric Brun | 2b58d04 | 2012-09-20 17:10:03 +0200 | [diff] [blame] | 6892 | free(bind_conf->ecdhe); |
Emeric Brun | fb510ea | 2012-10-05 12:00:26 +0200 | [diff] [blame] | 6893 | free(bind_conf->crl_file); |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 6894 | #endif /* USE_OPENSSL */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6895 | } |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 6896 | |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 6897 | /* Check multi-process mode compatibility for the current proxy */ |
| 6898 | if (global.nbproc > 1) { |
| 6899 | int nbproc = 0; |
| 6900 | if (curproxy->bind_proc) { |
| 6901 | int proc; |
| 6902 | for (proc = 0; proc < global.nbproc; proc++) { |
| 6903 | if (curproxy->bind_proc & (1 << proc)) { |
| 6904 | nbproc++; |
| 6905 | } |
| 6906 | } |
| 6907 | } else { |
| 6908 | nbproc = global.nbproc; |
| 6909 | } |
| 6910 | if (curproxy->table.peers.name) { |
| 6911 | Alert("Proxy '%s': peers can't be used in multi-process mode (nbproc > 1).\n", |
| 6912 | curproxy->id); |
| 6913 | cfgerr++; |
| 6914 | } |
| 6915 | if (nbproc > 1) { |
| 6916 | if (curproxy->uri_auth) { |
| 6917 | Warning("Proxy '%s': in multi-process mode, stats will be limited to process assigned to the current request.\n", |
| 6918 | curproxy->id); |
| 6919 | if (!LIST_ISEMPTY(&curproxy->uri_auth->admin_rules)) { |
| 6920 | Warning("Proxy '%s': stats admin will not work correctly in multi-process mode.\n", |
| 6921 | curproxy->id); |
| 6922 | } |
| 6923 | } |
| 6924 | if (curproxy->appsession_name) { |
| 6925 | Warning("Proxy '%s': appsession will not work correctly in multi-process mode.\n", |
| 6926 | curproxy->id); |
| 6927 | } |
| 6928 | if (!LIST_ISEMPTY(&curproxy->sticking_rules)) { |
| 6929 | Warning("Proxy '%s': sticking rules will not work correctly in multi-process mode.\n", |
| 6930 | curproxy->id); |
| 6931 | } |
| 6932 | } |
| 6933 | } |
Willy Tarreau | 918ff60 | 2011-07-25 16:33:49 +0200 | [diff] [blame] | 6934 | |
| 6935 | /* create the task associated with the proxy */ |
| 6936 | curproxy->task = task_new(); |
| 6937 | if (curproxy->task) { |
| 6938 | curproxy->task->context = curproxy; |
| 6939 | curproxy->task->process = manage_proxy; |
| 6940 | /* no need to queue, it will be done automatically if some |
| 6941 | * listener gets limited. |
| 6942 | */ |
| 6943 | curproxy->task->expire = TICK_ETERNITY; |
| 6944 | } else { |
| 6945 | Alert("Proxy '%s': no more memory when trying to allocate the management task\n", |
| 6946 | curproxy->id); |
| 6947 | cfgerr++; |
| 6948 | } |
| 6949 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6950 | curproxy = curproxy->next; |
| 6951 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 6952 | |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 6953 | /* Check multi-process mode compatibility */ |
| 6954 | if (global.nbproc > 1) { |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 6955 | if (global.stats_fe && !global.stats_fe->bind_proc) { |
| 6956 | 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] | 6957 | } |
| 6958 | } |
| 6959 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6960 | for (curuserlist = userlist; curuserlist; curuserlist = curuserlist->next) { |
| 6961 | struct auth_users *curuser; |
| 6962 | int g; |
| 6963 | |
| 6964 | for (curuser = curuserlist->users; curuser; curuser = curuser->next) { |
| 6965 | unsigned int group_mask = 0; |
| 6966 | char *group = NULL; |
| 6967 | |
Willy Tarreau | b4c06b7 | 2010-02-02 11:28:20 +0100 | [diff] [blame] | 6968 | if (!curuser->u.groups) |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6969 | continue; |
| 6970 | |
Willy Tarreau | b4c06b7 | 2010-02-02 11:28:20 +0100 | [diff] [blame] | 6971 | while ((group = strtok(group?NULL:curuser->u.groups, ","))) { |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6972 | |
| 6973 | for (g = 0; g < curuserlist->grpcnt; g++) |
| 6974 | if (!strcmp(curuserlist->groups[g], group)) |
| 6975 | break; |
| 6976 | |
| 6977 | if (g == curuserlist->grpcnt) { |
| 6978 | Alert("userlist '%s': no such group '%s' specified in user '%s'\n", |
| 6979 | curuserlist->name, group, curuser->user); |
| 6980 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6981 | goto out; |
| 6982 | } |
| 6983 | |
| 6984 | group_mask |= (1 << g); |
| 6985 | } |
| 6986 | |
Willy Tarreau | b4c06b7 | 2010-02-02 11:28:20 +0100 | [diff] [blame] | 6987 | free(curuser->u.groups); |
| 6988 | curuser->u.group_mask = group_mask; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6989 | } |
| 6990 | |
| 6991 | for (g = 0; g < curuserlist->grpcnt; g++) { |
| 6992 | char *user = NULL; |
| 6993 | |
| 6994 | if (!curuserlist->groupusers[g]) |
| 6995 | continue; |
| 6996 | |
| 6997 | while ((user = strtok(user?NULL:curuserlist->groupusers[g], ","))) { |
| 6998 | for (curuser = curuserlist->users; curuser; curuser = curuser->next) |
| 6999 | if (!strcmp(curuser->user, user)) |
| 7000 | break; |
| 7001 | |
| 7002 | if (!curuser) { |
| 7003 | Alert("userlist '%s': no such user '%s' specified in group '%s'\n", |
| 7004 | curuserlist->name, user, curuserlist->groups[g]); |
| 7005 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7006 | goto out; |
| 7007 | } |
| 7008 | |
Willy Tarreau | b4c06b7 | 2010-02-02 11:28:20 +0100 | [diff] [blame] | 7009 | curuser->u.group_mask |= (1 << g); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 7010 | } |
| 7011 | |
| 7012 | free(curuserlist->groupusers[g]); |
| 7013 | } |
| 7014 | |
| 7015 | free(curuserlist->groupusers); |
| 7016 | |
| 7017 | #ifdef DEBUG_AUTH |
| 7018 | for (g = 0; g < curuserlist->grpcnt; g++) { |
| 7019 | fprintf(stderr, "group %s, id %d, mask %08X, users:", curuserlist->groups[g], g , 1 << g); |
| 7020 | |
| 7021 | for (curuser = curuserlist->users; curuser; curuser = curuser->next) { |
Willy Tarreau | b950959 | 2012-05-10 23:25:35 +0200 | [diff] [blame] | 7022 | if (curuser->u.group_mask & (1 << g)) |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 7023 | fprintf(stderr, " %s", curuser->user); |
| 7024 | } |
| 7025 | |
| 7026 | fprintf(stderr, "\n"); |
| 7027 | } |
| 7028 | #endif |
| 7029 | |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 7030 | } |
| 7031 | |
| 7032 | /* automatically compute fullconn if not set. We must not do it in the |
| 7033 | * loop above because cross-references are not yet fully resolved. |
| 7034 | */ |
| 7035 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 7036 | /* If <fullconn> is not set, let's set it to 10% of the sum of |
| 7037 | * the possible incoming frontend's maxconns. |
| 7038 | */ |
| 7039 | if (!curproxy->fullconn && (curproxy->cap & PR_CAP_BE)) { |
| 7040 | struct proxy *fe; |
| 7041 | int total = 0; |
| 7042 | |
| 7043 | /* sum up the number of maxconns of frontends which |
| 7044 | * reference this backend at least once or which are |
| 7045 | * the same one ('listen'). |
| 7046 | */ |
| 7047 | for (fe = proxy; fe; fe = fe->next) { |
| 7048 | struct switching_rule *rule; |
| 7049 | struct hdr_exp *exp; |
| 7050 | int found = 0; |
| 7051 | |
| 7052 | if (!(fe->cap & PR_CAP_FE)) |
| 7053 | continue; |
| 7054 | |
| 7055 | if (fe == curproxy) /* we're on a "listen" instance */ |
| 7056 | found = 1; |
| 7057 | |
| 7058 | if (fe->defbe.be == curproxy) /* "default_backend" */ |
| 7059 | found = 1; |
| 7060 | |
| 7061 | /* check if a "use_backend" rule matches */ |
| 7062 | if (!found) { |
| 7063 | list_for_each_entry(rule, &fe->switching_rules, list) { |
| 7064 | if (rule->be.backend == curproxy) { |
| 7065 | found = 1; |
| 7066 | break; |
| 7067 | } |
| 7068 | } |
| 7069 | } |
| 7070 | |
| 7071 | /* check if a "reqsetbe" rule matches */ |
| 7072 | for (exp = fe->req_exp; !found && exp; exp = exp->next) { |
| 7073 | if (exp->action == ACT_SETBE && |
| 7074 | (struct proxy *)exp->replace == curproxy) { |
| 7075 | found = 1; |
| 7076 | break; |
| 7077 | } |
| 7078 | } |
| 7079 | |
| 7080 | /* now we've checked all possible ways to reference a backend |
| 7081 | * from a frontend. |
| 7082 | */ |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 7083 | if (!found) |
| 7084 | continue; |
| 7085 | total += fe->maxconn; |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 7086 | } |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 7087 | /* we have the sum of the maxconns in <total>. We only |
| 7088 | * keep 10% of that sum to set the default fullconn, with |
| 7089 | * a hard minimum of 1 (to avoid a divide by zero). |
| 7090 | */ |
| 7091 | curproxy->fullconn = (total + 9) / 10; |
| 7092 | if (!curproxy->fullconn) |
| 7093 | curproxy->fullconn = 1; |
| 7094 | } |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 7095 | } |
| 7096 | |
Willy Tarreau | 056f568 | 2010-06-06 15:51:11 +0200 | [diff] [blame] | 7097 | /* initialize stick-tables on backend capable proxies. This must not |
| 7098 | * be done earlier because the data size may be discovered while parsing |
| 7099 | * other proxies. |
| 7100 | */ |
| 7101 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) |
Willy Tarreau | c00cdc2 | 2010-06-06 16:48:26 +0200 | [diff] [blame] | 7102 | stktable_init(&curproxy->table); |
Willy Tarreau | 056f568 | 2010-06-06 15:51:11 +0200 | [diff] [blame] | 7103 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7104 | /* |
| 7105 | * Recount currently required checks. |
| 7106 | */ |
| 7107 | |
| 7108 | for (curproxy=proxy; curproxy; curproxy=curproxy->next) { |
| 7109 | int optnum; |
| 7110 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 7111 | for (optnum = 0; cfg_opts[optnum].name; optnum++) |
| 7112 | if (curproxy->options & cfg_opts[optnum].val) |
| 7113 | global.last_checks |= cfg_opts[optnum].checks; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7114 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 7115 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) |
| 7116 | if (curproxy->options2 & cfg_opts2[optnum].val) |
| 7117 | global.last_checks |= cfg_opts2[optnum].checks; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7118 | } |
| 7119 | |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 7120 | if (peers) { |
| 7121 | struct peers *curpeers = peers, **last; |
| 7122 | struct peer *p, *pb; |
| 7123 | |
| 7124 | /* Remove all peers sections which don't have a valid listener. |
| 7125 | * This can happen when a peers section is never referenced and |
| 7126 | * does not contain a local peer. |
| 7127 | */ |
| 7128 | last = &peers; |
| 7129 | while (*last) { |
| 7130 | curpeers = *last; |
| 7131 | if (curpeers->peers_fe) { |
Willy Tarreau | ca57de3 | 2012-11-23 20:08:09 +0100 | [diff] [blame] | 7132 | LIST_NEXT(&curpeers->peers_fe->conf.listeners, struct listener *, by_fe)->maxaccept = 1; |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 7133 | last = &curpeers->next; |
| 7134 | continue; |
| 7135 | } |
| 7136 | |
| 7137 | Warning("Removing incomplete section 'peers %s' (no peer named '%s').\n", |
| 7138 | curpeers->id, localpeer); |
| 7139 | |
| 7140 | p = curpeers->remote; |
| 7141 | while (p) { |
| 7142 | pb = p->next; |
| 7143 | free(p->id); |
| 7144 | free(p); |
| 7145 | p = pb; |
| 7146 | } |
| 7147 | |
| 7148 | /* Destroy and unlink this curpeers section. |
| 7149 | * Note: curpeers is backed up into *last. |
| 7150 | */ |
| 7151 | free(curpeers->id); |
| 7152 | curpeers = curpeers->next; |
| 7153 | free(*last); |
| 7154 | *last = curpeers; |
| 7155 | } |
| 7156 | } |
| 7157 | |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 7158 | pool2_hdr_idx = create_pool("hdr_idx", |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame] | 7159 | global.tune.max_http_hdr * sizeof(struct hdr_idx_elem), |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 7160 | MEM_F_SHARED); |
| 7161 | |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 7162 | if (cfgerr > 0) |
| 7163 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7164 | out: |
| 7165 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7166 | } |
| 7167 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 7168 | /* |
| 7169 | * Registers the CFG keyword list <kwl> as a list of valid keywords for next |
| 7170 | * parsing sessions. |
| 7171 | */ |
| 7172 | void cfg_register_keywords(struct cfg_kw_list *kwl) |
| 7173 | { |
| 7174 | LIST_ADDQ(&cfg_keywords.list, &kwl->list); |
| 7175 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7176 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 7177 | /* |
| 7178 | * Unregisters the CFG keyword list <kwl> from the list of valid keywords. |
| 7179 | */ |
| 7180 | void cfg_unregister_keywords(struct cfg_kw_list *kwl) |
| 7181 | { |
| 7182 | LIST_DEL(&kwl->list); |
| 7183 | LIST_INIT(&kwl->list); |
| 7184 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7185 | |
| 7186 | /* |
| 7187 | * Local variables: |
| 7188 | * c-indent-level: 8 |
| 7189 | * c-basic-offset: 8 |
| 7190 | * End: |
| 7191 | */ |