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 | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame] | 676 | else if (!strcmp(args[0], "tune.http.maxhdr")) { |
| 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.max_http_hdr = atol(args[1]); |
| 683 | } |
William Lallemand | a509e4c | 2012-11-07 16:54:34 +0100 | [diff] [blame] | 684 | else if (!strcmp(args[0], "tune.zlib.memlevel")) { |
| 685 | #ifdef USE_ZLIB |
| 686 | if (*args[1]) { |
| 687 | global.tune.zlibmemlevel = atoi(args[1]); |
| 688 | if (global.tune.zlibmemlevel < 1 || global.tune.zlibmemlevel > 9) { |
| 689 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n", |
| 690 | file, linenum, args[0]); |
| 691 | err_code |= ERR_ALERT | ERR_FATAL; |
| 692 | goto out; |
| 693 | } |
| 694 | } else { |
| 695 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n", |
| 696 | file, linenum, args[0]); |
| 697 | err_code |= ERR_ALERT | ERR_FATAL; |
| 698 | goto out; |
| 699 | } |
| 700 | #else |
| 701 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 702 | err_code |= ERR_ALERT | ERR_FATAL; |
| 703 | goto out; |
| 704 | #endif |
| 705 | } |
| 706 | else if (!strcmp(args[0], "tune.zlib.windowsize")) { |
| 707 | #ifdef USE_ZLIB |
| 708 | if (*args[1]) { |
| 709 | global.tune.zlibwindowsize = atoi(args[1]); |
| 710 | if (global.tune.zlibwindowsize < 8 || global.tune.zlibwindowsize > 15) { |
| 711 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 8 and 15\n", |
| 712 | file, linenum, args[0]); |
| 713 | err_code |= ERR_ALERT | ERR_FATAL; |
| 714 | goto out; |
| 715 | } |
| 716 | } else { |
| 717 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 8 and 15\n", |
| 718 | file, linenum, args[0]); |
| 719 | err_code |= ERR_ALERT | ERR_FATAL; |
| 720 | goto out; |
| 721 | } |
| 722 | #else |
| 723 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 724 | err_code |= ERR_ALERT | ERR_FATAL; |
| 725 | goto out; |
| 726 | #endif |
| 727 | } |
William Lallemand | f374783 | 2012-11-09 12:33:10 +0100 | [diff] [blame] | 728 | else if (!strcmp(args[0], "tune.comp.maxlevel")) { |
| 729 | if (*args[1]) { |
| 730 | global.tune.comp_maxlevel = atoi(args[1]); |
| 731 | if (global.tune.comp_maxlevel < 1 || global.tune.comp_maxlevel > 9) { |
| 732 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n", |
| 733 | file, linenum, args[0]); |
| 734 | err_code |= ERR_ALERT | ERR_FATAL; |
| 735 | goto out; |
| 736 | } |
| 737 | } else { |
| 738 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n", |
| 739 | file, linenum, args[0]); |
| 740 | err_code |= ERR_ALERT | ERR_FATAL; |
| 741 | goto out; |
| 742 | } |
| 743 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 744 | else if (!strcmp(args[0], "uid")) { |
| 745 | if (global.uid != 0) { |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 746 | Alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 747 | err_code |= ERR_ALERT; |
| 748 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 749 | } |
| 750 | if (*(args[1]) == 0) { |
| 751 | 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] | 752 | err_code |= ERR_ALERT | ERR_FATAL; |
| 753 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 754 | } |
| 755 | global.uid = atol(args[1]); |
| 756 | } |
| 757 | else if (!strcmp(args[0], "gid")) { |
| 758 | if (global.gid != 0) { |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 759 | Alert("parsing [%s:%d] : group/gid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 760 | err_code |= ERR_ALERT; |
| 761 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 762 | } |
| 763 | if (*(args[1]) == 0) { |
| 764 | 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] | 765 | err_code |= ERR_ALERT | ERR_FATAL; |
| 766 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 767 | } |
| 768 | global.gid = atol(args[1]); |
| 769 | } |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 770 | /* user/group name handling */ |
| 771 | else if (!strcmp(args[0], "user")) { |
| 772 | struct passwd *ha_user; |
| 773 | if (global.uid != 0) { |
| 774 | Alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 775 | err_code |= ERR_ALERT; |
| 776 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 777 | } |
| 778 | errno = 0; |
| 779 | ha_user = getpwnam(args[1]); |
| 780 | if (ha_user != NULL) { |
| 781 | global.uid = (int)ha_user->pw_uid; |
| 782 | } |
| 783 | else { |
| 784 | 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] | 785 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 786 | } |
| 787 | } |
| 788 | else if (!strcmp(args[0], "group")) { |
| 789 | struct group *ha_group; |
| 790 | if (global.gid != 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 791 | 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] | 792 | err_code |= ERR_ALERT; |
| 793 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 794 | } |
| 795 | errno = 0; |
| 796 | ha_group = getgrnam(args[1]); |
| 797 | if (ha_group != NULL) { |
| 798 | global.gid = (int)ha_group->gr_gid; |
| 799 | } |
| 800 | else { |
| 801 | 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] | 802 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 803 | } |
| 804 | } |
| 805 | /* end of user/group name handling*/ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 806 | else if (!strcmp(args[0], "nbproc")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 807 | if (*(args[1]) == 0) { |
| 808 | 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] | 809 | err_code |= ERR_ALERT | ERR_FATAL; |
| 810 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 811 | } |
| 812 | global.nbproc = atol(args[1]); |
| 813 | } |
| 814 | else if (!strcmp(args[0], "maxconn")) { |
| 815 | if (global.maxconn != 0) { |
| 816 | 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] | 817 | err_code |= ERR_ALERT; |
| 818 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 819 | } |
| 820 | if (*(args[1]) == 0) { |
| 821 | 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] | 822 | err_code |= ERR_ALERT | ERR_FATAL; |
| 823 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 824 | } |
| 825 | global.maxconn = atol(args[1]); |
| 826 | #ifdef SYSTEM_MAXCONN |
| 827 | if (global.maxconn > DEFAULT_MAXCONN && cfg_maxconn <= DEFAULT_MAXCONN) { |
| 828 | 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); |
| 829 | global.maxconn = DEFAULT_MAXCONN; |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 830 | err_code |= ERR_ALERT; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 831 | } |
| 832 | #endif /* SYSTEM_MAXCONN */ |
| 833 | } |
Willy Tarreau | 403edff | 2012-09-06 11:58:37 +0200 | [diff] [blame] | 834 | else if (!strcmp(args[0], "maxsslconn")) { |
| 835 | #ifdef USE_OPENSSL |
| 836 | if (*(args[1]) == 0) { |
| 837 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 838 | err_code |= ERR_ALERT | ERR_FATAL; |
| 839 | goto out; |
| 840 | } |
| 841 | global.maxsslconn = atol(args[1]); |
| 842 | #else |
Emeric Brun | 0914df8 | 2012-10-02 18:45:42 +0200 | [diff] [blame] | 843 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 844 | err_code |= ERR_ALERT | ERR_FATAL; |
| 845 | goto out; |
Willy Tarreau | 403edff | 2012-09-06 11:58:37 +0200 | [diff] [blame] | 846 | #endif |
| 847 | } |
Willy Tarreau | 81c25d0 | 2011-09-07 15:17:21 +0200 | [diff] [blame] | 848 | else if (!strcmp(args[0], "maxconnrate")) { |
| 849 | if (global.cps_lim != 0) { |
| 850 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 851 | err_code |= ERR_ALERT; |
| 852 | goto out; |
| 853 | } |
| 854 | if (*(args[1]) == 0) { |
| 855 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 856 | err_code |= ERR_ALERT | ERR_FATAL; |
| 857 | goto out; |
| 858 | } |
| 859 | global.cps_lim = atol(args[1]); |
| 860 | } |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 861 | else if (!strcmp(args[0], "maxcomprate")) { |
| 862 | if (*(args[1]) == 0) { |
| 863 | Alert("parsing [%s:%d] : '%s' expects an integer argument in kb/s.\n", file, linenum, args[0]); |
| 864 | err_code |= ERR_ALERT | ERR_FATAL; |
| 865 | goto out; |
| 866 | } |
| 867 | global.comp_rate_lim = atoi(args[1]) * 1024; |
| 868 | } |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 869 | else if (!strcmp(args[0], "maxpipes")) { |
| 870 | if (global.maxpipes != 0) { |
| 871 | 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] | 872 | err_code |= ERR_ALERT; |
| 873 | goto out; |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 874 | } |
| 875 | if (*(args[1]) == 0) { |
| 876 | 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] | 877 | err_code |= ERR_ALERT | ERR_FATAL; |
| 878 | goto out; |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 879 | } |
| 880 | global.maxpipes = atol(args[1]); |
| 881 | } |
William Lallemand | 9d5f548 | 2012-11-07 16:12:57 +0100 | [diff] [blame] | 882 | else if (!strcmp(args[0], "maxzlibmem")) { |
| 883 | if (*(args[1]) == 0) { |
| 884 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 885 | err_code |= ERR_ALERT | ERR_FATAL; |
| 886 | goto out; |
| 887 | } |
| 888 | global.maxzlibmem = atol(args[1]); |
| 889 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 890 | else if (!strcmp(args[0], "ulimit-n")) { |
| 891 | if (global.rlimit_nofile != 0) { |
| 892 | 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] | 893 | err_code |= ERR_ALERT; |
| 894 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 895 | } |
| 896 | if (*(args[1]) == 0) { |
| 897 | 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] | 898 | err_code |= ERR_ALERT | ERR_FATAL; |
| 899 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 900 | } |
| 901 | global.rlimit_nofile = atol(args[1]); |
| 902 | } |
| 903 | else if (!strcmp(args[0], "chroot")) { |
| 904 | if (global.chroot != NULL) { |
| 905 | 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] | 906 | err_code |= ERR_ALERT; |
| 907 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 908 | } |
| 909 | if (*(args[1]) == 0) { |
| 910 | 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] | 911 | err_code |= ERR_ALERT | ERR_FATAL; |
| 912 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 913 | } |
| 914 | global.chroot = strdup(args[1]); |
| 915 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 916 | else if (!strcmp(args[0], "description")) { |
| 917 | int i, len=0; |
| 918 | char *d; |
| 919 | |
| 920 | if (!*args[1]) { |
| 921 | Alert("parsing [%s:%d]: '%s' expects a string argument.\n", |
| 922 | file, linenum, args[0]); |
| 923 | err_code |= ERR_ALERT | ERR_FATAL; |
| 924 | goto out; |
| 925 | } |
| 926 | |
| 927 | for(i=1; *args[i]; i++) |
| 928 | len += strlen(args[i])+1; |
| 929 | |
| 930 | if (global.desc) |
| 931 | free(global.desc); |
| 932 | |
| 933 | global.desc = d = (char *)calloc(1, len); |
| 934 | |
| 935 | d += sprintf(d, "%s", args[1]); |
| 936 | for(i=2; *args[i]; i++) |
| 937 | d += sprintf(d, " %s", args[i]); |
| 938 | } |
| 939 | else if (!strcmp(args[0], "node")) { |
| 940 | int i; |
| 941 | char c; |
| 942 | |
| 943 | for (i=0; args[1][i]; i++) { |
| 944 | c = args[1][i]; |
Willy Tarreau | 88e0581 | 2010-03-03 00:16:00 +0100 | [diff] [blame] | 945 | if (!isupper((unsigned char)c) && !islower((unsigned char)c) && |
| 946 | !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.') |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 947 | break; |
| 948 | } |
| 949 | |
| 950 | if (!i || args[1][i]) { |
| 951 | Alert("parsing [%s:%d]: '%s' requires valid node name - non-empty string" |
| 952 | " with digits(0-9), letters(A-Z, a-z), dot(.), hyphen(-) or underscode(_).\n", |
| 953 | file, linenum, args[0]); |
| 954 | err_code |= ERR_ALERT | ERR_FATAL; |
| 955 | goto out; |
| 956 | } |
| 957 | |
| 958 | if (global.node) |
| 959 | free(global.node); |
| 960 | |
| 961 | global.node = strdup(args[1]); |
| 962 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 963 | else if (!strcmp(args[0], "pidfile")) { |
| 964 | if (global.pidfile != NULL) { |
| 965 | 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] | 966 | err_code |= ERR_ALERT; |
| 967 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 968 | } |
| 969 | if (*(args[1]) == 0) { |
| 970 | 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] | 971 | err_code |= ERR_ALERT | ERR_FATAL; |
| 972 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 973 | } |
| 974 | global.pidfile = strdup(args[1]); |
| 975 | } |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 976 | else if (!strcmp(args[0], "unix-bind")) { |
| 977 | int cur_arg = 1; |
| 978 | while (*(args[cur_arg])) { |
| 979 | if (!strcmp(args[cur_arg], "prefix")) { |
| 980 | if (global.unix_bind.prefix != NULL) { |
| 981 | Alert("parsing [%s:%d] : unix-bind '%s' already specified. Continuing.\n", file, linenum, args[cur_arg]); |
| 982 | err_code |= ERR_ALERT; |
| 983 | cur_arg += 2; |
| 984 | continue; |
| 985 | } |
| 986 | |
| 987 | if (*(args[cur_arg+1]) == 0) { |
| 988 | Alert("parsing [%s:%d] : unix_bind '%s' expects a path as an argument.\n", file, linenum, args[cur_arg]); |
| 989 | err_code |= ERR_ALERT | ERR_FATAL; |
| 990 | goto out; |
| 991 | } |
| 992 | global.unix_bind.prefix = strdup(args[cur_arg+1]); |
| 993 | cur_arg += 2; |
| 994 | continue; |
| 995 | } |
| 996 | |
| 997 | if (!strcmp(args[cur_arg], "mode")) { |
| 998 | |
| 999 | global.unix_bind.ux.mode = strtol(args[cur_arg + 1], NULL, 8); |
| 1000 | cur_arg += 2; |
| 1001 | continue; |
| 1002 | } |
| 1003 | |
| 1004 | if (!strcmp(args[cur_arg], "uid")) { |
| 1005 | |
| 1006 | global.unix_bind.ux.uid = atol(args[cur_arg + 1 ]); |
| 1007 | cur_arg += 2; |
| 1008 | continue; |
| 1009 | } |
| 1010 | |
| 1011 | if (!strcmp(args[cur_arg], "gid")) { |
| 1012 | |
| 1013 | global.unix_bind.ux.gid = atol(args[cur_arg + 1 ]); |
| 1014 | cur_arg += 2; |
| 1015 | continue; |
| 1016 | } |
| 1017 | |
| 1018 | if (!strcmp(args[cur_arg], "user")) { |
| 1019 | struct passwd *user; |
| 1020 | |
| 1021 | user = getpwnam(args[cur_arg + 1]); |
| 1022 | if (!user) { |
| 1023 | Alert("parsing [%s:%d] : '%s' : '%s' unknown user.\n", |
| 1024 | file, linenum, args[0], args[cur_arg + 1 ]); |
| 1025 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1026 | goto out; |
| 1027 | } |
| 1028 | |
| 1029 | global.unix_bind.ux.uid = user->pw_uid; |
| 1030 | cur_arg += 2; |
| 1031 | continue; |
| 1032 | } |
| 1033 | |
| 1034 | if (!strcmp(args[cur_arg], "group")) { |
| 1035 | struct group *group; |
| 1036 | |
| 1037 | group = getgrnam(args[cur_arg + 1]); |
| 1038 | if (!group) { |
| 1039 | Alert("parsing [%s:%d] : '%s' : '%s' unknown group.\n", |
| 1040 | file, linenum, args[0], args[cur_arg + 1 ]); |
| 1041 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1042 | goto out; |
| 1043 | } |
| 1044 | |
| 1045 | global.unix_bind.ux.gid = group->gr_gid; |
| 1046 | cur_arg += 2; |
| 1047 | continue; |
| 1048 | } |
| 1049 | |
Willy Tarreau | b48f958 | 2011-09-05 01:17:06 +0200 | [diff] [blame] | 1050 | 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] | 1051 | file, linenum, args[0]); |
| 1052 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1053 | goto out; |
| 1054 | } |
| 1055 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1056 | else if (!strcmp(args[0], "log") && kwm == KWM_NO) { /* no log */ |
| 1057 | /* delete previous herited or defined syslog servers */ |
| 1058 | struct logsrv *back; |
| 1059 | struct logsrv *tmp; |
| 1060 | |
| 1061 | if (*(args[1]) != 0) { |
| 1062 | Alert("parsing [%s:%d]:%s : 'no log' does not expect arguments.\n", file, linenum, args[1]); |
| 1063 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1064 | goto out; |
| 1065 | } |
| 1066 | |
| 1067 | list_for_each_entry_safe(tmp, back, &global.logsrvs, list) { |
| 1068 | LIST_DEL(&tmp->list); |
| 1069 | free(tmp); |
| 1070 | } |
| 1071 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1072 | else if (!strcmp(args[0], "log")) { /* syslog server address */ |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1073 | struct logsrv *logsrv; |
| 1074 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1075 | if (*(args[1]) == 0 || *(args[2]) == 0) { |
| 1076 | 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] | 1077 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1078 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1079 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1080 | |
| 1081 | logsrv = calloc(1, sizeof(struct logsrv)); |
| 1082 | |
| 1083 | logsrv->facility = get_log_facility(args[2]); |
| 1084 | if (logsrv->facility < 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1085 | 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] | 1086 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1087 | logsrv->facility = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1088 | } |
| 1089 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1090 | logsrv->level = 7; /* max syslog level = debug */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1091 | if (*(args[3])) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1092 | logsrv->level = get_log_level(args[3]); |
| 1093 | if (logsrv->level < 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1094 | 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] | 1095 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1096 | logsrv->level = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1097 | } |
| 1098 | } |
| 1099 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1100 | logsrv->minlvl = 0; /* limit syslog level to this level (emerg) */ |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 1101 | if (*(args[4])) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1102 | logsrv->minlvl = get_log_level(args[4]); |
| 1103 | if (logsrv->minlvl < 0) { |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 1104 | 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] | 1105 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1106 | logsrv->minlvl = 0; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 1107 | } |
| 1108 | } |
| 1109 | |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 1110 | if (args[1][0] == '/') { |
David du Colombier | 11bcb6c | 2011-03-24 12:23:00 +0100 | [diff] [blame] | 1111 | struct sockaddr_storage *sk = (struct sockaddr_storage *)str2sun(args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 1112 | if (!sk) { |
| 1113 | 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] | 1114 | args[1], (int)sizeof(((struct sockaddr_un *)&sk)->sun_path) - 1); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 1115 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1116 | free(logsrv); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 1117 | goto out; |
| 1118 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1119 | logsrv->addr = *sk; |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 1120 | } else { |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 1121 | struct sockaddr_storage *sk = str2sa(args[1]); |
David du Colombier | 11bcb6c | 2011-03-24 12:23:00 +0100 | [diff] [blame] | 1122 | if (!sk) { |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 1123 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[1]); |
| 1124 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1125 | free(logsrv); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 1126 | goto out; |
| 1127 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1128 | logsrv->addr = *sk; |
| 1129 | if (!get_host_port(&logsrv->addr)) |
| 1130 | set_host_port(&logsrv->addr, SYSLOG_PORT); |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 1131 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1132 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1133 | LIST_ADDQ(&global.logsrvs, &logsrv->list); |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1134 | } |
Joe Williams | df5b38f | 2010-12-29 17:05:48 +0100 | [diff] [blame] | 1135 | else if (!strcmp(args[0], "log-send-hostname")) { /* set the hostname in syslog header */ |
| 1136 | char *name; |
| 1137 | int len; |
| 1138 | |
| 1139 | if (global.log_send_hostname != NULL) { |
| 1140 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 1141 | err_code |= ERR_ALERT; |
| 1142 | goto out; |
| 1143 | } |
| 1144 | |
| 1145 | if (*(args[1])) |
| 1146 | name = args[1]; |
| 1147 | else |
| 1148 | name = hostname; |
| 1149 | |
| 1150 | len = strlen(name); |
| 1151 | |
| 1152 | /* We'll add a space after the name to respect the log format */ |
| 1153 | free(global.log_send_hostname); |
| 1154 | global.log_send_hostname = malloc(len + 2); |
| 1155 | snprintf(global.log_send_hostname, len + 2, "%s ", name); |
| 1156 | } |
Kevinm | 48936af | 2010-12-22 16:08:21 +0000 | [diff] [blame] | 1157 | else if (!strcmp(args[0], "log-tag")) { /* tag to report to syslog */ |
| 1158 | if (*(args[1]) == 0) { |
| 1159 | Alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]); |
| 1160 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1161 | goto out; |
| 1162 | } |
| 1163 | free(global.log_tag); |
| 1164 | global.log_tag = strdup(args[1]); |
| 1165 | } |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1166 | else if (!strcmp(args[0], "spread-checks")) { /* random time between checks (0-50) */ |
| 1167 | if (global.spread_checks != 0) { |
| 1168 | Alert("parsing [%s:%d]: spread-checks already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1169 | err_code |= ERR_ALERT; |
| 1170 | goto out; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1171 | } |
| 1172 | if (*(args[1]) == 0) { |
| 1173 | 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] | 1174 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1175 | goto out; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1176 | } |
| 1177 | global.spread_checks = atol(args[1]); |
| 1178 | if (global.spread_checks < 0 || global.spread_checks > 50) { |
| 1179 | 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] | 1180 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1181 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1182 | } |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1183 | else if (strcmp(args[0], "cpu-map") == 0) { /* map a process list to a CPU set */ |
| 1184 | #ifdef USE_CPU_AFFINITY |
| 1185 | int cur_arg, i; |
| 1186 | unsigned int proc = 0; |
| 1187 | unsigned long cpus = 0; |
| 1188 | |
| 1189 | if (strcmp(args[1], "all") == 0) |
| 1190 | proc = 0xFFFFFFFF; |
| 1191 | else if (strcmp(args[1], "odd") == 0) |
| 1192 | proc = 0x55555555; |
| 1193 | else if (strcmp(args[1], "even") == 0) |
| 1194 | proc = 0xAAAAAAAA; |
| 1195 | else { |
| 1196 | proc = atoi(args[1]); |
| 1197 | if (proc >= 1 && proc <= 32) |
| 1198 | proc = 1 << (proc - 1); |
| 1199 | } |
| 1200 | |
| 1201 | if (!proc || !*args[2]) { |
| 1202 | 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", |
| 1203 | file, linenum, args[0]); |
| 1204 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1205 | goto out; |
| 1206 | } |
| 1207 | |
| 1208 | cur_arg = 2; |
| 1209 | while (*args[cur_arg]) { |
| 1210 | unsigned int low, high; |
| 1211 | |
| 1212 | if (isdigit(*args[cur_arg])) { |
| 1213 | char *dash = strchr(args[cur_arg], '-'); |
| 1214 | |
| 1215 | low = high = str2uic(args[cur_arg]); |
| 1216 | if (dash) |
| 1217 | high = str2uic(dash + 1); |
| 1218 | |
| 1219 | if (high < low) { |
| 1220 | unsigned int swap = low; |
| 1221 | low = high; |
| 1222 | high = swap; |
| 1223 | } |
| 1224 | |
| 1225 | if (low < 0 || high >= sizeof(long) * 8) { |
| 1226 | Alert("parsing [%s:%d]: %s supports CPU numbers from 0 to %d.\n", |
| 1227 | file, linenum, args[0], (int)(sizeof(long) * 8 - 1)); |
| 1228 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1229 | goto out; |
| 1230 | } |
| 1231 | |
| 1232 | while (low <= high) |
| 1233 | cpus |= 1UL << low++; |
| 1234 | } |
| 1235 | else { |
| 1236 | Alert("parsing [%s:%d]: %s : '%s' is not a CPU range.\n", |
| 1237 | file, linenum, args[0], args[cur_arg]); |
| 1238 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1239 | goto out; |
| 1240 | } |
| 1241 | cur_arg++; |
| 1242 | } |
| 1243 | for (i = 0; i < 32; i++) |
| 1244 | if (proc & (1 << i)) |
| 1245 | global.cpu_map[i] = cpus; |
| 1246 | #else |
| 1247 | Alert("parsing [%s:%d] : '%s' is not enabled, please check build options for USE_CPU_AFFINITY.\n", file, linenum, args[0]); |
| 1248 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1249 | goto out; |
| 1250 | #endif |
| 1251 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1252 | else { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1253 | struct cfg_kw_list *kwl; |
| 1254 | int index; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1255 | int rc; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1256 | |
| 1257 | list_for_each_entry(kwl, &cfg_keywords.list, list) { |
| 1258 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 1259 | if (kwl->kw[index].section != CFG_GLOBAL) |
| 1260 | continue; |
| 1261 | if (strcmp(kwl->kw[index].kw, args[0]) == 0) { |
Willy Tarreau | 28a47d6 | 2012-09-18 20:02:48 +0200 | [diff] [blame] | 1262 | 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] | 1263 | if (rc < 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 1264 | Alert("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1265 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1266 | } |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1267 | else if (rc > 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 1268 | Warning("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1269 | err_code |= ERR_WARN; |
| 1270 | goto out; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1271 | } |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1272 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1273 | } |
| 1274 | } |
| 1275 | } |
| 1276 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1277 | 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] | 1278 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1279 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1280 | |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1281 | out: |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 1282 | free(errmsg); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1283 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1284 | } |
| 1285 | |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 1286 | void init_default_instance() |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1287 | { |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 1288 | init_new_proxy(&defproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1289 | defproxy.mode = PR_MODE_TCP; |
| 1290 | defproxy.state = PR_STNEW; |
| 1291 | defproxy.maxconn = cfg_maxpconn; |
| 1292 | defproxy.conn_retries = CONN_RETRIES; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1293 | |
| 1294 | defproxy.defsrv.inter = DEF_CHKINTR; |
| 1295 | defproxy.defsrv.fastinter = 0; |
| 1296 | defproxy.defsrv.downinter = 0; |
| 1297 | defproxy.defsrv.rise = DEF_RISETIME; |
| 1298 | defproxy.defsrv.fall = DEF_FALLTIME; |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 1299 | defproxy.defsrv.check.port = 0; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1300 | defproxy.defsrv.maxqueue = 0; |
| 1301 | defproxy.defsrv.minconn = 0; |
| 1302 | defproxy.defsrv.maxconn = 0; |
| 1303 | defproxy.defsrv.slowstart = 0; |
| 1304 | defproxy.defsrv.onerror = DEF_HANA_ONERR; |
| 1305 | defproxy.defsrv.consecutive_errors_limit = DEF_HANA_ERRLIMIT; |
| 1306 | defproxy.defsrv.uweight = defproxy.defsrv.iweight = 1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1307 | } |
| 1308 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1309 | |
| 1310 | static int create_cond_regex_rule(const char *file, int line, |
| 1311 | struct proxy *px, int dir, int action, int flags, |
| 1312 | const char *cmd, const char *reg, const char *repl, |
| 1313 | const char **cond_start) |
| 1314 | { |
| 1315 | regex_t *preg = NULL; |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 1316 | char *errmsg = NULL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1317 | const char *err; |
| 1318 | int err_code = 0; |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1319 | struct acl_cond *cond = NULL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1320 | |
| 1321 | if (px == &defproxy) { |
| 1322 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, line, cmd); |
| 1323 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1324 | goto err; |
| 1325 | } |
| 1326 | |
| 1327 | if (*reg == 0) { |
| 1328 | Alert("parsing [%s:%d] : '%s' expects <regex> as an argument.\n", file, line, cmd); |
| 1329 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1330 | goto err; |
| 1331 | } |
| 1332 | |
| 1333 | if (warnifnotcap(px, PR_CAP_RS, file, line, cmd, NULL)) |
| 1334 | err_code |= ERR_WARN; |
| 1335 | |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1336 | if (cond_start && |
| 1337 | (strcmp(*cond_start, "if") == 0 || strcmp(*cond_start, "unless") == 0)) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 1338 | if ((cond = build_acl_cond(file, line, px, cond_start, &errmsg)) == NULL) { |
| 1339 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 1340 | file, line, cmd, errmsg); |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1341 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1342 | goto err; |
| 1343 | } |
| 1344 | } |
| 1345 | else if (cond_start && **cond_start) { |
| 1346 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 1347 | file, line, cmd, *cond_start); |
| 1348 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1349 | goto err; |
| 1350 | } |
| 1351 | |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 1352 | if (dir == SMP_OPT_DIR_REQ) |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1353 | err_code |= warnif_cond_requires_resp(cond, file, line); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 1354 | else |
| 1355 | err_code |= warnif_cond_requires_req(cond, file, line); |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1356 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1357 | preg = calloc(1, sizeof(regex_t)); |
| 1358 | if (!preg) { |
| 1359 | Alert("parsing [%s:%d] : '%s' : not enough memory to build regex.\n", file, line, cmd); |
| 1360 | err_code = ERR_ALERT | ERR_FATAL; |
| 1361 | goto err; |
| 1362 | } |
| 1363 | |
| 1364 | if (regcomp(preg, reg, REG_EXTENDED | flags) != 0) { |
| 1365 | Alert("parsing [%s:%d] : '%s' : bad regular expression '%s'.\n", file, line, cmd, reg); |
| 1366 | err_code = ERR_ALERT | ERR_FATAL; |
| 1367 | goto err; |
| 1368 | } |
| 1369 | |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 1370 | 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] | 1371 | preg, action, repl ? strdup(repl) : NULL, cond); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1372 | if (repl && err) { |
| 1373 | Alert("parsing [%s:%d] : '%s' : invalid character or unterminated sequence in replacement string near '%c'.\n", |
| 1374 | file, line, cmd, *err); |
| 1375 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1376 | goto err; |
| 1377 | } |
| 1378 | |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 1379 | 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] | 1380 | err_code |= ERR_WARN; |
| 1381 | |
Willy Tarreau | f4068b6 | 2012-05-08 17:37:49 +0200 | [diff] [blame] | 1382 | free(errmsg); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1383 | return err_code; |
| 1384 | err: |
Willy Tarreau | f4068b6 | 2012-05-08 17:37:49 +0200 | [diff] [blame] | 1385 | free(errmsg); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1386 | free(preg); |
| 1387 | return err_code; |
| 1388 | } |
| 1389 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1390 | /* |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1391 | * Parse a line in a <listen>, <frontend>, <backend> or <ruleset> section. |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1392 | * Returns the error code, 0 if OK, or any combination of : |
| 1393 | * - ERR_ABORT: must abort ASAP |
| 1394 | * - ERR_FATAL: we can continue parsing but not start the service |
| 1395 | * - ERR_WARN: a warning has been emitted |
| 1396 | * - ERR_ALERT: an alert has been emitted |
| 1397 | * Only the two first ones can stop processing, the two others are just |
| 1398 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1399 | */ |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1400 | int cfg_parse_peers(const char *file, int linenum, char **args, int kwm) |
| 1401 | { |
| 1402 | static struct peers *curpeers = NULL; |
| 1403 | struct peer *newpeer = NULL; |
| 1404 | const char *err; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1405 | struct bind_conf *bind_conf; |
| 1406 | struct listener *l; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1407 | int err_code = 0; |
| 1408 | |
| 1409 | if (strcmp(args[0], "peers") == 0) { /* new peers section */ |
| 1410 | |
| 1411 | err = invalid_char(args[1]); |
| 1412 | if (err) { |
| 1413 | Alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 1414 | file, linenum, *err, args[0], args[1]); |
| 1415 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1416 | } |
| 1417 | |
| 1418 | for (curpeers = peers; curpeers != NULL; curpeers = curpeers->next) { |
| 1419 | /* |
| 1420 | * If there are two proxies with the same name only following |
| 1421 | * combinations are allowed: |
| 1422 | */ |
| 1423 | if (strcmp(curpeers->id, args[1]) == 0) { |
| 1424 | Warning("Parsing [%s:%d]: peers '%s' has same name as another peers (declared at %s:%d).\n", |
| 1425 | file, linenum, args[1], curpeers->conf.file, curpeers->conf.line); |
| 1426 | err_code |= ERR_WARN; |
| 1427 | } |
| 1428 | } |
| 1429 | |
| 1430 | if ((curpeers = (struct peers *)calloc(1, sizeof(struct peers))) == NULL) { |
| 1431 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1432 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1433 | goto out; |
| 1434 | } |
| 1435 | |
| 1436 | curpeers->next = peers; |
| 1437 | peers = curpeers; |
Willy Tarreau | 8113a5d | 2012-10-04 08:01:43 +0200 | [diff] [blame] | 1438 | curpeers->conf.file = strdup(file); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1439 | curpeers->conf.line = linenum; |
| 1440 | curpeers->last_change = now.tv_sec; |
| 1441 | curpeers->id = strdup(args[1]); |
| 1442 | } |
| 1443 | else if (strcmp(args[0], "peer") == 0) { /* peer definition */ |
| 1444 | char *rport, *raddr; |
| 1445 | short realport = 0; |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 1446 | struct sockaddr_storage *sk; |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 1447 | char *err_msg = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1448 | |
| 1449 | if (!*args[2]) { |
| 1450 | Alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n", |
| 1451 | file, linenum, args[0]); |
| 1452 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1453 | goto out; |
| 1454 | } |
| 1455 | |
| 1456 | err = invalid_char(args[1]); |
| 1457 | if (err) { |
| 1458 | Alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n", |
| 1459 | file, linenum, *err, args[1]); |
| 1460 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1461 | goto out; |
| 1462 | } |
| 1463 | |
| 1464 | if ((newpeer = (struct peer *)calloc(1, sizeof(struct peer))) == NULL) { |
| 1465 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1466 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1467 | goto out; |
| 1468 | } |
| 1469 | |
| 1470 | /* the peers are linked backwards first */ |
| 1471 | curpeers->count++; |
| 1472 | newpeer->next = curpeers->remote; |
| 1473 | curpeers->remote = newpeer; |
| 1474 | newpeer->peers = curpeers; |
Willy Tarreau | 8113a5d | 2012-10-04 08:01:43 +0200 | [diff] [blame] | 1475 | newpeer->conf.file = strdup(file); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1476 | newpeer->conf.line = linenum; |
| 1477 | |
| 1478 | newpeer->last_change = now.tv_sec; |
| 1479 | newpeer->id = strdup(args[1]); |
| 1480 | |
| 1481 | raddr = strdup(args[2]); |
Willy Tarreau | fab5a43 | 2011-03-04 15:31:53 +0100 | [diff] [blame] | 1482 | rport = strrchr(raddr, ':'); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1483 | if (rport) { |
| 1484 | *rport++ = 0; |
| 1485 | realport = atol(rport); |
| 1486 | } |
| 1487 | if (!realport) { |
| 1488 | Alert("parsing [%s:%d] : Missing or invalid port in '%s'\n", file, linenum, args[2]); |
| 1489 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1490 | goto out; |
| 1491 | } |
| 1492 | |
Willy Tarreau | fab5a43 | 2011-03-04 15:31:53 +0100 | [diff] [blame] | 1493 | sk = str2ip(raddr); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1494 | free(raddr); |
| 1495 | if (!sk) { |
| 1496 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[2]); |
| 1497 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1498 | goto out; |
| 1499 | } |
| 1500 | newpeer->addr = *sk; |
Willy Tarreau | 26d8c59 | 2012-05-07 18:12:14 +0200 | [diff] [blame] | 1501 | newpeer->proto = protocol_by_family(newpeer->addr.ss_family); |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 1502 | newpeer->xprt = &raw_sock; |
Willy Tarreau | d02394b | 2012-05-11 18:32:18 +0200 | [diff] [blame] | 1503 | newpeer->sock_init_arg = NULL; |
Willy Tarreau | 26d8c59 | 2012-05-07 18:12:14 +0200 | [diff] [blame] | 1504 | |
Willy Tarreau | 173e7fb | 2012-09-24 22:47:39 +0200 | [diff] [blame] | 1505 | if (!newpeer->proto) { |
Willy Tarreau | 26d8c59 | 2012-05-07 18:12:14 +0200 | [diff] [blame] | 1506 | Alert("parsing [%s:%d] : Unknown protocol family %d '%s'\n", |
| 1507 | file, linenum, newpeer->addr.ss_family, args[2]); |
| 1508 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1509 | goto out; |
| 1510 | } |
| 1511 | |
Willy Tarreau | 86ad42c | 2011-08-27 12:29:07 +0200 | [diff] [blame] | 1512 | set_host_port(&newpeer->addr, realport); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1513 | |
| 1514 | if (strcmp(newpeer->id, localpeer) == 0) { |
| 1515 | /* Current is local peer, it define a frontend */ |
| 1516 | newpeer->local = 1; |
| 1517 | |
| 1518 | if (!curpeers->peers_fe) { |
| 1519 | if ((curpeers->peers_fe = calloc(1, sizeof(struct proxy))) == NULL) { |
| 1520 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1521 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1522 | goto out; |
| 1523 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1524 | |
Willy Tarreau | 237250c | 2011-07-29 01:49:03 +0200 | [diff] [blame] | 1525 | init_new_proxy(curpeers->peers_fe); |
| 1526 | curpeers->peers_fe->parent = curpeers; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1527 | |
| 1528 | curpeers->peers_fe->last_change = now.tv_sec; |
| 1529 | curpeers->peers_fe->id = strdup(args[1]); |
| 1530 | curpeers->peers_fe->cap = PR_CAP_FE; |
Willy Tarreau | 3ae65a1 | 2011-09-07 17:40:39 +0200 | [diff] [blame] | 1531 | curpeers->peers_fe->maxconn = 0; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1532 | curpeers->peers_fe->conn_retries = CONN_RETRIES; |
| 1533 | curpeers->peers_fe->timeout.connect = 5000; |
| 1534 | curpeers->peers_fe->accept = peer_accept; |
| 1535 | curpeers->peers_fe->options2 |= PR_O2_INDEPSTR | PR_O2_SMARTCON | PR_O2_SMARTACC; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1536 | |
| 1537 | bind_conf = bind_conf_alloc(&curpeers->peers_fe->conf.bind, file, linenum, args[2]); |
| 1538 | |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 1539 | if (!str2listener(args[2], curpeers->peers_fe, bind_conf, file, linenum, &err_msg)) { |
| 1540 | if (err_msg && *err_msg) { |
| 1541 | indent_msg(&err_msg, 2); |
| 1542 | Alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], err_msg); |
| 1543 | } |
| 1544 | else |
| 1545 | Alert("parsing [%s:%d] : '%s %s' : error encountered while parsing listening address %s.\n", |
| 1546 | file, linenum, args[0], args[1], args[2]); |
| 1547 | free(err_msg); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1548 | err_code |= ERR_FATAL; |
| 1549 | goto out; |
| 1550 | } |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1551 | |
| 1552 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
| 1553 | l->maxconn = ((struct proxy *)curpeers->peers_fe)->maxconn; |
| 1554 | l->backlog = ((struct proxy *)curpeers->peers_fe)->backlog; |
| 1555 | l->timeout = &((struct proxy *)curpeers->peers_fe)->timeout.client; |
| 1556 | l->accept = session_accept; |
| 1557 | l->handler = process_session; |
| 1558 | l->analysers |= ((struct proxy *)curpeers->peers_fe)->fe_req_ana; |
| 1559 | l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */ |
| 1560 | global.maxsock += l->maxconn; |
| 1561 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1562 | } |
| 1563 | } |
| 1564 | } /* neither "peer" nor "peers" */ |
| 1565 | else if (*args[0] != 0) { |
| 1566 | Alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection); |
| 1567 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1568 | goto out; |
| 1569 | } |
| 1570 | |
| 1571 | out: |
| 1572 | return err_code; |
| 1573 | } |
| 1574 | |
| 1575 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 1576 | 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] | 1577 | { |
| 1578 | static struct proxy *curproxy = NULL; |
| 1579 | struct server *newsrv = NULL; |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 1580 | const char *err; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 1581 | int rc; |
| 1582 | unsigned val; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1583 | int err_code = 0; |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 1584 | struct acl_cond *cond = NULL; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 1585 | struct logsrv *tmplogsrv; |
Willy Tarreau | f4068b6 | 2012-05-08 17:37:49 +0200 | [diff] [blame] | 1586 | char *errmsg = NULL; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 1587 | struct bind_conf *bind_conf; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1588 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1589 | if (!strcmp(args[0], "listen")) |
| 1590 | rc = PR_CAP_LISTEN; |
| 1591 | else if (!strcmp(args[0], "frontend")) |
| 1592 | rc = PR_CAP_FE | PR_CAP_RS; |
| 1593 | else if (!strcmp(args[0], "backend")) |
| 1594 | rc = PR_CAP_BE | PR_CAP_RS; |
| 1595 | else if (!strcmp(args[0], "ruleset")) |
| 1596 | rc = PR_CAP_RS; |
| 1597 | else |
| 1598 | rc = PR_CAP_NONE; |
| 1599 | |
| 1600 | if (rc != PR_CAP_NONE) { /* new proxy */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1601 | if (!*args[1]) { |
| 1602 | Alert("parsing [%s:%d] : '%s' expects an <id> argument and\n" |
| 1603 | " optionnally supports [addr1]:port1[-end1]{,[addr]:port[-end]}...\n", |
| 1604 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1605 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1606 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1607 | } |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 1608 | |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 1609 | err = invalid_char(args[1]); |
| 1610 | if (err) { |
| 1611 | Alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 1612 | file, linenum, *err, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1613 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 1614 | } |
| 1615 | |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 1616 | for (curproxy = proxy; curproxy != NULL; curproxy = curproxy->next) { |
| 1617 | /* |
| 1618 | * If there are two proxies with the same name only following |
| 1619 | * combinations are allowed: |
| 1620 | * |
| 1621 | * listen backend frontend ruleset |
| 1622 | * listen - - - - |
| 1623 | * backend - - OK - |
| 1624 | * frontend - OK - - |
| 1625 | * ruleset - - - - |
| 1626 | */ |
| 1627 | |
| 1628 | if (!strcmp(curproxy->id, args[1]) && |
| 1629 | (rc!=(PR_CAP_FE|PR_CAP_RS) || curproxy->cap!=(PR_CAP_BE|PR_CAP_RS)) && |
| 1630 | (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] | 1631 | Warning("Parsing [%s:%d]: %s '%s' has same name as another %s (declared at %s:%d).\n", |
| 1632 | file, linenum, proxy_cap_str(rc), args[1], proxy_type_str(curproxy), |
| 1633 | curproxy->conf.file, curproxy->conf.line); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1634 | err_code |= ERR_WARN; |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 1635 | } |
| 1636 | } |
| 1637 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1638 | if ((curproxy = (struct proxy *)calloc(1, sizeof(struct proxy))) == NULL) { |
| 1639 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1640 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1641 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1642 | } |
Willy Tarreau | 5af24ef | 2009-03-15 15:23:16 +0100 | [diff] [blame] | 1643 | |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 1644 | init_new_proxy(curproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1645 | curproxy->next = proxy; |
| 1646 | proxy = curproxy; |
Willy Tarreau | 8113a5d | 2012-10-04 08:01:43 +0200 | [diff] [blame] | 1647 | curproxy->conf.file = strdup(file); |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 1648 | curproxy->conf.line = linenum; |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 1649 | curproxy->last_change = now.tv_sec; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1650 | curproxy->id = strdup(args[1]); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1651 | curproxy->cap = rc; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1652 | |
| 1653 | /* parse the listener address if any */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1654 | if ((curproxy->cap & PR_CAP_FE) && *args[2]) { |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1655 | struct listener *l; |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 1656 | char *err_msg = NULL; |
Willy Tarreau | 81a8117 | 2012-09-18 20:52:35 +0200 | [diff] [blame] | 1657 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1658 | bind_conf = bind_conf_alloc(&curproxy->conf.bind, file, linenum, args[2]); |
| 1659 | |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 1660 | if (!str2listener(args[2], curproxy, bind_conf, file, linenum, &err_msg)) { |
| 1661 | if (err_msg && *err_msg) { |
| 1662 | indent_msg(&err_msg, 2); |
| 1663 | Alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], err_msg); |
| 1664 | } |
| 1665 | else |
| 1666 | Alert("parsing [%s:%d] : '%s %s' : error encountered while parsing listening address '%s'.\n", |
| 1667 | file, linenum, args[0], args[1], args[2]); |
| 1668 | free(err_msg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1669 | err_code |= ERR_FATAL; |
| 1670 | goto out; |
| 1671 | } |
Willy Tarreau | 81a8117 | 2012-09-18 20:52:35 +0200 | [diff] [blame] | 1672 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1673 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
Willy Tarreau | c8b1109 | 2011-02-16 11:08:57 +0100 | [diff] [blame] | 1674 | global.maxsock++; |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 1675 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1676 | } |
| 1677 | |
| 1678 | /* set default values */ |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1679 | memcpy(&curproxy->defsrv, &defproxy.defsrv, sizeof(curproxy->defsrv)); |
Willy Tarreau | 7016020 | 2010-04-07 16:06:40 +0200 | [diff] [blame] | 1680 | curproxy->defsrv.id = "default-server"; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1681 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1682 | curproxy->state = defproxy.state; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1683 | curproxy->options = defproxy.options; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 1684 | curproxy->options2 = defproxy.options2; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 1685 | curproxy->no_options = defproxy.no_options; |
| 1686 | curproxy->no_options2 = defproxy.no_options2; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 1687 | curproxy->bind_proc = defproxy.bind_proc; |
Willy Tarreau | 3168223 | 2007-11-29 15:38:04 +0100 | [diff] [blame] | 1688 | curproxy->lbprm.algo = defproxy.lbprm.algo; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 1689 | curproxy->except_net = defproxy.except_net; |
| 1690 | curproxy->except_mask = defproxy.except_mask; |
Maik Broemme | 36db02e | 2009-05-08 17:02:07 +0200 | [diff] [blame] | 1691 | curproxy->except_to = defproxy.except_to; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 1692 | curproxy->except_mask_to = defproxy.except_mask_to; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1693 | |
Willy Tarreau | 79f5fe8 | 2008-08-23 08:18:21 +0200 | [diff] [blame] | 1694 | if (defproxy.fwdfor_hdr_len) { |
| 1695 | curproxy->fwdfor_hdr_len = defproxy.fwdfor_hdr_len; |
| 1696 | curproxy->fwdfor_hdr_name = strdup(defproxy.fwdfor_hdr_name); |
| 1697 | } |
| 1698 | |
Willy Tarreau | b86db34 | 2009-11-30 11:50:16 +0100 | [diff] [blame] | 1699 | if (defproxy.orgto_hdr_len) { |
| 1700 | curproxy->orgto_hdr_len = defproxy.orgto_hdr_len; |
| 1701 | curproxy->orgto_hdr_name = strdup(defproxy.orgto_hdr_name); |
| 1702 | } |
| 1703 | |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 1704 | if (defproxy.server_id_hdr_len) { |
| 1705 | curproxy->server_id_hdr_len = defproxy.server_id_hdr_len; |
| 1706 | curproxy->server_id_hdr_name = strdup(defproxy.server_id_hdr_name); |
| 1707 | } |
| 1708 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1709 | if (curproxy->cap & PR_CAP_FE) { |
| 1710 | curproxy->maxconn = defproxy.maxconn; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 1711 | curproxy->backlog = defproxy.backlog; |
Willy Tarreau | 13a34bd | 2009-05-10 18:52:49 +0200 | [diff] [blame] | 1712 | curproxy->fe_sps_lim = defproxy.fe_sps_lim; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1713 | |
| 1714 | /* initialize error relocations */ |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1715 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) |
| 1716 | chunk_dup(&curproxy->errmsg[rc], &defproxy.errmsg[rc]); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1717 | |
| 1718 | curproxy->to_log = defproxy.to_log & ~LW_COOKIE & ~LW_REQHDR & ~ LW_RSPHDR; |
| 1719 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1720 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1721 | if (curproxy->cap & PR_CAP_BE) { |
| 1722 | curproxy->fullconn = defproxy.fullconn; |
| 1723 | curproxy->conn_retries = defproxy.conn_retries; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1724 | |
Willy Tarreau | aa2f389 | 2010-10-22 16:15:31 +0200 | [diff] [blame] | 1725 | if (defproxy.check_req) { |
| 1726 | curproxy->check_req = calloc(1, defproxy.check_len); |
| 1727 | memcpy(curproxy->check_req, defproxy.check_req, defproxy.check_len); |
| 1728 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1729 | curproxy->check_len = defproxy.check_len; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1730 | |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 1731 | if (defproxy.expect_str) { |
| 1732 | curproxy->expect_str = strdup(defproxy.expect_str); |
| 1733 | if (defproxy.expect_regex) { |
| 1734 | /* note: this regex is known to be valid */ |
| 1735 | curproxy->expect_regex = calloc(1, sizeof(regex_t)); |
| 1736 | regcomp(curproxy->expect_regex, defproxy.expect_str, REG_EXTENDED); |
| 1737 | } |
| 1738 | } |
| 1739 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 1740 | curproxy->ck_opts = defproxy.ck_opts; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1741 | if (defproxy.cookie_name) |
| 1742 | curproxy->cookie_name = strdup(defproxy.cookie_name); |
| 1743 | curproxy->cookie_len = defproxy.cookie_len; |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 1744 | if (defproxy.cookie_domain) |
| 1745 | curproxy->cookie_domain = strdup(defproxy.cookie_domain); |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 1746 | |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 1747 | if (defproxy.cookie_maxidle) |
| 1748 | curproxy->cookie_maxidle = defproxy.cookie_maxidle; |
| 1749 | |
| 1750 | if (defproxy.cookie_maxlife) |
| 1751 | curproxy->cookie_maxlife = defproxy.cookie_maxlife; |
| 1752 | |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 1753 | if (defproxy.rdp_cookie_name) |
| 1754 | curproxy->rdp_cookie_name = strdup(defproxy.rdp_cookie_name); |
| 1755 | curproxy->rdp_cookie_len = defproxy.rdp_cookie_len; |
| 1756 | |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 1757 | if (defproxy.url_param_name) |
| 1758 | curproxy->url_param_name = strdup(defproxy.url_param_name); |
| 1759 | curproxy->url_param_len = defproxy.url_param_len; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 1760 | |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 1761 | if (defproxy.hh_name) |
| 1762 | curproxy->hh_name = strdup(defproxy.hh_name); |
| 1763 | curproxy->hh_len = defproxy.hh_len; |
| 1764 | curproxy->hh_match_domain = defproxy.hh_match_domain; |
| 1765 | |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 1766 | if (defproxy.iface_name) |
| 1767 | curproxy->iface_name = strdup(defproxy.iface_name); |
| 1768 | curproxy->iface_len = defproxy.iface_len; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1769 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1770 | |
Willy Tarreau | 3b6b1a9 | 2009-07-23 13:24:23 +0200 | [diff] [blame] | 1771 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1772 | if (defproxy.capture_name) |
| 1773 | curproxy->capture_name = strdup(defproxy.capture_name); |
| 1774 | curproxy->capture_namelen = defproxy.capture_namelen; |
| 1775 | curproxy->capture_len = defproxy.capture_len; |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 1776 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1777 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1778 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 1779 | curproxy->timeout.client = defproxy.timeout.client; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 1780 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | 036fae0 | 2008-01-06 13:24:40 +0100 | [diff] [blame] | 1781 | curproxy->timeout.httpreq = defproxy.timeout.httpreq; |
Willy Tarreau | b16a574 | 2010-01-10 14:46:16 +0100 | [diff] [blame] | 1782 | curproxy->timeout.httpka = defproxy.timeout.httpka; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1783 | curproxy->uri_auth = defproxy.uri_auth; |
| 1784 | curproxy->mon_net = defproxy.mon_net; |
| 1785 | curproxy->mon_mask = defproxy.mon_mask; |
| 1786 | if (defproxy.monitor_uri) |
| 1787 | curproxy->monitor_uri = strdup(defproxy.monitor_uri); |
| 1788 | curproxy->monitor_uri_len = defproxy.monitor_uri_len; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 1789 | if (defproxy.defbe.name) |
| 1790 | curproxy->defbe.name = strdup(defproxy.defbe.name); |
Willy Tarreau | 99a7ca2 | 2012-05-31 19:39:23 +0200 | [diff] [blame] | 1791 | |
| 1792 | /* get either a pointer to the logformat string or a copy of it */ |
| 1793 | curproxy->logformat_string = defproxy.logformat_string; |
| 1794 | if (curproxy->logformat_string && |
| 1795 | curproxy->logformat_string != default_http_log_format && |
| 1796 | curproxy->logformat_string != default_tcp_log_format && |
| 1797 | curproxy->logformat_string != clf_http_log_format) |
| 1798 | curproxy->logformat_string = strdup(curproxy->logformat_string); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1799 | } |
| 1800 | |
| 1801 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 1802 | curproxy->timeout.connect = defproxy.timeout.connect; |
| 1803 | curproxy->timeout.server = defproxy.timeout.server; |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 1804 | curproxy->timeout.check = defproxy.timeout.check; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 1805 | curproxy->timeout.queue = defproxy.timeout.queue; |
Willy Tarreau | 51c9bde | 2008-01-06 13:40:03 +0100 | [diff] [blame] | 1806 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | cd7afc0 | 2009-07-12 10:03:17 +0200 | [diff] [blame] | 1807 | curproxy->timeout.httpreq = defproxy.timeout.httpreq; |
Willy Tarreau | b16a574 | 2010-01-10 14:46:16 +0100 | [diff] [blame] | 1808 | curproxy->timeout.httpka = defproxy.timeout.httpka; |
Willy Tarreau | ce887fd | 2012-05-12 12:50:00 +0200 | [diff] [blame] | 1809 | curproxy->timeout.tunnel = defproxy.timeout.tunnel; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1810 | curproxy->source_addr = defproxy.source_addr; |
| 1811 | } |
| 1812 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1813 | curproxy->mode = defproxy.mode; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1814 | |
| 1815 | /* copy default logsrvs to curproxy */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 1816 | list_for_each_entry(tmplogsrv, &defproxy.logsrvs, list) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1817 | struct logsrv *node = malloc(sizeof(struct logsrv)); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 1818 | memcpy(node, tmplogsrv, sizeof(struct logsrv)); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1819 | LIST_INIT(&node->list); |
| 1820 | LIST_ADDQ(&curproxy->logsrvs, &node->list); |
| 1821 | } |
| 1822 | |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 1823 | curproxy->uniqueid_format_string = defproxy.uniqueid_format_string; |
| 1824 | if (curproxy->uniqueid_format_string) |
| 1825 | curproxy->uniqueid_format_string = strdup(curproxy->uniqueid_format_string); |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 1826 | |
| 1827 | /* copy default header unique id */ |
| 1828 | if (defproxy.header_unique_id) |
| 1829 | curproxy->header_unique_id = strdup(defproxy.header_unique_id); |
| 1830 | |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 1831 | /* default compression options */ |
| 1832 | if (defproxy.comp != NULL) { |
| 1833 | curproxy->comp = calloc(1, sizeof(struct comp)); |
| 1834 | curproxy->comp->algos = defproxy.comp->algos; |
| 1835 | curproxy->comp->types = defproxy.comp->types; |
| 1836 | } |
| 1837 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1838 | curproxy->grace = defproxy.grace; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1839 | curproxy->conf.used_listener_id = EB_ROOT; |
| 1840 | curproxy->conf.used_server_id = EB_ROOT; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 1841 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1842 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1843 | } |
| 1844 | else if (!strcmp(args[0], "defaults")) { /* use this one to assign default values */ |
| 1845 | /* some variables may have already been initialized earlier */ |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 1846 | /* FIXME-20070101: we should do this too at the end of the |
| 1847 | * config parsing to free all default values. |
| 1848 | */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1849 | free(defproxy.check_req); |
| 1850 | free(defproxy.cookie_name); |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 1851 | free(defproxy.rdp_cookie_name); |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 1852 | free(defproxy.cookie_domain); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1853 | free(defproxy.url_param_name); |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 1854 | free(defproxy.hh_name); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1855 | free(defproxy.capture_name); |
| 1856 | free(defproxy.monitor_uri); |
| 1857 | free(defproxy.defbe.name); |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 1858 | free(defproxy.iface_name); |
Willy Tarreau | 79f5fe8 | 2008-08-23 08:18:21 +0200 | [diff] [blame] | 1859 | free(defproxy.fwdfor_hdr_name); |
| 1860 | defproxy.fwdfor_hdr_len = 0; |
Willy Tarreau | b86db34 | 2009-11-30 11:50:16 +0100 | [diff] [blame] | 1861 | free(defproxy.orgto_hdr_name); |
| 1862 | defproxy.orgto_hdr_len = 0; |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 1863 | free(defproxy.server_id_hdr_name); |
| 1864 | defproxy.server_id_hdr_len = 0; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 1865 | free(defproxy.expect_str); |
| 1866 | if (defproxy.expect_regex) regfree(defproxy.expect_regex); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 1867 | |
Willy Tarreau | 39b0665 | 2012-06-01 10:58:06 +0200 | [diff] [blame] | 1868 | if (defproxy.logformat_string != default_http_log_format && |
| 1869 | defproxy.logformat_string != default_tcp_log_format && |
| 1870 | defproxy.logformat_string != clf_http_log_format) |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 1871 | free(defproxy.logformat_string); |
| 1872 | |
| 1873 | free(defproxy.uniqueid_format_string); |
| 1874 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1875 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1876 | chunk_destroy(&defproxy.errmsg[rc]); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 1877 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1878 | /* we cannot free uri_auth because it might already be used */ |
| 1879 | init_default_instance(); |
| 1880 | curproxy = &defproxy; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1881 | defproxy.cap = PR_CAP_LISTEN; /* all caps for now */ |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1882 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1883 | } |
| 1884 | else if (curproxy == NULL) { |
| 1885 | Alert("parsing [%s:%d] : 'listen' or 'defaults' expected.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1886 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1887 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1888 | } |
| 1889 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1890 | |
| 1891 | /* Now let's parse the proxy-specific keywords */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1892 | if (!strcmp(args[0], "bind")) { /* new listen addresses */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1893 | struct listener *l; |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1894 | int cur_arg; |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 1895 | char *err_msg = NULL; |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1896 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1897 | if (curproxy == &defproxy) { |
| 1898 | 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] | 1899 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1900 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1901 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1902 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1903 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1904 | |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 1905 | if ( *(args[1]) != '/' && strchr(args[1], ':') == NULL) { |
Willy Tarreau | d55c3fe | 2010-11-09 09:50:37 +0100 | [diff] [blame] | 1906 | 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] | 1907 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1908 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1909 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1910 | } |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 1911 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 1912 | bind_conf = bind_conf_alloc(&curproxy->conf.bind, file, linenum, args[1]); |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1913 | 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] | 1914 | |
| 1915 | /* NOTE: the following line might create several listeners if there |
| 1916 | * are comma-separated IPs or port ranges. So all further processing |
| 1917 | * will have to be applied to all listeners created after last_listen. |
| 1918 | */ |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 1919 | if (!str2listener(args[1], curproxy, bind_conf, file, linenum, &err_msg)) { |
| 1920 | if (err_msg && *err_msg) { |
| 1921 | indent_msg(&err_msg, 2); |
| 1922 | Alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], err_msg); |
| 1923 | } |
| 1924 | else |
| 1925 | Alert("parsing [%s:%d] : '%s' : error encountered while parsing listening address '%s'.\n", |
| 1926 | file, linenum, args[0], args[1]); |
| 1927 | free(err_msg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1928 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1929 | goto out; |
| 1930 | } |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1931 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1932 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
| 1933 | /* Set default global rights and owner for unix bind */ |
Willy Tarreau | c8b1109 | 2011-02-16 11:08:57 +0100 | [diff] [blame] | 1934 | global.maxsock++; |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 1935 | } |
| 1936 | |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1937 | cur_arg = 2; |
| 1938 | while (*(args[cur_arg])) { |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 1939 | static int bind_dumped; |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 1940 | struct bind_kw *kw; |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 1941 | char *err; |
| 1942 | |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 1943 | kw = bind_find_kw(args[cur_arg]); |
| 1944 | if (kw) { |
| 1945 | char *err = NULL; |
| 1946 | int code; |
| 1947 | |
| 1948 | if (!kw->parse) { |
Willy Tarreau | dda322d | 2012-09-18 16:34:09 +0200 | [diff] [blame] | 1949 | Alert("parsing [%s:%d] : '%s %s' : '%s' option is not implemented in this version (check build options).\n", |
| 1950 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 1951 | cur_arg += 1 + kw->skip ; |
| 1952 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1953 | goto out; |
| 1954 | } |
| 1955 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1956 | code = kw->parse(args, cur_arg, curproxy, bind_conf, &err); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 1957 | err_code |= code; |
| 1958 | |
| 1959 | if (code) { |
| 1960 | if (err && *err) { |
| 1961 | indent_msg(&err, 2); |
Willy Tarreau | dda322d | 2012-09-18 16:34:09 +0200 | [diff] [blame] | 1962 | 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] | 1963 | } |
| 1964 | else |
Willy Tarreau | dda322d | 2012-09-18 16:34:09 +0200 | [diff] [blame] | 1965 | Alert("parsing [%s:%d] : '%s %s' : error encountered while processing '%s'.\n", |
| 1966 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 1967 | if (code & ERR_FATAL) { |
| 1968 | free(err); |
| 1969 | cur_arg += 1 + kw->skip; |
| 1970 | goto out; |
| 1971 | } |
| 1972 | } |
| 1973 | free(err); |
| 1974 | cur_arg += 1 + kw->skip; |
| 1975 | continue; |
| 1976 | } |
| 1977 | |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 1978 | err = NULL; |
| 1979 | if (!bind_dumped) { |
| 1980 | bind_dump_kws(&err); |
| 1981 | indent_msg(&err, 4); |
| 1982 | bind_dumped = 1; |
| 1983 | } |
| 1984 | |
| 1985 | Alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'.%s%s\n", |
| 1986 | file, linenum, args[0], args[1], args[cur_arg], |
| 1987 | err ? " Registered keywords :" : "", err ? err : ""); |
| 1988 | free(err); |
| 1989 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1990 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1991 | goto out; |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 1992 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1993 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1994 | } |
| 1995 | else if (!strcmp(args[0], "monitor-net")) { /* set the range of IPs to ignore */ |
| 1996 | if (!*args[1] || !str2net(args[1], &curproxy->mon_net, &curproxy->mon_mask)) { |
| 1997 | Alert("parsing [%s:%d] : '%s' expects address[/mask].\n", |
| 1998 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1999 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2000 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2001 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2002 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2003 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2004 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2005 | /* flush useless bits */ |
| 2006 | curproxy->mon_net.s_addr &= curproxy->mon_mask.s_addr; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2007 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2008 | } |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2009 | else if (!strcmp(args[0], "monitor-uri")) { /* set the URI to intercept */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2010 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2011 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2012 | |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2013 | if (!*args[1]) { |
| 2014 | Alert("parsing [%s:%d] : '%s' expects an URI.\n", |
| 2015 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2016 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2017 | goto out; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2018 | } |
| 2019 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2020 | free(curproxy->monitor_uri); |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 2021 | curproxy->monitor_uri_len = strlen(args[1]); |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2022 | curproxy->monitor_uri = (char *)calloc(1, curproxy->monitor_uri_len + 1); |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 2023 | memcpy(curproxy->monitor_uri, args[1], curproxy->monitor_uri_len); |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2024 | curproxy->monitor_uri[curproxy->monitor_uri_len] = '\0'; |
| 2025 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2026 | goto out; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2027 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2028 | else if (!strcmp(args[0], "mode")) { /* sets the proxy mode */ |
| 2029 | if (!strcmp(args[1], "http")) curproxy->mode = PR_MODE_HTTP; |
| 2030 | else if (!strcmp(args[1], "tcp")) curproxy->mode = PR_MODE_TCP; |
| 2031 | else if (!strcmp(args[1], "health")) curproxy->mode = PR_MODE_HEALTH; |
| 2032 | else { |
| 2033 | 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] | 2034 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2035 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2036 | } |
| 2037 | } |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2038 | else if (!strcmp(args[0], "id")) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2039 | struct eb32_node *node; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2040 | |
| 2041 | if (curproxy == &defproxy) { |
| 2042 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", |
| 2043 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2044 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2045 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2046 | } |
| 2047 | |
| 2048 | if (!*args[1]) { |
| 2049 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 2050 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2051 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2052 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2053 | } |
| 2054 | |
| 2055 | curproxy->uuid = atol(args[1]); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2056 | curproxy->conf.id.key = curproxy->uuid; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2057 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2058 | if (curproxy->uuid <= 0) { |
| 2059 | Alert("parsing [%s:%d]: custom id has to be > 0.\n", |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2060 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2061 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2062 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2063 | } |
| 2064 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2065 | node = eb32_lookup(&used_proxy_id, curproxy->uuid); |
| 2066 | if (node) { |
| 2067 | struct proxy *target = container_of(node, struct proxy, conf.id); |
| 2068 | Alert("parsing [%s:%d]: %s %s reuses same custom id as %s %s (declared at %s:%d).\n", |
| 2069 | file, linenum, proxy_type_str(curproxy), curproxy->id, |
| 2070 | proxy_type_str(target), target->id, target->conf.file, target->conf.line); |
| 2071 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2072 | goto out; |
| 2073 | } |
| 2074 | eb32_insert(&used_proxy_id, &curproxy->conf.id); |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2075 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 2076 | else if (!strcmp(args[0], "description")) { |
| 2077 | int i, len=0; |
| 2078 | char *d; |
| 2079 | |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 2080 | if (curproxy == &defproxy) { |
| 2081 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", |
| 2082 | file, linenum, args[0]); |
| 2083 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2084 | goto out; |
| 2085 | } |
| 2086 | |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 2087 | if (!*args[1]) { |
| 2088 | Alert("parsing [%s:%d]: '%s' expects a string argument.\n", |
| 2089 | file, linenum, args[0]); |
| 2090 | return -1; |
| 2091 | } |
| 2092 | |
| 2093 | for(i=1; *args[i]; i++) |
| 2094 | len += strlen(args[i])+1; |
| 2095 | |
| 2096 | d = (char *)calloc(1, len); |
| 2097 | curproxy->desc = d; |
| 2098 | |
| 2099 | d += sprintf(d, "%s", args[1]); |
| 2100 | for(i=2; *args[i]; i++) |
| 2101 | d += sprintf(d, " %s", args[i]); |
| 2102 | |
| 2103 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2104 | else if (!strcmp(args[0], "disabled")) { /* disables this proxy */ |
| 2105 | curproxy->state = PR_STSTOPPED; |
| 2106 | } |
| 2107 | else if (!strcmp(args[0], "enabled")) { /* enables this proxy (used to revert a disabled default) */ |
| 2108 | curproxy->state = PR_STNEW; |
| 2109 | } |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2110 | else if (!strcmp(args[0], "bind-process")) { /* enable this proxy only on some processes */ |
| 2111 | int cur_arg = 1; |
| 2112 | unsigned int set = 0; |
| 2113 | |
| 2114 | while (*args[cur_arg]) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 2115 | unsigned int low, high; |
| 2116 | |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2117 | if (strcmp(args[cur_arg], "all") == 0) { |
| 2118 | set = 0; |
| 2119 | break; |
| 2120 | } |
| 2121 | else if (strcmp(args[cur_arg], "odd") == 0) { |
| 2122 | set |= 0x55555555; |
| 2123 | } |
| 2124 | else if (strcmp(args[cur_arg], "even") == 0) { |
| 2125 | set |= 0xAAAAAAAA; |
| 2126 | } |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 2127 | else if (isdigit(*args[cur_arg])) { |
| 2128 | char *dash = strchr(args[cur_arg], '-'); |
| 2129 | |
| 2130 | low = high = str2uic(args[cur_arg]); |
| 2131 | if (dash) |
| 2132 | high = str2uic(dash + 1); |
| 2133 | |
| 2134 | if (high < low) { |
| 2135 | unsigned int swap = low; |
| 2136 | low = high; |
| 2137 | high = swap; |
| 2138 | } |
| 2139 | |
| 2140 | if (low < 1 || high > 32) { |
| 2141 | 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] | 2142 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2143 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2144 | goto out; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2145 | } |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 2146 | |
| 2147 | if (high > global.nbproc) { |
| 2148 | Warning("parsing [%s:%d]: %s references process number %d which is higher than global.nbproc (%d).\n", |
| 2149 | file, linenum, args[0], high, global.nbproc); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2150 | err_code |= ERR_WARN; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2151 | } |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 2152 | while (low <= high) |
| 2153 | set |= 1 << (low++ - 1); |
| 2154 | } |
| 2155 | else { |
| 2156 | Alert("parsing [%s:%d]: %s expects 'all', 'odd', 'even', or a list of process ranges with numbers from 1 to 32.\n", |
| 2157 | file, linenum, args[0]); |
| 2158 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2159 | goto out; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2160 | } |
| 2161 | cur_arg++; |
| 2162 | } |
| 2163 | curproxy->bind_proc = set; |
| 2164 | } |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 2165 | else if (!strcmp(args[0], "acl")) { /* add an ACL */ |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2166 | if (curproxy == &defproxy) { |
| 2167 | 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] | 2168 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2169 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2170 | } |
| 2171 | |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 2172 | err = invalid_char(args[1]); |
| 2173 | if (err) { |
| 2174 | Alert("parsing [%s:%d] : character '%c' is not permitted in acl name '%s'.\n", |
| 2175 | file, linenum, *err, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2176 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 2177 | } |
| 2178 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 2179 | if (parse_acl((const char **)args + 1, &curproxy->acl, &errmsg) == NULL) { |
| 2180 | Alert("parsing [%s:%d] : error detected while parsing ACL '%s' : %s.\n", |
| 2181 | file, linenum, args[1], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2182 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2183 | goto out; |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 2184 | } |
| 2185 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2186 | else if (!strcmp(args[0], "cookie")) { /* cookie name */ |
| 2187 | int cur_arg; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2188 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2189 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2190 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2191 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2192 | if (*(args[1]) == 0) { |
| 2193 | Alert("parsing [%s:%d] : '%s' expects <cookie_name> as argument.\n", |
| 2194 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2195 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2196 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2197 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2198 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2199 | curproxy->ck_opts = 0; |
Willy Tarreau | c63d4bb | 2010-10-23 11:37:27 +0200 | [diff] [blame] | 2200 | curproxy->cookie_maxidle = curproxy->cookie_maxlife = 0; |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 2201 | free(curproxy->cookie_domain); curproxy->cookie_domain = NULL; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2202 | free(curproxy->cookie_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2203 | curproxy->cookie_name = strdup(args[1]); |
| 2204 | curproxy->cookie_len = strlen(curproxy->cookie_name); |
Willy Tarreau | c63d4bb | 2010-10-23 11:37:27 +0200 | [diff] [blame] | 2205 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2206 | cur_arg = 2; |
| 2207 | while (*(args[cur_arg])) { |
| 2208 | if (!strcmp(args[cur_arg], "rewrite")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2209 | curproxy->ck_opts |= PR_CK_RW; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2210 | } |
| 2211 | else if (!strcmp(args[cur_arg], "indirect")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2212 | curproxy->ck_opts |= PR_CK_IND; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2213 | } |
| 2214 | else if (!strcmp(args[cur_arg], "insert")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2215 | curproxy->ck_opts |= PR_CK_INS; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2216 | } |
| 2217 | else if (!strcmp(args[cur_arg], "nocache")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2218 | curproxy->ck_opts |= PR_CK_NOC; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2219 | } |
| 2220 | else if (!strcmp(args[cur_arg], "postonly")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2221 | curproxy->ck_opts |= PR_CK_POST; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2222 | } |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 2223 | else if (!strcmp(args[cur_arg], "preserve")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2224 | curproxy->ck_opts |= PR_CK_PSV; |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 2225 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2226 | else if (!strcmp(args[cur_arg], "prefix")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2227 | curproxy->ck_opts |= PR_CK_PFX; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2228 | } |
Willy Tarreau | 4992dd2 | 2012-05-31 21:02:17 +0200 | [diff] [blame] | 2229 | else if (!strcmp(args[cur_arg], "httponly")) { |
| 2230 | curproxy->ck_opts |= PR_CK_HTTPONLY; |
| 2231 | } |
| 2232 | else if (!strcmp(args[cur_arg], "secure")) { |
| 2233 | curproxy->ck_opts |= PR_CK_SECURE; |
| 2234 | } |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2235 | else if (!strcmp(args[cur_arg], "domain")) { |
| 2236 | if (!*args[cur_arg + 1]) { |
| 2237 | Alert("parsing [%s:%d]: '%s' expects <domain> as argument.\n", |
| 2238 | file, linenum, args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2239 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2240 | goto out; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2241 | } |
| 2242 | |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 2243 | if (*args[cur_arg + 1] != '.' || !strchr(args[cur_arg + 1] + 1, '.')) { |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2244 | /* rfc2109, 4.3.2 Rejecting Cookies */ |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 2245 | Warning("parsing [%s:%d]: domain '%s' contains no embedded" |
| 2246 | " dots nor does not start with a dot." |
| 2247 | " RFC forbids it, this configuration may not work properly.\n", |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2248 | file, linenum, args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 2249 | err_code |= ERR_WARN; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2250 | } |
| 2251 | |
| 2252 | err = invalid_domainchar(args[cur_arg + 1]); |
| 2253 | if (err) { |
| 2254 | Alert("parsing [%s:%d]: character '%c' is not permitted in domain name '%s'.\n", |
| 2255 | file, linenum, *err, args[cur_arg + 1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2256 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2257 | goto out; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2258 | } |
| 2259 | |
Willy Tarreau | 68a897b | 2009-12-03 23:28:34 +0100 | [diff] [blame] | 2260 | if (!curproxy->cookie_domain) { |
| 2261 | curproxy->cookie_domain = strdup(args[cur_arg + 1]); |
| 2262 | } else { |
| 2263 | /* one domain was already specified, add another one by |
| 2264 | * building the string which will be returned along with |
| 2265 | * the cookie. |
| 2266 | */ |
| 2267 | char *new_ptr; |
| 2268 | int new_len = strlen(curproxy->cookie_domain) + |
| 2269 | strlen("; domain=") + strlen(args[cur_arg + 1]) + 1; |
| 2270 | new_ptr = malloc(new_len); |
| 2271 | snprintf(new_ptr, new_len, "%s; domain=%s", curproxy->cookie_domain, args[cur_arg+1]); |
| 2272 | free(curproxy->cookie_domain); |
| 2273 | curproxy->cookie_domain = new_ptr; |
| 2274 | } |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 2275 | cur_arg++; |
| 2276 | } |
| 2277 | else if (!strcmp(args[cur_arg], "maxidle")) { |
| 2278 | unsigned int maxidle; |
| 2279 | const char *res; |
| 2280 | |
| 2281 | if (!*args[cur_arg + 1]) { |
| 2282 | Alert("parsing [%s:%d]: '%s' expects <idletime> in seconds as argument.\n", |
| 2283 | file, linenum, args[cur_arg]); |
| 2284 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2285 | goto out; |
| 2286 | } |
| 2287 | |
| 2288 | res = parse_time_err(args[cur_arg + 1], &maxidle, TIME_UNIT_S); |
| 2289 | if (res) { |
| 2290 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 2291 | file, linenum, *res, args[cur_arg]); |
| 2292 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2293 | goto out; |
| 2294 | } |
| 2295 | curproxy->cookie_maxidle = maxidle; |
| 2296 | cur_arg++; |
| 2297 | } |
| 2298 | else if (!strcmp(args[cur_arg], "maxlife")) { |
| 2299 | unsigned int maxlife; |
| 2300 | const char *res; |
| 2301 | |
| 2302 | if (!*args[cur_arg + 1]) { |
| 2303 | Alert("parsing [%s:%d]: '%s' expects <lifetime> in seconds as argument.\n", |
| 2304 | file, linenum, args[cur_arg]); |
| 2305 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2306 | goto out; |
| 2307 | } |
| 2308 | |
| 2309 | res = parse_time_err(args[cur_arg + 1], &maxlife, TIME_UNIT_S); |
| 2310 | if (res) { |
| 2311 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 2312 | file, linenum, *res, args[cur_arg]); |
| 2313 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2314 | goto out; |
| 2315 | } |
| 2316 | curproxy->cookie_maxlife = maxlife; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2317 | cur_arg++; |
| 2318 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2319 | else { |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 2320 | 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] | 2321 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2322 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2323 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2324 | } |
| 2325 | cur_arg++; |
| 2326 | } |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2327 | if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_IND))) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2328 | Alert("parsing [%s:%d] : cookie 'rewrite' and 'indirect' modes are incompatible.\n", |
| 2329 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2330 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2331 | } |
| 2332 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2333 | 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] | 2334 | Alert("parsing [%s:%d] : cookie 'rewrite', 'insert' and 'prefix' modes are incompatible.\n", |
| 2335 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2336 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2337 | } |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 2338 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2339 | 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] | 2340 | Alert("parsing [%s:%d] : cookie 'preserve' requires at least 'insert' or 'indirect'.\n", |
| 2341 | file, linenum); |
| 2342 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2343 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2344 | }/* end else if (!strcmp(args[0], "cookie")) */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2345 | else if (!strcmp(args[0], "persist")) { /* persist */ |
| 2346 | if (*(args[1]) == 0) { |
| 2347 | Alert("parsing [%s:%d] : missing persist method.\n", |
| 2348 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2349 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2350 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2351 | } |
| 2352 | |
| 2353 | if (!strncmp(args[1], "rdp-cookie", 10)) { |
| 2354 | curproxy->options2 |= PR_O2_RDPC_PRST; |
| 2355 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2356 | if (*(args[1] + 10) == '(') { /* cookie name */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2357 | const char *beg, *end; |
| 2358 | |
| 2359 | beg = args[1] + 11; |
| 2360 | end = strchr(beg, ')'); |
| 2361 | |
| 2362 | if (!end || end == beg) { |
| 2363 | Alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n", |
| 2364 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2365 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2366 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2367 | } |
| 2368 | |
| 2369 | free(curproxy->rdp_cookie_name); |
| 2370 | curproxy->rdp_cookie_name = my_strndup(beg, end - beg); |
| 2371 | curproxy->rdp_cookie_len = end-beg; |
| 2372 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2373 | else if (*(args[1] + 10) == '\0') { /* default cookie name 'msts' */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2374 | free(curproxy->rdp_cookie_name); |
| 2375 | curproxy->rdp_cookie_name = strdup("msts"); |
| 2376 | curproxy->rdp_cookie_len = strlen(curproxy->rdp_cookie_name); |
| 2377 | } |
| 2378 | else { /* syntax */ |
| 2379 | Alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n", |
| 2380 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2381 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2382 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2383 | } |
| 2384 | } |
| 2385 | else { |
| 2386 | Alert("parsing [%s:%d] : unknown persist method.\n", |
| 2387 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2388 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2389 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2390 | } |
| 2391 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2392 | else if (!strcmp(args[0], "appsession")) { /* cookie name */ |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2393 | int cur_arg; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2394 | |
Cyril Bonté | 3b7a369 | 2010-01-10 17:01:47 +0100 | [diff] [blame] | 2395 | if (curproxy == &defproxy) { |
| 2396 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2397 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2398 | goto out; |
| 2399 | } |
| 2400 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2401 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2402 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2403 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2404 | if (*(args[5]) == 0) { |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2405 | 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] | 2406 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2407 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2408 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2409 | } |
| 2410 | have_appsession = 1; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2411 | free(curproxy->appsession_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2412 | curproxy->appsession_name = strdup(args[1]); |
| 2413 | curproxy->appsession_name_len = strlen(curproxy->appsession_name); |
| 2414 | curproxy->appsession_len = atoi(args[3]); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 2415 | err = parse_time_err(args[5], &val, TIME_UNIT_MS); |
| 2416 | if (err) { |
| 2417 | Alert("parsing [%s:%d] : unexpected character '%c' in %s timeout.\n", |
| 2418 | file, linenum, *err, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2419 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2420 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 2421 | } |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 2422 | curproxy->timeout.appsession = val; |
Willy Tarreau | ee99136 | 2007-05-14 14:37:50 +0200 | [diff] [blame] | 2423 | |
Willy Tarreau | 51041c7 | 2007-09-09 21:56:53 +0200 | [diff] [blame] | 2424 | if (appsession_hash_init(&(curproxy->htbl_proxy), destroy) == 0) { |
| 2425 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2426 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2427 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2428 | } |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2429 | |
| 2430 | cur_arg = 6; |
| 2431 | curproxy->options2 &= ~PR_O2_AS_REQL; |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2432 | curproxy->options2 &= ~PR_O2_AS_M_ANY; |
| 2433 | curproxy->options2 |= PR_O2_AS_M_PP; |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2434 | while (*(args[cur_arg])) { |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2435 | if (!strcmp(args[cur_arg], "request-learn")) { |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2436 | curproxy->options2 |= PR_O2_AS_REQL; |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2437 | } else if (!strcmp(args[cur_arg], "prefix")) { |
| 2438 | curproxy->options2 |= PR_O2_AS_PFX; |
| 2439 | } else if (!strcmp(args[cur_arg], "mode")) { |
| 2440 | if (!*args[cur_arg + 1]) { |
| 2441 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 2442 | file, linenum, args[0], args[cur_arg]); |
| 2443 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2444 | goto out; |
| 2445 | } |
| 2446 | |
| 2447 | cur_arg++; |
| 2448 | if (!strcmp(args[cur_arg], "query-string")) { |
| 2449 | curproxy->options2 &= ~PR_O2_AS_M_ANY; |
| 2450 | curproxy->options2 |= PR_O2_AS_M_QS; |
| 2451 | } else if (!strcmp(args[cur_arg], "path-parameters")) { |
| 2452 | curproxy->options2 &= ~PR_O2_AS_M_ANY; |
| 2453 | curproxy->options2 |= PR_O2_AS_M_PP; |
| 2454 | } else { |
| 2455 | Alert("parsing [%s:%d] : unknown mode '%s'\n", file, linenum, args[cur_arg]); |
| 2456 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2457 | goto out; |
| 2458 | } |
| 2459 | } |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2460 | cur_arg++; |
| 2461 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2462 | } /* Url App Session */ |
| 2463 | else if (!strcmp(args[0], "capture")) { |
Willy Tarreau | 3b6b1a9 | 2009-07-23 13:24:23 +0200 | [diff] [blame] | 2464 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2465 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2466 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2467 | if (!strcmp(args[1], "cookie")) { /* name of a cookie to capture */ |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 2468 | if (curproxy == &defproxy) { |
| 2469 | Alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
| 2470 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2471 | goto out; |
| 2472 | } |
| 2473 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2474 | if (*(args[4]) == 0) { |
| 2475 | Alert("parsing [%s:%d] : '%s' expects 'cookie' <cookie_name> 'len' <len>.\n", |
| 2476 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2477 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2478 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2479 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2480 | free(curproxy->capture_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2481 | curproxy->capture_name = strdup(args[2]); |
| 2482 | curproxy->capture_namelen = strlen(curproxy->capture_name); |
| 2483 | curproxy->capture_len = atol(args[4]); |
| 2484 | if (curproxy->capture_len >= CAPTURE_LEN) { |
| 2485 | Warning("parsing [%s:%d] : truncating capture length to %d bytes.\n", |
| 2486 | file, linenum, CAPTURE_LEN - 1); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2487 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2488 | curproxy->capture_len = CAPTURE_LEN - 1; |
| 2489 | } |
| 2490 | curproxy->to_log |= LW_COOKIE; |
| 2491 | } |
| 2492 | else if (!strcmp(args[1], "request") && !strcmp(args[2], "header")) { |
| 2493 | struct cap_hdr *hdr; |
| 2494 | |
| 2495 | if (curproxy == &defproxy) { |
| 2496 | 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] | 2497 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2498 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2499 | } |
| 2500 | |
| 2501 | if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) { |
| 2502 | Alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n", |
| 2503 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2504 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2505 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2506 | } |
| 2507 | |
| 2508 | hdr = calloc(sizeof(struct cap_hdr), 1); |
| 2509 | hdr->next = curproxy->req_cap; |
| 2510 | hdr->name = strdup(args[3]); |
| 2511 | hdr->namelen = strlen(args[3]); |
| 2512 | hdr->len = atol(args[5]); |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 2513 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2514 | hdr->index = curproxy->nb_req_cap++; |
| 2515 | curproxy->req_cap = hdr; |
| 2516 | curproxy->to_log |= LW_REQHDR; |
| 2517 | } |
| 2518 | else if (!strcmp(args[1], "response") && !strcmp(args[2], "header")) { |
| 2519 | struct cap_hdr *hdr; |
| 2520 | |
| 2521 | if (curproxy == &defproxy) { |
| 2522 | 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] | 2523 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2524 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2525 | } |
| 2526 | |
| 2527 | if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) { |
| 2528 | Alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n", |
| 2529 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2530 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2531 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2532 | } |
| 2533 | hdr = calloc(sizeof(struct cap_hdr), 1); |
| 2534 | hdr->next = curproxy->rsp_cap; |
| 2535 | hdr->name = strdup(args[3]); |
| 2536 | hdr->namelen = strlen(args[3]); |
| 2537 | hdr->len = atol(args[5]); |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 2538 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2539 | hdr->index = curproxy->nb_rsp_cap++; |
| 2540 | curproxy->rsp_cap = hdr; |
| 2541 | curproxy->to_log |= LW_RSPHDR; |
| 2542 | } |
| 2543 | else { |
| 2544 | Alert("parsing [%s:%d] : '%s' expects 'cookie' or 'request header' or 'response header'.\n", |
| 2545 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2546 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2547 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2548 | } |
| 2549 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2550 | else if (!strcmp(args[0], "retries")) { /* connection retries */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2551 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2552 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2553 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2554 | if (*(args[1]) == 0) { |
| 2555 | Alert("parsing [%s:%d] : '%s' expects an integer argument (dispatch counts for one).\n", |
| 2556 | file, linenum, args[0]); |
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 | curproxy->conn_retries = atol(args[1]); |
| 2561 | } |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2562 | 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] | 2563 | struct http_req_rule *rule; |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2564 | |
| 2565 | if (curproxy == &defproxy) { |
| 2566 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2567 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2568 | goto out; |
| 2569 | } |
| 2570 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 2571 | if (!LIST_ISEMPTY(&curproxy->http_req_rules) && !LIST_PREV(&curproxy->http_req_rules, struct http_req_rule *, list)->cond) { |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2572 | Warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n", |
| 2573 | file, linenum, args[0]); |
| 2574 | err_code |= ERR_WARN; |
| 2575 | } |
| 2576 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 2577 | 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] | 2578 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 2579 | if (!rule) { |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2580 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2581 | goto out; |
| 2582 | } |
| 2583 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 2584 | err_code |= warnif_cond_requires_resp(rule->cond, file, linenum); |
| 2585 | LIST_ADDQ(&curproxy->http_req_rules, &rule->list); |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2586 | } |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 2587 | else if (!strcmp(args[0], "http-send-name-header")) { /* send server name in request header */ |
| 2588 | /* set the header name and length into the proxy structure */ |
| 2589 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 2590 | err_code |= ERR_WARN; |
| 2591 | |
| 2592 | if (!*args[1]) { |
| 2593 | Alert("parsing [%s:%d] : '%s' requires a header string.\n", |
| 2594 | file, linenum, args[0]); |
| 2595 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2596 | goto out; |
| 2597 | } |
| 2598 | |
| 2599 | /* set the desired header name */ |
| 2600 | free(curproxy->server_id_hdr_name); |
| 2601 | curproxy->server_id_hdr_name = strdup(args[1]); |
| 2602 | curproxy->server_id_hdr_len = strlen(curproxy->server_id_hdr_name); |
| 2603 | } |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2604 | else if (!strcmp(args[0], "block")) { /* early blocking based on ACLs */ |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2605 | if (curproxy == &defproxy) { |
| 2606 | 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] | 2607 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2608 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2609 | } |
| 2610 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2611 | if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) { |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2612 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 2613 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2614 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2615 | goto out; |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2616 | } |
| 2617 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 2618 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 1, &errmsg)) == NULL) { |
| 2619 | Alert("parsing [%s:%d] : error detected while parsing blocking condition : %s.\n", |
| 2620 | file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2621 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2622 | goto out; |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2623 | } |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2624 | |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2625 | LIST_ADDQ(&curproxy->block_cond, &cond->list); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 2626 | warnif_misplaced_block(curproxy, file, linenum, args[0]); |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2627 | } |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2628 | else if (!strcmp(args[0], "redirect")) { |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2629 | struct redirect_rule *rule; |
| 2630 | int cur_arg; |
| 2631 | int type = REDIRECT_TYPE_NONE; |
| 2632 | int code = 302; |
| 2633 | char *destination = NULL; |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2634 | char *cookie = NULL; |
| 2635 | int cookie_set = 0; |
Willy Tarreau | 79da469 | 2008-11-19 20:03:04 +0100 | [diff] [blame] | 2636 | unsigned int flags = REDIRECT_FLAG_NONE; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2637 | |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 2638 | if (curproxy == &defproxy) { |
| 2639 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2640 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2641 | goto out; |
| 2642 | } |
| 2643 | |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2644 | cur_arg = 1; |
| 2645 | while (*(args[cur_arg])) { |
| 2646 | if (!strcmp(args[cur_arg], "location")) { |
| 2647 | if (!*args[cur_arg + 1]) { |
| 2648 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 2649 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2650 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2651 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2652 | } |
| 2653 | |
| 2654 | type = REDIRECT_TYPE_LOCATION; |
| 2655 | cur_arg++; |
| 2656 | destination = args[cur_arg]; |
| 2657 | } |
| 2658 | else if (!strcmp(args[cur_arg], "prefix")) { |
| 2659 | if (!*args[cur_arg + 1]) { |
| 2660 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 2661 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2662 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2663 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2664 | } |
| 2665 | |
| 2666 | type = REDIRECT_TYPE_PREFIX; |
| 2667 | cur_arg++; |
| 2668 | destination = args[cur_arg]; |
| 2669 | } |
Willy Tarreau | 2e1dca8 | 2012-09-12 08:43:15 +0200 | [diff] [blame] | 2670 | else if (!strcmp(args[cur_arg], "scheme")) { |
| 2671 | if (!*args[cur_arg + 1]) { |
| 2672 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 2673 | file, linenum, args[0], args[cur_arg]); |
| 2674 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2675 | goto out; |
| 2676 | } |
| 2677 | |
| 2678 | type = REDIRECT_TYPE_SCHEME; |
| 2679 | cur_arg++; |
| 2680 | destination = args[cur_arg]; |
| 2681 | } |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2682 | else if (!strcmp(args[cur_arg], "set-cookie")) { |
| 2683 | if (!*args[cur_arg + 1]) { |
| 2684 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 2685 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2686 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2687 | goto out; |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2688 | } |
| 2689 | |
| 2690 | cur_arg++; |
| 2691 | cookie = args[cur_arg]; |
| 2692 | cookie_set = 1; |
| 2693 | } |
| 2694 | else if (!strcmp(args[cur_arg], "clear-cookie")) { |
| 2695 | if (!*args[cur_arg + 1]) { |
| 2696 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 2697 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2698 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2699 | goto out; |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2700 | } |
| 2701 | |
| 2702 | cur_arg++; |
| 2703 | cookie = args[cur_arg]; |
| 2704 | cookie_set = 0; |
| 2705 | } |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2706 | else if (!strcmp(args[cur_arg],"code")) { |
| 2707 | if (!*args[cur_arg + 1]) { |
| 2708 | Alert("parsing [%s:%d] : '%s': missing HTTP code.\n", |
| 2709 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2710 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2711 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2712 | } |
| 2713 | cur_arg++; |
| 2714 | code = atol(args[cur_arg]); |
| 2715 | if (code < 301 || code > 303) { |
| 2716 | Alert("parsing [%s:%d] : '%s': unsupported HTTP code '%d'.\n", |
| 2717 | file, linenum, args[0], code); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2718 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2719 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2720 | } |
| 2721 | } |
Willy Tarreau | 79da469 | 2008-11-19 20:03:04 +0100 | [diff] [blame] | 2722 | else if (!strcmp(args[cur_arg],"drop-query")) { |
| 2723 | flags |= REDIRECT_FLAG_DROP_QS; |
| 2724 | } |
Willy Tarreau | 81e3b4f | 2010-01-10 00:42:19 +0100 | [diff] [blame] | 2725 | else if (!strcmp(args[cur_arg],"append-slash")) { |
| 2726 | flags |= REDIRECT_FLAG_APPEND_SLASH; |
| 2727 | } |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2728 | else if (strcmp(args[cur_arg], "if") == 0 || |
| 2729 | strcmp(args[cur_arg], "unless") == 0) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 2730 | cond = build_acl_cond(file, linenum, curproxy, (const char **)args + cur_arg, &errmsg); |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2731 | if (!cond) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 2732 | Alert("parsing [%s:%d] : '%s': error detected while parsing redirect condition : %s.\n", |
| 2733 | file, linenum, args[0], errmsg); |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2734 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2735 | goto out; |
| 2736 | } |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2737 | break; |
| 2738 | } |
| 2739 | else { |
Willy Tarreau | 2e1dca8 | 2012-09-12 08:43:15 +0200 | [diff] [blame] | 2740 | Alert("parsing [%s:%d] : '%s' expects 'code', 'prefix', 'location', 'scheme', 'set-cookie', 'clear-cookie', 'drop-query' or 'append-slash' (was '%s').\n", |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2741 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2742 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2743 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2744 | } |
| 2745 | cur_arg++; |
| 2746 | } |
| 2747 | |
| 2748 | if (type == REDIRECT_TYPE_NONE) { |
| 2749 | Alert("parsing [%s:%d] : '%s' expects a redirection type ('prefix' or 'location').\n", |
| 2750 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2751 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2752 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2753 | } |
| 2754 | |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2755 | rule = (struct redirect_rule *)calloc(1, sizeof(*rule)); |
| 2756 | rule->cond = cond; |
| 2757 | rule->rdr_str = strdup(destination); |
| 2758 | rule->rdr_len = strlen(destination); |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2759 | if (cookie) { |
| 2760 | /* depending on cookie_set, either we want to set the cookie, or to clear it. |
William Turner | d986526 | 2010-03-01 13:30:34 -0500 | [diff] [blame] | 2761 | * a clear consists in appending "; path=/; Max-Age=0;" at the end. |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2762 | */ |
| 2763 | rule->cookie_len = strlen(cookie); |
William Turner | d986526 | 2010-03-01 13:30:34 -0500 | [diff] [blame] | 2764 | if (cookie_set) { |
| 2765 | rule->cookie_str = malloc(rule->cookie_len + 10); |
| 2766 | memcpy(rule->cookie_str, cookie, rule->cookie_len); |
| 2767 | memcpy(rule->cookie_str + rule->cookie_len, "; path=/;", 10); |
| 2768 | rule->cookie_len += 9; |
| 2769 | } else { |
| 2770 | rule->cookie_str = malloc(rule->cookie_len + 21); |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2771 | memcpy(rule->cookie_str, cookie, rule->cookie_len); |
William Turner | d986526 | 2010-03-01 13:30:34 -0500 | [diff] [blame] | 2772 | memcpy(rule->cookie_str + rule->cookie_len, "; path=/; Max-Age=0;", 21); |
| 2773 | rule->cookie_len += 20; |
Willy Tarreau | 0140f25 | 2008-11-19 21:07:09 +0100 | [diff] [blame] | 2774 | } |
| 2775 | } |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2776 | rule->type = type; |
| 2777 | rule->code = code; |
Willy Tarreau | 79da469 | 2008-11-19 20:03:04 +0100 | [diff] [blame] | 2778 | rule->flags = flags; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2779 | LIST_INIT(&rule->list); |
| 2780 | LIST_ADDQ(&curproxy->redirect_rules, &rule->list); |
Willy Tarreau | 9d9ed01 | 2011-02-23 15:24:42 +0100 | [diff] [blame] | 2781 | err_code |= warnif_rule_after_use_backend(curproxy, file, linenum, args[0]); |
| 2782 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2783 | } |
Krzysztof Piotr Oledzki | 7b723ef | 2009-01-27 21:09:41 +0100 | [diff] [blame] | 2784 | else if (!strcmp(args[0], "use_backend")) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2785 | struct switching_rule *rule; |
| 2786 | |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2787 | if (curproxy == &defproxy) { |
| 2788 | 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] | 2789 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2790 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2791 | } |
| 2792 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2793 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2794 | err_code |= ERR_WARN; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2795 | |
| 2796 | if (*(args[1]) == 0) { |
| 2797 | 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] | 2798 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2799 | goto out; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2800 | } |
| 2801 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2802 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2803 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 2804 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2805 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2806 | goto out; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2807 | } |
| 2808 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 2809 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 2810 | Alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n", |
| 2811 | file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2812 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2813 | goto out; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2814 | } |
| 2815 | |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 2816 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
Willy Tarreau | a980263 | 2008-07-25 19:13:19 +0200 | [diff] [blame] | 2817 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2818 | rule = (struct switching_rule *)calloc(1, sizeof(*rule)); |
| 2819 | rule->cond = cond; |
| 2820 | rule->be.name = strdup(args[1]); |
| 2821 | LIST_INIT(&rule->list); |
| 2822 | LIST_ADDQ(&curproxy->switching_rules, &rule->list); |
| 2823 | } |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 2824 | else if (strcmp(args[0], "use-server") == 0) { |
| 2825 | struct server_rule *rule; |
| 2826 | |
| 2827 | if (curproxy == &defproxy) { |
| 2828 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2829 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2830 | goto out; |
| 2831 | } |
| 2832 | |
| 2833 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 2834 | err_code |= ERR_WARN; |
| 2835 | |
| 2836 | if (*(args[1]) == 0) { |
| 2837 | Alert("parsing [%s:%d] : '%s' expects a server name.\n", file, linenum, args[0]); |
| 2838 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2839 | goto out; |
| 2840 | } |
| 2841 | |
| 2842 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
| 2843 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 2844 | file, linenum, args[0]); |
| 2845 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2846 | goto out; |
| 2847 | } |
| 2848 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 2849 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 2850 | Alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n", |
| 2851 | file, linenum, errmsg); |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 2852 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2853 | goto out; |
| 2854 | } |
| 2855 | |
| 2856 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
| 2857 | |
| 2858 | rule = (struct server_rule *)calloc(1, sizeof(*rule)); |
| 2859 | rule->cond = cond; |
| 2860 | rule->srv.name = strdup(args[1]); |
| 2861 | LIST_INIT(&rule->list); |
| 2862 | LIST_ADDQ(&curproxy->server_rules, &rule->list); |
| 2863 | curproxy->be_req_ana |= AN_REQ_SRV_RULES; |
| 2864 | } |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 2865 | else if ((!strcmp(args[0], "force-persist")) || |
| 2866 | (!strcmp(args[0], "ignore-persist"))) { |
| 2867 | struct persist_rule *rule; |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2868 | |
| 2869 | if (curproxy == &defproxy) { |
| 2870 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2871 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2872 | goto out; |
| 2873 | } |
| 2874 | |
| 2875 | if (warnifnotcap(curproxy, PR_CAP_FE|PR_CAP_BE, file, linenum, args[0], NULL)) |
| 2876 | err_code |= ERR_WARN; |
| 2877 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2878 | if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) { |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2879 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 2880 | file, linenum, args[0]); |
| 2881 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2882 | goto out; |
| 2883 | } |
| 2884 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 2885 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 1, &errmsg)) == NULL) { |
| 2886 | Alert("parsing [%s:%d] : error detected while parsing a '%s' rule : %s.\n", |
| 2887 | file, linenum, args[0], errmsg); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2888 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2889 | goto out; |
| 2890 | } |
| 2891 | |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 2892 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2893 | |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 2894 | rule = (struct persist_rule *)calloc(1, sizeof(*rule)); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2895 | rule->cond = cond; |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 2896 | if (!strcmp(args[0], "force-persist")) { |
| 2897 | rule->type = PERSIST_TYPE_FORCE; |
| 2898 | } else { |
| 2899 | rule->type = PERSIST_TYPE_IGNORE; |
| 2900 | } |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2901 | LIST_INIT(&rule->list); |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 2902 | LIST_ADDQ(&curproxy->persist_rules, &rule->list); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2903 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2904 | else if (!strcmp(args[0], "stick-table")) { |
| 2905 | int myidx = 1; |
| 2906 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2907 | curproxy->table.id = curproxy->id; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2908 | curproxy->table.type = (unsigned int)-1; |
| 2909 | while (*args[myidx]) { |
| 2910 | const char *err; |
| 2911 | |
| 2912 | if (strcmp(args[myidx], "size") == 0) { |
| 2913 | myidx++; |
| 2914 | if (!*(args[myidx])) { |
| 2915 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 2916 | file, linenum, args[myidx-1]); |
| 2917 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2918 | goto out; |
| 2919 | } |
| 2920 | if ((err = parse_size_err(args[myidx], &curproxy->table.size))) { |
| 2921 | Alert("parsing [%s:%d] : stick-table: unexpected character '%c' in argument of '%s'.\n", |
| 2922 | file, linenum, *err, args[myidx-1]); |
| 2923 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2924 | goto out; |
| 2925 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 2926 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2927 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2928 | else if (strcmp(args[myidx], "peers") == 0) { |
| 2929 | myidx++; |
| 2930 | if (!*(args[myidx])) { |
| 2931 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 2932 | file, linenum, args[myidx-1]); |
| 2933 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2934 | goto out; |
| 2935 | } |
| 2936 | curproxy->table.peers.name = strdup(args[myidx++]); |
| 2937 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2938 | else if (strcmp(args[myidx], "expire") == 0) { |
| 2939 | myidx++; |
| 2940 | if (!*(args[myidx])) { |
| 2941 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 2942 | file, linenum, args[myidx-1]); |
| 2943 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2944 | goto out; |
| 2945 | } |
| 2946 | err = parse_time_err(args[myidx], &val, TIME_UNIT_MS); |
| 2947 | if (err) { |
| 2948 | Alert("parsing [%s:%d] : stick-table: unexpected character '%c' in argument of '%s'.\n", |
| 2949 | file, linenum, *err, args[myidx-1]); |
| 2950 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2951 | goto out; |
| 2952 | } |
| 2953 | curproxy->table.expire = val; |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 2954 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2955 | } |
| 2956 | else if (strcmp(args[myidx], "nopurge") == 0) { |
| 2957 | curproxy->table.nopurge = 1; |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 2958 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2959 | } |
| 2960 | else if (strcmp(args[myidx], "type") == 0) { |
| 2961 | myidx++; |
| 2962 | if (stktable_parse_type(args, &myidx, &curproxy->table.type, &curproxy->table.key_size) != 0) { |
| 2963 | Alert("parsing [%s:%d] : stick-table: unknown type '%s'.\n", |
| 2964 | file, linenum, args[myidx]); |
| 2965 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2966 | goto out; |
| 2967 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 2968 | /* myidx already points to next arg */ |
| 2969 | } |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 2970 | else if (strcmp(args[myidx], "store") == 0) { |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 2971 | int type, err; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 2972 | char *cw, *nw, *sa; |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 2973 | |
| 2974 | myidx++; |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 2975 | nw = args[myidx]; |
| 2976 | while (*nw) { |
| 2977 | /* the "store" keyword supports a comma-separated list */ |
| 2978 | cw = nw; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 2979 | sa = NULL; /* store arg */ |
| 2980 | while (*nw && *nw != ',') { |
| 2981 | if (*nw == '(') { |
| 2982 | *nw = 0; |
| 2983 | sa = ++nw; |
| 2984 | while (*nw != ')') { |
| 2985 | if (!*nw) { |
| 2986 | Alert("parsing [%s:%d] : %s: missing closing parenthesis after store option '%s'.\n", |
| 2987 | file, linenum, args[0], cw); |
| 2988 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2989 | goto out; |
| 2990 | } |
| 2991 | nw++; |
| 2992 | } |
| 2993 | *nw = '\0'; |
| 2994 | } |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 2995 | nw++; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 2996 | } |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 2997 | if (*nw) |
| 2998 | *nw++ = '\0'; |
| 2999 | type = stktable_get_data_type(cw); |
| 3000 | if (type < 0) { |
| 3001 | Alert("parsing [%s:%d] : %s: unknown store option '%s'.\n", |
| 3002 | file, linenum, args[0], cw); |
| 3003 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3004 | goto out; |
| 3005 | } |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 3006 | |
| 3007 | err = stktable_alloc_data_type(&curproxy->table, type, sa); |
| 3008 | switch (err) { |
| 3009 | case PE_NONE: break; |
| 3010 | case PE_EXIST: |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 3011 | Warning("parsing [%s:%d]: %s: store option '%s' already enabled, ignored.\n", |
| 3012 | file, linenum, args[0], cw); |
| 3013 | err_code |= ERR_WARN; |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 3014 | break; |
| 3015 | |
| 3016 | case PE_ARG_MISSING: |
| 3017 | Alert("parsing [%s:%d] : %s: missing argument to store option '%s'.\n", |
| 3018 | file, linenum, args[0], cw); |
| 3019 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3020 | goto out; |
| 3021 | |
| 3022 | case PE_ARG_NOT_USED: |
| 3023 | Alert("parsing [%s:%d] : %s: unexpected argument to store option '%s'.\n", |
| 3024 | file, linenum, args[0], cw); |
| 3025 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3026 | goto out; |
| 3027 | |
| 3028 | default: |
| 3029 | Alert("parsing [%s:%d] : %s: error when processing store option '%s'.\n", |
| 3030 | file, linenum, args[0], cw); |
| 3031 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3032 | goto out; |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 3033 | } |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 3034 | } |
| 3035 | myidx++; |
| 3036 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 3037 | else { |
| 3038 | Alert("parsing [%s:%d] : stick-table: unknown argument '%s'.\n", |
| 3039 | file, linenum, args[myidx]); |
| 3040 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3041 | goto out; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3042 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3043 | } |
| 3044 | |
| 3045 | if (!curproxy->table.size) { |
| 3046 | Alert("parsing [%s:%d] : stick-table: missing size.\n", |
| 3047 | file, linenum); |
| 3048 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3049 | goto out; |
| 3050 | } |
| 3051 | |
| 3052 | if (curproxy->table.type == (unsigned int)-1) { |
| 3053 | Alert("parsing [%s:%d] : stick-table: missing type.\n", |
| 3054 | file, linenum); |
| 3055 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3056 | goto out; |
| 3057 | } |
| 3058 | } |
| 3059 | else if (!strcmp(args[0], "stick")) { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3060 | struct sticking_rule *rule; |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 3061 | struct sample_expr *expr; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3062 | int myidx = 0; |
| 3063 | const char *name = NULL; |
| 3064 | int flags; |
| 3065 | |
| 3066 | if (curproxy == &defproxy) { |
| 3067 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3068 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3069 | goto out; |
| 3070 | } |
| 3071 | |
| 3072 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) { |
| 3073 | err_code |= ERR_WARN; |
| 3074 | goto out; |
| 3075 | } |
| 3076 | |
| 3077 | myidx++; |
| 3078 | if ((strcmp(args[myidx], "store") == 0) || |
| 3079 | (strcmp(args[myidx], "store-request") == 0)) { |
| 3080 | myidx++; |
| 3081 | flags = STK_IS_STORE; |
| 3082 | } |
| 3083 | else if (strcmp(args[myidx], "store-response") == 0) { |
| 3084 | myidx++; |
| 3085 | flags = STK_IS_STORE | STK_ON_RSP; |
| 3086 | } |
| 3087 | else if (strcmp(args[myidx], "match") == 0) { |
| 3088 | myidx++; |
| 3089 | flags = STK_IS_MATCH; |
| 3090 | } |
| 3091 | else if (strcmp(args[myidx], "on") == 0) { |
| 3092 | myidx++; |
| 3093 | flags = STK_IS_MATCH | STK_IS_STORE; |
| 3094 | } |
| 3095 | else { |
| 3096 | Alert("parsing [%s:%d] : '%s' expects 'on', 'match', or 'store'.\n", file, linenum, args[0]); |
| 3097 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3098 | goto out; |
| 3099 | } |
| 3100 | |
| 3101 | if (*(args[myidx]) == 0) { |
| 3102 | Alert("parsing [%s:%d] : '%s' expects a fetch method.\n", file, linenum, args[0]); |
| 3103 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3104 | goto out; |
| 3105 | } |
| 3106 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3107 | expr = sample_parse_expr(args, &myidx, trash.str, trash.size); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3108 | if (!expr) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3109 | 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] | 3110 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3111 | goto out; |
| 3112 | } |
| 3113 | |
| 3114 | if (flags & STK_ON_RSP) { |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 3115 | if (!(expr->fetch->cap & SMP_CAP_RES)) { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3116 | Alert("parsing [%s:%d] : '%s': fetch method '%s' can not be used on response.\n", |
| 3117 | file, linenum, args[0], expr->fetch->kw); |
| 3118 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 3119 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3120 | goto out; |
| 3121 | } |
| 3122 | } else { |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 3123 | if (!(expr->fetch->cap & SMP_CAP_REQ)) { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3124 | Alert("parsing [%s:%d] : '%s': fetch method '%s' can not be used on request.\n", |
| 3125 | file, linenum, args[0], expr->fetch->kw); |
| 3126 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 3127 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3128 | goto out; |
| 3129 | } |
| 3130 | } |
| 3131 | |
Willy Tarreau | 1b6c00c | 2012-10-05 22:41:26 +0200 | [diff] [blame] | 3132 | /* check if we need to allocate an hdr_idx struct for HTTP parsing */ |
| 3133 | if (expr->fetch->cap & SMP_CAP_L7) |
| 3134 | curproxy->acl_requires |= ACL_USE_L7_ANY; |
| 3135 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3136 | if (strcmp(args[myidx], "table") == 0) { |
| 3137 | myidx++; |
| 3138 | name = args[myidx++]; |
| 3139 | } |
| 3140 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 3141 | if (strcmp(args[myidx], "if") == 0 || strcmp(args[myidx], "unless") == 0) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 3142 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + myidx, &errmsg)) == NULL) { |
| 3143 | Alert("parsing [%s:%d] : '%s': error detected while parsing sticking condition : %s.\n", |
| 3144 | file, linenum, args[0], errmsg); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3145 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 3146 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3147 | goto out; |
| 3148 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3149 | } |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 3150 | else if (*(args[myidx])) { |
| 3151 | Alert("parsing [%s:%d] : '%s': unknown keyword '%s'.\n", |
| 3152 | file, linenum, args[0], args[myidx]); |
| 3153 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 3154 | free(expr); |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 3155 | goto out; |
| 3156 | } |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 3157 | if (flags & STK_ON_RSP) |
| 3158 | err_code |= warnif_cond_requires_req(cond, file, linenum); |
| 3159 | else |
| 3160 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 3161 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3162 | rule = (struct sticking_rule *)calloc(1, sizeof(*rule)); |
| 3163 | rule->cond = cond; |
| 3164 | rule->expr = expr; |
| 3165 | rule->flags = flags; |
| 3166 | rule->table.name = name ? strdup(name) : NULL; |
| 3167 | LIST_INIT(&rule->list); |
| 3168 | if (flags & STK_ON_RSP) |
| 3169 | LIST_ADDQ(&curproxy->storersp_rules, &rule->list); |
| 3170 | else |
| 3171 | LIST_ADDQ(&curproxy->sticking_rules, &rule->list); |
| 3172 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3173 | else if (!strcmp(args[0], "stats")) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3174 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3175 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3176 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3177 | if (curproxy != &defproxy && curproxy->uri_auth == defproxy.uri_auth) |
| 3178 | curproxy->uri_auth = NULL; /* we must detach from the default config */ |
| 3179 | |
Krzysztof Piotr Oledzki | 260a3bb | 2010-01-06 16:25:05 +0100 | [diff] [blame] | 3180 | if (!*args[1]) { |
| 3181 | goto stats_error_parsing; |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3182 | } else if (!strcmp(args[1], "admin")) { |
| 3183 | struct stats_admin_rule *rule; |
| 3184 | |
| 3185 | if (curproxy == &defproxy) { |
| 3186 | Alert("parsing [%s:%d]: '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
| 3187 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3188 | goto out; |
| 3189 | } |
| 3190 | |
| 3191 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 3192 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3193 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3194 | goto out; |
| 3195 | } |
| 3196 | |
| 3197 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
| 3198 | Alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n", |
| 3199 | file, linenum, args[0], args[1]); |
| 3200 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3201 | goto out; |
| 3202 | } |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 3203 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 3204 | Alert("parsing [%s:%d] : error detected while parsing a '%s %s' rule : %s.\n", |
| 3205 | file, linenum, args[0], args[1], errmsg); |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3206 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3207 | goto out; |
| 3208 | } |
| 3209 | |
| 3210 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
| 3211 | |
| 3212 | rule = (struct stats_admin_rule *)calloc(1, sizeof(*rule)); |
| 3213 | rule->cond = cond; |
| 3214 | LIST_INIT(&rule->list); |
| 3215 | LIST_ADDQ(&curproxy->uri_auth->admin_rules, &rule->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3216 | } else if (!strcmp(args[1], "uri")) { |
| 3217 | if (*(args[2]) == 0) { |
| 3218 | Alert("parsing [%s:%d] : 'uri' needs an URI prefix.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3219 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3220 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3221 | } else if (!stats_set_uri(&curproxy->uri_auth, args[2])) { |
| 3222 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3223 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3224 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3225 | } |
| 3226 | } else if (!strcmp(args[1], "realm")) { |
| 3227 | if (*(args[2]) == 0) { |
| 3228 | Alert("parsing [%s:%d] : 'realm' needs an realm name.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3229 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3230 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3231 | } else if (!stats_set_realm(&curproxy->uri_auth, args[2])) { |
| 3232 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3233 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3234 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3235 | } |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 3236 | } else if (!strcmp(args[1], "refresh")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 3237 | unsigned interval; |
| 3238 | |
| 3239 | err = parse_time_err(args[2], &interval, TIME_UNIT_S); |
| 3240 | if (err) { |
| 3241 | Alert("parsing [%s:%d] : unexpected character '%c' in stats refresh interval.\n", |
| 3242 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3243 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3244 | goto out; |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 3245 | } else if (!stats_set_refresh(&curproxy->uri_auth, interval)) { |
| 3246 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3247 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3248 | goto out; |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 3249 | } |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3250 | } 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] | 3251 | struct http_req_rule *rule; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3252 | |
| 3253 | if (curproxy == &defproxy) { |
| 3254 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3255 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3256 | goto out; |
| 3257 | } |
| 3258 | |
| 3259 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 3260 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3261 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3262 | goto out; |
| 3263 | } |
| 3264 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3265 | if (!LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) && |
| 3266 | !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] | 3267 | Warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n", |
| 3268 | file, linenum, args[0]); |
| 3269 | err_code |= ERR_WARN; |
| 3270 | } |
| 3271 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3272 | 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] | 3273 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3274 | if (!rule) { |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3275 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3276 | goto out; |
| 3277 | } |
| 3278 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3279 | err_code |= warnif_cond_requires_resp(rule->cond, file, linenum); |
| 3280 | LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list); |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3281 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3282 | } else if (!strcmp(args[1], "auth")) { |
| 3283 | if (*(args[2]) == 0) { |
| 3284 | 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] | 3285 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3286 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3287 | } else if (!stats_add_auth(&curproxy->uri_auth, args[2])) { |
| 3288 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3289 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3290 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3291 | } |
| 3292 | } else if (!strcmp(args[1], "scope")) { |
| 3293 | if (*(args[2]) == 0) { |
| 3294 | Alert("parsing [%s:%d] : 'scope' needs a proxy name.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3295 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3296 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3297 | } else if (!stats_add_scope(&curproxy->uri_auth, args[2])) { |
| 3298 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3299 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3300 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3301 | } |
| 3302 | } else if (!strcmp(args[1], "enable")) { |
| 3303 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 3304 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3305 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3306 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3307 | } |
Krzysztof Oledzki | d9db927 | 2007-10-15 10:05:11 +0200 | [diff] [blame] | 3308 | } else if (!strcmp(args[1], "hide-version")) { |
| 3309 | if (!stats_set_flag(&curproxy->uri_auth, ST_HIDEVER)) { |
| 3310 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3311 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3312 | goto out; |
Krzysztof Oledzki | d9db927 | 2007-10-15 10:05:11 +0200 | [diff] [blame] | 3313 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3314 | } else if (!strcmp(args[1], "show-legends")) { |
| 3315 | if (!stats_set_flag(&curproxy->uri_auth, ST_SHLGNDS)) { |
| 3316 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3317 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3318 | goto out; |
| 3319 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3320 | } else if (!strcmp(args[1], "show-node")) { |
| 3321 | |
| 3322 | if (*args[2]) { |
| 3323 | int i; |
| 3324 | char c; |
| 3325 | |
| 3326 | for (i=0; args[2][i]; i++) { |
| 3327 | c = args[2][i]; |
Willy Tarreau | 88e0581 | 2010-03-03 00:16:00 +0100 | [diff] [blame] | 3328 | if (!isupper((unsigned char)c) && !islower((unsigned char)c) && |
| 3329 | !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.') |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3330 | break; |
| 3331 | } |
| 3332 | |
| 3333 | if (!i || args[2][i]) { |
| 3334 | Alert("parsing [%s:%d]: '%s %s' invalid node name - should be a string" |
| 3335 | "with digits(0-9), letters(A-Z, a-z), hyphen(-) or underscode(_).\n", |
| 3336 | file, linenum, args[0], args[1]); |
| 3337 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3338 | goto out; |
| 3339 | } |
| 3340 | } |
| 3341 | |
| 3342 | if (!stats_set_node(&curproxy->uri_auth, args[2])) { |
| 3343 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3344 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3345 | goto out; |
| 3346 | } |
| 3347 | } else if (!strcmp(args[1], "show-desc")) { |
| 3348 | char *desc = NULL; |
| 3349 | |
| 3350 | if (*args[2]) { |
| 3351 | int i, len=0; |
| 3352 | char *d; |
| 3353 | |
| 3354 | for(i=2; *args[i]; i++) |
| 3355 | len += strlen(args[i])+1; |
| 3356 | |
| 3357 | desc = d = (char *)calloc(1, len); |
| 3358 | |
| 3359 | d += sprintf(d, "%s", args[2]); |
| 3360 | for(i=3; *args[i]; i++) |
| 3361 | d += sprintf(d, " %s", args[i]); |
| 3362 | } |
| 3363 | |
| 3364 | if (!*args[2] && !global.desc) |
| 3365 | Warning("parsing [%s:%d]: '%s' requires a parameter or 'desc' to be set in the global section.\n", |
| 3366 | file, linenum, args[1]); |
| 3367 | else { |
| 3368 | if (!stats_set_desc(&curproxy->uri_auth, desc)) { |
| 3369 | free(desc); |
| 3370 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3371 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3372 | goto out; |
| 3373 | } |
| 3374 | free(desc); |
| 3375 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3376 | } else { |
Krzysztof Piotr Oledzki | 260a3bb | 2010-01-06 16:25:05 +0100 | [diff] [blame] | 3377 | stats_error_parsing: |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3378 | 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] | 3379 | 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] | 3380 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3381 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3382 | } |
| 3383 | } |
| 3384 | else if (!strcmp(args[0], "option")) { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3385 | int optnum; |
| 3386 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3387 | if (*(args[1]) == '\0') { |
| 3388 | Alert("parsing [%s:%d]: '%s' expects an option name.\n", |
| 3389 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3390 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3391 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3392 | } |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3393 | |
| 3394 | for (optnum = 0; cfg_opts[optnum].name; optnum++) { |
| 3395 | if (!strcmp(args[1], cfg_opts[optnum].name)) { |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 3396 | if (cfg_opts[optnum].cap == PR_CAP_NONE) { |
| 3397 | Alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n", |
| 3398 | file, linenum, cfg_opts[optnum].name); |
| 3399 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3400 | goto out; |
| 3401 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3402 | if (warnifnotcap(curproxy, cfg_opts[optnum].cap, file, linenum, args[1], NULL)) { |
| 3403 | err_code |= ERR_WARN; |
| 3404 | goto out; |
| 3405 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3406 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 3407 | curproxy->no_options &= ~cfg_opts[optnum].val; |
| 3408 | curproxy->options &= ~cfg_opts[optnum].val; |
| 3409 | |
| 3410 | switch (kwm) { |
| 3411 | case KWM_STD: |
| 3412 | curproxy->options |= cfg_opts[optnum].val; |
| 3413 | break; |
| 3414 | case KWM_NO: |
| 3415 | curproxy->no_options |= cfg_opts[optnum].val; |
| 3416 | break; |
| 3417 | case KWM_DEF: /* already cleared */ |
| 3418 | break; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 3419 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3420 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3421 | goto out; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3422 | } |
| 3423 | } |
| 3424 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 3425 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) { |
| 3426 | if (!strcmp(args[1], cfg_opts2[optnum].name)) { |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 3427 | if (cfg_opts2[optnum].cap == PR_CAP_NONE) { |
| 3428 | Alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n", |
| 3429 | file, linenum, cfg_opts2[optnum].name); |
| 3430 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3431 | goto out; |
| 3432 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3433 | if (warnifnotcap(curproxy, cfg_opts2[optnum].cap, file, linenum, args[1], NULL)) { |
| 3434 | err_code |= ERR_WARN; |
| 3435 | goto out; |
| 3436 | } |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 3437 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 3438 | curproxy->no_options2 &= ~cfg_opts2[optnum].val; |
| 3439 | curproxy->options2 &= ~cfg_opts2[optnum].val; |
| 3440 | |
| 3441 | switch (kwm) { |
| 3442 | case KWM_STD: |
| 3443 | curproxy->options2 |= cfg_opts2[optnum].val; |
| 3444 | break; |
| 3445 | case KWM_NO: |
| 3446 | curproxy->no_options2 |= cfg_opts2[optnum].val; |
| 3447 | break; |
| 3448 | case KWM_DEF: /* already cleared */ |
| 3449 | break; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 3450 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3451 | goto out; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 3452 | } |
| 3453 | } |
| 3454 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 3455 | if (kwm != KWM_STD) { |
| 3456 | 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] | 3457 | file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3458 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3459 | goto out; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3460 | } |
| 3461 | |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3462 | if (!strcmp(args[1], "httplog")) { |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 3463 | char *logformat; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3464 | /* generate a complete HTTP log */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 3465 | logformat = default_http_log_format; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3466 | if (*(args[2]) != '\0') { |
| 3467 | if (!strcmp(args[2], "clf")) { |
| 3468 | curproxy->options2 |= PR_O2_CLFLOG; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 3469 | logformat = clf_http_log_format; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3470 | } else { |
| 3471 | 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] | 3472 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3473 | goto out; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3474 | } |
| 3475 | } |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 3476 | if (curproxy->logformat_string != default_http_log_format && |
| 3477 | curproxy->logformat_string != default_tcp_log_format && |
| 3478 | curproxy->logformat_string != clf_http_log_format) |
| 3479 | free(curproxy->logformat_string); |
| 3480 | curproxy->logformat_string = logformat; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3481 | } |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 3482 | else if (!strcmp(args[1], "tcplog")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3483 | /* generate a detailed TCP log */ |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 3484 | if (curproxy->logformat_string != default_http_log_format && |
| 3485 | curproxy->logformat_string != default_tcp_log_format && |
| 3486 | curproxy->logformat_string != clf_http_log_format) |
| 3487 | free(curproxy->logformat_string); |
| 3488 | curproxy->logformat_string = default_tcp_log_format; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 3489 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3490 | else if (!strcmp(args[1], "tcpka")) { |
| 3491 | /* enable TCP keep-alives on client and server sessions */ |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3492 | 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] | 3493 | err_code |= ERR_WARN; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3494 | |
| 3495 | if (curproxy->cap & PR_CAP_FE) |
| 3496 | curproxy->options |= PR_O_TCP_CLI_KA; |
| 3497 | if (curproxy->cap & PR_CAP_BE) |
| 3498 | curproxy->options |= PR_O_TCP_SRV_KA; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3499 | } |
| 3500 | else if (!strcmp(args[1], "httpchk")) { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3501 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3502 | err_code |= ERR_WARN; |
| 3503 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3504 | /* use HTTP request to check servers' health */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3505 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 3506 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3507 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 3508 | curproxy->options2 |= PR_O2_HTTP_CHK; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3509 | if (!*args[2]) { /* no argument */ |
| 3510 | curproxy->check_req = strdup(DEF_CHECK_REQ); /* default request */ |
| 3511 | curproxy->check_len = strlen(DEF_CHECK_REQ); |
| 3512 | } else if (!*args[3]) { /* one argument : URI */ |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3513 | 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] | 3514 | curproxy->check_req = (char *)malloc(reqlen); |
| 3515 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3516 | "OPTIONS %s HTTP/1.0\r\n", args[2]); /* URI to use */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3517 | } else { /* more arguments : METHOD URI [HTTP_VER] */ |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3518 | int reqlen = strlen(args[2]) + strlen(args[3]) + 3 + strlen("\r\n"); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3519 | if (*args[4]) |
| 3520 | reqlen += strlen(args[4]); |
| 3521 | else |
| 3522 | reqlen += strlen("HTTP/1.0"); |
| 3523 | |
| 3524 | curproxy->check_req = (char *)malloc(reqlen); |
| 3525 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3526 | "%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] | 3527 | } |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 3528 | } |
| 3529 | else if (!strcmp(args[1], "ssl-hello-chk")) { |
| 3530 | /* use SSLv3 CLIENT HELLO to check servers' health */ |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3531 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3532 | err_code |= ERR_WARN; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3533 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3534 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 3535 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3536 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Willy Tarreau | 07a5490 | 2010-03-29 18:33:29 +0200 | [diff] [blame] | 3537 | curproxy->options2 |= PR_O2_SSL3_CHK; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3538 | } |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 3539 | else if (!strcmp(args[1], "smtpchk")) { |
| 3540 | /* use SMTP request to check servers' health */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3541 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 3542 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3543 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 3544 | curproxy->options2 |= PR_O2_SMTP_CHK; |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 3545 | |
| 3546 | if (!*args[2] || !*args[3]) { /* no argument or incomplete EHLO host */ |
| 3547 | curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */ |
| 3548 | curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ); |
| 3549 | } else { /* ESMTP EHLO, or SMTP HELO, and a hostname */ |
| 3550 | if (!strcmp(args[2], "EHLO") || !strcmp(args[2], "HELO")) { |
| 3551 | int reqlen = strlen(args[2]) + strlen(args[3]) + strlen(" \r\n") + 1; |
| 3552 | curproxy->check_req = (char *)malloc(reqlen); |
| 3553 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
| 3554 | "%s %s\r\n", args[2], args[3]); /* HELO hostname */ |
| 3555 | } else { |
| 3556 | /* this just hits the default for now, but you could potentially expand it to allow for other stuff |
| 3557 | though, it's unlikely you'd want to send anything other than an EHLO or HELO */ |
| 3558 | curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */ |
| 3559 | curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ); |
| 3560 | } |
| 3561 | } |
| 3562 | } |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 3563 | else if (!strcmp(args[1], "pgsql-check")) { |
| 3564 | /* use PostgreSQL request to check servers' health */ |
| 3565 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 3566 | err_code |= ERR_WARN; |
| 3567 | |
| 3568 | free(curproxy->check_req); |
| 3569 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3570 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 3571 | curproxy->options2 |= PR_O2_PGSQL_CHK; |
| 3572 | |
| 3573 | if (*(args[2])) { |
| 3574 | int cur_arg = 2; |
| 3575 | |
| 3576 | while (*(args[cur_arg])) { |
| 3577 | if (strcmp(args[cur_arg], "user") == 0) { |
| 3578 | char * packet; |
| 3579 | uint32_t packet_len; |
| 3580 | uint32_t pv; |
| 3581 | |
| 3582 | /* suboption header - needs additional argument for it */ |
| 3583 | if (*(args[cur_arg+1]) == 0) { |
| 3584 | Alert("parsing [%s:%d] : '%s %s %s' expects <username> as argument.\n", |
| 3585 | file, linenum, args[0], args[1], args[cur_arg]); |
| 3586 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3587 | goto out; |
| 3588 | } |
| 3589 | |
| 3590 | /* uint32_t + uint32_t + strlen("user")+1 + strlen(username)+1 + 1 */ |
| 3591 | packet_len = 4 + 4 + 5 + strlen(args[cur_arg + 1])+1 +1; |
| 3592 | pv = htonl(0x30000); /* protocol version 3.0 */ |
| 3593 | |
| 3594 | packet = (char*) calloc(1, packet_len); |
| 3595 | |
| 3596 | memcpy(packet + 4, &pv, 4); |
| 3597 | |
| 3598 | /* copy "user" */ |
| 3599 | memcpy(packet + 8, "user", 4); |
| 3600 | |
| 3601 | /* copy username */ |
| 3602 | memcpy(packet + 13, args[cur_arg+1], strlen(args[cur_arg+1])); |
| 3603 | |
| 3604 | free(curproxy->check_req); |
| 3605 | curproxy->check_req = packet; |
| 3606 | curproxy->check_len = packet_len; |
| 3607 | |
| 3608 | packet_len = htonl(packet_len); |
| 3609 | memcpy(packet, &packet_len, 4); |
| 3610 | cur_arg += 2; |
| 3611 | } else { |
| 3612 | /* unknown suboption - catchall */ |
| 3613 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'user'.\n", |
| 3614 | file, linenum, args[0], args[1]); |
| 3615 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3616 | goto out; |
| 3617 | } |
| 3618 | } /* end while loop */ |
| 3619 | } |
| 3620 | } |
| 3621 | |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 3622 | else if (!strcmp(args[1], "redis-check")) { |
| 3623 | /* use REDIS PING request to check servers' health */ |
| 3624 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 3625 | err_code |= ERR_WARN; |
| 3626 | |
| 3627 | free(curproxy->check_req); |
| 3628 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3629 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 3630 | curproxy->options2 |= PR_O2_REDIS_CHK; |
| 3631 | |
| 3632 | curproxy->check_req = (char *) malloc(sizeof(DEF_REDIS_CHECK_REQ) - 1); |
| 3633 | memcpy(curproxy->check_req, DEF_REDIS_CHECK_REQ, sizeof(DEF_REDIS_CHECK_REQ) - 1); |
| 3634 | curproxy->check_len = sizeof(DEF_REDIS_CHECK_REQ) - 1; |
| 3635 | } |
| 3636 | |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 3637 | else if (!strcmp(args[1], "mysql-check")) { |
| 3638 | /* use MYSQL request to check servers' health */ |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 3639 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 3640 | err_code |= ERR_WARN; |
| 3641 | |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 3642 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 3643 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3644 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 3645 | curproxy->options2 |= PR_O2_MYSQL_CHK; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 3646 | |
| 3647 | /* This is an exemple of an MySQL >=4.0 client Authentication packet kindly provided by Cyril Bonte. |
| 3648 | * const char mysql40_client_auth_pkt[] = { |
| 3649 | * "\x0e\x00\x00" // packet length |
| 3650 | * "\x01" // packet number |
| 3651 | * "\x00\x00" // client capabilities |
| 3652 | * "\x00\x00\x01" // max packet |
| 3653 | * "haproxy\x00" // username (null terminated string) |
| 3654 | * "\x00" // filler (always 0x00) |
| 3655 | * "\x01\x00\x00" // packet length |
| 3656 | * "\x00" // packet number |
| 3657 | * "\x01" // COM_QUIT command |
| 3658 | * }; |
| 3659 | */ |
| 3660 | |
| 3661 | if (*(args[2])) { |
| 3662 | int cur_arg = 2; |
| 3663 | |
| 3664 | while (*(args[cur_arg])) { |
| 3665 | if (strcmp(args[cur_arg], "user") == 0) { |
| 3666 | char *mysqluser; |
| 3667 | int packetlen, reqlen, userlen; |
| 3668 | |
| 3669 | /* suboption header - needs additional argument for it */ |
| 3670 | if (*(args[cur_arg+1]) == 0) { |
| 3671 | Alert("parsing [%s:%d] : '%s %s %s' expects <username> as argument.\n", |
| 3672 | file, linenum, args[0], args[1], args[cur_arg]); |
| 3673 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3674 | goto out; |
| 3675 | } |
| 3676 | mysqluser = args[cur_arg + 1]; |
| 3677 | userlen = strlen(mysqluser); |
| 3678 | packetlen = userlen + 7; |
| 3679 | reqlen = packetlen + 9; |
| 3680 | |
| 3681 | free(curproxy->check_req); |
| 3682 | curproxy->check_req = (char *)calloc(1, reqlen); |
| 3683 | curproxy->check_len = reqlen; |
| 3684 | |
| 3685 | snprintf(curproxy->check_req, 4, "%c%c%c", |
| 3686 | ((unsigned char) packetlen & 0xff), |
| 3687 | ((unsigned char) (packetlen >> 8) & 0xff), |
| 3688 | ((unsigned char) (packetlen >> 16) & 0xff)); |
| 3689 | |
| 3690 | curproxy->check_req[3] = 1; |
Hervé COMMOWICK | 212f778 | 2011-06-10 14:05:59 +0200 | [diff] [blame] | 3691 | curproxy->check_req[5] = 128; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 3692 | curproxy->check_req[8] = 1; |
| 3693 | memcpy(&curproxy->check_req[9], mysqluser, userlen); |
| 3694 | curproxy->check_req[9 + userlen + 1 + 1] = 1; |
| 3695 | curproxy->check_req[9 + userlen + 1 + 1 + 4] = 1; |
| 3696 | cur_arg += 2; |
| 3697 | } else { |
| 3698 | /* unknown suboption - catchall */ |
| 3699 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'user'.\n", |
| 3700 | file, linenum, args[0], args[1]); |
| 3701 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3702 | goto out; |
| 3703 | } |
| 3704 | } /* end while loop */ |
| 3705 | } |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 3706 | } |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 3707 | else if (!strcmp(args[1], "ldap-check")) { |
| 3708 | /* use LDAP request to check servers' health */ |
| 3709 | free(curproxy->check_req); |
| 3710 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3711 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 3712 | curproxy->options2 |= PR_O2_LDAP_CHK; |
| 3713 | |
| 3714 | curproxy->check_req = (char *) malloc(sizeof(DEF_LDAP_CHECK_REQ) - 1); |
| 3715 | memcpy(curproxy->check_req, DEF_LDAP_CHECK_REQ, sizeof(DEF_LDAP_CHECK_REQ) - 1); |
| 3716 | curproxy->check_len = sizeof(DEF_LDAP_CHECK_REQ) - 1; |
| 3717 | } |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3718 | else if (!strcmp(args[1], "forwardfor")) { |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3719 | int cur_arg; |
| 3720 | |
| 3721 | /* insert x-forwarded-for field, but not for the IP address listed as an except. |
| 3722 | * set default options (ie: bitfield, header name, etc) |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3723 | */ |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3724 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 3725 | curproxy->options |= PR_O_FWDFOR | PR_O_FF_ALWAYS; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3726 | |
| 3727 | free(curproxy->fwdfor_hdr_name); |
| 3728 | curproxy->fwdfor_hdr_name = strdup(DEF_XFORWARDFOR_HDR); |
| 3729 | curproxy->fwdfor_hdr_len = strlen(DEF_XFORWARDFOR_HDR); |
| 3730 | |
| 3731 | /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */ |
| 3732 | cur_arg = 2; |
| 3733 | while (*(args[cur_arg])) { |
| 3734 | if (!strcmp(args[cur_arg], "except")) { |
| 3735 | /* suboption except - needs additional argument for it */ |
| 3736 | if (!*(args[cur_arg+1]) || !str2net(args[cur_arg+1], &curproxy->except_net, &curproxy->except_mask)) { |
| 3737 | Alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n", |
| 3738 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3739 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3740 | goto out; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3741 | } |
| 3742 | /* flush useless bits */ |
| 3743 | curproxy->except_net.s_addr &= curproxy->except_mask.s_addr; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3744 | cur_arg += 2; |
| 3745 | } else if (!strcmp(args[cur_arg], "header")) { |
| 3746 | /* suboption header - needs additional argument for it */ |
| 3747 | if (*(args[cur_arg+1]) == 0) { |
| 3748 | Alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 3749 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3750 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3751 | goto out; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3752 | } |
| 3753 | free(curproxy->fwdfor_hdr_name); |
| 3754 | curproxy->fwdfor_hdr_name = strdup(args[cur_arg+1]); |
| 3755 | curproxy->fwdfor_hdr_len = strlen(curproxy->fwdfor_hdr_name); |
| 3756 | cur_arg += 2; |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 3757 | } else if (!strcmp(args[cur_arg], "if-none")) { |
| 3758 | curproxy->options &= ~PR_O_FF_ALWAYS; |
| 3759 | cur_arg += 1; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3760 | } else { |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3761 | /* unknown suboption - catchall */ |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 3762 | 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] | 3763 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3764 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3765 | goto out; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3766 | } |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3767 | } /* end while loop */ |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3768 | } |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 3769 | else if (!strcmp(args[1], "originalto")) { |
| 3770 | int cur_arg; |
| 3771 | |
| 3772 | /* insert x-original-to field, but not for the IP address listed as an except. |
| 3773 | * set default options (ie: bitfield, header name, etc) |
| 3774 | */ |
| 3775 | |
| 3776 | curproxy->options |= PR_O_ORGTO; |
| 3777 | |
| 3778 | free(curproxy->orgto_hdr_name); |
| 3779 | curproxy->orgto_hdr_name = strdup(DEF_XORIGINALTO_HDR); |
| 3780 | curproxy->orgto_hdr_len = strlen(DEF_XORIGINALTO_HDR); |
| 3781 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 3782 | /* 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] | 3783 | cur_arg = 2; |
| 3784 | while (*(args[cur_arg])) { |
| 3785 | if (!strcmp(args[cur_arg], "except")) { |
| 3786 | /* suboption except - needs additional argument for it */ |
| 3787 | if (!*(args[cur_arg+1]) || !str2net(args[cur_arg+1], &curproxy->except_to, &curproxy->except_mask_to)) { |
| 3788 | Alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n", |
| 3789 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3790 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3791 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 3792 | } |
| 3793 | /* flush useless bits */ |
| 3794 | curproxy->except_to.s_addr &= curproxy->except_mask_to.s_addr; |
| 3795 | cur_arg += 2; |
| 3796 | } else if (!strcmp(args[cur_arg], "header")) { |
| 3797 | /* suboption header - needs additional argument for it */ |
| 3798 | if (*(args[cur_arg+1]) == 0) { |
| 3799 | Alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 3800 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3801 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3802 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 3803 | } |
| 3804 | free(curproxy->orgto_hdr_name); |
| 3805 | curproxy->orgto_hdr_name = strdup(args[cur_arg+1]); |
| 3806 | curproxy->orgto_hdr_len = strlen(curproxy->orgto_hdr_name); |
| 3807 | cur_arg += 2; |
| 3808 | } else { |
| 3809 | /* unknown suboption - catchall */ |
| 3810 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n", |
| 3811 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3812 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3813 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 3814 | } |
| 3815 | } /* end while loop */ |
| 3816 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3817 | else { |
| 3818 | Alert("parsing [%s:%d] : unknown option '%s'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3819 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3820 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3821 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3822 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3823 | } |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 3824 | else if (!strcmp(args[0], "default_backend")) { |
| 3825 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3826 | err_code |= ERR_WARN; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 3827 | |
| 3828 | if (*(args[1]) == 0) { |
| 3829 | 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] | 3830 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3831 | goto out; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 3832 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3833 | free(curproxy->defbe.name); |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 3834 | curproxy->defbe.name = strdup(args[1]); |
| 3835 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3836 | else if (!strcmp(args[0], "redispatch") || !strcmp(args[0], "redisp")) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3837 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3838 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3839 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3840 | Warning("parsing [%s:%d]: keyword '%s' is deprecated, please use 'option redispatch' instead.\n", |
| 3841 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3842 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3843 | /* enable reconnections to dispatch */ |
| 3844 | curproxy->options |= PR_O_REDISP; |
| 3845 | } |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 3846 | else if (!strcmp(args[0], "http-check")) { |
| 3847 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3848 | err_code |= ERR_WARN; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 3849 | |
| 3850 | if (strcmp(args[1], "disable-on-404") == 0) { |
| 3851 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 3852 | curproxy->options |= PR_O_DISABLE404; |
| 3853 | } |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 3854 | else if (strcmp(args[1], "send-state") == 0) { |
| 3855 | /* enable emission of the apparent state of a server in HTTP checks */ |
| 3856 | curproxy->options2 |= PR_O2_CHK_SNDST; |
| 3857 | } |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 3858 | else if (strcmp(args[1], "expect") == 0) { |
| 3859 | const char *ptr_arg; |
| 3860 | int cur_arg; |
| 3861 | |
| 3862 | if (curproxy->options2 & PR_O2_EXP_TYPE) { |
| 3863 | Alert("parsing [%s:%d] : '%s %s' already specified.\n", file, linenum, args[0], args[1]); |
| 3864 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3865 | goto out; |
| 3866 | } |
| 3867 | |
| 3868 | cur_arg = 2; |
| 3869 | /* consider exclamation marks, sole or at the beginning of a word */ |
| 3870 | while (*(ptr_arg = args[cur_arg])) { |
| 3871 | while (*ptr_arg == '!') { |
| 3872 | curproxy->options2 ^= PR_O2_EXP_INV; |
| 3873 | ptr_arg++; |
| 3874 | } |
| 3875 | if (*ptr_arg) |
| 3876 | break; |
| 3877 | cur_arg++; |
| 3878 | } |
| 3879 | /* now ptr_arg points to the beginning of a word past any possible |
| 3880 | * exclamation mark, and cur_arg is the argument which holds this word. |
| 3881 | */ |
| 3882 | if (strcmp(ptr_arg, "status") == 0) { |
| 3883 | if (!*(args[cur_arg + 1])) { |
| 3884 | Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 3885 | file, linenum, args[0], args[1], ptr_arg); |
| 3886 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3887 | goto out; |
| 3888 | } |
| 3889 | curproxy->options2 |= PR_O2_EXP_STS; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 3890 | free(curproxy->expect_str); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 3891 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
| 3892 | } |
| 3893 | else if (strcmp(ptr_arg, "string") == 0) { |
| 3894 | if (!*(args[cur_arg + 1])) { |
| 3895 | Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 3896 | file, linenum, args[0], args[1], ptr_arg); |
| 3897 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3898 | goto out; |
| 3899 | } |
| 3900 | curproxy->options2 |= PR_O2_EXP_STR; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 3901 | free(curproxy->expect_str); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 3902 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
| 3903 | } |
| 3904 | else if (strcmp(ptr_arg, "rstatus") == 0) { |
| 3905 | if (!*(args[cur_arg + 1])) { |
| 3906 | Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 3907 | file, linenum, args[0], args[1], ptr_arg); |
| 3908 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3909 | goto out; |
| 3910 | } |
| 3911 | curproxy->options2 |= PR_O2_EXP_RSTS; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 3912 | free(curproxy->expect_str); |
| 3913 | if (curproxy->expect_regex) regfree(curproxy->expect_regex); |
| 3914 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 3915 | curproxy->expect_regex = calloc(1, sizeof(regex_t)); |
| 3916 | if (regcomp(curproxy->expect_regex, args[cur_arg + 1], REG_EXTENDED) != 0) { |
| 3917 | Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s'.\n", |
| 3918 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1]); |
| 3919 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3920 | goto out; |
| 3921 | } |
| 3922 | } |
| 3923 | else if (strcmp(ptr_arg, "rstring") == 0) { |
| 3924 | if (!*(args[cur_arg + 1])) { |
| 3925 | Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 3926 | file, linenum, args[0], args[1], ptr_arg); |
| 3927 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3928 | goto out; |
| 3929 | } |
| 3930 | curproxy->options2 |= PR_O2_EXP_RSTR; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 3931 | free(curproxy->expect_str); |
| 3932 | if (curproxy->expect_regex) regfree(curproxy->expect_regex); |
| 3933 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 3934 | curproxy->expect_regex = calloc(1, sizeof(regex_t)); |
| 3935 | if (regcomp(curproxy->expect_regex, args[cur_arg + 1], REG_EXTENDED) != 0) { |
| 3936 | Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s'.\n", |
| 3937 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1]); |
| 3938 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3939 | goto out; |
| 3940 | } |
| 3941 | } |
| 3942 | else { |
| 3943 | Alert("parsing [%s:%d] : '%s %s' only supports [!] 'status', 'string', 'rstatus', 'rstring', found '%s'.\n", |
| 3944 | file, linenum, args[0], args[1], ptr_arg); |
| 3945 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3946 | goto out; |
| 3947 | } |
| 3948 | } |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 3949 | else { |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 3950 | 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] | 3951 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3952 | goto out; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 3953 | } |
| 3954 | } |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3955 | else if (!strcmp(args[0], "monitor")) { |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3956 | if (curproxy == &defproxy) { |
| 3957 | 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] | 3958 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3959 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3960 | } |
| 3961 | |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3962 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3963 | err_code |= ERR_WARN; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3964 | |
| 3965 | if (strcmp(args[1], "fail") == 0) { |
| 3966 | /* add a condition to fail monitor requests */ |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 3967 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3968 | Alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n", |
| 3969 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3970 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3971 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3972 | } |
| 3973 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 3974 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 3975 | Alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition : %s.\n", |
| 3976 | file, linenum, args[0], args[1], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3977 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3978 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3979 | } |
| 3980 | LIST_ADDQ(&curproxy->mon_fail_cond, &cond->list); |
| 3981 | } |
| 3982 | else { |
| 3983 | 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] | 3984 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3985 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3986 | } |
| 3987 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3988 | #ifdef TPROXY |
| 3989 | else if (!strcmp(args[0], "transparent")) { |
| 3990 | /* enable transparent proxy connections */ |
| 3991 | curproxy->options |= PR_O_TRANSP; |
| 3992 | } |
| 3993 | #endif |
| 3994 | else if (!strcmp(args[0], "maxconn")) { /* maxconn */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3995 | 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] | 3996 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3997 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3998 | if (*(args[1]) == 0) { |
| 3999 | 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] | 4000 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4001 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4002 | } |
| 4003 | curproxy->maxconn = atol(args[1]); |
| 4004 | } |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 4005 | else if (!strcmp(args[0], "backlog")) { /* backlog */ |
| 4006 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4007 | err_code |= ERR_WARN; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 4008 | |
| 4009 | if (*(args[1]) == 0) { |
| 4010 | 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] | 4011 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4012 | goto out; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 4013 | } |
| 4014 | curproxy->backlog = atol(args[1]); |
| 4015 | } |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 4016 | else if (!strcmp(args[0], "fullconn")) { /* fullconn */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4017 | 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] | 4018 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4019 | |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 4020 | if (*(args[1]) == 0) { |
| 4021 | 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] | 4022 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4023 | goto out; |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 4024 | } |
| 4025 | curproxy->fullconn = atol(args[1]); |
| 4026 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4027 | else if (!strcmp(args[0], "grace")) { /* grace time (ms) */ |
| 4028 | if (*(args[1]) == 0) { |
| 4029 | 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] | 4030 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4031 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4032 | } |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4033 | err = parse_time_err(args[1], &val, TIME_UNIT_MS); |
| 4034 | if (err) { |
| 4035 | Alert("parsing [%s:%d] : unexpected character '%c' in grace time.\n", |
| 4036 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4037 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4038 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4039 | } |
| 4040 | curproxy->grace = val; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4041 | } |
| 4042 | else if (!strcmp(args[0], "dispatch")) { /* dispatch address */ |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4043 | struct sockaddr_storage *sk; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4044 | if (curproxy == &defproxy) { |
| 4045 | 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] | 4046 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4047 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4048 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4049 | else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4050 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4051 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4052 | if (strchr(args[1], ':') == NULL) { |
| 4053 | 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] | 4054 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4055 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4056 | } |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4057 | sk = str2sa(args[1]); |
| 4058 | if (!sk) { |
| 4059 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[1]); |
| 4060 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4061 | goto out; |
| 4062 | } |
| 4063 | curproxy->dispatch_addr = *sk; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4064 | curproxy->options |= PR_O_DISPATCH; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4065 | } |
| 4066 | else if (!strcmp(args[0], "balance")) { /* set balancing with optional algorithm */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4067 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4068 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4069 | |
Willy Tarreau | a93c74b | 2012-05-08 18:14:39 +0200 | [diff] [blame] | 4070 | if (backend_parse_balance((const char **)args + 1, &errmsg, curproxy) < 0) { |
| 4071 | Alert("parsing [%s:%d] : %s %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4072 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4073 | goto out; |
Willy Tarreau | 2fcb500 | 2007-05-08 13:35:26 +0200 | [diff] [blame] | 4074 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4075 | } |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 4076 | else if (!strcmp(args[0], "hash-type")) { /* set hashing method */ |
| 4077 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 4078 | err_code |= ERR_WARN; |
| 4079 | |
| 4080 | if (strcmp(args[1], "consistent") == 0) { /* use consistent hashing */ |
| 4081 | curproxy->lbprm.algo &= ~BE_LB_HASH_TYPE; |
| 4082 | curproxy->lbprm.algo |= BE_LB_HASH_CONS; |
| 4083 | } |
| 4084 | else if (strcmp(args[1], "map-based") == 0) { /* use map-based hashing */ |
| 4085 | curproxy->lbprm.algo &= ~BE_LB_HASH_TYPE; |
| 4086 | curproxy->lbprm.algo |= BE_LB_HASH_MAP; |
| 4087 | } |
Willy Tarreau | 798a39c | 2010-11-24 15:04:29 +0100 | [diff] [blame] | 4088 | else if (strcmp(args[1], "avalanche") == 0) { /* use full hash before map-based hashing */ |
| 4089 | curproxy->lbprm.algo &= ~BE_LB_HASH_TYPE; |
| 4090 | curproxy->lbprm.algo |= BE_LB_HASH_AVAL; |
| 4091 | } |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 4092 | else { |
Willy Tarreau | 798a39c | 2010-11-24 15:04:29 +0100 | [diff] [blame] | 4093 | 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] | 4094 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4095 | goto out; |
| 4096 | } |
| 4097 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4098 | 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] | 4099 | int cur_arg; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4100 | char *rport, *raddr; |
| 4101 | short realport = 0; |
| 4102 | int do_check = 0, defsrv = (*args[0] == 'd'); |
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 | if (!defsrv && curproxy == &defproxy) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4105 | 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] | 4106 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4107 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4108 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4109 | else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4110 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4111 | |
| 4112 | if (!*args[2]) { |
| 4113 | Alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n", |
| 4114 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4115 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4116 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4117 | } |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 4118 | |
| 4119 | err = invalid_char(args[1]); |
| 4120 | if (err) { |
| 4121 | Alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n", |
| 4122 | file, linenum, *err, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4123 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4124 | goto out; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 4125 | } |
| 4126 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4127 | if (!defsrv) { |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4128 | struct sockaddr_storage *sk; |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4129 | |
Krzysztof Piotr Oledzki | aff01ea | 2010-02-05 20:31:44 +0100 | [diff] [blame] | 4130 | if ((newsrv = (struct server *)calloc(1, sizeof(struct server))) == NULL) { |
| 4131 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 4132 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4133 | goto out; |
| 4134 | } |
| 4135 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4136 | /* the servers are linked backwards first */ |
| 4137 | newsrv->next = curproxy->srv; |
| 4138 | curproxy->srv = newsrv; |
| 4139 | newsrv->proxy = curproxy; |
Willy Tarreau | 8113a5d | 2012-10-04 08:01:43 +0200 | [diff] [blame] | 4140 | newsrv->conf.file = strdup(file); |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4141 | newsrv->conf.line = linenum; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4142 | |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 4143 | newsrv->obj_type = OBJ_TYPE_SERVER; |
Simon Horman | af51495 | 2011-06-21 14:34:57 +0900 | [diff] [blame] | 4144 | LIST_INIT(&newsrv->actconns); |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4145 | LIST_INIT(&newsrv->pendconns); |
| 4146 | do_check = 0; |
| 4147 | newsrv->state = SRV_RUNNING; /* early server setup */ |
| 4148 | newsrv->last_change = now.tv_sec; |
| 4149 | newsrv->id = strdup(args[1]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4150 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4151 | /* several ways to check the port component : |
David du Colombier | 9842ff1 | 2011-03-17 10:40:28 +0100 | [diff] [blame] | 4152 | * - IP => port=+0, relative (IPv4 only) |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4153 | * - IP: => port=+0, relative |
| 4154 | * - IP:N => port=N, absolute |
| 4155 | * - IP:+N => port=+N, relative |
| 4156 | * - IP:-N => port=-N, relative |
| 4157 | */ |
| 4158 | raddr = strdup(args[2]); |
Willy Tarreau | fab5a43 | 2011-03-04 15:31:53 +0100 | [diff] [blame] | 4159 | rport = strrchr(raddr, ':'); |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4160 | if (rport) { |
| 4161 | *rport++ = 0; |
| 4162 | realport = atol(rport); |
| 4163 | if (!isdigit((unsigned char)*rport)) |
| 4164 | newsrv->state |= SRV_MAPPORTS; |
| 4165 | } else |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4166 | newsrv->state |= SRV_MAPPORTS; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4167 | |
Willy Tarreau | fab5a43 | 2011-03-04 15:31:53 +0100 | [diff] [blame] | 4168 | sk = str2ip(raddr); |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4169 | free(raddr); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4170 | if (!sk) { |
| 4171 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[2]); |
| 4172 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4173 | goto out; |
| 4174 | } |
| 4175 | newsrv->addr = *sk; |
Willy Tarreau | f4288ee | 2012-09-28 18:13:10 +0200 | [diff] [blame] | 4176 | newsrv->proto = newsrv->check.proto = protocol_by_family(newsrv->addr.ss_family); |
| 4177 | newsrv->xprt = newsrv->check.xprt = &raw_sock; |
Willy Tarreau | 26d8c59 | 2012-05-07 18:12:14 +0200 | [diff] [blame] | 4178 | |
Willy Tarreau | 173e7fb | 2012-09-24 22:47:39 +0200 | [diff] [blame] | 4179 | if (!newsrv->proto) { |
Willy Tarreau | 26d8c59 | 2012-05-07 18:12:14 +0200 | [diff] [blame] | 4180 | Alert("parsing [%s:%d] : Unknown protocol family %d '%s'\n", |
| 4181 | file, linenum, newsrv->addr.ss_family, args[2]); |
| 4182 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4183 | goto out; |
| 4184 | } |
Willy Tarreau | 86ad42c | 2011-08-27 12:29:07 +0200 | [diff] [blame] | 4185 | set_host_port(&newsrv->addr, realport); |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4186 | |
Willy Tarreau | f4288ee | 2012-09-28 18:13:10 +0200 | [diff] [blame] | 4187 | newsrv->check.use_ssl = curproxy->defsrv.check.use_ssl; |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 4188 | newsrv->check.port = curproxy->defsrv.check.port; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4189 | newsrv->inter = curproxy->defsrv.inter; |
| 4190 | newsrv->fastinter = curproxy->defsrv.fastinter; |
| 4191 | newsrv->downinter = curproxy->defsrv.downinter; |
| 4192 | newsrv->rise = curproxy->defsrv.rise; |
| 4193 | newsrv->fall = curproxy->defsrv.fall; |
| 4194 | newsrv->maxqueue = curproxy->defsrv.maxqueue; |
| 4195 | newsrv->minconn = curproxy->defsrv.minconn; |
| 4196 | newsrv->maxconn = curproxy->defsrv.maxconn; |
| 4197 | newsrv->slowstart = curproxy->defsrv.slowstart; |
| 4198 | newsrv->onerror = curproxy->defsrv.onerror; |
| 4199 | newsrv->consecutive_errors_limit |
| 4200 | = curproxy->defsrv.consecutive_errors_limit; |
Emeric Brun | 01f8e2f | 2012-05-18 16:02:00 +0200 | [diff] [blame] | 4201 | #ifdef OPENSSL |
| 4202 | newsrv->use_ssl = curproxy->defsrv.use_ssl; |
| 4203 | #endif |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4204 | newsrv->uweight = newsrv->iweight |
| 4205 | = curproxy->defsrv.iweight; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4206 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4207 | newsrv->health = newsrv->rise; /* up, but will fall down at first failure */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4208 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4209 | cur_arg = 3; |
| 4210 | } else { |
| 4211 | newsrv = &curproxy->defsrv; |
| 4212 | cur_arg = 1; |
| 4213 | } |
Willy Tarreau | 0f03c6f | 2007-03-25 20:46:19 +0200 | [diff] [blame] | 4214 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4215 | while (*args[cur_arg]) { |
Willy Tarreau | dff5543 | 2012-10-10 17:51:05 +0200 | [diff] [blame] | 4216 | if (!defsrv && !strcmp(args[cur_arg], "cookie")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4217 | newsrv->cookie = strdup(args[cur_arg + 1]); |
| 4218 | newsrv->cklen = strlen(args[cur_arg + 1]); |
| 4219 | cur_arg += 2; |
| 4220 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4221 | else if (!defsrv && !strcmp(args[cur_arg], "redir")) { |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 4222 | newsrv->rdr_pfx = strdup(args[cur_arg + 1]); |
| 4223 | newsrv->rdr_len = strlen(args[cur_arg + 1]); |
| 4224 | cur_arg += 2; |
| 4225 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4226 | else if (!strcmp(args[cur_arg], "rise")) { |
Krzysztof Piotr Oledzki | 08ff959 | 2009-09-27 16:17:31 +0200 | [diff] [blame] | 4227 | if (!*args[cur_arg + 1]) { |
| 4228 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 4229 | file, linenum, args[cur_arg]); |
| 4230 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4231 | goto out; |
| 4232 | } |
| 4233 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4234 | newsrv->rise = atol(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 08ff959 | 2009-09-27 16:17:31 +0200 | [diff] [blame] | 4235 | if (newsrv->rise <= 0) { |
| 4236 | Alert("parsing [%s:%d]: '%s' has to be > 0.\n", |
| 4237 | file, linenum, args[cur_arg]); |
| 4238 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4239 | goto out; |
| 4240 | } |
| 4241 | |
Willy Tarreau | 9683909 | 2010-03-29 10:02:24 +0200 | [diff] [blame] | 4242 | if (newsrv->health) |
| 4243 | newsrv->health = newsrv->rise; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4244 | cur_arg += 2; |
| 4245 | } |
| 4246 | else if (!strcmp(args[cur_arg], "fall")) { |
| 4247 | newsrv->fall = atol(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 08ff959 | 2009-09-27 16:17:31 +0200 | [diff] [blame] | 4248 | |
| 4249 | if (!*args[cur_arg + 1]) { |
| 4250 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 4251 | file, linenum, args[cur_arg]); |
| 4252 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4253 | goto out; |
| 4254 | } |
| 4255 | |
| 4256 | if (newsrv->fall <= 0) { |
| 4257 | Alert("parsing [%s:%d]: '%s' has to be > 0.\n", |
| 4258 | file, linenum, args[cur_arg]); |
| 4259 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4260 | goto out; |
| 4261 | } |
| 4262 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4263 | cur_arg += 2; |
| 4264 | } |
| 4265 | else if (!strcmp(args[cur_arg], "inter")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4266 | const char *err = parse_time_err(args[cur_arg + 1], &val, TIME_UNIT_MS); |
| 4267 | if (err) { |
| 4268 | Alert("parsing [%s:%d] : unexpected character '%c' in 'inter' argument of server %s.\n", |
| 4269 | file, linenum, *err, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4270 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4271 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4272 | } |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4273 | if (val <= 0) { |
| 4274 | Alert("parsing [%s:%d]: invalid value %d for argument '%s' of server %s.\n", |
| 4275 | file, linenum, val, args[cur_arg], newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4276 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4277 | goto out; |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4278 | } |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4279 | newsrv->inter = val; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4280 | cur_arg += 2; |
| 4281 | } |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 4282 | else if (!strcmp(args[cur_arg], "fastinter")) { |
| 4283 | const char *err = parse_time_err(args[cur_arg + 1], &val, TIME_UNIT_MS); |
| 4284 | if (err) { |
| 4285 | Alert("parsing [%s:%d]: unexpected character '%c' in 'fastinter' argument of server %s.\n", |
| 4286 | file, linenum, *err, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4287 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4288 | goto out; |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 4289 | } |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4290 | if (val <= 0) { |
| 4291 | Alert("parsing [%s:%d]: invalid value %d for argument '%s' of server %s.\n", |
| 4292 | file, linenum, val, args[cur_arg], newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4293 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4294 | goto out; |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4295 | } |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 4296 | newsrv->fastinter = val; |
| 4297 | cur_arg += 2; |
| 4298 | } |
| 4299 | else if (!strcmp(args[cur_arg], "downinter")) { |
| 4300 | const char *err = parse_time_err(args[cur_arg + 1], &val, TIME_UNIT_MS); |
| 4301 | if (err) { |
| 4302 | Alert("parsing [%s:%d]: unexpected character '%c' in 'downinter' argument of server %s.\n", |
| 4303 | file, linenum, *err, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4304 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4305 | goto out; |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 4306 | } |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4307 | if (val <= 0) { |
| 4308 | Alert("parsing [%s:%d]: invalid value %d for argument '%s' of server %s.\n", |
| 4309 | file, linenum, val, args[cur_arg], newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4310 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4311 | goto out; |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4312 | } |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 4313 | newsrv->downinter = val; |
| 4314 | cur_arg += 2; |
| 4315 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4316 | else if (!defsrv && !strcmp(args[cur_arg], "addr")) { |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4317 | struct sockaddr_storage *sk = str2sa(args[cur_arg + 1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4318 | if (!sk) { |
| 4319 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[cur_arg + 1]); |
| 4320 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4321 | goto out; |
| 4322 | } |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 4323 | newsrv->check.addr = *sk; |
Willy Tarreau | 2ea3abb | 2007-03-25 16:45:16 +0200 | [diff] [blame] | 4324 | cur_arg += 2; |
| 4325 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4326 | else if (!strcmp(args[cur_arg], "port")) { |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 4327 | newsrv->check.port = atol(args[cur_arg + 1]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4328 | cur_arg += 2; |
| 4329 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4330 | else if (!defsrv && !strcmp(args[cur_arg], "backup")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4331 | newsrv->state |= SRV_BACKUP; |
| 4332 | cur_arg ++; |
| 4333 | } |
Simon Horman | fa46168 | 2011-06-25 09:39:49 +0900 | [diff] [blame] | 4334 | else if (!defsrv && !strcmp(args[cur_arg], "non-stick")) { |
| 4335 | newsrv->state |= SRV_NON_STICK; |
| 4336 | cur_arg ++; |
| 4337 | } |
Willy Tarreau | 5ab04ec | 2011-03-20 10:32:26 +0100 | [diff] [blame] | 4338 | else if (!defsrv && !strcmp(args[cur_arg], "send-proxy")) { |
| 4339 | newsrv->state |= SRV_SEND_PROXY; |
| 4340 | cur_arg ++; |
| 4341 | } |
Willy Tarreau | 6c16adc | 2012-10-05 00:04:16 +0200 | [diff] [blame] | 4342 | else if (!defsrv && !strcmp(args[cur_arg], "check-send-proxy")) { |
| 4343 | newsrv->check.send_proxy = 1; |
| 4344 | cur_arg ++; |
| 4345 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4346 | else if (!strcmp(args[cur_arg], "weight")) { |
| 4347 | int w; |
| 4348 | w = atol(args[cur_arg + 1]); |
Willy Tarreau | 6704d67 | 2009-06-15 10:56:05 +0200 | [diff] [blame] | 4349 | if (w < 0 || w > 256) { |
| 4350 | 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] | 4351 | file, linenum, newsrv->id, w); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4352 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4353 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4354 | } |
Willy Tarreau | 975c50b | 2009-10-10 19:34:06 +0200 | [diff] [blame] | 4355 | newsrv->uweight = newsrv->iweight = w; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4356 | cur_arg += 2; |
| 4357 | } |
| 4358 | else if (!strcmp(args[cur_arg], "minconn")) { |
| 4359 | newsrv->minconn = atol(args[cur_arg + 1]); |
| 4360 | cur_arg += 2; |
| 4361 | } |
| 4362 | else if (!strcmp(args[cur_arg], "maxconn")) { |
| 4363 | newsrv->maxconn = atol(args[cur_arg + 1]); |
| 4364 | cur_arg += 2; |
| 4365 | } |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 4366 | else if (!strcmp(args[cur_arg], "maxqueue")) { |
| 4367 | newsrv->maxqueue = atol(args[cur_arg + 1]); |
| 4368 | cur_arg += 2; |
| 4369 | } |
Willy Tarreau | 9909fc1 | 2007-11-30 17:42:05 +0100 | [diff] [blame] | 4370 | else if (!strcmp(args[cur_arg], "slowstart")) { |
| 4371 | /* slowstart is stored in seconds */ |
Willy Tarreau | 3259e33 | 2007-12-03 01:51:45 +0100 | [diff] [blame] | 4372 | 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] | 4373 | if (err) { |
| 4374 | Alert("parsing [%s:%d] : unexpected character '%c' in 'slowstart' argument of server %s.\n", |
| 4375 | file, linenum, *err, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4376 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4377 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4378 | } |
Willy Tarreau | 4554bc1 | 2010-03-26 10:40:49 +0100 | [diff] [blame] | 4379 | if (val < 0) { |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4380 | Alert("parsing [%s:%d]: invalid value %d for argument '%s' of server %s.\n", |
| 4381 | file, linenum, val, args[cur_arg], newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4382 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4383 | goto out; |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4384 | } |
Willy Tarreau | 3259e33 | 2007-12-03 01:51:45 +0100 | [diff] [blame] | 4385 | newsrv->slowstart = (val + 999) / 1000; |
Willy Tarreau | 9909fc1 | 2007-11-30 17:42:05 +0100 | [diff] [blame] | 4386 | cur_arg += 2; |
| 4387 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4388 | else if (!defsrv && !strcmp(args[cur_arg], "track")) { |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4389 | |
| 4390 | if (!*args[cur_arg + 1]) { |
| 4391 | Alert("parsing [%s:%d]: 'track' expects [<proxy>/]<server> as argument.\n", |
| 4392 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4393 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4394 | goto out; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4395 | } |
| 4396 | |
| 4397 | newsrv->trackit = strdup(args[cur_arg + 1]); |
| 4398 | |
| 4399 | cur_arg += 2; |
| 4400 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4401 | else if (!defsrv && !strcmp(args[cur_arg], "check")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4402 | global.maxsock++; |
| 4403 | do_check = 1; |
| 4404 | cur_arg += 1; |
| 4405 | } |
Willy Tarreau | 9683909 | 2010-03-29 10:02:24 +0200 | [diff] [blame] | 4406 | else if (!defsrv && !strcmp(args[cur_arg], "disabled")) { |
| 4407 | newsrv->state |= SRV_MAINTAIN; |
| 4408 | newsrv->state &= ~SRV_RUNNING; |
| 4409 | newsrv->health = 0; |
| 4410 | cur_arg += 1; |
Emeric Brun | c0ff492 | 2012-09-28 19:37:02 +0200 | [diff] [blame] | 4411 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4412 | else if (!defsrv && !strcmp(args[cur_arg], "observe")) { |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 4413 | if (!strcmp(args[cur_arg + 1], "none")) |
| 4414 | newsrv->observe = HANA_OBS_NONE; |
| 4415 | else if (!strcmp(args[cur_arg + 1], "layer4")) |
| 4416 | newsrv->observe = HANA_OBS_LAYER4; |
| 4417 | else if (!strcmp(args[cur_arg + 1], "layer7")) { |
| 4418 | if (curproxy->mode != PR_MODE_HTTP) { |
| 4419 | Alert("parsing [%s:%d]: '%s' can only be used in http proxies.\n", |
| 4420 | file, linenum, args[cur_arg + 1]); |
| 4421 | err_code |= ERR_ALERT; |
| 4422 | } |
| 4423 | newsrv->observe = HANA_OBS_LAYER7; |
| 4424 | } |
| 4425 | else { |
| 4426 | Alert("parsing [%s:%d]: '%s' expects one of 'none', " |
Willy Tarreau | 53621e0 | 2010-10-22 14:53:40 +0200 | [diff] [blame] | 4427 | "'layer4', 'layer7' but got '%s'\n", |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 4428 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
| 4429 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4430 | goto out; |
| 4431 | } |
| 4432 | |
| 4433 | cur_arg += 2; |
| 4434 | } |
| 4435 | else if (!strcmp(args[cur_arg], "on-error")) { |
| 4436 | if (!strcmp(args[cur_arg + 1], "fastinter")) |
| 4437 | newsrv->onerror = HANA_ONERR_FASTINTER; |
| 4438 | else if (!strcmp(args[cur_arg + 1], "fail-check")) |
| 4439 | newsrv->onerror = HANA_ONERR_FAILCHK; |
| 4440 | else if (!strcmp(args[cur_arg + 1], "sudden-death")) |
| 4441 | newsrv->onerror = HANA_ONERR_SUDDTH; |
| 4442 | else if (!strcmp(args[cur_arg + 1], "mark-down")) |
| 4443 | newsrv->onerror = HANA_ONERR_MARKDWN; |
| 4444 | else { |
| 4445 | Alert("parsing [%s:%d]: '%s' expects one of 'fastinter', " |
Willy Tarreau | 53621e0 | 2010-10-22 14:53:40 +0200 | [diff] [blame] | 4446 | "'fail-check', 'sudden-death' or 'mark-down' but got '%s'\n", |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 4447 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
| 4448 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4449 | goto out; |
| 4450 | } |
| 4451 | |
| 4452 | cur_arg += 2; |
| 4453 | } |
Simon Horman | e0d1bfb | 2011-06-21 14:34:58 +0900 | [diff] [blame] | 4454 | else if (!strcmp(args[cur_arg], "on-marked-down")) { |
| 4455 | if (!strcmp(args[cur_arg + 1], "shutdown-sessions")) |
| 4456 | newsrv->onmarkeddown = HANA_ONMARKEDDOWN_SHUTDOWNSESSIONS; |
| 4457 | else { |
| 4458 | Alert("parsing [%s:%d]: '%s' expects 'shutdown-sessions' but got '%s'\n", |
| 4459 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
| 4460 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4461 | goto out; |
| 4462 | } |
| 4463 | |
| 4464 | cur_arg += 2; |
| 4465 | } |
Justin Karneges | eb2c24a | 2012-05-24 15:28:52 -0700 | [diff] [blame] | 4466 | else if (!strcmp(args[cur_arg], "on-marked-up")) { |
| 4467 | if (!strcmp(args[cur_arg + 1], "shutdown-backup-sessions")) |
| 4468 | newsrv->onmarkedup = HANA_ONMARKEDUP_SHUTDOWNBACKUPSESSIONS; |
| 4469 | else { |
| 4470 | Alert("parsing [%s:%d]: '%s' expects 'shutdown-backup-sessions' but got '%s'\n", |
| 4471 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
| 4472 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4473 | goto out; |
| 4474 | } |
| 4475 | |
| 4476 | cur_arg += 2; |
| 4477 | } |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 4478 | else if (!strcmp(args[cur_arg], "error-limit")) { |
| 4479 | if (!*args[cur_arg + 1]) { |
| 4480 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 4481 | file, linenum, args[cur_arg]); |
| 4482 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4483 | goto out; |
| 4484 | } |
| 4485 | |
| 4486 | newsrv->consecutive_errors_limit = atoi(args[cur_arg + 1]); |
| 4487 | |
| 4488 | if (newsrv->consecutive_errors_limit <= 0) { |
| 4489 | Alert("parsing [%s:%d]: %s has to be > 0.\n", |
| 4490 | file, linenum, args[cur_arg]); |
| 4491 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4492 | goto out; |
| 4493 | } |
Willy Tarreau | f53b25d | 2010-03-15 19:40:37 +0100 | [diff] [blame] | 4494 | cur_arg += 2; |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 4495 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4496 | 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] | 4497 | int port_low, port_high; |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4498 | struct sockaddr_storage *sk; |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4499 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4500 | if (!*args[cur_arg + 1]) { |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4501 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 4502 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>[-<port>]], and optional '%s' <addr> as argument.\n", |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 4503 | file, linenum, "source", "usesrc"); |
| 4504 | #else |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 4505 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>[-<port>]] as argument.\n", |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4506 | file, linenum, "source"); |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 4507 | #endif |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4508 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4509 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4510 | } |
| 4511 | newsrv->state |= SRV_BIND_SRC; |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4512 | sk = str2sa_range(args[cur_arg + 1], &port_low, &port_high); |
| 4513 | if (!sk) { |
| 4514 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[cur_arg + 1]); |
| 4515 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4516 | goto out; |
| 4517 | } |
| 4518 | newsrv->source_addr = *sk; |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 4519 | |
| 4520 | if (port_low != port_high) { |
| 4521 | int i; |
| 4522 | if (port_low <= 0 || port_low > 65535 || |
| 4523 | port_high <= 0 || port_high > 65535 || |
| 4524 | port_low > port_high) { |
| 4525 | Alert("parsing [%s:%d] : invalid source port range %d-%d.\n", |
| 4526 | file, linenum, port_low, port_high); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4527 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4528 | goto out; |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 4529 | } |
| 4530 | newsrv->sport_range = port_range_alloc_range(port_high - port_low + 1); |
| 4531 | for (i = 0; i < newsrv->sport_range->size; i++) |
| 4532 | newsrv->sport_range->ports[i] = port_low + i; |
| 4533 | } |
| 4534 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4535 | cur_arg += 2; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4536 | while (*(args[cur_arg])) { |
| 4537 | if (!strcmp(args[cur_arg], "usesrc")) { /* address to use outside */ |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4538 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) |
| 4539 | #if !defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4540 | if (newsrv->source_addr.sin_addr.s_addr == INADDR_ANY) { |
| 4541 | Alert("parsing [%s:%d] : '%s' requires an explicit '%s' address.\n", |
| 4542 | file, linenum, "usesrc", "source"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4543 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4544 | goto out; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4545 | } |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4546 | #endif |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4547 | if (!*args[cur_arg + 1]) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4548 | 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] | 4549 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4550 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4551 | goto out; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4552 | } |
| 4553 | if (!strcmp(args[cur_arg + 1], "client")) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4554 | newsrv->state &= ~SRV_TPROXY_MASK; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4555 | newsrv->state |= SRV_TPROXY_CLI; |
| 4556 | } else if (!strcmp(args[cur_arg + 1], "clientip")) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4557 | newsrv->state &= ~SRV_TPROXY_MASK; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4558 | newsrv->state |= SRV_TPROXY_CIP; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4559 | } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) { |
| 4560 | char *name, *end; |
| 4561 | |
| 4562 | name = args[cur_arg+1] + 7; |
| 4563 | while (isspace(*name)) |
| 4564 | name++; |
| 4565 | |
| 4566 | end = name; |
| 4567 | while (*end && !isspace(*end) && *end != ',' && *end != ')') |
| 4568 | end++; |
| 4569 | |
| 4570 | newsrv->state &= ~SRV_TPROXY_MASK; |
| 4571 | newsrv->state |= SRV_TPROXY_DYN; |
| 4572 | newsrv->bind_hdr_name = calloc(1, end - name + 1); |
| 4573 | newsrv->bind_hdr_len = end - name; |
| 4574 | memcpy(newsrv->bind_hdr_name, name, end - name); |
| 4575 | newsrv->bind_hdr_name[end-name] = '\0'; |
| 4576 | newsrv->bind_hdr_occ = -1; |
| 4577 | |
| 4578 | /* now look for an occurrence number */ |
| 4579 | while (isspace(*end)) |
| 4580 | end++; |
| 4581 | if (*end == ',') { |
| 4582 | end++; |
| 4583 | name = end; |
| 4584 | if (*end == '-') |
| 4585 | end++; |
| 4586 | while (isdigit(*end)) |
| 4587 | end++; |
| 4588 | newsrv->bind_hdr_occ = strl2ic(name, end-name); |
| 4589 | } |
| 4590 | |
| 4591 | if (newsrv->bind_hdr_occ < -MAX_HDR_HISTORY) { |
| 4592 | Alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative" |
| 4593 | " occurrences values smaller than %d.\n", |
| 4594 | file, linenum, MAX_HDR_HISTORY); |
| 4595 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4596 | goto out; |
| 4597 | } |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4598 | } else { |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4599 | struct sockaddr_storage *sk = str2sa(args[cur_arg + 1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4600 | if (!sk) { |
| 4601 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[cur_arg + 1]); |
| 4602 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4603 | goto out; |
| 4604 | } |
| 4605 | newsrv->tproxy_addr = *sk; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4606 | newsrv->state |= SRV_TPROXY_ADDR; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4607 | } |
| 4608 | global.last_checks |= LSTCHK_NETADM; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4609 | #if !defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4610 | global.last_checks |= LSTCHK_CTTPROXY; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4611 | #endif |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4612 | cur_arg += 2; |
| 4613 | continue; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4614 | #else /* no TPROXY support */ |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4615 | 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] | 4616 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4617 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4618 | goto out; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4619 | #endif /* defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) */ |
| 4620 | } /* "usesrc" */ |
| 4621 | |
| 4622 | if (!strcmp(args[cur_arg], "interface")) { /* specifically bind to this interface */ |
| 4623 | #ifdef SO_BINDTODEVICE |
| 4624 | if (!*args[cur_arg + 1]) { |
| 4625 | Alert("parsing [%s:%d] : '%s' : missing interface name.\n", |
| 4626 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4627 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4628 | goto out; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4629 | } |
| 4630 | if (newsrv->iface_name) |
| 4631 | free(newsrv->iface_name); |
| 4632 | |
| 4633 | newsrv->iface_name = strdup(args[cur_arg + 1]); |
| 4634 | newsrv->iface_len = strlen(newsrv->iface_name); |
| 4635 | global.last_checks |= LSTCHK_NETADM; |
| 4636 | #else |
| 4637 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 4638 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4639 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4640 | goto out; |
Willy Tarreau | 77074d5 | 2006-11-12 23:57:19 +0100 | [diff] [blame] | 4641 | #endif |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4642 | cur_arg += 2; |
| 4643 | continue; |
| 4644 | } |
| 4645 | /* this keyword in not an option of "source" */ |
| 4646 | break; |
| 4647 | } /* while */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4648 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4649 | 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] | 4650 | Alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n", |
| 4651 | file, linenum, "usesrc", "source"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4652 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4653 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 4654 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4655 | else { |
Willy Tarreau | d0d6059 | 2012-10-10 08:57:40 +0200 | [diff] [blame] | 4656 | static int srv_dumped; |
| 4657 | struct srv_kw *kw; |
| 4658 | char *err; |
| 4659 | |
| 4660 | kw = srv_find_kw(args[cur_arg]); |
| 4661 | if (kw) { |
| 4662 | char *err = NULL; |
| 4663 | int code; |
| 4664 | |
| 4665 | if (!kw->parse) { |
| 4666 | Alert("parsing [%s:%d] : '%s %s' : '%s' option is not implemented in this version (check build options).\n", |
| 4667 | file, linenum, args[0], args[1], args[cur_arg]); |
| 4668 | cur_arg += 1 + kw->skip ; |
| 4669 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4670 | goto out; |
| 4671 | } |
| 4672 | |
| 4673 | if (defsrv && !kw->default_ok) { |
| 4674 | Alert("parsing [%s:%d] : '%s %s' : '%s' option is not accepted in default-server sections.\n", |
| 4675 | file, linenum, args[0], args[1], args[cur_arg]); |
| 4676 | cur_arg += 1 + kw->skip ; |
| 4677 | err_code |= ERR_ALERT; |
| 4678 | continue; |
| 4679 | } |
| 4680 | |
| 4681 | code = kw->parse(args, &cur_arg, curproxy, newsrv, &err); |
| 4682 | err_code |= code; |
| 4683 | |
| 4684 | if (code) { |
| 4685 | if (err && *err) { |
| 4686 | indent_msg(&err, 2); |
| 4687 | Alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], err); |
| 4688 | } |
| 4689 | else |
| 4690 | Alert("parsing [%s:%d] : '%s %s' : error encountered while processing '%s'.\n", |
| 4691 | file, linenum, args[0], args[1], args[cur_arg]); |
| 4692 | if (code & ERR_FATAL) { |
| 4693 | free(err); |
| 4694 | cur_arg += 1 + kw->skip; |
| 4695 | goto out; |
| 4696 | } |
| 4697 | } |
| 4698 | free(err); |
| 4699 | cur_arg += 1 + kw->skip; |
| 4700 | continue; |
| 4701 | } |
| 4702 | |
| 4703 | err = NULL; |
| 4704 | if (!srv_dumped) { |
| 4705 | srv_dump_kws(&err); |
| 4706 | indent_msg(&err, 4); |
| 4707 | srv_dumped = 1; |
| 4708 | } |
| 4709 | |
| 4710 | Alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'.%s%s\n", |
| 4711 | file, linenum, args[0], args[1], args[cur_arg], |
| 4712 | err ? " Registered keywords :" : "", err ? err : ""); |
| 4713 | free(err); |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4714 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4715 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4716 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4717 | } |
| 4718 | } |
| 4719 | |
| 4720 | if (do_check) { |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4721 | if (newsrv->trackit) { |
| 4722 | Alert("parsing [%s:%d]: unable to enable checks and tracking at the same time!\n", |
| 4723 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4724 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4725 | goto out; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4726 | } |
| 4727 | |
Willy Tarreau | f4288ee | 2012-09-28 18:13:10 +0200 | [diff] [blame] | 4728 | /* If neither a port nor an addr was specified and no check transport |
| 4729 | * layer is forced, then the transport layer used by the checks is the |
| 4730 | * same as for the production traffic. Otherwise we use raw_sock by |
| 4731 | * default, unless one is specified. |
| 4732 | */ |
Willy Tarreau | 6c16adc | 2012-10-05 00:04:16 +0200 | [diff] [blame] | 4733 | if (!newsrv->check.port && !is_addr(&newsrv->check.addr)) { |
Willy Tarreau | 7151633 | 2012-10-10 23:01:14 +0200 | [diff] [blame] | 4734 | #ifdef USE_OPENSSL |
Willy Tarreau | f4288ee | 2012-09-28 18:13:10 +0200 | [diff] [blame] | 4735 | newsrv->check.use_ssl |= newsrv->use_ssl; |
Willy Tarreau | 7151633 | 2012-10-10 23:01:14 +0200 | [diff] [blame] | 4736 | #endif |
Willy Tarreau | 6c16adc | 2012-10-05 00:04:16 +0200 | [diff] [blame] | 4737 | newsrv->check.send_proxy |= (newsrv->state & SRV_SEND_PROXY); |
| 4738 | } |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 4739 | /* try to get the port from check.addr if check.port not set */ |
| 4740 | if (!newsrv->check.port) |
| 4741 | newsrv->check.port = get_host_port(&newsrv->check.addr); |
Willy Tarreau | 0f03c6f | 2007-03-25 20:46:19 +0200 | [diff] [blame] | 4742 | |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 4743 | if (!newsrv->check.port && !(newsrv->state & SRV_MAPPORTS)) |
| 4744 | newsrv->check.port = realport; /* by default */ |
| 4745 | if (!newsrv->check.port) { |
Willy Tarreau | ef00b50 | 2007-01-07 02:40:09 +0100 | [diff] [blame] | 4746 | /* not yet valid, because no port was set on |
| 4747 | * the server either. We'll check if we have |
| 4748 | * a known port on the first listener. |
| 4749 | */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 4750 | struct listener *l; |
| 4751 | |
| 4752 | list_for_each_entry(l, &curproxy->conf.listeners, by_fe) { |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 4753 | newsrv->check.port = get_host_port(&l->addr); |
| 4754 | if (newsrv->check.port) |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 4755 | break; |
| 4756 | } |
Willy Tarreau | ef00b50 | 2007-01-07 02:40:09 +0100 | [diff] [blame] | 4757 | } |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 4758 | if (!newsrv->check.port) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4759 | Alert("parsing [%s:%d] : server %s has neither service port nor check port. Check has been disabled.\n", |
| 4760 | file, linenum, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4761 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4762 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4763 | } |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 4764 | |
Willy Tarreau | 1ae1b7b | 2012-09-28 15:28:30 +0200 | [diff] [blame] | 4765 | /* Allocate buffer for check requests... */ |
| 4766 | 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] | 4767 | Alert("parsing [%s:%d] : out of memory while allocating check buffer.\n", file, linenum); |
| 4768 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4769 | goto out; |
| 4770 | } |
Willy Tarreau | 1ae1b7b | 2012-09-28 15:28:30 +0200 | [diff] [blame] | 4771 | newsrv->check.bi->size = global.tune.chksize; |
| 4772 | |
| 4773 | /* Allocate buffer for check responses... */ |
| 4774 | if ((newsrv->check.bo = calloc(sizeof(struct buffer) + global.tune.chksize, sizeof(char))) == NULL) { |
| 4775 | Alert("parsing [%s:%d] : out of memory while allocating check buffer.\n", file, linenum); |
| 4776 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4777 | goto out; |
| 4778 | } |
| 4779 | newsrv->check.bo->size = global.tune.chksize; |
Cyril Bonté | c9f825f | 2010-03-17 18:56:31 +0100 | [diff] [blame] | 4780 | |
Willy Tarreau | da92e2f | 2012-07-06 09:40:59 +0200 | [diff] [blame] | 4781 | /* Allocate buffer for partial check results... */ |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 4782 | if ((newsrv->check.conn = calloc(1, sizeof(struct connection))) == NULL) { |
Willy Tarreau | da92e2f | 2012-07-06 09:40:59 +0200 | [diff] [blame] | 4783 | Alert("parsing [%s:%d] : out of memory while allocating check connection.\n", file, linenum); |
| 4784 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4785 | goto out; |
| 4786 | } |
| 4787 | |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 4788 | newsrv->check.conn->t.sock.fd = -1; /* no check in progress yet */ |
| 4789 | newsrv->check.status = HCHK_STATUS_INI; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4790 | newsrv->state |= SRV_CHECKED; |
| 4791 | } |
| 4792 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4793 | if (!defsrv) { |
| 4794 | if (newsrv->state & SRV_BACKUP) |
| 4795 | curproxy->srv_bck++; |
| 4796 | else |
| 4797 | curproxy->srv_act++; |
Willy Tarreau | b625a08 | 2007-11-26 01:15:43 +0100 | [diff] [blame] | 4798 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4799 | newsrv->prev_state = newsrv->state; |
| 4800 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 4801 | } |
| 4802 | |
| 4803 | else if (strcmp(args[0], "unique-id-format") == 0) { |
| 4804 | if (!*(args[1])) { |
| 4805 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 4806 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4807 | goto out; |
| 4808 | } |
William Lallemand | 3203ff4 | 2012-11-11 17:30:56 +0100 | [diff] [blame] | 4809 | if (*(args[2])) { |
| 4810 | Alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]); |
| 4811 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4812 | goto out; |
| 4813 | } |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 4814 | free(curproxy->uniqueid_format_string); |
| 4815 | curproxy->uniqueid_format_string = strdup(args[1]); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4816 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 4817 | |
| 4818 | else if (strcmp(args[0], "unique-id-header") == 0) { |
| 4819 | if (!*(args[1])) { |
| 4820 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 4821 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4822 | goto out; |
| 4823 | } |
| 4824 | free(curproxy->header_unique_id); |
| 4825 | curproxy->header_unique_id = strdup(args[1]); |
| 4826 | } |
| 4827 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4828 | else if (strcmp(args[0], "log-format") == 0) { |
| 4829 | if (!*(args[1])) { |
| 4830 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 4831 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4832 | goto out; |
| 4833 | } |
William Lallemand | 3203ff4 | 2012-11-11 17:30:56 +0100 | [diff] [blame] | 4834 | if (*(args[2])) { |
| 4835 | Alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]); |
| 4836 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4837 | goto out; |
| 4838 | } |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 4839 | |
| 4840 | if (curproxy->logformat_string != default_http_log_format && |
| 4841 | curproxy->logformat_string != default_tcp_log_format && |
| 4842 | curproxy->logformat_string != clf_http_log_format) |
| 4843 | free(curproxy->logformat_string); |
| 4844 | curproxy->logformat_string = strdup(args[1]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4845 | } |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4846 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4847 | else if (!strcmp(args[0], "log") && kwm == KWM_NO) { |
| 4848 | /* delete previous herited or defined syslog servers */ |
| 4849 | struct logsrv *back; |
| 4850 | |
| 4851 | if (*(args[1]) != 0) { |
| 4852 | Alert("parsing [%s:%d]:%s : 'no log' does not expect arguments.\n", file, linenum, args[1]); |
| 4853 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4854 | goto out; |
| 4855 | } |
| 4856 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4857 | list_for_each_entry_safe(tmplogsrv, back, &curproxy->logsrvs, list) { |
| 4858 | LIST_DEL(&tmplogsrv->list); |
| 4859 | free(tmplogsrv); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4860 | } |
| 4861 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4862 | else if (!strcmp(args[0], "log")) { /* syslog server address */ |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4863 | struct logsrv *logsrv; |
| 4864 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4865 | if (*(args[1]) && *(args[2]) == 0 && !strcmp(args[1], "global")) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4866 | /* copy global.logrsvs linked list to the end of curproxy->logsrvs */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4867 | list_for_each_entry(tmplogsrv, &global.logsrvs, list) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4868 | struct logsrv *node = malloc(sizeof(struct logsrv)); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4869 | memcpy(node, tmplogsrv, sizeof(struct logsrv)); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4870 | LIST_INIT(&node->list); |
| 4871 | LIST_ADDQ(&curproxy->logsrvs, &node->list); |
| 4872 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4873 | } |
| 4874 | else if (*(args[1]) && *(args[2])) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4875 | |
| 4876 | logsrv = calloc(1, sizeof(struct logsrv)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4877 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4878 | logsrv->facility = get_log_facility(args[2]); |
| 4879 | if (logsrv->facility < 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4880 | 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] | 4881 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4882 | goto out; |
| 4883 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4884 | } |
| 4885 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4886 | logsrv->level = 7; /* max syslog level = debug */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4887 | if (*(args[3])) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4888 | logsrv->level = get_log_level(args[3]); |
| 4889 | if (logsrv->level < 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4890 | 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] | 4891 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4892 | goto out; |
| 4893 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4894 | } |
| 4895 | } |
| 4896 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4897 | logsrv->minlvl = 0; /* limit syslog level to this level (emerg) */ |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 4898 | if (*(args[4])) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4899 | logsrv->minlvl = get_log_level(args[4]); |
| 4900 | if (logsrv->level < 0) { |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 4901 | 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] | 4902 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4903 | goto out; |
| 4904 | |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 4905 | } |
| 4906 | } |
| 4907 | |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 4908 | if (args[1][0] == '/') { |
David du Colombier | 11bcb6c | 2011-03-24 12:23:00 +0100 | [diff] [blame] | 4909 | struct sockaddr_storage *sk = (struct sockaddr_storage *)str2sun(args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4910 | if (!sk) { |
| 4911 | 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] | 4912 | args[1], (int)sizeof(((struct sockaddr_un *)sk)->sun_path) - 1); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4913 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4914 | goto out; |
| 4915 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4916 | logsrv->addr = *sk; |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 4917 | } else { |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4918 | struct sockaddr_storage *sk = str2sa(args[1]); |
David du Colombier | 11bcb6c | 2011-03-24 12:23:00 +0100 | [diff] [blame] | 4919 | if (!sk) { |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4920 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[1]); |
| 4921 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4922 | goto out; |
| 4923 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4924 | logsrv->addr = *sk; |
| 4925 | if (!get_host_port(&logsrv->addr)) |
| 4926 | set_host_port(&logsrv->addr, SYSLOG_PORT); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4927 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4928 | |
| 4929 | LIST_ADDQ(&curproxy->logsrvs, &logsrv->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4930 | } |
| 4931 | else { |
| 4932 | Alert("parsing [%s:%d] : 'log' expects either <address[:port]> and <facility> or 'global' as arguments.\n", |
| 4933 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4934 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4935 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4936 | } |
| 4937 | } |
| 4938 | 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] | 4939 | int cur_arg; |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4940 | struct sockaddr_storage *sk; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4941 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4942 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4943 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4944 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4945 | if (!*args[1]) { |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4946 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optionally '%s' <addr>, and '%s' <name>.\n", |
| 4947 | file, linenum, "source", "usesrc", "interface"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4948 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4949 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4950 | } |
Willy Tarreau | 368480c | 2009-03-01 08:27:21 +0100 | [diff] [blame] | 4951 | |
| 4952 | /* we must first clear any optional default setting */ |
| 4953 | curproxy->options &= ~PR_O_TPXY_MASK; |
| 4954 | free(curproxy->iface_name); |
| 4955 | curproxy->iface_name = NULL; |
| 4956 | curproxy->iface_len = 0; |
| 4957 | |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4958 | sk = str2sa(args[1]); |
| 4959 | if (!sk) { |
| 4960 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[1]); |
| 4961 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4962 | goto out; |
| 4963 | } |
| 4964 | curproxy->source_addr = *sk; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4965 | curproxy->options |= PR_O_BIND_SRC; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4966 | |
| 4967 | cur_arg = 2; |
| 4968 | while (*(args[cur_arg])) { |
| 4969 | if (!strcmp(args[cur_arg], "usesrc")) { /* address to use outside */ |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4970 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) |
| 4971 | #if !defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4972 | if (curproxy->source_addr.sin_addr.s_addr == INADDR_ANY) { |
| 4973 | Alert("parsing [%s:%d] : '%s' requires an explicit 'source' address.\n", |
| 4974 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4975 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4976 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4977 | } |
| 4978 | #endif |
| 4979 | if (!*args[cur_arg + 1]) { |
| 4980 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n", |
| 4981 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4982 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4983 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4984 | } |
| 4985 | |
| 4986 | if (!strcmp(args[cur_arg + 1], "client")) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4987 | curproxy->options &= ~PR_O_TPXY_MASK; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4988 | curproxy->options |= PR_O_TPXY_CLI; |
| 4989 | } else if (!strcmp(args[cur_arg + 1], "clientip")) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4990 | curproxy->options &= ~PR_O_TPXY_MASK; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4991 | curproxy->options |= PR_O_TPXY_CIP; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4992 | } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) { |
| 4993 | char *name, *end; |
| 4994 | |
| 4995 | name = args[cur_arg+1] + 7; |
| 4996 | while (isspace(*name)) |
| 4997 | name++; |
| 4998 | |
| 4999 | end = name; |
| 5000 | while (*end && !isspace(*end) && *end != ',' && *end != ')') |
| 5001 | end++; |
| 5002 | |
| 5003 | curproxy->options &= ~PR_O_TPXY_MASK; |
| 5004 | curproxy->options |= PR_O_TPXY_DYN; |
| 5005 | curproxy->bind_hdr_name = calloc(1, end - name + 1); |
| 5006 | curproxy->bind_hdr_len = end - name; |
| 5007 | memcpy(curproxy->bind_hdr_name, name, end - name); |
| 5008 | curproxy->bind_hdr_name[end-name] = '\0'; |
| 5009 | curproxy->bind_hdr_occ = -1; |
| 5010 | |
| 5011 | /* now look for an occurrence number */ |
| 5012 | while (isspace(*end)) |
| 5013 | end++; |
| 5014 | if (*end == ',') { |
| 5015 | end++; |
| 5016 | name = end; |
| 5017 | if (*end == '-') |
| 5018 | end++; |
| 5019 | while (isdigit(*end)) |
| 5020 | end++; |
| 5021 | curproxy->bind_hdr_occ = strl2ic(name, end-name); |
| 5022 | } |
| 5023 | |
| 5024 | if (curproxy->bind_hdr_occ < -MAX_HDR_HISTORY) { |
| 5025 | Alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative" |
| 5026 | " occurrences values smaller than %d.\n", |
| 5027 | file, linenum, MAX_HDR_HISTORY); |
| 5028 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5029 | goto out; |
| 5030 | } |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5031 | } else { |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 5032 | struct sockaddr_storage *sk = str2sa(args[cur_arg + 1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 5033 | if (!sk) { |
| 5034 | Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[cur_arg + 1]); |
| 5035 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5036 | goto out; |
| 5037 | } |
| 5038 | curproxy->tproxy_addr = *sk; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5039 | curproxy->options |= PR_O_TPXY_ADDR; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5040 | } |
| 5041 | global.last_checks |= LSTCHK_NETADM; |
| 5042 | #if !defined(CONFIG_HAP_LINUX_TPROXY) |
| 5043 | global.last_checks |= LSTCHK_CTTPROXY; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 5044 | #endif |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5045 | #else /* no TPROXY support */ |
| 5046 | 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] | 5047 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5048 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5049 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5050 | #endif |
| 5051 | cur_arg += 2; |
| 5052 | continue; |
Willy Tarreau | 77074d5 | 2006-11-12 23:57:19 +0100 | [diff] [blame] | 5053 | } |
| 5054 | |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5055 | if (!strcmp(args[cur_arg], "interface")) { /* specifically bind to this interface */ |
| 5056 | #ifdef SO_BINDTODEVICE |
| 5057 | if (!*args[cur_arg + 1]) { |
| 5058 | Alert("parsing [%s:%d] : '%s' : missing interface name.\n", |
| 5059 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5060 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5061 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5062 | } |
| 5063 | if (curproxy->iface_name) |
| 5064 | free(curproxy->iface_name); |
| 5065 | |
| 5066 | curproxy->iface_name = strdup(args[cur_arg + 1]); |
| 5067 | curproxy->iface_len = strlen(curproxy->iface_name); |
| 5068 | global.last_checks |= LSTCHK_NETADM; |
| 5069 | #else |
| 5070 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 5071 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5072 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5073 | goto out; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 5074 | #endif |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5075 | cur_arg += 2; |
| 5076 | continue; |
| 5077 | } |
| 5078 | 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] | 5079 | file, linenum, args[0], "interface", "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5080 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5081 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 5082 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5083 | } |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 5084 | else if (!strcmp(args[0], "usesrc")) { /* address to use outside: needs "source" first */ |
| 5085 | Alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n", |
| 5086 | file, linenum, "usesrc", "source"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5087 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5088 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 5089 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5090 | 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] | 5091 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5092 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 5093 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5094 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5095 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5096 | } |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5097 | |
| 5098 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5099 | SMP_OPT_DIR_REQ, ACT_REPLACE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5100 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5101 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5102 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5103 | } |
| 5104 | else if (!strcmp(args[0], "reqdel")) { /* delete request header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5105 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5106 | SMP_OPT_DIR_REQ, ACT_REMOVE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5107 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5108 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5109 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5110 | } |
| 5111 | 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] | 5112 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5113 | SMP_OPT_DIR_REQ, ACT_DENY, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5114 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5115 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5116 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5117 | } |
| 5118 | 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] | 5119 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5120 | SMP_OPT_DIR_REQ, ACT_PASS, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5121 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5122 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5123 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5124 | } |
| 5125 | 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] | 5126 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5127 | SMP_OPT_DIR_REQ, ACT_ALLOW, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5128 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5129 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5130 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5131 | } |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 5132 | 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] | 5133 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5134 | SMP_OPT_DIR_REQ, ACT_TARPIT, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5135 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5136 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5137 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 5138 | } |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5139 | 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] | 5140 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5141 | SMP_OPT_DIR_REQ, ACT_SETBE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5142 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5143 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5144 | goto out; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5145 | } |
| 5146 | 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] | 5147 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5148 | SMP_OPT_DIR_REQ, ACT_SETBE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5149 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5150 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5151 | goto out; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5152 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5153 | 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] | 5154 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5155 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 5156 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5157 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5158 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5159 | } |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5160 | |
| 5161 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5162 | SMP_OPT_DIR_REQ, ACT_REPLACE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5163 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5164 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5165 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5166 | } |
| 5167 | 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] | 5168 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5169 | SMP_OPT_DIR_REQ, ACT_REMOVE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5170 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5171 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5172 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5173 | } |
| 5174 | 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] | 5175 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5176 | SMP_OPT_DIR_REQ, ACT_DENY, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5177 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5178 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5179 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5180 | } |
| 5181 | 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] | 5182 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5183 | SMP_OPT_DIR_REQ, ACT_PASS, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5184 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5185 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5186 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5187 | } |
| 5188 | 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] | 5189 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5190 | SMP_OPT_DIR_REQ, ACT_ALLOW, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5191 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5192 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5193 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5194 | } |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 5195 | 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] | 5196 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5197 | SMP_OPT_DIR_REQ, ACT_TARPIT, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5198 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5199 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5200 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 5201 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5202 | else if (!strcmp(args[0], "reqadd")) { /* add request header */ |
Willy Tarreau | f4f0412 | 2010-01-28 18:10:50 +0100 | [diff] [blame] | 5203 | struct cond_wordlist *wl; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5204 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5205 | if (curproxy == &defproxy) { |
| 5206 | 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] | 5207 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5208 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5209 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5210 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5211 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5212 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5213 | if (*(args[1]) == 0) { |
| 5214 | 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] | 5215 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5216 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5217 | } |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5218 | |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 5219 | if ((strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0)) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 5220 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args+2, &errmsg)) == NULL) { |
| 5221 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 5222 | file, linenum, args[0], errmsg); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 5223 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5224 | goto out; |
| 5225 | } |
| 5226 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
| 5227 | } |
| 5228 | else if (*args[2]) { |
| 5229 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 5230 | file, linenum, args[0], args[2]); |
| 5231 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5232 | goto out; |
| 5233 | } |
| 5234 | |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5235 | wl = calloc(1, sizeof(*wl)); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 5236 | wl->cond = cond; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5237 | wl->s = strdup(args[1]); |
| 5238 | LIST_ADDQ(&curproxy->req_add, &wl->list); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 5239 | warnif_misplaced_reqadd(curproxy, file, linenum, args[0]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5240 | } |
| 5241 | 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] | 5242 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5243 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 5244 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5245 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5246 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5247 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5248 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5249 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5250 | SMP_OPT_DIR_RES, ACT_REPLACE, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5251 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5252 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5253 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5254 | } |
| 5255 | else if (!strcmp(args[0], "rspdel")) { /* delete response header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5256 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5257 | SMP_OPT_DIR_RES, ACT_REMOVE, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5258 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5259 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5260 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5261 | } |
| 5262 | else if (!strcmp(args[0], "rspdeny")) { /* block response header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5263 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5264 | SMP_OPT_DIR_RES, ACT_DENY, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5265 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5266 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5267 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5268 | } |
| 5269 | 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] | 5270 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5271 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 5272 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5273 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5274 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5275 | } |
| 5276 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5277 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5278 | SMP_OPT_DIR_RES, ACT_REPLACE, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5279 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5280 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5281 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5282 | } |
| 5283 | 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] | 5284 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5285 | SMP_OPT_DIR_RES, ACT_REMOVE, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5286 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5287 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5288 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5289 | } |
| 5290 | 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] | 5291 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5292 | SMP_OPT_DIR_RES, ACT_DENY, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5293 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5294 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5295 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5296 | } |
| 5297 | else if (!strcmp(args[0], "rspadd")) { /* add response header */ |
Willy Tarreau | f4f0412 | 2010-01-28 18:10:50 +0100 | [diff] [blame] | 5298 | struct cond_wordlist *wl; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5299 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5300 | if (curproxy == &defproxy) { |
| 5301 | 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] | 5302 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5303 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5304 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5305 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5306 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5307 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5308 | if (*(args[1]) == 0) { |
| 5309 | 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] | 5310 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5311 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5312 | } |
| 5313 | |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5314 | if ((strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0)) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 5315 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args+2, &errmsg)) == NULL) { |
| 5316 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 5317 | file, linenum, args[0], errmsg); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5318 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5319 | goto out; |
| 5320 | } |
| 5321 | err_code |= warnif_cond_requires_req(cond, file, linenum); |
| 5322 | } |
| 5323 | else if (*args[2]) { |
| 5324 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 5325 | file, linenum, args[0], args[2]); |
| 5326 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5327 | goto out; |
| 5328 | } |
| 5329 | |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5330 | wl = calloc(1, sizeof(*wl)); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5331 | wl->cond = cond; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5332 | wl->s = strdup(args[1]); |
| 5333 | LIST_ADDQ(&curproxy->rsp_add, &wl->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5334 | } |
| 5335 | else if (!strcmp(args[0], "errorloc") || |
| 5336 | !strcmp(args[0], "errorloc302") || |
| 5337 | !strcmp(args[0], "errorloc303")) { /* error location */ |
| 5338 | int errnum, errlen; |
| 5339 | char *err; |
| 5340 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5341 | 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] | 5342 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5343 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5344 | if (*(args[2]) == 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 5345 | 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] | 5346 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5347 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5348 | } |
| 5349 | |
| 5350 | errnum = atol(args[1]); |
| 5351 | if (!strcmp(args[0], "errorloc303")) { |
| 5352 | err = malloc(strlen(HTTP_303) + strlen(args[2]) + 5); |
| 5353 | errlen = sprintf(err, "%s%s\r\n\r\n", HTTP_303, args[2]); |
| 5354 | } else { |
| 5355 | err = malloc(strlen(HTTP_302) + strlen(args[2]) + 5); |
| 5356 | errlen = sprintf(err, "%s%s\r\n\r\n", HTTP_302, args[2]); |
| 5357 | } |
| 5358 | |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 5359 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) { |
| 5360 | if (http_err_codes[rc] == errnum) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 5361 | chunk_destroy(&curproxy->errmsg[rc]); |
| 5362 | chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 5363 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5364 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5365 | } |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 5366 | |
| 5367 | if (rc >= HTTP_ERR_SIZE) { |
| 5368 | Warning("parsing [%s:%d] : status code %d not handled, error relocation will be ignored.\n", |
| 5369 | file, linenum, errnum); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5370 | free(err); |
| 5371 | } |
| 5372 | } |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5373 | else if (!strcmp(args[0], "errorfile")) { /* error message from a file */ |
| 5374 | int errnum, errlen, fd; |
| 5375 | char *err; |
| 5376 | struct stat stat; |
| 5377 | |
| 5378 | 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] | 5379 | err_code |= ERR_WARN; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5380 | |
| 5381 | if (*(args[2]) == 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 5382 | 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] | 5383 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5384 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5385 | } |
| 5386 | |
| 5387 | fd = open(args[2], O_RDONLY); |
| 5388 | if ((fd < 0) || (fstat(fd, &stat) < 0)) { |
| 5389 | Alert("parsing [%s:%d] : error opening file <%s> for custom error message <%s>.\n", |
| 5390 | file, linenum, args[2], args[1]); |
| 5391 | if (fd >= 0) |
| 5392 | close(fd); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5393 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5394 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5395 | } |
| 5396 | |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 5397 | if (stat.st_size <= global.tune.bufsize) { |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5398 | errlen = stat.st_size; |
| 5399 | } else { |
| 5400 | 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] | 5401 | file, linenum, args[2], global.tune.bufsize); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5402 | err_code |= ERR_WARN; |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 5403 | errlen = global.tune.bufsize; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5404 | } |
| 5405 | |
| 5406 | err = malloc(errlen); /* malloc() must succeed during parsing */ |
| 5407 | errnum = read(fd, err, errlen); |
| 5408 | if (errnum != errlen) { |
| 5409 | Alert("parsing [%s:%d] : error reading file <%s> for custom error message <%s>.\n", |
| 5410 | file, linenum, args[2], args[1]); |
| 5411 | close(fd); |
| 5412 | free(err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5413 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5414 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5415 | } |
| 5416 | close(fd); |
| 5417 | |
| 5418 | errnum = atol(args[1]); |
| 5419 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) { |
| 5420 | if (http_err_codes[rc] == errnum) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 5421 | chunk_destroy(&curproxy->errmsg[rc]); |
| 5422 | chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen); |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5423 | break; |
| 5424 | } |
| 5425 | } |
| 5426 | |
| 5427 | if (rc >= HTTP_ERR_SIZE) { |
| 5428 | Warning("parsing [%s:%d] : status code %d not handled, error customization will be ignored.\n", |
| 5429 | file, linenum, errnum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5430 | err_code |= ERR_WARN; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5431 | free(err); |
| 5432 | } |
| 5433 | } |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5434 | else if (!strcmp(args[0], "compression")) { |
| 5435 | struct comp *comp; |
| 5436 | if (curproxy->comp == NULL) { |
| 5437 | comp = calloc(1, sizeof(struct comp)); |
| 5438 | curproxy->comp = comp; |
| 5439 | } else { |
| 5440 | comp = curproxy->comp; |
| 5441 | } |
| 5442 | |
| 5443 | if (!strcmp(args[1], "algo")) { |
| 5444 | int cur_arg; |
William Lallemand | 8b52bb3 | 2012-11-16 18:06:41 +0100 | [diff] [blame] | 5445 | struct comp_ctx *ctx; |
William Lallemand | 552df67 | 2012-11-07 13:21:47 +0100 | [diff] [blame] | 5446 | |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5447 | cur_arg = 2; |
| 5448 | if (!*args[cur_arg]) { |
| 5449 | Alert("parsing [%s:%d] : '%s' expects <algorithm>\n", |
| 5450 | file, linenum, args[0]); |
| 5451 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5452 | goto out; |
| 5453 | } |
| 5454 | while (*(args[cur_arg])) { |
| 5455 | if (comp_append_algo(comp, args[cur_arg]) < 0) { |
| 5456 | Alert("parsing [%s:%d] : '%s' : '%s' is not a supported algorithm.\n", |
| 5457 | file, linenum, args[0], args[cur_arg]); |
| 5458 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5459 | goto out; |
| 5460 | } |
William Lallemand | 552df67 | 2012-11-07 13:21:47 +0100 | [diff] [blame] | 5461 | if (curproxy->comp->algos->init(&ctx, 9) == 0) { |
| 5462 | curproxy->comp->algos->end(&ctx); |
| 5463 | } else { |
| 5464 | Alert("parsing [%s:%d] : '%s' : Can't init '%s' algorithm.\n", |
| 5465 | file, linenum, args[0], args[cur_arg]); |
| 5466 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5467 | goto out; |
| 5468 | } |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5469 | cur_arg ++; |
| 5470 | continue; |
| 5471 | } |
| 5472 | } |
Willy Tarreau | 70737d1 | 2012-10-27 00:34:28 +0200 | [diff] [blame] | 5473 | else if (!strcmp(args[1], "offload")) { |
| 5474 | comp->offload = 1; |
| 5475 | } |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5476 | else if (!strcmp(args[1], "type")) { |
| 5477 | int cur_arg; |
| 5478 | cur_arg = 2; |
| 5479 | if (!*args[cur_arg]) { |
| 5480 | Alert("parsing [%s:%d] : '%s' expects <type>\n", |
| 5481 | file, linenum, args[0]); |
| 5482 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5483 | goto out; |
| 5484 | } |
| 5485 | while (*(args[cur_arg])) { |
| 5486 | comp_append_type(comp, args[cur_arg]); |
| 5487 | cur_arg ++; |
| 5488 | continue; |
| 5489 | } |
| 5490 | } |
| 5491 | else { |
Willy Tarreau | 70737d1 | 2012-10-27 00:34:28 +0200 | [diff] [blame] | 5492 | Alert("parsing [%s:%d] : '%s' expects 'algo', 'type' or 'offload'\n", |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5493 | file, linenum, args[0]); |
| 5494 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5495 | goto out; |
| 5496 | } |
| 5497 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5498 | else { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 5499 | struct cfg_kw_list *kwl; |
| 5500 | int index; |
| 5501 | |
| 5502 | list_for_each_entry(kwl, &cfg_keywords.list, list) { |
| 5503 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 5504 | if (kwl->kw[index].section != CFG_LISTEN) |
| 5505 | continue; |
| 5506 | if (strcmp(kwl->kw[index].kw, args[0]) == 0) { |
| 5507 | /* prepare error message just in case */ |
Willy Tarreau | 28a47d6 | 2012-09-18 20:02:48 +0200 | [diff] [blame] | 5508 | 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] | 5509 | if (rc < 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 5510 | Alert("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5511 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5512 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 5513 | } |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 5514 | else if (rc > 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 5515 | Warning("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5516 | err_code |= ERR_WARN; |
| 5517 | goto out; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 5518 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5519 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 5520 | } |
| 5521 | } |
| 5522 | } |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5523 | |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5524 | 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] | 5525 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5526 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5527 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5528 | out: |
Willy Tarreau | f4068b6 | 2012-05-08 17:37:49 +0200 | [diff] [blame] | 5529 | free(errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5530 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5531 | } |
| 5532 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5533 | int |
| 5534 | cfg_parse_users(const char *file, int linenum, char **args, int kwm) |
| 5535 | { |
| 5536 | |
| 5537 | int err_code = 0; |
| 5538 | const char *err; |
| 5539 | |
| 5540 | if (!strcmp(args[0], "userlist")) { /* new userlist */ |
| 5541 | struct userlist *newul; |
| 5542 | |
| 5543 | if (!*args[1]) { |
| 5544 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 5545 | file, linenum, args[0]); |
| 5546 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5547 | goto out; |
| 5548 | } |
| 5549 | |
| 5550 | err = invalid_char(args[1]); |
| 5551 | if (err) { |
| 5552 | Alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 5553 | file, linenum, *err, args[0], args[1]); |
| 5554 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5555 | goto out; |
| 5556 | } |
| 5557 | |
| 5558 | for (newul = userlist; newul; newul = newul->next) |
| 5559 | if (!strcmp(newul->name, args[1])) { |
| 5560 | Warning("parsing [%s:%d]: ignoring duplicated userlist '%s'.\n", |
| 5561 | file, linenum, args[1]); |
| 5562 | err_code |= ERR_WARN; |
| 5563 | goto out; |
| 5564 | } |
| 5565 | |
| 5566 | newul = (struct userlist *)calloc(1, sizeof(struct userlist)); |
| 5567 | if (!newul) { |
| 5568 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 5569 | err_code |= ERR_ALERT | ERR_ABORT; |
| 5570 | goto out; |
| 5571 | } |
| 5572 | |
| 5573 | newul->groupusers = calloc(MAX_AUTH_GROUPS, sizeof(char *)); |
| 5574 | newul->name = strdup(args[1]); |
| 5575 | |
| 5576 | if (!newul->groupusers | !newul->name) { |
| 5577 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 5578 | err_code |= ERR_ALERT | ERR_ABORT; |
| 5579 | goto out; |
| 5580 | } |
| 5581 | |
| 5582 | newul->next = userlist; |
| 5583 | userlist = newul; |
| 5584 | |
| 5585 | } else if (!strcmp(args[0], "group")) { /* new group */ |
| 5586 | int cur_arg, i; |
| 5587 | const char *err; |
| 5588 | |
| 5589 | if (!*args[1]) { |
| 5590 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 5591 | file, linenum, args[0]); |
| 5592 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5593 | goto out; |
| 5594 | } |
| 5595 | |
| 5596 | err = invalid_char(args[1]); |
| 5597 | if (err) { |
| 5598 | Alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 5599 | file, linenum, *err, args[0], args[1]); |
| 5600 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5601 | goto out; |
| 5602 | } |
| 5603 | |
| 5604 | for(i = 0; i < userlist->grpcnt; i++) |
| 5605 | if (!strcmp(userlist->groups[i], args[1])) { |
| 5606 | Warning("parsing [%s:%d]: ignoring duplicated group '%s' in userlist '%s'.\n", |
| 5607 | file, linenum, args[1], userlist->name); |
| 5608 | err_code |= ERR_ALERT; |
| 5609 | goto out; |
| 5610 | } |
| 5611 | |
| 5612 | if (userlist->grpcnt >= MAX_AUTH_GROUPS) { |
| 5613 | Alert("parsing [%s:%d]: too many groups (%u) in in userlist '%s' while adding group '%s'.\n", |
| 5614 | file, linenum, MAX_AUTH_GROUPS, userlist->name, args[1]); |
| 5615 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5616 | goto out; |
| 5617 | } |
| 5618 | |
| 5619 | cur_arg = 2; |
| 5620 | |
| 5621 | while (*args[cur_arg]) { |
| 5622 | if (!strcmp(args[cur_arg], "users")) { |
| 5623 | userlist->groupusers[userlist->grpcnt] = strdup(args[cur_arg + 1]); |
| 5624 | cur_arg += 2; |
| 5625 | continue; |
| 5626 | } else { |
| 5627 | Alert("parsing [%s:%d]: '%s' only supports 'users' option.\n", |
| 5628 | file, linenum, args[0]); |
| 5629 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5630 | goto out; |
| 5631 | } |
| 5632 | } |
| 5633 | |
| 5634 | userlist->groups[userlist->grpcnt++] = strdup(args[1]); |
| 5635 | } else if (!strcmp(args[0], "user")) { /* new user */ |
| 5636 | struct auth_users *newuser; |
| 5637 | int cur_arg; |
| 5638 | |
| 5639 | if (!*args[1]) { |
| 5640 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 5641 | file, linenum, args[0]); |
| 5642 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5643 | goto out; |
| 5644 | } |
| 5645 | |
| 5646 | for (newuser = userlist->users; newuser; newuser = newuser->next) |
| 5647 | if (!strcmp(newuser->user, args[1])) { |
| 5648 | Warning("parsing [%s:%d]: ignoring duplicated user '%s' in userlist '%s'.\n", |
| 5649 | file, linenum, args[1], userlist->name); |
| 5650 | err_code |= ERR_ALERT; |
| 5651 | goto out; |
| 5652 | } |
| 5653 | |
| 5654 | newuser = (struct auth_users *)calloc(1, sizeof(struct auth_users)); |
| 5655 | if (!newuser) { |
| 5656 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 5657 | err_code |= ERR_ALERT | ERR_ABORT; |
| 5658 | goto out; |
| 5659 | } |
| 5660 | |
| 5661 | newuser->user = strdup(args[1]); |
| 5662 | |
| 5663 | newuser->next = userlist->users; |
| 5664 | userlist->users = newuser; |
| 5665 | |
| 5666 | cur_arg = 2; |
| 5667 | |
| 5668 | while (*args[cur_arg]) { |
| 5669 | if (!strcmp(args[cur_arg], "password")) { |
| 5670 | #ifndef CONFIG_HAP_CRYPT |
| 5671 | Warning("parsing [%s:%d]: no crypt(3) support compiled, encrypted passwords will not work.\n", |
| 5672 | file, linenum); |
| 5673 | err_code |= ERR_ALERT; |
| 5674 | #endif |
| 5675 | newuser->pass = strdup(args[cur_arg + 1]); |
| 5676 | cur_arg += 2; |
| 5677 | continue; |
| 5678 | } else if (!strcmp(args[cur_arg], "insecure-password")) { |
| 5679 | newuser->pass = strdup(args[cur_arg + 1]); |
| 5680 | newuser->flags |= AU_O_INSECURE; |
| 5681 | cur_arg += 2; |
| 5682 | continue; |
| 5683 | } else if (!strcmp(args[cur_arg], "groups")) { |
Willy Tarreau | b4c06b7 | 2010-02-02 11:28:20 +0100 | [diff] [blame] | 5684 | newuser->u.groups = strdup(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5685 | cur_arg += 2; |
| 5686 | continue; |
| 5687 | } else { |
| 5688 | Alert("parsing [%s:%d]: '%s' only supports 'password', 'insecure-password' and 'groups' options.\n", |
| 5689 | file, linenum, args[0]); |
| 5690 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5691 | goto out; |
| 5692 | } |
| 5693 | } |
| 5694 | } else { |
| 5695 | Alert("parsing [%s:%d]: unknown keyword '%s' in '%s' section\n", file, linenum, args[0], "users"); |
| 5696 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5697 | } |
| 5698 | |
| 5699 | out: |
| 5700 | return err_code; |
| 5701 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5702 | |
| 5703 | /* |
| 5704 | * This function reads and parses the configuration file given in the argument. |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5705 | * Returns the error code, 0 if OK, or any combination of : |
| 5706 | * - ERR_ABORT: must abort ASAP |
| 5707 | * - ERR_FATAL: we can continue parsing but not start the service |
| 5708 | * - ERR_WARN: a warning has been emitted |
| 5709 | * - ERR_ALERT: an alert has been emitted |
| 5710 | * Only the two first ones can stop processing, the two others are just |
| 5711 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5712 | */ |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 5713 | int readcfgfile(const char *file) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5714 | { |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5715 | char thisline[LINESIZE]; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5716 | FILE *f; |
| 5717 | int linenum = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5718 | int confsect = CFG_NONE; |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5719 | int err_code = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5720 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5721 | if ((f=fopen(file,"r")) == NULL) |
| 5722 | return -1; |
| 5723 | |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5724 | while (fgets(thisline, sizeof(thisline), f) != NULL) { |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 5725 | int arg, kwm = KWM_STD; |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5726 | char *end; |
| 5727 | char *args[MAX_LINE_ARGS + 1]; |
| 5728 | char *line = thisline; |
| 5729 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5730 | linenum++; |
| 5731 | |
| 5732 | end = line + strlen(line); |
| 5733 | |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5734 | if (end-line == sizeof(thisline)-1 && *(end-1) != '\n') { |
| 5735 | /* Check if we reached the limit and the last char is not \n. |
| 5736 | * Watch out for the last line without the terminating '\n'! |
| 5737 | */ |
| 5738 | Alert("parsing [%s:%d]: line too long, limit: %d.\n", |
Willy Tarreau | 5e4a6f1 | 2009-04-11 19:42:49 +0200 | [diff] [blame] | 5739 | file, linenum, (int)sizeof(thisline)-1); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5740 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5741 | } |
| 5742 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5743 | /* skip leading spaces */ |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 5744 | while (isspace((unsigned char)*line)) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5745 | line++; |
| 5746 | |
| 5747 | arg = 0; |
| 5748 | args[arg] = line; |
| 5749 | |
| 5750 | while (*line && arg < MAX_LINE_ARGS) { |
| 5751 | /* first, we'll replace \\, \<space>, \#, \r, \n, \t, \xXX with their |
| 5752 | * C equivalent value. Other combinations left unchanged (eg: \1). |
| 5753 | */ |
| 5754 | if (*line == '\\') { |
| 5755 | int skip = 0; |
| 5756 | if (line[1] == ' ' || line[1] == '\\' || line[1] == '#') { |
| 5757 | *line = line[1]; |
| 5758 | skip = 1; |
| 5759 | } |
| 5760 | else if (line[1] == 'r') { |
| 5761 | *line = '\r'; |
| 5762 | skip = 1; |
| 5763 | } |
| 5764 | else if (line[1] == 'n') { |
| 5765 | *line = '\n'; |
| 5766 | skip = 1; |
| 5767 | } |
| 5768 | else if (line[1] == 't') { |
| 5769 | *line = '\t'; |
| 5770 | skip = 1; |
| 5771 | } |
| 5772 | else if (line[1] == 'x') { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5773 | if ((line + 3 < end) && ishex(line[2]) && ishex(line[3])) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5774 | unsigned char hex1, hex2; |
| 5775 | hex1 = toupper(line[2]) - '0'; |
| 5776 | hex2 = toupper(line[3]) - '0'; |
| 5777 | if (hex1 > 9) hex1 -= 'A' - '9' - 1; |
| 5778 | if (hex2 > 9) hex2 -= 'A' - '9' - 1; |
| 5779 | *line = (hex1<<4) + hex2; |
| 5780 | skip = 3; |
| 5781 | } |
| 5782 | else { |
| 5783 | 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] | 5784 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5785 | } |
| 5786 | } |
| 5787 | if (skip) { |
Cyril Bonté | dd1b01d | 2009-12-06 13:43:42 +0100 | [diff] [blame] | 5788 | memmove(line + 1, line + 1 + skip, end - (line + skip)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5789 | end -= skip; |
| 5790 | } |
| 5791 | line++; |
| 5792 | } |
| 5793 | else if (*line == '#' || *line == '\n' || *line == '\r') { |
| 5794 | /* end of string, end of loop */ |
| 5795 | *line = 0; |
| 5796 | break; |
| 5797 | } |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 5798 | else if (isspace((unsigned char)*line)) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5799 | /* a non-escaped space is an argument separator */ |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5800 | *line++ = '\0'; |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 5801 | while (isspace((unsigned char)*line)) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5802 | line++; |
| 5803 | args[++arg] = line; |
| 5804 | } |
| 5805 | else { |
| 5806 | line++; |
| 5807 | } |
| 5808 | } |
| 5809 | |
| 5810 | /* empty line */ |
| 5811 | if (!**args) |
| 5812 | continue; |
| 5813 | |
Willy Tarreau | 7bb651e | 2009-11-09 21:16:53 +0100 | [diff] [blame] | 5814 | if (*line) { |
| 5815 | /* we had to stop due to too many args. |
| 5816 | * Let's terminate the string, print the offending part then cut the |
| 5817 | * last arg. |
| 5818 | */ |
| 5819 | while (*line && *line != '#' && *line != '\n' && *line != '\r') |
| 5820 | line++; |
| 5821 | *line = '\0'; |
| 5822 | |
Krzysztof Piotr Oledzki | 500b8f0 | 2009-12-15 22:34:51 +0100 | [diff] [blame] | 5823 | 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] | 5824 | file, linenum, arg + 1, (long)(args[arg] - thisline + 1), args[arg]); |
Willy Tarreau | 7bb651e | 2009-11-09 21:16:53 +0100 | [diff] [blame] | 5825 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5826 | args[arg] = line; |
| 5827 | } |
| 5828 | |
Willy Tarreau | 540abe4 | 2007-05-02 20:50:16 +0200 | [diff] [blame] | 5829 | /* zero out remaining args and ensure that at least one entry |
| 5830 | * is zeroed out. |
| 5831 | */ |
| 5832 | while (++arg <= MAX_LINE_ARGS) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5833 | args[arg] = line; |
| 5834 | } |
| 5835 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 5836 | /* check for keyword modifiers "no" and "default" */ |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5837 | if (!strcmp(args[0], "no")) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5838 | char *tmp; |
| 5839 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 5840 | kwm = KWM_NO; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5841 | tmp = args[0]; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5842 | for (arg=0; *args[arg+1]; arg++) |
| 5843 | args[arg] = args[arg+1]; // shift args after inversion |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5844 | *tmp = '\0'; // fix the next arg to \0 |
| 5845 | args[arg] = tmp; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5846 | } |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 5847 | else if (!strcmp(args[0], "default")) { |
| 5848 | kwm = KWM_DEF; |
| 5849 | for (arg=0; *args[arg+1]; arg++) |
| 5850 | args[arg] = args[arg+1]; // shift args after inversion |
| 5851 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5852 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5853 | if (kwm != KWM_STD && strcmp(args[0], "option") != 0 && \ |
| 5854 | strcmp(args[0], "log") != 0) { |
| 5855 | 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] | 5856 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5857 | } |
| 5858 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5859 | if (!strcmp(args[0], "listen") || |
| 5860 | !strcmp(args[0], "frontend") || |
| 5861 | !strcmp(args[0], "backend") || |
| 5862 | !strcmp(args[0], "ruleset") || |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5863 | !strcmp(args[0], "defaults")) { /* new proxy */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5864 | confsect = CFG_LISTEN; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 5865 | free(cursection); |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5866 | cursection = strdup(args[0]); |
| 5867 | } |
| 5868 | else if (!strcmp(args[0], "global")) { /* global config */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5869 | confsect = CFG_GLOBAL; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 5870 | free(cursection); |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5871 | cursection = strdup(args[0]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 5872 | } |
| 5873 | else if (!strcmp(args[0], "userlist")) { |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5874 | confsect = CFG_USERLIST; |
| 5875 | free(cursection); |
| 5876 | cursection = strdup(args[0]); |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5877 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 5878 | else if (!strcmp(args[0], "peers")) { |
| 5879 | confsect = CFG_PEERS; |
| 5880 | free(cursection); |
| 5881 | cursection = strdup(args[0]); |
| 5882 | } |
| 5883 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5884 | /* else it's a section keyword */ |
| 5885 | |
| 5886 | switch (confsect) { |
| 5887 | case CFG_LISTEN: |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5888 | err_code |= cfg_parse_listen(file, linenum, args, kwm); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5889 | break; |
| 5890 | case CFG_GLOBAL: |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5891 | err_code |= cfg_parse_global(file, linenum, args, kwm); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5892 | break; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5893 | case CFG_USERLIST: |
| 5894 | err_code |= cfg_parse_users(file, linenum, args, kwm); |
| 5895 | break; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 5896 | case CFG_PEERS: |
| 5897 | err_code |= cfg_parse_peers(file, linenum, args, kwm); |
| 5898 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5899 | default: |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5900 | 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] | 5901 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5902 | } |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5903 | |
| 5904 | if (err_code & ERR_ABORT) |
| 5905 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5906 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 5907 | free(cursection); |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5908 | cursection = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5909 | fclose(f); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5910 | return err_code; |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5911 | } |
| 5912 | |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 5913 | /* |
| 5914 | * Returns the error code, 0 if OK, or any combination of : |
| 5915 | * - ERR_ABORT: must abort ASAP |
| 5916 | * - ERR_FATAL: we can continue parsing but not start the service |
| 5917 | * - ERR_WARN: a warning has been emitted |
| 5918 | * - ERR_ALERT: an alert has been emitted |
| 5919 | * Only the two first ones can stop processing, the two others are just |
| 5920 | * indicators. |
| 5921 | */ |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5922 | int check_config_validity() |
| 5923 | { |
| 5924 | int cfgerr = 0; |
| 5925 | struct proxy *curproxy = NULL; |
| 5926 | struct server *newsrv = NULL; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5927 | struct userlist *curuserlist = NULL; |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 5928 | int err_code = 0; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 5929 | unsigned int next_pxid = 1; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 5930 | struct bind_conf *bind_conf; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5931 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 5932 | bind_conf = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5933 | /* |
| 5934 | * Now, check for the integrity of all that we have collected. |
| 5935 | */ |
| 5936 | |
| 5937 | /* will be needed further to delay some tasks */ |
Willy Tarreau | b0b37bc | 2008-06-23 14:00:57 +0200 | [diff] [blame] | 5938 | tv_update_date(0,1); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5939 | |
Willy Tarreau | 55bc0f8 | 2009-03-15 14:51:53 +0100 | [diff] [blame] | 5940 | /* first, we will invert the proxy list order */ |
| 5941 | curproxy = NULL; |
| 5942 | while (proxy) { |
| 5943 | struct proxy *next; |
| 5944 | |
| 5945 | next = proxy->next; |
| 5946 | proxy->next = curproxy; |
| 5947 | curproxy = proxy; |
| 5948 | if (!next) |
| 5949 | break; |
| 5950 | proxy = next; |
| 5951 | } |
| 5952 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5953 | while (curproxy != NULL) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 5954 | struct switching_rule *rule; |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 5955 | struct server_rule *srule; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5956 | struct sticking_rule *mrule; |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 5957 | struct tcp_rule *trule; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 5958 | struct listener *listener; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 5959 | unsigned int next_id; |
Willy Tarreau | 16a2147 | 2012-11-19 12:39:59 +0100 | [diff] [blame] | 5960 | int nbproc; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 5961 | |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 5962 | if (curproxy->uuid < 0) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 5963 | /* proxy ID not set, use automatic numbering with first |
| 5964 | * spare entry starting with next_pxid. |
| 5965 | */ |
| 5966 | next_pxid = get_next_id(&used_proxy_id, next_pxid); |
| 5967 | curproxy->conf.id.key = curproxy->uuid = next_pxid; |
| 5968 | eb32_insert(&used_proxy_id, &curproxy->conf.id); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 5969 | } |
Krzysztof Piotr Oledzki | df5cb9f | 2010-02-05 20:58:27 +0100 | [diff] [blame] | 5970 | next_pxid++; |
| 5971 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 5972 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5973 | if (curproxy->state == PR_STSTOPPED) { |
Willy Tarreau | da250db | 2008-10-12 12:07:48 +0200 | [diff] [blame] | 5974 | /* ensure we don't keep listeners uselessly bound */ |
| 5975 | stop_proxy(curproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5976 | curproxy = curproxy->next; |
| 5977 | continue; |
| 5978 | } |
| 5979 | |
Willy Tarreau | 16a2147 | 2012-11-19 12:39:59 +0100 | [diff] [blame] | 5980 | /* number of processes this proxy is bound to */ |
| 5981 | nbproc = curproxy->bind_proc ? popcount(curproxy->bind_proc) : global.nbproc; |
| 5982 | |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 5983 | switch (curproxy->mode) { |
| 5984 | case PR_MODE_HEALTH: |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5985 | cfgerr += proxy_cfg_ensure_no_http(curproxy); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 5986 | if (!(curproxy->cap & PR_CAP_FE)) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5987 | Alert("config : %s '%s' cannot be in health mode as it has no frontend capability.\n", |
| 5988 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 5989 | cfgerr++; |
| 5990 | } |
| 5991 | |
| 5992 | if (curproxy->srv != NULL) |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5993 | Warning("config : servers will be ignored for %s '%s'.\n", |
| 5994 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 5995 | break; |
| 5996 | |
| 5997 | case PR_MODE_TCP: |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5998 | cfgerr += proxy_cfg_ensure_no_http(curproxy); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 5999 | break; |
| 6000 | |
| 6001 | case PR_MODE_HTTP: |
Willy Tarreau | a9fb083 | 2009-07-10 20:53:53 +0200 | [diff] [blame] | 6002 | curproxy->acl_requires |= ACL_USE_L7_ANY; |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 6003 | break; |
| 6004 | } |
| 6005 | |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 6006 | if ((curproxy->cap & PR_CAP_BE) && (curproxy->mode != PR_MODE_HEALTH)) { |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6007 | if (curproxy->lbprm.algo & BE_LB_KIND) { |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 6008 | if (curproxy->options & PR_O_TRANSP) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6009 | Alert("config : %s '%s' cannot use both transparent and balance mode.\n", |
| 6010 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 6011 | cfgerr++; |
| 6012 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6013 | #ifdef WE_DONT_SUPPORT_SERVERLESS_LISTENERS |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 6014 | else if (curproxy->srv == NULL) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6015 | Alert("config : %s '%s' needs at least 1 server in balance mode.\n", |
| 6016 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 6017 | cfgerr++; |
| 6018 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6019 | #endif |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 6020 | else if (curproxy->options & PR_O_DISPATCH) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6021 | Warning("config : dispatch address of %s '%s' will be ignored in balance mode.\n", |
| 6022 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6023 | err_code |= ERR_WARN; |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 6024 | } |
| 6025 | } |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 6026 | 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] | 6027 | /* If no LB algo is set in a backend, and we're not in |
| 6028 | * transparent mode, dispatch mode nor proxy mode, we |
| 6029 | * want to use balance roundrobin by default. |
| 6030 | */ |
| 6031 | curproxy->lbprm.algo &= ~BE_LB_ALGO; |
| 6032 | curproxy->lbprm.algo |= BE_LB_ALGO_RR; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6033 | } |
| 6034 | } |
Willy Tarreau | 193cf93 | 2007-09-17 10:17:23 +0200 | [diff] [blame] | 6035 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 6036 | if (curproxy->options & PR_O_DISPATCH) |
| 6037 | curproxy->options &= ~(PR_O_TRANSP | PR_O_HTTP_PROXY); |
| 6038 | else if (curproxy->options & PR_O_HTTP_PROXY) |
| 6039 | curproxy->options &= ~(PR_O_DISPATCH | PR_O_TRANSP); |
| 6040 | else if (curproxy->options & PR_O_TRANSP) |
| 6041 | curproxy->options &= ~(PR_O_DISPATCH | PR_O_HTTP_PROXY); |
Willy Tarreau | 8293658 | 2007-11-30 15:20:09 +0100 | [diff] [blame] | 6042 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 6043 | if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_HTTP_CHK) { |
| 6044 | if (curproxy->options & PR_O_DISABLE404) { |
| 6045 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n", |
| 6046 | "disable-on-404", proxy_type_str(curproxy), curproxy->id); |
| 6047 | err_code |= ERR_WARN; |
| 6048 | curproxy->options &= ~PR_O_DISABLE404; |
| 6049 | } |
| 6050 | if (curproxy->options2 & PR_O2_CHK_SNDST) { |
| 6051 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n", |
| 6052 | "send-state", proxy_type_str(curproxy), curproxy->id); |
| 6053 | err_code |= ERR_WARN; |
| 6054 | curproxy->options &= ~PR_O2_CHK_SNDST; |
| 6055 | } |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 6056 | } |
| 6057 | |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 6058 | /* if a default backend was specified, let's find it */ |
| 6059 | if (curproxy->defbe.name) { |
| 6060 | struct proxy *target; |
| 6061 | |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 6062 | target = findproxy_mode(curproxy->defbe.name, curproxy->mode, PR_CAP_BE); |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6063 | if (!target) { |
| 6064 | Alert("Proxy '%s': unable to find required default_backend: '%s'.\n", |
| 6065 | curproxy->id, curproxy->defbe.name); |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 6066 | cfgerr++; |
| 6067 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6068 | Alert("Proxy '%s': loop detected for default_backend: '%s'.\n", |
| 6069 | curproxy->id, curproxy->defbe.name); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6070 | cfgerr++; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 6071 | } else { |
| 6072 | free(curproxy->defbe.name); |
| 6073 | curproxy->defbe.be = target; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 6074 | /* we force the backend to be present on at least all of |
| 6075 | * the frontend's processes. |
| 6076 | */ |
| 6077 | target->bind_proc = curproxy->bind_proc ? |
| 6078 | (target->bind_proc | curproxy->bind_proc) : 0; |
Willy Tarreau | ff67813 | 2012-02-13 14:32:34 +0100 | [diff] [blame] | 6079 | |
| 6080 | /* Emit a warning if this proxy also has some servers */ |
| 6081 | if (curproxy->srv) { |
| 6082 | Warning("In proxy '%s', the 'default_backend' rule always has precedence over the servers, which will never be used.\n", |
| 6083 | curproxy->id); |
| 6084 | err_code |= ERR_WARN; |
| 6085 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6086 | } |
| 6087 | } |
| 6088 | |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 6089 | /* find the target proxy in setbe */ |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 6090 | if (curproxy->mode == PR_MODE_HTTP && curproxy->req_exp != NULL) { |
| 6091 | /* map jump target for ACT_SETBE in req_rep chain */ |
| 6092 | struct hdr_exp *exp; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 6093 | for (exp = curproxy->req_exp; exp != NULL; exp = exp->next) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6094 | struct proxy *target; |
| 6095 | |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 6096 | if (exp->action != ACT_SETBE) |
| 6097 | continue; |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6098 | |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 6099 | target = findproxy_mode(exp->replace, PR_MODE_HTTP, PR_CAP_BE); |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6100 | if (!target) { |
| 6101 | Alert("Proxy '%s': unable to find required setbe: '%s'.\n", |
| 6102 | curproxy->id, exp->replace); |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 6103 | cfgerr++; |
| 6104 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6105 | Alert("Proxy '%s': loop detected for setbe: '%s'.\n", |
| 6106 | curproxy->id, exp->replace); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 6107 | cfgerr++; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 6108 | } else { |
| 6109 | free((void *)exp->replace); |
| 6110 | exp->replace = (const char *)target; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 6111 | /* we force the backend to be present on at least all of |
| 6112 | * the frontend's processes. |
| 6113 | */ |
| 6114 | target->bind_proc = curproxy->bind_proc ? |
| 6115 | (target->bind_proc | curproxy->bind_proc) : 0; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 6116 | } |
| 6117 | } |
| 6118 | } |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6119 | |
| 6120 | /* find the target proxy for 'use_backend' rules */ |
| 6121 | list_for_each_entry(rule, &curproxy->switching_rules, list) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6122 | struct proxy *target; |
| 6123 | |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 6124 | target = findproxy_mode(rule->be.name, curproxy->mode, PR_CAP_BE); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6125 | |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6126 | if (!target) { |
| 6127 | Alert("Proxy '%s': unable to find required use_backend: '%s'.\n", |
| 6128 | curproxy->id, rule->be.name); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6129 | cfgerr++; |
| 6130 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6131 | Alert("Proxy '%s': loop detected for use_backend: '%s'.\n", |
| 6132 | curproxy->id, rule->be.name); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6133 | cfgerr++; |
| 6134 | } else { |
| 6135 | free((void *)rule->be.name); |
| 6136 | rule->be.backend = target; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 6137 | /* we force the backend to be present on at least all of |
| 6138 | * the frontend's processes. |
| 6139 | */ |
| 6140 | target->bind_proc = curproxy->bind_proc ? |
| 6141 | (target->bind_proc | curproxy->bind_proc) : 0; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6142 | } |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 6143 | } |
| 6144 | |
| 6145 | /* find the target proxy for 'use_backend' rules */ |
| 6146 | list_for_each_entry(srule, &curproxy->server_rules, list) { |
| 6147 | struct server *target = findserver(curproxy, srule->srv.name); |
| 6148 | |
| 6149 | if (!target) { |
| 6150 | Alert("config : %s '%s' : unable to find server '%s' referenced in a 'use-server' rule.\n", |
| 6151 | proxy_type_str(curproxy), curproxy->id, srule->srv.name); |
| 6152 | cfgerr++; |
| 6153 | continue; |
| 6154 | } |
| 6155 | free((void *)srule->srv.name); |
| 6156 | srule->srv.ptr = target; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6157 | } |
| 6158 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6159 | /* find the target table for 'stick' rules */ |
| 6160 | list_for_each_entry(mrule, &curproxy->sticking_rules, list) { |
| 6161 | struct proxy *target; |
| 6162 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 6163 | curproxy->be_req_ana |= AN_REQ_STICKING_RULES; |
| 6164 | if (mrule->flags & STK_IS_STORE) |
| 6165 | curproxy->be_rsp_ana |= AN_RES_STORE_RULES; |
| 6166 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6167 | if (mrule->table.name) |
Willy Tarreau | c00cdc2 | 2010-06-06 16:48:26 +0200 | [diff] [blame] | 6168 | target = findproxy(mrule->table.name, 0); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6169 | else |
| 6170 | target = curproxy; |
| 6171 | |
| 6172 | if (!target) { |
| 6173 | Alert("Proxy '%s': unable to find stick-table '%s'.\n", |
| 6174 | curproxy->id, mrule->table.name); |
| 6175 | cfgerr++; |
| 6176 | } |
| 6177 | else if (target->table.size == 0) { |
| 6178 | Alert("Proxy '%s': stick-table '%s' used but not configured.\n", |
| 6179 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 6180 | cfgerr++; |
| 6181 | } |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 6182 | else if (!stktable_compatible_sample(mrule->expr, target->table.type)) { |
| 6183 | 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] | 6184 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 6185 | cfgerr++; |
| 6186 | } |
| 6187 | else { |
| 6188 | free((void *)mrule->table.name); |
| 6189 | mrule->table.t = &(target->table); |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 6190 | stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID, NULL); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6191 | } |
| 6192 | } |
| 6193 | |
| 6194 | /* find the target table for 'store response' rules */ |
| 6195 | list_for_each_entry(mrule, &curproxy->storersp_rules, list) { |
| 6196 | struct proxy *target; |
| 6197 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 6198 | curproxy->be_rsp_ana |= AN_RES_STORE_RULES; |
| 6199 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6200 | if (mrule->table.name) |
Willy Tarreau | c00cdc2 | 2010-06-06 16:48:26 +0200 | [diff] [blame] | 6201 | target = findproxy(mrule->table.name, 0); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6202 | else |
| 6203 | target = curproxy; |
| 6204 | |
| 6205 | if (!target) { |
| 6206 | Alert("Proxy '%s': unable to find store table '%s'.\n", |
| 6207 | curproxy->id, mrule->table.name); |
| 6208 | cfgerr++; |
| 6209 | } |
| 6210 | else if (target->table.size == 0) { |
| 6211 | Alert("Proxy '%s': stick-table '%s' used but not configured.\n", |
| 6212 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 6213 | cfgerr++; |
| 6214 | } |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 6215 | else if (!stktable_compatible_sample(mrule->expr, target->table.type)) { |
| 6216 | 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] | 6217 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 6218 | cfgerr++; |
| 6219 | } |
| 6220 | else { |
| 6221 | free((void *)mrule->table.name); |
| 6222 | mrule->table.t = &(target->table); |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 6223 | stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID, NULL); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6224 | } |
| 6225 | } |
| 6226 | |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 6227 | /* find the target table for 'tcp-request' layer 4 rules */ |
| 6228 | list_for_each_entry(trule, &curproxy->tcp_req.l4_rules, list) { |
| 6229 | struct proxy *target; |
| 6230 | |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6231 | 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] | 6232 | continue; |
| 6233 | |
| 6234 | if (trule->act_prm.trk_ctr.table.n) |
| 6235 | target = findproxy(trule->act_prm.trk_ctr.table.n, 0); |
| 6236 | else |
| 6237 | target = curproxy; |
| 6238 | |
| 6239 | if (!target) { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6240 | Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n", |
| 6241 | curproxy->id, trule->act_prm.trk_ctr.table.n, |
| 6242 | trule->action == TCP_ACT_TRK_SC1 ? 1 : 2); |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 6243 | cfgerr++; |
| 6244 | } |
| 6245 | else if (target->table.size == 0) { |
| 6246 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
| 6247 | curproxy->id, trule->act_prm.trk_ctr.table.n ? trule->act_prm.trk_ctr.table.n : curproxy->id); |
| 6248 | cfgerr++; |
| 6249 | } |
| 6250 | else if (trule->act_prm.trk_ctr.type != target->table.type) { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6251 | Alert("Proxy '%s': type of tracking key for sticky counter not usable with type of stick-table '%s'.\n", |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 6252 | curproxy->id, trule->act_prm.trk_ctr.table.n ? trule->act_prm.trk_ctr.table.n : curproxy->id); |
| 6253 | cfgerr++; |
| 6254 | } |
| 6255 | else { |
| 6256 | free(trule->act_prm.trk_ctr.table.n); |
| 6257 | trule->act_prm.trk_ctr.table.t = &target->table; |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6258 | /* 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] | 6259 | * to pass a list of counters to track and allocate them right here using |
| 6260 | * stktable_alloc_data_type(). |
| 6261 | */ |
| 6262 | } |
| 6263 | } |
| 6264 | |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 6265 | /* find the target table for 'tcp-request' layer 6 rules */ |
| 6266 | list_for_each_entry(trule, &curproxy->tcp_req.inspect_rules, list) { |
| 6267 | struct proxy *target; |
| 6268 | |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6269 | 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] | 6270 | continue; |
| 6271 | |
| 6272 | if (trule->act_prm.trk_ctr.table.n) |
| 6273 | target = findproxy(trule->act_prm.trk_ctr.table.n, 0); |
| 6274 | else |
| 6275 | target = curproxy; |
| 6276 | |
| 6277 | if (!target) { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6278 | Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n", |
| 6279 | curproxy->id, trule->act_prm.trk_ctr.table.n, |
| 6280 | trule->action == TCP_ACT_TRK_SC1 ? 1 : 2); |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 6281 | cfgerr++; |
| 6282 | } |
| 6283 | else if (target->table.size == 0) { |
| 6284 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
| 6285 | curproxy->id, trule->act_prm.trk_ctr.table.n ? trule->act_prm.trk_ctr.table.n : curproxy->id); |
| 6286 | cfgerr++; |
| 6287 | } |
| 6288 | else if (trule->act_prm.trk_ctr.type != target->table.type) { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6289 | Alert("Proxy '%s': type of tracking key for sticky counter not usable with type of stick-table '%s'.\n", |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 6290 | curproxy->id, trule->act_prm.trk_ctr.table.n ? trule->act_prm.trk_ctr.table.n : curproxy->id); |
| 6291 | cfgerr++; |
| 6292 | } |
| 6293 | else { |
| 6294 | free(trule->act_prm.trk_ctr.table.n); |
| 6295 | trule->act_prm.trk_ctr.table.t = &target->table; |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6296 | /* 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] | 6297 | * to pass a list of counters to track and allocate them right here using |
| 6298 | * stktable_alloc_data_type(). |
| 6299 | */ |
| 6300 | } |
| 6301 | } |
| 6302 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 6303 | if (curproxy->table.peers.name) { |
| 6304 | struct peers *curpeers = peers; |
| 6305 | |
| 6306 | for (curpeers = peers; curpeers; curpeers = curpeers->next) { |
| 6307 | if (strcmp(curpeers->id, curproxy->table.peers.name) == 0) { |
| 6308 | free((void *)curproxy->table.peers.name); |
| 6309 | curproxy->table.peers.p = peers; |
| 6310 | break; |
| 6311 | } |
| 6312 | } |
| 6313 | |
| 6314 | if (!curpeers) { |
| 6315 | Alert("Proxy '%s': unable to find sync peers '%s'.\n", |
| 6316 | curproxy->id, curproxy->table.peers.name); |
Willy Tarreau | d66bf96 | 2011-10-28 14:16:49 +0200 | [diff] [blame] | 6317 | free((void *)curproxy->table.peers.name); |
| 6318 | curproxy->table.peers.p = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 6319 | cfgerr++; |
| 6320 | } |
| 6321 | else if (!curpeers->peers_fe) { |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 6322 | Alert("Proxy '%s': unable to find local peer '%s' in peers section '%s'.\n", |
| 6323 | curproxy->id, localpeer, curpeers->id); |
Willy Tarreau | d66bf96 | 2011-10-28 14:16:49 +0200 | [diff] [blame] | 6324 | curproxy->table.peers.p = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 6325 | cfgerr++; |
| 6326 | } |
| 6327 | } |
| 6328 | |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 6329 | if (curproxy->uri_auth && !(curproxy->uri_auth->flags & ST_CONVDONE) && |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 6330 | !LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) && |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6331 | (curproxy->uri_auth->userlist || curproxy->uri_auth->auth_realm )) { |
| 6332 | Alert("%s '%s': stats 'auth'/'realm' and 'http-request' can't be used at the same time.\n", |
| 6333 | "proxy", curproxy->id); |
| 6334 | cfgerr++; |
| 6335 | goto out_uri_auth_compat; |
| 6336 | } |
| 6337 | |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 6338 | 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] | 6339 | const char *uri_auth_compat_req[10]; |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 6340 | struct http_req_rule *rule; |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6341 | int i = 0; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6342 | |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6343 | /* build the ACL condition from scratch. We're relying on anonymous ACLs for that */ |
| 6344 | uri_auth_compat_req[i++] = "auth"; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6345 | |
| 6346 | if (curproxy->uri_auth->auth_realm) { |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6347 | uri_auth_compat_req[i++] = "realm"; |
| 6348 | uri_auth_compat_req[i++] = curproxy->uri_auth->auth_realm; |
| 6349 | } |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6350 | |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6351 | uri_auth_compat_req[i++] = "unless"; |
| 6352 | uri_auth_compat_req[i++] = "{"; |
| 6353 | uri_auth_compat_req[i++] = "http_auth(.internal-stats-userlist)"; |
| 6354 | uri_auth_compat_req[i++] = "}"; |
| 6355 | uri_auth_compat_req[i++] = ""; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6356 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 6357 | rule = parse_http_req_cond(uri_auth_compat_req, "internal-stats-auth-compat", 0, curproxy); |
| 6358 | if (!rule) { |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6359 | cfgerr++; |
| 6360 | break; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6361 | } |
| 6362 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 6363 | LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list); |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6364 | |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6365 | if (curproxy->uri_auth->auth_realm) { |
| 6366 | free(curproxy->uri_auth->auth_realm); |
| 6367 | curproxy->uri_auth->auth_realm = NULL; |
| 6368 | } |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 6369 | |
| 6370 | curproxy->uri_auth->flags |= ST_CONVDONE; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6371 | } |
| 6372 | out_uri_auth_compat: |
| 6373 | |
Krzysztof Piotr Oledzki | f9423ae | 2010-01-29 19:26:18 +0100 | [diff] [blame] | 6374 | cfgerr += acl_find_targets(curproxy); |
| 6375 | |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 6376 | if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) && |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6377 | (((curproxy->cap & PR_CAP_FE) && !curproxy->timeout.client) || |
Willy Tarreau | d825eef | 2007-05-12 22:35:00 +0200 | [diff] [blame] | 6378 | ((curproxy->cap & PR_CAP_BE) && (curproxy->srv) && |
Willy Tarreau | ce887fd | 2012-05-12 12:50:00 +0200 | [diff] [blame] | 6379 | (!curproxy->timeout.connect || |
| 6380 | (!curproxy->timeout.server && (curproxy->mode == PR_MODE_HTTP || !curproxy->timeout.tunnel)))))) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6381 | Warning("config : missing timeouts for %s '%s'.\n" |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 6382 | " | While not properly invalid, you will certainly encounter various problems\n" |
| 6383 | " | 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] | 6384 | " | timeouts are set to a non-zero value: 'client', 'connect', 'server'.\n", |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6385 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6386 | err_code |= ERR_WARN; |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 6387 | } |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 6388 | |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6389 | /* Historically, the tarpit and queue timeouts were inherited from contimeout. |
| 6390 | * We must still support older configurations, so let's find out whether those |
| 6391 | * parameters have been set or must be copied from contimeouts. |
| 6392 | */ |
| 6393 | if (curproxy != &defproxy) { |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6394 | if (!curproxy->timeout.tarpit || |
| 6395 | curproxy->timeout.tarpit == defproxy.timeout.tarpit) { |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6396 | /* tarpit timeout not set. We search in the following order: |
| 6397 | * default.tarpit, curr.connect, default.connect. |
| 6398 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6399 | if (defproxy.timeout.tarpit) |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6400 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6401 | else if (curproxy->timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6402 | curproxy->timeout.tarpit = curproxy->timeout.connect; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6403 | else if (defproxy.timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6404 | curproxy->timeout.tarpit = defproxy.timeout.connect; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6405 | } |
| 6406 | if ((curproxy->cap & PR_CAP_BE) && |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6407 | (!curproxy->timeout.queue || |
| 6408 | curproxy->timeout.queue == defproxy.timeout.queue)) { |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6409 | /* queue timeout not set. We search in the following order: |
| 6410 | * default.queue, curr.connect, default.connect. |
| 6411 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6412 | if (defproxy.timeout.queue) |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6413 | curproxy->timeout.queue = defproxy.timeout.queue; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6414 | else if (curproxy->timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6415 | curproxy->timeout.queue = curproxy->timeout.connect; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6416 | else if (defproxy.timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6417 | curproxy->timeout.queue = defproxy.timeout.connect; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6418 | } |
| 6419 | } |
| 6420 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 6421 | if ((curproxy->options2 & PR_O2_CHK_ANY) == PR_O2_SSL3_CHK) { |
Willy Tarreau | 137325d | 2010-02-01 16:38:17 +0100 | [diff] [blame] | 6422 | curproxy->check_len = sizeof(sslv3_client_hello_pkt) - 1; |
| 6423 | curproxy->check_req = (char *)malloc(curproxy->check_len); |
| 6424 | memcpy(curproxy->check_req, sslv3_client_hello_pkt, curproxy->check_len); |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 6425 | } |
| 6426 | |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 6427 | /* The small pools required for the capture lists */ |
Willy Tarreau | 9a54e13 | 2012-03-24 08:33:05 +0100 | [diff] [blame] | 6428 | if (curproxy->nb_req_cap) { |
| 6429 | if (curproxy->mode == PR_MODE_HTTP) { |
| 6430 | curproxy->req_cap_pool = create_pool("ptrcap", |
| 6431 | curproxy->nb_req_cap * sizeof(char *), |
| 6432 | MEM_F_SHARED); |
| 6433 | } else { |
| 6434 | Warning("config : 'capture request header' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6435 | proxy_type_str(curproxy), curproxy->id); |
| 6436 | err_code |= ERR_WARN; |
| 6437 | curproxy->to_log &= ~LW_REQHDR; |
| 6438 | curproxy->nb_req_cap = 0; |
| 6439 | } |
| 6440 | } |
| 6441 | |
| 6442 | if (curproxy->nb_rsp_cap) { |
| 6443 | if (curproxy->mode == PR_MODE_HTTP) { |
| 6444 | curproxy->rsp_cap_pool = create_pool("ptrcap", |
| 6445 | curproxy->nb_rsp_cap * sizeof(char *), |
| 6446 | MEM_F_SHARED); |
| 6447 | } else { |
| 6448 | Warning("config : 'capture response header' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6449 | proxy_type_str(curproxy), curproxy->id); |
| 6450 | err_code |= ERR_WARN; |
| 6451 | curproxy->to_log &= ~LW_REQHDR; |
| 6452 | curproxy->nb_rsp_cap = 0; |
| 6453 | } |
| 6454 | } |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 6455 | |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 6456 | /* compile the log format */ |
Willy Tarreau | 99a7ca2 | 2012-05-31 19:39:23 +0200 | [diff] [blame] | 6457 | if (!(curproxy->cap & PR_CAP_FE)) { |
| 6458 | if (curproxy->logformat_string != default_http_log_format && |
| 6459 | curproxy->logformat_string != default_tcp_log_format && |
| 6460 | curproxy->logformat_string != clf_http_log_format) |
| 6461 | free(curproxy->logformat_string); |
| 6462 | curproxy->logformat_string = NULL; |
| 6463 | } |
| 6464 | |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 6465 | if (curproxy->logformat_string) |
| 6466 | parse_logformat_string(curproxy->logformat_string, curproxy, &curproxy->logformat, curproxy->mode); |
| 6467 | |
| 6468 | if (curproxy->uniqueid_format_string) |
| 6469 | parse_logformat_string(curproxy->uniqueid_format_string, curproxy, &curproxy->format_unique_id, PR_MODE_HTTP); |
| 6470 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6471 | /* first, we will invert the servers list order */ |
| 6472 | newsrv = NULL; |
| 6473 | while (curproxy->srv) { |
| 6474 | struct server *next; |
| 6475 | |
| 6476 | next = curproxy->srv->next; |
| 6477 | curproxy->srv->next = newsrv; |
| 6478 | newsrv = curproxy->srv; |
| 6479 | if (!next) |
| 6480 | break; |
| 6481 | curproxy->srv = next; |
| 6482 | } |
| 6483 | |
Willy Tarreau | dd70165 | 2010-05-25 23:03:02 +0200 | [diff] [blame] | 6484 | /* assign automatic UIDs to servers which don't have one yet */ |
| 6485 | next_id = 1; |
| 6486 | newsrv = curproxy->srv; |
| 6487 | while (newsrv != NULL) { |
| 6488 | if (!newsrv->puid) { |
| 6489 | /* server ID not set, use automatic numbering with first |
| 6490 | * spare entry starting with next_svid. |
| 6491 | */ |
| 6492 | next_id = get_next_id(&curproxy->conf.used_server_id, next_id); |
| 6493 | newsrv->conf.id.key = newsrv->puid = next_id; |
| 6494 | eb32_insert(&curproxy->conf.used_server_id, &newsrv->conf.id); |
| 6495 | } |
| 6496 | next_id++; |
| 6497 | newsrv = newsrv->next; |
| 6498 | } |
| 6499 | |
Willy Tarreau | 2069704 | 2007-11-15 23:26:18 +0100 | [diff] [blame] | 6500 | curproxy->lbprm.wmult = 1; /* default weight multiplier */ |
Willy Tarreau | 5dc2fa6 | 2007-11-19 19:10:18 +0100 | [diff] [blame] | 6501 | curproxy->lbprm.wdiv = 1; /* default weight divider */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6502 | |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 6503 | /* |
| 6504 | * If this server supports a maxconn parameter, it needs a dedicated |
| 6505 | * tasks to fill the emptied slots when a connection leaves. |
| 6506 | * Also, resolve deferred tracking dependency if needed. |
| 6507 | */ |
| 6508 | newsrv = curproxy->srv; |
| 6509 | while (newsrv != NULL) { |
| 6510 | if (newsrv->minconn > newsrv->maxconn) { |
| 6511 | /* Only 'minconn' was specified, or it was higher than or equal |
| 6512 | * to 'maxconn'. Let's turn this into maxconn and clean it, as |
| 6513 | * this will avoid further useless expensive computations. |
| 6514 | */ |
| 6515 | newsrv->maxconn = newsrv->minconn; |
| 6516 | } else if (newsrv->maxconn && !newsrv->minconn) { |
| 6517 | /* minconn was not specified, so we set it to maxconn */ |
| 6518 | newsrv->minconn = newsrv->maxconn; |
| 6519 | } |
| 6520 | |
Emeric Brun | 01f8e2f | 2012-05-18 16:02:00 +0200 | [diff] [blame] | 6521 | #ifdef USE_OPENSSL |
Emeric Brun | 94324a4 | 2012-10-11 14:00:19 +0200 | [diff] [blame] | 6522 | if (newsrv->use_ssl || newsrv->check.use_ssl) |
| 6523 | cfgerr += ssl_sock_prepare_srv_ctx(newsrv, curproxy); |
Emeric Brun | 01f8e2f | 2012-05-18 16:02:00 +0200 | [diff] [blame] | 6524 | #endif /* USE_OPENSSL */ |
Emeric Brun | 94324a4 | 2012-10-11 14:00:19 +0200 | [diff] [blame] | 6525 | |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 6526 | if (newsrv->trackit) { |
| 6527 | struct proxy *px; |
| 6528 | struct server *srv; |
| 6529 | char *pname, *sname; |
| 6530 | |
| 6531 | pname = newsrv->trackit; |
| 6532 | sname = strrchr(pname, '/'); |
| 6533 | |
| 6534 | if (sname) |
| 6535 | *sname++ = '\0'; |
| 6536 | else { |
| 6537 | sname = pname; |
| 6538 | pname = NULL; |
| 6539 | } |
| 6540 | |
| 6541 | if (pname) { |
| 6542 | px = findproxy(pname, PR_CAP_BE); |
| 6543 | if (!px) { |
| 6544 | Alert("config : %s '%s', server '%s': unable to find required proxy '%s' for tracking.\n", |
| 6545 | proxy_type_str(curproxy), curproxy->id, |
| 6546 | newsrv->id, pname); |
| 6547 | cfgerr++; |
| 6548 | goto next_srv; |
| 6549 | } |
| 6550 | } else |
| 6551 | px = curproxy; |
| 6552 | |
| 6553 | srv = findserver(px, sname); |
| 6554 | if (!srv) { |
| 6555 | Alert("config : %s '%s', server '%s': unable to find required server '%s' for tracking.\n", |
| 6556 | proxy_type_str(curproxy), curproxy->id, |
| 6557 | newsrv->id, sname); |
| 6558 | cfgerr++; |
| 6559 | goto next_srv; |
| 6560 | } |
| 6561 | |
| 6562 | if (!(srv->state & SRV_CHECKED)) { |
| 6563 | Alert("config : %s '%s', server '%s': unable to use %s/%s for " |
| 6564 | "tracking as it does not have checks enabled.\n", |
| 6565 | proxy_type_str(curproxy), curproxy->id, |
| 6566 | newsrv->id, px->id, srv->id); |
| 6567 | cfgerr++; |
| 6568 | goto next_srv; |
| 6569 | } |
| 6570 | |
| 6571 | if (curproxy != px && |
| 6572 | (curproxy->options & PR_O_DISABLE404) != (px->options & PR_O_DISABLE404)) { |
| 6573 | Alert("config : %s '%s', server '%s': unable to use %s/%s for" |
| 6574 | "tracking: disable-on-404 option inconsistency.\n", |
| 6575 | proxy_type_str(curproxy), curproxy->id, |
| 6576 | newsrv->id, px->id, srv->id); |
| 6577 | cfgerr++; |
| 6578 | goto next_srv; |
| 6579 | } |
| 6580 | |
| 6581 | /* if the other server is forced disabled, we have to do the same here */ |
| 6582 | if (srv->state & SRV_MAINTAIN) { |
| 6583 | newsrv->state |= SRV_MAINTAIN; |
| 6584 | newsrv->state &= ~SRV_RUNNING; |
| 6585 | newsrv->health = 0; |
| 6586 | } |
| 6587 | |
| 6588 | newsrv->track = srv; |
| 6589 | newsrv->tracknext = srv->tracknext; |
| 6590 | srv->tracknext = newsrv; |
| 6591 | |
| 6592 | free(newsrv->trackit); |
| 6593 | newsrv->trackit = NULL; |
| 6594 | } |
| 6595 | next_srv: |
| 6596 | newsrv = newsrv->next; |
| 6597 | } |
| 6598 | |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6599 | /* We have to initialize the server lookup mechanism depending |
| 6600 | * on what LB algorithm was choosen. |
| 6601 | */ |
| 6602 | |
| 6603 | curproxy->lbprm.algo &= ~(BE_LB_LKUP | BE_LB_PROP_DYN); |
| 6604 | switch (curproxy->lbprm.algo & BE_LB_KIND) { |
| 6605 | case BE_LB_KIND_RR: |
Willy Tarreau | 9757a38 | 2009-10-03 12:56:50 +0200 | [diff] [blame] | 6606 | if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_RR_STATIC) { |
| 6607 | curproxy->lbprm.algo |= BE_LB_LKUP_MAP; |
| 6608 | init_server_map(curproxy); |
| 6609 | } else { |
| 6610 | curproxy->lbprm.algo |= BE_LB_LKUP_RRTREE | BE_LB_PROP_DYN; |
| 6611 | fwrr_init_server_groups(curproxy); |
| 6612 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6613 | break; |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 6614 | |
Willy Tarreau | 3ebb116 | 2012-02-13 16:57:44 +0100 | [diff] [blame] | 6615 | case BE_LB_KIND_CB: |
Willy Tarreau | f09c660 | 2012-02-13 17:12:08 +0100 | [diff] [blame] | 6616 | if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_CB_LC) { |
| 6617 | curproxy->lbprm.algo |= BE_LB_LKUP_LCTREE | BE_LB_PROP_DYN; |
| 6618 | fwlc_init_server_tree(curproxy); |
| 6619 | } else { |
| 6620 | curproxy->lbprm.algo |= BE_LB_LKUP_FSTREE | BE_LB_PROP_DYN; |
| 6621 | fas_init_server_tree(curproxy); |
| 6622 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6623 | break; |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 6624 | |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6625 | case BE_LB_KIND_HI: |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 6626 | if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS) { |
| 6627 | curproxy->lbprm.algo |= BE_LB_LKUP_CHTREE | BE_LB_PROP_DYN; |
| 6628 | chash_init_server_tree(curproxy); |
| 6629 | } else { |
| 6630 | curproxy->lbprm.algo |= BE_LB_LKUP_MAP; |
| 6631 | init_server_map(curproxy); |
| 6632 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6633 | break; |
| 6634 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6635 | |
| 6636 | if (curproxy->options & PR_O_LOGASAP) |
| 6637 | curproxy->to_log &= ~LW_BYTES; |
| 6638 | |
Willy Tarreau | e7ded1f | 2009-08-09 10:11:45 +0200 | [diff] [blame] | 6639 | if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) && |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6640 | (curproxy->cap & PR_CAP_FE) && curproxy->to_log && LIST_ISEMPTY(&curproxy->logsrvs)) { |
Willy Tarreau | e7ded1f | 2009-08-09 10:11:45 +0200 | [diff] [blame] | 6641 | Warning("config : log format ignored for %s '%s' since it has no log address.\n", |
| 6642 | proxy_type_str(curproxy), curproxy->id); |
| 6643 | err_code |= ERR_WARN; |
| 6644 | } |
| 6645 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 6646 | if (curproxy->mode != PR_MODE_HTTP) { |
| 6647 | int optnum; |
| 6648 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 6649 | if (curproxy->uri_auth) { |
| 6650 | Warning("config : 'stats' statement ignored for %s '%s' as it requires HTTP mode.\n", |
| 6651 | proxy_type_str(curproxy), curproxy->id); |
| 6652 | err_code |= ERR_WARN; |
| 6653 | curproxy->uri_auth = NULL; |
| 6654 | } |
| 6655 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 6656 | if (curproxy->options & (PR_O_FWDFOR | PR_O_FF_ALWAYS)) { |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 6657 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6658 | "forwardfor", proxy_type_str(curproxy), curproxy->id); |
| 6659 | err_code |= ERR_WARN; |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 6660 | curproxy->options &= ~(PR_O_FWDFOR | PR_O_FF_ALWAYS); |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 6661 | } |
| 6662 | |
| 6663 | if (curproxy->options & PR_O_ORGTO) { |
| 6664 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6665 | "originalto", proxy_type_str(curproxy), curproxy->id); |
| 6666 | err_code |= ERR_WARN; |
| 6667 | curproxy->options &= ~PR_O_ORGTO; |
| 6668 | } |
| 6669 | |
| 6670 | for (optnum = 0; cfg_opts[optnum].name; optnum++) { |
| 6671 | if (cfg_opts[optnum].mode == PR_MODE_HTTP && |
| 6672 | (curproxy->cap & cfg_opts[optnum].cap) && |
| 6673 | (curproxy->options & cfg_opts[optnum].val)) { |
| 6674 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6675 | cfg_opts[optnum].name, proxy_type_str(curproxy), curproxy->id); |
| 6676 | err_code |= ERR_WARN; |
| 6677 | curproxy->options &= ~cfg_opts[optnum].val; |
| 6678 | } |
| 6679 | } |
| 6680 | |
| 6681 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) { |
| 6682 | if (cfg_opts2[optnum].mode == PR_MODE_HTTP && |
| 6683 | (curproxy->cap & cfg_opts2[optnum].cap) && |
| 6684 | (curproxy->options2 & cfg_opts2[optnum].val)) { |
| 6685 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6686 | cfg_opts2[optnum].name, proxy_type_str(curproxy), curproxy->id); |
| 6687 | err_code |= ERR_WARN; |
| 6688 | curproxy->options2 &= ~cfg_opts2[optnum].val; |
| 6689 | } |
| 6690 | } |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6691 | |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 6692 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6693 | if (curproxy->bind_hdr_occ) { |
| 6694 | curproxy->bind_hdr_occ = 0; |
| 6695 | Warning("config : %s '%s' : ignoring use of header %s as source IP in non-HTTP mode.\n", |
| 6696 | proxy_type_str(curproxy), curproxy->id, curproxy->bind_hdr_name); |
| 6697 | err_code |= ERR_WARN; |
| 6698 | } |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 6699 | #endif |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 6700 | } |
| 6701 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6702 | /* |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 6703 | * ensure that we're not cross-dressing a TCP server into HTTP. |
| 6704 | */ |
| 6705 | newsrv = curproxy->srv; |
| 6706 | while (newsrv != NULL) { |
Willy Tarreau | 0cec331 | 2011-10-31 13:49:26 +0100 | [diff] [blame] | 6707 | if ((curproxy->mode != PR_MODE_HTTP) && newsrv->rdr_len) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6708 | Alert("config : %s '%s' : server cannot have cookie or redirect prefix in non-HTTP mode.\n", |
| 6709 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6710 | cfgerr++; |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 6711 | } |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6712 | |
Willy Tarreau | 0cec331 | 2011-10-31 13:49:26 +0100 | [diff] [blame] | 6713 | if ((curproxy->mode != PR_MODE_HTTP) && newsrv->cklen) { |
| 6714 | Warning("config : %s '%s' : ignoring cookie for server '%s' as HTTP mode is disabled.\n", |
| 6715 | proxy_type_str(curproxy), curproxy->id, newsrv->id); |
| 6716 | err_code |= ERR_WARN; |
| 6717 | } |
| 6718 | |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 6719 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6720 | if (curproxy->mode != PR_MODE_HTTP && newsrv->bind_hdr_occ) { |
| 6721 | newsrv->bind_hdr_occ = 0; |
| 6722 | Warning("config : %s '%s' : server %s cannot use header %s as source IP in non-HTTP mode.\n", |
| 6723 | proxy_type_str(curproxy), curproxy->id, newsrv->id, newsrv->bind_hdr_name); |
| 6724 | err_code |= ERR_WARN; |
| 6725 | } |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 6726 | #endif |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 6727 | newsrv = newsrv->next; |
| 6728 | } |
| 6729 | |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6730 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 6731 | if (!curproxy->accept) |
| 6732 | curproxy->accept = frontend_accept; |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 6733 | |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6734 | if (curproxy->tcp_req.inspect_delay || |
| 6735 | !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules)) |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 6736 | curproxy->fe_req_ana |= AN_REQ_INSPECT_FE; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6737 | |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 6738 | if (curproxy->mode == PR_MODE_HTTP) { |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6739 | 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] | 6740 | 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] | 6741 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6742 | |
| 6743 | /* both TCP and HTTP must check switching rules */ |
| 6744 | curproxy->fe_req_ana |= AN_REQ_SWITCHING_RULES; |
| 6745 | } |
| 6746 | |
| 6747 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 6748 | if (curproxy->tcp_req.inspect_delay || |
| 6749 | !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules)) |
| 6750 | curproxy->be_req_ana |= AN_REQ_INSPECT_BE; |
| 6751 | |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 6752 | if (!LIST_ISEMPTY(&curproxy->tcp_rep.inspect_rules)) |
| 6753 | curproxy->be_rsp_ana |= AN_RES_INSPECT; |
| 6754 | |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 6755 | if (curproxy->mode == PR_MODE_HTTP) { |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6756 | 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] | 6757 | 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] | 6758 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6759 | |
| 6760 | /* If the backend does requires RDP cookie persistence, we have to |
| 6761 | * enable the corresponding analyser. |
| 6762 | */ |
| 6763 | if (curproxy->options2 & PR_O2_RDPC_PRST) |
| 6764 | curproxy->be_req_ana |= AN_REQ_PRST_RDP_COOKIE; |
| 6765 | } |
| 6766 | |
Emeric Brun | c52962f | 2012-11-15 18:28:02 +0100 | [diff] [blame] | 6767 | #ifdef USE_OPENSSL |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 6768 | /* Configure SSL for each bind line. |
| 6769 | * Note: if configuration fails at some point, the ->ctx member |
| 6770 | * remains NULL so that listeners can later detach. |
| 6771 | */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6772 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
Emeric Brun | c52962f | 2012-11-15 18:28:02 +0100 | [diff] [blame] | 6773 | if (!bind_conf->is_ssl) { |
| 6774 | if (bind_conf->default_ctx) { |
| 6775 | Warning("Proxy '%s': A certificate was specified but SSL was not enabled on bind '%s' at [%s:%d] (use 'ssl').\n", |
| 6776 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
| 6777 | } |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6778 | continue; |
Emeric Brun | c52962f | 2012-11-15 18:28:02 +0100 | [diff] [blame] | 6779 | } |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6780 | if (!bind_conf->default_ctx) { |
Emeric Brun | fc0421f | 2012-09-07 17:30:07 +0200 | [diff] [blame] | 6781 | 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] | 6782 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 6783 | cfgerr++; |
| 6784 | continue; |
| 6785 | } |
| 6786 | |
Emeric Brun | 4b3091e | 2012-09-24 15:48:52 +0200 | [diff] [blame] | 6787 | 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] | 6788 | Alert("Unable to allocate SSL session cache.\n"); |
| 6789 | cfgerr++; |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 6790 | continue; |
| 6791 | } |
| 6792 | |
Emeric Brun | fc0421f | 2012-09-07 17:30:07 +0200 | [diff] [blame] | 6793 | /* initialize all certificate contexts */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6794 | cfgerr += ssl_sock_prepare_all_ctx(bind_conf, curproxy); |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6795 | } |
Emeric Brun | c52962f | 2012-11-15 18:28:02 +0100 | [diff] [blame] | 6796 | #endif /* USE_OPENSSL */ |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 6797 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 6798 | /* adjust this proxy's listeners */ |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6799 | next_id = 1; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 6800 | list_for_each_entry(listener, &curproxy->conf.listeners, by_fe) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6801 | if (!listener->luid) { |
| 6802 | /* listener ID not set, use automatic numbering with first |
| 6803 | * spare entry starting with next_luid. |
| 6804 | */ |
| 6805 | next_id = get_next_id(&curproxy->conf.used_listener_id, next_id); |
| 6806 | listener->conf.id.key = listener->luid = next_id; |
| 6807 | eb32_insert(&curproxy->conf.used_listener_id, &listener->conf.id); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6808 | } |
Krzysztof Piotr Oledzki | df5cb9f | 2010-02-05 20:58:27 +0100 | [diff] [blame] | 6809 | next_id++; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6810 | |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 6811 | /* enable separate counters */ |
| 6812 | if (curproxy->options2 & PR_O2_SOCKSTAT) { |
| 6813 | listener->counters = (struct licounters *)calloc(1, sizeof(struct licounters)); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6814 | if (!listener->name) |
| 6815 | memprintf(&listener->name, "sock-%d", listener->luid); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 6816 | } |
Willy Tarreau | 81796be | 2012-09-22 19:11:47 +0200 | [diff] [blame] | 6817 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 6818 | if (curproxy->options & PR_O_TCP_NOLING) |
| 6819 | listener->options |= LI_O_NOLINGER; |
Willy Tarreau | 32368ce | 2012-09-06 11:10:55 +0200 | [diff] [blame] | 6820 | if (!listener->maxconn) |
| 6821 | listener->maxconn = curproxy->maxconn; |
| 6822 | if (!listener->backlog) |
| 6823 | listener->backlog = curproxy->backlog; |
Willy Tarreau | 16a2147 | 2012-11-19 12:39:59 +0100 | [diff] [blame] | 6824 | if (!listener->maxaccept) |
| 6825 | listener->maxaccept = global.tune.maxaccept ? global.tune.maxaccept : 64; |
| 6826 | |
| 6827 | /* we want to have an optimal behaviour on single process mode to |
| 6828 | * maximize the work at once, but in multi-process we want to keep |
| 6829 | * some fairness between processes, so we target half of the max |
| 6830 | * number of events to be balanced over all the processes the proxy |
| 6831 | * is bound to. Rememeber that maxaccept = -1 must be kept as it is |
| 6832 | * used to disable the limit. |
| 6833 | */ |
| 6834 | if (listener->maxaccept > 0) { |
| 6835 | if (nbproc > 1) |
| 6836 | listener->maxaccept = (listener->maxaccept + 1) / 2; |
| 6837 | listener->maxaccept = (listener->maxaccept + nbproc - 1) / nbproc; |
| 6838 | } |
| 6839 | |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6840 | listener->timeout = &curproxy->timeout.client; |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 6841 | listener->accept = session_accept; |
Willy Tarreau | 3bc1377 | 2008-12-07 11:50:35 +0100 | [diff] [blame] | 6842 | listener->handler = process_session; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6843 | listener->analysers |= curproxy->fe_req_ana; |
Willy Tarreau | 3bc1377 | 2008-12-07 11:50:35 +0100 | [diff] [blame] | 6844 | |
Willy Tarreau | a5c0ab2 | 2010-05-31 10:30:33 +0200 | [diff] [blame] | 6845 | if (!LIST_ISEMPTY(&curproxy->tcp_req.l4_rules)) |
| 6846 | listener->options |= LI_O_TCP_RULES; |
| 6847 | |
Willy Tarreau | de3041d | 2010-05-31 10:56:17 +0200 | [diff] [blame] | 6848 | if (curproxy->mon_mask.s_addr) |
| 6849 | listener->options |= LI_O_CHK_MONNET; |
| 6850 | |
Willy Tarreau | 9ea05a7 | 2009-06-14 12:07:01 +0200 | [diff] [blame] | 6851 | /* smart accept mode is automatic in HTTP mode */ |
| 6852 | if ((curproxy->options2 & PR_O2_SMARTACC) || |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6853 | ((curproxy->mode == PR_MODE_HTTP || listener->bind_conf->is_ssl) && |
Willy Tarreau | 9ea05a7 | 2009-06-14 12:07:01 +0200 | [diff] [blame] | 6854 | !(curproxy->no_options2 & PR_O2_SMARTACC))) |
| 6855 | listener->options |= LI_O_NOQUICKACK; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 6856 | } |
| 6857 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6858 | /* Release unused SSL configs */ |
| 6859 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
| 6860 | if (bind_conf->is_ssl) |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 6861 | continue; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6862 | #ifdef USE_OPENSSL |
| 6863 | ssl_sock_free_all_ctx(bind_conf); |
Emeric Brun | fb510ea | 2012-10-05 12:00:26 +0200 | [diff] [blame] | 6864 | free(bind_conf->ca_file); |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6865 | free(bind_conf->ciphers); |
Emeric Brun | 2b58d04 | 2012-09-20 17:10:03 +0200 | [diff] [blame] | 6866 | free(bind_conf->ecdhe); |
Emeric Brun | fb510ea | 2012-10-05 12:00:26 +0200 | [diff] [blame] | 6867 | free(bind_conf->crl_file); |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 6868 | #endif /* USE_OPENSSL */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6869 | } |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 6870 | |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 6871 | /* Check multi-process mode compatibility for the current proxy */ |
| 6872 | if (global.nbproc > 1) { |
| 6873 | int nbproc = 0; |
| 6874 | if (curproxy->bind_proc) { |
| 6875 | int proc; |
| 6876 | for (proc = 0; proc < global.nbproc; proc++) { |
| 6877 | if (curproxy->bind_proc & (1 << proc)) { |
| 6878 | nbproc++; |
| 6879 | } |
| 6880 | } |
| 6881 | } else { |
| 6882 | nbproc = global.nbproc; |
| 6883 | } |
| 6884 | if (curproxy->table.peers.name) { |
| 6885 | Alert("Proxy '%s': peers can't be used in multi-process mode (nbproc > 1).\n", |
| 6886 | curproxy->id); |
| 6887 | cfgerr++; |
| 6888 | } |
| 6889 | if (nbproc > 1) { |
| 6890 | if (curproxy->uri_auth) { |
| 6891 | Warning("Proxy '%s': in multi-process mode, stats will be limited to process assigned to the current request.\n", |
| 6892 | curproxy->id); |
| 6893 | if (!LIST_ISEMPTY(&curproxy->uri_auth->admin_rules)) { |
| 6894 | Warning("Proxy '%s': stats admin will not work correctly in multi-process mode.\n", |
| 6895 | curproxy->id); |
| 6896 | } |
| 6897 | } |
| 6898 | if (curproxy->appsession_name) { |
| 6899 | Warning("Proxy '%s': appsession will not work correctly in multi-process mode.\n", |
| 6900 | curproxy->id); |
| 6901 | } |
| 6902 | if (!LIST_ISEMPTY(&curproxy->sticking_rules)) { |
| 6903 | Warning("Proxy '%s': sticking rules will not work correctly in multi-process mode.\n", |
| 6904 | curproxy->id); |
| 6905 | } |
| 6906 | } |
| 6907 | } |
Willy Tarreau | 918ff60 | 2011-07-25 16:33:49 +0200 | [diff] [blame] | 6908 | |
| 6909 | /* create the task associated with the proxy */ |
| 6910 | curproxy->task = task_new(); |
| 6911 | if (curproxy->task) { |
| 6912 | curproxy->task->context = curproxy; |
| 6913 | curproxy->task->process = manage_proxy; |
| 6914 | /* no need to queue, it will be done automatically if some |
| 6915 | * listener gets limited. |
| 6916 | */ |
| 6917 | curproxy->task->expire = TICK_ETERNITY; |
| 6918 | } else { |
| 6919 | Alert("Proxy '%s': no more memory when trying to allocate the management task\n", |
| 6920 | curproxy->id); |
| 6921 | cfgerr++; |
| 6922 | } |
| 6923 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6924 | curproxy = curproxy->next; |
| 6925 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 6926 | |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 6927 | /* Check multi-process mode compatibility */ |
| 6928 | if (global.nbproc > 1) { |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 6929 | if (global.stats_fe && !global.stats_fe->bind_proc) { |
| 6930 | 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] | 6931 | } |
| 6932 | } |
| 6933 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6934 | for (curuserlist = userlist; curuserlist; curuserlist = curuserlist->next) { |
| 6935 | struct auth_users *curuser; |
| 6936 | int g; |
| 6937 | |
| 6938 | for (curuser = curuserlist->users; curuser; curuser = curuser->next) { |
| 6939 | unsigned int group_mask = 0; |
| 6940 | char *group = NULL; |
| 6941 | |
Willy Tarreau | b4c06b7 | 2010-02-02 11:28:20 +0100 | [diff] [blame] | 6942 | if (!curuser->u.groups) |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6943 | continue; |
| 6944 | |
Willy Tarreau | b4c06b7 | 2010-02-02 11:28:20 +0100 | [diff] [blame] | 6945 | while ((group = strtok(group?NULL:curuser->u.groups, ","))) { |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6946 | |
| 6947 | for (g = 0; g < curuserlist->grpcnt; g++) |
| 6948 | if (!strcmp(curuserlist->groups[g], group)) |
| 6949 | break; |
| 6950 | |
| 6951 | if (g == curuserlist->grpcnt) { |
| 6952 | Alert("userlist '%s': no such group '%s' specified in user '%s'\n", |
| 6953 | curuserlist->name, group, curuser->user); |
| 6954 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6955 | goto out; |
| 6956 | } |
| 6957 | |
| 6958 | group_mask |= (1 << g); |
| 6959 | } |
| 6960 | |
Willy Tarreau | b4c06b7 | 2010-02-02 11:28:20 +0100 | [diff] [blame] | 6961 | free(curuser->u.groups); |
| 6962 | curuser->u.group_mask = group_mask; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6963 | } |
| 6964 | |
| 6965 | for (g = 0; g < curuserlist->grpcnt; g++) { |
| 6966 | char *user = NULL; |
| 6967 | |
| 6968 | if (!curuserlist->groupusers[g]) |
| 6969 | continue; |
| 6970 | |
| 6971 | while ((user = strtok(user?NULL:curuserlist->groupusers[g], ","))) { |
| 6972 | for (curuser = curuserlist->users; curuser; curuser = curuser->next) |
| 6973 | if (!strcmp(curuser->user, user)) |
| 6974 | break; |
| 6975 | |
| 6976 | if (!curuser) { |
| 6977 | Alert("userlist '%s': no such user '%s' specified in group '%s'\n", |
| 6978 | curuserlist->name, user, curuserlist->groups[g]); |
| 6979 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6980 | goto out; |
| 6981 | } |
| 6982 | |
Willy Tarreau | b4c06b7 | 2010-02-02 11:28:20 +0100 | [diff] [blame] | 6983 | curuser->u.group_mask |= (1 << g); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6984 | } |
| 6985 | |
| 6986 | free(curuserlist->groupusers[g]); |
| 6987 | } |
| 6988 | |
| 6989 | free(curuserlist->groupusers); |
| 6990 | |
| 6991 | #ifdef DEBUG_AUTH |
| 6992 | for (g = 0; g < curuserlist->grpcnt; g++) { |
| 6993 | fprintf(stderr, "group %s, id %d, mask %08X, users:", curuserlist->groups[g], g , 1 << g); |
| 6994 | |
| 6995 | for (curuser = curuserlist->users; curuser; curuser = curuser->next) { |
Willy Tarreau | b950959 | 2012-05-10 23:25:35 +0200 | [diff] [blame] | 6996 | if (curuser->u.group_mask & (1 << g)) |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6997 | fprintf(stderr, " %s", curuser->user); |
| 6998 | } |
| 6999 | |
| 7000 | fprintf(stderr, "\n"); |
| 7001 | } |
| 7002 | #endif |
| 7003 | |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 7004 | } |
| 7005 | |
| 7006 | /* automatically compute fullconn if not set. We must not do it in the |
| 7007 | * loop above because cross-references are not yet fully resolved. |
| 7008 | */ |
| 7009 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 7010 | /* If <fullconn> is not set, let's set it to 10% of the sum of |
| 7011 | * the possible incoming frontend's maxconns. |
| 7012 | */ |
| 7013 | if (!curproxy->fullconn && (curproxy->cap & PR_CAP_BE)) { |
| 7014 | struct proxy *fe; |
| 7015 | int total = 0; |
| 7016 | |
| 7017 | /* sum up the number of maxconns of frontends which |
| 7018 | * reference this backend at least once or which are |
| 7019 | * the same one ('listen'). |
| 7020 | */ |
| 7021 | for (fe = proxy; fe; fe = fe->next) { |
| 7022 | struct switching_rule *rule; |
| 7023 | struct hdr_exp *exp; |
| 7024 | int found = 0; |
| 7025 | |
| 7026 | if (!(fe->cap & PR_CAP_FE)) |
| 7027 | continue; |
| 7028 | |
| 7029 | if (fe == curproxy) /* we're on a "listen" instance */ |
| 7030 | found = 1; |
| 7031 | |
| 7032 | if (fe->defbe.be == curproxy) /* "default_backend" */ |
| 7033 | found = 1; |
| 7034 | |
| 7035 | /* check if a "use_backend" rule matches */ |
| 7036 | if (!found) { |
| 7037 | list_for_each_entry(rule, &fe->switching_rules, list) { |
| 7038 | if (rule->be.backend == curproxy) { |
| 7039 | found = 1; |
| 7040 | break; |
| 7041 | } |
| 7042 | } |
| 7043 | } |
| 7044 | |
| 7045 | /* check if a "reqsetbe" rule matches */ |
| 7046 | for (exp = fe->req_exp; !found && exp; exp = exp->next) { |
| 7047 | if (exp->action == ACT_SETBE && |
| 7048 | (struct proxy *)exp->replace == curproxy) { |
| 7049 | found = 1; |
| 7050 | break; |
| 7051 | } |
| 7052 | } |
| 7053 | |
| 7054 | /* now we've checked all possible ways to reference a backend |
| 7055 | * from a frontend. |
| 7056 | */ |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 7057 | if (!found) |
| 7058 | continue; |
| 7059 | total += fe->maxconn; |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 7060 | } |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 7061 | /* we have the sum of the maxconns in <total>. We only |
| 7062 | * keep 10% of that sum to set the default fullconn, with |
| 7063 | * a hard minimum of 1 (to avoid a divide by zero). |
| 7064 | */ |
| 7065 | curproxy->fullconn = (total + 9) / 10; |
| 7066 | if (!curproxy->fullconn) |
| 7067 | curproxy->fullconn = 1; |
| 7068 | } |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 7069 | } |
| 7070 | |
Willy Tarreau | 056f568 | 2010-06-06 15:51:11 +0200 | [diff] [blame] | 7071 | /* initialize stick-tables on backend capable proxies. This must not |
| 7072 | * be done earlier because the data size may be discovered while parsing |
| 7073 | * other proxies. |
| 7074 | */ |
| 7075 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) |
Willy Tarreau | c00cdc2 | 2010-06-06 16:48:26 +0200 | [diff] [blame] | 7076 | stktable_init(&curproxy->table); |
Willy Tarreau | 056f568 | 2010-06-06 15:51:11 +0200 | [diff] [blame] | 7077 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7078 | /* |
| 7079 | * Recount currently required checks. |
| 7080 | */ |
| 7081 | |
| 7082 | for (curproxy=proxy; curproxy; curproxy=curproxy->next) { |
| 7083 | int optnum; |
| 7084 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 7085 | for (optnum = 0; cfg_opts[optnum].name; optnum++) |
| 7086 | if (curproxy->options & cfg_opts[optnum].val) |
| 7087 | global.last_checks |= cfg_opts[optnum].checks; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7088 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 7089 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) |
| 7090 | if (curproxy->options2 & cfg_opts2[optnum].val) |
| 7091 | global.last_checks |= cfg_opts2[optnum].checks; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7092 | } |
| 7093 | |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 7094 | if (peers) { |
| 7095 | struct peers *curpeers = peers, **last; |
| 7096 | struct peer *p, *pb; |
| 7097 | |
| 7098 | /* Remove all peers sections which don't have a valid listener. |
| 7099 | * This can happen when a peers section is never referenced and |
| 7100 | * does not contain a local peer. |
| 7101 | */ |
| 7102 | last = &peers; |
| 7103 | while (*last) { |
| 7104 | curpeers = *last; |
| 7105 | if (curpeers->peers_fe) { |
| 7106 | last = &curpeers->next; |
| 7107 | continue; |
| 7108 | } |
| 7109 | |
| 7110 | Warning("Removing incomplete section 'peers %s' (no peer named '%s').\n", |
| 7111 | curpeers->id, localpeer); |
| 7112 | |
| 7113 | p = curpeers->remote; |
| 7114 | while (p) { |
| 7115 | pb = p->next; |
| 7116 | free(p->id); |
| 7117 | free(p); |
| 7118 | p = pb; |
| 7119 | } |
| 7120 | |
| 7121 | /* Destroy and unlink this curpeers section. |
| 7122 | * Note: curpeers is backed up into *last. |
| 7123 | */ |
| 7124 | free(curpeers->id); |
| 7125 | curpeers = curpeers->next; |
| 7126 | free(*last); |
| 7127 | *last = curpeers; |
| 7128 | } |
| 7129 | } |
| 7130 | |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame] | 7131 | if (!global.tune.max_http_hdr) |
| 7132 | global.tune.max_http_hdr = MAX_HTTP_HDR; |
| 7133 | |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 7134 | pool2_hdr_idx = create_pool("hdr_idx", |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame] | 7135 | global.tune.max_http_hdr * sizeof(struct hdr_idx_elem), |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 7136 | MEM_F_SHARED); |
| 7137 | |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 7138 | if (cfgerr > 0) |
| 7139 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7140 | out: |
| 7141 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7142 | } |
| 7143 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 7144 | /* |
| 7145 | * Registers the CFG keyword list <kwl> as a list of valid keywords for next |
| 7146 | * parsing sessions. |
| 7147 | */ |
| 7148 | void cfg_register_keywords(struct cfg_kw_list *kwl) |
| 7149 | { |
| 7150 | LIST_ADDQ(&cfg_keywords.list, &kwl->list); |
| 7151 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7152 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 7153 | /* |
| 7154 | * Unregisters the CFG keyword list <kwl> from the list of valid keywords. |
| 7155 | */ |
| 7156 | void cfg_unregister_keywords(struct cfg_kw_list *kwl) |
| 7157 | { |
| 7158 | LIST_DEL(&kwl->list); |
| 7159 | LIST_INIT(&kwl->list); |
| 7160 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7161 | |
| 7162 | /* |
| 7163 | * Local variables: |
| 7164 | * c-indent-level: 8 |
| 7165 | * c-basic-offset: 8 |
| 7166 | * End: |
| 7167 | */ |