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; |
Willy Tarreau | 846257e | 2013-01-24 00:29:37 +0100 | [diff] [blame] | 1512 | free(raddr); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1513 | goto out; |
| 1514 | } |
| 1515 | |
Willy Tarreau | fab5a43 | 2011-03-04 15:31:53 +0100 | [diff] [blame] | 1516 | sk = str2ip(raddr); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1517 | free(raddr); |
| 1518 | if (!sk) { |
| 1519 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[2]); |
| 1520 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1521 | goto out; |
| 1522 | } |
| 1523 | newpeer->addr = *sk; |
Willy Tarreau | 26d8c59 | 2012-05-07 18:12:14 +0200 | [diff] [blame] | 1524 | newpeer->proto = protocol_by_family(newpeer->addr.ss_family); |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 1525 | newpeer->xprt = &raw_sock; |
Willy Tarreau | d02394b | 2012-05-11 18:32:18 +0200 | [diff] [blame] | 1526 | newpeer->sock_init_arg = NULL; |
Willy Tarreau | 26d8c59 | 2012-05-07 18:12:14 +0200 | [diff] [blame] | 1527 | |
Willy Tarreau | 173e7fb | 2012-09-24 22:47:39 +0200 | [diff] [blame] | 1528 | if (!newpeer->proto) { |
Willy Tarreau | 26d8c59 | 2012-05-07 18:12:14 +0200 | [diff] [blame] | 1529 | Alert("parsing [%s:%d] : Unknown protocol family %d '%s'\n", |
| 1530 | file, linenum, newpeer->addr.ss_family, args[2]); |
| 1531 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1532 | goto out; |
| 1533 | } |
| 1534 | |
Willy Tarreau | 86ad42c | 2011-08-27 12:29:07 +0200 | [diff] [blame] | 1535 | set_host_port(&newpeer->addr, realport); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1536 | |
| 1537 | if (strcmp(newpeer->id, localpeer) == 0) { |
| 1538 | /* Current is local peer, it define a frontend */ |
| 1539 | newpeer->local = 1; |
| 1540 | |
| 1541 | if (!curpeers->peers_fe) { |
| 1542 | if ((curpeers->peers_fe = calloc(1, sizeof(struct proxy))) == NULL) { |
| 1543 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1544 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1545 | goto out; |
| 1546 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1547 | |
Willy Tarreau | 237250c | 2011-07-29 01:49:03 +0200 | [diff] [blame] | 1548 | init_new_proxy(curpeers->peers_fe); |
| 1549 | curpeers->peers_fe->parent = curpeers; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1550 | |
| 1551 | curpeers->peers_fe->last_change = now.tv_sec; |
| 1552 | curpeers->peers_fe->id = strdup(args[1]); |
| 1553 | curpeers->peers_fe->cap = PR_CAP_FE; |
Willy Tarreau | 3ae65a1 | 2011-09-07 17:40:39 +0200 | [diff] [blame] | 1554 | curpeers->peers_fe->maxconn = 0; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1555 | curpeers->peers_fe->conn_retries = CONN_RETRIES; |
| 1556 | curpeers->peers_fe->timeout.connect = 5000; |
| 1557 | curpeers->peers_fe->accept = peer_accept; |
| 1558 | curpeers->peers_fe->options2 |= PR_O2_INDEPSTR | PR_O2_SMARTCON | PR_O2_SMARTACC; |
Willy Tarreau | 8b8fd56 | 2013-01-18 11:12:27 +0100 | [diff] [blame] | 1559 | curpeers->peers_fe->conf.file = strdup(file); |
| 1560 | curpeers->peers_fe->conf.line = linenum; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1561 | |
| 1562 | bind_conf = bind_conf_alloc(&curpeers->peers_fe->conf.bind, file, linenum, args[2]); |
| 1563 | |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 1564 | if (!str2listener(args[2], curpeers->peers_fe, bind_conf, file, linenum, &err_msg)) { |
| 1565 | if (err_msg && *err_msg) { |
| 1566 | indent_msg(&err_msg, 2); |
| 1567 | Alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], err_msg); |
| 1568 | } |
| 1569 | else |
| 1570 | Alert("parsing [%s:%d] : '%s %s' : error encountered while parsing listening address %s.\n", |
| 1571 | file, linenum, args[0], args[1], args[2]); |
| 1572 | free(err_msg); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1573 | err_code |= ERR_FATAL; |
| 1574 | goto out; |
| 1575 | } |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1576 | |
| 1577 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
| 1578 | l->maxconn = ((struct proxy *)curpeers->peers_fe)->maxconn; |
| 1579 | l->backlog = ((struct proxy *)curpeers->peers_fe)->backlog; |
| 1580 | l->timeout = &((struct proxy *)curpeers->peers_fe)->timeout.client; |
| 1581 | l->accept = session_accept; |
| 1582 | l->handler = process_session; |
| 1583 | l->analysers |= ((struct proxy *)curpeers->peers_fe)->fe_req_ana; |
| 1584 | l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */ |
| 1585 | global.maxsock += l->maxconn; |
| 1586 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1587 | } |
Willy Tarreau | 8b8fd56 | 2013-01-18 11:12:27 +0100 | [diff] [blame] | 1588 | else { |
| 1589 | Alert("parsing [%s:%d] : '%s %s' : local peer name already referenced at %s:%d.\n", |
| 1590 | file, linenum, args[0], args[1], |
| 1591 | curpeers->peers_fe->conf.file, curpeers->peers_fe->conf.line); |
| 1592 | err_code |= ERR_FATAL; |
| 1593 | goto out; |
| 1594 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1595 | } |
| 1596 | } /* neither "peer" nor "peers" */ |
| 1597 | else if (*args[0] != 0) { |
| 1598 | Alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection); |
| 1599 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1600 | goto out; |
| 1601 | } |
| 1602 | |
| 1603 | out: |
| 1604 | return err_code; |
| 1605 | } |
| 1606 | |
| 1607 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 1608 | 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] | 1609 | { |
| 1610 | static struct proxy *curproxy = NULL; |
| 1611 | struct server *newsrv = NULL; |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 1612 | const char *err; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 1613 | int rc; |
| 1614 | unsigned val; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1615 | int err_code = 0; |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 1616 | struct acl_cond *cond = NULL; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 1617 | struct logsrv *tmplogsrv; |
Willy Tarreau | f4068b6 | 2012-05-08 17:37:49 +0200 | [diff] [blame] | 1618 | char *errmsg = NULL; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 1619 | struct bind_conf *bind_conf; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1620 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1621 | if (!strcmp(args[0], "listen")) |
| 1622 | rc = PR_CAP_LISTEN; |
| 1623 | else if (!strcmp(args[0], "frontend")) |
| 1624 | rc = PR_CAP_FE | PR_CAP_RS; |
| 1625 | else if (!strcmp(args[0], "backend")) |
| 1626 | rc = PR_CAP_BE | PR_CAP_RS; |
| 1627 | else if (!strcmp(args[0], "ruleset")) |
| 1628 | rc = PR_CAP_RS; |
| 1629 | else |
| 1630 | rc = PR_CAP_NONE; |
| 1631 | |
| 1632 | if (rc != PR_CAP_NONE) { /* new proxy */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1633 | if (!*args[1]) { |
| 1634 | Alert("parsing [%s:%d] : '%s' expects an <id> argument and\n" |
| 1635 | " optionnally supports [addr1]:port1[-end1]{,[addr]:port[-end]}...\n", |
| 1636 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1637 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1638 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1639 | } |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 1640 | |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 1641 | err = invalid_char(args[1]); |
| 1642 | if (err) { |
| 1643 | Alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 1644 | file, linenum, *err, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1645 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 1646 | } |
| 1647 | |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 1648 | for (curproxy = proxy; curproxy != NULL; curproxy = curproxy->next) { |
| 1649 | /* |
| 1650 | * If there are two proxies with the same name only following |
| 1651 | * combinations are allowed: |
| 1652 | * |
| 1653 | * listen backend frontend ruleset |
| 1654 | * listen - - - - |
| 1655 | * backend - - OK - |
| 1656 | * frontend - OK - - |
| 1657 | * ruleset - - - - |
| 1658 | */ |
| 1659 | |
| 1660 | if (!strcmp(curproxy->id, args[1]) && |
| 1661 | (rc!=(PR_CAP_FE|PR_CAP_RS) || curproxy->cap!=(PR_CAP_BE|PR_CAP_RS)) && |
| 1662 | (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] | 1663 | Warning("Parsing [%s:%d]: %s '%s' has same name as another %s (declared at %s:%d).\n", |
| 1664 | file, linenum, proxy_cap_str(rc), args[1], proxy_type_str(curproxy), |
| 1665 | curproxy->conf.file, curproxy->conf.line); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1666 | err_code |= ERR_WARN; |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 1667 | } |
| 1668 | } |
| 1669 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1670 | if ((curproxy = (struct proxy *)calloc(1, sizeof(struct proxy))) == NULL) { |
| 1671 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1672 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1673 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1674 | } |
Willy Tarreau | 5af24ef | 2009-03-15 15:23:16 +0100 | [diff] [blame] | 1675 | |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 1676 | init_new_proxy(curproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1677 | curproxy->next = proxy; |
| 1678 | proxy = curproxy; |
Willy Tarreau | 8113a5d | 2012-10-04 08:01:43 +0200 | [diff] [blame] | 1679 | curproxy->conf.file = strdup(file); |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 1680 | curproxy->conf.line = linenum; |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 1681 | curproxy->last_change = now.tv_sec; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1682 | curproxy->id = strdup(args[1]); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1683 | curproxy->cap = rc; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1684 | |
| 1685 | /* parse the listener address if any */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1686 | if ((curproxy->cap & PR_CAP_FE) && *args[2]) { |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1687 | struct listener *l; |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 1688 | char *err_msg = NULL; |
Willy Tarreau | 81a8117 | 2012-09-18 20:52:35 +0200 | [diff] [blame] | 1689 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1690 | bind_conf = bind_conf_alloc(&curproxy->conf.bind, file, linenum, args[2]); |
| 1691 | |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 1692 | if (!str2listener(args[2], curproxy, bind_conf, file, linenum, &err_msg)) { |
| 1693 | if (err_msg && *err_msg) { |
| 1694 | indent_msg(&err_msg, 2); |
| 1695 | Alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], err_msg); |
| 1696 | } |
| 1697 | else |
| 1698 | Alert("parsing [%s:%d] : '%s %s' : error encountered while parsing listening address '%s'.\n", |
| 1699 | file, linenum, args[0], args[1], args[2]); |
| 1700 | free(err_msg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1701 | err_code |= ERR_FATAL; |
| 1702 | goto out; |
| 1703 | } |
Willy Tarreau | 81a8117 | 2012-09-18 20:52:35 +0200 | [diff] [blame] | 1704 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1705 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
Willy Tarreau | c8b1109 | 2011-02-16 11:08:57 +0100 | [diff] [blame] | 1706 | global.maxsock++; |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 1707 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1708 | } |
| 1709 | |
| 1710 | /* set default values */ |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1711 | memcpy(&curproxy->defsrv, &defproxy.defsrv, sizeof(curproxy->defsrv)); |
Willy Tarreau | 7016020 | 2010-04-07 16:06:40 +0200 | [diff] [blame] | 1712 | curproxy->defsrv.id = "default-server"; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1713 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1714 | curproxy->state = defproxy.state; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1715 | curproxy->options = defproxy.options; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 1716 | curproxy->options2 = defproxy.options2; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 1717 | curproxy->no_options = defproxy.no_options; |
| 1718 | curproxy->no_options2 = defproxy.no_options2; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 1719 | curproxy->bind_proc = defproxy.bind_proc; |
Willy Tarreau | 3168223 | 2007-11-29 15:38:04 +0100 | [diff] [blame] | 1720 | curproxy->lbprm.algo = defproxy.lbprm.algo; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 1721 | curproxy->except_net = defproxy.except_net; |
| 1722 | curproxy->except_mask = defproxy.except_mask; |
Maik Broemme | 36db02e | 2009-05-08 17:02:07 +0200 | [diff] [blame] | 1723 | curproxy->except_to = defproxy.except_to; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 1724 | curproxy->except_mask_to = defproxy.except_mask_to; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1725 | |
Willy Tarreau | 79f5fe8 | 2008-08-23 08:18:21 +0200 | [diff] [blame] | 1726 | if (defproxy.fwdfor_hdr_len) { |
| 1727 | curproxy->fwdfor_hdr_len = defproxy.fwdfor_hdr_len; |
| 1728 | curproxy->fwdfor_hdr_name = strdup(defproxy.fwdfor_hdr_name); |
| 1729 | } |
| 1730 | |
Willy Tarreau | b86db34 | 2009-11-30 11:50:16 +0100 | [diff] [blame] | 1731 | if (defproxy.orgto_hdr_len) { |
| 1732 | curproxy->orgto_hdr_len = defproxy.orgto_hdr_len; |
| 1733 | curproxy->orgto_hdr_name = strdup(defproxy.orgto_hdr_name); |
| 1734 | } |
| 1735 | |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 1736 | if (defproxy.server_id_hdr_len) { |
| 1737 | curproxy->server_id_hdr_len = defproxy.server_id_hdr_len; |
| 1738 | curproxy->server_id_hdr_name = strdup(defproxy.server_id_hdr_name); |
| 1739 | } |
| 1740 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1741 | if (curproxy->cap & PR_CAP_FE) { |
| 1742 | curproxy->maxconn = defproxy.maxconn; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 1743 | curproxy->backlog = defproxy.backlog; |
Willy Tarreau | 13a34bd | 2009-05-10 18:52:49 +0200 | [diff] [blame] | 1744 | curproxy->fe_sps_lim = defproxy.fe_sps_lim; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1745 | |
| 1746 | /* initialize error relocations */ |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1747 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) |
| 1748 | chunk_dup(&curproxy->errmsg[rc], &defproxy.errmsg[rc]); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1749 | |
| 1750 | curproxy->to_log = defproxy.to_log & ~LW_COOKIE & ~LW_REQHDR & ~ LW_RSPHDR; |
| 1751 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1752 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1753 | if (curproxy->cap & PR_CAP_BE) { |
| 1754 | curproxy->fullconn = defproxy.fullconn; |
| 1755 | curproxy->conn_retries = defproxy.conn_retries; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1756 | |
Willy Tarreau | aa2f389 | 2010-10-22 16:15:31 +0200 | [diff] [blame] | 1757 | if (defproxy.check_req) { |
| 1758 | curproxy->check_req = calloc(1, defproxy.check_len); |
| 1759 | memcpy(curproxy->check_req, defproxy.check_req, defproxy.check_len); |
| 1760 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1761 | curproxy->check_len = defproxy.check_len; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1762 | |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 1763 | if (defproxy.expect_str) { |
| 1764 | curproxy->expect_str = strdup(defproxy.expect_str); |
| 1765 | if (defproxy.expect_regex) { |
| 1766 | /* note: this regex is known to be valid */ |
| 1767 | curproxy->expect_regex = calloc(1, sizeof(regex_t)); |
| 1768 | regcomp(curproxy->expect_regex, defproxy.expect_str, REG_EXTENDED); |
| 1769 | } |
| 1770 | } |
| 1771 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 1772 | curproxy->ck_opts = defproxy.ck_opts; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1773 | if (defproxy.cookie_name) |
| 1774 | curproxy->cookie_name = strdup(defproxy.cookie_name); |
| 1775 | curproxy->cookie_len = defproxy.cookie_len; |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 1776 | if (defproxy.cookie_domain) |
| 1777 | curproxy->cookie_domain = strdup(defproxy.cookie_domain); |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 1778 | |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 1779 | if (defproxy.cookie_maxidle) |
| 1780 | curproxy->cookie_maxidle = defproxy.cookie_maxidle; |
| 1781 | |
| 1782 | if (defproxy.cookie_maxlife) |
| 1783 | curproxy->cookie_maxlife = defproxy.cookie_maxlife; |
| 1784 | |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 1785 | if (defproxy.rdp_cookie_name) |
| 1786 | curproxy->rdp_cookie_name = strdup(defproxy.rdp_cookie_name); |
| 1787 | curproxy->rdp_cookie_len = defproxy.rdp_cookie_len; |
| 1788 | |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 1789 | if (defproxy.url_param_name) |
| 1790 | curproxy->url_param_name = strdup(defproxy.url_param_name); |
| 1791 | curproxy->url_param_len = defproxy.url_param_len; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 1792 | |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 1793 | if (defproxy.hh_name) |
| 1794 | curproxy->hh_name = strdup(defproxy.hh_name); |
| 1795 | curproxy->hh_len = defproxy.hh_len; |
| 1796 | curproxy->hh_match_domain = defproxy.hh_match_domain; |
| 1797 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 1798 | if (defproxy.conn_src.iface_name) |
| 1799 | curproxy->conn_src.iface_name = strdup(defproxy.conn_src.iface_name); |
| 1800 | curproxy->conn_src.iface_len = defproxy.conn_src.iface_len; |
| 1801 | curproxy->conn_src.opts = defproxy.conn_src.opts & ~CO_SRC_TPROXY_MASK; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1802 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1803 | |
Willy Tarreau | 3b6b1a9 | 2009-07-23 13:24:23 +0200 | [diff] [blame] | 1804 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1805 | if (defproxy.capture_name) |
| 1806 | curproxy->capture_name = strdup(defproxy.capture_name); |
| 1807 | curproxy->capture_namelen = defproxy.capture_namelen; |
| 1808 | curproxy->capture_len = defproxy.capture_len; |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 1809 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1810 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1811 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 1812 | curproxy->timeout.client = defproxy.timeout.client; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 1813 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | 036fae0 | 2008-01-06 13:24:40 +0100 | [diff] [blame] | 1814 | curproxy->timeout.httpreq = defproxy.timeout.httpreq; |
Willy Tarreau | b16a574 | 2010-01-10 14:46:16 +0100 | [diff] [blame] | 1815 | curproxy->timeout.httpka = defproxy.timeout.httpka; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1816 | curproxy->uri_auth = defproxy.uri_auth; |
| 1817 | curproxy->mon_net = defproxy.mon_net; |
| 1818 | curproxy->mon_mask = defproxy.mon_mask; |
| 1819 | if (defproxy.monitor_uri) |
| 1820 | curproxy->monitor_uri = strdup(defproxy.monitor_uri); |
| 1821 | curproxy->monitor_uri_len = defproxy.monitor_uri_len; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 1822 | if (defproxy.defbe.name) |
| 1823 | curproxy->defbe.name = strdup(defproxy.defbe.name); |
Willy Tarreau | 99a7ca2 | 2012-05-31 19:39:23 +0200 | [diff] [blame] | 1824 | |
| 1825 | /* get either a pointer to the logformat string or a copy of it */ |
| 1826 | curproxy->logformat_string = defproxy.logformat_string; |
| 1827 | if (curproxy->logformat_string && |
| 1828 | curproxy->logformat_string != default_http_log_format && |
| 1829 | curproxy->logformat_string != default_tcp_log_format && |
| 1830 | curproxy->logformat_string != clf_http_log_format) |
| 1831 | curproxy->logformat_string = strdup(curproxy->logformat_string); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1832 | } |
| 1833 | |
| 1834 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 1835 | curproxy->timeout.connect = defproxy.timeout.connect; |
| 1836 | curproxy->timeout.server = defproxy.timeout.server; |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 1837 | curproxy->timeout.check = defproxy.timeout.check; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 1838 | curproxy->timeout.queue = defproxy.timeout.queue; |
Willy Tarreau | 51c9bde | 2008-01-06 13:40:03 +0100 | [diff] [blame] | 1839 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | cd7afc0 | 2009-07-12 10:03:17 +0200 | [diff] [blame] | 1840 | curproxy->timeout.httpreq = defproxy.timeout.httpreq; |
Willy Tarreau | b16a574 | 2010-01-10 14:46:16 +0100 | [diff] [blame] | 1841 | curproxy->timeout.httpka = defproxy.timeout.httpka; |
Willy Tarreau | ce887fd | 2012-05-12 12:50:00 +0200 | [diff] [blame] | 1842 | curproxy->timeout.tunnel = defproxy.timeout.tunnel; |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 1843 | curproxy->conn_src.source_addr = defproxy.conn_src.source_addr; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1844 | } |
| 1845 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1846 | curproxy->mode = defproxy.mode; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1847 | |
| 1848 | /* copy default logsrvs to curproxy */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 1849 | list_for_each_entry(tmplogsrv, &defproxy.logsrvs, list) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1850 | struct logsrv *node = malloc(sizeof(struct logsrv)); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 1851 | memcpy(node, tmplogsrv, sizeof(struct logsrv)); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1852 | LIST_INIT(&node->list); |
| 1853 | LIST_ADDQ(&curproxy->logsrvs, &node->list); |
| 1854 | } |
| 1855 | |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 1856 | curproxy->uniqueid_format_string = defproxy.uniqueid_format_string; |
| 1857 | if (curproxy->uniqueid_format_string) |
| 1858 | curproxy->uniqueid_format_string = strdup(curproxy->uniqueid_format_string); |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 1859 | |
| 1860 | /* copy default header unique id */ |
| 1861 | if (defproxy.header_unique_id) |
| 1862 | curproxy->header_unique_id = strdup(defproxy.header_unique_id); |
| 1863 | |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 1864 | /* default compression options */ |
| 1865 | if (defproxy.comp != NULL) { |
| 1866 | curproxy->comp = calloc(1, sizeof(struct comp)); |
| 1867 | curproxy->comp->algos = defproxy.comp->algos; |
| 1868 | curproxy->comp->types = defproxy.comp->types; |
| 1869 | } |
| 1870 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1871 | curproxy->grace = defproxy.grace; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1872 | curproxy->conf.used_listener_id = EB_ROOT; |
| 1873 | curproxy->conf.used_server_id = EB_ROOT; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 1874 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1875 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1876 | } |
| 1877 | else if (!strcmp(args[0], "defaults")) { /* use this one to assign default values */ |
| 1878 | /* some variables may have already been initialized earlier */ |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 1879 | /* FIXME-20070101: we should do this too at the end of the |
| 1880 | * config parsing to free all default values. |
| 1881 | */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1882 | free(defproxy.check_req); |
| 1883 | free(defproxy.cookie_name); |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 1884 | free(defproxy.rdp_cookie_name); |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 1885 | free(defproxy.cookie_domain); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1886 | free(defproxy.url_param_name); |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 1887 | free(defproxy.hh_name); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1888 | free(defproxy.capture_name); |
| 1889 | free(defproxy.monitor_uri); |
| 1890 | free(defproxy.defbe.name); |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 1891 | free(defproxy.conn_src.iface_name); |
Willy Tarreau | 79f5fe8 | 2008-08-23 08:18:21 +0200 | [diff] [blame] | 1892 | free(defproxy.fwdfor_hdr_name); |
| 1893 | defproxy.fwdfor_hdr_len = 0; |
Willy Tarreau | b86db34 | 2009-11-30 11:50:16 +0100 | [diff] [blame] | 1894 | free(defproxy.orgto_hdr_name); |
| 1895 | defproxy.orgto_hdr_len = 0; |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 1896 | free(defproxy.server_id_hdr_name); |
| 1897 | defproxy.server_id_hdr_len = 0; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 1898 | free(defproxy.expect_str); |
| 1899 | if (defproxy.expect_regex) regfree(defproxy.expect_regex); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 1900 | |
Willy Tarreau | 39b0665 | 2012-06-01 10:58:06 +0200 | [diff] [blame] | 1901 | if (defproxy.logformat_string != default_http_log_format && |
| 1902 | defproxy.logformat_string != default_tcp_log_format && |
| 1903 | defproxy.logformat_string != clf_http_log_format) |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 1904 | free(defproxy.logformat_string); |
| 1905 | |
| 1906 | free(defproxy.uniqueid_format_string); |
| 1907 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1908 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1909 | chunk_destroy(&defproxy.errmsg[rc]); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 1910 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1911 | /* we cannot free uri_auth because it might already be used */ |
| 1912 | init_default_instance(); |
| 1913 | curproxy = &defproxy; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1914 | defproxy.cap = PR_CAP_LISTEN; /* all caps for now */ |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1915 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1916 | } |
| 1917 | else if (curproxy == NULL) { |
| 1918 | Alert("parsing [%s:%d] : 'listen' or 'defaults' expected.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1919 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1920 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1921 | } |
| 1922 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1923 | |
| 1924 | /* Now let's parse the proxy-specific keywords */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1925 | if (!strcmp(args[0], "bind")) { /* new listen addresses */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1926 | struct listener *l; |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1927 | int cur_arg; |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 1928 | char *err_msg = NULL; |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1929 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1930 | if (curproxy == &defproxy) { |
| 1931 | 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] | 1932 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1933 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1934 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1935 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1936 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1937 | |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 1938 | if ( *(args[1]) != '/' && strchr(args[1], ':') == NULL) { |
Willy Tarreau | d55c3fe | 2010-11-09 09:50:37 +0100 | [diff] [blame] | 1939 | 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] | 1940 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1941 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1942 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1943 | } |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 1944 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 1945 | bind_conf = bind_conf_alloc(&curproxy->conf.bind, file, linenum, args[1]); |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1946 | 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] | 1947 | |
| 1948 | /* NOTE: the following line might create several listeners if there |
| 1949 | * are comma-separated IPs or port ranges. So all further processing |
| 1950 | * will have to be applied to all listeners created after last_listen. |
| 1951 | */ |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 1952 | if (!str2listener(args[1], curproxy, bind_conf, file, linenum, &err_msg)) { |
| 1953 | if (err_msg && *err_msg) { |
| 1954 | indent_msg(&err_msg, 2); |
| 1955 | Alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], err_msg); |
| 1956 | } |
| 1957 | else |
| 1958 | Alert("parsing [%s:%d] : '%s' : error encountered while parsing listening address '%s'.\n", |
| 1959 | file, linenum, args[0], args[1]); |
| 1960 | free(err_msg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1961 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1962 | goto out; |
| 1963 | } |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1964 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1965 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
| 1966 | /* Set default global rights and owner for unix bind */ |
Willy Tarreau | c8b1109 | 2011-02-16 11:08:57 +0100 | [diff] [blame] | 1967 | global.maxsock++; |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 1968 | } |
| 1969 | |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1970 | cur_arg = 2; |
| 1971 | while (*(args[cur_arg])) { |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 1972 | static int bind_dumped; |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 1973 | struct bind_kw *kw; |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 1974 | char *err; |
| 1975 | |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 1976 | kw = bind_find_kw(args[cur_arg]); |
| 1977 | if (kw) { |
| 1978 | char *err = NULL; |
| 1979 | int code; |
| 1980 | |
| 1981 | if (!kw->parse) { |
Willy Tarreau | dda322d | 2012-09-18 16:34:09 +0200 | [diff] [blame] | 1982 | Alert("parsing [%s:%d] : '%s %s' : '%s' option is not implemented in this version (check build options).\n", |
| 1983 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 1984 | cur_arg += 1 + kw->skip ; |
| 1985 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1986 | goto out; |
| 1987 | } |
| 1988 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1989 | code = kw->parse(args, cur_arg, curproxy, bind_conf, &err); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 1990 | err_code |= code; |
| 1991 | |
| 1992 | if (code) { |
| 1993 | if (err && *err) { |
| 1994 | indent_msg(&err, 2); |
Willy Tarreau | dda322d | 2012-09-18 16:34:09 +0200 | [diff] [blame] | 1995 | 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] | 1996 | } |
| 1997 | else |
Willy Tarreau | dda322d | 2012-09-18 16:34:09 +0200 | [diff] [blame] | 1998 | Alert("parsing [%s:%d] : '%s %s' : error encountered while processing '%s'.\n", |
| 1999 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 2000 | if (code & ERR_FATAL) { |
| 2001 | free(err); |
| 2002 | cur_arg += 1 + kw->skip; |
| 2003 | goto out; |
| 2004 | } |
| 2005 | } |
| 2006 | free(err); |
| 2007 | cur_arg += 1 + kw->skip; |
| 2008 | continue; |
| 2009 | } |
| 2010 | |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 2011 | err = NULL; |
| 2012 | if (!bind_dumped) { |
| 2013 | bind_dump_kws(&err); |
| 2014 | indent_msg(&err, 4); |
| 2015 | bind_dumped = 1; |
| 2016 | } |
| 2017 | |
| 2018 | Alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'.%s%s\n", |
| 2019 | file, linenum, args[0], args[1], args[cur_arg], |
| 2020 | err ? " Registered keywords :" : "", err ? err : ""); |
| 2021 | free(err); |
| 2022 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2023 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2024 | goto out; |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 2025 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2026 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2027 | } |
| 2028 | else if (!strcmp(args[0], "monitor-net")) { /* set the range of IPs to ignore */ |
| 2029 | if (!*args[1] || !str2net(args[1], &curproxy->mon_net, &curproxy->mon_mask)) { |
| 2030 | Alert("parsing [%s:%d] : '%s' expects address[/mask].\n", |
| 2031 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2032 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2033 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2034 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2035 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2036 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2037 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2038 | /* flush useless bits */ |
| 2039 | curproxy->mon_net.s_addr &= curproxy->mon_mask.s_addr; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2040 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2041 | } |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2042 | else if (!strcmp(args[0], "monitor-uri")) { /* set the URI to intercept */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2043 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2044 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2045 | |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2046 | if (!*args[1]) { |
| 2047 | Alert("parsing [%s:%d] : '%s' expects an URI.\n", |
| 2048 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2049 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2050 | goto out; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2051 | } |
| 2052 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2053 | free(curproxy->monitor_uri); |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 2054 | curproxy->monitor_uri_len = strlen(args[1]); |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2055 | curproxy->monitor_uri = (char *)calloc(1, curproxy->monitor_uri_len + 1); |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 2056 | memcpy(curproxy->monitor_uri, args[1], curproxy->monitor_uri_len); |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2057 | curproxy->monitor_uri[curproxy->monitor_uri_len] = '\0'; |
| 2058 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2059 | goto out; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2060 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2061 | else if (!strcmp(args[0], "mode")) { /* sets the proxy mode */ |
| 2062 | if (!strcmp(args[1], "http")) curproxy->mode = PR_MODE_HTTP; |
| 2063 | else if (!strcmp(args[1], "tcp")) curproxy->mode = PR_MODE_TCP; |
| 2064 | else if (!strcmp(args[1], "health")) curproxy->mode = PR_MODE_HEALTH; |
| 2065 | else { |
| 2066 | 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] | 2067 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2068 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2069 | } |
| 2070 | } |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2071 | else if (!strcmp(args[0], "id")) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2072 | struct eb32_node *node; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2073 | |
| 2074 | if (curproxy == &defproxy) { |
| 2075 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", |
| 2076 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2077 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2078 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2079 | } |
| 2080 | |
| 2081 | if (!*args[1]) { |
| 2082 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 2083 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2084 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2085 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2086 | } |
| 2087 | |
| 2088 | curproxy->uuid = atol(args[1]); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2089 | curproxy->conf.id.key = curproxy->uuid; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2090 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2091 | if (curproxy->uuid <= 0) { |
| 2092 | Alert("parsing [%s:%d]: custom id has to be > 0.\n", |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2093 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2094 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2095 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2096 | } |
| 2097 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2098 | node = eb32_lookup(&used_proxy_id, curproxy->uuid); |
| 2099 | if (node) { |
| 2100 | struct proxy *target = container_of(node, struct proxy, conf.id); |
| 2101 | Alert("parsing [%s:%d]: %s %s reuses same custom id as %s %s (declared at %s:%d).\n", |
| 2102 | file, linenum, proxy_type_str(curproxy), curproxy->id, |
| 2103 | proxy_type_str(target), target->id, target->conf.file, target->conf.line); |
| 2104 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2105 | goto out; |
| 2106 | } |
| 2107 | eb32_insert(&used_proxy_id, &curproxy->conf.id); |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2108 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 2109 | else if (!strcmp(args[0], "description")) { |
| 2110 | int i, len=0; |
| 2111 | char *d; |
| 2112 | |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 2113 | if (curproxy == &defproxy) { |
| 2114 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", |
| 2115 | file, linenum, args[0]); |
| 2116 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2117 | goto out; |
| 2118 | } |
| 2119 | |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 2120 | if (!*args[1]) { |
| 2121 | Alert("parsing [%s:%d]: '%s' expects a string argument.\n", |
| 2122 | file, linenum, args[0]); |
| 2123 | return -1; |
| 2124 | } |
| 2125 | |
| 2126 | for(i=1; *args[i]; i++) |
| 2127 | len += strlen(args[i])+1; |
| 2128 | |
| 2129 | d = (char *)calloc(1, len); |
| 2130 | curproxy->desc = d; |
| 2131 | |
| 2132 | d += sprintf(d, "%s", args[1]); |
| 2133 | for(i=2; *args[i]; i++) |
| 2134 | d += sprintf(d, " %s", args[i]); |
| 2135 | |
| 2136 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2137 | else if (!strcmp(args[0], "disabled")) { /* disables this proxy */ |
| 2138 | curproxy->state = PR_STSTOPPED; |
| 2139 | } |
| 2140 | else if (!strcmp(args[0], "enabled")) { /* enables this proxy (used to revert a disabled default) */ |
| 2141 | curproxy->state = PR_STNEW; |
| 2142 | } |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2143 | else if (!strcmp(args[0], "bind-process")) { /* enable this proxy only on some processes */ |
| 2144 | int cur_arg = 1; |
| 2145 | unsigned int set = 0; |
| 2146 | |
| 2147 | while (*args[cur_arg]) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 2148 | unsigned int low, high; |
| 2149 | |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2150 | if (strcmp(args[cur_arg], "all") == 0) { |
| 2151 | set = 0; |
| 2152 | break; |
| 2153 | } |
| 2154 | else if (strcmp(args[cur_arg], "odd") == 0) { |
| 2155 | set |= 0x55555555; |
| 2156 | } |
| 2157 | else if (strcmp(args[cur_arg], "even") == 0) { |
| 2158 | set |= 0xAAAAAAAA; |
| 2159 | } |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 2160 | else if (isdigit((int)*args[cur_arg])) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 2161 | char *dash = strchr(args[cur_arg], '-'); |
| 2162 | |
| 2163 | low = high = str2uic(args[cur_arg]); |
| 2164 | if (dash) |
| 2165 | high = str2uic(dash + 1); |
| 2166 | |
| 2167 | if (high < low) { |
| 2168 | unsigned int swap = low; |
| 2169 | low = high; |
| 2170 | high = swap; |
| 2171 | } |
| 2172 | |
| 2173 | if (low < 1 || high > 32) { |
| 2174 | 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] | 2175 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2176 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2177 | goto out; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2178 | } |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 2179 | |
| 2180 | if (high > global.nbproc) { |
| 2181 | Warning("parsing [%s:%d]: %s references process number %d which is higher than global.nbproc (%d).\n", |
| 2182 | file, linenum, args[0], high, global.nbproc); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2183 | err_code |= ERR_WARN; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2184 | } |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 2185 | while (low <= high) |
| 2186 | set |= 1 << (low++ - 1); |
| 2187 | } |
| 2188 | else { |
| 2189 | Alert("parsing [%s:%d]: %s expects 'all', 'odd', 'even', or a list of process ranges with numbers from 1 to 32.\n", |
| 2190 | file, linenum, args[0]); |
| 2191 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2192 | goto out; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2193 | } |
| 2194 | cur_arg++; |
| 2195 | } |
| 2196 | curproxy->bind_proc = set; |
| 2197 | } |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 2198 | else if (!strcmp(args[0], "acl")) { /* add an ACL */ |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2199 | if (curproxy == &defproxy) { |
| 2200 | 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] | 2201 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2202 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2203 | } |
| 2204 | |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 2205 | err = invalid_char(args[1]); |
| 2206 | if (err) { |
| 2207 | Alert("parsing [%s:%d] : character '%c' is not permitted in acl name '%s'.\n", |
| 2208 | file, linenum, *err, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2209 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 2210 | } |
| 2211 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 2212 | if (parse_acl((const char **)args + 1, &curproxy->acl, &errmsg) == NULL) { |
| 2213 | Alert("parsing [%s:%d] : error detected while parsing ACL '%s' : %s.\n", |
| 2214 | file, linenum, args[1], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2215 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2216 | goto out; |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 2217 | } |
| 2218 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2219 | else if (!strcmp(args[0], "cookie")) { /* cookie name */ |
| 2220 | int cur_arg; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2221 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2222 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2223 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2224 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2225 | if (*(args[1]) == 0) { |
| 2226 | Alert("parsing [%s:%d] : '%s' expects <cookie_name> as argument.\n", |
| 2227 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2228 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2229 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2230 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2231 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2232 | curproxy->ck_opts = 0; |
Willy Tarreau | c63d4bb | 2010-10-23 11:37:27 +0200 | [diff] [blame] | 2233 | curproxy->cookie_maxidle = curproxy->cookie_maxlife = 0; |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 2234 | free(curproxy->cookie_domain); curproxy->cookie_domain = NULL; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2235 | free(curproxy->cookie_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2236 | curproxy->cookie_name = strdup(args[1]); |
| 2237 | curproxy->cookie_len = strlen(curproxy->cookie_name); |
Willy Tarreau | c63d4bb | 2010-10-23 11:37:27 +0200 | [diff] [blame] | 2238 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2239 | cur_arg = 2; |
| 2240 | while (*(args[cur_arg])) { |
| 2241 | if (!strcmp(args[cur_arg], "rewrite")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2242 | curproxy->ck_opts |= PR_CK_RW; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2243 | } |
| 2244 | else if (!strcmp(args[cur_arg], "indirect")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2245 | curproxy->ck_opts |= PR_CK_IND; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2246 | } |
| 2247 | else if (!strcmp(args[cur_arg], "insert")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2248 | curproxy->ck_opts |= PR_CK_INS; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2249 | } |
| 2250 | else if (!strcmp(args[cur_arg], "nocache")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2251 | curproxy->ck_opts |= PR_CK_NOC; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2252 | } |
| 2253 | else if (!strcmp(args[cur_arg], "postonly")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2254 | curproxy->ck_opts |= PR_CK_POST; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2255 | } |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 2256 | else if (!strcmp(args[cur_arg], "preserve")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2257 | curproxy->ck_opts |= PR_CK_PSV; |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 2258 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2259 | else if (!strcmp(args[cur_arg], "prefix")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2260 | curproxy->ck_opts |= PR_CK_PFX; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2261 | } |
Willy Tarreau | 4992dd2 | 2012-05-31 21:02:17 +0200 | [diff] [blame] | 2262 | else if (!strcmp(args[cur_arg], "httponly")) { |
| 2263 | curproxy->ck_opts |= PR_CK_HTTPONLY; |
| 2264 | } |
| 2265 | else if (!strcmp(args[cur_arg], "secure")) { |
| 2266 | curproxy->ck_opts |= PR_CK_SECURE; |
| 2267 | } |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2268 | else if (!strcmp(args[cur_arg], "domain")) { |
| 2269 | if (!*args[cur_arg + 1]) { |
| 2270 | Alert("parsing [%s:%d]: '%s' expects <domain> as argument.\n", |
| 2271 | file, linenum, args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2272 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2273 | goto out; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2274 | } |
| 2275 | |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 2276 | if (*args[cur_arg + 1] != '.' || !strchr(args[cur_arg + 1] + 1, '.')) { |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2277 | /* rfc2109, 4.3.2 Rejecting Cookies */ |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 2278 | Warning("parsing [%s:%d]: domain '%s' contains no embedded" |
| 2279 | " dots nor does not start with a dot." |
| 2280 | " RFC forbids it, this configuration may not work properly.\n", |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2281 | file, linenum, args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 2282 | err_code |= ERR_WARN; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2283 | } |
| 2284 | |
| 2285 | err = invalid_domainchar(args[cur_arg + 1]); |
| 2286 | if (err) { |
| 2287 | Alert("parsing [%s:%d]: character '%c' is not permitted in domain name '%s'.\n", |
| 2288 | file, linenum, *err, args[cur_arg + 1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2289 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2290 | goto out; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2291 | } |
| 2292 | |
Willy Tarreau | 68a897b | 2009-12-03 23:28:34 +0100 | [diff] [blame] | 2293 | if (!curproxy->cookie_domain) { |
| 2294 | curproxy->cookie_domain = strdup(args[cur_arg + 1]); |
| 2295 | } else { |
| 2296 | /* one domain was already specified, add another one by |
| 2297 | * building the string which will be returned along with |
| 2298 | * the cookie. |
| 2299 | */ |
| 2300 | char *new_ptr; |
| 2301 | int new_len = strlen(curproxy->cookie_domain) + |
| 2302 | strlen("; domain=") + strlen(args[cur_arg + 1]) + 1; |
| 2303 | new_ptr = malloc(new_len); |
| 2304 | snprintf(new_ptr, new_len, "%s; domain=%s", curproxy->cookie_domain, args[cur_arg+1]); |
| 2305 | free(curproxy->cookie_domain); |
| 2306 | curproxy->cookie_domain = new_ptr; |
| 2307 | } |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 2308 | cur_arg++; |
| 2309 | } |
| 2310 | else if (!strcmp(args[cur_arg], "maxidle")) { |
| 2311 | unsigned int maxidle; |
| 2312 | const char *res; |
| 2313 | |
| 2314 | if (!*args[cur_arg + 1]) { |
| 2315 | Alert("parsing [%s:%d]: '%s' expects <idletime> in seconds as argument.\n", |
| 2316 | file, linenum, args[cur_arg]); |
| 2317 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2318 | goto out; |
| 2319 | } |
| 2320 | |
| 2321 | res = parse_time_err(args[cur_arg + 1], &maxidle, TIME_UNIT_S); |
| 2322 | if (res) { |
| 2323 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 2324 | file, linenum, *res, args[cur_arg]); |
| 2325 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2326 | goto out; |
| 2327 | } |
| 2328 | curproxy->cookie_maxidle = maxidle; |
| 2329 | cur_arg++; |
| 2330 | } |
| 2331 | else if (!strcmp(args[cur_arg], "maxlife")) { |
| 2332 | unsigned int maxlife; |
| 2333 | const char *res; |
| 2334 | |
| 2335 | if (!*args[cur_arg + 1]) { |
| 2336 | Alert("parsing [%s:%d]: '%s' expects <lifetime> in seconds as argument.\n", |
| 2337 | file, linenum, args[cur_arg]); |
| 2338 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2339 | goto out; |
| 2340 | } |
| 2341 | |
| 2342 | res = parse_time_err(args[cur_arg + 1], &maxlife, TIME_UNIT_S); |
| 2343 | if (res) { |
| 2344 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 2345 | file, linenum, *res, args[cur_arg]); |
| 2346 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2347 | goto out; |
| 2348 | } |
| 2349 | curproxy->cookie_maxlife = maxlife; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2350 | cur_arg++; |
| 2351 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2352 | else { |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 2353 | 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] | 2354 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2355 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2356 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2357 | } |
| 2358 | cur_arg++; |
| 2359 | } |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2360 | if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_IND))) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2361 | Alert("parsing [%s:%d] : cookie 'rewrite' and 'indirect' modes are incompatible.\n", |
| 2362 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2363 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2364 | } |
| 2365 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2366 | 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] | 2367 | Alert("parsing [%s:%d] : cookie 'rewrite', 'insert' and 'prefix' modes are incompatible.\n", |
| 2368 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2369 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2370 | } |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 2371 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2372 | 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] | 2373 | Alert("parsing [%s:%d] : cookie 'preserve' requires at least 'insert' or 'indirect'.\n", |
| 2374 | file, linenum); |
| 2375 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2376 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2377 | }/* end else if (!strcmp(args[0], "cookie")) */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2378 | else if (!strcmp(args[0], "persist")) { /* persist */ |
| 2379 | if (*(args[1]) == 0) { |
| 2380 | Alert("parsing [%s:%d] : missing persist method.\n", |
| 2381 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2382 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2383 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2384 | } |
| 2385 | |
| 2386 | if (!strncmp(args[1], "rdp-cookie", 10)) { |
| 2387 | curproxy->options2 |= PR_O2_RDPC_PRST; |
| 2388 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2389 | if (*(args[1] + 10) == '(') { /* cookie name */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2390 | const char *beg, *end; |
| 2391 | |
| 2392 | beg = args[1] + 11; |
| 2393 | end = strchr(beg, ')'); |
| 2394 | |
| 2395 | if (!end || end == beg) { |
| 2396 | Alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n", |
| 2397 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2398 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2399 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2400 | } |
| 2401 | |
| 2402 | free(curproxy->rdp_cookie_name); |
| 2403 | curproxy->rdp_cookie_name = my_strndup(beg, end - beg); |
| 2404 | curproxy->rdp_cookie_len = end-beg; |
| 2405 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2406 | else if (*(args[1] + 10) == '\0') { /* default cookie name 'msts' */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2407 | free(curproxy->rdp_cookie_name); |
| 2408 | curproxy->rdp_cookie_name = strdup("msts"); |
| 2409 | curproxy->rdp_cookie_len = strlen(curproxy->rdp_cookie_name); |
| 2410 | } |
| 2411 | else { /* syntax */ |
| 2412 | Alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n", |
| 2413 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2414 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2415 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2416 | } |
| 2417 | } |
| 2418 | else { |
| 2419 | Alert("parsing [%s:%d] : unknown persist method.\n", |
| 2420 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2421 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2422 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2423 | } |
| 2424 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2425 | else if (!strcmp(args[0], "appsession")) { /* cookie name */ |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2426 | int cur_arg; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2427 | |
Cyril Bonté | 3b7a369 | 2010-01-10 17:01:47 +0100 | [diff] [blame] | 2428 | if (curproxy == &defproxy) { |
| 2429 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2430 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2431 | goto out; |
| 2432 | } |
| 2433 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2434 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2435 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2436 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2437 | if (*(args[5]) == 0) { |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2438 | 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] | 2439 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2440 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2441 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2442 | } |
| 2443 | have_appsession = 1; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2444 | free(curproxy->appsession_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2445 | curproxy->appsession_name = strdup(args[1]); |
| 2446 | curproxy->appsession_name_len = strlen(curproxy->appsession_name); |
| 2447 | curproxy->appsession_len = atoi(args[3]); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 2448 | err = parse_time_err(args[5], &val, TIME_UNIT_MS); |
| 2449 | if (err) { |
| 2450 | Alert("parsing [%s:%d] : unexpected character '%c' in %s timeout.\n", |
| 2451 | file, linenum, *err, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2452 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2453 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 2454 | } |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 2455 | curproxy->timeout.appsession = val; |
Willy Tarreau | ee99136 | 2007-05-14 14:37:50 +0200 | [diff] [blame] | 2456 | |
Willy Tarreau | 51041c7 | 2007-09-09 21:56:53 +0200 | [diff] [blame] | 2457 | if (appsession_hash_init(&(curproxy->htbl_proxy), destroy) == 0) { |
| 2458 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2459 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2460 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2461 | } |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2462 | |
| 2463 | cur_arg = 6; |
| 2464 | curproxy->options2 &= ~PR_O2_AS_REQL; |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2465 | curproxy->options2 &= ~PR_O2_AS_M_ANY; |
| 2466 | curproxy->options2 |= PR_O2_AS_M_PP; |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2467 | while (*(args[cur_arg])) { |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2468 | if (!strcmp(args[cur_arg], "request-learn")) { |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2469 | curproxy->options2 |= PR_O2_AS_REQL; |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2470 | } else if (!strcmp(args[cur_arg], "prefix")) { |
| 2471 | curproxy->options2 |= PR_O2_AS_PFX; |
| 2472 | } else if (!strcmp(args[cur_arg], "mode")) { |
| 2473 | if (!*args[cur_arg + 1]) { |
| 2474 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 2475 | file, linenum, args[0], args[cur_arg]); |
| 2476 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2477 | goto out; |
| 2478 | } |
| 2479 | |
| 2480 | cur_arg++; |
| 2481 | if (!strcmp(args[cur_arg], "query-string")) { |
| 2482 | curproxy->options2 &= ~PR_O2_AS_M_ANY; |
| 2483 | curproxy->options2 |= PR_O2_AS_M_QS; |
| 2484 | } else if (!strcmp(args[cur_arg], "path-parameters")) { |
| 2485 | curproxy->options2 &= ~PR_O2_AS_M_ANY; |
| 2486 | curproxy->options2 |= PR_O2_AS_M_PP; |
| 2487 | } else { |
| 2488 | Alert("parsing [%s:%d] : unknown mode '%s'\n", file, linenum, args[cur_arg]); |
| 2489 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2490 | goto out; |
| 2491 | } |
| 2492 | } |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2493 | cur_arg++; |
| 2494 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2495 | } /* Url App Session */ |
| 2496 | else if (!strcmp(args[0], "capture")) { |
Willy Tarreau | 3b6b1a9 | 2009-07-23 13:24:23 +0200 | [diff] [blame] | 2497 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2498 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2499 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2500 | if (!strcmp(args[1], "cookie")) { /* name of a cookie to capture */ |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 2501 | if (curproxy == &defproxy) { |
| 2502 | Alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
| 2503 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2504 | goto out; |
| 2505 | } |
| 2506 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2507 | if (*(args[4]) == 0) { |
| 2508 | Alert("parsing [%s:%d] : '%s' expects 'cookie' <cookie_name> 'len' <len>.\n", |
| 2509 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2510 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2511 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2512 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2513 | free(curproxy->capture_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2514 | curproxy->capture_name = strdup(args[2]); |
| 2515 | curproxy->capture_namelen = strlen(curproxy->capture_name); |
| 2516 | curproxy->capture_len = atol(args[4]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2517 | curproxy->to_log |= LW_COOKIE; |
| 2518 | } |
| 2519 | else if (!strcmp(args[1], "request") && !strcmp(args[2], "header")) { |
| 2520 | struct cap_hdr *hdr; |
| 2521 | |
| 2522 | if (curproxy == &defproxy) { |
| 2523 | 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] | 2524 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2525 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2526 | } |
| 2527 | |
| 2528 | if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) { |
| 2529 | Alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n", |
| 2530 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2531 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2532 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2533 | } |
| 2534 | |
| 2535 | hdr = calloc(sizeof(struct cap_hdr), 1); |
| 2536 | hdr->next = curproxy->req_cap; |
| 2537 | hdr->name = strdup(args[3]); |
| 2538 | hdr->namelen = strlen(args[3]); |
| 2539 | hdr->len = atol(args[5]); |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 2540 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2541 | hdr->index = curproxy->nb_req_cap++; |
| 2542 | curproxy->req_cap = hdr; |
| 2543 | curproxy->to_log |= LW_REQHDR; |
| 2544 | } |
| 2545 | else if (!strcmp(args[1], "response") && !strcmp(args[2], "header")) { |
| 2546 | struct cap_hdr *hdr; |
| 2547 | |
| 2548 | if (curproxy == &defproxy) { |
| 2549 | 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] | 2550 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2551 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2552 | } |
| 2553 | |
| 2554 | if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) { |
| 2555 | Alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n", |
| 2556 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2557 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2558 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2559 | } |
| 2560 | hdr = calloc(sizeof(struct cap_hdr), 1); |
| 2561 | hdr->next = curproxy->rsp_cap; |
| 2562 | hdr->name = strdup(args[3]); |
| 2563 | hdr->namelen = strlen(args[3]); |
| 2564 | hdr->len = atol(args[5]); |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 2565 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2566 | hdr->index = curproxy->nb_rsp_cap++; |
| 2567 | curproxy->rsp_cap = hdr; |
| 2568 | curproxy->to_log |= LW_RSPHDR; |
| 2569 | } |
| 2570 | else { |
| 2571 | Alert("parsing [%s:%d] : '%s' expects 'cookie' or 'request header' or 'response header'.\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 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2577 | else if (!strcmp(args[0], "retries")) { /* connection retries */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2578 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2579 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2580 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2581 | if (*(args[1]) == 0) { |
| 2582 | Alert("parsing [%s:%d] : '%s' expects an integer argument (dispatch counts for one).\n", |
| 2583 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2584 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2585 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2586 | } |
| 2587 | curproxy->conn_retries = atol(args[1]); |
| 2588 | } |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2589 | 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] | 2590 | struct http_req_rule *rule; |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2591 | |
| 2592 | if (curproxy == &defproxy) { |
| 2593 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2594 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2595 | goto out; |
| 2596 | } |
| 2597 | |
Willy Tarreau | 20b0de5 | 2012-12-24 15:45:22 +0100 | [diff] [blame] | 2598 | if (!LIST_ISEMPTY(&curproxy->http_req_rules) && |
| 2599 | !LIST_PREV(&curproxy->http_req_rules, struct http_req_rule *, list)->cond && |
| 2600 | (LIST_PREV(&curproxy->http_req_rules, struct http_req_rule *, list)->action == HTTP_REQ_ACT_ALLOW || |
| 2601 | LIST_PREV(&curproxy->http_req_rules, struct http_req_rule *, list)->action == HTTP_REQ_ACT_DENY || |
| 2602 | LIST_PREV(&curproxy->http_req_rules, struct http_req_rule *, list)->action == HTTP_REQ_ACT_AUTH)) { |
| 2603 | Warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n", |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2604 | file, linenum, args[0]); |
| 2605 | err_code |= ERR_WARN; |
| 2606 | } |
| 2607 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 2608 | 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] | 2609 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 2610 | if (!rule) { |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2611 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2612 | goto out; |
| 2613 | } |
| 2614 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 2615 | err_code |= warnif_cond_requires_resp(rule->cond, file, linenum); |
| 2616 | LIST_ADDQ(&curproxy->http_req_rules, &rule->list); |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2617 | } |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 2618 | else if (!strcmp(args[0], "http-send-name-header")) { /* send server name in request header */ |
| 2619 | /* set the header name and length into the proxy structure */ |
| 2620 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 2621 | err_code |= ERR_WARN; |
| 2622 | |
| 2623 | if (!*args[1]) { |
| 2624 | Alert("parsing [%s:%d] : '%s' requires a header string.\n", |
| 2625 | file, linenum, args[0]); |
| 2626 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2627 | goto out; |
| 2628 | } |
| 2629 | |
| 2630 | /* set the desired header name */ |
| 2631 | free(curproxy->server_id_hdr_name); |
| 2632 | curproxy->server_id_hdr_name = strdup(args[1]); |
| 2633 | curproxy->server_id_hdr_len = strlen(curproxy->server_id_hdr_name); |
| 2634 | } |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2635 | else if (!strcmp(args[0], "block")) { /* early blocking based on ACLs */ |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2636 | if (curproxy == &defproxy) { |
| 2637 | 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] | 2638 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2639 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2640 | } |
| 2641 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2642 | if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) { |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2643 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 2644 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2645 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2646 | goto out; |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2647 | } |
| 2648 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 2649 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 1, &errmsg)) == NULL) { |
| 2650 | Alert("parsing [%s:%d] : error detected while parsing blocking condition : %s.\n", |
| 2651 | file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2652 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2653 | goto out; |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2654 | } |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2655 | |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2656 | LIST_ADDQ(&curproxy->block_cond, &cond->list); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 2657 | warnif_misplaced_block(curproxy, file, linenum, args[0]); |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2658 | } |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2659 | else if (!strcmp(args[0], "redirect")) { |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2660 | struct redirect_rule *rule; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2661 | |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 2662 | if (curproxy == &defproxy) { |
| 2663 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2664 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2665 | goto out; |
| 2666 | } |
| 2667 | |
Willy Tarreau | 4baae24 | 2012-12-27 12:00:31 +0100 | [diff] [blame] | 2668 | if ((rule = http_parse_redirect_rule(file, linenum, curproxy, (const char **)args + 1, &errmsg)) == NULL) { |
| 2669 | Alert("parsing [%s:%d] : error detected in %s '%s' while parsing redirect rule : %s.\n", |
| 2670 | file, linenum, proxy_type_str(curproxy), curproxy->id, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2671 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2672 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2673 | } |
| 2674 | |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2675 | LIST_ADDQ(&curproxy->redirect_rules, &rule->list); |
Willy Tarreau | 9d9ed01 | 2011-02-23 15:24:42 +0100 | [diff] [blame] | 2676 | err_code |= warnif_rule_after_use_backend(curproxy, file, linenum, args[0]); |
| 2677 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2678 | } |
Krzysztof Piotr Oledzki | 7b723ef | 2009-01-27 21:09:41 +0100 | [diff] [blame] | 2679 | else if (!strcmp(args[0], "use_backend")) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2680 | struct switching_rule *rule; |
| 2681 | |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2682 | if (curproxy == &defproxy) { |
| 2683 | 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] | 2684 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2685 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2686 | } |
| 2687 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2688 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2689 | err_code |= ERR_WARN; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2690 | |
| 2691 | if (*(args[1]) == 0) { |
| 2692 | 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] | 2693 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2694 | goto out; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2695 | } |
| 2696 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2697 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2698 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 2699 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2700 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2701 | goto out; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2702 | } |
| 2703 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 2704 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 2705 | Alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n", |
| 2706 | file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2707 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2708 | goto out; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2709 | } |
| 2710 | |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 2711 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
Willy Tarreau | a980263 | 2008-07-25 19:13:19 +0200 | [diff] [blame] | 2712 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2713 | rule = (struct switching_rule *)calloc(1, sizeof(*rule)); |
| 2714 | rule->cond = cond; |
| 2715 | rule->be.name = strdup(args[1]); |
| 2716 | LIST_INIT(&rule->list); |
| 2717 | LIST_ADDQ(&curproxy->switching_rules, &rule->list); |
| 2718 | } |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 2719 | else if (strcmp(args[0], "use-server") == 0) { |
| 2720 | struct server_rule *rule; |
| 2721 | |
| 2722 | if (curproxy == &defproxy) { |
| 2723 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2724 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2725 | goto out; |
| 2726 | } |
| 2727 | |
| 2728 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 2729 | err_code |= ERR_WARN; |
| 2730 | |
| 2731 | if (*(args[1]) == 0) { |
| 2732 | Alert("parsing [%s:%d] : '%s' expects a server name.\n", file, linenum, args[0]); |
| 2733 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2734 | goto out; |
| 2735 | } |
| 2736 | |
| 2737 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
| 2738 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 2739 | file, linenum, args[0]); |
| 2740 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2741 | goto out; |
| 2742 | } |
| 2743 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 2744 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 2745 | Alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n", |
| 2746 | file, linenum, errmsg); |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 2747 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2748 | goto out; |
| 2749 | } |
| 2750 | |
| 2751 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
| 2752 | |
| 2753 | rule = (struct server_rule *)calloc(1, sizeof(*rule)); |
| 2754 | rule->cond = cond; |
| 2755 | rule->srv.name = strdup(args[1]); |
| 2756 | LIST_INIT(&rule->list); |
| 2757 | LIST_ADDQ(&curproxy->server_rules, &rule->list); |
| 2758 | curproxy->be_req_ana |= AN_REQ_SRV_RULES; |
| 2759 | } |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 2760 | else if ((!strcmp(args[0], "force-persist")) || |
| 2761 | (!strcmp(args[0], "ignore-persist"))) { |
| 2762 | struct persist_rule *rule; |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2763 | |
| 2764 | if (curproxy == &defproxy) { |
| 2765 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2766 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2767 | goto out; |
| 2768 | } |
| 2769 | |
| 2770 | if (warnifnotcap(curproxy, PR_CAP_FE|PR_CAP_BE, file, linenum, args[0], NULL)) |
| 2771 | err_code |= ERR_WARN; |
| 2772 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2773 | if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) { |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2774 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 2775 | file, linenum, args[0]); |
| 2776 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2777 | goto out; |
| 2778 | } |
| 2779 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 2780 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 1, &errmsg)) == NULL) { |
| 2781 | Alert("parsing [%s:%d] : error detected while parsing a '%s' rule : %s.\n", |
| 2782 | file, linenum, args[0], errmsg); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2783 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2784 | goto out; |
| 2785 | } |
| 2786 | |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 2787 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2788 | |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 2789 | rule = (struct persist_rule *)calloc(1, sizeof(*rule)); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2790 | rule->cond = cond; |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 2791 | if (!strcmp(args[0], "force-persist")) { |
| 2792 | rule->type = PERSIST_TYPE_FORCE; |
| 2793 | } else { |
| 2794 | rule->type = PERSIST_TYPE_IGNORE; |
| 2795 | } |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2796 | LIST_INIT(&rule->list); |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 2797 | LIST_ADDQ(&curproxy->persist_rules, &rule->list); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2798 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2799 | else if (!strcmp(args[0], "stick-table")) { |
| 2800 | int myidx = 1; |
| 2801 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2802 | curproxy->table.id = curproxy->id; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2803 | curproxy->table.type = (unsigned int)-1; |
| 2804 | while (*args[myidx]) { |
| 2805 | const char *err; |
| 2806 | |
| 2807 | if (strcmp(args[myidx], "size") == 0) { |
| 2808 | myidx++; |
| 2809 | if (!*(args[myidx])) { |
| 2810 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 2811 | file, linenum, args[myidx-1]); |
| 2812 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2813 | goto out; |
| 2814 | } |
| 2815 | if ((err = parse_size_err(args[myidx], &curproxy->table.size))) { |
| 2816 | Alert("parsing [%s:%d] : stick-table: unexpected character '%c' in argument of '%s'.\n", |
| 2817 | file, linenum, *err, args[myidx-1]); |
| 2818 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2819 | goto out; |
| 2820 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 2821 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2822 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2823 | else if (strcmp(args[myidx], "peers") == 0) { |
| 2824 | myidx++; |
| 2825 | if (!*(args[myidx])) { |
| 2826 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 2827 | file, linenum, args[myidx-1]); |
| 2828 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2829 | goto out; |
| 2830 | } |
| 2831 | curproxy->table.peers.name = strdup(args[myidx++]); |
| 2832 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2833 | else if (strcmp(args[myidx], "expire") == 0) { |
| 2834 | myidx++; |
| 2835 | if (!*(args[myidx])) { |
| 2836 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 2837 | file, linenum, args[myidx-1]); |
| 2838 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2839 | goto out; |
| 2840 | } |
| 2841 | err = parse_time_err(args[myidx], &val, TIME_UNIT_MS); |
| 2842 | if (err) { |
| 2843 | Alert("parsing [%s:%d] : stick-table: unexpected character '%c' in argument of '%s'.\n", |
| 2844 | file, linenum, *err, args[myidx-1]); |
| 2845 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2846 | goto out; |
| 2847 | } |
| 2848 | curproxy->table.expire = val; |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 2849 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2850 | } |
| 2851 | else if (strcmp(args[myidx], "nopurge") == 0) { |
| 2852 | curproxy->table.nopurge = 1; |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 2853 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2854 | } |
| 2855 | else if (strcmp(args[myidx], "type") == 0) { |
| 2856 | myidx++; |
| 2857 | if (stktable_parse_type(args, &myidx, &curproxy->table.type, &curproxy->table.key_size) != 0) { |
| 2858 | Alert("parsing [%s:%d] : stick-table: unknown type '%s'.\n", |
| 2859 | file, linenum, args[myidx]); |
| 2860 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2861 | goto out; |
| 2862 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 2863 | /* myidx already points to next arg */ |
| 2864 | } |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 2865 | else if (strcmp(args[myidx], "store") == 0) { |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 2866 | int type, err; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 2867 | char *cw, *nw, *sa; |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 2868 | |
| 2869 | myidx++; |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 2870 | nw = args[myidx]; |
| 2871 | while (*nw) { |
| 2872 | /* the "store" keyword supports a comma-separated list */ |
| 2873 | cw = nw; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 2874 | sa = NULL; /* store arg */ |
| 2875 | while (*nw && *nw != ',') { |
| 2876 | if (*nw == '(') { |
| 2877 | *nw = 0; |
| 2878 | sa = ++nw; |
| 2879 | while (*nw != ')') { |
| 2880 | if (!*nw) { |
| 2881 | Alert("parsing [%s:%d] : %s: missing closing parenthesis after store option '%s'.\n", |
| 2882 | file, linenum, args[0], cw); |
| 2883 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2884 | goto out; |
| 2885 | } |
| 2886 | nw++; |
| 2887 | } |
| 2888 | *nw = '\0'; |
| 2889 | } |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 2890 | nw++; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 2891 | } |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 2892 | if (*nw) |
| 2893 | *nw++ = '\0'; |
| 2894 | type = stktable_get_data_type(cw); |
| 2895 | if (type < 0) { |
| 2896 | Alert("parsing [%s:%d] : %s: unknown store option '%s'.\n", |
| 2897 | file, linenum, args[0], cw); |
| 2898 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2899 | goto out; |
| 2900 | } |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 2901 | |
| 2902 | err = stktable_alloc_data_type(&curproxy->table, type, sa); |
| 2903 | switch (err) { |
| 2904 | case PE_NONE: break; |
| 2905 | case PE_EXIST: |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 2906 | Warning("parsing [%s:%d]: %s: store option '%s' already enabled, ignored.\n", |
| 2907 | file, linenum, args[0], cw); |
| 2908 | err_code |= ERR_WARN; |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 2909 | break; |
| 2910 | |
| 2911 | case PE_ARG_MISSING: |
| 2912 | Alert("parsing [%s:%d] : %s: missing argument to store option '%s'.\n", |
| 2913 | file, linenum, args[0], cw); |
| 2914 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2915 | goto out; |
| 2916 | |
| 2917 | case PE_ARG_NOT_USED: |
| 2918 | Alert("parsing [%s:%d] : %s: unexpected argument to store option '%s'.\n", |
| 2919 | file, linenum, args[0], cw); |
| 2920 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2921 | goto out; |
| 2922 | |
| 2923 | default: |
| 2924 | Alert("parsing [%s:%d] : %s: error when processing store option '%s'.\n", |
| 2925 | file, linenum, args[0], cw); |
| 2926 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2927 | goto out; |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 2928 | } |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 2929 | } |
| 2930 | myidx++; |
| 2931 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 2932 | else { |
| 2933 | Alert("parsing [%s:%d] : stick-table: unknown argument '%s'.\n", |
| 2934 | file, linenum, args[myidx]); |
| 2935 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2936 | goto out; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2937 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2938 | } |
| 2939 | |
| 2940 | if (!curproxy->table.size) { |
| 2941 | Alert("parsing [%s:%d] : stick-table: missing size.\n", |
| 2942 | file, linenum); |
| 2943 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2944 | goto out; |
| 2945 | } |
| 2946 | |
| 2947 | if (curproxy->table.type == (unsigned int)-1) { |
| 2948 | Alert("parsing [%s:%d] : stick-table: missing type.\n", |
| 2949 | file, linenum); |
| 2950 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2951 | goto out; |
| 2952 | } |
| 2953 | } |
| 2954 | else if (!strcmp(args[0], "stick")) { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2955 | struct sticking_rule *rule; |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 2956 | struct sample_expr *expr; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2957 | int myidx = 0; |
| 2958 | const char *name = NULL; |
| 2959 | int flags; |
| 2960 | |
| 2961 | if (curproxy == &defproxy) { |
| 2962 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2963 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2964 | goto out; |
| 2965 | } |
| 2966 | |
| 2967 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) { |
| 2968 | err_code |= ERR_WARN; |
| 2969 | goto out; |
| 2970 | } |
| 2971 | |
| 2972 | myidx++; |
| 2973 | if ((strcmp(args[myidx], "store") == 0) || |
| 2974 | (strcmp(args[myidx], "store-request") == 0)) { |
| 2975 | myidx++; |
| 2976 | flags = STK_IS_STORE; |
| 2977 | } |
| 2978 | else if (strcmp(args[myidx], "store-response") == 0) { |
| 2979 | myidx++; |
| 2980 | flags = STK_IS_STORE | STK_ON_RSP; |
| 2981 | } |
| 2982 | else if (strcmp(args[myidx], "match") == 0) { |
| 2983 | myidx++; |
| 2984 | flags = STK_IS_MATCH; |
| 2985 | } |
| 2986 | else if (strcmp(args[myidx], "on") == 0) { |
| 2987 | myidx++; |
| 2988 | flags = STK_IS_MATCH | STK_IS_STORE; |
| 2989 | } |
| 2990 | else { |
| 2991 | Alert("parsing [%s:%d] : '%s' expects 'on', 'match', or 'store'.\n", file, linenum, args[0]); |
| 2992 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2993 | goto out; |
| 2994 | } |
| 2995 | |
| 2996 | if (*(args[myidx]) == 0) { |
| 2997 | Alert("parsing [%s:%d] : '%s' expects a fetch method.\n", file, linenum, args[0]); |
| 2998 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2999 | goto out; |
| 3000 | } |
| 3001 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3002 | expr = sample_parse_expr(args, &myidx, trash.str, trash.size); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3003 | if (!expr) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3004 | 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] | 3005 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3006 | goto out; |
| 3007 | } |
| 3008 | |
| 3009 | if (flags & STK_ON_RSP) { |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 3010 | if (!(expr->fetch->cap & SMP_CAP_RES)) { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3011 | Alert("parsing [%s:%d] : '%s': fetch method '%s' can not be used on response.\n", |
| 3012 | file, linenum, args[0], expr->fetch->kw); |
| 3013 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 3014 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3015 | goto out; |
| 3016 | } |
| 3017 | } else { |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 3018 | if (!(expr->fetch->cap & SMP_CAP_REQ)) { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3019 | Alert("parsing [%s:%d] : '%s': fetch method '%s' can not be used on request.\n", |
| 3020 | file, linenum, args[0], expr->fetch->kw); |
| 3021 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 3022 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3023 | goto out; |
| 3024 | } |
| 3025 | } |
| 3026 | |
Willy Tarreau | 1b6c00c | 2012-10-05 22:41:26 +0200 | [diff] [blame] | 3027 | /* check if we need to allocate an hdr_idx struct for HTTP parsing */ |
| 3028 | if (expr->fetch->cap & SMP_CAP_L7) |
| 3029 | curproxy->acl_requires |= ACL_USE_L7_ANY; |
| 3030 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3031 | if (strcmp(args[myidx], "table") == 0) { |
| 3032 | myidx++; |
| 3033 | name = args[myidx++]; |
| 3034 | } |
| 3035 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 3036 | if (strcmp(args[myidx], "if") == 0 || strcmp(args[myidx], "unless") == 0) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 3037 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + myidx, &errmsg)) == NULL) { |
| 3038 | Alert("parsing [%s:%d] : '%s': error detected while parsing sticking condition : %s.\n", |
| 3039 | file, linenum, args[0], errmsg); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3040 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 3041 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3042 | goto out; |
| 3043 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3044 | } |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 3045 | else if (*(args[myidx])) { |
| 3046 | Alert("parsing [%s:%d] : '%s': unknown keyword '%s'.\n", |
| 3047 | file, linenum, args[0], args[myidx]); |
| 3048 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 3049 | free(expr); |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 3050 | goto out; |
| 3051 | } |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 3052 | if (flags & STK_ON_RSP) |
| 3053 | err_code |= warnif_cond_requires_req(cond, file, linenum); |
| 3054 | else |
| 3055 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 3056 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3057 | rule = (struct sticking_rule *)calloc(1, sizeof(*rule)); |
| 3058 | rule->cond = cond; |
| 3059 | rule->expr = expr; |
| 3060 | rule->flags = flags; |
| 3061 | rule->table.name = name ? strdup(name) : NULL; |
| 3062 | LIST_INIT(&rule->list); |
| 3063 | if (flags & STK_ON_RSP) |
| 3064 | LIST_ADDQ(&curproxy->storersp_rules, &rule->list); |
| 3065 | else |
| 3066 | LIST_ADDQ(&curproxy->sticking_rules, &rule->list); |
| 3067 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3068 | else if (!strcmp(args[0], "stats")) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3069 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3070 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3071 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3072 | if (curproxy != &defproxy && curproxy->uri_auth == defproxy.uri_auth) |
| 3073 | curproxy->uri_auth = NULL; /* we must detach from the default config */ |
| 3074 | |
Krzysztof Piotr Oledzki | 260a3bb | 2010-01-06 16:25:05 +0100 | [diff] [blame] | 3075 | if (!*args[1]) { |
| 3076 | goto stats_error_parsing; |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3077 | } else if (!strcmp(args[1], "admin")) { |
| 3078 | struct stats_admin_rule *rule; |
| 3079 | |
| 3080 | if (curproxy == &defproxy) { |
| 3081 | Alert("parsing [%s:%d]: '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
| 3082 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3083 | goto out; |
| 3084 | } |
| 3085 | |
| 3086 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 3087 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3088 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3089 | goto out; |
| 3090 | } |
| 3091 | |
| 3092 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
| 3093 | Alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n", |
| 3094 | file, linenum, args[0], args[1]); |
| 3095 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3096 | goto out; |
| 3097 | } |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 3098 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 3099 | Alert("parsing [%s:%d] : error detected while parsing a '%s %s' rule : %s.\n", |
| 3100 | file, linenum, args[0], args[1], errmsg); |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3101 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3102 | goto out; |
| 3103 | } |
| 3104 | |
| 3105 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
| 3106 | |
| 3107 | rule = (struct stats_admin_rule *)calloc(1, sizeof(*rule)); |
| 3108 | rule->cond = cond; |
| 3109 | LIST_INIT(&rule->list); |
| 3110 | LIST_ADDQ(&curproxy->uri_auth->admin_rules, &rule->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3111 | } else if (!strcmp(args[1], "uri")) { |
| 3112 | if (*(args[2]) == 0) { |
| 3113 | Alert("parsing [%s:%d] : 'uri' needs an URI prefix.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3114 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3115 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3116 | } else if (!stats_set_uri(&curproxy->uri_auth, args[2])) { |
| 3117 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3118 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3119 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3120 | } |
| 3121 | } else if (!strcmp(args[1], "realm")) { |
| 3122 | if (*(args[2]) == 0) { |
| 3123 | Alert("parsing [%s:%d] : 'realm' needs an realm name.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3124 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3125 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3126 | } else if (!stats_set_realm(&curproxy->uri_auth, args[2])) { |
| 3127 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3128 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3129 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3130 | } |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 3131 | } else if (!strcmp(args[1], "refresh")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 3132 | unsigned interval; |
| 3133 | |
| 3134 | err = parse_time_err(args[2], &interval, TIME_UNIT_S); |
| 3135 | if (err) { |
| 3136 | Alert("parsing [%s:%d] : unexpected character '%c' in stats refresh interval.\n", |
| 3137 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3138 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3139 | goto out; |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 3140 | } else if (!stats_set_refresh(&curproxy->uri_auth, interval)) { |
| 3141 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3142 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3143 | goto out; |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 3144 | } |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3145 | } 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] | 3146 | struct http_req_rule *rule; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3147 | |
| 3148 | if (curproxy == &defproxy) { |
| 3149 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3150 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3151 | goto out; |
| 3152 | } |
| 3153 | |
| 3154 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 3155 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3156 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3157 | goto out; |
| 3158 | } |
| 3159 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3160 | if (!LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) && |
| 3161 | !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] | 3162 | Warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n", |
| 3163 | file, linenum, args[0]); |
| 3164 | err_code |= ERR_WARN; |
| 3165 | } |
| 3166 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3167 | 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] | 3168 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3169 | if (!rule) { |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3170 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3171 | goto out; |
| 3172 | } |
| 3173 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3174 | err_code |= warnif_cond_requires_resp(rule->cond, file, linenum); |
| 3175 | LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list); |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3176 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3177 | } else if (!strcmp(args[1], "auth")) { |
| 3178 | if (*(args[2]) == 0) { |
| 3179 | 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] | 3180 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3181 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3182 | } else if (!stats_add_auth(&curproxy->uri_auth, args[2])) { |
| 3183 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3184 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3185 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3186 | } |
| 3187 | } else if (!strcmp(args[1], "scope")) { |
| 3188 | if (*(args[2]) == 0) { |
| 3189 | Alert("parsing [%s:%d] : 'scope' needs a proxy name.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3190 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3191 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3192 | } else if (!stats_add_scope(&curproxy->uri_auth, args[2])) { |
| 3193 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3194 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3195 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3196 | } |
| 3197 | } else if (!strcmp(args[1], "enable")) { |
| 3198 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 3199 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3200 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3201 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3202 | } |
Krzysztof Oledzki | d9db927 | 2007-10-15 10:05:11 +0200 | [diff] [blame] | 3203 | } else if (!strcmp(args[1], "hide-version")) { |
| 3204 | if (!stats_set_flag(&curproxy->uri_auth, ST_HIDEVER)) { |
| 3205 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3206 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3207 | goto out; |
Krzysztof Oledzki | d9db927 | 2007-10-15 10:05:11 +0200 | [diff] [blame] | 3208 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3209 | } else if (!strcmp(args[1], "show-legends")) { |
| 3210 | if (!stats_set_flag(&curproxy->uri_auth, ST_SHLGNDS)) { |
| 3211 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3212 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3213 | goto out; |
| 3214 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3215 | } else if (!strcmp(args[1], "show-node")) { |
| 3216 | |
| 3217 | if (*args[2]) { |
| 3218 | int i; |
| 3219 | char c; |
| 3220 | |
| 3221 | for (i=0; args[2][i]; i++) { |
| 3222 | c = args[2][i]; |
Willy Tarreau | 88e0581 | 2010-03-03 00:16:00 +0100 | [diff] [blame] | 3223 | if (!isupper((unsigned char)c) && !islower((unsigned char)c) && |
| 3224 | !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.') |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3225 | break; |
| 3226 | } |
| 3227 | |
| 3228 | if (!i || args[2][i]) { |
| 3229 | Alert("parsing [%s:%d]: '%s %s' invalid node name - should be a string" |
| 3230 | "with digits(0-9), letters(A-Z, a-z), hyphen(-) or underscode(_).\n", |
| 3231 | file, linenum, args[0], args[1]); |
| 3232 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3233 | goto out; |
| 3234 | } |
| 3235 | } |
| 3236 | |
| 3237 | if (!stats_set_node(&curproxy->uri_auth, args[2])) { |
| 3238 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3239 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3240 | goto out; |
| 3241 | } |
| 3242 | } else if (!strcmp(args[1], "show-desc")) { |
| 3243 | char *desc = NULL; |
| 3244 | |
| 3245 | if (*args[2]) { |
| 3246 | int i, len=0; |
| 3247 | char *d; |
| 3248 | |
| 3249 | for(i=2; *args[i]; i++) |
| 3250 | len += strlen(args[i])+1; |
| 3251 | |
| 3252 | desc = d = (char *)calloc(1, len); |
| 3253 | |
| 3254 | d += sprintf(d, "%s", args[2]); |
| 3255 | for(i=3; *args[i]; i++) |
| 3256 | d += sprintf(d, " %s", args[i]); |
| 3257 | } |
| 3258 | |
| 3259 | if (!*args[2] && !global.desc) |
| 3260 | Warning("parsing [%s:%d]: '%s' requires a parameter or 'desc' to be set in the global section.\n", |
| 3261 | file, linenum, args[1]); |
| 3262 | else { |
| 3263 | if (!stats_set_desc(&curproxy->uri_auth, desc)) { |
| 3264 | free(desc); |
| 3265 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3266 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3267 | goto out; |
| 3268 | } |
| 3269 | free(desc); |
| 3270 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3271 | } else { |
Krzysztof Piotr Oledzki | 260a3bb | 2010-01-06 16:25:05 +0100 | [diff] [blame] | 3272 | stats_error_parsing: |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3273 | 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] | 3274 | 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] | 3275 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3276 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3277 | } |
| 3278 | } |
| 3279 | else if (!strcmp(args[0], "option")) { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3280 | int optnum; |
| 3281 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3282 | if (*(args[1]) == '\0') { |
| 3283 | Alert("parsing [%s:%d]: '%s' expects an option name.\n", |
| 3284 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3285 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3286 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3287 | } |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3288 | |
| 3289 | for (optnum = 0; cfg_opts[optnum].name; optnum++) { |
| 3290 | if (!strcmp(args[1], cfg_opts[optnum].name)) { |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 3291 | if (cfg_opts[optnum].cap == PR_CAP_NONE) { |
| 3292 | Alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n", |
| 3293 | file, linenum, cfg_opts[optnum].name); |
| 3294 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3295 | goto out; |
| 3296 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3297 | if (warnifnotcap(curproxy, cfg_opts[optnum].cap, file, linenum, args[1], NULL)) { |
| 3298 | err_code |= ERR_WARN; |
| 3299 | goto out; |
| 3300 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3301 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 3302 | curproxy->no_options &= ~cfg_opts[optnum].val; |
| 3303 | curproxy->options &= ~cfg_opts[optnum].val; |
| 3304 | |
| 3305 | switch (kwm) { |
| 3306 | case KWM_STD: |
| 3307 | curproxy->options |= cfg_opts[optnum].val; |
| 3308 | break; |
| 3309 | case KWM_NO: |
| 3310 | curproxy->no_options |= cfg_opts[optnum].val; |
| 3311 | break; |
| 3312 | case KWM_DEF: /* already cleared */ |
| 3313 | break; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 3314 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3315 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3316 | goto out; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3317 | } |
| 3318 | } |
| 3319 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 3320 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) { |
| 3321 | if (!strcmp(args[1], cfg_opts2[optnum].name)) { |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 3322 | if (cfg_opts2[optnum].cap == PR_CAP_NONE) { |
| 3323 | Alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n", |
| 3324 | file, linenum, cfg_opts2[optnum].name); |
| 3325 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3326 | goto out; |
| 3327 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3328 | if (warnifnotcap(curproxy, cfg_opts2[optnum].cap, file, linenum, args[1], NULL)) { |
| 3329 | err_code |= ERR_WARN; |
| 3330 | goto out; |
| 3331 | } |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 3332 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 3333 | curproxy->no_options2 &= ~cfg_opts2[optnum].val; |
| 3334 | curproxy->options2 &= ~cfg_opts2[optnum].val; |
| 3335 | |
| 3336 | switch (kwm) { |
| 3337 | case KWM_STD: |
| 3338 | curproxy->options2 |= cfg_opts2[optnum].val; |
| 3339 | break; |
| 3340 | case KWM_NO: |
| 3341 | curproxy->no_options2 |= cfg_opts2[optnum].val; |
| 3342 | break; |
| 3343 | case KWM_DEF: /* already cleared */ |
| 3344 | break; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 3345 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3346 | goto out; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 3347 | } |
| 3348 | } |
| 3349 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 3350 | if (kwm != KWM_STD) { |
| 3351 | 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] | 3352 | file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3353 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3354 | goto out; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3355 | } |
| 3356 | |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3357 | if (!strcmp(args[1], "httplog")) { |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 3358 | char *logformat; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3359 | /* generate a complete HTTP log */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 3360 | logformat = default_http_log_format; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3361 | if (*(args[2]) != '\0') { |
| 3362 | if (!strcmp(args[2], "clf")) { |
| 3363 | curproxy->options2 |= PR_O2_CLFLOG; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 3364 | logformat = clf_http_log_format; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3365 | } else { |
| 3366 | 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] | 3367 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3368 | goto out; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3369 | } |
| 3370 | } |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 3371 | if (curproxy->logformat_string != default_http_log_format && |
| 3372 | curproxy->logformat_string != default_tcp_log_format && |
| 3373 | curproxy->logformat_string != clf_http_log_format) |
| 3374 | free(curproxy->logformat_string); |
| 3375 | curproxy->logformat_string = logformat; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3376 | } |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 3377 | else if (!strcmp(args[1], "tcplog")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3378 | /* generate a detailed TCP log */ |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 3379 | if (curproxy->logformat_string != default_http_log_format && |
| 3380 | curproxy->logformat_string != default_tcp_log_format && |
| 3381 | curproxy->logformat_string != clf_http_log_format) |
| 3382 | free(curproxy->logformat_string); |
| 3383 | curproxy->logformat_string = default_tcp_log_format; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 3384 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3385 | else if (!strcmp(args[1], "tcpka")) { |
| 3386 | /* enable TCP keep-alives on client and server sessions */ |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3387 | 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] | 3388 | err_code |= ERR_WARN; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3389 | |
| 3390 | if (curproxy->cap & PR_CAP_FE) |
| 3391 | curproxy->options |= PR_O_TCP_CLI_KA; |
| 3392 | if (curproxy->cap & PR_CAP_BE) |
| 3393 | curproxy->options |= PR_O_TCP_SRV_KA; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3394 | } |
| 3395 | else if (!strcmp(args[1], "httpchk")) { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3396 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3397 | err_code |= ERR_WARN; |
| 3398 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3399 | /* use HTTP request to check servers' health */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3400 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 3401 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3402 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 3403 | curproxy->options2 |= PR_O2_HTTP_CHK; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3404 | if (!*args[2]) { /* no argument */ |
| 3405 | curproxy->check_req = strdup(DEF_CHECK_REQ); /* default request */ |
| 3406 | curproxy->check_len = strlen(DEF_CHECK_REQ); |
| 3407 | } else if (!*args[3]) { /* one argument : URI */ |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3408 | 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] | 3409 | curproxy->check_req = (char *)malloc(reqlen); |
| 3410 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3411 | "OPTIONS %s HTTP/1.0\r\n", args[2]); /* URI to use */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3412 | } else { /* more arguments : METHOD URI [HTTP_VER] */ |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3413 | int reqlen = strlen(args[2]) + strlen(args[3]) + 3 + strlen("\r\n"); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3414 | if (*args[4]) |
| 3415 | reqlen += strlen(args[4]); |
| 3416 | else |
| 3417 | reqlen += strlen("HTTP/1.0"); |
| 3418 | |
| 3419 | curproxy->check_req = (char *)malloc(reqlen); |
| 3420 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3421 | "%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] | 3422 | } |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 3423 | } |
| 3424 | else if (!strcmp(args[1], "ssl-hello-chk")) { |
| 3425 | /* use SSLv3 CLIENT HELLO to check servers' health */ |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3426 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3427 | err_code |= ERR_WARN; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3428 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3429 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 3430 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3431 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Willy Tarreau | 07a5490 | 2010-03-29 18:33:29 +0200 | [diff] [blame] | 3432 | curproxy->options2 |= PR_O2_SSL3_CHK; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3433 | } |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 3434 | else if (!strcmp(args[1], "smtpchk")) { |
| 3435 | /* use SMTP request to check servers' health */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3436 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 3437 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3438 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 3439 | curproxy->options2 |= PR_O2_SMTP_CHK; |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 3440 | |
| 3441 | if (!*args[2] || !*args[3]) { /* no argument or incomplete EHLO host */ |
| 3442 | curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */ |
| 3443 | curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ); |
| 3444 | } else { /* ESMTP EHLO, or SMTP HELO, and a hostname */ |
| 3445 | if (!strcmp(args[2], "EHLO") || !strcmp(args[2], "HELO")) { |
| 3446 | int reqlen = strlen(args[2]) + strlen(args[3]) + strlen(" \r\n") + 1; |
| 3447 | curproxy->check_req = (char *)malloc(reqlen); |
| 3448 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
| 3449 | "%s %s\r\n", args[2], args[3]); /* HELO hostname */ |
| 3450 | } else { |
| 3451 | /* this just hits the default for now, but you could potentially expand it to allow for other stuff |
| 3452 | though, it's unlikely you'd want to send anything other than an EHLO or HELO */ |
| 3453 | curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */ |
| 3454 | curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ); |
| 3455 | } |
| 3456 | } |
| 3457 | } |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 3458 | else if (!strcmp(args[1], "pgsql-check")) { |
| 3459 | /* use PostgreSQL request to check servers' health */ |
| 3460 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 3461 | err_code |= ERR_WARN; |
| 3462 | |
| 3463 | free(curproxy->check_req); |
| 3464 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3465 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 3466 | curproxy->options2 |= PR_O2_PGSQL_CHK; |
| 3467 | |
| 3468 | if (*(args[2])) { |
| 3469 | int cur_arg = 2; |
| 3470 | |
| 3471 | while (*(args[cur_arg])) { |
| 3472 | if (strcmp(args[cur_arg], "user") == 0) { |
| 3473 | char * packet; |
| 3474 | uint32_t packet_len; |
| 3475 | uint32_t pv; |
| 3476 | |
| 3477 | /* suboption header - needs additional argument for it */ |
| 3478 | if (*(args[cur_arg+1]) == 0) { |
| 3479 | Alert("parsing [%s:%d] : '%s %s %s' expects <username> as argument.\n", |
| 3480 | file, linenum, args[0], args[1], args[cur_arg]); |
| 3481 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3482 | goto out; |
| 3483 | } |
| 3484 | |
| 3485 | /* uint32_t + uint32_t + strlen("user")+1 + strlen(username)+1 + 1 */ |
| 3486 | packet_len = 4 + 4 + 5 + strlen(args[cur_arg + 1])+1 +1; |
| 3487 | pv = htonl(0x30000); /* protocol version 3.0 */ |
| 3488 | |
| 3489 | packet = (char*) calloc(1, packet_len); |
| 3490 | |
| 3491 | memcpy(packet + 4, &pv, 4); |
| 3492 | |
| 3493 | /* copy "user" */ |
| 3494 | memcpy(packet + 8, "user", 4); |
| 3495 | |
| 3496 | /* copy username */ |
| 3497 | memcpy(packet + 13, args[cur_arg+1], strlen(args[cur_arg+1])); |
| 3498 | |
| 3499 | free(curproxy->check_req); |
| 3500 | curproxy->check_req = packet; |
| 3501 | curproxy->check_len = packet_len; |
| 3502 | |
| 3503 | packet_len = htonl(packet_len); |
| 3504 | memcpy(packet, &packet_len, 4); |
| 3505 | cur_arg += 2; |
| 3506 | } else { |
| 3507 | /* unknown suboption - catchall */ |
| 3508 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'user'.\n", |
| 3509 | file, linenum, args[0], args[1]); |
| 3510 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3511 | goto out; |
| 3512 | } |
| 3513 | } /* end while loop */ |
| 3514 | } |
| 3515 | } |
| 3516 | |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 3517 | else if (!strcmp(args[1], "redis-check")) { |
| 3518 | /* use REDIS PING request to check servers' health */ |
| 3519 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 3520 | err_code |= ERR_WARN; |
| 3521 | |
| 3522 | free(curproxy->check_req); |
| 3523 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3524 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 3525 | curproxy->options2 |= PR_O2_REDIS_CHK; |
| 3526 | |
| 3527 | curproxy->check_req = (char *) malloc(sizeof(DEF_REDIS_CHECK_REQ) - 1); |
| 3528 | memcpy(curproxy->check_req, DEF_REDIS_CHECK_REQ, sizeof(DEF_REDIS_CHECK_REQ) - 1); |
| 3529 | curproxy->check_len = sizeof(DEF_REDIS_CHECK_REQ) - 1; |
| 3530 | } |
| 3531 | |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 3532 | else if (!strcmp(args[1], "mysql-check")) { |
| 3533 | /* use MYSQL request to check servers' health */ |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 3534 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 3535 | err_code |= ERR_WARN; |
| 3536 | |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 3537 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 3538 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3539 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 3540 | curproxy->options2 |= PR_O2_MYSQL_CHK; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 3541 | |
| 3542 | /* This is an exemple of an MySQL >=4.0 client Authentication packet kindly provided by Cyril Bonte. |
| 3543 | * const char mysql40_client_auth_pkt[] = { |
| 3544 | * "\x0e\x00\x00" // packet length |
| 3545 | * "\x01" // packet number |
| 3546 | * "\x00\x00" // client capabilities |
| 3547 | * "\x00\x00\x01" // max packet |
| 3548 | * "haproxy\x00" // username (null terminated string) |
| 3549 | * "\x00" // filler (always 0x00) |
| 3550 | * "\x01\x00\x00" // packet length |
| 3551 | * "\x00" // packet number |
| 3552 | * "\x01" // COM_QUIT command |
| 3553 | * }; |
| 3554 | */ |
| 3555 | |
| 3556 | if (*(args[2])) { |
| 3557 | int cur_arg = 2; |
| 3558 | |
| 3559 | while (*(args[cur_arg])) { |
| 3560 | if (strcmp(args[cur_arg], "user") == 0) { |
| 3561 | char *mysqluser; |
| 3562 | int packetlen, reqlen, userlen; |
| 3563 | |
| 3564 | /* suboption header - needs additional argument for it */ |
| 3565 | if (*(args[cur_arg+1]) == 0) { |
| 3566 | Alert("parsing [%s:%d] : '%s %s %s' expects <username> as argument.\n", |
| 3567 | file, linenum, args[0], args[1], args[cur_arg]); |
| 3568 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3569 | goto out; |
| 3570 | } |
| 3571 | mysqluser = args[cur_arg + 1]; |
| 3572 | userlen = strlen(mysqluser); |
| 3573 | packetlen = userlen + 7; |
| 3574 | reqlen = packetlen + 9; |
| 3575 | |
| 3576 | free(curproxy->check_req); |
| 3577 | curproxy->check_req = (char *)calloc(1, reqlen); |
| 3578 | curproxy->check_len = reqlen; |
| 3579 | |
| 3580 | snprintf(curproxy->check_req, 4, "%c%c%c", |
| 3581 | ((unsigned char) packetlen & 0xff), |
| 3582 | ((unsigned char) (packetlen >> 8) & 0xff), |
| 3583 | ((unsigned char) (packetlen >> 16) & 0xff)); |
| 3584 | |
| 3585 | curproxy->check_req[3] = 1; |
Hervé COMMOWICK | 212f778 | 2011-06-10 14:05:59 +0200 | [diff] [blame] | 3586 | curproxy->check_req[5] = 128; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 3587 | curproxy->check_req[8] = 1; |
| 3588 | memcpy(&curproxy->check_req[9], mysqluser, userlen); |
| 3589 | curproxy->check_req[9 + userlen + 1 + 1] = 1; |
| 3590 | curproxy->check_req[9 + userlen + 1 + 1 + 4] = 1; |
| 3591 | cur_arg += 2; |
| 3592 | } else { |
| 3593 | /* unknown suboption - catchall */ |
| 3594 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'user'.\n", |
| 3595 | file, linenum, args[0], args[1]); |
| 3596 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3597 | goto out; |
| 3598 | } |
| 3599 | } /* end while loop */ |
| 3600 | } |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 3601 | } |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 3602 | else if (!strcmp(args[1], "ldap-check")) { |
| 3603 | /* use LDAP request to check servers' health */ |
| 3604 | free(curproxy->check_req); |
| 3605 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3606 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 3607 | curproxy->options2 |= PR_O2_LDAP_CHK; |
| 3608 | |
| 3609 | curproxy->check_req = (char *) malloc(sizeof(DEF_LDAP_CHECK_REQ) - 1); |
| 3610 | memcpy(curproxy->check_req, DEF_LDAP_CHECK_REQ, sizeof(DEF_LDAP_CHECK_REQ) - 1); |
| 3611 | curproxy->check_len = sizeof(DEF_LDAP_CHECK_REQ) - 1; |
| 3612 | } |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3613 | else if (!strcmp(args[1], "forwardfor")) { |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3614 | int cur_arg; |
| 3615 | |
| 3616 | /* insert x-forwarded-for field, but not for the IP address listed as an except. |
| 3617 | * set default options (ie: bitfield, header name, etc) |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3618 | */ |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3619 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 3620 | curproxy->options |= PR_O_FWDFOR | PR_O_FF_ALWAYS; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3621 | |
| 3622 | free(curproxy->fwdfor_hdr_name); |
| 3623 | curproxy->fwdfor_hdr_name = strdup(DEF_XFORWARDFOR_HDR); |
| 3624 | curproxy->fwdfor_hdr_len = strlen(DEF_XFORWARDFOR_HDR); |
| 3625 | |
| 3626 | /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */ |
| 3627 | cur_arg = 2; |
| 3628 | while (*(args[cur_arg])) { |
| 3629 | if (!strcmp(args[cur_arg], "except")) { |
| 3630 | /* suboption except - needs additional argument for it */ |
| 3631 | if (!*(args[cur_arg+1]) || !str2net(args[cur_arg+1], &curproxy->except_net, &curproxy->except_mask)) { |
| 3632 | Alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n", |
| 3633 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3634 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3635 | goto out; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3636 | } |
| 3637 | /* flush useless bits */ |
| 3638 | curproxy->except_net.s_addr &= curproxy->except_mask.s_addr; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3639 | cur_arg += 2; |
| 3640 | } else if (!strcmp(args[cur_arg], "header")) { |
| 3641 | /* suboption header - needs additional argument for it */ |
| 3642 | if (*(args[cur_arg+1]) == 0) { |
| 3643 | Alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 3644 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3645 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3646 | goto out; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3647 | } |
| 3648 | free(curproxy->fwdfor_hdr_name); |
| 3649 | curproxy->fwdfor_hdr_name = strdup(args[cur_arg+1]); |
| 3650 | curproxy->fwdfor_hdr_len = strlen(curproxy->fwdfor_hdr_name); |
| 3651 | cur_arg += 2; |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 3652 | } else if (!strcmp(args[cur_arg], "if-none")) { |
| 3653 | curproxy->options &= ~PR_O_FF_ALWAYS; |
| 3654 | cur_arg += 1; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3655 | } else { |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3656 | /* unknown suboption - catchall */ |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 3657 | 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] | 3658 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3659 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3660 | goto out; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3661 | } |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3662 | } /* end while loop */ |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3663 | } |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 3664 | else if (!strcmp(args[1], "originalto")) { |
| 3665 | int cur_arg; |
| 3666 | |
| 3667 | /* insert x-original-to field, but not for the IP address listed as an except. |
| 3668 | * set default options (ie: bitfield, header name, etc) |
| 3669 | */ |
| 3670 | |
| 3671 | curproxy->options |= PR_O_ORGTO; |
| 3672 | |
| 3673 | free(curproxy->orgto_hdr_name); |
| 3674 | curproxy->orgto_hdr_name = strdup(DEF_XORIGINALTO_HDR); |
| 3675 | curproxy->orgto_hdr_len = strlen(DEF_XORIGINALTO_HDR); |
| 3676 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 3677 | /* 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] | 3678 | cur_arg = 2; |
| 3679 | while (*(args[cur_arg])) { |
| 3680 | if (!strcmp(args[cur_arg], "except")) { |
| 3681 | /* suboption except - needs additional argument for it */ |
| 3682 | if (!*(args[cur_arg+1]) || !str2net(args[cur_arg+1], &curproxy->except_to, &curproxy->except_mask_to)) { |
| 3683 | Alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n", |
| 3684 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3685 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3686 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 3687 | } |
| 3688 | /* flush useless bits */ |
| 3689 | curproxy->except_to.s_addr &= curproxy->except_mask_to.s_addr; |
| 3690 | cur_arg += 2; |
| 3691 | } else if (!strcmp(args[cur_arg], "header")) { |
| 3692 | /* suboption header - needs additional argument for it */ |
| 3693 | if (*(args[cur_arg+1]) == 0) { |
| 3694 | Alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 3695 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3696 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3697 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 3698 | } |
| 3699 | free(curproxy->orgto_hdr_name); |
| 3700 | curproxy->orgto_hdr_name = strdup(args[cur_arg+1]); |
| 3701 | curproxy->orgto_hdr_len = strlen(curproxy->orgto_hdr_name); |
| 3702 | cur_arg += 2; |
| 3703 | } else { |
| 3704 | /* unknown suboption - catchall */ |
| 3705 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n", |
| 3706 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3707 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3708 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 3709 | } |
| 3710 | } /* end while loop */ |
| 3711 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3712 | else { |
| 3713 | Alert("parsing [%s:%d] : unknown option '%s'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3714 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3715 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3716 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3717 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3718 | } |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 3719 | else if (!strcmp(args[0], "default_backend")) { |
| 3720 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3721 | err_code |= ERR_WARN; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 3722 | |
| 3723 | if (*(args[1]) == 0) { |
| 3724 | 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] | 3725 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3726 | goto out; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 3727 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3728 | free(curproxy->defbe.name); |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 3729 | curproxy->defbe.name = strdup(args[1]); |
| 3730 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3731 | else if (!strcmp(args[0], "redispatch") || !strcmp(args[0], "redisp")) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3732 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3733 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3734 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3735 | Warning("parsing [%s:%d]: keyword '%s' is deprecated, please use 'option redispatch' instead.\n", |
| 3736 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3737 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3738 | /* enable reconnections to dispatch */ |
| 3739 | curproxy->options |= PR_O_REDISP; |
| 3740 | } |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 3741 | else if (!strcmp(args[0], "http-check")) { |
| 3742 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3743 | err_code |= ERR_WARN; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 3744 | |
| 3745 | if (strcmp(args[1], "disable-on-404") == 0) { |
| 3746 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 3747 | curproxy->options |= PR_O_DISABLE404; |
| 3748 | } |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 3749 | else if (strcmp(args[1], "send-state") == 0) { |
| 3750 | /* enable emission of the apparent state of a server in HTTP checks */ |
| 3751 | curproxy->options2 |= PR_O2_CHK_SNDST; |
| 3752 | } |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 3753 | else if (strcmp(args[1], "expect") == 0) { |
| 3754 | const char *ptr_arg; |
| 3755 | int cur_arg; |
| 3756 | |
| 3757 | if (curproxy->options2 & PR_O2_EXP_TYPE) { |
| 3758 | Alert("parsing [%s:%d] : '%s %s' already specified.\n", file, linenum, args[0], args[1]); |
| 3759 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3760 | goto out; |
| 3761 | } |
| 3762 | |
| 3763 | cur_arg = 2; |
| 3764 | /* consider exclamation marks, sole or at the beginning of a word */ |
| 3765 | while (*(ptr_arg = args[cur_arg])) { |
| 3766 | while (*ptr_arg == '!') { |
| 3767 | curproxy->options2 ^= PR_O2_EXP_INV; |
| 3768 | ptr_arg++; |
| 3769 | } |
| 3770 | if (*ptr_arg) |
| 3771 | break; |
| 3772 | cur_arg++; |
| 3773 | } |
| 3774 | /* now ptr_arg points to the beginning of a word past any possible |
| 3775 | * exclamation mark, and cur_arg is the argument which holds this word. |
| 3776 | */ |
| 3777 | if (strcmp(ptr_arg, "status") == 0) { |
| 3778 | if (!*(args[cur_arg + 1])) { |
| 3779 | Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 3780 | file, linenum, args[0], args[1], ptr_arg); |
| 3781 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3782 | goto out; |
| 3783 | } |
| 3784 | curproxy->options2 |= PR_O2_EXP_STS; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 3785 | free(curproxy->expect_str); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 3786 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
| 3787 | } |
| 3788 | else if (strcmp(ptr_arg, "string") == 0) { |
| 3789 | if (!*(args[cur_arg + 1])) { |
| 3790 | Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 3791 | file, linenum, args[0], args[1], ptr_arg); |
| 3792 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3793 | goto out; |
| 3794 | } |
| 3795 | curproxy->options2 |= PR_O2_EXP_STR; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 3796 | free(curproxy->expect_str); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 3797 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
| 3798 | } |
| 3799 | else if (strcmp(ptr_arg, "rstatus") == 0) { |
| 3800 | if (!*(args[cur_arg + 1])) { |
| 3801 | Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 3802 | file, linenum, args[0], args[1], ptr_arg); |
| 3803 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3804 | goto out; |
| 3805 | } |
| 3806 | curproxy->options2 |= PR_O2_EXP_RSTS; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 3807 | free(curproxy->expect_str); |
| 3808 | if (curproxy->expect_regex) regfree(curproxy->expect_regex); |
| 3809 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 3810 | curproxy->expect_regex = calloc(1, sizeof(regex_t)); |
| 3811 | if (regcomp(curproxy->expect_regex, args[cur_arg + 1], REG_EXTENDED) != 0) { |
| 3812 | Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s'.\n", |
| 3813 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1]); |
| 3814 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3815 | goto out; |
| 3816 | } |
| 3817 | } |
| 3818 | else if (strcmp(ptr_arg, "rstring") == 0) { |
| 3819 | if (!*(args[cur_arg + 1])) { |
| 3820 | Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 3821 | file, linenum, args[0], args[1], ptr_arg); |
| 3822 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3823 | goto out; |
| 3824 | } |
| 3825 | curproxy->options2 |= PR_O2_EXP_RSTR; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 3826 | free(curproxy->expect_str); |
| 3827 | if (curproxy->expect_regex) regfree(curproxy->expect_regex); |
| 3828 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 3829 | curproxy->expect_regex = calloc(1, sizeof(regex_t)); |
| 3830 | if (regcomp(curproxy->expect_regex, args[cur_arg + 1], REG_EXTENDED) != 0) { |
| 3831 | Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s'.\n", |
| 3832 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1]); |
| 3833 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3834 | goto out; |
| 3835 | } |
| 3836 | } |
| 3837 | else { |
| 3838 | Alert("parsing [%s:%d] : '%s %s' only supports [!] 'status', 'string', 'rstatus', 'rstring', found '%s'.\n", |
| 3839 | file, linenum, args[0], args[1], ptr_arg); |
| 3840 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3841 | goto out; |
| 3842 | } |
| 3843 | } |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 3844 | else { |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 3845 | 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] | 3846 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3847 | goto out; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 3848 | } |
| 3849 | } |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3850 | else if (!strcmp(args[0], "monitor")) { |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3851 | if (curproxy == &defproxy) { |
| 3852 | 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] | 3853 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3854 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3855 | } |
| 3856 | |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3857 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3858 | err_code |= ERR_WARN; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3859 | |
| 3860 | if (strcmp(args[1], "fail") == 0) { |
| 3861 | /* add a condition to fail monitor requests */ |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 3862 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3863 | Alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n", |
| 3864 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3865 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3866 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3867 | } |
| 3868 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 3869 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 3870 | Alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition : %s.\n", |
| 3871 | file, linenum, args[0], args[1], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3872 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3873 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3874 | } |
| 3875 | LIST_ADDQ(&curproxy->mon_fail_cond, &cond->list); |
| 3876 | } |
| 3877 | else { |
| 3878 | 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] | 3879 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3880 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3881 | } |
| 3882 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3883 | #ifdef TPROXY |
| 3884 | else if (!strcmp(args[0], "transparent")) { |
| 3885 | /* enable transparent proxy connections */ |
| 3886 | curproxy->options |= PR_O_TRANSP; |
| 3887 | } |
| 3888 | #endif |
| 3889 | else if (!strcmp(args[0], "maxconn")) { /* maxconn */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3890 | 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] | 3891 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3892 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3893 | if (*(args[1]) == 0) { |
| 3894 | 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] | 3895 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3896 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3897 | } |
| 3898 | curproxy->maxconn = atol(args[1]); |
| 3899 | } |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 3900 | else if (!strcmp(args[0], "backlog")) { /* backlog */ |
| 3901 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3902 | err_code |= ERR_WARN; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 3903 | |
| 3904 | if (*(args[1]) == 0) { |
| 3905 | 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] | 3906 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3907 | goto out; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 3908 | } |
| 3909 | curproxy->backlog = atol(args[1]); |
| 3910 | } |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 3911 | else if (!strcmp(args[0], "fullconn")) { /* fullconn */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3912 | 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] | 3913 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3914 | |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 3915 | if (*(args[1]) == 0) { |
| 3916 | 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] | 3917 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3918 | goto out; |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 3919 | } |
| 3920 | curproxy->fullconn = atol(args[1]); |
| 3921 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3922 | else if (!strcmp(args[0], "grace")) { /* grace time (ms) */ |
| 3923 | if (*(args[1]) == 0) { |
| 3924 | 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] | 3925 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3926 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3927 | } |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 3928 | err = parse_time_err(args[1], &val, TIME_UNIT_MS); |
| 3929 | if (err) { |
| 3930 | Alert("parsing [%s:%d] : unexpected character '%c' in grace time.\n", |
| 3931 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3932 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3933 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 3934 | } |
| 3935 | curproxy->grace = val; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3936 | } |
| 3937 | else if (!strcmp(args[0], "dispatch")) { /* dispatch address */ |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 3938 | struct sockaddr_storage *sk; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3939 | if (curproxy == &defproxy) { |
| 3940 | 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] | 3941 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3942 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3943 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3944 | else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3945 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3946 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3947 | if (strchr(args[1], ':') == NULL) { |
| 3948 | 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] | 3949 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3950 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3951 | } |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 3952 | sk = str2sa(args[1]); |
| 3953 | if (!sk) { |
| 3954 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[1]); |
| 3955 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3956 | goto out; |
| 3957 | } |
| 3958 | curproxy->dispatch_addr = *sk; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3959 | curproxy->options |= PR_O_DISPATCH; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3960 | } |
| 3961 | else if (!strcmp(args[0], "balance")) { /* set balancing with optional algorithm */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3962 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3963 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3964 | |
Willy Tarreau | a93c74b | 2012-05-08 18:14:39 +0200 | [diff] [blame] | 3965 | if (backend_parse_balance((const char **)args + 1, &errmsg, curproxy) < 0) { |
| 3966 | Alert("parsing [%s:%d] : %s %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3967 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3968 | goto out; |
Willy Tarreau | 2fcb500 | 2007-05-08 13:35:26 +0200 | [diff] [blame] | 3969 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3970 | } |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 3971 | else if (!strcmp(args[0], "hash-type")) { /* set hashing method */ |
| 3972 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 3973 | err_code |= ERR_WARN; |
| 3974 | |
| 3975 | if (strcmp(args[1], "consistent") == 0) { /* use consistent hashing */ |
| 3976 | curproxy->lbprm.algo &= ~BE_LB_HASH_TYPE; |
| 3977 | curproxy->lbprm.algo |= BE_LB_HASH_CONS; |
| 3978 | } |
| 3979 | else if (strcmp(args[1], "map-based") == 0) { /* use map-based hashing */ |
| 3980 | curproxy->lbprm.algo &= ~BE_LB_HASH_TYPE; |
| 3981 | curproxy->lbprm.algo |= BE_LB_HASH_MAP; |
| 3982 | } |
Willy Tarreau | 798a39c | 2010-11-24 15:04:29 +0100 | [diff] [blame] | 3983 | else if (strcmp(args[1], "avalanche") == 0) { /* use full hash before map-based hashing */ |
| 3984 | curproxy->lbprm.algo &= ~BE_LB_HASH_TYPE; |
| 3985 | curproxy->lbprm.algo |= BE_LB_HASH_AVAL; |
| 3986 | } |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 3987 | else { |
Willy Tarreau | 798a39c | 2010-11-24 15:04:29 +0100 | [diff] [blame] | 3988 | 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] | 3989 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3990 | goto out; |
| 3991 | } |
| 3992 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3993 | 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] | 3994 | int cur_arg; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3995 | char *rport, *raddr; |
| 3996 | short realport = 0; |
| 3997 | int do_check = 0, defsrv = (*args[0] == 'd'); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3998 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 3999 | if (!defsrv && curproxy == &defproxy) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4000 | 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] | 4001 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4002 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4003 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4004 | else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4005 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4006 | |
| 4007 | if (!*args[2]) { |
| 4008 | Alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n", |
| 4009 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4010 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4011 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4012 | } |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 4013 | |
| 4014 | err = invalid_char(args[1]); |
| 4015 | if (err) { |
| 4016 | Alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n", |
| 4017 | file, linenum, *err, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4018 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4019 | goto out; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 4020 | } |
| 4021 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4022 | if (!defsrv) { |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4023 | struct sockaddr_storage *sk; |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4024 | |
Krzysztof Piotr Oledzki | aff01ea | 2010-02-05 20:31:44 +0100 | [diff] [blame] | 4025 | if ((newsrv = (struct server *)calloc(1, sizeof(struct server))) == NULL) { |
| 4026 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 4027 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4028 | goto out; |
| 4029 | } |
| 4030 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4031 | /* the servers are linked backwards first */ |
| 4032 | newsrv->next = curproxy->srv; |
| 4033 | curproxy->srv = newsrv; |
| 4034 | newsrv->proxy = curproxy; |
Willy Tarreau | 8113a5d | 2012-10-04 08:01:43 +0200 | [diff] [blame] | 4035 | newsrv->conf.file = strdup(file); |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4036 | newsrv->conf.line = linenum; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4037 | |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 4038 | newsrv->obj_type = OBJ_TYPE_SERVER; |
Simon Horman | af51495 | 2011-06-21 14:34:57 +0900 | [diff] [blame] | 4039 | LIST_INIT(&newsrv->actconns); |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4040 | LIST_INIT(&newsrv->pendconns); |
| 4041 | do_check = 0; |
| 4042 | newsrv->state = SRV_RUNNING; /* early server setup */ |
| 4043 | newsrv->last_change = now.tv_sec; |
| 4044 | newsrv->id = strdup(args[1]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4045 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4046 | /* several ways to check the port component : |
David du Colombier | 9842ff1 | 2011-03-17 10:40:28 +0100 | [diff] [blame] | 4047 | * - IP => port=+0, relative (IPv4 only) |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4048 | * - IP: => port=+0, relative |
| 4049 | * - IP:N => port=N, absolute |
| 4050 | * - IP:+N => port=+N, relative |
| 4051 | * - IP:-N => port=-N, relative |
| 4052 | */ |
| 4053 | raddr = strdup(args[2]); |
Willy Tarreau | fab5a43 | 2011-03-04 15:31:53 +0100 | [diff] [blame] | 4054 | rport = strrchr(raddr, ':'); |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4055 | if (rport) { |
| 4056 | *rport++ = 0; |
| 4057 | realport = atol(rport); |
| 4058 | if (!isdigit((unsigned char)*rport)) |
| 4059 | newsrv->state |= SRV_MAPPORTS; |
| 4060 | } else |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4061 | newsrv->state |= SRV_MAPPORTS; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4062 | |
Willy Tarreau | fab5a43 | 2011-03-04 15:31:53 +0100 | [diff] [blame] | 4063 | sk = str2ip(raddr); |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4064 | free(raddr); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4065 | if (!sk) { |
| 4066 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[2]); |
| 4067 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4068 | goto out; |
| 4069 | } |
| 4070 | newsrv->addr = *sk; |
Willy Tarreau | f4288ee | 2012-09-28 18:13:10 +0200 | [diff] [blame] | 4071 | newsrv->proto = newsrv->check.proto = protocol_by_family(newsrv->addr.ss_family); |
| 4072 | newsrv->xprt = newsrv->check.xprt = &raw_sock; |
Willy Tarreau | 26d8c59 | 2012-05-07 18:12:14 +0200 | [diff] [blame] | 4073 | |
Willy Tarreau | 173e7fb | 2012-09-24 22:47:39 +0200 | [diff] [blame] | 4074 | if (!newsrv->proto) { |
Willy Tarreau | 26d8c59 | 2012-05-07 18:12:14 +0200 | [diff] [blame] | 4075 | Alert("parsing [%s:%d] : Unknown protocol family %d '%s'\n", |
| 4076 | file, linenum, newsrv->addr.ss_family, args[2]); |
| 4077 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4078 | goto out; |
| 4079 | } |
Willy Tarreau | 86ad42c | 2011-08-27 12:29:07 +0200 | [diff] [blame] | 4080 | set_host_port(&newsrv->addr, realport); |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4081 | |
Willy Tarreau | f4288ee | 2012-09-28 18:13:10 +0200 | [diff] [blame] | 4082 | newsrv->check.use_ssl = curproxy->defsrv.check.use_ssl; |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 4083 | newsrv->check.port = curproxy->defsrv.check.port; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4084 | newsrv->inter = curproxy->defsrv.inter; |
| 4085 | newsrv->fastinter = curproxy->defsrv.fastinter; |
| 4086 | newsrv->downinter = curproxy->defsrv.downinter; |
| 4087 | newsrv->rise = curproxy->defsrv.rise; |
| 4088 | newsrv->fall = curproxy->defsrv.fall; |
| 4089 | newsrv->maxqueue = curproxy->defsrv.maxqueue; |
| 4090 | newsrv->minconn = curproxy->defsrv.minconn; |
| 4091 | newsrv->maxconn = curproxy->defsrv.maxconn; |
| 4092 | newsrv->slowstart = curproxy->defsrv.slowstart; |
| 4093 | newsrv->onerror = curproxy->defsrv.onerror; |
| 4094 | newsrv->consecutive_errors_limit |
| 4095 | = curproxy->defsrv.consecutive_errors_limit; |
Emeric Brun | 01f8e2f | 2012-05-18 16:02:00 +0200 | [diff] [blame] | 4096 | #ifdef OPENSSL |
| 4097 | newsrv->use_ssl = curproxy->defsrv.use_ssl; |
| 4098 | #endif |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4099 | newsrv->uweight = newsrv->iweight |
| 4100 | = curproxy->defsrv.iweight; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4101 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4102 | newsrv->health = newsrv->rise; /* up, but will fall down at first failure */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4103 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4104 | cur_arg = 3; |
| 4105 | } else { |
| 4106 | newsrv = &curproxy->defsrv; |
| 4107 | cur_arg = 1; |
| 4108 | } |
Willy Tarreau | 0f03c6f | 2007-03-25 20:46:19 +0200 | [diff] [blame] | 4109 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4110 | while (*args[cur_arg]) { |
Willy Tarreau | dff5543 | 2012-10-10 17:51:05 +0200 | [diff] [blame] | 4111 | if (!defsrv && !strcmp(args[cur_arg], "cookie")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4112 | newsrv->cookie = strdup(args[cur_arg + 1]); |
| 4113 | newsrv->cklen = strlen(args[cur_arg + 1]); |
| 4114 | cur_arg += 2; |
| 4115 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4116 | else if (!defsrv && !strcmp(args[cur_arg], "redir")) { |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 4117 | newsrv->rdr_pfx = strdup(args[cur_arg + 1]); |
| 4118 | newsrv->rdr_len = strlen(args[cur_arg + 1]); |
| 4119 | cur_arg += 2; |
| 4120 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4121 | else if (!strcmp(args[cur_arg], "rise")) { |
Krzysztof Piotr Oledzki | 08ff959 | 2009-09-27 16:17:31 +0200 | [diff] [blame] | 4122 | if (!*args[cur_arg + 1]) { |
| 4123 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 4124 | file, linenum, args[cur_arg]); |
| 4125 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4126 | goto out; |
| 4127 | } |
| 4128 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4129 | newsrv->rise = atol(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 08ff959 | 2009-09-27 16:17:31 +0200 | [diff] [blame] | 4130 | if (newsrv->rise <= 0) { |
| 4131 | Alert("parsing [%s:%d]: '%s' has to be > 0.\n", |
| 4132 | file, linenum, args[cur_arg]); |
| 4133 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4134 | goto out; |
| 4135 | } |
| 4136 | |
Willy Tarreau | 9683909 | 2010-03-29 10:02:24 +0200 | [diff] [blame] | 4137 | if (newsrv->health) |
| 4138 | newsrv->health = newsrv->rise; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4139 | cur_arg += 2; |
| 4140 | } |
| 4141 | else if (!strcmp(args[cur_arg], "fall")) { |
| 4142 | newsrv->fall = atol(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 08ff959 | 2009-09-27 16:17:31 +0200 | [diff] [blame] | 4143 | |
| 4144 | if (!*args[cur_arg + 1]) { |
| 4145 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 4146 | file, linenum, args[cur_arg]); |
| 4147 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4148 | goto out; |
| 4149 | } |
| 4150 | |
| 4151 | if (newsrv->fall <= 0) { |
| 4152 | Alert("parsing [%s:%d]: '%s' has to be > 0.\n", |
| 4153 | file, linenum, args[cur_arg]); |
| 4154 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4155 | goto out; |
| 4156 | } |
| 4157 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4158 | cur_arg += 2; |
| 4159 | } |
| 4160 | else if (!strcmp(args[cur_arg], "inter")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4161 | const char *err = parse_time_err(args[cur_arg + 1], &val, TIME_UNIT_MS); |
| 4162 | if (err) { |
| 4163 | Alert("parsing [%s:%d] : unexpected character '%c' in 'inter' argument of server %s.\n", |
| 4164 | file, linenum, *err, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4165 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4166 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4167 | } |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4168 | if (val <= 0) { |
| 4169 | Alert("parsing [%s:%d]: invalid value %d for argument '%s' of server %s.\n", |
| 4170 | file, linenum, val, args[cur_arg], newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4171 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4172 | goto out; |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4173 | } |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4174 | newsrv->inter = val; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4175 | cur_arg += 2; |
| 4176 | } |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 4177 | else if (!strcmp(args[cur_arg], "fastinter")) { |
| 4178 | const char *err = parse_time_err(args[cur_arg + 1], &val, TIME_UNIT_MS); |
| 4179 | if (err) { |
| 4180 | Alert("parsing [%s:%d]: unexpected character '%c' in 'fastinter' argument of server %s.\n", |
| 4181 | file, linenum, *err, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4182 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4183 | goto out; |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 4184 | } |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4185 | if (val <= 0) { |
| 4186 | Alert("parsing [%s:%d]: invalid value %d for argument '%s' of server %s.\n", |
| 4187 | file, linenum, val, args[cur_arg], newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4188 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4189 | goto out; |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4190 | } |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 4191 | newsrv->fastinter = val; |
| 4192 | cur_arg += 2; |
| 4193 | } |
| 4194 | else if (!strcmp(args[cur_arg], "downinter")) { |
| 4195 | const char *err = parse_time_err(args[cur_arg + 1], &val, TIME_UNIT_MS); |
| 4196 | if (err) { |
| 4197 | Alert("parsing [%s:%d]: unexpected character '%c' in 'downinter' argument of server %s.\n", |
| 4198 | file, linenum, *err, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4199 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4200 | goto out; |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 4201 | } |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4202 | if (val <= 0) { |
| 4203 | Alert("parsing [%s:%d]: invalid value %d for argument '%s' of server %s.\n", |
| 4204 | file, linenum, val, args[cur_arg], newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4205 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4206 | goto out; |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4207 | } |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 4208 | newsrv->downinter = val; |
| 4209 | cur_arg += 2; |
| 4210 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4211 | else if (!defsrv && !strcmp(args[cur_arg], "addr")) { |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4212 | struct sockaddr_storage *sk = str2sa(args[cur_arg + 1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4213 | if (!sk) { |
| 4214 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[cur_arg + 1]); |
| 4215 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4216 | goto out; |
| 4217 | } |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 4218 | newsrv->check.addr = *sk; |
Willy Tarreau | 2ea3abb | 2007-03-25 16:45:16 +0200 | [diff] [blame] | 4219 | cur_arg += 2; |
| 4220 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4221 | else if (!strcmp(args[cur_arg], "port")) { |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 4222 | newsrv->check.port = atol(args[cur_arg + 1]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4223 | cur_arg += 2; |
| 4224 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4225 | else if (!defsrv && !strcmp(args[cur_arg], "backup")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4226 | newsrv->state |= SRV_BACKUP; |
| 4227 | cur_arg ++; |
| 4228 | } |
Simon Horman | fa46168 | 2011-06-25 09:39:49 +0900 | [diff] [blame] | 4229 | else if (!defsrv && !strcmp(args[cur_arg], "non-stick")) { |
| 4230 | newsrv->state |= SRV_NON_STICK; |
| 4231 | cur_arg ++; |
| 4232 | } |
Willy Tarreau | 5ab04ec | 2011-03-20 10:32:26 +0100 | [diff] [blame] | 4233 | else if (!defsrv && !strcmp(args[cur_arg], "send-proxy")) { |
| 4234 | newsrv->state |= SRV_SEND_PROXY; |
| 4235 | cur_arg ++; |
| 4236 | } |
Willy Tarreau | 6c16adc | 2012-10-05 00:04:16 +0200 | [diff] [blame] | 4237 | else if (!defsrv && !strcmp(args[cur_arg], "check-send-proxy")) { |
| 4238 | newsrv->check.send_proxy = 1; |
| 4239 | cur_arg ++; |
| 4240 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4241 | else if (!strcmp(args[cur_arg], "weight")) { |
| 4242 | int w; |
| 4243 | w = atol(args[cur_arg + 1]); |
Willy Tarreau | 6704d67 | 2009-06-15 10:56:05 +0200 | [diff] [blame] | 4244 | if (w < 0 || w > 256) { |
| 4245 | 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] | 4246 | file, linenum, newsrv->id, w); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4247 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4248 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4249 | } |
Willy Tarreau | 975c50b | 2009-10-10 19:34:06 +0200 | [diff] [blame] | 4250 | newsrv->uweight = newsrv->iweight = w; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4251 | cur_arg += 2; |
| 4252 | } |
| 4253 | else if (!strcmp(args[cur_arg], "minconn")) { |
| 4254 | newsrv->minconn = atol(args[cur_arg + 1]); |
| 4255 | cur_arg += 2; |
| 4256 | } |
| 4257 | else if (!strcmp(args[cur_arg], "maxconn")) { |
| 4258 | newsrv->maxconn = atol(args[cur_arg + 1]); |
| 4259 | cur_arg += 2; |
| 4260 | } |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 4261 | else if (!strcmp(args[cur_arg], "maxqueue")) { |
| 4262 | newsrv->maxqueue = atol(args[cur_arg + 1]); |
| 4263 | cur_arg += 2; |
| 4264 | } |
Willy Tarreau | 9909fc1 | 2007-11-30 17:42:05 +0100 | [diff] [blame] | 4265 | else if (!strcmp(args[cur_arg], "slowstart")) { |
| 4266 | /* slowstart is stored in seconds */ |
Willy Tarreau | 3259e33 | 2007-12-03 01:51:45 +0100 | [diff] [blame] | 4267 | 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] | 4268 | if (err) { |
| 4269 | Alert("parsing [%s:%d] : unexpected character '%c' in 'slowstart' argument of server %s.\n", |
| 4270 | file, linenum, *err, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4271 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4272 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4273 | } |
Willy Tarreau | 4554bc1 | 2010-03-26 10:40:49 +0100 | [diff] [blame] | 4274 | if (val < 0) { |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4275 | Alert("parsing [%s:%d]: invalid value %d for argument '%s' of server %s.\n", |
| 4276 | file, linenum, val, args[cur_arg], newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4277 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4278 | goto out; |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4279 | } |
Willy Tarreau | 3259e33 | 2007-12-03 01:51:45 +0100 | [diff] [blame] | 4280 | newsrv->slowstart = (val + 999) / 1000; |
Willy Tarreau | 9909fc1 | 2007-11-30 17:42:05 +0100 | [diff] [blame] | 4281 | cur_arg += 2; |
| 4282 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4283 | else if (!defsrv && !strcmp(args[cur_arg], "track")) { |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4284 | |
| 4285 | if (!*args[cur_arg + 1]) { |
| 4286 | Alert("parsing [%s:%d]: 'track' expects [<proxy>/]<server> as argument.\n", |
| 4287 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4288 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4289 | goto out; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4290 | } |
| 4291 | |
| 4292 | newsrv->trackit = strdup(args[cur_arg + 1]); |
| 4293 | |
| 4294 | cur_arg += 2; |
| 4295 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4296 | else if (!defsrv && !strcmp(args[cur_arg], "check")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4297 | global.maxsock++; |
| 4298 | do_check = 1; |
| 4299 | cur_arg += 1; |
| 4300 | } |
Willy Tarreau | 9683909 | 2010-03-29 10:02:24 +0200 | [diff] [blame] | 4301 | else if (!defsrv && !strcmp(args[cur_arg], "disabled")) { |
| 4302 | newsrv->state |= SRV_MAINTAIN; |
| 4303 | newsrv->state &= ~SRV_RUNNING; |
| 4304 | newsrv->health = 0; |
| 4305 | cur_arg += 1; |
Emeric Brun | c0ff492 | 2012-09-28 19:37:02 +0200 | [diff] [blame] | 4306 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4307 | else if (!defsrv && !strcmp(args[cur_arg], "observe")) { |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 4308 | if (!strcmp(args[cur_arg + 1], "none")) |
| 4309 | newsrv->observe = HANA_OBS_NONE; |
| 4310 | else if (!strcmp(args[cur_arg + 1], "layer4")) |
| 4311 | newsrv->observe = HANA_OBS_LAYER4; |
| 4312 | else if (!strcmp(args[cur_arg + 1], "layer7")) { |
| 4313 | if (curproxy->mode != PR_MODE_HTTP) { |
| 4314 | Alert("parsing [%s:%d]: '%s' can only be used in http proxies.\n", |
| 4315 | file, linenum, args[cur_arg + 1]); |
| 4316 | err_code |= ERR_ALERT; |
| 4317 | } |
| 4318 | newsrv->observe = HANA_OBS_LAYER7; |
| 4319 | } |
| 4320 | else { |
| 4321 | Alert("parsing [%s:%d]: '%s' expects one of 'none', " |
Willy Tarreau | 53621e0 | 2010-10-22 14:53:40 +0200 | [diff] [blame] | 4322 | "'layer4', 'layer7' but got '%s'\n", |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 4323 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
| 4324 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4325 | goto out; |
| 4326 | } |
| 4327 | |
| 4328 | cur_arg += 2; |
| 4329 | } |
| 4330 | else if (!strcmp(args[cur_arg], "on-error")) { |
| 4331 | if (!strcmp(args[cur_arg + 1], "fastinter")) |
| 4332 | newsrv->onerror = HANA_ONERR_FASTINTER; |
| 4333 | else if (!strcmp(args[cur_arg + 1], "fail-check")) |
| 4334 | newsrv->onerror = HANA_ONERR_FAILCHK; |
| 4335 | else if (!strcmp(args[cur_arg + 1], "sudden-death")) |
| 4336 | newsrv->onerror = HANA_ONERR_SUDDTH; |
| 4337 | else if (!strcmp(args[cur_arg + 1], "mark-down")) |
| 4338 | newsrv->onerror = HANA_ONERR_MARKDWN; |
| 4339 | else { |
| 4340 | Alert("parsing [%s:%d]: '%s' expects one of 'fastinter', " |
Willy Tarreau | 53621e0 | 2010-10-22 14:53:40 +0200 | [diff] [blame] | 4341 | "'fail-check', 'sudden-death' or 'mark-down' but got '%s'\n", |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 4342 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
| 4343 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4344 | goto out; |
| 4345 | } |
| 4346 | |
| 4347 | cur_arg += 2; |
| 4348 | } |
Simon Horman | e0d1bfb | 2011-06-21 14:34:58 +0900 | [diff] [blame] | 4349 | else if (!strcmp(args[cur_arg], "on-marked-down")) { |
| 4350 | if (!strcmp(args[cur_arg + 1], "shutdown-sessions")) |
| 4351 | newsrv->onmarkeddown = HANA_ONMARKEDDOWN_SHUTDOWNSESSIONS; |
| 4352 | else { |
| 4353 | Alert("parsing [%s:%d]: '%s' expects 'shutdown-sessions' but got '%s'\n", |
| 4354 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
| 4355 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4356 | goto out; |
| 4357 | } |
| 4358 | |
| 4359 | cur_arg += 2; |
| 4360 | } |
Justin Karneges | eb2c24a | 2012-05-24 15:28:52 -0700 | [diff] [blame] | 4361 | else if (!strcmp(args[cur_arg], "on-marked-up")) { |
| 4362 | if (!strcmp(args[cur_arg + 1], "shutdown-backup-sessions")) |
| 4363 | newsrv->onmarkedup = HANA_ONMARKEDUP_SHUTDOWNBACKUPSESSIONS; |
| 4364 | else { |
| 4365 | Alert("parsing [%s:%d]: '%s' expects 'shutdown-backup-sessions' but got '%s'\n", |
| 4366 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
| 4367 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4368 | goto out; |
| 4369 | } |
| 4370 | |
| 4371 | cur_arg += 2; |
| 4372 | } |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 4373 | else if (!strcmp(args[cur_arg], "error-limit")) { |
| 4374 | if (!*args[cur_arg + 1]) { |
| 4375 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 4376 | file, linenum, args[cur_arg]); |
| 4377 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4378 | goto out; |
| 4379 | } |
| 4380 | |
| 4381 | newsrv->consecutive_errors_limit = atoi(args[cur_arg + 1]); |
| 4382 | |
| 4383 | if (newsrv->consecutive_errors_limit <= 0) { |
| 4384 | Alert("parsing [%s:%d]: %s has to be > 0.\n", |
| 4385 | file, linenum, args[cur_arg]); |
| 4386 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4387 | goto out; |
| 4388 | } |
Willy Tarreau | f53b25d | 2010-03-15 19:40:37 +0100 | [diff] [blame] | 4389 | cur_arg += 2; |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 4390 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4391 | 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] | 4392 | int port_low, port_high; |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4393 | struct sockaddr_storage *sk; |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4394 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4395 | if (!*args[cur_arg + 1]) { |
Willy Tarreau | eb37faa | 2012-12-08 23:21:19 +0100 | [diff] [blame] | 4396 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>[-<port>]], and optionally '%s' <addr>, and '%s' <name> as argument.\n", |
| 4397 | file, linenum, "source", "usesrc", "interface"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4398 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4399 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4400 | } |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4401 | newsrv->conn_src.opts |= CO_SRC_BIND; |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4402 | sk = str2sa_range(args[cur_arg + 1], &port_low, &port_high); |
| 4403 | if (!sk) { |
| 4404 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[cur_arg + 1]); |
| 4405 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4406 | goto out; |
| 4407 | } |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4408 | newsrv->conn_src.source_addr = *sk; |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 4409 | |
| 4410 | if (port_low != port_high) { |
| 4411 | int i; |
| 4412 | if (port_low <= 0 || port_low > 65535 || |
| 4413 | port_high <= 0 || port_high > 65535 || |
| 4414 | port_low > port_high) { |
| 4415 | Alert("parsing [%s:%d] : invalid source port range %d-%d.\n", |
| 4416 | file, linenum, port_low, port_high); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4417 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4418 | goto out; |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 4419 | } |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4420 | newsrv->conn_src.sport_range = port_range_alloc_range(port_high - port_low + 1); |
| 4421 | for (i = 0; i < newsrv->conn_src.sport_range->size; i++) |
| 4422 | newsrv->conn_src.sport_range->ports[i] = port_low + i; |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 4423 | } |
| 4424 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4425 | cur_arg += 2; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4426 | while (*(args[cur_arg])) { |
| 4427 | if (!strcmp(args[cur_arg], "usesrc")) { /* address to use outside */ |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4428 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) |
| 4429 | #if !defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4430 | if (!is_addr(&newsrv->conn_src.source_addr)) { |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4431 | Alert("parsing [%s:%d] : '%s' requires an explicit '%s' address.\n", |
| 4432 | file, linenum, "usesrc", "source"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4433 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4434 | goto out; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4435 | } |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4436 | #endif |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4437 | if (!*args[cur_arg + 1]) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4438 | 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] | 4439 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4440 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4441 | goto out; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4442 | } |
| 4443 | if (!strcmp(args[cur_arg + 1], "client")) { |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4444 | newsrv->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 4445 | newsrv->conn_src.opts |= CO_SRC_TPROXY_CLI; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4446 | } else if (!strcmp(args[cur_arg + 1], "clientip")) { |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4447 | newsrv->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 4448 | newsrv->conn_src.opts |= CO_SRC_TPROXY_CIP; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4449 | } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) { |
| 4450 | char *name, *end; |
| 4451 | |
| 4452 | name = args[cur_arg+1] + 7; |
| 4453 | while (isspace(*name)) |
| 4454 | name++; |
| 4455 | |
| 4456 | end = name; |
| 4457 | while (*end && !isspace(*end) && *end != ',' && *end != ')') |
| 4458 | end++; |
| 4459 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4460 | newsrv->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 4461 | newsrv->conn_src.opts |= CO_SRC_TPROXY_DYN; |
| 4462 | newsrv->conn_src.bind_hdr_name = calloc(1, end - name + 1); |
| 4463 | newsrv->conn_src.bind_hdr_len = end - name; |
| 4464 | memcpy(newsrv->conn_src.bind_hdr_name, name, end - name); |
| 4465 | newsrv->conn_src.bind_hdr_name[end-name] = '\0'; |
| 4466 | newsrv->conn_src.bind_hdr_occ = -1; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4467 | |
| 4468 | /* now look for an occurrence number */ |
| 4469 | while (isspace(*end)) |
| 4470 | end++; |
| 4471 | if (*end == ',') { |
| 4472 | end++; |
| 4473 | name = end; |
| 4474 | if (*end == '-') |
| 4475 | end++; |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 4476 | while (isdigit((int)*end)) |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4477 | end++; |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4478 | newsrv->conn_src.bind_hdr_occ = strl2ic(name, end-name); |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4479 | } |
| 4480 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4481 | if (newsrv->conn_src.bind_hdr_occ < -MAX_HDR_HISTORY) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4482 | Alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative" |
| 4483 | " occurrences values smaller than %d.\n", |
| 4484 | file, linenum, MAX_HDR_HISTORY); |
| 4485 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4486 | goto out; |
| 4487 | } |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4488 | } else { |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4489 | struct sockaddr_storage *sk = str2sa(args[cur_arg + 1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4490 | if (!sk) { |
| 4491 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[cur_arg + 1]); |
| 4492 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4493 | goto out; |
| 4494 | } |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4495 | newsrv->conn_src.tproxy_addr = *sk; |
| 4496 | newsrv->conn_src.opts |= CO_SRC_TPROXY_ADDR; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4497 | } |
| 4498 | global.last_checks |= LSTCHK_NETADM; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4499 | #if !defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4500 | global.last_checks |= LSTCHK_CTTPROXY; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4501 | #endif |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4502 | cur_arg += 2; |
| 4503 | continue; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4504 | #else /* no TPROXY support */ |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4505 | 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] | 4506 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4507 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4508 | goto out; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4509 | #endif /* defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) */ |
| 4510 | } /* "usesrc" */ |
| 4511 | |
| 4512 | if (!strcmp(args[cur_arg], "interface")) { /* specifically bind to this interface */ |
| 4513 | #ifdef SO_BINDTODEVICE |
| 4514 | if (!*args[cur_arg + 1]) { |
| 4515 | Alert("parsing [%s:%d] : '%s' : missing interface name.\n", |
| 4516 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4517 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4518 | goto out; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4519 | } |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4520 | free(newsrv->conn_src.iface_name); |
| 4521 | newsrv->conn_src.iface_name = strdup(args[cur_arg + 1]); |
| 4522 | newsrv->conn_src.iface_len = strlen(newsrv->conn_src.iface_name); |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4523 | global.last_checks |= LSTCHK_NETADM; |
| 4524 | #else |
| 4525 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 4526 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4527 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4528 | goto out; |
Willy Tarreau | 77074d5 | 2006-11-12 23:57:19 +0100 | [diff] [blame] | 4529 | #endif |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4530 | cur_arg += 2; |
| 4531 | continue; |
| 4532 | } |
| 4533 | /* this keyword in not an option of "source" */ |
| 4534 | break; |
| 4535 | } /* while */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4536 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4537 | 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] | 4538 | Alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n", |
| 4539 | file, linenum, "usesrc", "source"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4540 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4541 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 4542 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4543 | else { |
Willy Tarreau | d0d6059 | 2012-10-10 08:57:40 +0200 | [diff] [blame] | 4544 | static int srv_dumped; |
| 4545 | struct srv_kw *kw; |
| 4546 | char *err; |
| 4547 | |
| 4548 | kw = srv_find_kw(args[cur_arg]); |
| 4549 | if (kw) { |
| 4550 | char *err = NULL; |
| 4551 | int code; |
| 4552 | |
| 4553 | if (!kw->parse) { |
| 4554 | Alert("parsing [%s:%d] : '%s %s' : '%s' option is not implemented in this version (check build options).\n", |
| 4555 | file, linenum, args[0], args[1], args[cur_arg]); |
| 4556 | cur_arg += 1 + kw->skip ; |
| 4557 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4558 | goto out; |
| 4559 | } |
| 4560 | |
| 4561 | if (defsrv && !kw->default_ok) { |
| 4562 | Alert("parsing [%s:%d] : '%s %s' : '%s' option is not accepted in default-server sections.\n", |
| 4563 | file, linenum, args[0], args[1], args[cur_arg]); |
| 4564 | cur_arg += 1 + kw->skip ; |
| 4565 | err_code |= ERR_ALERT; |
| 4566 | continue; |
| 4567 | } |
| 4568 | |
| 4569 | code = kw->parse(args, &cur_arg, curproxy, newsrv, &err); |
| 4570 | err_code |= code; |
| 4571 | |
| 4572 | if (code) { |
| 4573 | if (err && *err) { |
| 4574 | indent_msg(&err, 2); |
| 4575 | Alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], err); |
| 4576 | } |
| 4577 | else |
| 4578 | Alert("parsing [%s:%d] : '%s %s' : error encountered while processing '%s'.\n", |
| 4579 | file, linenum, args[0], args[1], args[cur_arg]); |
| 4580 | if (code & ERR_FATAL) { |
| 4581 | free(err); |
| 4582 | cur_arg += 1 + kw->skip; |
| 4583 | goto out; |
| 4584 | } |
| 4585 | } |
| 4586 | free(err); |
| 4587 | cur_arg += 1 + kw->skip; |
| 4588 | continue; |
| 4589 | } |
| 4590 | |
| 4591 | err = NULL; |
| 4592 | if (!srv_dumped) { |
| 4593 | srv_dump_kws(&err); |
| 4594 | indent_msg(&err, 4); |
| 4595 | srv_dumped = 1; |
| 4596 | } |
| 4597 | |
| 4598 | Alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'.%s%s\n", |
| 4599 | file, linenum, args[0], args[1], args[cur_arg], |
| 4600 | err ? " Registered keywords :" : "", err ? err : ""); |
| 4601 | free(err); |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4602 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4603 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4604 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4605 | } |
| 4606 | } |
| 4607 | |
| 4608 | if (do_check) { |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4609 | if (newsrv->trackit) { |
| 4610 | Alert("parsing [%s:%d]: unable to enable checks and tracking at the same time!\n", |
| 4611 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4612 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4613 | goto out; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4614 | } |
| 4615 | |
Willy Tarreau | f4288ee | 2012-09-28 18:13:10 +0200 | [diff] [blame] | 4616 | /* If neither a port nor an addr was specified and no check transport |
| 4617 | * layer is forced, then the transport layer used by the checks is the |
| 4618 | * same as for the production traffic. Otherwise we use raw_sock by |
| 4619 | * default, unless one is specified. |
| 4620 | */ |
Willy Tarreau | 6c16adc | 2012-10-05 00:04:16 +0200 | [diff] [blame] | 4621 | if (!newsrv->check.port && !is_addr(&newsrv->check.addr)) { |
Willy Tarreau | 7151633 | 2012-10-10 23:01:14 +0200 | [diff] [blame] | 4622 | #ifdef USE_OPENSSL |
Willy Tarreau | f4288ee | 2012-09-28 18:13:10 +0200 | [diff] [blame] | 4623 | newsrv->check.use_ssl |= newsrv->use_ssl; |
Willy Tarreau | 7151633 | 2012-10-10 23:01:14 +0200 | [diff] [blame] | 4624 | #endif |
Willy Tarreau | 6c16adc | 2012-10-05 00:04:16 +0200 | [diff] [blame] | 4625 | newsrv->check.send_proxy |= (newsrv->state & SRV_SEND_PROXY); |
| 4626 | } |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 4627 | /* try to get the port from check.addr if check.port not set */ |
| 4628 | if (!newsrv->check.port) |
| 4629 | newsrv->check.port = get_host_port(&newsrv->check.addr); |
Willy Tarreau | 0f03c6f | 2007-03-25 20:46:19 +0200 | [diff] [blame] | 4630 | |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 4631 | if (!newsrv->check.port && !(newsrv->state & SRV_MAPPORTS)) |
| 4632 | newsrv->check.port = realport; /* by default */ |
| 4633 | if (!newsrv->check.port) { |
Willy Tarreau | ef00b50 | 2007-01-07 02:40:09 +0100 | [diff] [blame] | 4634 | /* not yet valid, because no port was set on |
| 4635 | * the server either. We'll check if we have |
| 4636 | * a known port on the first listener. |
| 4637 | */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 4638 | struct listener *l; |
| 4639 | |
| 4640 | list_for_each_entry(l, &curproxy->conf.listeners, by_fe) { |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 4641 | newsrv->check.port = get_host_port(&l->addr); |
| 4642 | if (newsrv->check.port) |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 4643 | break; |
| 4644 | } |
Willy Tarreau | ef00b50 | 2007-01-07 02:40:09 +0100 | [diff] [blame] | 4645 | } |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 4646 | if (!newsrv->check.port) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4647 | Alert("parsing [%s:%d] : server %s has neither service port nor check port. Check has been disabled.\n", |
| 4648 | file, linenum, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4649 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4650 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4651 | } |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 4652 | |
Willy Tarreau | 1ae1b7b | 2012-09-28 15:28:30 +0200 | [diff] [blame] | 4653 | /* Allocate buffer for check requests... */ |
| 4654 | 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] | 4655 | Alert("parsing [%s:%d] : out of memory while allocating check buffer.\n", file, linenum); |
| 4656 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4657 | goto out; |
| 4658 | } |
Willy Tarreau | 1ae1b7b | 2012-09-28 15:28:30 +0200 | [diff] [blame] | 4659 | newsrv->check.bi->size = global.tune.chksize; |
| 4660 | |
| 4661 | /* Allocate buffer for check responses... */ |
| 4662 | if ((newsrv->check.bo = calloc(sizeof(struct buffer) + global.tune.chksize, sizeof(char))) == NULL) { |
| 4663 | Alert("parsing [%s:%d] : out of memory while allocating check buffer.\n", file, linenum); |
| 4664 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4665 | goto out; |
| 4666 | } |
| 4667 | newsrv->check.bo->size = global.tune.chksize; |
Cyril Bonté | c9f825f | 2010-03-17 18:56:31 +0100 | [diff] [blame] | 4668 | |
Willy Tarreau | da92e2f | 2012-07-06 09:40:59 +0200 | [diff] [blame] | 4669 | /* Allocate buffer for partial check results... */ |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 4670 | if ((newsrv->check.conn = calloc(1, sizeof(struct connection))) == NULL) { |
Willy Tarreau | da92e2f | 2012-07-06 09:40:59 +0200 | [diff] [blame] | 4671 | Alert("parsing [%s:%d] : out of memory while allocating check connection.\n", file, linenum); |
| 4672 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4673 | goto out; |
| 4674 | } |
| 4675 | |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 4676 | newsrv->check.conn->t.sock.fd = -1; /* no check in progress yet */ |
| 4677 | newsrv->check.status = HCHK_STATUS_INI; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4678 | newsrv->state |= SRV_CHECKED; |
| 4679 | } |
| 4680 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4681 | if (!defsrv) { |
| 4682 | if (newsrv->state & SRV_BACKUP) |
| 4683 | curproxy->srv_bck++; |
| 4684 | else |
| 4685 | curproxy->srv_act++; |
Willy Tarreau | b625a08 | 2007-11-26 01:15:43 +0100 | [diff] [blame] | 4686 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4687 | newsrv->prev_state = newsrv->state; |
| 4688 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 4689 | } |
| 4690 | |
| 4691 | else if (strcmp(args[0], "unique-id-format") == 0) { |
| 4692 | if (!*(args[1])) { |
| 4693 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 4694 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4695 | goto out; |
| 4696 | } |
William Lallemand | 3203ff4 | 2012-11-11 17:30:56 +0100 | [diff] [blame] | 4697 | if (*(args[2])) { |
| 4698 | Alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]); |
| 4699 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4700 | goto out; |
| 4701 | } |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 4702 | free(curproxy->uniqueid_format_string); |
| 4703 | curproxy->uniqueid_format_string = strdup(args[1]); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4704 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 4705 | |
| 4706 | else if (strcmp(args[0], "unique-id-header") == 0) { |
| 4707 | if (!*(args[1])) { |
| 4708 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 4709 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4710 | goto out; |
| 4711 | } |
| 4712 | free(curproxy->header_unique_id); |
| 4713 | curproxy->header_unique_id = strdup(args[1]); |
| 4714 | } |
| 4715 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4716 | else if (strcmp(args[0], "log-format") == 0) { |
| 4717 | if (!*(args[1])) { |
| 4718 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 4719 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4720 | goto out; |
| 4721 | } |
William Lallemand | 3203ff4 | 2012-11-11 17:30:56 +0100 | [diff] [blame] | 4722 | if (*(args[2])) { |
| 4723 | Alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]); |
| 4724 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4725 | goto out; |
| 4726 | } |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 4727 | |
| 4728 | if (curproxy->logformat_string != default_http_log_format && |
| 4729 | curproxy->logformat_string != default_tcp_log_format && |
| 4730 | curproxy->logformat_string != clf_http_log_format) |
| 4731 | free(curproxy->logformat_string); |
| 4732 | curproxy->logformat_string = strdup(args[1]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4733 | } |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4734 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4735 | else if (!strcmp(args[0], "log") && kwm == KWM_NO) { |
| 4736 | /* delete previous herited or defined syslog servers */ |
| 4737 | struct logsrv *back; |
| 4738 | |
| 4739 | if (*(args[1]) != 0) { |
| 4740 | Alert("parsing [%s:%d]:%s : 'no log' does not expect arguments.\n", file, linenum, args[1]); |
| 4741 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4742 | goto out; |
| 4743 | } |
| 4744 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4745 | list_for_each_entry_safe(tmplogsrv, back, &curproxy->logsrvs, list) { |
| 4746 | LIST_DEL(&tmplogsrv->list); |
| 4747 | free(tmplogsrv); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4748 | } |
| 4749 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4750 | else if (!strcmp(args[0], "log")) { /* syslog server address */ |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4751 | struct logsrv *logsrv; |
| 4752 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4753 | if (*(args[1]) && *(args[2]) == 0 && !strcmp(args[1], "global")) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4754 | /* copy global.logrsvs linked list to the end of curproxy->logsrvs */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4755 | list_for_each_entry(tmplogsrv, &global.logsrvs, list) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4756 | struct logsrv *node = malloc(sizeof(struct logsrv)); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4757 | memcpy(node, tmplogsrv, sizeof(struct logsrv)); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4758 | LIST_INIT(&node->list); |
| 4759 | LIST_ADDQ(&curproxy->logsrvs, &node->list); |
| 4760 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4761 | } |
| 4762 | else if (*(args[1]) && *(args[2])) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4763 | |
| 4764 | logsrv = calloc(1, sizeof(struct logsrv)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4765 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4766 | logsrv->facility = get_log_facility(args[2]); |
| 4767 | if (logsrv->facility < 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4768 | 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] | 4769 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4770 | goto out; |
| 4771 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4772 | } |
| 4773 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4774 | logsrv->level = 7; /* max syslog level = debug */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4775 | if (*(args[3])) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4776 | logsrv->level = get_log_level(args[3]); |
| 4777 | if (logsrv->level < 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4778 | 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] | 4779 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4780 | goto out; |
| 4781 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4782 | } |
| 4783 | } |
| 4784 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4785 | logsrv->minlvl = 0; /* limit syslog level to this level (emerg) */ |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 4786 | if (*(args[4])) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4787 | logsrv->minlvl = get_log_level(args[4]); |
Willy Tarreau | f7f057b | 2013-01-24 00:31:24 +0100 | [diff] [blame] | 4788 | if (logsrv->minlvl < 0) { |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 4789 | 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] | 4790 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4791 | goto out; |
| 4792 | |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 4793 | } |
| 4794 | } |
| 4795 | |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 4796 | if (args[1][0] == '/') { |
David du Colombier | 11bcb6c | 2011-03-24 12:23:00 +0100 | [diff] [blame] | 4797 | struct sockaddr_storage *sk = (struct sockaddr_storage *)str2sun(args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4798 | if (!sk) { |
| 4799 | 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] | 4800 | args[1], (int)sizeof(((struct sockaddr_un *)sk)->sun_path) - 1); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4801 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4802 | goto out; |
| 4803 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4804 | logsrv->addr = *sk; |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 4805 | } else { |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4806 | struct sockaddr_storage *sk = str2sa(args[1]); |
David du Colombier | 11bcb6c | 2011-03-24 12:23:00 +0100 | [diff] [blame] | 4807 | if (!sk) { |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4808 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[1]); |
| 4809 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4810 | goto out; |
| 4811 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4812 | logsrv->addr = *sk; |
| 4813 | if (!get_host_port(&logsrv->addr)) |
| 4814 | set_host_port(&logsrv->addr, SYSLOG_PORT); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4815 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4816 | |
| 4817 | LIST_ADDQ(&curproxy->logsrvs, &logsrv->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4818 | } |
| 4819 | else { |
| 4820 | Alert("parsing [%s:%d] : 'log' expects either <address[:port]> and <facility> or 'global' as arguments.\n", |
| 4821 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4822 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4823 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4824 | } |
| 4825 | } |
| 4826 | 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] | 4827 | int cur_arg; |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4828 | struct sockaddr_storage *sk; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4829 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4830 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4831 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4832 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4833 | if (!*args[1]) { |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4834 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optionally '%s' <addr>, and '%s' <name>.\n", |
| 4835 | file, linenum, "source", "usesrc", "interface"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4836 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4837 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4838 | } |
Willy Tarreau | 368480c | 2009-03-01 08:27:21 +0100 | [diff] [blame] | 4839 | |
| 4840 | /* we must first clear any optional default setting */ |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4841 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 4842 | free(curproxy->conn_src.iface_name); |
| 4843 | curproxy->conn_src.iface_name = NULL; |
| 4844 | curproxy->conn_src.iface_len = 0; |
Willy Tarreau | 368480c | 2009-03-01 08:27:21 +0100 | [diff] [blame] | 4845 | |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4846 | sk = str2sa(args[1]); |
| 4847 | if (!sk) { |
| 4848 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[1]); |
| 4849 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4850 | goto out; |
| 4851 | } |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4852 | curproxy->conn_src.source_addr = *sk; |
| 4853 | curproxy->conn_src.opts |= CO_SRC_BIND; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4854 | |
| 4855 | cur_arg = 2; |
| 4856 | while (*(args[cur_arg])) { |
| 4857 | if (!strcmp(args[cur_arg], "usesrc")) { /* address to use outside */ |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4858 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) |
| 4859 | #if !defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4860 | if (!is_addr(&curproxy->conn_src.source_addr)) { |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4861 | Alert("parsing [%s:%d] : '%s' requires an explicit 'source' address.\n", |
| 4862 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4863 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4864 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4865 | } |
| 4866 | #endif |
| 4867 | if (!*args[cur_arg + 1]) { |
| 4868 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n", |
| 4869 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4870 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4871 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4872 | } |
| 4873 | |
| 4874 | if (!strcmp(args[cur_arg + 1], "client")) { |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4875 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 4876 | curproxy->conn_src.opts |= CO_SRC_TPROXY_CLI; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4877 | } else if (!strcmp(args[cur_arg + 1], "clientip")) { |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4878 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 4879 | curproxy->conn_src.opts |= CO_SRC_TPROXY_CIP; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4880 | } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) { |
| 4881 | char *name, *end; |
| 4882 | |
| 4883 | name = args[cur_arg+1] + 7; |
| 4884 | while (isspace(*name)) |
| 4885 | name++; |
| 4886 | |
| 4887 | end = name; |
| 4888 | while (*end && !isspace(*end) && *end != ',' && *end != ')') |
| 4889 | end++; |
| 4890 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4891 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 4892 | curproxy->conn_src.opts |= CO_SRC_TPROXY_DYN; |
| 4893 | curproxy->conn_src.bind_hdr_name = calloc(1, end - name + 1); |
| 4894 | curproxy->conn_src.bind_hdr_len = end - name; |
| 4895 | memcpy(curproxy->conn_src.bind_hdr_name, name, end - name); |
| 4896 | curproxy->conn_src.bind_hdr_name[end-name] = '\0'; |
| 4897 | curproxy->conn_src.bind_hdr_occ = -1; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4898 | |
| 4899 | /* now look for an occurrence number */ |
| 4900 | while (isspace(*end)) |
| 4901 | end++; |
| 4902 | if (*end == ',') { |
| 4903 | end++; |
| 4904 | name = end; |
| 4905 | if (*end == '-') |
| 4906 | end++; |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 4907 | while (isdigit((int)*end)) |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4908 | end++; |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4909 | curproxy->conn_src.bind_hdr_occ = strl2ic(name, end-name); |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4910 | } |
| 4911 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4912 | if (curproxy->conn_src.bind_hdr_occ < -MAX_HDR_HISTORY) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4913 | Alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative" |
| 4914 | " occurrences values smaller than %d.\n", |
| 4915 | file, linenum, MAX_HDR_HISTORY); |
| 4916 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4917 | goto out; |
| 4918 | } |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4919 | } else { |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4920 | struct sockaddr_storage *sk = str2sa(args[cur_arg + 1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4921 | if (!sk) { |
| 4922 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[cur_arg + 1]); |
| 4923 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4924 | goto out; |
| 4925 | } |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4926 | curproxy->conn_src.tproxy_addr = *sk; |
| 4927 | curproxy->conn_src.opts |= CO_SRC_TPROXY_ADDR; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4928 | } |
| 4929 | global.last_checks |= LSTCHK_NETADM; |
| 4930 | #if !defined(CONFIG_HAP_LINUX_TPROXY) |
| 4931 | global.last_checks |= LSTCHK_CTTPROXY; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4932 | #endif |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4933 | #else /* no TPROXY support */ |
| 4934 | 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] | 4935 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4936 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4937 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4938 | #endif |
| 4939 | cur_arg += 2; |
| 4940 | continue; |
Willy Tarreau | 77074d5 | 2006-11-12 23:57:19 +0100 | [diff] [blame] | 4941 | } |
| 4942 | |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4943 | if (!strcmp(args[cur_arg], "interface")) { /* specifically bind to this interface */ |
| 4944 | #ifdef SO_BINDTODEVICE |
| 4945 | if (!*args[cur_arg + 1]) { |
| 4946 | Alert("parsing [%s:%d] : '%s' : missing interface name.\n", |
| 4947 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4948 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4949 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4950 | } |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4951 | free(curproxy->conn_src.iface_name); |
| 4952 | curproxy->conn_src.iface_name = strdup(args[cur_arg + 1]); |
| 4953 | curproxy->conn_src.iface_len = strlen(curproxy->conn_src.iface_name); |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4954 | global.last_checks |= LSTCHK_NETADM; |
| 4955 | #else |
| 4956 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 4957 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4958 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4959 | goto out; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4960 | #endif |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4961 | cur_arg += 2; |
| 4962 | continue; |
| 4963 | } |
| 4964 | 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] | 4965 | file, linenum, args[0], "interface", "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4966 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4967 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 4968 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4969 | } |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 4970 | else if (!strcmp(args[0], "usesrc")) { /* address to use outside: needs "source" first */ |
| 4971 | Alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n", |
| 4972 | file, linenum, "usesrc", "source"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4973 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4974 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 4975 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4976 | 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] | 4977 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4978 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 4979 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4980 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4981 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4982 | } |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4983 | |
| 4984 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 4985 | SMP_OPT_DIR_REQ, ACT_REPLACE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4986 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4987 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4988 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4989 | } |
| 4990 | else if (!strcmp(args[0], "reqdel")) { /* delete request header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4991 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 4992 | SMP_OPT_DIR_REQ, ACT_REMOVE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4993 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4994 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4995 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4996 | } |
| 4997 | 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] | 4998 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 4999 | SMP_OPT_DIR_REQ, ACT_DENY, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5000 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5001 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5002 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5003 | } |
| 5004 | 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] | 5005 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5006 | SMP_OPT_DIR_REQ, ACT_PASS, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5007 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5008 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5009 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5010 | } |
| 5011 | 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] | 5012 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5013 | SMP_OPT_DIR_REQ, ACT_ALLOW, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5014 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5015 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5016 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5017 | } |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 5018 | 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] | 5019 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5020 | SMP_OPT_DIR_REQ, ACT_TARPIT, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5021 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5022 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5023 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 5024 | } |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5025 | 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] | 5026 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5027 | SMP_OPT_DIR_REQ, ACT_SETBE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5028 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5029 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5030 | goto out; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5031 | } |
| 5032 | 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] | 5033 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5034 | SMP_OPT_DIR_REQ, ACT_SETBE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5035 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5036 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5037 | goto out; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5038 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5039 | 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] | 5040 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5041 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 5042 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5043 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5044 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5045 | } |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5046 | |
| 5047 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5048 | SMP_OPT_DIR_REQ, ACT_REPLACE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5049 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5050 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5051 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5052 | } |
| 5053 | 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] | 5054 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5055 | SMP_OPT_DIR_REQ, ACT_REMOVE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5056 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5057 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5058 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5059 | } |
| 5060 | 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] | 5061 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5062 | SMP_OPT_DIR_REQ, ACT_DENY, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5063 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5064 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5065 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5066 | } |
| 5067 | 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] | 5068 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5069 | SMP_OPT_DIR_REQ, ACT_PASS, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5070 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5071 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5072 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5073 | } |
| 5074 | 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] | 5075 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5076 | SMP_OPT_DIR_REQ, ACT_ALLOW, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5077 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5078 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5079 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5080 | } |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 5081 | 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] | 5082 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5083 | SMP_OPT_DIR_REQ, ACT_TARPIT, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5084 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5085 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5086 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 5087 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5088 | else if (!strcmp(args[0], "reqadd")) { /* add request header */ |
Willy Tarreau | f4f0412 | 2010-01-28 18:10:50 +0100 | [diff] [blame] | 5089 | struct cond_wordlist *wl; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5090 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5091 | if (curproxy == &defproxy) { |
| 5092 | 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] | 5093 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5094 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5095 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5096 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5097 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5098 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5099 | if (*(args[1]) == 0) { |
| 5100 | 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] | 5101 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5102 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5103 | } |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5104 | |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 5105 | if ((strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0)) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 5106 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args+2, &errmsg)) == NULL) { |
| 5107 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 5108 | file, linenum, args[0], errmsg); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 5109 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5110 | goto out; |
| 5111 | } |
| 5112 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
| 5113 | } |
| 5114 | else if (*args[2]) { |
| 5115 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 5116 | file, linenum, args[0], args[2]); |
| 5117 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5118 | goto out; |
| 5119 | } |
| 5120 | |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5121 | wl = calloc(1, sizeof(*wl)); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 5122 | wl->cond = cond; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5123 | wl->s = strdup(args[1]); |
| 5124 | LIST_ADDQ(&curproxy->req_add, &wl->list); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 5125 | warnif_misplaced_reqadd(curproxy, file, linenum, args[0]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5126 | } |
| 5127 | 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] | 5128 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5129 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 5130 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5131 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5132 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5133 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5134 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5135 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5136 | SMP_OPT_DIR_RES, ACT_REPLACE, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5137 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5138 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5139 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5140 | } |
| 5141 | else if (!strcmp(args[0], "rspdel")) { /* delete response header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5142 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5143 | SMP_OPT_DIR_RES, ACT_REMOVE, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5144 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5145 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5146 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5147 | } |
| 5148 | else if (!strcmp(args[0], "rspdeny")) { /* block response header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5149 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5150 | SMP_OPT_DIR_RES, ACT_DENY, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5151 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5152 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5153 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5154 | } |
| 5155 | 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] | 5156 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5157 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 5158 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5159 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5160 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5161 | } |
| 5162 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5163 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5164 | SMP_OPT_DIR_RES, ACT_REPLACE, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5165 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5166 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5167 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5168 | } |
| 5169 | 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] | 5170 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5171 | SMP_OPT_DIR_RES, ACT_REMOVE, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5172 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5173 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5174 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5175 | } |
| 5176 | 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] | 5177 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5178 | SMP_OPT_DIR_RES, ACT_DENY, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5179 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5180 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5181 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5182 | } |
| 5183 | else if (!strcmp(args[0], "rspadd")) { /* add response header */ |
Willy Tarreau | f4f0412 | 2010-01-28 18:10:50 +0100 | [diff] [blame] | 5184 | struct cond_wordlist *wl; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5185 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5186 | if (curproxy == &defproxy) { |
| 5187 | 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] | 5188 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5189 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5190 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5191 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5192 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5193 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5194 | if (*(args[1]) == 0) { |
| 5195 | 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] | 5196 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5197 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5198 | } |
| 5199 | |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5200 | if ((strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0)) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 5201 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args+2, &errmsg)) == NULL) { |
| 5202 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 5203 | file, linenum, args[0], errmsg); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5204 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5205 | goto out; |
| 5206 | } |
| 5207 | err_code |= warnif_cond_requires_req(cond, file, linenum); |
| 5208 | } |
| 5209 | else if (*args[2]) { |
| 5210 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 5211 | file, linenum, args[0], args[2]); |
| 5212 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5213 | goto out; |
| 5214 | } |
| 5215 | |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5216 | wl = calloc(1, sizeof(*wl)); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5217 | wl->cond = cond; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5218 | wl->s = strdup(args[1]); |
| 5219 | LIST_ADDQ(&curproxy->rsp_add, &wl->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5220 | } |
| 5221 | else if (!strcmp(args[0], "errorloc") || |
| 5222 | !strcmp(args[0], "errorloc302") || |
| 5223 | !strcmp(args[0], "errorloc303")) { /* error location */ |
| 5224 | int errnum, errlen; |
| 5225 | char *err; |
| 5226 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5227 | 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] | 5228 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5229 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5230 | if (*(args[2]) == 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 5231 | 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] | 5232 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5233 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5234 | } |
| 5235 | |
| 5236 | errnum = atol(args[1]); |
| 5237 | if (!strcmp(args[0], "errorloc303")) { |
| 5238 | err = malloc(strlen(HTTP_303) + strlen(args[2]) + 5); |
| 5239 | errlen = sprintf(err, "%s%s\r\n\r\n", HTTP_303, args[2]); |
| 5240 | } else { |
| 5241 | err = malloc(strlen(HTTP_302) + strlen(args[2]) + 5); |
| 5242 | errlen = sprintf(err, "%s%s\r\n\r\n", HTTP_302, args[2]); |
| 5243 | } |
| 5244 | |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 5245 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) { |
| 5246 | if (http_err_codes[rc] == errnum) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 5247 | chunk_destroy(&curproxy->errmsg[rc]); |
| 5248 | chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 5249 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5250 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5251 | } |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 5252 | |
| 5253 | if (rc >= HTTP_ERR_SIZE) { |
| 5254 | Warning("parsing [%s:%d] : status code %d not handled, error relocation will be ignored.\n", |
| 5255 | file, linenum, errnum); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5256 | free(err); |
| 5257 | } |
| 5258 | } |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5259 | else if (!strcmp(args[0], "errorfile")) { /* error message from a file */ |
| 5260 | int errnum, errlen, fd; |
| 5261 | char *err; |
| 5262 | struct stat stat; |
| 5263 | |
| 5264 | 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] | 5265 | err_code |= ERR_WARN; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5266 | |
| 5267 | if (*(args[2]) == 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 5268 | 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] | 5269 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5270 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5271 | } |
| 5272 | |
| 5273 | fd = open(args[2], O_RDONLY); |
| 5274 | if ((fd < 0) || (fstat(fd, &stat) < 0)) { |
| 5275 | Alert("parsing [%s:%d] : error opening file <%s> for custom error message <%s>.\n", |
| 5276 | file, linenum, args[2], args[1]); |
| 5277 | if (fd >= 0) |
| 5278 | close(fd); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5279 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5280 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5281 | } |
| 5282 | |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 5283 | if (stat.st_size <= global.tune.bufsize) { |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5284 | errlen = stat.st_size; |
| 5285 | } else { |
| 5286 | 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] | 5287 | file, linenum, args[2], global.tune.bufsize); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5288 | err_code |= ERR_WARN; |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 5289 | errlen = global.tune.bufsize; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5290 | } |
| 5291 | |
| 5292 | err = malloc(errlen); /* malloc() must succeed during parsing */ |
| 5293 | errnum = read(fd, err, errlen); |
| 5294 | if (errnum != errlen) { |
| 5295 | Alert("parsing [%s:%d] : error reading file <%s> for custom error message <%s>.\n", |
| 5296 | file, linenum, args[2], args[1]); |
| 5297 | close(fd); |
| 5298 | free(err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5299 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5300 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5301 | } |
| 5302 | close(fd); |
| 5303 | |
| 5304 | errnum = atol(args[1]); |
| 5305 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) { |
| 5306 | if (http_err_codes[rc] == errnum) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 5307 | chunk_destroy(&curproxy->errmsg[rc]); |
| 5308 | chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen); |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5309 | break; |
| 5310 | } |
| 5311 | } |
| 5312 | |
| 5313 | if (rc >= HTTP_ERR_SIZE) { |
| 5314 | Warning("parsing [%s:%d] : status code %d not handled, error customization will be ignored.\n", |
| 5315 | file, linenum, errnum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5316 | err_code |= ERR_WARN; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5317 | free(err); |
| 5318 | } |
| 5319 | } |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5320 | else if (!strcmp(args[0], "compression")) { |
| 5321 | struct comp *comp; |
| 5322 | if (curproxy->comp == NULL) { |
| 5323 | comp = calloc(1, sizeof(struct comp)); |
| 5324 | curproxy->comp = comp; |
| 5325 | } else { |
| 5326 | comp = curproxy->comp; |
| 5327 | } |
| 5328 | |
| 5329 | if (!strcmp(args[1], "algo")) { |
| 5330 | int cur_arg; |
William Lallemand | 8b52bb3 | 2012-11-16 18:06:41 +0100 | [diff] [blame] | 5331 | struct comp_ctx *ctx; |
William Lallemand | 552df67 | 2012-11-07 13:21:47 +0100 | [diff] [blame] | 5332 | |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5333 | cur_arg = 2; |
| 5334 | if (!*args[cur_arg]) { |
| 5335 | Alert("parsing [%s:%d] : '%s' expects <algorithm>\n", |
| 5336 | file, linenum, args[0]); |
| 5337 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5338 | goto out; |
| 5339 | } |
| 5340 | while (*(args[cur_arg])) { |
| 5341 | if (comp_append_algo(comp, args[cur_arg]) < 0) { |
| 5342 | Alert("parsing [%s:%d] : '%s' : '%s' is not a supported algorithm.\n", |
| 5343 | file, linenum, args[0], args[cur_arg]); |
| 5344 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5345 | goto out; |
| 5346 | } |
William Lallemand | 552df67 | 2012-11-07 13:21:47 +0100 | [diff] [blame] | 5347 | if (curproxy->comp->algos->init(&ctx, 9) == 0) { |
| 5348 | curproxy->comp->algos->end(&ctx); |
| 5349 | } else { |
| 5350 | Alert("parsing [%s:%d] : '%s' : Can't init '%s' algorithm.\n", |
| 5351 | file, linenum, args[0], args[cur_arg]); |
| 5352 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5353 | goto out; |
| 5354 | } |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5355 | cur_arg ++; |
| 5356 | continue; |
| 5357 | } |
| 5358 | } |
Willy Tarreau | 70737d1 | 2012-10-27 00:34:28 +0200 | [diff] [blame] | 5359 | else if (!strcmp(args[1], "offload")) { |
| 5360 | comp->offload = 1; |
| 5361 | } |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5362 | else if (!strcmp(args[1], "type")) { |
| 5363 | int cur_arg; |
| 5364 | cur_arg = 2; |
| 5365 | if (!*args[cur_arg]) { |
| 5366 | Alert("parsing [%s:%d] : '%s' expects <type>\n", |
| 5367 | file, linenum, args[0]); |
| 5368 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5369 | goto out; |
| 5370 | } |
| 5371 | while (*(args[cur_arg])) { |
| 5372 | comp_append_type(comp, args[cur_arg]); |
| 5373 | cur_arg ++; |
| 5374 | continue; |
| 5375 | } |
| 5376 | } |
| 5377 | else { |
Willy Tarreau | 70737d1 | 2012-10-27 00:34:28 +0200 | [diff] [blame] | 5378 | Alert("parsing [%s:%d] : '%s' expects 'algo', 'type' or 'offload'\n", |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5379 | file, linenum, args[0]); |
| 5380 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5381 | goto out; |
| 5382 | } |
| 5383 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5384 | else { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 5385 | struct cfg_kw_list *kwl; |
| 5386 | int index; |
| 5387 | |
| 5388 | list_for_each_entry(kwl, &cfg_keywords.list, list) { |
| 5389 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 5390 | if (kwl->kw[index].section != CFG_LISTEN) |
| 5391 | continue; |
| 5392 | if (strcmp(kwl->kw[index].kw, args[0]) == 0) { |
| 5393 | /* prepare error message just in case */ |
Willy Tarreau | 28a47d6 | 2012-09-18 20:02:48 +0200 | [diff] [blame] | 5394 | 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] | 5395 | if (rc < 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 5396 | Alert("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5397 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5398 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 5399 | } |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 5400 | else if (rc > 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 5401 | Warning("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5402 | err_code |= ERR_WARN; |
| 5403 | goto out; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 5404 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5405 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 5406 | } |
| 5407 | } |
| 5408 | } |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5409 | |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5410 | 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] | 5411 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5412 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5413 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5414 | out: |
Willy Tarreau | f4068b6 | 2012-05-08 17:37:49 +0200 | [diff] [blame] | 5415 | free(errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5416 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5417 | } |
| 5418 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5419 | int |
| 5420 | cfg_parse_users(const char *file, int linenum, char **args, int kwm) |
| 5421 | { |
| 5422 | |
| 5423 | int err_code = 0; |
| 5424 | const char *err; |
| 5425 | |
| 5426 | if (!strcmp(args[0], "userlist")) { /* new userlist */ |
| 5427 | struct userlist *newul; |
| 5428 | |
| 5429 | if (!*args[1]) { |
| 5430 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 5431 | file, linenum, args[0]); |
| 5432 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5433 | goto out; |
| 5434 | } |
| 5435 | |
| 5436 | err = invalid_char(args[1]); |
| 5437 | if (err) { |
| 5438 | Alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 5439 | file, linenum, *err, args[0], args[1]); |
| 5440 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5441 | goto out; |
| 5442 | } |
| 5443 | |
| 5444 | for (newul = userlist; newul; newul = newul->next) |
| 5445 | if (!strcmp(newul->name, args[1])) { |
| 5446 | Warning("parsing [%s:%d]: ignoring duplicated userlist '%s'.\n", |
| 5447 | file, linenum, args[1]); |
| 5448 | err_code |= ERR_WARN; |
| 5449 | goto out; |
| 5450 | } |
| 5451 | |
| 5452 | newul = (struct userlist *)calloc(1, sizeof(struct userlist)); |
| 5453 | if (!newul) { |
| 5454 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 5455 | err_code |= ERR_ALERT | ERR_ABORT; |
| 5456 | goto out; |
| 5457 | } |
| 5458 | |
| 5459 | newul->groupusers = calloc(MAX_AUTH_GROUPS, sizeof(char *)); |
| 5460 | newul->name = strdup(args[1]); |
| 5461 | |
| 5462 | if (!newul->groupusers | !newul->name) { |
| 5463 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 5464 | err_code |= ERR_ALERT | ERR_ABORT; |
| 5465 | goto out; |
| 5466 | } |
| 5467 | |
| 5468 | newul->next = userlist; |
| 5469 | userlist = newul; |
| 5470 | |
| 5471 | } else if (!strcmp(args[0], "group")) { /* new group */ |
| 5472 | int cur_arg, i; |
| 5473 | const char *err; |
| 5474 | |
| 5475 | if (!*args[1]) { |
| 5476 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 5477 | file, linenum, args[0]); |
| 5478 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5479 | goto out; |
| 5480 | } |
| 5481 | |
| 5482 | err = invalid_char(args[1]); |
| 5483 | if (err) { |
| 5484 | Alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 5485 | file, linenum, *err, args[0], args[1]); |
| 5486 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5487 | goto out; |
| 5488 | } |
| 5489 | |
| 5490 | for(i = 0; i < userlist->grpcnt; i++) |
| 5491 | if (!strcmp(userlist->groups[i], args[1])) { |
| 5492 | Warning("parsing [%s:%d]: ignoring duplicated group '%s' in userlist '%s'.\n", |
| 5493 | file, linenum, args[1], userlist->name); |
| 5494 | err_code |= ERR_ALERT; |
| 5495 | goto out; |
| 5496 | } |
| 5497 | |
| 5498 | if (userlist->grpcnt >= MAX_AUTH_GROUPS) { |
| 5499 | Alert("parsing [%s:%d]: too many groups (%u) in in userlist '%s' while adding group '%s'.\n", |
| 5500 | file, linenum, MAX_AUTH_GROUPS, userlist->name, args[1]); |
| 5501 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5502 | goto out; |
| 5503 | } |
| 5504 | |
| 5505 | cur_arg = 2; |
| 5506 | |
| 5507 | while (*args[cur_arg]) { |
| 5508 | if (!strcmp(args[cur_arg], "users")) { |
| 5509 | userlist->groupusers[userlist->grpcnt] = strdup(args[cur_arg + 1]); |
| 5510 | cur_arg += 2; |
| 5511 | continue; |
| 5512 | } else { |
| 5513 | Alert("parsing [%s:%d]: '%s' only supports 'users' option.\n", |
| 5514 | file, linenum, args[0]); |
| 5515 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5516 | goto out; |
| 5517 | } |
| 5518 | } |
| 5519 | |
| 5520 | userlist->groups[userlist->grpcnt++] = strdup(args[1]); |
| 5521 | } else if (!strcmp(args[0], "user")) { /* new user */ |
| 5522 | struct auth_users *newuser; |
| 5523 | int cur_arg; |
| 5524 | |
| 5525 | if (!*args[1]) { |
| 5526 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 5527 | file, linenum, args[0]); |
| 5528 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5529 | goto out; |
| 5530 | } |
| 5531 | |
| 5532 | for (newuser = userlist->users; newuser; newuser = newuser->next) |
| 5533 | if (!strcmp(newuser->user, args[1])) { |
| 5534 | Warning("parsing [%s:%d]: ignoring duplicated user '%s' in userlist '%s'.\n", |
| 5535 | file, linenum, args[1], userlist->name); |
| 5536 | err_code |= ERR_ALERT; |
| 5537 | goto out; |
| 5538 | } |
| 5539 | |
| 5540 | newuser = (struct auth_users *)calloc(1, sizeof(struct auth_users)); |
| 5541 | if (!newuser) { |
| 5542 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 5543 | err_code |= ERR_ALERT | ERR_ABORT; |
| 5544 | goto out; |
| 5545 | } |
| 5546 | |
| 5547 | newuser->user = strdup(args[1]); |
| 5548 | |
| 5549 | newuser->next = userlist->users; |
| 5550 | userlist->users = newuser; |
| 5551 | |
| 5552 | cur_arg = 2; |
| 5553 | |
| 5554 | while (*args[cur_arg]) { |
| 5555 | if (!strcmp(args[cur_arg], "password")) { |
| 5556 | #ifndef CONFIG_HAP_CRYPT |
| 5557 | Warning("parsing [%s:%d]: no crypt(3) support compiled, encrypted passwords will not work.\n", |
| 5558 | file, linenum); |
| 5559 | err_code |= ERR_ALERT; |
| 5560 | #endif |
| 5561 | newuser->pass = strdup(args[cur_arg + 1]); |
| 5562 | cur_arg += 2; |
| 5563 | continue; |
| 5564 | } else if (!strcmp(args[cur_arg], "insecure-password")) { |
| 5565 | newuser->pass = strdup(args[cur_arg + 1]); |
| 5566 | newuser->flags |= AU_O_INSECURE; |
| 5567 | cur_arg += 2; |
| 5568 | continue; |
| 5569 | } else if (!strcmp(args[cur_arg], "groups")) { |
Willy Tarreau | b4c06b7 | 2010-02-02 11:28:20 +0100 | [diff] [blame] | 5570 | newuser->u.groups = strdup(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5571 | cur_arg += 2; |
| 5572 | continue; |
| 5573 | } else { |
| 5574 | Alert("parsing [%s:%d]: '%s' only supports 'password', 'insecure-password' and 'groups' options.\n", |
| 5575 | file, linenum, args[0]); |
| 5576 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5577 | goto out; |
| 5578 | } |
| 5579 | } |
| 5580 | } else { |
| 5581 | Alert("parsing [%s:%d]: unknown keyword '%s' in '%s' section\n", file, linenum, args[0], "users"); |
| 5582 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5583 | } |
| 5584 | |
| 5585 | out: |
| 5586 | return err_code; |
| 5587 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5588 | |
| 5589 | /* |
| 5590 | * This function reads and parses the configuration file given in the argument. |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5591 | * Returns the error code, 0 if OK, or any combination of : |
| 5592 | * - ERR_ABORT: must abort ASAP |
| 5593 | * - ERR_FATAL: we can continue parsing but not start the service |
| 5594 | * - ERR_WARN: a warning has been emitted |
| 5595 | * - ERR_ALERT: an alert has been emitted |
| 5596 | * Only the two first ones can stop processing, the two others are just |
| 5597 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5598 | */ |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 5599 | int readcfgfile(const char *file) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5600 | { |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5601 | char thisline[LINESIZE]; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5602 | FILE *f; |
| 5603 | int linenum = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5604 | int confsect = CFG_NONE; |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5605 | int err_code = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5606 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5607 | if ((f=fopen(file,"r")) == NULL) |
| 5608 | return -1; |
| 5609 | |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5610 | while (fgets(thisline, sizeof(thisline), f) != NULL) { |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 5611 | int arg, kwm = KWM_STD; |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5612 | char *end; |
| 5613 | char *args[MAX_LINE_ARGS + 1]; |
| 5614 | char *line = thisline; |
| 5615 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5616 | linenum++; |
| 5617 | |
| 5618 | end = line + strlen(line); |
| 5619 | |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5620 | if (end-line == sizeof(thisline)-1 && *(end-1) != '\n') { |
| 5621 | /* Check if we reached the limit and the last char is not \n. |
| 5622 | * Watch out for the last line without the terminating '\n'! |
| 5623 | */ |
| 5624 | Alert("parsing [%s:%d]: line too long, limit: %d.\n", |
Willy Tarreau | 5e4a6f1 | 2009-04-11 19:42:49 +0200 | [diff] [blame] | 5625 | file, linenum, (int)sizeof(thisline)-1); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5626 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5627 | } |
| 5628 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5629 | /* skip leading spaces */ |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 5630 | while (isspace((unsigned char)*line)) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5631 | line++; |
| 5632 | |
| 5633 | arg = 0; |
| 5634 | args[arg] = line; |
| 5635 | |
| 5636 | while (*line && arg < MAX_LINE_ARGS) { |
| 5637 | /* first, we'll replace \\, \<space>, \#, \r, \n, \t, \xXX with their |
| 5638 | * C equivalent value. Other combinations left unchanged (eg: \1). |
| 5639 | */ |
| 5640 | if (*line == '\\') { |
| 5641 | int skip = 0; |
| 5642 | if (line[1] == ' ' || line[1] == '\\' || line[1] == '#') { |
| 5643 | *line = line[1]; |
| 5644 | skip = 1; |
| 5645 | } |
| 5646 | else if (line[1] == 'r') { |
| 5647 | *line = '\r'; |
| 5648 | skip = 1; |
| 5649 | } |
| 5650 | else if (line[1] == 'n') { |
| 5651 | *line = '\n'; |
| 5652 | skip = 1; |
| 5653 | } |
| 5654 | else if (line[1] == 't') { |
| 5655 | *line = '\t'; |
| 5656 | skip = 1; |
| 5657 | } |
| 5658 | else if (line[1] == 'x') { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5659 | if ((line + 3 < end) && ishex(line[2]) && ishex(line[3])) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5660 | unsigned char hex1, hex2; |
| 5661 | hex1 = toupper(line[2]) - '0'; |
| 5662 | hex2 = toupper(line[3]) - '0'; |
| 5663 | if (hex1 > 9) hex1 -= 'A' - '9' - 1; |
| 5664 | if (hex2 > 9) hex2 -= 'A' - '9' - 1; |
| 5665 | *line = (hex1<<4) + hex2; |
| 5666 | skip = 3; |
| 5667 | } |
| 5668 | else { |
| 5669 | 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] | 5670 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5671 | } |
| 5672 | } |
| 5673 | if (skip) { |
Cyril Bonté | dd1b01d | 2009-12-06 13:43:42 +0100 | [diff] [blame] | 5674 | memmove(line + 1, line + 1 + skip, end - (line + skip)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5675 | end -= skip; |
| 5676 | } |
| 5677 | line++; |
| 5678 | } |
| 5679 | else if (*line == '#' || *line == '\n' || *line == '\r') { |
| 5680 | /* end of string, end of loop */ |
| 5681 | *line = 0; |
| 5682 | break; |
| 5683 | } |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 5684 | else if (isspace((unsigned char)*line)) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5685 | /* a non-escaped space is an argument separator */ |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5686 | *line++ = '\0'; |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 5687 | while (isspace((unsigned char)*line)) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5688 | line++; |
| 5689 | args[++arg] = line; |
| 5690 | } |
| 5691 | else { |
| 5692 | line++; |
| 5693 | } |
| 5694 | } |
| 5695 | |
| 5696 | /* empty line */ |
| 5697 | if (!**args) |
| 5698 | continue; |
| 5699 | |
Willy Tarreau | 7bb651e | 2009-11-09 21:16:53 +0100 | [diff] [blame] | 5700 | if (*line) { |
| 5701 | /* we had to stop due to too many args. |
| 5702 | * Let's terminate the string, print the offending part then cut the |
| 5703 | * last arg. |
| 5704 | */ |
| 5705 | while (*line && *line != '#' && *line != '\n' && *line != '\r') |
| 5706 | line++; |
| 5707 | *line = '\0'; |
| 5708 | |
Krzysztof Piotr Oledzki | 500b8f0 | 2009-12-15 22:34:51 +0100 | [diff] [blame] | 5709 | 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] | 5710 | file, linenum, arg + 1, (long)(args[arg] - thisline + 1), args[arg]); |
Willy Tarreau | 7bb651e | 2009-11-09 21:16:53 +0100 | [diff] [blame] | 5711 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5712 | args[arg] = line; |
| 5713 | } |
| 5714 | |
Willy Tarreau | 540abe4 | 2007-05-02 20:50:16 +0200 | [diff] [blame] | 5715 | /* zero out remaining args and ensure that at least one entry |
| 5716 | * is zeroed out. |
| 5717 | */ |
| 5718 | while (++arg <= MAX_LINE_ARGS) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5719 | args[arg] = line; |
| 5720 | } |
| 5721 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 5722 | /* check for keyword modifiers "no" and "default" */ |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5723 | if (!strcmp(args[0], "no")) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5724 | char *tmp; |
| 5725 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 5726 | kwm = KWM_NO; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5727 | tmp = args[0]; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5728 | for (arg=0; *args[arg+1]; arg++) |
| 5729 | args[arg] = args[arg+1]; // shift args after inversion |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5730 | *tmp = '\0'; // fix the next arg to \0 |
| 5731 | args[arg] = tmp; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5732 | } |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 5733 | else if (!strcmp(args[0], "default")) { |
| 5734 | kwm = KWM_DEF; |
| 5735 | for (arg=0; *args[arg+1]; arg++) |
| 5736 | args[arg] = args[arg+1]; // shift args after inversion |
| 5737 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5738 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5739 | if (kwm != KWM_STD && strcmp(args[0], "option") != 0 && \ |
| 5740 | strcmp(args[0], "log") != 0) { |
| 5741 | 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] | 5742 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5743 | } |
| 5744 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5745 | if (!strcmp(args[0], "listen") || |
| 5746 | !strcmp(args[0], "frontend") || |
| 5747 | !strcmp(args[0], "backend") || |
| 5748 | !strcmp(args[0], "ruleset") || |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5749 | !strcmp(args[0], "defaults")) { /* new proxy */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5750 | confsect = CFG_LISTEN; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 5751 | free(cursection); |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5752 | cursection = strdup(args[0]); |
| 5753 | } |
| 5754 | else if (!strcmp(args[0], "global")) { /* global config */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5755 | confsect = CFG_GLOBAL; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 5756 | free(cursection); |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5757 | cursection = strdup(args[0]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 5758 | } |
| 5759 | else if (!strcmp(args[0], "userlist")) { |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5760 | confsect = CFG_USERLIST; |
| 5761 | free(cursection); |
| 5762 | cursection = strdup(args[0]); |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5763 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 5764 | else if (!strcmp(args[0], "peers")) { |
| 5765 | confsect = CFG_PEERS; |
| 5766 | free(cursection); |
| 5767 | cursection = strdup(args[0]); |
| 5768 | } |
| 5769 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5770 | /* else it's a section keyword */ |
| 5771 | |
| 5772 | switch (confsect) { |
| 5773 | case CFG_LISTEN: |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5774 | err_code |= cfg_parse_listen(file, linenum, args, kwm); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5775 | break; |
| 5776 | case CFG_GLOBAL: |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5777 | err_code |= cfg_parse_global(file, linenum, args, kwm); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5778 | break; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5779 | case CFG_USERLIST: |
| 5780 | err_code |= cfg_parse_users(file, linenum, args, kwm); |
| 5781 | break; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 5782 | case CFG_PEERS: |
| 5783 | err_code |= cfg_parse_peers(file, linenum, args, kwm); |
| 5784 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5785 | default: |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5786 | 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] | 5787 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5788 | } |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5789 | |
| 5790 | if (err_code & ERR_ABORT) |
| 5791 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5792 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 5793 | free(cursection); |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5794 | cursection = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5795 | fclose(f); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5796 | return err_code; |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5797 | } |
| 5798 | |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 5799 | /* |
| 5800 | * Returns the error code, 0 if OK, or any combination of : |
| 5801 | * - ERR_ABORT: must abort ASAP |
| 5802 | * - ERR_FATAL: we can continue parsing but not start the service |
| 5803 | * - ERR_WARN: a warning has been emitted |
| 5804 | * - ERR_ALERT: an alert has been emitted |
| 5805 | * Only the two first ones can stop processing, the two others are just |
| 5806 | * indicators. |
| 5807 | */ |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5808 | int check_config_validity() |
| 5809 | { |
| 5810 | int cfgerr = 0; |
| 5811 | struct proxy *curproxy = NULL; |
| 5812 | struct server *newsrv = NULL; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5813 | struct userlist *curuserlist = NULL; |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 5814 | int err_code = 0; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 5815 | unsigned int next_pxid = 1; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 5816 | struct bind_conf *bind_conf; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5817 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 5818 | bind_conf = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5819 | /* |
| 5820 | * Now, check for the integrity of all that we have collected. |
| 5821 | */ |
| 5822 | |
| 5823 | /* will be needed further to delay some tasks */ |
Willy Tarreau | b0b37bc | 2008-06-23 14:00:57 +0200 | [diff] [blame] | 5824 | tv_update_date(0,1); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5825 | |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 5826 | if (!global.tune.max_http_hdr) |
| 5827 | global.tune.max_http_hdr = MAX_HTTP_HDR; |
| 5828 | |
| 5829 | if (!global.tune.cookie_len) |
| 5830 | global.tune.cookie_len = CAPTURE_LEN; |
| 5831 | |
| 5832 | pool2_capture = create_pool("capture", global.tune.cookie_len, MEM_F_SHARED); |
| 5833 | |
Willy Tarreau | 55bc0f8 | 2009-03-15 14:51:53 +0100 | [diff] [blame] | 5834 | /* first, we will invert the proxy list order */ |
| 5835 | curproxy = NULL; |
| 5836 | while (proxy) { |
| 5837 | struct proxy *next; |
| 5838 | |
| 5839 | next = proxy->next; |
| 5840 | proxy->next = curproxy; |
| 5841 | curproxy = proxy; |
| 5842 | if (!next) |
| 5843 | break; |
| 5844 | proxy = next; |
| 5845 | } |
| 5846 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5847 | while (curproxy != NULL) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 5848 | struct switching_rule *rule; |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 5849 | struct server_rule *srule; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5850 | struct sticking_rule *mrule; |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 5851 | struct tcp_rule *trule; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 5852 | struct listener *listener; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 5853 | unsigned int next_id; |
Willy Tarreau | 16a2147 | 2012-11-19 12:39:59 +0100 | [diff] [blame] | 5854 | int nbproc; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 5855 | |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 5856 | if (curproxy->uuid < 0) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 5857 | /* proxy ID not set, use automatic numbering with first |
| 5858 | * spare entry starting with next_pxid. |
| 5859 | */ |
| 5860 | next_pxid = get_next_id(&used_proxy_id, next_pxid); |
| 5861 | curproxy->conf.id.key = curproxy->uuid = next_pxid; |
| 5862 | eb32_insert(&used_proxy_id, &curproxy->conf.id); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 5863 | } |
Krzysztof Piotr Oledzki | df5cb9f | 2010-02-05 20:58:27 +0100 | [diff] [blame] | 5864 | next_pxid++; |
| 5865 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 5866 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5867 | if (curproxy->state == PR_STSTOPPED) { |
Willy Tarreau | da250db | 2008-10-12 12:07:48 +0200 | [diff] [blame] | 5868 | /* ensure we don't keep listeners uselessly bound */ |
| 5869 | stop_proxy(curproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5870 | curproxy = curproxy->next; |
| 5871 | continue; |
| 5872 | } |
| 5873 | |
Willy Tarreau | 16a2147 | 2012-11-19 12:39:59 +0100 | [diff] [blame] | 5874 | /* number of processes this proxy is bound to */ |
| 5875 | nbproc = curproxy->bind_proc ? popcount(curproxy->bind_proc) : global.nbproc; |
| 5876 | |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 5877 | switch (curproxy->mode) { |
| 5878 | case PR_MODE_HEALTH: |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5879 | cfgerr += proxy_cfg_ensure_no_http(curproxy); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 5880 | if (!(curproxy->cap & PR_CAP_FE)) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5881 | Alert("config : %s '%s' cannot be in health mode as it has no frontend capability.\n", |
| 5882 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 5883 | cfgerr++; |
| 5884 | } |
| 5885 | |
| 5886 | if (curproxy->srv != NULL) |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5887 | Warning("config : servers will be ignored for %s '%s'.\n", |
| 5888 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 5889 | break; |
| 5890 | |
| 5891 | case PR_MODE_TCP: |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5892 | cfgerr += proxy_cfg_ensure_no_http(curproxy); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 5893 | break; |
| 5894 | |
| 5895 | case PR_MODE_HTTP: |
Willy Tarreau | a9fb083 | 2009-07-10 20:53:53 +0200 | [diff] [blame] | 5896 | curproxy->acl_requires |= ACL_USE_L7_ANY; |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 5897 | break; |
| 5898 | } |
| 5899 | |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 5900 | if ((curproxy->cap & PR_CAP_BE) && (curproxy->mode != PR_MODE_HEALTH)) { |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 5901 | if (curproxy->lbprm.algo & BE_LB_KIND) { |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 5902 | if (curproxy->options & PR_O_TRANSP) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5903 | Alert("config : %s '%s' cannot use both transparent and balance mode.\n", |
| 5904 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 5905 | cfgerr++; |
| 5906 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5907 | #ifdef WE_DONT_SUPPORT_SERVERLESS_LISTENERS |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 5908 | else if (curproxy->srv == NULL) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5909 | Alert("config : %s '%s' needs at least 1 server in balance mode.\n", |
| 5910 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 5911 | cfgerr++; |
| 5912 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5913 | #endif |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 5914 | else if (curproxy->options & PR_O_DISPATCH) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5915 | Warning("config : dispatch address of %s '%s' will be ignored in balance mode.\n", |
| 5916 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 5917 | err_code |= ERR_WARN; |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 5918 | } |
| 5919 | } |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 5920 | 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] | 5921 | /* If no LB algo is set in a backend, and we're not in |
| 5922 | * transparent mode, dispatch mode nor proxy mode, we |
| 5923 | * want to use balance roundrobin by default. |
| 5924 | */ |
| 5925 | curproxy->lbprm.algo &= ~BE_LB_ALGO; |
| 5926 | curproxy->lbprm.algo |= BE_LB_ALGO_RR; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5927 | } |
| 5928 | } |
Willy Tarreau | 193cf93 | 2007-09-17 10:17:23 +0200 | [diff] [blame] | 5929 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 5930 | if (curproxy->options & PR_O_DISPATCH) |
| 5931 | curproxy->options &= ~(PR_O_TRANSP | PR_O_HTTP_PROXY); |
| 5932 | else if (curproxy->options & PR_O_HTTP_PROXY) |
| 5933 | curproxy->options &= ~(PR_O_DISPATCH | PR_O_TRANSP); |
| 5934 | else if (curproxy->options & PR_O_TRANSP) |
| 5935 | curproxy->options &= ~(PR_O_DISPATCH | PR_O_HTTP_PROXY); |
Willy Tarreau | 8293658 | 2007-11-30 15:20:09 +0100 | [diff] [blame] | 5936 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 5937 | if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_HTTP_CHK) { |
| 5938 | if (curproxy->options & PR_O_DISABLE404) { |
| 5939 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n", |
| 5940 | "disable-on-404", proxy_type_str(curproxy), curproxy->id); |
| 5941 | err_code |= ERR_WARN; |
| 5942 | curproxy->options &= ~PR_O_DISABLE404; |
| 5943 | } |
| 5944 | if (curproxy->options2 & PR_O2_CHK_SNDST) { |
| 5945 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n", |
| 5946 | "send-state", proxy_type_str(curproxy), curproxy->id); |
| 5947 | err_code |= ERR_WARN; |
| 5948 | curproxy->options &= ~PR_O2_CHK_SNDST; |
| 5949 | } |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 5950 | } |
| 5951 | |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5952 | /* if a default backend was specified, let's find it */ |
| 5953 | if (curproxy->defbe.name) { |
| 5954 | struct proxy *target; |
| 5955 | |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 5956 | target = findproxy_mode(curproxy->defbe.name, curproxy->mode, PR_CAP_BE); |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 5957 | if (!target) { |
| 5958 | Alert("Proxy '%s': unable to find required default_backend: '%s'.\n", |
| 5959 | curproxy->id, curproxy->defbe.name); |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5960 | cfgerr++; |
| 5961 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 5962 | Alert("Proxy '%s': loop detected for default_backend: '%s'.\n", |
| 5963 | curproxy->id, curproxy->defbe.name); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 5964 | cfgerr++; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5965 | } else { |
| 5966 | free(curproxy->defbe.name); |
| 5967 | curproxy->defbe.be = target; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 5968 | /* we force the backend to be present on at least all of |
| 5969 | * the frontend's processes. |
| 5970 | */ |
| 5971 | target->bind_proc = curproxy->bind_proc ? |
| 5972 | (target->bind_proc | curproxy->bind_proc) : 0; |
Willy Tarreau | ff67813 | 2012-02-13 14:32:34 +0100 | [diff] [blame] | 5973 | |
| 5974 | /* Emit a warning if this proxy also has some servers */ |
| 5975 | if (curproxy->srv) { |
| 5976 | Warning("In proxy '%s', the 'default_backend' rule always has precedence over the servers, which will never be used.\n", |
| 5977 | curproxy->id); |
| 5978 | err_code |= ERR_WARN; |
| 5979 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5980 | } |
| 5981 | } |
| 5982 | |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5983 | /* find the target proxy in setbe */ |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5984 | if (curproxy->mode == PR_MODE_HTTP && curproxy->req_exp != NULL) { |
| 5985 | /* map jump target for ACT_SETBE in req_rep chain */ |
| 5986 | struct hdr_exp *exp; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5987 | for (exp = curproxy->req_exp; exp != NULL; exp = exp->next) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 5988 | struct proxy *target; |
| 5989 | |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5990 | if (exp->action != ACT_SETBE) |
| 5991 | continue; |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 5992 | |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 5993 | target = findproxy_mode(exp->replace, PR_MODE_HTTP, PR_CAP_BE); |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 5994 | if (!target) { |
| 5995 | Alert("Proxy '%s': unable to find required setbe: '%s'.\n", |
| 5996 | curproxy->id, exp->replace); |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5997 | cfgerr++; |
| 5998 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 5999 | Alert("Proxy '%s': loop detected for setbe: '%s'.\n", |
| 6000 | curproxy->id, exp->replace); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 6001 | cfgerr++; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 6002 | } else { |
| 6003 | free((void *)exp->replace); |
| 6004 | exp->replace = (const char *)target; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 6005 | /* we force the backend to be present on at least all of |
| 6006 | * the frontend's processes. |
| 6007 | */ |
| 6008 | target->bind_proc = curproxy->bind_proc ? |
| 6009 | (target->bind_proc | curproxy->bind_proc) : 0; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 6010 | } |
| 6011 | } |
| 6012 | } |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6013 | |
| 6014 | /* find the target proxy for 'use_backend' rules */ |
| 6015 | list_for_each_entry(rule, &curproxy->switching_rules, list) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6016 | struct proxy *target; |
| 6017 | |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 6018 | target = findproxy_mode(rule->be.name, curproxy->mode, PR_CAP_BE); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6019 | |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6020 | if (!target) { |
| 6021 | Alert("Proxy '%s': unable to find required use_backend: '%s'.\n", |
| 6022 | curproxy->id, rule->be.name); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6023 | cfgerr++; |
| 6024 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6025 | Alert("Proxy '%s': loop detected for use_backend: '%s'.\n", |
| 6026 | curproxy->id, rule->be.name); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6027 | cfgerr++; |
| 6028 | } else { |
| 6029 | free((void *)rule->be.name); |
| 6030 | rule->be.backend = target; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 6031 | /* we force the backend to be present on at least all of |
| 6032 | * the frontend's processes. |
| 6033 | */ |
| 6034 | target->bind_proc = curproxy->bind_proc ? |
| 6035 | (target->bind_proc | curproxy->bind_proc) : 0; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6036 | } |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 6037 | } |
| 6038 | |
| 6039 | /* find the target proxy for 'use_backend' rules */ |
| 6040 | list_for_each_entry(srule, &curproxy->server_rules, list) { |
| 6041 | struct server *target = findserver(curproxy, srule->srv.name); |
| 6042 | |
| 6043 | if (!target) { |
| 6044 | Alert("config : %s '%s' : unable to find server '%s' referenced in a 'use-server' rule.\n", |
| 6045 | proxy_type_str(curproxy), curproxy->id, srule->srv.name); |
| 6046 | cfgerr++; |
| 6047 | continue; |
| 6048 | } |
| 6049 | free((void *)srule->srv.name); |
| 6050 | srule->srv.ptr = target; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6051 | } |
| 6052 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6053 | /* find the target table for 'stick' rules */ |
| 6054 | list_for_each_entry(mrule, &curproxy->sticking_rules, list) { |
| 6055 | struct proxy *target; |
| 6056 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 6057 | curproxy->be_req_ana |= AN_REQ_STICKING_RULES; |
| 6058 | if (mrule->flags & STK_IS_STORE) |
| 6059 | curproxy->be_rsp_ana |= AN_RES_STORE_RULES; |
| 6060 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6061 | if (mrule->table.name) |
Willy Tarreau | c00cdc2 | 2010-06-06 16:48:26 +0200 | [diff] [blame] | 6062 | target = findproxy(mrule->table.name, 0); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6063 | else |
| 6064 | target = curproxy; |
| 6065 | |
| 6066 | if (!target) { |
| 6067 | Alert("Proxy '%s': unable to find stick-table '%s'.\n", |
| 6068 | curproxy->id, mrule->table.name); |
| 6069 | cfgerr++; |
| 6070 | } |
| 6071 | else if (target->table.size == 0) { |
| 6072 | Alert("Proxy '%s': stick-table '%s' used but not configured.\n", |
| 6073 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 6074 | cfgerr++; |
| 6075 | } |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 6076 | else if (!stktable_compatible_sample(mrule->expr, target->table.type)) { |
| 6077 | 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] | 6078 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 6079 | cfgerr++; |
| 6080 | } |
| 6081 | else { |
| 6082 | free((void *)mrule->table.name); |
| 6083 | mrule->table.t = &(target->table); |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 6084 | stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID, NULL); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6085 | } |
| 6086 | } |
| 6087 | |
| 6088 | /* find the target table for 'store response' rules */ |
| 6089 | list_for_each_entry(mrule, &curproxy->storersp_rules, list) { |
| 6090 | struct proxy *target; |
| 6091 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 6092 | curproxy->be_rsp_ana |= AN_RES_STORE_RULES; |
| 6093 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6094 | if (mrule->table.name) |
Willy Tarreau | c00cdc2 | 2010-06-06 16:48:26 +0200 | [diff] [blame] | 6095 | target = findproxy(mrule->table.name, 0); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6096 | else |
| 6097 | target = curproxy; |
| 6098 | |
| 6099 | if (!target) { |
| 6100 | Alert("Proxy '%s': unable to find store table '%s'.\n", |
| 6101 | curproxy->id, mrule->table.name); |
| 6102 | cfgerr++; |
| 6103 | } |
| 6104 | else if (target->table.size == 0) { |
| 6105 | Alert("Proxy '%s': stick-table '%s' used but not configured.\n", |
| 6106 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 6107 | cfgerr++; |
| 6108 | } |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 6109 | else if (!stktable_compatible_sample(mrule->expr, target->table.type)) { |
| 6110 | 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] | 6111 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 6112 | cfgerr++; |
| 6113 | } |
| 6114 | else { |
| 6115 | free((void *)mrule->table.name); |
| 6116 | mrule->table.t = &(target->table); |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 6117 | stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID, NULL); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6118 | } |
| 6119 | } |
| 6120 | |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 6121 | /* find the target table for 'tcp-request' layer 4 rules */ |
| 6122 | list_for_each_entry(trule, &curproxy->tcp_req.l4_rules, list) { |
| 6123 | struct proxy *target; |
| 6124 | |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6125 | 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] | 6126 | continue; |
| 6127 | |
| 6128 | if (trule->act_prm.trk_ctr.table.n) |
| 6129 | target = findproxy(trule->act_prm.trk_ctr.table.n, 0); |
| 6130 | else |
| 6131 | target = curproxy; |
| 6132 | |
| 6133 | if (!target) { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6134 | Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n", |
| 6135 | curproxy->id, trule->act_prm.trk_ctr.table.n, |
| 6136 | trule->action == TCP_ACT_TRK_SC1 ? 1 : 2); |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 6137 | cfgerr++; |
| 6138 | } |
| 6139 | else if (target->table.size == 0) { |
| 6140 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
| 6141 | curproxy->id, trule->act_prm.trk_ctr.table.n ? trule->act_prm.trk_ctr.table.n : curproxy->id); |
| 6142 | cfgerr++; |
| 6143 | } |
Willy Tarreau | 5f53de7 | 2012-12-12 00:25:44 +0100 | [diff] [blame] | 6144 | else if (!stktable_compatible_sample(trule->act_prm.trk_ctr.expr, target->table.type)) { |
| 6145 | Alert("Proxy '%s': stick-table '%s' uses a type incompatible with the 'track-sc%d' rule.\n", |
| 6146 | curproxy->id, trule->act_prm.trk_ctr.table.n ? trule->act_prm.trk_ctr.table.n : curproxy->id, |
| 6147 | trule->action == TCP_ACT_TRK_SC1 ? 1 : 2); |
| 6148 | cfgerr++; |
| 6149 | } |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 6150 | else { |
| 6151 | free(trule->act_prm.trk_ctr.table.n); |
| 6152 | trule->act_prm.trk_ctr.table.t = &target->table; |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6153 | /* 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] | 6154 | * to pass a list of counters to track and allocate them right here using |
| 6155 | * stktable_alloc_data_type(). |
| 6156 | */ |
| 6157 | } |
| 6158 | } |
| 6159 | |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 6160 | /* find the target table for 'tcp-request' layer 6 rules */ |
| 6161 | list_for_each_entry(trule, &curproxy->tcp_req.inspect_rules, list) { |
| 6162 | struct proxy *target; |
| 6163 | |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6164 | 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] | 6165 | continue; |
| 6166 | |
| 6167 | if (trule->act_prm.trk_ctr.table.n) |
| 6168 | target = findproxy(trule->act_prm.trk_ctr.table.n, 0); |
| 6169 | else |
| 6170 | target = curproxy; |
| 6171 | |
| 6172 | if (!target) { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6173 | Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n", |
| 6174 | curproxy->id, trule->act_prm.trk_ctr.table.n, |
| 6175 | trule->action == TCP_ACT_TRK_SC1 ? 1 : 2); |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 6176 | cfgerr++; |
| 6177 | } |
| 6178 | else if (target->table.size == 0) { |
| 6179 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
| 6180 | curproxy->id, trule->act_prm.trk_ctr.table.n ? trule->act_prm.trk_ctr.table.n : curproxy->id); |
| 6181 | cfgerr++; |
| 6182 | } |
Willy Tarreau | 5f53de7 | 2012-12-12 00:25:44 +0100 | [diff] [blame] | 6183 | else if (!stktable_compatible_sample(trule->act_prm.trk_ctr.expr, target->table.type)) { |
| 6184 | Alert("Proxy '%s': stick-table '%s' uses a type incompatible with the 'track-sc%d' rule.\n", |
| 6185 | curproxy->id, trule->act_prm.trk_ctr.table.n ? trule->act_prm.trk_ctr.table.n : curproxy->id, |
| 6186 | trule->action == TCP_ACT_TRK_SC1 ? 1 : 2); |
| 6187 | cfgerr++; |
| 6188 | } |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 6189 | else { |
| 6190 | free(trule->act_prm.trk_ctr.table.n); |
| 6191 | trule->act_prm.trk_ctr.table.t = &target->table; |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6192 | /* 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] | 6193 | * to pass a list of counters to track and allocate them right here using |
| 6194 | * stktable_alloc_data_type(). |
| 6195 | */ |
| 6196 | } |
| 6197 | } |
| 6198 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 6199 | if (curproxy->table.peers.name) { |
| 6200 | struct peers *curpeers = peers; |
| 6201 | |
| 6202 | for (curpeers = peers; curpeers; curpeers = curpeers->next) { |
| 6203 | if (strcmp(curpeers->id, curproxy->table.peers.name) == 0) { |
| 6204 | free((void *)curproxy->table.peers.name); |
Willy Tarreau | 973ca49 | 2013-01-17 21:34:52 +0100 | [diff] [blame] | 6205 | curproxy->table.peers.p = curpeers; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 6206 | break; |
| 6207 | } |
| 6208 | } |
| 6209 | |
| 6210 | if (!curpeers) { |
| 6211 | Alert("Proxy '%s': unable to find sync peers '%s'.\n", |
| 6212 | curproxy->id, curproxy->table.peers.name); |
Willy Tarreau | d66bf96 | 2011-10-28 14:16:49 +0200 | [diff] [blame] | 6213 | free((void *)curproxy->table.peers.name); |
| 6214 | curproxy->table.peers.p = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 6215 | cfgerr++; |
| 6216 | } |
| 6217 | else if (!curpeers->peers_fe) { |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 6218 | Alert("Proxy '%s': unable to find local peer '%s' in peers section '%s'.\n", |
| 6219 | curproxy->id, localpeer, curpeers->id); |
Willy Tarreau | d66bf96 | 2011-10-28 14:16:49 +0200 | [diff] [blame] | 6220 | curproxy->table.peers.p = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 6221 | cfgerr++; |
| 6222 | } |
| 6223 | } |
| 6224 | |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 6225 | if (curproxy->uri_auth && !(curproxy->uri_auth->flags & ST_CONVDONE) && |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 6226 | !LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) && |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6227 | (curproxy->uri_auth->userlist || curproxy->uri_auth->auth_realm )) { |
| 6228 | Alert("%s '%s': stats 'auth'/'realm' and 'http-request' can't be used at the same time.\n", |
| 6229 | "proxy", curproxy->id); |
| 6230 | cfgerr++; |
| 6231 | goto out_uri_auth_compat; |
| 6232 | } |
| 6233 | |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 6234 | 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] | 6235 | const char *uri_auth_compat_req[10]; |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 6236 | struct http_req_rule *rule; |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6237 | int i = 0; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6238 | |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6239 | /* build the ACL condition from scratch. We're relying on anonymous ACLs for that */ |
| 6240 | uri_auth_compat_req[i++] = "auth"; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6241 | |
| 6242 | if (curproxy->uri_auth->auth_realm) { |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6243 | uri_auth_compat_req[i++] = "realm"; |
| 6244 | uri_auth_compat_req[i++] = curproxy->uri_auth->auth_realm; |
| 6245 | } |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6246 | |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6247 | uri_auth_compat_req[i++] = "unless"; |
| 6248 | uri_auth_compat_req[i++] = "{"; |
| 6249 | uri_auth_compat_req[i++] = "http_auth(.internal-stats-userlist)"; |
| 6250 | uri_auth_compat_req[i++] = "}"; |
| 6251 | uri_auth_compat_req[i++] = ""; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6252 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 6253 | rule = parse_http_req_cond(uri_auth_compat_req, "internal-stats-auth-compat", 0, curproxy); |
| 6254 | if (!rule) { |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6255 | cfgerr++; |
| 6256 | break; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6257 | } |
| 6258 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 6259 | LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list); |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6260 | |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6261 | if (curproxy->uri_auth->auth_realm) { |
| 6262 | free(curproxy->uri_auth->auth_realm); |
| 6263 | curproxy->uri_auth->auth_realm = NULL; |
| 6264 | } |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 6265 | |
| 6266 | curproxy->uri_auth->flags |= ST_CONVDONE; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6267 | } |
| 6268 | out_uri_auth_compat: |
| 6269 | |
Krzysztof Piotr Oledzki | f9423ae | 2010-01-29 19:26:18 +0100 | [diff] [blame] | 6270 | cfgerr += acl_find_targets(curproxy); |
| 6271 | |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 6272 | if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) && |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6273 | (((curproxy->cap & PR_CAP_FE) && !curproxy->timeout.client) || |
Willy Tarreau | d825eef | 2007-05-12 22:35:00 +0200 | [diff] [blame] | 6274 | ((curproxy->cap & PR_CAP_BE) && (curproxy->srv) && |
Willy Tarreau | ce887fd | 2012-05-12 12:50:00 +0200 | [diff] [blame] | 6275 | (!curproxy->timeout.connect || |
| 6276 | (!curproxy->timeout.server && (curproxy->mode == PR_MODE_HTTP || !curproxy->timeout.tunnel)))))) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6277 | Warning("config : missing timeouts for %s '%s'.\n" |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 6278 | " | While not properly invalid, you will certainly encounter various problems\n" |
| 6279 | " | 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] | 6280 | " | timeouts are set to a non-zero value: 'client', 'connect', 'server'.\n", |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6281 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6282 | err_code |= ERR_WARN; |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 6283 | } |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 6284 | |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6285 | /* Historically, the tarpit and queue timeouts were inherited from contimeout. |
| 6286 | * We must still support older configurations, so let's find out whether those |
| 6287 | * parameters have been set or must be copied from contimeouts. |
| 6288 | */ |
| 6289 | if (curproxy != &defproxy) { |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6290 | if (!curproxy->timeout.tarpit || |
| 6291 | curproxy->timeout.tarpit == defproxy.timeout.tarpit) { |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6292 | /* tarpit timeout not set. We search in the following order: |
| 6293 | * default.tarpit, curr.connect, default.connect. |
| 6294 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6295 | if (defproxy.timeout.tarpit) |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6296 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6297 | else if (curproxy->timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6298 | curproxy->timeout.tarpit = curproxy->timeout.connect; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6299 | else if (defproxy.timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6300 | curproxy->timeout.tarpit = defproxy.timeout.connect; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6301 | } |
| 6302 | if ((curproxy->cap & PR_CAP_BE) && |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6303 | (!curproxy->timeout.queue || |
| 6304 | curproxy->timeout.queue == defproxy.timeout.queue)) { |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6305 | /* queue timeout not set. We search in the following order: |
| 6306 | * default.queue, curr.connect, default.connect. |
| 6307 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6308 | if (defproxy.timeout.queue) |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6309 | curproxy->timeout.queue = defproxy.timeout.queue; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6310 | else if (curproxy->timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6311 | curproxy->timeout.queue = curproxy->timeout.connect; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6312 | else if (defproxy.timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6313 | curproxy->timeout.queue = defproxy.timeout.connect; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6314 | } |
| 6315 | } |
| 6316 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 6317 | if ((curproxy->options2 & PR_O2_CHK_ANY) == PR_O2_SSL3_CHK) { |
Willy Tarreau | 137325d | 2010-02-01 16:38:17 +0100 | [diff] [blame] | 6318 | curproxy->check_len = sizeof(sslv3_client_hello_pkt) - 1; |
| 6319 | curproxy->check_req = (char *)malloc(curproxy->check_len); |
| 6320 | memcpy(curproxy->check_req, sslv3_client_hello_pkt, curproxy->check_len); |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 6321 | } |
| 6322 | |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 6323 | /* ensure that cookie capture length is not too large */ |
| 6324 | if (curproxy->capture_len >= global.tune.cookie_len) { |
| 6325 | Warning("config : truncating capture length to %d bytes for %s '%s'.\n", |
| 6326 | global.tune.cookie_len - 1, proxy_type_str(curproxy), curproxy->id); |
| 6327 | err_code |= ERR_WARN; |
| 6328 | curproxy->capture_len = global.tune.cookie_len - 1; |
| 6329 | } |
| 6330 | |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 6331 | /* The small pools required for the capture lists */ |
Willy Tarreau | 9a54e13 | 2012-03-24 08:33:05 +0100 | [diff] [blame] | 6332 | if (curproxy->nb_req_cap) { |
| 6333 | if (curproxy->mode == PR_MODE_HTTP) { |
| 6334 | curproxy->req_cap_pool = create_pool("ptrcap", |
| 6335 | curproxy->nb_req_cap * sizeof(char *), |
| 6336 | MEM_F_SHARED); |
| 6337 | } else { |
| 6338 | Warning("config : 'capture request header' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6339 | proxy_type_str(curproxy), curproxy->id); |
| 6340 | err_code |= ERR_WARN; |
| 6341 | curproxy->to_log &= ~LW_REQHDR; |
| 6342 | curproxy->nb_req_cap = 0; |
| 6343 | } |
| 6344 | } |
| 6345 | |
| 6346 | if (curproxy->nb_rsp_cap) { |
| 6347 | if (curproxy->mode == PR_MODE_HTTP) { |
| 6348 | curproxy->rsp_cap_pool = create_pool("ptrcap", |
| 6349 | curproxy->nb_rsp_cap * sizeof(char *), |
| 6350 | MEM_F_SHARED); |
| 6351 | } else { |
| 6352 | Warning("config : 'capture response header' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6353 | proxy_type_str(curproxy), curproxy->id); |
| 6354 | err_code |= ERR_WARN; |
| 6355 | curproxy->to_log &= ~LW_REQHDR; |
| 6356 | curproxy->nb_rsp_cap = 0; |
| 6357 | } |
| 6358 | } |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 6359 | |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 6360 | /* compile the log format */ |
Willy Tarreau | 99a7ca2 | 2012-05-31 19:39:23 +0200 | [diff] [blame] | 6361 | if (!(curproxy->cap & PR_CAP_FE)) { |
| 6362 | if (curproxy->logformat_string != default_http_log_format && |
| 6363 | curproxy->logformat_string != default_tcp_log_format && |
| 6364 | curproxy->logformat_string != clf_http_log_format) |
| 6365 | free(curproxy->logformat_string); |
| 6366 | curproxy->logformat_string = NULL; |
| 6367 | } |
| 6368 | |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 6369 | if (curproxy->logformat_string) |
| 6370 | parse_logformat_string(curproxy->logformat_string, curproxy, &curproxy->logformat, curproxy->mode); |
| 6371 | |
| 6372 | if (curproxy->uniqueid_format_string) |
| 6373 | parse_logformat_string(curproxy->uniqueid_format_string, curproxy, &curproxy->format_unique_id, PR_MODE_HTTP); |
| 6374 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6375 | /* first, we will invert the servers list order */ |
| 6376 | newsrv = NULL; |
| 6377 | while (curproxy->srv) { |
| 6378 | struct server *next; |
| 6379 | |
| 6380 | next = curproxy->srv->next; |
| 6381 | curproxy->srv->next = newsrv; |
| 6382 | newsrv = curproxy->srv; |
| 6383 | if (!next) |
| 6384 | break; |
| 6385 | curproxy->srv = next; |
| 6386 | } |
| 6387 | |
Willy Tarreau | dd70165 | 2010-05-25 23:03:02 +0200 | [diff] [blame] | 6388 | /* assign automatic UIDs to servers which don't have one yet */ |
| 6389 | next_id = 1; |
| 6390 | newsrv = curproxy->srv; |
| 6391 | while (newsrv != NULL) { |
| 6392 | if (!newsrv->puid) { |
| 6393 | /* server ID not set, use automatic numbering with first |
| 6394 | * spare entry starting with next_svid. |
| 6395 | */ |
| 6396 | next_id = get_next_id(&curproxy->conf.used_server_id, next_id); |
| 6397 | newsrv->conf.id.key = newsrv->puid = next_id; |
| 6398 | eb32_insert(&curproxy->conf.used_server_id, &newsrv->conf.id); |
| 6399 | } |
| 6400 | next_id++; |
| 6401 | newsrv = newsrv->next; |
| 6402 | } |
| 6403 | |
Willy Tarreau | 2069704 | 2007-11-15 23:26:18 +0100 | [diff] [blame] | 6404 | curproxy->lbprm.wmult = 1; /* default weight multiplier */ |
Willy Tarreau | 5dc2fa6 | 2007-11-19 19:10:18 +0100 | [diff] [blame] | 6405 | curproxy->lbprm.wdiv = 1; /* default weight divider */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6406 | |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 6407 | /* |
| 6408 | * If this server supports a maxconn parameter, it needs a dedicated |
| 6409 | * tasks to fill the emptied slots when a connection leaves. |
| 6410 | * Also, resolve deferred tracking dependency if needed. |
| 6411 | */ |
| 6412 | newsrv = curproxy->srv; |
| 6413 | while (newsrv != NULL) { |
| 6414 | if (newsrv->minconn > newsrv->maxconn) { |
| 6415 | /* Only 'minconn' was specified, or it was higher than or equal |
| 6416 | * to 'maxconn'. Let's turn this into maxconn and clean it, as |
| 6417 | * this will avoid further useless expensive computations. |
| 6418 | */ |
| 6419 | newsrv->maxconn = newsrv->minconn; |
| 6420 | } else if (newsrv->maxconn && !newsrv->minconn) { |
| 6421 | /* minconn was not specified, so we set it to maxconn */ |
| 6422 | newsrv->minconn = newsrv->maxconn; |
| 6423 | } |
| 6424 | |
Emeric Brun | 01f8e2f | 2012-05-18 16:02:00 +0200 | [diff] [blame] | 6425 | #ifdef USE_OPENSSL |
Emeric Brun | 94324a4 | 2012-10-11 14:00:19 +0200 | [diff] [blame] | 6426 | if (newsrv->use_ssl || newsrv->check.use_ssl) |
| 6427 | cfgerr += ssl_sock_prepare_srv_ctx(newsrv, curproxy); |
Emeric Brun | 01f8e2f | 2012-05-18 16:02:00 +0200 | [diff] [blame] | 6428 | #endif /* USE_OPENSSL */ |
Emeric Brun | 94324a4 | 2012-10-11 14:00:19 +0200 | [diff] [blame] | 6429 | |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 6430 | if (newsrv->trackit) { |
| 6431 | struct proxy *px; |
| 6432 | struct server *srv; |
| 6433 | char *pname, *sname; |
| 6434 | |
| 6435 | pname = newsrv->trackit; |
| 6436 | sname = strrchr(pname, '/'); |
| 6437 | |
| 6438 | if (sname) |
| 6439 | *sname++ = '\0'; |
| 6440 | else { |
| 6441 | sname = pname; |
| 6442 | pname = NULL; |
| 6443 | } |
| 6444 | |
| 6445 | if (pname) { |
| 6446 | px = findproxy(pname, PR_CAP_BE); |
| 6447 | if (!px) { |
| 6448 | Alert("config : %s '%s', server '%s': unable to find required proxy '%s' for tracking.\n", |
| 6449 | proxy_type_str(curproxy), curproxy->id, |
| 6450 | newsrv->id, pname); |
| 6451 | cfgerr++; |
| 6452 | goto next_srv; |
| 6453 | } |
| 6454 | } else |
| 6455 | px = curproxy; |
| 6456 | |
| 6457 | srv = findserver(px, sname); |
| 6458 | if (!srv) { |
| 6459 | Alert("config : %s '%s', server '%s': unable to find required server '%s' for tracking.\n", |
| 6460 | proxy_type_str(curproxy), curproxy->id, |
| 6461 | newsrv->id, sname); |
| 6462 | cfgerr++; |
| 6463 | goto next_srv; |
| 6464 | } |
| 6465 | |
| 6466 | if (!(srv->state & SRV_CHECKED)) { |
| 6467 | Alert("config : %s '%s', server '%s': unable to use %s/%s for " |
| 6468 | "tracking as it does not have checks enabled.\n", |
| 6469 | proxy_type_str(curproxy), curproxy->id, |
| 6470 | newsrv->id, px->id, srv->id); |
| 6471 | cfgerr++; |
| 6472 | goto next_srv; |
| 6473 | } |
| 6474 | |
| 6475 | if (curproxy != px && |
| 6476 | (curproxy->options & PR_O_DISABLE404) != (px->options & PR_O_DISABLE404)) { |
| 6477 | Alert("config : %s '%s', server '%s': unable to use %s/%s for" |
| 6478 | "tracking: disable-on-404 option inconsistency.\n", |
| 6479 | proxy_type_str(curproxy), curproxy->id, |
| 6480 | newsrv->id, px->id, srv->id); |
| 6481 | cfgerr++; |
| 6482 | goto next_srv; |
| 6483 | } |
| 6484 | |
| 6485 | /* if the other server is forced disabled, we have to do the same here */ |
| 6486 | if (srv->state & SRV_MAINTAIN) { |
| 6487 | newsrv->state |= SRV_MAINTAIN; |
| 6488 | newsrv->state &= ~SRV_RUNNING; |
| 6489 | newsrv->health = 0; |
| 6490 | } |
| 6491 | |
| 6492 | newsrv->track = srv; |
| 6493 | newsrv->tracknext = srv->tracknext; |
| 6494 | srv->tracknext = newsrv; |
| 6495 | |
| 6496 | free(newsrv->trackit); |
| 6497 | newsrv->trackit = NULL; |
| 6498 | } |
| 6499 | next_srv: |
| 6500 | newsrv = newsrv->next; |
| 6501 | } |
| 6502 | |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6503 | /* We have to initialize the server lookup mechanism depending |
| 6504 | * on what LB algorithm was choosen. |
| 6505 | */ |
| 6506 | |
| 6507 | curproxy->lbprm.algo &= ~(BE_LB_LKUP | BE_LB_PROP_DYN); |
| 6508 | switch (curproxy->lbprm.algo & BE_LB_KIND) { |
| 6509 | case BE_LB_KIND_RR: |
Willy Tarreau | 9757a38 | 2009-10-03 12:56:50 +0200 | [diff] [blame] | 6510 | if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_RR_STATIC) { |
| 6511 | curproxy->lbprm.algo |= BE_LB_LKUP_MAP; |
| 6512 | init_server_map(curproxy); |
| 6513 | } else { |
| 6514 | curproxy->lbprm.algo |= BE_LB_LKUP_RRTREE | BE_LB_PROP_DYN; |
| 6515 | fwrr_init_server_groups(curproxy); |
| 6516 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6517 | break; |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 6518 | |
Willy Tarreau | 3ebb116 | 2012-02-13 16:57:44 +0100 | [diff] [blame] | 6519 | case BE_LB_KIND_CB: |
Willy Tarreau | f09c660 | 2012-02-13 17:12:08 +0100 | [diff] [blame] | 6520 | if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_CB_LC) { |
| 6521 | curproxy->lbprm.algo |= BE_LB_LKUP_LCTREE | BE_LB_PROP_DYN; |
| 6522 | fwlc_init_server_tree(curproxy); |
| 6523 | } else { |
| 6524 | curproxy->lbprm.algo |= BE_LB_LKUP_FSTREE | BE_LB_PROP_DYN; |
| 6525 | fas_init_server_tree(curproxy); |
| 6526 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6527 | break; |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 6528 | |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6529 | case BE_LB_KIND_HI: |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 6530 | if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS) { |
| 6531 | curproxy->lbprm.algo |= BE_LB_LKUP_CHTREE | BE_LB_PROP_DYN; |
| 6532 | chash_init_server_tree(curproxy); |
| 6533 | } else { |
| 6534 | curproxy->lbprm.algo |= BE_LB_LKUP_MAP; |
| 6535 | init_server_map(curproxy); |
| 6536 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6537 | break; |
| 6538 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6539 | |
| 6540 | if (curproxy->options & PR_O_LOGASAP) |
| 6541 | curproxy->to_log &= ~LW_BYTES; |
| 6542 | |
Willy Tarreau | e7ded1f | 2009-08-09 10:11:45 +0200 | [diff] [blame] | 6543 | if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) && |
Willy Tarreau | d79a3b2 | 2012-12-28 09:40:16 +0100 | [diff] [blame] | 6544 | (curproxy->cap & PR_CAP_FE) && !LIST_ISEMPTY(&curproxy->logformat) && LIST_ISEMPTY(&curproxy->logsrvs)) { |
Willy Tarreau | e7ded1f | 2009-08-09 10:11:45 +0200 | [diff] [blame] | 6545 | Warning("config : log format ignored for %s '%s' since it has no log address.\n", |
| 6546 | proxy_type_str(curproxy), curproxy->id); |
| 6547 | err_code |= ERR_WARN; |
| 6548 | } |
| 6549 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 6550 | if (curproxy->mode != PR_MODE_HTTP) { |
| 6551 | int optnum; |
| 6552 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 6553 | if (curproxy->uri_auth) { |
| 6554 | Warning("config : 'stats' statement ignored for %s '%s' as it requires HTTP mode.\n", |
| 6555 | proxy_type_str(curproxy), curproxy->id); |
| 6556 | err_code |= ERR_WARN; |
| 6557 | curproxy->uri_auth = NULL; |
| 6558 | } |
| 6559 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 6560 | if (curproxy->options & (PR_O_FWDFOR | PR_O_FF_ALWAYS)) { |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 6561 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6562 | "forwardfor", proxy_type_str(curproxy), curproxy->id); |
| 6563 | err_code |= ERR_WARN; |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 6564 | curproxy->options &= ~(PR_O_FWDFOR | PR_O_FF_ALWAYS); |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 6565 | } |
| 6566 | |
| 6567 | if (curproxy->options & PR_O_ORGTO) { |
| 6568 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6569 | "originalto", proxy_type_str(curproxy), curproxy->id); |
| 6570 | err_code |= ERR_WARN; |
| 6571 | curproxy->options &= ~PR_O_ORGTO; |
| 6572 | } |
| 6573 | |
| 6574 | for (optnum = 0; cfg_opts[optnum].name; optnum++) { |
| 6575 | if (cfg_opts[optnum].mode == PR_MODE_HTTP && |
| 6576 | (curproxy->cap & cfg_opts[optnum].cap) && |
| 6577 | (curproxy->options & cfg_opts[optnum].val)) { |
| 6578 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6579 | cfg_opts[optnum].name, proxy_type_str(curproxy), curproxy->id); |
| 6580 | err_code |= ERR_WARN; |
| 6581 | curproxy->options &= ~cfg_opts[optnum].val; |
| 6582 | } |
| 6583 | } |
| 6584 | |
| 6585 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) { |
| 6586 | if (cfg_opts2[optnum].mode == PR_MODE_HTTP && |
| 6587 | (curproxy->cap & cfg_opts2[optnum].cap) && |
| 6588 | (curproxy->options2 & cfg_opts2[optnum].val)) { |
| 6589 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6590 | cfg_opts2[optnum].name, proxy_type_str(curproxy), curproxy->id); |
| 6591 | err_code |= ERR_WARN; |
| 6592 | curproxy->options2 &= ~cfg_opts2[optnum].val; |
| 6593 | } |
| 6594 | } |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6595 | |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 6596 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6597 | if (curproxy->conn_src.bind_hdr_occ) { |
| 6598 | curproxy->conn_src.bind_hdr_occ = 0; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6599 | Warning("config : %s '%s' : ignoring use of header %s as source IP in non-HTTP mode.\n", |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6600 | proxy_type_str(curproxy), curproxy->id, curproxy->conn_src.bind_hdr_name); |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6601 | err_code |= ERR_WARN; |
| 6602 | } |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 6603 | #endif |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 6604 | } |
| 6605 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6606 | /* |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 6607 | * ensure that we're not cross-dressing a TCP server into HTTP. |
| 6608 | */ |
| 6609 | newsrv = curproxy->srv; |
| 6610 | while (newsrv != NULL) { |
Willy Tarreau | 0cec331 | 2011-10-31 13:49:26 +0100 | [diff] [blame] | 6611 | if ((curproxy->mode != PR_MODE_HTTP) && newsrv->rdr_len) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6612 | Alert("config : %s '%s' : server cannot have cookie or redirect prefix in non-HTTP mode.\n", |
| 6613 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6614 | cfgerr++; |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 6615 | } |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6616 | |
Willy Tarreau | 0cec331 | 2011-10-31 13:49:26 +0100 | [diff] [blame] | 6617 | if ((curproxy->mode != PR_MODE_HTTP) && newsrv->cklen) { |
| 6618 | Warning("config : %s '%s' : ignoring cookie for server '%s' as HTTP mode is disabled.\n", |
| 6619 | proxy_type_str(curproxy), curproxy->id, newsrv->id); |
| 6620 | err_code |= ERR_WARN; |
| 6621 | } |
| 6622 | |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 6623 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6624 | if (curproxy->mode != PR_MODE_HTTP && newsrv->conn_src.bind_hdr_occ) { |
| 6625 | newsrv->conn_src.bind_hdr_occ = 0; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6626 | Warning("config : %s '%s' : server %s cannot use header %s as source IP in non-HTTP mode.\n", |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6627 | proxy_type_str(curproxy), curproxy->id, newsrv->id, newsrv->conn_src.bind_hdr_name); |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6628 | err_code |= ERR_WARN; |
| 6629 | } |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 6630 | #endif |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 6631 | newsrv = newsrv->next; |
| 6632 | } |
| 6633 | |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6634 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 6635 | if (!curproxy->accept) |
| 6636 | curproxy->accept = frontend_accept; |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 6637 | |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6638 | if (curproxy->tcp_req.inspect_delay || |
| 6639 | !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules)) |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 6640 | curproxy->fe_req_ana |= AN_REQ_INSPECT_FE; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6641 | |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 6642 | if (curproxy->mode == PR_MODE_HTTP) { |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6643 | 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] | 6644 | 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] | 6645 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6646 | |
| 6647 | /* both TCP and HTTP must check switching rules */ |
| 6648 | curproxy->fe_req_ana |= AN_REQ_SWITCHING_RULES; |
| 6649 | } |
| 6650 | |
| 6651 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 6652 | if (curproxy->tcp_req.inspect_delay || |
| 6653 | !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules)) |
| 6654 | curproxy->be_req_ana |= AN_REQ_INSPECT_BE; |
| 6655 | |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 6656 | if (!LIST_ISEMPTY(&curproxy->tcp_rep.inspect_rules)) |
| 6657 | curproxy->be_rsp_ana |= AN_RES_INSPECT; |
| 6658 | |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 6659 | if (curproxy->mode == PR_MODE_HTTP) { |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6660 | 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] | 6661 | 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] | 6662 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6663 | |
| 6664 | /* If the backend does requires RDP cookie persistence, we have to |
| 6665 | * enable the corresponding analyser. |
| 6666 | */ |
| 6667 | if (curproxy->options2 & PR_O2_RDPC_PRST) |
| 6668 | curproxy->be_req_ana |= AN_REQ_PRST_RDP_COOKIE; |
| 6669 | } |
| 6670 | |
Emeric Brun | c52962f | 2012-11-15 18:28:02 +0100 | [diff] [blame] | 6671 | #ifdef USE_OPENSSL |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 6672 | /* Configure SSL for each bind line. |
| 6673 | * Note: if configuration fails at some point, the ->ctx member |
| 6674 | * remains NULL so that listeners can later detach. |
| 6675 | */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6676 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
Emeric Brun | c52962f | 2012-11-15 18:28:02 +0100 | [diff] [blame] | 6677 | if (!bind_conf->is_ssl) { |
| 6678 | if (bind_conf->default_ctx) { |
| 6679 | Warning("Proxy '%s': A certificate was specified but SSL was not enabled on bind '%s' at [%s:%d] (use 'ssl').\n", |
| 6680 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
| 6681 | } |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6682 | continue; |
Emeric Brun | c52962f | 2012-11-15 18:28:02 +0100 | [diff] [blame] | 6683 | } |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6684 | if (!bind_conf->default_ctx) { |
Emeric Brun | fc0421f | 2012-09-07 17:30:07 +0200 | [diff] [blame] | 6685 | 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] | 6686 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 6687 | cfgerr++; |
| 6688 | continue; |
| 6689 | } |
| 6690 | |
Emeric Brun | 4b3091e | 2012-09-24 15:48:52 +0200 | [diff] [blame] | 6691 | 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] | 6692 | Alert("Unable to allocate SSL session cache.\n"); |
| 6693 | cfgerr++; |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 6694 | continue; |
| 6695 | } |
| 6696 | |
Emeric Brun | fc0421f | 2012-09-07 17:30:07 +0200 | [diff] [blame] | 6697 | /* initialize all certificate contexts */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6698 | cfgerr += ssl_sock_prepare_all_ctx(bind_conf, curproxy); |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6699 | } |
Emeric Brun | c52962f | 2012-11-15 18:28:02 +0100 | [diff] [blame] | 6700 | #endif /* USE_OPENSSL */ |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 6701 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 6702 | /* adjust this proxy's listeners */ |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6703 | next_id = 1; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 6704 | list_for_each_entry(listener, &curproxy->conf.listeners, by_fe) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6705 | if (!listener->luid) { |
| 6706 | /* listener ID not set, use automatic numbering with first |
| 6707 | * spare entry starting with next_luid. |
| 6708 | */ |
| 6709 | next_id = get_next_id(&curproxy->conf.used_listener_id, next_id); |
| 6710 | listener->conf.id.key = listener->luid = next_id; |
| 6711 | eb32_insert(&curproxy->conf.used_listener_id, &listener->conf.id); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6712 | } |
Krzysztof Piotr Oledzki | df5cb9f | 2010-02-05 20:58:27 +0100 | [diff] [blame] | 6713 | next_id++; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6714 | |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 6715 | /* enable separate counters */ |
| 6716 | if (curproxy->options2 & PR_O2_SOCKSTAT) { |
| 6717 | listener->counters = (struct licounters *)calloc(1, sizeof(struct licounters)); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6718 | if (!listener->name) |
| 6719 | memprintf(&listener->name, "sock-%d", listener->luid); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 6720 | } |
Willy Tarreau | 81796be | 2012-09-22 19:11:47 +0200 | [diff] [blame] | 6721 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 6722 | if (curproxy->options & PR_O_TCP_NOLING) |
| 6723 | listener->options |= LI_O_NOLINGER; |
Willy Tarreau | 32368ce | 2012-09-06 11:10:55 +0200 | [diff] [blame] | 6724 | if (!listener->maxconn) |
| 6725 | listener->maxconn = curproxy->maxconn; |
| 6726 | if (!listener->backlog) |
| 6727 | listener->backlog = curproxy->backlog; |
Willy Tarreau | 16a2147 | 2012-11-19 12:39:59 +0100 | [diff] [blame] | 6728 | if (!listener->maxaccept) |
| 6729 | listener->maxaccept = global.tune.maxaccept ? global.tune.maxaccept : 64; |
| 6730 | |
| 6731 | /* we want to have an optimal behaviour on single process mode to |
| 6732 | * maximize the work at once, but in multi-process we want to keep |
| 6733 | * some fairness between processes, so we target half of the max |
| 6734 | * number of events to be balanced over all the processes the proxy |
| 6735 | * is bound to. Rememeber that maxaccept = -1 must be kept as it is |
| 6736 | * used to disable the limit. |
| 6737 | */ |
| 6738 | if (listener->maxaccept > 0) { |
| 6739 | if (nbproc > 1) |
| 6740 | listener->maxaccept = (listener->maxaccept + 1) / 2; |
| 6741 | listener->maxaccept = (listener->maxaccept + nbproc - 1) / nbproc; |
| 6742 | } |
| 6743 | |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6744 | listener->timeout = &curproxy->timeout.client; |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 6745 | listener->accept = session_accept; |
Willy Tarreau | 3bc1377 | 2008-12-07 11:50:35 +0100 | [diff] [blame] | 6746 | listener->handler = process_session; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6747 | listener->analysers |= curproxy->fe_req_ana; |
Willy Tarreau | 3bc1377 | 2008-12-07 11:50:35 +0100 | [diff] [blame] | 6748 | |
Willy Tarreau | a5c0ab2 | 2010-05-31 10:30:33 +0200 | [diff] [blame] | 6749 | if (!LIST_ISEMPTY(&curproxy->tcp_req.l4_rules)) |
| 6750 | listener->options |= LI_O_TCP_RULES; |
| 6751 | |
Willy Tarreau | de3041d | 2010-05-31 10:56:17 +0200 | [diff] [blame] | 6752 | if (curproxy->mon_mask.s_addr) |
| 6753 | listener->options |= LI_O_CHK_MONNET; |
| 6754 | |
Willy Tarreau | 9ea05a7 | 2009-06-14 12:07:01 +0200 | [diff] [blame] | 6755 | /* smart accept mode is automatic in HTTP mode */ |
| 6756 | if ((curproxy->options2 & PR_O2_SMARTACC) || |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6757 | ((curproxy->mode == PR_MODE_HTTP || listener->bind_conf->is_ssl) && |
Willy Tarreau | 9ea05a7 | 2009-06-14 12:07:01 +0200 | [diff] [blame] | 6758 | !(curproxy->no_options2 & PR_O2_SMARTACC))) |
| 6759 | listener->options |= LI_O_NOQUICKACK; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 6760 | } |
| 6761 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6762 | /* Release unused SSL configs */ |
| 6763 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
| 6764 | if (bind_conf->is_ssl) |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 6765 | continue; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6766 | #ifdef USE_OPENSSL |
| 6767 | ssl_sock_free_all_ctx(bind_conf); |
Emeric Brun | fb510ea | 2012-10-05 12:00:26 +0200 | [diff] [blame] | 6768 | free(bind_conf->ca_file); |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6769 | free(bind_conf->ciphers); |
Emeric Brun | 2b58d04 | 2012-09-20 17:10:03 +0200 | [diff] [blame] | 6770 | free(bind_conf->ecdhe); |
Emeric Brun | fb510ea | 2012-10-05 12:00:26 +0200 | [diff] [blame] | 6771 | free(bind_conf->crl_file); |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 6772 | #endif /* USE_OPENSSL */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6773 | } |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 6774 | |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 6775 | /* Check multi-process mode compatibility for the current proxy */ |
| 6776 | if (global.nbproc > 1) { |
| 6777 | int nbproc = 0; |
| 6778 | if (curproxy->bind_proc) { |
| 6779 | int proc; |
| 6780 | for (proc = 0; proc < global.nbproc; proc++) { |
| 6781 | if (curproxy->bind_proc & (1 << proc)) { |
| 6782 | nbproc++; |
| 6783 | } |
| 6784 | } |
| 6785 | } else { |
| 6786 | nbproc = global.nbproc; |
| 6787 | } |
| 6788 | if (curproxy->table.peers.name) { |
| 6789 | Alert("Proxy '%s': peers can't be used in multi-process mode (nbproc > 1).\n", |
| 6790 | curproxy->id); |
| 6791 | cfgerr++; |
| 6792 | } |
| 6793 | if (nbproc > 1) { |
| 6794 | if (curproxy->uri_auth) { |
| 6795 | Warning("Proxy '%s': in multi-process mode, stats will be limited to process assigned to the current request.\n", |
| 6796 | curproxy->id); |
| 6797 | if (!LIST_ISEMPTY(&curproxy->uri_auth->admin_rules)) { |
| 6798 | Warning("Proxy '%s': stats admin will not work correctly in multi-process mode.\n", |
| 6799 | curproxy->id); |
| 6800 | } |
| 6801 | } |
| 6802 | if (curproxy->appsession_name) { |
| 6803 | Warning("Proxy '%s': appsession will not work correctly in multi-process mode.\n", |
| 6804 | curproxy->id); |
| 6805 | } |
| 6806 | if (!LIST_ISEMPTY(&curproxy->sticking_rules)) { |
| 6807 | Warning("Proxy '%s': sticking rules will not work correctly in multi-process mode.\n", |
| 6808 | curproxy->id); |
| 6809 | } |
| 6810 | } |
| 6811 | } |
Willy Tarreau | 918ff60 | 2011-07-25 16:33:49 +0200 | [diff] [blame] | 6812 | |
| 6813 | /* create the task associated with the proxy */ |
| 6814 | curproxy->task = task_new(); |
| 6815 | if (curproxy->task) { |
| 6816 | curproxy->task->context = curproxy; |
| 6817 | curproxy->task->process = manage_proxy; |
| 6818 | /* no need to queue, it will be done automatically if some |
| 6819 | * listener gets limited. |
| 6820 | */ |
| 6821 | curproxy->task->expire = TICK_ETERNITY; |
| 6822 | } else { |
| 6823 | Alert("Proxy '%s': no more memory when trying to allocate the management task\n", |
| 6824 | curproxy->id); |
| 6825 | cfgerr++; |
| 6826 | } |
| 6827 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6828 | curproxy = curproxy->next; |
| 6829 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 6830 | |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 6831 | /* Check multi-process mode compatibility */ |
| 6832 | if (global.nbproc > 1) { |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 6833 | if (global.stats_fe && !global.stats_fe->bind_proc) { |
| 6834 | 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] | 6835 | } |
| 6836 | } |
| 6837 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6838 | for (curuserlist = userlist; curuserlist; curuserlist = curuserlist->next) { |
| 6839 | struct auth_users *curuser; |
| 6840 | int g; |
| 6841 | |
| 6842 | for (curuser = curuserlist->users; curuser; curuser = curuser->next) { |
| 6843 | unsigned int group_mask = 0; |
| 6844 | char *group = NULL; |
| 6845 | |
Willy Tarreau | b4c06b7 | 2010-02-02 11:28:20 +0100 | [diff] [blame] | 6846 | if (!curuser->u.groups) |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6847 | continue; |
| 6848 | |
Willy Tarreau | b4c06b7 | 2010-02-02 11:28:20 +0100 | [diff] [blame] | 6849 | while ((group = strtok(group?NULL:curuser->u.groups, ","))) { |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6850 | |
| 6851 | for (g = 0; g < curuserlist->grpcnt; g++) |
| 6852 | if (!strcmp(curuserlist->groups[g], group)) |
| 6853 | break; |
| 6854 | |
| 6855 | if (g == curuserlist->grpcnt) { |
| 6856 | Alert("userlist '%s': no such group '%s' specified in user '%s'\n", |
| 6857 | curuserlist->name, group, curuser->user); |
| 6858 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6859 | goto out; |
| 6860 | } |
| 6861 | |
| 6862 | group_mask |= (1 << g); |
| 6863 | } |
| 6864 | |
Willy Tarreau | b4c06b7 | 2010-02-02 11:28:20 +0100 | [diff] [blame] | 6865 | free(curuser->u.groups); |
| 6866 | curuser->u.group_mask = group_mask; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6867 | } |
| 6868 | |
| 6869 | for (g = 0; g < curuserlist->grpcnt; g++) { |
| 6870 | char *user = NULL; |
| 6871 | |
| 6872 | if (!curuserlist->groupusers[g]) |
| 6873 | continue; |
| 6874 | |
| 6875 | while ((user = strtok(user?NULL:curuserlist->groupusers[g], ","))) { |
| 6876 | for (curuser = curuserlist->users; curuser; curuser = curuser->next) |
| 6877 | if (!strcmp(curuser->user, user)) |
| 6878 | break; |
| 6879 | |
| 6880 | if (!curuser) { |
| 6881 | Alert("userlist '%s': no such user '%s' specified in group '%s'\n", |
| 6882 | curuserlist->name, user, curuserlist->groups[g]); |
| 6883 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6884 | goto out; |
| 6885 | } |
| 6886 | |
Willy Tarreau | b4c06b7 | 2010-02-02 11:28:20 +0100 | [diff] [blame] | 6887 | curuser->u.group_mask |= (1 << g); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6888 | } |
| 6889 | |
| 6890 | free(curuserlist->groupusers[g]); |
| 6891 | } |
| 6892 | |
| 6893 | free(curuserlist->groupusers); |
| 6894 | |
| 6895 | #ifdef DEBUG_AUTH |
| 6896 | for (g = 0; g < curuserlist->grpcnt; g++) { |
| 6897 | fprintf(stderr, "group %s, id %d, mask %08X, users:", curuserlist->groups[g], g , 1 << g); |
| 6898 | |
| 6899 | for (curuser = curuserlist->users; curuser; curuser = curuser->next) { |
Willy Tarreau | b950959 | 2012-05-10 23:25:35 +0200 | [diff] [blame] | 6900 | if (curuser->u.group_mask & (1 << g)) |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6901 | fprintf(stderr, " %s", curuser->user); |
| 6902 | } |
| 6903 | |
| 6904 | fprintf(stderr, "\n"); |
| 6905 | } |
| 6906 | #endif |
| 6907 | |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 6908 | } |
| 6909 | |
| 6910 | /* automatically compute fullconn if not set. We must not do it in the |
| 6911 | * loop above because cross-references are not yet fully resolved. |
| 6912 | */ |
| 6913 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 6914 | /* If <fullconn> is not set, let's set it to 10% of the sum of |
| 6915 | * the possible incoming frontend's maxconns. |
| 6916 | */ |
| 6917 | if (!curproxy->fullconn && (curproxy->cap & PR_CAP_BE)) { |
| 6918 | struct proxy *fe; |
| 6919 | int total = 0; |
| 6920 | |
| 6921 | /* sum up the number of maxconns of frontends which |
| 6922 | * reference this backend at least once or which are |
| 6923 | * the same one ('listen'). |
| 6924 | */ |
| 6925 | for (fe = proxy; fe; fe = fe->next) { |
| 6926 | struct switching_rule *rule; |
| 6927 | struct hdr_exp *exp; |
| 6928 | int found = 0; |
| 6929 | |
| 6930 | if (!(fe->cap & PR_CAP_FE)) |
| 6931 | continue; |
| 6932 | |
| 6933 | if (fe == curproxy) /* we're on a "listen" instance */ |
| 6934 | found = 1; |
| 6935 | |
| 6936 | if (fe->defbe.be == curproxy) /* "default_backend" */ |
| 6937 | found = 1; |
| 6938 | |
| 6939 | /* check if a "use_backend" rule matches */ |
| 6940 | if (!found) { |
| 6941 | list_for_each_entry(rule, &fe->switching_rules, list) { |
| 6942 | if (rule->be.backend == curproxy) { |
| 6943 | found = 1; |
| 6944 | break; |
| 6945 | } |
| 6946 | } |
| 6947 | } |
| 6948 | |
| 6949 | /* check if a "reqsetbe" rule matches */ |
| 6950 | for (exp = fe->req_exp; !found && exp; exp = exp->next) { |
| 6951 | if (exp->action == ACT_SETBE && |
| 6952 | (struct proxy *)exp->replace == curproxy) { |
| 6953 | found = 1; |
| 6954 | break; |
| 6955 | } |
| 6956 | } |
| 6957 | |
| 6958 | /* now we've checked all possible ways to reference a backend |
| 6959 | * from a frontend. |
| 6960 | */ |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 6961 | if (!found) |
| 6962 | continue; |
| 6963 | total += fe->maxconn; |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 6964 | } |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 6965 | /* we have the sum of the maxconns in <total>. We only |
| 6966 | * keep 10% of that sum to set the default fullconn, with |
| 6967 | * a hard minimum of 1 (to avoid a divide by zero). |
| 6968 | */ |
| 6969 | curproxy->fullconn = (total + 9) / 10; |
| 6970 | if (!curproxy->fullconn) |
| 6971 | curproxy->fullconn = 1; |
| 6972 | } |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6973 | } |
| 6974 | |
Willy Tarreau | 056f568 | 2010-06-06 15:51:11 +0200 | [diff] [blame] | 6975 | /* initialize stick-tables on backend capable proxies. This must not |
| 6976 | * be done earlier because the data size may be discovered while parsing |
| 6977 | * other proxies. |
| 6978 | */ |
| 6979 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) |
Willy Tarreau | c00cdc2 | 2010-06-06 16:48:26 +0200 | [diff] [blame] | 6980 | stktable_init(&curproxy->table); |
Willy Tarreau | 056f568 | 2010-06-06 15:51:11 +0200 | [diff] [blame] | 6981 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 6982 | /* |
| 6983 | * Recount currently required checks. |
| 6984 | */ |
| 6985 | |
| 6986 | for (curproxy=proxy; curproxy; curproxy=curproxy->next) { |
| 6987 | int optnum; |
| 6988 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 6989 | for (optnum = 0; cfg_opts[optnum].name; optnum++) |
| 6990 | if (curproxy->options & cfg_opts[optnum].val) |
| 6991 | global.last_checks |= cfg_opts[optnum].checks; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 6992 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 6993 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) |
| 6994 | if (curproxy->options2 & cfg_opts2[optnum].val) |
| 6995 | global.last_checks |= cfg_opts2[optnum].checks; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 6996 | } |
| 6997 | |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 6998 | if (peers) { |
| 6999 | struct peers *curpeers = peers, **last; |
| 7000 | struct peer *p, *pb; |
| 7001 | |
| 7002 | /* Remove all peers sections which don't have a valid listener. |
| 7003 | * This can happen when a peers section is never referenced and |
| 7004 | * does not contain a local peer. |
| 7005 | */ |
| 7006 | last = &peers; |
| 7007 | while (*last) { |
| 7008 | curpeers = *last; |
| 7009 | if (curpeers->peers_fe) { |
Willy Tarreau | ca57de3 | 2012-11-23 20:08:09 +0100 | [diff] [blame] | 7010 | 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] | 7011 | last = &curpeers->next; |
| 7012 | continue; |
| 7013 | } |
| 7014 | |
| 7015 | Warning("Removing incomplete section 'peers %s' (no peer named '%s').\n", |
| 7016 | curpeers->id, localpeer); |
| 7017 | |
| 7018 | p = curpeers->remote; |
| 7019 | while (p) { |
| 7020 | pb = p->next; |
| 7021 | free(p->id); |
| 7022 | free(p); |
| 7023 | p = pb; |
| 7024 | } |
| 7025 | |
| 7026 | /* Destroy and unlink this curpeers section. |
| 7027 | * Note: curpeers is backed up into *last. |
| 7028 | */ |
| 7029 | free(curpeers->id); |
| 7030 | curpeers = curpeers->next; |
| 7031 | free(*last); |
| 7032 | *last = curpeers; |
| 7033 | } |
| 7034 | } |
| 7035 | |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 7036 | pool2_hdr_idx = create_pool("hdr_idx", |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame] | 7037 | global.tune.max_http_hdr * sizeof(struct hdr_idx_elem), |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 7038 | MEM_F_SHARED); |
| 7039 | |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 7040 | if (cfgerr > 0) |
| 7041 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7042 | out: |
| 7043 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7044 | } |
| 7045 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 7046 | /* |
| 7047 | * Registers the CFG keyword list <kwl> as a list of valid keywords for next |
| 7048 | * parsing sessions. |
| 7049 | */ |
| 7050 | void cfg_register_keywords(struct cfg_kw_list *kwl) |
| 7051 | { |
| 7052 | LIST_ADDQ(&cfg_keywords.list, &kwl->list); |
| 7053 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7054 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 7055 | /* |
| 7056 | * Unregisters the CFG keyword list <kwl> from the list of valid keywords. |
| 7057 | */ |
| 7058 | void cfg_unregister_keywords(struct cfg_kw_list *kwl) |
| 7059 | { |
| 7060 | LIST_DEL(&kwl->list); |
| 7061 | LIST_INIT(&kwl->list); |
| 7062 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7063 | |
| 7064 | /* |
| 7065 | * Local variables: |
| 7066 | * c-indent-level: 8 |
| 7067 | * c-basic-offset: 8 |
| 7068 | * End: |
| 7069 | */ |