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) { |
Willy Tarreau | 12eb2a6 | 2013-03-06 15:45:03 +0100 | [diff] [blame] | 209 | struct sockaddr_storage ss, *ss2; |
Willy Tarreau | 40aa070 | 2013-03-10 23:51:38 +0100 | [diff] [blame] | 210 | int fd = -1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 211 | |
| 212 | str = next; |
| 213 | /* 1) look for the end of the first address */ |
Krzysztof Piotr Oledzki | 52d522b | 2009-01-27 16:57:08 +0100 | [diff] [blame] | 214 | if ((next = strchr(str, ',')) != NULL) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 215 | *next++ = 0; |
| 216 | } |
| 217 | |
Willy Tarreau | 12eb2a6 | 2013-03-06 15:45:03 +0100 | [diff] [blame] | 218 | ss2 = str2sa_range(str, &port, &end, err, |
| 219 | curproxy == global.stats_fe ? NULL : global.unix_bind.prefix); |
| 220 | if (!ss2) |
| 221 | goto fail; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 222 | |
Willy Tarreau | 12eb2a6 | 2013-03-06 15:45:03 +0100 | [diff] [blame] | 223 | if (ss2->ss_family == AF_INET || ss2->ss_family == AF_INET6) { |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 224 | if (!port && !end) { |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 225 | memprintf(err, "missing port number: '%s'\n", str); |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 226 | goto fail; |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 227 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 228 | |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 229 | if (!port || !end) { |
| 230 | memprintf(err, "port offsets are not allowed in 'bind': '%s'\n", str); |
| 231 | goto fail; |
| 232 | } |
| 233 | |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 234 | if (port < 1 || port > 65535) { |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 235 | memprintf(err, "invalid port '%d' specified for address '%s'.\n", port, str); |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 236 | goto fail; |
| 237 | } |
| 238 | |
| 239 | if (end < 1 || end > 65535) { |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 240 | memprintf(err, "invalid port '%d' specified for address '%s'.\n", end, str); |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 241 | goto fail; |
| 242 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 243 | } |
Willy Tarreau | 40aa070 | 2013-03-10 23:51:38 +0100 | [diff] [blame] | 244 | else if (ss2->ss_family == AF_UNSPEC) { |
| 245 | socklen_t addr_len; |
| 246 | |
| 247 | /* We want to attach to an already bound fd whose number |
| 248 | * is in the addr part of ss2 when cast to sockaddr_in. |
| 249 | * Note that by definition there is a single listener. |
| 250 | * We still have to determine the address family to |
| 251 | * register the correct protocol. |
| 252 | */ |
| 253 | fd = ((struct sockaddr_in *)ss2)->sin_addr.s_addr; |
| 254 | addr_len = sizeof(*ss2); |
| 255 | if (getsockname(fd, (struct sockaddr *)ss2, &addr_len) == -1) { |
| 256 | memprintf(err, "cannot use file descriptor '%d' : %s.\n", fd, strerror(errno)); |
| 257 | goto fail; |
| 258 | } |
| 259 | |
| 260 | port = end = get_host_port(ss2); |
| 261 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 262 | |
Willy Tarreau | 12eb2a6 | 2013-03-06 15:45:03 +0100 | [diff] [blame] | 263 | /* OK the address looks correct */ |
| 264 | ss = *ss2; |
| 265 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 266 | for (; port <= end; port++) { |
| 267 | l = (struct listener *)calloc(1, sizeof(struct listener)); |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 268 | l->obj_type = OBJ_TYPE_LISTENER; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 269 | LIST_ADDQ(&curproxy->conf.listeners, &l->by_fe); |
| 270 | LIST_ADDQ(&bind_conf->listeners, &l->by_bind); |
| 271 | l->frontend = curproxy; |
| 272 | l->bind_conf = bind_conf; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 273 | |
Willy Tarreau | 40aa070 | 2013-03-10 23:51:38 +0100 | [diff] [blame] | 274 | l->fd = fd; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 275 | l->addr = ss; |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 276 | l->xprt = &raw_sock; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 277 | l->state = LI_INIT; |
| 278 | |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 279 | if (ss.ss_family == AF_INET) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 280 | ((struct sockaddr_in *)(&l->addr))->sin_port = htons(port); |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 281 | tcpv4_add_listener(l); |
| 282 | } |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 283 | else if (ss.ss_family == AF_INET6) { |
| 284 | ((struct sockaddr_in6 *)(&l->addr))->sin6_port = htons(port); |
| 285 | tcpv6_add_listener(l); |
| 286 | } |
| 287 | else { |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 288 | uxst_add_listener(l); |
| 289 | } |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 290 | |
Willy Tarreau | af7ad00 | 2010-08-31 15:39:26 +0200 | [diff] [blame] | 291 | jobs++; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 292 | listeners++; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 293 | } /* end for(port) */ |
| 294 | } /* end while(next) */ |
| 295 | free(dupstr); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 296 | return 1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 297 | fail: |
| 298 | free(dupstr); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 299 | return 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 300 | } |
| 301 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 302 | /* |
| 303 | * Sends a warning if proxy <proxy> does not have at least one of the |
| 304 | * capabilities in <cap>. An optionnal <hint> may be added at the end |
| 305 | * of the warning to help the user. Returns 1 if a warning was emitted |
| 306 | * or 0 if the condition is valid. |
| 307 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 308 | 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] | 309 | { |
| 310 | char *msg; |
| 311 | |
| 312 | switch (cap) { |
| 313 | case PR_CAP_BE: msg = "no backend"; break; |
| 314 | case PR_CAP_FE: msg = "no frontend"; break; |
| 315 | case PR_CAP_RS: msg = "no ruleset"; break; |
| 316 | case PR_CAP_BE|PR_CAP_FE: msg = "neither frontend nor backend"; break; |
| 317 | default: msg = "not enough"; break; |
| 318 | } |
| 319 | |
| 320 | if (!(proxy->cap & cap)) { |
| 321 | 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] | 322 | file, line, arg, proxy_type_str(proxy), proxy->id, msg, hint ? hint : ""); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 323 | return 1; |
| 324 | } |
| 325 | return 0; |
| 326 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 327 | |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 328 | /* Report a warning if a rule is placed after a 'block' rule. |
| 329 | * Return 1 if the warning has been emitted, otherwise 0. |
| 330 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 331 | 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] | 332 | { |
| 333 | if (!LIST_ISEMPTY(&proxy->block_cond)) { |
| 334 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'block' rule will still be processed before.\n", |
| 335 | file, line, arg); |
| 336 | return 1; |
| 337 | } |
| 338 | return 0; |
| 339 | } |
| 340 | |
| 341 | /* Report a warning if a rule is placed after a reqrewrite rule. |
| 342 | * Return 1 if the warning has been emitted, otherwise 0. |
| 343 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 344 | 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] | 345 | { |
| 346 | if (proxy->req_exp) { |
| 347 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'reqxxx' rule will still be processed before.\n", |
| 348 | file, line, arg); |
| 349 | return 1; |
| 350 | } |
| 351 | return 0; |
| 352 | } |
| 353 | |
| 354 | /* Report a warning if a rule is placed after a reqadd rule. |
| 355 | * Return 1 if the warning has been emitted, otherwise 0. |
| 356 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 357 | 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] | 358 | { |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 359 | if (!LIST_ISEMPTY(&proxy->req_add)) { |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 360 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'reqadd' rule will still be processed before.\n", |
| 361 | file, line, arg); |
| 362 | return 1; |
| 363 | } |
| 364 | return 0; |
| 365 | } |
| 366 | |
| 367 | /* Report a warning if a rule is placed after a redirect rule. |
| 368 | * Return 1 if the warning has been emitted, otherwise 0. |
| 369 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 370 | 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] | 371 | { |
| 372 | if (!LIST_ISEMPTY(&proxy->redirect_rules)) { |
| 373 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'redirect' rule will still be processed before.\n", |
| 374 | file, line, arg); |
| 375 | return 1; |
| 376 | } |
| 377 | return 0; |
| 378 | } |
| 379 | |
| 380 | /* Report a warning if a rule is placed after a 'use_backend' rule. |
| 381 | * Return 1 if the warning has been emitted, otherwise 0. |
| 382 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 383 | 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] | 384 | { |
| 385 | if (!LIST_ISEMPTY(&proxy->switching_rules)) { |
| 386 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'use_backend' rule will still be processed before.\n", |
| 387 | file, line, arg); |
| 388 | return 1; |
| 389 | } |
| 390 | return 0; |
| 391 | } |
| 392 | |
| 393 | /* report a warning if a block rule is dangerously placed */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 394 | 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] | 395 | { |
| 396 | return warnif_rule_after_reqxxx(proxy, file, line, arg) || |
| 397 | warnif_rule_after_reqadd(proxy, file, line, arg) || |
| 398 | warnif_rule_after_redirect(proxy, file, line, arg) || |
| 399 | warnif_rule_after_use_backend(proxy, file, line, arg); |
| 400 | } |
| 401 | |
| 402 | /* report a warning if a reqxxx rule is dangerously placed */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 403 | 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] | 404 | { |
| 405 | return warnif_rule_after_reqadd(proxy, file, line, arg) || |
| 406 | warnif_rule_after_redirect(proxy, file, line, arg) || |
| 407 | warnif_rule_after_use_backend(proxy, file, line, arg); |
| 408 | } |
| 409 | |
| 410 | /* report a warning if a reqadd rule is dangerously placed */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 411 | 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] | 412 | { |
| 413 | return warnif_rule_after_redirect(proxy, file, line, arg) || |
| 414 | warnif_rule_after_use_backend(proxy, file, line, arg); |
| 415 | } |
| 416 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 417 | /* Report it if a request ACL condition uses some keywords that are incompatible |
| 418 | * with the place where the ACL is used. It returns either 0 or ERR_WARN so that |
| 419 | * its result can be or'ed with err_code. Note that <cond> may be NULL and then |
| 420 | * will be ignored. |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 421 | */ |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 422 | static int warnif_cond_conflicts(const struct acl_cond *cond, unsigned int where, const char *file, int line) |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 423 | { |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 424 | const struct acl *acl; |
Willy Tarreau | 93fddf1 | 2013-03-31 22:59:32 +0200 | [diff] [blame] | 425 | const char *kw; |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 426 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 427 | if (!cond) |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 428 | return 0; |
| 429 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 430 | acl = acl_cond_conflicts(cond, where); |
| 431 | if (acl) { |
| 432 | if (acl->name && *acl->name) |
| 433 | Warning("parsing [%s:%d] : acl '%s' will never match because it only involves keywords that are incompatible with '%s'\n", |
| 434 | file, line, acl->name, sample_ckp_names(where)); |
| 435 | else |
| 436 | Warning("parsing [%s:%d] : anonymous acl will never match because it uses keyword '%s' which is incompatible with '%s'\n", |
Willy Tarreau | 93fddf1 | 2013-03-31 22:59:32 +0200 | [diff] [blame] | 437 | file, line, LIST_ELEM(acl->expr.n, struct acl_expr *, list)->kw, sample_ckp_names(where)); |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 438 | return ERR_WARN; |
| 439 | } |
| 440 | if (!acl_cond_kw_conflicts(cond, where, &acl, &kw)) |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 441 | return 0; |
| 442 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 443 | if (acl->name && *acl->name) |
| 444 | Warning("parsing [%s:%d] : acl '%s' involves keywords '%s' which is incompatible with '%s'\n", |
Willy Tarreau | 93fddf1 | 2013-03-31 22:59:32 +0200 | [diff] [blame] | 445 | file, line, acl->name, kw, sample_ckp_names(where)); |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 446 | else |
| 447 | Warning("parsing [%s:%d] : anonymous acl involves keyword '%s' which is incompatible with '%s'\n", |
Willy Tarreau | 93fddf1 | 2013-03-31 22:59:32 +0200 | [diff] [blame] | 448 | file, line, kw, sample_ckp_names(where)); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 449 | return ERR_WARN; |
| 450 | } |
| 451 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 452 | /* |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 453 | * parse a line in a <global> section. Returns the error code, 0 if OK, or |
| 454 | * any combination of : |
| 455 | * - ERR_ABORT: must abort ASAP |
| 456 | * - ERR_FATAL: we can continue parsing but not start the service |
| 457 | * - ERR_WARN: a warning has been emitted |
| 458 | * - ERR_ALERT: an alert has been emitted |
| 459 | * Only the two first ones can stop processing, the two others are just |
| 460 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 461 | */ |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 462 | 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] | 463 | { |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 464 | int err_code = 0; |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 465 | char *errmsg = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 466 | |
| 467 | if (!strcmp(args[0], "global")) { /* new section */ |
| 468 | /* no option, nothing special to do */ |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 469 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 470 | } |
Emeric Brun | c8e8d12 | 2012-10-02 18:42:10 +0200 | [diff] [blame] | 471 | else if (!strcmp(args[0], "ca-base")) { |
| 472 | #ifdef USE_OPENSSL |
| 473 | if (global.ca_base != NULL) { |
| 474 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 475 | err_code |= ERR_ALERT; |
| 476 | goto out; |
| 477 | } |
| 478 | if (*(args[1]) == 0) { |
| 479 | Alert("parsing [%s:%d] : '%s' expects a directory path as an argument.\n", file, linenum, args[0]); |
| 480 | err_code |= ERR_ALERT | ERR_FATAL; |
| 481 | goto out; |
| 482 | } |
| 483 | global.ca_base = strdup(args[1]); |
| 484 | #else |
| 485 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 486 | err_code |= ERR_ALERT | ERR_FATAL; |
| 487 | goto out; |
| 488 | #endif |
| 489 | } |
| 490 | else if (!strcmp(args[0], "crt-base")) { |
| 491 | #ifdef USE_OPENSSL |
| 492 | if (global.crt_base != NULL) { |
| 493 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 494 | err_code |= ERR_ALERT; |
| 495 | goto out; |
| 496 | } |
| 497 | if (*(args[1]) == 0) { |
| 498 | Alert("parsing [%s:%d] : '%s' expects a directory path as an argument.\n", file, linenum, args[0]); |
| 499 | err_code |= ERR_ALERT | ERR_FATAL; |
| 500 | goto out; |
| 501 | } |
| 502 | global.crt_base = strdup(args[1]); |
| 503 | #else |
| 504 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 505 | err_code |= ERR_ALERT | ERR_FATAL; |
| 506 | goto out; |
| 507 | #endif |
| 508 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 509 | else if (!strcmp(args[0], "daemon")) { |
| 510 | global.mode |= MODE_DAEMON; |
| 511 | } |
| 512 | else if (!strcmp(args[0], "debug")) { |
| 513 | global.mode |= MODE_DEBUG; |
| 514 | } |
| 515 | else if (!strcmp(args[0], "noepoll")) { |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 516 | global.tune.options &= ~GTUNE_USE_EPOLL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 517 | } |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 518 | else if (!strcmp(args[0], "nokqueue")) { |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 519 | global.tune.options &= ~GTUNE_USE_KQUEUE; |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 520 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 521 | else if (!strcmp(args[0], "nopoll")) { |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 522 | global.tune.options &= ~GTUNE_USE_POLL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 523 | } |
Willy Tarreau | 3ab68cf | 2009-01-25 16:03:28 +0100 | [diff] [blame] | 524 | else if (!strcmp(args[0], "nosplice")) { |
| 525 | global.tune.options &= ~GTUNE_USE_SPLICE; |
| 526 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 527 | else if (!strcmp(args[0], "quiet")) { |
| 528 | global.mode |= MODE_QUIET; |
| 529 | } |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 530 | else if (!strcmp(args[0], "tune.maxpollevents")) { |
| 531 | if (global.tune.maxpollevents != 0) { |
| 532 | 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] | 533 | err_code |= ERR_ALERT; |
| 534 | goto out; |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 535 | } |
| 536 | if (*(args[1]) == 0) { |
| 537 | 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] | 538 | err_code |= ERR_ALERT | ERR_FATAL; |
| 539 | goto out; |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 540 | } |
| 541 | global.tune.maxpollevents = atol(args[1]); |
| 542 | } |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 543 | else if (!strcmp(args[0], "tune.maxaccept")) { |
| 544 | if (global.tune.maxaccept != 0) { |
| 545 | 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] | 546 | err_code |= ERR_ALERT; |
| 547 | goto out; |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 548 | } |
| 549 | if (*(args[1]) == 0) { |
| 550 | 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] | 551 | err_code |= ERR_ALERT | ERR_FATAL; |
| 552 | goto out; |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 553 | } |
| 554 | global.tune.maxaccept = atol(args[1]); |
| 555 | } |
Willy Tarreau | 43961d5 | 2010-10-04 20:39:20 +0200 | [diff] [blame] | 556 | else if (!strcmp(args[0], "tune.chksize")) { |
| 557 | if (*(args[1]) == 0) { |
| 558 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 559 | err_code |= ERR_ALERT | ERR_FATAL; |
| 560 | goto out; |
| 561 | } |
| 562 | global.tune.chksize = atol(args[1]); |
| 563 | } |
Emeric Brun | fc32aca | 2012-09-03 12:10:29 +0200 | [diff] [blame] | 564 | #ifdef USE_OPENSSL |
Willy Tarreau | 6ec58db | 2012-11-16 16:32:15 +0100 | [diff] [blame] | 565 | else if (!strcmp(args[0], "tune.ssl.cachesize")) { |
Emeric Brun | fc32aca | 2012-09-03 12:10:29 +0200 | [diff] [blame] | 566 | if (*(args[1]) == 0) { |
| 567 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 568 | err_code |= ERR_ALERT | ERR_FATAL; |
| 569 | goto out; |
| 570 | } |
| 571 | global.tune.sslcachesize = atol(args[1]); |
| 572 | } |
Emeric Brun | 4f65bff | 2012-11-16 15:11:00 +0100 | [diff] [blame] | 573 | else if (!strcmp(args[0], "tune.ssl.lifetime")) { |
| 574 | unsigned int ssllifetime; |
| 575 | const char *res; |
| 576 | |
| 577 | if (*(args[1]) == 0) { |
| 578 | Alert("parsing [%s:%d] : '%s' expects ssl sessions <lifetime> in seconds as argument.\n", file, linenum, args[0]); |
| 579 | err_code |= ERR_ALERT | ERR_FATAL; |
| 580 | goto out; |
| 581 | } |
| 582 | |
| 583 | res = parse_time_err(args[1], &ssllifetime, TIME_UNIT_S); |
| 584 | if (res) { |
| 585 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 586 | file, linenum, *res, args[0]); |
| 587 | err_code |= ERR_ALERT | ERR_FATAL; |
| 588 | goto out; |
| 589 | } |
| 590 | |
| 591 | global.tune.ssllifetime = ssllifetime; |
| 592 | } |
Willy Tarreau | bfd5946 | 2013-02-21 07:46:09 +0100 | [diff] [blame] | 593 | else if (!strcmp(args[0], "tune.ssl.maxrecord")) { |
| 594 | if (*(args[1]) == 0) { |
| 595 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 596 | err_code |= ERR_ALERT | ERR_FATAL; |
| 597 | goto out; |
| 598 | } |
| 599 | global.tune.ssl_max_record = atol(args[1]); |
| 600 | } |
Emeric Brun | fc32aca | 2012-09-03 12:10:29 +0200 | [diff] [blame] | 601 | #endif |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 602 | else if (!strcmp(args[0], "tune.bufsize")) { |
| 603 | if (*(args[1]) == 0) { |
| 604 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 605 | err_code |= ERR_ALERT | ERR_FATAL; |
| 606 | goto out; |
| 607 | } |
| 608 | global.tune.bufsize = atol(args[1]); |
| 609 | if (global.tune.maxrewrite >= global.tune.bufsize / 2) |
| 610 | global.tune.maxrewrite = global.tune.bufsize / 2; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 611 | chunk_init(&trash, realloc(trash.str, global.tune.bufsize), global.tune.bufsize); |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 612 | } |
| 613 | else if (!strcmp(args[0], "tune.maxrewrite")) { |
| 614 | if (*(args[1]) == 0) { |
| 615 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 616 | err_code |= ERR_ALERT | ERR_FATAL; |
| 617 | goto out; |
| 618 | } |
| 619 | global.tune.maxrewrite = atol(args[1]); |
| 620 | if (global.tune.maxrewrite >= global.tune.bufsize / 2) |
| 621 | global.tune.maxrewrite = global.tune.bufsize / 2; |
| 622 | } |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 623 | else if (!strcmp(args[0], "tune.rcvbuf.client")) { |
| 624 | if (global.tune.client_rcvbuf != 0) { |
| 625 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 626 | err_code |= ERR_ALERT; |
| 627 | goto out; |
| 628 | } |
| 629 | if (*(args[1]) == 0) { |
| 630 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 631 | err_code |= ERR_ALERT | ERR_FATAL; |
| 632 | goto out; |
| 633 | } |
| 634 | global.tune.client_rcvbuf = atol(args[1]); |
| 635 | } |
| 636 | else if (!strcmp(args[0], "tune.rcvbuf.server")) { |
| 637 | if (global.tune.server_rcvbuf != 0) { |
| 638 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 639 | err_code |= ERR_ALERT; |
| 640 | goto out; |
| 641 | } |
| 642 | if (*(args[1]) == 0) { |
| 643 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 644 | err_code |= ERR_ALERT | ERR_FATAL; |
| 645 | goto out; |
| 646 | } |
| 647 | global.tune.server_rcvbuf = atol(args[1]); |
| 648 | } |
| 649 | else if (!strcmp(args[0], "tune.sndbuf.client")) { |
| 650 | if (global.tune.client_sndbuf != 0) { |
| 651 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 652 | err_code |= ERR_ALERT; |
| 653 | goto out; |
| 654 | } |
| 655 | if (*(args[1]) == 0) { |
| 656 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 657 | err_code |= ERR_ALERT | ERR_FATAL; |
| 658 | goto out; |
| 659 | } |
| 660 | global.tune.client_sndbuf = atol(args[1]); |
| 661 | } |
| 662 | else if (!strcmp(args[0], "tune.sndbuf.server")) { |
| 663 | if (global.tune.server_sndbuf != 0) { |
| 664 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 665 | err_code |= ERR_ALERT; |
| 666 | goto out; |
| 667 | } |
| 668 | if (*(args[1]) == 0) { |
| 669 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 670 | err_code |= ERR_ALERT | ERR_FATAL; |
| 671 | goto out; |
| 672 | } |
| 673 | global.tune.server_sndbuf = atol(args[1]); |
| 674 | } |
Willy Tarreau | bd9a0a7 | 2011-10-23 21:14:29 +0200 | [diff] [blame] | 675 | else if (!strcmp(args[0], "tune.pipesize")) { |
| 676 | if (*(args[1]) == 0) { |
| 677 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 678 | err_code |= ERR_ALERT | ERR_FATAL; |
| 679 | goto out; |
| 680 | } |
| 681 | global.tune.pipesize = atol(args[1]); |
| 682 | } |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 683 | else if (!strcmp(args[0], "tune.http.cookielen")) { |
| 684 | if (*(args[1]) == 0) { |
| 685 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 686 | err_code |= ERR_ALERT | ERR_FATAL; |
| 687 | goto out; |
| 688 | } |
| 689 | global.tune.cookie_len = atol(args[1]) + 1; |
| 690 | } |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame] | 691 | else if (!strcmp(args[0], "tune.http.maxhdr")) { |
| 692 | if (*(args[1]) == 0) { |
| 693 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 694 | err_code |= ERR_ALERT | ERR_FATAL; |
| 695 | goto out; |
| 696 | } |
| 697 | global.tune.max_http_hdr = atol(args[1]); |
| 698 | } |
William Lallemand | a509e4c | 2012-11-07 16:54:34 +0100 | [diff] [blame] | 699 | else if (!strcmp(args[0], "tune.zlib.memlevel")) { |
| 700 | #ifdef USE_ZLIB |
| 701 | if (*args[1]) { |
| 702 | global.tune.zlibmemlevel = atoi(args[1]); |
| 703 | if (global.tune.zlibmemlevel < 1 || global.tune.zlibmemlevel > 9) { |
| 704 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n", |
| 705 | file, linenum, args[0]); |
| 706 | err_code |= ERR_ALERT | ERR_FATAL; |
| 707 | goto out; |
| 708 | } |
| 709 | } else { |
| 710 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n", |
| 711 | file, linenum, args[0]); |
| 712 | err_code |= ERR_ALERT | ERR_FATAL; |
| 713 | goto out; |
| 714 | } |
| 715 | #else |
| 716 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 717 | err_code |= ERR_ALERT | ERR_FATAL; |
| 718 | goto out; |
| 719 | #endif |
| 720 | } |
| 721 | else if (!strcmp(args[0], "tune.zlib.windowsize")) { |
| 722 | #ifdef USE_ZLIB |
| 723 | if (*args[1]) { |
| 724 | global.tune.zlibwindowsize = atoi(args[1]); |
| 725 | if (global.tune.zlibwindowsize < 8 || global.tune.zlibwindowsize > 15) { |
| 726 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 8 and 15\n", |
| 727 | file, linenum, args[0]); |
| 728 | err_code |= ERR_ALERT | ERR_FATAL; |
| 729 | goto out; |
| 730 | } |
| 731 | } else { |
| 732 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 8 and 15\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' is not implemented.\n", file, linenum, args[0]); |
| 739 | err_code |= ERR_ALERT | ERR_FATAL; |
| 740 | goto out; |
| 741 | #endif |
| 742 | } |
William Lallemand | f374783 | 2012-11-09 12:33:10 +0100 | [diff] [blame] | 743 | else if (!strcmp(args[0], "tune.comp.maxlevel")) { |
| 744 | if (*args[1]) { |
| 745 | global.tune.comp_maxlevel = atoi(args[1]); |
| 746 | if (global.tune.comp_maxlevel < 1 || global.tune.comp_maxlevel > 9) { |
| 747 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n", |
| 748 | file, linenum, args[0]); |
| 749 | err_code |= ERR_ALERT | ERR_FATAL; |
| 750 | goto out; |
| 751 | } |
| 752 | } else { |
| 753 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n", |
| 754 | file, linenum, args[0]); |
| 755 | err_code |= ERR_ALERT | ERR_FATAL; |
| 756 | goto out; |
| 757 | } |
| 758 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 759 | else if (!strcmp(args[0], "uid")) { |
| 760 | if (global.uid != 0) { |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 761 | Alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 762 | err_code |= ERR_ALERT; |
| 763 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 764 | } |
| 765 | if (*(args[1]) == 0) { |
| 766 | 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] | 767 | err_code |= ERR_ALERT | ERR_FATAL; |
| 768 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 769 | } |
| 770 | global.uid = atol(args[1]); |
| 771 | } |
| 772 | else if (!strcmp(args[0], "gid")) { |
| 773 | if (global.gid != 0) { |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 774 | Alert("parsing [%s:%d] : group/gid 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 | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 777 | } |
| 778 | if (*(args[1]) == 0) { |
| 779 | 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] | 780 | err_code |= ERR_ALERT | ERR_FATAL; |
| 781 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 782 | } |
| 783 | global.gid = atol(args[1]); |
| 784 | } |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 785 | /* user/group name handling */ |
| 786 | else if (!strcmp(args[0], "user")) { |
| 787 | struct passwd *ha_user; |
| 788 | if (global.uid != 0) { |
| 789 | Alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 790 | err_code |= ERR_ALERT; |
| 791 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 792 | } |
| 793 | errno = 0; |
| 794 | ha_user = getpwnam(args[1]); |
| 795 | if (ha_user != NULL) { |
| 796 | global.uid = (int)ha_user->pw_uid; |
| 797 | } |
| 798 | else { |
| 799 | 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] | 800 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 801 | } |
| 802 | } |
| 803 | else if (!strcmp(args[0], "group")) { |
| 804 | struct group *ha_group; |
| 805 | if (global.gid != 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 806 | 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] | 807 | err_code |= ERR_ALERT; |
| 808 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 809 | } |
| 810 | errno = 0; |
| 811 | ha_group = getgrnam(args[1]); |
| 812 | if (ha_group != NULL) { |
| 813 | global.gid = (int)ha_group->gr_gid; |
| 814 | } |
| 815 | else { |
| 816 | 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] | 817 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 818 | } |
| 819 | } |
| 820 | /* end of user/group name handling*/ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 821 | else if (!strcmp(args[0], "nbproc")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 822 | if (*(args[1]) == 0) { |
| 823 | 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] | 824 | err_code |= ERR_ALERT | ERR_FATAL; |
| 825 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 826 | } |
| 827 | global.nbproc = atol(args[1]); |
| 828 | } |
| 829 | else if (!strcmp(args[0], "maxconn")) { |
| 830 | if (global.maxconn != 0) { |
| 831 | 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] | 832 | err_code |= ERR_ALERT; |
| 833 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 834 | } |
| 835 | if (*(args[1]) == 0) { |
| 836 | 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] | 837 | err_code |= ERR_ALERT | ERR_FATAL; |
| 838 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 839 | } |
| 840 | global.maxconn = atol(args[1]); |
| 841 | #ifdef SYSTEM_MAXCONN |
| 842 | if (global.maxconn > DEFAULT_MAXCONN && cfg_maxconn <= DEFAULT_MAXCONN) { |
| 843 | 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); |
| 844 | global.maxconn = DEFAULT_MAXCONN; |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 845 | err_code |= ERR_ALERT; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 846 | } |
| 847 | #endif /* SYSTEM_MAXCONN */ |
| 848 | } |
Willy Tarreau | 403edff | 2012-09-06 11:58:37 +0200 | [diff] [blame] | 849 | else if (!strcmp(args[0], "maxsslconn")) { |
| 850 | #ifdef USE_OPENSSL |
| 851 | if (*(args[1]) == 0) { |
| 852 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 853 | err_code |= ERR_ALERT | ERR_FATAL; |
| 854 | goto out; |
| 855 | } |
| 856 | global.maxsslconn = atol(args[1]); |
| 857 | #else |
Emeric Brun | 0914df8 | 2012-10-02 18:45:42 +0200 | [diff] [blame] | 858 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 859 | err_code |= ERR_ALERT | ERR_FATAL; |
| 860 | goto out; |
Willy Tarreau | 403edff | 2012-09-06 11:58:37 +0200 | [diff] [blame] | 861 | #endif |
| 862 | } |
Willy Tarreau | 81c25d0 | 2011-09-07 15:17:21 +0200 | [diff] [blame] | 863 | else if (!strcmp(args[0], "maxconnrate")) { |
| 864 | if (global.cps_lim != 0) { |
| 865 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 866 | err_code |= ERR_ALERT; |
| 867 | goto out; |
| 868 | } |
| 869 | if (*(args[1]) == 0) { |
| 870 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 871 | err_code |= ERR_ALERT | ERR_FATAL; |
| 872 | goto out; |
| 873 | } |
| 874 | global.cps_lim = atol(args[1]); |
| 875 | } |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 876 | else if (!strcmp(args[0], "maxcomprate")) { |
| 877 | if (*(args[1]) == 0) { |
| 878 | Alert("parsing [%s:%d] : '%s' expects an integer argument in kb/s.\n", file, linenum, args[0]); |
| 879 | err_code |= ERR_ALERT | ERR_FATAL; |
| 880 | goto out; |
| 881 | } |
| 882 | global.comp_rate_lim = atoi(args[1]) * 1024; |
| 883 | } |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 884 | else if (!strcmp(args[0], "maxpipes")) { |
| 885 | if (global.maxpipes != 0) { |
| 886 | 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] | 887 | err_code |= ERR_ALERT; |
| 888 | goto out; |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 889 | } |
| 890 | if (*(args[1]) == 0) { |
| 891 | 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] | 892 | err_code |= ERR_ALERT | ERR_FATAL; |
| 893 | goto out; |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 894 | } |
| 895 | global.maxpipes = atol(args[1]); |
| 896 | } |
William Lallemand | 9d5f548 | 2012-11-07 16:12:57 +0100 | [diff] [blame] | 897 | else if (!strcmp(args[0], "maxzlibmem")) { |
| 898 | if (*(args[1]) == 0) { |
| 899 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 900 | err_code |= ERR_ALERT | ERR_FATAL; |
| 901 | goto out; |
| 902 | } |
William Lallemand | e3a7d99 | 2012-11-20 11:25:20 +0100 | [diff] [blame] | 903 | global.maxzlibmem = atol(args[1]) * 1024L * 1024L; |
William Lallemand | 9d5f548 | 2012-11-07 16:12:57 +0100 | [diff] [blame] | 904 | } |
William Lallemand | 072a2bf | 2012-11-20 17:01:01 +0100 | [diff] [blame] | 905 | else if (!strcmp(args[0], "maxcompcpuusage")) { |
| 906 | if (*(args[1]) == 0) { |
| 907 | Alert("parsing [%s:%d] : '%s' expects an integer argument between 0 and 100.\n", file, linenum, args[0]); |
| 908 | err_code |= ERR_ALERT | ERR_FATAL; |
| 909 | goto out; |
| 910 | } |
| 911 | compress_min_idle = 100 - atoi(args[1]); |
Willy Tarreau | cb2699a | 2013-01-24 16:25:38 +0100 | [diff] [blame] | 912 | if (compress_min_idle > 100) { |
William Lallemand | 072a2bf | 2012-11-20 17:01:01 +0100 | [diff] [blame] | 913 | Alert("parsing [%s:%d] : '%s' expects an integer argument between 0 and 100.\n", file, linenum, args[0]); |
| 914 | err_code |= ERR_ALERT | ERR_FATAL; |
| 915 | goto out; |
| 916 | } |
| 917 | } |
| 918 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 919 | else if (!strcmp(args[0], "ulimit-n")) { |
| 920 | if (global.rlimit_nofile != 0) { |
| 921 | 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] | 922 | err_code |= ERR_ALERT; |
| 923 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 924 | } |
| 925 | if (*(args[1]) == 0) { |
| 926 | 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] | 927 | err_code |= ERR_ALERT | ERR_FATAL; |
| 928 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 929 | } |
| 930 | global.rlimit_nofile = atol(args[1]); |
| 931 | } |
| 932 | else if (!strcmp(args[0], "chroot")) { |
| 933 | if (global.chroot != NULL) { |
| 934 | 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] | 935 | err_code |= ERR_ALERT; |
| 936 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 937 | } |
| 938 | if (*(args[1]) == 0) { |
| 939 | 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] | 940 | err_code |= ERR_ALERT | ERR_FATAL; |
| 941 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 942 | } |
| 943 | global.chroot = strdup(args[1]); |
| 944 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 945 | else if (!strcmp(args[0], "description")) { |
| 946 | int i, len=0; |
| 947 | char *d; |
| 948 | |
| 949 | if (!*args[1]) { |
| 950 | Alert("parsing [%s:%d]: '%s' expects a string argument.\n", |
| 951 | file, linenum, args[0]); |
| 952 | err_code |= ERR_ALERT | ERR_FATAL; |
| 953 | goto out; |
| 954 | } |
| 955 | |
| 956 | for(i=1; *args[i]; i++) |
| 957 | len += strlen(args[i])+1; |
| 958 | |
| 959 | if (global.desc) |
| 960 | free(global.desc); |
| 961 | |
| 962 | global.desc = d = (char *)calloc(1, len); |
| 963 | |
| 964 | d += sprintf(d, "%s", args[1]); |
| 965 | for(i=2; *args[i]; i++) |
| 966 | d += sprintf(d, " %s", args[i]); |
| 967 | } |
| 968 | else if (!strcmp(args[0], "node")) { |
| 969 | int i; |
| 970 | char c; |
| 971 | |
| 972 | for (i=0; args[1][i]; i++) { |
| 973 | c = args[1][i]; |
Willy Tarreau | 88e0581 | 2010-03-03 00:16:00 +0100 | [diff] [blame] | 974 | if (!isupper((unsigned char)c) && !islower((unsigned char)c) && |
| 975 | !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.') |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 976 | break; |
| 977 | } |
| 978 | |
| 979 | if (!i || args[1][i]) { |
| 980 | Alert("parsing [%s:%d]: '%s' requires valid node name - non-empty string" |
| 981 | " with digits(0-9), letters(A-Z, a-z), dot(.), hyphen(-) or underscode(_).\n", |
| 982 | file, linenum, args[0]); |
| 983 | err_code |= ERR_ALERT | ERR_FATAL; |
| 984 | goto out; |
| 985 | } |
| 986 | |
| 987 | if (global.node) |
| 988 | free(global.node); |
| 989 | |
| 990 | global.node = strdup(args[1]); |
| 991 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 992 | else if (!strcmp(args[0], "pidfile")) { |
| 993 | if (global.pidfile != NULL) { |
| 994 | 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] | 995 | err_code |= ERR_ALERT; |
| 996 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 997 | } |
| 998 | if (*(args[1]) == 0) { |
| 999 | 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] | 1000 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1001 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1002 | } |
| 1003 | global.pidfile = strdup(args[1]); |
| 1004 | } |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 1005 | else if (!strcmp(args[0], "unix-bind")) { |
| 1006 | int cur_arg = 1; |
| 1007 | while (*(args[cur_arg])) { |
| 1008 | if (!strcmp(args[cur_arg], "prefix")) { |
| 1009 | if (global.unix_bind.prefix != NULL) { |
| 1010 | Alert("parsing [%s:%d] : unix-bind '%s' already specified. Continuing.\n", file, linenum, args[cur_arg]); |
| 1011 | err_code |= ERR_ALERT; |
| 1012 | cur_arg += 2; |
| 1013 | continue; |
| 1014 | } |
| 1015 | |
| 1016 | if (*(args[cur_arg+1]) == 0) { |
| 1017 | Alert("parsing [%s:%d] : unix_bind '%s' expects a path as an argument.\n", file, linenum, args[cur_arg]); |
| 1018 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1019 | goto out; |
| 1020 | } |
| 1021 | global.unix_bind.prefix = strdup(args[cur_arg+1]); |
| 1022 | cur_arg += 2; |
| 1023 | continue; |
| 1024 | } |
| 1025 | |
| 1026 | if (!strcmp(args[cur_arg], "mode")) { |
| 1027 | |
| 1028 | global.unix_bind.ux.mode = strtol(args[cur_arg + 1], NULL, 8); |
| 1029 | cur_arg += 2; |
| 1030 | continue; |
| 1031 | } |
| 1032 | |
| 1033 | if (!strcmp(args[cur_arg], "uid")) { |
| 1034 | |
| 1035 | global.unix_bind.ux.uid = atol(args[cur_arg + 1 ]); |
| 1036 | cur_arg += 2; |
| 1037 | continue; |
| 1038 | } |
| 1039 | |
| 1040 | if (!strcmp(args[cur_arg], "gid")) { |
| 1041 | |
| 1042 | global.unix_bind.ux.gid = atol(args[cur_arg + 1 ]); |
| 1043 | cur_arg += 2; |
| 1044 | continue; |
| 1045 | } |
| 1046 | |
| 1047 | if (!strcmp(args[cur_arg], "user")) { |
| 1048 | struct passwd *user; |
| 1049 | |
| 1050 | user = getpwnam(args[cur_arg + 1]); |
| 1051 | if (!user) { |
| 1052 | Alert("parsing [%s:%d] : '%s' : '%s' unknown user.\n", |
| 1053 | file, linenum, args[0], args[cur_arg + 1 ]); |
| 1054 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1055 | goto out; |
| 1056 | } |
| 1057 | |
| 1058 | global.unix_bind.ux.uid = user->pw_uid; |
| 1059 | cur_arg += 2; |
| 1060 | continue; |
| 1061 | } |
| 1062 | |
| 1063 | if (!strcmp(args[cur_arg], "group")) { |
| 1064 | struct group *group; |
| 1065 | |
| 1066 | group = getgrnam(args[cur_arg + 1]); |
| 1067 | if (!group) { |
| 1068 | Alert("parsing [%s:%d] : '%s' : '%s' unknown group.\n", |
| 1069 | file, linenum, args[0], args[cur_arg + 1 ]); |
| 1070 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1071 | goto out; |
| 1072 | } |
| 1073 | |
| 1074 | global.unix_bind.ux.gid = group->gr_gid; |
| 1075 | cur_arg += 2; |
| 1076 | continue; |
| 1077 | } |
| 1078 | |
Willy Tarreau | b48f958 | 2011-09-05 01:17:06 +0200 | [diff] [blame] | 1079 | 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] | 1080 | file, linenum, args[0]); |
| 1081 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1082 | goto out; |
| 1083 | } |
| 1084 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1085 | else if (!strcmp(args[0], "log") && kwm == KWM_NO) { /* no log */ |
| 1086 | /* delete previous herited or defined syslog servers */ |
| 1087 | struct logsrv *back; |
| 1088 | struct logsrv *tmp; |
| 1089 | |
| 1090 | if (*(args[1]) != 0) { |
| 1091 | Alert("parsing [%s:%d]:%s : 'no log' does not expect arguments.\n", file, linenum, args[1]); |
| 1092 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1093 | goto out; |
| 1094 | } |
| 1095 | |
| 1096 | list_for_each_entry_safe(tmp, back, &global.logsrvs, list) { |
| 1097 | LIST_DEL(&tmp->list); |
| 1098 | free(tmp); |
| 1099 | } |
| 1100 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1101 | else if (!strcmp(args[0], "log")) { /* syslog server address */ |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1102 | struct sockaddr_storage *sk; |
| 1103 | int port1, port2; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1104 | struct logsrv *logsrv; |
| 1105 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1106 | if (*(args[1]) == 0 || *(args[2]) == 0) { |
| 1107 | 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] | 1108 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1109 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1110 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1111 | |
| 1112 | logsrv = calloc(1, sizeof(struct logsrv)); |
| 1113 | |
| 1114 | logsrv->facility = get_log_facility(args[2]); |
| 1115 | if (logsrv->facility < 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1116 | 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] | 1117 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1118 | logsrv->facility = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1119 | } |
| 1120 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1121 | logsrv->level = 7; /* max syslog level = debug */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1122 | if (*(args[3])) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1123 | logsrv->level = get_log_level(args[3]); |
| 1124 | if (logsrv->level < 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1125 | 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] | 1126 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1127 | logsrv->level = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1128 | } |
| 1129 | } |
| 1130 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1131 | logsrv->minlvl = 0; /* limit syslog level to this level (emerg) */ |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 1132 | if (*(args[4])) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1133 | logsrv->minlvl = get_log_level(args[4]); |
| 1134 | if (logsrv->minlvl < 0) { |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 1135 | 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] | 1136 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1137 | logsrv->minlvl = 0; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 1138 | } |
| 1139 | } |
| 1140 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1141 | sk = str2sa_range(args[1], &port1, &port2, &errmsg, NULL); |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1142 | if (!sk) { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1143 | Alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1144 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1145 | free(logsrv); |
| 1146 | goto out; |
| 1147 | } |
| 1148 | logsrv->addr = *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 1149 | |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1150 | if (sk->ss_family == AF_INET || sk->ss_family == AF_INET6) { |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 1151 | if (port1 != port2) { |
| 1152 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 1153 | file, linenum, args[0], args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 1154 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1155 | free(logsrv); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 1156 | goto out; |
| 1157 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 1158 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1159 | logsrv->addr = *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 1160 | if (!port1) |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1161 | set_host_port(&logsrv->addr, SYSLOG_PORT); |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 1162 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1163 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1164 | LIST_ADDQ(&global.logsrvs, &logsrv->list); |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1165 | } |
Joe Williams | df5b38f | 2010-12-29 17:05:48 +0100 | [diff] [blame] | 1166 | else if (!strcmp(args[0], "log-send-hostname")) { /* set the hostname in syslog header */ |
| 1167 | char *name; |
| 1168 | int len; |
| 1169 | |
| 1170 | if (global.log_send_hostname != NULL) { |
| 1171 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 1172 | err_code |= ERR_ALERT; |
| 1173 | goto out; |
| 1174 | } |
| 1175 | |
| 1176 | if (*(args[1])) |
| 1177 | name = args[1]; |
| 1178 | else |
| 1179 | name = hostname; |
| 1180 | |
| 1181 | len = strlen(name); |
| 1182 | |
| 1183 | /* We'll add a space after the name to respect the log format */ |
| 1184 | free(global.log_send_hostname); |
| 1185 | global.log_send_hostname = malloc(len + 2); |
| 1186 | snprintf(global.log_send_hostname, len + 2, "%s ", name); |
| 1187 | } |
Kevinm | 48936af | 2010-12-22 16:08:21 +0000 | [diff] [blame] | 1188 | else if (!strcmp(args[0], "log-tag")) { /* tag to report to syslog */ |
| 1189 | if (*(args[1]) == 0) { |
| 1190 | Alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]); |
| 1191 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1192 | goto out; |
| 1193 | } |
| 1194 | free(global.log_tag); |
| 1195 | global.log_tag = strdup(args[1]); |
| 1196 | } |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1197 | else if (!strcmp(args[0], "spread-checks")) { /* random time between checks (0-50) */ |
| 1198 | if (global.spread_checks != 0) { |
| 1199 | Alert("parsing [%s:%d]: spread-checks already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1200 | err_code |= ERR_ALERT; |
| 1201 | goto out; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1202 | } |
| 1203 | if (*(args[1]) == 0) { |
| 1204 | 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] | 1205 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1206 | goto out; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1207 | } |
| 1208 | global.spread_checks = atol(args[1]); |
| 1209 | if (global.spread_checks < 0 || global.spread_checks > 50) { |
| 1210 | 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] | 1211 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1212 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1213 | } |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1214 | else if (strcmp(args[0], "cpu-map") == 0) { /* map a process list to a CPU set */ |
| 1215 | #ifdef USE_CPU_AFFINITY |
| 1216 | int cur_arg, i; |
| 1217 | unsigned int proc = 0; |
| 1218 | unsigned long cpus = 0; |
| 1219 | |
| 1220 | if (strcmp(args[1], "all") == 0) |
| 1221 | proc = 0xFFFFFFFF; |
| 1222 | else if (strcmp(args[1], "odd") == 0) |
| 1223 | proc = 0x55555555; |
| 1224 | else if (strcmp(args[1], "even") == 0) |
| 1225 | proc = 0xAAAAAAAA; |
| 1226 | else { |
| 1227 | proc = atoi(args[1]); |
| 1228 | if (proc >= 1 && proc <= 32) |
| 1229 | proc = 1 << (proc - 1); |
| 1230 | } |
| 1231 | |
| 1232 | if (!proc || !*args[2]) { |
| 1233 | 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", |
| 1234 | file, linenum, args[0]); |
| 1235 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1236 | goto out; |
| 1237 | } |
| 1238 | |
| 1239 | cur_arg = 2; |
| 1240 | while (*args[cur_arg]) { |
| 1241 | unsigned int low, high; |
| 1242 | |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 1243 | if (isdigit((int)*args[cur_arg])) { |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1244 | char *dash = strchr(args[cur_arg], '-'); |
| 1245 | |
| 1246 | low = high = str2uic(args[cur_arg]); |
| 1247 | if (dash) |
| 1248 | high = str2uic(dash + 1); |
| 1249 | |
| 1250 | if (high < low) { |
| 1251 | unsigned int swap = low; |
| 1252 | low = high; |
| 1253 | high = swap; |
| 1254 | } |
| 1255 | |
| 1256 | if (low < 0 || high >= sizeof(long) * 8) { |
| 1257 | Alert("parsing [%s:%d]: %s supports CPU numbers from 0 to %d.\n", |
| 1258 | file, linenum, args[0], (int)(sizeof(long) * 8 - 1)); |
| 1259 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1260 | goto out; |
| 1261 | } |
| 1262 | |
| 1263 | while (low <= high) |
| 1264 | cpus |= 1UL << low++; |
| 1265 | } |
| 1266 | else { |
| 1267 | Alert("parsing [%s:%d]: %s : '%s' is not a CPU range.\n", |
| 1268 | file, linenum, args[0], args[cur_arg]); |
| 1269 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1270 | goto out; |
| 1271 | } |
| 1272 | cur_arg++; |
| 1273 | } |
| 1274 | for (i = 0; i < 32; i++) |
| 1275 | if (proc & (1 << i)) |
| 1276 | global.cpu_map[i] = cpus; |
| 1277 | #else |
| 1278 | Alert("parsing [%s:%d] : '%s' is not enabled, please check build options for USE_CPU_AFFINITY.\n", file, linenum, args[0]); |
| 1279 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1280 | goto out; |
| 1281 | #endif |
| 1282 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1283 | else { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1284 | struct cfg_kw_list *kwl; |
| 1285 | int index; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1286 | int rc; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1287 | |
| 1288 | list_for_each_entry(kwl, &cfg_keywords.list, list) { |
| 1289 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 1290 | if (kwl->kw[index].section != CFG_GLOBAL) |
| 1291 | continue; |
| 1292 | if (strcmp(kwl->kw[index].kw, args[0]) == 0) { |
Willy Tarreau | 28a47d6 | 2012-09-18 20:02:48 +0200 | [diff] [blame] | 1293 | 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] | 1294 | if (rc < 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 1295 | Alert("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1296 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1297 | } |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1298 | else if (rc > 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 1299 | Warning("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1300 | err_code |= ERR_WARN; |
| 1301 | goto out; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1302 | } |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1303 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1304 | } |
| 1305 | } |
| 1306 | } |
| 1307 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1308 | 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] | 1309 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1310 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1311 | |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1312 | out: |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 1313 | free(errmsg); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1314 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1315 | } |
| 1316 | |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 1317 | void init_default_instance() |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1318 | { |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 1319 | init_new_proxy(&defproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1320 | defproxy.mode = PR_MODE_TCP; |
| 1321 | defproxy.state = PR_STNEW; |
| 1322 | defproxy.maxconn = cfg_maxpconn; |
| 1323 | defproxy.conn_retries = CONN_RETRIES; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1324 | |
Simon Horman | 6618300 | 2013-02-23 10:16:43 +0900 | [diff] [blame] | 1325 | defproxy.defsrv.check.inter = DEF_CHKINTR; |
| 1326 | defproxy.defsrv.check.fastinter = 0; |
| 1327 | defproxy.defsrv.check.downinter = 0; |
Simon Horman | d60d691 | 2013-11-25 10:46:36 +0900 | [diff] [blame] | 1328 | defproxy.defsrv.agent.inter = DEF_CHKINTR; |
| 1329 | defproxy.defsrv.agent.fastinter = 0; |
| 1330 | defproxy.defsrv.agent.downinter = 0; |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 1331 | defproxy.defsrv.check.rise = DEF_RISETIME; |
| 1332 | defproxy.defsrv.check.fall = DEF_FALLTIME; |
| 1333 | defproxy.defsrv.agent.rise = DEF_AGENT_RISETIME; |
| 1334 | defproxy.defsrv.agent.fall = DEF_AGENT_FALLTIME; |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 1335 | defproxy.defsrv.check.port = 0; |
Simon Horman | d60d691 | 2013-11-25 10:46:36 +0900 | [diff] [blame] | 1336 | defproxy.defsrv.agent.port = 0; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1337 | defproxy.defsrv.maxqueue = 0; |
| 1338 | defproxy.defsrv.minconn = 0; |
| 1339 | defproxy.defsrv.maxconn = 0; |
| 1340 | defproxy.defsrv.slowstart = 0; |
| 1341 | defproxy.defsrv.onerror = DEF_HANA_ONERR; |
| 1342 | defproxy.defsrv.consecutive_errors_limit = DEF_HANA_ERRLIMIT; |
| 1343 | defproxy.defsrv.uweight = defproxy.defsrv.iweight = 1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1344 | } |
| 1345 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1346 | |
| 1347 | static int create_cond_regex_rule(const char *file, int line, |
| 1348 | struct proxy *px, int dir, int action, int flags, |
| 1349 | const char *cmd, const char *reg, const char *repl, |
| 1350 | const char **cond_start) |
| 1351 | { |
| 1352 | regex_t *preg = NULL; |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 1353 | char *errmsg = NULL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1354 | const char *err; |
| 1355 | int err_code = 0; |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1356 | struct acl_cond *cond = NULL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1357 | |
| 1358 | if (px == &defproxy) { |
| 1359 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, line, cmd); |
| 1360 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1361 | goto err; |
| 1362 | } |
| 1363 | |
| 1364 | if (*reg == 0) { |
| 1365 | Alert("parsing [%s:%d] : '%s' expects <regex> as an argument.\n", file, line, cmd); |
| 1366 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1367 | goto err; |
| 1368 | } |
| 1369 | |
| 1370 | if (warnifnotcap(px, PR_CAP_RS, file, line, cmd, NULL)) |
| 1371 | err_code |= ERR_WARN; |
| 1372 | |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1373 | if (cond_start && |
| 1374 | (strcmp(*cond_start, "if") == 0 || strcmp(*cond_start, "unless") == 0)) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 1375 | if ((cond = build_acl_cond(file, line, px, cond_start, &errmsg)) == NULL) { |
| 1376 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 1377 | file, line, cmd, errmsg); |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1378 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1379 | goto err; |
| 1380 | } |
| 1381 | } |
| 1382 | else if (cond_start && **cond_start) { |
| 1383 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 1384 | file, line, cmd, *cond_start); |
| 1385 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1386 | goto err; |
| 1387 | } |
| 1388 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 1389 | err_code |= warnif_cond_conflicts(cond, |
| 1390 | (dir == SMP_OPT_DIR_REQ) ? |
| 1391 | ((px->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR) : |
| 1392 | ((px->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR), |
| 1393 | file, line); |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1394 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1395 | preg = calloc(1, sizeof(regex_t)); |
| 1396 | if (!preg) { |
| 1397 | Alert("parsing [%s:%d] : '%s' : not enough memory to build regex.\n", file, line, cmd); |
| 1398 | err_code = ERR_ALERT | ERR_FATAL; |
| 1399 | goto err; |
| 1400 | } |
| 1401 | |
| 1402 | if (regcomp(preg, reg, REG_EXTENDED | flags) != 0) { |
| 1403 | Alert("parsing [%s:%d] : '%s' : bad regular expression '%s'.\n", file, line, cmd, reg); |
| 1404 | err_code = ERR_ALERT | ERR_FATAL; |
| 1405 | goto err; |
| 1406 | } |
| 1407 | |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 1408 | 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] | 1409 | preg, action, repl ? strdup(repl) : NULL, cond); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1410 | if (repl && err) { |
| 1411 | Alert("parsing [%s:%d] : '%s' : invalid character or unterminated sequence in replacement string near '%c'.\n", |
| 1412 | file, line, cmd, *err); |
| 1413 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1414 | goto err; |
| 1415 | } |
| 1416 | |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 1417 | 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] | 1418 | err_code |= ERR_WARN; |
| 1419 | |
Willy Tarreau | f4068b6 | 2012-05-08 17:37:49 +0200 | [diff] [blame] | 1420 | free(errmsg); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1421 | return err_code; |
| 1422 | err: |
Willy Tarreau | f4068b6 | 2012-05-08 17:37:49 +0200 | [diff] [blame] | 1423 | free(errmsg); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1424 | free(preg); |
| 1425 | return err_code; |
| 1426 | } |
| 1427 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1428 | /* |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1429 | * Parse a line in a <listen>, <frontend>, <backend> or <ruleset> section. |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1430 | * Returns the error code, 0 if OK, or any combination of : |
| 1431 | * - ERR_ABORT: must abort ASAP |
| 1432 | * - ERR_FATAL: we can continue parsing but not start the service |
| 1433 | * - ERR_WARN: a warning has been emitted |
| 1434 | * - ERR_ALERT: an alert has been emitted |
| 1435 | * Only the two first ones can stop processing, the two others are just |
| 1436 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1437 | */ |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1438 | int cfg_parse_peers(const char *file, int linenum, char **args, int kwm) |
| 1439 | { |
| 1440 | static struct peers *curpeers = NULL; |
| 1441 | struct peer *newpeer = NULL; |
| 1442 | const char *err; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1443 | struct bind_conf *bind_conf; |
| 1444 | struct listener *l; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1445 | int err_code = 0; |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1446 | char *errmsg = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1447 | |
| 1448 | if (strcmp(args[0], "peers") == 0) { /* new peers section */ |
Willy Tarreau | 0dbbf31 | 2013-03-05 11:31:55 +0100 | [diff] [blame] | 1449 | if (!*args[1]) { |
| 1450 | Alert("parsing [%s:%d] : missing name for peers section.\n", file, linenum); |
| 1451 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1452 | goto out; |
| 1453 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1454 | |
| 1455 | err = invalid_char(args[1]); |
| 1456 | if (err) { |
| 1457 | Alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 1458 | file, linenum, *err, args[0], args[1]); |
| 1459 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 0dbbf31 | 2013-03-05 11:31:55 +0100 | [diff] [blame] | 1460 | goto out; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1461 | } |
| 1462 | |
| 1463 | for (curpeers = peers; curpeers != NULL; curpeers = curpeers->next) { |
| 1464 | /* |
| 1465 | * If there are two proxies with the same name only following |
| 1466 | * combinations are allowed: |
| 1467 | */ |
| 1468 | if (strcmp(curpeers->id, args[1]) == 0) { |
| 1469 | Warning("Parsing [%s:%d]: peers '%s' has same name as another peers (declared at %s:%d).\n", |
| 1470 | file, linenum, args[1], curpeers->conf.file, curpeers->conf.line); |
| 1471 | err_code |= ERR_WARN; |
| 1472 | } |
| 1473 | } |
| 1474 | |
| 1475 | if ((curpeers = (struct peers *)calloc(1, sizeof(struct peers))) == NULL) { |
| 1476 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1477 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1478 | goto out; |
| 1479 | } |
| 1480 | |
| 1481 | curpeers->next = peers; |
| 1482 | peers = curpeers; |
Willy Tarreau | 8113a5d | 2012-10-04 08:01:43 +0200 | [diff] [blame] | 1483 | curpeers->conf.file = strdup(file); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1484 | curpeers->conf.line = linenum; |
| 1485 | curpeers->last_change = now.tv_sec; |
| 1486 | curpeers->id = strdup(args[1]); |
| 1487 | } |
| 1488 | else if (strcmp(args[0], "peer") == 0) { /* peer definition */ |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 1489 | struct sockaddr_storage *sk; |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 1490 | int port1, port2; |
Willy Tarreau | b36487e | 2013-03-10 18:37:42 +0100 | [diff] [blame] | 1491 | struct protocol *proto; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1492 | |
| 1493 | if (!*args[2]) { |
| 1494 | Alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n", |
| 1495 | file, linenum, args[0]); |
| 1496 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1497 | goto out; |
| 1498 | } |
| 1499 | |
| 1500 | err = invalid_char(args[1]); |
| 1501 | if (err) { |
| 1502 | Alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n", |
| 1503 | file, linenum, *err, args[1]); |
| 1504 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1505 | goto out; |
| 1506 | } |
| 1507 | |
| 1508 | if ((newpeer = (struct peer *)calloc(1, sizeof(struct peer))) == NULL) { |
| 1509 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1510 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1511 | goto out; |
| 1512 | } |
| 1513 | |
| 1514 | /* the peers are linked backwards first */ |
| 1515 | curpeers->count++; |
| 1516 | newpeer->next = curpeers->remote; |
| 1517 | curpeers->remote = newpeer; |
| 1518 | newpeer->peers = curpeers; |
Willy Tarreau | 8113a5d | 2012-10-04 08:01:43 +0200 | [diff] [blame] | 1519 | newpeer->conf.file = strdup(file); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1520 | newpeer->conf.line = linenum; |
| 1521 | |
| 1522 | newpeer->last_change = now.tv_sec; |
| 1523 | newpeer->id = strdup(args[1]); |
| 1524 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1525 | sk = str2sa_range(args[2], &port1, &port2, &errmsg, NULL); |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 1526 | if (!sk) { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1527 | Alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg); |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 1528 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1529 | goto out; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1530 | } |
Willy Tarreau | b36487e | 2013-03-10 18:37:42 +0100 | [diff] [blame] | 1531 | |
| 1532 | proto = protocol_by_family(sk->ss_family); |
| 1533 | if (!proto || !proto->connect) { |
| 1534 | Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 1535 | file, linenum, args[0], args[1]); |
| 1536 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1537 | goto out; |
| 1538 | } |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 1539 | |
| 1540 | if (port1 != port2) { |
| 1541 | Alert("parsing [%s:%d] : '%s %s' : port ranges and offsets are not allowed in '%s'\n", |
| 1542 | file, linenum, args[0], args[1], args[2]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1543 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1544 | goto out; |
| 1545 | } |
| 1546 | |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 1547 | if (!port1) { |
| 1548 | Alert("parsing [%s:%d] : '%s %s' : missing or invalid port in '%s'\n", |
| 1549 | file, linenum, args[0], args[1], args[2]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1550 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1551 | goto out; |
| 1552 | } |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 1553 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1554 | newpeer->addr = *sk; |
Willy Tarreau | b36487e | 2013-03-10 18:37:42 +0100 | [diff] [blame] | 1555 | newpeer->proto = proto; |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 1556 | newpeer->xprt = &raw_sock; |
Willy Tarreau | d02394b | 2012-05-11 18:32:18 +0200 | [diff] [blame] | 1557 | newpeer->sock_init_arg = NULL; |
Willy Tarreau | 26d8c59 | 2012-05-07 18:12:14 +0200 | [diff] [blame] | 1558 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1559 | if (strcmp(newpeer->id, localpeer) == 0) { |
| 1560 | /* Current is local peer, it define a frontend */ |
| 1561 | newpeer->local = 1; |
| 1562 | |
| 1563 | if (!curpeers->peers_fe) { |
| 1564 | if ((curpeers->peers_fe = calloc(1, sizeof(struct proxy))) == NULL) { |
| 1565 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1566 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1567 | goto out; |
| 1568 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1569 | |
Willy Tarreau | 237250c | 2011-07-29 01:49:03 +0200 | [diff] [blame] | 1570 | init_new_proxy(curpeers->peers_fe); |
| 1571 | curpeers->peers_fe->parent = curpeers; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1572 | |
| 1573 | curpeers->peers_fe->last_change = now.tv_sec; |
| 1574 | curpeers->peers_fe->id = strdup(args[1]); |
| 1575 | curpeers->peers_fe->cap = PR_CAP_FE; |
Willy Tarreau | 3ae65a1 | 2011-09-07 17:40:39 +0200 | [diff] [blame] | 1576 | curpeers->peers_fe->maxconn = 0; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1577 | curpeers->peers_fe->conn_retries = CONN_RETRIES; |
| 1578 | curpeers->peers_fe->timeout.connect = 5000; |
| 1579 | curpeers->peers_fe->accept = peer_accept; |
| 1580 | curpeers->peers_fe->options2 |= PR_O2_INDEPSTR | PR_O2_SMARTCON | PR_O2_SMARTACC; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 1581 | curpeers->peers_fe->conf.args.file = curpeers->peers_fe->conf.file = strdup(file); |
| 1582 | curpeers->peers_fe->conf.args.line = curpeers->peers_fe->conf.line = linenum; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1583 | |
| 1584 | bind_conf = bind_conf_alloc(&curpeers->peers_fe->conf.bind, file, linenum, args[2]); |
| 1585 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1586 | if (!str2listener(args[2], curpeers->peers_fe, bind_conf, file, linenum, &errmsg)) { |
| 1587 | if (errmsg && *errmsg) { |
| 1588 | indent_msg(&errmsg, 2); |
| 1589 | Alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg); |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 1590 | } |
| 1591 | else |
| 1592 | Alert("parsing [%s:%d] : '%s %s' : error encountered while parsing listening address %s.\n", |
| 1593 | file, linenum, args[0], args[1], args[2]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1594 | err_code |= ERR_FATAL; |
| 1595 | goto out; |
| 1596 | } |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1597 | |
| 1598 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
| 1599 | l->maxconn = ((struct proxy *)curpeers->peers_fe)->maxconn; |
| 1600 | l->backlog = ((struct proxy *)curpeers->peers_fe)->backlog; |
| 1601 | l->timeout = &((struct proxy *)curpeers->peers_fe)->timeout.client; |
| 1602 | l->accept = session_accept; |
| 1603 | l->handler = process_session; |
| 1604 | l->analysers |= ((struct proxy *)curpeers->peers_fe)->fe_req_ana; |
| 1605 | l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */ |
| 1606 | global.maxsock += l->maxconn; |
| 1607 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1608 | } |
Willy Tarreau | 8b8fd56 | 2013-01-18 11:12:27 +0100 | [diff] [blame] | 1609 | else { |
| 1610 | Alert("parsing [%s:%d] : '%s %s' : local peer name already referenced at %s:%d.\n", |
| 1611 | file, linenum, args[0], args[1], |
| 1612 | curpeers->peers_fe->conf.file, curpeers->peers_fe->conf.line); |
| 1613 | err_code |= ERR_FATAL; |
| 1614 | goto out; |
| 1615 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1616 | } |
| 1617 | } /* neither "peer" nor "peers" */ |
| 1618 | else if (*args[0] != 0) { |
| 1619 | Alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection); |
| 1620 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1621 | goto out; |
| 1622 | } |
| 1623 | |
| 1624 | out: |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1625 | free(errmsg); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1626 | return err_code; |
| 1627 | } |
| 1628 | |
Simon Horman | 69d29f9 | 2013-02-23 15:14:19 +0900 | [diff] [blame] | 1629 | static int init_check(struct check *check, int type, const char * file, int linenum) |
| 1630 | { |
| 1631 | check->type = type; |
| 1632 | |
| 1633 | /* Allocate buffer for requests... */ |
| 1634 | if ((check->bi = calloc(sizeof(struct buffer) + global.tune.chksize, sizeof(char))) == NULL) { |
| 1635 | Alert("parsing [%s:%d] : out of memory while allocating check buffer.\n", file, linenum); |
| 1636 | return ERR_ALERT | ERR_ABORT; |
| 1637 | } |
| 1638 | check->bi->size = global.tune.chksize; |
| 1639 | |
| 1640 | /* Allocate buffer for responses... */ |
| 1641 | if ((check->bo = calloc(sizeof(struct buffer) + global.tune.chksize, sizeof(char))) == NULL) { |
| 1642 | Alert("parsing [%s:%d] : out of memory while allocating check buffer.\n", file, linenum); |
| 1643 | return ERR_ALERT | ERR_ABORT; |
| 1644 | } |
| 1645 | check->bo->size = global.tune.chksize; |
| 1646 | |
| 1647 | /* Allocate buffer for partial results... */ |
| 1648 | if ((check->conn = calloc(1, sizeof(struct connection))) == NULL) { |
| 1649 | Alert("parsing [%s:%d] : out of memory while allocating check connection.\n", file, linenum); |
| 1650 | return ERR_ALERT | ERR_ABORT; |
| 1651 | } |
| 1652 | |
| 1653 | check->conn->t.sock.fd = -1; /* no agent in progress yet */ |
| 1654 | |
| 1655 | return 0; |
| 1656 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1657 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 1658 | 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] | 1659 | { |
| 1660 | static struct proxy *curproxy = NULL; |
| 1661 | struct server *newsrv = NULL; |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 1662 | const char *err; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 1663 | int rc; |
| 1664 | unsigned val; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1665 | int err_code = 0; |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 1666 | struct acl_cond *cond = NULL; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 1667 | struct logsrv *tmplogsrv; |
Willy Tarreau | f4068b6 | 2012-05-08 17:37:49 +0200 | [diff] [blame] | 1668 | char *errmsg = NULL; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 1669 | struct bind_conf *bind_conf; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1670 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1671 | if (!strcmp(args[0], "listen")) |
| 1672 | rc = PR_CAP_LISTEN; |
| 1673 | else if (!strcmp(args[0], "frontend")) |
| 1674 | rc = PR_CAP_FE | PR_CAP_RS; |
| 1675 | else if (!strcmp(args[0], "backend")) |
| 1676 | rc = PR_CAP_BE | PR_CAP_RS; |
| 1677 | else if (!strcmp(args[0], "ruleset")) |
| 1678 | rc = PR_CAP_RS; |
| 1679 | else |
| 1680 | rc = PR_CAP_NONE; |
| 1681 | |
| 1682 | if (rc != PR_CAP_NONE) { /* new proxy */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1683 | if (!*args[1]) { |
| 1684 | Alert("parsing [%s:%d] : '%s' expects an <id> argument and\n" |
| 1685 | " optionnally supports [addr1]:port1[-end1]{,[addr]:port[-end]}...\n", |
| 1686 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1687 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1688 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1689 | } |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 1690 | |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 1691 | err = invalid_char(args[1]); |
| 1692 | if (err) { |
| 1693 | Alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 1694 | file, linenum, *err, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1695 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 1696 | } |
| 1697 | |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 1698 | for (curproxy = proxy; curproxy != NULL; curproxy = curproxy->next) { |
| 1699 | /* |
| 1700 | * If there are two proxies with the same name only following |
| 1701 | * combinations are allowed: |
| 1702 | * |
| 1703 | * listen backend frontend ruleset |
| 1704 | * listen - - - - |
| 1705 | * backend - - OK - |
| 1706 | * frontend - OK - - |
| 1707 | * ruleset - - - - |
| 1708 | */ |
| 1709 | |
| 1710 | if (!strcmp(curproxy->id, args[1]) && |
| 1711 | (rc!=(PR_CAP_FE|PR_CAP_RS) || curproxy->cap!=(PR_CAP_BE|PR_CAP_RS)) && |
| 1712 | (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] | 1713 | Warning("Parsing [%s:%d]: %s '%s' has same name as another %s (declared at %s:%d).\n", |
| 1714 | file, linenum, proxy_cap_str(rc), args[1], proxy_type_str(curproxy), |
| 1715 | curproxy->conf.file, curproxy->conf.line); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1716 | err_code |= ERR_WARN; |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 1717 | } |
| 1718 | } |
| 1719 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1720 | if ((curproxy = (struct proxy *)calloc(1, sizeof(struct proxy))) == NULL) { |
| 1721 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1722 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1723 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1724 | } |
Willy Tarreau | 5af24ef | 2009-03-15 15:23:16 +0100 | [diff] [blame] | 1725 | |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 1726 | init_new_proxy(curproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1727 | curproxy->next = proxy; |
| 1728 | proxy = curproxy; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 1729 | curproxy->conf.args.file = curproxy->conf.file = strdup(file); |
| 1730 | curproxy->conf.args.line = curproxy->conf.line = linenum; |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 1731 | curproxy->last_change = now.tv_sec; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1732 | curproxy->id = strdup(args[1]); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1733 | curproxy->cap = rc; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1734 | |
| 1735 | /* parse the listener address if any */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1736 | if ((curproxy->cap & PR_CAP_FE) && *args[2]) { |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1737 | struct listener *l; |
Willy Tarreau | 81a8117 | 2012-09-18 20:52:35 +0200 | [diff] [blame] | 1738 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1739 | bind_conf = bind_conf_alloc(&curproxy->conf.bind, file, linenum, args[2]); |
| 1740 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1741 | if (!str2listener(args[2], curproxy, bind_conf, file, linenum, &errmsg)) { |
| 1742 | if (errmsg && *errmsg) { |
| 1743 | indent_msg(&errmsg, 2); |
| 1744 | Alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg); |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 1745 | } |
| 1746 | else |
| 1747 | Alert("parsing [%s:%d] : '%s %s' : error encountered while parsing listening address '%s'.\n", |
| 1748 | file, linenum, args[0], args[1], args[2]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1749 | err_code |= ERR_FATAL; |
| 1750 | goto out; |
| 1751 | } |
Willy Tarreau | 81a8117 | 2012-09-18 20:52:35 +0200 | [diff] [blame] | 1752 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1753 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
Willy Tarreau | c8b1109 | 2011-02-16 11:08:57 +0100 | [diff] [blame] | 1754 | global.maxsock++; |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 1755 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1756 | } |
| 1757 | |
| 1758 | /* set default values */ |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1759 | memcpy(&curproxy->defsrv, &defproxy.defsrv, sizeof(curproxy->defsrv)); |
Willy Tarreau | 7016020 | 2010-04-07 16:06:40 +0200 | [diff] [blame] | 1760 | curproxy->defsrv.id = "default-server"; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1761 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1762 | curproxy->state = defproxy.state; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1763 | curproxy->options = defproxy.options; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 1764 | curproxy->options2 = defproxy.options2; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 1765 | curproxy->no_options = defproxy.no_options; |
| 1766 | curproxy->no_options2 = defproxy.no_options2; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 1767 | curproxy->bind_proc = defproxy.bind_proc; |
Willy Tarreau | 3168223 | 2007-11-29 15:38:04 +0100 | [diff] [blame] | 1768 | curproxy->lbprm.algo = defproxy.lbprm.algo; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 1769 | curproxy->except_net = defproxy.except_net; |
| 1770 | curproxy->except_mask = defproxy.except_mask; |
Maik Broemme | 36db02e | 2009-05-08 17:02:07 +0200 | [diff] [blame] | 1771 | curproxy->except_to = defproxy.except_to; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 1772 | curproxy->except_mask_to = defproxy.except_mask_to; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1773 | |
Willy Tarreau | 79f5fe8 | 2008-08-23 08:18:21 +0200 | [diff] [blame] | 1774 | if (defproxy.fwdfor_hdr_len) { |
| 1775 | curproxy->fwdfor_hdr_len = defproxy.fwdfor_hdr_len; |
| 1776 | curproxy->fwdfor_hdr_name = strdup(defproxy.fwdfor_hdr_name); |
| 1777 | } |
| 1778 | |
Willy Tarreau | b86db34 | 2009-11-30 11:50:16 +0100 | [diff] [blame] | 1779 | if (defproxy.orgto_hdr_len) { |
| 1780 | curproxy->orgto_hdr_len = defproxy.orgto_hdr_len; |
| 1781 | curproxy->orgto_hdr_name = strdup(defproxy.orgto_hdr_name); |
| 1782 | } |
| 1783 | |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 1784 | if (defproxy.server_id_hdr_len) { |
| 1785 | curproxy->server_id_hdr_len = defproxy.server_id_hdr_len; |
| 1786 | curproxy->server_id_hdr_name = strdup(defproxy.server_id_hdr_name); |
| 1787 | } |
| 1788 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1789 | if (curproxy->cap & PR_CAP_FE) { |
| 1790 | curproxy->maxconn = defproxy.maxconn; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 1791 | curproxy->backlog = defproxy.backlog; |
Willy Tarreau | 13a34bd | 2009-05-10 18:52:49 +0200 | [diff] [blame] | 1792 | curproxy->fe_sps_lim = defproxy.fe_sps_lim; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1793 | |
| 1794 | /* initialize error relocations */ |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1795 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) |
| 1796 | chunk_dup(&curproxy->errmsg[rc], &defproxy.errmsg[rc]); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1797 | |
| 1798 | curproxy->to_log = defproxy.to_log & ~LW_COOKIE & ~LW_REQHDR & ~ LW_RSPHDR; |
| 1799 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1800 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1801 | if (curproxy->cap & PR_CAP_BE) { |
| 1802 | curproxy->fullconn = defproxy.fullconn; |
| 1803 | curproxy->conn_retries = defproxy.conn_retries; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1804 | |
Willy Tarreau | aa2f389 | 2010-10-22 16:15:31 +0200 | [diff] [blame] | 1805 | if (defproxy.check_req) { |
| 1806 | curproxy->check_req = calloc(1, defproxy.check_len); |
| 1807 | memcpy(curproxy->check_req, defproxy.check_req, defproxy.check_len); |
| 1808 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1809 | curproxy->check_len = defproxy.check_len; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1810 | |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 1811 | if (defproxy.expect_str) { |
| 1812 | curproxy->expect_str = strdup(defproxy.expect_str); |
| 1813 | if (defproxy.expect_regex) { |
| 1814 | /* note: this regex is known to be valid */ |
| 1815 | curproxy->expect_regex = calloc(1, sizeof(regex_t)); |
| 1816 | regcomp(curproxy->expect_regex, defproxy.expect_str, REG_EXTENDED); |
| 1817 | } |
| 1818 | } |
| 1819 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 1820 | curproxy->ck_opts = defproxy.ck_opts; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1821 | if (defproxy.cookie_name) |
| 1822 | curproxy->cookie_name = strdup(defproxy.cookie_name); |
| 1823 | curproxy->cookie_len = defproxy.cookie_len; |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 1824 | if (defproxy.cookie_domain) |
| 1825 | curproxy->cookie_domain = strdup(defproxy.cookie_domain); |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 1826 | |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 1827 | if (defproxy.cookie_maxidle) |
| 1828 | curproxy->cookie_maxidle = defproxy.cookie_maxidle; |
| 1829 | |
| 1830 | if (defproxy.cookie_maxlife) |
| 1831 | curproxy->cookie_maxlife = defproxy.cookie_maxlife; |
| 1832 | |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 1833 | if (defproxy.rdp_cookie_name) |
| 1834 | curproxy->rdp_cookie_name = strdup(defproxy.rdp_cookie_name); |
| 1835 | curproxy->rdp_cookie_len = defproxy.rdp_cookie_len; |
| 1836 | |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 1837 | if (defproxy.url_param_name) |
| 1838 | curproxy->url_param_name = strdup(defproxy.url_param_name); |
| 1839 | curproxy->url_param_len = defproxy.url_param_len; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 1840 | |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 1841 | if (defproxy.hh_name) |
| 1842 | curproxy->hh_name = strdup(defproxy.hh_name); |
| 1843 | curproxy->hh_len = defproxy.hh_len; |
| 1844 | curproxy->hh_match_domain = defproxy.hh_match_domain; |
| 1845 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 1846 | if (defproxy.conn_src.iface_name) |
| 1847 | curproxy->conn_src.iface_name = strdup(defproxy.conn_src.iface_name); |
| 1848 | curproxy->conn_src.iface_len = defproxy.conn_src.iface_len; |
Godbach | 9f04853 | 2013-04-23 15:27:57 +0800 | [diff] [blame] | 1849 | curproxy->conn_src.opts = defproxy.conn_src.opts; |
Pieter Baauw | d551fb5 | 2013-05-08 22:49:23 +0200 | [diff] [blame] | 1850 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_TRANSPARENT) |
Godbach | 9f04853 | 2013-04-23 15:27:57 +0800 | [diff] [blame] | 1851 | curproxy->conn_src.tproxy_addr = defproxy.conn_src.tproxy_addr; |
Willy Tarreau | c621d36 | 2013-04-25 17:35:22 +0200 | [diff] [blame] | 1852 | #endif |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1853 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1854 | |
Willy Tarreau | 3b6b1a9 | 2009-07-23 13:24:23 +0200 | [diff] [blame] | 1855 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1856 | if (defproxy.capture_name) |
| 1857 | curproxy->capture_name = strdup(defproxy.capture_name); |
| 1858 | curproxy->capture_namelen = defproxy.capture_namelen; |
| 1859 | curproxy->capture_len = defproxy.capture_len; |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 1860 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1861 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1862 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 1863 | curproxy->timeout.client = defproxy.timeout.client; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 1864 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | 036fae0 | 2008-01-06 13:24:40 +0100 | [diff] [blame] | 1865 | curproxy->timeout.httpreq = defproxy.timeout.httpreq; |
Willy Tarreau | b16a574 | 2010-01-10 14:46:16 +0100 | [diff] [blame] | 1866 | curproxy->timeout.httpka = defproxy.timeout.httpka; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1867 | curproxy->uri_auth = defproxy.uri_auth; |
| 1868 | curproxy->mon_net = defproxy.mon_net; |
| 1869 | curproxy->mon_mask = defproxy.mon_mask; |
| 1870 | if (defproxy.monitor_uri) |
| 1871 | curproxy->monitor_uri = strdup(defproxy.monitor_uri); |
| 1872 | curproxy->monitor_uri_len = defproxy.monitor_uri_len; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 1873 | if (defproxy.defbe.name) |
| 1874 | curproxy->defbe.name = strdup(defproxy.defbe.name); |
Willy Tarreau | 99a7ca2 | 2012-05-31 19:39:23 +0200 | [diff] [blame] | 1875 | |
| 1876 | /* get either a pointer to the logformat string or a copy of it */ |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 1877 | curproxy->conf.logformat_string = defproxy.conf.logformat_string; |
| 1878 | if (curproxy->conf.logformat_string && |
| 1879 | curproxy->conf.logformat_string != default_http_log_format && |
| 1880 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 1881 | curproxy->conf.logformat_string != clf_http_log_format) |
| 1882 | curproxy->conf.logformat_string = strdup(curproxy->conf.logformat_string); |
| 1883 | |
| 1884 | if (defproxy.conf.lfs_file) { |
| 1885 | curproxy->conf.lfs_file = strdup(defproxy.conf.lfs_file); |
| 1886 | curproxy->conf.lfs_line = defproxy.conf.lfs_line; |
| 1887 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1888 | } |
| 1889 | |
| 1890 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 1891 | curproxy->timeout.connect = defproxy.timeout.connect; |
| 1892 | curproxy->timeout.server = defproxy.timeout.server; |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 1893 | curproxy->timeout.check = defproxy.timeout.check; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 1894 | curproxy->timeout.queue = defproxy.timeout.queue; |
Willy Tarreau | 51c9bde | 2008-01-06 13:40:03 +0100 | [diff] [blame] | 1895 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | cd7afc0 | 2009-07-12 10:03:17 +0200 | [diff] [blame] | 1896 | curproxy->timeout.httpreq = defproxy.timeout.httpreq; |
Willy Tarreau | b16a574 | 2010-01-10 14:46:16 +0100 | [diff] [blame] | 1897 | curproxy->timeout.httpka = defproxy.timeout.httpka; |
Willy Tarreau | ce887fd | 2012-05-12 12:50:00 +0200 | [diff] [blame] | 1898 | curproxy->timeout.tunnel = defproxy.timeout.tunnel; |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 1899 | curproxy->conn_src.source_addr = defproxy.conn_src.source_addr; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1900 | } |
| 1901 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1902 | curproxy->mode = defproxy.mode; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1903 | |
| 1904 | /* copy default logsrvs to curproxy */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 1905 | list_for_each_entry(tmplogsrv, &defproxy.logsrvs, list) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1906 | struct logsrv *node = malloc(sizeof(struct logsrv)); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 1907 | memcpy(node, tmplogsrv, sizeof(struct logsrv)); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1908 | LIST_INIT(&node->list); |
| 1909 | LIST_ADDQ(&curproxy->logsrvs, &node->list); |
| 1910 | } |
| 1911 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 1912 | curproxy->conf.uniqueid_format_string = defproxy.conf.uniqueid_format_string; |
| 1913 | if (curproxy->conf.uniqueid_format_string) |
| 1914 | curproxy->conf.uniqueid_format_string = strdup(curproxy->conf.uniqueid_format_string); |
| 1915 | |
| 1916 | if (defproxy.conf.uif_file) { |
| 1917 | curproxy->conf.uif_file = strdup(defproxy.conf.uif_file); |
| 1918 | curproxy->conf.uif_line = defproxy.conf.uif_line; |
| 1919 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 1920 | |
| 1921 | /* copy default header unique id */ |
| 1922 | if (defproxy.header_unique_id) |
| 1923 | curproxy->header_unique_id = strdup(defproxy.header_unique_id); |
| 1924 | |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 1925 | /* default compression options */ |
| 1926 | if (defproxy.comp != NULL) { |
| 1927 | curproxy->comp = calloc(1, sizeof(struct comp)); |
| 1928 | curproxy->comp->algos = defproxy.comp->algos; |
| 1929 | curproxy->comp->types = defproxy.comp->types; |
| 1930 | } |
| 1931 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1932 | curproxy->grace = defproxy.grace; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1933 | curproxy->conf.used_listener_id = EB_ROOT; |
| 1934 | curproxy->conf.used_server_id = EB_ROOT; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 1935 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1936 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1937 | } |
| 1938 | else if (!strcmp(args[0], "defaults")) { /* use this one to assign default values */ |
| 1939 | /* some variables may have already been initialized earlier */ |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 1940 | /* FIXME-20070101: we should do this too at the end of the |
| 1941 | * config parsing to free all default values. |
| 1942 | */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1943 | free(defproxy.check_req); |
| 1944 | free(defproxy.cookie_name); |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 1945 | free(defproxy.rdp_cookie_name); |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 1946 | free(defproxy.cookie_domain); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1947 | free(defproxy.url_param_name); |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 1948 | free(defproxy.hh_name); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1949 | free(defproxy.capture_name); |
| 1950 | free(defproxy.monitor_uri); |
| 1951 | free(defproxy.defbe.name); |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 1952 | free(defproxy.conn_src.iface_name); |
Willy Tarreau | 79f5fe8 | 2008-08-23 08:18:21 +0200 | [diff] [blame] | 1953 | free(defproxy.fwdfor_hdr_name); |
| 1954 | defproxy.fwdfor_hdr_len = 0; |
Willy Tarreau | b86db34 | 2009-11-30 11:50:16 +0100 | [diff] [blame] | 1955 | free(defproxy.orgto_hdr_name); |
| 1956 | defproxy.orgto_hdr_len = 0; |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 1957 | free(defproxy.server_id_hdr_name); |
| 1958 | defproxy.server_id_hdr_len = 0; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 1959 | free(defproxy.expect_str); |
| 1960 | if (defproxy.expect_regex) regfree(defproxy.expect_regex); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 1961 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 1962 | if (defproxy.conf.logformat_string != default_http_log_format && |
| 1963 | defproxy.conf.logformat_string != default_tcp_log_format && |
| 1964 | defproxy.conf.logformat_string != clf_http_log_format) |
| 1965 | free(defproxy.conf.logformat_string); |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 1966 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 1967 | free(defproxy.conf.uniqueid_format_string); |
| 1968 | free(defproxy.conf.lfs_file); |
| 1969 | free(defproxy.conf.uif_file); |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 1970 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1971 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1972 | chunk_destroy(&defproxy.errmsg[rc]); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 1973 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1974 | /* we cannot free uri_auth because it might already be used */ |
| 1975 | init_default_instance(); |
| 1976 | curproxy = &defproxy; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 1977 | curproxy->conf.args.file = curproxy->conf.file = strdup(file); |
| 1978 | curproxy->conf.args.line = curproxy->conf.line = linenum; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1979 | defproxy.cap = PR_CAP_LISTEN; /* all caps for now */ |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1980 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1981 | } |
| 1982 | else if (curproxy == NULL) { |
| 1983 | Alert("parsing [%s:%d] : 'listen' or 'defaults' expected.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1984 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1985 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1986 | } |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 1987 | |
| 1988 | /* update the current file and line being parsed */ |
| 1989 | curproxy->conf.args.file = curproxy->conf.file; |
| 1990 | curproxy->conf.args.line = linenum; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1991 | |
| 1992 | /* Now let's parse the proxy-specific keywords */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1993 | if (!strcmp(args[0], "bind")) { /* new listen addresses */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1994 | struct listener *l; |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1995 | int cur_arg; |
| 1996 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1997 | if (curproxy == &defproxy) { |
| 1998 | 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] | 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 | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2004 | |
Willy Tarreau | 2470928 | 2013-03-10 21:32:12 +0100 | [diff] [blame] | 2005 | if (!*(args[1])) { |
Willy Tarreau | d55c3fe | 2010-11-09 09:50:37 +0100 | [diff] [blame] | 2006 | 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] | 2007 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2008 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2009 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2010 | } |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 2011 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 2012 | bind_conf = bind_conf_alloc(&curproxy->conf.bind, file, linenum, args[1]); |
Willy Tarreau | 8dc21fa | 2013-01-24 15:17:20 +0100 | [diff] [blame] | 2013 | |
| 2014 | /* use default settings for unix sockets */ |
| 2015 | bind_conf->ux.uid = global.unix_bind.ux.uid; |
| 2016 | bind_conf->ux.gid = global.unix_bind.ux.gid; |
| 2017 | bind_conf->ux.mode = global.unix_bind.ux.mode; |
Willy Tarreau | 8a95691 | 2010-10-15 14:27:08 +0200 | [diff] [blame] | 2018 | |
| 2019 | /* NOTE: the following line might create several listeners if there |
| 2020 | * are comma-separated IPs or port ranges. So all further processing |
| 2021 | * will have to be applied to all listeners created after last_listen. |
| 2022 | */ |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 2023 | if (!str2listener(args[1], curproxy, bind_conf, file, linenum, &errmsg)) { |
| 2024 | if (errmsg && *errmsg) { |
| 2025 | indent_msg(&errmsg, 2); |
| 2026 | Alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 2027 | } |
| 2028 | else |
| 2029 | Alert("parsing [%s:%d] : '%s' : error encountered while parsing listening address '%s'.\n", |
| 2030 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2031 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2032 | goto out; |
| 2033 | } |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 2034 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2035 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
| 2036 | /* Set default global rights and owner for unix bind */ |
Willy Tarreau | c8b1109 | 2011-02-16 11:08:57 +0100 | [diff] [blame] | 2037 | global.maxsock++; |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 2038 | } |
| 2039 | |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 2040 | cur_arg = 2; |
| 2041 | while (*(args[cur_arg])) { |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 2042 | static int bind_dumped; |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 2043 | struct bind_kw *kw; |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 2044 | char *err; |
| 2045 | |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 2046 | kw = bind_find_kw(args[cur_arg]); |
| 2047 | if (kw) { |
| 2048 | char *err = NULL; |
| 2049 | int code; |
| 2050 | |
| 2051 | if (!kw->parse) { |
Willy Tarreau | dda322d | 2012-09-18 16:34:09 +0200 | [diff] [blame] | 2052 | Alert("parsing [%s:%d] : '%s %s' : '%s' option is not implemented in this version (check build options).\n", |
| 2053 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 2054 | cur_arg += 1 + kw->skip ; |
| 2055 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2056 | goto out; |
| 2057 | } |
| 2058 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2059 | code = kw->parse(args, cur_arg, curproxy, bind_conf, &err); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 2060 | err_code |= code; |
| 2061 | |
| 2062 | if (code) { |
| 2063 | if (err && *err) { |
| 2064 | indent_msg(&err, 2); |
Willy Tarreau | dda322d | 2012-09-18 16:34:09 +0200 | [diff] [blame] | 2065 | 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] | 2066 | } |
| 2067 | else |
Willy Tarreau | dda322d | 2012-09-18 16:34:09 +0200 | [diff] [blame] | 2068 | Alert("parsing [%s:%d] : '%s %s' : error encountered while processing '%s'.\n", |
| 2069 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 2070 | if (code & ERR_FATAL) { |
| 2071 | free(err); |
| 2072 | cur_arg += 1 + kw->skip; |
| 2073 | goto out; |
| 2074 | } |
| 2075 | } |
| 2076 | free(err); |
| 2077 | cur_arg += 1 + kw->skip; |
| 2078 | continue; |
| 2079 | } |
| 2080 | |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 2081 | err = NULL; |
| 2082 | if (!bind_dumped) { |
| 2083 | bind_dump_kws(&err); |
| 2084 | indent_msg(&err, 4); |
| 2085 | bind_dumped = 1; |
| 2086 | } |
| 2087 | |
| 2088 | Alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'.%s%s\n", |
| 2089 | file, linenum, args[0], args[1], args[cur_arg], |
| 2090 | err ? " Registered keywords :" : "", err ? err : ""); |
| 2091 | free(err); |
| 2092 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2093 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2094 | goto out; |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 2095 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2096 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2097 | } |
| 2098 | else if (!strcmp(args[0], "monitor-net")) { /* set the range of IPs to ignore */ |
| 2099 | if (!*args[1] || !str2net(args[1], &curproxy->mon_net, &curproxy->mon_mask)) { |
| 2100 | Alert("parsing [%s:%d] : '%s' expects address[/mask].\n", |
| 2101 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2102 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2103 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2104 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2105 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2106 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2107 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2108 | /* flush useless bits */ |
| 2109 | curproxy->mon_net.s_addr &= curproxy->mon_mask.s_addr; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2110 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2111 | } |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2112 | else if (!strcmp(args[0], "monitor-uri")) { /* set the URI to intercept */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2113 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2114 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2115 | |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2116 | if (!*args[1]) { |
| 2117 | Alert("parsing [%s:%d] : '%s' expects an URI.\n", |
| 2118 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2119 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2120 | goto out; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2121 | } |
| 2122 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2123 | free(curproxy->monitor_uri); |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 2124 | curproxy->monitor_uri_len = strlen(args[1]); |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2125 | curproxy->monitor_uri = (char *)calloc(1, curproxy->monitor_uri_len + 1); |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 2126 | memcpy(curproxy->monitor_uri, args[1], curproxy->monitor_uri_len); |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2127 | curproxy->monitor_uri[curproxy->monitor_uri_len] = '\0'; |
| 2128 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2129 | goto out; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2130 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2131 | else if (!strcmp(args[0], "mode")) { /* sets the proxy mode */ |
| 2132 | if (!strcmp(args[1], "http")) curproxy->mode = PR_MODE_HTTP; |
| 2133 | else if (!strcmp(args[1], "tcp")) curproxy->mode = PR_MODE_TCP; |
| 2134 | else if (!strcmp(args[1], "health")) curproxy->mode = PR_MODE_HEALTH; |
| 2135 | else { |
| 2136 | 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] | 2137 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2138 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2139 | } |
| 2140 | } |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2141 | else if (!strcmp(args[0], "id")) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2142 | struct eb32_node *node; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2143 | |
| 2144 | if (curproxy == &defproxy) { |
| 2145 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", |
| 2146 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2147 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2148 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2149 | } |
| 2150 | |
| 2151 | if (!*args[1]) { |
| 2152 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 2153 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2154 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2155 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2156 | } |
| 2157 | |
| 2158 | curproxy->uuid = atol(args[1]); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2159 | curproxy->conf.id.key = curproxy->uuid; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2160 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2161 | if (curproxy->uuid <= 0) { |
| 2162 | Alert("parsing [%s:%d]: custom id has to be > 0.\n", |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2163 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2164 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2165 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2166 | } |
| 2167 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2168 | node = eb32_lookup(&used_proxy_id, curproxy->uuid); |
| 2169 | if (node) { |
| 2170 | struct proxy *target = container_of(node, struct proxy, conf.id); |
| 2171 | Alert("parsing [%s:%d]: %s %s reuses same custom id as %s %s (declared at %s:%d).\n", |
| 2172 | file, linenum, proxy_type_str(curproxy), curproxy->id, |
| 2173 | proxy_type_str(target), target->id, target->conf.file, target->conf.line); |
| 2174 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2175 | goto out; |
| 2176 | } |
| 2177 | eb32_insert(&used_proxy_id, &curproxy->conf.id); |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2178 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 2179 | else if (!strcmp(args[0], "description")) { |
| 2180 | int i, len=0; |
| 2181 | char *d; |
| 2182 | |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 2183 | if (curproxy == &defproxy) { |
| 2184 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", |
| 2185 | file, linenum, args[0]); |
| 2186 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2187 | goto out; |
| 2188 | } |
| 2189 | |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 2190 | if (!*args[1]) { |
| 2191 | Alert("parsing [%s:%d]: '%s' expects a string argument.\n", |
| 2192 | file, linenum, args[0]); |
| 2193 | return -1; |
| 2194 | } |
| 2195 | |
| 2196 | for(i=1; *args[i]; i++) |
| 2197 | len += strlen(args[i])+1; |
| 2198 | |
| 2199 | d = (char *)calloc(1, len); |
| 2200 | curproxy->desc = d; |
| 2201 | |
| 2202 | d += sprintf(d, "%s", args[1]); |
| 2203 | for(i=2; *args[i]; i++) |
| 2204 | d += sprintf(d, " %s", args[i]); |
| 2205 | |
| 2206 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2207 | else if (!strcmp(args[0], "disabled")) { /* disables this proxy */ |
| 2208 | curproxy->state = PR_STSTOPPED; |
| 2209 | } |
| 2210 | else if (!strcmp(args[0], "enabled")) { /* enables this proxy (used to revert a disabled default) */ |
| 2211 | curproxy->state = PR_STNEW; |
| 2212 | } |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2213 | else if (!strcmp(args[0], "bind-process")) { /* enable this proxy only on some processes */ |
| 2214 | int cur_arg = 1; |
| 2215 | unsigned int set = 0; |
| 2216 | |
| 2217 | while (*args[cur_arg]) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 2218 | unsigned int low, high; |
| 2219 | |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2220 | if (strcmp(args[cur_arg], "all") == 0) { |
| 2221 | set = 0; |
| 2222 | break; |
| 2223 | } |
| 2224 | else if (strcmp(args[cur_arg], "odd") == 0) { |
| 2225 | set |= 0x55555555; |
| 2226 | } |
| 2227 | else if (strcmp(args[cur_arg], "even") == 0) { |
| 2228 | set |= 0xAAAAAAAA; |
| 2229 | } |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 2230 | else if (isdigit((int)*args[cur_arg])) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 2231 | char *dash = strchr(args[cur_arg], '-'); |
| 2232 | |
| 2233 | low = high = str2uic(args[cur_arg]); |
| 2234 | if (dash) |
| 2235 | high = str2uic(dash + 1); |
| 2236 | |
| 2237 | if (high < low) { |
| 2238 | unsigned int swap = low; |
| 2239 | low = high; |
| 2240 | high = swap; |
| 2241 | } |
| 2242 | |
| 2243 | if (low < 1 || high > 32) { |
| 2244 | 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] | 2245 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2246 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2247 | goto out; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2248 | } |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 2249 | |
| 2250 | if (high > global.nbproc) { |
| 2251 | Warning("parsing [%s:%d]: %s references process number %d which is higher than global.nbproc (%d).\n", |
| 2252 | file, linenum, args[0], high, global.nbproc); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2253 | err_code |= ERR_WARN; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2254 | } |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 2255 | while (low <= high) |
| 2256 | set |= 1 << (low++ - 1); |
| 2257 | } |
| 2258 | else { |
| 2259 | Alert("parsing [%s:%d]: %s expects 'all', 'odd', 'even', or a list of process ranges with numbers from 1 to 32.\n", |
| 2260 | file, linenum, args[0]); |
| 2261 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2262 | goto out; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2263 | } |
| 2264 | cur_arg++; |
| 2265 | } |
| 2266 | curproxy->bind_proc = set; |
| 2267 | } |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 2268 | else if (!strcmp(args[0], "acl")) { /* add an ACL */ |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2269 | if (curproxy == &defproxy) { |
| 2270 | 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] | 2271 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2272 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2273 | } |
| 2274 | |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 2275 | err = invalid_char(args[1]); |
| 2276 | if (err) { |
| 2277 | Alert("parsing [%s:%d] : character '%c' is not permitted in acl name '%s'.\n", |
| 2278 | file, linenum, *err, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2279 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 2280 | } |
| 2281 | |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 2282 | if (parse_acl((const char **)args + 1, &curproxy->acl, &errmsg, &curproxy->conf.args) == NULL) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 2283 | Alert("parsing [%s:%d] : error detected while parsing ACL '%s' : %s.\n", |
| 2284 | file, linenum, args[1], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2285 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2286 | goto out; |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 2287 | } |
| 2288 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2289 | else if (!strcmp(args[0], "cookie")) { /* cookie name */ |
| 2290 | int cur_arg; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2291 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2292 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2293 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2294 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2295 | if (*(args[1]) == 0) { |
| 2296 | Alert("parsing [%s:%d] : '%s' expects <cookie_name> as argument.\n", |
| 2297 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2298 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2299 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2300 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2301 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2302 | curproxy->ck_opts = 0; |
Willy Tarreau | c63d4bb | 2010-10-23 11:37:27 +0200 | [diff] [blame] | 2303 | curproxy->cookie_maxidle = curproxy->cookie_maxlife = 0; |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 2304 | free(curproxy->cookie_domain); curproxy->cookie_domain = NULL; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2305 | free(curproxy->cookie_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2306 | curproxy->cookie_name = strdup(args[1]); |
| 2307 | curproxy->cookie_len = strlen(curproxy->cookie_name); |
Willy Tarreau | c63d4bb | 2010-10-23 11:37:27 +0200 | [diff] [blame] | 2308 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2309 | cur_arg = 2; |
| 2310 | while (*(args[cur_arg])) { |
| 2311 | if (!strcmp(args[cur_arg], "rewrite")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2312 | curproxy->ck_opts |= PR_CK_RW; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2313 | } |
| 2314 | else if (!strcmp(args[cur_arg], "indirect")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2315 | curproxy->ck_opts |= PR_CK_IND; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2316 | } |
| 2317 | else if (!strcmp(args[cur_arg], "insert")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2318 | curproxy->ck_opts |= PR_CK_INS; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2319 | } |
| 2320 | else if (!strcmp(args[cur_arg], "nocache")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2321 | curproxy->ck_opts |= PR_CK_NOC; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2322 | } |
| 2323 | else if (!strcmp(args[cur_arg], "postonly")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2324 | curproxy->ck_opts |= PR_CK_POST; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2325 | } |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 2326 | else if (!strcmp(args[cur_arg], "preserve")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2327 | curproxy->ck_opts |= PR_CK_PSV; |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 2328 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2329 | else if (!strcmp(args[cur_arg], "prefix")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2330 | curproxy->ck_opts |= PR_CK_PFX; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2331 | } |
Willy Tarreau | 4992dd2 | 2012-05-31 21:02:17 +0200 | [diff] [blame] | 2332 | else if (!strcmp(args[cur_arg], "httponly")) { |
| 2333 | curproxy->ck_opts |= PR_CK_HTTPONLY; |
| 2334 | } |
| 2335 | else if (!strcmp(args[cur_arg], "secure")) { |
| 2336 | curproxy->ck_opts |= PR_CK_SECURE; |
| 2337 | } |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2338 | else if (!strcmp(args[cur_arg], "domain")) { |
| 2339 | if (!*args[cur_arg + 1]) { |
| 2340 | Alert("parsing [%s:%d]: '%s' expects <domain> as argument.\n", |
| 2341 | file, linenum, args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2342 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2343 | goto out; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2344 | } |
| 2345 | |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 2346 | if (*args[cur_arg + 1] != '.' || !strchr(args[cur_arg + 1] + 1, '.')) { |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2347 | /* rfc2109, 4.3.2 Rejecting Cookies */ |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 2348 | Warning("parsing [%s:%d]: domain '%s' contains no embedded" |
| 2349 | " dots nor does not start with a dot." |
| 2350 | " RFC forbids it, this configuration may not work properly.\n", |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2351 | file, linenum, args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 2352 | err_code |= ERR_WARN; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2353 | } |
| 2354 | |
| 2355 | err = invalid_domainchar(args[cur_arg + 1]); |
| 2356 | if (err) { |
| 2357 | Alert("parsing [%s:%d]: character '%c' is not permitted in domain name '%s'.\n", |
| 2358 | file, linenum, *err, args[cur_arg + 1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2359 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2360 | goto out; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2361 | } |
| 2362 | |
Willy Tarreau | 68a897b | 2009-12-03 23:28:34 +0100 | [diff] [blame] | 2363 | if (!curproxy->cookie_domain) { |
| 2364 | curproxy->cookie_domain = strdup(args[cur_arg + 1]); |
| 2365 | } else { |
| 2366 | /* one domain was already specified, add another one by |
| 2367 | * building the string which will be returned along with |
| 2368 | * the cookie. |
| 2369 | */ |
| 2370 | char *new_ptr; |
| 2371 | int new_len = strlen(curproxy->cookie_domain) + |
| 2372 | strlen("; domain=") + strlen(args[cur_arg + 1]) + 1; |
| 2373 | new_ptr = malloc(new_len); |
| 2374 | snprintf(new_ptr, new_len, "%s; domain=%s", curproxy->cookie_domain, args[cur_arg+1]); |
| 2375 | free(curproxy->cookie_domain); |
| 2376 | curproxy->cookie_domain = new_ptr; |
| 2377 | } |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 2378 | cur_arg++; |
| 2379 | } |
| 2380 | else if (!strcmp(args[cur_arg], "maxidle")) { |
| 2381 | unsigned int maxidle; |
| 2382 | const char *res; |
| 2383 | |
| 2384 | if (!*args[cur_arg + 1]) { |
| 2385 | Alert("parsing [%s:%d]: '%s' expects <idletime> in seconds as argument.\n", |
| 2386 | file, linenum, args[cur_arg]); |
| 2387 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2388 | goto out; |
| 2389 | } |
| 2390 | |
| 2391 | res = parse_time_err(args[cur_arg + 1], &maxidle, TIME_UNIT_S); |
| 2392 | if (res) { |
| 2393 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 2394 | file, linenum, *res, args[cur_arg]); |
| 2395 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2396 | goto out; |
| 2397 | } |
| 2398 | curproxy->cookie_maxidle = maxidle; |
| 2399 | cur_arg++; |
| 2400 | } |
| 2401 | else if (!strcmp(args[cur_arg], "maxlife")) { |
| 2402 | unsigned int maxlife; |
| 2403 | const char *res; |
| 2404 | |
| 2405 | if (!*args[cur_arg + 1]) { |
| 2406 | Alert("parsing [%s:%d]: '%s' expects <lifetime> in seconds as argument.\n", |
| 2407 | file, linenum, args[cur_arg]); |
| 2408 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2409 | goto out; |
| 2410 | } |
| 2411 | |
| 2412 | res = parse_time_err(args[cur_arg + 1], &maxlife, TIME_UNIT_S); |
| 2413 | if (res) { |
| 2414 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 2415 | file, linenum, *res, args[cur_arg]); |
| 2416 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2417 | goto out; |
| 2418 | } |
| 2419 | curproxy->cookie_maxlife = maxlife; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2420 | cur_arg++; |
| 2421 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2422 | else { |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 2423 | 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] | 2424 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2425 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2426 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2427 | } |
| 2428 | cur_arg++; |
| 2429 | } |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2430 | if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_IND))) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2431 | Alert("parsing [%s:%d] : cookie 'rewrite' and 'indirect' modes are incompatible.\n", |
| 2432 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2433 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2434 | } |
| 2435 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2436 | 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] | 2437 | Alert("parsing [%s:%d] : cookie 'rewrite', 'insert' and 'prefix' modes are incompatible.\n", |
| 2438 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2439 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2440 | } |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 2441 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2442 | 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] | 2443 | Alert("parsing [%s:%d] : cookie 'preserve' requires at least 'insert' or 'indirect'.\n", |
| 2444 | file, linenum); |
| 2445 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2446 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2447 | }/* end else if (!strcmp(args[0], "cookie")) */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2448 | else if (!strcmp(args[0], "persist")) { /* persist */ |
| 2449 | if (*(args[1]) == 0) { |
| 2450 | Alert("parsing [%s:%d] : missing persist method.\n", |
| 2451 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2452 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2453 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2454 | } |
| 2455 | |
| 2456 | if (!strncmp(args[1], "rdp-cookie", 10)) { |
| 2457 | curproxy->options2 |= PR_O2_RDPC_PRST; |
| 2458 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2459 | if (*(args[1] + 10) == '(') { /* cookie name */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2460 | const char *beg, *end; |
| 2461 | |
| 2462 | beg = args[1] + 11; |
| 2463 | end = strchr(beg, ')'); |
| 2464 | |
| 2465 | if (!end || end == beg) { |
| 2466 | Alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n", |
| 2467 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2468 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2469 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2470 | } |
| 2471 | |
| 2472 | free(curproxy->rdp_cookie_name); |
| 2473 | curproxy->rdp_cookie_name = my_strndup(beg, end - beg); |
| 2474 | curproxy->rdp_cookie_len = end-beg; |
| 2475 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2476 | else if (*(args[1] + 10) == '\0') { /* default cookie name 'msts' */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2477 | free(curproxy->rdp_cookie_name); |
| 2478 | curproxy->rdp_cookie_name = strdup("msts"); |
| 2479 | curproxy->rdp_cookie_len = strlen(curproxy->rdp_cookie_name); |
| 2480 | } |
| 2481 | else { /* syntax */ |
| 2482 | Alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n", |
| 2483 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2484 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2485 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2486 | } |
| 2487 | } |
| 2488 | else { |
| 2489 | Alert("parsing [%s:%d] : unknown persist method.\n", |
| 2490 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2491 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2492 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2493 | } |
| 2494 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2495 | else if (!strcmp(args[0], "appsession")) { /* cookie name */ |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2496 | int cur_arg; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2497 | |
Cyril Bonté | 3b7a369 | 2010-01-10 17:01:47 +0100 | [diff] [blame] | 2498 | if (curproxy == &defproxy) { |
| 2499 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2500 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2501 | goto out; |
| 2502 | } |
| 2503 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2504 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2505 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2506 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2507 | if (*(args[5]) == 0) { |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2508 | 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] | 2509 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2510 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2511 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2512 | } |
| 2513 | have_appsession = 1; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2514 | free(curproxy->appsession_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2515 | curproxy->appsession_name = strdup(args[1]); |
| 2516 | curproxy->appsession_name_len = strlen(curproxy->appsession_name); |
| 2517 | curproxy->appsession_len = atoi(args[3]); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 2518 | err = parse_time_err(args[5], &val, TIME_UNIT_MS); |
| 2519 | if (err) { |
| 2520 | Alert("parsing [%s:%d] : unexpected character '%c' in %s timeout.\n", |
| 2521 | file, linenum, *err, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2522 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2523 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 2524 | } |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 2525 | curproxy->timeout.appsession = val; |
Willy Tarreau | ee99136 | 2007-05-14 14:37:50 +0200 | [diff] [blame] | 2526 | |
Willy Tarreau | 51041c7 | 2007-09-09 21:56:53 +0200 | [diff] [blame] | 2527 | if (appsession_hash_init(&(curproxy->htbl_proxy), destroy) == 0) { |
| 2528 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2529 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2530 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2531 | } |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2532 | |
| 2533 | cur_arg = 6; |
| 2534 | curproxy->options2 &= ~PR_O2_AS_REQL; |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2535 | curproxy->options2 &= ~PR_O2_AS_M_ANY; |
| 2536 | curproxy->options2 |= PR_O2_AS_M_PP; |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2537 | while (*(args[cur_arg])) { |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2538 | if (!strcmp(args[cur_arg], "request-learn")) { |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2539 | curproxy->options2 |= PR_O2_AS_REQL; |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2540 | } else if (!strcmp(args[cur_arg], "prefix")) { |
| 2541 | curproxy->options2 |= PR_O2_AS_PFX; |
| 2542 | } else if (!strcmp(args[cur_arg], "mode")) { |
| 2543 | if (!*args[cur_arg + 1]) { |
| 2544 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 2545 | file, linenum, args[0], args[cur_arg]); |
| 2546 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2547 | goto out; |
| 2548 | } |
| 2549 | |
| 2550 | cur_arg++; |
| 2551 | if (!strcmp(args[cur_arg], "query-string")) { |
| 2552 | curproxy->options2 &= ~PR_O2_AS_M_ANY; |
| 2553 | curproxy->options2 |= PR_O2_AS_M_QS; |
| 2554 | } else if (!strcmp(args[cur_arg], "path-parameters")) { |
| 2555 | curproxy->options2 &= ~PR_O2_AS_M_ANY; |
| 2556 | curproxy->options2 |= PR_O2_AS_M_PP; |
| 2557 | } else { |
| 2558 | Alert("parsing [%s:%d] : unknown mode '%s'\n", file, linenum, args[cur_arg]); |
| 2559 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2560 | goto out; |
| 2561 | } |
| 2562 | } |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2563 | cur_arg++; |
| 2564 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2565 | } /* Url App Session */ |
| 2566 | else if (!strcmp(args[0], "capture")) { |
Willy Tarreau | 3b6b1a9 | 2009-07-23 13:24:23 +0200 | [diff] [blame] | 2567 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2568 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2569 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2570 | if (!strcmp(args[1], "cookie")) { /* name of a cookie to capture */ |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 2571 | if (curproxy == &defproxy) { |
| 2572 | Alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
| 2573 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2574 | goto out; |
| 2575 | } |
| 2576 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2577 | if (*(args[4]) == 0) { |
| 2578 | Alert("parsing [%s:%d] : '%s' expects 'cookie' <cookie_name> 'len' <len>.\n", |
| 2579 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2580 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2581 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2582 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2583 | free(curproxy->capture_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2584 | curproxy->capture_name = strdup(args[2]); |
| 2585 | curproxy->capture_namelen = strlen(curproxy->capture_name); |
| 2586 | curproxy->capture_len = atol(args[4]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2587 | curproxy->to_log |= LW_COOKIE; |
| 2588 | } |
| 2589 | else if (!strcmp(args[1], "request") && !strcmp(args[2], "header")) { |
| 2590 | struct cap_hdr *hdr; |
| 2591 | |
| 2592 | if (curproxy == &defproxy) { |
| 2593 | 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] | 2594 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2595 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2596 | } |
| 2597 | |
| 2598 | if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) { |
| 2599 | Alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n", |
| 2600 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2601 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2602 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2603 | } |
| 2604 | |
| 2605 | hdr = calloc(sizeof(struct cap_hdr), 1); |
| 2606 | hdr->next = curproxy->req_cap; |
| 2607 | hdr->name = strdup(args[3]); |
| 2608 | hdr->namelen = strlen(args[3]); |
| 2609 | hdr->len = atol(args[5]); |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 2610 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2611 | hdr->index = curproxy->nb_req_cap++; |
| 2612 | curproxy->req_cap = hdr; |
| 2613 | curproxy->to_log |= LW_REQHDR; |
| 2614 | } |
| 2615 | else if (!strcmp(args[1], "response") && !strcmp(args[2], "header")) { |
| 2616 | struct cap_hdr *hdr; |
| 2617 | |
| 2618 | if (curproxy == &defproxy) { |
| 2619 | 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] | 2620 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2621 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2622 | } |
| 2623 | |
| 2624 | if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) { |
| 2625 | Alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n", |
| 2626 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2627 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2628 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2629 | } |
| 2630 | hdr = calloc(sizeof(struct cap_hdr), 1); |
| 2631 | hdr->next = curproxy->rsp_cap; |
| 2632 | hdr->name = strdup(args[3]); |
| 2633 | hdr->namelen = strlen(args[3]); |
| 2634 | hdr->len = atol(args[5]); |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 2635 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2636 | hdr->index = curproxy->nb_rsp_cap++; |
| 2637 | curproxy->rsp_cap = hdr; |
| 2638 | curproxy->to_log |= LW_RSPHDR; |
| 2639 | } |
| 2640 | else { |
| 2641 | Alert("parsing [%s:%d] : '%s' expects 'cookie' or 'request header' or 'response header'.\n", |
| 2642 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2643 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2644 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2645 | } |
| 2646 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2647 | else if (!strcmp(args[0], "retries")) { /* connection retries */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2648 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2649 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2650 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2651 | if (*(args[1]) == 0) { |
| 2652 | Alert("parsing [%s:%d] : '%s' expects an integer argument (dispatch counts for one).\n", |
| 2653 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2654 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2655 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2656 | } |
| 2657 | curproxy->conn_retries = atol(args[1]); |
| 2658 | } |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2659 | 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] | 2660 | struct http_req_rule *rule; |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2661 | |
| 2662 | if (curproxy == &defproxy) { |
| 2663 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2664 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2665 | goto out; |
| 2666 | } |
| 2667 | |
Willy Tarreau | 20b0de5 | 2012-12-24 15:45:22 +0100 | [diff] [blame] | 2668 | if (!LIST_ISEMPTY(&curproxy->http_req_rules) && |
| 2669 | !LIST_PREV(&curproxy->http_req_rules, struct http_req_rule *, list)->cond && |
| 2670 | (LIST_PREV(&curproxy->http_req_rules, struct http_req_rule *, list)->action == HTTP_REQ_ACT_ALLOW || |
| 2671 | LIST_PREV(&curproxy->http_req_rules, struct http_req_rule *, list)->action == HTTP_REQ_ACT_DENY || |
Willy Tarreau | e365c0b | 2013-06-11 16:06:12 +0200 | [diff] [blame] | 2672 | LIST_PREV(&curproxy->http_req_rules, struct http_req_rule *, list)->action == HTTP_REQ_ACT_REDIR || |
Willy Tarreau | 20b0de5 | 2012-12-24 15:45:22 +0100 | [diff] [blame] | 2673 | LIST_PREV(&curproxy->http_req_rules, struct http_req_rule *, list)->action == HTTP_REQ_ACT_AUTH)) { |
| 2674 | Warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n", |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2675 | file, linenum, args[0]); |
| 2676 | err_code |= ERR_WARN; |
| 2677 | } |
| 2678 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 2679 | 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] | 2680 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 2681 | if (!rule) { |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2682 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2683 | goto out; |
| 2684 | } |
| 2685 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 2686 | err_code |= warnif_cond_conflicts(rule->cond, |
| 2687 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 2688 | file, linenum); |
| 2689 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 2690 | LIST_ADDQ(&curproxy->http_req_rules, &rule->list); |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2691 | } |
Willy Tarreau | e365c0b | 2013-06-11 16:06:12 +0200 | [diff] [blame] | 2692 | else if (!strcmp(args[0], "http-response")) { /* response access control */ |
| 2693 | struct http_res_rule *rule; |
| 2694 | |
| 2695 | if (curproxy == &defproxy) { |
| 2696 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2697 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2698 | goto out; |
| 2699 | } |
| 2700 | |
| 2701 | if (!LIST_ISEMPTY(&curproxy->http_res_rules) && |
| 2702 | !LIST_PREV(&curproxy->http_res_rules, struct http_res_rule *, list)->cond && |
| 2703 | (LIST_PREV(&curproxy->http_res_rules, struct http_res_rule *, list)->action == HTTP_RES_ACT_ALLOW || |
| 2704 | LIST_PREV(&curproxy->http_res_rules, struct http_res_rule *, list)->action == HTTP_RES_ACT_DENY)) { |
| 2705 | Warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n", |
| 2706 | file, linenum, args[0]); |
| 2707 | err_code |= ERR_WARN; |
| 2708 | } |
| 2709 | |
| 2710 | rule = parse_http_res_cond((const char **)args + 1, file, linenum, curproxy); |
| 2711 | |
| 2712 | if (!rule) { |
| 2713 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2714 | goto out; |
| 2715 | } |
| 2716 | |
| 2717 | err_code |= warnif_cond_conflicts(rule->cond, |
| 2718 | (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR, |
| 2719 | file, linenum); |
| 2720 | |
| 2721 | LIST_ADDQ(&curproxy->http_res_rules, &rule->list); |
| 2722 | } |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 2723 | else if (!strcmp(args[0], "http-send-name-header")) { /* send server name in request header */ |
| 2724 | /* set the header name and length into the proxy structure */ |
| 2725 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 2726 | err_code |= ERR_WARN; |
| 2727 | |
| 2728 | if (!*args[1]) { |
| 2729 | Alert("parsing [%s:%d] : '%s' requires a header string.\n", |
| 2730 | file, linenum, args[0]); |
| 2731 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2732 | goto out; |
| 2733 | } |
| 2734 | |
| 2735 | /* set the desired header name */ |
| 2736 | free(curproxy->server_id_hdr_name); |
| 2737 | curproxy->server_id_hdr_name = strdup(args[1]); |
| 2738 | curproxy->server_id_hdr_len = strlen(curproxy->server_id_hdr_name); |
| 2739 | } |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2740 | else if (!strcmp(args[0], "block")) { /* early blocking based on ACLs */ |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2741 | if (curproxy == &defproxy) { |
| 2742 | 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] | 2743 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2744 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2745 | } |
| 2746 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2747 | if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) { |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2748 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 2749 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2750 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2751 | goto out; |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2752 | } |
| 2753 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 2754 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 1, &errmsg)) == NULL) { |
| 2755 | Alert("parsing [%s:%d] : error detected while parsing blocking condition : %s.\n", |
| 2756 | file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2757 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2758 | goto out; |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2759 | } |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2760 | |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2761 | LIST_ADDQ(&curproxy->block_cond, &cond->list); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 2762 | warnif_misplaced_block(curproxy, file, linenum, args[0]); |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2763 | } |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2764 | else if (!strcmp(args[0], "redirect")) { |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2765 | struct redirect_rule *rule; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2766 | |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 2767 | if (curproxy == &defproxy) { |
| 2768 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2769 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2770 | goto out; |
| 2771 | } |
| 2772 | |
Thierry FOURNIER | d18cd0f | 2013-11-29 12:15:45 +0100 | [diff] [blame] | 2773 | if ((rule = http_parse_redirect_rule(file, linenum, curproxy, (const char **)args + 1, &errmsg, 0)) == NULL) { |
Willy Tarreau | 4baae24 | 2012-12-27 12:00:31 +0100 | [diff] [blame] | 2774 | Alert("parsing [%s:%d] : error detected in %s '%s' while parsing redirect rule : %s.\n", |
| 2775 | file, linenum, proxy_type_str(curproxy), curproxy->id, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2776 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2777 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2778 | } |
| 2779 | |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 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]); |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 2782 | err_code |= warnif_cond_conflicts(rule->cond, |
| 2783 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 2784 | file, linenum); |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2785 | } |
Krzysztof Piotr Oledzki | 7b723ef | 2009-01-27 21:09:41 +0100 | [diff] [blame] | 2786 | else if (!strcmp(args[0], "use_backend")) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2787 | struct switching_rule *rule; |
| 2788 | |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2789 | if (curproxy == &defproxy) { |
| 2790 | 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] | 2791 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2792 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2793 | } |
| 2794 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2795 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2796 | err_code |= ERR_WARN; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2797 | |
| 2798 | if (*(args[1]) == 0) { |
| 2799 | 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] | 2800 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2801 | goto out; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2802 | } |
| 2803 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2804 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2805 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 2806 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2807 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2808 | goto out; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2809 | } |
| 2810 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 2811 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 2812 | Alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n", |
| 2813 | file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2814 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2815 | goto out; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2816 | } |
| 2817 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 2818 | err_code |= warnif_cond_conflicts(cond, SMP_VAL_FE_SET_BCK, file, linenum); |
Willy Tarreau | a980263 | 2008-07-25 19:13:19 +0200 | [diff] [blame] | 2819 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2820 | rule = (struct switching_rule *)calloc(1, sizeof(*rule)); |
| 2821 | rule->cond = cond; |
| 2822 | rule->be.name = strdup(args[1]); |
| 2823 | LIST_INIT(&rule->list); |
| 2824 | LIST_ADDQ(&curproxy->switching_rules, &rule->list); |
| 2825 | } |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 2826 | else if (strcmp(args[0], "use-server") == 0) { |
| 2827 | struct server_rule *rule; |
| 2828 | |
| 2829 | if (curproxy == &defproxy) { |
| 2830 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2831 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2832 | goto out; |
| 2833 | } |
| 2834 | |
| 2835 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 2836 | err_code |= ERR_WARN; |
| 2837 | |
| 2838 | if (*(args[1]) == 0) { |
| 2839 | Alert("parsing [%s:%d] : '%s' expects a server name.\n", file, linenum, args[0]); |
| 2840 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2841 | goto out; |
| 2842 | } |
| 2843 | |
| 2844 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
| 2845 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 2846 | file, linenum, args[0]); |
| 2847 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2848 | goto out; |
| 2849 | } |
| 2850 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 2851 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 2852 | Alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n", |
| 2853 | file, linenum, errmsg); |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 2854 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2855 | goto out; |
| 2856 | } |
| 2857 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 2858 | err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum); |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 2859 | |
| 2860 | rule = (struct server_rule *)calloc(1, sizeof(*rule)); |
| 2861 | rule->cond = cond; |
| 2862 | rule->srv.name = strdup(args[1]); |
| 2863 | LIST_INIT(&rule->list); |
| 2864 | LIST_ADDQ(&curproxy->server_rules, &rule->list); |
| 2865 | curproxy->be_req_ana |= AN_REQ_SRV_RULES; |
| 2866 | } |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 2867 | else if ((!strcmp(args[0], "force-persist")) || |
| 2868 | (!strcmp(args[0], "ignore-persist"))) { |
| 2869 | struct persist_rule *rule; |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2870 | |
| 2871 | if (curproxy == &defproxy) { |
| 2872 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2873 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2874 | goto out; |
| 2875 | } |
| 2876 | |
| 2877 | if (warnifnotcap(curproxy, PR_CAP_FE|PR_CAP_BE, file, linenum, args[0], NULL)) |
| 2878 | err_code |= ERR_WARN; |
| 2879 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2880 | if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) { |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2881 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 2882 | file, linenum, args[0]); |
| 2883 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2884 | goto out; |
| 2885 | } |
| 2886 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 2887 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 1, &errmsg)) == NULL) { |
| 2888 | Alert("parsing [%s:%d] : error detected while parsing a '%s' rule : %s.\n", |
| 2889 | file, linenum, args[0], errmsg); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2890 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2891 | goto out; |
| 2892 | } |
| 2893 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 2894 | /* note: BE_REQ_CNT is the first one after FE_SET_BCK, which is |
| 2895 | * where force-persist is applied. |
| 2896 | */ |
| 2897 | err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_REQ_CNT, file, linenum); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2898 | |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 2899 | rule = (struct persist_rule *)calloc(1, sizeof(*rule)); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2900 | rule->cond = cond; |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 2901 | if (!strcmp(args[0], "force-persist")) { |
| 2902 | rule->type = PERSIST_TYPE_FORCE; |
| 2903 | } else { |
| 2904 | rule->type = PERSIST_TYPE_IGNORE; |
| 2905 | } |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2906 | LIST_INIT(&rule->list); |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 2907 | LIST_ADDQ(&curproxy->persist_rules, &rule->list); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2908 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2909 | else if (!strcmp(args[0], "stick-table")) { |
| 2910 | int myidx = 1; |
| 2911 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2912 | curproxy->table.id = curproxy->id; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2913 | curproxy->table.type = (unsigned int)-1; |
| 2914 | while (*args[myidx]) { |
| 2915 | const char *err; |
| 2916 | |
| 2917 | if (strcmp(args[myidx], "size") == 0) { |
| 2918 | myidx++; |
| 2919 | if (!*(args[myidx])) { |
| 2920 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 2921 | file, linenum, args[myidx-1]); |
| 2922 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2923 | goto out; |
| 2924 | } |
| 2925 | if ((err = parse_size_err(args[myidx], &curproxy->table.size))) { |
| 2926 | Alert("parsing [%s:%d] : stick-table: unexpected character '%c' in argument of '%s'.\n", |
| 2927 | file, linenum, *err, args[myidx-1]); |
| 2928 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2929 | goto out; |
| 2930 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 2931 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2932 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2933 | else if (strcmp(args[myidx], "peers") == 0) { |
| 2934 | myidx++; |
| 2935 | if (!*(args[myidx])) { |
| 2936 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 2937 | file, linenum, args[myidx-1]); |
| 2938 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2939 | goto out; |
| 2940 | } |
| 2941 | curproxy->table.peers.name = strdup(args[myidx++]); |
| 2942 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2943 | else if (strcmp(args[myidx], "expire") == 0) { |
| 2944 | myidx++; |
| 2945 | if (!*(args[myidx])) { |
| 2946 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 2947 | file, linenum, args[myidx-1]); |
| 2948 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2949 | goto out; |
| 2950 | } |
| 2951 | err = parse_time_err(args[myidx], &val, TIME_UNIT_MS); |
| 2952 | if (err) { |
| 2953 | Alert("parsing [%s:%d] : stick-table: unexpected character '%c' in argument of '%s'.\n", |
| 2954 | file, linenum, *err, args[myidx-1]); |
| 2955 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2956 | goto out; |
| 2957 | } |
| 2958 | curproxy->table.expire = val; |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 2959 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2960 | } |
| 2961 | else if (strcmp(args[myidx], "nopurge") == 0) { |
| 2962 | curproxy->table.nopurge = 1; |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 2963 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2964 | } |
| 2965 | else if (strcmp(args[myidx], "type") == 0) { |
| 2966 | myidx++; |
| 2967 | if (stktable_parse_type(args, &myidx, &curproxy->table.type, &curproxy->table.key_size) != 0) { |
| 2968 | Alert("parsing [%s:%d] : stick-table: unknown type '%s'.\n", |
| 2969 | file, linenum, args[myidx]); |
| 2970 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2971 | goto out; |
| 2972 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 2973 | /* myidx already points to next arg */ |
| 2974 | } |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 2975 | else if (strcmp(args[myidx], "store") == 0) { |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 2976 | int type, err; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 2977 | char *cw, *nw, *sa; |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 2978 | |
| 2979 | myidx++; |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 2980 | nw = args[myidx]; |
| 2981 | while (*nw) { |
| 2982 | /* the "store" keyword supports a comma-separated list */ |
| 2983 | cw = nw; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 2984 | sa = NULL; /* store arg */ |
| 2985 | while (*nw && *nw != ',') { |
| 2986 | if (*nw == '(') { |
| 2987 | *nw = 0; |
| 2988 | sa = ++nw; |
| 2989 | while (*nw != ')') { |
| 2990 | if (!*nw) { |
| 2991 | Alert("parsing [%s:%d] : %s: missing closing parenthesis after store option '%s'.\n", |
| 2992 | file, linenum, args[0], cw); |
| 2993 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2994 | goto out; |
| 2995 | } |
| 2996 | nw++; |
| 2997 | } |
| 2998 | *nw = '\0'; |
| 2999 | } |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 3000 | nw++; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 3001 | } |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 3002 | if (*nw) |
| 3003 | *nw++ = '\0'; |
| 3004 | type = stktable_get_data_type(cw); |
| 3005 | if (type < 0) { |
| 3006 | Alert("parsing [%s:%d] : %s: unknown store option '%s'.\n", |
| 3007 | file, linenum, args[0], cw); |
| 3008 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3009 | goto out; |
| 3010 | } |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 3011 | |
| 3012 | err = stktable_alloc_data_type(&curproxy->table, type, sa); |
| 3013 | switch (err) { |
| 3014 | case PE_NONE: break; |
| 3015 | case PE_EXIST: |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 3016 | Warning("parsing [%s:%d]: %s: store option '%s' already enabled, ignored.\n", |
| 3017 | file, linenum, args[0], cw); |
| 3018 | err_code |= ERR_WARN; |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 3019 | break; |
| 3020 | |
| 3021 | case PE_ARG_MISSING: |
| 3022 | Alert("parsing [%s:%d] : %s: missing argument to store option '%s'.\n", |
| 3023 | file, linenum, args[0], cw); |
| 3024 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3025 | goto out; |
| 3026 | |
| 3027 | case PE_ARG_NOT_USED: |
| 3028 | Alert("parsing [%s:%d] : %s: unexpected argument to store option '%s'.\n", |
| 3029 | file, linenum, args[0], cw); |
| 3030 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3031 | goto out; |
| 3032 | |
| 3033 | default: |
| 3034 | Alert("parsing [%s:%d] : %s: error when processing store option '%s'.\n", |
| 3035 | file, linenum, args[0], cw); |
| 3036 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3037 | goto out; |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 3038 | } |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 3039 | } |
| 3040 | myidx++; |
| 3041 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 3042 | else { |
| 3043 | Alert("parsing [%s:%d] : stick-table: unknown argument '%s'.\n", |
| 3044 | file, linenum, args[myidx]); |
| 3045 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3046 | goto out; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3047 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3048 | } |
| 3049 | |
| 3050 | if (!curproxy->table.size) { |
| 3051 | Alert("parsing [%s:%d] : stick-table: missing size.\n", |
| 3052 | file, linenum); |
| 3053 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3054 | goto out; |
| 3055 | } |
| 3056 | |
| 3057 | if (curproxy->table.type == (unsigned int)-1) { |
| 3058 | Alert("parsing [%s:%d] : stick-table: missing type.\n", |
| 3059 | file, linenum); |
| 3060 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3061 | goto out; |
| 3062 | } |
| 3063 | } |
| 3064 | else if (!strcmp(args[0], "stick")) { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3065 | struct sticking_rule *rule; |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 3066 | struct sample_expr *expr; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3067 | int myidx = 0; |
| 3068 | const char *name = NULL; |
| 3069 | int flags; |
| 3070 | |
| 3071 | if (curproxy == &defproxy) { |
| 3072 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3073 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3074 | goto out; |
| 3075 | } |
| 3076 | |
| 3077 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) { |
| 3078 | err_code |= ERR_WARN; |
| 3079 | goto out; |
| 3080 | } |
| 3081 | |
| 3082 | myidx++; |
| 3083 | if ((strcmp(args[myidx], "store") == 0) || |
| 3084 | (strcmp(args[myidx], "store-request") == 0)) { |
| 3085 | myidx++; |
| 3086 | flags = STK_IS_STORE; |
| 3087 | } |
| 3088 | else if (strcmp(args[myidx], "store-response") == 0) { |
| 3089 | myidx++; |
| 3090 | flags = STK_IS_STORE | STK_ON_RSP; |
| 3091 | } |
| 3092 | else if (strcmp(args[myidx], "match") == 0) { |
| 3093 | myidx++; |
| 3094 | flags = STK_IS_MATCH; |
| 3095 | } |
| 3096 | else if (strcmp(args[myidx], "on") == 0) { |
| 3097 | myidx++; |
| 3098 | flags = STK_IS_MATCH | STK_IS_STORE; |
| 3099 | } |
| 3100 | else { |
| 3101 | Alert("parsing [%s:%d] : '%s' expects 'on', 'match', or 'store'.\n", file, linenum, args[0]); |
| 3102 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3103 | goto out; |
| 3104 | } |
| 3105 | |
| 3106 | if (*(args[myidx]) == 0) { |
| 3107 | Alert("parsing [%s:%d] : '%s' expects a fetch method.\n", file, linenum, args[0]); |
| 3108 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3109 | goto out; |
| 3110 | } |
| 3111 | |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 3112 | curproxy->conf.args.ctx = ARGC_STK; |
| 3113 | expr = sample_parse_expr(args, &myidx, trash.str, trash.size, &curproxy->conf.args); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3114 | if (!expr) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3115 | 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] | 3116 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3117 | goto out; |
| 3118 | } |
| 3119 | |
| 3120 | if (flags & STK_ON_RSP) { |
Willy Tarreau | 80aca90 | 2013-01-07 15:42:20 +0100 | [diff] [blame] | 3121 | if (!(expr->fetch->val & SMP_VAL_BE_STO_RUL)) { |
| 3122 | Alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available for 'store-response'.\n", |
| 3123 | file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use)); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3124 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 3125 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3126 | goto out; |
| 3127 | } |
| 3128 | } else { |
Willy Tarreau | 80aca90 | 2013-01-07 15:42:20 +0100 | [diff] [blame] | 3129 | if (!(expr->fetch->val & SMP_VAL_BE_SET_SRV)) { |
| 3130 | Alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available during request.\n", |
| 3131 | file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use)); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3132 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 3133 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3134 | goto out; |
| 3135 | } |
| 3136 | } |
| 3137 | |
Willy Tarreau | 1b6c00c | 2012-10-05 22:41:26 +0200 | [diff] [blame] | 3138 | /* check if we need to allocate an hdr_idx struct for HTTP parsing */ |
Willy Tarreau | 25320b2 | 2013-03-24 07:22:08 +0100 | [diff] [blame] | 3139 | curproxy->http_needed |= !!(expr->fetch->use & SMP_USE_HTTP_ANY); |
Willy Tarreau | 1b6c00c | 2012-10-05 22:41:26 +0200 | [diff] [blame] | 3140 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3141 | if (strcmp(args[myidx], "table") == 0) { |
| 3142 | myidx++; |
| 3143 | name = args[myidx++]; |
| 3144 | } |
| 3145 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 3146 | if (strcmp(args[myidx], "if") == 0 || strcmp(args[myidx], "unless") == 0) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 3147 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + myidx, &errmsg)) == NULL) { |
| 3148 | Alert("parsing [%s:%d] : '%s': error detected while parsing sticking condition : %s.\n", |
| 3149 | file, linenum, args[0], errmsg); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3150 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 3151 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3152 | goto out; |
| 3153 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3154 | } |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 3155 | else if (*(args[myidx])) { |
| 3156 | Alert("parsing [%s:%d] : '%s': unknown keyword '%s'.\n", |
| 3157 | file, linenum, args[0], args[myidx]); |
| 3158 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 3159 | free(expr); |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 3160 | goto out; |
| 3161 | } |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 3162 | if (flags & STK_ON_RSP) |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3163 | err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_STO_RUL, file, linenum); |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 3164 | else |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3165 | err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum); |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 3166 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3167 | rule = (struct sticking_rule *)calloc(1, sizeof(*rule)); |
| 3168 | rule->cond = cond; |
| 3169 | rule->expr = expr; |
| 3170 | rule->flags = flags; |
| 3171 | rule->table.name = name ? strdup(name) : NULL; |
| 3172 | LIST_INIT(&rule->list); |
| 3173 | if (flags & STK_ON_RSP) |
| 3174 | LIST_ADDQ(&curproxy->storersp_rules, &rule->list); |
| 3175 | else |
| 3176 | LIST_ADDQ(&curproxy->sticking_rules, &rule->list); |
| 3177 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3178 | else if (!strcmp(args[0], "stats")) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3179 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3180 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3181 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3182 | if (curproxy != &defproxy && curproxy->uri_auth == defproxy.uri_auth) |
| 3183 | curproxy->uri_auth = NULL; /* we must detach from the default config */ |
| 3184 | |
Krzysztof Piotr Oledzki | 260a3bb | 2010-01-06 16:25:05 +0100 | [diff] [blame] | 3185 | if (!*args[1]) { |
| 3186 | goto stats_error_parsing; |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3187 | } else if (!strcmp(args[1], "admin")) { |
| 3188 | struct stats_admin_rule *rule; |
| 3189 | |
| 3190 | if (curproxy == &defproxy) { |
| 3191 | Alert("parsing [%s:%d]: '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
| 3192 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3193 | goto out; |
| 3194 | } |
| 3195 | |
| 3196 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 3197 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3198 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3199 | goto out; |
| 3200 | } |
| 3201 | |
| 3202 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
| 3203 | Alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n", |
| 3204 | file, linenum, args[0], args[1]); |
| 3205 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3206 | goto out; |
| 3207 | } |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 3208 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 3209 | Alert("parsing [%s:%d] : error detected while parsing a '%s %s' rule : %s.\n", |
| 3210 | file, linenum, args[0], args[1], errmsg); |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3211 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3212 | goto out; |
| 3213 | } |
| 3214 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3215 | err_code |= warnif_cond_conflicts(cond, |
| 3216 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 3217 | file, linenum); |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3218 | |
| 3219 | rule = (struct stats_admin_rule *)calloc(1, sizeof(*rule)); |
| 3220 | rule->cond = cond; |
| 3221 | LIST_INIT(&rule->list); |
| 3222 | LIST_ADDQ(&curproxy->uri_auth->admin_rules, &rule->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3223 | } else if (!strcmp(args[1], "uri")) { |
| 3224 | if (*(args[2]) == 0) { |
| 3225 | Alert("parsing [%s:%d] : 'uri' needs an URI prefix.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3226 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3227 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3228 | } else if (!stats_set_uri(&curproxy->uri_auth, args[2])) { |
| 3229 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3230 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3231 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3232 | } |
| 3233 | } else if (!strcmp(args[1], "realm")) { |
| 3234 | if (*(args[2]) == 0) { |
| 3235 | Alert("parsing [%s:%d] : 'realm' needs an realm name.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3236 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3237 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3238 | } else if (!stats_set_realm(&curproxy->uri_auth, args[2])) { |
| 3239 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3240 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3241 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3242 | } |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 3243 | } else if (!strcmp(args[1], "refresh")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 3244 | unsigned interval; |
| 3245 | |
| 3246 | err = parse_time_err(args[2], &interval, TIME_UNIT_S); |
| 3247 | if (err) { |
| 3248 | Alert("parsing [%s:%d] : unexpected character '%c' in stats refresh interval.\n", |
| 3249 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3250 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3251 | goto out; |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 3252 | } else if (!stats_set_refresh(&curproxy->uri_auth, interval)) { |
| 3253 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3254 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3255 | goto out; |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 3256 | } |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3257 | } 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] | 3258 | struct http_req_rule *rule; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3259 | |
| 3260 | if (curproxy == &defproxy) { |
| 3261 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3262 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3263 | goto out; |
| 3264 | } |
| 3265 | |
| 3266 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 3267 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3268 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3269 | goto out; |
| 3270 | } |
| 3271 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3272 | if (!LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) && |
| 3273 | !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] | 3274 | Warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n", |
| 3275 | file, linenum, args[0]); |
| 3276 | err_code |= ERR_WARN; |
| 3277 | } |
| 3278 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3279 | 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] | 3280 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3281 | if (!rule) { |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3282 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3283 | goto out; |
| 3284 | } |
| 3285 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3286 | err_code |= warnif_cond_conflicts(rule->cond, |
| 3287 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 3288 | file, linenum); |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3289 | LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list); |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3290 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3291 | } else if (!strcmp(args[1], "auth")) { |
| 3292 | if (*(args[2]) == 0) { |
| 3293 | 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] | 3294 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3295 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3296 | } else if (!stats_add_auth(&curproxy->uri_auth, args[2])) { |
| 3297 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3298 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3299 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3300 | } |
| 3301 | } else if (!strcmp(args[1], "scope")) { |
| 3302 | if (*(args[2]) == 0) { |
| 3303 | Alert("parsing [%s:%d] : 'scope' needs a proxy name.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3304 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3305 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3306 | } else if (!stats_add_scope(&curproxy->uri_auth, args[2])) { |
| 3307 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3308 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3309 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3310 | } |
| 3311 | } else if (!strcmp(args[1], "enable")) { |
| 3312 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 3313 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3314 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3315 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3316 | } |
Krzysztof Oledzki | d9db927 | 2007-10-15 10:05:11 +0200 | [diff] [blame] | 3317 | } else if (!strcmp(args[1], "hide-version")) { |
| 3318 | if (!stats_set_flag(&curproxy->uri_auth, ST_HIDEVER)) { |
| 3319 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3320 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3321 | goto out; |
Krzysztof Oledzki | d9db927 | 2007-10-15 10:05:11 +0200 | [diff] [blame] | 3322 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3323 | } else if (!strcmp(args[1], "show-legends")) { |
| 3324 | if (!stats_set_flag(&curproxy->uri_auth, ST_SHLGNDS)) { |
| 3325 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3326 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3327 | goto out; |
| 3328 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3329 | } else if (!strcmp(args[1], "show-node")) { |
| 3330 | |
| 3331 | if (*args[2]) { |
| 3332 | int i; |
| 3333 | char c; |
| 3334 | |
| 3335 | for (i=0; args[2][i]; i++) { |
| 3336 | c = args[2][i]; |
Willy Tarreau | 88e0581 | 2010-03-03 00:16:00 +0100 | [diff] [blame] | 3337 | if (!isupper((unsigned char)c) && !islower((unsigned char)c) && |
| 3338 | !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.') |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3339 | break; |
| 3340 | } |
| 3341 | |
| 3342 | if (!i || args[2][i]) { |
| 3343 | Alert("parsing [%s:%d]: '%s %s' invalid node name - should be a string" |
| 3344 | "with digits(0-9), letters(A-Z, a-z), hyphen(-) or underscode(_).\n", |
| 3345 | file, linenum, args[0], args[1]); |
| 3346 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3347 | goto out; |
| 3348 | } |
| 3349 | } |
| 3350 | |
| 3351 | if (!stats_set_node(&curproxy->uri_auth, args[2])) { |
| 3352 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3353 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3354 | goto out; |
| 3355 | } |
| 3356 | } else if (!strcmp(args[1], "show-desc")) { |
| 3357 | char *desc = NULL; |
| 3358 | |
| 3359 | if (*args[2]) { |
| 3360 | int i, len=0; |
| 3361 | char *d; |
| 3362 | |
| 3363 | for(i=2; *args[i]; i++) |
| 3364 | len += strlen(args[i])+1; |
| 3365 | |
| 3366 | desc = d = (char *)calloc(1, len); |
| 3367 | |
| 3368 | d += sprintf(d, "%s", args[2]); |
| 3369 | for(i=3; *args[i]; i++) |
| 3370 | d += sprintf(d, " %s", args[i]); |
| 3371 | } |
| 3372 | |
| 3373 | if (!*args[2] && !global.desc) |
| 3374 | Warning("parsing [%s:%d]: '%s' requires a parameter or 'desc' to be set in the global section.\n", |
| 3375 | file, linenum, args[1]); |
| 3376 | else { |
| 3377 | if (!stats_set_desc(&curproxy->uri_auth, desc)) { |
| 3378 | free(desc); |
| 3379 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3380 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3381 | goto out; |
| 3382 | } |
| 3383 | free(desc); |
| 3384 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3385 | } else { |
Krzysztof Piotr Oledzki | 260a3bb | 2010-01-06 16:25:05 +0100 | [diff] [blame] | 3386 | stats_error_parsing: |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3387 | 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] | 3388 | 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] | 3389 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3390 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3391 | } |
| 3392 | } |
| 3393 | else if (!strcmp(args[0], "option")) { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3394 | int optnum; |
| 3395 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3396 | if (*(args[1]) == '\0') { |
| 3397 | Alert("parsing [%s:%d]: '%s' expects an option name.\n", |
| 3398 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3399 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3400 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3401 | } |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3402 | |
| 3403 | for (optnum = 0; cfg_opts[optnum].name; optnum++) { |
| 3404 | if (!strcmp(args[1], cfg_opts[optnum].name)) { |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 3405 | if (cfg_opts[optnum].cap == PR_CAP_NONE) { |
| 3406 | Alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n", |
| 3407 | file, linenum, cfg_opts[optnum].name); |
| 3408 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3409 | goto out; |
| 3410 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3411 | if (warnifnotcap(curproxy, cfg_opts[optnum].cap, file, linenum, args[1], NULL)) { |
| 3412 | err_code |= ERR_WARN; |
| 3413 | goto out; |
| 3414 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3415 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 3416 | curproxy->no_options &= ~cfg_opts[optnum].val; |
| 3417 | curproxy->options &= ~cfg_opts[optnum].val; |
| 3418 | |
| 3419 | switch (kwm) { |
| 3420 | case KWM_STD: |
| 3421 | curproxy->options |= cfg_opts[optnum].val; |
| 3422 | break; |
| 3423 | case KWM_NO: |
| 3424 | curproxy->no_options |= cfg_opts[optnum].val; |
| 3425 | break; |
| 3426 | case KWM_DEF: /* already cleared */ |
| 3427 | break; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 3428 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3429 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3430 | goto out; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3431 | } |
| 3432 | } |
| 3433 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 3434 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) { |
| 3435 | if (!strcmp(args[1], cfg_opts2[optnum].name)) { |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 3436 | if (cfg_opts2[optnum].cap == PR_CAP_NONE) { |
| 3437 | Alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n", |
| 3438 | file, linenum, cfg_opts2[optnum].name); |
| 3439 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3440 | goto out; |
| 3441 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3442 | if (warnifnotcap(curproxy, cfg_opts2[optnum].cap, file, linenum, args[1], NULL)) { |
| 3443 | err_code |= ERR_WARN; |
| 3444 | goto out; |
| 3445 | } |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 3446 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 3447 | curproxy->no_options2 &= ~cfg_opts2[optnum].val; |
| 3448 | curproxy->options2 &= ~cfg_opts2[optnum].val; |
| 3449 | |
| 3450 | switch (kwm) { |
| 3451 | case KWM_STD: |
| 3452 | curproxy->options2 |= cfg_opts2[optnum].val; |
| 3453 | break; |
| 3454 | case KWM_NO: |
| 3455 | curproxy->no_options2 |= cfg_opts2[optnum].val; |
| 3456 | break; |
| 3457 | case KWM_DEF: /* already cleared */ |
| 3458 | break; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 3459 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3460 | goto out; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 3461 | } |
| 3462 | } |
| 3463 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 3464 | if (kwm != KWM_STD) { |
| 3465 | 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] | 3466 | file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3467 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3468 | goto out; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3469 | } |
| 3470 | |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3471 | if (!strcmp(args[1], "httplog")) { |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 3472 | char *logformat; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3473 | /* generate a complete HTTP log */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 3474 | logformat = default_http_log_format; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3475 | if (*(args[2]) != '\0') { |
| 3476 | if (!strcmp(args[2], "clf")) { |
| 3477 | curproxy->options2 |= PR_O2_CLFLOG; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 3478 | logformat = clf_http_log_format; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3479 | } else { |
| 3480 | 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] | 3481 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3482 | goto out; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3483 | } |
| 3484 | } |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 3485 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 3486 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 3487 | curproxy->conf.logformat_string != clf_http_log_format) |
| 3488 | free(curproxy->conf.logformat_string); |
| 3489 | curproxy->conf.logformat_string = logformat; |
| 3490 | |
| 3491 | free(curproxy->conf.lfs_file); |
| 3492 | curproxy->conf.lfs_file = strdup(curproxy->conf.args.file); |
| 3493 | curproxy->conf.lfs_line = curproxy->conf.args.line; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3494 | } |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 3495 | else if (!strcmp(args[1], "tcplog")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3496 | /* generate a detailed TCP log */ |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 3497 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 3498 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 3499 | curproxy->conf.logformat_string != clf_http_log_format) |
| 3500 | free(curproxy->conf.logformat_string); |
| 3501 | curproxy->conf.logformat_string = default_tcp_log_format; |
| 3502 | |
| 3503 | free(curproxy->conf.lfs_file); |
| 3504 | curproxy->conf.lfs_file = strdup(curproxy->conf.args.file); |
| 3505 | curproxy->conf.lfs_line = curproxy->conf.args.line; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 3506 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3507 | else if (!strcmp(args[1], "tcpka")) { |
| 3508 | /* enable TCP keep-alives on client and server sessions */ |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3509 | if (warnifnotcap(curproxy, PR_CAP_BE | PR_CAP_FE, file, linenum, args[1], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3510 | err_code |= ERR_WARN; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3511 | |
| 3512 | if (curproxy->cap & PR_CAP_FE) |
| 3513 | curproxy->options |= PR_O_TCP_CLI_KA; |
| 3514 | if (curproxy->cap & PR_CAP_BE) |
| 3515 | curproxy->options |= PR_O_TCP_SRV_KA; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3516 | } |
| 3517 | else if (!strcmp(args[1], "httpchk")) { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3518 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3519 | err_code |= ERR_WARN; |
| 3520 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3521 | /* use HTTP request to check servers' health */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3522 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 3523 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3524 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 3525 | curproxy->options2 |= PR_O2_HTTP_CHK; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3526 | if (!*args[2]) { /* no argument */ |
| 3527 | curproxy->check_req = strdup(DEF_CHECK_REQ); /* default request */ |
| 3528 | curproxy->check_len = strlen(DEF_CHECK_REQ); |
| 3529 | } else if (!*args[3]) { /* one argument : URI */ |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3530 | int reqlen = strlen(args[2]) + strlen("OPTIONS HTTP/1.0\r\n") + 1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3531 | curproxy->check_req = (char *)malloc(reqlen); |
| 3532 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3533 | "OPTIONS %s HTTP/1.0\r\n", args[2]); /* URI to use */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3534 | } else { /* more arguments : METHOD URI [HTTP_VER] */ |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3535 | int reqlen = strlen(args[2]) + strlen(args[3]) + 3 + strlen("\r\n"); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3536 | if (*args[4]) |
| 3537 | reqlen += strlen(args[4]); |
| 3538 | else |
| 3539 | reqlen += strlen("HTTP/1.0"); |
| 3540 | |
| 3541 | curproxy->check_req = (char *)malloc(reqlen); |
| 3542 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3543 | "%s %s %s\r\n", args[2], args[3], *args[4]?args[4]:"HTTP/1.0"); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3544 | } |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 3545 | } |
| 3546 | else if (!strcmp(args[1], "ssl-hello-chk")) { |
| 3547 | /* use SSLv3 CLIENT HELLO to check servers' health */ |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3548 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3549 | err_code |= ERR_WARN; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3550 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3551 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 3552 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3553 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Willy Tarreau | 07a5490 | 2010-03-29 18:33:29 +0200 | [diff] [blame] | 3554 | curproxy->options2 |= PR_O2_SSL3_CHK; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3555 | } |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 3556 | else if (!strcmp(args[1], "smtpchk")) { |
| 3557 | /* use SMTP request to check servers' health */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3558 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 3559 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3560 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 3561 | curproxy->options2 |= PR_O2_SMTP_CHK; |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 3562 | |
| 3563 | if (!*args[2] || !*args[3]) { /* no argument or incomplete EHLO host */ |
| 3564 | curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */ |
| 3565 | curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ); |
| 3566 | } else { /* ESMTP EHLO, or SMTP HELO, and a hostname */ |
| 3567 | if (!strcmp(args[2], "EHLO") || !strcmp(args[2], "HELO")) { |
| 3568 | int reqlen = strlen(args[2]) + strlen(args[3]) + strlen(" \r\n") + 1; |
| 3569 | curproxy->check_req = (char *)malloc(reqlen); |
| 3570 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
| 3571 | "%s %s\r\n", args[2], args[3]); /* HELO hostname */ |
| 3572 | } else { |
| 3573 | /* this just hits the default for now, but you could potentially expand it to allow for other stuff |
| 3574 | though, it's unlikely you'd want to send anything other than an EHLO or HELO */ |
| 3575 | curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */ |
| 3576 | curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ); |
| 3577 | } |
| 3578 | } |
| 3579 | } |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 3580 | else if (!strcmp(args[1], "pgsql-check")) { |
| 3581 | /* use PostgreSQL request to check servers' health */ |
| 3582 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 3583 | err_code |= ERR_WARN; |
| 3584 | |
| 3585 | free(curproxy->check_req); |
| 3586 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3587 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 3588 | curproxy->options2 |= PR_O2_PGSQL_CHK; |
| 3589 | |
| 3590 | if (*(args[2])) { |
| 3591 | int cur_arg = 2; |
| 3592 | |
| 3593 | while (*(args[cur_arg])) { |
| 3594 | if (strcmp(args[cur_arg], "user") == 0) { |
| 3595 | char * packet; |
| 3596 | uint32_t packet_len; |
| 3597 | uint32_t pv; |
| 3598 | |
| 3599 | /* suboption header - needs additional argument for it */ |
| 3600 | if (*(args[cur_arg+1]) == 0) { |
| 3601 | Alert("parsing [%s:%d] : '%s %s %s' expects <username> as argument.\n", |
| 3602 | file, linenum, args[0], args[1], args[cur_arg]); |
| 3603 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3604 | goto out; |
| 3605 | } |
| 3606 | |
| 3607 | /* uint32_t + uint32_t + strlen("user")+1 + strlen(username)+1 + 1 */ |
| 3608 | packet_len = 4 + 4 + 5 + strlen(args[cur_arg + 1])+1 +1; |
| 3609 | pv = htonl(0x30000); /* protocol version 3.0 */ |
| 3610 | |
| 3611 | packet = (char*) calloc(1, packet_len); |
| 3612 | |
| 3613 | memcpy(packet + 4, &pv, 4); |
| 3614 | |
| 3615 | /* copy "user" */ |
| 3616 | memcpy(packet + 8, "user", 4); |
| 3617 | |
| 3618 | /* copy username */ |
| 3619 | memcpy(packet + 13, args[cur_arg+1], strlen(args[cur_arg+1])); |
| 3620 | |
| 3621 | free(curproxy->check_req); |
| 3622 | curproxy->check_req = packet; |
| 3623 | curproxy->check_len = packet_len; |
| 3624 | |
| 3625 | packet_len = htonl(packet_len); |
| 3626 | memcpy(packet, &packet_len, 4); |
| 3627 | cur_arg += 2; |
| 3628 | } else { |
| 3629 | /* unknown suboption - catchall */ |
| 3630 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'user'.\n", |
| 3631 | file, linenum, args[0], args[1]); |
| 3632 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3633 | goto out; |
| 3634 | } |
| 3635 | } /* end while loop */ |
| 3636 | } |
| 3637 | } |
| 3638 | |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 3639 | else if (!strcmp(args[1], "redis-check")) { |
| 3640 | /* use REDIS PING request to check servers' health */ |
| 3641 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 3642 | err_code |= ERR_WARN; |
| 3643 | |
| 3644 | free(curproxy->check_req); |
| 3645 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3646 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 3647 | curproxy->options2 |= PR_O2_REDIS_CHK; |
| 3648 | |
| 3649 | curproxy->check_req = (char *) malloc(sizeof(DEF_REDIS_CHECK_REQ) - 1); |
| 3650 | memcpy(curproxy->check_req, DEF_REDIS_CHECK_REQ, sizeof(DEF_REDIS_CHECK_REQ) - 1); |
| 3651 | curproxy->check_len = sizeof(DEF_REDIS_CHECK_REQ) - 1; |
| 3652 | } |
| 3653 | |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 3654 | else if (!strcmp(args[1], "mysql-check")) { |
| 3655 | /* use MYSQL request to check servers' health */ |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 3656 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 3657 | err_code |= ERR_WARN; |
| 3658 | |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 3659 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 3660 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3661 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 3662 | curproxy->options2 |= PR_O2_MYSQL_CHK; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 3663 | |
| 3664 | /* This is an exemple of an MySQL >=4.0 client Authentication packet kindly provided by Cyril Bonte. |
| 3665 | * const char mysql40_client_auth_pkt[] = { |
| 3666 | * "\x0e\x00\x00" // packet length |
| 3667 | * "\x01" // packet number |
| 3668 | * "\x00\x00" // client capabilities |
| 3669 | * "\x00\x00\x01" // max packet |
| 3670 | * "haproxy\x00" // username (null terminated string) |
| 3671 | * "\x00" // filler (always 0x00) |
| 3672 | * "\x01\x00\x00" // packet length |
| 3673 | * "\x00" // packet number |
| 3674 | * "\x01" // COM_QUIT command |
| 3675 | * }; |
| 3676 | */ |
| 3677 | |
| 3678 | if (*(args[2])) { |
| 3679 | int cur_arg = 2; |
| 3680 | |
| 3681 | while (*(args[cur_arg])) { |
| 3682 | if (strcmp(args[cur_arg], "user") == 0) { |
| 3683 | char *mysqluser; |
| 3684 | int packetlen, reqlen, userlen; |
| 3685 | |
| 3686 | /* suboption header - needs additional argument for it */ |
| 3687 | if (*(args[cur_arg+1]) == 0) { |
| 3688 | Alert("parsing [%s:%d] : '%s %s %s' expects <username> as argument.\n", |
| 3689 | file, linenum, args[0], args[1], args[cur_arg]); |
| 3690 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3691 | goto out; |
| 3692 | } |
| 3693 | mysqluser = args[cur_arg + 1]; |
| 3694 | userlen = strlen(mysqluser); |
| 3695 | packetlen = userlen + 7; |
| 3696 | reqlen = packetlen + 9; |
| 3697 | |
| 3698 | free(curproxy->check_req); |
| 3699 | curproxy->check_req = (char *)calloc(1, reqlen); |
| 3700 | curproxy->check_len = reqlen; |
| 3701 | |
| 3702 | snprintf(curproxy->check_req, 4, "%c%c%c", |
| 3703 | ((unsigned char) packetlen & 0xff), |
| 3704 | ((unsigned char) (packetlen >> 8) & 0xff), |
| 3705 | ((unsigned char) (packetlen >> 16) & 0xff)); |
| 3706 | |
| 3707 | curproxy->check_req[3] = 1; |
Hervé COMMOWICK | 212f778 | 2011-06-10 14:05:59 +0200 | [diff] [blame] | 3708 | curproxy->check_req[5] = 128; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 3709 | curproxy->check_req[8] = 1; |
| 3710 | memcpy(&curproxy->check_req[9], mysqluser, userlen); |
| 3711 | curproxy->check_req[9 + userlen + 1 + 1] = 1; |
| 3712 | curproxy->check_req[9 + userlen + 1 + 1 + 4] = 1; |
| 3713 | cur_arg += 2; |
| 3714 | } else { |
| 3715 | /* unknown suboption - catchall */ |
| 3716 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'user'.\n", |
| 3717 | file, linenum, args[0], args[1]); |
| 3718 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3719 | goto out; |
| 3720 | } |
| 3721 | } /* end while loop */ |
| 3722 | } |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 3723 | } |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 3724 | else if (!strcmp(args[1], "ldap-check")) { |
| 3725 | /* use LDAP request to check servers' health */ |
| 3726 | free(curproxy->check_req); |
| 3727 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3728 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 3729 | curproxy->options2 |= PR_O2_LDAP_CHK; |
| 3730 | |
| 3731 | curproxy->check_req = (char *) malloc(sizeof(DEF_LDAP_CHECK_REQ) - 1); |
| 3732 | memcpy(curproxy->check_req, DEF_LDAP_CHECK_REQ, sizeof(DEF_LDAP_CHECK_REQ) - 1); |
| 3733 | curproxy->check_len = sizeof(DEF_LDAP_CHECK_REQ) - 1; |
| 3734 | } |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 3735 | else if (!strcmp(args[1], "tcp-check")) { |
| 3736 | /* use raw TCPCHK send/expect to check servers' health */ |
| 3737 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 3738 | err_code |= ERR_WARN; |
| 3739 | |
| 3740 | free(curproxy->check_req); |
| 3741 | curproxy->check_req = NULL; |
| 3742 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 3743 | curproxy->options2 |= PR_O2_TCPCHK_CHK; |
| 3744 | } |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3745 | else if (!strcmp(args[1], "forwardfor")) { |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3746 | int cur_arg; |
| 3747 | |
| 3748 | /* insert x-forwarded-for field, but not for the IP address listed as an except. |
| 3749 | * set default options (ie: bitfield, header name, etc) |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3750 | */ |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3751 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 3752 | curproxy->options |= PR_O_FWDFOR | PR_O_FF_ALWAYS; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3753 | |
| 3754 | free(curproxy->fwdfor_hdr_name); |
| 3755 | curproxy->fwdfor_hdr_name = strdup(DEF_XFORWARDFOR_HDR); |
| 3756 | curproxy->fwdfor_hdr_len = strlen(DEF_XFORWARDFOR_HDR); |
| 3757 | |
| 3758 | /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */ |
| 3759 | cur_arg = 2; |
| 3760 | while (*(args[cur_arg])) { |
| 3761 | if (!strcmp(args[cur_arg], "except")) { |
| 3762 | /* suboption except - needs additional argument for it */ |
| 3763 | if (!*(args[cur_arg+1]) || !str2net(args[cur_arg+1], &curproxy->except_net, &curproxy->except_mask)) { |
| 3764 | Alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n", |
| 3765 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3766 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3767 | goto out; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3768 | } |
| 3769 | /* flush useless bits */ |
| 3770 | curproxy->except_net.s_addr &= curproxy->except_mask.s_addr; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3771 | cur_arg += 2; |
| 3772 | } else if (!strcmp(args[cur_arg], "header")) { |
| 3773 | /* suboption header - needs additional argument for it */ |
| 3774 | if (*(args[cur_arg+1]) == 0) { |
| 3775 | Alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 3776 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3777 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3778 | goto out; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3779 | } |
| 3780 | free(curproxy->fwdfor_hdr_name); |
| 3781 | curproxy->fwdfor_hdr_name = strdup(args[cur_arg+1]); |
| 3782 | curproxy->fwdfor_hdr_len = strlen(curproxy->fwdfor_hdr_name); |
| 3783 | cur_arg += 2; |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 3784 | } else if (!strcmp(args[cur_arg], "if-none")) { |
| 3785 | curproxy->options &= ~PR_O_FF_ALWAYS; |
| 3786 | cur_arg += 1; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3787 | } else { |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3788 | /* unknown suboption - catchall */ |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 3789 | 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] | 3790 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3791 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3792 | goto out; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3793 | } |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3794 | } /* end while loop */ |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3795 | } |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 3796 | else if (!strcmp(args[1], "originalto")) { |
| 3797 | int cur_arg; |
| 3798 | |
| 3799 | /* insert x-original-to field, but not for the IP address listed as an except. |
| 3800 | * set default options (ie: bitfield, header name, etc) |
| 3801 | */ |
| 3802 | |
| 3803 | curproxy->options |= PR_O_ORGTO; |
| 3804 | |
| 3805 | free(curproxy->orgto_hdr_name); |
| 3806 | curproxy->orgto_hdr_name = strdup(DEF_XORIGINALTO_HDR); |
| 3807 | curproxy->orgto_hdr_len = strlen(DEF_XORIGINALTO_HDR); |
| 3808 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 3809 | /* 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] | 3810 | cur_arg = 2; |
| 3811 | while (*(args[cur_arg])) { |
| 3812 | if (!strcmp(args[cur_arg], "except")) { |
| 3813 | /* suboption except - needs additional argument for it */ |
| 3814 | if (!*(args[cur_arg+1]) || !str2net(args[cur_arg+1], &curproxy->except_to, &curproxy->except_mask_to)) { |
| 3815 | Alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n", |
| 3816 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3817 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3818 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 3819 | } |
| 3820 | /* flush useless bits */ |
| 3821 | curproxy->except_to.s_addr &= curproxy->except_mask_to.s_addr; |
| 3822 | cur_arg += 2; |
| 3823 | } else if (!strcmp(args[cur_arg], "header")) { |
| 3824 | /* suboption header - needs additional argument for it */ |
| 3825 | if (*(args[cur_arg+1]) == 0) { |
| 3826 | Alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 3827 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3828 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3829 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 3830 | } |
| 3831 | free(curproxy->orgto_hdr_name); |
| 3832 | curproxy->orgto_hdr_name = strdup(args[cur_arg+1]); |
| 3833 | curproxy->orgto_hdr_len = strlen(curproxy->orgto_hdr_name); |
| 3834 | cur_arg += 2; |
| 3835 | } else { |
| 3836 | /* unknown suboption - catchall */ |
| 3837 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n", |
| 3838 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3839 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3840 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 3841 | } |
| 3842 | } /* end while loop */ |
| 3843 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3844 | else { |
| 3845 | Alert("parsing [%s:%d] : unknown option '%s'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3846 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3847 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3848 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3849 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3850 | } |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 3851 | else if (!strcmp(args[0], "default_backend")) { |
| 3852 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3853 | err_code |= ERR_WARN; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 3854 | |
| 3855 | if (*(args[1]) == 0) { |
| 3856 | 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] | 3857 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3858 | goto out; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 3859 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3860 | free(curproxy->defbe.name); |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 3861 | curproxy->defbe.name = strdup(args[1]); |
| 3862 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3863 | else if (!strcmp(args[0], "redispatch") || !strcmp(args[0], "redisp")) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3864 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3865 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3866 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3867 | Warning("parsing [%s:%d]: keyword '%s' is deprecated, please use 'option redispatch' instead.\n", |
| 3868 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3869 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3870 | /* enable reconnections to dispatch */ |
| 3871 | curproxy->options |= PR_O_REDISP; |
| 3872 | } |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 3873 | else if (!strcmp(args[0], "http-check")) { |
| 3874 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3875 | err_code |= ERR_WARN; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 3876 | |
| 3877 | if (strcmp(args[1], "disable-on-404") == 0) { |
| 3878 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 3879 | curproxy->options |= PR_O_DISABLE404; |
| 3880 | } |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 3881 | else if (strcmp(args[1], "send-state") == 0) { |
| 3882 | /* enable emission of the apparent state of a server in HTTP checks */ |
| 3883 | curproxy->options2 |= PR_O2_CHK_SNDST; |
| 3884 | } |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 3885 | else if (strcmp(args[1], "expect") == 0) { |
| 3886 | const char *ptr_arg; |
| 3887 | int cur_arg; |
| 3888 | |
| 3889 | if (curproxy->options2 & PR_O2_EXP_TYPE) { |
| 3890 | Alert("parsing [%s:%d] : '%s %s' already specified.\n", file, linenum, args[0], args[1]); |
| 3891 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3892 | goto out; |
| 3893 | } |
| 3894 | |
| 3895 | cur_arg = 2; |
| 3896 | /* consider exclamation marks, sole or at the beginning of a word */ |
| 3897 | while (*(ptr_arg = args[cur_arg])) { |
| 3898 | while (*ptr_arg == '!') { |
| 3899 | curproxy->options2 ^= PR_O2_EXP_INV; |
| 3900 | ptr_arg++; |
| 3901 | } |
| 3902 | if (*ptr_arg) |
| 3903 | break; |
| 3904 | cur_arg++; |
| 3905 | } |
| 3906 | /* now ptr_arg points to the beginning of a word past any possible |
| 3907 | * exclamation mark, and cur_arg is the argument which holds this word. |
| 3908 | */ |
| 3909 | if (strcmp(ptr_arg, "status") == 0) { |
| 3910 | if (!*(args[cur_arg + 1])) { |
| 3911 | Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 3912 | file, linenum, args[0], args[1], ptr_arg); |
| 3913 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3914 | goto out; |
| 3915 | } |
| 3916 | curproxy->options2 |= PR_O2_EXP_STS; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 3917 | free(curproxy->expect_str); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 3918 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
| 3919 | } |
| 3920 | else if (strcmp(ptr_arg, "string") == 0) { |
| 3921 | if (!*(args[cur_arg + 1])) { |
| 3922 | Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 3923 | file, linenum, args[0], args[1], ptr_arg); |
| 3924 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3925 | goto out; |
| 3926 | } |
| 3927 | curproxy->options2 |= PR_O2_EXP_STR; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 3928 | free(curproxy->expect_str); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 3929 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
| 3930 | } |
| 3931 | else if (strcmp(ptr_arg, "rstatus") == 0) { |
| 3932 | if (!*(args[cur_arg + 1])) { |
| 3933 | Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 3934 | file, linenum, args[0], args[1], ptr_arg); |
| 3935 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3936 | goto out; |
| 3937 | } |
| 3938 | curproxy->options2 |= PR_O2_EXP_RSTS; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 3939 | free(curproxy->expect_str); |
| 3940 | if (curproxy->expect_regex) regfree(curproxy->expect_regex); |
| 3941 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 3942 | curproxy->expect_regex = calloc(1, sizeof(regex_t)); |
| 3943 | if (regcomp(curproxy->expect_regex, args[cur_arg + 1], REG_EXTENDED) != 0) { |
| 3944 | Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s'.\n", |
| 3945 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1]); |
| 3946 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3947 | goto out; |
| 3948 | } |
| 3949 | } |
| 3950 | else if (strcmp(ptr_arg, "rstring") == 0) { |
| 3951 | if (!*(args[cur_arg + 1])) { |
| 3952 | Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 3953 | file, linenum, args[0], args[1], ptr_arg); |
| 3954 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3955 | goto out; |
| 3956 | } |
| 3957 | curproxy->options2 |= PR_O2_EXP_RSTR; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 3958 | free(curproxy->expect_str); |
| 3959 | if (curproxy->expect_regex) regfree(curproxy->expect_regex); |
| 3960 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 3961 | curproxy->expect_regex = calloc(1, sizeof(regex_t)); |
| 3962 | if (regcomp(curproxy->expect_regex, args[cur_arg + 1], REG_EXTENDED) != 0) { |
| 3963 | Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s'.\n", |
| 3964 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1]); |
| 3965 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3966 | goto out; |
| 3967 | } |
| 3968 | } |
| 3969 | else { |
| 3970 | Alert("parsing [%s:%d] : '%s %s' only supports [!] 'status', 'string', 'rstatus', 'rstring', found '%s'.\n", |
| 3971 | file, linenum, args[0], args[1], ptr_arg); |
| 3972 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3973 | goto out; |
| 3974 | } |
| 3975 | } |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 3976 | else { |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 3977 | 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] | 3978 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3979 | goto out; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 3980 | } |
| 3981 | } |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 3982 | else if (!strcmp(args[0], "tcp-check")) { |
| 3983 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 3984 | err_code |= ERR_WARN; |
| 3985 | |
| 3986 | if (strcmp(args[1], "send") == 0) { |
| 3987 | if (! *(args[2]) ) { |
| 3988 | /* SEND string expected */ |
| 3989 | Alert("parsing [%s:%d] : '%s %s %s' expects <STRING> as argument.\n", |
| 3990 | file, linenum, args[0], args[1], args[2]); |
| 3991 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3992 | goto out; |
| 3993 | } else { |
| 3994 | struct tcpcheck_rule *tcpcheck; |
| 3995 | |
| 3996 | tcpcheck = (struct tcpcheck_rule *)calloc(1, sizeof(*tcpcheck)); |
| 3997 | |
| 3998 | tcpcheck->action = TCPCHK_ACT_SEND; |
| 3999 | tcpcheck->string_len = strlen(args[2]); |
| 4000 | tcpcheck->string = strdup(args[2]); |
| 4001 | tcpcheck->expect_regex = NULL; |
| 4002 | |
| 4003 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 4004 | } |
| 4005 | } |
| 4006 | else if (strcmp(args[1], "send-binary") == 0) { |
| 4007 | if (! *(args[2]) ) { |
| 4008 | /* SEND binary string expected */ |
| 4009 | Alert("parsing [%s:%d] : '%s %s %s' expects <BINARY STRING> as argument.\n", |
| 4010 | file, linenum, args[0], args[1], args[2]); |
| 4011 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4012 | goto out; |
| 4013 | } else { |
| 4014 | struct tcpcheck_rule *tcpcheck; |
| 4015 | char *err = NULL; |
| 4016 | |
| 4017 | tcpcheck = (struct tcpcheck_rule *)calloc(1, sizeof(*tcpcheck)); |
| 4018 | |
| 4019 | tcpcheck->action = TCPCHK_ACT_SEND; |
| 4020 | if (parse_binary(args[2], &tcpcheck->string, &tcpcheck->string_len, &err) == 0) { |
| 4021 | Alert("parsing [%s:%d] : '%s %s %s' expects <BINARY STRING> as argument, but %s\n", |
| 4022 | file, linenum, args[0], args[1], args[2], err); |
| 4023 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4024 | goto out; |
| 4025 | } |
| 4026 | tcpcheck->expect_regex = NULL; |
| 4027 | |
| 4028 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 4029 | } |
| 4030 | } |
| 4031 | else if (strcmp(args[1], "expect") == 0) { |
| 4032 | const char *ptr_arg; |
| 4033 | int cur_arg; |
| 4034 | int inverse = 0; |
| 4035 | |
| 4036 | if (curproxy->options2 & PR_O2_EXP_TYPE) { |
| 4037 | Alert("parsing [%s:%d] : '%s %s' already specified.\n", file, linenum, args[0], args[1]); |
| 4038 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4039 | goto out; |
| 4040 | } |
| 4041 | |
| 4042 | cur_arg = 2; |
| 4043 | /* consider exclamation marks, sole or at the beginning of a word */ |
| 4044 | while (*(ptr_arg = args[cur_arg])) { |
| 4045 | while (*ptr_arg == '!') { |
| 4046 | inverse = !inverse; |
| 4047 | ptr_arg++; |
| 4048 | } |
| 4049 | if (*ptr_arg) |
| 4050 | break; |
| 4051 | cur_arg++; |
| 4052 | } |
| 4053 | /* now ptr_arg points to the beginning of a word past any possible |
| 4054 | * exclamation mark, and cur_arg is the argument which holds this word. |
| 4055 | */ |
| 4056 | if (strcmp(ptr_arg, "binary") == 0) { |
| 4057 | if (!*(args[cur_arg + 1])) { |
| 4058 | Alert("parsing [%s:%d] : '%s %s %s' expects <binary string> as an argument.\n", |
| 4059 | file, linenum, args[0], args[1], ptr_arg); |
| 4060 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4061 | goto out; |
| 4062 | } |
| 4063 | struct tcpcheck_rule *tcpcheck; |
| 4064 | char *err = NULL; |
| 4065 | |
| 4066 | tcpcheck = (struct tcpcheck_rule *)calloc(1, sizeof(*tcpcheck)); |
| 4067 | |
| 4068 | tcpcheck->action = TCPCHK_ACT_EXPECT; |
| 4069 | if (parse_binary(args[cur_arg + 1], &tcpcheck->string, &tcpcheck->string_len, &err) == 0) { |
| 4070 | Alert("parsing [%s:%d] : '%s %s %s' expects <BINARY STRING> as argument, but %s\n", |
| 4071 | file, linenum, args[0], args[1], args[2], err); |
| 4072 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4073 | goto out; |
| 4074 | } |
| 4075 | tcpcheck->expect_regex = NULL; |
| 4076 | tcpcheck->inverse = inverse; |
| 4077 | |
| 4078 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 4079 | } |
| 4080 | else if (strcmp(ptr_arg, "string") == 0) { |
| 4081 | if (!*(args[cur_arg + 1])) { |
| 4082 | Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 4083 | file, linenum, args[0], args[1], ptr_arg); |
| 4084 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4085 | goto out; |
| 4086 | } |
| 4087 | struct tcpcheck_rule *tcpcheck; |
| 4088 | |
| 4089 | tcpcheck = (struct tcpcheck_rule *)calloc(1, sizeof(*tcpcheck)); |
| 4090 | |
| 4091 | tcpcheck->action = TCPCHK_ACT_EXPECT; |
| 4092 | tcpcheck->string_len = strlen(args[cur_arg + 1]); |
| 4093 | tcpcheck->string = strdup(args[cur_arg + 1]); |
| 4094 | tcpcheck->expect_regex = NULL; |
| 4095 | tcpcheck->inverse = inverse; |
| 4096 | |
| 4097 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 4098 | } |
| 4099 | else if (strcmp(ptr_arg, "rstring") == 0) { |
| 4100 | if (!*(args[cur_arg + 1])) { |
| 4101 | Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 4102 | file, linenum, args[0], args[1], ptr_arg); |
| 4103 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4104 | goto out; |
| 4105 | } |
| 4106 | struct tcpcheck_rule *tcpcheck; |
| 4107 | |
| 4108 | tcpcheck = (struct tcpcheck_rule *)calloc(1, sizeof(*tcpcheck)); |
| 4109 | |
| 4110 | tcpcheck->action = TCPCHK_ACT_EXPECT; |
| 4111 | tcpcheck->string_len = 0; |
| 4112 | tcpcheck->string = NULL; |
| 4113 | tcpcheck->expect_regex = calloc(1, sizeof(regex_t)); |
| 4114 | if (regcomp(tcpcheck->expect_regex, args[cur_arg + 1], REG_EXTENDED) != 0) { |
| 4115 | Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s'.\n", |
| 4116 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1]); |
| 4117 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4118 | goto out; |
| 4119 | } |
| 4120 | tcpcheck->inverse = inverse; |
| 4121 | |
| 4122 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 4123 | } |
| 4124 | else { |
| 4125 | Alert("parsing [%s:%d] : '%s %s' only supports [!] 'binary', 'string', 'rstring', found '%s'.\n", |
| 4126 | file, linenum, args[0], args[1], ptr_arg); |
| 4127 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4128 | goto out; |
| 4129 | } |
| 4130 | } |
| 4131 | else { |
| 4132 | Alert("parsing [%s:%d] : '%s' only supports 'send' or 'expect'.\n", file, linenum, args[0]); |
| 4133 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4134 | goto out; |
| 4135 | } |
| 4136 | } |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 4137 | else if (!strcmp(args[0], "monitor")) { |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 4138 | if (curproxy == &defproxy) { |
| 4139 | 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] | 4140 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4141 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 4142 | } |
| 4143 | |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 4144 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4145 | err_code |= ERR_WARN; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 4146 | |
| 4147 | if (strcmp(args[1], "fail") == 0) { |
| 4148 | /* add a condition to fail monitor requests */ |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 4149 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 4150 | Alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n", |
| 4151 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4152 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4153 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 4154 | } |
| 4155 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 4156 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 4157 | Alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition : %s.\n", |
| 4158 | file, linenum, args[0], args[1], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4159 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4160 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 4161 | } |
| 4162 | LIST_ADDQ(&curproxy->mon_fail_cond, &cond->list); |
| 4163 | } |
| 4164 | else { |
| 4165 | 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] | 4166 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4167 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 4168 | } |
| 4169 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4170 | #ifdef TPROXY |
| 4171 | else if (!strcmp(args[0], "transparent")) { |
| 4172 | /* enable transparent proxy connections */ |
| 4173 | curproxy->options |= PR_O_TRANSP; |
| 4174 | } |
| 4175 | #endif |
| 4176 | else if (!strcmp(args[0], "maxconn")) { /* maxconn */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4177 | 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] | 4178 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4179 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4180 | if (*(args[1]) == 0) { |
| 4181 | 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] | 4182 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4183 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4184 | } |
| 4185 | curproxy->maxconn = atol(args[1]); |
| 4186 | } |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 4187 | else if (!strcmp(args[0], "backlog")) { /* backlog */ |
| 4188 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4189 | err_code |= ERR_WARN; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 4190 | |
| 4191 | if (*(args[1]) == 0) { |
| 4192 | 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] | 4193 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4194 | goto out; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 4195 | } |
| 4196 | curproxy->backlog = atol(args[1]); |
| 4197 | } |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 4198 | else if (!strcmp(args[0], "fullconn")) { /* fullconn */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4199 | 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] | 4200 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4201 | |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 4202 | if (*(args[1]) == 0) { |
| 4203 | 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] | 4204 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4205 | goto out; |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 4206 | } |
| 4207 | curproxy->fullconn = atol(args[1]); |
| 4208 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4209 | else if (!strcmp(args[0], "grace")) { /* grace time (ms) */ |
| 4210 | if (*(args[1]) == 0) { |
| 4211 | 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] | 4212 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4213 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4214 | } |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4215 | err = parse_time_err(args[1], &val, TIME_UNIT_MS); |
| 4216 | if (err) { |
| 4217 | Alert("parsing [%s:%d] : unexpected character '%c' in grace time.\n", |
| 4218 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4219 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4220 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4221 | } |
| 4222 | curproxy->grace = val; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4223 | } |
| 4224 | else if (!strcmp(args[0], "dispatch")) { /* dispatch address */ |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4225 | struct sockaddr_storage *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4226 | int port1, port2; |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 4227 | struct protocol *proto; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4228 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4229 | if (curproxy == &defproxy) { |
| 4230 | 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] | 4231 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4232 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4233 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4234 | else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4235 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4236 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 4237 | sk = str2sa_range(args[1], &port1, &port2, &errmsg, NULL); |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4238 | if (!sk) { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 4239 | Alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 4240 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 4241 | goto out; |
| 4242 | } |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 4243 | |
| 4244 | proto = protocol_by_family(sk->ss_family); |
| 4245 | if (!proto || !proto->connect) { |
| 4246 | Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 4247 | file, linenum, args[0], args[1]); |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4248 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4249 | goto out; |
| 4250 | } |
| 4251 | |
| 4252 | if (port1 != port2) { |
| 4253 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'.\n", |
| 4254 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4255 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4256 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4257 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4258 | |
| 4259 | if (!port1) { |
| 4260 | Alert("parsing [%s:%d] : '%s' : missing port number in '%s', <addr:port> expected.\n", |
| 4261 | file, linenum, args[0], args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4262 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4263 | goto out; |
| 4264 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4265 | |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4266 | curproxy->dispatch_addr = *sk; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4267 | curproxy->options |= PR_O_DISPATCH; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4268 | } |
| 4269 | else if (!strcmp(args[0], "balance")) { /* set balancing with optional algorithm */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4270 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4271 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4272 | |
Willy Tarreau | a93c74b | 2012-05-08 18:14:39 +0200 | [diff] [blame] | 4273 | if (backend_parse_balance((const char **)args + 1, &errmsg, curproxy) < 0) { |
| 4274 | Alert("parsing [%s:%d] : %s %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4275 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4276 | goto out; |
Willy Tarreau | 2fcb500 | 2007-05-08 13:35:26 +0200 | [diff] [blame] | 4277 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4278 | } |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 4279 | else if (!strcmp(args[0], "hash-type")) { /* set hashing method */ |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 4280 | /** |
| 4281 | * The syntax for hash-type config element is |
| 4282 | * hash-type {map-based|consistent} [[<algo>] avalanche] |
| 4283 | * |
| 4284 | * The default hash function is sdbm for map-based and sdbm+avalanche for consistent. |
| 4285 | */ |
| 4286 | curproxy->lbprm.algo &= ~(BE_LB_HASH_TYPE | BE_LB_HASH_FUNC | BE_LB_HASH_MOD); |
Bhaskar | 98634f0 | 2013-10-29 23:30:51 -0400 | [diff] [blame] | 4287 | |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 4288 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 4289 | err_code |= ERR_WARN; |
| 4290 | |
| 4291 | if (strcmp(args[1], "consistent") == 0) { /* use consistent hashing */ |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 4292 | curproxy->lbprm.algo |= BE_LB_HASH_CONS; |
| 4293 | } |
| 4294 | else if (strcmp(args[1], "map-based") == 0) { /* use map-based hashing */ |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 4295 | curproxy->lbprm.algo |= BE_LB_HASH_MAP; |
| 4296 | } |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 4297 | else if (strcmp(args[1], "avalanche") == 0) { |
| 4298 | Alert("parsing [%s:%d] : experimental feature '%s %s' is not supported anymore, please use '%s map-based sdbm avalanche' instead.\n", file, linenum, args[0], args[1], args[0]); |
| 4299 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4300 | goto out; |
Willy Tarreau | 798a39c | 2010-11-24 15:04:29 +0100 | [diff] [blame] | 4301 | } |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 4302 | else { |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 4303 | Alert("parsing [%s:%d] : '%s' only supports 'consistent' and 'map-based'.\n", file, linenum, args[0]); |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 4304 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4305 | goto out; |
| 4306 | } |
Bhaskar | 98634f0 | 2013-10-29 23:30:51 -0400 | [diff] [blame] | 4307 | |
| 4308 | /* set the hash function to use */ |
| 4309 | if (!*args[2]) { |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 4310 | /* the default algo is sdbm */ |
Bhaskar | 98634f0 | 2013-10-29 23:30:51 -0400 | [diff] [blame] | 4311 | curproxy->lbprm.algo |= BE_LB_HFCN_SDBM; |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 4312 | |
| 4313 | /* if consistent with no argument, then avalanche modifier is also applied */ |
| 4314 | if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS) |
| 4315 | curproxy->lbprm.algo |= BE_LB_HMOD_AVAL; |
Bhaskar | 98634f0 | 2013-10-29 23:30:51 -0400 | [diff] [blame] | 4316 | } else { |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 4317 | /* set the hash function */ |
| 4318 | if (!strcmp(args[2], "sdbm")) { |
| 4319 | curproxy->lbprm.algo |= BE_LB_HFCN_SDBM; |
| 4320 | } |
| 4321 | else if (!strcmp(args[2], "djb2")) { |
| 4322 | curproxy->lbprm.algo |= BE_LB_HFCN_DJB2; |
Willy Tarreau | a0f4271 | 2013-11-14 14:30:35 +0100 | [diff] [blame] | 4323 | } else if (!strcmp(args[2], "wt6")) { |
| 4324 | curproxy->lbprm.algo |= BE_LB_HFCN_WT6; |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 4325 | } |
| 4326 | else { |
Willy Tarreau | a0f4271 | 2013-11-14 14:30:35 +0100 | [diff] [blame] | 4327 | Alert("parsing [%s:%d] : '%s' only supports 'sdbm', 'djb2' or 'wt6' hash functions.\n", file, linenum, args[0]); |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 4328 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4329 | goto out; |
| 4330 | } |
| 4331 | |
| 4332 | /* set the hash modifier */ |
| 4333 | if (!strcmp(args[3], "avalanche")) { |
| 4334 | curproxy->lbprm.algo |= BE_LB_HMOD_AVAL; |
| 4335 | } |
| 4336 | else if (*args[3]) { |
| 4337 | Alert("parsing [%s:%d] : '%s' only supports 'avalanche' as a modifier for hash functions.\n", file, linenum, args[0]); |
| 4338 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4339 | goto out; |
| 4340 | } |
Bhaskar | 98634f0 | 2013-10-29 23:30:51 -0400 | [diff] [blame] | 4341 | } |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 4342 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4343 | 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] | 4344 | int cur_arg; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4345 | short realport = 0; |
Simon Horman | d60d691 | 2013-11-25 10:46:36 +0900 | [diff] [blame] | 4346 | int do_agent = 0, do_check = 0, defsrv = (*args[0] == 'd'); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4347 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4348 | if (!defsrv && curproxy == &defproxy) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4349 | 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] | 4350 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4351 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4352 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4353 | else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4354 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4355 | |
| 4356 | if (!*args[2]) { |
| 4357 | Alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n", |
| 4358 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4359 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4360 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4361 | } |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 4362 | |
| 4363 | err = invalid_char(args[1]); |
Willy Tarreau | 4217a7d | 2013-03-06 20:04:27 +0100 | [diff] [blame] | 4364 | if (err && !defsrv) { |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 4365 | Alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n", |
| 4366 | file, linenum, *err, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4367 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4368 | goto out; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 4369 | } |
| 4370 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4371 | if (!defsrv) { |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4372 | struct sockaddr_storage *sk; |
Willy Tarreau | dbfa445 | 2013-02-20 19:06:35 +0100 | [diff] [blame] | 4373 | int port1, port2; |
Willy Tarreau | 4217a7d | 2013-03-06 20:04:27 +0100 | [diff] [blame] | 4374 | struct protocol *proto; |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4375 | |
Krzysztof Piotr Oledzki | aff01ea | 2010-02-05 20:31:44 +0100 | [diff] [blame] | 4376 | if ((newsrv = (struct server *)calloc(1, sizeof(struct server))) == NULL) { |
| 4377 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 4378 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4379 | goto out; |
| 4380 | } |
| 4381 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4382 | /* the servers are linked backwards first */ |
| 4383 | newsrv->next = curproxy->srv; |
| 4384 | curproxy->srv = newsrv; |
| 4385 | newsrv->proxy = curproxy; |
Willy Tarreau | 8113a5d | 2012-10-04 08:01:43 +0200 | [diff] [blame] | 4386 | newsrv->conf.file = strdup(file); |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4387 | newsrv->conf.line = linenum; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4388 | |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 4389 | newsrv->obj_type = OBJ_TYPE_SERVER; |
Simon Horman | af51495 | 2011-06-21 14:34:57 +0900 | [diff] [blame] | 4390 | LIST_INIT(&newsrv->actconns); |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4391 | LIST_INIT(&newsrv->pendconns); |
| 4392 | do_check = 0; |
Simon Horman | d60d691 | 2013-11-25 10:46:36 +0900 | [diff] [blame] | 4393 | do_agent = 0; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4394 | newsrv->state = SRV_RUNNING; /* early server setup */ |
| 4395 | newsrv->last_change = now.tv_sec; |
| 4396 | newsrv->id = strdup(args[1]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4397 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4398 | /* several ways to check the port component : |
David du Colombier | 9842ff1 | 2011-03-17 10:40:28 +0100 | [diff] [blame] | 4399 | * - IP => port=+0, relative (IPv4 only) |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4400 | * - IP: => port=+0, relative |
| 4401 | * - IP:N => port=N, absolute |
| 4402 | * - IP:+N => port=+N, relative |
| 4403 | * - IP:-N => port=-N, relative |
| 4404 | */ |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 4405 | sk = str2sa_range(args[2], &port1, &port2, &errmsg, NULL); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4406 | if (!sk) { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 4407 | Alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg); |
Willy Tarreau | 4217a7d | 2013-03-06 20:04:27 +0100 | [diff] [blame] | 4408 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 4217a7d | 2013-03-06 20:04:27 +0100 | [diff] [blame] | 4409 | goto out; |
| 4410 | } |
Willy Tarreau | 4217a7d | 2013-03-06 20:04:27 +0100 | [diff] [blame] | 4411 | |
| 4412 | proto = protocol_by_family(sk->ss_family); |
| 4413 | if (!proto || !proto->connect) { |
| 4414 | Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 4415 | file, linenum, args[0], args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4416 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4417 | goto out; |
| 4418 | } |
Willy Tarreau | dbfa445 | 2013-02-20 19:06:35 +0100 | [diff] [blame] | 4419 | |
| 4420 | if (!port1 || !port2) { |
| 4421 | /* no port specified, +offset, -offset */ |
| 4422 | newsrv->state |= SRV_MAPPORTS; |
| 4423 | } |
| 4424 | else if (port1 != port2) { |
| 4425 | /* port range */ |
| 4426 | Alert("parsing [%s:%d] : '%s %s' : port ranges are not allowed in '%s'\n", |
| 4427 | file, linenum, args[0], args[1], args[2]); |
| 4428 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4429 | goto out; |
| 4430 | } |
| 4431 | else { |
| 4432 | /* used by checks */ |
| 4433 | realport = port1; |
| 4434 | } |
| 4435 | |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4436 | newsrv->addr = *sk; |
Simon Horman | 6618300 | 2013-02-23 10:16:43 +0900 | [diff] [blame] | 4437 | newsrv->proto = newsrv->check_common.proto = protocol_by_family(newsrv->addr.ss_family); |
| 4438 | newsrv->xprt = newsrv->check_common.xprt = &raw_sock; |
Willy Tarreau | 26d8c59 | 2012-05-07 18:12:14 +0200 | [diff] [blame] | 4439 | |
Willy Tarreau | 173e7fb | 2012-09-24 22:47:39 +0200 | [diff] [blame] | 4440 | if (!newsrv->proto) { |
Willy Tarreau | 26d8c59 | 2012-05-07 18:12:14 +0200 | [diff] [blame] | 4441 | Alert("parsing [%s:%d] : Unknown protocol family %d '%s'\n", |
| 4442 | file, linenum, newsrv->addr.ss_family, args[2]); |
| 4443 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4444 | goto out; |
| 4445 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4446 | |
Simon Horman | d60d691 | 2013-11-25 10:46:36 +0900 | [diff] [blame] | 4447 | newsrv->check.use_ssl = curproxy->defsrv.check.use_ssl; |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 4448 | newsrv->check.port = curproxy->defsrv.check.port; |
Simon Horman | 6618300 | 2013-02-23 10:16:43 +0900 | [diff] [blame] | 4449 | newsrv->check.inter = curproxy->defsrv.check.inter; |
| 4450 | newsrv->check.fastinter = curproxy->defsrv.check.fastinter; |
| 4451 | newsrv->check.downinter = curproxy->defsrv.check.downinter; |
Simon Horman | d60d691 | 2013-11-25 10:46:36 +0900 | [diff] [blame] | 4452 | newsrv->agent.use_ssl = curproxy->defsrv.agent.use_ssl; |
| 4453 | newsrv->agent.port = curproxy->defsrv.agent.port; |
| 4454 | newsrv->agent.inter = curproxy->defsrv.agent.inter; |
| 4455 | newsrv->agent.fastinter = curproxy->defsrv.agent.fastinter; |
| 4456 | newsrv->agent.downinter = curproxy->defsrv.agent.downinter; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4457 | newsrv->maxqueue = curproxy->defsrv.maxqueue; |
| 4458 | newsrv->minconn = curproxy->defsrv.minconn; |
| 4459 | newsrv->maxconn = curproxy->defsrv.maxconn; |
| 4460 | newsrv->slowstart = curproxy->defsrv.slowstart; |
| 4461 | newsrv->onerror = curproxy->defsrv.onerror; |
| 4462 | newsrv->consecutive_errors_limit |
| 4463 | = curproxy->defsrv.consecutive_errors_limit; |
Emeric Brun | 01f8e2f | 2012-05-18 16:02:00 +0200 | [diff] [blame] | 4464 | #ifdef OPENSSL |
| 4465 | newsrv->use_ssl = curproxy->defsrv.use_ssl; |
| 4466 | #endif |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4467 | newsrv->uweight = newsrv->iweight |
| 4468 | = curproxy->defsrv.iweight; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4469 | |
Simon Horman | 69d29f9 | 2013-02-23 15:14:19 +0900 | [diff] [blame] | 4470 | newsrv->check.status = HCHK_STATUS_INI; |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 4471 | newsrv->check.rise = curproxy->defsrv.check.rise; |
| 4472 | newsrv->check.fall = curproxy->defsrv.check.fall; |
| 4473 | newsrv->check.health = newsrv->check.rise; /* up, but will fall down at first failure */ |
Simon Horman | 69d29f9 | 2013-02-23 15:14:19 +0900 | [diff] [blame] | 4474 | newsrv->check.server = newsrv; |
| 4475 | |
Simon Horman | d60d691 | 2013-11-25 10:46:36 +0900 | [diff] [blame] | 4476 | newsrv->agent.status = HCHK_STATUS_INI; |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 4477 | newsrv->agent.rise = curproxy->defsrv.agent.rise; |
| 4478 | newsrv->agent.fall = curproxy->defsrv.agent.fall; |
| 4479 | newsrv->agent.health = newsrv->agent.rise; /* up, but will fall down at first failure */ |
Simon Horman | d60d691 | 2013-11-25 10:46:36 +0900 | [diff] [blame] | 4480 | newsrv->agent.server = newsrv; |
| 4481 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4482 | cur_arg = 3; |
| 4483 | } else { |
| 4484 | newsrv = &curproxy->defsrv; |
| 4485 | cur_arg = 1; |
| 4486 | } |
Willy Tarreau | 0f03c6f | 2007-03-25 20:46:19 +0200 | [diff] [blame] | 4487 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4488 | while (*args[cur_arg]) { |
Simon Horman | d60d691 | 2013-11-25 10:46:36 +0900 | [diff] [blame] | 4489 | if (!strcmp(args[cur_arg], "agent-check")) { |
| 4490 | global.maxsock++; |
| 4491 | do_agent = 1; |
| 4492 | cur_arg += 1; |
| 4493 | } else if (!strcmp(args[cur_arg], "agent-inter")) { |
| 4494 | const char *err = parse_time_err(args[cur_arg + 1], &val, TIME_UNIT_MS); |
| 4495 | if (err) { |
| 4496 | Alert("parsing [%s:%d] : unexpected character '%c' in 'agent-inter' argument of server %s.\n", |
| 4497 | file, linenum, *err, newsrv->id); |
| 4498 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4499 | goto out; |
| 4500 | } |
| 4501 | if (val <= 0) { |
| 4502 | Alert("parsing [%s:%d]: invalid value %d for argument '%s' of server %s.\n", |
| 4503 | file, linenum, val, args[cur_arg], newsrv->id); |
| 4504 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4505 | goto out; |
| 4506 | } |
| 4507 | newsrv->agent.inter = val; |
| 4508 | cur_arg += 2; |
| 4509 | } |
| 4510 | else if (!strcmp(args[cur_arg], "agent-port")) { |
| 4511 | global.maxsock++; |
| 4512 | newsrv->agent.port = atol(args[cur_arg + 1]); |
| 4513 | cur_arg += 2; |
| 4514 | } |
| 4515 | else if (!defsrv && !strcmp(args[cur_arg], "cookie")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4516 | newsrv->cookie = strdup(args[cur_arg + 1]); |
| 4517 | newsrv->cklen = strlen(args[cur_arg + 1]); |
| 4518 | cur_arg += 2; |
| 4519 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4520 | else if (!defsrv && !strcmp(args[cur_arg], "redir")) { |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 4521 | newsrv->rdr_pfx = strdup(args[cur_arg + 1]); |
| 4522 | newsrv->rdr_len = strlen(args[cur_arg + 1]); |
| 4523 | cur_arg += 2; |
| 4524 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4525 | else if (!strcmp(args[cur_arg], "rise")) { |
Krzysztof Piotr Oledzki | 08ff959 | 2009-09-27 16:17:31 +0200 | [diff] [blame] | 4526 | if (!*args[cur_arg + 1]) { |
| 4527 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 4528 | file, linenum, args[cur_arg]); |
| 4529 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4530 | goto out; |
| 4531 | } |
| 4532 | |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 4533 | newsrv->check.rise = atol(args[cur_arg + 1]); |
| 4534 | if (newsrv->check.rise <= 0) { |
Krzysztof Piotr Oledzki | 08ff959 | 2009-09-27 16:17:31 +0200 | [diff] [blame] | 4535 | Alert("parsing [%s:%d]: '%s' has to be > 0.\n", |
| 4536 | file, linenum, args[cur_arg]); |
| 4537 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4538 | goto out; |
| 4539 | } |
| 4540 | |
Simon Horman | 125d099 | 2013-02-24 17:23:38 +0900 | [diff] [blame] | 4541 | if (newsrv->check.health) |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 4542 | newsrv->check.health = newsrv->check.rise; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4543 | cur_arg += 2; |
| 4544 | } |
| 4545 | else if (!strcmp(args[cur_arg], "fall")) { |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 4546 | newsrv->check.fall = atol(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 08ff959 | 2009-09-27 16:17:31 +0200 | [diff] [blame] | 4547 | |
| 4548 | if (!*args[cur_arg + 1]) { |
| 4549 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 4550 | file, linenum, args[cur_arg]); |
| 4551 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4552 | goto out; |
| 4553 | } |
| 4554 | |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 4555 | if (newsrv->check.fall <= 0) { |
Krzysztof Piotr Oledzki | 08ff959 | 2009-09-27 16:17:31 +0200 | [diff] [blame] | 4556 | Alert("parsing [%s:%d]: '%s' has to be > 0.\n", |
| 4557 | file, linenum, args[cur_arg]); |
| 4558 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4559 | goto out; |
| 4560 | } |
| 4561 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4562 | cur_arg += 2; |
| 4563 | } |
| 4564 | else if (!strcmp(args[cur_arg], "inter")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4565 | const char *err = parse_time_err(args[cur_arg + 1], &val, TIME_UNIT_MS); |
| 4566 | if (err) { |
| 4567 | Alert("parsing [%s:%d] : unexpected character '%c' in 'inter' argument of server %s.\n", |
| 4568 | file, linenum, *err, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4569 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4570 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4571 | } |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4572 | if (val <= 0) { |
| 4573 | Alert("parsing [%s:%d]: invalid value %d for argument '%s' of server %s.\n", |
| 4574 | file, linenum, val, args[cur_arg], newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4575 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4576 | goto out; |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4577 | } |
Simon Horman | 6618300 | 2013-02-23 10:16:43 +0900 | [diff] [blame] | 4578 | newsrv->check.inter = val; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4579 | cur_arg += 2; |
| 4580 | } |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 4581 | else if (!strcmp(args[cur_arg], "fastinter")) { |
| 4582 | const char *err = parse_time_err(args[cur_arg + 1], &val, TIME_UNIT_MS); |
| 4583 | if (err) { |
| 4584 | Alert("parsing [%s:%d]: unexpected character '%c' in 'fastinter' argument of server %s.\n", |
| 4585 | file, linenum, *err, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4586 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4587 | goto out; |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 4588 | } |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4589 | if (val <= 0) { |
| 4590 | Alert("parsing [%s:%d]: invalid value %d for argument '%s' of server %s.\n", |
| 4591 | file, linenum, val, args[cur_arg], newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4592 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4593 | goto out; |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4594 | } |
Simon Horman | 6618300 | 2013-02-23 10:16:43 +0900 | [diff] [blame] | 4595 | newsrv->check.fastinter = val; |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 4596 | cur_arg += 2; |
| 4597 | } |
| 4598 | else if (!strcmp(args[cur_arg], "downinter")) { |
| 4599 | const char *err = parse_time_err(args[cur_arg + 1], &val, TIME_UNIT_MS); |
| 4600 | if (err) { |
| 4601 | Alert("parsing [%s:%d]: unexpected character '%c' in 'downinter' argument of server %s.\n", |
| 4602 | file, linenum, *err, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4603 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4604 | goto out; |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 4605 | } |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4606 | if (val <= 0) { |
| 4607 | Alert("parsing [%s:%d]: invalid value %d for argument '%s' of server %s.\n", |
| 4608 | file, linenum, val, args[cur_arg], newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4609 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4610 | goto out; |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4611 | } |
Simon Horman | 6618300 | 2013-02-23 10:16:43 +0900 | [diff] [blame] | 4612 | newsrv->check.downinter = val; |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 4613 | cur_arg += 2; |
| 4614 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4615 | else if (!defsrv && !strcmp(args[cur_arg], "addr")) { |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4616 | struct sockaddr_storage *sk; |
| 4617 | int port1, port2; |
Willy Tarreau | 1a20b14 | 2013-03-06 18:05:34 +0100 | [diff] [blame] | 4618 | struct protocol *proto; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4619 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 4620 | sk = str2sa_range(args[cur_arg + 1], &port1, &port2, &errmsg, NULL); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4621 | if (!sk) { |
Willy Tarreau | 1a20b14 | 2013-03-06 18:05:34 +0100 | [diff] [blame] | 4622 | Alert("parsing [%s:%d] : '%s' : %s\n", |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 4623 | file, linenum, args[cur_arg], errmsg); |
Willy Tarreau | 1a20b14 | 2013-03-06 18:05:34 +0100 | [diff] [blame] | 4624 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 1a20b14 | 2013-03-06 18:05:34 +0100 | [diff] [blame] | 4625 | goto out; |
| 4626 | } |
Willy Tarreau | 1a20b14 | 2013-03-06 18:05:34 +0100 | [diff] [blame] | 4627 | |
| 4628 | proto = protocol_by_family(sk->ss_family); |
| 4629 | if (!proto || !proto->connect) { |
| 4630 | Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4631 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4632 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4633 | goto out; |
| 4634 | } |
Willy Tarreau | 1a20b14 | 2013-03-06 18:05:34 +0100 | [diff] [blame] | 4635 | |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4636 | if (port1 != port2) { |
| 4637 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 4638 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
| 4639 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4640 | goto out; |
| 4641 | } |
| 4642 | |
Simon Horman | 6618300 | 2013-02-23 10:16:43 +0900 | [diff] [blame] | 4643 | newsrv->check_common.addr = *sk; |
Willy Tarreau | 2ea3abb | 2007-03-25 16:45:16 +0200 | [diff] [blame] | 4644 | cur_arg += 2; |
| 4645 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4646 | else if (!strcmp(args[cur_arg], "port")) { |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 4647 | newsrv->check.port = atol(args[cur_arg + 1]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4648 | cur_arg += 2; |
| 4649 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4650 | else if (!defsrv && !strcmp(args[cur_arg], "backup")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4651 | newsrv->state |= SRV_BACKUP; |
| 4652 | cur_arg ++; |
| 4653 | } |
Simon Horman | fa46168 | 2011-06-25 09:39:49 +0900 | [diff] [blame] | 4654 | else if (!defsrv && !strcmp(args[cur_arg], "non-stick")) { |
| 4655 | newsrv->state |= SRV_NON_STICK; |
| 4656 | cur_arg ++; |
| 4657 | } |
Willy Tarreau | 5ab04ec | 2011-03-20 10:32:26 +0100 | [diff] [blame] | 4658 | else if (!defsrv && !strcmp(args[cur_arg], "send-proxy")) { |
| 4659 | newsrv->state |= SRV_SEND_PROXY; |
| 4660 | cur_arg ++; |
| 4661 | } |
Willy Tarreau | 6c16adc | 2012-10-05 00:04:16 +0200 | [diff] [blame] | 4662 | else if (!defsrv && !strcmp(args[cur_arg], "check-send-proxy")) { |
| 4663 | newsrv->check.send_proxy = 1; |
| 4664 | cur_arg ++; |
| 4665 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4666 | else if (!strcmp(args[cur_arg], "weight")) { |
| 4667 | int w; |
| 4668 | w = atol(args[cur_arg + 1]); |
Godbach | a34bdc0 | 2013-07-22 07:44:53 +0800 | [diff] [blame] | 4669 | if (w < 0 || w > SRV_UWGHT_MAX) { |
| 4670 | Alert("parsing [%s:%d] : weight of server %s is not within 0 and %d (%d).\n", |
| 4671 | file, linenum, newsrv->id, SRV_UWGHT_MAX, w); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4672 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4673 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4674 | } |
Willy Tarreau | 975c50b | 2009-10-10 19:34:06 +0200 | [diff] [blame] | 4675 | newsrv->uweight = newsrv->iweight = w; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4676 | cur_arg += 2; |
| 4677 | } |
| 4678 | else if (!strcmp(args[cur_arg], "minconn")) { |
| 4679 | newsrv->minconn = atol(args[cur_arg + 1]); |
| 4680 | cur_arg += 2; |
| 4681 | } |
| 4682 | else if (!strcmp(args[cur_arg], "maxconn")) { |
| 4683 | newsrv->maxconn = atol(args[cur_arg + 1]); |
| 4684 | cur_arg += 2; |
| 4685 | } |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 4686 | else if (!strcmp(args[cur_arg], "maxqueue")) { |
| 4687 | newsrv->maxqueue = atol(args[cur_arg + 1]); |
| 4688 | cur_arg += 2; |
| 4689 | } |
Willy Tarreau | 9909fc1 | 2007-11-30 17:42:05 +0100 | [diff] [blame] | 4690 | else if (!strcmp(args[cur_arg], "slowstart")) { |
| 4691 | /* slowstart is stored in seconds */ |
Willy Tarreau | 3259e33 | 2007-12-03 01:51:45 +0100 | [diff] [blame] | 4692 | 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] | 4693 | if (err) { |
| 4694 | Alert("parsing [%s:%d] : unexpected character '%c' in 'slowstart' argument of server %s.\n", |
| 4695 | file, linenum, *err, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4696 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4697 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4698 | } |
Willy Tarreau | 3259e33 | 2007-12-03 01:51:45 +0100 | [diff] [blame] | 4699 | newsrv->slowstart = (val + 999) / 1000; |
Willy Tarreau | 9909fc1 | 2007-11-30 17:42:05 +0100 | [diff] [blame] | 4700 | cur_arg += 2; |
| 4701 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4702 | else if (!defsrv && !strcmp(args[cur_arg], "track")) { |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4703 | |
| 4704 | if (!*args[cur_arg + 1]) { |
| 4705 | Alert("parsing [%s:%d]: 'track' expects [<proxy>/]<server> as argument.\n", |
| 4706 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4707 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4708 | goto out; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4709 | } |
| 4710 | |
| 4711 | newsrv->trackit = strdup(args[cur_arg + 1]); |
| 4712 | |
| 4713 | cur_arg += 2; |
| 4714 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4715 | else if (!defsrv && !strcmp(args[cur_arg], "check")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4716 | global.maxsock++; |
| 4717 | do_check = 1; |
| 4718 | cur_arg += 1; |
| 4719 | } |
Willy Tarreau | 9683909 | 2010-03-29 10:02:24 +0200 | [diff] [blame] | 4720 | else if (!defsrv && !strcmp(args[cur_arg], "disabled")) { |
| 4721 | newsrv->state |= SRV_MAINTAIN; |
| 4722 | newsrv->state &= ~SRV_RUNNING; |
Simon Horman | 125d099 | 2013-02-24 17:23:38 +0900 | [diff] [blame] | 4723 | newsrv->check.health = 0; |
Simon Horman | d60d691 | 2013-11-25 10:46:36 +0900 | [diff] [blame] | 4724 | newsrv->agent.health = 0; |
Willy Tarreau | 9683909 | 2010-03-29 10:02:24 +0200 | [diff] [blame] | 4725 | cur_arg += 1; |
Emeric Brun | c0ff492 | 2012-09-28 19:37:02 +0200 | [diff] [blame] | 4726 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4727 | else if (!defsrv && !strcmp(args[cur_arg], "observe")) { |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 4728 | if (!strcmp(args[cur_arg + 1], "none")) |
| 4729 | newsrv->observe = HANA_OBS_NONE; |
| 4730 | else if (!strcmp(args[cur_arg + 1], "layer4")) |
| 4731 | newsrv->observe = HANA_OBS_LAYER4; |
| 4732 | else if (!strcmp(args[cur_arg + 1], "layer7")) { |
| 4733 | if (curproxy->mode != PR_MODE_HTTP) { |
| 4734 | Alert("parsing [%s:%d]: '%s' can only be used in http proxies.\n", |
| 4735 | file, linenum, args[cur_arg + 1]); |
| 4736 | err_code |= ERR_ALERT; |
| 4737 | } |
| 4738 | newsrv->observe = HANA_OBS_LAYER7; |
| 4739 | } |
| 4740 | else { |
| 4741 | Alert("parsing [%s:%d]: '%s' expects one of 'none', " |
Willy Tarreau | 53621e0 | 2010-10-22 14:53:40 +0200 | [diff] [blame] | 4742 | "'layer4', 'layer7' but got '%s'\n", |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 4743 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
| 4744 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4745 | goto out; |
| 4746 | } |
| 4747 | |
| 4748 | cur_arg += 2; |
| 4749 | } |
| 4750 | else if (!strcmp(args[cur_arg], "on-error")) { |
| 4751 | if (!strcmp(args[cur_arg + 1], "fastinter")) |
| 4752 | newsrv->onerror = HANA_ONERR_FASTINTER; |
| 4753 | else if (!strcmp(args[cur_arg + 1], "fail-check")) |
| 4754 | newsrv->onerror = HANA_ONERR_FAILCHK; |
| 4755 | else if (!strcmp(args[cur_arg + 1], "sudden-death")) |
| 4756 | newsrv->onerror = HANA_ONERR_SUDDTH; |
| 4757 | else if (!strcmp(args[cur_arg + 1], "mark-down")) |
| 4758 | newsrv->onerror = HANA_ONERR_MARKDWN; |
| 4759 | else { |
| 4760 | Alert("parsing [%s:%d]: '%s' expects one of 'fastinter', " |
Willy Tarreau | 53621e0 | 2010-10-22 14:53:40 +0200 | [diff] [blame] | 4761 | "'fail-check', 'sudden-death' or 'mark-down' but got '%s'\n", |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 4762 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
| 4763 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4764 | goto out; |
| 4765 | } |
| 4766 | |
| 4767 | cur_arg += 2; |
| 4768 | } |
Simon Horman | e0d1bfb | 2011-06-21 14:34:58 +0900 | [diff] [blame] | 4769 | else if (!strcmp(args[cur_arg], "on-marked-down")) { |
| 4770 | if (!strcmp(args[cur_arg + 1], "shutdown-sessions")) |
| 4771 | newsrv->onmarkeddown = HANA_ONMARKEDDOWN_SHUTDOWNSESSIONS; |
| 4772 | else { |
| 4773 | Alert("parsing [%s:%d]: '%s' expects 'shutdown-sessions' but got '%s'\n", |
| 4774 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
| 4775 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4776 | goto out; |
| 4777 | } |
| 4778 | |
| 4779 | cur_arg += 2; |
| 4780 | } |
Justin Karneges | eb2c24a | 2012-05-24 15:28:52 -0700 | [diff] [blame] | 4781 | else if (!strcmp(args[cur_arg], "on-marked-up")) { |
| 4782 | if (!strcmp(args[cur_arg + 1], "shutdown-backup-sessions")) |
| 4783 | newsrv->onmarkedup = HANA_ONMARKEDUP_SHUTDOWNBACKUPSESSIONS; |
| 4784 | else { |
| 4785 | Alert("parsing [%s:%d]: '%s' expects 'shutdown-backup-sessions' but got '%s'\n", |
| 4786 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
| 4787 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4788 | goto out; |
| 4789 | } |
| 4790 | |
| 4791 | cur_arg += 2; |
| 4792 | } |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 4793 | else if (!strcmp(args[cur_arg], "error-limit")) { |
| 4794 | if (!*args[cur_arg + 1]) { |
| 4795 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 4796 | file, linenum, args[cur_arg]); |
| 4797 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4798 | goto out; |
| 4799 | } |
| 4800 | |
| 4801 | newsrv->consecutive_errors_limit = atoi(args[cur_arg + 1]); |
| 4802 | |
| 4803 | if (newsrv->consecutive_errors_limit <= 0) { |
| 4804 | Alert("parsing [%s:%d]: %s has to be > 0.\n", |
| 4805 | file, linenum, args[cur_arg]); |
| 4806 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4807 | goto out; |
| 4808 | } |
Willy Tarreau | f53b25d | 2010-03-15 19:40:37 +0100 | [diff] [blame] | 4809 | cur_arg += 2; |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 4810 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4811 | 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] | 4812 | int port_low, port_high; |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4813 | struct sockaddr_storage *sk; |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 4814 | struct protocol *proto; |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4815 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4816 | if (!*args[cur_arg + 1]) { |
Willy Tarreau | eb37faa | 2012-12-08 23:21:19 +0100 | [diff] [blame] | 4817 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>[-<port>]], and optionally '%s' <addr>, and '%s' <name> as argument.\n", |
| 4818 | file, linenum, "source", "usesrc", "interface"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4819 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4820 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4821 | } |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 4822 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4823 | newsrv->conn_src.opts |= CO_SRC_BIND; |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 4824 | sk = str2sa_range(args[cur_arg + 1], &port_low, &port_high, &errmsg, NULL); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4825 | if (!sk) { |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 4826 | Alert("parsing [%s:%d] : '%s %s' : %s\n", |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 4827 | file, linenum, args[cur_arg], args[cur_arg+1], errmsg); |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 4828 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 4829 | goto out; |
| 4830 | } |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 4831 | |
| 4832 | proto = protocol_by_family(sk->ss_family); |
| 4833 | if (!proto || !proto->connect) { |
| 4834 | Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 4835 | file, linenum, args[cur_arg], args[cur_arg+1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4836 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4837 | goto out; |
| 4838 | } |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 4839 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4840 | newsrv->conn_src.source_addr = *sk; |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 4841 | |
| 4842 | if (port_low != port_high) { |
| 4843 | int i; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4844 | |
| 4845 | if (!port_low || !port_high) { |
| 4846 | Alert("parsing [%s:%d] : %s does not support port offsets (found '%s').\n", |
| 4847 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
| 4848 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4849 | goto out; |
| 4850 | } |
| 4851 | |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 4852 | if (port_low <= 0 || port_low > 65535 || |
| 4853 | port_high <= 0 || port_high > 65535 || |
| 4854 | port_low > port_high) { |
| 4855 | Alert("parsing [%s:%d] : invalid source port range %d-%d.\n", |
| 4856 | file, linenum, port_low, port_high); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4857 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4858 | goto out; |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 4859 | } |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4860 | newsrv->conn_src.sport_range = port_range_alloc_range(port_high - port_low + 1); |
| 4861 | for (i = 0; i < newsrv->conn_src.sport_range->size; i++) |
| 4862 | newsrv->conn_src.sport_range->ports[i] = port_low + i; |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 4863 | } |
| 4864 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4865 | cur_arg += 2; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4866 | while (*(args[cur_arg])) { |
| 4867 | if (!strcmp(args[cur_arg], "usesrc")) { /* address to use outside */ |
Pieter Baauw | d551fb5 | 2013-05-08 22:49:23 +0200 | [diff] [blame] | 4868 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_TRANSPARENT) |
| 4869 | #if !defined(CONFIG_HAP_TRANSPARENT) |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4870 | if (!is_addr(&newsrv->conn_src.source_addr)) { |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4871 | Alert("parsing [%s:%d] : '%s' requires an explicit '%s' address.\n", |
| 4872 | file, linenum, "usesrc", "source"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4873 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4874 | goto out; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4875 | } |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4876 | #endif |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4877 | if (!*args[cur_arg + 1]) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4878 | 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] | 4879 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4880 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4881 | goto out; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4882 | } |
| 4883 | if (!strcmp(args[cur_arg + 1], "client")) { |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4884 | newsrv->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 4885 | newsrv->conn_src.opts |= CO_SRC_TPROXY_CLI; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4886 | } else if (!strcmp(args[cur_arg + 1], "clientip")) { |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4887 | newsrv->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 4888 | newsrv->conn_src.opts |= CO_SRC_TPROXY_CIP; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4889 | } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) { |
| 4890 | char *name, *end; |
| 4891 | |
| 4892 | name = args[cur_arg+1] + 7; |
| 4893 | while (isspace(*name)) |
| 4894 | name++; |
| 4895 | |
| 4896 | end = name; |
| 4897 | while (*end && !isspace(*end) && *end != ',' && *end != ')') |
| 4898 | end++; |
| 4899 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4900 | newsrv->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 4901 | newsrv->conn_src.opts |= CO_SRC_TPROXY_DYN; |
| 4902 | newsrv->conn_src.bind_hdr_name = calloc(1, end - name + 1); |
| 4903 | newsrv->conn_src.bind_hdr_len = end - name; |
| 4904 | memcpy(newsrv->conn_src.bind_hdr_name, name, end - name); |
| 4905 | newsrv->conn_src.bind_hdr_name[end-name] = '\0'; |
| 4906 | newsrv->conn_src.bind_hdr_occ = -1; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4907 | |
| 4908 | /* now look for an occurrence number */ |
| 4909 | while (isspace(*end)) |
| 4910 | end++; |
| 4911 | if (*end == ',') { |
| 4912 | end++; |
| 4913 | name = end; |
| 4914 | if (*end == '-') |
| 4915 | end++; |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 4916 | while (isdigit((int)*end)) |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4917 | end++; |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4918 | newsrv->conn_src.bind_hdr_occ = strl2ic(name, end-name); |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4919 | } |
| 4920 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4921 | if (newsrv->conn_src.bind_hdr_occ < -MAX_HDR_HISTORY) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4922 | Alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative" |
| 4923 | " occurrences values smaller than %d.\n", |
| 4924 | file, linenum, MAX_HDR_HISTORY); |
| 4925 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4926 | goto out; |
| 4927 | } |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4928 | } else { |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4929 | struct sockaddr_storage *sk; |
| 4930 | int port1, port2; |
| 4931 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 4932 | sk = str2sa_range(args[cur_arg + 1], &port1, &port2, &errmsg, NULL); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4933 | if (!sk) { |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 4934 | Alert("parsing [%s:%d] : '%s %s' : %s\n", |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 4935 | file, linenum, args[cur_arg], args[cur_arg+1], errmsg); |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 4936 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 4937 | goto out; |
| 4938 | } |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 4939 | |
| 4940 | proto = protocol_by_family(sk->ss_family); |
| 4941 | if (!proto || !proto->connect) { |
| 4942 | Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 4943 | file, linenum, args[cur_arg], args[cur_arg+1]); |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4944 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4945 | goto out; |
| 4946 | } |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 4947 | |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4948 | if (port1 != port2) { |
| 4949 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 4950 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4951 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4952 | goto out; |
| 4953 | } |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4954 | newsrv->conn_src.tproxy_addr = *sk; |
| 4955 | newsrv->conn_src.opts |= CO_SRC_TPROXY_ADDR; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4956 | } |
| 4957 | global.last_checks |= LSTCHK_NETADM; |
Pieter Baauw | d551fb5 | 2013-05-08 22:49:23 +0200 | [diff] [blame] | 4958 | #if !defined(CONFIG_HAP_TRANSPARENT) |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4959 | global.last_checks |= LSTCHK_CTTPROXY; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4960 | #endif |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4961 | cur_arg += 2; |
| 4962 | continue; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4963 | #else /* no TPROXY support */ |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4964 | 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] | 4965 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4966 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4967 | goto out; |
Pieter Baauw | d551fb5 | 2013-05-08 22:49:23 +0200 | [diff] [blame] | 4968 | #endif /* defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_TRANSPARENT) */ |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4969 | } /* "usesrc" */ |
| 4970 | |
| 4971 | if (!strcmp(args[cur_arg], "interface")) { /* specifically bind to this interface */ |
| 4972 | #ifdef SO_BINDTODEVICE |
| 4973 | if (!*args[cur_arg + 1]) { |
| 4974 | Alert("parsing [%s:%d] : '%s' : missing interface name.\n", |
| 4975 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4976 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4977 | goto out; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4978 | } |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4979 | free(newsrv->conn_src.iface_name); |
| 4980 | newsrv->conn_src.iface_name = strdup(args[cur_arg + 1]); |
| 4981 | newsrv->conn_src.iface_len = strlen(newsrv->conn_src.iface_name); |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4982 | global.last_checks |= LSTCHK_NETADM; |
| 4983 | #else |
| 4984 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 4985 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4986 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4987 | goto out; |
Willy Tarreau | 77074d5 | 2006-11-12 23:57:19 +0100 | [diff] [blame] | 4988 | #endif |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4989 | cur_arg += 2; |
| 4990 | continue; |
| 4991 | } |
| 4992 | /* this keyword in not an option of "source" */ |
| 4993 | break; |
| 4994 | } /* while */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4995 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4996 | 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] | 4997 | Alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n", |
| 4998 | file, linenum, "usesrc", "source"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4999 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5000 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 5001 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5002 | else { |
Willy Tarreau | d0d6059 | 2012-10-10 08:57:40 +0200 | [diff] [blame] | 5003 | static int srv_dumped; |
| 5004 | struct srv_kw *kw; |
| 5005 | char *err; |
| 5006 | |
| 5007 | kw = srv_find_kw(args[cur_arg]); |
| 5008 | if (kw) { |
| 5009 | char *err = NULL; |
| 5010 | int code; |
| 5011 | |
| 5012 | if (!kw->parse) { |
| 5013 | Alert("parsing [%s:%d] : '%s %s' : '%s' option is not implemented in this version (check build options).\n", |
| 5014 | file, linenum, args[0], args[1], args[cur_arg]); |
| 5015 | cur_arg += 1 + kw->skip ; |
| 5016 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5017 | goto out; |
| 5018 | } |
| 5019 | |
| 5020 | if (defsrv && !kw->default_ok) { |
| 5021 | Alert("parsing [%s:%d] : '%s %s' : '%s' option is not accepted in default-server sections.\n", |
| 5022 | file, linenum, args[0], args[1], args[cur_arg]); |
| 5023 | cur_arg += 1 + kw->skip ; |
| 5024 | err_code |= ERR_ALERT; |
| 5025 | continue; |
| 5026 | } |
| 5027 | |
| 5028 | code = kw->parse(args, &cur_arg, curproxy, newsrv, &err); |
| 5029 | err_code |= code; |
| 5030 | |
| 5031 | if (code) { |
| 5032 | if (err && *err) { |
| 5033 | indent_msg(&err, 2); |
| 5034 | Alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], err); |
| 5035 | } |
| 5036 | else |
| 5037 | Alert("parsing [%s:%d] : '%s %s' : error encountered while processing '%s'.\n", |
| 5038 | file, linenum, args[0], args[1], args[cur_arg]); |
| 5039 | if (code & ERR_FATAL) { |
| 5040 | free(err); |
| 5041 | cur_arg += 1 + kw->skip; |
| 5042 | goto out; |
| 5043 | } |
| 5044 | } |
| 5045 | free(err); |
| 5046 | cur_arg += 1 + kw->skip; |
| 5047 | continue; |
| 5048 | } |
| 5049 | |
| 5050 | err = NULL; |
| 5051 | if (!srv_dumped) { |
| 5052 | srv_dump_kws(&err); |
| 5053 | indent_msg(&err, 4); |
| 5054 | srv_dumped = 1; |
| 5055 | } |
| 5056 | |
| 5057 | Alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'.%s%s\n", |
| 5058 | file, linenum, args[0], args[1], args[cur_arg], |
| 5059 | err ? " Registered keywords :" : "", err ? err : ""); |
| 5060 | free(err); |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 5061 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5062 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5063 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5064 | } |
| 5065 | } |
| 5066 | |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 5067 | /* Set initial drain state using now-configured weight */ |
| 5068 | set_server_drain_state(newsrv); |
| 5069 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5070 | if (do_check) { |
Simon Horman | 69d29f9 | 2013-02-23 15:14:19 +0900 | [diff] [blame] | 5071 | int ret; |
| 5072 | |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 5073 | if (newsrv->trackit) { |
| 5074 | Alert("parsing [%s:%d]: unable to enable checks and tracking at the same time!\n", |
| 5075 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5076 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5077 | goto out; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 5078 | } |
| 5079 | |
Willy Tarreau | f4288ee | 2012-09-28 18:13:10 +0200 | [diff] [blame] | 5080 | /* If neither a port nor an addr was specified and no check transport |
| 5081 | * layer is forced, then the transport layer used by the checks is the |
| 5082 | * same as for the production traffic. Otherwise we use raw_sock by |
| 5083 | * default, unless one is specified. |
| 5084 | */ |
Simon Horman | 6618300 | 2013-02-23 10:16:43 +0900 | [diff] [blame] | 5085 | if (!newsrv->check.port && !is_addr(&newsrv->check_common.addr)) { |
Willy Tarreau | 7151633 | 2012-10-10 23:01:14 +0200 | [diff] [blame] | 5086 | #ifdef USE_OPENSSL |
Willy Tarreau | f4288ee | 2012-09-28 18:13:10 +0200 | [diff] [blame] | 5087 | newsrv->check.use_ssl |= newsrv->use_ssl; |
Willy Tarreau | 7151633 | 2012-10-10 23:01:14 +0200 | [diff] [blame] | 5088 | #endif |
Willy Tarreau | 6c16adc | 2012-10-05 00:04:16 +0200 | [diff] [blame] | 5089 | newsrv->check.send_proxy |= (newsrv->state & SRV_SEND_PROXY); |
| 5090 | } |
Simon Horman | 6618300 | 2013-02-23 10:16:43 +0900 | [diff] [blame] | 5091 | /* try to get the port from check_core.addr if check.port not set */ |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 5092 | if (!newsrv->check.port) |
Simon Horman | 6618300 | 2013-02-23 10:16:43 +0900 | [diff] [blame] | 5093 | newsrv->check.port = get_host_port(&newsrv->check_common.addr); |
Willy Tarreau | 0f03c6f | 2007-03-25 20:46:19 +0200 | [diff] [blame] | 5094 | |
Willy Tarreau | dbfa445 | 2013-02-20 19:06:35 +0100 | [diff] [blame] | 5095 | if (!newsrv->check.port) |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 5096 | newsrv->check.port = realport; /* by default */ |
Willy Tarreau | dbfa445 | 2013-02-20 19:06:35 +0100 | [diff] [blame] | 5097 | |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 5098 | if (!newsrv->check.port) { |
Willy Tarreau | ef00b50 | 2007-01-07 02:40:09 +0100 | [diff] [blame] | 5099 | /* not yet valid, because no port was set on |
| 5100 | * the server either. We'll check if we have |
| 5101 | * a known port on the first listener. |
| 5102 | */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 5103 | struct listener *l; |
| 5104 | |
| 5105 | list_for_each_entry(l, &curproxy->conf.listeners, by_fe) { |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 5106 | newsrv->check.port = get_host_port(&l->addr); |
| 5107 | if (newsrv->check.port) |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 5108 | break; |
| 5109 | } |
Willy Tarreau | ef00b50 | 2007-01-07 02:40:09 +0100 | [diff] [blame] | 5110 | } |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 5111 | if (!newsrv->check.port) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5112 | Alert("parsing [%s:%d] : server %s has neither service port nor check port. Check has been disabled.\n", |
| 5113 | file, linenum, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5114 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5115 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5116 | } |
Willy Tarreau | 1ae1b7b | 2012-09-28 15:28:30 +0200 | [diff] [blame] | 5117 | |
Willy Tarreau | 2f075e9 | 2013-12-03 11:11:34 +0100 | [diff] [blame] | 5118 | /* note: check type will be set during the config review phase */ |
| 5119 | ret = init_check(&newsrv->check, 0, file, linenum); |
Simon Horman | 69d29f9 | 2013-02-23 15:14:19 +0900 | [diff] [blame] | 5120 | if (ret) { |
| 5121 | err_code |= ret; |
Willy Tarreau | da92e2f | 2012-07-06 09:40:59 +0200 | [diff] [blame] | 5122 | goto out; |
| 5123 | } |
| 5124 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5125 | newsrv->state |= SRV_CHECKED; |
| 5126 | } |
| 5127 | |
Simon Horman | d60d691 | 2013-11-25 10:46:36 +0900 | [diff] [blame] | 5128 | if (do_agent) { |
| 5129 | int ret; |
| 5130 | |
| 5131 | if (!newsrv->agent.port) { |
| 5132 | Alert("parsing [%s:%d] : server %s does not have agent port. Agent check has been disabled.\n", |
| 5133 | file, linenum, newsrv->id); |
| 5134 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5135 | goto out; |
| 5136 | } |
| 5137 | |
| 5138 | if (!newsrv->agent.inter) |
| 5139 | newsrv->agent.inter = newsrv->check.inter; |
| 5140 | |
| 5141 | ret = init_check(&newsrv->agent, PR_O2_LB_AGENT_CHK, file, linenum); |
| 5142 | if (ret) { |
| 5143 | err_code |= ret; |
| 5144 | goto out; |
| 5145 | } |
| 5146 | |
| 5147 | newsrv->state |= SRV_AGENT_CHECKED; |
| 5148 | } |
| 5149 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 5150 | if (!defsrv) { |
| 5151 | if (newsrv->state & SRV_BACKUP) |
| 5152 | curproxy->srv_bck++; |
| 5153 | else |
| 5154 | curproxy->srv_act++; |
Willy Tarreau | b625a08 | 2007-11-26 01:15:43 +0100 | [diff] [blame] | 5155 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 5156 | newsrv->prev_state = newsrv->state; |
| 5157 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 5158 | } |
| 5159 | |
| 5160 | else if (strcmp(args[0], "unique-id-format") == 0) { |
| 5161 | if (!*(args[1])) { |
| 5162 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 5163 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5164 | goto out; |
| 5165 | } |
William Lallemand | 3203ff4 | 2012-11-11 17:30:56 +0100 | [diff] [blame] | 5166 | if (*(args[2])) { |
| 5167 | Alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]); |
| 5168 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5169 | goto out; |
| 5170 | } |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 5171 | free(curproxy->conf.uniqueid_format_string); |
| 5172 | curproxy->conf.uniqueid_format_string = strdup(args[1]); |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 5173 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 5174 | free(curproxy->conf.uif_file); |
| 5175 | curproxy->conf.uif_file = strdup(curproxy->conf.args.file); |
| 5176 | curproxy->conf.uif_line = curproxy->conf.args.line; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 5177 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 5178 | |
| 5179 | else if (strcmp(args[0], "unique-id-header") == 0) { |
| 5180 | if (!*(args[1])) { |
| 5181 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 5182 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5183 | goto out; |
| 5184 | } |
| 5185 | free(curproxy->header_unique_id); |
| 5186 | curproxy->header_unique_id = strdup(args[1]); |
| 5187 | } |
| 5188 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 5189 | else if (strcmp(args[0], "log-format") == 0) { |
| 5190 | if (!*(args[1])) { |
| 5191 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 5192 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5193 | goto out; |
| 5194 | } |
William Lallemand | 3203ff4 | 2012-11-11 17:30:56 +0100 | [diff] [blame] | 5195 | if (*(args[2])) { |
| 5196 | Alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]); |
| 5197 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5198 | goto out; |
| 5199 | } |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 5200 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 5201 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 5202 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 5203 | curproxy->conf.logformat_string != clf_http_log_format) |
| 5204 | free(curproxy->conf.logformat_string); |
| 5205 | curproxy->conf.logformat_string = strdup(args[1]); |
| 5206 | |
| 5207 | free(curproxy->conf.lfs_file); |
| 5208 | curproxy->conf.lfs_file = strdup(curproxy->conf.args.file); |
| 5209 | curproxy->conf.lfs_line = curproxy->conf.args.line; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 5210 | |
| 5211 | /* get a chance to improve log-format error reporting by |
| 5212 | * reporting the correct line-number when possible. |
| 5213 | */ |
| 5214 | if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) { |
| 5215 | Warning("parsing [%s:%d] : backend '%s' : 'log-format' directive is ignored in backends.\n", |
| 5216 | file, linenum, curproxy->id); |
| 5217 | err_code |= ERR_WARN; |
| 5218 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5219 | } |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 5220 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5221 | else if (!strcmp(args[0], "log") && kwm == KWM_NO) { |
| 5222 | /* delete previous herited or defined syslog servers */ |
| 5223 | struct logsrv *back; |
| 5224 | |
| 5225 | if (*(args[1]) != 0) { |
| 5226 | Alert("parsing [%s:%d]:%s : 'no log' does not expect arguments.\n", file, linenum, args[1]); |
| 5227 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5228 | goto out; |
| 5229 | } |
| 5230 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 5231 | list_for_each_entry_safe(tmplogsrv, back, &curproxy->logsrvs, list) { |
| 5232 | LIST_DEL(&tmplogsrv->list); |
| 5233 | free(tmplogsrv); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5234 | } |
| 5235 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5236 | else if (!strcmp(args[0], "log")) { /* syslog server address */ |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5237 | struct logsrv *logsrv; |
| 5238 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5239 | if (*(args[1]) && *(args[2]) == 0 && !strcmp(args[1], "global")) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5240 | /* copy global.logrsvs linked list to the end of curproxy->logsrvs */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 5241 | list_for_each_entry(tmplogsrv, &global.logsrvs, list) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5242 | struct logsrv *node = malloc(sizeof(struct logsrv)); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 5243 | memcpy(node, tmplogsrv, sizeof(struct logsrv)); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5244 | LIST_INIT(&node->list); |
| 5245 | LIST_ADDQ(&curproxy->logsrvs, &node->list); |
| 5246 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5247 | } |
| 5248 | else if (*(args[1]) && *(args[2])) { |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 5249 | struct sockaddr_storage *sk; |
| 5250 | int port1, port2; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5251 | |
| 5252 | logsrv = calloc(1, sizeof(struct logsrv)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5253 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5254 | logsrv->facility = get_log_facility(args[2]); |
| 5255 | if (logsrv->facility < 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5256 | 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] | 5257 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5258 | goto out; |
| 5259 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5260 | } |
| 5261 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5262 | logsrv->level = 7; /* max syslog level = debug */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5263 | if (*(args[3])) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5264 | logsrv->level = get_log_level(args[3]); |
| 5265 | if (logsrv->level < 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5266 | 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] | 5267 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5268 | goto out; |
| 5269 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5270 | } |
| 5271 | } |
| 5272 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5273 | logsrv->minlvl = 0; /* limit syslog level to this level (emerg) */ |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 5274 | if (*(args[4])) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5275 | logsrv->minlvl = get_log_level(args[4]); |
Willy Tarreau | f7f057b | 2013-01-24 00:31:24 +0100 | [diff] [blame] | 5276 | if (logsrv->minlvl < 0) { |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 5277 | 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] | 5278 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5279 | goto out; |
| 5280 | |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 5281 | } |
| 5282 | } |
| 5283 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 5284 | sk = str2sa_range(args[1], &port1, &port2, &errmsg, NULL); |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 5285 | if (!sk) { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 5286 | Alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 5287 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 5288 | goto out; |
| 5289 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5290 | |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 5291 | logsrv->addr = *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5292 | |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 5293 | if (sk->ss_family == AF_INET || sk->ss_family == AF_INET6) { |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5294 | if (port1 != port2) { |
| 5295 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 5296 | file, linenum, args[0], args[1]); |
| 5297 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5298 | goto out; |
| 5299 | } |
| 5300 | |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5301 | if (!port1) |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5302 | set_host_port(&logsrv->addr, SYSLOG_PORT); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5303 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5304 | |
| 5305 | LIST_ADDQ(&curproxy->logsrvs, &logsrv->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5306 | } |
| 5307 | else { |
| 5308 | Alert("parsing [%s:%d] : 'log' expects either <address[:port]> and <facility> or 'global' as arguments.\n", |
| 5309 | file, linenum); |
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 | } |
| 5314 | 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] | 5315 | int cur_arg; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5316 | int port1, port2; |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 5317 | struct sockaddr_storage *sk; |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 5318 | struct protocol *proto; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5319 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5320 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5321 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5322 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5323 | if (!*args[1]) { |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5324 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optionally '%s' <addr>, and '%s' <name>.\n", |
| 5325 | file, linenum, "source", "usesrc", "interface"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5326 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5327 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5328 | } |
Willy Tarreau | 368480c | 2009-03-01 08:27:21 +0100 | [diff] [blame] | 5329 | |
| 5330 | /* we must first clear any optional default setting */ |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 5331 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 5332 | free(curproxy->conn_src.iface_name); |
| 5333 | curproxy->conn_src.iface_name = NULL; |
| 5334 | curproxy->conn_src.iface_len = 0; |
Willy Tarreau | 368480c | 2009-03-01 08:27:21 +0100 | [diff] [blame] | 5335 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 5336 | sk = str2sa_range(args[1], &port1, &port2, &errmsg, NULL); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 5337 | if (!sk) { |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 5338 | Alert("parsing [%s:%d] : '%s %s' : %s\n", |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 5339 | file, linenum, args[0], args[1], errmsg); |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 5340 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 5341 | goto out; |
| 5342 | } |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 5343 | |
| 5344 | proto = protocol_by_family(sk->ss_family); |
| 5345 | if (!proto || !proto->connect) { |
| 5346 | Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5347 | file, linenum, args[0], args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 5348 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5349 | goto out; |
| 5350 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5351 | |
| 5352 | if (port1 != port2) { |
| 5353 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 5354 | file, linenum, args[0], args[1]); |
| 5355 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5356 | goto out; |
| 5357 | } |
| 5358 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 5359 | curproxy->conn_src.source_addr = *sk; |
| 5360 | curproxy->conn_src.opts |= CO_SRC_BIND; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5361 | |
| 5362 | cur_arg = 2; |
| 5363 | while (*(args[cur_arg])) { |
| 5364 | if (!strcmp(args[cur_arg], "usesrc")) { /* address to use outside */ |
Pieter Baauw | d551fb5 | 2013-05-08 22:49:23 +0200 | [diff] [blame] | 5365 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_TRANSPARENT) |
| 5366 | #if !defined(CONFIG_HAP_TRANSPARENT) |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 5367 | if (!is_addr(&curproxy->conn_src.source_addr)) { |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5368 | Alert("parsing [%s:%d] : '%s' requires an explicit 'source' address.\n", |
| 5369 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5370 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5371 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5372 | } |
| 5373 | #endif |
| 5374 | if (!*args[cur_arg + 1]) { |
| 5375 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n", |
| 5376 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5377 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5378 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5379 | } |
| 5380 | |
| 5381 | if (!strcmp(args[cur_arg + 1], "client")) { |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 5382 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 5383 | curproxy->conn_src.opts |= CO_SRC_TPROXY_CLI; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5384 | } else if (!strcmp(args[cur_arg + 1], "clientip")) { |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 5385 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 5386 | curproxy->conn_src.opts |= CO_SRC_TPROXY_CIP; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 5387 | } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) { |
| 5388 | char *name, *end; |
| 5389 | |
| 5390 | name = args[cur_arg+1] + 7; |
| 5391 | while (isspace(*name)) |
| 5392 | name++; |
| 5393 | |
| 5394 | end = name; |
| 5395 | while (*end && !isspace(*end) && *end != ',' && *end != ')') |
| 5396 | end++; |
| 5397 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 5398 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 5399 | curproxy->conn_src.opts |= CO_SRC_TPROXY_DYN; |
| 5400 | curproxy->conn_src.bind_hdr_name = calloc(1, end - name + 1); |
| 5401 | curproxy->conn_src.bind_hdr_len = end - name; |
| 5402 | memcpy(curproxy->conn_src.bind_hdr_name, name, end - name); |
| 5403 | curproxy->conn_src.bind_hdr_name[end-name] = '\0'; |
| 5404 | curproxy->conn_src.bind_hdr_occ = -1; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 5405 | |
| 5406 | /* now look for an occurrence number */ |
| 5407 | while (isspace(*end)) |
| 5408 | end++; |
| 5409 | if (*end == ',') { |
| 5410 | end++; |
| 5411 | name = end; |
| 5412 | if (*end == '-') |
| 5413 | end++; |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 5414 | while (isdigit((int)*end)) |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 5415 | end++; |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 5416 | curproxy->conn_src.bind_hdr_occ = strl2ic(name, end-name); |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 5417 | } |
| 5418 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 5419 | if (curproxy->conn_src.bind_hdr_occ < -MAX_HDR_HISTORY) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 5420 | Alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative" |
| 5421 | " occurrences values smaller than %d.\n", |
| 5422 | file, linenum, MAX_HDR_HISTORY); |
| 5423 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5424 | goto out; |
| 5425 | } |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5426 | } else { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 5427 | struct sockaddr_storage *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5428 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 5429 | sk = str2sa_range(args[cur_arg + 1], &port1, &port2, &errmsg, NULL); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 5430 | if (!sk) { |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 5431 | Alert("parsing [%s:%d] : '%s %s' : %s\n", |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 5432 | file, linenum, args[cur_arg], args[cur_arg+1], errmsg); |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 5433 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 5434 | goto out; |
| 5435 | } |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 5436 | |
| 5437 | proto = protocol_by_family(sk->ss_family); |
| 5438 | if (!proto || !proto->connect) { |
| 5439 | Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 5440 | file, linenum, args[cur_arg], args[cur_arg+1]); |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5441 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5442 | goto out; |
| 5443 | } |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 5444 | |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5445 | if (port1 != port2) { |
| 5446 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 5447 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 5448 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5449 | goto out; |
| 5450 | } |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 5451 | curproxy->conn_src.tproxy_addr = *sk; |
| 5452 | curproxy->conn_src.opts |= CO_SRC_TPROXY_ADDR; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5453 | } |
| 5454 | global.last_checks |= LSTCHK_NETADM; |
Pieter Baauw | d551fb5 | 2013-05-08 22:49:23 +0200 | [diff] [blame] | 5455 | #if !defined(CONFIG_HAP_TRANSPARENT) |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5456 | global.last_checks |= LSTCHK_CTTPROXY; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 5457 | #endif |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5458 | #else /* no TPROXY support */ |
| 5459 | 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] | 5460 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5461 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5462 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5463 | #endif |
| 5464 | cur_arg += 2; |
| 5465 | continue; |
Willy Tarreau | 77074d5 | 2006-11-12 23:57:19 +0100 | [diff] [blame] | 5466 | } |
| 5467 | |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5468 | if (!strcmp(args[cur_arg], "interface")) { /* specifically bind to this interface */ |
| 5469 | #ifdef SO_BINDTODEVICE |
| 5470 | if (!*args[cur_arg + 1]) { |
| 5471 | Alert("parsing [%s:%d] : '%s' : missing interface name.\n", |
| 5472 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5473 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5474 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5475 | } |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 5476 | free(curproxy->conn_src.iface_name); |
| 5477 | curproxy->conn_src.iface_name = strdup(args[cur_arg + 1]); |
| 5478 | curproxy->conn_src.iface_len = strlen(curproxy->conn_src.iface_name); |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5479 | global.last_checks |= LSTCHK_NETADM; |
| 5480 | #else |
| 5481 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 5482 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5483 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5484 | goto out; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 5485 | #endif |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5486 | cur_arg += 2; |
| 5487 | continue; |
| 5488 | } |
| 5489 | 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] | 5490 | file, linenum, args[0], "interface", "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5491 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5492 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 5493 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5494 | } |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 5495 | else if (!strcmp(args[0], "usesrc")) { /* address to use outside: needs "source" first */ |
| 5496 | Alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n", |
| 5497 | file, linenum, "usesrc", "source"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5498 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5499 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 5500 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5501 | 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] | 5502 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5503 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 5504 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5505 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5506 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5507 | } |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5508 | |
| 5509 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5510 | SMP_OPT_DIR_REQ, ACT_REPLACE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5511 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5512 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5513 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5514 | } |
| 5515 | else if (!strcmp(args[0], "reqdel")) { /* delete request header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5516 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5517 | SMP_OPT_DIR_REQ, ACT_REMOVE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5518 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5519 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5520 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5521 | } |
| 5522 | 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] | 5523 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5524 | SMP_OPT_DIR_REQ, ACT_DENY, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5525 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5526 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5527 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5528 | } |
| 5529 | 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] | 5530 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5531 | SMP_OPT_DIR_REQ, ACT_PASS, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5532 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5533 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5534 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5535 | } |
| 5536 | 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] | 5537 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5538 | SMP_OPT_DIR_REQ, ACT_ALLOW, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5539 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5540 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5541 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5542 | } |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 5543 | 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] | 5544 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5545 | SMP_OPT_DIR_REQ, ACT_TARPIT, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5546 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5547 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5548 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 5549 | } |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5550 | 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] | 5551 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5552 | SMP_OPT_DIR_REQ, ACT_SETBE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5553 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5554 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5555 | goto out; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5556 | } |
| 5557 | 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] | 5558 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5559 | SMP_OPT_DIR_REQ, ACT_SETBE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5560 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5561 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5562 | goto out; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5563 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5564 | 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] | 5565 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5566 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 5567 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5568 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5569 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5570 | } |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5571 | |
| 5572 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5573 | SMP_OPT_DIR_REQ, ACT_REPLACE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5574 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5575 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5576 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5577 | } |
| 5578 | 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] | 5579 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5580 | SMP_OPT_DIR_REQ, ACT_REMOVE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5581 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5582 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5583 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5584 | } |
| 5585 | 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] | 5586 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5587 | SMP_OPT_DIR_REQ, ACT_DENY, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5588 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5589 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5590 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5591 | } |
| 5592 | 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] | 5593 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5594 | SMP_OPT_DIR_REQ, ACT_PASS, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5595 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5596 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5597 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5598 | } |
| 5599 | 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] | 5600 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5601 | SMP_OPT_DIR_REQ, ACT_ALLOW, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5602 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5603 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5604 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5605 | } |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 5606 | 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] | 5607 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5608 | SMP_OPT_DIR_REQ, ACT_TARPIT, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5609 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5610 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5611 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 5612 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5613 | else if (!strcmp(args[0], "reqadd")) { /* add request header */ |
Willy Tarreau | f4f0412 | 2010-01-28 18:10:50 +0100 | [diff] [blame] | 5614 | struct cond_wordlist *wl; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5615 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5616 | if (curproxy == &defproxy) { |
| 5617 | 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] | 5618 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5619 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5620 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5621 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5622 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5623 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5624 | if (*(args[1]) == 0) { |
| 5625 | 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] | 5626 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5627 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5628 | } |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5629 | |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 5630 | if ((strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0)) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 5631 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args+2, &errmsg)) == NULL) { |
| 5632 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 5633 | file, linenum, args[0], errmsg); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 5634 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5635 | goto out; |
| 5636 | } |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 5637 | err_code |= warnif_cond_conflicts(cond, |
| 5638 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 5639 | file, linenum); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 5640 | } |
| 5641 | else if (*args[2]) { |
| 5642 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 5643 | file, linenum, args[0], args[2]); |
| 5644 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5645 | goto out; |
| 5646 | } |
| 5647 | |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5648 | wl = calloc(1, sizeof(*wl)); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 5649 | wl->cond = cond; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5650 | wl->s = strdup(args[1]); |
| 5651 | LIST_ADDQ(&curproxy->req_add, &wl->list); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 5652 | warnif_misplaced_reqadd(curproxy, file, linenum, args[0]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5653 | } |
| 5654 | 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] | 5655 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5656 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 5657 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5658 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5659 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5660 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5661 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5662 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5663 | SMP_OPT_DIR_RES, ACT_REPLACE, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5664 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5665 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5666 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5667 | } |
| 5668 | else if (!strcmp(args[0], "rspdel")) { /* delete response header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5669 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5670 | SMP_OPT_DIR_RES, ACT_REMOVE, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5671 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5672 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5673 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5674 | } |
| 5675 | else if (!strcmp(args[0], "rspdeny")) { /* block response header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5676 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5677 | SMP_OPT_DIR_RES, ACT_DENY, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5678 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5679 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5680 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5681 | } |
| 5682 | 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] | 5683 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5684 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 5685 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5686 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5687 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5688 | } |
| 5689 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5690 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5691 | SMP_OPT_DIR_RES, ACT_REPLACE, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5692 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5693 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5694 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5695 | } |
| 5696 | 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] | 5697 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5698 | SMP_OPT_DIR_RES, ACT_REMOVE, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5699 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5700 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5701 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5702 | } |
| 5703 | 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] | 5704 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5705 | SMP_OPT_DIR_RES, ACT_DENY, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5706 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5707 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5708 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5709 | } |
| 5710 | else if (!strcmp(args[0], "rspadd")) { /* add response header */ |
Willy Tarreau | f4f0412 | 2010-01-28 18:10:50 +0100 | [diff] [blame] | 5711 | struct cond_wordlist *wl; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5712 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5713 | if (curproxy == &defproxy) { |
| 5714 | 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] | 5715 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5716 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5717 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5718 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5719 | err_code |= ERR_WARN; |
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 (*(args[1]) == 0) { |
| 5722 | 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] | 5723 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5724 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5725 | } |
| 5726 | |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5727 | if ((strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0)) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 5728 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args+2, &errmsg)) == NULL) { |
| 5729 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 5730 | file, linenum, args[0], errmsg); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5731 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5732 | goto out; |
| 5733 | } |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 5734 | err_code |= warnif_cond_conflicts(cond, |
| 5735 | (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR, |
| 5736 | file, linenum); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5737 | } |
| 5738 | else if (*args[2]) { |
| 5739 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 5740 | file, linenum, args[0], args[2]); |
| 5741 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5742 | goto out; |
| 5743 | } |
| 5744 | |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5745 | wl = calloc(1, sizeof(*wl)); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5746 | wl->cond = cond; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5747 | wl->s = strdup(args[1]); |
| 5748 | LIST_ADDQ(&curproxy->rsp_add, &wl->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5749 | } |
| 5750 | else if (!strcmp(args[0], "errorloc") || |
| 5751 | !strcmp(args[0], "errorloc302") || |
| 5752 | !strcmp(args[0], "errorloc303")) { /* error location */ |
| 5753 | int errnum, errlen; |
| 5754 | char *err; |
| 5755 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5756 | 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] | 5757 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5758 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5759 | if (*(args[2]) == 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 5760 | 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] | 5761 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5762 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5763 | } |
| 5764 | |
| 5765 | errnum = atol(args[1]); |
| 5766 | if (!strcmp(args[0], "errorloc303")) { |
| 5767 | err = malloc(strlen(HTTP_303) + strlen(args[2]) + 5); |
| 5768 | errlen = sprintf(err, "%s%s\r\n\r\n", HTTP_303, args[2]); |
| 5769 | } else { |
| 5770 | err = malloc(strlen(HTTP_302) + strlen(args[2]) + 5); |
| 5771 | errlen = sprintf(err, "%s%s\r\n\r\n", HTTP_302, args[2]); |
| 5772 | } |
| 5773 | |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 5774 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) { |
| 5775 | if (http_err_codes[rc] == errnum) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 5776 | chunk_destroy(&curproxy->errmsg[rc]); |
| 5777 | chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 5778 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5779 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5780 | } |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 5781 | |
| 5782 | if (rc >= HTTP_ERR_SIZE) { |
| 5783 | Warning("parsing [%s:%d] : status code %d not handled, error relocation will be ignored.\n", |
| 5784 | file, linenum, errnum); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5785 | free(err); |
| 5786 | } |
| 5787 | } |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5788 | else if (!strcmp(args[0], "errorfile")) { /* error message from a file */ |
| 5789 | int errnum, errlen, fd; |
| 5790 | char *err; |
| 5791 | struct stat stat; |
| 5792 | |
| 5793 | 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] | 5794 | err_code |= ERR_WARN; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5795 | |
| 5796 | if (*(args[2]) == 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 5797 | 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] | 5798 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5799 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5800 | } |
| 5801 | |
| 5802 | fd = open(args[2], O_RDONLY); |
| 5803 | if ((fd < 0) || (fstat(fd, &stat) < 0)) { |
| 5804 | Alert("parsing [%s:%d] : error opening file <%s> for custom error message <%s>.\n", |
| 5805 | file, linenum, args[2], args[1]); |
| 5806 | if (fd >= 0) |
| 5807 | close(fd); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5808 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5809 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5810 | } |
| 5811 | |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 5812 | if (stat.st_size <= global.tune.bufsize) { |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5813 | errlen = stat.st_size; |
| 5814 | } else { |
| 5815 | 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] | 5816 | file, linenum, args[2], global.tune.bufsize); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5817 | err_code |= ERR_WARN; |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 5818 | errlen = global.tune.bufsize; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5819 | } |
| 5820 | |
| 5821 | err = malloc(errlen); /* malloc() must succeed during parsing */ |
| 5822 | errnum = read(fd, err, errlen); |
| 5823 | if (errnum != errlen) { |
| 5824 | Alert("parsing [%s:%d] : error reading file <%s> for custom error message <%s>.\n", |
| 5825 | file, linenum, args[2], args[1]); |
| 5826 | close(fd); |
| 5827 | free(err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5828 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5829 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5830 | } |
| 5831 | close(fd); |
| 5832 | |
| 5833 | errnum = atol(args[1]); |
| 5834 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) { |
| 5835 | if (http_err_codes[rc] == errnum) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 5836 | chunk_destroy(&curproxy->errmsg[rc]); |
| 5837 | chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen); |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5838 | break; |
| 5839 | } |
| 5840 | } |
| 5841 | |
| 5842 | if (rc >= HTTP_ERR_SIZE) { |
| 5843 | Warning("parsing [%s:%d] : status code %d not handled, error customization will be ignored.\n", |
| 5844 | file, linenum, errnum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5845 | err_code |= ERR_WARN; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5846 | free(err); |
| 5847 | } |
| 5848 | } |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5849 | else if (!strcmp(args[0], "compression")) { |
| 5850 | struct comp *comp; |
| 5851 | if (curproxy->comp == NULL) { |
| 5852 | comp = calloc(1, sizeof(struct comp)); |
| 5853 | curproxy->comp = comp; |
| 5854 | } else { |
| 5855 | comp = curproxy->comp; |
| 5856 | } |
| 5857 | |
| 5858 | if (!strcmp(args[1], "algo")) { |
| 5859 | int cur_arg; |
William Lallemand | 8b52bb3 | 2012-11-16 18:06:41 +0100 | [diff] [blame] | 5860 | struct comp_ctx *ctx; |
William Lallemand | 552df67 | 2012-11-07 13:21:47 +0100 | [diff] [blame] | 5861 | |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5862 | cur_arg = 2; |
| 5863 | if (!*args[cur_arg]) { |
| 5864 | Alert("parsing [%s:%d] : '%s' expects <algorithm>\n", |
| 5865 | file, linenum, args[0]); |
| 5866 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5867 | goto out; |
| 5868 | } |
| 5869 | while (*(args[cur_arg])) { |
| 5870 | if (comp_append_algo(comp, args[cur_arg]) < 0) { |
| 5871 | Alert("parsing [%s:%d] : '%s' : '%s' is not a supported algorithm.\n", |
| 5872 | file, linenum, args[0], args[cur_arg]); |
| 5873 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5874 | goto out; |
| 5875 | } |
William Lallemand | 552df67 | 2012-11-07 13:21:47 +0100 | [diff] [blame] | 5876 | if (curproxy->comp->algos->init(&ctx, 9) == 0) { |
| 5877 | curproxy->comp->algos->end(&ctx); |
| 5878 | } else { |
| 5879 | Alert("parsing [%s:%d] : '%s' : Can't init '%s' algorithm.\n", |
| 5880 | file, linenum, args[0], args[cur_arg]); |
| 5881 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5882 | goto out; |
| 5883 | } |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5884 | cur_arg ++; |
| 5885 | continue; |
| 5886 | } |
| 5887 | } |
Willy Tarreau | 70737d1 | 2012-10-27 00:34:28 +0200 | [diff] [blame] | 5888 | else if (!strcmp(args[1], "offload")) { |
| 5889 | comp->offload = 1; |
| 5890 | } |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5891 | else if (!strcmp(args[1], "type")) { |
| 5892 | int cur_arg; |
| 5893 | cur_arg = 2; |
| 5894 | if (!*args[cur_arg]) { |
| 5895 | Alert("parsing [%s:%d] : '%s' expects <type>\n", |
| 5896 | file, linenum, args[0]); |
| 5897 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5898 | goto out; |
| 5899 | } |
| 5900 | while (*(args[cur_arg])) { |
| 5901 | comp_append_type(comp, args[cur_arg]); |
| 5902 | cur_arg ++; |
| 5903 | continue; |
| 5904 | } |
| 5905 | } |
| 5906 | else { |
Willy Tarreau | 70737d1 | 2012-10-27 00:34:28 +0200 | [diff] [blame] | 5907 | Alert("parsing [%s:%d] : '%s' expects 'algo', 'type' or 'offload'\n", |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5908 | file, linenum, args[0]); |
| 5909 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5910 | goto out; |
| 5911 | } |
| 5912 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5913 | else { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 5914 | struct cfg_kw_list *kwl; |
| 5915 | int index; |
| 5916 | |
| 5917 | list_for_each_entry(kwl, &cfg_keywords.list, list) { |
| 5918 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 5919 | if (kwl->kw[index].section != CFG_LISTEN) |
| 5920 | continue; |
| 5921 | if (strcmp(kwl->kw[index].kw, args[0]) == 0) { |
| 5922 | /* prepare error message just in case */ |
Willy Tarreau | 28a47d6 | 2012-09-18 20:02:48 +0200 | [diff] [blame] | 5923 | 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] | 5924 | if (rc < 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 5925 | Alert("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5926 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5927 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 5928 | } |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 5929 | else if (rc > 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 5930 | Warning("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5931 | err_code |= ERR_WARN; |
| 5932 | goto out; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 5933 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5934 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 5935 | } |
| 5936 | } |
| 5937 | } |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5938 | |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5939 | 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] | 5940 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5941 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5942 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5943 | out: |
Willy Tarreau | f4068b6 | 2012-05-08 17:37:49 +0200 | [diff] [blame] | 5944 | free(errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5945 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5946 | } |
| 5947 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5948 | int |
| 5949 | cfg_parse_users(const char *file, int linenum, char **args, int kwm) |
| 5950 | { |
| 5951 | |
| 5952 | int err_code = 0; |
| 5953 | const char *err; |
| 5954 | |
| 5955 | if (!strcmp(args[0], "userlist")) { /* new userlist */ |
| 5956 | struct userlist *newul; |
| 5957 | |
| 5958 | if (!*args[1]) { |
| 5959 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 5960 | file, linenum, args[0]); |
| 5961 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5962 | goto out; |
| 5963 | } |
| 5964 | |
| 5965 | err = invalid_char(args[1]); |
| 5966 | if (err) { |
| 5967 | Alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 5968 | file, linenum, *err, args[0], args[1]); |
| 5969 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5970 | goto out; |
| 5971 | } |
| 5972 | |
| 5973 | for (newul = userlist; newul; newul = newul->next) |
| 5974 | if (!strcmp(newul->name, args[1])) { |
| 5975 | Warning("parsing [%s:%d]: ignoring duplicated userlist '%s'.\n", |
| 5976 | file, linenum, args[1]); |
| 5977 | err_code |= ERR_WARN; |
| 5978 | goto out; |
| 5979 | } |
| 5980 | |
| 5981 | newul = (struct userlist *)calloc(1, sizeof(struct userlist)); |
| 5982 | if (!newul) { |
| 5983 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 5984 | err_code |= ERR_ALERT | ERR_ABORT; |
| 5985 | goto out; |
| 5986 | } |
| 5987 | |
| 5988 | newul->groupusers = calloc(MAX_AUTH_GROUPS, sizeof(char *)); |
| 5989 | newul->name = strdup(args[1]); |
| 5990 | |
| 5991 | if (!newul->groupusers | !newul->name) { |
| 5992 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 5993 | err_code |= ERR_ALERT | ERR_ABORT; |
| 5994 | goto out; |
| 5995 | } |
| 5996 | |
| 5997 | newul->next = userlist; |
| 5998 | userlist = newul; |
| 5999 | |
| 6000 | } else if (!strcmp(args[0], "group")) { /* new group */ |
| 6001 | int cur_arg, i; |
| 6002 | const char *err; |
| 6003 | |
| 6004 | if (!*args[1]) { |
| 6005 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 6006 | file, linenum, args[0]); |
| 6007 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6008 | goto out; |
| 6009 | } |
| 6010 | |
| 6011 | err = invalid_char(args[1]); |
| 6012 | if (err) { |
| 6013 | Alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 6014 | file, linenum, *err, args[0], args[1]); |
| 6015 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6016 | goto out; |
| 6017 | } |
| 6018 | |
| 6019 | for(i = 0; i < userlist->grpcnt; i++) |
| 6020 | if (!strcmp(userlist->groups[i], args[1])) { |
| 6021 | Warning("parsing [%s:%d]: ignoring duplicated group '%s' in userlist '%s'.\n", |
| 6022 | file, linenum, args[1], userlist->name); |
| 6023 | err_code |= ERR_ALERT; |
| 6024 | goto out; |
| 6025 | } |
| 6026 | |
| 6027 | if (userlist->grpcnt >= MAX_AUTH_GROUPS) { |
| 6028 | Alert("parsing [%s:%d]: too many groups (%u) in in userlist '%s' while adding group '%s'.\n", |
| 6029 | file, linenum, MAX_AUTH_GROUPS, userlist->name, args[1]); |
| 6030 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6031 | goto out; |
| 6032 | } |
| 6033 | |
| 6034 | cur_arg = 2; |
| 6035 | |
| 6036 | while (*args[cur_arg]) { |
| 6037 | if (!strcmp(args[cur_arg], "users")) { |
| 6038 | userlist->groupusers[userlist->grpcnt] = strdup(args[cur_arg + 1]); |
| 6039 | cur_arg += 2; |
| 6040 | continue; |
| 6041 | } else { |
| 6042 | Alert("parsing [%s:%d]: '%s' only supports 'users' option.\n", |
| 6043 | file, linenum, args[0]); |
| 6044 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6045 | goto out; |
| 6046 | } |
| 6047 | } |
| 6048 | |
| 6049 | userlist->groups[userlist->grpcnt++] = strdup(args[1]); |
| 6050 | } else if (!strcmp(args[0], "user")) { /* new user */ |
| 6051 | struct auth_users *newuser; |
| 6052 | int cur_arg; |
| 6053 | |
| 6054 | if (!*args[1]) { |
| 6055 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 6056 | file, linenum, args[0]); |
| 6057 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6058 | goto out; |
| 6059 | } |
| 6060 | |
| 6061 | for (newuser = userlist->users; newuser; newuser = newuser->next) |
| 6062 | if (!strcmp(newuser->user, args[1])) { |
| 6063 | Warning("parsing [%s:%d]: ignoring duplicated user '%s' in userlist '%s'.\n", |
| 6064 | file, linenum, args[1], userlist->name); |
| 6065 | err_code |= ERR_ALERT; |
| 6066 | goto out; |
| 6067 | } |
| 6068 | |
| 6069 | newuser = (struct auth_users *)calloc(1, sizeof(struct auth_users)); |
| 6070 | if (!newuser) { |
| 6071 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 6072 | err_code |= ERR_ALERT | ERR_ABORT; |
| 6073 | goto out; |
| 6074 | } |
| 6075 | |
| 6076 | newuser->user = strdup(args[1]); |
| 6077 | |
| 6078 | newuser->next = userlist->users; |
| 6079 | userlist->users = newuser; |
| 6080 | |
| 6081 | cur_arg = 2; |
| 6082 | |
| 6083 | while (*args[cur_arg]) { |
| 6084 | if (!strcmp(args[cur_arg], "password")) { |
| 6085 | #ifndef CONFIG_HAP_CRYPT |
| 6086 | Warning("parsing [%s:%d]: no crypt(3) support compiled, encrypted passwords will not work.\n", |
| 6087 | file, linenum); |
| 6088 | err_code |= ERR_ALERT; |
| 6089 | #endif |
| 6090 | newuser->pass = strdup(args[cur_arg + 1]); |
| 6091 | cur_arg += 2; |
| 6092 | continue; |
| 6093 | } else if (!strcmp(args[cur_arg], "insecure-password")) { |
| 6094 | newuser->pass = strdup(args[cur_arg + 1]); |
| 6095 | newuser->flags |= AU_O_INSECURE; |
| 6096 | cur_arg += 2; |
| 6097 | continue; |
| 6098 | } else if (!strcmp(args[cur_arg], "groups")) { |
Willy Tarreau | b4c06b7 | 2010-02-02 11:28:20 +0100 | [diff] [blame] | 6099 | newuser->u.groups = strdup(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6100 | cur_arg += 2; |
| 6101 | continue; |
| 6102 | } else { |
| 6103 | Alert("parsing [%s:%d]: '%s' only supports 'password', 'insecure-password' and 'groups' options.\n", |
| 6104 | file, linenum, args[0]); |
| 6105 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6106 | goto out; |
| 6107 | } |
| 6108 | } |
| 6109 | } else { |
| 6110 | Alert("parsing [%s:%d]: unknown keyword '%s' in '%s' section\n", file, linenum, args[0], "users"); |
| 6111 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6112 | } |
| 6113 | |
| 6114 | out: |
| 6115 | return err_code; |
| 6116 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6117 | |
| 6118 | /* |
| 6119 | * This function reads and parses the configuration file given in the argument. |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 6120 | * Returns the error code, 0 if OK, or any combination of : |
| 6121 | * - ERR_ABORT: must abort ASAP |
| 6122 | * - ERR_FATAL: we can continue parsing but not start the service |
| 6123 | * - ERR_WARN: a warning has been emitted |
| 6124 | * - ERR_ALERT: an alert has been emitted |
| 6125 | * Only the two first ones can stop processing, the two others are just |
| 6126 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6127 | */ |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 6128 | int readcfgfile(const char *file) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6129 | { |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 6130 | char thisline[LINESIZE]; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6131 | FILE *f; |
| 6132 | int linenum = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6133 | int confsect = CFG_NONE; |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 6134 | int err_code = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6135 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6136 | if ((f=fopen(file,"r")) == NULL) |
| 6137 | return -1; |
| 6138 | |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 6139 | while (fgets(thisline, sizeof(thisline), f) != NULL) { |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 6140 | int arg, kwm = KWM_STD; |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 6141 | char *end; |
| 6142 | char *args[MAX_LINE_ARGS + 1]; |
| 6143 | char *line = thisline; |
| 6144 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6145 | linenum++; |
| 6146 | |
| 6147 | end = line + strlen(line); |
| 6148 | |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 6149 | if (end-line == sizeof(thisline)-1 && *(end-1) != '\n') { |
| 6150 | /* Check if we reached the limit and the last char is not \n. |
| 6151 | * Watch out for the last line without the terminating '\n'! |
| 6152 | */ |
| 6153 | Alert("parsing [%s:%d]: line too long, limit: %d.\n", |
Willy Tarreau | 5e4a6f1 | 2009-04-11 19:42:49 +0200 | [diff] [blame] | 6154 | file, linenum, (int)sizeof(thisline)-1); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 6155 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 6156 | } |
| 6157 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6158 | /* skip leading spaces */ |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 6159 | while (isspace((unsigned char)*line)) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6160 | line++; |
| 6161 | |
| 6162 | arg = 0; |
| 6163 | args[arg] = line; |
| 6164 | |
| 6165 | while (*line && arg < MAX_LINE_ARGS) { |
| 6166 | /* first, we'll replace \\, \<space>, \#, \r, \n, \t, \xXX with their |
| 6167 | * C equivalent value. Other combinations left unchanged (eg: \1). |
| 6168 | */ |
| 6169 | if (*line == '\\') { |
| 6170 | int skip = 0; |
| 6171 | if (line[1] == ' ' || line[1] == '\\' || line[1] == '#') { |
| 6172 | *line = line[1]; |
| 6173 | skip = 1; |
| 6174 | } |
| 6175 | else if (line[1] == 'r') { |
| 6176 | *line = '\r'; |
| 6177 | skip = 1; |
| 6178 | } |
| 6179 | else if (line[1] == 'n') { |
| 6180 | *line = '\n'; |
| 6181 | skip = 1; |
| 6182 | } |
| 6183 | else if (line[1] == 't') { |
| 6184 | *line = '\t'; |
| 6185 | skip = 1; |
| 6186 | } |
| 6187 | else if (line[1] == 'x') { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6188 | if ((line + 3 < end) && ishex(line[2]) && ishex(line[3])) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6189 | unsigned char hex1, hex2; |
| 6190 | hex1 = toupper(line[2]) - '0'; |
| 6191 | hex2 = toupper(line[3]) - '0'; |
| 6192 | if (hex1 > 9) hex1 -= 'A' - '9' - 1; |
| 6193 | if (hex2 > 9) hex2 -= 'A' - '9' - 1; |
| 6194 | *line = (hex1<<4) + hex2; |
| 6195 | skip = 3; |
| 6196 | } |
| 6197 | else { |
| 6198 | 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] | 6199 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6200 | } |
| 6201 | } |
| 6202 | if (skip) { |
Cyril Bonté | dd1b01d | 2009-12-06 13:43:42 +0100 | [diff] [blame] | 6203 | memmove(line + 1, line + 1 + skip, end - (line + skip)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6204 | end -= skip; |
| 6205 | } |
| 6206 | line++; |
| 6207 | } |
| 6208 | else if (*line == '#' || *line == '\n' || *line == '\r') { |
| 6209 | /* end of string, end of loop */ |
| 6210 | *line = 0; |
| 6211 | break; |
| 6212 | } |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 6213 | else if (isspace((unsigned char)*line)) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6214 | /* a non-escaped space is an argument separator */ |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 6215 | *line++ = '\0'; |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 6216 | while (isspace((unsigned char)*line)) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6217 | line++; |
| 6218 | args[++arg] = line; |
| 6219 | } |
| 6220 | else { |
| 6221 | line++; |
| 6222 | } |
| 6223 | } |
| 6224 | |
| 6225 | /* empty line */ |
| 6226 | if (!**args) |
| 6227 | continue; |
| 6228 | |
Willy Tarreau | 7bb651e | 2009-11-09 21:16:53 +0100 | [diff] [blame] | 6229 | if (*line) { |
| 6230 | /* we had to stop due to too many args. |
| 6231 | * Let's terminate the string, print the offending part then cut the |
| 6232 | * last arg. |
| 6233 | */ |
| 6234 | while (*line && *line != '#' && *line != '\n' && *line != '\r') |
| 6235 | line++; |
| 6236 | *line = '\0'; |
| 6237 | |
Krzysztof Piotr Oledzki | 500b8f0 | 2009-12-15 22:34:51 +0100 | [diff] [blame] | 6238 | 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] | 6239 | file, linenum, arg + 1, (long)(args[arg] - thisline + 1), args[arg]); |
Willy Tarreau | 7bb651e | 2009-11-09 21:16:53 +0100 | [diff] [blame] | 6240 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6241 | args[arg] = line; |
| 6242 | } |
| 6243 | |
Willy Tarreau | 540abe4 | 2007-05-02 20:50:16 +0200 | [diff] [blame] | 6244 | /* zero out remaining args and ensure that at least one entry |
| 6245 | * is zeroed out. |
| 6246 | */ |
| 6247 | while (++arg <= MAX_LINE_ARGS) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6248 | args[arg] = line; |
| 6249 | } |
| 6250 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 6251 | /* check for keyword modifiers "no" and "default" */ |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 6252 | if (!strcmp(args[0], "no")) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6253 | char *tmp; |
| 6254 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 6255 | kwm = KWM_NO; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6256 | tmp = args[0]; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 6257 | for (arg=0; *args[arg+1]; arg++) |
| 6258 | args[arg] = args[arg+1]; // shift args after inversion |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6259 | *tmp = '\0'; // fix the next arg to \0 |
| 6260 | args[arg] = tmp; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 6261 | } |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 6262 | else if (!strcmp(args[0], "default")) { |
| 6263 | kwm = KWM_DEF; |
| 6264 | for (arg=0; *args[arg+1]; arg++) |
| 6265 | args[arg] = args[arg+1]; // shift args after inversion |
| 6266 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 6267 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6268 | if (kwm != KWM_STD && strcmp(args[0], "option") != 0 && \ |
| 6269 | strcmp(args[0], "log") != 0) { |
| 6270 | 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] | 6271 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 6272 | } |
| 6273 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 6274 | if (!strcmp(args[0], "listen") || |
| 6275 | !strcmp(args[0], "frontend") || |
| 6276 | !strcmp(args[0], "backend") || |
| 6277 | !strcmp(args[0], "ruleset") || |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 6278 | !strcmp(args[0], "defaults")) { /* new proxy */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6279 | confsect = CFG_LISTEN; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 6280 | free(cursection); |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 6281 | cursection = strdup(args[0]); |
| 6282 | } |
| 6283 | else if (!strcmp(args[0], "global")) { /* global config */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6284 | confsect = CFG_GLOBAL; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 6285 | free(cursection); |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 6286 | cursection = strdup(args[0]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 6287 | } |
| 6288 | else if (!strcmp(args[0], "userlist")) { |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6289 | confsect = CFG_USERLIST; |
| 6290 | free(cursection); |
| 6291 | cursection = strdup(args[0]); |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 6292 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 6293 | else if (!strcmp(args[0], "peers")) { |
| 6294 | confsect = CFG_PEERS; |
| 6295 | free(cursection); |
| 6296 | cursection = strdup(args[0]); |
| 6297 | } |
| 6298 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6299 | /* else it's a section keyword */ |
| 6300 | |
| 6301 | switch (confsect) { |
| 6302 | case CFG_LISTEN: |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6303 | err_code |= cfg_parse_listen(file, linenum, args, kwm); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6304 | break; |
| 6305 | case CFG_GLOBAL: |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 6306 | err_code |= cfg_parse_global(file, linenum, args, kwm); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6307 | break; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6308 | case CFG_USERLIST: |
| 6309 | err_code |= cfg_parse_users(file, linenum, args, kwm); |
| 6310 | break; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 6311 | case CFG_PEERS: |
| 6312 | err_code |= cfg_parse_peers(file, linenum, args, kwm); |
| 6313 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6314 | default: |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6315 | 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] | 6316 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6317 | } |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 6318 | |
| 6319 | if (err_code & ERR_ABORT) |
| 6320 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6321 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 6322 | free(cursection); |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 6323 | cursection = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6324 | fclose(f); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 6325 | return err_code; |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6326 | } |
| 6327 | |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6328 | /* |
| 6329 | * Returns the error code, 0 if OK, or any combination of : |
| 6330 | * - ERR_ABORT: must abort ASAP |
| 6331 | * - ERR_FATAL: we can continue parsing but not start the service |
| 6332 | * - ERR_WARN: a warning has been emitted |
| 6333 | * - ERR_ALERT: an alert has been emitted |
| 6334 | * Only the two first ones can stop processing, the two others are just |
| 6335 | * indicators. |
| 6336 | */ |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6337 | int check_config_validity() |
| 6338 | { |
| 6339 | int cfgerr = 0; |
| 6340 | struct proxy *curproxy = NULL; |
| 6341 | struct server *newsrv = NULL; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6342 | struct userlist *curuserlist = NULL; |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6343 | int err_code = 0; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6344 | unsigned int next_pxid = 1; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6345 | struct bind_conf *bind_conf; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6346 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6347 | bind_conf = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6348 | /* |
| 6349 | * Now, check for the integrity of all that we have collected. |
| 6350 | */ |
| 6351 | |
| 6352 | /* will be needed further to delay some tasks */ |
Willy Tarreau | b0b37bc | 2008-06-23 14:00:57 +0200 | [diff] [blame] | 6353 | tv_update_date(0,1); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6354 | |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 6355 | if (!global.tune.max_http_hdr) |
| 6356 | global.tune.max_http_hdr = MAX_HTTP_HDR; |
| 6357 | |
| 6358 | if (!global.tune.cookie_len) |
| 6359 | global.tune.cookie_len = CAPTURE_LEN; |
| 6360 | |
| 6361 | pool2_capture = create_pool("capture", global.tune.cookie_len, MEM_F_SHARED); |
| 6362 | |
Willy Tarreau | 55bc0f8 | 2009-03-15 14:51:53 +0100 | [diff] [blame] | 6363 | /* first, we will invert the proxy list order */ |
| 6364 | curproxy = NULL; |
| 6365 | while (proxy) { |
| 6366 | struct proxy *next; |
| 6367 | |
| 6368 | next = proxy->next; |
| 6369 | proxy->next = curproxy; |
| 6370 | curproxy = proxy; |
| 6371 | if (!next) |
| 6372 | break; |
| 6373 | proxy = next; |
| 6374 | } |
| 6375 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6376 | while (curproxy != NULL) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6377 | struct switching_rule *rule; |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 6378 | struct server_rule *srule; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6379 | struct sticking_rule *mrule; |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 6380 | struct tcp_rule *trule; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 6381 | struct listener *listener; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6382 | unsigned int next_id; |
Willy Tarreau | 16a2147 | 2012-11-19 12:39:59 +0100 | [diff] [blame] | 6383 | int nbproc; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6384 | |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 6385 | if (curproxy->uuid < 0) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6386 | /* proxy ID not set, use automatic numbering with first |
| 6387 | * spare entry starting with next_pxid. |
| 6388 | */ |
| 6389 | next_pxid = get_next_id(&used_proxy_id, next_pxid); |
| 6390 | curproxy->conf.id.key = curproxy->uuid = next_pxid; |
| 6391 | eb32_insert(&used_proxy_id, &curproxy->conf.id); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6392 | } |
Krzysztof Piotr Oledzki | df5cb9f | 2010-02-05 20:58:27 +0100 | [diff] [blame] | 6393 | next_pxid++; |
| 6394 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6395 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6396 | if (curproxy->state == PR_STSTOPPED) { |
Willy Tarreau | da250db | 2008-10-12 12:07:48 +0200 | [diff] [blame] | 6397 | /* ensure we don't keep listeners uselessly bound */ |
| 6398 | stop_proxy(curproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6399 | curproxy = curproxy->next; |
| 6400 | continue; |
| 6401 | } |
| 6402 | |
Willy Tarreau | 16a2147 | 2012-11-19 12:39:59 +0100 | [diff] [blame] | 6403 | /* number of processes this proxy is bound to */ |
| 6404 | nbproc = curproxy->bind_proc ? popcount(curproxy->bind_proc) : global.nbproc; |
| 6405 | |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 6406 | switch (curproxy->mode) { |
| 6407 | case PR_MODE_HEALTH: |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6408 | cfgerr += proxy_cfg_ensure_no_http(curproxy); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 6409 | if (!(curproxy->cap & PR_CAP_FE)) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6410 | Alert("config : %s '%s' cannot be in health mode as it has no frontend capability.\n", |
| 6411 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 6412 | cfgerr++; |
| 6413 | } |
| 6414 | |
| 6415 | if (curproxy->srv != NULL) |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6416 | Warning("config : servers will be ignored for %s '%s'.\n", |
| 6417 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 6418 | break; |
| 6419 | |
| 6420 | case PR_MODE_TCP: |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6421 | cfgerr += proxy_cfg_ensure_no_http(curproxy); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 6422 | break; |
| 6423 | |
| 6424 | case PR_MODE_HTTP: |
Willy Tarreau | 25320b2 | 2013-03-24 07:22:08 +0100 | [diff] [blame] | 6425 | curproxy->http_needed = 1; |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 6426 | break; |
| 6427 | } |
| 6428 | |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 6429 | if ((curproxy->cap & PR_CAP_BE) && (curproxy->mode != PR_MODE_HEALTH)) { |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6430 | if (curproxy->lbprm.algo & BE_LB_KIND) { |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 6431 | if (curproxy->options & PR_O_TRANSP) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6432 | Alert("config : %s '%s' cannot use both transparent and balance mode.\n", |
| 6433 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 6434 | cfgerr++; |
| 6435 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6436 | #ifdef WE_DONT_SUPPORT_SERVERLESS_LISTENERS |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 6437 | else if (curproxy->srv == NULL) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6438 | Alert("config : %s '%s' needs at least 1 server in balance mode.\n", |
| 6439 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 6440 | cfgerr++; |
| 6441 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6442 | #endif |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 6443 | else if (curproxy->options & PR_O_DISPATCH) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6444 | Warning("config : dispatch address of %s '%s' will be ignored in balance mode.\n", |
| 6445 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6446 | err_code |= ERR_WARN; |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 6447 | } |
| 6448 | } |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 6449 | 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] | 6450 | /* If no LB algo is set in a backend, and we're not in |
| 6451 | * transparent mode, dispatch mode nor proxy mode, we |
| 6452 | * want to use balance roundrobin by default. |
| 6453 | */ |
| 6454 | curproxy->lbprm.algo &= ~BE_LB_ALGO; |
| 6455 | curproxy->lbprm.algo |= BE_LB_ALGO_RR; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6456 | } |
| 6457 | } |
Willy Tarreau | 193cf93 | 2007-09-17 10:17:23 +0200 | [diff] [blame] | 6458 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 6459 | if (curproxy->options & PR_O_DISPATCH) |
| 6460 | curproxy->options &= ~(PR_O_TRANSP | PR_O_HTTP_PROXY); |
| 6461 | else if (curproxy->options & PR_O_HTTP_PROXY) |
| 6462 | curproxy->options &= ~(PR_O_DISPATCH | PR_O_TRANSP); |
| 6463 | else if (curproxy->options & PR_O_TRANSP) |
| 6464 | curproxy->options &= ~(PR_O_DISPATCH | PR_O_HTTP_PROXY); |
Willy Tarreau | 8293658 | 2007-11-30 15:20:09 +0100 | [diff] [blame] | 6465 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 6466 | if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_HTTP_CHK) { |
| 6467 | if (curproxy->options & PR_O_DISABLE404) { |
| 6468 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n", |
| 6469 | "disable-on-404", proxy_type_str(curproxy), curproxy->id); |
| 6470 | err_code |= ERR_WARN; |
| 6471 | curproxy->options &= ~PR_O_DISABLE404; |
| 6472 | } |
| 6473 | if (curproxy->options2 & PR_O2_CHK_SNDST) { |
| 6474 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n", |
| 6475 | "send-state", proxy_type_str(curproxy), curproxy->id); |
| 6476 | err_code |= ERR_WARN; |
| 6477 | curproxy->options &= ~PR_O2_CHK_SNDST; |
| 6478 | } |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 6479 | } |
| 6480 | |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 6481 | /* if a default backend was specified, let's find it */ |
| 6482 | if (curproxy->defbe.name) { |
| 6483 | struct proxy *target; |
| 6484 | |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 6485 | target = findproxy_mode(curproxy->defbe.name, curproxy->mode, PR_CAP_BE); |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6486 | if (!target) { |
| 6487 | Alert("Proxy '%s': unable to find required default_backend: '%s'.\n", |
| 6488 | curproxy->id, curproxy->defbe.name); |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 6489 | cfgerr++; |
| 6490 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6491 | Alert("Proxy '%s': loop detected for default_backend: '%s'.\n", |
| 6492 | curproxy->id, curproxy->defbe.name); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6493 | cfgerr++; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 6494 | } else { |
| 6495 | free(curproxy->defbe.name); |
| 6496 | curproxy->defbe.be = target; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 6497 | /* we force the backend to be present on at least all of |
| 6498 | * the frontend's processes. |
| 6499 | */ |
| 6500 | target->bind_proc = curproxy->bind_proc ? |
| 6501 | (target->bind_proc | curproxy->bind_proc) : 0; |
Willy Tarreau | ff67813 | 2012-02-13 14:32:34 +0100 | [diff] [blame] | 6502 | |
| 6503 | /* Emit a warning if this proxy also has some servers */ |
| 6504 | if (curproxy->srv) { |
| 6505 | Warning("In proxy '%s', the 'default_backend' rule always has precedence over the servers, which will never be used.\n", |
| 6506 | curproxy->id); |
| 6507 | err_code |= ERR_WARN; |
| 6508 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6509 | } |
| 6510 | } |
| 6511 | |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 6512 | /* find the target proxy in setbe */ |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 6513 | if (curproxy->mode == PR_MODE_HTTP && curproxy->req_exp != NULL) { |
| 6514 | /* map jump target for ACT_SETBE in req_rep chain */ |
| 6515 | struct hdr_exp *exp; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 6516 | for (exp = curproxy->req_exp; exp != NULL; exp = exp->next) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6517 | struct proxy *target; |
| 6518 | |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 6519 | if (exp->action != ACT_SETBE) |
| 6520 | continue; |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6521 | |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 6522 | target = findproxy_mode(exp->replace, PR_MODE_HTTP, PR_CAP_BE); |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6523 | if (!target) { |
| 6524 | Alert("Proxy '%s': unable to find required setbe: '%s'.\n", |
| 6525 | curproxy->id, exp->replace); |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 6526 | cfgerr++; |
| 6527 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6528 | Alert("Proxy '%s': loop detected for setbe: '%s'.\n", |
| 6529 | curproxy->id, exp->replace); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 6530 | cfgerr++; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 6531 | } else { |
| 6532 | free((void *)exp->replace); |
| 6533 | exp->replace = (const char *)target; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 6534 | /* we force the backend to be present on at least all of |
| 6535 | * the frontend's processes. |
| 6536 | */ |
| 6537 | target->bind_proc = curproxy->bind_proc ? |
| 6538 | (target->bind_proc | curproxy->bind_proc) : 0; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 6539 | } |
| 6540 | } |
| 6541 | } |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6542 | |
| 6543 | /* find the target proxy for 'use_backend' rules */ |
| 6544 | list_for_each_entry(rule, &curproxy->switching_rules, list) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6545 | struct proxy *target; |
| 6546 | |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 6547 | target = findproxy_mode(rule->be.name, curproxy->mode, PR_CAP_BE); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6548 | |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6549 | if (!target) { |
| 6550 | Alert("Proxy '%s': unable to find required use_backend: '%s'.\n", |
| 6551 | curproxy->id, rule->be.name); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6552 | cfgerr++; |
| 6553 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6554 | Alert("Proxy '%s': loop detected for use_backend: '%s'.\n", |
| 6555 | curproxy->id, rule->be.name); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6556 | cfgerr++; |
| 6557 | } else { |
| 6558 | free((void *)rule->be.name); |
| 6559 | rule->be.backend = target; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 6560 | /* we force the backend to be present on at least all of |
| 6561 | * the frontend's processes. |
| 6562 | */ |
| 6563 | target->bind_proc = curproxy->bind_proc ? |
| 6564 | (target->bind_proc | curproxy->bind_proc) : 0; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6565 | } |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 6566 | } |
| 6567 | |
| 6568 | /* find the target proxy for 'use_backend' rules */ |
| 6569 | list_for_each_entry(srule, &curproxy->server_rules, list) { |
| 6570 | struct server *target = findserver(curproxy, srule->srv.name); |
| 6571 | |
| 6572 | if (!target) { |
| 6573 | Alert("config : %s '%s' : unable to find server '%s' referenced in a 'use-server' rule.\n", |
| 6574 | proxy_type_str(curproxy), curproxy->id, srule->srv.name); |
| 6575 | cfgerr++; |
| 6576 | continue; |
| 6577 | } |
| 6578 | free((void *)srule->srv.name); |
| 6579 | srule->srv.ptr = target; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6580 | } |
| 6581 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6582 | /* find the target table for 'stick' rules */ |
| 6583 | list_for_each_entry(mrule, &curproxy->sticking_rules, list) { |
| 6584 | struct proxy *target; |
| 6585 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 6586 | curproxy->be_req_ana |= AN_REQ_STICKING_RULES; |
| 6587 | if (mrule->flags & STK_IS_STORE) |
| 6588 | curproxy->be_rsp_ana |= AN_RES_STORE_RULES; |
| 6589 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6590 | if (mrule->table.name) |
Willy Tarreau | c00cdc2 | 2010-06-06 16:48:26 +0200 | [diff] [blame] | 6591 | target = findproxy(mrule->table.name, 0); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6592 | else |
| 6593 | target = curproxy; |
| 6594 | |
| 6595 | if (!target) { |
| 6596 | Alert("Proxy '%s': unable to find stick-table '%s'.\n", |
| 6597 | curproxy->id, mrule->table.name); |
| 6598 | cfgerr++; |
| 6599 | } |
| 6600 | else if (target->table.size == 0) { |
| 6601 | Alert("Proxy '%s': stick-table '%s' used but not configured.\n", |
| 6602 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 6603 | cfgerr++; |
| 6604 | } |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 6605 | else if (!stktable_compatible_sample(mrule->expr, target->table.type)) { |
| 6606 | 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] | 6607 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 6608 | cfgerr++; |
| 6609 | } |
| 6610 | else { |
| 6611 | free((void *)mrule->table.name); |
| 6612 | mrule->table.t = &(target->table); |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 6613 | stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID, NULL); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6614 | } |
| 6615 | } |
| 6616 | |
| 6617 | /* find the target table for 'store response' rules */ |
| 6618 | list_for_each_entry(mrule, &curproxy->storersp_rules, list) { |
| 6619 | struct proxy *target; |
| 6620 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 6621 | curproxy->be_rsp_ana |= AN_RES_STORE_RULES; |
| 6622 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6623 | if (mrule->table.name) |
Willy Tarreau | c00cdc2 | 2010-06-06 16:48:26 +0200 | [diff] [blame] | 6624 | target = findproxy(mrule->table.name, 0); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6625 | else |
| 6626 | target = curproxy; |
| 6627 | |
| 6628 | if (!target) { |
| 6629 | Alert("Proxy '%s': unable to find store table '%s'.\n", |
| 6630 | curproxy->id, mrule->table.name); |
| 6631 | cfgerr++; |
| 6632 | } |
| 6633 | else if (target->table.size == 0) { |
| 6634 | Alert("Proxy '%s': stick-table '%s' used but not configured.\n", |
| 6635 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 6636 | cfgerr++; |
| 6637 | } |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 6638 | else if (!stktable_compatible_sample(mrule->expr, target->table.type)) { |
| 6639 | 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] | 6640 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 6641 | cfgerr++; |
| 6642 | } |
| 6643 | else { |
| 6644 | free((void *)mrule->table.name); |
| 6645 | mrule->table.t = &(target->table); |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 6646 | stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID, NULL); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6647 | } |
| 6648 | } |
| 6649 | |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 6650 | /* find the target table for 'tcp-request' layer 4 rules */ |
| 6651 | list_for_each_entry(trule, &curproxy->tcp_req.l4_rules, list) { |
| 6652 | struct proxy *target; |
| 6653 | |
Willy Tarreau | b4c8493 | 2013-07-23 19:15:30 +0200 | [diff] [blame] | 6654 | if (trule->action < TCP_ACT_TRK_SC0 || trule->action > TCP_ACT_TRK_SCMAX) |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 6655 | continue; |
| 6656 | |
| 6657 | if (trule->act_prm.trk_ctr.table.n) |
| 6658 | target = findproxy(trule->act_prm.trk_ctr.table.n, 0); |
| 6659 | else |
| 6660 | target = curproxy; |
| 6661 | |
| 6662 | if (!target) { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6663 | Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n", |
| 6664 | curproxy->id, trule->act_prm.trk_ctr.table.n, |
Willy Tarreau | 34c2fb6 | 2013-12-02 23:29:05 +0100 | [diff] [blame] | 6665 | tcp_trk_idx(trule->action)); |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 6666 | cfgerr++; |
| 6667 | } |
| 6668 | else if (target->table.size == 0) { |
| 6669 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
| 6670 | curproxy->id, trule->act_prm.trk_ctr.table.n ? trule->act_prm.trk_ctr.table.n : curproxy->id); |
| 6671 | cfgerr++; |
| 6672 | } |
Willy Tarreau | 5f53de7 | 2012-12-12 00:25:44 +0100 | [diff] [blame] | 6673 | else if (!stktable_compatible_sample(trule->act_prm.trk_ctr.expr, target->table.type)) { |
| 6674 | Alert("Proxy '%s': stick-table '%s' uses a type incompatible with the 'track-sc%d' rule.\n", |
| 6675 | curproxy->id, trule->act_prm.trk_ctr.table.n ? trule->act_prm.trk_ctr.table.n : curproxy->id, |
Willy Tarreau | 34c2fb6 | 2013-12-02 23:29:05 +0100 | [diff] [blame] | 6676 | tcp_trk_idx(trule->action)); |
Willy Tarreau | 5f53de7 | 2012-12-12 00:25:44 +0100 | [diff] [blame] | 6677 | cfgerr++; |
| 6678 | } |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 6679 | else { |
| 6680 | free(trule->act_prm.trk_ctr.table.n); |
| 6681 | trule->act_prm.trk_ctr.table.t = &target->table; |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6682 | /* 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] | 6683 | * to pass a list of counters to track and allocate them right here using |
| 6684 | * stktable_alloc_data_type(). |
| 6685 | */ |
| 6686 | } |
| 6687 | } |
| 6688 | |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 6689 | /* find the target table for 'tcp-request' layer 6 rules */ |
| 6690 | list_for_each_entry(trule, &curproxy->tcp_req.inspect_rules, list) { |
| 6691 | struct proxy *target; |
| 6692 | |
Willy Tarreau | b4c8493 | 2013-07-23 19:15:30 +0200 | [diff] [blame] | 6693 | if (trule->action < TCP_ACT_TRK_SC0 || trule->action > TCP_ACT_TRK_SCMAX) |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 6694 | continue; |
| 6695 | |
| 6696 | if (trule->act_prm.trk_ctr.table.n) |
| 6697 | target = findproxy(trule->act_prm.trk_ctr.table.n, 0); |
| 6698 | else |
| 6699 | target = curproxy; |
| 6700 | |
| 6701 | if (!target) { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6702 | Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n", |
| 6703 | curproxy->id, trule->act_prm.trk_ctr.table.n, |
Willy Tarreau | 34c2fb6 | 2013-12-02 23:29:05 +0100 | [diff] [blame] | 6704 | tcp_trk_idx(trule->action)); |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 6705 | cfgerr++; |
| 6706 | } |
| 6707 | else if (target->table.size == 0) { |
| 6708 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
| 6709 | curproxy->id, trule->act_prm.trk_ctr.table.n ? trule->act_prm.trk_ctr.table.n : curproxy->id); |
| 6710 | cfgerr++; |
| 6711 | } |
Willy Tarreau | 5f53de7 | 2012-12-12 00:25:44 +0100 | [diff] [blame] | 6712 | else if (!stktable_compatible_sample(trule->act_prm.trk_ctr.expr, target->table.type)) { |
| 6713 | Alert("Proxy '%s': stick-table '%s' uses a type incompatible with the 'track-sc%d' rule.\n", |
| 6714 | curproxy->id, trule->act_prm.trk_ctr.table.n ? trule->act_prm.trk_ctr.table.n : curproxy->id, |
Willy Tarreau | 34c2fb6 | 2013-12-02 23:29:05 +0100 | [diff] [blame] | 6715 | tcp_trk_idx(trule->action)); |
Willy Tarreau | 5f53de7 | 2012-12-12 00:25:44 +0100 | [diff] [blame] | 6716 | cfgerr++; |
| 6717 | } |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 6718 | else { |
| 6719 | free(trule->act_prm.trk_ctr.table.n); |
| 6720 | trule->act_prm.trk_ctr.table.t = &target->table; |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6721 | /* 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] | 6722 | * to pass a list of counters to track and allocate them right here using |
| 6723 | * stktable_alloc_data_type(). |
| 6724 | */ |
| 6725 | } |
| 6726 | } |
| 6727 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 6728 | if (curproxy->table.peers.name) { |
| 6729 | struct peers *curpeers = peers; |
| 6730 | |
| 6731 | for (curpeers = peers; curpeers; curpeers = curpeers->next) { |
| 6732 | if (strcmp(curpeers->id, curproxy->table.peers.name) == 0) { |
| 6733 | free((void *)curproxy->table.peers.name); |
Willy Tarreau | 973ca49 | 2013-01-17 21:34:52 +0100 | [diff] [blame] | 6734 | curproxy->table.peers.p = curpeers; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 6735 | break; |
| 6736 | } |
| 6737 | } |
| 6738 | |
| 6739 | if (!curpeers) { |
| 6740 | Alert("Proxy '%s': unable to find sync peers '%s'.\n", |
| 6741 | curproxy->id, curproxy->table.peers.name); |
Willy Tarreau | d66bf96 | 2011-10-28 14:16:49 +0200 | [diff] [blame] | 6742 | free((void *)curproxy->table.peers.name); |
| 6743 | curproxy->table.peers.p = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 6744 | cfgerr++; |
| 6745 | } |
| 6746 | else if (!curpeers->peers_fe) { |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 6747 | Alert("Proxy '%s': unable to find local peer '%s' in peers section '%s'.\n", |
| 6748 | curproxy->id, localpeer, curpeers->id); |
Willy Tarreau | d66bf96 | 2011-10-28 14:16:49 +0200 | [diff] [blame] | 6749 | curproxy->table.peers.p = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 6750 | cfgerr++; |
| 6751 | } |
| 6752 | } |
| 6753 | |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 6754 | if (curproxy->uri_auth && !(curproxy->uri_auth->flags & ST_CONVDONE) && |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 6755 | !LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) && |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6756 | (curproxy->uri_auth->userlist || curproxy->uri_auth->auth_realm )) { |
| 6757 | Alert("%s '%s': stats 'auth'/'realm' and 'http-request' can't be used at the same time.\n", |
| 6758 | "proxy", curproxy->id); |
| 6759 | cfgerr++; |
| 6760 | goto out_uri_auth_compat; |
| 6761 | } |
| 6762 | |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 6763 | 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] | 6764 | const char *uri_auth_compat_req[10]; |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 6765 | struct http_req_rule *rule; |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6766 | int i = 0; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6767 | |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6768 | /* build the ACL condition from scratch. We're relying on anonymous ACLs for that */ |
| 6769 | uri_auth_compat_req[i++] = "auth"; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6770 | |
| 6771 | if (curproxy->uri_auth->auth_realm) { |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6772 | uri_auth_compat_req[i++] = "realm"; |
| 6773 | uri_auth_compat_req[i++] = curproxy->uri_auth->auth_realm; |
| 6774 | } |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6775 | |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6776 | uri_auth_compat_req[i++] = "unless"; |
| 6777 | uri_auth_compat_req[i++] = "{"; |
| 6778 | uri_auth_compat_req[i++] = "http_auth(.internal-stats-userlist)"; |
| 6779 | uri_auth_compat_req[i++] = "}"; |
| 6780 | uri_auth_compat_req[i++] = ""; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6781 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 6782 | rule = parse_http_req_cond(uri_auth_compat_req, "internal-stats-auth-compat", 0, curproxy); |
| 6783 | if (!rule) { |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6784 | cfgerr++; |
| 6785 | break; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6786 | } |
| 6787 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 6788 | LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list); |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6789 | |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6790 | if (curproxy->uri_auth->auth_realm) { |
| 6791 | free(curproxy->uri_auth->auth_realm); |
| 6792 | curproxy->uri_auth->auth_realm = NULL; |
| 6793 | } |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 6794 | |
| 6795 | curproxy->uri_auth->flags |= ST_CONVDONE; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6796 | } |
| 6797 | out_uri_auth_compat: |
| 6798 | |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 6799 | /* compile the log format */ |
| 6800 | if (!(curproxy->cap & PR_CAP_FE)) { |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 6801 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 6802 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 6803 | curproxy->conf.logformat_string != clf_http_log_format) |
| 6804 | free(curproxy->conf.logformat_string); |
| 6805 | curproxy->conf.logformat_string = NULL; |
| 6806 | free(curproxy->conf.lfs_file); |
| 6807 | curproxy->conf.lfs_file = NULL; |
| 6808 | curproxy->conf.lfs_line = 0; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 6809 | } |
| 6810 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 6811 | if (curproxy->conf.logformat_string) { |
| 6812 | curproxy->conf.args.ctx = ARGC_LOG; |
| 6813 | curproxy->conf.args.file = curproxy->conf.lfs_file; |
| 6814 | curproxy->conf.args.line = curproxy->conf.lfs_line; |
| 6815 | parse_logformat_string(curproxy->conf.logformat_string, curproxy, &curproxy->logformat, LOG_OPT_MANDATORY, |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 6816 | SMP_VAL_FE_LOG_END); |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 6817 | curproxy->conf.args.file = NULL; |
| 6818 | curproxy->conf.args.line = 0; |
| 6819 | } |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 6820 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 6821 | if (curproxy->conf.uniqueid_format_string) { |
| 6822 | curproxy->conf.args.ctx = ARGC_UIF; |
| 6823 | curproxy->conf.args.file = curproxy->conf.uif_file; |
| 6824 | curproxy->conf.args.line = curproxy->conf.uif_line; |
| 6825 | parse_logformat_string(curproxy->conf.uniqueid_format_string, curproxy, &curproxy->format_unique_id, 0, |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 6826 | (proxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR); |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 6827 | curproxy->conf.args.file = NULL; |
| 6828 | curproxy->conf.args.line = 0; |
| 6829 | } |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 6830 | |
| 6831 | /* only now we can check if some args remain unresolved */ |
| 6832 | cfgerr += smp_resolve_args(curproxy); |
| 6833 | if (!cfgerr) |
| 6834 | cfgerr += acl_find_targets(curproxy); |
Krzysztof Piotr Oledzki | f9423ae | 2010-01-29 19:26:18 +0100 | [diff] [blame] | 6835 | |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 6836 | if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) && |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6837 | (((curproxy->cap & PR_CAP_FE) && !curproxy->timeout.client) || |
Willy Tarreau | d825eef | 2007-05-12 22:35:00 +0200 | [diff] [blame] | 6838 | ((curproxy->cap & PR_CAP_BE) && (curproxy->srv) && |
Willy Tarreau | ce887fd | 2012-05-12 12:50:00 +0200 | [diff] [blame] | 6839 | (!curproxy->timeout.connect || |
| 6840 | (!curproxy->timeout.server && (curproxy->mode == PR_MODE_HTTP || !curproxy->timeout.tunnel)))))) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6841 | Warning("config : missing timeouts for %s '%s'.\n" |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 6842 | " | While not properly invalid, you will certainly encounter various problems\n" |
| 6843 | " | 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] | 6844 | " | timeouts are set to a non-zero value: 'client', 'connect', 'server'.\n", |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6845 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6846 | err_code |= ERR_WARN; |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 6847 | } |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 6848 | |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6849 | /* Historically, the tarpit and queue timeouts were inherited from contimeout. |
| 6850 | * We must still support older configurations, so let's find out whether those |
| 6851 | * parameters have been set or must be copied from contimeouts. |
| 6852 | */ |
| 6853 | if (curproxy != &defproxy) { |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6854 | if (!curproxy->timeout.tarpit || |
| 6855 | curproxy->timeout.tarpit == defproxy.timeout.tarpit) { |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6856 | /* tarpit timeout not set. We search in the following order: |
| 6857 | * default.tarpit, curr.connect, default.connect. |
| 6858 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6859 | if (defproxy.timeout.tarpit) |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6860 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6861 | else if (curproxy->timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6862 | curproxy->timeout.tarpit = curproxy->timeout.connect; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6863 | else if (defproxy.timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6864 | curproxy->timeout.tarpit = defproxy.timeout.connect; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6865 | } |
| 6866 | if ((curproxy->cap & PR_CAP_BE) && |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6867 | (!curproxy->timeout.queue || |
| 6868 | curproxy->timeout.queue == defproxy.timeout.queue)) { |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6869 | /* queue timeout not set. We search in the following order: |
| 6870 | * default.queue, curr.connect, default.connect. |
| 6871 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6872 | if (defproxy.timeout.queue) |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6873 | curproxy->timeout.queue = defproxy.timeout.queue; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6874 | else if (curproxy->timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6875 | curproxy->timeout.queue = curproxy->timeout.connect; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6876 | else if (defproxy.timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6877 | curproxy->timeout.queue = defproxy.timeout.connect; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6878 | } |
| 6879 | } |
| 6880 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 6881 | if ((curproxy->options2 & PR_O2_CHK_ANY) == PR_O2_SSL3_CHK) { |
Willy Tarreau | 137325d | 2010-02-01 16:38:17 +0100 | [diff] [blame] | 6882 | curproxy->check_len = sizeof(sslv3_client_hello_pkt) - 1; |
| 6883 | curproxy->check_req = (char *)malloc(curproxy->check_len); |
| 6884 | memcpy(curproxy->check_req, sslv3_client_hello_pkt, curproxy->check_len); |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 6885 | } |
| 6886 | |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 6887 | /* ensure that cookie capture length is not too large */ |
| 6888 | if (curproxy->capture_len >= global.tune.cookie_len) { |
| 6889 | Warning("config : truncating capture length to %d bytes for %s '%s'.\n", |
| 6890 | global.tune.cookie_len - 1, proxy_type_str(curproxy), curproxy->id); |
| 6891 | err_code |= ERR_WARN; |
| 6892 | curproxy->capture_len = global.tune.cookie_len - 1; |
| 6893 | } |
| 6894 | |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 6895 | /* The small pools required for the capture lists */ |
Willy Tarreau | 9a54e13 | 2012-03-24 08:33:05 +0100 | [diff] [blame] | 6896 | if (curproxy->nb_req_cap) { |
| 6897 | if (curproxy->mode == PR_MODE_HTTP) { |
| 6898 | curproxy->req_cap_pool = create_pool("ptrcap", |
| 6899 | curproxy->nb_req_cap * sizeof(char *), |
| 6900 | MEM_F_SHARED); |
| 6901 | } else { |
| 6902 | Warning("config : 'capture request header' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6903 | proxy_type_str(curproxy), curproxy->id); |
| 6904 | err_code |= ERR_WARN; |
| 6905 | curproxy->to_log &= ~LW_REQHDR; |
| 6906 | curproxy->nb_req_cap = 0; |
| 6907 | } |
| 6908 | } |
| 6909 | |
| 6910 | if (curproxy->nb_rsp_cap) { |
| 6911 | if (curproxy->mode == PR_MODE_HTTP) { |
| 6912 | curproxy->rsp_cap_pool = create_pool("ptrcap", |
| 6913 | curproxy->nb_rsp_cap * sizeof(char *), |
| 6914 | MEM_F_SHARED); |
| 6915 | } else { |
| 6916 | Warning("config : 'capture response header' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6917 | proxy_type_str(curproxy), curproxy->id); |
| 6918 | err_code |= ERR_WARN; |
| 6919 | curproxy->to_log &= ~LW_REQHDR; |
| 6920 | curproxy->nb_rsp_cap = 0; |
| 6921 | } |
| 6922 | } |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 6923 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6924 | /* first, we will invert the servers list order */ |
| 6925 | newsrv = NULL; |
| 6926 | while (curproxy->srv) { |
| 6927 | struct server *next; |
| 6928 | |
| 6929 | next = curproxy->srv->next; |
| 6930 | curproxy->srv->next = newsrv; |
| 6931 | newsrv = curproxy->srv; |
| 6932 | if (!next) |
| 6933 | break; |
| 6934 | curproxy->srv = next; |
| 6935 | } |
| 6936 | |
Willy Tarreau | dd70165 | 2010-05-25 23:03:02 +0200 | [diff] [blame] | 6937 | /* assign automatic UIDs to servers which don't have one yet */ |
| 6938 | next_id = 1; |
| 6939 | newsrv = curproxy->srv; |
| 6940 | while (newsrv != NULL) { |
| 6941 | if (!newsrv->puid) { |
| 6942 | /* server ID not set, use automatic numbering with first |
| 6943 | * spare entry starting with next_svid. |
| 6944 | */ |
| 6945 | next_id = get_next_id(&curproxy->conf.used_server_id, next_id); |
| 6946 | newsrv->conf.id.key = newsrv->puid = next_id; |
| 6947 | eb32_insert(&curproxy->conf.used_server_id, &newsrv->conf.id); |
| 6948 | } |
| 6949 | next_id++; |
| 6950 | newsrv = newsrv->next; |
| 6951 | } |
| 6952 | |
Willy Tarreau | 2069704 | 2007-11-15 23:26:18 +0100 | [diff] [blame] | 6953 | curproxy->lbprm.wmult = 1; /* default weight multiplier */ |
Willy Tarreau | 5dc2fa6 | 2007-11-19 19:10:18 +0100 | [diff] [blame] | 6954 | curproxy->lbprm.wdiv = 1; /* default weight divider */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6955 | |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 6956 | /* |
| 6957 | * If this server supports a maxconn parameter, it needs a dedicated |
| 6958 | * tasks to fill the emptied slots when a connection leaves. |
| 6959 | * Also, resolve deferred tracking dependency if needed. |
| 6960 | */ |
| 6961 | newsrv = curproxy->srv; |
| 6962 | while (newsrv != NULL) { |
| 6963 | if (newsrv->minconn > newsrv->maxconn) { |
| 6964 | /* Only 'minconn' was specified, or it was higher than or equal |
| 6965 | * to 'maxconn'. Let's turn this into maxconn and clean it, as |
| 6966 | * this will avoid further useless expensive computations. |
| 6967 | */ |
| 6968 | newsrv->maxconn = newsrv->minconn; |
| 6969 | } else if (newsrv->maxconn && !newsrv->minconn) { |
| 6970 | /* minconn was not specified, so we set it to maxconn */ |
| 6971 | newsrv->minconn = newsrv->maxconn; |
| 6972 | } |
| 6973 | |
Emeric Brun | 01f8e2f | 2012-05-18 16:02:00 +0200 | [diff] [blame] | 6974 | #ifdef USE_OPENSSL |
Emeric Brun | 94324a4 | 2012-10-11 14:00:19 +0200 | [diff] [blame] | 6975 | if (newsrv->use_ssl || newsrv->check.use_ssl) |
| 6976 | cfgerr += ssl_sock_prepare_srv_ctx(newsrv, curproxy); |
Emeric Brun | 01f8e2f | 2012-05-18 16:02:00 +0200 | [diff] [blame] | 6977 | #endif /* USE_OPENSSL */ |
Emeric Brun | 94324a4 | 2012-10-11 14:00:19 +0200 | [diff] [blame] | 6978 | |
Willy Tarreau | 2f075e9 | 2013-12-03 11:11:34 +0100 | [diff] [blame] | 6979 | /* set the check type on the server */ |
| 6980 | newsrv->check.type = curproxy->options2 & PR_O2_CHK_ANY; |
| 6981 | |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 6982 | if (newsrv->trackit) { |
| 6983 | struct proxy *px; |
| 6984 | struct server *srv; |
| 6985 | char *pname, *sname; |
| 6986 | |
| 6987 | pname = newsrv->trackit; |
| 6988 | sname = strrchr(pname, '/'); |
| 6989 | |
| 6990 | if (sname) |
| 6991 | *sname++ = '\0'; |
| 6992 | else { |
| 6993 | sname = pname; |
| 6994 | pname = NULL; |
| 6995 | } |
| 6996 | |
| 6997 | if (pname) { |
| 6998 | px = findproxy(pname, PR_CAP_BE); |
| 6999 | if (!px) { |
| 7000 | Alert("config : %s '%s', server '%s': unable to find required proxy '%s' for tracking.\n", |
| 7001 | proxy_type_str(curproxy), curproxy->id, |
| 7002 | newsrv->id, pname); |
| 7003 | cfgerr++; |
| 7004 | goto next_srv; |
| 7005 | } |
| 7006 | } else |
| 7007 | px = curproxy; |
| 7008 | |
| 7009 | srv = findserver(px, sname); |
| 7010 | if (!srv) { |
| 7011 | Alert("config : %s '%s', server '%s': unable to find required server '%s' for tracking.\n", |
| 7012 | proxy_type_str(curproxy), curproxy->id, |
| 7013 | newsrv->id, sname); |
| 7014 | cfgerr++; |
| 7015 | goto next_srv; |
| 7016 | } |
| 7017 | |
| 7018 | if (!(srv->state & SRV_CHECKED)) { |
| 7019 | Alert("config : %s '%s', server '%s': unable to use %s/%s for " |
| 7020 | "tracking as it does not have checks enabled.\n", |
| 7021 | proxy_type_str(curproxy), curproxy->id, |
| 7022 | newsrv->id, px->id, srv->id); |
| 7023 | cfgerr++; |
| 7024 | goto next_srv; |
| 7025 | } |
| 7026 | |
| 7027 | if (curproxy != px && |
| 7028 | (curproxy->options & PR_O_DISABLE404) != (px->options & PR_O_DISABLE404)) { |
| 7029 | Alert("config : %s '%s', server '%s': unable to use %s/%s for" |
| 7030 | "tracking: disable-on-404 option inconsistency.\n", |
| 7031 | proxy_type_str(curproxy), curproxy->id, |
| 7032 | newsrv->id, px->id, srv->id); |
| 7033 | cfgerr++; |
| 7034 | goto next_srv; |
| 7035 | } |
| 7036 | |
| 7037 | /* if the other server is forced disabled, we have to do the same here */ |
| 7038 | if (srv->state & SRV_MAINTAIN) { |
| 7039 | newsrv->state |= SRV_MAINTAIN; |
| 7040 | newsrv->state &= ~SRV_RUNNING; |
Simon Horman | 125d099 | 2013-02-24 17:23:38 +0900 | [diff] [blame] | 7041 | newsrv->check.health = 0; |
Simon Horman | d60d691 | 2013-11-25 10:46:36 +0900 | [diff] [blame] | 7042 | newsrv->agent.health = 0; |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 7043 | } |
| 7044 | |
| 7045 | newsrv->track = srv; |
| 7046 | newsrv->tracknext = srv->tracknext; |
| 7047 | srv->tracknext = newsrv; |
| 7048 | |
| 7049 | free(newsrv->trackit); |
| 7050 | newsrv->trackit = NULL; |
| 7051 | } |
| 7052 | next_srv: |
| 7053 | newsrv = newsrv->next; |
| 7054 | } |
| 7055 | |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 7056 | /* We have to initialize the server lookup mechanism depending |
| 7057 | * on what LB algorithm was choosen. |
| 7058 | */ |
| 7059 | |
| 7060 | curproxy->lbprm.algo &= ~(BE_LB_LKUP | BE_LB_PROP_DYN); |
| 7061 | switch (curproxy->lbprm.algo & BE_LB_KIND) { |
| 7062 | case BE_LB_KIND_RR: |
Willy Tarreau | 9757a38 | 2009-10-03 12:56:50 +0200 | [diff] [blame] | 7063 | if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_RR_STATIC) { |
| 7064 | curproxy->lbprm.algo |= BE_LB_LKUP_MAP; |
| 7065 | init_server_map(curproxy); |
| 7066 | } else { |
| 7067 | curproxy->lbprm.algo |= BE_LB_LKUP_RRTREE | BE_LB_PROP_DYN; |
| 7068 | fwrr_init_server_groups(curproxy); |
| 7069 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 7070 | break; |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 7071 | |
Willy Tarreau | 3ebb116 | 2012-02-13 16:57:44 +0100 | [diff] [blame] | 7072 | case BE_LB_KIND_CB: |
Willy Tarreau | f09c660 | 2012-02-13 17:12:08 +0100 | [diff] [blame] | 7073 | if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_CB_LC) { |
| 7074 | curproxy->lbprm.algo |= BE_LB_LKUP_LCTREE | BE_LB_PROP_DYN; |
| 7075 | fwlc_init_server_tree(curproxy); |
| 7076 | } else { |
| 7077 | curproxy->lbprm.algo |= BE_LB_LKUP_FSTREE | BE_LB_PROP_DYN; |
| 7078 | fas_init_server_tree(curproxy); |
| 7079 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 7080 | break; |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 7081 | |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 7082 | case BE_LB_KIND_HI: |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 7083 | if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS) { |
| 7084 | curproxy->lbprm.algo |= BE_LB_LKUP_CHTREE | BE_LB_PROP_DYN; |
| 7085 | chash_init_server_tree(curproxy); |
| 7086 | } else { |
| 7087 | curproxy->lbprm.algo |= BE_LB_LKUP_MAP; |
| 7088 | init_server_map(curproxy); |
| 7089 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 7090 | break; |
| 7091 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7092 | |
| 7093 | if (curproxy->options & PR_O_LOGASAP) |
| 7094 | curproxy->to_log &= ~LW_BYTES; |
| 7095 | |
Willy Tarreau | e7ded1f | 2009-08-09 10:11:45 +0200 | [diff] [blame] | 7096 | if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) && |
Willy Tarreau | d79a3b2 | 2012-12-28 09:40:16 +0100 | [diff] [blame] | 7097 | (curproxy->cap & PR_CAP_FE) && !LIST_ISEMPTY(&curproxy->logformat) && LIST_ISEMPTY(&curproxy->logsrvs)) { |
Willy Tarreau | e7ded1f | 2009-08-09 10:11:45 +0200 | [diff] [blame] | 7098 | Warning("config : log format ignored for %s '%s' since it has no log address.\n", |
| 7099 | proxy_type_str(curproxy), curproxy->id); |
| 7100 | err_code |= ERR_WARN; |
| 7101 | } |
| 7102 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 7103 | if (curproxy->mode != PR_MODE_HTTP) { |
| 7104 | int optnum; |
| 7105 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 7106 | if (curproxy->uri_auth) { |
| 7107 | Warning("config : 'stats' statement ignored for %s '%s' as it requires HTTP mode.\n", |
| 7108 | proxy_type_str(curproxy), curproxy->id); |
| 7109 | err_code |= ERR_WARN; |
| 7110 | curproxy->uri_auth = NULL; |
| 7111 | } |
| 7112 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 7113 | if (curproxy->options & (PR_O_FWDFOR | PR_O_FF_ALWAYS)) { |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 7114 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 7115 | "forwardfor", proxy_type_str(curproxy), curproxy->id); |
| 7116 | err_code |= ERR_WARN; |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 7117 | curproxy->options &= ~(PR_O_FWDFOR | PR_O_FF_ALWAYS); |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 7118 | } |
| 7119 | |
| 7120 | if (curproxy->options & PR_O_ORGTO) { |
| 7121 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 7122 | "originalto", proxy_type_str(curproxy), curproxy->id); |
| 7123 | err_code |= ERR_WARN; |
| 7124 | curproxy->options &= ~PR_O_ORGTO; |
| 7125 | } |
| 7126 | |
| 7127 | for (optnum = 0; cfg_opts[optnum].name; optnum++) { |
| 7128 | if (cfg_opts[optnum].mode == PR_MODE_HTTP && |
| 7129 | (curproxy->cap & cfg_opts[optnum].cap) && |
| 7130 | (curproxy->options & cfg_opts[optnum].val)) { |
| 7131 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 7132 | cfg_opts[optnum].name, proxy_type_str(curproxy), curproxy->id); |
| 7133 | err_code |= ERR_WARN; |
| 7134 | curproxy->options &= ~cfg_opts[optnum].val; |
| 7135 | } |
| 7136 | } |
| 7137 | |
| 7138 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) { |
| 7139 | if (cfg_opts2[optnum].mode == PR_MODE_HTTP && |
| 7140 | (curproxy->cap & cfg_opts2[optnum].cap) && |
| 7141 | (curproxy->options2 & cfg_opts2[optnum].val)) { |
| 7142 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 7143 | cfg_opts2[optnum].name, proxy_type_str(curproxy), curproxy->id); |
| 7144 | err_code |= ERR_WARN; |
| 7145 | curproxy->options2 &= ~cfg_opts2[optnum].val; |
| 7146 | } |
| 7147 | } |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 7148 | |
Pieter Baauw | d551fb5 | 2013-05-08 22:49:23 +0200 | [diff] [blame] | 7149 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_TRANSPARENT) |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 7150 | if (curproxy->conn_src.bind_hdr_occ) { |
| 7151 | curproxy->conn_src.bind_hdr_occ = 0; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 7152 | Warning("config : %s '%s' : ignoring use of header %s as source IP in non-HTTP mode.\n", |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 7153 | proxy_type_str(curproxy), curproxy->id, curproxy->conn_src.bind_hdr_name); |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 7154 | err_code |= ERR_WARN; |
| 7155 | } |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 7156 | #endif |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 7157 | } |
| 7158 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7159 | /* |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 7160 | * ensure that we're not cross-dressing a TCP server into HTTP. |
| 7161 | */ |
| 7162 | newsrv = curproxy->srv; |
| 7163 | while (newsrv != NULL) { |
Willy Tarreau | 0cec331 | 2011-10-31 13:49:26 +0100 | [diff] [blame] | 7164 | if ((curproxy->mode != PR_MODE_HTTP) && newsrv->rdr_len) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7165 | Alert("config : %s '%s' : server cannot have cookie or redirect prefix in non-HTTP mode.\n", |
| 7166 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 7167 | cfgerr++; |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 7168 | } |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 7169 | |
Willy Tarreau | 0cec331 | 2011-10-31 13:49:26 +0100 | [diff] [blame] | 7170 | if ((curproxy->mode != PR_MODE_HTTP) && newsrv->cklen) { |
| 7171 | Warning("config : %s '%s' : ignoring cookie for server '%s' as HTTP mode is disabled.\n", |
| 7172 | proxy_type_str(curproxy), curproxy->id, newsrv->id); |
| 7173 | err_code |= ERR_WARN; |
| 7174 | } |
| 7175 | |
Willy Tarreau | 82ffa39 | 2013-08-13 17:19:08 +0200 | [diff] [blame] | 7176 | if ((newsrv->state & SRV_MAPPORTS) && (curproxy->options2 & PR_O2_RDPC_PRST)) { |
| 7177 | Warning("config : %s '%s' : RDP cookie persistence will not work for server '%s' because it lacks an explicit port number.\n", |
| 7178 | proxy_type_str(curproxy), curproxy->id, newsrv->id); |
| 7179 | err_code |= ERR_WARN; |
| 7180 | } |
| 7181 | |
Pieter Baauw | d551fb5 | 2013-05-08 22:49:23 +0200 | [diff] [blame] | 7182 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_TRANSPARENT) |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 7183 | if (curproxy->mode != PR_MODE_HTTP && newsrv->conn_src.bind_hdr_occ) { |
| 7184 | newsrv->conn_src.bind_hdr_occ = 0; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 7185 | Warning("config : %s '%s' : server %s cannot use header %s as source IP in non-HTTP mode.\n", |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 7186 | proxy_type_str(curproxy), curproxy->id, newsrv->id, newsrv->conn_src.bind_hdr_name); |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 7187 | err_code |= ERR_WARN; |
| 7188 | } |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 7189 | #endif |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 7190 | newsrv = newsrv->next; |
| 7191 | } |
| 7192 | |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 7193 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 7194 | if (!curproxy->accept) |
| 7195 | curproxy->accept = frontend_accept; |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 7196 | |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 7197 | if (curproxy->tcp_req.inspect_delay || |
| 7198 | !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules)) |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 7199 | curproxy->fe_req_ana |= AN_REQ_INSPECT_FE; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 7200 | |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 7201 | if (curproxy->mode == PR_MODE_HTTP) { |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 7202 | 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] | 7203 | 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] | 7204 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 7205 | |
| 7206 | /* both TCP and HTTP must check switching rules */ |
| 7207 | curproxy->fe_req_ana |= AN_REQ_SWITCHING_RULES; |
| 7208 | } |
| 7209 | |
| 7210 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 7211 | if (curproxy->tcp_req.inspect_delay || |
| 7212 | !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules)) |
| 7213 | curproxy->be_req_ana |= AN_REQ_INSPECT_BE; |
| 7214 | |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 7215 | if (!LIST_ISEMPTY(&curproxy->tcp_rep.inspect_rules)) |
| 7216 | curproxy->be_rsp_ana |= AN_RES_INSPECT; |
| 7217 | |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 7218 | if (curproxy->mode == PR_MODE_HTTP) { |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 7219 | 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] | 7220 | 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] | 7221 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 7222 | |
| 7223 | /* If the backend does requires RDP cookie persistence, we have to |
| 7224 | * enable the corresponding analyser. |
| 7225 | */ |
| 7226 | if (curproxy->options2 & PR_O2_RDPC_PRST) |
| 7227 | curproxy->be_req_ana |= AN_REQ_PRST_RDP_COOKIE; |
| 7228 | } |
| 7229 | |
Emeric Brun | c52962f | 2012-11-15 18:28:02 +0100 | [diff] [blame] | 7230 | #ifdef USE_OPENSSL |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 7231 | /* Configure SSL for each bind line. |
| 7232 | * Note: if configuration fails at some point, the ->ctx member |
| 7233 | * remains NULL so that listeners can later detach. |
| 7234 | */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7235 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
Emeric Brun | c52962f | 2012-11-15 18:28:02 +0100 | [diff] [blame] | 7236 | if (!bind_conf->is_ssl) { |
| 7237 | if (bind_conf->default_ctx) { |
| 7238 | Warning("Proxy '%s': A certificate was specified but SSL was not enabled on bind '%s' at [%s:%d] (use 'ssl').\n", |
| 7239 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
| 7240 | } |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7241 | continue; |
Emeric Brun | c52962f | 2012-11-15 18:28:02 +0100 | [diff] [blame] | 7242 | } |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7243 | if (!bind_conf->default_ctx) { |
Emeric Brun | fc0421f | 2012-09-07 17:30:07 +0200 | [diff] [blame] | 7244 | 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] | 7245 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 7246 | cfgerr++; |
| 7247 | continue; |
| 7248 | } |
| 7249 | |
Emeric Brun | 4b3091e | 2012-09-24 15:48:52 +0200 | [diff] [blame] | 7250 | 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] | 7251 | Alert("Unable to allocate SSL session cache.\n"); |
| 7252 | cfgerr++; |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 7253 | continue; |
| 7254 | } |
| 7255 | |
Emeric Brun | fc0421f | 2012-09-07 17:30:07 +0200 | [diff] [blame] | 7256 | /* initialize all certificate contexts */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7257 | cfgerr += ssl_sock_prepare_all_ctx(bind_conf, curproxy); |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7258 | } |
Emeric Brun | c52962f | 2012-11-15 18:28:02 +0100 | [diff] [blame] | 7259 | #endif /* USE_OPENSSL */ |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 7260 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 7261 | /* adjust this proxy's listeners */ |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7262 | next_id = 1; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 7263 | list_for_each_entry(listener, &curproxy->conf.listeners, by_fe) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7264 | if (!listener->luid) { |
| 7265 | /* listener ID not set, use automatic numbering with first |
| 7266 | * spare entry starting with next_luid. |
| 7267 | */ |
| 7268 | next_id = get_next_id(&curproxy->conf.used_listener_id, next_id); |
| 7269 | listener->conf.id.key = listener->luid = next_id; |
| 7270 | eb32_insert(&curproxy->conf.used_listener_id, &listener->conf.id); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7271 | } |
Krzysztof Piotr Oledzki | df5cb9f | 2010-02-05 20:58:27 +0100 | [diff] [blame] | 7272 | next_id++; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7273 | |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 7274 | /* enable separate counters */ |
| 7275 | if (curproxy->options2 & PR_O2_SOCKSTAT) { |
| 7276 | listener->counters = (struct licounters *)calloc(1, sizeof(struct licounters)); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 7277 | if (!listener->name) |
| 7278 | memprintf(&listener->name, "sock-%d", listener->luid); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 7279 | } |
Willy Tarreau | 81796be | 2012-09-22 19:11:47 +0200 | [diff] [blame] | 7280 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 7281 | if (curproxy->options & PR_O_TCP_NOLING) |
| 7282 | listener->options |= LI_O_NOLINGER; |
Willy Tarreau | 32368ce | 2012-09-06 11:10:55 +0200 | [diff] [blame] | 7283 | if (!listener->maxconn) |
| 7284 | listener->maxconn = curproxy->maxconn; |
| 7285 | if (!listener->backlog) |
| 7286 | listener->backlog = curproxy->backlog; |
Willy Tarreau | 16a2147 | 2012-11-19 12:39:59 +0100 | [diff] [blame] | 7287 | if (!listener->maxaccept) |
| 7288 | listener->maxaccept = global.tune.maxaccept ? global.tune.maxaccept : 64; |
| 7289 | |
| 7290 | /* we want to have an optimal behaviour on single process mode to |
| 7291 | * maximize the work at once, but in multi-process we want to keep |
| 7292 | * some fairness between processes, so we target half of the max |
| 7293 | * number of events to be balanced over all the processes the proxy |
| 7294 | * is bound to. Rememeber that maxaccept = -1 must be kept as it is |
| 7295 | * used to disable the limit. |
| 7296 | */ |
| 7297 | if (listener->maxaccept > 0) { |
| 7298 | if (nbproc > 1) |
| 7299 | listener->maxaccept = (listener->maxaccept + 1) / 2; |
| 7300 | listener->maxaccept = (listener->maxaccept + nbproc - 1) / nbproc; |
| 7301 | } |
| 7302 | |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 7303 | listener->timeout = &curproxy->timeout.client; |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 7304 | listener->accept = session_accept; |
Willy Tarreau | 3bc1377 | 2008-12-07 11:50:35 +0100 | [diff] [blame] | 7305 | listener->handler = process_session; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 7306 | listener->analysers |= curproxy->fe_req_ana; |
Willy Tarreau | 3bc1377 | 2008-12-07 11:50:35 +0100 | [diff] [blame] | 7307 | |
Willy Tarreau | a5c0ab2 | 2010-05-31 10:30:33 +0200 | [diff] [blame] | 7308 | if (!LIST_ISEMPTY(&curproxy->tcp_req.l4_rules)) |
| 7309 | listener->options |= LI_O_TCP_RULES; |
| 7310 | |
Willy Tarreau | de3041d | 2010-05-31 10:56:17 +0200 | [diff] [blame] | 7311 | if (curproxy->mon_mask.s_addr) |
| 7312 | listener->options |= LI_O_CHK_MONNET; |
| 7313 | |
Willy Tarreau | 9ea05a7 | 2009-06-14 12:07:01 +0200 | [diff] [blame] | 7314 | /* smart accept mode is automatic in HTTP mode */ |
| 7315 | if ((curproxy->options2 & PR_O2_SMARTACC) || |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7316 | ((curproxy->mode == PR_MODE_HTTP || listener->bind_conf->is_ssl) && |
Willy Tarreau | 9ea05a7 | 2009-06-14 12:07:01 +0200 | [diff] [blame] | 7317 | !(curproxy->no_options2 & PR_O2_SMARTACC))) |
| 7318 | listener->options |= LI_O_NOQUICKACK; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 7319 | } |
| 7320 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7321 | /* Release unused SSL configs */ |
| 7322 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
| 7323 | if (bind_conf->is_ssl) |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 7324 | continue; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7325 | #ifdef USE_OPENSSL |
| 7326 | ssl_sock_free_all_ctx(bind_conf); |
Emeric Brun | fb510ea | 2012-10-05 12:00:26 +0200 | [diff] [blame] | 7327 | free(bind_conf->ca_file); |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7328 | free(bind_conf->ciphers); |
Emeric Brun | 2b58d04 | 2012-09-20 17:10:03 +0200 | [diff] [blame] | 7329 | free(bind_conf->ecdhe); |
Emeric Brun | fb510ea | 2012-10-05 12:00:26 +0200 | [diff] [blame] | 7330 | free(bind_conf->crl_file); |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 7331 | #endif /* USE_OPENSSL */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7332 | } |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 7333 | |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 7334 | /* Check multi-process mode compatibility for the current proxy */ |
| 7335 | if (global.nbproc > 1) { |
| 7336 | int nbproc = 0; |
| 7337 | if (curproxy->bind_proc) { |
| 7338 | int proc; |
| 7339 | for (proc = 0; proc < global.nbproc; proc++) { |
| 7340 | if (curproxy->bind_proc & (1 << proc)) { |
| 7341 | nbproc++; |
| 7342 | } |
| 7343 | } |
| 7344 | } else { |
| 7345 | nbproc = global.nbproc; |
| 7346 | } |
| 7347 | if (curproxy->table.peers.name) { |
| 7348 | Alert("Proxy '%s': peers can't be used in multi-process mode (nbproc > 1).\n", |
| 7349 | curproxy->id); |
| 7350 | cfgerr++; |
| 7351 | } |
| 7352 | if (nbproc > 1) { |
| 7353 | if (curproxy->uri_auth) { |
| 7354 | Warning("Proxy '%s': in multi-process mode, stats will be limited to process assigned to the current request.\n", |
| 7355 | curproxy->id); |
| 7356 | if (!LIST_ISEMPTY(&curproxy->uri_auth->admin_rules)) { |
| 7357 | Warning("Proxy '%s': stats admin will not work correctly in multi-process mode.\n", |
| 7358 | curproxy->id); |
| 7359 | } |
| 7360 | } |
| 7361 | if (curproxy->appsession_name) { |
| 7362 | Warning("Proxy '%s': appsession will not work correctly in multi-process mode.\n", |
| 7363 | curproxy->id); |
| 7364 | } |
| 7365 | if (!LIST_ISEMPTY(&curproxy->sticking_rules)) { |
| 7366 | Warning("Proxy '%s': sticking rules will not work correctly in multi-process mode.\n", |
| 7367 | curproxy->id); |
| 7368 | } |
| 7369 | } |
| 7370 | } |
Willy Tarreau | 918ff60 | 2011-07-25 16:33:49 +0200 | [diff] [blame] | 7371 | |
| 7372 | /* create the task associated with the proxy */ |
| 7373 | curproxy->task = task_new(); |
| 7374 | if (curproxy->task) { |
| 7375 | curproxy->task->context = curproxy; |
| 7376 | curproxy->task->process = manage_proxy; |
| 7377 | /* no need to queue, it will be done automatically if some |
| 7378 | * listener gets limited. |
| 7379 | */ |
| 7380 | curproxy->task->expire = TICK_ETERNITY; |
| 7381 | } else { |
| 7382 | Alert("Proxy '%s': no more memory when trying to allocate the management task\n", |
| 7383 | curproxy->id); |
| 7384 | cfgerr++; |
| 7385 | } |
| 7386 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7387 | curproxy = curproxy->next; |
| 7388 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7389 | |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 7390 | /* Check multi-process mode compatibility */ |
| 7391 | if (global.nbproc > 1) { |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 7392 | if (global.stats_fe && !global.stats_fe->bind_proc) { |
| 7393 | 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] | 7394 | } |
| 7395 | } |
| 7396 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 7397 | for (curuserlist = userlist; curuserlist; curuserlist = curuserlist->next) { |
| 7398 | struct auth_users *curuser; |
| 7399 | int g; |
| 7400 | |
| 7401 | for (curuser = curuserlist->users; curuser; curuser = curuser->next) { |
| 7402 | unsigned int group_mask = 0; |
| 7403 | char *group = NULL; |
| 7404 | |
Willy Tarreau | b4c06b7 | 2010-02-02 11:28:20 +0100 | [diff] [blame] | 7405 | if (!curuser->u.groups) |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 7406 | continue; |
| 7407 | |
Willy Tarreau | b4c06b7 | 2010-02-02 11:28:20 +0100 | [diff] [blame] | 7408 | while ((group = strtok(group?NULL:curuser->u.groups, ","))) { |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 7409 | |
| 7410 | for (g = 0; g < curuserlist->grpcnt; g++) |
| 7411 | if (!strcmp(curuserlist->groups[g], group)) |
| 7412 | break; |
| 7413 | |
| 7414 | if (g == curuserlist->grpcnt) { |
| 7415 | Alert("userlist '%s': no such group '%s' specified in user '%s'\n", |
| 7416 | curuserlist->name, group, curuser->user); |
| 7417 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7418 | goto out; |
| 7419 | } |
| 7420 | |
| 7421 | group_mask |= (1 << g); |
| 7422 | } |
| 7423 | |
Willy Tarreau | b4c06b7 | 2010-02-02 11:28:20 +0100 | [diff] [blame] | 7424 | free(curuser->u.groups); |
| 7425 | curuser->u.group_mask = group_mask; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 7426 | } |
| 7427 | |
| 7428 | for (g = 0; g < curuserlist->grpcnt; g++) { |
| 7429 | char *user = NULL; |
| 7430 | |
| 7431 | if (!curuserlist->groupusers[g]) |
| 7432 | continue; |
| 7433 | |
| 7434 | while ((user = strtok(user?NULL:curuserlist->groupusers[g], ","))) { |
| 7435 | for (curuser = curuserlist->users; curuser; curuser = curuser->next) |
| 7436 | if (!strcmp(curuser->user, user)) |
| 7437 | break; |
| 7438 | |
| 7439 | if (!curuser) { |
| 7440 | Alert("userlist '%s': no such user '%s' specified in group '%s'\n", |
| 7441 | curuserlist->name, user, curuserlist->groups[g]); |
| 7442 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7443 | goto out; |
| 7444 | } |
| 7445 | |
Willy Tarreau | b4c06b7 | 2010-02-02 11:28:20 +0100 | [diff] [blame] | 7446 | curuser->u.group_mask |= (1 << g); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 7447 | } |
| 7448 | |
| 7449 | free(curuserlist->groupusers[g]); |
| 7450 | } |
| 7451 | |
| 7452 | free(curuserlist->groupusers); |
| 7453 | |
| 7454 | #ifdef DEBUG_AUTH |
| 7455 | for (g = 0; g < curuserlist->grpcnt; g++) { |
| 7456 | fprintf(stderr, "group %s, id %d, mask %08X, users:", curuserlist->groups[g], g , 1 << g); |
| 7457 | |
| 7458 | for (curuser = curuserlist->users; curuser; curuser = curuser->next) { |
Willy Tarreau | b950959 | 2012-05-10 23:25:35 +0200 | [diff] [blame] | 7459 | if (curuser->u.group_mask & (1 << g)) |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 7460 | fprintf(stderr, " %s", curuser->user); |
| 7461 | } |
| 7462 | |
| 7463 | fprintf(stderr, "\n"); |
| 7464 | } |
| 7465 | #endif |
| 7466 | |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 7467 | } |
| 7468 | |
| 7469 | /* automatically compute fullconn if not set. We must not do it in the |
| 7470 | * loop above because cross-references are not yet fully resolved. |
| 7471 | */ |
| 7472 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 7473 | /* If <fullconn> is not set, let's set it to 10% of the sum of |
| 7474 | * the possible incoming frontend's maxconns. |
| 7475 | */ |
| 7476 | if (!curproxy->fullconn && (curproxy->cap & PR_CAP_BE)) { |
| 7477 | struct proxy *fe; |
| 7478 | int total = 0; |
| 7479 | |
| 7480 | /* sum up the number of maxconns of frontends which |
| 7481 | * reference this backend at least once or which are |
| 7482 | * the same one ('listen'). |
| 7483 | */ |
| 7484 | for (fe = proxy; fe; fe = fe->next) { |
| 7485 | struct switching_rule *rule; |
| 7486 | struct hdr_exp *exp; |
| 7487 | int found = 0; |
| 7488 | |
| 7489 | if (!(fe->cap & PR_CAP_FE)) |
| 7490 | continue; |
| 7491 | |
| 7492 | if (fe == curproxy) /* we're on a "listen" instance */ |
| 7493 | found = 1; |
| 7494 | |
| 7495 | if (fe->defbe.be == curproxy) /* "default_backend" */ |
| 7496 | found = 1; |
| 7497 | |
| 7498 | /* check if a "use_backend" rule matches */ |
| 7499 | if (!found) { |
| 7500 | list_for_each_entry(rule, &fe->switching_rules, list) { |
| 7501 | if (rule->be.backend == curproxy) { |
| 7502 | found = 1; |
| 7503 | break; |
| 7504 | } |
| 7505 | } |
| 7506 | } |
| 7507 | |
| 7508 | /* check if a "reqsetbe" rule matches */ |
| 7509 | for (exp = fe->req_exp; !found && exp; exp = exp->next) { |
| 7510 | if (exp->action == ACT_SETBE && |
| 7511 | (struct proxy *)exp->replace == curproxy) { |
| 7512 | found = 1; |
| 7513 | break; |
| 7514 | } |
| 7515 | } |
| 7516 | |
| 7517 | /* now we've checked all possible ways to reference a backend |
| 7518 | * from a frontend. |
| 7519 | */ |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 7520 | if (!found) |
| 7521 | continue; |
| 7522 | total += fe->maxconn; |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 7523 | } |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 7524 | /* we have the sum of the maxconns in <total>. We only |
| 7525 | * keep 10% of that sum to set the default fullconn, with |
| 7526 | * a hard minimum of 1 (to avoid a divide by zero). |
| 7527 | */ |
| 7528 | curproxy->fullconn = (total + 9) / 10; |
| 7529 | if (!curproxy->fullconn) |
| 7530 | curproxy->fullconn = 1; |
| 7531 | } |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 7532 | } |
| 7533 | |
Willy Tarreau | 056f568 | 2010-06-06 15:51:11 +0200 | [diff] [blame] | 7534 | /* initialize stick-tables on backend capable proxies. This must not |
| 7535 | * be done earlier because the data size may be discovered while parsing |
| 7536 | * other proxies. |
| 7537 | */ |
| 7538 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) |
Willy Tarreau | c00cdc2 | 2010-06-06 16:48:26 +0200 | [diff] [blame] | 7539 | stktable_init(&curproxy->table); |
Willy Tarreau | 056f568 | 2010-06-06 15:51:11 +0200 | [diff] [blame] | 7540 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7541 | /* |
| 7542 | * Recount currently required checks. |
| 7543 | */ |
| 7544 | |
| 7545 | for (curproxy=proxy; curproxy; curproxy=curproxy->next) { |
| 7546 | int optnum; |
| 7547 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 7548 | for (optnum = 0; cfg_opts[optnum].name; optnum++) |
| 7549 | if (curproxy->options & cfg_opts[optnum].val) |
| 7550 | global.last_checks |= cfg_opts[optnum].checks; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7551 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 7552 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) |
| 7553 | if (curproxy->options2 & cfg_opts2[optnum].val) |
| 7554 | global.last_checks |= cfg_opts2[optnum].checks; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7555 | } |
| 7556 | |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 7557 | if (peers) { |
| 7558 | struct peers *curpeers = peers, **last; |
| 7559 | struct peer *p, *pb; |
| 7560 | |
| 7561 | /* Remove all peers sections which don't have a valid listener. |
| 7562 | * This can happen when a peers section is never referenced and |
| 7563 | * does not contain a local peer. |
| 7564 | */ |
| 7565 | last = &peers; |
| 7566 | while (*last) { |
| 7567 | curpeers = *last; |
| 7568 | if (curpeers->peers_fe) { |
Willy Tarreau | ca57de3 | 2012-11-23 20:08:09 +0100 | [diff] [blame] | 7569 | LIST_NEXT(&curpeers->peers_fe->conf.listeners, struct listener *, by_fe)->maxaccept = 1; |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 7570 | last = &curpeers->next; |
| 7571 | continue; |
| 7572 | } |
| 7573 | |
| 7574 | Warning("Removing incomplete section 'peers %s' (no peer named '%s').\n", |
| 7575 | curpeers->id, localpeer); |
| 7576 | |
| 7577 | p = curpeers->remote; |
| 7578 | while (p) { |
| 7579 | pb = p->next; |
| 7580 | free(p->id); |
| 7581 | free(p); |
| 7582 | p = pb; |
| 7583 | } |
| 7584 | |
| 7585 | /* Destroy and unlink this curpeers section. |
| 7586 | * Note: curpeers is backed up into *last. |
| 7587 | */ |
| 7588 | free(curpeers->id); |
| 7589 | curpeers = curpeers->next; |
| 7590 | free(*last); |
| 7591 | *last = curpeers; |
| 7592 | } |
| 7593 | } |
| 7594 | |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 7595 | pool2_hdr_idx = create_pool("hdr_idx", |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame] | 7596 | global.tune.max_http_hdr * sizeof(struct hdr_idx_elem), |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 7597 | MEM_F_SHARED); |
| 7598 | |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 7599 | if (cfgerr > 0) |
| 7600 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7601 | out: |
| 7602 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7603 | } |
| 7604 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 7605 | /* |
| 7606 | * Registers the CFG keyword list <kwl> as a list of valid keywords for next |
| 7607 | * parsing sessions. |
| 7608 | */ |
| 7609 | void cfg_register_keywords(struct cfg_kw_list *kwl) |
| 7610 | { |
| 7611 | LIST_ADDQ(&cfg_keywords.list, &kwl->list); |
| 7612 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7613 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 7614 | /* |
| 7615 | * Unregisters the CFG keyword list <kwl> from the list of valid keywords. |
| 7616 | */ |
| 7617 | void cfg_unregister_keywords(struct cfg_kw_list *kwl) |
| 7618 | { |
| 7619 | LIST_DEL(&kwl->list); |
| 7620 | LIST_INIT(&kwl->list); |
| 7621 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7622 | |
| 7623 | /* |
| 7624 | * Local variables: |
| 7625 | * c-indent-level: 8 |
| 7626 | * c-basic-offset: 8 |
| 7627 | * End: |
| 7628 | */ |