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 | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 1788 | if (defproxy.iface_name) |
| 1789 | curproxy->iface_name = strdup(defproxy.iface_name); |
| 1790 | curproxy->iface_len = defproxy.iface_len; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1791 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1792 | |
Willy Tarreau | 3b6b1a9 | 2009-07-23 13:24:23 +0200 | [diff] [blame] | 1793 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1794 | if (defproxy.capture_name) |
| 1795 | curproxy->capture_name = strdup(defproxy.capture_name); |
| 1796 | curproxy->capture_namelen = defproxy.capture_namelen; |
| 1797 | curproxy->capture_len = defproxy.capture_len; |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 1798 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1799 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1800 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 1801 | curproxy->timeout.client = defproxy.timeout.client; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 1802 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | 036fae0 | 2008-01-06 13:24:40 +0100 | [diff] [blame] | 1803 | curproxy->timeout.httpreq = defproxy.timeout.httpreq; |
Willy Tarreau | b16a574 | 2010-01-10 14:46:16 +0100 | [diff] [blame] | 1804 | curproxy->timeout.httpka = defproxy.timeout.httpka; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1805 | curproxy->uri_auth = defproxy.uri_auth; |
| 1806 | curproxy->mon_net = defproxy.mon_net; |
| 1807 | curproxy->mon_mask = defproxy.mon_mask; |
| 1808 | if (defproxy.monitor_uri) |
| 1809 | curproxy->monitor_uri = strdup(defproxy.monitor_uri); |
| 1810 | curproxy->monitor_uri_len = defproxy.monitor_uri_len; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 1811 | if (defproxy.defbe.name) |
| 1812 | curproxy->defbe.name = strdup(defproxy.defbe.name); |
Willy Tarreau | 99a7ca2 | 2012-05-31 19:39:23 +0200 | [diff] [blame] | 1813 | |
| 1814 | /* get either a pointer to the logformat string or a copy of it */ |
| 1815 | curproxy->logformat_string = defproxy.logformat_string; |
| 1816 | if (curproxy->logformat_string && |
| 1817 | curproxy->logformat_string != default_http_log_format && |
| 1818 | curproxy->logformat_string != default_tcp_log_format && |
| 1819 | curproxy->logformat_string != clf_http_log_format) |
| 1820 | curproxy->logformat_string = strdup(curproxy->logformat_string); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1821 | } |
| 1822 | |
| 1823 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 1824 | curproxy->timeout.connect = defproxy.timeout.connect; |
| 1825 | curproxy->timeout.server = defproxy.timeout.server; |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 1826 | curproxy->timeout.check = defproxy.timeout.check; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 1827 | curproxy->timeout.queue = defproxy.timeout.queue; |
Willy Tarreau | 51c9bde | 2008-01-06 13:40:03 +0100 | [diff] [blame] | 1828 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | cd7afc0 | 2009-07-12 10:03:17 +0200 | [diff] [blame] | 1829 | curproxy->timeout.httpreq = defproxy.timeout.httpreq; |
Willy Tarreau | b16a574 | 2010-01-10 14:46:16 +0100 | [diff] [blame] | 1830 | curproxy->timeout.httpka = defproxy.timeout.httpka; |
Willy Tarreau | ce887fd | 2012-05-12 12:50:00 +0200 | [diff] [blame] | 1831 | curproxy->timeout.tunnel = defproxy.timeout.tunnel; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1832 | curproxy->source_addr = defproxy.source_addr; |
| 1833 | } |
| 1834 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1835 | curproxy->mode = defproxy.mode; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1836 | |
| 1837 | /* copy default logsrvs to curproxy */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 1838 | list_for_each_entry(tmplogsrv, &defproxy.logsrvs, list) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1839 | struct logsrv *node = malloc(sizeof(struct logsrv)); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 1840 | memcpy(node, tmplogsrv, sizeof(struct logsrv)); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1841 | LIST_INIT(&node->list); |
| 1842 | LIST_ADDQ(&curproxy->logsrvs, &node->list); |
| 1843 | } |
| 1844 | |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 1845 | curproxy->uniqueid_format_string = defproxy.uniqueid_format_string; |
| 1846 | if (curproxy->uniqueid_format_string) |
| 1847 | curproxy->uniqueid_format_string = strdup(curproxy->uniqueid_format_string); |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 1848 | |
| 1849 | /* copy default header unique id */ |
| 1850 | if (defproxy.header_unique_id) |
| 1851 | curproxy->header_unique_id = strdup(defproxy.header_unique_id); |
| 1852 | |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 1853 | /* default compression options */ |
| 1854 | if (defproxy.comp != NULL) { |
| 1855 | curproxy->comp = calloc(1, sizeof(struct comp)); |
| 1856 | curproxy->comp->algos = defproxy.comp->algos; |
| 1857 | curproxy->comp->types = defproxy.comp->types; |
| 1858 | } |
| 1859 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1860 | curproxy->grace = defproxy.grace; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1861 | curproxy->conf.used_listener_id = EB_ROOT; |
| 1862 | curproxy->conf.used_server_id = EB_ROOT; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 1863 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1864 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1865 | } |
| 1866 | else if (!strcmp(args[0], "defaults")) { /* use this one to assign default values */ |
| 1867 | /* some variables may have already been initialized earlier */ |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 1868 | /* FIXME-20070101: we should do this too at the end of the |
| 1869 | * config parsing to free all default values. |
| 1870 | */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1871 | free(defproxy.check_req); |
| 1872 | free(defproxy.cookie_name); |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 1873 | free(defproxy.rdp_cookie_name); |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 1874 | free(defproxy.cookie_domain); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1875 | free(defproxy.url_param_name); |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 1876 | free(defproxy.hh_name); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1877 | free(defproxy.capture_name); |
| 1878 | free(defproxy.monitor_uri); |
| 1879 | free(defproxy.defbe.name); |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 1880 | free(defproxy.iface_name); |
Willy Tarreau | 79f5fe8 | 2008-08-23 08:18:21 +0200 | [diff] [blame] | 1881 | free(defproxy.fwdfor_hdr_name); |
| 1882 | defproxy.fwdfor_hdr_len = 0; |
Willy Tarreau | b86db34 | 2009-11-30 11:50:16 +0100 | [diff] [blame] | 1883 | free(defproxy.orgto_hdr_name); |
| 1884 | defproxy.orgto_hdr_len = 0; |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 1885 | free(defproxy.server_id_hdr_name); |
| 1886 | defproxy.server_id_hdr_len = 0; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 1887 | free(defproxy.expect_str); |
| 1888 | if (defproxy.expect_regex) regfree(defproxy.expect_regex); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 1889 | |
Willy Tarreau | 39b0665 | 2012-06-01 10:58:06 +0200 | [diff] [blame] | 1890 | if (defproxy.logformat_string != default_http_log_format && |
| 1891 | defproxy.logformat_string != default_tcp_log_format && |
| 1892 | defproxy.logformat_string != clf_http_log_format) |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 1893 | free(defproxy.logformat_string); |
| 1894 | |
| 1895 | free(defproxy.uniqueid_format_string); |
| 1896 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1897 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1898 | chunk_destroy(&defproxy.errmsg[rc]); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 1899 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1900 | /* we cannot free uri_auth because it might already be used */ |
| 1901 | init_default_instance(); |
| 1902 | curproxy = &defproxy; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1903 | defproxy.cap = PR_CAP_LISTEN; /* all caps for now */ |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1904 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1905 | } |
| 1906 | else if (curproxy == NULL) { |
| 1907 | Alert("parsing [%s:%d] : 'listen' or 'defaults' expected.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1908 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1909 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1910 | } |
| 1911 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1912 | |
| 1913 | /* Now let's parse the proxy-specific keywords */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1914 | if (!strcmp(args[0], "bind")) { /* new listen addresses */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1915 | struct listener *l; |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1916 | int cur_arg; |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 1917 | char *err_msg = NULL; |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1918 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1919 | if (curproxy == &defproxy) { |
| 1920 | 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] | 1921 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1922 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1923 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1924 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1925 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1926 | |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 1927 | if ( *(args[1]) != '/' && strchr(args[1], ':') == NULL) { |
Willy Tarreau | d55c3fe | 2010-11-09 09:50:37 +0100 | [diff] [blame] | 1928 | 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] | 1929 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1930 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1931 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1932 | } |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 1933 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 1934 | bind_conf = bind_conf_alloc(&curproxy->conf.bind, file, linenum, args[1]); |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1935 | 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] | 1936 | |
| 1937 | /* NOTE: the following line might create several listeners if there |
| 1938 | * are comma-separated IPs or port ranges. So all further processing |
| 1939 | * will have to be applied to all listeners created after last_listen. |
| 1940 | */ |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 1941 | if (!str2listener(args[1], curproxy, bind_conf, file, linenum, &err_msg)) { |
| 1942 | if (err_msg && *err_msg) { |
| 1943 | indent_msg(&err_msg, 2); |
| 1944 | Alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], err_msg); |
| 1945 | } |
| 1946 | else |
| 1947 | Alert("parsing [%s:%d] : '%s' : error encountered while parsing listening address '%s'.\n", |
| 1948 | file, linenum, args[0], args[1]); |
| 1949 | free(err_msg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1950 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1951 | goto out; |
| 1952 | } |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1953 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1954 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
| 1955 | /* Set default global rights and owner for unix bind */ |
Willy Tarreau | c8b1109 | 2011-02-16 11:08:57 +0100 | [diff] [blame] | 1956 | global.maxsock++; |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 1957 | } |
| 1958 | |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1959 | cur_arg = 2; |
| 1960 | while (*(args[cur_arg])) { |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 1961 | static int bind_dumped; |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 1962 | struct bind_kw *kw; |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 1963 | char *err; |
| 1964 | |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 1965 | kw = bind_find_kw(args[cur_arg]); |
| 1966 | if (kw) { |
| 1967 | char *err = NULL; |
| 1968 | int code; |
| 1969 | |
| 1970 | if (!kw->parse) { |
Willy Tarreau | dda322d | 2012-09-18 16:34:09 +0200 | [diff] [blame] | 1971 | Alert("parsing [%s:%d] : '%s %s' : '%s' option is not implemented in this version (check build options).\n", |
| 1972 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 1973 | cur_arg += 1 + kw->skip ; |
| 1974 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1975 | goto out; |
| 1976 | } |
| 1977 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1978 | code = kw->parse(args, cur_arg, curproxy, bind_conf, &err); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 1979 | err_code |= code; |
| 1980 | |
| 1981 | if (code) { |
| 1982 | if (err && *err) { |
| 1983 | indent_msg(&err, 2); |
Willy Tarreau | dda322d | 2012-09-18 16:34:09 +0200 | [diff] [blame] | 1984 | 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] | 1985 | } |
| 1986 | else |
Willy Tarreau | dda322d | 2012-09-18 16:34:09 +0200 | [diff] [blame] | 1987 | Alert("parsing [%s:%d] : '%s %s' : error encountered while processing '%s'.\n", |
| 1988 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 1989 | if (code & ERR_FATAL) { |
| 1990 | free(err); |
| 1991 | cur_arg += 1 + kw->skip; |
| 1992 | goto out; |
| 1993 | } |
| 1994 | } |
| 1995 | free(err); |
| 1996 | cur_arg += 1 + kw->skip; |
| 1997 | continue; |
| 1998 | } |
| 1999 | |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 2000 | err = NULL; |
| 2001 | if (!bind_dumped) { |
| 2002 | bind_dump_kws(&err); |
| 2003 | indent_msg(&err, 4); |
| 2004 | bind_dumped = 1; |
| 2005 | } |
| 2006 | |
| 2007 | Alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'.%s%s\n", |
| 2008 | file, linenum, args[0], args[1], args[cur_arg], |
| 2009 | err ? " Registered keywords :" : "", err ? err : ""); |
| 2010 | free(err); |
| 2011 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2012 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2013 | goto out; |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 2014 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2015 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2016 | } |
| 2017 | else if (!strcmp(args[0], "monitor-net")) { /* set the range of IPs to ignore */ |
| 2018 | if (!*args[1] || !str2net(args[1], &curproxy->mon_net, &curproxy->mon_mask)) { |
| 2019 | Alert("parsing [%s:%d] : '%s' expects address[/mask].\n", |
| 2020 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2021 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2022 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2023 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2024 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2025 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2026 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2027 | /* flush useless bits */ |
| 2028 | curproxy->mon_net.s_addr &= curproxy->mon_mask.s_addr; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2029 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2030 | } |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2031 | else if (!strcmp(args[0], "monitor-uri")) { /* set the URI to intercept */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2032 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2033 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2034 | |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2035 | if (!*args[1]) { |
| 2036 | Alert("parsing [%s:%d] : '%s' expects an URI.\n", |
| 2037 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2038 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2039 | goto out; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2040 | } |
| 2041 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2042 | free(curproxy->monitor_uri); |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 2043 | curproxy->monitor_uri_len = strlen(args[1]); |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2044 | curproxy->monitor_uri = (char *)calloc(1, curproxy->monitor_uri_len + 1); |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 2045 | memcpy(curproxy->monitor_uri, args[1], curproxy->monitor_uri_len); |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2046 | curproxy->monitor_uri[curproxy->monitor_uri_len] = '\0'; |
| 2047 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2048 | goto out; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2049 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2050 | else if (!strcmp(args[0], "mode")) { /* sets the proxy mode */ |
| 2051 | if (!strcmp(args[1], "http")) curproxy->mode = PR_MODE_HTTP; |
| 2052 | else if (!strcmp(args[1], "tcp")) curproxy->mode = PR_MODE_TCP; |
| 2053 | else if (!strcmp(args[1], "health")) curproxy->mode = PR_MODE_HEALTH; |
| 2054 | else { |
| 2055 | 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] | 2056 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2057 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2058 | } |
| 2059 | } |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2060 | else if (!strcmp(args[0], "id")) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2061 | struct eb32_node *node; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2062 | |
| 2063 | if (curproxy == &defproxy) { |
| 2064 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", |
| 2065 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2066 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2067 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2068 | } |
| 2069 | |
| 2070 | if (!*args[1]) { |
| 2071 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 2072 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2073 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2074 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2075 | } |
| 2076 | |
| 2077 | curproxy->uuid = atol(args[1]); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2078 | curproxy->conf.id.key = curproxy->uuid; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2079 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2080 | if (curproxy->uuid <= 0) { |
| 2081 | Alert("parsing [%s:%d]: custom id has to be > 0.\n", |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2082 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2083 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2084 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2085 | } |
| 2086 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2087 | node = eb32_lookup(&used_proxy_id, curproxy->uuid); |
| 2088 | if (node) { |
| 2089 | struct proxy *target = container_of(node, struct proxy, conf.id); |
| 2090 | Alert("parsing [%s:%d]: %s %s reuses same custom id as %s %s (declared at %s:%d).\n", |
| 2091 | file, linenum, proxy_type_str(curproxy), curproxy->id, |
| 2092 | proxy_type_str(target), target->id, target->conf.file, target->conf.line); |
| 2093 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2094 | goto out; |
| 2095 | } |
| 2096 | eb32_insert(&used_proxy_id, &curproxy->conf.id); |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2097 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 2098 | else if (!strcmp(args[0], "description")) { |
| 2099 | int i, len=0; |
| 2100 | char *d; |
| 2101 | |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 2102 | if (curproxy == &defproxy) { |
| 2103 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", |
| 2104 | file, linenum, args[0]); |
| 2105 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2106 | goto out; |
| 2107 | } |
| 2108 | |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 2109 | if (!*args[1]) { |
| 2110 | Alert("parsing [%s:%d]: '%s' expects a string argument.\n", |
| 2111 | file, linenum, args[0]); |
| 2112 | return -1; |
| 2113 | } |
| 2114 | |
| 2115 | for(i=1; *args[i]; i++) |
| 2116 | len += strlen(args[i])+1; |
| 2117 | |
| 2118 | d = (char *)calloc(1, len); |
| 2119 | curproxy->desc = d; |
| 2120 | |
| 2121 | d += sprintf(d, "%s", args[1]); |
| 2122 | for(i=2; *args[i]; i++) |
| 2123 | d += sprintf(d, " %s", args[i]); |
| 2124 | |
| 2125 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2126 | else if (!strcmp(args[0], "disabled")) { /* disables this proxy */ |
| 2127 | curproxy->state = PR_STSTOPPED; |
| 2128 | } |
| 2129 | else if (!strcmp(args[0], "enabled")) { /* enables this proxy (used to revert a disabled default) */ |
| 2130 | curproxy->state = PR_STNEW; |
| 2131 | } |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2132 | else if (!strcmp(args[0], "bind-process")) { /* enable this proxy only on some processes */ |
| 2133 | int cur_arg = 1; |
| 2134 | unsigned int set = 0; |
| 2135 | |
| 2136 | while (*args[cur_arg]) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 2137 | unsigned int low, high; |
| 2138 | |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2139 | if (strcmp(args[cur_arg], "all") == 0) { |
| 2140 | set = 0; |
| 2141 | break; |
| 2142 | } |
| 2143 | else if (strcmp(args[cur_arg], "odd") == 0) { |
| 2144 | set |= 0x55555555; |
| 2145 | } |
| 2146 | else if (strcmp(args[cur_arg], "even") == 0) { |
| 2147 | set |= 0xAAAAAAAA; |
| 2148 | } |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 2149 | else if (isdigit((int)*args[cur_arg])) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 2150 | char *dash = strchr(args[cur_arg], '-'); |
| 2151 | |
| 2152 | low = high = str2uic(args[cur_arg]); |
| 2153 | if (dash) |
| 2154 | high = str2uic(dash + 1); |
| 2155 | |
| 2156 | if (high < low) { |
| 2157 | unsigned int swap = low; |
| 2158 | low = high; |
| 2159 | high = swap; |
| 2160 | } |
| 2161 | |
| 2162 | if (low < 1 || high > 32) { |
| 2163 | 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] | 2164 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2165 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2166 | goto out; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2167 | } |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 2168 | |
| 2169 | if (high > global.nbproc) { |
| 2170 | Warning("parsing [%s:%d]: %s references process number %d which is higher than global.nbproc (%d).\n", |
| 2171 | file, linenum, args[0], high, global.nbproc); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2172 | err_code |= ERR_WARN; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2173 | } |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 2174 | while (low <= high) |
| 2175 | set |= 1 << (low++ - 1); |
| 2176 | } |
| 2177 | else { |
| 2178 | Alert("parsing [%s:%d]: %s expects 'all', 'odd', 'even', or a list of process ranges with numbers from 1 to 32.\n", |
| 2179 | file, linenum, args[0]); |
| 2180 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2181 | goto out; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2182 | } |
| 2183 | cur_arg++; |
| 2184 | } |
| 2185 | curproxy->bind_proc = set; |
| 2186 | } |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 2187 | else if (!strcmp(args[0], "acl")) { /* add an ACL */ |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2188 | if (curproxy == &defproxy) { |
| 2189 | 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] | 2190 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2191 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2192 | } |
| 2193 | |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 2194 | err = invalid_char(args[1]); |
| 2195 | if (err) { |
| 2196 | Alert("parsing [%s:%d] : character '%c' is not permitted in acl name '%s'.\n", |
| 2197 | file, linenum, *err, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2198 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 2199 | } |
| 2200 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 2201 | if (parse_acl((const char **)args + 1, &curproxy->acl, &errmsg) == NULL) { |
| 2202 | Alert("parsing [%s:%d] : error detected while parsing ACL '%s' : %s.\n", |
| 2203 | file, linenum, args[1], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2204 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2205 | goto out; |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 2206 | } |
| 2207 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2208 | else if (!strcmp(args[0], "cookie")) { /* cookie name */ |
| 2209 | int cur_arg; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2210 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2211 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2212 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2213 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2214 | if (*(args[1]) == 0) { |
| 2215 | Alert("parsing [%s:%d] : '%s' expects <cookie_name> as argument.\n", |
| 2216 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2217 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2218 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2219 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2220 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2221 | curproxy->ck_opts = 0; |
Willy Tarreau | c63d4bb | 2010-10-23 11:37:27 +0200 | [diff] [blame] | 2222 | curproxy->cookie_maxidle = curproxy->cookie_maxlife = 0; |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 2223 | free(curproxy->cookie_domain); curproxy->cookie_domain = NULL; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2224 | free(curproxy->cookie_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2225 | curproxy->cookie_name = strdup(args[1]); |
| 2226 | curproxy->cookie_len = strlen(curproxy->cookie_name); |
Willy Tarreau | c63d4bb | 2010-10-23 11:37:27 +0200 | [diff] [blame] | 2227 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2228 | cur_arg = 2; |
| 2229 | while (*(args[cur_arg])) { |
| 2230 | if (!strcmp(args[cur_arg], "rewrite")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2231 | curproxy->ck_opts |= PR_CK_RW; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2232 | } |
| 2233 | else if (!strcmp(args[cur_arg], "indirect")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2234 | curproxy->ck_opts |= PR_CK_IND; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2235 | } |
| 2236 | else if (!strcmp(args[cur_arg], "insert")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2237 | curproxy->ck_opts |= PR_CK_INS; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2238 | } |
| 2239 | else if (!strcmp(args[cur_arg], "nocache")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2240 | curproxy->ck_opts |= PR_CK_NOC; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2241 | } |
| 2242 | else if (!strcmp(args[cur_arg], "postonly")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2243 | curproxy->ck_opts |= PR_CK_POST; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2244 | } |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 2245 | else if (!strcmp(args[cur_arg], "preserve")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2246 | curproxy->ck_opts |= PR_CK_PSV; |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 2247 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2248 | else if (!strcmp(args[cur_arg], "prefix")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2249 | curproxy->ck_opts |= PR_CK_PFX; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2250 | } |
Willy Tarreau | 4992dd2 | 2012-05-31 21:02:17 +0200 | [diff] [blame] | 2251 | else if (!strcmp(args[cur_arg], "httponly")) { |
| 2252 | curproxy->ck_opts |= PR_CK_HTTPONLY; |
| 2253 | } |
| 2254 | else if (!strcmp(args[cur_arg], "secure")) { |
| 2255 | curproxy->ck_opts |= PR_CK_SECURE; |
| 2256 | } |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2257 | else if (!strcmp(args[cur_arg], "domain")) { |
| 2258 | if (!*args[cur_arg + 1]) { |
| 2259 | Alert("parsing [%s:%d]: '%s' expects <domain> as argument.\n", |
| 2260 | file, linenum, args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2261 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2262 | goto out; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2263 | } |
| 2264 | |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 2265 | if (*args[cur_arg + 1] != '.' || !strchr(args[cur_arg + 1] + 1, '.')) { |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2266 | /* rfc2109, 4.3.2 Rejecting Cookies */ |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 2267 | Warning("parsing [%s:%d]: domain '%s' contains no embedded" |
| 2268 | " dots nor does not start with a dot." |
| 2269 | " RFC forbids it, this configuration may not work properly.\n", |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2270 | file, linenum, args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 2271 | err_code |= ERR_WARN; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2272 | } |
| 2273 | |
| 2274 | err = invalid_domainchar(args[cur_arg + 1]); |
| 2275 | if (err) { |
| 2276 | Alert("parsing [%s:%d]: character '%c' is not permitted in domain name '%s'.\n", |
| 2277 | file, linenum, *err, args[cur_arg + 1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2278 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2279 | goto out; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2280 | } |
| 2281 | |
Willy Tarreau | 68a897b | 2009-12-03 23:28:34 +0100 | [diff] [blame] | 2282 | if (!curproxy->cookie_domain) { |
| 2283 | curproxy->cookie_domain = strdup(args[cur_arg + 1]); |
| 2284 | } else { |
| 2285 | /* one domain was already specified, add another one by |
| 2286 | * building the string which will be returned along with |
| 2287 | * the cookie. |
| 2288 | */ |
| 2289 | char *new_ptr; |
| 2290 | int new_len = strlen(curproxy->cookie_domain) + |
| 2291 | strlen("; domain=") + strlen(args[cur_arg + 1]) + 1; |
| 2292 | new_ptr = malloc(new_len); |
| 2293 | snprintf(new_ptr, new_len, "%s; domain=%s", curproxy->cookie_domain, args[cur_arg+1]); |
| 2294 | free(curproxy->cookie_domain); |
| 2295 | curproxy->cookie_domain = new_ptr; |
| 2296 | } |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 2297 | cur_arg++; |
| 2298 | } |
| 2299 | else if (!strcmp(args[cur_arg], "maxidle")) { |
| 2300 | unsigned int maxidle; |
| 2301 | const char *res; |
| 2302 | |
| 2303 | if (!*args[cur_arg + 1]) { |
| 2304 | Alert("parsing [%s:%d]: '%s' expects <idletime> in seconds as argument.\n", |
| 2305 | file, linenum, args[cur_arg]); |
| 2306 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2307 | goto out; |
| 2308 | } |
| 2309 | |
| 2310 | res = parse_time_err(args[cur_arg + 1], &maxidle, TIME_UNIT_S); |
| 2311 | if (res) { |
| 2312 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 2313 | file, linenum, *res, args[cur_arg]); |
| 2314 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2315 | goto out; |
| 2316 | } |
| 2317 | curproxy->cookie_maxidle = maxidle; |
| 2318 | cur_arg++; |
| 2319 | } |
| 2320 | else if (!strcmp(args[cur_arg], "maxlife")) { |
| 2321 | unsigned int maxlife; |
| 2322 | const char *res; |
| 2323 | |
| 2324 | if (!*args[cur_arg + 1]) { |
| 2325 | Alert("parsing [%s:%d]: '%s' expects <lifetime> in seconds as argument.\n", |
| 2326 | file, linenum, args[cur_arg]); |
| 2327 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2328 | goto out; |
| 2329 | } |
| 2330 | |
| 2331 | res = parse_time_err(args[cur_arg + 1], &maxlife, TIME_UNIT_S); |
| 2332 | if (res) { |
| 2333 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 2334 | file, linenum, *res, args[cur_arg]); |
| 2335 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2336 | goto out; |
| 2337 | } |
| 2338 | curproxy->cookie_maxlife = maxlife; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2339 | cur_arg++; |
| 2340 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2341 | else { |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 2342 | 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] | 2343 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2344 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2345 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2346 | } |
| 2347 | cur_arg++; |
| 2348 | } |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2349 | if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_IND))) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2350 | Alert("parsing [%s:%d] : cookie 'rewrite' and 'indirect' modes are incompatible.\n", |
| 2351 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2352 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2353 | } |
| 2354 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2355 | 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] | 2356 | Alert("parsing [%s:%d] : cookie 'rewrite', 'insert' and 'prefix' modes are incompatible.\n", |
| 2357 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2358 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2359 | } |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 2360 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2361 | 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] | 2362 | Alert("parsing [%s:%d] : cookie 'preserve' requires at least 'insert' or 'indirect'.\n", |
| 2363 | file, linenum); |
| 2364 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2365 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2366 | }/* end else if (!strcmp(args[0], "cookie")) */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2367 | else if (!strcmp(args[0], "persist")) { /* persist */ |
| 2368 | if (*(args[1]) == 0) { |
| 2369 | Alert("parsing [%s:%d] : missing persist method.\n", |
| 2370 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2371 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2372 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2373 | } |
| 2374 | |
| 2375 | if (!strncmp(args[1], "rdp-cookie", 10)) { |
| 2376 | curproxy->options2 |= PR_O2_RDPC_PRST; |
| 2377 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2378 | if (*(args[1] + 10) == '(') { /* cookie name */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2379 | const char *beg, *end; |
| 2380 | |
| 2381 | beg = args[1] + 11; |
| 2382 | end = strchr(beg, ')'); |
| 2383 | |
| 2384 | if (!end || end == beg) { |
| 2385 | Alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n", |
| 2386 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2387 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2388 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2389 | } |
| 2390 | |
| 2391 | free(curproxy->rdp_cookie_name); |
| 2392 | curproxy->rdp_cookie_name = my_strndup(beg, end - beg); |
| 2393 | curproxy->rdp_cookie_len = end-beg; |
| 2394 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2395 | else if (*(args[1] + 10) == '\0') { /* default cookie name 'msts' */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2396 | free(curproxy->rdp_cookie_name); |
| 2397 | curproxy->rdp_cookie_name = strdup("msts"); |
| 2398 | curproxy->rdp_cookie_len = strlen(curproxy->rdp_cookie_name); |
| 2399 | } |
| 2400 | else { /* syntax */ |
| 2401 | Alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n", |
| 2402 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2403 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2404 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2405 | } |
| 2406 | } |
| 2407 | else { |
| 2408 | Alert("parsing [%s:%d] : unknown persist method.\n", |
| 2409 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2410 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2411 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2412 | } |
| 2413 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2414 | else if (!strcmp(args[0], "appsession")) { /* cookie name */ |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2415 | int cur_arg; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2416 | |
Cyril Bonté | 3b7a369 | 2010-01-10 17:01:47 +0100 | [diff] [blame] | 2417 | if (curproxy == &defproxy) { |
| 2418 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2419 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2420 | goto out; |
| 2421 | } |
| 2422 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2423 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2424 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2425 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2426 | if (*(args[5]) == 0) { |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2427 | 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] | 2428 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2429 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2430 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2431 | } |
| 2432 | have_appsession = 1; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2433 | free(curproxy->appsession_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2434 | curproxy->appsession_name = strdup(args[1]); |
| 2435 | curproxy->appsession_name_len = strlen(curproxy->appsession_name); |
| 2436 | curproxy->appsession_len = atoi(args[3]); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 2437 | err = parse_time_err(args[5], &val, TIME_UNIT_MS); |
| 2438 | if (err) { |
| 2439 | Alert("parsing [%s:%d] : unexpected character '%c' in %s timeout.\n", |
| 2440 | file, linenum, *err, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2441 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2442 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 2443 | } |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 2444 | curproxy->timeout.appsession = val; |
Willy Tarreau | ee99136 | 2007-05-14 14:37:50 +0200 | [diff] [blame] | 2445 | |
Willy Tarreau | 51041c7 | 2007-09-09 21:56:53 +0200 | [diff] [blame] | 2446 | if (appsession_hash_init(&(curproxy->htbl_proxy), destroy) == 0) { |
| 2447 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2448 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2449 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2450 | } |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2451 | |
| 2452 | cur_arg = 6; |
| 2453 | curproxy->options2 &= ~PR_O2_AS_REQL; |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2454 | curproxy->options2 &= ~PR_O2_AS_M_ANY; |
| 2455 | curproxy->options2 |= PR_O2_AS_M_PP; |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2456 | while (*(args[cur_arg])) { |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2457 | if (!strcmp(args[cur_arg], "request-learn")) { |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2458 | curproxy->options2 |= PR_O2_AS_REQL; |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2459 | } else if (!strcmp(args[cur_arg], "prefix")) { |
| 2460 | curproxy->options2 |= PR_O2_AS_PFX; |
| 2461 | } else if (!strcmp(args[cur_arg], "mode")) { |
| 2462 | if (!*args[cur_arg + 1]) { |
| 2463 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 2464 | file, linenum, args[0], args[cur_arg]); |
| 2465 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2466 | goto out; |
| 2467 | } |
| 2468 | |
| 2469 | cur_arg++; |
| 2470 | if (!strcmp(args[cur_arg], "query-string")) { |
| 2471 | curproxy->options2 &= ~PR_O2_AS_M_ANY; |
| 2472 | curproxy->options2 |= PR_O2_AS_M_QS; |
| 2473 | } else if (!strcmp(args[cur_arg], "path-parameters")) { |
| 2474 | curproxy->options2 &= ~PR_O2_AS_M_ANY; |
| 2475 | curproxy->options2 |= PR_O2_AS_M_PP; |
| 2476 | } else { |
| 2477 | Alert("parsing [%s:%d] : unknown mode '%s'\n", file, linenum, args[cur_arg]); |
| 2478 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2479 | goto out; |
| 2480 | } |
| 2481 | } |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2482 | cur_arg++; |
| 2483 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2484 | } /* Url App Session */ |
| 2485 | else if (!strcmp(args[0], "capture")) { |
Willy Tarreau | 3b6b1a9 | 2009-07-23 13:24:23 +0200 | [diff] [blame] | 2486 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2487 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2488 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2489 | if (!strcmp(args[1], "cookie")) { /* name of a cookie to capture */ |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 2490 | if (curproxy == &defproxy) { |
| 2491 | Alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
| 2492 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2493 | goto out; |
| 2494 | } |
| 2495 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2496 | if (*(args[4]) == 0) { |
| 2497 | Alert("parsing [%s:%d] : '%s' expects 'cookie' <cookie_name> 'len' <len>.\n", |
| 2498 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2499 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2500 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2501 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2502 | free(curproxy->capture_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2503 | curproxy->capture_name = strdup(args[2]); |
| 2504 | curproxy->capture_namelen = strlen(curproxy->capture_name); |
| 2505 | curproxy->capture_len = atol(args[4]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2506 | curproxy->to_log |= LW_COOKIE; |
| 2507 | } |
| 2508 | else if (!strcmp(args[1], "request") && !strcmp(args[2], "header")) { |
| 2509 | struct cap_hdr *hdr; |
| 2510 | |
| 2511 | if (curproxy == &defproxy) { |
| 2512 | 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] | 2513 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2514 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2515 | } |
| 2516 | |
| 2517 | if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) { |
| 2518 | Alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n", |
| 2519 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2520 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2521 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2522 | } |
| 2523 | |
| 2524 | hdr = calloc(sizeof(struct cap_hdr), 1); |
| 2525 | hdr->next = curproxy->req_cap; |
| 2526 | hdr->name = strdup(args[3]); |
| 2527 | hdr->namelen = strlen(args[3]); |
| 2528 | hdr->len = atol(args[5]); |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 2529 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2530 | hdr->index = curproxy->nb_req_cap++; |
| 2531 | curproxy->req_cap = hdr; |
| 2532 | curproxy->to_log |= LW_REQHDR; |
| 2533 | } |
| 2534 | else if (!strcmp(args[1], "response") && !strcmp(args[2], "header")) { |
| 2535 | struct cap_hdr *hdr; |
| 2536 | |
| 2537 | if (curproxy == &defproxy) { |
| 2538 | 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] | 2539 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2540 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2541 | } |
| 2542 | |
| 2543 | if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) { |
| 2544 | Alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n", |
| 2545 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2546 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2547 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2548 | } |
| 2549 | hdr = calloc(sizeof(struct cap_hdr), 1); |
| 2550 | hdr->next = curproxy->rsp_cap; |
| 2551 | hdr->name = strdup(args[3]); |
| 2552 | hdr->namelen = strlen(args[3]); |
| 2553 | hdr->len = atol(args[5]); |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 2554 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2555 | hdr->index = curproxy->nb_rsp_cap++; |
| 2556 | curproxy->rsp_cap = hdr; |
| 2557 | curproxy->to_log |= LW_RSPHDR; |
| 2558 | } |
| 2559 | else { |
| 2560 | Alert("parsing [%s:%d] : '%s' expects 'cookie' or 'request header' or 'response header'.\n", |
| 2561 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2562 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2563 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2564 | } |
| 2565 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2566 | else if (!strcmp(args[0], "retries")) { /* connection retries */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2567 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2568 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2569 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2570 | if (*(args[1]) == 0) { |
| 2571 | Alert("parsing [%s:%d] : '%s' expects an integer argument (dispatch counts for one).\n", |
| 2572 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2573 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2574 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2575 | } |
| 2576 | curproxy->conn_retries = atol(args[1]); |
| 2577 | } |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2578 | 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] | 2579 | struct http_req_rule *rule; |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2580 | |
| 2581 | if (curproxy == &defproxy) { |
| 2582 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2583 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2584 | goto out; |
| 2585 | } |
| 2586 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 2587 | 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] | 2588 | Warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n", |
| 2589 | file, linenum, args[0]); |
| 2590 | err_code |= ERR_WARN; |
| 2591 | } |
| 2592 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 2593 | 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] | 2594 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 2595 | if (!rule) { |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2596 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2597 | goto out; |
| 2598 | } |
| 2599 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 2600 | err_code |= warnif_cond_requires_resp(rule->cond, file, linenum); |
| 2601 | LIST_ADDQ(&curproxy->http_req_rules, &rule->list); |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2602 | } |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 2603 | else if (!strcmp(args[0], "http-send-name-header")) { /* send server name in request header */ |
| 2604 | /* set the header name and length into the proxy structure */ |
| 2605 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 2606 | err_code |= ERR_WARN; |
| 2607 | |
| 2608 | if (!*args[1]) { |
| 2609 | Alert("parsing [%s:%d] : '%s' requires a header string.\n", |
| 2610 | file, linenum, args[0]); |
| 2611 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2612 | goto out; |
| 2613 | } |
| 2614 | |
| 2615 | /* set the desired header name */ |
| 2616 | free(curproxy->server_id_hdr_name); |
| 2617 | curproxy->server_id_hdr_name = strdup(args[1]); |
| 2618 | curproxy->server_id_hdr_len = strlen(curproxy->server_id_hdr_name); |
| 2619 | } |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2620 | else if (!strcmp(args[0], "block")) { /* early blocking based on ACLs */ |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2621 | if (curproxy == &defproxy) { |
| 2622 | 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] | 2623 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2624 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2625 | } |
| 2626 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2627 | if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) { |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2628 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 2629 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2630 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2631 | goto out; |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2632 | } |
| 2633 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 2634 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 1, &errmsg)) == NULL) { |
| 2635 | Alert("parsing [%s:%d] : error detected while parsing blocking condition : %s.\n", |
| 2636 | file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2637 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2638 | goto out; |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2639 | } |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2640 | |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2641 | LIST_ADDQ(&curproxy->block_cond, &cond->list); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 2642 | warnif_misplaced_block(curproxy, file, linenum, args[0]); |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2643 | } |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2644 | else if (!strcmp(args[0], "redirect")) { |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2645 | struct redirect_rule *rule; |
| 2646 | int cur_arg; |
| 2647 | int type = REDIRECT_TYPE_NONE; |
| 2648 | int code = 302; |
| 2649 | char *destination = NULL; |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2650 | char *cookie = NULL; |
| 2651 | int cookie_set = 0; |
Willy Tarreau | 79da469 | 2008-11-19 20:03:04 +0100 | [diff] [blame] | 2652 | unsigned int flags = REDIRECT_FLAG_NONE; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2653 | |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 2654 | if (curproxy == &defproxy) { |
| 2655 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2656 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2657 | goto out; |
| 2658 | } |
| 2659 | |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2660 | cur_arg = 1; |
| 2661 | while (*(args[cur_arg])) { |
| 2662 | if (!strcmp(args[cur_arg], "location")) { |
| 2663 | if (!*args[cur_arg + 1]) { |
| 2664 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 2665 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2666 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2667 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2668 | } |
| 2669 | |
| 2670 | type = REDIRECT_TYPE_LOCATION; |
| 2671 | cur_arg++; |
| 2672 | destination = args[cur_arg]; |
| 2673 | } |
| 2674 | else if (!strcmp(args[cur_arg], "prefix")) { |
| 2675 | if (!*args[cur_arg + 1]) { |
| 2676 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 2677 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2678 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2679 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2680 | } |
| 2681 | |
| 2682 | type = REDIRECT_TYPE_PREFIX; |
| 2683 | cur_arg++; |
| 2684 | destination = args[cur_arg]; |
| 2685 | } |
Willy Tarreau | 2e1dca8 | 2012-09-12 08:43:15 +0200 | [diff] [blame] | 2686 | else if (!strcmp(args[cur_arg], "scheme")) { |
| 2687 | if (!*args[cur_arg + 1]) { |
| 2688 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 2689 | file, linenum, args[0], args[cur_arg]); |
| 2690 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2691 | goto out; |
| 2692 | } |
| 2693 | |
| 2694 | type = REDIRECT_TYPE_SCHEME; |
| 2695 | cur_arg++; |
| 2696 | destination = args[cur_arg]; |
| 2697 | } |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2698 | else if (!strcmp(args[cur_arg], "set-cookie")) { |
| 2699 | if (!*args[cur_arg + 1]) { |
| 2700 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 2701 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2702 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2703 | goto out; |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2704 | } |
| 2705 | |
| 2706 | cur_arg++; |
| 2707 | cookie = args[cur_arg]; |
| 2708 | cookie_set = 1; |
| 2709 | } |
| 2710 | else if (!strcmp(args[cur_arg], "clear-cookie")) { |
| 2711 | if (!*args[cur_arg + 1]) { |
| 2712 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 2713 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2714 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2715 | goto out; |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2716 | } |
| 2717 | |
| 2718 | cur_arg++; |
| 2719 | cookie = args[cur_arg]; |
| 2720 | cookie_set = 0; |
| 2721 | } |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2722 | else if (!strcmp(args[cur_arg],"code")) { |
| 2723 | if (!*args[cur_arg + 1]) { |
| 2724 | Alert("parsing [%s:%d] : '%s': missing HTTP code.\n", |
| 2725 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2726 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2727 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2728 | } |
| 2729 | cur_arg++; |
| 2730 | code = atol(args[cur_arg]); |
| 2731 | if (code < 301 || code > 303) { |
| 2732 | Alert("parsing [%s:%d] : '%s': unsupported HTTP code '%d'.\n", |
| 2733 | file, linenum, args[0], code); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2734 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2735 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2736 | } |
| 2737 | } |
Willy Tarreau | 79da469 | 2008-11-19 20:03:04 +0100 | [diff] [blame] | 2738 | else if (!strcmp(args[cur_arg],"drop-query")) { |
| 2739 | flags |= REDIRECT_FLAG_DROP_QS; |
| 2740 | } |
Willy Tarreau | 81e3b4f | 2010-01-10 00:42:19 +0100 | [diff] [blame] | 2741 | else if (!strcmp(args[cur_arg],"append-slash")) { |
| 2742 | flags |= REDIRECT_FLAG_APPEND_SLASH; |
| 2743 | } |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2744 | else if (strcmp(args[cur_arg], "if") == 0 || |
| 2745 | strcmp(args[cur_arg], "unless") == 0) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 2746 | 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] | 2747 | if (!cond) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 2748 | Alert("parsing [%s:%d] : '%s': error detected while parsing redirect condition : %s.\n", |
| 2749 | file, linenum, args[0], errmsg); |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2750 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2751 | goto out; |
| 2752 | } |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2753 | break; |
| 2754 | } |
| 2755 | else { |
Willy Tarreau | 2e1dca8 | 2012-09-12 08:43:15 +0200 | [diff] [blame] | 2756 | 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] | 2757 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2758 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2759 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2760 | } |
| 2761 | cur_arg++; |
| 2762 | } |
| 2763 | |
| 2764 | if (type == REDIRECT_TYPE_NONE) { |
| 2765 | Alert("parsing [%s:%d] : '%s' expects a redirection type ('prefix' or 'location').\n", |
| 2766 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2767 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2768 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2769 | } |
| 2770 | |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2771 | rule = (struct redirect_rule *)calloc(1, sizeof(*rule)); |
| 2772 | rule->cond = cond; |
| 2773 | rule->rdr_str = strdup(destination); |
| 2774 | rule->rdr_len = strlen(destination); |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2775 | if (cookie) { |
| 2776 | /* 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] | 2777 | * a clear consists in appending "; path=/; Max-Age=0;" at the end. |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2778 | */ |
| 2779 | rule->cookie_len = strlen(cookie); |
William Turner | d986526 | 2010-03-01 13:30:34 -0500 | [diff] [blame] | 2780 | if (cookie_set) { |
| 2781 | rule->cookie_str = malloc(rule->cookie_len + 10); |
| 2782 | memcpy(rule->cookie_str, cookie, rule->cookie_len); |
| 2783 | memcpy(rule->cookie_str + rule->cookie_len, "; path=/;", 10); |
| 2784 | rule->cookie_len += 9; |
| 2785 | } else { |
| 2786 | rule->cookie_str = malloc(rule->cookie_len + 21); |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2787 | memcpy(rule->cookie_str, cookie, rule->cookie_len); |
William Turner | d986526 | 2010-03-01 13:30:34 -0500 | [diff] [blame] | 2788 | memcpy(rule->cookie_str + rule->cookie_len, "; path=/; Max-Age=0;", 21); |
| 2789 | rule->cookie_len += 20; |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2790 | } |
| 2791 | } |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2792 | rule->type = type; |
| 2793 | rule->code = code; |
Willy Tarreau | 79da469 | 2008-11-19 20:03:04 +0100 | [diff] [blame] | 2794 | rule->flags = flags; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2795 | LIST_INIT(&rule->list); |
| 2796 | LIST_ADDQ(&curproxy->redirect_rules, &rule->list); |
Willy Tarreau | 9d9ed01 | 2011-02-23 15:24:42 +0100 | [diff] [blame] | 2797 | err_code |= warnif_rule_after_use_backend(curproxy, file, linenum, args[0]); |
| 2798 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2799 | } |
Krzysztof Piotr Oledzki | 7b723ef | 2009-01-27 21:09:41 +0100 | [diff] [blame] | 2800 | else if (!strcmp(args[0], "use_backend")) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2801 | struct switching_rule *rule; |
| 2802 | |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2803 | if (curproxy == &defproxy) { |
| 2804 | 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] | 2805 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2806 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2807 | } |
| 2808 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2809 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2810 | err_code |= ERR_WARN; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2811 | |
| 2812 | if (*(args[1]) == 0) { |
| 2813 | 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] | 2814 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2815 | goto out; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2816 | } |
| 2817 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2818 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2819 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 2820 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2821 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2822 | goto out; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2823 | } |
| 2824 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 2825 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 2826 | Alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n", |
| 2827 | file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2828 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2829 | goto out; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2830 | } |
| 2831 | |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 2832 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
Willy Tarreau | a980263 | 2008-07-25 19:13:19 +0200 | [diff] [blame] | 2833 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2834 | rule = (struct switching_rule *)calloc(1, sizeof(*rule)); |
| 2835 | rule->cond = cond; |
| 2836 | rule->be.name = strdup(args[1]); |
| 2837 | LIST_INIT(&rule->list); |
| 2838 | LIST_ADDQ(&curproxy->switching_rules, &rule->list); |
| 2839 | } |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 2840 | else if (strcmp(args[0], "use-server") == 0) { |
| 2841 | struct server_rule *rule; |
| 2842 | |
| 2843 | if (curproxy == &defproxy) { |
| 2844 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2845 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2846 | goto out; |
| 2847 | } |
| 2848 | |
| 2849 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 2850 | err_code |= ERR_WARN; |
| 2851 | |
| 2852 | if (*(args[1]) == 0) { |
| 2853 | Alert("parsing [%s:%d] : '%s' expects a server name.\n", file, linenum, args[0]); |
| 2854 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2855 | goto out; |
| 2856 | } |
| 2857 | |
| 2858 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
| 2859 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 2860 | file, linenum, args[0]); |
| 2861 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2862 | goto out; |
| 2863 | } |
| 2864 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 2865 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 2866 | Alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n", |
| 2867 | file, linenum, errmsg); |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 2868 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2869 | goto out; |
| 2870 | } |
| 2871 | |
| 2872 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
| 2873 | |
| 2874 | rule = (struct server_rule *)calloc(1, sizeof(*rule)); |
| 2875 | rule->cond = cond; |
| 2876 | rule->srv.name = strdup(args[1]); |
| 2877 | LIST_INIT(&rule->list); |
| 2878 | LIST_ADDQ(&curproxy->server_rules, &rule->list); |
| 2879 | curproxy->be_req_ana |= AN_REQ_SRV_RULES; |
| 2880 | } |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 2881 | else if ((!strcmp(args[0], "force-persist")) || |
| 2882 | (!strcmp(args[0], "ignore-persist"))) { |
| 2883 | struct persist_rule *rule; |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2884 | |
| 2885 | if (curproxy == &defproxy) { |
| 2886 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2887 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2888 | goto out; |
| 2889 | } |
| 2890 | |
| 2891 | if (warnifnotcap(curproxy, PR_CAP_FE|PR_CAP_BE, file, linenum, args[0], NULL)) |
| 2892 | err_code |= ERR_WARN; |
| 2893 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2894 | if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) { |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2895 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 2896 | file, linenum, args[0]); |
| 2897 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2898 | goto out; |
| 2899 | } |
| 2900 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 2901 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 1, &errmsg)) == NULL) { |
| 2902 | Alert("parsing [%s:%d] : error detected while parsing a '%s' rule : %s.\n", |
| 2903 | file, linenum, args[0], errmsg); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2904 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2905 | goto out; |
| 2906 | } |
| 2907 | |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 2908 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2909 | |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 2910 | rule = (struct persist_rule *)calloc(1, sizeof(*rule)); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2911 | rule->cond = cond; |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 2912 | if (!strcmp(args[0], "force-persist")) { |
| 2913 | rule->type = PERSIST_TYPE_FORCE; |
| 2914 | } else { |
| 2915 | rule->type = PERSIST_TYPE_IGNORE; |
| 2916 | } |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2917 | LIST_INIT(&rule->list); |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 2918 | LIST_ADDQ(&curproxy->persist_rules, &rule->list); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2919 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2920 | else if (!strcmp(args[0], "stick-table")) { |
| 2921 | int myidx = 1; |
| 2922 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2923 | curproxy->table.id = curproxy->id; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2924 | curproxy->table.type = (unsigned int)-1; |
| 2925 | while (*args[myidx]) { |
| 2926 | const char *err; |
| 2927 | |
| 2928 | if (strcmp(args[myidx], "size") == 0) { |
| 2929 | myidx++; |
| 2930 | if (!*(args[myidx])) { |
| 2931 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 2932 | file, linenum, args[myidx-1]); |
| 2933 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2934 | goto out; |
| 2935 | } |
| 2936 | if ((err = parse_size_err(args[myidx], &curproxy->table.size))) { |
| 2937 | Alert("parsing [%s:%d] : stick-table: unexpected character '%c' in argument of '%s'.\n", |
| 2938 | file, linenum, *err, args[myidx-1]); |
| 2939 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2940 | goto out; |
| 2941 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 2942 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2943 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2944 | else if (strcmp(args[myidx], "peers") == 0) { |
| 2945 | myidx++; |
| 2946 | if (!*(args[myidx])) { |
| 2947 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 2948 | file, linenum, args[myidx-1]); |
| 2949 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2950 | goto out; |
| 2951 | } |
| 2952 | curproxy->table.peers.name = strdup(args[myidx++]); |
| 2953 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2954 | else if (strcmp(args[myidx], "expire") == 0) { |
| 2955 | myidx++; |
| 2956 | if (!*(args[myidx])) { |
| 2957 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 2958 | file, linenum, args[myidx-1]); |
| 2959 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2960 | goto out; |
| 2961 | } |
| 2962 | err = parse_time_err(args[myidx], &val, TIME_UNIT_MS); |
| 2963 | if (err) { |
| 2964 | Alert("parsing [%s:%d] : stick-table: unexpected character '%c' in argument of '%s'.\n", |
| 2965 | file, linenum, *err, args[myidx-1]); |
| 2966 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2967 | goto out; |
| 2968 | } |
| 2969 | curproxy->table.expire = val; |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 2970 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2971 | } |
| 2972 | else if (strcmp(args[myidx], "nopurge") == 0) { |
| 2973 | curproxy->table.nopurge = 1; |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 2974 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2975 | } |
| 2976 | else if (strcmp(args[myidx], "type") == 0) { |
| 2977 | myidx++; |
| 2978 | if (stktable_parse_type(args, &myidx, &curproxy->table.type, &curproxy->table.key_size) != 0) { |
| 2979 | Alert("parsing [%s:%d] : stick-table: unknown type '%s'.\n", |
| 2980 | file, linenum, args[myidx]); |
| 2981 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2982 | goto out; |
| 2983 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 2984 | /* myidx already points to next arg */ |
| 2985 | } |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 2986 | else if (strcmp(args[myidx], "store") == 0) { |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 2987 | int type, err; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 2988 | char *cw, *nw, *sa; |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 2989 | |
| 2990 | myidx++; |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 2991 | nw = args[myidx]; |
| 2992 | while (*nw) { |
| 2993 | /* the "store" keyword supports a comma-separated list */ |
| 2994 | cw = nw; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 2995 | sa = NULL; /* store arg */ |
| 2996 | while (*nw && *nw != ',') { |
| 2997 | if (*nw == '(') { |
| 2998 | *nw = 0; |
| 2999 | sa = ++nw; |
| 3000 | while (*nw != ')') { |
| 3001 | if (!*nw) { |
| 3002 | Alert("parsing [%s:%d] : %s: missing closing parenthesis after store option '%s'.\n", |
| 3003 | file, linenum, args[0], cw); |
| 3004 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3005 | goto out; |
| 3006 | } |
| 3007 | nw++; |
| 3008 | } |
| 3009 | *nw = '\0'; |
| 3010 | } |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 3011 | nw++; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 3012 | } |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 3013 | if (*nw) |
| 3014 | *nw++ = '\0'; |
| 3015 | type = stktable_get_data_type(cw); |
| 3016 | if (type < 0) { |
| 3017 | Alert("parsing [%s:%d] : %s: unknown store option '%s'.\n", |
| 3018 | file, linenum, args[0], cw); |
| 3019 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3020 | goto out; |
| 3021 | } |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 3022 | |
| 3023 | err = stktable_alloc_data_type(&curproxy->table, type, sa); |
| 3024 | switch (err) { |
| 3025 | case PE_NONE: break; |
| 3026 | case PE_EXIST: |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 3027 | Warning("parsing [%s:%d]: %s: store option '%s' already enabled, ignored.\n", |
| 3028 | file, linenum, args[0], cw); |
| 3029 | err_code |= ERR_WARN; |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 3030 | break; |
| 3031 | |
| 3032 | case PE_ARG_MISSING: |
| 3033 | Alert("parsing [%s:%d] : %s: missing argument to store option '%s'.\n", |
| 3034 | file, linenum, args[0], cw); |
| 3035 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3036 | goto out; |
| 3037 | |
| 3038 | case PE_ARG_NOT_USED: |
| 3039 | Alert("parsing [%s:%d] : %s: unexpected argument to store option '%s'.\n", |
| 3040 | file, linenum, args[0], cw); |
| 3041 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3042 | goto out; |
| 3043 | |
| 3044 | default: |
| 3045 | Alert("parsing [%s:%d] : %s: error when processing store option '%s'.\n", |
| 3046 | file, linenum, args[0], cw); |
| 3047 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3048 | goto out; |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 3049 | } |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 3050 | } |
| 3051 | myidx++; |
| 3052 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 3053 | else { |
| 3054 | Alert("parsing [%s:%d] : stick-table: unknown argument '%s'.\n", |
| 3055 | file, linenum, args[myidx]); |
| 3056 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3057 | goto out; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3058 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3059 | } |
| 3060 | |
| 3061 | if (!curproxy->table.size) { |
| 3062 | Alert("parsing [%s:%d] : stick-table: missing size.\n", |
| 3063 | file, linenum); |
| 3064 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3065 | goto out; |
| 3066 | } |
| 3067 | |
| 3068 | if (curproxy->table.type == (unsigned int)-1) { |
| 3069 | Alert("parsing [%s:%d] : stick-table: missing type.\n", |
| 3070 | file, linenum); |
| 3071 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3072 | goto out; |
| 3073 | } |
| 3074 | } |
| 3075 | else if (!strcmp(args[0], "stick")) { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3076 | struct sticking_rule *rule; |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 3077 | struct sample_expr *expr; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3078 | int myidx = 0; |
| 3079 | const char *name = NULL; |
| 3080 | int flags; |
| 3081 | |
| 3082 | if (curproxy == &defproxy) { |
| 3083 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3084 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3085 | goto out; |
| 3086 | } |
| 3087 | |
| 3088 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) { |
| 3089 | err_code |= ERR_WARN; |
| 3090 | goto out; |
| 3091 | } |
| 3092 | |
| 3093 | myidx++; |
| 3094 | if ((strcmp(args[myidx], "store") == 0) || |
| 3095 | (strcmp(args[myidx], "store-request") == 0)) { |
| 3096 | myidx++; |
| 3097 | flags = STK_IS_STORE; |
| 3098 | } |
| 3099 | else if (strcmp(args[myidx], "store-response") == 0) { |
| 3100 | myidx++; |
| 3101 | flags = STK_IS_STORE | STK_ON_RSP; |
| 3102 | } |
| 3103 | else if (strcmp(args[myidx], "match") == 0) { |
| 3104 | myidx++; |
| 3105 | flags = STK_IS_MATCH; |
| 3106 | } |
| 3107 | else if (strcmp(args[myidx], "on") == 0) { |
| 3108 | myidx++; |
| 3109 | flags = STK_IS_MATCH | STK_IS_STORE; |
| 3110 | } |
| 3111 | else { |
| 3112 | Alert("parsing [%s:%d] : '%s' expects 'on', 'match', or 'store'.\n", file, linenum, args[0]); |
| 3113 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3114 | goto out; |
| 3115 | } |
| 3116 | |
| 3117 | if (*(args[myidx]) == 0) { |
| 3118 | Alert("parsing [%s:%d] : '%s' expects a fetch method.\n", file, linenum, args[0]); |
| 3119 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3120 | goto out; |
| 3121 | } |
| 3122 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3123 | expr = sample_parse_expr(args, &myidx, trash.str, trash.size); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3124 | if (!expr) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3125 | 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] | 3126 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3127 | goto out; |
| 3128 | } |
| 3129 | |
| 3130 | if (flags & STK_ON_RSP) { |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 3131 | if (!(expr->fetch->cap & SMP_CAP_RES)) { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3132 | Alert("parsing [%s:%d] : '%s': fetch method '%s' can not be used on response.\n", |
| 3133 | file, linenum, args[0], expr->fetch->kw); |
| 3134 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 3135 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3136 | goto out; |
| 3137 | } |
| 3138 | } else { |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 3139 | if (!(expr->fetch->cap & SMP_CAP_REQ)) { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3140 | Alert("parsing [%s:%d] : '%s': fetch method '%s' can not be used on request.\n", |
| 3141 | file, linenum, args[0], expr->fetch->kw); |
| 3142 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 3143 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3144 | goto out; |
| 3145 | } |
| 3146 | } |
| 3147 | |
Willy Tarreau | 1b6c00c | 2012-10-05 22:41:26 +0200 | [diff] [blame] | 3148 | /* check if we need to allocate an hdr_idx struct for HTTP parsing */ |
| 3149 | if (expr->fetch->cap & SMP_CAP_L7) |
| 3150 | curproxy->acl_requires |= ACL_USE_L7_ANY; |
| 3151 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3152 | if (strcmp(args[myidx], "table") == 0) { |
| 3153 | myidx++; |
| 3154 | name = args[myidx++]; |
| 3155 | } |
| 3156 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 3157 | if (strcmp(args[myidx], "if") == 0 || strcmp(args[myidx], "unless") == 0) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 3158 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + myidx, &errmsg)) == NULL) { |
| 3159 | Alert("parsing [%s:%d] : '%s': error detected while parsing sticking condition : %s.\n", |
| 3160 | file, linenum, args[0], errmsg); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3161 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 3162 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3163 | goto out; |
| 3164 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3165 | } |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 3166 | else if (*(args[myidx])) { |
| 3167 | Alert("parsing [%s:%d] : '%s': unknown keyword '%s'.\n", |
| 3168 | file, linenum, args[0], args[myidx]); |
| 3169 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 3170 | free(expr); |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 3171 | goto out; |
| 3172 | } |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 3173 | if (flags & STK_ON_RSP) |
| 3174 | err_code |= warnif_cond_requires_req(cond, file, linenum); |
| 3175 | else |
| 3176 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 3177 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3178 | rule = (struct sticking_rule *)calloc(1, sizeof(*rule)); |
| 3179 | rule->cond = cond; |
| 3180 | rule->expr = expr; |
| 3181 | rule->flags = flags; |
| 3182 | rule->table.name = name ? strdup(name) : NULL; |
| 3183 | LIST_INIT(&rule->list); |
| 3184 | if (flags & STK_ON_RSP) |
| 3185 | LIST_ADDQ(&curproxy->storersp_rules, &rule->list); |
| 3186 | else |
| 3187 | LIST_ADDQ(&curproxy->sticking_rules, &rule->list); |
| 3188 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3189 | else if (!strcmp(args[0], "stats")) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3190 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3191 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3192 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3193 | if (curproxy != &defproxy && curproxy->uri_auth == defproxy.uri_auth) |
| 3194 | curproxy->uri_auth = NULL; /* we must detach from the default config */ |
| 3195 | |
Krzysztof Piotr Oledzki | 260a3bb | 2010-01-06 16:25:05 +0100 | [diff] [blame] | 3196 | if (!*args[1]) { |
| 3197 | goto stats_error_parsing; |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3198 | } else if (!strcmp(args[1], "admin")) { |
| 3199 | struct stats_admin_rule *rule; |
| 3200 | |
| 3201 | if (curproxy == &defproxy) { |
| 3202 | Alert("parsing [%s:%d]: '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
| 3203 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3204 | goto out; |
| 3205 | } |
| 3206 | |
| 3207 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 3208 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3209 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3210 | goto out; |
| 3211 | } |
| 3212 | |
| 3213 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
| 3214 | Alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n", |
| 3215 | file, linenum, args[0], args[1]); |
| 3216 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3217 | goto out; |
| 3218 | } |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 3219 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 3220 | Alert("parsing [%s:%d] : error detected while parsing a '%s %s' rule : %s.\n", |
| 3221 | file, linenum, args[0], args[1], errmsg); |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3222 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3223 | goto out; |
| 3224 | } |
| 3225 | |
| 3226 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
| 3227 | |
| 3228 | rule = (struct stats_admin_rule *)calloc(1, sizeof(*rule)); |
| 3229 | rule->cond = cond; |
| 3230 | LIST_INIT(&rule->list); |
| 3231 | LIST_ADDQ(&curproxy->uri_auth->admin_rules, &rule->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3232 | } else if (!strcmp(args[1], "uri")) { |
| 3233 | if (*(args[2]) == 0) { |
| 3234 | Alert("parsing [%s:%d] : 'uri' needs an URI prefix.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3235 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3236 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3237 | } else if (!stats_set_uri(&curproxy->uri_auth, args[2])) { |
| 3238 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3239 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3240 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3241 | } |
| 3242 | } else if (!strcmp(args[1], "realm")) { |
| 3243 | if (*(args[2]) == 0) { |
| 3244 | Alert("parsing [%s:%d] : 'realm' needs an realm name.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3245 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3246 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3247 | } else if (!stats_set_realm(&curproxy->uri_auth, args[2])) { |
| 3248 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3249 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3250 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3251 | } |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 3252 | } else if (!strcmp(args[1], "refresh")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 3253 | unsigned interval; |
| 3254 | |
| 3255 | err = parse_time_err(args[2], &interval, TIME_UNIT_S); |
| 3256 | if (err) { |
| 3257 | Alert("parsing [%s:%d] : unexpected character '%c' in stats refresh interval.\n", |
| 3258 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3259 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3260 | goto out; |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 3261 | } else if (!stats_set_refresh(&curproxy->uri_auth, interval)) { |
| 3262 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3263 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3264 | goto out; |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 3265 | } |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3266 | } 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] | 3267 | struct http_req_rule *rule; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3268 | |
| 3269 | if (curproxy == &defproxy) { |
| 3270 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3271 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3272 | goto out; |
| 3273 | } |
| 3274 | |
| 3275 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 3276 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3277 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3278 | goto out; |
| 3279 | } |
| 3280 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3281 | if (!LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) && |
| 3282 | !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] | 3283 | Warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n", |
| 3284 | file, linenum, args[0]); |
| 3285 | err_code |= ERR_WARN; |
| 3286 | } |
| 3287 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3288 | 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] | 3289 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3290 | if (!rule) { |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3291 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3292 | goto out; |
| 3293 | } |
| 3294 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3295 | err_code |= warnif_cond_requires_resp(rule->cond, file, linenum); |
| 3296 | LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list); |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3297 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3298 | } else if (!strcmp(args[1], "auth")) { |
| 3299 | if (*(args[2]) == 0) { |
| 3300 | 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] | 3301 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3302 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3303 | } else if (!stats_add_auth(&curproxy->uri_auth, args[2])) { |
| 3304 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3305 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3306 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3307 | } |
| 3308 | } else if (!strcmp(args[1], "scope")) { |
| 3309 | if (*(args[2]) == 0) { |
| 3310 | Alert("parsing [%s:%d] : 'scope' needs a proxy name.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3311 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3312 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3313 | } else if (!stats_add_scope(&curproxy->uri_auth, args[2])) { |
| 3314 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3315 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3316 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3317 | } |
| 3318 | } else if (!strcmp(args[1], "enable")) { |
| 3319 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 3320 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3321 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3322 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3323 | } |
Krzysztof Oledzki | d9db927 | 2007-10-15 10:05:11 +0200 | [diff] [blame] | 3324 | } else if (!strcmp(args[1], "hide-version")) { |
| 3325 | if (!stats_set_flag(&curproxy->uri_auth, ST_HIDEVER)) { |
| 3326 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3327 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3328 | goto out; |
Krzysztof Oledzki | d9db927 | 2007-10-15 10:05:11 +0200 | [diff] [blame] | 3329 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3330 | } else if (!strcmp(args[1], "show-legends")) { |
| 3331 | if (!stats_set_flag(&curproxy->uri_auth, ST_SHLGNDS)) { |
| 3332 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3333 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3334 | goto out; |
| 3335 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3336 | } else if (!strcmp(args[1], "show-node")) { |
| 3337 | |
| 3338 | if (*args[2]) { |
| 3339 | int i; |
| 3340 | char c; |
| 3341 | |
| 3342 | for (i=0; args[2][i]; i++) { |
| 3343 | c = args[2][i]; |
Willy Tarreau | 88e0581 | 2010-03-03 00:16:00 +0100 | [diff] [blame] | 3344 | if (!isupper((unsigned char)c) && !islower((unsigned char)c) && |
| 3345 | !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.') |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3346 | break; |
| 3347 | } |
| 3348 | |
| 3349 | if (!i || args[2][i]) { |
| 3350 | Alert("parsing [%s:%d]: '%s %s' invalid node name - should be a string" |
| 3351 | "with digits(0-9), letters(A-Z, a-z), hyphen(-) or underscode(_).\n", |
| 3352 | file, linenum, args[0], args[1]); |
| 3353 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3354 | goto out; |
| 3355 | } |
| 3356 | } |
| 3357 | |
| 3358 | if (!stats_set_node(&curproxy->uri_auth, args[2])) { |
| 3359 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3360 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3361 | goto out; |
| 3362 | } |
| 3363 | } else if (!strcmp(args[1], "show-desc")) { |
| 3364 | char *desc = NULL; |
| 3365 | |
| 3366 | if (*args[2]) { |
| 3367 | int i, len=0; |
| 3368 | char *d; |
| 3369 | |
| 3370 | for(i=2; *args[i]; i++) |
| 3371 | len += strlen(args[i])+1; |
| 3372 | |
| 3373 | desc = d = (char *)calloc(1, len); |
| 3374 | |
| 3375 | d += sprintf(d, "%s", args[2]); |
| 3376 | for(i=3; *args[i]; i++) |
| 3377 | d += sprintf(d, " %s", args[i]); |
| 3378 | } |
| 3379 | |
| 3380 | if (!*args[2] && !global.desc) |
| 3381 | Warning("parsing [%s:%d]: '%s' requires a parameter or 'desc' to be set in the global section.\n", |
| 3382 | file, linenum, args[1]); |
| 3383 | else { |
| 3384 | if (!stats_set_desc(&curproxy->uri_auth, desc)) { |
| 3385 | free(desc); |
| 3386 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3387 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3388 | goto out; |
| 3389 | } |
| 3390 | free(desc); |
| 3391 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3392 | } else { |
Krzysztof Piotr Oledzki | 260a3bb | 2010-01-06 16:25:05 +0100 | [diff] [blame] | 3393 | stats_error_parsing: |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3394 | 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] | 3395 | 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] | 3396 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3397 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3398 | } |
| 3399 | } |
| 3400 | else if (!strcmp(args[0], "option")) { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3401 | int optnum; |
| 3402 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3403 | if (*(args[1]) == '\0') { |
| 3404 | Alert("parsing [%s:%d]: '%s' expects an option name.\n", |
| 3405 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3406 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3407 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3408 | } |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3409 | |
| 3410 | for (optnum = 0; cfg_opts[optnum].name; optnum++) { |
| 3411 | if (!strcmp(args[1], cfg_opts[optnum].name)) { |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 3412 | if (cfg_opts[optnum].cap == PR_CAP_NONE) { |
| 3413 | Alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n", |
| 3414 | file, linenum, cfg_opts[optnum].name); |
| 3415 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3416 | goto out; |
| 3417 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3418 | if (warnifnotcap(curproxy, cfg_opts[optnum].cap, file, linenum, args[1], NULL)) { |
| 3419 | err_code |= ERR_WARN; |
| 3420 | goto out; |
| 3421 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3422 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 3423 | curproxy->no_options &= ~cfg_opts[optnum].val; |
| 3424 | curproxy->options &= ~cfg_opts[optnum].val; |
| 3425 | |
| 3426 | switch (kwm) { |
| 3427 | case KWM_STD: |
| 3428 | curproxy->options |= cfg_opts[optnum].val; |
| 3429 | break; |
| 3430 | case KWM_NO: |
| 3431 | curproxy->no_options |= cfg_opts[optnum].val; |
| 3432 | break; |
| 3433 | case KWM_DEF: /* already cleared */ |
| 3434 | break; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 3435 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3436 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3437 | goto out; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3438 | } |
| 3439 | } |
| 3440 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 3441 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) { |
| 3442 | if (!strcmp(args[1], cfg_opts2[optnum].name)) { |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 3443 | if (cfg_opts2[optnum].cap == PR_CAP_NONE) { |
| 3444 | Alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n", |
| 3445 | file, linenum, cfg_opts2[optnum].name); |
| 3446 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3447 | goto out; |
| 3448 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3449 | if (warnifnotcap(curproxy, cfg_opts2[optnum].cap, file, linenum, args[1], NULL)) { |
| 3450 | err_code |= ERR_WARN; |
| 3451 | goto out; |
| 3452 | } |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 3453 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 3454 | curproxy->no_options2 &= ~cfg_opts2[optnum].val; |
| 3455 | curproxy->options2 &= ~cfg_opts2[optnum].val; |
| 3456 | |
| 3457 | switch (kwm) { |
| 3458 | case KWM_STD: |
| 3459 | curproxy->options2 |= cfg_opts2[optnum].val; |
| 3460 | break; |
| 3461 | case KWM_NO: |
| 3462 | curproxy->no_options2 |= cfg_opts2[optnum].val; |
| 3463 | break; |
| 3464 | case KWM_DEF: /* already cleared */ |
| 3465 | break; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 3466 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3467 | goto out; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 3468 | } |
| 3469 | } |
| 3470 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 3471 | if (kwm != KWM_STD) { |
| 3472 | 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] | 3473 | file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3474 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3475 | goto out; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3476 | } |
| 3477 | |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3478 | if (!strcmp(args[1], "httplog")) { |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 3479 | char *logformat; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3480 | /* generate a complete HTTP log */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 3481 | logformat = default_http_log_format; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3482 | if (*(args[2]) != '\0') { |
| 3483 | if (!strcmp(args[2], "clf")) { |
| 3484 | curproxy->options2 |= PR_O2_CLFLOG; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 3485 | logformat = clf_http_log_format; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3486 | } else { |
| 3487 | 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] | 3488 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3489 | goto out; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3490 | } |
| 3491 | } |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 3492 | if (curproxy->logformat_string != default_http_log_format && |
| 3493 | curproxy->logformat_string != default_tcp_log_format && |
| 3494 | curproxy->logformat_string != clf_http_log_format) |
| 3495 | free(curproxy->logformat_string); |
| 3496 | curproxy->logformat_string = logformat; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3497 | } |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 3498 | else if (!strcmp(args[1], "tcplog")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3499 | /* generate a detailed TCP log */ |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 3500 | if (curproxy->logformat_string != default_http_log_format && |
| 3501 | curproxy->logformat_string != default_tcp_log_format && |
| 3502 | curproxy->logformat_string != clf_http_log_format) |
| 3503 | free(curproxy->logformat_string); |
| 3504 | curproxy->logformat_string = default_tcp_log_format; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 3505 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3506 | else if (!strcmp(args[1], "tcpka")) { |
| 3507 | /* enable TCP keep-alives on client and server sessions */ |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3508 | 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] | 3509 | err_code |= ERR_WARN; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3510 | |
| 3511 | if (curproxy->cap & PR_CAP_FE) |
| 3512 | curproxy->options |= PR_O_TCP_CLI_KA; |
| 3513 | if (curproxy->cap & PR_CAP_BE) |
| 3514 | curproxy->options |= PR_O_TCP_SRV_KA; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3515 | } |
| 3516 | else if (!strcmp(args[1], "httpchk")) { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3517 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3518 | err_code |= ERR_WARN; |
| 3519 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3520 | /* use HTTP request to check servers' health */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3521 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 3522 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3523 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 3524 | curproxy->options2 |= PR_O2_HTTP_CHK; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3525 | if (!*args[2]) { /* no argument */ |
| 3526 | curproxy->check_req = strdup(DEF_CHECK_REQ); /* default request */ |
| 3527 | curproxy->check_len = strlen(DEF_CHECK_REQ); |
| 3528 | } else if (!*args[3]) { /* one argument : URI */ |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3529 | 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] | 3530 | curproxy->check_req = (char *)malloc(reqlen); |
| 3531 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3532 | "OPTIONS %s HTTP/1.0\r\n", args[2]); /* URI to use */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3533 | } else { /* more arguments : METHOD URI [HTTP_VER] */ |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3534 | int reqlen = strlen(args[2]) + strlen(args[3]) + 3 + strlen("\r\n"); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3535 | if (*args[4]) |
| 3536 | reqlen += strlen(args[4]); |
| 3537 | else |
| 3538 | reqlen += strlen("HTTP/1.0"); |
| 3539 | |
| 3540 | curproxy->check_req = (char *)malloc(reqlen); |
| 3541 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3542 | "%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] | 3543 | } |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 3544 | } |
| 3545 | else if (!strcmp(args[1], "ssl-hello-chk")) { |
| 3546 | /* use SSLv3 CLIENT HELLO to check servers' health */ |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3547 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3548 | err_code |= ERR_WARN; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3549 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3550 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 3551 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3552 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Willy Tarreau | 07a5490 | 2010-03-29 18:33:29 +0200 | [diff] [blame] | 3553 | curproxy->options2 |= PR_O2_SSL3_CHK; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3554 | } |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 3555 | else if (!strcmp(args[1], "smtpchk")) { |
| 3556 | /* use SMTP request to check servers' health */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3557 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 3558 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3559 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 3560 | curproxy->options2 |= PR_O2_SMTP_CHK; |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 3561 | |
| 3562 | if (!*args[2] || !*args[3]) { /* no argument or incomplete EHLO host */ |
| 3563 | curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */ |
| 3564 | curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ); |
| 3565 | } else { /* ESMTP EHLO, or SMTP HELO, and a hostname */ |
| 3566 | if (!strcmp(args[2], "EHLO") || !strcmp(args[2], "HELO")) { |
| 3567 | int reqlen = strlen(args[2]) + strlen(args[3]) + strlen(" \r\n") + 1; |
| 3568 | curproxy->check_req = (char *)malloc(reqlen); |
| 3569 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
| 3570 | "%s %s\r\n", args[2], args[3]); /* HELO hostname */ |
| 3571 | } else { |
| 3572 | /* this just hits the default for now, but you could potentially expand it to allow for other stuff |
| 3573 | though, it's unlikely you'd want to send anything other than an EHLO or HELO */ |
| 3574 | curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */ |
| 3575 | curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ); |
| 3576 | } |
| 3577 | } |
| 3578 | } |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 3579 | else if (!strcmp(args[1], "pgsql-check")) { |
| 3580 | /* use PostgreSQL request to check servers' health */ |
| 3581 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 3582 | err_code |= ERR_WARN; |
| 3583 | |
| 3584 | free(curproxy->check_req); |
| 3585 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3586 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 3587 | curproxy->options2 |= PR_O2_PGSQL_CHK; |
| 3588 | |
| 3589 | if (*(args[2])) { |
| 3590 | int cur_arg = 2; |
| 3591 | |
| 3592 | while (*(args[cur_arg])) { |
| 3593 | if (strcmp(args[cur_arg], "user") == 0) { |
| 3594 | char * packet; |
| 3595 | uint32_t packet_len; |
| 3596 | uint32_t pv; |
| 3597 | |
| 3598 | /* suboption header - needs additional argument for it */ |
| 3599 | if (*(args[cur_arg+1]) == 0) { |
| 3600 | Alert("parsing [%s:%d] : '%s %s %s' expects <username> as argument.\n", |
| 3601 | file, linenum, args[0], args[1], args[cur_arg]); |
| 3602 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3603 | goto out; |
| 3604 | } |
| 3605 | |
| 3606 | /* uint32_t + uint32_t + strlen("user")+1 + strlen(username)+1 + 1 */ |
| 3607 | packet_len = 4 + 4 + 5 + strlen(args[cur_arg + 1])+1 +1; |
| 3608 | pv = htonl(0x30000); /* protocol version 3.0 */ |
| 3609 | |
| 3610 | packet = (char*) calloc(1, packet_len); |
| 3611 | |
| 3612 | memcpy(packet + 4, &pv, 4); |
| 3613 | |
| 3614 | /* copy "user" */ |
| 3615 | memcpy(packet + 8, "user", 4); |
| 3616 | |
| 3617 | /* copy username */ |
| 3618 | memcpy(packet + 13, args[cur_arg+1], strlen(args[cur_arg+1])); |
| 3619 | |
| 3620 | free(curproxy->check_req); |
| 3621 | curproxy->check_req = packet; |
| 3622 | curproxy->check_len = packet_len; |
| 3623 | |
| 3624 | packet_len = htonl(packet_len); |
| 3625 | memcpy(packet, &packet_len, 4); |
| 3626 | cur_arg += 2; |
| 3627 | } else { |
| 3628 | /* unknown suboption - catchall */ |
| 3629 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'user'.\n", |
| 3630 | file, linenum, args[0], args[1]); |
| 3631 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3632 | goto out; |
| 3633 | } |
| 3634 | } /* end while loop */ |
| 3635 | } |
| 3636 | } |
| 3637 | |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 3638 | else if (!strcmp(args[1], "redis-check")) { |
| 3639 | /* use REDIS PING request to check servers' health */ |
| 3640 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 3641 | err_code |= ERR_WARN; |
| 3642 | |
| 3643 | free(curproxy->check_req); |
| 3644 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3645 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 3646 | curproxy->options2 |= PR_O2_REDIS_CHK; |
| 3647 | |
| 3648 | curproxy->check_req = (char *) malloc(sizeof(DEF_REDIS_CHECK_REQ) - 1); |
| 3649 | memcpy(curproxy->check_req, DEF_REDIS_CHECK_REQ, sizeof(DEF_REDIS_CHECK_REQ) - 1); |
| 3650 | curproxy->check_len = sizeof(DEF_REDIS_CHECK_REQ) - 1; |
| 3651 | } |
| 3652 | |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 3653 | else if (!strcmp(args[1], "mysql-check")) { |
| 3654 | /* use MYSQL request to check servers' health */ |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 3655 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 3656 | err_code |= ERR_WARN; |
| 3657 | |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 3658 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 3659 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3660 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 3661 | curproxy->options2 |= PR_O2_MYSQL_CHK; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 3662 | |
| 3663 | /* This is an exemple of an MySQL >=4.0 client Authentication packet kindly provided by Cyril Bonte. |
| 3664 | * const char mysql40_client_auth_pkt[] = { |
| 3665 | * "\x0e\x00\x00" // packet length |
| 3666 | * "\x01" // packet number |
| 3667 | * "\x00\x00" // client capabilities |
| 3668 | * "\x00\x00\x01" // max packet |
| 3669 | * "haproxy\x00" // username (null terminated string) |
| 3670 | * "\x00" // filler (always 0x00) |
| 3671 | * "\x01\x00\x00" // packet length |
| 3672 | * "\x00" // packet number |
| 3673 | * "\x01" // COM_QUIT command |
| 3674 | * }; |
| 3675 | */ |
| 3676 | |
| 3677 | if (*(args[2])) { |
| 3678 | int cur_arg = 2; |
| 3679 | |
| 3680 | while (*(args[cur_arg])) { |
| 3681 | if (strcmp(args[cur_arg], "user") == 0) { |
| 3682 | char *mysqluser; |
| 3683 | int packetlen, reqlen, userlen; |
| 3684 | |
| 3685 | /* suboption header - needs additional argument for it */ |
| 3686 | if (*(args[cur_arg+1]) == 0) { |
| 3687 | Alert("parsing [%s:%d] : '%s %s %s' expects <username> as argument.\n", |
| 3688 | file, linenum, args[0], args[1], args[cur_arg]); |
| 3689 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3690 | goto out; |
| 3691 | } |
| 3692 | mysqluser = args[cur_arg + 1]; |
| 3693 | userlen = strlen(mysqluser); |
| 3694 | packetlen = userlen + 7; |
| 3695 | reqlen = packetlen + 9; |
| 3696 | |
| 3697 | free(curproxy->check_req); |
| 3698 | curproxy->check_req = (char *)calloc(1, reqlen); |
| 3699 | curproxy->check_len = reqlen; |
| 3700 | |
| 3701 | snprintf(curproxy->check_req, 4, "%c%c%c", |
| 3702 | ((unsigned char) packetlen & 0xff), |
| 3703 | ((unsigned char) (packetlen >> 8) & 0xff), |
| 3704 | ((unsigned char) (packetlen >> 16) & 0xff)); |
| 3705 | |
| 3706 | curproxy->check_req[3] = 1; |
Hervé COMMOWICK | 212f778 | 2011-06-10 14:05:59 +0200 | [diff] [blame] | 3707 | curproxy->check_req[5] = 128; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 3708 | curproxy->check_req[8] = 1; |
| 3709 | memcpy(&curproxy->check_req[9], mysqluser, userlen); |
| 3710 | curproxy->check_req[9 + userlen + 1 + 1] = 1; |
| 3711 | curproxy->check_req[9 + userlen + 1 + 1 + 4] = 1; |
| 3712 | cur_arg += 2; |
| 3713 | } else { |
| 3714 | /* unknown suboption - catchall */ |
| 3715 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'user'.\n", |
| 3716 | file, linenum, args[0], args[1]); |
| 3717 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3718 | goto out; |
| 3719 | } |
| 3720 | } /* end while loop */ |
| 3721 | } |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 3722 | } |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 3723 | else if (!strcmp(args[1], "ldap-check")) { |
| 3724 | /* use LDAP request to check servers' health */ |
| 3725 | free(curproxy->check_req); |
| 3726 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3727 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 3728 | curproxy->options2 |= PR_O2_LDAP_CHK; |
| 3729 | |
| 3730 | curproxy->check_req = (char *) malloc(sizeof(DEF_LDAP_CHECK_REQ) - 1); |
| 3731 | memcpy(curproxy->check_req, DEF_LDAP_CHECK_REQ, sizeof(DEF_LDAP_CHECK_REQ) - 1); |
| 3732 | curproxy->check_len = sizeof(DEF_LDAP_CHECK_REQ) - 1; |
| 3733 | } |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3734 | else if (!strcmp(args[1], "forwardfor")) { |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3735 | int cur_arg; |
| 3736 | |
| 3737 | /* insert x-forwarded-for field, but not for the IP address listed as an except. |
| 3738 | * set default options (ie: bitfield, header name, etc) |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3739 | */ |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3740 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 3741 | curproxy->options |= PR_O_FWDFOR | PR_O_FF_ALWAYS; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3742 | |
| 3743 | free(curproxy->fwdfor_hdr_name); |
| 3744 | curproxy->fwdfor_hdr_name = strdup(DEF_XFORWARDFOR_HDR); |
| 3745 | curproxy->fwdfor_hdr_len = strlen(DEF_XFORWARDFOR_HDR); |
| 3746 | |
| 3747 | /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */ |
| 3748 | cur_arg = 2; |
| 3749 | while (*(args[cur_arg])) { |
| 3750 | if (!strcmp(args[cur_arg], "except")) { |
| 3751 | /* suboption except - needs additional argument for it */ |
| 3752 | if (!*(args[cur_arg+1]) || !str2net(args[cur_arg+1], &curproxy->except_net, &curproxy->except_mask)) { |
| 3753 | Alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n", |
| 3754 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3755 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3756 | goto out; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3757 | } |
| 3758 | /* flush useless bits */ |
| 3759 | curproxy->except_net.s_addr &= curproxy->except_mask.s_addr; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3760 | cur_arg += 2; |
| 3761 | } else if (!strcmp(args[cur_arg], "header")) { |
| 3762 | /* suboption header - needs additional argument for it */ |
| 3763 | if (*(args[cur_arg+1]) == 0) { |
| 3764 | Alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 3765 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3766 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3767 | goto out; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3768 | } |
| 3769 | free(curproxy->fwdfor_hdr_name); |
| 3770 | curproxy->fwdfor_hdr_name = strdup(args[cur_arg+1]); |
| 3771 | curproxy->fwdfor_hdr_len = strlen(curproxy->fwdfor_hdr_name); |
| 3772 | cur_arg += 2; |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 3773 | } else if (!strcmp(args[cur_arg], "if-none")) { |
| 3774 | curproxy->options &= ~PR_O_FF_ALWAYS; |
| 3775 | cur_arg += 1; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3776 | } else { |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3777 | /* unknown suboption - catchall */ |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 3778 | 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] | 3779 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3780 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3781 | goto out; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3782 | } |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3783 | } /* end while loop */ |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3784 | } |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 3785 | else if (!strcmp(args[1], "originalto")) { |
| 3786 | int cur_arg; |
| 3787 | |
| 3788 | /* insert x-original-to field, but not for the IP address listed as an except. |
| 3789 | * set default options (ie: bitfield, header name, etc) |
| 3790 | */ |
| 3791 | |
| 3792 | curproxy->options |= PR_O_ORGTO; |
| 3793 | |
| 3794 | free(curproxy->orgto_hdr_name); |
| 3795 | curproxy->orgto_hdr_name = strdup(DEF_XORIGINALTO_HDR); |
| 3796 | curproxy->orgto_hdr_len = strlen(DEF_XORIGINALTO_HDR); |
| 3797 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 3798 | /* 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] | 3799 | cur_arg = 2; |
| 3800 | while (*(args[cur_arg])) { |
| 3801 | if (!strcmp(args[cur_arg], "except")) { |
| 3802 | /* suboption except - needs additional argument for it */ |
| 3803 | if (!*(args[cur_arg+1]) || !str2net(args[cur_arg+1], &curproxy->except_to, &curproxy->except_mask_to)) { |
| 3804 | Alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n", |
| 3805 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3806 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3807 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 3808 | } |
| 3809 | /* flush useless bits */ |
| 3810 | curproxy->except_to.s_addr &= curproxy->except_mask_to.s_addr; |
| 3811 | cur_arg += 2; |
| 3812 | } else if (!strcmp(args[cur_arg], "header")) { |
| 3813 | /* suboption header - needs additional argument for it */ |
| 3814 | if (*(args[cur_arg+1]) == 0) { |
| 3815 | Alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 3816 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3817 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3818 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 3819 | } |
| 3820 | free(curproxy->orgto_hdr_name); |
| 3821 | curproxy->orgto_hdr_name = strdup(args[cur_arg+1]); |
| 3822 | curproxy->orgto_hdr_len = strlen(curproxy->orgto_hdr_name); |
| 3823 | cur_arg += 2; |
| 3824 | } else { |
| 3825 | /* unknown suboption - catchall */ |
| 3826 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n", |
| 3827 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3828 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3829 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 3830 | } |
| 3831 | } /* end while loop */ |
| 3832 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3833 | else { |
| 3834 | Alert("parsing [%s:%d] : unknown option '%s'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3835 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3836 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3837 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3838 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3839 | } |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 3840 | else if (!strcmp(args[0], "default_backend")) { |
| 3841 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3842 | err_code |= ERR_WARN; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 3843 | |
| 3844 | if (*(args[1]) == 0) { |
| 3845 | 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] | 3846 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3847 | goto out; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 3848 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3849 | free(curproxy->defbe.name); |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 3850 | curproxy->defbe.name = strdup(args[1]); |
| 3851 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3852 | else if (!strcmp(args[0], "redispatch") || !strcmp(args[0], "redisp")) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3853 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3854 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3855 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3856 | Warning("parsing [%s:%d]: keyword '%s' is deprecated, please use 'option redispatch' instead.\n", |
| 3857 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3858 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3859 | /* enable reconnections to dispatch */ |
| 3860 | curproxy->options |= PR_O_REDISP; |
| 3861 | } |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 3862 | else if (!strcmp(args[0], "http-check")) { |
| 3863 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3864 | err_code |= ERR_WARN; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 3865 | |
| 3866 | if (strcmp(args[1], "disable-on-404") == 0) { |
| 3867 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 3868 | curproxy->options |= PR_O_DISABLE404; |
| 3869 | } |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 3870 | else if (strcmp(args[1], "send-state") == 0) { |
| 3871 | /* enable emission of the apparent state of a server in HTTP checks */ |
| 3872 | curproxy->options2 |= PR_O2_CHK_SNDST; |
| 3873 | } |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 3874 | else if (strcmp(args[1], "expect") == 0) { |
| 3875 | const char *ptr_arg; |
| 3876 | int cur_arg; |
| 3877 | |
| 3878 | if (curproxy->options2 & PR_O2_EXP_TYPE) { |
| 3879 | Alert("parsing [%s:%d] : '%s %s' already specified.\n", file, linenum, args[0], args[1]); |
| 3880 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3881 | goto out; |
| 3882 | } |
| 3883 | |
| 3884 | cur_arg = 2; |
| 3885 | /* consider exclamation marks, sole or at the beginning of a word */ |
| 3886 | while (*(ptr_arg = args[cur_arg])) { |
| 3887 | while (*ptr_arg == '!') { |
| 3888 | curproxy->options2 ^= PR_O2_EXP_INV; |
| 3889 | ptr_arg++; |
| 3890 | } |
| 3891 | if (*ptr_arg) |
| 3892 | break; |
| 3893 | cur_arg++; |
| 3894 | } |
| 3895 | /* now ptr_arg points to the beginning of a word past any possible |
| 3896 | * exclamation mark, and cur_arg is the argument which holds this word. |
| 3897 | */ |
| 3898 | if (strcmp(ptr_arg, "status") == 0) { |
| 3899 | if (!*(args[cur_arg + 1])) { |
| 3900 | Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 3901 | file, linenum, args[0], args[1], ptr_arg); |
| 3902 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3903 | goto out; |
| 3904 | } |
| 3905 | curproxy->options2 |= PR_O2_EXP_STS; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 3906 | free(curproxy->expect_str); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 3907 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
| 3908 | } |
| 3909 | else if (strcmp(ptr_arg, "string") == 0) { |
| 3910 | if (!*(args[cur_arg + 1])) { |
| 3911 | Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 3912 | file, linenum, args[0], args[1], ptr_arg); |
| 3913 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3914 | goto out; |
| 3915 | } |
| 3916 | curproxy->options2 |= PR_O2_EXP_STR; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 3917 | free(curproxy->expect_str); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 3918 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
| 3919 | } |
| 3920 | else if (strcmp(ptr_arg, "rstatus") == 0) { |
| 3921 | if (!*(args[cur_arg + 1])) { |
| 3922 | Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 3923 | file, linenum, args[0], args[1], ptr_arg); |
| 3924 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3925 | goto out; |
| 3926 | } |
| 3927 | curproxy->options2 |= PR_O2_EXP_RSTS; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 3928 | free(curproxy->expect_str); |
| 3929 | if (curproxy->expect_regex) regfree(curproxy->expect_regex); |
| 3930 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 3931 | curproxy->expect_regex = calloc(1, sizeof(regex_t)); |
| 3932 | if (regcomp(curproxy->expect_regex, args[cur_arg + 1], REG_EXTENDED) != 0) { |
| 3933 | Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s'.\n", |
| 3934 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1]); |
| 3935 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3936 | goto out; |
| 3937 | } |
| 3938 | } |
| 3939 | else if (strcmp(ptr_arg, "rstring") == 0) { |
| 3940 | if (!*(args[cur_arg + 1])) { |
| 3941 | Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 3942 | file, linenum, args[0], args[1], ptr_arg); |
| 3943 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3944 | goto out; |
| 3945 | } |
| 3946 | curproxy->options2 |= PR_O2_EXP_RSTR; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 3947 | free(curproxy->expect_str); |
| 3948 | if (curproxy->expect_regex) regfree(curproxy->expect_regex); |
| 3949 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 3950 | curproxy->expect_regex = calloc(1, sizeof(regex_t)); |
| 3951 | if (regcomp(curproxy->expect_regex, args[cur_arg + 1], REG_EXTENDED) != 0) { |
| 3952 | Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s'.\n", |
| 3953 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1]); |
| 3954 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3955 | goto out; |
| 3956 | } |
| 3957 | } |
| 3958 | else { |
| 3959 | Alert("parsing [%s:%d] : '%s %s' only supports [!] 'status', 'string', 'rstatus', 'rstring', found '%s'.\n", |
| 3960 | file, linenum, args[0], args[1], ptr_arg); |
| 3961 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3962 | goto out; |
| 3963 | } |
| 3964 | } |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 3965 | else { |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 3966 | 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] | 3967 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3968 | goto out; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 3969 | } |
| 3970 | } |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3971 | else if (!strcmp(args[0], "monitor")) { |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3972 | if (curproxy == &defproxy) { |
| 3973 | 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] | 3974 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3975 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3976 | } |
| 3977 | |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3978 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3979 | err_code |= ERR_WARN; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3980 | |
| 3981 | if (strcmp(args[1], "fail") == 0) { |
| 3982 | /* add a condition to fail monitor requests */ |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 3983 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3984 | Alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n", |
| 3985 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3986 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3987 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3988 | } |
| 3989 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 3990 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 3991 | Alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition : %s.\n", |
| 3992 | file, linenum, args[0], args[1], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3993 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3994 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3995 | } |
| 3996 | LIST_ADDQ(&curproxy->mon_fail_cond, &cond->list); |
| 3997 | } |
| 3998 | else { |
| 3999 | 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] | 4000 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4001 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 4002 | } |
| 4003 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4004 | #ifdef TPROXY |
| 4005 | else if (!strcmp(args[0], "transparent")) { |
| 4006 | /* enable transparent proxy connections */ |
| 4007 | curproxy->options |= PR_O_TRANSP; |
| 4008 | } |
| 4009 | #endif |
| 4010 | else if (!strcmp(args[0], "maxconn")) { /* maxconn */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4011 | 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] | 4012 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4013 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4014 | if (*(args[1]) == 0) { |
| 4015 | 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] | 4016 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4017 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4018 | } |
| 4019 | curproxy->maxconn = atol(args[1]); |
| 4020 | } |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 4021 | else if (!strcmp(args[0], "backlog")) { /* backlog */ |
| 4022 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4023 | err_code |= ERR_WARN; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 4024 | |
| 4025 | if (*(args[1]) == 0) { |
| 4026 | 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] | 4027 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4028 | goto out; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 4029 | } |
| 4030 | curproxy->backlog = atol(args[1]); |
| 4031 | } |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 4032 | else if (!strcmp(args[0], "fullconn")) { /* fullconn */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4033 | 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] | 4034 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4035 | |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 4036 | if (*(args[1]) == 0) { |
| 4037 | 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] | 4038 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4039 | goto out; |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 4040 | } |
| 4041 | curproxy->fullconn = atol(args[1]); |
| 4042 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4043 | else if (!strcmp(args[0], "grace")) { /* grace time (ms) */ |
| 4044 | if (*(args[1]) == 0) { |
| 4045 | 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] | 4046 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4047 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4048 | } |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4049 | err = parse_time_err(args[1], &val, TIME_UNIT_MS); |
| 4050 | if (err) { |
| 4051 | Alert("parsing [%s:%d] : unexpected character '%c' in grace time.\n", |
| 4052 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4053 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4054 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4055 | } |
| 4056 | curproxy->grace = val; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4057 | } |
| 4058 | else if (!strcmp(args[0], "dispatch")) { /* dispatch address */ |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4059 | struct sockaddr_storage *sk; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4060 | if (curproxy == &defproxy) { |
| 4061 | 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] | 4062 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4063 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4064 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4065 | else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4066 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4067 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4068 | if (strchr(args[1], ':') == NULL) { |
| 4069 | 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] | 4070 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4071 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4072 | } |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4073 | sk = str2sa(args[1]); |
| 4074 | if (!sk) { |
| 4075 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[1]); |
| 4076 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4077 | goto out; |
| 4078 | } |
| 4079 | curproxy->dispatch_addr = *sk; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4080 | curproxy->options |= PR_O_DISPATCH; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4081 | } |
| 4082 | else if (!strcmp(args[0], "balance")) { /* set balancing with optional algorithm */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4083 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4084 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4085 | |
Willy Tarreau | a93c74b | 2012-05-08 18:14:39 +0200 | [diff] [blame] | 4086 | if (backend_parse_balance((const char **)args + 1, &errmsg, curproxy) < 0) { |
| 4087 | Alert("parsing [%s:%d] : %s %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4088 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4089 | goto out; |
Willy Tarreau | 2fcb500 | 2007-05-08 13:35:26 +0200 | [diff] [blame] | 4090 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4091 | } |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 4092 | else if (!strcmp(args[0], "hash-type")) { /* set hashing method */ |
| 4093 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 4094 | err_code |= ERR_WARN; |
| 4095 | |
| 4096 | if (strcmp(args[1], "consistent") == 0) { /* use consistent hashing */ |
| 4097 | curproxy->lbprm.algo &= ~BE_LB_HASH_TYPE; |
| 4098 | curproxy->lbprm.algo |= BE_LB_HASH_CONS; |
| 4099 | } |
| 4100 | else if (strcmp(args[1], "map-based") == 0) { /* use map-based hashing */ |
| 4101 | curproxy->lbprm.algo &= ~BE_LB_HASH_TYPE; |
| 4102 | curproxy->lbprm.algo |= BE_LB_HASH_MAP; |
| 4103 | } |
Willy Tarreau | 798a39c | 2010-11-24 15:04:29 +0100 | [diff] [blame] | 4104 | else if (strcmp(args[1], "avalanche") == 0) { /* use full hash before map-based hashing */ |
| 4105 | curproxy->lbprm.algo &= ~BE_LB_HASH_TYPE; |
| 4106 | curproxy->lbprm.algo |= BE_LB_HASH_AVAL; |
| 4107 | } |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 4108 | else { |
Willy Tarreau | 798a39c | 2010-11-24 15:04:29 +0100 | [diff] [blame] | 4109 | 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] | 4110 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4111 | goto out; |
| 4112 | } |
| 4113 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4114 | 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] | 4115 | int cur_arg; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4116 | char *rport, *raddr; |
| 4117 | short realport = 0; |
| 4118 | int do_check = 0, defsrv = (*args[0] == 'd'); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4119 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4120 | if (!defsrv && curproxy == &defproxy) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4121 | 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] | 4122 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4123 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4124 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4125 | else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4126 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4127 | |
| 4128 | if (!*args[2]) { |
| 4129 | Alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n", |
| 4130 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4131 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4132 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4133 | } |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 4134 | |
| 4135 | err = invalid_char(args[1]); |
| 4136 | if (err) { |
| 4137 | Alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n", |
| 4138 | file, linenum, *err, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4139 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4140 | goto out; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 4141 | } |
| 4142 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4143 | if (!defsrv) { |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4144 | struct sockaddr_storage *sk; |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4145 | |
Krzysztof Piotr Oledzki | aff01ea | 2010-02-05 20:31:44 +0100 | [diff] [blame] | 4146 | if ((newsrv = (struct server *)calloc(1, sizeof(struct server))) == NULL) { |
| 4147 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 4148 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4149 | goto out; |
| 4150 | } |
| 4151 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4152 | /* the servers are linked backwards first */ |
| 4153 | newsrv->next = curproxy->srv; |
| 4154 | curproxy->srv = newsrv; |
| 4155 | newsrv->proxy = curproxy; |
Willy Tarreau | 8113a5d | 2012-10-04 08:01:43 +0200 | [diff] [blame] | 4156 | newsrv->conf.file = strdup(file); |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4157 | newsrv->conf.line = linenum; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4158 | |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 4159 | newsrv->obj_type = OBJ_TYPE_SERVER; |
Simon Horman | af51495 | 2011-06-21 14:34:57 +0900 | [diff] [blame] | 4160 | LIST_INIT(&newsrv->actconns); |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4161 | LIST_INIT(&newsrv->pendconns); |
| 4162 | do_check = 0; |
| 4163 | newsrv->state = SRV_RUNNING; /* early server setup */ |
| 4164 | newsrv->last_change = now.tv_sec; |
| 4165 | newsrv->id = strdup(args[1]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4166 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4167 | /* several ways to check the port component : |
David du Colombier | 9842ff1 | 2011-03-17 10:40:28 +0100 | [diff] [blame] | 4168 | * - IP => port=+0, relative (IPv4 only) |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4169 | * - IP: => port=+0, relative |
| 4170 | * - IP:N => port=N, absolute |
| 4171 | * - IP:+N => port=+N, relative |
| 4172 | * - IP:-N => port=-N, relative |
| 4173 | */ |
| 4174 | raddr = strdup(args[2]); |
Willy Tarreau | fab5a43 | 2011-03-04 15:31:53 +0100 | [diff] [blame] | 4175 | rport = strrchr(raddr, ':'); |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4176 | if (rport) { |
| 4177 | *rport++ = 0; |
| 4178 | realport = atol(rport); |
| 4179 | if (!isdigit((unsigned char)*rport)) |
| 4180 | newsrv->state |= SRV_MAPPORTS; |
| 4181 | } else |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4182 | newsrv->state |= SRV_MAPPORTS; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4183 | |
Willy Tarreau | fab5a43 | 2011-03-04 15:31:53 +0100 | [diff] [blame] | 4184 | sk = str2ip(raddr); |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4185 | free(raddr); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4186 | if (!sk) { |
| 4187 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[2]); |
| 4188 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4189 | goto out; |
| 4190 | } |
| 4191 | newsrv->addr = *sk; |
Willy Tarreau | f4288ee | 2012-09-28 18:13:10 +0200 | [diff] [blame] | 4192 | newsrv->proto = newsrv->check.proto = protocol_by_family(newsrv->addr.ss_family); |
| 4193 | newsrv->xprt = newsrv->check.xprt = &raw_sock; |
Willy Tarreau | 26d8c59 | 2012-05-07 18:12:14 +0200 | [diff] [blame] | 4194 | |
Willy Tarreau | 173e7fb | 2012-09-24 22:47:39 +0200 | [diff] [blame] | 4195 | if (!newsrv->proto) { |
Willy Tarreau | 26d8c59 | 2012-05-07 18:12:14 +0200 | [diff] [blame] | 4196 | Alert("parsing [%s:%d] : Unknown protocol family %d '%s'\n", |
| 4197 | file, linenum, newsrv->addr.ss_family, args[2]); |
| 4198 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4199 | goto out; |
| 4200 | } |
Willy Tarreau | 86ad42c | 2011-08-27 12:29:07 +0200 | [diff] [blame] | 4201 | set_host_port(&newsrv->addr, realport); |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4202 | |
Willy Tarreau | f4288ee | 2012-09-28 18:13:10 +0200 | [diff] [blame] | 4203 | newsrv->check.use_ssl = curproxy->defsrv.check.use_ssl; |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 4204 | newsrv->check.port = curproxy->defsrv.check.port; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4205 | newsrv->inter = curproxy->defsrv.inter; |
| 4206 | newsrv->fastinter = curproxy->defsrv.fastinter; |
| 4207 | newsrv->downinter = curproxy->defsrv.downinter; |
| 4208 | newsrv->rise = curproxy->defsrv.rise; |
| 4209 | newsrv->fall = curproxy->defsrv.fall; |
| 4210 | newsrv->maxqueue = curproxy->defsrv.maxqueue; |
| 4211 | newsrv->minconn = curproxy->defsrv.minconn; |
| 4212 | newsrv->maxconn = curproxy->defsrv.maxconn; |
| 4213 | newsrv->slowstart = curproxy->defsrv.slowstart; |
| 4214 | newsrv->onerror = curproxy->defsrv.onerror; |
| 4215 | newsrv->consecutive_errors_limit |
| 4216 | = curproxy->defsrv.consecutive_errors_limit; |
Emeric Brun | 01f8e2f | 2012-05-18 16:02:00 +0200 | [diff] [blame] | 4217 | #ifdef OPENSSL |
| 4218 | newsrv->use_ssl = curproxy->defsrv.use_ssl; |
| 4219 | #endif |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4220 | newsrv->uweight = newsrv->iweight |
| 4221 | = curproxy->defsrv.iweight; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4222 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4223 | newsrv->health = newsrv->rise; /* up, but will fall down at first failure */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4224 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4225 | cur_arg = 3; |
| 4226 | } else { |
| 4227 | newsrv = &curproxy->defsrv; |
| 4228 | cur_arg = 1; |
| 4229 | } |
Willy Tarreau | 0f03c6f | 2007-03-25 20:46:19 +0200 | [diff] [blame] | 4230 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4231 | while (*args[cur_arg]) { |
Willy Tarreau | dff5543 | 2012-10-10 17:51:05 +0200 | [diff] [blame] | 4232 | if (!defsrv && !strcmp(args[cur_arg], "cookie")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4233 | newsrv->cookie = strdup(args[cur_arg + 1]); |
| 4234 | newsrv->cklen = strlen(args[cur_arg + 1]); |
| 4235 | cur_arg += 2; |
| 4236 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4237 | else if (!defsrv && !strcmp(args[cur_arg], "redir")) { |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 4238 | newsrv->rdr_pfx = strdup(args[cur_arg + 1]); |
| 4239 | newsrv->rdr_len = strlen(args[cur_arg + 1]); |
| 4240 | cur_arg += 2; |
| 4241 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4242 | else if (!strcmp(args[cur_arg], "rise")) { |
Krzysztof Piotr Oledzki | 08ff959 | 2009-09-27 16:17:31 +0200 | [diff] [blame] | 4243 | if (!*args[cur_arg + 1]) { |
| 4244 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 4245 | file, linenum, args[cur_arg]); |
| 4246 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4247 | goto out; |
| 4248 | } |
| 4249 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4250 | newsrv->rise = atol(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 08ff959 | 2009-09-27 16:17:31 +0200 | [diff] [blame] | 4251 | if (newsrv->rise <= 0) { |
| 4252 | Alert("parsing [%s:%d]: '%s' has to be > 0.\n", |
| 4253 | file, linenum, args[cur_arg]); |
| 4254 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4255 | goto out; |
| 4256 | } |
| 4257 | |
Willy Tarreau | 9683909 | 2010-03-29 10:02:24 +0200 | [diff] [blame] | 4258 | if (newsrv->health) |
| 4259 | newsrv->health = newsrv->rise; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4260 | cur_arg += 2; |
| 4261 | } |
| 4262 | else if (!strcmp(args[cur_arg], "fall")) { |
| 4263 | newsrv->fall = atol(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 08ff959 | 2009-09-27 16:17:31 +0200 | [diff] [blame] | 4264 | |
| 4265 | if (!*args[cur_arg + 1]) { |
| 4266 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 4267 | file, linenum, args[cur_arg]); |
| 4268 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4269 | goto out; |
| 4270 | } |
| 4271 | |
| 4272 | if (newsrv->fall <= 0) { |
| 4273 | Alert("parsing [%s:%d]: '%s' has to be > 0.\n", |
| 4274 | file, linenum, args[cur_arg]); |
| 4275 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4276 | goto out; |
| 4277 | } |
| 4278 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4279 | cur_arg += 2; |
| 4280 | } |
| 4281 | else if (!strcmp(args[cur_arg], "inter")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4282 | const char *err = parse_time_err(args[cur_arg + 1], &val, TIME_UNIT_MS); |
| 4283 | if (err) { |
| 4284 | Alert("parsing [%s:%d] : unexpected character '%c' in 'inter' argument of server %s.\n", |
| 4285 | file, linenum, *err, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4286 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4287 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4288 | } |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4289 | if (val <= 0) { |
| 4290 | Alert("parsing [%s:%d]: invalid value %d for argument '%s' of server %s.\n", |
| 4291 | file, linenum, val, args[cur_arg], newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4292 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4293 | goto out; |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4294 | } |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4295 | newsrv->inter = val; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4296 | cur_arg += 2; |
| 4297 | } |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 4298 | else if (!strcmp(args[cur_arg], "fastinter")) { |
| 4299 | const char *err = parse_time_err(args[cur_arg + 1], &val, TIME_UNIT_MS); |
| 4300 | if (err) { |
| 4301 | Alert("parsing [%s:%d]: unexpected character '%c' in 'fastinter' argument of server %s.\n", |
| 4302 | file, linenum, *err, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4303 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4304 | goto out; |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 4305 | } |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4306 | if (val <= 0) { |
| 4307 | Alert("parsing [%s:%d]: invalid value %d for argument '%s' of server %s.\n", |
| 4308 | file, linenum, val, args[cur_arg], newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4309 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4310 | goto out; |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4311 | } |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 4312 | newsrv->fastinter = val; |
| 4313 | cur_arg += 2; |
| 4314 | } |
| 4315 | else if (!strcmp(args[cur_arg], "downinter")) { |
| 4316 | const char *err = parse_time_err(args[cur_arg + 1], &val, TIME_UNIT_MS); |
| 4317 | if (err) { |
| 4318 | Alert("parsing [%s:%d]: unexpected character '%c' in 'downinter' argument of server %s.\n", |
| 4319 | file, linenum, *err, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4320 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4321 | goto out; |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 4322 | } |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4323 | if (val <= 0) { |
| 4324 | Alert("parsing [%s:%d]: invalid value %d for argument '%s' of server %s.\n", |
| 4325 | file, linenum, val, args[cur_arg], newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4326 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4327 | goto out; |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4328 | } |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 4329 | newsrv->downinter = val; |
| 4330 | cur_arg += 2; |
| 4331 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4332 | else if (!defsrv && !strcmp(args[cur_arg], "addr")) { |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4333 | struct sockaddr_storage *sk = str2sa(args[cur_arg + 1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4334 | if (!sk) { |
| 4335 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[cur_arg + 1]); |
| 4336 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4337 | goto out; |
| 4338 | } |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 4339 | newsrv->check.addr = *sk; |
Willy Tarreau | 2ea3abb | 2007-03-25 16:45:16 +0200 | [diff] [blame] | 4340 | cur_arg += 2; |
| 4341 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4342 | else if (!strcmp(args[cur_arg], "port")) { |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 4343 | newsrv->check.port = atol(args[cur_arg + 1]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4344 | cur_arg += 2; |
| 4345 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4346 | else if (!defsrv && !strcmp(args[cur_arg], "backup")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4347 | newsrv->state |= SRV_BACKUP; |
| 4348 | cur_arg ++; |
| 4349 | } |
Simon Horman | fa46168 | 2011-06-25 09:39:49 +0900 | [diff] [blame] | 4350 | else if (!defsrv && !strcmp(args[cur_arg], "non-stick")) { |
| 4351 | newsrv->state |= SRV_NON_STICK; |
| 4352 | cur_arg ++; |
| 4353 | } |
Willy Tarreau | 5ab04ec | 2011-03-20 10:32:26 +0100 | [diff] [blame] | 4354 | else if (!defsrv && !strcmp(args[cur_arg], "send-proxy")) { |
| 4355 | newsrv->state |= SRV_SEND_PROXY; |
| 4356 | cur_arg ++; |
| 4357 | } |
Willy Tarreau | 6c16adc | 2012-10-05 00:04:16 +0200 | [diff] [blame] | 4358 | else if (!defsrv && !strcmp(args[cur_arg], "check-send-proxy")) { |
| 4359 | newsrv->check.send_proxy = 1; |
| 4360 | cur_arg ++; |
| 4361 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4362 | else if (!strcmp(args[cur_arg], "weight")) { |
| 4363 | int w; |
| 4364 | w = atol(args[cur_arg + 1]); |
Willy Tarreau | 6704d67 | 2009-06-15 10:56:05 +0200 | [diff] [blame] | 4365 | if (w < 0 || w > 256) { |
| 4366 | 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] | 4367 | file, linenum, newsrv->id, w); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4368 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4369 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4370 | } |
Willy Tarreau | 975c50b | 2009-10-10 19:34:06 +0200 | [diff] [blame] | 4371 | newsrv->uweight = newsrv->iweight = w; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4372 | cur_arg += 2; |
| 4373 | } |
| 4374 | else if (!strcmp(args[cur_arg], "minconn")) { |
| 4375 | newsrv->minconn = atol(args[cur_arg + 1]); |
| 4376 | cur_arg += 2; |
| 4377 | } |
| 4378 | else if (!strcmp(args[cur_arg], "maxconn")) { |
| 4379 | newsrv->maxconn = atol(args[cur_arg + 1]); |
| 4380 | cur_arg += 2; |
| 4381 | } |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 4382 | else if (!strcmp(args[cur_arg], "maxqueue")) { |
| 4383 | newsrv->maxqueue = atol(args[cur_arg + 1]); |
| 4384 | cur_arg += 2; |
| 4385 | } |
Willy Tarreau | 9909fc1 | 2007-11-30 17:42:05 +0100 | [diff] [blame] | 4386 | else if (!strcmp(args[cur_arg], "slowstart")) { |
| 4387 | /* slowstart is stored in seconds */ |
Willy Tarreau | 3259e33 | 2007-12-03 01:51:45 +0100 | [diff] [blame] | 4388 | 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] | 4389 | if (err) { |
| 4390 | Alert("parsing [%s:%d] : unexpected character '%c' in 'slowstart' argument of server %s.\n", |
| 4391 | file, linenum, *err, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4392 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4393 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4394 | } |
Willy Tarreau | 4554bc1 | 2010-03-26 10:40:49 +0100 | [diff] [blame] | 4395 | if (val < 0) { |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4396 | Alert("parsing [%s:%d]: invalid value %d for argument '%s' of server %s.\n", |
| 4397 | file, linenum, val, args[cur_arg], newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4398 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4399 | goto out; |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4400 | } |
Willy Tarreau | 3259e33 | 2007-12-03 01:51:45 +0100 | [diff] [blame] | 4401 | newsrv->slowstart = (val + 999) / 1000; |
Willy Tarreau | 9909fc1 | 2007-11-30 17:42:05 +0100 | [diff] [blame] | 4402 | cur_arg += 2; |
| 4403 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4404 | else if (!defsrv && !strcmp(args[cur_arg], "track")) { |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4405 | |
| 4406 | if (!*args[cur_arg + 1]) { |
| 4407 | Alert("parsing [%s:%d]: 'track' expects [<proxy>/]<server> as argument.\n", |
| 4408 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4409 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4410 | goto out; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4411 | } |
| 4412 | |
| 4413 | newsrv->trackit = strdup(args[cur_arg + 1]); |
| 4414 | |
| 4415 | cur_arg += 2; |
| 4416 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4417 | else if (!defsrv && !strcmp(args[cur_arg], "check")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4418 | global.maxsock++; |
| 4419 | do_check = 1; |
| 4420 | cur_arg += 1; |
| 4421 | } |
Willy Tarreau | 9683909 | 2010-03-29 10:02:24 +0200 | [diff] [blame] | 4422 | else if (!defsrv && !strcmp(args[cur_arg], "disabled")) { |
| 4423 | newsrv->state |= SRV_MAINTAIN; |
| 4424 | newsrv->state &= ~SRV_RUNNING; |
| 4425 | newsrv->health = 0; |
| 4426 | cur_arg += 1; |
Emeric Brun | c0ff492 | 2012-09-28 19:37:02 +0200 | [diff] [blame] | 4427 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4428 | else if (!defsrv && !strcmp(args[cur_arg], "observe")) { |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 4429 | if (!strcmp(args[cur_arg + 1], "none")) |
| 4430 | newsrv->observe = HANA_OBS_NONE; |
| 4431 | else if (!strcmp(args[cur_arg + 1], "layer4")) |
| 4432 | newsrv->observe = HANA_OBS_LAYER4; |
| 4433 | else if (!strcmp(args[cur_arg + 1], "layer7")) { |
| 4434 | if (curproxy->mode != PR_MODE_HTTP) { |
| 4435 | Alert("parsing [%s:%d]: '%s' can only be used in http proxies.\n", |
| 4436 | file, linenum, args[cur_arg + 1]); |
| 4437 | err_code |= ERR_ALERT; |
| 4438 | } |
| 4439 | newsrv->observe = HANA_OBS_LAYER7; |
| 4440 | } |
| 4441 | else { |
| 4442 | Alert("parsing [%s:%d]: '%s' expects one of 'none', " |
Willy Tarreau | 53621e0 | 2010-10-22 14:53:40 +0200 | [diff] [blame] | 4443 | "'layer4', 'layer7' but got '%s'\n", |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 4444 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
| 4445 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4446 | goto out; |
| 4447 | } |
| 4448 | |
| 4449 | cur_arg += 2; |
| 4450 | } |
| 4451 | else if (!strcmp(args[cur_arg], "on-error")) { |
| 4452 | if (!strcmp(args[cur_arg + 1], "fastinter")) |
| 4453 | newsrv->onerror = HANA_ONERR_FASTINTER; |
| 4454 | else if (!strcmp(args[cur_arg + 1], "fail-check")) |
| 4455 | newsrv->onerror = HANA_ONERR_FAILCHK; |
| 4456 | else if (!strcmp(args[cur_arg + 1], "sudden-death")) |
| 4457 | newsrv->onerror = HANA_ONERR_SUDDTH; |
| 4458 | else if (!strcmp(args[cur_arg + 1], "mark-down")) |
| 4459 | newsrv->onerror = HANA_ONERR_MARKDWN; |
| 4460 | else { |
| 4461 | Alert("parsing [%s:%d]: '%s' expects one of 'fastinter', " |
Willy Tarreau | 53621e0 | 2010-10-22 14:53:40 +0200 | [diff] [blame] | 4462 | "'fail-check', 'sudden-death' or 'mark-down' but got '%s'\n", |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 4463 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
| 4464 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4465 | goto out; |
| 4466 | } |
| 4467 | |
| 4468 | cur_arg += 2; |
| 4469 | } |
Simon Horman | e0d1bfb | 2011-06-21 14:34:58 +0900 | [diff] [blame] | 4470 | else if (!strcmp(args[cur_arg], "on-marked-down")) { |
| 4471 | if (!strcmp(args[cur_arg + 1], "shutdown-sessions")) |
| 4472 | newsrv->onmarkeddown = HANA_ONMARKEDDOWN_SHUTDOWNSESSIONS; |
| 4473 | else { |
| 4474 | Alert("parsing [%s:%d]: '%s' expects 'shutdown-sessions' but got '%s'\n", |
| 4475 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
| 4476 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4477 | goto out; |
| 4478 | } |
| 4479 | |
| 4480 | cur_arg += 2; |
| 4481 | } |
Justin Karneges | eb2c24a | 2012-05-24 15:28:52 -0700 | [diff] [blame] | 4482 | else if (!strcmp(args[cur_arg], "on-marked-up")) { |
| 4483 | if (!strcmp(args[cur_arg + 1], "shutdown-backup-sessions")) |
| 4484 | newsrv->onmarkedup = HANA_ONMARKEDUP_SHUTDOWNBACKUPSESSIONS; |
| 4485 | else { |
| 4486 | Alert("parsing [%s:%d]: '%s' expects 'shutdown-backup-sessions' but got '%s'\n", |
| 4487 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
| 4488 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4489 | goto out; |
| 4490 | } |
| 4491 | |
| 4492 | cur_arg += 2; |
| 4493 | } |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 4494 | else if (!strcmp(args[cur_arg], "error-limit")) { |
| 4495 | if (!*args[cur_arg + 1]) { |
| 4496 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 4497 | file, linenum, args[cur_arg]); |
| 4498 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4499 | goto out; |
| 4500 | } |
| 4501 | |
| 4502 | newsrv->consecutive_errors_limit = atoi(args[cur_arg + 1]); |
| 4503 | |
| 4504 | if (newsrv->consecutive_errors_limit <= 0) { |
| 4505 | Alert("parsing [%s:%d]: %s has to be > 0.\n", |
| 4506 | file, linenum, args[cur_arg]); |
| 4507 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4508 | goto out; |
| 4509 | } |
Willy Tarreau | f53b25d | 2010-03-15 19:40:37 +0100 | [diff] [blame] | 4510 | cur_arg += 2; |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 4511 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4512 | 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] | 4513 | int port_low, port_high; |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4514 | struct sockaddr_storage *sk; |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4515 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4516 | if (!*args[cur_arg + 1]) { |
Willy Tarreau | eb37faa | 2012-12-08 23:21:19 +0100 | [diff] [blame^] | 4517 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>[-<port>]], and optionally '%s' <addr>, and '%s' <name> as argument.\n", |
| 4518 | file, linenum, "source", "usesrc", "interface"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4519 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4520 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4521 | } |
| 4522 | newsrv->state |= SRV_BIND_SRC; |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4523 | sk = str2sa_range(args[cur_arg + 1], &port_low, &port_high); |
| 4524 | if (!sk) { |
| 4525 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[cur_arg + 1]); |
| 4526 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4527 | goto out; |
| 4528 | } |
| 4529 | newsrv->source_addr = *sk; |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 4530 | |
| 4531 | if (port_low != port_high) { |
| 4532 | int i; |
| 4533 | if (port_low <= 0 || port_low > 65535 || |
| 4534 | port_high <= 0 || port_high > 65535 || |
| 4535 | port_low > port_high) { |
| 4536 | Alert("parsing [%s:%d] : invalid source port range %d-%d.\n", |
| 4537 | file, linenum, port_low, port_high); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4538 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4539 | goto out; |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 4540 | } |
| 4541 | newsrv->sport_range = port_range_alloc_range(port_high - port_low + 1); |
| 4542 | for (i = 0; i < newsrv->sport_range->size; i++) |
| 4543 | newsrv->sport_range->ports[i] = port_low + i; |
| 4544 | } |
| 4545 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4546 | cur_arg += 2; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4547 | while (*(args[cur_arg])) { |
| 4548 | if (!strcmp(args[cur_arg], "usesrc")) { /* address to use outside */ |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4549 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) |
| 4550 | #if !defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4551 | if (newsrv->source_addr.sin_addr.s_addr == INADDR_ANY) { |
| 4552 | Alert("parsing [%s:%d] : '%s' requires an explicit '%s' address.\n", |
| 4553 | file, linenum, "usesrc", "source"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4554 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4555 | goto out; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4556 | } |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4557 | #endif |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4558 | if (!*args[cur_arg + 1]) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4559 | 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] | 4560 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4561 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4562 | goto out; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4563 | } |
| 4564 | if (!strcmp(args[cur_arg + 1], "client")) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4565 | newsrv->state &= ~SRV_TPROXY_MASK; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4566 | newsrv->state |= SRV_TPROXY_CLI; |
| 4567 | } else if (!strcmp(args[cur_arg + 1], "clientip")) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4568 | newsrv->state &= ~SRV_TPROXY_MASK; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4569 | newsrv->state |= SRV_TPROXY_CIP; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4570 | } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) { |
| 4571 | char *name, *end; |
| 4572 | |
| 4573 | name = args[cur_arg+1] + 7; |
| 4574 | while (isspace(*name)) |
| 4575 | name++; |
| 4576 | |
| 4577 | end = name; |
| 4578 | while (*end && !isspace(*end) && *end != ',' && *end != ')') |
| 4579 | end++; |
| 4580 | |
| 4581 | newsrv->state &= ~SRV_TPROXY_MASK; |
| 4582 | newsrv->state |= SRV_TPROXY_DYN; |
| 4583 | newsrv->bind_hdr_name = calloc(1, end - name + 1); |
| 4584 | newsrv->bind_hdr_len = end - name; |
| 4585 | memcpy(newsrv->bind_hdr_name, name, end - name); |
| 4586 | newsrv->bind_hdr_name[end-name] = '\0'; |
| 4587 | newsrv->bind_hdr_occ = -1; |
| 4588 | |
| 4589 | /* now look for an occurrence number */ |
| 4590 | while (isspace(*end)) |
| 4591 | end++; |
| 4592 | if (*end == ',') { |
| 4593 | end++; |
| 4594 | name = end; |
| 4595 | if (*end == '-') |
| 4596 | end++; |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 4597 | while (isdigit((int)*end)) |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4598 | end++; |
| 4599 | newsrv->bind_hdr_occ = strl2ic(name, end-name); |
| 4600 | } |
| 4601 | |
| 4602 | if (newsrv->bind_hdr_occ < -MAX_HDR_HISTORY) { |
| 4603 | Alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative" |
| 4604 | " occurrences values smaller than %d.\n", |
| 4605 | file, linenum, MAX_HDR_HISTORY); |
| 4606 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4607 | goto out; |
| 4608 | } |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4609 | } else { |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4610 | struct sockaddr_storage *sk = str2sa(args[cur_arg + 1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4611 | if (!sk) { |
| 4612 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[cur_arg + 1]); |
| 4613 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4614 | goto out; |
| 4615 | } |
| 4616 | newsrv->tproxy_addr = *sk; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4617 | newsrv->state |= SRV_TPROXY_ADDR; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4618 | } |
| 4619 | global.last_checks |= LSTCHK_NETADM; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4620 | #if !defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4621 | global.last_checks |= LSTCHK_CTTPROXY; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4622 | #endif |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4623 | cur_arg += 2; |
| 4624 | continue; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4625 | #else /* no TPROXY support */ |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4626 | 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] | 4627 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4628 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4629 | goto out; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4630 | #endif /* defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) */ |
| 4631 | } /* "usesrc" */ |
| 4632 | |
| 4633 | if (!strcmp(args[cur_arg], "interface")) { /* specifically bind to this interface */ |
| 4634 | #ifdef SO_BINDTODEVICE |
| 4635 | if (!*args[cur_arg + 1]) { |
| 4636 | Alert("parsing [%s:%d] : '%s' : missing interface name.\n", |
| 4637 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4638 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4639 | goto out; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4640 | } |
| 4641 | if (newsrv->iface_name) |
| 4642 | free(newsrv->iface_name); |
| 4643 | |
| 4644 | newsrv->iface_name = strdup(args[cur_arg + 1]); |
| 4645 | newsrv->iface_len = strlen(newsrv->iface_name); |
| 4646 | global.last_checks |= LSTCHK_NETADM; |
| 4647 | #else |
| 4648 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 4649 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4650 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4651 | goto out; |
Willy Tarreau | 77074d5 | 2006-11-12 23:57:19 +0100 | [diff] [blame] | 4652 | #endif |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4653 | cur_arg += 2; |
| 4654 | continue; |
| 4655 | } |
| 4656 | /* this keyword in not an option of "source" */ |
| 4657 | break; |
| 4658 | } /* while */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4659 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4660 | 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] | 4661 | Alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n", |
| 4662 | file, linenum, "usesrc", "source"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4663 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4664 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 4665 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4666 | else { |
Willy Tarreau | d0d6059 | 2012-10-10 08:57:40 +0200 | [diff] [blame] | 4667 | static int srv_dumped; |
| 4668 | struct srv_kw *kw; |
| 4669 | char *err; |
| 4670 | |
| 4671 | kw = srv_find_kw(args[cur_arg]); |
| 4672 | if (kw) { |
| 4673 | char *err = NULL; |
| 4674 | int code; |
| 4675 | |
| 4676 | if (!kw->parse) { |
| 4677 | Alert("parsing [%s:%d] : '%s %s' : '%s' option is not implemented in this version (check build options).\n", |
| 4678 | file, linenum, args[0], args[1], args[cur_arg]); |
| 4679 | cur_arg += 1 + kw->skip ; |
| 4680 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4681 | goto out; |
| 4682 | } |
| 4683 | |
| 4684 | if (defsrv && !kw->default_ok) { |
| 4685 | Alert("parsing [%s:%d] : '%s %s' : '%s' option is not accepted in default-server sections.\n", |
| 4686 | file, linenum, args[0], args[1], args[cur_arg]); |
| 4687 | cur_arg += 1 + kw->skip ; |
| 4688 | err_code |= ERR_ALERT; |
| 4689 | continue; |
| 4690 | } |
| 4691 | |
| 4692 | code = kw->parse(args, &cur_arg, curproxy, newsrv, &err); |
| 4693 | err_code |= code; |
| 4694 | |
| 4695 | if (code) { |
| 4696 | if (err && *err) { |
| 4697 | indent_msg(&err, 2); |
| 4698 | Alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], err); |
| 4699 | } |
| 4700 | else |
| 4701 | Alert("parsing [%s:%d] : '%s %s' : error encountered while processing '%s'.\n", |
| 4702 | file, linenum, args[0], args[1], args[cur_arg]); |
| 4703 | if (code & ERR_FATAL) { |
| 4704 | free(err); |
| 4705 | cur_arg += 1 + kw->skip; |
| 4706 | goto out; |
| 4707 | } |
| 4708 | } |
| 4709 | free(err); |
| 4710 | cur_arg += 1 + kw->skip; |
| 4711 | continue; |
| 4712 | } |
| 4713 | |
| 4714 | err = NULL; |
| 4715 | if (!srv_dumped) { |
| 4716 | srv_dump_kws(&err); |
| 4717 | indent_msg(&err, 4); |
| 4718 | srv_dumped = 1; |
| 4719 | } |
| 4720 | |
| 4721 | Alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'.%s%s\n", |
| 4722 | file, linenum, args[0], args[1], args[cur_arg], |
| 4723 | err ? " Registered keywords :" : "", err ? err : ""); |
| 4724 | free(err); |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4725 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4726 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4727 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4728 | } |
| 4729 | } |
| 4730 | |
| 4731 | if (do_check) { |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4732 | if (newsrv->trackit) { |
| 4733 | Alert("parsing [%s:%d]: unable to enable checks and tracking at the same time!\n", |
| 4734 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4735 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4736 | goto out; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4737 | } |
| 4738 | |
Willy Tarreau | f4288ee | 2012-09-28 18:13:10 +0200 | [diff] [blame] | 4739 | /* If neither a port nor an addr was specified and no check transport |
| 4740 | * layer is forced, then the transport layer used by the checks is the |
| 4741 | * same as for the production traffic. Otherwise we use raw_sock by |
| 4742 | * default, unless one is specified. |
| 4743 | */ |
Willy Tarreau | 6c16adc | 2012-10-05 00:04:16 +0200 | [diff] [blame] | 4744 | if (!newsrv->check.port && !is_addr(&newsrv->check.addr)) { |
Willy Tarreau | 7151633 | 2012-10-10 23:01:14 +0200 | [diff] [blame] | 4745 | #ifdef USE_OPENSSL |
Willy Tarreau | f4288ee | 2012-09-28 18:13:10 +0200 | [diff] [blame] | 4746 | newsrv->check.use_ssl |= newsrv->use_ssl; |
Willy Tarreau | 7151633 | 2012-10-10 23:01:14 +0200 | [diff] [blame] | 4747 | #endif |
Willy Tarreau | 6c16adc | 2012-10-05 00:04:16 +0200 | [diff] [blame] | 4748 | newsrv->check.send_proxy |= (newsrv->state & SRV_SEND_PROXY); |
| 4749 | } |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 4750 | /* try to get the port from check.addr if check.port not set */ |
| 4751 | if (!newsrv->check.port) |
| 4752 | newsrv->check.port = get_host_port(&newsrv->check.addr); |
Willy Tarreau | 0f03c6f | 2007-03-25 20:46:19 +0200 | [diff] [blame] | 4753 | |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 4754 | if (!newsrv->check.port && !(newsrv->state & SRV_MAPPORTS)) |
| 4755 | newsrv->check.port = realport; /* by default */ |
| 4756 | if (!newsrv->check.port) { |
Willy Tarreau | ef00b50 | 2007-01-07 02:40:09 +0100 | [diff] [blame] | 4757 | /* not yet valid, because no port was set on |
| 4758 | * the server either. We'll check if we have |
| 4759 | * a known port on the first listener. |
| 4760 | */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 4761 | struct listener *l; |
| 4762 | |
| 4763 | list_for_each_entry(l, &curproxy->conf.listeners, by_fe) { |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 4764 | newsrv->check.port = get_host_port(&l->addr); |
| 4765 | if (newsrv->check.port) |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 4766 | break; |
| 4767 | } |
Willy Tarreau | ef00b50 | 2007-01-07 02:40:09 +0100 | [diff] [blame] | 4768 | } |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 4769 | if (!newsrv->check.port) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4770 | Alert("parsing [%s:%d] : server %s has neither service port nor check port. Check has been disabled.\n", |
| 4771 | file, linenum, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4772 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4773 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4774 | } |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 4775 | |
Willy Tarreau | 1ae1b7b | 2012-09-28 15:28:30 +0200 | [diff] [blame] | 4776 | /* Allocate buffer for check requests... */ |
| 4777 | 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] | 4778 | Alert("parsing [%s:%d] : out of memory while allocating check buffer.\n", file, linenum); |
| 4779 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4780 | goto out; |
| 4781 | } |
Willy Tarreau | 1ae1b7b | 2012-09-28 15:28:30 +0200 | [diff] [blame] | 4782 | newsrv->check.bi->size = global.tune.chksize; |
| 4783 | |
| 4784 | /* Allocate buffer for check responses... */ |
| 4785 | if ((newsrv->check.bo = calloc(sizeof(struct buffer) + global.tune.chksize, sizeof(char))) == NULL) { |
| 4786 | Alert("parsing [%s:%d] : out of memory while allocating check buffer.\n", file, linenum); |
| 4787 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4788 | goto out; |
| 4789 | } |
| 4790 | newsrv->check.bo->size = global.tune.chksize; |
Cyril Bonté | c9f825f | 2010-03-17 18:56:31 +0100 | [diff] [blame] | 4791 | |
Willy Tarreau | da92e2f | 2012-07-06 09:40:59 +0200 | [diff] [blame] | 4792 | /* Allocate buffer for partial check results... */ |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 4793 | if ((newsrv->check.conn = calloc(1, sizeof(struct connection))) == NULL) { |
Willy Tarreau | da92e2f | 2012-07-06 09:40:59 +0200 | [diff] [blame] | 4794 | Alert("parsing [%s:%d] : out of memory while allocating check connection.\n", file, linenum); |
| 4795 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4796 | goto out; |
| 4797 | } |
| 4798 | |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 4799 | newsrv->check.conn->t.sock.fd = -1; /* no check in progress yet */ |
| 4800 | newsrv->check.status = HCHK_STATUS_INI; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4801 | newsrv->state |= SRV_CHECKED; |
| 4802 | } |
| 4803 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4804 | if (!defsrv) { |
| 4805 | if (newsrv->state & SRV_BACKUP) |
| 4806 | curproxy->srv_bck++; |
| 4807 | else |
| 4808 | curproxy->srv_act++; |
Willy Tarreau | b625a08 | 2007-11-26 01:15:43 +0100 | [diff] [blame] | 4809 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4810 | newsrv->prev_state = newsrv->state; |
| 4811 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 4812 | } |
| 4813 | |
| 4814 | else if (strcmp(args[0], "unique-id-format") == 0) { |
| 4815 | if (!*(args[1])) { |
| 4816 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 4817 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4818 | goto out; |
| 4819 | } |
William Lallemand | 3203ff4 | 2012-11-11 17:30:56 +0100 | [diff] [blame] | 4820 | if (*(args[2])) { |
| 4821 | Alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]); |
| 4822 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4823 | goto out; |
| 4824 | } |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 4825 | free(curproxy->uniqueid_format_string); |
| 4826 | curproxy->uniqueid_format_string = strdup(args[1]); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4827 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 4828 | |
| 4829 | else if (strcmp(args[0], "unique-id-header") == 0) { |
| 4830 | if (!*(args[1])) { |
| 4831 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 4832 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4833 | goto out; |
| 4834 | } |
| 4835 | free(curproxy->header_unique_id); |
| 4836 | curproxy->header_unique_id = strdup(args[1]); |
| 4837 | } |
| 4838 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4839 | else if (strcmp(args[0], "log-format") == 0) { |
| 4840 | if (!*(args[1])) { |
| 4841 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 4842 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4843 | goto out; |
| 4844 | } |
William Lallemand | 3203ff4 | 2012-11-11 17:30:56 +0100 | [diff] [blame] | 4845 | if (*(args[2])) { |
| 4846 | Alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]); |
| 4847 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4848 | goto out; |
| 4849 | } |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 4850 | |
| 4851 | if (curproxy->logformat_string != default_http_log_format && |
| 4852 | curproxy->logformat_string != default_tcp_log_format && |
| 4853 | curproxy->logformat_string != clf_http_log_format) |
| 4854 | free(curproxy->logformat_string); |
| 4855 | curproxy->logformat_string = strdup(args[1]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4856 | } |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4857 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4858 | else if (!strcmp(args[0], "log") && kwm == KWM_NO) { |
| 4859 | /* delete previous herited or defined syslog servers */ |
| 4860 | struct logsrv *back; |
| 4861 | |
| 4862 | if (*(args[1]) != 0) { |
| 4863 | Alert("parsing [%s:%d]:%s : 'no log' does not expect arguments.\n", file, linenum, args[1]); |
| 4864 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4865 | goto out; |
| 4866 | } |
| 4867 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4868 | list_for_each_entry_safe(tmplogsrv, back, &curproxy->logsrvs, list) { |
| 4869 | LIST_DEL(&tmplogsrv->list); |
| 4870 | free(tmplogsrv); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4871 | } |
| 4872 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4873 | else if (!strcmp(args[0], "log")) { /* syslog server address */ |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4874 | struct logsrv *logsrv; |
| 4875 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4876 | if (*(args[1]) && *(args[2]) == 0 && !strcmp(args[1], "global")) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4877 | /* copy global.logrsvs linked list to the end of curproxy->logsrvs */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4878 | list_for_each_entry(tmplogsrv, &global.logsrvs, list) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4879 | struct logsrv *node = malloc(sizeof(struct logsrv)); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4880 | memcpy(node, tmplogsrv, sizeof(struct logsrv)); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4881 | LIST_INIT(&node->list); |
| 4882 | LIST_ADDQ(&curproxy->logsrvs, &node->list); |
| 4883 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4884 | } |
| 4885 | else if (*(args[1]) && *(args[2])) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4886 | |
| 4887 | logsrv = calloc(1, sizeof(struct logsrv)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4888 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4889 | logsrv->facility = get_log_facility(args[2]); |
| 4890 | if (logsrv->facility < 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4891 | 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] | 4892 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4893 | goto out; |
| 4894 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4895 | } |
| 4896 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4897 | logsrv->level = 7; /* max syslog level = debug */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4898 | if (*(args[3])) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4899 | logsrv->level = get_log_level(args[3]); |
| 4900 | if (logsrv->level < 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4901 | 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] | 4902 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4903 | goto out; |
| 4904 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4905 | } |
| 4906 | } |
| 4907 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4908 | logsrv->minlvl = 0; /* limit syslog level to this level (emerg) */ |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 4909 | if (*(args[4])) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4910 | logsrv->minlvl = get_log_level(args[4]); |
| 4911 | if (logsrv->level < 0) { |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 4912 | 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] | 4913 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4914 | goto out; |
| 4915 | |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 4916 | } |
| 4917 | } |
| 4918 | |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 4919 | if (args[1][0] == '/') { |
David du Colombier | 11bcb6c | 2011-03-24 12:23:00 +0100 | [diff] [blame] | 4920 | struct sockaddr_storage *sk = (struct sockaddr_storage *)str2sun(args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4921 | if (!sk) { |
| 4922 | 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] | 4923 | args[1], (int)sizeof(((struct sockaddr_un *)sk)->sun_path) - 1); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4924 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4925 | goto out; |
| 4926 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4927 | logsrv->addr = *sk; |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 4928 | } else { |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4929 | struct sockaddr_storage *sk = str2sa(args[1]); |
David du Colombier | 11bcb6c | 2011-03-24 12:23:00 +0100 | [diff] [blame] | 4930 | if (!sk) { |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4931 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[1]); |
| 4932 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4933 | goto out; |
| 4934 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4935 | logsrv->addr = *sk; |
| 4936 | if (!get_host_port(&logsrv->addr)) |
| 4937 | set_host_port(&logsrv->addr, SYSLOG_PORT); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4938 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4939 | |
| 4940 | LIST_ADDQ(&curproxy->logsrvs, &logsrv->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4941 | } |
| 4942 | else { |
| 4943 | Alert("parsing [%s:%d] : 'log' expects either <address[:port]> and <facility> or 'global' as arguments.\n", |
| 4944 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4945 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4946 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4947 | } |
| 4948 | } |
| 4949 | 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] | 4950 | int cur_arg; |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4951 | struct sockaddr_storage *sk; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4952 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4953 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4954 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4955 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4956 | if (!*args[1]) { |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4957 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optionally '%s' <addr>, and '%s' <name>.\n", |
| 4958 | file, linenum, "source", "usesrc", "interface"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4959 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4960 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4961 | } |
Willy Tarreau | 368480c | 2009-03-01 08:27:21 +0100 | [diff] [blame] | 4962 | |
| 4963 | /* we must first clear any optional default setting */ |
| 4964 | curproxy->options &= ~PR_O_TPXY_MASK; |
| 4965 | free(curproxy->iface_name); |
| 4966 | curproxy->iface_name = NULL; |
| 4967 | curproxy->iface_len = 0; |
| 4968 | |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4969 | sk = str2sa(args[1]); |
| 4970 | if (!sk) { |
| 4971 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[1]); |
| 4972 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4973 | goto out; |
| 4974 | } |
| 4975 | curproxy->source_addr = *sk; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4976 | curproxy->options |= PR_O_BIND_SRC; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4977 | |
| 4978 | cur_arg = 2; |
| 4979 | while (*(args[cur_arg])) { |
| 4980 | if (!strcmp(args[cur_arg], "usesrc")) { /* address to use outside */ |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4981 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) |
| 4982 | #if !defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4983 | if (curproxy->source_addr.sin_addr.s_addr == INADDR_ANY) { |
| 4984 | Alert("parsing [%s:%d] : '%s' requires an explicit 'source' address.\n", |
| 4985 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4986 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4987 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4988 | } |
| 4989 | #endif |
| 4990 | if (!*args[cur_arg + 1]) { |
| 4991 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n", |
| 4992 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4993 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4994 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4995 | } |
| 4996 | |
| 4997 | if (!strcmp(args[cur_arg + 1], "client")) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4998 | curproxy->options &= ~PR_O_TPXY_MASK; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4999 | curproxy->options |= PR_O_TPXY_CLI; |
| 5000 | } else if (!strcmp(args[cur_arg + 1], "clientip")) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 5001 | curproxy->options &= ~PR_O_TPXY_MASK; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5002 | curproxy->options |= PR_O_TPXY_CIP; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 5003 | } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) { |
| 5004 | char *name, *end; |
| 5005 | |
| 5006 | name = args[cur_arg+1] + 7; |
| 5007 | while (isspace(*name)) |
| 5008 | name++; |
| 5009 | |
| 5010 | end = name; |
| 5011 | while (*end && !isspace(*end) && *end != ',' && *end != ')') |
| 5012 | end++; |
| 5013 | |
| 5014 | curproxy->options &= ~PR_O_TPXY_MASK; |
| 5015 | curproxy->options |= PR_O_TPXY_DYN; |
| 5016 | curproxy->bind_hdr_name = calloc(1, end - name + 1); |
| 5017 | curproxy->bind_hdr_len = end - name; |
| 5018 | memcpy(curproxy->bind_hdr_name, name, end - name); |
| 5019 | curproxy->bind_hdr_name[end-name] = '\0'; |
| 5020 | curproxy->bind_hdr_occ = -1; |
| 5021 | |
| 5022 | /* now look for an occurrence number */ |
| 5023 | while (isspace(*end)) |
| 5024 | end++; |
| 5025 | if (*end == ',') { |
| 5026 | end++; |
| 5027 | name = end; |
| 5028 | if (*end == '-') |
| 5029 | end++; |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 5030 | while (isdigit((int)*end)) |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 5031 | end++; |
| 5032 | curproxy->bind_hdr_occ = strl2ic(name, end-name); |
| 5033 | } |
| 5034 | |
| 5035 | if (curproxy->bind_hdr_occ < -MAX_HDR_HISTORY) { |
| 5036 | Alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative" |
| 5037 | " occurrences values smaller than %d.\n", |
| 5038 | file, linenum, MAX_HDR_HISTORY); |
| 5039 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5040 | goto out; |
| 5041 | } |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5042 | } else { |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 5043 | struct sockaddr_storage *sk = str2sa(args[cur_arg + 1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 5044 | if (!sk) { |
| 5045 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[cur_arg + 1]); |
| 5046 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5047 | goto out; |
| 5048 | } |
| 5049 | curproxy->tproxy_addr = *sk; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5050 | curproxy->options |= PR_O_TPXY_ADDR; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5051 | } |
| 5052 | global.last_checks |= LSTCHK_NETADM; |
| 5053 | #if !defined(CONFIG_HAP_LINUX_TPROXY) |
| 5054 | global.last_checks |= LSTCHK_CTTPROXY; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 5055 | #endif |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5056 | #else /* no TPROXY support */ |
| 5057 | 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] | 5058 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5059 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5060 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5061 | #endif |
| 5062 | cur_arg += 2; |
| 5063 | continue; |
Willy Tarreau | 77074d5 | 2006-11-12 23:57:19 +0100 | [diff] [blame] | 5064 | } |
| 5065 | |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5066 | if (!strcmp(args[cur_arg], "interface")) { /* specifically bind to this interface */ |
| 5067 | #ifdef SO_BINDTODEVICE |
| 5068 | if (!*args[cur_arg + 1]) { |
| 5069 | Alert("parsing [%s:%d] : '%s' : missing interface name.\n", |
| 5070 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5071 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5072 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5073 | } |
| 5074 | if (curproxy->iface_name) |
| 5075 | free(curproxy->iface_name); |
| 5076 | |
| 5077 | curproxy->iface_name = strdup(args[cur_arg + 1]); |
| 5078 | curproxy->iface_len = strlen(curproxy->iface_name); |
| 5079 | global.last_checks |= LSTCHK_NETADM; |
| 5080 | #else |
| 5081 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 5082 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5083 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5084 | goto out; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 5085 | #endif |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5086 | cur_arg += 2; |
| 5087 | continue; |
| 5088 | } |
| 5089 | 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] | 5090 | file, linenum, args[0], "interface", "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5091 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5092 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 5093 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5094 | } |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 5095 | else if (!strcmp(args[0], "usesrc")) { /* address to use outside: needs "source" first */ |
| 5096 | Alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n", |
| 5097 | file, linenum, "usesrc", "source"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5098 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5099 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 5100 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5101 | 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] | 5102 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5103 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 5104 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5105 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5106 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5107 | } |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5108 | |
| 5109 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5110 | SMP_OPT_DIR_REQ, ACT_REPLACE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5111 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5112 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5113 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5114 | } |
| 5115 | else if (!strcmp(args[0], "reqdel")) { /* delete request header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5116 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5117 | SMP_OPT_DIR_REQ, ACT_REMOVE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5118 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5119 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5120 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5121 | } |
| 5122 | 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] | 5123 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5124 | SMP_OPT_DIR_REQ, ACT_DENY, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5125 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5126 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5127 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5128 | } |
| 5129 | 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] | 5130 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5131 | SMP_OPT_DIR_REQ, ACT_PASS, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5132 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5133 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5134 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5135 | } |
| 5136 | 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] | 5137 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5138 | SMP_OPT_DIR_REQ, ACT_ALLOW, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5139 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5140 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5141 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5142 | } |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 5143 | 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] | 5144 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5145 | SMP_OPT_DIR_REQ, ACT_TARPIT, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5146 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5147 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5148 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 5149 | } |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5150 | 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] | 5151 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5152 | SMP_OPT_DIR_REQ, ACT_SETBE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5153 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5154 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5155 | goto out; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5156 | } |
| 5157 | 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] | 5158 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5159 | SMP_OPT_DIR_REQ, ACT_SETBE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5160 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5161 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5162 | goto out; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5163 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5164 | 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] | 5165 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5166 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 5167 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5168 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5169 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5170 | } |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5171 | |
| 5172 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5173 | SMP_OPT_DIR_REQ, ACT_REPLACE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5174 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5175 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5176 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5177 | } |
| 5178 | 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] | 5179 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5180 | SMP_OPT_DIR_REQ, ACT_REMOVE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5181 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5182 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5183 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5184 | } |
| 5185 | 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] | 5186 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5187 | SMP_OPT_DIR_REQ, ACT_DENY, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5188 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5189 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5190 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5191 | } |
| 5192 | 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] | 5193 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5194 | SMP_OPT_DIR_REQ, ACT_PASS, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5195 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5196 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5197 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5198 | } |
| 5199 | 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] | 5200 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5201 | SMP_OPT_DIR_REQ, ACT_ALLOW, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5202 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5203 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5204 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5205 | } |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 5206 | 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] | 5207 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5208 | SMP_OPT_DIR_REQ, ACT_TARPIT, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5209 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5210 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5211 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 5212 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5213 | else if (!strcmp(args[0], "reqadd")) { /* add request header */ |
Willy Tarreau | f4f0412 | 2010-01-28 18:10:50 +0100 | [diff] [blame] | 5214 | struct cond_wordlist *wl; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5215 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5216 | if (curproxy == &defproxy) { |
| 5217 | 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] | 5218 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5219 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5220 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5221 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5222 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5223 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5224 | if (*(args[1]) == 0) { |
| 5225 | 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] | 5226 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5227 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5228 | } |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5229 | |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 5230 | if ((strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0)) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 5231 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args+2, &errmsg)) == NULL) { |
| 5232 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 5233 | file, linenum, args[0], errmsg); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 5234 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5235 | goto out; |
| 5236 | } |
| 5237 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
| 5238 | } |
| 5239 | else if (*args[2]) { |
| 5240 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 5241 | file, linenum, args[0], args[2]); |
| 5242 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5243 | goto out; |
| 5244 | } |
| 5245 | |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5246 | wl = calloc(1, sizeof(*wl)); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 5247 | wl->cond = cond; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5248 | wl->s = strdup(args[1]); |
| 5249 | LIST_ADDQ(&curproxy->req_add, &wl->list); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 5250 | warnif_misplaced_reqadd(curproxy, file, linenum, args[0]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5251 | } |
| 5252 | 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] | 5253 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5254 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 5255 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5256 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5257 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5258 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5259 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5260 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5261 | SMP_OPT_DIR_RES, ACT_REPLACE, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5262 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5263 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5264 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5265 | } |
| 5266 | else if (!strcmp(args[0], "rspdel")) { /* delete response header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5267 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5268 | SMP_OPT_DIR_RES, ACT_REMOVE, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5269 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5270 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5271 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5272 | } |
| 5273 | else if (!strcmp(args[0], "rspdeny")) { /* block response header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5274 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5275 | SMP_OPT_DIR_RES, ACT_DENY, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5276 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5277 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5278 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5279 | } |
| 5280 | 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] | 5281 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5282 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 5283 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5284 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5285 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5286 | } |
| 5287 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5288 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5289 | SMP_OPT_DIR_RES, ACT_REPLACE, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5290 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5291 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5292 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5293 | } |
| 5294 | 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] | 5295 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5296 | SMP_OPT_DIR_RES, ACT_REMOVE, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5297 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5298 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5299 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5300 | } |
| 5301 | 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] | 5302 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5303 | SMP_OPT_DIR_RES, ACT_DENY, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5304 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5305 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5306 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5307 | } |
| 5308 | else if (!strcmp(args[0], "rspadd")) { /* add response header */ |
Willy Tarreau | f4f0412 | 2010-01-28 18:10:50 +0100 | [diff] [blame] | 5309 | struct cond_wordlist *wl; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5310 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5311 | if (curproxy == &defproxy) { |
| 5312 | 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] | 5313 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5314 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5315 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5316 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5317 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5318 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5319 | if (*(args[1]) == 0) { |
| 5320 | 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] | 5321 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5322 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5323 | } |
| 5324 | |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5325 | if ((strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0)) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 5326 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args+2, &errmsg)) == NULL) { |
| 5327 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 5328 | file, linenum, args[0], errmsg); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5329 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5330 | goto out; |
| 5331 | } |
| 5332 | err_code |= warnif_cond_requires_req(cond, file, linenum); |
| 5333 | } |
| 5334 | else if (*args[2]) { |
| 5335 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 5336 | file, linenum, args[0], args[2]); |
| 5337 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5338 | goto out; |
| 5339 | } |
| 5340 | |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5341 | wl = calloc(1, sizeof(*wl)); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5342 | wl->cond = cond; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5343 | wl->s = strdup(args[1]); |
| 5344 | LIST_ADDQ(&curproxy->rsp_add, &wl->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5345 | } |
| 5346 | else if (!strcmp(args[0], "errorloc") || |
| 5347 | !strcmp(args[0], "errorloc302") || |
| 5348 | !strcmp(args[0], "errorloc303")) { /* error location */ |
| 5349 | int errnum, errlen; |
| 5350 | char *err; |
| 5351 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5352 | 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] | 5353 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5354 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5355 | if (*(args[2]) == 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 5356 | 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] | 5357 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5358 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5359 | } |
| 5360 | |
| 5361 | errnum = atol(args[1]); |
| 5362 | if (!strcmp(args[0], "errorloc303")) { |
| 5363 | err = malloc(strlen(HTTP_303) + strlen(args[2]) + 5); |
| 5364 | errlen = sprintf(err, "%s%s\r\n\r\n", HTTP_303, args[2]); |
| 5365 | } else { |
| 5366 | err = malloc(strlen(HTTP_302) + strlen(args[2]) + 5); |
| 5367 | errlen = sprintf(err, "%s%s\r\n\r\n", HTTP_302, args[2]); |
| 5368 | } |
| 5369 | |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 5370 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) { |
| 5371 | if (http_err_codes[rc] == errnum) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 5372 | chunk_destroy(&curproxy->errmsg[rc]); |
| 5373 | chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 5374 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5375 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5376 | } |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 5377 | |
| 5378 | if (rc >= HTTP_ERR_SIZE) { |
| 5379 | Warning("parsing [%s:%d] : status code %d not handled, error relocation will be ignored.\n", |
| 5380 | file, linenum, errnum); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5381 | free(err); |
| 5382 | } |
| 5383 | } |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5384 | else if (!strcmp(args[0], "errorfile")) { /* error message from a file */ |
| 5385 | int errnum, errlen, fd; |
| 5386 | char *err; |
| 5387 | struct stat stat; |
| 5388 | |
| 5389 | 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] | 5390 | err_code |= ERR_WARN; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5391 | |
| 5392 | if (*(args[2]) == 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 5393 | 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] | 5394 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5395 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5396 | } |
| 5397 | |
| 5398 | fd = open(args[2], O_RDONLY); |
| 5399 | if ((fd < 0) || (fstat(fd, &stat) < 0)) { |
| 5400 | Alert("parsing [%s:%d] : error opening file <%s> for custom error message <%s>.\n", |
| 5401 | file, linenum, args[2], args[1]); |
| 5402 | if (fd >= 0) |
| 5403 | close(fd); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5404 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5405 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5406 | } |
| 5407 | |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 5408 | if (stat.st_size <= global.tune.bufsize) { |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5409 | errlen = stat.st_size; |
| 5410 | } else { |
| 5411 | 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] | 5412 | file, linenum, args[2], global.tune.bufsize); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5413 | err_code |= ERR_WARN; |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 5414 | errlen = global.tune.bufsize; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5415 | } |
| 5416 | |
| 5417 | err = malloc(errlen); /* malloc() must succeed during parsing */ |
| 5418 | errnum = read(fd, err, errlen); |
| 5419 | if (errnum != errlen) { |
| 5420 | Alert("parsing [%s:%d] : error reading file <%s> for custom error message <%s>.\n", |
| 5421 | file, linenum, args[2], args[1]); |
| 5422 | close(fd); |
| 5423 | free(err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5424 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5425 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5426 | } |
| 5427 | close(fd); |
| 5428 | |
| 5429 | errnum = atol(args[1]); |
| 5430 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) { |
| 5431 | if (http_err_codes[rc] == errnum) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 5432 | chunk_destroy(&curproxy->errmsg[rc]); |
| 5433 | chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen); |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5434 | break; |
| 5435 | } |
| 5436 | } |
| 5437 | |
| 5438 | if (rc >= HTTP_ERR_SIZE) { |
| 5439 | Warning("parsing [%s:%d] : status code %d not handled, error customization will be ignored.\n", |
| 5440 | file, linenum, errnum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5441 | err_code |= ERR_WARN; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5442 | free(err); |
| 5443 | } |
| 5444 | } |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5445 | else if (!strcmp(args[0], "compression")) { |
| 5446 | struct comp *comp; |
| 5447 | if (curproxy->comp == NULL) { |
| 5448 | comp = calloc(1, sizeof(struct comp)); |
| 5449 | curproxy->comp = comp; |
| 5450 | } else { |
| 5451 | comp = curproxy->comp; |
| 5452 | } |
| 5453 | |
| 5454 | if (!strcmp(args[1], "algo")) { |
| 5455 | int cur_arg; |
William Lallemand | 8b52bb3 | 2012-11-16 18:06:41 +0100 | [diff] [blame] | 5456 | struct comp_ctx *ctx; |
William Lallemand | 552df67 | 2012-11-07 13:21:47 +0100 | [diff] [blame] | 5457 | |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5458 | cur_arg = 2; |
| 5459 | if (!*args[cur_arg]) { |
| 5460 | Alert("parsing [%s:%d] : '%s' expects <algorithm>\n", |
| 5461 | file, linenum, args[0]); |
| 5462 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5463 | goto out; |
| 5464 | } |
| 5465 | while (*(args[cur_arg])) { |
| 5466 | if (comp_append_algo(comp, args[cur_arg]) < 0) { |
| 5467 | Alert("parsing [%s:%d] : '%s' : '%s' is not a supported algorithm.\n", |
| 5468 | file, linenum, args[0], args[cur_arg]); |
| 5469 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5470 | goto out; |
| 5471 | } |
William Lallemand | 552df67 | 2012-11-07 13:21:47 +0100 | [diff] [blame] | 5472 | if (curproxy->comp->algos->init(&ctx, 9) == 0) { |
| 5473 | curproxy->comp->algos->end(&ctx); |
| 5474 | } else { |
| 5475 | Alert("parsing [%s:%d] : '%s' : Can't init '%s' algorithm.\n", |
| 5476 | file, linenum, args[0], args[cur_arg]); |
| 5477 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5478 | goto out; |
| 5479 | } |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5480 | cur_arg ++; |
| 5481 | continue; |
| 5482 | } |
| 5483 | } |
Willy Tarreau | 70737d1 | 2012-10-27 00:34:28 +0200 | [diff] [blame] | 5484 | else if (!strcmp(args[1], "offload")) { |
| 5485 | comp->offload = 1; |
| 5486 | } |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5487 | else if (!strcmp(args[1], "type")) { |
| 5488 | int cur_arg; |
| 5489 | cur_arg = 2; |
| 5490 | if (!*args[cur_arg]) { |
| 5491 | Alert("parsing [%s:%d] : '%s' expects <type>\n", |
| 5492 | file, linenum, args[0]); |
| 5493 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5494 | goto out; |
| 5495 | } |
| 5496 | while (*(args[cur_arg])) { |
| 5497 | comp_append_type(comp, args[cur_arg]); |
| 5498 | cur_arg ++; |
| 5499 | continue; |
| 5500 | } |
| 5501 | } |
| 5502 | else { |
Willy Tarreau | 70737d1 | 2012-10-27 00:34:28 +0200 | [diff] [blame] | 5503 | Alert("parsing [%s:%d] : '%s' expects 'algo', 'type' or 'offload'\n", |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5504 | file, linenum, args[0]); |
| 5505 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5506 | goto out; |
| 5507 | } |
| 5508 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5509 | else { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 5510 | struct cfg_kw_list *kwl; |
| 5511 | int index; |
| 5512 | |
| 5513 | list_for_each_entry(kwl, &cfg_keywords.list, list) { |
| 5514 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 5515 | if (kwl->kw[index].section != CFG_LISTEN) |
| 5516 | continue; |
| 5517 | if (strcmp(kwl->kw[index].kw, args[0]) == 0) { |
| 5518 | /* prepare error message just in case */ |
Willy Tarreau | 28a47d6 | 2012-09-18 20:02:48 +0200 | [diff] [blame] | 5519 | 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] | 5520 | if (rc < 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 5521 | Alert("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5522 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5523 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 5524 | } |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 5525 | else if (rc > 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 5526 | Warning("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5527 | err_code |= ERR_WARN; |
| 5528 | goto out; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 5529 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5530 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 5531 | } |
| 5532 | } |
| 5533 | } |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5534 | |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5535 | 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] | 5536 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5537 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5538 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5539 | out: |
Willy Tarreau | f4068b6 | 2012-05-08 17:37:49 +0200 | [diff] [blame] | 5540 | free(errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5541 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5542 | } |
| 5543 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5544 | int |
| 5545 | cfg_parse_users(const char *file, int linenum, char **args, int kwm) |
| 5546 | { |
| 5547 | |
| 5548 | int err_code = 0; |
| 5549 | const char *err; |
| 5550 | |
| 5551 | if (!strcmp(args[0], "userlist")) { /* new userlist */ |
| 5552 | struct userlist *newul; |
| 5553 | |
| 5554 | if (!*args[1]) { |
| 5555 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 5556 | file, linenum, args[0]); |
| 5557 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5558 | goto out; |
| 5559 | } |
| 5560 | |
| 5561 | err = invalid_char(args[1]); |
| 5562 | if (err) { |
| 5563 | Alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 5564 | file, linenum, *err, args[0], args[1]); |
| 5565 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5566 | goto out; |
| 5567 | } |
| 5568 | |
| 5569 | for (newul = userlist; newul; newul = newul->next) |
| 5570 | if (!strcmp(newul->name, args[1])) { |
| 5571 | Warning("parsing [%s:%d]: ignoring duplicated userlist '%s'.\n", |
| 5572 | file, linenum, args[1]); |
| 5573 | err_code |= ERR_WARN; |
| 5574 | goto out; |
| 5575 | } |
| 5576 | |
| 5577 | newul = (struct userlist *)calloc(1, sizeof(struct userlist)); |
| 5578 | if (!newul) { |
| 5579 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 5580 | err_code |= ERR_ALERT | ERR_ABORT; |
| 5581 | goto out; |
| 5582 | } |
| 5583 | |
| 5584 | newul->groupusers = calloc(MAX_AUTH_GROUPS, sizeof(char *)); |
| 5585 | newul->name = strdup(args[1]); |
| 5586 | |
| 5587 | if (!newul->groupusers | !newul->name) { |
| 5588 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 5589 | err_code |= ERR_ALERT | ERR_ABORT; |
| 5590 | goto out; |
| 5591 | } |
| 5592 | |
| 5593 | newul->next = userlist; |
| 5594 | userlist = newul; |
| 5595 | |
| 5596 | } else if (!strcmp(args[0], "group")) { /* new group */ |
| 5597 | int cur_arg, i; |
| 5598 | const char *err; |
| 5599 | |
| 5600 | if (!*args[1]) { |
| 5601 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 5602 | file, linenum, args[0]); |
| 5603 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5604 | goto out; |
| 5605 | } |
| 5606 | |
| 5607 | err = invalid_char(args[1]); |
| 5608 | if (err) { |
| 5609 | Alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 5610 | file, linenum, *err, args[0], args[1]); |
| 5611 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5612 | goto out; |
| 5613 | } |
| 5614 | |
| 5615 | for(i = 0; i < userlist->grpcnt; i++) |
| 5616 | if (!strcmp(userlist->groups[i], args[1])) { |
| 5617 | Warning("parsing [%s:%d]: ignoring duplicated group '%s' in userlist '%s'.\n", |
| 5618 | file, linenum, args[1], userlist->name); |
| 5619 | err_code |= ERR_ALERT; |
| 5620 | goto out; |
| 5621 | } |
| 5622 | |
| 5623 | if (userlist->grpcnt >= MAX_AUTH_GROUPS) { |
| 5624 | Alert("parsing [%s:%d]: too many groups (%u) in in userlist '%s' while adding group '%s'.\n", |
| 5625 | file, linenum, MAX_AUTH_GROUPS, userlist->name, args[1]); |
| 5626 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5627 | goto out; |
| 5628 | } |
| 5629 | |
| 5630 | cur_arg = 2; |
| 5631 | |
| 5632 | while (*args[cur_arg]) { |
| 5633 | if (!strcmp(args[cur_arg], "users")) { |
| 5634 | userlist->groupusers[userlist->grpcnt] = strdup(args[cur_arg + 1]); |
| 5635 | cur_arg += 2; |
| 5636 | continue; |
| 5637 | } else { |
| 5638 | Alert("parsing [%s:%d]: '%s' only supports 'users' option.\n", |
| 5639 | file, linenum, args[0]); |
| 5640 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5641 | goto out; |
| 5642 | } |
| 5643 | } |
| 5644 | |
| 5645 | userlist->groups[userlist->grpcnt++] = strdup(args[1]); |
| 5646 | } else if (!strcmp(args[0], "user")) { /* new user */ |
| 5647 | struct auth_users *newuser; |
| 5648 | int cur_arg; |
| 5649 | |
| 5650 | if (!*args[1]) { |
| 5651 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 5652 | file, linenum, args[0]); |
| 5653 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5654 | goto out; |
| 5655 | } |
| 5656 | |
| 5657 | for (newuser = userlist->users; newuser; newuser = newuser->next) |
| 5658 | if (!strcmp(newuser->user, args[1])) { |
| 5659 | Warning("parsing [%s:%d]: ignoring duplicated user '%s' in userlist '%s'.\n", |
| 5660 | file, linenum, args[1], userlist->name); |
| 5661 | err_code |= ERR_ALERT; |
| 5662 | goto out; |
| 5663 | } |
| 5664 | |
| 5665 | newuser = (struct auth_users *)calloc(1, sizeof(struct auth_users)); |
| 5666 | if (!newuser) { |
| 5667 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 5668 | err_code |= ERR_ALERT | ERR_ABORT; |
| 5669 | goto out; |
| 5670 | } |
| 5671 | |
| 5672 | newuser->user = strdup(args[1]); |
| 5673 | |
| 5674 | newuser->next = userlist->users; |
| 5675 | userlist->users = newuser; |
| 5676 | |
| 5677 | cur_arg = 2; |
| 5678 | |
| 5679 | while (*args[cur_arg]) { |
| 5680 | if (!strcmp(args[cur_arg], "password")) { |
| 5681 | #ifndef CONFIG_HAP_CRYPT |
| 5682 | Warning("parsing [%s:%d]: no crypt(3) support compiled, encrypted passwords will not work.\n", |
| 5683 | file, linenum); |
| 5684 | err_code |= ERR_ALERT; |
| 5685 | #endif |
| 5686 | newuser->pass = strdup(args[cur_arg + 1]); |
| 5687 | cur_arg += 2; |
| 5688 | continue; |
| 5689 | } else if (!strcmp(args[cur_arg], "insecure-password")) { |
| 5690 | newuser->pass = strdup(args[cur_arg + 1]); |
| 5691 | newuser->flags |= AU_O_INSECURE; |
| 5692 | cur_arg += 2; |
| 5693 | continue; |
| 5694 | } else if (!strcmp(args[cur_arg], "groups")) { |
Willy Tarreau | b4c06b7 | 2010-02-02 11:28:20 +0100 | [diff] [blame] | 5695 | newuser->u.groups = strdup(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5696 | cur_arg += 2; |
| 5697 | continue; |
| 5698 | } else { |
| 5699 | Alert("parsing [%s:%d]: '%s' only supports 'password', 'insecure-password' and 'groups' options.\n", |
| 5700 | file, linenum, args[0]); |
| 5701 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5702 | goto out; |
| 5703 | } |
| 5704 | } |
| 5705 | } else { |
| 5706 | Alert("parsing [%s:%d]: unknown keyword '%s' in '%s' section\n", file, linenum, args[0], "users"); |
| 5707 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5708 | } |
| 5709 | |
| 5710 | out: |
| 5711 | return err_code; |
| 5712 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5713 | |
| 5714 | /* |
| 5715 | * This function reads and parses the configuration file given in the argument. |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5716 | * Returns the error code, 0 if OK, or any combination of : |
| 5717 | * - ERR_ABORT: must abort ASAP |
| 5718 | * - ERR_FATAL: we can continue parsing but not start the service |
| 5719 | * - ERR_WARN: a warning has been emitted |
| 5720 | * - ERR_ALERT: an alert has been emitted |
| 5721 | * Only the two first ones can stop processing, the two others are just |
| 5722 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5723 | */ |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 5724 | int readcfgfile(const char *file) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5725 | { |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5726 | char thisline[LINESIZE]; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5727 | FILE *f; |
| 5728 | int linenum = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5729 | int confsect = CFG_NONE; |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5730 | int err_code = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5731 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5732 | if ((f=fopen(file,"r")) == NULL) |
| 5733 | return -1; |
| 5734 | |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5735 | while (fgets(thisline, sizeof(thisline), f) != NULL) { |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 5736 | int arg, kwm = KWM_STD; |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5737 | char *end; |
| 5738 | char *args[MAX_LINE_ARGS + 1]; |
| 5739 | char *line = thisline; |
| 5740 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5741 | linenum++; |
| 5742 | |
| 5743 | end = line + strlen(line); |
| 5744 | |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5745 | if (end-line == sizeof(thisline)-1 && *(end-1) != '\n') { |
| 5746 | /* Check if we reached the limit and the last char is not \n. |
| 5747 | * Watch out for the last line without the terminating '\n'! |
| 5748 | */ |
| 5749 | Alert("parsing [%s:%d]: line too long, limit: %d.\n", |
Willy Tarreau | 5e4a6f1 | 2009-04-11 19:42:49 +0200 | [diff] [blame] | 5750 | file, linenum, (int)sizeof(thisline)-1); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5751 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5752 | } |
| 5753 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5754 | /* skip leading spaces */ |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 5755 | while (isspace((unsigned char)*line)) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5756 | line++; |
| 5757 | |
| 5758 | arg = 0; |
| 5759 | args[arg] = line; |
| 5760 | |
| 5761 | while (*line && arg < MAX_LINE_ARGS) { |
| 5762 | /* first, we'll replace \\, \<space>, \#, \r, \n, \t, \xXX with their |
| 5763 | * C equivalent value. Other combinations left unchanged (eg: \1). |
| 5764 | */ |
| 5765 | if (*line == '\\') { |
| 5766 | int skip = 0; |
| 5767 | if (line[1] == ' ' || line[1] == '\\' || line[1] == '#') { |
| 5768 | *line = line[1]; |
| 5769 | skip = 1; |
| 5770 | } |
| 5771 | else if (line[1] == 'r') { |
| 5772 | *line = '\r'; |
| 5773 | skip = 1; |
| 5774 | } |
| 5775 | else if (line[1] == 'n') { |
| 5776 | *line = '\n'; |
| 5777 | skip = 1; |
| 5778 | } |
| 5779 | else if (line[1] == 't') { |
| 5780 | *line = '\t'; |
| 5781 | skip = 1; |
| 5782 | } |
| 5783 | else if (line[1] == 'x') { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5784 | if ((line + 3 < end) && ishex(line[2]) && ishex(line[3])) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5785 | unsigned char hex1, hex2; |
| 5786 | hex1 = toupper(line[2]) - '0'; |
| 5787 | hex2 = toupper(line[3]) - '0'; |
| 5788 | if (hex1 > 9) hex1 -= 'A' - '9' - 1; |
| 5789 | if (hex2 > 9) hex2 -= 'A' - '9' - 1; |
| 5790 | *line = (hex1<<4) + hex2; |
| 5791 | skip = 3; |
| 5792 | } |
| 5793 | else { |
| 5794 | 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] | 5795 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5796 | } |
| 5797 | } |
| 5798 | if (skip) { |
Cyril Bonté | dd1b01d | 2009-12-06 13:43:42 +0100 | [diff] [blame] | 5799 | memmove(line + 1, line + 1 + skip, end - (line + skip)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5800 | end -= skip; |
| 5801 | } |
| 5802 | line++; |
| 5803 | } |
| 5804 | else if (*line == '#' || *line == '\n' || *line == '\r') { |
| 5805 | /* end of string, end of loop */ |
| 5806 | *line = 0; |
| 5807 | break; |
| 5808 | } |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 5809 | else if (isspace((unsigned char)*line)) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5810 | /* a non-escaped space is an argument separator */ |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5811 | *line++ = '\0'; |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 5812 | while (isspace((unsigned char)*line)) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5813 | line++; |
| 5814 | args[++arg] = line; |
| 5815 | } |
| 5816 | else { |
| 5817 | line++; |
| 5818 | } |
| 5819 | } |
| 5820 | |
| 5821 | /* empty line */ |
| 5822 | if (!**args) |
| 5823 | continue; |
| 5824 | |
Willy Tarreau | 7bb651e | 2009-11-09 21:16:53 +0100 | [diff] [blame] | 5825 | if (*line) { |
| 5826 | /* we had to stop due to too many args. |
| 5827 | * Let's terminate the string, print the offending part then cut the |
| 5828 | * last arg. |
| 5829 | */ |
| 5830 | while (*line && *line != '#' && *line != '\n' && *line != '\r') |
| 5831 | line++; |
| 5832 | *line = '\0'; |
| 5833 | |
Krzysztof Piotr Oledzki | 500b8f0 | 2009-12-15 22:34:51 +0100 | [diff] [blame] | 5834 | 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] | 5835 | file, linenum, arg + 1, (long)(args[arg] - thisline + 1), args[arg]); |
Willy Tarreau | 7bb651e | 2009-11-09 21:16:53 +0100 | [diff] [blame] | 5836 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5837 | args[arg] = line; |
| 5838 | } |
| 5839 | |
Willy Tarreau | 540abe4 | 2007-05-02 20:50:16 +0200 | [diff] [blame] | 5840 | /* zero out remaining args and ensure that at least one entry |
| 5841 | * is zeroed out. |
| 5842 | */ |
| 5843 | while (++arg <= MAX_LINE_ARGS) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5844 | args[arg] = line; |
| 5845 | } |
| 5846 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 5847 | /* check for keyword modifiers "no" and "default" */ |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5848 | if (!strcmp(args[0], "no")) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5849 | char *tmp; |
| 5850 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 5851 | kwm = KWM_NO; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5852 | tmp = args[0]; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5853 | for (arg=0; *args[arg+1]; arg++) |
| 5854 | args[arg] = args[arg+1]; // shift args after inversion |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5855 | *tmp = '\0'; // fix the next arg to \0 |
| 5856 | args[arg] = tmp; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5857 | } |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 5858 | else if (!strcmp(args[0], "default")) { |
| 5859 | kwm = KWM_DEF; |
| 5860 | for (arg=0; *args[arg+1]; arg++) |
| 5861 | args[arg] = args[arg+1]; // shift args after inversion |
| 5862 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5863 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5864 | if (kwm != KWM_STD && strcmp(args[0], "option") != 0 && \ |
| 5865 | strcmp(args[0], "log") != 0) { |
| 5866 | 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] | 5867 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5868 | } |
| 5869 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5870 | if (!strcmp(args[0], "listen") || |
| 5871 | !strcmp(args[0], "frontend") || |
| 5872 | !strcmp(args[0], "backend") || |
| 5873 | !strcmp(args[0], "ruleset") || |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5874 | !strcmp(args[0], "defaults")) { /* new proxy */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5875 | confsect = CFG_LISTEN; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 5876 | free(cursection); |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5877 | cursection = strdup(args[0]); |
| 5878 | } |
| 5879 | else if (!strcmp(args[0], "global")) { /* global config */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5880 | confsect = CFG_GLOBAL; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 5881 | free(cursection); |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5882 | cursection = strdup(args[0]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 5883 | } |
| 5884 | else if (!strcmp(args[0], "userlist")) { |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5885 | confsect = CFG_USERLIST; |
| 5886 | free(cursection); |
| 5887 | cursection = strdup(args[0]); |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5888 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 5889 | else if (!strcmp(args[0], "peers")) { |
| 5890 | confsect = CFG_PEERS; |
| 5891 | free(cursection); |
| 5892 | cursection = strdup(args[0]); |
| 5893 | } |
| 5894 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5895 | /* else it's a section keyword */ |
| 5896 | |
| 5897 | switch (confsect) { |
| 5898 | case CFG_LISTEN: |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5899 | err_code |= cfg_parse_listen(file, linenum, args, kwm); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5900 | break; |
| 5901 | case CFG_GLOBAL: |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5902 | err_code |= cfg_parse_global(file, linenum, args, kwm); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5903 | break; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5904 | case CFG_USERLIST: |
| 5905 | err_code |= cfg_parse_users(file, linenum, args, kwm); |
| 5906 | break; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 5907 | case CFG_PEERS: |
| 5908 | err_code |= cfg_parse_peers(file, linenum, args, kwm); |
| 5909 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5910 | default: |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5911 | 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] | 5912 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5913 | } |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5914 | |
| 5915 | if (err_code & ERR_ABORT) |
| 5916 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5917 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 5918 | free(cursection); |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5919 | cursection = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5920 | fclose(f); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5921 | return err_code; |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5922 | } |
| 5923 | |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 5924 | /* |
| 5925 | * Returns the error code, 0 if OK, or any combination of : |
| 5926 | * - ERR_ABORT: must abort ASAP |
| 5927 | * - ERR_FATAL: we can continue parsing but not start the service |
| 5928 | * - ERR_WARN: a warning has been emitted |
| 5929 | * - ERR_ALERT: an alert has been emitted |
| 5930 | * Only the two first ones can stop processing, the two others are just |
| 5931 | * indicators. |
| 5932 | */ |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5933 | int check_config_validity() |
| 5934 | { |
| 5935 | int cfgerr = 0; |
| 5936 | struct proxy *curproxy = NULL; |
| 5937 | struct server *newsrv = NULL; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5938 | struct userlist *curuserlist = NULL; |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 5939 | int err_code = 0; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 5940 | unsigned int next_pxid = 1; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 5941 | struct bind_conf *bind_conf; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5942 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 5943 | bind_conf = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5944 | /* |
| 5945 | * Now, check for the integrity of all that we have collected. |
| 5946 | */ |
| 5947 | |
| 5948 | /* will be needed further to delay some tasks */ |
Willy Tarreau | b0b37bc | 2008-06-23 14:00:57 +0200 | [diff] [blame] | 5949 | tv_update_date(0,1); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5950 | |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 5951 | if (!global.tune.max_http_hdr) |
| 5952 | global.tune.max_http_hdr = MAX_HTTP_HDR; |
| 5953 | |
| 5954 | if (!global.tune.cookie_len) |
| 5955 | global.tune.cookie_len = CAPTURE_LEN; |
| 5956 | |
| 5957 | pool2_capture = create_pool("capture", global.tune.cookie_len, MEM_F_SHARED); |
| 5958 | |
Willy Tarreau | 55bc0f8 | 2009-03-15 14:51:53 +0100 | [diff] [blame] | 5959 | /* first, we will invert the proxy list order */ |
| 5960 | curproxy = NULL; |
| 5961 | while (proxy) { |
| 5962 | struct proxy *next; |
| 5963 | |
| 5964 | next = proxy->next; |
| 5965 | proxy->next = curproxy; |
| 5966 | curproxy = proxy; |
| 5967 | if (!next) |
| 5968 | break; |
| 5969 | proxy = next; |
| 5970 | } |
| 5971 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5972 | while (curproxy != NULL) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 5973 | struct switching_rule *rule; |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 5974 | struct server_rule *srule; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5975 | struct sticking_rule *mrule; |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 5976 | struct tcp_rule *trule; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 5977 | struct listener *listener; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 5978 | unsigned int next_id; |
Willy Tarreau | 16a2147 | 2012-11-19 12:39:59 +0100 | [diff] [blame] | 5979 | int nbproc; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 5980 | |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 5981 | if (curproxy->uuid < 0) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 5982 | /* proxy ID not set, use automatic numbering with first |
| 5983 | * spare entry starting with next_pxid. |
| 5984 | */ |
| 5985 | next_pxid = get_next_id(&used_proxy_id, next_pxid); |
| 5986 | curproxy->conf.id.key = curproxy->uuid = next_pxid; |
| 5987 | eb32_insert(&used_proxy_id, &curproxy->conf.id); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 5988 | } |
Krzysztof Piotr Oledzki | df5cb9f | 2010-02-05 20:58:27 +0100 | [diff] [blame] | 5989 | next_pxid++; |
| 5990 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 5991 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5992 | if (curproxy->state == PR_STSTOPPED) { |
Willy Tarreau | da250db | 2008-10-12 12:07:48 +0200 | [diff] [blame] | 5993 | /* ensure we don't keep listeners uselessly bound */ |
| 5994 | stop_proxy(curproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5995 | curproxy = curproxy->next; |
| 5996 | continue; |
| 5997 | } |
| 5998 | |
Willy Tarreau | 16a2147 | 2012-11-19 12:39:59 +0100 | [diff] [blame] | 5999 | /* number of processes this proxy is bound to */ |
| 6000 | nbproc = curproxy->bind_proc ? popcount(curproxy->bind_proc) : global.nbproc; |
| 6001 | |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 6002 | switch (curproxy->mode) { |
| 6003 | case PR_MODE_HEALTH: |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6004 | cfgerr += proxy_cfg_ensure_no_http(curproxy); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 6005 | if (!(curproxy->cap & PR_CAP_FE)) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6006 | Alert("config : %s '%s' cannot be in health mode as it has no frontend capability.\n", |
| 6007 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 6008 | cfgerr++; |
| 6009 | } |
| 6010 | |
| 6011 | if (curproxy->srv != NULL) |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6012 | Warning("config : servers will be ignored for %s '%s'.\n", |
| 6013 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 6014 | break; |
| 6015 | |
| 6016 | case PR_MODE_TCP: |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6017 | cfgerr += proxy_cfg_ensure_no_http(curproxy); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 6018 | break; |
| 6019 | |
| 6020 | case PR_MODE_HTTP: |
Willy Tarreau | a9fb083 | 2009-07-10 20:53:53 +0200 | [diff] [blame] | 6021 | curproxy->acl_requires |= ACL_USE_L7_ANY; |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 6022 | break; |
| 6023 | } |
| 6024 | |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 6025 | if ((curproxy->cap & PR_CAP_BE) && (curproxy->mode != PR_MODE_HEALTH)) { |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6026 | if (curproxy->lbprm.algo & BE_LB_KIND) { |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 6027 | if (curproxy->options & PR_O_TRANSP) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6028 | Alert("config : %s '%s' cannot use both transparent and balance mode.\n", |
| 6029 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 6030 | cfgerr++; |
| 6031 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6032 | #ifdef WE_DONT_SUPPORT_SERVERLESS_LISTENERS |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 6033 | else if (curproxy->srv == NULL) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6034 | Alert("config : %s '%s' needs at least 1 server in balance mode.\n", |
| 6035 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 6036 | cfgerr++; |
| 6037 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6038 | #endif |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 6039 | else if (curproxy->options & PR_O_DISPATCH) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6040 | Warning("config : dispatch address of %s '%s' will be ignored in balance mode.\n", |
| 6041 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6042 | err_code |= ERR_WARN; |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 6043 | } |
| 6044 | } |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 6045 | 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] | 6046 | /* If no LB algo is set in a backend, and we're not in |
| 6047 | * transparent mode, dispatch mode nor proxy mode, we |
| 6048 | * want to use balance roundrobin by default. |
| 6049 | */ |
| 6050 | curproxy->lbprm.algo &= ~BE_LB_ALGO; |
| 6051 | curproxy->lbprm.algo |= BE_LB_ALGO_RR; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6052 | } |
| 6053 | } |
Willy Tarreau | 193cf93 | 2007-09-17 10:17:23 +0200 | [diff] [blame] | 6054 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 6055 | if (curproxy->options & PR_O_DISPATCH) |
| 6056 | curproxy->options &= ~(PR_O_TRANSP | PR_O_HTTP_PROXY); |
| 6057 | else if (curproxy->options & PR_O_HTTP_PROXY) |
| 6058 | curproxy->options &= ~(PR_O_DISPATCH | PR_O_TRANSP); |
| 6059 | else if (curproxy->options & PR_O_TRANSP) |
| 6060 | curproxy->options &= ~(PR_O_DISPATCH | PR_O_HTTP_PROXY); |
Willy Tarreau | 8293658 | 2007-11-30 15:20:09 +0100 | [diff] [blame] | 6061 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 6062 | if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_HTTP_CHK) { |
| 6063 | if (curproxy->options & PR_O_DISABLE404) { |
| 6064 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n", |
| 6065 | "disable-on-404", proxy_type_str(curproxy), curproxy->id); |
| 6066 | err_code |= ERR_WARN; |
| 6067 | curproxy->options &= ~PR_O_DISABLE404; |
| 6068 | } |
| 6069 | if (curproxy->options2 & PR_O2_CHK_SNDST) { |
| 6070 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n", |
| 6071 | "send-state", proxy_type_str(curproxy), curproxy->id); |
| 6072 | err_code |= ERR_WARN; |
| 6073 | curproxy->options &= ~PR_O2_CHK_SNDST; |
| 6074 | } |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 6075 | } |
| 6076 | |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 6077 | /* if a default backend was specified, let's find it */ |
| 6078 | if (curproxy->defbe.name) { |
| 6079 | struct proxy *target; |
| 6080 | |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 6081 | target = findproxy_mode(curproxy->defbe.name, curproxy->mode, PR_CAP_BE); |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6082 | if (!target) { |
| 6083 | Alert("Proxy '%s': unable to find required default_backend: '%s'.\n", |
| 6084 | curproxy->id, curproxy->defbe.name); |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 6085 | cfgerr++; |
| 6086 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6087 | Alert("Proxy '%s': loop detected for default_backend: '%s'.\n", |
| 6088 | curproxy->id, curproxy->defbe.name); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6089 | cfgerr++; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 6090 | } else { |
| 6091 | free(curproxy->defbe.name); |
| 6092 | curproxy->defbe.be = target; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 6093 | /* we force the backend to be present on at least all of |
| 6094 | * the frontend's processes. |
| 6095 | */ |
| 6096 | target->bind_proc = curproxy->bind_proc ? |
| 6097 | (target->bind_proc | curproxy->bind_proc) : 0; |
Willy Tarreau | ff67813 | 2012-02-13 14:32:34 +0100 | [diff] [blame] | 6098 | |
| 6099 | /* Emit a warning if this proxy also has some servers */ |
| 6100 | if (curproxy->srv) { |
| 6101 | Warning("In proxy '%s', the 'default_backend' rule always has precedence over the servers, which will never be used.\n", |
| 6102 | curproxy->id); |
| 6103 | err_code |= ERR_WARN; |
| 6104 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6105 | } |
| 6106 | } |
| 6107 | |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 6108 | /* find the target proxy in setbe */ |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 6109 | if (curproxy->mode == PR_MODE_HTTP && curproxy->req_exp != NULL) { |
| 6110 | /* map jump target for ACT_SETBE in req_rep chain */ |
| 6111 | struct hdr_exp *exp; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 6112 | for (exp = curproxy->req_exp; exp != NULL; exp = exp->next) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6113 | struct proxy *target; |
| 6114 | |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 6115 | if (exp->action != ACT_SETBE) |
| 6116 | continue; |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6117 | |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 6118 | target = findproxy_mode(exp->replace, PR_MODE_HTTP, PR_CAP_BE); |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6119 | if (!target) { |
| 6120 | Alert("Proxy '%s': unable to find required setbe: '%s'.\n", |
| 6121 | curproxy->id, exp->replace); |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 6122 | cfgerr++; |
| 6123 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6124 | Alert("Proxy '%s': loop detected for setbe: '%s'.\n", |
| 6125 | curproxy->id, exp->replace); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 6126 | cfgerr++; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 6127 | } else { |
| 6128 | free((void *)exp->replace); |
| 6129 | exp->replace = (const char *)target; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 6130 | /* we force the backend to be present on at least all of |
| 6131 | * the frontend's processes. |
| 6132 | */ |
| 6133 | target->bind_proc = curproxy->bind_proc ? |
| 6134 | (target->bind_proc | curproxy->bind_proc) : 0; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 6135 | } |
| 6136 | } |
| 6137 | } |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6138 | |
| 6139 | /* find the target proxy for 'use_backend' rules */ |
| 6140 | list_for_each_entry(rule, &curproxy->switching_rules, list) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6141 | struct proxy *target; |
| 6142 | |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 6143 | target = findproxy_mode(rule->be.name, curproxy->mode, PR_CAP_BE); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6144 | |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6145 | if (!target) { |
| 6146 | Alert("Proxy '%s': unable to find required use_backend: '%s'.\n", |
| 6147 | curproxy->id, rule->be.name); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6148 | cfgerr++; |
| 6149 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6150 | Alert("Proxy '%s': loop detected for use_backend: '%s'.\n", |
| 6151 | curproxy->id, rule->be.name); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6152 | cfgerr++; |
| 6153 | } else { |
| 6154 | free((void *)rule->be.name); |
| 6155 | rule->be.backend = target; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 6156 | /* we force the backend to be present on at least all of |
| 6157 | * the frontend's processes. |
| 6158 | */ |
| 6159 | target->bind_proc = curproxy->bind_proc ? |
| 6160 | (target->bind_proc | curproxy->bind_proc) : 0; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6161 | } |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 6162 | } |
| 6163 | |
| 6164 | /* find the target proxy for 'use_backend' rules */ |
| 6165 | list_for_each_entry(srule, &curproxy->server_rules, list) { |
| 6166 | struct server *target = findserver(curproxy, srule->srv.name); |
| 6167 | |
| 6168 | if (!target) { |
| 6169 | Alert("config : %s '%s' : unable to find server '%s' referenced in a 'use-server' rule.\n", |
| 6170 | proxy_type_str(curproxy), curproxy->id, srule->srv.name); |
| 6171 | cfgerr++; |
| 6172 | continue; |
| 6173 | } |
| 6174 | free((void *)srule->srv.name); |
| 6175 | srule->srv.ptr = target; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6176 | } |
| 6177 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6178 | /* find the target table for 'stick' rules */ |
| 6179 | list_for_each_entry(mrule, &curproxy->sticking_rules, list) { |
| 6180 | struct proxy *target; |
| 6181 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 6182 | curproxy->be_req_ana |= AN_REQ_STICKING_RULES; |
| 6183 | if (mrule->flags & STK_IS_STORE) |
| 6184 | curproxy->be_rsp_ana |= AN_RES_STORE_RULES; |
| 6185 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6186 | if (mrule->table.name) |
Willy Tarreau | c00cdc2 | 2010-06-06 16:48:26 +0200 | [diff] [blame] | 6187 | target = findproxy(mrule->table.name, 0); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6188 | else |
| 6189 | target = curproxy; |
| 6190 | |
| 6191 | if (!target) { |
| 6192 | Alert("Proxy '%s': unable to find stick-table '%s'.\n", |
| 6193 | curproxy->id, mrule->table.name); |
| 6194 | cfgerr++; |
| 6195 | } |
| 6196 | else if (target->table.size == 0) { |
| 6197 | Alert("Proxy '%s': stick-table '%s' used but not configured.\n", |
| 6198 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 6199 | cfgerr++; |
| 6200 | } |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 6201 | else if (!stktable_compatible_sample(mrule->expr, target->table.type)) { |
| 6202 | 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] | 6203 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 6204 | cfgerr++; |
| 6205 | } |
| 6206 | else { |
| 6207 | free((void *)mrule->table.name); |
| 6208 | mrule->table.t = &(target->table); |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 6209 | stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID, NULL); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6210 | } |
| 6211 | } |
| 6212 | |
| 6213 | /* find the target table for 'store response' rules */ |
| 6214 | list_for_each_entry(mrule, &curproxy->storersp_rules, list) { |
| 6215 | struct proxy *target; |
| 6216 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 6217 | curproxy->be_rsp_ana |= AN_RES_STORE_RULES; |
| 6218 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6219 | if (mrule->table.name) |
Willy Tarreau | c00cdc2 | 2010-06-06 16:48:26 +0200 | [diff] [blame] | 6220 | target = findproxy(mrule->table.name, 0); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6221 | else |
| 6222 | target = curproxy; |
| 6223 | |
| 6224 | if (!target) { |
| 6225 | Alert("Proxy '%s': unable to find store table '%s'.\n", |
| 6226 | curproxy->id, mrule->table.name); |
| 6227 | cfgerr++; |
| 6228 | } |
| 6229 | else if (target->table.size == 0) { |
| 6230 | Alert("Proxy '%s': stick-table '%s' used but not configured.\n", |
| 6231 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 6232 | cfgerr++; |
| 6233 | } |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 6234 | else if (!stktable_compatible_sample(mrule->expr, target->table.type)) { |
| 6235 | 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] | 6236 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 6237 | cfgerr++; |
| 6238 | } |
| 6239 | else { |
| 6240 | free((void *)mrule->table.name); |
| 6241 | mrule->table.t = &(target->table); |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 6242 | stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID, NULL); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6243 | } |
| 6244 | } |
| 6245 | |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 6246 | /* find the target table for 'tcp-request' layer 4 rules */ |
| 6247 | list_for_each_entry(trule, &curproxy->tcp_req.l4_rules, list) { |
| 6248 | struct proxy *target; |
| 6249 | |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6250 | 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] | 6251 | continue; |
| 6252 | |
| 6253 | if (trule->act_prm.trk_ctr.table.n) |
| 6254 | target = findproxy(trule->act_prm.trk_ctr.table.n, 0); |
| 6255 | else |
| 6256 | target = curproxy; |
| 6257 | |
| 6258 | if (!target) { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6259 | Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n", |
| 6260 | curproxy->id, trule->act_prm.trk_ctr.table.n, |
| 6261 | trule->action == TCP_ACT_TRK_SC1 ? 1 : 2); |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 6262 | cfgerr++; |
| 6263 | } |
| 6264 | else if (target->table.size == 0) { |
| 6265 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
| 6266 | curproxy->id, trule->act_prm.trk_ctr.table.n ? trule->act_prm.trk_ctr.table.n : curproxy->id); |
| 6267 | cfgerr++; |
| 6268 | } |
| 6269 | else if (trule->act_prm.trk_ctr.type != target->table.type) { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6270 | Alert("Proxy '%s': type of tracking key for sticky counter not usable with type of stick-table '%s'.\n", |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 6271 | curproxy->id, trule->act_prm.trk_ctr.table.n ? trule->act_prm.trk_ctr.table.n : curproxy->id); |
| 6272 | cfgerr++; |
| 6273 | } |
| 6274 | else { |
| 6275 | free(trule->act_prm.trk_ctr.table.n); |
| 6276 | trule->act_prm.trk_ctr.table.t = &target->table; |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6277 | /* 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] | 6278 | * to pass a list of counters to track and allocate them right here using |
| 6279 | * stktable_alloc_data_type(). |
| 6280 | */ |
| 6281 | } |
| 6282 | } |
| 6283 | |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 6284 | /* find the target table for 'tcp-request' layer 6 rules */ |
| 6285 | list_for_each_entry(trule, &curproxy->tcp_req.inspect_rules, list) { |
| 6286 | struct proxy *target; |
| 6287 | |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6288 | 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] | 6289 | continue; |
| 6290 | |
| 6291 | if (trule->act_prm.trk_ctr.table.n) |
| 6292 | target = findproxy(trule->act_prm.trk_ctr.table.n, 0); |
| 6293 | else |
| 6294 | target = curproxy; |
| 6295 | |
| 6296 | if (!target) { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6297 | Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n", |
| 6298 | curproxy->id, trule->act_prm.trk_ctr.table.n, |
| 6299 | trule->action == TCP_ACT_TRK_SC1 ? 1 : 2); |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 6300 | cfgerr++; |
| 6301 | } |
| 6302 | else if (target->table.size == 0) { |
| 6303 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
| 6304 | curproxy->id, trule->act_prm.trk_ctr.table.n ? trule->act_prm.trk_ctr.table.n : curproxy->id); |
| 6305 | cfgerr++; |
| 6306 | } |
| 6307 | else if (trule->act_prm.trk_ctr.type != target->table.type) { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6308 | Alert("Proxy '%s': type of tracking key for sticky counter not usable with type of stick-table '%s'.\n", |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 6309 | curproxy->id, trule->act_prm.trk_ctr.table.n ? trule->act_prm.trk_ctr.table.n : curproxy->id); |
| 6310 | cfgerr++; |
| 6311 | } |
| 6312 | else { |
| 6313 | free(trule->act_prm.trk_ctr.table.n); |
| 6314 | trule->act_prm.trk_ctr.table.t = &target->table; |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6315 | /* 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] | 6316 | * to pass a list of counters to track and allocate them right here using |
| 6317 | * stktable_alloc_data_type(). |
| 6318 | */ |
| 6319 | } |
| 6320 | } |
| 6321 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 6322 | if (curproxy->table.peers.name) { |
| 6323 | struct peers *curpeers = peers; |
| 6324 | |
| 6325 | for (curpeers = peers; curpeers; curpeers = curpeers->next) { |
| 6326 | if (strcmp(curpeers->id, curproxy->table.peers.name) == 0) { |
| 6327 | free((void *)curproxy->table.peers.name); |
| 6328 | curproxy->table.peers.p = peers; |
| 6329 | break; |
| 6330 | } |
| 6331 | } |
| 6332 | |
| 6333 | if (!curpeers) { |
| 6334 | Alert("Proxy '%s': unable to find sync peers '%s'.\n", |
| 6335 | curproxy->id, curproxy->table.peers.name); |
Willy Tarreau | d66bf96 | 2011-10-28 14:16:49 +0200 | [diff] [blame] | 6336 | free((void *)curproxy->table.peers.name); |
| 6337 | curproxy->table.peers.p = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 6338 | cfgerr++; |
| 6339 | } |
| 6340 | else if (!curpeers->peers_fe) { |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 6341 | Alert("Proxy '%s': unable to find local peer '%s' in peers section '%s'.\n", |
| 6342 | curproxy->id, localpeer, curpeers->id); |
Willy Tarreau | d66bf96 | 2011-10-28 14:16:49 +0200 | [diff] [blame] | 6343 | curproxy->table.peers.p = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 6344 | cfgerr++; |
| 6345 | } |
| 6346 | } |
| 6347 | |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 6348 | if (curproxy->uri_auth && !(curproxy->uri_auth->flags & ST_CONVDONE) && |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 6349 | !LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) && |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6350 | (curproxy->uri_auth->userlist || curproxy->uri_auth->auth_realm )) { |
| 6351 | Alert("%s '%s': stats 'auth'/'realm' and 'http-request' can't be used at the same time.\n", |
| 6352 | "proxy", curproxy->id); |
| 6353 | cfgerr++; |
| 6354 | goto out_uri_auth_compat; |
| 6355 | } |
| 6356 | |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 6357 | 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] | 6358 | const char *uri_auth_compat_req[10]; |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 6359 | struct http_req_rule *rule; |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6360 | int i = 0; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6361 | |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6362 | /* build the ACL condition from scratch. We're relying on anonymous ACLs for that */ |
| 6363 | uri_auth_compat_req[i++] = "auth"; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6364 | |
| 6365 | if (curproxy->uri_auth->auth_realm) { |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6366 | uri_auth_compat_req[i++] = "realm"; |
| 6367 | uri_auth_compat_req[i++] = curproxy->uri_auth->auth_realm; |
| 6368 | } |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6369 | |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6370 | uri_auth_compat_req[i++] = "unless"; |
| 6371 | uri_auth_compat_req[i++] = "{"; |
| 6372 | uri_auth_compat_req[i++] = "http_auth(.internal-stats-userlist)"; |
| 6373 | uri_auth_compat_req[i++] = "}"; |
| 6374 | uri_auth_compat_req[i++] = ""; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6375 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 6376 | rule = parse_http_req_cond(uri_auth_compat_req, "internal-stats-auth-compat", 0, curproxy); |
| 6377 | if (!rule) { |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6378 | cfgerr++; |
| 6379 | break; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6380 | } |
| 6381 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 6382 | LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list); |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6383 | |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6384 | if (curproxy->uri_auth->auth_realm) { |
| 6385 | free(curproxy->uri_auth->auth_realm); |
| 6386 | curproxy->uri_auth->auth_realm = NULL; |
| 6387 | } |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 6388 | |
| 6389 | curproxy->uri_auth->flags |= ST_CONVDONE; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6390 | } |
| 6391 | out_uri_auth_compat: |
| 6392 | |
Krzysztof Piotr Oledzki | f9423ae | 2010-01-29 19:26:18 +0100 | [diff] [blame] | 6393 | cfgerr += acl_find_targets(curproxy); |
| 6394 | |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 6395 | if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) && |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6396 | (((curproxy->cap & PR_CAP_FE) && !curproxy->timeout.client) || |
Willy Tarreau | d825eef | 2007-05-12 22:35:00 +0200 | [diff] [blame] | 6397 | ((curproxy->cap & PR_CAP_BE) && (curproxy->srv) && |
Willy Tarreau | ce887fd | 2012-05-12 12:50:00 +0200 | [diff] [blame] | 6398 | (!curproxy->timeout.connect || |
| 6399 | (!curproxy->timeout.server && (curproxy->mode == PR_MODE_HTTP || !curproxy->timeout.tunnel)))))) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6400 | Warning("config : missing timeouts for %s '%s'.\n" |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 6401 | " | While not properly invalid, you will certainly encounter various problems\n" |
| 6402 | " | 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] | 6403 | " | timeouts are set to a non-zero value: 'client', 'connect', 'server'.\n", |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6404 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6405 | err_code |= ERR_WARN; |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 6406 | } |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 6407 | |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6408 | /* Historically, the tarpit and queue timeouts were inherited from contimeout. |
| 6409 | * We must still support older configurations, so let's find out whether those |
| 6410 | * parameters have been set or must be copied from contimeouts. |
| 6411 | */ |
| 6412 | if (curproxy != &defproxy) { |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6413 | if (!curproxy->timeout.tarpit || |
| 6414 | curproxy->timeout.tarpit == defproxy.timeout.tarpit) { |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6415 | /* tarpit timeout not set. We search in the following order: |
| 6416 | * default.tarpit, curr.connect, default.connect. |
| 6417 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6418 | if (defproxy.timeout.tarpit) |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6419 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6420 | else if (curproxy->timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6421 | curproxy->timeout.tarpit = curproxy->timeout.connect; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6422 | else if (defproxy.timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6423 | curproxy->timeout.tarpit = defproxy.timeout.connect; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6424 | } |
| 6425 | if ((curproxy->cap & PR_CAP_BE) && |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6426 | (!curproxy->timeout.queue || |
| 6427 | curproxy->timeout.queue == defproxy.timeout.queue)) { |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6428 | /* queue timeout not set. We search in the following order: |
| 6429 | * default.queue, curr.connect, default.connect. |
| 6430 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6431 | if (defproxy.timeout.queue) |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6432 | curproxy->timeout.queue = defproxy.timeout.queue; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6433 | else if (curproxy->timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6434 | curproxy->timeout.queue = curproxy->timeout.connect; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6435 | else if (defproxy.timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6436 | curproxy->timeout.queue = defproxy.timeout.connect; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6437 | } |
| 6438 | } |
| 6439 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 6440 | if ((curproxy->options2 & PR_O2_CHK_ANY) == PR_O2_SSL3_CHK) { |
Willy Tarreau | 137325d | 2010-02-01 16:38:17 +0100 | [diff] [blame] | 6441 | curproxy->check_len = sizeof(sslv3_client_hello_pkt) - 1; |
| 6442 | curproxy->check_req = (char *)malloc(curproxy->check_len); |
| 6443 | memcpy(curproxy->check_req, sslv3_client_hello_pkt, curproxy->check_len); |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 6444 | } |
| 6445 | |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 6446 | /* ensure that cookie capture length is not too large */ |
| 6447 | if (curproxy->capture_len >= global.tune.cookie_len) { |
| 6448 | Warning("config : truncating capture length to %d bytes for %s '%s'.\n", |
| 6449 | global.tune.cookie_len - 1, proxy_type_str(curproxy), curproxy->id); |
| 6450 | err_code |= ERR_WARN; |
| 6451 | curproxy->capture_len = global.tune.cookie_len - 1; |
| 6452 | } |
| 6453 | |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 6454 | /* The small pools required for the capture lists */ |
Willy Tarreau | 9a54e13 | 2012-03-24 08:33:05 +0100 | [diff] [blame] | 6455 | if (curproxy->nb_req_cap) { |
| 6456 | if (curproxy->mode == PR_MODE_HTTP) { |
| 6457 | curproxy->req_cap_pool = create_pool("ptrcap", |
| 6458 | curproxy->nb_req_cap * sizeof(char *), |
| 6459 | MEM_F_SHARED); |
| 6460 | } else { |
| 6461 | Warning("config : 'capture request header' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6462 | proxy_type_str(curproxy), curproxy->id); |
| 6463 | err_code |= ERR_WARN; |
| 6464 | curproxy->to_log &= ~LW_REQHDR; |
| 6465 | curproxy->nb_req_cap = 0; |
| 6466 | } |
| 6467 | } |
| 6468 | |
| 6469 | if (curproxy->nb_rsp_cap) { |
| 6470 | if (curproxy->mode == PR_MODE_HTTP) { |
| 6471 | curproxy->rsp_cap_pool = create_pool("ptrcap", |
| 6472 | curproxy->nb_rsp_cap * sizeof(char *), |
| 6473 | MEM_F_SHARED); |
| 6474 | } else { |
| 6475 | Warning("config : 'capture response header' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6476 | proxy_type_str(curproxy), curproxy->id); |
| 6477 | err_code |= ERR_WARN; |
| 6478 | curproxy->to_log &= ~LW_REQHDR; |
| 6479 | curproxy->nb_rsp_cap = 0; |
| 6480 | } |
| 6481 | } |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 6482 | |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 6483 | /* compile the log format */ |
Willy Tarreau | 99a7ca2 | 2012-05-31 19:39:23 +0200 | [diff] [blame] | 6484 | if (!(curproxy->cap & PR_CAP_FE)) { |
| 6485 | if (curproxy->logformat_string != default_http_log_format && |
| 6486 | curproxy->logformat_string != default_tcp_log_format && |
| 6487 | curproxy->logformat_string != clf_http_log_format) |
| 6488 | free(curproxy->logformat_string); |
| 6489 | curproxy->logformat_string = NULL; |
| 6490 | } |
| 6491 | |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 6492 | if (curproxy->logformat_string) |
| 6493 | parse_logformat_string(curproxy->logformat_string, curproxy, &curproxy->logformat, curproxy->mode); |
| 6494 | |
| 6495 | if (curproxy->uniqueid_format_string) |
| 6496 | parse_logformat_string(curproxy->uniqueid_format_string, curproxy, &curproxy->format_unique_id, PR_MODE_HTTP); |
| 6497 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6498 | /* first, we will invert the servers list order */ |
| 6499 | newsrv = NULL; |
| 6500 | while (curproxy->srv) { |
| 6501 | struct server *next; |
| 6502 | |
| 6503 | next = curproxy->srv->next; |
| 6504 | curproxy->srv->next = newsrv; |
| 6505 | newsrv = curproxy->srv; |
| 6506 | if (!next) |
| 6507 | break; |
| 6508 | curproxy->srv = next; |
| 6509 | } |
| 6510 | |
Willy Tarreau | dd70165 | 2010-05-25 23:03:02 +0200 | [diff] [blame] | 6511 | /* assign automatic UIDs to servers which don't have one yet */ |
| 6512 | next_id = 1; |
| 6513 | newsrv = curproxy->srv; |
| 6514 | while (newsrv != NULL) { |
| 6515 | if (!newsrv->puid) { |
| 6516 | /* server ID not set, use automatic numbering with first |
| 6517 | * spare entry starting with next_svid. |
| 6518 | */ |
| 6519 | next_id = get_next_id(&curproxy->conf.used_server_id, next_id); |
| 6520 | newsrv->conf.id.key = newsrv->puid = next_id; |
| 6521 | eb32_insert(&curproxy->conf.used_server_id, &newsrv->conf.id); |
| 6522 | } |
| 6523 | next_id++; |
| 6524 | newsrv = newsrv->next; |
| 6525 | } |
| 6526 | |
Willy Tarreau | 2069704 | 2007-11-15 23:26:18 +0100 | [diff] [blame] | 6527 | curproxy->lbprm.wmult = 1; /* default weight multiplier */ |
Willy Tarreau | 5dc2fa6 | 2007-11-19 19:10:18 +0100 | [diff] [blame] | 6528 | curproxy->lbprm.wdiv = 1; /* default weight divider */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6529 | |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 6530 | /* |
| 6531 | * If this server supports a maxconn parameter, it needs a dedicated |
| 6532 | * tasks to fill the emptied slots when a connection leaves. |
| 6533 | * Also, resolve deferred tracking dependency if needed. |
| 6534 | */ |
| 6535 | newsrv = curproxy->srv; |
| 6536 | while (newsrv != NULL) { |
| 6537 | if (newsrv->minconn > newsrv->maxconn) { |
| 6538 | /* Only 'minconn' was specified, or it was higher than or equal |
| 6539 | * to 'maxconn'. Let's turn this into maxconn and clean it, as |
| 6540 | * this will avoid further useless expensive computations. |
| 6541 | */ |
| 6542 | newsrv->maxconn = newsrv->minconn; |
| 6543 | } else if (newsrv->maxconn && !newsrv->minconn) { |
| 6544 | /* minconn was not specified, so we set it to maxconn */ |
| 6545 | newsrv->minconn = newsrv->maxconn; |
| 6546 | } |
| 6547 | |
Emeric Brun | 01f8e2f | 2012-05-18 16:02:00 +0200 | [diff] [blame] | 6548 | #ifdef USE_OPENSSL |
Emeric Brun | 94324a4 | 2012-10-11 14:00:19 +0200 | [diff] [blame] | 6549 | if (newsrv->use_ssl || newsrv->check.use_ssl) |
| 6550 | cfgerr += ssl_sock_prepare_srv_ctx(newsrv, curproxy); |
Emeric Brun | 01f8e2f | 2012-05-18 16:02:00 +0200 | [diff] [blame] | 6551 | #endif /* USE_OPENSSL */ |
Emeric Brun | 94324a4 | 2012-10-11 14:00:19 +0200 | [diff] [blame] | 6552 | |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 6553 | if (newsrv->trackit) { |
| 6554 | struct proxy *px; |
| 6555 | struct server *srv; |
| 6556 | char *pname, *sname; |
| 6557 | |
| 6558 | pname = newsrv->trackit; |
| 6559 | sname = strrchr(pname, '/'); |
| 6560 | |
| 6561 | if (sname) |
| 6562 | *sname++ = '\0'; |
| 6563 | else { |
| 6564 | sname = pname; |
| 6565 | pname = NULL; |
| 6566 | } |
| 6567 | |
| 6568 | if (pname) { |
| 6569 | px = findproxy(pname, PR_CAP_BE); |
| 6570 | if (!px) { |
| 6571 | Alert("config : %s '%s', server '%s': unable to find required proxy '%s' for tracking.\n", |
| 6572 | proxy_type_str(curproxy), curproxy->id, |
| 6573 | newsrv->id, pname); |
| 6574 | cfgerr++; |
| 6575 | goto next_srv; |
| 6576 | } |
| 6577 | } else |
| 6578 | px = curproxy; |
| 6579 | |
| 6580 | srv = findserver(px, sname); |
| 6581 | if (!srv) { |
| 6582 | Alert("config : %s '%s', server '%s': unable to find required server '%s' for tracking.\n", |
| 6583 | proxy_type_str(curproxy), curproxy->id, |
| 6584 | newsrv->id, sname); |
| 6585 | cfgerr++; |
| 6586 | goto next_srv; |
| 6587 | } |
| 6588 | |
| 6589 | if (!(srv->state & SRV_CHECKED)) { |
| 6590 | Alert("config : %s '%s', server '%s': unable to use %s/%s for " |
| 6591 | "tracking as it does not have checks enabled.\n", |
| 6592 | proxy_type_str(curproxy), curproxy->id, |
| 6593 | newsrv->id, px->id, srv->id); |
| 6594 | cfgerr++; |
| 6595 | goto next_srv; |
| 6596 | } |
| 6597 | |
| 6598 | if (curproxy != px && |
| 6599 | (curproxy->options & PR_O_DISABLE404) != (px->options & PR_O_DISABLE404)) { |
| 6600 | Alert("config : %s '%s', server '%s': unable to use %s/%s for" |
| 6601 | "tracking: disable-on-404 option inconsistency.\n", |
| 6602 | proxy_type_str(curproxy), curproxy->id, |
| 6603 | newsrv->id, px->id, srv->id); |
| 6604 | cfgerr++; |
| 6605 | goto next_srv; |
| 6606 | } |
| 6607 | |
| 6608 | /* if the other server is forced disabled, we have to do the same here */ |
| 6609 | if (srv->state & SRV_MAINTAIN) { |
| 6610 | newsrv->state |= SRV_MAINTAIN; |
| 6611 | newsrv->state &= ~SRV_RUNNING; |
| 6612 | newsrv->health = 0; |
| 6613 | } |
| 6614 | |
| 6615 | newsrv->track = srv; |
| 6616 | newsrv->tracknext = srv->tracknext; |
| 6617 | srv->tracknext = newsrv; |
| 6618 | |
| 6619 | free(newsrv->trackit); |
| 6620 | newsrv->trackit = NULL; |
| 6621 | } |
| 6622 | next_srv: |
| 6623 | newsrv = newsrv->next; |
| 6624 | } |
| 6625 | |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6626 | /* We have to initialize the server lookup mechanism depending |
| 6627 | * on what LB algorithm was choosen. |
| 6628 | */ |
| 6629 | |
| 6630 | curproxy->lbprm.algo &= ~(BE_LB_LKUP | BE_LB_PROP_DYN); |
| 6631 | switch (curproxy->lbprm.algo & BE_LB_KIND) { |
| 6632 | case BE_LB_KIND_RR: |
Willy Tarreau | 9757a38 | 2009-10-03 12:56:50 +0200 | [diff] [blame] | 6633 | if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_RR_STATIC) { |
| 6634 | curproxy->lbprm.algo |= BE_LB_LKUP_MAP; |
| 6635 | init_server_map(curproxy); |
| 6636 | } else { |
| 6637 | curproxy->lbprm.algo |= BE_LB_LKUP_RRTREE | BE_LB_PROP_DYN; |
| 6638 | fwrr_init_server_groups(curproxy); |
| 6639 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6640 | break; |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 6641 | |
Willy Tarreau | 3ebb116 | 2012-02-13 16:57:44 +0100 | [diff] [blame] | 6642 | case BE_LB_KIND_CB: |
Willy Tarreau | f09c660 | 2012-02-13 17:12:08 +0100 | [diff] [blame] | 6643 | if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_CB_LC) { |
| 6644 | curproxy->lbprm.algo |= BE_LB_LKUP_LCTREE | BE_LB_PROP_DYN; |
| 6645 | fwlc_init_server_tree(curproxy); |
| 6646 | } else { |
| 6647 | curproxy->lbprm.algo |= BE_LB_LKUP_FSTREE | BE_LB_PROP_DYN; |
| 6648 | fas_init_server_tree(curproxy); |
| 6649 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6650 | break; |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 6651 | |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6652 | case BE_LB_KIND_HI: |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 6653 | if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS) { |
| 6654 | curproxy->lbprm.algo |= BE_LB_LKUP_CHTREE | BE_LB_PROP_DYN; |
| 6655 | chash_init_server_tree(curproxy); |
| 6656 | } else { |
| 6657 | curproxy->lbprm.algo |= BE_LB_LKUP_MAP; |
| 6658 | init_server_map(curproxy); |
| 6659 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6660 | break; |
| 6661 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6662 | |
| 6663 | if (curproxy->options & PR_O_LOGASAP) |
| 6664 | curproxy->to_log &= ~LW_BYTES; |
| 6665 | |
Willy Tarreau | e7ded1f | 2009-08-09 10:11:45 +0200 | [diff] [blame] | 6666 | if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) && |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6667 | (curproxy->cap & PR_CAP_FE) && curproxy->to_log && LIST_ISEMPTY(&curproxy->logsrvs)) { |
Willy Tarreau | e7ded1f | 2009-08-09 10:11:45 +0200 | [diff] [blame] | 6668 | Warning("config : log format ignored for %s '%s' since it has no log address.\n", |
| 6669 | proxy_type_str(curproxy), curproxy->id); |
| 6670 | err_code |= ERR_WARN; |
| 6671 | } |
| 6672 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 6673 | if (curproxy->mode != PR_MODE_HTTP) { |
| 6674 | int optnum; |
| 6675 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 6676 | if (curproxy->uri_auth) { |
| 6677 | Warning("config : 'stats' statement ignored for %s '%s' as it requires HTTP mode.\n", |
| 6678 | proxy_type_str(curproxy), curproxy->id); |
| 6679 | err_code |= ERR_WARN; |
| 6680 | curproxy->uri_auth = NULL; |
| 6681 | } |
| 6682 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 6683 | if (curproxy->options & (PR_O_FWDFOR | PR_O_FF_ALWAYS)) { |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 6684 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6685 | "forwardfor", proxy_type_str(curproxy), curproxy->id); |
| 6686 | err_code |= ERR_WARN; |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 6687 | curproxy->options &= ~(PR_O_FWDFOR | PR_O_FF_ALWAYS); |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 6688 | } |
| 6689 | |
| 6690 | if (curproxy->options & PR_O_ORGTO) { |
| 6691 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6692 | "originalto", proxy_type_str(curproxy), curproxy->id); |
| 6693 | err_code |= ERR_WARN; |
| 6694 | curproxy->options &= ~PR_O_ORGTO; |
| 6695 | } |
| 6696 | |
| 6697 | for (optnum = 0; cfg_opts[optnum].name; optnum++) { |
| 6698 | if (cfg_opts[optnum].mode == PR_MODE_HTTP && |
| 6699 | (curproxy->cap & cfg_opts[optnum].cap) && |
| 6700 | (curproxy->options & cfg_opts[optnum].val)) { |
| 6701 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6702 | cfg_opts[optnum].name, proxy_type_str(curproxy), curproxy->id); |
| 6703 | err_code |= ERR_WARN; |
| 6704 | curproxy->options &= ~cfg_opts[optnum].val; |
| 6705 | } |
| 6706 | } |
| 6707 | |
| 6708 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) { |
| 6709 | if (cfg_opts2[optnum].mode == PR_MODE_HTTP && |
| 6710 | (curproxy->cap & cfg_opts2[optnum].cap) && |
| 6711 | (curproxy->options2 & cfg_opts2[optnum].val)) { |
| 6712 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6713 | cfg_opts2[optnum].name, proxy_type_str(curproxy), curproxy->id); |
| 6714 | err_code |= ERR_WARN; |
| 6715 | curproxy->options2 &= ~cfg_opts2[optnum].val; |
| 6716 | } |
| 6717 | } |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6718 | |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 6719 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6720 | if (curproxy->bind_hdr_occ) { |
| 6721 | curproxy->bind_hdr_occ = 0; |
| 6722 | Warning("config : %s '%s' : ignoring use of header %s as source IP in non-HTTP mode.\n", |
| 6723 | proxy_type_str(curproxy), curproxy->id, curproxy->bind_hdr_name); |
| 6724 | err_code |= ERR_WARN; |
| 6725 | } |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 6726 | #endif |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 6727 | } |
| 6728 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6729 | /* |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 6730 | * ensure that we're not cross-dressing a TCP server into HTTP. |
| 6731 | */ |
| 6732 | newsrv = curproxy->srv; |
| 6733 | while (newsrv != NULL) { |
Willy Tarreau | 0cec331 | 2011-10-31 13:49:26 +0100 | [diff] [blame] | 6734 | if ((curproxy->mode != PR_MODE_HTTP) && newsrv->rdr_len) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6735 | Alert("config : %s '%s' : server cannot have cookie or redirect prefix in non-HTTP mode.\n", |
| 6736 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6737 | cfgerr++; |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 6738 | } |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6739 | |
Willy Tarreau | 0cec331 | 2011-10-31 13:49:26 +0100 | [diff] [blame] | 6740 | if ((curproxy->mode != PR_MODE_HTTP) && newsrv->cklen) { |
| 6741 | Warning("config : %s '%s' : ignoring cookie for server '%s' as HTTP mode is disabled.\n", |
| 6742 | proxy_type_str(curproxy), curproxy->id, newsrv->id); |
| 6743 | err_code |= ERR_WARN; |
| 6744 | } |
| 6745 | |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 6746 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6747 | if (curproxy->mode != PR_MODE_HTTP && newsrv->bind_hdr_occ) { |
| 6748 | newsrv->bind_hdr_occ = 0; |
| 6749 | Warning("config : %s '%s' : server %s cannot use header %s as source IP in non-HTTP mode.\n", |
| 6750 | proxy_type_str(curproxy), curproxy->id, newsrv->id, newsrv->bind_hdr_name); |
| 6751 | err_code |= ERR_WARN; |
| 6752 | } |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 6753 | #endif |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 6754 | newsrv = newsrv->next; |
| 6755 | } |
| 6756 | |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6757 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 6758 | if (!curproxy->accept) |
| 6759 | curproxy->accept = frontend_accept; |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 6760 | |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6761 | if (curproxy->tcp_req.inspect_delay || |
| 6762 | !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules)) |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 6763 | curproxy->fe_req_ana |= AN_REQ_INSPECT_FE; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6764 | |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 6765 | if (curproxy->mode == PR_MODE_HTTP) { |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6766 | 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] | 6767 | 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] | 6768 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6769 | |
| 6770 | /* both TCP and HTTP must check switching rules */ |
| 6771 | curproxy->fe_req_ana |= AN_REQ_SWITCHING_RULES; |
| 6772 | } |
| 6773 | |
| 6774 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 6775 | if (curproxy->tcp_req.inspect_delay || |
| 6776 | !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules)) |
| 6777 | curproxy->be_req_ana |= AN_REQ_INSPECT_BE; |
| 6778 | |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 6779 | if (!LIST_ISEMPTY(&curproxy->tcp_rep.inspect_rules)) |
| 6780 | curproxy->be_rsp_ana |= AN_RES_INSPECT; |
| 6781 | |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 6782 | if (curproxy->mode == PR_MODE_HTTP) { |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6783 | 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] | 6784 | 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] | 6785 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6786 | |
| 6787 | /* If the backend does requires RDP cookie persistence, we have to |
| 6788 | * enable the corresponding analyser. |
| 6789 | */ |
| 6790 | if (curproxy->options2 & PR_O2_RDPC_PRST) |
| 6791 | curproxy->be_req_ana |= AN_REQ_PRST_RDP_COOKIE; |
| 6792 | } |
| 6793 | |
Emeric Brun | c52962f | 2012-11-15 18:28:02 +0100 | [diff] [blame] | 6794 | #ifdef USE_OPENSSL |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 6795 | /* Configure SSL for each bind line. |
| 6796 | * Note: if configuration fails at some point, the ->ctx member |
| 6797 | * remains NULL so that listeners can later detach. |
| 6798 | */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6799 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
Emeric Brun | c52962f | 2012-11-15 18:28:02 +0100 | [diff] [blame] | 6800 | if (!bind_conf->is_ssl) { |
| 6801 | if (bind_conf->default_ctx) { |
| 6802 | Warning("Proxy '%s': A certificate was specified but SSL was not enabled on bind '%s' at [%s:%d] (use 'ssl').\n", |
| 6803 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
| 6804 | } |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6805 | continue; |
Emeric Brun | c52962f | 2012-11-15 18:28:02 +0100 | [diff] [blame] | 6806 | } |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6807 | if (!bind_conf->default_ctx) { |
Emeric Brun | fc0421f | 2012-09-07 17:30:07 +0200 | [diff] [blame] | 6808 | 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] | 6809 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 6810 | cfgerr++; |
| 6811 | continue; |
| 6812 | } |
| 6813 | |
Emeric Brun | 4b3091e | 2012-09-24 15:48:52 +0200 | [diff] [blame] | 6814 | 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] | 6815 | Alert("Unable to allocate SSL session cache.\n"); |
| 6816 | cfgerr++; |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 6817 | continue; |
| 6818 | } |
| 6819 | |
Emeric Brun | fc0421f | 2012-09-07 17:30:07 +0200 | [diff] [blame] | 6820 | /* initialize all certificate contexts */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6821 | cfgerr += ssl_sock_prepare_all_ctx(bind_conf, curproxy); |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6822 | } |
Emeric Brun | c52962f | 2012-11-15 18:28:02 +0100 | [diff] [blame] | 6823 | #endif /* USE_OPENSSL */ |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 6824 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 6825 | /* adjust this proxy's listeners */ |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6826 | next_id = 1; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 6827 | list_for_each_entry(listener, &curproxy->conf.listeners, by_fe) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6828 | if (!listener->luid) { |
| 6829 | /* listener ID not set, use automatic numbering with first |
| 6830 | * spare entry starting with next_luid. |
| 6831 | */ |
| 6832 | next_id = get_next_id(&curproxy->conf.used_listener_id, next_id); |
| 6833 | listener->conf.id.key = listener->luid = next_id; |
| 6834 | eb32_insert(&curproxy->conf.used_listener_id, &listener->conf.id); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6835 | } |
Krzysztof Piotr Oledzki | df5cb9f | 2010-02-05 20:58:27 +0100 | [diff] [blame] | 6836 | next_id++; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6837 | |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 6838 | /* enable separate counters */ |
| 6839 | if (curproxy->options2 & PR_O2_SOCKSTAT) { |
| 6840 | listener->counters = (struct licounters *)calloc(1, sizeof(struct licounters)); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6841 | if (!listener->name) |
| 6842 | memprintf(&listener->name, "sock-%d", listener->luid); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 6843 | } |
Willy Tarreau | 81796be | 2012-09-22 19:11:47 +0200 | [diff] [blame] | 6844 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 6845 | if (curproxy->options & PR_O_TCP_NOLING) |
| 6846 | listener->options |= LI_O_NOLINGER; |
Willy Tarreau | 32368ce | 2012-09-06 11:10:55 +0200 | [diff] [blame] | 6847 | if (!listener->maxconn) |
| 6848 | listener->maxconn = curproxy->maxconn; |
| 6849 | if (!listener->backlog) |
| 6850 | listener->backlog = curproxy->backlog; |
Willy Tarreau | 16a2147 | 2012-11-19 12:39:59 +0100 | [diff] [blame] | 6851 | if (!listener->maxaccept) |
| 6852 | listener->maxaccept = global.tune.maxaccept ? global.tune.maxaccept : 64; |
| 6853 | |
| 6854 | /* we want to have an optimal behaviour on single process mode to |
| 6855 | * maximize the work at once, but in multi-process we want to keep |
| 6856 | * some fairness between processes, so we target half of the max |
| 6857 | * number of events to be balanced over all the processes the proxy |
| 6858 | * is bound to. Rememeber that maxaccept = -1 must be kept as it is |
| 6859 | * used to disable the limit. |
| 6860 | */ |
| 6861 | if (listener->maxaccept > 0) { |
| 6862 | if (nbproc > 1) |
| 6863 | listener->maxaccept = (listener->maxaccept + 1) / 2; |
| 6864 | listener->maxaccept = (listener->maxaccept + nbproc - 1) / nbproc; |
| 6865 | } |
| 6866 | |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6867 | listener->timeout = &curproxy->timeout.client; |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 6868 | listener->accept = session_accept; |
Willy Tarreau | 3bc1377 | 2008-12-07 11:50:35 +0100 | [diff] [blame] | 6869 | listener->handler = process_session; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6870 | listener->analysers |= curproxy->fe_req_ana; |
Willy Tarreau | 3bc1377 | 2008-12-07 11:50:35 +0100 | [diff] [blame] | 6871 | |
Willy Tarreau | a5c0ab2 | 2010-05-31 10:30:33 +0200 | [diff] [blame] | 6872 | if (!LIST_ISEMPTY(&curproxy->tcp_req.l4_rules)) |
| 6873 | listener->options |= LI_O_TCP_RULES; |
| 6874 | |
Willy Tarreau | de3041d | 2010-05-31 10:56:17 +0200 | [diff] [blame] | 6875 | if (curproxy->mon_mask.s_addr) |
| 6876 | listener->options |= LI_O_CHK_MONNET; |
| 6877 | |
Willy Tarreau | 9ea05a7 | 2009-06-14 12:07:01 +0200 | [diff] [blame] | 6878 | /* smart accept mode is automatic in HTTP mode */ |
| 6879 | if ((curproxy->options2 & PR_O2_SMARTACC) || |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6880 | ((curproxy->mode == PR_MODE_HTTP || listener->bind_conf->is_ssl) && |
Willy Tarreau | 9ea05a7 | 2009-06-14 12:07:01 +0200 | [diff] [blame] | 6881 | !(curproxy->no_options2 & PR_O2_SMARTACC))) |
| 6882 | listener->options |= LI_O_NOQUICKACK; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 6883 | } |
| 6884 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6885 | /* Release unused SSL configs */ |
| 6886 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
| 6887 | if (bind_conf->is_ssl) |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 6888 | continue; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6889 | #ifdef USE_OPENSSL |
| 6890 | ssl_sock_free_all_ctx(bind_conf); |
Emeric Brun | fb510ea | 2012-10-05 12:00:26 +0200 | [diff] [blame] | 6891 | free(bind_conf->ca_file); |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6892 | free(bind_conf->ciphers); |
Emeric Brun | 2b58d04 | 2012-09-20 17:10:03 +0200 | [diff] [blame] | 6893 | free(bind_conf->ecdhe); |
Emeric Brun | fb510ea | 2012-10-05 12:00:26 +0200 | [diff] [blame] | 6894 | free(bind_conf->crl_file); |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 6895 | #endif /* USE_OPENSSL */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6896 | } |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 6897 | |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 6898 | /* Check multi-process mode compatibility for the current proxy */ |
| 6899 | if (global.nbproc > 1) { |
| 6900 | int nbproc = 0; |
| 6901 | if (curproxy->bind_proc) { |
| 6902 | int proc; |
| 6903 | for (proc = 0; proc < global.nbproc; proc++) { |
| 6904 | if (curproxy->bind_proc & (1 << proc)) { |
| 6905 | nbproc++; |
| 6906 | } |
| 6907 | } |
| 6908 | } else { |
| 6909 | nbproc = global.nbproc; |
| 6910 | } |
| 6911 | if (curproxy->table.peers.name) { |
| 6912 | Alert("Proxy '%s': peers can't be used in multi-process mode (nbproc > 1).\n", |
| 6913 | curproxy->id); |
| 6914 | cfgerr++; |
| 6915 | } |
| 6916 | if (nbproc > 1) { |
| 6917 | if (curproxy->uri_auth) { |
| 6918 | Warning("Proxy '%s': in multi-process mode, stats will be limited to process assigned to the current request.\n", |
| 6919 | curproxy->id); |
| 6920 | if (!LIST_ISEMPTY(&curproxy->uri_auth->admin_rules)) { |
| 6921 | Warning("Proxy '%s': stats admin will not work correctly in multi-process mode.\n", |
| 6922 | curproxy->id); |
| 6923 | } |
| 6924 | } |
| 6925 | if (curproxy->appsession_name) { |
| 6926 | Warning("Proxy '%s': appsession will not work correctly in multi-process mode.\n", |
| 6927 | curproxy->id); |
| 6928 | } |
| 6929 | if (!LIST_ISEMPTY(&curproxy->sticking_rules)) { |
| 6930 | Warning("Proxy '%s': sticking rules will not work correctly in multi-process mode.\n", |
| 6931 | curproxy->id); |
| 6932 | } |
| 6933 | } |
| 6934 | } |
Willy Tarreau | 918ff60 | 2011-07-25 16:33:49 +0200 | [diff] [blame] | 6935 | |
| 6936 | /* create the task associated with the proxy */ |
| 6937 | curproxy->task = task_new(); |
| 6938 | if (curproxy->task) { |
| 6939 | curproxy->task->context = curproxy; |
| 6940 | curproxy->task->process = manage_proxy; |
| 6941 | /* no need to queue, it will be done automatically if some |
| 6942 | * listener gets limited. |
| 6943 | */ |
| 6944 | curproxy->task->expire = TICK_ETERNITY; |
| 6945 | } else { |
| 6946 | Alert("Proxy '%s': no more memory when trying to allocate the management task\n", |
| 6947 | curproxy->id); |
| 6948 | cfgerr++; |
| 6949 | } |
| 6950 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6951 | curproxy = curproxy->next; |
| 6952 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 6953 | |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 6954 | /* Check multi-process mode compatibility */ |
| 6955 | if (global.nbproc > 1) { |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 6956 | if (global.stats_fe && !global.stats_fe->bind_proc) { |
| 6957 | 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] | 6958 | } |
| 6959 | } |
| 6960 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6961 | for (curuserlist = userlist; curuserlist; curuserlist = curuserlist->next) { |
| 6962 | struct auth_users *curuser; |
| 6963 | int g; |
| 6964 | |
| 6965 | for (curuser = curuserlist->users; curuser; curuser = curuser->next) { |
| 6966 | unsigned int group_mask = 0; |
| 6967 | char *group = NULL; |
| 6968 | |
Willy Tarreau | b4c06b7 | 2010-02-02 11:28:20 +0100 | [diff] [blame] | 6969 | if (!curuser->u.groups) |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6970 | continue; |
| 6971 | |
Willy Tarreau | b4c06b7 | 2010-02-02 11:28:20 +0100 | [diff] [blame] | 6972 | while ((group = strtok(group?NULL:curuser->u.groups, ","))) { |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6973 | |
| 6974 | for (g = 0; g < curuserlist->grpcnt; g++) |
| 6975 | if (!strcmp(curuserlist->groups[g], group)) |
| 6976 | break; |
| 6977 | |
| 6978 | if (g == curuserlist->grpcnt) { |
| 6979 | Alert("userlist '%s': no such group '%s' specified in user '%s'\n", |
| 6980 | curuserlist->name, group, curuser->user); |
| 6981 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6982 | goto out; |
| 6983 | } |
| 6984 | |
| 6985 | group_mask |= (1 << g); |
| 6986 | } |
| 6987 | |
Willy Tarreau | b4c06b7 | 2010-02-02 11:28:20 +0100 | [diff] [blame] | 6988 | free(curuser->u.groups); |
| 6989 | curuser->u.group_mask = group_mask; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6990 | } |
| 6991 | |
| 6992 | for (g = 0; g < curuserlist->grpcnt; g++) { |
| 6993 | char *user = NULL; |
| 6994 | |
| 6995 | if (!curuserlist->groupusers[g]) |
| 6996 | continue; |
| 6997 | |
| 6998 | while ((user = strtok(user?NULL:curuserlist->groupusers[g], ","))) { |
| 6999 | for (curuser = curuserlist->users; curuser; curuser = curuser->next) |
| 7000 | if (!strcmp(curuser->user, user)) |
| 7001 | break; |
| 7002 | |
| 7003 | if (!curuser) { |
| 7004 | Alert("userlist '%s': no such user '%s' specified in group '%s'\n", |
| 7005 | curuserlist->name, user, curuserlist->groups[g]); |
| 7006 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7007 | goto out; |
| 7008 | } |
| 7009 | |
Willy Tarreau | b4c06b7 | 2010-02-02 11:28:20 +0100 | [diff] [blame] | 7010 | curuser->u.group_mask |= (1 << g); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 7011 | } |
| 7012 | |
| 7013 | free(curuserlist->groupusers[g]); |
| 7014 | } |
| 7015 | |
| 7016 | free(curuserlist->groupusers); |
| 7017 | |
| 7018 | #ifdef DEBUG_AUTH |
| 7019 | for (g = 0; g < curuserlist->grpcnt; g++) { |
| 7020 | fprintf(stderr, "group %s, id %d, mask %08X, users:", curuserlist->groups[g], g , 1 << g); |
| 7021 | |
| 7022 | for (curuser = curuserlist->users; curuser; curuser = curuser->next) { |
Willy Tarreau | b950959 | 2012-05-10 23:25:35 +0200 | [diff] [blame] | 7023 | if (curuser->u.group_mask & (1 << g)) |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 7024 | fprintf(stderr, " %s", curuser->user); |
| 7025 | } |
| 7026 | |
| 7027 | fprintf(stderr, "\n"); |
| 7028 | } |
| 7029 | #endif |
| 7030 | |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 7031 | } |
| 7032 | |
| 7033 | /* automatically compute fullconn if not set. We must not do it in the |
| 7034 | * loop above because cross-references are not yet fully resolved. |
| 7035 | */ |
| 7036 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 7037 | /* If <fullconn> is not set, let's set it to 10% of the sum of |
| 7038 | * the possible incoming frontend's maxconns. |
| 7039 | */ |
| 7040 | if (!curproxy->fullconn && (curproxy->cap & PR_CAP_BE)) { |
| 7041 | struct proxy *fe; |
| 7042 | int total = 0; |
| 7043 | |
| 7044 | /* sum up the number of maxconns of frontends which |
| 7045 | * reference this backend at least once or which are |
| 7046 | * the same one ('listen'). |
| 7047 | */ |
| 7048 | for (fe = proxy; fe; fe = fe->next) { |
| 7049 | struct switching_rule *rule; |
| 7050 | struct hdr_exp *exp; |
| 7051 | int found = 0; |
| 7052 | |
| 7053 | if (!(fe->cap & PR_CAP_FE)) |
| 7054 | continue; |
| 7055 | |
| 7056 | if (fe == curproxy) /* we're on a "listen" instance */ |
| 7057 | found = 1; |
| 7058 | |
| 7059 | if (fe->defbe.be == curproxy) /* "default_backend" */ |
| 7060 | found = 1; |
| 7061 | |
| 7062 | /* check if a "use_backend" rule matches */ |
| 7063 | if (!found) { |
| 7064 | list_for_each_entry(rule, &fe->switching_rules, list) { |
| 7065 | if (rule->be.backend == curproxy) { |
| 7066 | found = 1; |
| 7067 | break; |
| 7068 | } |
| 7069 | } |
| 7070 | } |
| 7071 | |
| 7072 | /* check if a "reqsetbe" rule matches */ |
| 7073 | for (exp = fe->req_exp; !found && exp; exp = exp->next) { |
| 7074 | if (exp->action == ACT_SETBE && |
| 7075 | (struct proxy *)exp->replace == curproxy) { |
| 7076 | found = 1; |
| 7077 | break; |
| 7078 | } |
| 7079 | } |
| 7080 | |
| 7081 | /* now we've checked all possible ways to reference a backend |
| 7082 | * from a frontend. |
| 7083 | */ |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 7084 | if (!found) |
| 7085 | continue; |
| 7086 | total += fe->maxconn; |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 7087 | } |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 7088 | /* we have the sum of the maxconns in <total>. We only |
| 7089 | * keep 10% of that sum to set the default fullconn, with |
| 7090 | * a hard minimum of 1 (to avoid a divide by zero). |
| 7091 | */ |
| 7092 | curproxy->fullconn = (total + 9) / 10; |
| 7093 | if (!curproxy->fullconn) |
| 7094 | curproxy->fullconn = 1; |
| 7095 | } |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 7096 | } |
| 7097 | |
Willy Tarreau | 056f568 | 2010-06-06 15:51:11 +0200 | [diff] [blame] | 7098 | /* initialize stick-tables on backend capable proxies. This must not |
| 7099 | * be done earlier because the data size may be discovered while parsing |
| 7100 | * other proxies. |
| 7101 | */ |
| 7102 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) |
Willy Tarreau | c00cdc2 | 2010-06-06 16:48:26 +0200 | [diff] [blame] | 7103 | stktable_init(&curproxy->table); |
Willy Tarreau | 056f568 | 2010-06-06 15:51:11 +0200 | [diff] [blame] | 7104 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7105 | /* |
| 7106 | * Recount currently required checks. |
| 7107 | */ |
| 7108 | |
| 7109 | for (curproxy=proxy; curproxy; curproxy=curproxy->next) { |
| 7110 | int optnum; |
| 7111 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 7112 | for (optnum = 0; cfg_opts[optnum].name; optnum++) |
| 7113 | if (curproxy->options & cfg_opts[optnum].val) |
| 7114 | global.last_checks |= cfg_opts[optnum].checks; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7115 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 7116 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) |
| 7117 | if (curproxy->options2 & cfg_opts2[optnum].val) |
| 7118 | global.last_checks |= cfg_opts2[optnum].checks; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7119 | } |
| 7120 | |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 7121 | if (peers) { |
| 7122 | struct peers *curpeers = peers, **last; |
| 7123 | struct peer *p, *pb; |
| 7124 | |
| 7125 | /* Remove all peers sections which don't have a valid listener. |
| 7126 | * This can happen when a peers section is never referenced and |
| 7127 | * does not contain a local peer. |
| 7128 | */ |
| 7129 | last = &peers; |
| 7130 | while (*last) { |
| 7131 | curpeers = *last; |
| 7132 | if (curpeers->peers_fe) { |
Willy Tarreau | ca57de3 | 2012-11-23 20:08:09 +0100 | [diff] [blame] | 7133 | 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] | 7134 | last = &curpeers->next; |
| 7135 | continue; |
| 7136 | } |
| 7137 | |
| 7138 | Warning("Removing incomplete section 'peers %s' (no peer named '%s').\n", |
| 7139 | curpeers->id, localpeer); |
| 7140 | |
| 7141 | p = curpeers->remote; |
| 7142 | while (p) { |
| 7143 | pb = p->next; |
| 7144 | free(p->id); |
| 7145 | free(p); |
| 7146 | p = pb; |
| 7147 | } |
| 7148 | |
| 7149 | /* Destroy and unlink this curpeers section. |
| 7150 | * Note: curpeers is backed up into *last. |
| 7151 | */ |
| 7152 | free(curpeers->id); |
| 7153 | curpeers = curpeers->next; |
| 7154 | free(*last); |
| 7155 | *last = curpeers; |
| 7156 | } |
| 7157 | } |
| 7158 | |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 7159 | pool2_hdr_idx = create_pool("hdr_idx", |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame] | 7160 | global.tune.max_http_hdr * sizeof(struct hdr_idx_elem), |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 7161 | MEM_F_SHARED); |
| 7162 | |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 7163 | if (cfgerr > 0) |
| 7164 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7165 | out: |
| 7166 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7167 | } |
| 7168 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 7169 | /* |
| 7170 | * Registers the CFG keyword list <kwl> as a list of valid keywords for next |
| 7171 | * parsing sessions. |
| 7172 | */ |
| 7173 | void cfg_register_keywords(struct cfg_kw_list *kwl) |
| 7174 | { |
| 7175 | LIST_ADDQ(&cfg_keywords.list, &kwl->list); |
| 7176 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7177 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 7178 | /* |
| 7179 | * Unregisters the CFG keyword list <kwl> from the list of valid keywords. |
| 7180 | */ |
| 7181 | void cfg_unregister_keywords(struct cfg_kw_list *kwl) |
| 7182 | { |
| 7183 | LIST_DEL(&kwl->list); |
| 7184 | LIST_INIT(&kwl->list); |
| 7185 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7186 | |
| 7187 | /* |
| 7188 | * Local variables: |
| 7189 | * c-indent-level: 8 |
| 7190 | * c-basic-offset: 8 |
| 7191 | * End: |
| 7192 | */ |