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 | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 417 | /* Report it if a request ACL condition uses some response-only parameters. It |
| 418 | * returns either 0 or ERR_WARN so that its result can be or'ed with err_code. |
| 419 | * Note that <cond> may be NULL and then will be ignored. |
| 420 | */ |
| 421 | static int warnif_cond_requires_resp(const struct acl_cond *cond, const char *file, int line) |
| 422 | { |
| 423 | struct acl *acl; |
| 424 | |
| 425 | if (!cond || !(cond->requires & ACL_USE_RTR_ANY)) |
| 426 | return 0; |
| 427 | |
| 428 | acl = cond_find_require(cond, ACL_USE_RTR_ANY); |
| 429 | Warning("parsing [%s:%d] : acl '%s' involves some response-only criteria which will be ignored.\n", |
| 430 | file, line, acl ? acl->name : "(unknown)"); |
| 431 | return ERR_WARN; |
| 432 | } |
| 433 | |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 434 | /* Report it if a request ACL condition uses some request-only volatile parameters. |
| 435 | * It returns either 0 or ERR_WARN so that its result can be or'ed with err_code. |
| 436 | * Note that <cond> may be NULL and then will be ignored. |
| 437 | */ |
| 438 | static int warnif_cond_requires_req(const struct acl_cond *cond, const char *file, int line) |
| 439 | { |
| 440 | struct acl *acl; |
| 441 | |
| 442 | if (!cond || !(cond->requires & ACL_USE_REQ_VOLATILE)) |
| 443 | return 0; |
| 444 | |
| 445 | acl = cond_find_require(cond, ACL_USE_REQ_VOLATILE); |
| 446 | Warning("parsing [%s:%d] : acl '%s' involves some volatile request-only criteria which will be ignored.\n", |
| 447 | file, line, acl ? acl->name : "(unknown)"); |
| 448 | return ERR_WARN; |
| 449 | } |
| 450 | |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 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 | |
| 1325 | defproxy.defsrv.inter = DEF_CHKINTR; |
| 1326 | defproxy.defsrv.fastinter = 0; |
| 1327 | defproxy.defsrv.downinter = 0; |
| 1328 | defproxy.defsrv.rise = DEF_RISETIME; |
| 1329 | defproxy.defsrv.fall = DEF_FALLTIME; |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 1330 | defproxy.defsrv.check.port = 0; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1331 | defproxy.defsrv.maxqueue = 0; |
| 1332 | defproxy.defsrv.minconn = 0; |
| 1333 | defproxy.defsrv.maxconn = 0; |
| 1334 | defproxy.defsrv.slowstart = 0; |
| 1335 | defproxy.defsrv.onerror = DEF_HANA_ONERR; |
| 1336 | defproxy.defsrv.consecutive_errors_limit = DEF_HANA_ERRLIMIT; |
| 1337 | defproxy.defsrv.uweight = defproxy.defsrv.iweight = 1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1338 | } |
| 1339 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1340 | |
| 1341 | static int create_cond_regex_rule(const char *file, int line, |
| 1342 | struct proxy *px, int dir, int action, int flags, |
| 1343 | const char *cmd, const char *reg, const char *repl, |
| 1344 | const char **cond_start) |
| 1345 | { |
| 1346 | regex_t *preg = NULL; |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 1347 | char *errmsg = NULL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1348 | const char *err; |
| 1349 | int err_code = 0; |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1350 | struct acl_cond *cond = NULL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1351 | |
| 1352 | if (px == &defproxy) { |
| 1353 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, line, cmd); |
| 1354 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1355 | goto err; |
| 1356 | } |
| 1357 | |
| 1358 | if (*reg == 0) { |
| 1359 | Alert("parsing [%s:%d] : '%s' expects <regex> as an argument.\n", file, line, cmd); |
| 1360 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1361 | goto err; |
| 1362 | } |
| 1363 | |
| 1364 | if (warnifnotcap(px, PR_CAP_RS, file, line, cmd, NULL)) |
| 1365 | err_code |= ERR_WARN; |
| 1366 | |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1367 | if (cond_start && |
| 1368 | (strcmp(*cond_start, "if") == 0 || strcmp(*cond_start, "unless") == 0)) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 1369 | if ((cond = build_acl_cond(file, line, px, cond_start, &errmsg)) == NULL) { |
| 1370 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 1371 | file, line, cmd, errmsg); |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1372 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1373 | goto err; |
| 1374 | } |
| 1375 | } |
| 1376 | else if (cond_start && **cond_start) { |
| 1377 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 1378 | file, line, cmd, *cond_start); |
| 1379 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1380 | goto err; |
| 1381 | } |
| 1382 | |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 1383 | if (dir == SMP_OPT_DIR_REQ) |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1384 | err_code |= warnif_cond_requires_resp(cond, file, line); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 1385 | else |
| 1386 | err_code |= warnif_cond_requires_req(cond, file, line); |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1387 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1388 | preg = calloc(1, sizeof(regex_t)); |
| 1389 | if (!preg) { |
| 1390 | Alert("parsing [%s:%d] : '%s' : not enough memory to build regex.\n", file, line, cmd); |
| 1391 | err_code = ERR_ALERT | ERR_FATAL; |
| 1392 | goto err; |
| 1393 | } |
| 1394 | |
| 1395 | if (regcomp(preg, reg, REG_EXTENDED | flags) != 0) { |
| 1396 | Alert("parsing [%s:%d] : '%s' : bad regular expression '%s'.\n", file, line, cmd, reg); |
| 1397 | err_code = ERR_ALERT | ERR_FATAL; |
| 1398 | goto err; |
| 1399 | } |
| 1400 | |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 1401 | 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] | 1402 | preg, action, repl ? strdup(repl) : NULL, cond); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1403 | if (repl && err) { |
| 1404 | Alert("parsing [%s:%d] : '%s' : invalid character or unterminated sequence in replacement string near '%c'.\n", |
| 1405 | file, line, cmd, *err); |
| 1406 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1407 | goto err; |
| 1408 | } |
| 1409 | |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 1410 | 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] | 1411 | err_code |= ERR_WARN; |
| 1412 | |
Willy Tarreau | f4068b6 | 2012-05-08 17:37:49 +0200 | [diff] [blame] | 1413 | free(errmsg); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1414 | return err_code; |
| 1415 | err: |
Willy Tarreau | f4068b6 | 2012-05-08 17:37:49 +0200 | [diff] [blame] | 1416 | free(errmsg); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1417 | free(preg); |
| 1418 | return err_code; |
| 1419 | } |
| 1420 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1421 | /* |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1422 | * Parse a line in a <listen>, <frontend>, <backend> or <ruleset> section. |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1423 | * Returns the error code, 0 if OK, or any combination of : |
| 1424 | * - ERR_ABORT: must abort ASAP |
| 1425 | * - ERR_FATAL: we can continue parsing but not start the service |
| 1426 | * - ERR_WARN: a warning has been emitted |
| 1427 | * - ERR_ALERT: an alert has been emitted |
| 1428 | * Only the two first ones can stop processing, the two others are just |
| 1429 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1430 | */ |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1431 | int cfg_parse_peers(const char *file, int linenum, char **args, int kwm) |
| 1432 | { |
| 1433 | static struct peers *curpeers = NULL; |
| 1434 | struct peer *newpeer = NULL; |
| 1435 | const char *err; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1436 | struct bind_conf *bind_conf; |
| 1437 | struct listener *l; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1438 | int err_code = 0; |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1439 | char *errmsg = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1440 | |
| 1441 | if (strcmp(args[0], "peers") == 0) { /* new peers section */ |
Willy Tarreau | 0dbbf31 | 2013-03-05 11:31:55 +0100 | [diff] [blame] | 1442 | if (!*args[1]) { |
| 1443 | Alert("parsing [%s:%d] : missing name for peers section.\n", file, linenum); |
| 1444 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1445 | goto out; |
| 1446 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1447 | |
| 1448 | err = invalid_char(args[1]); |
| 1449 | if (err) { |
| 1450 | Alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 1451 | file, linenum, *err, args[0], args[1]); |
| 1452 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 0dbbf31 | 2013-03-05 11:31:55 +0100 | [diff] [blame] | 1453 | goto out; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1454 | } |
| 1455 | |
| 1456 | for (curpeers = peers; curpeers != NULL; curpeers = curpeers->next) { |
| 1457 | /* |
| 1458 | * If there are two proxies with the same name only following |
| 1459 | * combinations are allowed: |
| 1460 | */ |
| 1461 | if (strcmp(curpeers->id, args[1]) == 0) { |
| 1462 | Warning("Parsing [%s:%d]: peers '%s' has same name as another peers (declared at %s:%d).\n", |
| 1463 | file, linenum, args[1], curpeers->conf.file, curpeers->conf.line); |
| 1464 | err_code |= ERR_WARN; |
| 1465 | } |
| 1466 | } |
| 1467 | |
| 1468 | if ((curpeers = (struct peers *)calloc(1, sizeof(struct peers))) == NULL) { |
| 1469 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1470 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1471 | goto out; |
| 1472 | } |
| 1473 | |
| 1474 | curpeers->next = peers; |
| 1475 | peers = curpeers; |
Willy Tarreau | 8113a5d | 2012-10-04 08:01:43 +0200 | [diff] [blame] | 1476 | curpeers->conf.file = strdup(file); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1477 | curpeers->conf.line = linenum; |
| 1478 | curpeers->last_change = now.tv_sec; |
| 1479 | curpeers->id = strdup(args[1]); |
| 1480 | } |
| 1481 | else if (strcmp(args[0], "peer") == 0) { /* peer definition */ |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 1482 | struct sockaddr_storage *sk; |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 1483 | int port1, port2; |
Willy Tarreau | b36487e | 2013-03-10 18:37:42 +0100 | [diff] [blame] | 1484 | struct protocol *proto; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1485 | |
| 1486 | if (!*args[2]) { |
| 1487 | Alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n", |
| 1488 | file, linenum, args[0]); |
| 1489 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1490 | goto out; |
| 1491 | } |
| 1492 | |
| 1493 | err = invalid_char(args[1]); |
| 1494 | if (err) { |
| 1495 | Alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n", |
| 1496 | file, linenum, *err, args[1]); |
| 1497 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1498 | goto out; |
| 1499 | } |
| 1500 | |
| 1501 | if ((newpeer = (struct peer *)calloc(1, sizeof(struct peer))) == NULL) { |
| 1502 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1503 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1504 | goto out; |
| 1505 | } |
| 1506 | |
| 1507 | /* the peers are linked backwards first */ |
| 1508 | curpeers->count++; |
| 1509 | newpeer->next = curpeers->remote; |
| 1510 | curpeers->remote = newpeer; |
| 1511 | newpeer->peers = curpeers; |
Willy Tarreau | 8113a5d | 2012-10-04 08:01:43 +0200 | [diff] [blame] | 1512 | newpeer->conf.file = strdup(file); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1513 | newpeer->conf.line = linenum; |
| 1514 | |
| 1515 | newpeer->last_change = now.tv_sec; |
| 1516 | newpeer->id = strdup(args[1]); |
| 1517 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1518 | sk = str2sa_range(args[2], &port1, &port2, &errmsg, NULL); |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 1519 | if (!sk) { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1520 | 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] | 1521 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1522 | goto out; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1523 | } |
Willy Tarreau | b36487e | 2013-03-10 18:37:42 +0100 | [diff] [blame] | 1524 | |
| 1525 | proto = protocol_by_family(sk->ss_family); |
| 1526 | if (!proto || !proto->connect) { |
| 1527 | Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 1528 | file, linenum, args[0], args[1]); |
| 1529 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1530 | goto out; |
| 1531 | } |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 1532 | |
| 1533 | if (port1 != port2) { |
| 1534 | Alert("parsing [%s:%d] : '%s %s' : port ranges and offsets are not allowed in '%s'\n", |
| 1535 | file, linenum, args[0], args[1], args[2]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1536 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1537 | goto out; |
| 1538 | } |
| 1539 | |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 1540 | if (!port1) { |
| 1541 | Alert("parsing [%s:%d] : '%s %s' : missing or invalid port 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 | } |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 1546 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1547 | newpeer->addr = *sk; |
Willy Tarreau | b36487e | 2013-03-10 18:37:42 +0100 | [diff] [blame] | 1548 | newpeer->proto = proto; |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 1549 | newpeer->xprt = &raw_sock; |
Willy Tarreau | d02394b | 2012-05-11 18:32:18 +0200 | [diff] [blame] | 1550 | newpeer->sock_init_arg = NULL; |
Willy Tarreau | 26d8c59 | 2012-05-07 18:12:14 +0200 | [diff] [blame] | 1551 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1552 | if (strcmp(newpeer->id, localpeer) == 0) { |
| 1553 | /* Current is local peer, it define a frontend */ |
| 1554 | newpeer->local = 1; |
| 1555 | |
| 1556 | if (!curpeers->peers_fe) { |
| 1557 | if ((curpeers->peers_fe = calloc(1, sizeof(struct proxy))) == NULL) { |
| 1558 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1559 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1560 | goto out; |
| 1561 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1562 | |
Willy Tarreau | 237250c | 2011-07-29 01:49:03 +0200 | [diff] [blame] | 1563 | init_new_proxy(curpeers->peers_fe); |
| 1564 | curpeers->peers_fe->parent = curpeers; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1565 | |
| 1566 | curpeers->peers_fe->last_change = now.tv_sec; |
| 1567 | curpeers->peers_fe->id = strdup(args[1]); |
| 1568 | curpeers->peers_fe->cap = PR_CAP_FE; |
Willy Tarreau | 3ae65a1 | 2011-09-07 17:40:39 +0200 | [diff] [blame] | 1569 | curpeers->peers_fe->maxconn = 0; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1570 | curpeers->peers_fe->conn_retries = CONN_RETRIES; |
| 1571 | curpeers->peers_fe->timeout.connect = 5000; |
| 1572 | curpeers->peers_fe->accept = peer_accept; |
| 1573 | curpeers->peers_fe->options2 |= PR_O2_INDEPSTR | PR_O2_SMARTCON | PR_O2_SMARTACC; |
Willy Tarreau | 8b8fd56 | 2013-01-18 11:12:27 +0100 | [diff] [blame] | 1574 | curpeers->peers_fe->conf.file = strdup(file); |
| 1575 | curpeers->peers_fe->conf.line = linenum; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1576 | |
| 1577 | bind_conf = bind_conf_alloc(&curpeers->peers_fe->conf.bind, file, linenum, args[2]); |
| 1578 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1579 | if (!str2listener(args[2], curpeers->peers_fe, bind_conf, file, linenum, &errmsg)) { |
| 1580 | if (errmsg && *errmsg) { |
| 1581 | indent_msg(&errmsg, 2); |
| 1582 | 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] | 1583 | } |
| 1584 | else |
| 1585 | Alert("parsing [%s:%d] : '%s %s' : error encountered while parsing listening address %s.\n", |
| 1586 | file, linenum, args[0], args[1], args[2]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1587 | err_code |= ERR_FATAL; |
| 1588 | goto out; |
| 1589 | } |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1590 | |
| 1591 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
| 1592 | l->maxconn = ((struct proxy *)curpeers->peers_fe)->maxconn; |
| 1593 | l->backlog = ((struct proxy *)curpeers->peers_fe)->backlog; |
| 1594 | l->timeout = &((struct proxy *)curpeers->peers_fe)->timeout.client; |
| 1595 | l->accept = session_accept; |
| 1596 | l->handler = process_session; |
| 1597 | l->analysers |= ((struct proxy *)curpeers->peers_fe)->fe_req_ana; |
| 1598 | l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */ |
| 1599 | global.maxsock += l->maxconn; |
| 1600 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1601 | } |
Willy Tarreau | 8b8fd56 | 2013-01-18 11:12:27 +0100 | [diff] [blame] | 1602 | else { |
| 1603 | Alert("parsing [%s:%d] : '%s %s' : local peer name already referenced at %s:%d.\n", |
| 1604 | file, linenum, args[0], args[1], |
| 1605 | curpeers->peers_fe->conf.file, curpeers->peers_fe->conf.line); |
| 1606 | err_code |= ERR_FATAL; |
| 1607 | goto out; |
| 1608 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1609 | } |
| 1610 | } /* neither "peer" nor "peers" */ |
| 1611 | else if (*args[0] != 0) { |
| 1612 | Alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection); |
| 1613 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1614 | goto out; |
| 1615 | } |
| 1616 | |
| 1617 | out: |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1618 | free(errmsg); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1619 | return err_code; |
| 1620 | } |
| 1621 | |
| 1622 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 1623 | 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] | 1624 | { |
| 1625 | static struct proxy *curproxy = NULL; |
| 1626 | struct server *newsrv = NULL; |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 1627 | const char *err; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 1628 | int rc; |
| 1629 | unsigned val; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1630 | int err_code = 0; |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 1631 | struct acl_cond *cond = NULL; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 1632 | struct logsrv *tmplogsrv; |
Willy Tarreau | f4068b6 | 2012-05-08 17:37:49 +0200 | [diff] [blame] | 1633 | char *errmsg = NULL; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 1634 | struct bind_conf *bind_conf; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1635 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1636 | if (!strcmp(args[0], "listen")) |
| 1637 | rc = PR_CAP_LISTEN; |
| 1638 | else if (!strcmp(args[0], "frontend")) |
| 1639 | rc = PR_CAP_FE | PR_CAP_RS; |
| 1640 | else if (!strcmp(args[0], "backend")) |
| 1641 | rc = PR_CAP_BE | PR_CAP_RS; |
| 1642 | else if (!strcmp(args[0], "ruleset")) |
| 1643 | rc = PR_CAP_RS; |
| 1644 | else |
| 1645 | rc = PR_CAP_NONE; |
| 1646 | |
| 1647 | if (rc != PR_CAP_NONE) { /* new proxy */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1648 | if (!*args[1]) { |
| 1649 | Alert("parsing [%s:%d] : '%s' expects an <id> argument and\n" |
| 1650 | " optionnally supports [addr1]:port1[-end1]{,[addr]:port[-end]}...\n", |
| 1651 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1652 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1653 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1654 | } |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 1655 | |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 1656 | err = invalid_char(args[1]); |
| 1657 | if (err) { |
| 1658 | Alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 1659 | file, linenum, *err, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1660 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 1661 | } |
| 1662 | |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 1663 | for (curproxy = proxy; curproxy != NULL; curproxy = curproxy->next) { |
| 1664 | /* |
| 1665 | * If there are two proxies with the same name only following |
| 1666 | * combinations are allowed: |
| 1667 | * |
| 1668 | * listen backend frontend ruleset |
| 1669 | * listen - - - - |
| 1670 | * backend - - OK - |
| 1671 | * frontend - OK - - |
| 1672 | * ruleset - - - - |
| 1673 | */ |
| 1674 | |
| 1675 | if (!strcmp(curproxy->id, args[1]) && |
| 1676 | (rc!=(PR_CAP_FE|PR_CAP_RS) || curproxy->cap!=(PR_CAP_BE|PR_CAP_RS)) && |
| 1677 | (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] | 1678 | Warning("Parsing [%s:%d]: %s '%s' has same name as another %s (declared at %s:%d).\n", |
| 1679 | file, linenum, proxy_cap_str(rc), args[1], proxy_type_str(curproxy), |
| 1680 | curproxy->conf.file, curproxy->conf.line); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1681 | err_code |= ERR_WARN; |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 1682 | } |
| 1683 | } |
| 1684 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1685 | if ((curproxy = (struct proxy *)calloc(1, sizeof(struct proxy))) == NULL) { |
| 1686 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
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 | } |
Willy Tarreau | 5af24ef | 2009-03-15 15:23:16 +0100 | [diff] [blame] | 1690 | |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 1691 | init_new_proxy(curproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1692 | curproxy->next = proxy; |
| 1693 | proxy = curproxy; |
Willy Tarreau | 8113a5d | 2012-10-04 08:01:43 +0200 | [diff] [blame] | 1694 | curproxy->conf.file = strdup(file); |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 1695 | curproxy->conf.line = linenum; |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 1696 | curproxy->last_change = now.tv_sec; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1697 | curproxy->id = strdup(args[1]); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1698 | curproxy->cap = rc; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1699 | |
| 1700 | /* parse the listener address if any */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1701 | if ((curproxy->cap & PR_CAP_FE) && *args[2]) { |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1702 | struct listener *l; |
Willy Tarreau | 81a8117 | 2012-09-18 20:52:35 +0200 | [diff] [blame] | 1703 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1704 | bind_conf = bind_conf_alloc(&curproxy->conf.bind, file, linenum, args[2]); |
| 1705 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1706 | if (!str2listener(args[2], curproxy, bind_conf, file, linenum, &errmsg)) { |
| 1707 | if (errmsg && *errmsg) { |
| 1708 | indent_msg(&errmsg, 2); |
| 1709 | 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] | 1710 | } |
| 1711 | else |
| 1712 | Alert("parsing [%s:%d] : '%s %s' : error encountered while parsing listening address '%s'.\n", |
| 1713 | file, linenum, args[0], args[1], args[2]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1714 | err_code |= ERR_FATAL; |
| 1715 | goto out; |
| 1716 | } |
Willy Tarreau | 81a8117 | 2012-09-18 20:52:35 +0200 | [diff] [blame] | 1717 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1718 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
Willy Tarreau | c8b1109 | 2011-02-16 11:08:57 +0100 | [diff] [blame] | 1719 | global.maxsock++; |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 1720 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1721 | } |
| 1722 | |
| 1723 | /* set default values */ |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1724 | memcpy(&curproxy->defsrv, &defproxy.defsrv, sizeof(curproxy->defsrv)); |
Willy Tarreau | 7016020 | 2010-04-07 16:06:40 +0200 | [diff] [blame] | 1725 | curproxy->defsrv.id = "default-server"; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1726 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1727 | curproxy->state = defproxy.state; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1728 | curproxy->options = defproxy.options; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 1729 | curproxy->options2 = defproxy.options2; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 1730 | curproxy->no_options = defproxy.no_options; |
| 1731 | curproxy->no_options2 = defproxy.no_options2; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 1732 | curproxy->bind_proc = defproxy.bind_proc; |
Willy Tarreau | 3168223 | 2007-11-29 15:38:04 +0100 | [diff] [blame] | 1733 | curproxy->lbprm.algo = defproxy.lbprm.algo; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 1734 | curproxy->except_net = defproxy.except_net; |
| 1735 | curproxy->except_mask = defproxy.except_mask; |
Maik Broemme | 36db02e | 2009-05-08 17:02:07 +0200 | [diff] [blame] | 1736 | curproxy->except_to = defproxy.except_to; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 1737 | curproxy->except_mask_to = defproxy.except_mask_to; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1738 | |
Willy Tarreau | 79f5fe8 | 2008-08-23 08:18:21 +0200 | [diff] [blame] | 1739 | if (defproxy.fwdfor_hdr_len) { |
| 1740 | curproxy->fwdfor_hdr_len = defproxy.fwdfor_hdr_len; |
| 1741 | curproxy->fwdfor_hdr_name = strdup(defproxy.fwdfor_hdr_name); |
| 1742 | } |
| 1743 | |
Willy Tarreau | b86db34 | 2009-11-30 11:50:16 +0100 | [diff] [blame] | 1744 | if (defproxy.orgto_hdr_len) { |
| 1745 | curproxy->orgto_hdr_len = defproxy.orgto_hdr_len; |
| 1746 | curproxy->orgto_hdr_name = strdup(defproxy.orgto_hdr_name); |
| 1747 | } |
| 1748 | |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 1749 | if (defproxy.server_id_hdr_len) { |
| 1750 | curproxy->server_id_hdr_len = defproxy.server_id_hdr_len; |
| 1751 | curproxy->server_id_hdr_name = strdup(defproxy.server_id_hdr_name); |
| 1752 | } |
| 1753 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1754 | if (curproxy->cap & PR_CAP_FE) { |
| 1755 | curproxy->maxconn = defproxy.maxconn; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 1756 | curproxy->backlog = defproxy.backlog; |
Willy Tarreau | 13a34bd | 2009-05-10 18:52:49 +0200 | [diff] [blame] | 1757 | curproxy->fe_sps_lim = defproxy.fe_sps_lim; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1758 | |
| 1759 | /* initialize error relocations */ |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1760 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) |
| 1761 | chunk_dup(&curproxy->errmsg[rc], &defproxy.errmsg[rc]); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1762 | |
| 1763 | curproxy->to_log = defproxy.to_log & ~LW_COOKIE & ~LW_REQHDR & ~ LW_RSPHDR; |
| 1764 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1765 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1766 | if (curproxy->cap & PR_CAP_BE) { |
| 1767 | curproxy->fullconn = defproxy.fullconn; |
| 1768 | curproxy->conn_retries = defproxy.conn_retries; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1769 | |
Willy Tarreau | aa2f389 | 2010-10-22 16:15:31 +0200 | [diff] [blame] | 1770 | if (defproxy.check_req) { |
| 1771 | curproxy->check_req = calloc(1, defproxy.check_len); |
| 1772 | memcpy(curproxy->check_req, defproxy.check_req, defproxy.check_len); |
| 1773 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1774 | curproxy->check_len = defproxy.check_len; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1775 | |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 1776 | if (defproxy.expect_str) { |
| 1777 | curproxy->expect_str = strdup(defproxy.expect_str); |
| 1778 | if (defproxy.expect_regex) { |
| 1779 | /* note: this regex is known to be valid */ |
| 1780 | curproxy->expect_regex = calloc(1, sizeof(regex_t)); |
| 1781 | regcomp(curproxy->expect_regex, defproxy.expect_str, REG_EXTENDED); |
| 1782 | } |
| 1783 | } |
| 1784 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 1785 | curproxy->ck_opts = defproxy.ck_opts; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1786 | if (defproxy.cookie_name) |
| 1787 | curproxy->cookie_name = strdup(defproxy.cookie_name); |
| 1788 | curproxy->cookie_len = defproxy.cookie_len; |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 1789 | if (defproxy.cookie_domain) |
| 1790 | curproxy->cookie_domain = strdup(defproxy.cookie_domain); |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 1791 | |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 1792 | if (defproxy.cookie_maxidle) |
| 1793 | curproxy->cookie_maxidle = defproxy.cookie_maxidle; |
| 1794 | |
| 1795 | if (defproxy.cookie_maxlife) |
| 1796 | curproxy->cookie_maxlife = defproxy.cookie_maxlife; |
| 1797 | |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 1798 | if (defproxy.rdp_cookie_name) |
| 1799 | curproxy->rdp_cookie_name = strdup(defproxy.rdp_cookie_name); |
| 1800 | curproxy->rdp_cookie_len = defproxy.rdp_cookie_len; |
| 1801 | |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 1802 | if (defproxy.url_param_name) |
| 1803 | curproxy->url_param_name = strdup(defproxy.url_param_name); |
| 1804 | curproxy->url_param_len = defproxy.url_param_len; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 1805 | |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 1806 | if (defproxy.hh_name) |
| 1807 | curproxy->hh_name = strdup(defproxy.hh_name); |
| 1808 | curproxy->hh_len = defproxy.hh_len; |
| 1809 | curproxy->hh_match_domain = defproxy.hh_match_domain; |
| 1810 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 1811 | if (defproxy.conn_src.iface_name) |
| 1812 | curproxy->conn_src.iface_name = strdup(defproxy.conn_src.iface_name); |
| 1813 | curproxy->conn_src.iface_len = defproxy.conn_src.iface_len; |
| 1814 | curproxy->conn_src.opts = defproxy.conn_src.opts & ~CO_SRC_TPROXY_MASK; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1815 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1816 | |
Willy Tarreau | 3b6b1a9 | 2009-07-23 13:24:23 +0200 | [diff] [blame] | 1817 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1818 | if (defproxy.capture_name) |
| 1819 | curproxy->capture_name = strdup(defproxy.capture_name); |
| 1820 | curproxy->capture_namelen = defproxy.capture_namelen; |
| 1821 | curproxy->capture_len = defproxy.capture_len; |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 1822 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1823 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1824 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 1825 | curproxy->timeout.client = defproxy.timeout.client; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 1826 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | 036fae0 | 2008-01-06 13:24:40 +0100 | [diff] [blame] | 1827 | curproxy->timeout.httpreq = defproxy.timeout.httpreq; |
Willy Tarreau | b16a574 | 2010-01-10 14:46:16 +0100 | [diff] [blame] | 1828 | curproxy->timeout.httpka = defproxy.timeout.httpka; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1829 | curproxy->uri_auth = defproxy.uri_auth; |
| 1830 | curproxy->mon_net = defproxy.mon_net; |
| 1831 | curproxy->mon_mask = defproxy.mon_mask; |
| 1832 | if (defproxy.monitor_uri) |
| 1833 | curproxy->monitor_uri = strdup(defproxy.monitor_uri); |
| 1834 | curproxy->monitor_uri_len = defproxy.monitor_uri_len; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 1835 | if (defproxy.defbe.name) |
| 1836 | curproxy->defbe.name = strdup(defproxy.defbe.name); |
Willy Tarreau | 99a7ca2 | 2012-05-31 19:39:23 +0200 | [diff] [blame] | 1837 | |
| 1838 | /* get either a pointer to the logformat string or a copy of it */ |
| 1839 | curproxy->logformat_string = defproxy.logformat_string; |
| 1840 | if (curproxy->logformat_string && |
| 1841 | curproxy->logformat_string != default_http_log_format && |
| 1842 | curproxy->logformat_string != default_tcp_log_format && |
| 1843 | curproxy->logformat_string != clf_http_log_format) |
| 1844 | curproxy->logformat_string = strdup(curproxy->logformat_string); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1845 | } |
| 1846 | |
| 1847 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 1848 | curproxy->timeout.connect = defproxy.timeout.connect; |
| 1849 | curproxy->timeout.server = defproxy.timeout.server; |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 1850 | curproxy->timeout.check = defproxy.timeout.check; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 1851 | curproxy->timeout.queue = defproxy.timeout.queue; |
Willy Tarreau | 51c9bde | 2008-01-06 13:40:03 +0100 | [diff] [blame] | 1852 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | cd7afc0 | 2009-07-12 10:03:17 +0200 | [diff] [blame] | 1853 | curproxy->timeout.httpreq = defproxy.timeout.httpreq; |
Willy Tarreau | b16a574 | 2010-01-10 14:46:16 +0100 | [diff] [blame] | 1854 | curproxy->timeout.httpka = defproxy.timeout.httpka; |
Willy Tarreau | ce887fd | 2012-05-12 12:50:00 +0200 | [diff] [blame] | 1855 | curproxy->timeout.tunnel = defproxy.timeout.tunnel; |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 1856 | curproxy->conn_src.source_addr = defproxy.conn_src.source_addr; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1857 | } |
| 1858 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1859 | curproxy->mode = defproxy.mode; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1860 | |
| 1861 | /* copy default logsrvs to curproxy */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 1862 | list_for_each_entry(tmplogsrv, &defproxy.logsrvs, list) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1863 | struct logsrv *node = malloc(sizeof(struct logsrv)); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 1864 | memcpy(node, tmplogsrv, sizeof(struct logsrv)); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1865 | LIST_INIT(&node->list); |
| 1866 | LIST_ADDQ(&curproxy->logsrvs, &node->list); |
| 1867 | } |
| 1868 | |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 1869 | curproxy->uniqueid_format_string = defproxy.uniqueid_format_string; |
| 1870 | if (curproxy->uniqueid_format_string) |
| 1871 | curproxy->uniqueid_format_string = strdup(curproxy->uniqueid_format_string); |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 1872 | |
| 1873 | /* copy default header unique id */ |
| 1874 | if (defproxy.header_unique_id) |
| 1875 | curproxy->header_unique_id = strdup(defproxy.header_unique_id); |
| 1876 | |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 1877 | /* default compression options */ |
| 1878 | if (defproxy.comp != NULL) { |
| 1879 | curproxy->comp = calloc(1, sizeof(struct comp)); |
| 1880 | curproxy->comp->algos = defproxy.comp->algos; |
| 1881 | curproxy->comp->types = defproxy.comp->types; |
| 1882 | } |
| 1883 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1884 | curproxy->grace = defproxy.grace; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 1885 | curproxy->conf.used_listener_id = EB_ROOT; |
| 1886 | curproxy->conf.used_server_id = EB_ROOT; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 1887 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1888 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1889 | } |
| 1890 | else if (!strcmp(args[0], "defaults")) { /* use this one to assign default values */ |
| 1891 | /* some variables may have already been initialized earlier */ |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 1892 | /* FIXME-20070101: we should do this too at the end of the |
| 1893 | * config parsing to free all default values. |
| 1894 | */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1895 | free(defproxy.check_req); |
| 1896 | free(defproxy.cookie_name); |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 1897 | free(defproxy.rdp_cookie_name); |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 1898 | free(defproxy.cookie_domain); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1899 | free(defproxy.url_param_name); |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 1900 | free(defproxy.hh_name); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1901 | free(defproxy.capture_name); |
| 1902 | free(defproxy.monitor_uri); |
| 1903 | free(defproxy.defbe.name); |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 1904 | free(defproxy.conn_src.iface_name); |
Willy Tarreau | 79f5fe8 | 2008-08-23 08:18:21 +0200 | [diff] [blame] | 1905 | free(defproxy.fwdfor_hdr_name); |
| 1906 | defproxy.fwdfor_hdr_len = 0; |
Willy Tarreau | b86db34 | 2009-11-30 11:50:16 +0100 | [diff] [blame] | 1907 | free(defproxy.orgto_hdr_name); |
| 1908 | defproxy.orgto_hdr_len = 0; |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 1909 | free(defproxy.server_id_hdr_name); |
| 1910 | defproxy.server_id_hdr_len = 0; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 1911 | free(defproxy.expect_str); |
| 1912 | if (defproxy.expect_regex) regfree(defproxy.expect_regex); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 1913 | |
Willy Tarreau | 39b0665 | 2012-06-01 10:58:06 +0200 | [diff] [blame] | 1914 | if (defproxy.logformat_string != default_http_log_format && |
| 1915 | defproxy.logformat_string != default_tcp_log_format && |
| 1916 | defproxy.logformat_string != clf_http_log_format) |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 1917 | free(defproxy.logformat_string); |
| 1918 | |
| 1919 | free(defproxy.uniqueid_format_string); |
| 1920 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1921 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1922 | chunk_destroy(&defproxy.errmsg[rc]); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 1923 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1924 | /* we cannot free uri_auth because it might already be used */ |
| 1925 | init_default_instance(); |
| 1926 | curproxy = &defproxy; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1927 | defproxy.cap = PR_CAP_LISTEN; /* all caps for now */ |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1928 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1929 | } |
| 1930 | else if (curproxy == NULL) { |
| 1931 | Alert("parsing [%s:%d] : 'listen' or 'defaults' expected.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1932 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1933 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1934 | } |
| 1935 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1936 | |
| 1937 | /* Now let's parse the proxy-specific keywords */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1938 | if (!strcmp(args[0], "bind")) { /* new listen addresses */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1939 | struct listener *l; |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1940 | int cur_arg; |
| 1941 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1942 | if (curproxy == &defproxy) { |
| 1943 | 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] | 1944 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1945 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1946 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1947 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1948 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1949 | |
Willy Tarreau | 2470928 | 2013-03-10 21:32:12 +0100 | [diff] [blame] | 1950 | if (!*(args[1])) { |
Willy Tarreau | d55c3fe | 2010-11-09 09:50:37 +0100 | [diff] [blame] | 1951 | 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] | 1952 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1953 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1954 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1955 | } |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 1956 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 1957 | bind_conf = bind_conf_alloc(&curproxy->conf.bind, file, linenum, args[1]); |
Willy Tarreau | 8dc21fa | 2013-01-24 15:17:20 +0100 | [diff] [blame] | 1958 | |
| 1959 | /* use default settings for unix sockets */ |
| 1960 | bind_conf->ux.uid = global.unix_bind.ux.uid; |
| 1961 | bind_conf->ux.gid = global.unix_bind.ux.gid; |
| 1962 | bind_conf->ux.mode = global.unix_bind.ux.mode; |
Willy Tarreau | 8a95691 | 2010-10-15 14:27:08 +0200 | [diff] [blame] | 1963 | |
| 1964 | /* NOTE: the following line might create several listeners if there |
| 1965 | * are comma-separated IPs or port ranges. So all further processing |
| 1966 | * will have to be applied to all listeners created after last_listen. |
| 1967 | */ |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1968 | if (!str2listener(args[1], curproxy, bind_conf, file, linenum, &errmsg)) { |
| 1969 | if (errmsg && *errmsg) { |
| 1970 | indent_msg(&errmsg, 2); |
| 1971 | Alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 1972 | } |
| 1973 | else |
| 1974 | Alert("parsing [%s:%d] : '%s' : error encountered while parsing listening address '%s'.\n", |
| 1975 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1976 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1977 | goto out; |
| 1978 | } |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1979 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1980 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
| 1981 | /* Set default global rights and owner for unix bind */ |
Willy Tarreau | c8b1109 | 2011-02-16 11:08:57 +0100 | [diff] [blame] | 1982 | global.maxsock++; |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 1983 | } |
| 1984 | |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 1985 | cur_arg = 2; |
| 1986 | while (*(args[cur_arg])) { |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 1987 | static int bind_dumped; |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 1988 | struct bind_kw *kw; |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 1989 | char *err; |
| 1990 | |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 1991 | kw = bind_find_kw(args[cur_arg]); |
| 1992 | if (kw) { |
| 1993 | char *err = NULL; |
| 1994 | int code; |
| 1995 | |
| 1996 | if (!kw->parse) { |
Willy Tarreau | dda322d | 2012-09-18 16:34:09 +0200 | [diff] [blame] | 1997 | Alert("parsing [%s:%d] : '%s %s' : '%s' option is not implemented in this version (check build options).\n", |
| 1998 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 1999 | cur_arg += 1 + kw->skip ; |
| 2000 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2001 | goto out; |
| 2002 | } |
| 2003 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2004 | code = kw->parse(args, cur_arg, curproxy, bind_conf, &err); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 2005 | err_code |= code; |
| 2006 | |
| 2007 | if (code) { |
| 2008 | if (err && *err) { |
| 2009 | indent_msg(&err, 2); |
Willy Tarreau | dda322d | 2012-09-18 16:34:09 +0200 | [diff] [blame] | 2010 | 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] | 2011 | } |
| 2012 | else |
Willy Tarreau | dda322d | 2012-09-18 16:34:09 +0200 | [diff] [blame] | 2013 | Alert("parsing [%s:%d] : '%s %s' : error encountered while processing '%s'.\n", |
| 2014 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 2015 | if (code & ERR_FATAL) { |
| 2016 | free(err); |
| 2017 | cur_arg += 1 + kw->skip; |
| 2018 | goto out; |
| 2019 | } |
| 2020 | } |
| 2021 | free(err); |
| 2022 | cur_arg += 1 + kw->skip; |
| 2023 | continue; |
| 2024 | } |
| 2025 | |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 2026 | err = NULL; |
| 2027 | if (!bind_dumped) { |
| 2028 | bind_dump_kws(&err); |
| 2029 | indent_msg(&err, 4); |
| 2030 | bind_dumped = 1; |
| 2031 | } |
| 2032 | |
| 2033 | Alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'.%s%s\n", |
| 2034 | file, linenum, args[0], args[1], args[cur_arg], |
| 2035 | err ? " Registered keywords :" : "", err ? err : ""); |
| 2036 | free(err); |
| 2037 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2038 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2039 | goto out; |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 2040 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2041 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2042 | } |
| 2043 | else if (!strcmp(args[0], "monitor-net")) { /* set the range of IPs to ignore */ |
| 2044 | if (!*args[1] || !str2net(args[1], &curproxy->mon_net, &curproxy->mon_mask)) { |
| 2045 | Alert("parsing [%s:%d] : '%s' expects address[/mask].\n", |
| 2046 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2047 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2048 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2049 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2050 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2051 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2052 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2053 | /* flush useless bits */ |
| 2054 | curproxy->mon_net.s_addr &= curproxy->mon_mask.s_addr; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2055 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2056 | } |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2057 | else if (!strcmp(args[0], "monitor-uri")) { /* set the URI to intercept */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2058 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2059 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2060 | |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2061 | if (!*args[1]) { |
| 2062 | Alert("parsing [%s:%d] : '%s' expects an URI.\n", |
| 2063 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2064 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2065 | goto out; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2066 | } |
| 2067 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2068 | free(curproxy->monitor_uri); |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 2069 | curproxy->monitor_uri_len = strlen(args[1]); |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2070 | curproxy->monitor_uri = (char *)calloc(1, curproxy->monitor_uri_len + 1); |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 2071 | memcpy(curproxy->monitor_uri, args[1], curproxy->monitor_uri_len); |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2072 | curproxy->monitor_uri[curproxy->monitor_uri_len] = '\0'; |
| 2073 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2074 | goto out; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2075 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2076 | else if (!strcmp(args[0], "mode")) { /* sets the proxy mode */ |
| 2077 | if (!strcmp(args[1], "http")) curproxy->mode = PR_MODE_HTTP; |
| 2078 | else if (!strcmp(args[1], "tcp")) curproxy->mode = PR_MODE_TCP; |
| 2079 | else if (!strcmp(args[1], "health")) curproxy->mode = PR_MODE_HEALTH; |
| 2080 | else { |
| 2081 | 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] | 2082 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2083 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2084 | } |
| 2085 | } |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2086 | else if (!strcmp(args[0], "id")) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2087 | struct eb32_node *node; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2088 | |
| 2089 | if (curproxy == &defproxy) { |
| 2090 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", |
| 2091 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2092 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2093 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2094 | } |
| 2095 | |
| 2096 | if (!*args[1]) { |
| 2097 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 2098 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2099 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2100 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2101 | } |
| 2102 | |
| 2103 | curproxy->uuid = atol(args[1]); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2104 | curproxy->conf.id.key = curproxy->uuid; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2105 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2106 | if (curproxy->uuid <= 0) { |
| 2107 | Alert("parsing [%s:%d]: custom id has to be > 0.\n", |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2108 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2109 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2110 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2111 | } |
| 2112 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2113 | node = eb32_lookup(&used_proxy_id, curproxy->uuid); |
| 2114 | if (node) { |
| 2115 | struct proxy *target = container_of(node, struct proxy, conf.id); |
| 2116 | Alert("parsing [%s:%d]: %s %s reuses same custom id as %s %s (declared at %s:%d).\n", |
| 2117 | file, linenum, proxy_type_str(curproxy), curproxy->id, |
| 2118 | proxy_type_str(target), target->id, target->conf.file, target->conf.line); |
| 2119 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2120 | goto out; |
| 2121 | } |
| 2122 | eb32_insert(&used_proxy_id, &curproxy->conf.id); |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2123 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 2124 | else if (!strcmp(args[0], "description")) { |
| 2125 | int i, len=0; |
| 2126 | char *d; |
| 2127 | |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 2128 | if (curproxy == &defproxy) { |
| 2129 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", |
| 2130 | file, linenum, args[0]); |
| 2131 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2132 | goto out; |
| 2133 | } |
| 2134 | |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 2135 | if (!*args[1]) { |
| 2136 | Alert("parsing [%s:%d]: '%s' expects a string argument.\n", |
| 2137 | file, linenum, args[0]); |
| 2138 | return -1; |
| 2139 | } |
| 2140 | |
| 2141 | for(i=1; *args[i]; i++) |
| 2142 | len += strlen(args[i])+1; |
| 2143 | |
| 2144 | d = (char *)calloc(1, len); |
| 2145 | curproxy->desc = d; |
| 2146 | |
| 2147 | d += sprintf(d, "%s", args[1]); |
| 2148 | for(i=2; *args[i]; i++) |
| 2149 | d += sprintf(d, " %s", args[i]); |
| 2150 | |
| 2151 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2152 | else if (!strcmp(args[0], "disabled")) { /* disables this proxy */ |
| 2153 | curproxy->state = PR_STSTOPPED; |
| 2154 | } |
| 2155 | else if (!strcmp(args[0], "enabled")) { /* enables this proxy (used to revert a disabled default) */ |
| 2156 | curproxy->state = PR_STNEW; |
| 2157 | } |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2158 | else if (!strcmp(args[0], "bind-process")) { /* enable this proxy only on some processes */ |
| 2159 | int cur_arg = 1; |
| 2160 | unsigned int set = 0; |
| 2161 | |
| 2162 | while (*args[cur_arg]) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 2163 | unsigned int low, high; |
| 2164 | |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2165 | if (strcmp(args[cur_arg], "all") == 0) { |
| 2166 | set = 0; |
| 2167 | break; |
| 2168 | } |
| 2169 | else if (strcmp(args[cur_arg], "odd") == 0) { |
| 2170 | set |= 0x55555555; |
| 2171 | } |
| 2172 | else if (strcmp(args[cur_arg], "even") == 0) { |
| 2173 | set |= 0xAAAAAAAA; |
| 2174 | } |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 2175 | else if (isdigit((int)*args[cur_arg])) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 2176 | char *dash = strchr(args[cur_arg], '-'); |
| 2177 | |
| 2178 | low = high = str2uic(args[cur_arg]); |
| 2179 | if (dash) |
| 2180 | high = str2uic(dash + 1); |
| 2181 | |
| 2182 | if (high < low) { |
| 2183 | unsigned int swap = low; |
| 2184 | low = high; |
| 2185 | high = swap; |
| 2186 | } |
| 2187 | |
| 2188 | if (low < 1 || high > 32) { |
| 2189 | 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] | 2190 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2191 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2192 | goto out; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2193 | } |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 2194 | |
| 2195 | if (high > global.nbproc) { |
| 2196 | Warning("parsing [%s:%d]: %s references process number %d which is higher than global.nbproc (%d).\n", |
| 2197 | file, linenum, args[0], high, global.nbproc); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2198 | err_code |= ERR_WARN; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2199 | } |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 2200 | while (low <= high) |
| 2201 | set |= 1 << (low++ - 1); |
| 2202 | } |
| 2203 | else { |
| 2204 | Alert("parsing [%s:%d]: %s expects 'all', 'odd', 'even', or a list of process ranges with numbers from 1 to 32.\n", |
| 2205 | file, linenum, args[0]); |
| 2206 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2207 | goto out; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2208 | } |
| 2209 | cur_arg++; |
| 2210 | } |
| 2211 | curproxy->bind_proc = set; |
| 2212 | } |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 2213 | else if (!strcmp(args[0], "acl")) { /* add an ACL */ |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2214 | if (curproxy == &defproxy) { |
| 2215 | 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] | 2216 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2217 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2218 | } |
| 2219 | |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 2220 | err = invalid_char(args[1]); |
| 2221 | if (err) { |
| 2222 | Alert("parsing [%s:%d] : character '%c' is not permitted in acl name '%s'.\n", |
| 2223 | file, linenum, *err, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2224 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 2225 | } |
| 2226 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 2227 | if (parse_acl((const char **)args + 1, &curproxy->acl, &errmsg) == NULL) { |
| 2228 | Alert("parsing [%s:%d] : error detected while parsing ACL '%s' : %s.\n", |
| 2229 | file, linenum, args[1], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2230 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2231 | goto out; |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 2232 | } |
| 2233 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2234 | else if (!strcmp(args[0], "cookie")) { /* cookie name */ |
| 2235 | int cur_arg; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2236 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2237 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2238 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2239 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2240 | if (*(args[1]) == 0) { |
| 2241 | Alert("parsing [%s:%d] : '%s' expects <cookie_name> as argument.\n", |
| 2242 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2243 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2244 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2245 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2246 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2247 | curproxy->ck_opts = 0; |
Willy Tarreau | c63d4bb | 2010-10-23 11:37:27 +0200 | [diff] [blame] | 2248 | curproxy->cookie_maxidle = curproxy->cookie_maxlife = 0; |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 2249 | free(curproxy->cookie_domain); curproxy->cookie_domain = NULL; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2250 | free(curproxy->cookie_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2251 | curproxy->cookie_name = strdup(args[1]); |
| 2252 | curproxy->cookie_len = strlen(curproxy->cookie_name); |
Willy Tarreau | c63d4bb | 2010-10-23 11:37:27 +0200 | [diff] [blame] | 2253 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2254 | cur_arg = 2; |
| 2255 | while (*(args[cur_arg])) { |
| 2256 | if (!strcmp(args[cur_arg], "rewrite")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2257 | curproxy->ck_opts |= PR_CK_RW; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2258 | } |
| 2259 | else if (!strcmp(args[cur_arg], "indirect")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2260 | curproxy->ck_opts |= PR_CK_IND; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2261 | } |
| 2262 | else if (!strcmp(args[cur_arg], "insert")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2263 | curproxy->ck_opts |= PR_CK_INS; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2264 | } |
| 2265 | else if (!strcmp(args[cur_arg], "nocache")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2266 | curproxy->ck_opts |= PR_CK_NOC; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2267 | } |
| 2268 | else if (!strcmp(args[cur_arg], "postonly")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2269 | curproxy->ck_opts |= PR_CK_POST; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2270 | } |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 2271 | else if (!strcmp(args[cur_arg], "preserve")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2272 | curproxy->ck_opts |= PR_CK_PSV; |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 2273 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2274 | else if (!strcmp(args[cur_arg], "prefix")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2275 | curproxy->ck_opts |= PR_CK_PFX; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2276 | } |
Willy Tarreau | 4992dd2 | 2012-05-31 21:02:17 +0200 | [diff] [blame] | 2277 | else if (!strcmp(args[cur_arg], "httponly")) { |
| 2278 | curproxy->ck_opts |= PR_CK_HTTPONLY; |
| 2279 | } |
| 2280 | else if (!strcmp(args[cur_arg], "secure")) { |
| 2281 | curproxy->ck_opts |= PR_CK_SECURE; |
| 2282 | } |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2283 | else if (!strcmp(args[cur_arg], "domain")) { |
| 2284 | if (!*args[cur_arg + 1]) { |
| 2285 | Alert("parsing [%s:%d]: '%s' expects <domain> as argument.\n", |
| 2286 | file, linenum, args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2287 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2288 | goto out; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2289 | } |
| 2290 | |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 2291 | if (*args[cur_arg + 1] != '.' || !strchr(args[cur_arg + 1] + 1, '.')) { |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2292 | /* rfc2109, 4.3.2 Rejecting Cookies */ |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 2293 | Warning("parsing [%s:%d]: domain '%s' contains no embedded" |
| 2294 | " dots nor does not start with a dot." |
| 2295 | " RFC forbids it, this configuration may not work properly.\n", |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2296 | file, linenum, args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 2297 | err_code |= ERR_WARN; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2298 | } |
| 2299 | |
| 2300 | err = invalid_domainchar(args[cur_arg + 1]); |
| 2301 | if (err) { |
| 2302 | Alert("parsing [%s:%d]: character '%c' is not permitted in domain name '%s'.\n", |
| 2303 | file, linenum, *err, args[cur_arg + 1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2304 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2305 | goto out; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2306 | } |
| 2307 | |
Willy Tarreau | 68a897b | 2009-12-03 23:28:34 +0100 | [diff] [blame] | 2308 | if (!curproxy->cookie_domain) { |
| 2309 | curproxy->cookie_domain = strdup(args[cur_arg + 1]); |
| 2310 | } else { |
| 2311 | /* one domain was already specified, add another one by |
| 2312 | * building the string which will be returned along with |
| 2313 | * the cookie. |
| 2314 | */ |
| 2315 | char *new_ptr; |
| 2316 | int new_len = strlen(curproxy->cookie_domain) + |
| 2317 | strlen("; domain=") + strlen(args[cur_arg + 1]) + 1; |
| 2318 | new_ptr = malloc(new_len); |
| 2319 | snprintf(new_ptr, new_len, "%s; domain=%s", curproxy->cookie_domain, args[cur_arg+1]); |
| 2320 | free(curproxy->cookie_domain); |
| 2321 | curproxy->cookie_domain = new_ptr; |
| 2322 | } |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 2323 | cur_arg++; |
| 2324 | } |
| 2325 | else if (!strcmp(args[cur_arg], "maxidle")) { |
| 2326 | unsigned int maxidle; |
| 2327 | const char *res; |
| 2328 | |
| 2329 | if (!*args[cur_arg + 1]) { |
| 2330 | Alert("parsing [%s:%d]: '%s' expects <idletime> in seconds as argument.\n", |
| 2331 | file, linenum, args[cur_arg]); |
| 2332 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2333 | goto out; |
| 2334 | } |
| 2335 | |
| 2336 | res = parse_time_err(args[cur_arg + 1], &maxidle, TIME_UNIT_S); |
| 2337 | if (res) { |
| 2338 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 2339 | file, linenum, *res, args[cur_arg]); |
| 2340 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2341 | goto out; |
| 2342 | } |
| 2343 | curproxy->cookie_maxidle = maxidle; |
| 2344 | cur_arg++; |
| 2345 | } |
| 2346 | else if (!strcmp(args[cur_arg], "maxlife")) { |
| 2347 | unsigned int maxlife; |
| 2348 | const char *res; |
| 2349 | |
| 2350 | if (!*args[cur_arg + 1]) { |
| 2351 | Alert("parsing [%s:%d]: '%s' expects <lifetime> in seconds as argument.\n", |
| 2352 | file, linenum, args[cur_arg]); |
| 2353 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2354 | goto out; |
| 2355 | } |
| 2356 | |
| 2357 | res = parse_time_err(args[cur_arg + 1], &maxlife, TIME_UNIT_S); |
| 2358 | if (res) { |
| 2359 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 2360 | file, linenum, *res, args[cur_arg]); |
| 2361 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2362 | goto out; |
| 2363 | } |
| 2364 | curproxy->cookie_maxlife = maxlife; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2365 | cur_arg++; |
| 2366 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2367 | else { |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 2368 | 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] | 2369 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2370 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2371 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2372 | } |
| 2373 | cur_arg++; |
| 2374 | } |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2375 | if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_IND))) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2376 | Alert("parsing [%s:%d] : cookie 'rewrite' and 'indirect' modes are incompatible.\n", |
| 2377 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2378 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2379 | } |
| 2380 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2381 | 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] | 2382 | Alert("parsing [%s:%d] : cookie 'rewrite', 'insert' and 'prefix' modes are incompatible.\n", |
| 2383 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2384 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2385 | } |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 2386 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2387 | 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] | 2388 | Alert("parsing [%s:%d] : cookie 'preserve' requires at least 'insert' or 'indirect'.\n", |
| 2389 | file, linenum); |
| 2390 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2391 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2392 | }/* end else if (!strcmp(args[0], "cookie")) */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2393 | else if (!strcmp(args[0], "persist")) { /* persist */ |
| 2394 | if (*(args[1]) == 0) { |
| 2395 | Alert("parsing [%s:%d] : missing persist method.\n", |
| 2396 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2397 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2398 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2399 | } |
| 2400 | |
| 2401 | if (!strncmp(args[1], "rdp-cookie", 10)) { |
| 2402 | curproxy->options2 |= PR_O2_RDPC_PRST; |
| 2403 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2404 | if (*(args[1] + 10) == '(') { /* cookie name */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2405 | const char *beg, *end; |
| 2406 | |
| 2407 | beg = args[1] + 11; |
| 2408 | end = strchr(beg, ')'); |
| 2409 | |
| 2410 | if (!end || end == beg) { |
| 2411 | Alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n", |
| 2412 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2413 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2414 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2415 | } |
| 2416 | |
| 2417 | free(curproxy->rdp_cookie_name); |
| 2418 | curproxy->rdp_cookie_name = my_strndup(beg, end - beg); |
| 2419 | curproxy->rdp_cookie_len = end-beg; |
| 2420 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2421 | else if (*(args[1] + 10) == '\0') { /* default cookie name 'msts' */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2422 | free(curproxy->rdp_cookie_name); |
| 2423 | curproxy->rdp_cookie_name = strdup("msts"); |
| 2424 | curproxy->rdp_cookie_len = strlen(curproxy->rdp_cookie_name); |
| 2425 | } |
| 2426 | else { /* syntax */ |
| 2427 | Alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n", |
| 2428 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2429 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2430 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2431 | } |
| 2432 | } |
| 2433 | else { |
| 2434 | Alert("parsing [%s:%d] : unknown persist method.\n", |
| 2435 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2436 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2437 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2438 | } |
| 2439 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2440 | else if (!strcmp(args[0], "appsession")) { /* cookie name */ |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2441 | int cur_arg; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2442 | |
Cyril Bonté | 3b7a369 | 2010-01-10 17:01:47 +0100 | [diff] [blame] | 2443 | if (curproxy == &defproxy) { |
| 2444 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2445 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2446 | goto out; |
| 2447 | } |
| 2448 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2449 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2450 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2451 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2452 | if (*(args[5]) == 0) { |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2453 | 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] | 2454 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2455 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2456 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2457 | } |
| 2458 | have_appsession = 1; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2459 | free(curproxy->appsession_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2460 | curproxy->appsession_name = strdup(args[1]); |
| 2461 | curproxy->appsession_name_len = strlen(curproxy->appsession_name); |
| 2462 | curproxy->appsession_len = atoi(args[3]); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 2463 | err = parse_time_err(args[5], &val, TIME_UNIT_MS); |
| 2464 | if (err) { |
| 2465 | Alert("parsing [%s:%d] : unexpected character '%c' in %s timeout.\n", |
| 2466 | file, linenum, *err, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2467 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2468 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 2469 | } |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 2470 | curproxy->timeout.appsession = val; |
Willy Tarreau | ee99136 | 2007-05-14 14:37:50 +0200 | [diff] [blame] | 2471 | |
Willy Tarreau | 51041c7 | 2007-09-09 21:56:53 +0200 | [diff] [blame] | 2472 | if (appsession_hash_init(&(curproxy->htbl_proxy), destroy) == 0) { |
| 2473 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2474 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2475 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2476 | } |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2477 | |
| 2478 | cur_arg = 6; |
| 2479 | curproxy->options2 &= ~PR_O2_AS_REQL; |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2480 | curproxy->options2 &= ~PR_O2_AS_M_ANY; |
| 2481 | curproxy->options2 |= PR_O2_AS_M_PP; |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2482 | while (*(args[cur_arg])) { |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2483 | if (!strcmp(args[cur_arg], "request-learn")) { |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2484 | curproxy->options2 |= PR_O2_AS_REQL; |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2485 | } else if (!strcmp(args[cur_arg], "prefix")) { |
| 2486 | curproxy->options2 |= PR_O2_AS_PFX; |
| 2487 | } else if (!strcmp(args[cur_arg], "mode")) { |
| 2488 | if (!*args[cur_arg + 1]) { |
| 2489 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 2490 | file, linenum, args[0], args[cur_arg]); |
| 2491 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2492 | goto out; |
| 2493 | } |
| 2494 | |
| 2495 | cur_arg++; |
| 2496 | if (!strcmp(args[cur_arg], "query-string")) { |
| 2497 | curproxy->options2 &= ~PR_O2_AS_M_ANY; |
| 2498 | curproxy->options2 |= PR_O2_AS_M_QS; |
| 2499 | } else if (!strcmp(args[cur_arg], "path-parameters")) { |
| 2500 | curproxy->options2 &= ~PR_O2_AS_M_ANY; |
| 2501 | curproxy->options2 |= PR_O2_AS_M_PP; |
| 2502 | } else { |
| 2503 | Alert("parsing [%s:%d] : unknown mode '%s'\n", file, linenum, args[cur_arg]); |
| 2504 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2505 | goto out; |
| 2506 | } |
| 2507 | } |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2508 | cur_arg++; |
| 2509 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2510 | } /* Url App Session */ |
| 2511 | else if (!strcmp(args[0], "capture")) { |
Willy Tarreau | 3b6b1a9 | 2009-07-23 13:24:23 +0200 | [diff] [blame] | 2512 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2513 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2514 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2515 | if (!strcmp(args[1], "cookie")) { /* name of a cookie to capture */ |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 2516 | if (curproxy == &defproxy) { |
| 2517 | Alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
| 2518 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2519 | goto out; |
| 2520 | } |
| 2521 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2522 | if (*(args[4]) == 0) { |
| 2523 | Alert("parsing [%s:%d] : '%s' expects 'cookie' <cookie_name> 'len' <len>.\n", |
| 2524 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2525 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2526 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2527 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2528 | free(curproxy->capture_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2529 | curproxy->capture_name = strdup(args[2]); |
| 2530 | curproxy->capture_namelen = strlen(curproxy->capture_name); |
| 2531 | curproxy->capture_len = atol(args[4]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2532 | curproxy->to_log |= LW_COOKIE; |
| 2533 | } |
| 2534 | else if (!strcmp(args[1], "request") && !strcmp(args[2], "header")) { |
| 2535 | struct cap_hdr *hdr; |
| 2536 | |
| 2537 | if (curproxy == &defproxy) { |
| 2538 | Alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2539 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2540 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2541 | } |
| 2542 | |
| 2543 | if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) { |
| 2544 | Alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n", |
| 2545 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2546 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2547 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2548 | } |
| 2549 | |
| 2550 | hdr = calloc(sizeof(struct cap_hdr), 1); |
| 2551 | hdr->next = curproxy->req_cap; |
| 2552 | hdr->name = strdup(args[3]); |
| 2553 | hdr->namelen = strlen(args[3]); |
| 2554 | hdr->len = atol(args[5]); |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 2555 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2556 | hdr->index = curproxy->nb_req_cap++; |
| 2557 | curproxy->req_cap = hdr; |
| 2558 | curproxy->to_log |= LW_REQHDR; |
| 2559 | } |
| 2560 | else if (!strcmp(args[1], "response") && !strcmp(args[2], "header")) { |
| 2561 | struct cap_hdr *hdr; |
| 2562 | |
| 2563 | if (curproxy == &defproxy) { |
| 2564 | 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] | 2565 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2566 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2567 | } |
| 2568 | |
| 2569 | if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) { |
| 2570 | Alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n", |
| 2571 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2572 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2573 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2574 | } |
| 2575 | hdr = calloc(sizeof(struct cap_hdr), 1); |
| 2576 | hdr->next = curproxy->rsp_cap; |
| 2577 | hdr->name = strdup(args[3]); |
| 2578 | hdr->namelen = strlen(args[3]); |
| 2579 | hdr->len = atol(args[5]); |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 2580 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2581 | hdr->index = curproxy->nb_rsp_cap++; |
| 2582 | curproxy->rsp_cap = hdr; |
| 2583 | curproxy->to_log |= LW_RSPHDR; |
| 2584 | } |
| 2585 | else { |
| 2586 | Alert("parsing [%s:%d] : '%s' expects 'cookie' or 'request header' or 'response header'.\n", |
| 2587 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2588 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2589 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2590 | } |
| 2591 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2592 | else if (!strcmp(args[0], "retries")) { /* connection retries */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2593 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2594 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2595 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2596 | if (*(args[1]) == 0) { |
| 2597 | Alert("parsing [%s:%d] : '%s' expects an integer argument (dispatch counts for one).\n", |
| 2598 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2599 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2600 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2601 | } |
| 2602 | curproxy->conn_retries = atol(args[1]); |
| 2603 | } |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2604 | 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] | 2605 | struct http_req_rule *rule; |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2606 | |
| 2607 | if (curproxy == &defproxy) { |
| 2608 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2609 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2610 | goto out; |
| 2611 | } |
| 2612 | |
Willy Tarreau | 20b0de5 | 2012-12-24 15:45:22 +0100 | [diff] [blame] | 2613 | if (!LIST_ISEMPTY(&curproxy->http_req_rules) && |
| 2614 | !LIST_PREV(&curproxy->http_req_rules, struct http_req_rule *, list)->cond && |
| 2615 | (LIST_PREV(&curproxy->http_req_rules, struct http_req_rule *, list)->action == HTTP_REQ_ACT_ALLOW || |
| 2616 | LIST_PREV(&curproxy->http_req_rules, struct http_req_rule *, list)->action == HTTP_REQ_ACT_DENY || |
| 2617 | LIST_PREV(&curproxy->http_req_rules, struct http_req_rule *, list)->action == HTTP_REQ_ACT_AUTH)) { |
| 2618 | 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] | 2619 | file, linenum, args[0]); |
| 2620 | err_code |= ERR_WARN; |
| 2621 | } |
| 2622 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 2623 | 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] | 2624 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 2625 | if (!rule) { |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2626 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2627 | goto out; |
| 2628 | } |
| 2629 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 2630 | err_code |= warnif_cond_requires_resp(rule->cond, file, linenum); |
| 2631 | LIST_ADDQ(&curproxy->http_req_rules, &rule->list); |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2632 | } |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 2633 | else if (!strcmp(args[0], "http-send-name-header")) { /* send server name in request header */ |
| 2634 | /* set the header name and length into the proxy structure */ |
| 2635 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 2636 | err_code |= ERR_WARN; |
| 2637 | |
| 2638 | if (!*args[1]) { |
| 2639 | Alert("parsing [%s:%d] : '%s' requires a header string.\n", |
| 2640 | file, linenum, args[0]); |
| 2641 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2642 | goto out; |
| 2643 | } |
| 2644 | |
| 2645 | /* set the desired header name */ |
| 2646 | free(curproxy->server_id_hdr_name); |
| 2647 | curproxy->server_id_hdr_name = strdup(args[1]); |
| 2648 | curproxy->server_id_hdr_len = strlen(curproxy->server_id_hdr_name); |
| 2649 | } |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2650 | else if (!strcmp(args[0], "block")) { /* early blocking based on ACLs */ |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2651 | if (curproxy == &defproxy) { |
| 2652 | 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] | 2653 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2654 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2655 | } |
| 2656 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2657 | if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) { |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2658 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 2659 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2660 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2661 | goto out; |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2662 | } |
| 2663 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 2664 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 1, &errmsg)) == NULL) { |
| 2665 | Alert("parsing [%s:%d] : error detected while parsing blocking condition : %s.\n", |
| 2666 | file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2667 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2668 | goto out; |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2669 | } |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2670 | |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2671 | LIST_ADDQ(&curproxy->block_cond, &cond->list); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 2672 | warnif_misplaced_block(curproxy, file, linenum, args[0]); |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2673 | } |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2674 | else if (!strcmp(args[0], "redirect")) { |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2675 | struct redirect_rule *rule; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2676 | |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 2677 | if (curproxy == &defproxy) { |
| 2678 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2679 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2680 | goto out; |
| 2681 | } |
| 2682 | |
Willy Tarreau | 4baae24 | 2012-12-27 12:00:31 +0100 | [diff] [blame] | 2683 | if ((rule = http_parse_redirect_rule(file, linenum, curproxy, (const char **)args + 1, &errmsg)) == NULL) { |
| 2684 | Alert("parsing [%s:%d] : error detected in %s '%s' while parsing redirect rule : %s.\n", |
| 2685 | file, linenum, proxy_type_str(curproxy), curproxy->id, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2686 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2687 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2688 | } |
| 2689 | |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2690 | LIST_ADDQ(&curproxy->redirect_rules, &rule->list); |
Willy Tarreau | 9d9ed01 | 2011-02-23 15:24:42 +0100 | [diff] [blame] | 2691 | err_code |= warnif_rule_after_use_backend(curproxy, file, linenum, args[0]); |
Willy Tarreau | 2f47651 | 2013-03-25 19:16:31 +0100 | [diff] [blame^] | 2692 | err_code |= warnif_cond_requires_resp(rule->cond, file, linenum); |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2693 | } |
Krzysztof Piotr Oledzki | 7b723ef | 2009-01-27 21:09:41 +0100 | [diff] [blame] | 2694 | else if (!strcmp(args[0], "use_backend")) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2695 | struct switching_rule *rule; |
| 2696 | |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2697 | if (curproxy == &defproxy) { |
| 2698 | 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] | 2699 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2700 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2701 | } |
| 2702 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2703 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2704 | err_code |= ERR_WARN; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2705 | |
| 2706 | if (*(args[1]) == 0) { |
| 2707 | 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] | 2708 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2709 | goto out; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2710 | } |
| 2711 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2712 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2713 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 2714 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2715 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2716 | goto out; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2717 | } |
| 2718 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 2719 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 2720 | Alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n", |
| 2721 | file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2722 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2723 | goto out; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2724 | } |
| 2725 | |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 2726 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
Willy Tarreau | a980263 | 2008-07-25 19:13:19 +0200 | [diff] [blame] | 2727 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2728 | rule = (struct switching_rule *)calloc(1, sizeof(*rule)); |
| 2729 | rule->cond = cond; |
| 2730 | rule->be.name = strdup(args[1]); |
| 2731 | LIST_INIT(&rule->list); |
| 2732 | LIST_ADDQ(&curproxy->switching_rules, &rule->list); |
| 2733 | } |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 2734 | else if (strcmp(args[0], "use-server") == 0) { |
| 2735 | struct server_rule *rule; |
| 2736 | |
| 2737 | if (curproxy == &defproxy) { |
| 2738 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2739 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2740 | goto out; |
| 2741 | } |
| 2742 | |
| 2743 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 2744 | err_code |= ERR_WARN; |
| 2745 | |
| 2746 | if (*(args[1]) == 0) { |
| 2747 | Alert("parsing [%s:%d] : '%s' expects a server name.\n", file, linenum, args[0]); |
| 2748 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2749 | goto out; |
| 2750 | } |
| 2751 | |
| 2752 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
| 2753 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 2754 | file, linenum, args[0]); |
| 2755 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2756 | goto out; |
| 2757 | } |
| 2758 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 2759 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 2760 | Alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n", |
| 2761 | file, linenum, errmsg); |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 2762 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2763 | goto out; |
| 2764 | } |
| 2765 | |
| 2766 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
| 2767 | |
| 2768 | rule = (struct server_rule *)calloc(1, sizeof(*rule)); |
| 2769 | rule->cond = cond; |
| 2770 | rule->srv.name = strdup(args[1]); |
| 2771 | LIST_INIT(&rule->list); |
| 2772 | LIST_ADDQ(&curproxy->server_rules, &rule->list); |
| 2773 | curproxy->be_req_ana |= AN_REQ_SRV_RULES; |
| 2774 | } |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 2775 | else if ((!strcmp(args[0], "force-persist")) || |
| 2776 | (!strcmp(args[0], "ignore-persist"))) { |
| 2777 | struct persist_rule *rule; |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2778 | |
| 2779 | if (curproxy == &defproxy) { |
| 2780 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2781 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2782 | goto out; |
| 2783 | } |
| 2784 | |
| 2785 | if (warnifnotcap(curproxy, PR_CAP_FE|PR_CAP_BE, file, linenum, args[0], NULL)) |
| 2786 | err_code |= ERR_WARN; |
| 2787 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 2788 | if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) { |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2789 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 2790 | file, linenum, args[0]); |
| 2791 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2792 | goto out; |
| 2793 | } |
| 2794 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 2795 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 1, &errmsg)) == NULL) { |
| 2796 | Alert("parsing [%s:%d] : error detected while parsing a '%s' rule : %s.\n", |
| 2797 | file, linenum, args[0], errmsg); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2798 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2799 | goto out; |
| 2800 | } |
| 2801 | |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 2802 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2803 | |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 2804 | rule = (struct persist_rule *)calloc(1, sizeof(*rule)); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2805 | rule->cond = cond; |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 2806 | if (!strcmp(args[0], "force-persist")) { |
| 2807 | rule->type = PERSIST_TYPE_FORCE; |
| 2808 | } else { |
| 2809 | rule->type = PERSIST_TYPE_IGNORE; |
| 2810 | } |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2811 | LIST_INIT(&rule->list); |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 2812 | LIST_ADDQ(&curproxy->persist_rules, &rule->list); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 2813 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2814 | else if (!strcmp(args[0], "stick-table")) { |
| 2815 | int myidx = 1; |
| 2816 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2817 | curproxy->table.id = curproxy->id; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2818 | curproxy->table.type = (unsigned int)-1; |
| 2819 | while (*args[myidx]) { |
| 2820 | const char *err; |
| 2821 | |
| 2822 | if (strcmp(args[myidx], "size") == 0) { |
| 2823 | myidx++; |
| 2824 | if (!*(args[myidx])) { |
| 2825 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 2826 | file, linenum, args[myidx-1]); |
| 2827 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2828 | goto out; |
| 2829 | } |
| 2830 | if ((err = parse_size_err(args[myidx], &curproxy->table.size))) { |
| 2831 | Alert("parsing [%s:%d] : stick-table: unexpected character '%c' in argument of '%s'.\n", |
| 2832 | file, linenum, *err, args[myidx-1]); |
| 2833 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2834 | goto out; |
| 2835 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 2836 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2837 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2838 | else if (strcmp(args[myidx], "peers") == 0) { |
| 2839 | myidx++; |
| 2840 | if (!*(args[myidx])) { |
| 2841 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 2842 | file, linenum, args[myidx-1]); |
| 2843 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2844 | goto out; |
| 2845 | } |
| 2846 | curproxy->table.peers.name = strdup(args[myidx++]); |
| 2847 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2848 | else if (strcmp(args[myidx], "expire") == 0) { |
| 2849 | myidx++; |
| 2850 | if (!*(args[myidx])) { |
| 2851 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 2852 | file, linenum, args[myidx-1]); |
| 2853 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2854 | goto out; |
| 2855 | } |
| 2856 | err = parse_time_err(args[myidx], &val, TIME_UNIT_MS); |
| 2857 | if (err) { |
| 2858 | Alert("parsing [%s:%d] : stick-table: unexpected character '%c' in argument of '%s'.\n", |
| 2859 | file, linenum, *err, args[myidx-1]); |
| 2860 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2861 | goto out; |
| 2862 | } |
| 2863 | curproxy->table.expire = val; |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 2864 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2865 | } |
| 2866 | else if (strcmp(args[myidx], "nopurge") == 0) { |
| 2867 | curproxy->table.nopurge = 1; |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 2868 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2869 | } |
| 2870 | else if (strcmp(args[myidx], "type") == 0) { |
| 2871 | myidx++; |
| 2872 | if (stktable_parse_type(args, &myidx, &curproxy->table.type, &curproxy->table.key_size) != 0) { |
| 2873 | Alert("parsing [%s:%d] : stick-table: unknown type '%s'.\n", |
| 2874 | file, linenum, args[myidx]); |
| 2875 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2876 | goto out; |
| 2877 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 2878 | /* myidx already points to next arg */ |
| 2879 | } |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 2880 | else if (strcmp(args[myidx], "store") == 0) { |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 2881 | int type, err; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 2882 | char *cw, *nw, *sa; |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 2883 | |
| 2884 | myidx++; |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 2885 | nw = args[myidx]; |
| 2886 | while (*nw) { |
| 2887 | /* the "store" keyword supports a comma-separated list */ |
| 2888 | cw = nw; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 2889 | sa = NULL; /* store arg */ |
| 2890 | while (*nw && *nw != ',') { |
| 2891 | if (*nw == '(') { |
| 2892 | *nw = 0; |
| 2893 | sa = ++nw; |
| 2894 | while (*nw != ')') { |
| 2895 | if (!*nw) { |
| 2896 | Alert("parsing [%s:%d] : %s: missing closing parenthesis after store option '%s'.\n", |
| 2897 | file, linenum, args[0], cw); |
| 2898 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2899 | goto out; |
| 2900 | } |
| 2901 | nw++; |
| 2902 | } |
| 2903 | *nw = '\0'; |
| 2904 | } |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 2905 | nw++; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 2906 | } |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 2907 | if (*nw) |
| 2908 | *nw++ = '\0'; |
| 2909 | type = stktable_get_data_type(cw); |
| 2910 | if (type < 0) { |
| 2911 | Alert("parsing [%s:%d] : %s: unknown store option '%s'.\n", |
| 2912 | file, linenum, args[0], cw); |
| 2913 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2914 | goto out; |
| 2915 | } |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 2916 | |
| 2917 | err = stktable_alloc_data_type(&curproxy->table, type, sa); |
| 2918 | switch (err) { |
| 2919 | case PE_NONE: break; |
| 2920 | case PE_EXIST: |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 2921 | Warning("parsing [%s:%d]: %s: store option '%s' already enabled, ignored.\n", |
| 2922 | file, linenum, args[0], cw); |
| 2923 | err_code |= ERR_WARN; |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 2924 | break; |
| 2925 | |
| 2926 | case PE_ARG_MISSING: |
| 2927 | Alert("parsing [%s:%d] : %s: missing argument to store option '%s'.\n", |
| 2928 | file, linenum, args[0], cw); |
| 2929 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2930 | goto out; |
| 2931 | |
| 2932 | case PE_ARG_NOT_USED: |
| 2933 | Alert("parsing [%s:%d] : %s: unexpected argument to store option '%s'.\n", |
| 2934 | file, linenum, args[0], cw); |
| 2935 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2936 | goto out; |
| 2937 | |
| 2938 | default: |
| 2939 | Alert("parsing [%s:%d] : %s: error when processing store option '%s'.\n", |
| 2940 | file, linenum, args[0], cw); |
| 2941 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2942 | goto out; |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 2943 | } |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 2944 | } |
| 2945 | myidx++; |
| 2946 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 2947 | else { |
| 2948 | Alert("parsing [%s:%d] : stick-table: unknown argument '%s'.\n", |
| 2949 | file, linenum, args[myidx]); |
| 2950 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2951 | goto out; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2952 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2953 | } |
| 2954 | |
| 2955 | if (!curproxy->table.size) { |
| 2956 | Alert("parsing [%s:%d] : stick-table: missing size.\n", |
| 2957 | file, linenum); |
| 2958 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2959 | goto out; |
| 2960 | } |
| 2961 | |
| 2962 | if (curproxy->table.type == (unsigned int)-1) { |
| 2963 | Alert("parsing [%s:%d] : stick-table: missing type.\n", |
| 2964 | file, linenum); |
| 2965 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2966 | goto out; |
| 2967 | } |
| 2968 | } |
| 2969 | else if (!strcmp(args[0], "stick")) { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2970 | struct sticking_rule *rule; |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 2971 | struct sample_expr *expr; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2972 | int myidx = 0; |
| 2973 | const char *name = NULL; |
| 2974 | int flags; |
| 2975 | |
| 2976 | if (curproxy == &defproxy) { |
| 2977 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2978 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2979 | goto out; |
| 2980 | } |
| 2981 | |
| 2982 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) { |
| 2983 | err_code |= ERR_WARN; |
| 2984 | goto out; |
| 2985 | } |
| 2986 | |
| 2987 | myidx++; |
| 2988 | if ((strcmp(args[myidx], "store") == 0) || |
| 2989 | (strcmp(args[myidx], "store-request") == 0)) { |
| 2990 | myidx++; |
| 2991 | flags = STK_IS_STORE; |
| 2992 | } |
| 2993 | else if (strcmp(args[myidx], "store-response") == 0) { |
| 2994 | myidx++; |
| 2995 | flags = STK_IS_STORE | STK_ON_RSP; |
| 2996 | } |
| 2997 | else if (strcmp(args[myidx], "match") == 0) { |
| 2998 | myidx++; |
| 2999 | flags = STK_IS_MATCH; |
| 3000 | } |
| 3001 | else if (strcmp(args[myidx], "on") == 0) { |
| 3002 | myidx++; |
| 3003 | flags = STK_IS_MATCH | STK_IS_STORE; |
| 3004 | } |
| 3005 | else { |
| 3006 | Alert("parsing [%s:%d] : '%s' expects 'on', 'match', or 'store'.\n", file, linenum, args[0]); |
| 3007 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3008 | goto out; |
| 3009 | } |
| 3010 | |
| 3011 | if (*(args[myidx]) == 0) { |
| 3012 | Alert("parsing [%s:%d] : '%s' expects a fetch method.\n", file, linenum, args[0]); |
| 3013 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3014 | goto out; |
| 3015 | } |
| 3016 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3017 | expr = sample_parse_expr(args, &myidx, trash.str, trash.size); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3018 | if (!expr) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3019 | 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] | 3020 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3021 | goto out; |
| 3022 | } |
| 3023 | |
| 3024 | if (flags & STK_ON_RSP) { |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 3025 | if (!(expr->fetch->cap & SMP_CAP_RES)) { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3026 | Alert("parsing [%s:%d] : '%s': fetch method '%s' can not be used on response.\n", |
| 3027 | file, linenum, args[0], expr->fetch->kw); |
| 3028 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 3029 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3030 | goto out; |
| 3031 | } |
| 3032 | } else { |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 3033 | if (!(expr->fetch->cap & SMP_CAP_REQ)) { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3034 | Alert("parsing [%s:%d] : '%s': fetch method '%s' can not be used on request.\n", |
| 3035 | file, linenum, args[0], expr->fetch->kw); |
| 3036 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 3037 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3038 | goto out; |
| 3039 | } |
| 3040 | } |
| 3041 | |
Willy Tarreau | 1b6c00c | 2012-10-05 22:41:26 +0200 | [diff] [blame] | 3042 | /* check if we need to allocate an hdr_idx struct for HTTP parsing */ |
| 3043 | if (expr->fetch->cap & SMP_CAP_L7) |
| 3044 | curproxy->acl_requires |= ACL_USE_L7_ANY; |
| 3045 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3046 | if (strcmp(args[myidx], "table") == 0) { |
| 3047 | myidx++; |
| 3048 | name = args[myidx++]; |
| 3049 | } |
| 3050 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 3051 | if (strcmp(args[myidx], "if") == 0 || strcmp(args[myidx], "unless") == 0) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 3052 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + myidx, &errmsg)) == NULL) { |
| 3053 | Alert("parsing [%s:%d] : '%s': error detected while parsing sticking condition : %s.\n", |
| 3054 | file, linenum, args[0], errmsg); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3055 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 3056 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3057 | goto out; |
| 3058 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3059 | } |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 3060 | else if (*(args[myidx])) { |
| 3061 | Alert("parsing [%s:%d] : '%s': unknown keyword '%s'.\n", |
| 3062 | file, linenum, args[0], args[myidx]); |
| 3063 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 3064 | free(expr); |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 3065 | goto out; |
| 3066 | } |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 3067 | if (flags & STK_ON_RSP) |
| 3068 | err_code |= warnif_cond_requires_req(cond, file, linenum); |
| 3069 | else |
| 3070 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 3071 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3072 | rule = (struct sticking_rule *)calloc(1, sizeof(*rule)); |
| 3073 | rule->cond = cond; |
| 3074 | rule->expr = expr; |
| 3075 | rule->flags = flags; |
| 3076 | rule->table.name = name ? strdup(name) : NULL; |
| 3077 | LIST_INIT(&rule->list); |
| 3078 | if (flags & STK_ON_RSP) |
| 3079 | LIST_ADDQ(&curproxy->storersp_rules, &rule->list); |
| 3080 | else |
| 3081 | LIST_ADDQ(&curproxy->sticking_rules, &rule->list); |
| 3082 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3083 | else if (!strcmp(args[0], "stats")) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3084 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3085 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3086 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3087 | if (curproxy != &defproxy && curproxy->uri_auth == defproxy.uri_auth) |
| 3088 | curproxy->uri_auth = NULL; /* we must detach from the default config */ |
| 3089 | |
Krzysztof Piotr Oledzki | 260a3bb | 2010-01-06 16:25:05 +0100 | [diff] [blame] | 3090 | if (!*args[1]) { |
| 3091 | goto stats_error_parsing; |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3092 | } else if (!strcmp(args[1], "admin")) { |
| 3093 | struct stats_admin_rule *rule; |
| 3094 | |
| 3095 | if (curproxy == &defproxy) { |
| 3096 | Alert("parsing [%s:%d]: '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
| 3097 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3098 | goto out; |
| 3099 | } |
| 3100 | |
| 3101 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 3102 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3103 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3104 | goto out; |
| 3105 | } |
| 3106 | |
| 3107 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
| 3108 | Alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n", |
| 3109 | file, linenum, args[0], args[1]); |
| 3110 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3111 | goto out; |
| 3112 | } |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 3113 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 3114 | Alert("parsing [%s:%d] : error detected while parsing a '%s %s' rule : %s.\n", |
| 3115 | file, linenum, args[0], args[1], errmsg); |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3116 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3117 | goto out; |
| 3118 | } |
| 3119 | |
| 3120 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
| 3121 | |
| 3122 | rule = (struct stats_admin_rule *)calloc(1, sizeof(*rule)); |
| 3123 | rule->cond = cond; |
| 3124 | LIST_INIT(&rule->list); |
| 3125 | LIST_ADDQ(&curproxy->uri_auth->admin_rules, &rule->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3126 | } else if (!strcmp(args[1], "uri")) { |
| 3127 | if (*(args[2]) == 0) { |
| 3128 | Alert("parsing [%s:%d] : 'uri' needs an URI prefix.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3129 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3130 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3131 | } else if (!stats_set_uri(&curproxy->uri_auth, args[2])) { |
| 3132 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3133 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3134 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3135 | } |
| 3136 | } else if (!strcmp(args[1], "realm")) { |
| 3137 | if (*(args[2]) == 0) { |
| 3138 | Alert("parsing [%s:%d] : 'realm' needs an realm name.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3139 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3140 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3141 | } else if (!stats_set_realm(&curproxy->uri_auth, args[2])) { |
| 3142 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3143 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3144 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3145 | } |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 3146 | } else if (!strcmp(args[1], "refresh")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 3147 | unsigned interval; |
| 3148 | |
| 3149 | err = parse_time_err(args[2], &interval, TIME_UNIT_S); |
| 3150 | if (err) { |
| 3151 | Alert("parsing [%s:%d] : unexpected character '%c' in stats refresh interval.\n", |
| 3152 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3153 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3154 | goto out; |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 3155 | } else if (!stats_set_refresh(&curproxy->uri_auth, interval)) { |
| 3156 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3157 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3158 | goto out; |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 3159 | } |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3160 | } 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] | 3161 | struct http_req_rule *rule; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3162 | |
| 3163 | if (curproxy == &defproxy) { |
| 3164 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3165 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3166 | goto out; |
| 3167 | } |
| 3168 | |
| 3169 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 3170 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3171 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3172 | goto out; |
| 3173 | } |
| 3174 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3175 | if (!LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) && |
| 3176 | !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] | 3177 | Warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n", |
| 3178 | file, linenum, args[0]); |
| 3179 | err_code |= ERR_WARN; |
| 3180 | } |
| 3181 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3182 | 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] | 3183 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3184 | if (!rule) { |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3185 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3186 | goto out; |
| 3187 | } |
| 3188 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3189 | err_code |= warnif_cond_requires_resp(rule->cond, file, linenum); |
| 3190 | LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list); |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3191 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3192 | } else if (!strcmp(args[1], "auth")) { |
| 3193 | if (*(args[2]) == 0) { |
| 3194 | 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] | 3195 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3196 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3197 | } else if (!stats_add_auth(&curproxy->uri_auth, args[2])) { |
| 3198 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3199 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3200 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3201 | } |
| 3202 | } else if (!strcmp(args[1], "scope")) { |
| 3203 | if (*(args[2]) == 0) { |
| 3204 | Alert("parsing [%s:%d] : 'scope' needs a proxy name.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3205 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3206 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3207 | } else if (!stats_add_scope(&curproxy->uri_auth, args[2])) { |
| 3208 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3209 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3210 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3211 | } |
| 3212 | } else if (!strcmp(args[1], "enable")) { |
| 3213 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 3214 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3215 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3216 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3217 | } |
Krzysztof Oledzki | d9db927 | 2007-10-15 10:05:11 +0200 | [diff] [blame] | 3218 | } else if (!strcmp(args[1], "hide-version")) { |
| 3219 | if (!stats_set_flag(&curproxy->uri_auth, ST_HIDEVER)) { |
| 3220 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3221 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3222 | goto out; |
Krzysztof Oledzki | d9db927 | 2007-10-15 10:05:11 +0200 | [diff] [blame] | 3223 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3224 | } else if (!strcmp(args[1], "show-legends")) { |
| 3225 | if (!stats_set_flag(&curproxy->uri_auth, ST_SHLGNDS)) { |
| 3226 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3227 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3228 | goto out; |
| 3229 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3230 | } else if (!strcmp(args[1], "show-node")) { |
| 3231 | |
| 3232 | if (*args[2]) { |
| 3233 | int i; |
| 3234 | char c; |
| 3235 | |
| 3236 | for (i=0; args[2][i]; i++) { |
| 3237 | c = args[2][i]; |
Willy Tarreau | 88e0581 | 2010-03-03 00:16:00 +0100 | [diff] [blame] | 3238 | if (!isupper((unsigned char)c) && !islower((unsigned char)c) && |
| 3239 | !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.') |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3240 | break; |
| 3241 | } |
| 3242 | |
| 3243 | if (!i || args[2][i]) { |
| 3244 | Alert("parsing [%s:%d]: '%s %s' invalid node name - should be a string" |
| 3245 | "with digits(0-9), letters(A-Z, a-z), hyphen(-) or underscode(_).\n", |
| 3246 | file, linenum, args[0], args[1]); |
| 3247 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3248 | goto out; |
| 3249 | } |
| 3250 | } |
| 3251 | |
| 3252 | if (!stats_set_node(&curproxy->uri_auth, args[2])) { |
| 3253 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3254 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3255 | goto out; |
| 3256 | } |
| 3257 | } else if (!strcmp(args[1], "show-desc")) { |
| 3258 | char *desc = NULL; |
| 3259 | |
| 3260 | if (*args[2]) { |
| 3261 | int i, len=0; |
| 3262 | char *d; |
| 3263 | |
| 3264 | for(i=2; *args[i]; i++) |
| 3265 | len += strlen(args[i])+1; |
| 3266 | |
| 3267 | desc = d = (char *)calloc(1, len); |
| 3268 | |
| 3269 | d += sprintf(d, "%s", args[2]); |
| 3270 | for(i=3; *args[i]; i++) |
| 3271 | d += sprintf(d, " %s", args[i]); |
| 3272 | } |
| 3273 | |
| 3274 | if (!*args[2] && !global.desc) |
| 3275 | Warning("parsing [%s:%d]: '%s' requires a parameter or 'desc' to be set in the global section.\n", |
| 3276 | file, linenum, args[1]); |
| 3277 | else { |
| 3278 | if (!stats_set_desc(&curproxy->uri_auth, desc)) { |
| 3279 | free(desc); |
| 3280 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3281 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3282 | goto out; |
| 3283 | } |
| 3284 | free(desc); |
| 3285 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3286 | } else { |
Krzysztof Piotr Oledzki | 260a3bb | 2010-01-06 16:25:05 +0100 | [diff] [blame] | 3287 | stats_error_parsing: |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3288 | 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] | 3289 | 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] | 3290 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3291 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3292 | } |
| 3293 | } |
| 3294 | else if (!strcmp(args[0], "option")) { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3295 | int optnum; |
| 3296 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3297 | if (*(args[1]) == '\0') { |
| 3298 | Alert("parsing [%s:%d]: '%s' expects an option name.\n", |
| 3299 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3300 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3301 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3302 | } |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3303 | |
| 3304 | for (optnum = 0; cfg_opts[optnum].name; optnum++) { |
| 3305 | if (!strcmp(args[1], cfg_opts[optnum].name)) { |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 3306 | if (cfg_opts[optnum].cap == PR_CAP_NONE) { |
| 3307 | Alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n", |
| 3308 | file, linenum, cfg_opts[optnum].name); |
| 3309 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3310 | goto out; |
| 3311 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3312 | if (warnifnotcap(curproxy, cfg_opts[optnum].cap, file, linenum, args[1], NULL)) { |
| 3313 | err_code |= ERR_WARN; |
| 3314 | goto out; |
| 3315 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3316 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 3317 | curproxy->no_options &= ~cfg_opts[optnum].val; |
| 3318 | curproxy->options &= ~cfg_opts[optnum].val; |
| 3319 | |
| 3320 | switch (kwm) { |
| 3321 | case KWM_STD: |
| 3322 | curproxy->options |= cfg_opts[optnum].val; |
| 3323 | break; |
| 3324 | case KWM_NO: |
| 3325 | curproxy->no_options |= cfg_opts[optnum].val; |
| 3326 | break; |
| 3327 | case KWM_DEF: /* already cleared */ |
| 3328 | break; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 3329 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3330 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3331 | goto out; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3332 | } |
| 3333 | } |
| 3334 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 3335 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) { |
| 3336 | if (!strcmp(args[1], cfg_opts2[optnum].name)) { |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 3337 | if (cfg_opts2[optnum].cap == PR_CAP_NONE) { |
| 3338 | Alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n", |
| 3339 | file, linenum, cfg_opts2[optnum].name); |
| 3340 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3341 | goto out; |
| 3342 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3343 | if (warnifnotcap(curproxy, cfg_opts2[optnum].cap, file, linenum, args[1], NULL)) { |
| 3344 | err_code |= ERR_WARN; |
| 3345 | goto out; |
| 3346 | } |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 3347 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 3348 | curproxy->no_options2 &= ~cfg_opts2[optnum].val; |
| 3349 | curproxy->options2 &= ~cfg_opts2[optnum].val; |
| 3350 | |
| 3351 | switch (kwm) { |
| 3352 | case KWM_STD: |
| 3353 | curproxy->options2 |= cfg_opts2[optnum].val; |
| 3354 | break; |
| 3355 | case KWM_NO: |
| 3356 | curproxy->no_options2 |= cfg_opts2[optnum].val; |
| 3357 | break; |
| 3358 | case KWM_DEF: /* already cleared */ |
| 3359 | break; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 3360 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3361 | goto out; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 3362 | } |
| 3363 | } |
| 3364 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 3365 | if (kwm != KWM_STD) { |
| 3366 | 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] | 3367 | file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3368 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3369 | goto out; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3370 | } |
| 3371 | |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3372 | if (!strcmp(args[1], "httplog")) { |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 3373 | char *logformat; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3374 | /* generate a complete HTTP log */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 3375 | logformat = default_http_log_format; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3376 | if (*(args[2]) != '\0') { |
| 3377 | if (!strcmp(args[2], "clf")) { |
| 3378 | curproxy->options2 |= PR_O2_CLFLOG; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 3379 | logformat = clf_http_log_format; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3380 | } else { |
| 3381 | 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] | 3382 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3383 | goto out; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3384 | } |
| 3385 | } |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 3386 | if (curproxy->logformat_string != default_http_log_format && |
| 3387 | curproxy->logformat_string != default_tcp_log_format && |
| 3388 | curproxy->logformat_string != clf_http_log_format) |
| 3389 | free(curproxy->logformat_string); |
| 3390 | curproxy->logformat_string = logformat; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3391 | } |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 3392 | else if (!strcmp(args[1], "tcplog")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3393 | /* generate a detailed TCP log */ |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 3394 | if (curproxy->logformat_string != default_http_log_format && |
| 3395 | curproxy->logformat_string != default_tcp_log_format && |
| 3396 | curproxy->logformat_string != clf_http_log_format) |
| 3397 | free(curproxy->logformat_string); |
| 3398 | curproxy->logformat_string = default_tcp_log_format; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 3399 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3400 | else if (!strcmp(args[1], "tcpka")) { |
| 3401 | /* enable TCP keep-alives on client and server sessions */ |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3402 | 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] | 3403 | err_code |= ERR_WARN; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3404 | |
| 3405 | if (curproxy->cap & PR_CAP_FE) |
| 3406 | curproxy->options |= PR_O_TCP_CLI_KA; |
| 3407 | if (curproxy->cap & PR_CAP_BE) |
| 3408 | curproxy->options |= PR_O_TCP_SRV_KA; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3409 | } |
| 3410 | else if (!strcmp(args[1], "httpchk")) { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3411 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3412 | err_code |= ERR_WARN; |
| 3413 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3414 | /* use HTTP request to check servers' health */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3415 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 3416 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3417 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 3418 | curproxy->options2 |= PR_O2_HTTP_CHK; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3419 | if (!*args[2]) { /* no argument */ |
| 3420 | curproxy->check_req = strdup(DEF_CHECK_REQ); /* default request */ |
| 3421 | curproxy->check_len = strlen(DEF_CHECK_REQ); |
| 3422 | } else if (!*args[3]) { /* one argument : URI */ |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3423 | 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] | 3424 | curproxy->check_req = (char *)malloc(reqlen); |
| 3425 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3426 | "OPTIONS %s HTTP/1.0\r\n", args[2]); /* URI to use */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3427 | } else { /* more arguments : METHOD URI [HTTP_VER] */ |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3428 | int reqlen = strlen(args[2]) + strlen(args[3]) + 3 + strlen("\r\n"); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3429 | if (*args[4]) |
| 3430 | reqlen += strlen(args[4]); |
| 3431 | else |
| 3432 | reqlen += strlen("HTTP/1.0"); |
| 3433 | |
| 3434 | curproxy->check_req = (char *)malloc(reqlen); |
| 3435 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3436 | "%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] | 3437 | } |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 3438 | } |
| 3439 | else if (!strcmp(args[1], "ssl-hello-chk")) { |
| 3440 | /* use SSLv3 CLIENT HELLO to check servers' health */ |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3441 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3442 | err_code |= ERR_WARN; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3443 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3444 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 3445 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3446 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Willy Tarreau | 07a5490 | 2010-03-29 18:33:29 +0200 | [diff] [blame] | 3447 | curproxy->options2 |= PR_O2_SSL3_CHK; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3448 | } |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 3449 | else if (!strcmp(args[1], "smtpchk")) { |
| 3450 | /* use SMTP request to check servers' health */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3451 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 3452 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3453 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 3454 | curproxy->options2 |= PR_O2_SMTP_CHK; |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 3455 | |
| 3456 | if (!*args[2] || !*args[3]) { /* no argument or incomplete EHLO host */ |
| 3457 | curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */ |
| 3458 | curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ); |
| 3459 | } else { /* ESMTP EHLO, or SMTP HELO, and a hostname */ |
| 3460 | if (!strcmp(args[2], "EHLO") || !strcmp(args[2], "HELO")) { |
| 3461 | int reqlen = strlen(args[2]) + strlen(args[3]) + strlen(" \r\n") + 1; |
| 3462 | curproxy->check_req = (char *)malloc(reqlen); |
| 3463 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
| 3464 | "%s %s\r\n", args[2], args[3]); /* HELO hostname */ |
| 3465 | } else { |
| 3466 | /* this just hits the default for now, but you could potentially expand it to allow for other stuff |
| 3467 | though, it's unlikely you'd want to send anything other than an EHLO or HELO */ |
| 3468 | curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */ |
| 3469 | curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ); |
| 3470 | } |
| 3471 | } |
| 3472 | } |
Simon Horman | a2b9dad | 2013-02-12 10:45:54 +0900 | [diff] [blame] | 3473 | else if (!strcmp(args[1], "lb-agent-chk")) { |
| 3474 | /* use dynmaic health check */ |
| 3475 | free(curproxy->check_req); |
| 3476 | curproxy->check_req = NULL; |
| 3477 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 3478 | curproxy->options2 |= PR_O2_LB_AGENT_CHK; |
| 3479 | } |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 3480 | else if (!strcmp(args[1], "pgsql-check")) { |
| 3481 | /* use PostgreSQL request to check servers' health */ |
| 3482 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 3483 | err_code |= ERR_WARN; |
| 3484 | |
| 3485 | free(curproxy->check_req); |
| 3486 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3487 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 3488 | curproxy->options2 |= PR_O2_PGSQL_CHK; |
| 3489 | |
| 3490 | if (*(args[2])) { |
| 3491 | int cur_arg = 2; |
| 3492 | |
| 3493 | while (*(args[cur_arg])) { |
| 3494 | if (strcmp(args[cur_arg], "user") == 0) { |
| 3495 | char * packet; |
| 3496 | uint32_t packet_len; |
| 3497 | uint32_t pv; |
| 3498 | |
| 3499 | /* suboption header - needs additional argument for it */ |
| 3500 | if (*(args[cur_arg+1]) == 0) { |
| 3501 | Alert("parsing [%s:%d] : '%s %s %s' expects <username> as argument.\n", |
| 3502 | file, linenum, args[0], args[1], args[cur_arg]); |
| 3503 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3504 | goto out; |
| 3505 | } |
| 3506 | |
| 3507 | /* uint32_t + uint32_t + strlen("user")+1 + strlen(username)+1 + 1 */ |
| 3508 | packet_len = 4 + 4 + 5 + strlen(args[cur_arg + 1])+1 +1; |
| 3509 | pv = htonl(0x30000); /* protocol version 3.0 */ |
| 3510 | |
| 3511 | packet = (char*) calloc(1, packet_len); |
| 3512 | |
| 3513 | memcpy(packet + 4, &pv, 4); |
| 3514 | |
| 3515 | /* copy "user" */ |
| 3516 | memcpy(packet + 8, "user", 4); |
| 3517 | |
| 3518 | /* copy username */ |
| 3519 | memcpy(packet + 13, args[cur_arg+1], strlen(args[cur_arg+1])); |
| 3520 | |
| 3521 | free(curproxy->check_req); |
| 3522 | curproxy->check_req = packet; |
| 3523 | curproxy->check_len = packet_len; |
| 3524 | |
| 3525 | packet_len = htonl(packet_len); |
| 3526 | memcpy(packet, &packet_len, 4); |
| 3527 | cur_arg += 2; |
| 3528 | } else { |
| 3529 | /* unknown suboption - catchall */ |
| 3530 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'user'.\n", |
| 3531 | file, linenum, args[0], args[1]); |
| 3532 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3533 | goto out; |
| 3534 | } |
| 3535 | } /* end while loop */ |
| 3536 | } |
| 3537 | } |
| 3538 | |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 3539 | else if (!strcmp(args[1], "redis-check")) { |
| 3540 | /* use REDIS PING request to check servers' health */ |
| 3541 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 3542 | err_code |= ERR_WARN; |
| 3543 | |
| 3544 | free(curproxy->check_req); |
| 3545 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3546 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 3547 | curproxy->options2 |= PR_O2_REDIS_CHK; |
| 3548 | |
| 3549 | curproxy->check_req = (char *) malloc(sizeof(DEF_REDIS_CHECK_REQ) - 1); |
| 3550 | memcpy(curproxy->check_req, DEF_REDIS_CHECK_REQ, sizeof(DEF_REDIS_CHECK_REQ) - 1); |
| 3551 | curproxy->check_len = sizeof(DEF_REDIS_CHECK_REQ) - 1; |
| 3552 | } |
| 3553 | |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 3554 | else if (!strcmp(args[1], "mysql-check")) { |
| 3555 | /* use MYSQL request to check servers' health */ |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 3556 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 3557 | err_code |= ERR_WARN; |
| 3558 | |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 3559 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 3560 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3561 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 3562 | curproxy->options2 |= PR_O2_MYSQL_CHK; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 3563 | |
| 3564 | /* This is an exemple of an MySQL >=4.0 client Authentication packet kindly provided by Cyril Bonte. |
| 3565 | * const char mysql40_client_auth_pkt[] = { |
| 3566 | * "\x0e\x00\x00" // packet length |
| 3567 | * "\x01" // packet number |
| 3568 | * "\x00\x00" // client capabilities |
| 3569 | * "\x00\x00\x01" // max packet |
| 3570 | * "haproxy\x00" // username (null terminated string) |
| 3571 | * "\x00" // filler (always 0x00) |
| 3572 | * "\x01\x00\x00" // packet length |
| 3573 | * "\x00" // packet number |
| 3574 | * "\x01" // COM_QUIT command |
| 3575 | * }; |
| 3576 | */ |
| 3577 | |
| 3578 | if (*(args[2])) { |
| 3579 | int cur_arg = 2; |
| 3580 | |
| 3581 | while (*(args[cur_arg])) { |
| 3582 | if (strcmp(args[cur_arg], "user") == 0) { |
| 3583 | char *mysqluser; |
| 3584 | int packetlen, reqlen, userlen; |
| 3585 | |
| 3586 | /* suboption header - needs additional argument for it */ |
| 3587 | if (*(args[cur_arg+1]) == 0) { |
| 3588 | Alert("parsing [%s:%d] : '%s %s %s' expects <username> as argument.\n", |
| 3589 | file, linenum, args[0], args[1], args[cur_arg]); |
| 3590 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3591 | goto out; |
| 3592 | } |
| 3593 | mysqluser = args[cur_arg + 1]; |
| 3594 | userlen = strlen(mysqluser); |
| 3595 | packetlen = userlen + 7; |
| 3596 | reqlen = packetlen + 9; |
| 3597 | |
| 3598 | free(curproxy->check_req); |
| 3599 | curproxy->check_req = (char *)calloc(1, reqlen); |
| 3600 | curproxy->check_len = reqlen; |
| 3601 | |
| 3602 | snprintf(curproxy->check_req, 4, "%c%c%c", |
| 3603 | ((unsigned char) packetlen & 0xff), |
| 3604 | ((unsigned char) (packetlen >> 8) & 0xff), |
| 3605 | ((unsigned char) (packetlen >> 16) & 0xff)); |
| 3606 | |
| 3607 | curproxy->check_req[3] = 1; |
Hervé COMMOWICK | 212f778 | 2011-06-10 14:05:59 +0200 | [diff] [blame] | 3608 | curproxy->check_req[5] = 128; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 3609 | curproxy->check_req[8] = 1; |
| 3610 | memcpy(&curproxy->check_req[9], mysqluser, userlen); |
| 3611 | curproxy->check_req[9 + userlen + 1 + 1] = 1; |
| 3612 | curproxy->check_req[9 + userlen + 1 + 1 + 4] = 1; |
| 3613 | cur_arg += 2; |
| 3614 | } else { |
| 3615 | /* unknown suboption - catchall */ |
| 3616 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'user'.\n", |
| 3617 | file, linenum, args[0], args[1]); |
| 3618 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3619 | goto out; |
| 3620 | } |
| 3621 | } /* end while loop */ |
| 3622 | } |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 3623 | } |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 3624 | else if (!strcmp(args[1], "ldap-check")) { |
| 3625 | /* use LDAP request to check servers' health */ |
| 3626 | free(curproxy->check_req); |
| 3627 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3628 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 3629 | curproxy->options2 |= PR_O2_LDAP_CHK; |
| 3630 | |
| 3631 | curproxy->check_req = (char *) malloc(sizeof(DEF_LDAP_CHECK_REQ) - 1); |
| 3632 | memcpy(curproxy->check_req, DEF_LDAP_CHECK_REQ, sizeof(DEF_LDAP_CHECK_REQ) - 1); |
| 3633 | curproxy->check_len = sizeof(DEF_LDAP_CHECK_REQ) - 1; |
| 3634 | } |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3635 | else if (!strcmp(args[1], "forwardfor")) { |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3636 | int cur_arg; |
| 3637 | |
| 3638 | /* insert x-forwarded-for field, but not for the IP address listed as an except. |
| 3639 | * set default options (ie: bitfield, header name, etc) |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3640 | */ |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3641 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 3642 | curproxy->options |= PR_O_FWDFOR | PR_O_FF_ALWAYS; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3643 | |
| 3644 | free(curproxy->fwdfor_hdr_name); |
| 3645 | curproxy->fwdfor_hdr_name = strdup(DEF_XFORWARDFOR_HDR); |
| 3646 | curproxy->fwdfor_hdr_len = strlen(DEF_XFORWARDFOR_HDR); |
| 3647 | |
| 3648 | /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */ |
| 3649 | cur_arg = 2; |
| 3650 | while (*(args[cur_arg])) { |
| 3651 | if (!strcmp(args[cur_arg], "except")) { |
| 3652 | /* suboption except - needs additional argument for it */ |
| 3653 | if (!*(args[cur_arg+1]) || !str2net(args[cur_arg+1], &curproxy->except_net, &curproxy->except_mask)) { |
| 3654 | Alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n", |
| 3655 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3656 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3657 | goto out; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3658 | } |
| 3659 | /* flush useless bits */ |
| 3660 | curproxy->except_net.s_addr &= curproxy->except_mask.s_addr; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3661 | cur_arg += 2; |
| 3662 | } else if (!strcmp(args[cur_arg], "header")) { |
| 3663 | /* suboption header - needs additional argument for it */ |
| 3664 | if (*(args[cur_arg+1]) == 0) { |
| 3665 | Alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 3666 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3667 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3668 | goto out; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3669 | } |
| 3670 | free(curproxy->fwdfor_hdr_name); |
| 3671 | curproxy->fwdfor_hdr_name = strdup(args[cur_arg+1]); |
| 3672 | curproxy->fwdfor_hdr_len = strlen(curproxy->fwdfor_hdr_name); |
| 3673 | cur_arg += 2; |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 3674 | } else if (!strcmp(args[cur_arg], "if-none")) { |
| 3675 | curproxy->options &= ~PR_O_FF_ALWAYS; |
| 3676 | cur_arg += 1; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3677 | } else { |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3678 | /* unknown suboption - catchall */ |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 3679 | 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] | 3680 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3681 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3682 | goto out; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3683 | } |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3684 | } /* end while loop */ |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3685 | } |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 3686 | else if (!strcmp(args[1], "originalto")) { |
| 3687 | int cur_arg; |
| 3688 | |
| 3689 | /* insert x-original-to field, but not for the IP address listed as an except. |
| 3690 | * set default options (ie: bitfield, header name, etc) |
| 3691 | */ |
| 3692 | |
| 3693 | curproxy->options |= PR_O_ORGTO; |
| 3694 | |
| 3695 | free(curproxy->orgto_hdr_name); |
| 3696 | curproxy->orgto_hdr_name = strdup(DEF_XORIGINALTO_HDR); |
| 3697 | curproxy->orgto_hdr_len = strlen(DEF_XORIGINALTO_HDR); |
| 3698 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 3699 | /* 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] | 3700 | cur_arg = 2; |
| 3701 | while (*(args[cur_arg])) { |
| 3702 | if (!strcmp(args[cur_arg], "except")) { |
| 3703 | /* suboption except - needs additional argument for it */ |
| 3704 | if (!*(args[cur_arg+1]) || !str2net(args[cur_arg+1], &curproxy->except_to, &curproxy->except_mask_to)) { |
| 3705 | Alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n", |
| 3706 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3707 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3708 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 3709 | } |
| 3710 | /* flush useless bits */ |
| 3711 | curproxy->except_to.s_addr &= curproxy->except_mask_to.s_addr; |
| 3712 | cur_arg += 2; |
| 3713 | } else if (!strcmp(args[cur_arg], "header")) { |
| 3714 | /* suboption header - needs additional argument for it */ |
| 3715 | if (*(args[cur_arg+1]) == 0) { |
| 3716 | Alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 3717 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3718 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3719 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 3720 | } |
| 3721 | free(curproxy->orgto_hdr_name); |
| 3722 | curproxy->orgto_hdr_name = strdup(args[cur_arg+1]); |
| 3723 | curproxy->orgto_hdr_len = strlen(curproxy->orgto_hdr_name); |
| 3724 | cur_arg += 2; |
| 3725 | } else { |
| 3726 | /* unknown suboption - catchall */ |
| 3727 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n", |
| 3728 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3729 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3730 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 3731 | } |
| 3732 | } /* end while loop */ |
| 3733 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3734 | else { |
| 3735 | Alert("parsing [%s:%d] : unknown option '%s'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3736 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3737 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3738 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3739 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3740 | } |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 3741 | else if (!strcmp(args[0], "default_backend")) { |
| 3742 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3743 | err_code |= ERR_WARN; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 3744 | |
| 3745 | if (*(args[1]) == 0) { |
| 3746 | 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] | 3747 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3748 | goto out; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 3749 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3750 | free(curproxy->defbe.name); |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 3751 | curproxy->defbe.name = strdup(args[1]); |
| 3752 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3753 | else if (!strcmp(args[0], "redispatch") || !strcmp(args[0], "redisp")) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3754 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3755 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3756 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3757 | Warning("parsing [%s:%d]: keyword '%s' is deprecated, please use 'option redispatch' instead.\n", |
| 3758 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3759 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3760 | /* enable reconnections to dispatch */ |
| 3761 | curproxy->options |= PR_O_REDISP; |
| 3762 | } |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 3763 | else if (!strcmp(args[0], "http-check")) { |
| 3764 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3765 | err_code |= ERR_WARN; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 3766 | |
| 3767 | if (strcmp(args[1], "disable-on-404") == 0) { |
| 3768 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 3769 | curproxy->options |= PR_O_DISABLE404; |
| 3770 | } |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 3771 | else if (strcmp(args[1], "send-state") == 0) { |
| 3772 | /* enable emission of the apparent state of a server in HTTP checks */ |
| 3773 | curproxy->options2 |= PR_O2_CHK_SNDST; |
| 3774 | } |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 3775 | else if (strcmp(args[1], "expect") == 0) { |
| 3776 | const char *ptr_arg; |
| 3777 | int cur_arg; |
| 3778 | |
| 3779 | if (curproxy->options2 & PR_O2_EXP_TYPE) { |
| 3780 | Alert("parsing [%s:%d] : '%s %s' already specified.\n", file, linenum, args[0], args[1]); |
| 3781 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3782 | goto out; |
| 3783 | } |
| 3784 | |
| 3785 | cur_arg = 2; |
| 3786 | /* consider exclamation marks, sole or at the beginning of a word */ |
| 3787 | while (*(ptr_arg = args[cur_arg])) { |
| 3788 | while (*ptr_arg == '!') { |
| 3789 | curproxy->options2 ^= PR_O2_EXP_INV; |
| 3790 | ptr_arg++; |
| 3791 | } |
| 3792 | if (*ptr_arg) |
| 3793 | break; |
| 3794 | cur_arg++; |
| 3795 | } |
| 3796 | /* now ptr_arg points to the beginning of a word past any possible |
| 3797 | * exclamation mark, and cur_arg is the argument which holds this word. |
| 3798 | */ |
| 3799 | if (strcmp(ptr_arg, "status") == 0) { |
| 3800 | if (!*(args[cur_arg + 1])) { |
| 3801 | Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 3802 | file, linenum, args[0], args[1], ptr_arg); |
| 3803 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3804 | goto out; |
| 3805 | } |
| 3806 | curproxy->options2 |= PR_O2_EXP_STS; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 3807 | free(curproxy->expect_str); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 3808 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
| 3809 | } |
| 3810 | else if (strcmp(ptr_arg, "string") == 0) { |
| 3811 | if (!*(args[cur_arg + 1])) { |
| 3812 | Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 3813 | file, linenum, args[0], args[1], ptr_arg); |
| 3814 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3815 | goto out; |
| 3816 | } |
| 3817 | curproxy->options2 |= PR_O2_EXP_STR; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 3818 | free(curproxy->expect_str); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 3819 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
| 3820 | } |
| 3821 | else if (strcmp(ptr_arg, "rstatus") == 0) { |
| 3822 | if (!*(args[cur_arg + 1])) { |
| 3823 | Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 3824 | file, linenum, args[0], args[1], ptr_arg); |
| 3825 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3826 | goto out; |
| 3827 | } |
| 3828 | curproxy->options2 |= PR_O2_EXP_RSTS; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 3829 | free(curproxy->expect_str); |
| 3830 | if (curproxy->expect_regex) regfree(curproxy->expect_regex); |
| 3831 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 3832 | curproxy->expect_regex = calloc(1, sizeof(regex_t)); |
| 3833 | if (regcomp(curproxy->expect_regex, args[cur_arg + 1], REG_EXTENDED) != 0) { |
| 3834 | Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s'.\n", |
| 3835 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1]); |
| 3836 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3837 | goto out; |
| 3838 | } |
| 3839 | } |
| 3840 | else if (strcmp(ptr_arg, "rstring") == 0) { |
| 3841 | if (!*(args[cur_arg + 1])) { |
| 3842 | Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 3843 | file, linenum, args[0], args[1], ptr_arg); |
| 3844 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3845 | goto out; |
| 3846 | } |
| 3847 | curproxy->options2 |= PR_O2_EXP_RSTR; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 3848 | free(curproxy->expect_str); |
| 3849 | if (curproxy->expect_regex) regfree(curproxy->expect_regex); |
| 3850 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 3851 | curproxy->expect_regex = calloc(1, sizeof(regex_t)); |
| 3852 | if (regcomp(curproxy->expect_regex, args[cur_arg + 1], REG_EXTENDED) != 0) { |
| 3853 | Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s'.\n", |
| 3854 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1]); |
| 3855 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3856 | goto out; |
| 3857 | } |
| 3858 | } |
| 3859 | else { |
| 3860 | Alert("parsing [%s:%d] : '%s %s' only supports [!] 'status', 'string', 'rstatus', 'rstring', found '%s'.\n", |
| 3861 | file, linenum, args[0], args[1], ptr_arg); |
| 3862 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3863 | goto out; |
| 3864 | } |
| 3865 | } |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 3866 | else { |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 3867 | 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] | 3868 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3869 | goto out; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 3870 | } |
| 3871 | } |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3872 | else if (!strcmp(args[0], "monitor")) { |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3873 | if (curproxy == &defproxy) { |
| 3874 | 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] | 3875 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3876 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3877 | } |
| 3878 | |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3879 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3880 | err_code |= ERR_WARN; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3881 | |
| 3882 | if (strcmp(args[1], "fail") == 0) { |
| 3883 | /* add a condition to fail monitor requests */ |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 3884 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3885 | Alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n", |
| 3886 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3887 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3888 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3889 | } |
| 3890 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 3891 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 3892 | Alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition : %s.\n", |
| 3893 | file, linenum, args[0], args[1], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3894 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3895 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3896 | } |
| 3897 | LIST_ADDQ(&curproxy->mon_fail_cond, &cond->list); |
| 3898 | } |
| 3899 | else { |
| 3900 | 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] | 3901 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3902 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 3903 | } |
| 3904 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3905 | #ifdef TPROXY |
| 3906 | else if (!strcmp(args[0], "transparent")) { |
| 3907 | /* enable transparent proxy connections */ |
| 3908 | curproxy->options |= PR_O_TRANSP; |
| 3909 | } |
| 3910 | #endif |
| 3911 | else if (!strcmp(args[0], "maxconn")) { /* maxconn */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3912 | 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] | 3913 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3914 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3915 | if (*(args[1]) == 0) { |
| 3916 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3917 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3918 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3919 | } |
| 3920 | curproxy->maxconn = atol(args[1]); |
| 3921 | } |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 3922 | else if (!strcmp(args[0], "backlog")) { /* backlog */ |
| 3923 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3924 | err_code |= ERR_WARN; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 3925 | |
| 3926 | if (*(args[1]) == 0) { |
| 3927 | 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] | 3928 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3929 | goto out; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 3930 | } |
| 3931 | curproxy->backlog = atol(args[1]); |
| 3932 | } |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 3933 | else if (!strcmp(args[0], "fullconn")) { /* fullconn */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3934 | 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] | 3935 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3936 | |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 3937 | if (*(args[1]) == 0) { |
| 3938 | 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] | 3939 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3940 | goto out; |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 3941 | } |
| 3942 | curproxy->fullconn = atol(args[1]); |
| 3943 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3944 | else if (!strcmp(args[0], "grace")) { /* grace time (ms) */ |
| 3945 | if (*(args[1]) == 0) { |
| 3946 | 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] | 3947 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3948 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3949 | } |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 3950 | err = parse_time_err(args[1], &val, TIME_UNIT_MS); |
| 3951 | if (err) { |
| 3952 | Alert("parsing [%s:%d] : unexpected character '%c' in grace time.\n", |
| 3953 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3954 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3955 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 3956 | } |
| 3957 | curproxy->grace = val; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3958 | } |
| 3959 | else if (!strcmp(args[0], "dispatch")) { /* dispatch address */ |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 3960 | struct sockaddr_storage *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 3961 | int port1, port2; |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 3962 | struct protocol *proto; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 3963 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3964 | if (curproxy == &defproxy) { |
| 3965 | 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] | 3966 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3967 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3968 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3969 | else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3970 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3971 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 3972 | sk = str2sa_range(args[1], &port1, &port2, &errmsg, NULL); |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 3973 | if (!sk) { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 3974 | Alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 3975 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 3976 | goto out; |
| 3977 | } |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 3978 | |
| 3979 | proto = protocol_by_family(sk->ss_family); |
| 3980 | if (!proto || !proto->connect) { |
| 3981 | Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 3982 | file, linenum, args[0], args[1]); |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 3983 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3984 | goto out; |
| 3985 | } |
| 3986 | |
| 3987 | if (port1 != port2) { |
| 3988 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'.\n", |
| 3989 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3990 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3991 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3992 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 3993 | |
| 3994 | if (!port1) { |
| 3995 | Alert("parsing [%s:%d] : '%s' : missing port number in '%s', <addr:port> expected.\n", |
| 3996 | file, linenum, args[0], args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 3997 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3998 | goto out; |
| 3999 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4000 | |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4001 | curproxy->dispatch_addr = *sk; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4002 | curproxy->options |= PR_O_DISPATCH; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4003 | } |
| 4004 | else if (!strcmp(args[0], "balance")) { /* set balancing with optional algorithm */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4005 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4006 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4007 | |
Willy Tarreau | a93c74b | 2012-05-08 18:14:39 +0200 | [diff] [blame] | 4008 | if (backend_parse_balance((const char **)args + 1, &errmsg, curproxy) < 0) { |
| 4009 | Alert("parsing [%s:%d] : %s %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4010 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4011 | goto out; |
Willy Tarreau | 2fcb500 | 2007-05-08 13:35:26 +0200 | [diff] [blame] | 4012 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4013 | } |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 4014 | else if (!strcmp(args[0], "hash-type")) { /* set hashing method */ |
| 4015 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 4016 | err_code |= ERR_WARN; |
| 4017 | |
| 4018 | if (strcmp(args[1], "consistent") == 0) { /* use consistent hashing */ |
| 4019 | curproxy->lbprm.algo &= ~BE_LB_HASH_TYPE; |
| 4020 | curproxy->lbprm.algo |= BE_LB_HASH_CONS; |
| 4021 | } |
| 4022 | else if (strcmp(args[1], "map-based") == 0) { /* use map-based hashing */ |
| 4023 | curproxy->lbprm.algo &= ~BE_LB_HASH_TYPE; |
| 4024 | curproxy->lbprm.algo |= BE_LB_HASH_MAP; |
| 4025 | } |
Willy Tarreau | 798a39c | 2010-11-24 15:04:29 +0100 | [diff] [blame] | 4026 | else if (strcmp(args[1], "avalanche") == 0) { /* use full hash before map-based hashing */ |
| 4027 | curproxy->lbprm.algo &= ~BE_LB_HASH_TYPE; |
| 4028 | curproxy->lbprm.algo |= BE_LB_HASH_AVAL; |
| 4029 | } |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 4030 | else { |
Willy Tarreau | 798a39c | 2010-11-24 15:04:29 +0100 | [diff] [blame] | 4031 | Alert("parsing [%s:%d] : '%s' only supports 'avalanche', 'consistent' and 'map-based'.\n", file, linenum, args[0]); |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 4032 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4033 | goto out; |
| 4034 | } |
| 4035 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4036 | 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] | 4037 | int cur_arg; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4038 | short realport = 0; |
| 4039 | int do_check = 0, defsrv = (*args[0] == 'd'); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4040 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4041 | if (!defsrv && curproxy == &defproxy) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4042 | 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] | 4043 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4044 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4045 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4046 | else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4047 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4048 | |
| 4049 | if (!*args[2]) { |
| 4050 | Alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n", |
| 4051 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4052 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4053 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4054 | } |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 4055 | |
| 4056 | err = invalid_char(args[1]); |
Willy Tarreau | 4217a7d | 2013-03-06 20:04:27 +0100 | [diff] [blame] | 4057 | if (err && !defsrv) { |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 4058 | Alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n", |
| 4059 | file, linenum, *err, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4060 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4061 | goto out; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 4062 | } |
| 4063 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4064 | if (!defsrv) { |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4065 | struct sockaddr_storage *sk; |
Willy Tarreau | dbfa445 | 2013-02-20 19:06:35 +0100 | [diff] [blame] | 4066 | int port1, port2; |
Willy Tarreau | 4217a7d | 2013-03-06 20:04:27 +0100 | [diff] [blame] | 4067 | struct protocol *proto; |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4068 | |
Krzysztof Piotr Oledzki | aff01ea | 2010-02-05 20:31:44 +0100 | [diff] [blame] | 4069 | if ((newsrv = (struct server *)calloc(1, sizeof(struct server))) == NULL) { |
| 4070 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 4071 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4072 | goto out; |
| 4073 | } |
| 4074 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4075 | /* the servers are linked backwards first */ |
| 4076 | newsrv->next = curproxy->srv; |
| 4077 | curproxy->srv = newsrv; |
| 4078 | newsrv->proxy = curproxy; |
Willy Tarreau | 8113a5d | 2012-10-04 08:01:43 +0200 | [diff] [blame] | 4079 | newsrv->conf.file = strdup(file); |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4080 | newsrv->conf.line = linenum; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4081 | |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 4082 | newsrv->obj_type = OBJ_TYPE_SERVER; |
Simon Horman | af51495 | 2011-06-21 14:34:57 +0900 | [diff] [blame] | 4083 | LIST_INIT(&newsrv->actconns); |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4084 | LIST_INIT(&newsrv->pendconns); |
| 4085 | do_check = 0; |
| 4086 | newsrv->state = SRV_RUNNING; /* early server setup */ |
| 4087 | newsrv->last_change = now.tv_sec; |
| 4088 | newsrv->id = strdup(args[1]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4089 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4090 | /* several ways to check the port component : |
David du Colombier | 9842ff1 | 2011-03-17 10:40:28 +0100 | [diff] [blame] | 4091 | * - IP => port=+0, relative (IPv4 only) |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4092 | * - IP: => port=+0, relative |
| 4093 | * - IP:N => port=N, absolute |
| 4094 | * - IP:+N => port=+N, relative |
| 4095 | * - IP:-N => port=-N, relative |
| 4096 | */ |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 4097 | sk = str2sa_range(args[2], &port1, &port2, &errmsg, NULL); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4098 | if (!sk) { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 4099 | 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] | 4100 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 4217a7d | 2013-03-06 20:04:27 +0100 | [diff] [blame] | 4101 | goto out; |
| 4102 | } |
Willy Tarreau | 4217a7d | 2013-03-06 20:04:27 +0100 | [diff] [blame] | 4103 | |
| 4104 | proto = protocol_by_family(sk->ss_family); |
| 4105 | if (!proto || !proto->connect) { |
| 4106 | Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 4107 | file, linenum, args[0], args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4108 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4109 | goto out; |
| 4110 | } |
Willy Tarreau | dbfa445 | 2013-02-20 19:06:35 +0100 | [diff] [blame] | 4111 | |
| 4112 | if (!port1 || !port2) { |
| 4113 | /* no port specified, +offset, -offset */ |
| 4114 | newsrv->state |= SRV_MAPPORTS; |
| 4115 | } |
| 4116 | else if (port1 != port2) { |
| 4117 | /* port range */ |
| 4118 | Alert("parsing [%s:%d] : '%s %s' : port ranges are not allowed in '%s'\n", |
| 4119 | file, linenum, args[0], args[1], args[2]); |
| 4120 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4121 | goto out; |
| 4122 | } |
| 4123 | else { |
| 4124 | /* used by checks */ |
| 4125 | realport = port1; |
| 4126 | } |
| 4127 | |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4128 | newsrv->addr = *sk; |
Willy Tarreau | f4288ee | 2012-09-28 18:13:10 +0200 | [diff] [blame] | 4129 | newsrv->proto = newsrv->check.proto = protocol_by_family(newsrv->addr.ss_family); |
| 4130 | newsrv->xprt = newsrv->check.xprt = &raw_sock; |
Willy Tarreau | 26d8c59 | 2012-05-07 18:12:14 +0200 | [diff] [blame] | 4131 | |
Willy Tarreau | 173e7fb | 2012-09-24 22:47:39 +0200 | [diff] [blame] | 4132 | if (!newsrv->proto) { |
Willy Tarreau | 26d8c59 | 2012-05-07 18:12:14 +0200 | [diff] [blame] | 4133 | Alert("parsing [%s:%d] : Unknown protocol family %d '%s'\n", |
| 4134 | file, linenum, newsrv->addr.ss_family, args[2]); |
| 4135 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4136 | goto out; |
| 4137 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4138 | |
Willy Tarreau | f4288ee | 2012-09-28 18:13:10 +0200 | [diff] [blame] | 4139 | newsrv->check.use_ssl = curproxy->defsrv.check.use_ssl; |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 4140 | newsrv->check.port = curproxy->defsrv.check.port; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4141 | newsrv->inter = curproxy->defsrv.inter; |
| 4142 | newsrv->fastinter = curproxy->defsrv.fastinter; |
| 4143 | newsrv->downinter = curproxy->defsrv.downinter; |
| 4144 | newsrv->rise = curproxy->defsrv.rise; |
| 4145 | newsrv->fall = curproxy->defsrv.fall; |
| 4146 | newsrv->maxqueue = curproxy->defsrv.maxqueue; |
| 4147 | newsrv->minconn = curproxy->defsrv.minconn; |
| 4148 | newsrv->maxconn = curproxy->defsrv.maxconn; |
| 4149 | newsrv->slowstart = curproxy->defsrv.slowstart; |
| 4150 | newsrv->onerror = curproxy->defsrv.onerror; |
| 4151 | newsrv->consecutive_errors_limit |
| 4152 | = curproxy->defsrv.consecutive_errors_limit; |
Emeric Brun | 01f8e2f | 2012-05-18 16:02:00 +0200 | [diff] [blame] | 4153 | #ifdef OPENSSL |
| 4154 | newsrv->use_ssl = curproxy->defsrv.use_ssl; |
| 4155 | #endif |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4156 | newsrv->uweight = newsrv->iweight |
| 4157 | = curproxy->defsrv.iweight; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4158 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4159 | newsrv->health = newsrv->rise; /* up, but will fall down at first failure */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4160 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4161 | cur_arg = 3; |
| 4162 | } else { |
| 4163 | newsrv = &curproxy->defsrv; |
| 4164 | cur_arg = 1; |
| 4165 | } |
Willy Tarreau | 0f03c6f | 2007-03-25 20:46:19 +0200 | [diff] [blame] | 4166 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4167 | while (*args[cur_arg]) { |
Willy Tarreau | dff5543 | 2012-10-10 17:51:05 +0200 | [diff] [blame] | 4168 | if (!defsrv && !strcmp(args[cur_arg], "cookie")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4169 | newsrv->cookie = strdup(args[cur_arg + 1]); |
| 4170 | newsrv->cklen = strlen(args[cur_arg + 1]); |
| 4171 | cur_arg += 2; |
| 4172 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4173 | else if (!defsrv && !strcmp(args[cur_arg], "redir")) { |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 4174 | newsrv->rdr_pfx = strdup(args[cur_arg + 1]); |
| 4175 | newsrv->rdr_len = strlen(args[cur_arg + 1]); |
| 4176 | cur_arg += 2; |
| 4177 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4178 | else if (!strcmp(args[cur_arg], "rise")) { |
Krzysztof Piotr Oledzki | 08ff959 | 2009-09-27 16:17:31 +0200 | [diff] [blame] | 4179 | if (!*args[cur_arg + 1]) { |
| 4180 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 4181 | file, linenum, args[cur_arg]); |
| 4182 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4183 | goto out; |
| 4184 | } |
| 4185 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4186 | newsrv->rise = atol(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 08ff959 | 2009-09-27 16:17:31 +0200 | [diff] [blame] | 4187 | if (newsrv->rise <= 0) { |
| 4188 | Alert("parsing [%s:%d]: '%s' has to be > 0.\n", |
| 4189 | file, linenum, args[cur_arg]); |
| 4190 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4191 | goto out; |
| 4192 | } |
| 4193 | |
Willy Tarreau | 9683909 | 2010-03-29 10:02:24 +0200 | [diff] [blame] | 4194 | if (newsrv->health) |
| 4195 | newsrv->health = newsrv->rise; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4196 | cur_arg += 2; |
| 4197 | } |
| 4198 | else if (!strcmp(args[cur_arg], "fall")) { |
| 4199 | newsrv->fall = atol(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 08ff959 | 2009-09-27 16:17:31 +0200 | [diff] [blame] | 4200 | |
| 4201 | if (!*args[cur_arg + 1]) { |
| 4202 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 4203 | file, linenum, args[cur_arg]); |
| 4204 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4205 | goto out; |
| 4206 | } |
| 4207 | |
| 4208 | if (newsrv->fall <= 0) { |
| 4209 | Alert("parsing [%s:%d]: '%s' has to be > 0.\n", |
| 4210 | file, linenum, args[cur_arg]); |
| 4211 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4212 | goto out; |
| 4213 | } |
| 4214 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4215 | cur_arg += 2; |
| 4216 | } |
| 4217 | else if (!strcmp(args[cur_arg], "inter")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4218 | const char *err = parse_time_err(args[cur_arg + 1], &val, TIME_UNIT_MS); |
| 4219 | if (err) { |
| 4220 | Alert("parsing [%s:%d] : unexpected character '%c' in 'inter' argument of server %s.\n", |
| 4221 | file, linenum, *err, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4222 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4223 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4224 | } |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4225 | if (val <= 0) { |
| 4226 | Alert("parsing [%s:%d]: invalid value %d for argument '%s' of server %s.\n", |
| 4227 | file, linenum, val, args[cur_arg], newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4228 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4229 | goto out; |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4230 | } |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4231 | newsrv->inter = val; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4232 | cur_arg += 2; |
| 4233 | } |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 4234 | else if (!strcmp(args[cur_arg], "fastinter")) { |
| 4235 | const char *err = parse_time_err(args[cur_arg + 1], &val, TIME_UNIT_MS); |
| 4236 | if (err) { |
| 4237 | Alert("parsing [%s:%d]: unexpected character '%c' in 'fastinter' argument of server %s.\n", |
| 4238 | file, linenum, *err, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4239 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4240 | goto out; |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 4241 | } |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4242 | if (val <= 0) { |
| 4243 | Alert("parsing [%s:%d]: invalid value %d for argument '%s' of server %s.\n", |
| 4244 | file, linenum, val, args[cur_arg], newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4245 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4246 | goto out; |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4247 | } |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 4248 | newsrv->fastinter = val; |
| 4249 | cur_arg += 2; |
| 4250 | } |
| 4251 | else if (!strcmp(args[cur_arg], "downinter")) { |
| 4252 | const char *err = parse_time_err(args[cur_arg + 1], &val, TIME_UNIT_MS); |
| 4253 | if (err) { |
| 4254 | Alert("parsing [%s:%d]: unexpected character '%c' in 'downinter' argument of server %s.\n", |
| 4255 | file, linenum, *err, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4256 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4257 | goto out; |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 4258 | } |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4259 | if (val <= 0) { |
| 4260 | Alert("parsing [%s:%d]: invalid value %d for argument '%s' of server %s.\n", |
| 4261 | file, linenum, val, args[cur_arg], newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4262 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4263 | goto out; |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 4264 | } |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 4265 | newsrv->downinter = val; |
| 4266 | cur_arg += 2; |
| 4267 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4268 | else if (!defsrv && !strcmp(args[cur_arg], "addr")) { |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4269 | struct sockaddr_storage *sk; |
| 4270 | int port1, port2; |
Willy Tarreau | 1a20b14 | 2013-03-06 18:05:34 +0100 | [diff] [blame] | 4271 | struct protocol *proto; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4272 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 4273 | sk = str2sa_range(args[cur_arg + 1], &port1, &port2, &errmsg, NULL); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4274 | if (!sk) { |
Willy Tarreau | 1a20b14 | 2013-03-06 18:05:34 +0100 | [diff] [blame] | 4275 | Alert("parsing [%s:%d] : '%s' : %s\n", |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 4276 | file, linenum, args[cur_arg], errmsg); |
Willy Tarreau | 1a20b14 | 2013-03-06 18:05:34 +0100 | [diff] [blame] | 4277 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 1a20b14 | 2013-03-06 18:05:34 +0100 | [diff] [blame] | 4278 | goto out; |
| 4279 | } |
Willy Tarreau | 1a20b14 | 2013-03-06 18:05:34 +0100 | [diff] [blame] | 4280 | |
| 4281 | proto = protocol_by_family(sk->ss_family); |
| 4282 | if (!proto || !proto->connect) { |
| 4283 | 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] | 4284 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4285 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4286 | goto out; |
| 4287 | } |
Willy Tarreau | 1a20b14 | 2013-03-06 18:05:34 +0100 | [diff] [blame] | 4288 | |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4289 | if (port1 != port2) { |
| 4290 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 4291 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
| 4292 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4293 | goto out; |
| 4294 | } |
| 4295 | |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 4296 | newsrv->check.addr = *sk; |
Willy Tarreau | 2ea3abb | 2007-03-25 16:45:16 +0200 | [diff] [blame] | 4297 | cur_arg += 2; |
| 4298 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4299 | else if (!strcmp(args[cur_arg], "port")) { |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 4300 | newsrv->check.port = atol(args[cur_arg + 1]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4301 | cur_arg += 2; |
| 4302 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4303 | else if (!defsrv && !strcmp(args[cur_arg], "backup")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4304 | newsrv->state |= SRV_BACKUP; |
| 4305 | cur_arg ++; |
| 4306 | } |
Simon Horman | fa46168 | 2011-06-25 09:39:49 +0900 | [diff] [blame] | 4307 | else if (!defsrv && !strcmp(args[cur_arg], "non-stick")) { |
| 4308 | newsrv->state |= SRV_NON_STICK; |
| 4309 | cur_arg ++; |
| 4310 | } |
Willy Tarreau | 5ab04ec | 2011-03-20 10:32:26 +0100 | [diff] [blame] | 4311 | else if (!defsrv && !strcmp(args[cur_arg], "send-proxy")) { |
| 4312 | newsrv->state |= SRV_SEND_PROXY; |
| 4313 | cur_arg ++; |
| 4314 | } |
Willy Tarreau | 6c16adc | 2012-10-05 00:04:16 +0200 | [diff] [blame] | 4315 | else if (!defsrv && !strcmp(args[cur_arg], "check-send-proxy")) { |
| 4316 | newsrv->check.send_proxy = 1; |
| 4317 | cur_arg ++; |
| 4318 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4319 | else if (!strcmp(args[cur_arg], "weight")) { |
| 4320 | int w; |
| 4321 | w = atol(args[cur_arg + 1]); |
Willy Tarreau | 6704d67 | 2009-06-15 10:56:05 +0200 | [diff] [blame] | 4322 | if (w < 0 || w > 256) { |
| 4323 | Alert("parsing [%s:%d] : weight of server %s is not within 0 and 256 (%d).\n", |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4324 | file, linenum, newsrv->id, w); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4325 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4326 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4327 | } |
Willy Tarreau | 975c50b | 2009-10-10 19:34:06 +0200 | [diff] [blame] | 4328 | newsrv->uweight = newsrv->iweight = w; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4329 | cur_arg += 2; |
| 4330 | } |
| 4331 | else if (!strcmp(args[cur_arg], "minconn")) { |
| 4332 | newsrv->minconn = atol(args[cur_arg + 1]); |
| 4333 | cur_arg += 2; |
| 4334 | } |
| 4335 | else if (!strcmp(args[cur_arg], "maxconn")) { |
| 4336 | newsrv->maxconn = atol(args[cur_arg + 1]); |
| 4337 | cur_arg += 2; |
| 4338 | } |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 4339 | else if (!strcmp(args[cur_arg], "maxqueue")) { |
| 4340 | newsrv->maxqueue = atol(args[cur_arg + 1]); |
| 4341 | cur_arg += 2; |
| 4342 | } |
Willy Tarreau | 9909fc1 | 2007-11-30 17:42:05 +0100 | [diff] [blame] | 4343 | else if (!strcmp(args[cur_arg], "slowstart")) { |
| 4344 | /* slowstart is stored in seconds */ |
Willy Tarreau | 3259e33 | 2007-12-03 01:51:45 +0100 | [diff] [blame] | 4345 | 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] | 4346 | if (err) { |
| 4347 | Alert("parsing [%s:%d] : unexpected character '%c' in 'slowstart' argument of server %s.\n", |
| 4348 | file, linenum, *err, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4349 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4350 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4351 | } |
Willy Tarreau | 3259e33 | 2007-12-03 01:51:45 +0100 | [diff] [blame] | 4352 | newsrv->slowstart = (val + 999) / 1000; |
Willy Tarreau | 9909fc1 | 2007-11-30 17:42:05 +0100 | [diff] [blame] | 4353 | cur_arg += 2; |
| 4354 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4355 | else if (!defsrv && !strcmp(args[cur_arg], "track")) { |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4356 | |
| 4357 | if (!*args[cur_arg + 1]) { |
| 4358 | Alert("parsing [%s:%d]: 'track' expects [<proxy>/]<server> as argument.\n", |
| 4359 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4360 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4361 | goto out; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4362 | } |
| 4363 | |
| 4364 | newsrv->trackit = strdup(args[cur_arg + 1]); |
| 4365 | |
| 4366 | cur_arg += 2; |
| 4367 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4368 | else if (!defsrv && !strcmp(args[cur_arg], "check")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4369 | global.maxsock++; |
| 4370 | do_check = 1; |
| 4371 | cur_arg += 1; |
| 4372 | } |
Willy Tarreau | 9683909 | 2010-03-29 10:02:24 +0200 | [diff] [blame] | 4373 | else if (!defsrv && !strcmp(args[cur_arg], "disabled")) { |
| 4374 | newsrv->state |= SRV_MAINTAIN; |
| 4375 | newsrv->state &= ~SRV_RUNNING; |
| 4376 | newsrv->health = 0; |
| 4377 | cur_arg += 1; |
Emeric Brun | c0ff492 | 2012-09-28 19:37:02 +0200 | [diff] [blame] | 4378 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4379 | else if (!defsrv && !strcmp(args[cur_arg], "observe")) { |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 4380 | if (!strcmp(args[cur_arg + 1], "none")) |
| 4381 | newsrv->observe = HANA_OBS_NONE; |
| 4382 | else if (!strcmp(args[cur_arg + 1], "layer4")) |
| 4383 | newsrv->observe = HANA_OBS_LAYER4; |
| 4384 | else if (!strcmp(args[cur_arg + 1], "layer7")) { |
| 4385 | if (curproxy->mode != PR_MODE_HTTP) { |
| 4386 | Alert("parsing [%s:%d]: '%s' can only be used in http proxies.\n", |
| 4387 | file, linenum, args[cur_arg + 1]); |
| 4388 | err_code |= ERR_ALERT; |
| 4389 | } |
| 4390 | newsrv->observe = HANA_OBS_LAYER7; |
| 4391 | } |
| 4392 | else { |
| 4393 | Alert("parsing [%s:%d]: '%s' expects one of 'none', " |
Willy Tarreau | 53621e0 | 2010-10-22 14:53:40 +0200 | [diff] [blame] | 4394 | "'layer4', 'layer7' but got '%s'\n", |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 4395 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
| 4396 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4397 | goto out; |
| 4398 | } |
| 4399 | |
| 4400 | cur_arg += 2; |
| 4401 | } |
| 4402 | else if (!strcmp(args[cur_arg], "on-error")) { |
| 4403 | if (!strcmp(args[cur_arg + 1], "fastinter")) |
| 4404 | newsrv->onerror = HANA_ONERR_FASTINTER; |
| 4405 | else if (!strcmp(args[cur_arg + 1], "fail-check")) |
| 4406 | newsrv->onerror = HANA_ONERR_FAILCHK; |
| 4407 | else if (!strcmp(args[cur_arg + 1], "sudden-death")) |
| 4408 | newsrv->onerror = HANA_ONERR_SUDDTH; |
| 4409 | else if (!strcmp(args[cur_arg + 1], "mark-down")) |
| 4410 | newsrv->onerror = HANA_ONERR_MARKDWN; |
| 4411 | else { |
| 4412 | Alert("parsing [%s:%d]: '%s' expects one of 'fastinter', " |
Willy Tarreau | 53621e0 | 2010-10-22 14:53:40 +0200 | [diff] [blame] | 4413 | "'fail-check', 'sudden-death' or 'mark-down' but got '%s'\n", |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 4414 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
| 4415 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4416 | goto out; |
| 4417 | } |
| 4418 | |
| 4419 | cur_arg += 2; |
| 4420 | } |
Simon Horman | e0d1bfb | 2011-06-21 14:34:58 +0900 | [diff] [blame] | 4421 | else if (!strcmp(args[cur_arg], "on-marked-down")) { |
| 4422 | if (!strcmp(args[cur_arg + 1], "shutdown-sessions")) |
| 4423 | newsrv->onmarkeddown = HANA_ONMARKEDDOWN_SHUTDOWNSESSIONS; |
| 4424 | else { |
| 4425 | Alert("parsing [%s:%d]: '%s' expects 'shutdown-sessions' but got '%s'\n", |
| 4426 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
| 4427 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4428 | goto out; |
| 4429 | } |
| 4430 | |
| 4431 | cur_arg += 2; |
| 4432 | } |
Justin Karneges | eb2c24a | 2012-05-24 15:28:52 -0700 | [diff] [blame] | 4433 | else if (!strcmp(args[cur_arg], "on-marked-up")) { |
| 4434 | if (!strcmp(args[cur_arg + 1], "shutdown-backup-sessions")) |
| 4435 | newsrv->onmarkedup = HANA_ONMARKEDUP_SHUTDOWNBACKUPSESSIONS; |
| 4436 | else { |
| 4437 | Alert("parsing [%s:%d]: '%s' expects 'shutdown-backup-sessions' but got '%s'\n", |
| 4438 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
| 4439 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4440 | goto out; |
| 4441 | } |
| 4442 | |
| 4443 | cur_arg += 2; |
| 4444 | } |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 4445 | else if (!strcmp(args[cur_arg], "error-limit")) { |
| 4446 | if (!*args[cur_arg + 1]) { |
| 4447 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 4448 | file, linenum, args[cur_arg]); |
| 4449 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4450 | goto out; |
| 4451 | } |
| 4452 | |
| 4453 | newsrv->consecutive_errors_limit = atoi(args[cur_arg + 1]); |
| 4454 | |
| 4455 | if (newsrv->consecutive_errors_limit <= 0) { |
| 4456 | Alert("parsing [%s:%d]: %s has to be > 0.\n", |
| 4457 | file, linenum, args[cur_arg]); |
| 4458 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4459 | goto out; |
| 4460 | } |
Willy Tarreau | f53b25d | 2010-03-15 19:40:37 +0100 | [diff] [blame] | 4461 | cur_arg += 2; |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 4462 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4463 | 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] | 4464 | int port_low, port_high; |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4465 | struct sockaddr_storage *sk; |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 4466 | struct protocol *proto; |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4467 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4468 | if (!*args[cur_arg + 1]) { |
Willy Tarreau | eb37faa | 2012-12-08 23:21:19 +0100 | [diff] [blame] | 4469 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>[-<port>]], and optionally '%s' <addr>, and '%s' <name> as argument.\n", |
| 4470 | file, linenum, "source", "usesrc", "interface"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4471 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4472 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4473 | } |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 4474 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4475 | newsrv->conn_src.opts |= CO_SRC_BIND; |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 4476 | 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] | 4477 | if (!sk) { |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 4478 | Alert("parsing [%s:%d] : '%s %s' : %s\n", |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 4479 | file, linenum, args[cur_arg], args[cur_arg+1], errmsg); |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 4480 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 4481 | goto out; |
| 4482 | } |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 4483 | |
| 4484 | proto = protocol_by_family(sk->ss_family); |
| 4485 | if (!proto || !proto->connect) { |
| 4486 | Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 4487 | file, linenum, args[cur_arg], args[cur_arg+1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4488 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4489 | goto out; |
| 4490 | } |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 4491 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4492 | newsrv->conn_src.source_addr = *sk; |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 4493 | |
| 4494 | if (port_low != port_high) { |
| 4495 | int i; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4496 | |
| 4497 | if (!port_low || !port_high) { |
| 4498 | Alert("parsing [%s:%d] : %s does not support port offsets (found '%s').\n", |
| 4499 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
| 4500 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4501 | goto out; |
| 4502 | } |
| 4503 | |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 4504 | if (port_low <= 0 || port_low > 65535 || |
| 4505 | port_high <= 0 || port_high > 65535 || |
| 4506 | port_low > port_high) { |
| 4507 | Alert("parsing [%s:%d] : invalid source port range %d-%d.\n", |
| 4508 | file, linenum, port_low, port_high); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4509 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4510 | goto out; |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 4511 | } |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4512 | newsrv->conn_src.sport_range = port_range_alloc_range(port_high - port_low + 1); |
| 4513 | for (i = 0; i < newsrv->conn_src.sport_range->size; i++) |
| 4514 | newsrv->conn_src.sport_range->ports[i] = port_low + i; |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 4515 | } |
| 4516 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4517 | cur_arg += 2; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4518 | while (*(args[cur_arg])) { |
| 4519 | if (!strcmp(args[cur_arg], "usesrc")) { /* address to use outside */ |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4520 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) |
| 4521 | #if !defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4522 | if (!is_addr(&newsrv->conn_src.source_addr)) { |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4523 | Alert("parsing [%s:%d] : '%s' requires an explicit '%s' address.\n", |
| 4524 | file, linenum, "usesrc", "source"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4525 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4526 | goto out; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4527 | } |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4528 | #endif |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4529 | if (!*args[cur_arg + 1]) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4530 | 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] | 4531 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4532 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4533 | goto out; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4534 | } |
| 4535 | if (!strcmp(args[cur_arg + 1], "client")) { |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4536 | newsrv->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 4537 | newsrv->conn_src.opts |= CO_SRC_TPROXY_CLI; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4538 | } else if (!strcmp(args[cur_arg + 1], "clientip")) { |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4539 | newsrv->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 4540 | newsrv->conn_src.opts |= CO_SRC_TPROXY_CIP; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4541 | } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) { |
| 4542 | char *name, *end; |
| 4543 | |
| 4544 | name = args[cur_arg+1] + 7; |
| 4545 | while (isspace(*name)) |
| 4546 | name++; |
| 4547 | |
| 4548 | end = name; |
| 4549 | while (*end && !isspace(*end) && *end != ',' && *end != ')') |
| 4550 | end++; |
| 4551 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4552 | newsrv->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 4553 | newsrv->conn_src.opts |= CO_SRC_TPROXY_DYN; |
| 4554 | newsrv->conn_src.bind_hdr_name = calloc(1, end - name + 1); |
| 4555 | newsrv->conn_src.bind_hdr_len = end - name; |
| 4556 | memcpy(newsrv->conn_src.bind_hdr_name, name, end - name); |
| 4557 | newsrv->conn_src.bind_hdr_name[end-name] = '\0'; |
| 4558 | newsrv->conn_src.bind_hdr_occ = -1; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4559 | |
| 4560 | /* now look for an occurrence number */ |
| 4561 | while (isspace(*end)) |
| 4562 | end++; |
| 4563 | if (*end == ',') { |
| 4564 | end++; |
| 4565 | name = end; |
| 4566 | if (*end == '-') |
| 4567 | end++; |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 4568 | while (isdigit((int)*end)) |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4569 | end++; |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4570 | newsrv->conn_src.bind_hdr_occ = strl2ic(name, end-name); |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4571 | } |
| 4572 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4573 | if (newsrv->conn_src.bind_hdr_occ < -MAX_HDR_HISTORY) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4574 | Alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative" |
| 4575 | " occurrences values smaller than %d.\n", |
| 4576 | file, linenum, MAX_HDR_HISTORY); |
| 4577 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4578 | goto out; |
| 4579 | } |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4580 | } else { |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4581 | struct sockaddr_storage *sk; |
| 4582 | int port1, port2; |
| 4583 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 4584 | sk = str2sa_range(args[cur_arg + 1], &port1, &port2, &errmsg, NULL); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4585 | if (!sk) { |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 4586 | Alert("parsing [%s:%d] : '%s %s' : %s\n", |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 4587 | file, linenum, args[cur_arg], args[cur_arg+1], errmsg); |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 4588 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 4589 | goto out; |
| 4590 | } |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 4591 | |
| 4592 | proto = protocol_by_family(sk->ss_family); |
| 4593 | if (!proto || !proto->connect) { |
| 4594 | Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 4595 | file, linenum, args[cur_arg], args[cur_arg+1]); |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4596 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4597 | goto out; |
| 4598 | } |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 4599 | |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4600 | if (port1 != port2) { |
| 4601 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 4602 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4603 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4604 | goto out; |
| 4605 | } |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4606 | newsrv->conn_src.tproxy_addr = *sk; |
| 4607 | newsrv->conn_src.opts |= CO_SRC_TPROXY_ADDR; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4608 | } |
| 4609 | global.last_checks |= LSTCHK_NETADM; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4610 | #if !defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4611 | global.last_checks |= LSTCHK_CTTPROXY; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4612 | #endif |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4613 | cur_arg += 2; |
| 4614 | continue; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4615 | #else /* no TPROXY support */ |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4616 | 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] | 4617 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4618 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4619 | goto out; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4620 | #endif /* defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) */ |
| 4621 | } /* "usesrc" */ |
| 4622 | |
| 4623 | if (!strcmp(args[cur_arg], "interface")) { /* specifically bind to this interface */ |
| 4624 | #ifdef SO_BINDTODEVICE |
| 4625 | if (!*args[cur_arg + 1]) { |
| 4626 | Alert("parsing [%s:%d] : '%s' : missing interface name.\n", |
| 4627 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4628 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4629 | goto out; |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4630 | } |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4631 | free(newsrv->conn_src.iface_name); |
| 4632 | newsrv->conn_src.iface_name = strdup(args[cur_arg + 1]); |
| 4633 | newsrv->conn_src.iface_len = strlen(newsrv->conn_src.iface_name); |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4634 | global.last_checks |= LSTCHK_NETADM; |
| 4635 | #else |
| 4636 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 4637 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4638 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4639 | goto out; |
Willy Tarreau | 77074d5 | 2006-11-12 23:57:19 +0100 | [diff] [blame] | 4640 | #endif |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 4641 | cur_arg += 2; |
| 4642 | continue; |
| 4643 | } |
| 4644 | /* this keyword in not an option of "source" */ |
| 4645 | break; |
| 4646 | } /* while */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4647 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4648 | 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] | 4649 | Alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n", |
| 4650 | file, linenum, "usesrc", "source"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4651 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4652 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 4653 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4654 | else { |
Willy Tarreau | d0d6059 | 2012-10-10 08:57:40 +0200 | [diff] [blame] | 4655 | static int srv_dumped; |
| 4656 | struct srv_kw *kw; |
| 4657 | char *err; |
| 4658 | |
| 4659 | kw = srv_find_kw(args[cur_arg]); |
| 4660 | if (kw) { |
| 4661 | char *err = NULL; |
| 4662 | int code; |
| 4663 | |
| 4664 | if (!kw->parse) { |
| 4665 | Alert("parsing [%s:%d] : '%s %s' : '%s' option is not implemented in this version (check build options).\n", |
| 4666 | file, linenum, args[0], args[1], args[cur_arg]); |
| 4667 | cur_arg += 1 + kw->skip ; |
| 4668 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4669 | goto out; |
| 4670 | } |
| 4671 | |
| 4672 | if (defsrv && !kw->default_ok) { |
| 4673 | Alert("parsing [%s:%d] : '%s %s' : '%s' option is not accepted in default-server sections.\n", |
| 4674 | file, linenum, args[0], args[1], args[cur_arg]); |
| 4675 | cur_arg += 1 + kw->skip ; |
| 4676 | err_code |= ERR_ALERT; |
| 4677 | continue; |
| 4678 | } |
| 4679 | |
| 4680 | code = kw->parse(args, &cur_arg, curproxy, newsrv, &err); |
| 4681 | err_code |= code; |
| 4682 | |
| 4683 | if (code) { |
| 4684 | if (err && *err) { |
| 4685 | indent_msg(&err, 2); |
| 4686 | Alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], err); |
| 4687 | } |
| 4688 | else |
| 4689 | Alert("parsing [%s:%d] : '%s %s' : error encountered while processing '%s'.\n", |
| 4690 | file, linenum, args[0], args[1], args[cur_arg]); |
| 4691 | if (code & ERR_FATAL) { |
| 4692 | free(err); |
| 4693 | cur_arg += 1 + kw->skip; |
| 4694 | goto out; |
| 4695 | } |
| 4696 | } |
| 4697 | free(err); |
| 4698 | cur_arg += 1 + kw->skip; |
| 4699 | continue; |
| 4700 | } |
| 4701 | |
| 4702 | err = NULL; |
| 4703 | if (!srv_dumped) { |
| 4704 | srv_dump_kws(&err); |
| 4705 | indent_msg(&err, 4); |
| 4706 | srv_dumped = 1; |
| 4707 | } |
| 4708 | |
| 4709 | Alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'.%s%s\n", |
| 4710 | file, linenum, args[0], args[1], args[cur_arg], |
| 4711 | err ? " Registered keywords :" : "", err ? err : ""); |
| 4712 | free(err); |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4713 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4714 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4715 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4716 | } |
| 4717 | } |
| 4718 | |
| 4719 | if (do_check) { |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4720 | if (newsrv->trackit) { |
| 4721 | Alert("parsing [%s:%d]: unable to enable checks and tracking at the same time!\n", |
| 4722 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4723 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4724 | goto out; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4725 | } |
| 4726 | |
Willy Tarreau | f4288ee | 2012-09-28 18:13:10 +0200 | [diff] [blame] | 4727 | /* If neither a port nor an addr was specified and no check transport |
| 4728 | * layer is forced, then the transport layer used by the checks is the |
| 4729 | * same as for the production traffic. Otherwise we use raw_sock by |
| 4730 | * default, unless one is specified. |
| 4731 | */ |
Willy Tarreau | 6c16adc | 2012-10-05 00:04:16 +0200 | [diff] [blame] | 4732 | if (!newsrv->check.port && !is_addr(&newsrv->check.addr)) { |
Willy Tarreau | 7151633 | 2012-10-10 23:01:14 +0200 | [diff] [blame] | 4733 | #ifdef USE_OPENSSL |
Willy Tarreau | f4288ee | 2012-09-28 18:13:10 +0200 | [diff] [blame] | 4734 | newsrv->check.use_ssl |= newsrv->use_ssl; |
Willy Tarreau | 7151633 | 2012-10-10 23:01:14 +0200 | [diff] [blame] | 4735 | #endif |
Willy Tarreau | 6c16adc | 2012-10-05 00:04:16 +0200 | [diff] [blame] | 4736 | newsrv->check.send_proxy |= (newsrv->state & SRV_SEND_PROXY); |
| 4737 | } |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 4738 | /* try to get the port from check.addr if check.port not set */ |
| 4739 | if (!newsrv->check.port) |
| 4740 | newsrv->check.port = get_host_port(&newsrv->check.addr); |
Willy Tarreau | 0f03c6f | 2007-03-25 20:46:19 +0200 | [diff] [blame] | 4741 | |
Willy Tarreau | dbfa445 | 2013-02-20 19:06:35 +0100 | [diff] [blame] | 4742 | if (!newsrv->check.port) |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 4743 | newsrv->check.port = realport; /* by default */ |
Willy Tarreau | dbfa445 | 2013-02-20 19:06:35 +0100 | [diff] [blame] | 4744 | |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 4745 | if (!newsrv->check.port) { |
Willy Tarreau | ef00b50 | 2007-01-07 02:40:09 +0100 | [diff] [blame] | 4746 | /* not yet valid, because no port was set on |
| 4747 | * the server either. We'll check if we have |
| 4748 | * a known port on the first listener. |
| 4749 | */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 4750 | struct listener *l; |
| 4751 | |
| 4752 | list_for_each_entry(l, &curproxy->conf.listeners, by_fe) { |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 4753 | newsrv->check.port = get_host_port(&l->addr); |
| 4754 | if (newsrv->check.port) |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 4755 | break; |
| 4756 | } |
Willy Tarreau | ef00b50 | 2007-01-07 02:40:09 +0100 | [diff] [blame] | 4757 | } |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 4758 | if (!newsrv->check.port) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4759 | Alert("parsing [%s:%d] : server %s has neither service port nor check port. Check has been disabled.\n", |
| 4760 | file, linenum, newsrv->id); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4761 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4762 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4763 | } |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 4764 | |
Willy Tarreau | 1ae1b7b | 2012-09-28 15:28:30 +0200 | [diff] [blame] | 4765 | /* Allocate buffer for check requests... */ |
| 4766 | if ((newsrv->check.bi = calloc(sizeof(struct buffer) + global.tune.chksize, sizeof(char))) == NULL) { |
Cyril Bonté | c9f825f | 2010-03-17 18:56:31 +0100 | [diff] [blame] | 4767 | Alert("parsing [%s:%d] : out of memory while allocating check buffer.\n", file, linenum); |
| 4768 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4769 | goto out; |
| 4770 | } |
Willy Tarreau | 1ae1b7b | 2012-09-28 15:28:30 +0200 | [diff] [blame] | 4771 | newsrv->check.bi->size = global.tune.chksize; |
| 4772 | |
| 4773 | /* Allocate buffer for check responses... */ |
| 4774 | if ((newsrv->check.bo = calloc(sizeof(struct buffer) + global.tune.chksize, sizeof(char))) == NULL) { |
| 4775 | Alert("parsing [%s:%d] : out of memory while allocating check buffer.\n", file, linenum); |
| 4776 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4777 | goto out; |
| 4778 | } |
| 4779 | newsrv->check.bo->size = global.tune.chksize; |
Cyril Bonté | c9f825f | 2010-03-17 18:56:31 +0100 | [diff] [blame] | 4780 | |
Willy Tarreau | da92e2f | 2012-07-06 09:40:59 +0200 | [diff] [blame] | 4781 | /* Allocate buffer for partial check results... */ |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 4782 | if ((newsrv->check.conn = calloc(1, sizeof(struct connection))) == NULL) { |
Willy Tarreau | da92e2f | 2012-07-06 09:40:59 +0200 | [diff] [blame] | 4783 | Alert("parsing [%s:%d] : out of memory while allocating check connection.\n", file, linenum); |
| 4784 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4785 | goto out; |
| 4786 | } |
| 4787 | |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 4788 | newsrv->check.conn->t.sock.fd = -1; /* no check in progress yet */ |
| 4789 | newsrv->check.status = HCHK_STATUS_INI; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4790 | newsrv->state |= SRV_CHECKED; |
| 4791 | } |
| 4792 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4793 | if (!defsrv) { |
| 4794 | if (newsrv->state & SRV_BACKUP) |
| 4795 | curproxy->srv_bck++; |
| 4796 | else |
| 4797 | curproxy->srv_act++; |
Willy Tarreau | b625a08 | 2007-11-26 01:15:43 +0100 | [diff] [blame] | 4798 | |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4799 | newsrv->prev_state = newsrv->state; |
| 4800 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 4801 | } |
| 4802 | |
| 4803 | else if (strcmp(args[0], "unique-id-format") == 0) { |
| 4804 | if (!*(args[1])) { |
| 4805 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 4806 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4807 | goto out; |
| 4808 | } |
William Lallemand | 3203ff4 | 2012-11-11 17:30:56 +0100 | [diff] [blame] | 4809 | if (*(args[2])) { |
| 4810 | Alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]); |
| 4811 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4812 | goto out; |
| 4813 | } |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 4814 | free(curproxy->uniqueid_format_string); |
| 4815 | curproxy->uniqueid_format_string = strdup(args[1]); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4816 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 4817 | |
| 4818 | else if (strcmp(args[0], "unique-id-header") == 0) { |
| 4819 | if (!*(args[1])) { |
| 4820 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 4821 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4822 | goto out; |
| 4823 | } |
| 4824 | free(curproxy->header_unique_id); |
| 4825 | curproxy->header_unique_id = strdup(args[1]); |
| 4826 | } |
| 4827 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4828 | else if (strcmp(args[0], "log-format") == 0) { |
| 4829 | if (!*(args[1])) { |
| 4830 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 4831 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4832 | goto out; |
| 4833 | } |
William Lallemand | 3203ff4 | 2012-11-11 17:30:56 +0100 | [diff] [blame] | 4834 | if (*(args[2])) { |
| 4835 | Alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]); |
| 4836 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4837 | goto out; |
| 4838 | } |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 4839 | |
| 4840 | if (curproxy->logformat_string != default_http_log_format && |
| 4841 | curproxy->logformat_string != default_tcp_log_format && |
| 4842 | curproxy->logformat_string != clf_http_log_format) |
| 4843 | free(curproxy->logformat_string); |
| 4844 | curproxy->logformat_string = strdup(args[1]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4845 | } |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4846 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4847 | else if (!strcmp(args[0], "log") && kwm == KWM_NO) { |
| 4848 | /* delete previous herited or defined syslog servers */ |
| 4849 | struct logsrv *back; |
| 4850 | |
| 4851 | if (*(args[1]) != 0) { |
| 4852 | Alert("parsing [%s:%d]:%s : 'no log' does not expect arguments.\n", file, linenum, args[1]); |
| 4853 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4854 | goto out; |
| 4855 | } |
| 4856 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4857 | list_for_each_entry_safe(tmplogsrv, back, &curproxy->logsrvs, list) { |
| 4858 | LIST_DEL(&tmplogsrv->list); |
| 4859 | free(tmplogsrv); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4860 | } |
| 4861 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4862 | else if (!strcmp(args[0], "log")) { /* syslog server address */ |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4863 | struct logsrv *logsrv; |
| 4864 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4865 | if (*(args[1]) && *(args[2]) == 0 && !strcmp(args[1], "global")) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4866 | /* copy global.logrsvs linked list to the end of curproxy->logsrvs */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4867 | list_for_each_entry(tmplogsrv, &global.logsrvs, list) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4868 | struct logsrv *node = malloc(sizeof(struct logsrv)); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4869 | memcpy(node, tmplogsrv, sizeof(struct logsrv)); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4870 | LIST_INIT(&node->list); |
| 4871 | LIST_ADDQ(&curproxy->logsrvs, &node->list); |
| 4872 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4873 | } |
| 4874 | else if (*(args[1]) && *(args[2])) { |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 4875 | struct sockaddr_storage *sk; |
| 4876 | int port1, port2; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4877 | |
| 4878 | logsrv = calloc(1, sizeof(struct logsrv)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4879 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4880 | logsrv->facility = get_log_facility(args[2]); |
| 4881 | if (logsrv->facility < 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4882 | 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] | 4883 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4884 | goto out; |
| 4885 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4886 | } |
| 4887 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4888 | logsrv->level = 7; /* max syslog level = debug */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4889 | if (*(args[3])) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4890 | logsrv->level = get_log_level(args[3]); |
| 4891 | if (logsrv->level < 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4892 | 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] | 4893 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4894 | goto out; |
| 4895 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4896 | } |
| 4897 | } |
| 4898 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4899 | logsrv->minlvl = 0; /* limit syslog level to this level (emerg) */ |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 4900 | if (*(args[4])) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4901 | logsrv->minlvl = get_log_level(args[4]); |
Willy Tarreau | f7f057b | 2013-01-24 00:31:24 +0100 | [diff] [blame] | 4902 | if (logsrv->minlvl < 0) { |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 4903 | 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] | 4904 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4905 | goto out; |
| 4906 | |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 4907 | } |
| 4908 | } |
| 4909 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 4910 | sk = str2sa_range(args[1], &port1, &port2, &errmsg, NULL); |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 4911 | if (!sk) { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 4912 | Alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 4913 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 4914 | goto out; |
| 4915 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4916 | |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 4917 | logsrv->addr = *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4918 | |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 4919 | if (sk->ss_family == AF_INET || sk->ss_family == AF_INET6) { |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4920 | if (port1 != port2) { |
| 4921 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 4922 | file, linenum, args[0], args[1]); |
| 4923 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4924 | goto out; |
| 4925 | } |
| 4926 | |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4927 | if (!port1) |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4928 | set_host_port(&logsrv->addr, SYSLOG_PORT); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4929 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4930 | |
| 4931 | LIST_ADDQ(&curproxy->logsrvs, &logsrv->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4932 | } |
| 4933 | else { |
| 4934 | Alert("parsing [%s:%d] : 'log' expects either <address[:port]> and <facility> or 'global' as arguments.\n", |
| 4935 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4936 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4937 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4938 | } |
| 4939 | } |
| 4940 | 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] | 4941 | int cur_arg; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4942 | int port1, port2; |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4943 | struct sockaddr_storage *sk; |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 4944 | struct protocol *proto; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4945 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4946 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4947 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4948 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4949 | if (!*args[1]) { |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4950 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optionally '%s' <addr>, and '%s' <name>.\n", |
| 4951 | file, linenum, "source", "usesrc", "interface"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4952 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4953 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4954 | } |
Willy Tarreau | 368480c | 2009-03-01 08:27:21 +0100 | [diff] [blame] | 4955 | |
| 4956 | /* we must first clear any optional default setting */ |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4957 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 4958 | free(curproxy->conn_src.iface_name); |
| 4959 | curproxy->conn_src.iface_name = NULL; |
| 4960 | curproxy->conn_src.iface_len = 0; |
Willy Tarreau | 368480c | 2009-03-01 08:27:21 +0100 | [diff] [blame] | 4961 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 4962 | sk = str2sa_range(args[1], &port1, &port2, &errmsg, NULL); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4963 | if (!sk) { |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 4964 | Alert("parsing [%s:%d] : '%s %s' : %s\n", |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 4965 | file, linenum, args[0], args[1], errmsg); |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 4966 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 4967 | goto out; |
| 4968 | } |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 4969 | |
| 4970 | proto = protocol_by_family(sk->ss_family); |
| 4971 | if (!proto || !proto->connect) { |
| 4972 | 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] | 4973 | file, linenum, args[0], args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4974 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4975 | goto out; |
| 4976 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4977 | |
| 4978 | if (port1 != port2) { |
| 4979 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 4980 | file, linenum, args[0], args[1]); |
| 4981 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4982 | goto out; |
| 4983 | } |
| 4984 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4985 | curproxy->conn_src.source_addr = *sk; |
| 4986 | curproxy->conn_src.opts |= CO_SRC_BIND; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4987 | |
| 4988 | cur_arg = 2; |
| 4989 | while (*(args[cur_arg])) { |
| 4990 | if (!strcmp(args[cur_arg], "usesrc")) { /* address to use outside */ |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4991 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) |
| 4992 | #if !defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4993 | if (!is_addr(&curproxy->conn_src.source_addr)) { |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4994 | Alert("parsing [%s:%d] : '%s' requires an explicit 'source' address.\n", |
| 4995 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4996 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4997 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4998 | } |
| 4999 | #endif |
| 5000 | if (!*args[cur_arg + 1]) { |
| 5001 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n", |
| 5002 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5003 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5004 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5005 | } |
| 5006 | |
| 5007 | if (!strcmp(args[cur_arg + 1], "client")) { |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 5008 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 5009 | curproxy->conn_src.opts |= CO_SRC_TPROXY_CLI; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5010 | } else if (!strcmp(args[cur_arg + 1], "clientip")) { |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 5011 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 5012 | curproxy->conn_src.opts |= CO_SRC_TPROXY_CIP; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 5013 | } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) { |
| 5014 | char *name, *end; |
| 5015 | |
| 5016 | name = args[cur_arg+1] + 7; |
| 5017 | while (isspace(*name)) |
| 5018 | name++; |
| 5019 | |
| 5020 | end = name; |
| 5021 | while (*end && !isspace(*end) && *end != ',' && *end != ')') |
| 5022 | end++; |
| 5023 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 5024 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 5025 | curproxy->conn_src.opts |= CO_SRC_TPROXY_DYN; |
| 5026 | curproxy->conn_src.bind_hdr_name = calloc(1, end - name + 1); |
| 5027 | curproxy->conn_src.bind_hdr_len = end - name; |
| 5028 | memcpy(curproxy->conn_src.bind_hdr_name, name, end - name); |
| 5029 | curproxy->conn_src.bind_hdr_name[end-name] = '\0'; |
| 5030 | curproxy->conn_src.bind_hdr_occ = -1; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 5031 | |
| 5032 | /* now look for an occurrence number */ |
| 5033 | while (isspace(*end)) |
| 5034 | end++; |
| 5035 | if (*end == ',') { |
| 5036 | end++; |
| 5037 | name = end; |
| 5038 | if (*end == '-') |
| 5039 | end++; |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 5040 | while (isdigit((int)*end)) |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 5041 | end++; |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 5042 | curproxy->conn_src.bind_hdr_occ = strl2ic(name, end-name); |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 5043 | } |
| 5044 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 5045 | if (curproxy->conn_src.bind_hdr_occ < -MAX_HDR_HISTORY) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 5046 | Alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative" |
| 5047 | " occurrences values smaller than %d.\n", |
| 5048 | file, linenum, MAX_HDR_HISTORY); |
| 5049 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5050 | goto out; |
| 5051 | } |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5052 | } else { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 5053 | struct sockaddr_storage *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5054 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 5055 | sk = str2sa_range(args[cur_arg + 1], &port1, &port2, &errmsg, NULL); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 5056 | if (!sk) { |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 5057 | Alert("parsing [%s:%d] : '%s %s' : %s\n", |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 5058 | file, linenum, args[cur_arg], args[cur_arg+1], errmsg); |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 5059 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 5060 | goto out; |
| 5061 | } |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 5062 | |
| 5063 | proto = protocol_by_family(sk->ss_family); |
| 5064 | if (!proto || !proto->connect) { |
| 5065 | Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 5066 | file, linenum, args[cur_arg], args[cur_arg+1]); |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5067 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5068 | goto out; |
| 5069 | } |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 5070 | |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5071 | if (port1 != port2) { |
| 5072 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 5073 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 5074 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5075 | goto out; |
| 5076 | } |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 5077 | curproxy->conn_src.tproxy_addr = *sk; |
| 5078 | curproxy->conn_src.opts |= CO_SRC_TPROXY_ADDR; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5079 | } |
| 5080 | global.last_checks |= LSTCHK_NETADM; |
| 5081 | #if !defined(CONFIG_HAP_LINUX_TPROXY) |
| 5082 | global.last_checks |= LSTCHK_CTTPROXY; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 5083 | #endif |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5084 | #else /* no TPROXY support */ |
| 5085 | 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] | 5086 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5087 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5088 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5089 | #endif |
| 5090 | cur_arg += 2; |
| 5091 | continue; |
Willy Tarreau | 77074d5 | 2006-11-12 23:57:19 +0100 | [diff] [blame] | 5092 | } |
| 5093 | |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5094 | if (!strcmp(args[cur_arg], "interface")) { /* specifically bind to this interface */ |
| 5095 | #ifdef SO_BINDTODEVICE |
| 5096 | if (!*args[cur_arg + 1]) { |
| 5097 | Alert("parsing [%s:%d] : '%s' : missing interface name.\n", |
| 5098 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5099 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5100 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5101 | } |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 5102 | free(curproxy->conn_src.iface_name); |
| 5103 | curproxy->conn_src.iface_name = strdup(args[cur_arg + 1]); |
| 5104 | curproxy->conn_src.iface_len = strlen(curproxy->conn_src.iface_name); |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5105 | global.last_checks |= LSTCHK_NETADM; |
| 5106 | #else |
| 5107 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 5108 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5109 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5110 | goto out; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 5111 | #endif |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5112 | cur_arg += 2; |
| 5113 | continue; |
| 5114 | } |
| 5115 | 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] | 5116 | file, linenum, args[0], "interface", "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5117 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5118 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 5119 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5120 | } |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 5121 | else if (!strcmp(args[0], "usesrc")) { /* address to use outside: needs "source" first */ |
| 5122 | Alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n", |
| 5123 | file, linenum, "usesrc", "source"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5124 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5125 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 5126 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5127 | 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] | 5128 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5129 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 5130 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5131 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5132 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5133 | } |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5134 | |
| 5135 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5136 | SMP_OPT_DIR_REQ, ACT_REPLACE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5137 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5138 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5139 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5140 | } |
| 5141 | else if (!strcmp(args[0], "reqdel")) { /* delete request header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5142 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5143 | SMP_OPT_DIR_REQ, ACT_REMOVE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5144 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5145 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5146 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5147 | } |
| 5148 | else if (!strcmp(args[0], "reqdeny")) { /* deny a request if a header matches this regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5149 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5150 | SMP_OPT_DIR_REQ, ACT_DENY, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5151 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5152 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5153 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5154 | } |
| 5155 | else if (!strcmp(args[0], "reqpass")) { /* pass this header without allowing or denying the request */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5156 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5157 | SMP_OPT_DIR_REQ, ACT_PASS, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5158 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5159 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5160 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5161 | } |
| 5162 | 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] | 5163 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5164 | SMP_OPT_DIR_REQ, ACT_ALLOW, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5165 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5166 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5167 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5168 | } |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 5169 | 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] | 5170 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5171 | SMP_OPT_DIR_REQ, ACT_TARPIT, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5172 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5173 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5174 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 5175 | } |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5176 | 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] | 5177 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5178 | SMP_OPT_DIR_REQ, ACT_SETBE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5179 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5180 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5181 | goto out; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5182 | } |
| 5183 | 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] | 5184 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5185 | SMP_OPT_DIR_REQ, ACT_SETBE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5186 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5187 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5188 | goto out; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5189 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5190 | 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] | 5191 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5192 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 5193 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5194 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5195 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5196 | } |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5197 | |
| 5198 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5199 | SMP_OPT_DIR_REQ, ACT_REPLACE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5200 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5201 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5202 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5203 | } |
| 5204 | 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] | 5205 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5206 | SMP_OPT_DIR_REQ, ACT_REMOVE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5207 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5208 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5209 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5210 | } |
| 5211 | 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] | 5212 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5213 | SMP_OPT_DIR_REQ, ACT_DENY, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5214 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5215 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5216 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5217 | } |
| 5218 | 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] | 5219 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5220 | SMP_OPT_DIR_REQ, ACT_PASS, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5221 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5222 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5223 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5224 | } |
| 5225 | 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] | 5226 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5227 | SMP_OPT_DIR_REQ, ACT_ALLOW, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5228 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5229 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5230 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5231 | } |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 5232 | 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] | 5233 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5234 | SMP_OPT_DIR_REQ, ACT_TARPIT, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5235 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5236 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5237 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 5238 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5239 | else if (!strcmp(args[0], "reqadd")) { /* add request header */ |
Willy Tarreau | f4f0412 | 2010-01-28 18:10:50 +0100 | [diff] [blame] | 5240 | struct cond_wordlist *wl; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5241 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5242 | if (curproxy == &defproxy) { |
| 5243 | 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] | 5244 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5245 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5246 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5247 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5248 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5249 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5250 | if (*(args[1]) == 0) { |
| 5251 | 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] | 5252 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5253 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5254 | } |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5255 | |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 5256 | if ((strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0)) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 5257 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args+2, &errmsg)) == NULL) { |
| 5258 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 5259 | file, linenum, args[0], errmsg); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 5260 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5261 | goto out; |
| 5262 | } |
| 5263 | err_code |= warnif_cond_requires_resp(cond, file, linenum); |
| 5264 | } |
| 5265 | else if (*args[2]) { |
| 5266 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 5267 | file, linenum, args[0], args[2]); |
| 5268 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5269 | goto out; |
| 5270 | } |
| 5271 | |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5272 | wl = calloc(1, sizeof(*wl)); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 5273 | wl->cond = cond; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5274 | wl->s = strdup(args[1]); |
| 5275 | LIST_ADDQ(&curproxy->req_add, &wl->list); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 5276 | warnif_misplaced_reqadd(curproxy, file, linenum, args[0]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5277 | } |
| 5278 | 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] | 5279 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5280 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 5281 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5282 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5283 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5284 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5285 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5286 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5287 | SMP_OPT_DIR_RES, ACT_REPLACE, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5288 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5289 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5290 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5291 | } |
| 5292 | else if (!strcmp(args[0], "rspdel")) { /* delete response header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5293 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5294 | SMP_OPT_DIR_RES, ACT_REMOVE, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5295 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5296 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5297 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5298 | } |
| 5299 | else if (!strcmp(args[0], "rspdeny")) { /* block response header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5300 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5301 | SMP_OPT_DIR_RES, ACT_DENY, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5302 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5303 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5304 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5305 | } |
| 5306 | 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] | 5307 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5308 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 5309 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5310 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5311 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5312 | } |
| 5313 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5314 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5315 | SMP_OPT_DIR_RES, ACT_REPLACE, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5316 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5317 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5318 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5319 | } |
| 5320 | 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] | 5321 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5322 | SMP_OPT_DIR_RES, ACT_REMOVE, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5323 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5324 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5325 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5326 | } |
| 5327 | 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] | 5328 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5329 | SMP_OPT_DIR_RES, ACT_DENY, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5330 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5331 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5332 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5333 | } |
| 5334 | else if (!strcmp(args[0], "rspadd")) { /* add response header */ |
Willy Tarreau | f4f0412 | 2010-01-28 18:10:50 +0100 | [diff] [blame] | 5335 | struct cond_wordlist *wl; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5336 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5337 | if (curproxy == &defproxy) { |
| 5338 | 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] | 5339 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5340 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5341 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5342 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5343 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5344 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5345 | if (*(args[1]) == 0) { |
| 5346 | 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] | 5347 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5348 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5349 | } |
| 5350 | |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5351 | if ((strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0)) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 5352 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args+2, &errmsg)) == NULL) { |
| 5353 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 5354 | file, linenum, args[0], errmsg); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5355 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5356 | goto out; |
| 5357 | } |
| 5358 | err_code |= warnif_cond_requires_req(cond, file, linenum); |
| 5359 | } |
| 5360 | else if (*args[2]) { |
| 5361 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 5362 | file, linenum, args[0], args[2]); |
| 5363 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5364 | goto out; |
| 5365 | } |
| 5366 | |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5367 | wl = calloc(1, sizeof(*wl)); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5368 | wl->cond = cond; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5369 | wl->s = strdup(args[1]); |
| 5370 | LIST_ADDQ(&curproxy->rsp_add, &wl->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5371 | } |
| 5372 | else if (!strcmp(args[0], "errorloc") || |
| 5373 | !strcmp(args[0], "errorloc302") || |
| 5374 | !strcmp(args[0], "errorloc303")) { /* error location */ |
| 5375 | int errnum, errlen; |
| 5376 | char *err; |
| 5377 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5378 | if (warnifnotcap(curproxy, PR_CAP_FE | PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5379 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5380 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5381 | if (*(args[2]) == 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 5382 | Alert("parsing [%s:%d] : <%s> expects <status_code> and <url> as arguments.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5383 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5384 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5385 | } |
| 5386 | |
| 5387 | errnum = atol(args[1]); |
| 5388 | if (!strcmp(args[0], "errorloc303")) { |
| 5389 | err = malloc(strlen(HTTP_303) + strlen(args[2]) + 5); |
| 5390 | errlen = sprintf(err, "%s%s\r\n\r\n", HTTP_303, args[2]); |
| 5391 | } else { |
| 5392 | err = malloc(strlen(HTTP_302) + strlen(args[2]) + 5); |
| 5393 | errlen = sprintf(err, "%s%s\r\n\r\n", HTTP_302, args[2]); |
| 5394 | } |
| 5395 | |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 5396 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) { |
| 5397 | if (http_err_codes[rc] == errnum) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 5398 | chunk_destroy(&curproxy->errmsg[rc]); |
| 5399 | chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 5400 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5401 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5402 | } |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 5403 | |
| 5404 | if (rc >= HTTP_ERR_SIZE) { |
| 5405 | Warning("parsing [%s:%d] : status code %d not handled, error relocation will be ignored.\n", |
| 5406 | file, linenum, errnum); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5407 | free(err); |
| 5408 | } |
| 5409 | } |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5410 | else if (!strcmp(args[0], "errorfile")) { /* error message from a file */ |
| 5411 | int errnum, errlen, fd; |
| 5412 | char *err; |
| 5413 | struct stat stat; |
| 5414 | |
| 5415 | 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] | 5416 | err_code |= ERR_WARN; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5417 | |
| 5418 | if (*(args[2]) == 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 5419 | 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] | 5420 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5421 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5422 | } |
| 5423 | |
| 5424 | fd = open(args[2], O_RDONLY); |
| 5425 | if ((fd < 0) || (fstat(fd, &stat) < 0)) { |
| 5426 | Alert("parsing [%s:%d] : error opening file <%s> for custom error message <%s>.\n", |
| 5427 | file, linenum, args[2], args[1]); |
| 5428 | if (fd >= 0) |
| 5429 | close(fd); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5430 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5431 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5432 | } |
| 5433 | |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 5434 | if (stat.st_size <= global.tune.bufsize) { |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5435 | errlen = stat.st_size; |
| 5436 | } else { |
| 5437 | 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] | 5438 | file, linenum, args[2], global.tune.bufsize); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5439 | err_code |= ERR_WARN; |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 5440 | errlen = global.tune.bufsize; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5441 | } |
| 5442 | |
| 5443 | err = malloc(errlen); /* malloc() must succeed during parsing */ |
| 5444 | errnum = read(fd, err, errlen); |
| 5445 | if (errnum != errlen) { |
| 5446 | Alert("parsing [%s:%d] : error reading file <%s> for custom error message <%s>.\n", |
| 5447 | file, linenum, args[2], args[1]); |
| 5448 | close(fd); |
| 5449 | free(err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5450 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5451 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5452 | } |
| 5453 | close(fd); |
| 5454 | |
| 5455 | errnum = atol(args[1]); |
| 5456 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) { |
| 5457 | if (http_err_codes[rc] == errnum) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 5458 | chunk_destroy(&curproxy->errmsg[rc]); |
| 5459 | chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen); |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5460 | break; |
| 5461 | } |
| 5462 | } |
| 5463 | |
| 5464 | if (rc >= HTTP_ERR_SIZE) { |
| 5465 | Warning("parsing [%s:%d] : status code %d not handled, error customization will be ignored.\n", |
| 5466 | file, linenum, errnum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5467 | err_code |= ERR_WARN; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5468 | free(err); |
| 5469 | } |
| 5470 | } |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5471 | else if (!strcmp(args[0], "compression")) { |
| 5472 | struct comp *comp; |
| 5473 | if (curproxy->comp == NULL) { |
| 5474 | comp = calloc(1, sizeof(struct comp)); |
| 5475 | curproxy->comp = comp; |
| 5476 | } else { |
| 5477 | comp = curproxy->comp; |
| 5478 | } |
| 5479 | |
| 5480 | if (!strcmp(args[1], "algo")) { |
| 5481 | int cur_arg; |
William Lallemand | 8b52bb3 | 2012-11-16 18:06:41 +0100 | [diff] [blame] | 5482 | struct comp_ctx *ctx; |
William Lallemand | 552df67 | 2012-11-07 13:21:47 +0100 | [diff] [blame] | 5483 | |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5484 | cur_arg = 2; |
| 5485 | if (!*args[cur_arg]) { |
| 5486 | Alert("parsing [%s:%d] : '%s' expects <algorithm>\n", |
| 5487 | file, linenum, args[0]); |
| 5488 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5489 | goto out; |
| 5490 | } |
| 5491 | while (*(args[cur_arg])) { |
| 5492 | if (comp_append_algo(comp, args[cur_arg]) < 0) { |
| 5493 | Alert("parsing [%s:%d] : '%s' : '%s' is not a supported algorithm.\n", |
| 5494 | file, linenum, args[0], args[cur_arg]); |
| 5495 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5496 | goto out; |
| 5497 | } |
William Lallemand | 552df67 | 2012-11-07 13:21:47 +0100 | [diff] [blame] | 5498 | if (curproxy->comp->algos->init(&ctx, 9) == 0) { |
| 5499 | curproxy->comp->algos->end(&ctx); |
| 5500 | } else { |
| 5501 | Alert("parsing [%s:%d] : '%s' : Can't init '%s' algorithm.\n", |
| 5502 | file, linenum, args[0], args[cur_arg]); |
| 5503 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5504 | goto out; |
| 5505 | } |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5506 | cur_arg ++; |
| 5507 | continue; |
| 5508 | } |
| 5509 | } |
Willy Tarreau | 70737d1 | 2012-10-27 00:34:28 +0200 | [diff] [blame] | 5510 | else if (!strcmp(args[1], "offload")) { |
| 5511 | comp->offload = 1; |
| 5512 | } |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5513 | else if (!strcmp(args[1], "type")) { |
| 5514 | int cur_arg; |
| 5515 | cur_arg = 2; |
| 5516 | if (!*args[cur_arg]) { |
| 5517 | Alert("parsing [%s:%d] : '%s' expects <type>\n", |
| 5518 | file, linenum, args[0]); |
| 5519 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5520 | goto out; |
| 5521 | } |
| 5522 | while (*(args[cur_arg])) { |
| 5523 | comp_append_type(comp, args[cur_arg]); |
| 5524 | cur_arg ++; |
| 5525 | continue; |
| 5526 | } |
| 5527 | } |
| 5528 | else { |
Willy Tarreau | 70737d1 | 2012-10-27 00:34:28 +0200 | [diff] [blame] | 5529 | Alert("parsing [%s:%d] : '%s' expects 'algo', 'type' or 'offload'\n", |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5530 | file, linenum, args[0]); |
| 5531 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5532 | goto out; |
| 5533 | } |
| 5534 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5535 | else { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 5536 | struct cfg_kw_list *kwl; |
| 5537 | int index; |
| 5538 | |
| 5539 | list_for_each_entry(kwl, &cfg_keywords.list, list) { |
| 5540 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 5541 | if (kwl->kw[index].section != CFG_LISTEN) |
| 5542 | continue; |
| 5543 | if (strcmp(kwl->kw[index].kw, args[0]) == 0) { |
| 5544 | /* prepare error message just in case */ |
Willy Tarreau | 28a47d6 | 2012-09-18 20:02:48 +0200 | [diff] [blame] | 5545 | 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] | 5546 | if (rc < 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 5547 | Alert("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5548 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5549 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 5550 | } |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 5551 | else if (rc > 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 5552 | Warning("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5553 | err_code |= ERR_WARN; |
| 5554 | goto out; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 5555 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5556 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 5557 | } |
| 5558 | } |
| 5559 | } |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5560 | |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5561 | 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] | 5562 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5563 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5564 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5565 | out: |
Willy Tarreau | f4068b6 | 2012-05-08 17:37:49 +0200 | [diff] [blame] | 5566 | free(errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5567 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5568 | } |
| 5569 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5570 | int |
| 5571 | cfg_parse_users(const char *file, int linenum, char **args, int kwm) |
| 5572 | { |
| 5573 | |
| 5574 | int err_code = 0; |
| 5575 | const char *err; |
| 5576 | |
| 5577 | if (!strcmp(args[0], "userlist")) { /* new userlist */ |
| 5578 | struct userlist *newul; |
| 5579 | |
| 5580 | if (!*args[1]) { |
| 5581 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 5582 | file, linenum, args[0]); |
| 5583 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5584 | goto out; |
| 5585 | } |
| 5586 | |
| 5587 | err = invalid_char(args[1]); |
| 5588 | if (err) { |
| 5589 | Alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 5590 | file, linenum, *err, args[0], args[1]); |
| 5591 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5592 | goto out; |
| 5593 | } |
| 5594 | |
| 5595 | for (newul = userlist; newul; newul = newul->next) |
| 5596 | if (!strcmp(newul->name, args[1])) { |
| 5597 | Warning("parsing [%s:%d]: ignoring duplicated userlist '%s'.\n", |
| 5598 | file, linenum, args[1]); |
| 5599 | err_code |= ERR_WARN; |
| 5600 | goto out; |
| 5601 | } |
| 5602 | |
| 5603 | newul = (struct userlist *)calloc(1, sizeof(struct userlist)); |
| 5604 | if (!newul) { |
| 5605 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 5606 | err_code |= ERR_ALERT | ERR_ABORT; |
| 5607 | goto out; |
| 5608 | } |
| 5609 | |
| 5610 | newul->groupusers = calloc(MAX_AUTH_GROUPS, sizeof(char *)); |
| 5611 | newul->name = strdup(args[1]); |
| 5612 | |
| 5613 | if (!newul->groupusers | !newul->name) { |
| 5614 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 5615 | err_code |= ERR_ALERT | ERR_ABORT; |
| 5616 | goto out; |
| 5617 | } |
| 5618 | |
| 5619 | newul->next = userlist; |
| 5620 | userlist = newul; |
| 5621 | |
| 5622 | } else if (!strcmp(args[0], "group")) { /* new group */ |
| 5623 | int cur_arg, i; |
| 5624 | const char *err; |
| 5625 | |
| 5626 | if (!*args[1]) { |
| 5627 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 5628 | file, linenum, args[0]); |
| 5629 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5630 | goto out; |
| 5631 | } |
| 5632 | |
| 5633 | err = invalid_char(args[1]); |
| 5634 | if (err) { |
| 5635 | Alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 5636 | file, linenum, *err, args[0], args[1]); |
| 5637 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5638 | goto out; |
| 5639 | } |
| 5640 | |
| 5641 | for(i = 0; i < userlist->grpcnt; i++) |
| 5642 | if (!strcmp(userlist->groups[i], args[1])) { |
| 5643 | Warning("parsing [%s:%d]: ignoring duplicated group '%s' in userlist '%s'.\n", |
| 5644 | file, linenum, args[1], userlist->name); |
| 5645 | err_code |= ERR_ALERT; |
| 5646 | goto out; |
| 5647 | } |
| 5648 | |
| 5649 | if (userlist->grpcnt >= MAX_AUTH_GROUPS) { |
| 5650 | Alert("parsing [%s:%d]: too many groups (%u) in in userlist '%s' while adding group '%s'.\n", |
| 5651 | file, linenum, MAX_AUTH_GROUPS, userlist->name, args[1]); |
| 5652 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5653 | goto out; |
| 5654 | } |
| 5655 | |
| 5656 | cur_arg = 2; |
| 5657 | |
| 5658 | while (*args[cur_arg]) { |
| 5659 | if (!strcmp(args[cur_arg], "users")) { |
| 5660 | userlist->groupusers[userlist->grpcnt] = strdup(args[cur_arg + 1]); |
| 5661 | cur_arg += 2; |
| 5662 | continue; |
| 5663 | } else { |
| 5664 | Alert("parsing [%s:%d]: '%s' only supports 'users' option.\n", |
| 5665 | file, linenum, args[0]); |
| 5666 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5667 | goto out; |
| 5668 | } |
| 5669 | } |
| 5670 | |
| 5671 | userlist->groups[userlist->grpcnt++] = strdup(args[1]); |
| 5672 | } else if (!strcmp(args[0], "user")) { /* new user */ |
| 5673 | struct auth_users *newuser; |
| 5674 | int cur_arg; |
| 5675 | |
| 5676 | if (!*args[1]) { |
| 5677 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 5678 | file, linenum, args[0]); |
| 5679 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5680 | goto out; |
| 5681 | } |
| 5682 | |
| 5683 | for (newuser = userlist->users; newuser; newuser = newuser->next) |
| 5684 | if (!strcmp(newuser->user, args[1])) { |
| 5685 | Warning("parsing [%s:%d]: ignoring duplicated user '%s' in userlist '%s'.\n", |
| 5686 | file, linenum, args[1], userlist->name); |
| 5687 | err_code |= ERR_ALERT; |
| 5688 | goto out; |
| 5689 | } |
| 5690 | |
| 5691 | newuser = (struct auth_users *)calloc(1, sizeof(struct auth_users)); |
| 5692 | if (!newuser) { |
| 5693 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 5694 | err_code |= ERR_ALERT | ERR_ABORT; |
| 5695 | goto out; |
| 5696 | } |
| 5697 | |
| 5698 | newuser->user = strdup(args[1]); |
| 5699 | |
| 5700 | newuser->next = userlist->users; |
| 5701 | userlist->users = newuser; |
| 5702 | |
| 5703 | cur_arg = 2; |
| 5704 | |
| 5705 | while (*args[cur_arg]) { |
| 5706 | if (!strcmp(args[cur_arg], "password")) { |
| 5707 | #ifndef CONFIG_HAP_CRYPT |
| 5708 | Warning("parsing [%s:%d]: no crypt(3) support compiled, encrypted passwords will not work.\n", |
| 5709 | file, linenum); |
| 5710 | err_code |= ERR_ALERT; |
| 5711 | #endif |
| 5712 | newuser->pass = strdup(args[cur_arg + 1]); |
| 5713 | cur_arg += 2; |
| 5714 | continue; |
| 5715 | } else if (!strcmp(args[cur_arg], "insecure-password")) { |
| 5716 | newuser->pass = strdup(args[cur_arg + 1]); |
| 5717 | newuser->flags |= AU_O_INSECURE; |
| 5718 | cur_arg += 2; |
| 5719 | continue; |
| 5720 | } else if (!strcmp(args[cur_arg], "groups")) { |
Willy Tarreau | b4c06b7 | 2010-02-02 11:28:20 +0100 | [diff] [blame] | 5721 | newuser->u.groups = strdup(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5722 | cur_arg += 2; |
| 5723 | continue; |
| 5724 | } else { |
| 5725 | Alert("parsing [%s:%d]: '%s' only supports 'password', 'insecure-password' and 'groups' options.\n", |
| 5726 | file, linenum, args[0]); |
| 5727 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5728 | goto out; |
| 5729 | } |
| 5730 | } |
| 5731 | } else { |
| 5732 | Alert("parsing [%s:%d]: unknown keyword '%s' in '%s' section\n", file, linenum, args[0], "users"); |
| 5733 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5734 | } |
| 5735 | |
| 5736 | out: |
| 5737 | return err_code; |
| 5738 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5739 | |
| 5740 | /* |
| 5741 | * This function reads and parses the configuration file given in the argument. |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5742 | * Returns the error code, 0 if OK, or any combination of : |
| 5743 | * - ERR_ABORT: must abort ASAP |
| 5744 | * - ERR_FATAL: we can continue parsing but not start the service |
| 5745 | * - ERR_WARN: a warning has been emitted |
| 5746 | * - ERR_ALERT: an alert has been emitted |
| 5747 | * Only the two first ones can stop processing, the two others are just |
| 5748 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5749 | */ |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 5750 | int readcfgfile(const char *file) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5751 | { |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5752 | char thisline[LINESIZE]; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5753 | FILE *f; |
| 5754 | int linenum = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5755 | int confsect = CFG_NONE; |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5756 | int err_code = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5757 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5758 | if ((f=fopen(file,"r")) == NULL) |
| 5759 | return -1; |
| 5760 | |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5761 | while (fgets(thisline, sizeof(thisline), f) != NULL) { |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 5762 | int arg, kwm = KWM_STD; |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5763 | char *end; |
| 5764 | char *args[MAX_LINE_ARGS + 1]; |
| 5765 | char *line = thisline; |
| 5766 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5767 | linenum++; |
| 5768 | |
| 5769 | end = line + strlen(line); |
| 5770 | |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5771 | if (end-line == sizeof(thisline)-1 && *(end-1) != '\n') { |
| 5772 | /* Check if we reached the limit and the last char is not \n. |
| 5773 | * Watch out for the last line without the terminating '\n'! |
| 5774 | */ |
| 5775 | Alert("parsing [%s:%d]: line too long, limit: %d.\n", |
Willy Tarreau | 5e4a6f1 | 2009-04-11 19:42:49 +0200 | [diff] [blame] | 5776 | file, linenum, (int)sizeof(thisline)-1); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5777 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5778 | } |
| 5779 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5780 | /* skip leading spaces */ |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 5781 | while (isspace((unsigned char)*line)) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5782 | line++; |
| 5783 | |
| 5784 | arg = 0; |
| 5785 | args[arg] = line; |
| 5786 | |
| 5787 | while (*line && arg < MAX_LINE_ARGS) { |
| 5788 | /* first, we'll replace \\, \<space>, \#, \r, \n, \t, \xXX with their |
| 5789 | * C equivalent value. Other combinations left unchanged (eg: \1). |
| 5790 | */ |
| 5791 | if (*line == '\\') { |
| 5792 | int skip = 0; |
| 5793 | if (line[1] == ' ' || line[1] == '\\' || line[1] == '#') { |
| 5794 | *line = line[1]; |
| 5795 | skip = 1; |
| 5796 | } |
| 5797 | else if (line[1] == 'r') { |
| 5798 | *line = '\r'; |
| 5799 | skip = 1; |
| 5800 | } |
| 5801 | else if (line[1] == 'n') { |
| 5802 | *line = '\n'; |
| 5803 | skip = 1; |
| 5804 | } |
| 5805 | else if (line[1] == 't') { |
| 5806 | *line = '\t'; |
| 5807 | skip = 1; |
| 5808 | } |
| 5809 | else if (line[1] == 'x') { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5810 | if ((line + 3 < end) && ishex(line[2]) && ishex(line[3])) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5811 | unsigned char hex1, hex2; |
| 5812 | hex1 = toupper(line[2]) - '0'; |
| 5813 | hex2 = toupper(line[3]) - '0'; |
| 5814 | if (hex1 > 9) hex1 -= 'A' - '9' - 1; |
| 5815 | if (hex2 > 9) hex2 -= 'A' - '9' - 1; |
| 5816 | *line = (hex1<<4) + hex2; |
| 5817 | skip = 3; |
| 5818 | } |
| 5819 | else { |
| 5820 | 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] | 5821 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5822 | } |
| 5823 | } |
| 5824 | if (skip) { |
Cyril Bonté | dd1b01d | 2009-12-06 13:43:42 +0100 | [diff] [blame] | 5825 | memmove(line + 1, line + 1 + skip, end - (line + skip)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5826 | end -= skip; |
| 5827 | } |
| 5828 | line++; |
| 5829 | } |
| 5830 | else if (*line == '#' || *line == '\n' || *line == '\r') { |
| 5831 | /* end of string, end of loop */ |
| 5832 | *line = 0; |
| 5833 | break; |
| 5834 | } |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 5835 | else if (isspace((unsigned char)*line)) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5836 | /* a non-escaped space is an argument separator */ |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5837 | *line++ = '\0'; |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 5838 | while (isspace((unsigned char)*line)) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5839 | line++; |
| 5840 | args[++arg] = line; |
| 5841 | } |
| 5842 | else { |
| 5843 | line++; |
| 5844 | } |
| 5845 | } |
| 5846 | |
| 5847 | /* empty line */ |
| 5848 | if (!**args) |
| 5849 | continue; |
| 5850 | |
Willy Tarreau | 7bb651e | 2009-11-09 21:16:53 +0100 | [diff] [blame] | 5851 | if (*line) { |
| 5852 | /* we had to stop due to too many args. |
| 5853 | * Let's terminate the string, print the offending part then cut the |
| 5854 | * last arg. |
| 5855 | */ |
| 5856 | while (*line && *line != '#' && *line != '\n' && *line != '\r') |
| 5857 | line++; |
| 5858 | *line = '\0'; |
| 5859 | |
Krzysztof Piotr Oledzki | 500b8f0 | 2009-12-15 22:34:51 +0100 | [diff] [blame] | 5860 | 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] | 5861 | file, linenum, arg + 1, (long)(args[arg] - thisline + 1), args[arg]); |
Willy Tarreau | 7bb651e | 2009-11-09 21:16:53 +0100 | [diff] [blame] | 5862 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5863 | args[arg] = line; |
| 5864 | } |
| 5865 | |
Willy Tarreau | 540abe4 | 2007-05-02 20:50:16 +0200 | [diff] [blame] | 5866 | /* zero out remaining args and ensure that at least one entry |
| 5867 | * is zeroed out. |
| 5868 | */ |
| 5869 | while (++arg <= MAX_LINE_ARGS) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5870 | args[arg] = line; |
| 5871 | } |
| 5872 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 5873 | /* check for keyword modifiers "no" and "default" */ |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5874 | if (!strcmp(args[0], "no")) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5875 | char *tmp; |
| 5876 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 5877 | kwm = KWM_NO; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5878 | tmp = args[0]; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5879 | for (arg=0; *args[arg+1]; arg++) |
| 5880 | args[arg] = args[arg+1]; // shift args after inversion |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5881 | *tmp = '\0'; // fix the next arg to \0 |
| 5882 | args[arg] = tmp; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5883 | } |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 5884 | else if (!strcmp(args[0], "default")) { |
| 5885 | kwm = KWM_DEF; |
| 5886 | for (arg=0; *args[arg+1]; arg++) |
| 5887 | args[arg] = args[arg+1]; // shift args after inversion |
| 5888 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5889 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5890 | if (kwm != KWM_STD && strcmp(args[0], "option") != 0 && \ |
| 5891 | strcmp(args[0], "log") != 0) { |
| 5892 | 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] | 5893 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5894 | } |
| 5895 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5896 | if (!strcmp(args[0], "listen") || |
| 5897 | !strcmp(args[0], "frontend") || |
| 5898 | !strcmp(args[0], "backend") || |
| 5899 | !strcmp(args[0], "ruleset") || |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5900 | !strcmp(args[0], "defaults")) { /* new proxy */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5901 | confsect = CFG_LISTEN; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 5902 | free(cursection); |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5903 | cursection = strdup(args[0]); |
| 5904 | } |
| 5905 | else if (!strcmp(args[0], "global")) { /* global config */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5906 | confsect = CFG_GLOBAL; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 5907 | free(cursection); |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5908 | cursection = strdup(args[0]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 5909 | } |
| 5910 | else if (!strcmp(args[0], "userlist")) { |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5911 | confsect = CFG_USERLIST; |
| 5912 | free(cursection); |
| 5913 | cursection = strdup(args[0]); |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5914 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 5915 | else if (!strcmp(args[0], "peers")) { |
| 5916 | confsect = CFG_PEERS; |
| 5917 | free(cursection); |
| 5918 | cursection = strdup(args[0]); |
| 5919 | } |
| 5920 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5921 | /* else it's a section keyword */ |
| 5922 | |
| 5923 | switch (confsect) { |
| 5924 | case CFG_LISTEN: |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5925 | err_code |= cfg_parse_listen(file, linenum, args, kwm); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5926 | break; |
| 5927 | case CFG_GLOBAL: |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5928 | err_code |= cfg_parse_global(file, linenum, args, kwm); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5929 | break; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5930 | case CFG_USERLIST: |
| 5931 | err_code |= cfg_parse_users(file, linenum, args, kwm); |
| 5932 | break; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 5933 | case CFG_PEERS: |
| 5934 | err_code |= cfg_parse_peers(file, linenum, args, kwm); |
| 5935 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5936 | default: |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5937 | 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] | 5938 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5939 | } |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5940 | |
| 5941 | if (err_code & ERR_ABORT) |
| 5942 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5943 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 5944 | free(cursection); |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5945 | cursection = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5946 | fclose(f); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5947 | return err_code; |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5948 | } |
| 5949 | |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 5950 | /* |
| 5951 | * Returns the error code, 0 if OK, or any combination of : |
| 5952 | * - ERR_ABORT: must abort ASAP |
| 5953 | * - ERR_FATAL: we can continue parsing but not start the service |
| 5954 | * - ERR_WARN: a warning has been emitted |
| 5955 | * - ERR_ALERT: an alert has been emitted |
| 5956 | * Only the two first ones can stop processing, the two others are just |
| 5957 | * indicators. |
| 5958 | */ |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5959 | int check_config_validity() |
| 5960 | { |
| 5961 | int cfgerr = 0; |
| 5962 | struct proxy *curproxy = NULL; |
| 5963 | struct server *newsrv = NULL; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5964 | struct userlist *curuserlist = NULL; |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 5965 | int err_code = 0; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 5966 | unsigned int next_pxid = 1; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 5967 | struct bind_conf *bind_conf; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5968 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 5969 | bind_conf = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5970 | /* |
| 5971 | * Now, check for the integrity of all that we have collected. |
| 5972 | */ |
| 5973 | |
| 5974 | /* will be needed further to delay some tasks */ |
Willy Tarreau | b0b37bc | 2008-06-23 14:00:57 +0200 | [diff] [blame] | 5975 | tv_update_date(0,1); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5976 | |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 5977 | if (!global.tune.max_http_hdr) |
| 5978 | global.tune.max_http_hdr = MAX_HTTP_HDR; |
| 5979 | |
| 5980 | if (!global.tune.cookie_len) |
| 5981 | global.tune.cookie_len = CAPTURE_LEN; |
| 5982 | |
| 5983 | pool2_capture = create_pool("capture", global.tune.cookie_len, MEM_F_SHARED); |
| 5984 | |
Willy Tarreau | 55bc0f8 | 2009-03-15 14:51:53 +0100 | [diff] [blame] | 5985 | /* first, we will invert the proxy list order */ |
| 5986 | curproxy = NULL; |
| 5987 | while (proxy) { |
| 5988 | struct proxy *next; |
| 5989 | |
| 5990 | next = proxy->next; |
| 5991 | proxy->next = curproxy; |
| 5992 | curproxy = proxy; |
| 5993 | if (!next) |
| 5994 | break; |
| 5995 | proxy = next; |
| 5996 | } |
| 5997 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5998 | while (curproxy != NULL) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 5999 | struct switching_rule *rule; |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 6000 | struct server_rule *srule; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6001 | struct sticking_rule *mrule; |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 6002 | struct tcp_rule *trule; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 6003 | struct listener *listener; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6004 | unsigned int next_id; |
Willy Tarreau | 16a2147 | 2012-11-19 12:39:59 +0100 | [diff] [blame] | 6005 | int nbproc; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6006 | |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 6007 | if (curproxy->uuid < 0) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6008 | /* proxy ID not set, use automatic numbering with first |
| 6009 | * spare entry starting with next_pxid. |
| 6010 | */ |
| 6011 | next_pxid = get_next_id(&used_proxy_id, next_pxid); |
| 6012 | curproxy->conf.id.key = curproxy->uuid = next_pxid; |
| 6013 | eb32_insert(&used_proxy_id, &curproxy->conf.id); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6014 | } |
Krzysztof Piotr Oledzki | df5cb9f | 2010-02-05 20:58:27 +0100 | [diff] [blame] | 6015 | next_pxid++; |
| 6016 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6017 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6018 | if (curproxy->state == PR_STSTOPPED) { |
Willy Tarreau | da250db | 2008-10-12 12:07:48 +0200 | [diff] [blame] | 6019 | /* ensure we don't keep listeners uselessly bound */ |
| 6020 | stop_proxy(curproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6021 | curproxy = curproxy->next; |
| 6022 | continue; |
| 6023 | } |
| 6024 | |
Willy Tarreau | 16a2147 | 2012-11-19 12:39:59 +0100 | [diff] [blame] | 6025 | /* number of processes this proxy is bound to */ |
| 6026 | nbproc = curproxy->bind_proc ? popcount(curproxy->bind_proc) : global.nbproc; |
| 6027 | |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 6028 | switch (curproxy->mode) { |
| 6029 | case PR_MODE_HEALTH: |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6030 | cfgerr += proxy_cfg_ensure_no_http(curproxy); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 6031 | if (!(curproxy->cap & PR_CAP_FE)) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6032 | Alert("config : %s '%s' cannot be in health mode as it has no frontend capability.\n", |
| 6033 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 6034 | cfgerr++; |
| 6035 | } |
| 6036 | |
| 6037 | if (curproxy->srv != NULL) |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6038 | Warning("config : servers will be ignored for %s '%s'.\n", |
| 6039 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 6040 | break; |
| 6041 | |
| 6042 | case PR_MODE_TCP: |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6043 | cfgerr += proxy_cfg_ensure_no_http(curproxy); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 6044 | break; |
| 6045 | |
| 6046 | case PR_MODE_HTTP: |
Willy Tarreau | a9fb083 | 2009-07-10 20:53:53 +0200 | [diff] [blame] | 6047 | curproxy->acl_requires |= ACL_USE_L7_ANY; |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 6048 | break; |
| 6049 | } |
| 6050 | |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 6051 | if ((curproxy->cap & PR_CAP_BE) && (curproxy->mode != PR_MODE_HEALTH)) { |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6052 | if (curproxy->lbprm.algo & BE_LB_KIND) { |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 6053 | if (curproxy->options & PR_O_TRANSP) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6054 | Alert("config : %s '%s' cannot use both transparent and balance mode.\n", |
| 6055 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 6056 | cfgerr++; |
| 6057 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6058 | #ifdef WE_DONT_SUPPORT_SERVERLESS_LISTENERS |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 6059 | else if (curproxy->srv == NULL) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6060 | Alert("config : %s '%s' needs at least 1 server in balance mode.\n", |
| 6061 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 6062 | cfgerr++; |
| 6063 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6064 | #endif |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 6065 | else if (curproxy->options & PR_O_DISPATCH) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6066 | Warning("config : dispatch address of %s '%s' will be ignored in balance mode.\n", |
| 6067 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6068 | err_code |= ERR_WARN; |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 6069 | } |
| 6070 | } |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 6071 | 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] | 6072 | /* If no LB algo is set in a backend, and we're not in |
| 6073 | * transparent mode, dispatch mode nor proxy mode, we |
| 6074 | * want to use balance roundrobin by default. |
| 6075 | */ |
| 6076 | curproxy->lbprm.algo &= ~BE_LB_ALGO; |
| 6077 | curproxy->lbprm.algo |= BE_LB_ALGO_RR; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6078 | } |
| 6079 | } |
Willy Tarreau | 193cf93 | 2007-09-17 10:17:23 +0200 | [diff] [blame] | 6080 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 6081 | if (curproxy->options & PR_O_DISPATCH) |
| 6082 | curproxy->options &= ~(PR_O_TRANSP | PR_O_HTTP_PROXY); |
| 6083 | else if (curproxy->options & PR_O_HTTP_PROXY) |
| 6084 | curproxy->options &= ~(PR_O_DISPATCH | PR_O_TRANSP); |
| 6085 | else if (curproxy->options & PR_O_TRANSP) |
| 6086 | curproxy->options &= ~(PR_O_DISPATCH | PR_O_HTTP_PROXY); |
Willy Tarreau | 8293658 | 2007-11-30 15:20:09 +0100 | [diff] [blame] | 6087 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 6088 | if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_HTTP_CHK) { |
| 6089 | if (curproxy->options & PR_O_DISABLE404) { |
| 6090 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n", |
| 6091 | "disable-on-404", proxy_type_str(curproxy), curproxy->id); |
| 6092 | err_code |= ERR_WARN; |
| 6093 | curproxy->options &= ~PR_O_DISABLE404; |
| 6094 | } |
| 6095 | if (curproxy->options2 & PR_O2_CHK_SNDST) { |
| 6096 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n", |
| 6097 | "send-state", proxy_type_str(curproxy), curproxy->id); |
| 6098 | err_code |= ERR_WARN; |
| 6099 | curproxy->options &= ~PR_O2_CHK_SNDST; |
| 6100 | } |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 6101 | } |
| 6102 | |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 6103 | /* if a default backend was specified, let's find it */ |
| 6104 | if (curproxy->defbe.name) { |
| 6105 | struct proxy *target; |
| 6106 | |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 6107 | target = findproxy_mode(curproxy->defbe.name, curproxy->mode, PR_CAP_BE); |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6108 | if (!target) { |
| 6109 | Alert("Proxy '%s': unable to find required default_backend: '%s'.\n", |
| 6110 | curproxy->id, curproxy->defbe.name); |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 6111 | cfgerr++; |
| 6112 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6113 | Alert("Proxy '%s': loop detected for default_backend: '%s'.\n", |
| 6114 | curproxy->id, curproxy->defbe.name); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6115 | cfgerr++; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 6116 | } else { |
| 6117 | free(curproxy->defbe.name); |
| 6118 | curproxy->defbe.be = target; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 6119 | /* we force the backend to be present on at least all of |
| 6120 | * the frontend's processes. |
| 6121 | */ |
| 6122 | target->bind_proc = curproxy->bind_proc ? |
| 6123 | (target->bind_proc | curproxy->bind_proc) : 0; |
Willy Tarreau | ff67813 | 2012-02-13 14:32:34 +0100 | [diff] [blame] | 6124 | |
| 6125 | /* Emit a warning if this proxy also has some servers */ |
| 6126 | if (curproxy->srv) { |
| 6127 | Warning("In proxy '%s', the 'default_backend' rule always has precedence over the servers, which will never be used.\n", |
| 6128 | curproxy->id); |
| 6129 | err_code |= ERR_WARN; |
| 6130 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6131 | } |
| 6132 | } |
| 6133 | |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 6134 | /* find the target proxy in setbe */ |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 6135 | if (curproxy->mode == PR_MODE_HTTP && curproxy->req_exp != NULL) { |
| 6136 | /* map jump target for ACT_SETBE in req_rep chain */ |
| 6137 | struct hdr_exp *exp; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 6138 | for (exp = curproxy->req_exp; exp != NULL; exp = exp->next) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6139 | struct proxy *target; |
| 6140 | |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 6141 | if (exp->action != ACT_SETBE) |
| 6142 | continue; |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6143 | |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 6144 | target = findproxy_mode(exp->replace, PR_MODE_HTTP, PR_CAP_BE); |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6145 | if (!target) { |
| 6146 | Alert("Proxy '%s': unable to find required setbe: '%s'.\n", |
| 6147 | curproxy->id, exp->replace); |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 6148 | cfgerr++; |
| 6149 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6150 | Alert("Proxy '%s': loop detected for setbe: '%s'.\n", |
| 6151 | curproxy->id, exp->replace); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 6152 | cfgerr++; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 6153 | } else { |
| 6154 | free((void *)exp->replace); |
| 6155 | exp->replace = (const char *)target; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 6156 | /* we force the backend to be present on at least all of |
| 6157 | * the frontend's processes. |
| 6158 | */ |
| 6159 | target->bind_proc = curproxy->bind_proc ? |
| 6160 | (target->bind_proc | curproxy->bind_proc) : 0; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 6161 | } |
| 6162 | } |
| 6163 | } |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6164 | |
| 6165 | /* find the target proxy for 'use_backend' rules */ |
| 6166 | list_for_each_entry(rule, &curproxy->switching_rules, list) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6167 | struct proxy *target; |
| 6168 | |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 6169 | target = findproxy_mode(rule->be.name, curproxy->mode, PR_CAP_BE); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6170 | |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6171 | if (!target) { |
| 6172 | Alert("Proxy '%s': unable to find required use_backend: '%s'.\n", |
| 6173 | curproxy->id, rule->be.name); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6174 | cfgerr++; |
| 6175 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6176 | Alert("Proxy '%s': loop detected for use_backend: '%s'.\n", |
| 6177 | curproxy->id, rule->be.name); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6178 | cfgerr++; |
| 6179 | } else { |
| 6180 | free((void *)rule->be.name); |
| 6181 | rule->be.backend = target; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 6182 | /* we force the backend to be present on at least all of |
| 6183 | * the frontend's processes. |
| 6184 | */ |
| 6185 | target->bind_proc = curproxy->bind_proc ? |
| 6186 | (target->bind_proc | curproxy->bind_proc) : 0; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6187 | } |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 6188 | } |
| 6189 | |
| 6190 | /* find the target proxy for 'use_backend' rules */ |
| 6191 | list_for_each_entry(srule, &curproxy->server_rules, list) { |
| 6192 | struct server *target = findserver(curproxy, srule->srv.name); |
| 6193 | |
| 6194 | if (!target) { |
| 6195 | Alert("config : %s '%s' : unable to find server '%s' referenced in a 'use-server' rule.\n", |
| 6196 | proxy_type_str(curproxy), curproxy->id, srule->srv.name); |
| 6197 | cfgerr++; |
| 6198 | continue; |
| 6199 | } |
| 6200 | free((void *)srule->srv.name); |
| 6201 | srule->srv.ptr = target; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6202 | } |
| 6203 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6204 | /* find the target table for 'stick' rules */ |
| 6205 | list_for_each_entry(mrule, &curproxy->sticking_rules, list) { |
| 6206 | struct proxy *target; |
| 6207 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 6208 | curproxy->be_req_ana |= AN_REQ_STICKING_RULES; |
| 6209 | if (mrule->flags & STK_IS_STORE) |
| 6210 | curproxy->be_rsp_ana |= AN_RES_STORE_RULES; |
| 6211 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6212 | if (mrule->table.name) |
Willy Tarreau | c00cdc2 | 2010-06-06 16:48:26 +0200 | [diff] [blame] | 6213 | target = findproxy(mrule->table.name, 0); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6214 | else |
| 6215 | target = curproxy; |
| 6216 | |
| 6217 | if (!target) { |
| 6218 | Alert("Proxy '%s': unable to find stick-table '%s'.\n", |
| 6219 | curproxy->id, mrule->table.name); |
| 6220 | cfgerr++; |
| 6221 | } |
| 6222 | else if (target->table.size == 0) { |
| 6223 | Alert("Proxy '%s': stick-table '%s' used but not configured.\n", |
| 6224 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 6225 | cfgerr++; |
| 6226 | } |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 6227 | else if (!stktable_compatible_sample(mrule->expr, target->table.type)) { |
| 6228 | 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] | 6229 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 6230 | cfgerr++; |
| 6231 | } |
| 6232 | else { |
| 6233 | free((void *)mrule->table.name); |
| 6234 | mrule->table.t = &(target->table); |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 6235 | stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID, NULL); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6236 | } |
| 6237 | } |
| 6238 | |
| 6239 | /* find the target table for 'store response' rules */ |
| 6240 | list_for_each_entry(mrule, &curproxy->storersp_rules, list) { |
| 6241 | struct proxy *target; |
| 6242 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 6243 | curproxy->be_rsp_ana |= AN_RES_STORE_RULES; |
| 6244 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6245 | if (mrule->table.name) |
Willy Tarreau | c00cdc2 | 2010-06-06 16:48:26 +0200 | [diff] [blame] | 6246 | target = findproxy(mrule->table.name, 0); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6247 | else |
| 6248 | target = curproxy; |
| 6249 | |
| 6250 | if (!target) { |
| 6251 | Alert("Proxy '%s': unable to find store table '%s'.\n", |
| 6252 | curproxy->id, mrule->table.name); |
| 6253 | cfgerr++; |
| 6254 | } |
| 6255 | else if (target->table.size == 0) { |
| 6256 | Alert("Proxy '%s': stick-table '%s' used but not configured.\n", |
| 6257 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 6258 | cfgerr++; |
| 6259 | } |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 6260 | else if (!stktable_compatible_sample(mrule->expr, target->table.type)) { |
| 6261 | 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] | 6262 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 6263 | cfgerr++; |
| 6264 | } |
| 6265 | else { |
| 6266 | free((void *)mrule->table.name); |
| 6267 | mrule->table.t = &(target->table); |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 6268 | stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID, NULL); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6269 | } |
| 6270 | } |
| 6271 | |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 6272 | /* find the target table for 'tcp-request' layer 4 rules */ |
| 6273 | list_for_each_entry(trule, &curproxy->tcp_req.l4_rules, list) { |
| 6274 | struct proxy *target; |
| 6275 | |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6276 | if (trule->action != TCP_ACT_TRK_SC1 && trule->action != TCP_ACT_TRK_SC2) |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 6277 | continue; |
| 6278 | |
| 6279 | if (trule->act_prm.trk_ctr.table.n) |
| 6280 | target = findproxy(trule->act_prm.trk_ctr.table.n, 0); |
| 6281 | else |
| 6282 | target = curproxy; |
| 6283 | |
| 6284 | if (!target) { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6285 | Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n", |
| 6286 | curproxy->id, trule->act_prm.trk_ctr.table.n, |
| 6287 | trule->action == TCP_ACT_TRK_SC1 ? 1 : 2); |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 6288 | cfgerr++; |
| 6289 | } |
| 6290 | else if (target->table.size == 0) { |
| 6291 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
| 6292 | curproxy->id, trule->act_prm.trk_ctr.table.n ? trule->act_prm.trk_ctr.table.n : curproxy->id); |
| 6293 | cfgerr++; |
| 6294 | } |
Willy Tarreau | 5f53de7 | 2012-12-12 00:25:44 +0100 | [diff] [blame] | 6295 | else if (!stktable_compatible_sample(trule->act_prm.trk_ctr.expr, target->table.type)) { |
| 6296 | Alert("Proxy '%s': stick-table '%s' uses a type incompatible with the 'track-sc%d' rule.\n", |
| 6297 | curproxy->id, trule->act_prm.trk_ctr.table.n ? trule->act_prm.trk_ctr.table.n : curproxy->id, |
| 6298 | trule->action == TCP_ACT_TRK_SC1 ? 1 : 2); |
| 6299 | cfgerr++; |
| 6300 | } |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 6301 | else { |
| 6302 | free(trule->act_prm.trk_ctr.table.n); |
| 6303 | trule->act_prm.trk_ctr.table.t = &target->table; |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6304 | /* 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] | 6305 | * to pass a list of counters to track and allocate them right here using |
| 6306 | * stktable_alloc_data_type(). |
| 6307 | */ |
| 6308 | } |
| 6309 | } |
| 6310 | |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 6311 | /* find the target table for 'tcp-request' layer 6 rules */ |
| 6312 | list_for_each_entry(trule, &curproxy->tcp_req.inspect_rules, list) { |
| 6313 | struct proxy *target; |
| 6314 | |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6315 | if (trule->action != TCP_ACT_TRK_SC1 && trule->action != TCP_ACT_TRK_SC2) |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 6316 | continue; |
| 6317 | |
| 6318 | if (trule->act_prm.trk_ctr.table.n) |
| 6319 | target = findproxy(trule->act_prm.trk_ctr.table.n, 0); |
| 6320 | else |
| 6321 | target = curproxy; |
| 6322 | |
| 6323 | if (!target) { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6324 | Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n", |
| 6325 | curproxy->id, trule->act_prm.trk_ctr.table.n, |
| 6326 | trule->action == TCP_ACT_TRK_SC1 ? 1 : 2); |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 6327 | cfgerr++; |
| 6328 | } |
| 6329 | else if (target->table.size == 0) { |
| 6330 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
| 6331 | curproxy->id, trule->act_prm.trk_ctr.table.n ? trule->act_prm.trk_ctr.table.n : curproxy->id); |
| 6332 | cfgerr++; |
| 6333 | } |
Willy Tarreau | 5f53de7 | 2012-12-12 00:25:44 +0100 | [diff] [blame] | 6334 | else if (!stktable_compatible_sample(trule->act_prm.trk_ctr.expr, target->table.type)) { |
| 6335 | Alert("Proxy '%s': stick-table '%s' uses a type incompatible with the 'track-sc%d' rule.\n", |
| 6336 | curproxy->id, trule->act_prm.trk_ctr.table.n ? trule->act_prm.trk_ctr.table.n : curproxy->id, |
| 6337 | trule->action == TCP_ACT_TRK_SC1 ? 1 : 2); |
| 6338 | cfgerr++; |
| 6339 | } |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 6340 | else { |
| 6341 | free(trule->act_prm.trk_ctr.table.n); |
| 6342 | trule->act_prm.trk_ctr.table.t = &target->table; |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6343 | /* 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] | 6344 | * to pass a list of counters to track and allocate them right here using |
| 6345 | * stktable_alloc_data_type(). |
| 6346 | */ |
| 6347 | } |
| 6348 | } |
| 6349 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 6350 | if (curproxy->table.peers.name) { |
| 6351 | struct peers *curpeers = peers; |
| 6352 | |
| 6353 | for (curpeers = peers; curpeers; curpeers = curpeers->next) { |
| 6354 | if (strcmp(curpeers->id, curproxy->table.peers.name) == 0) { |
| 6355 | free((void *)curproxy->table.peers.name); |
Willy Tarreau | 973ca49 | 2013-01-17 21:34:52 +0100 | [diff] [blame] | 6356 | curproxy->table.peers.p = curpeers; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 6357 | break; |
| 6358 | } |
| 6359 | } |
| 6360 | |
| 6361 | if (!curpeers) { |
| 6362 | Alert("Proxy '%s': unable to find sync peers '%s'.\n", |
| 6363 | curproxy->id, curproxy->table.peers.name); |
Willy Tarreau | d66bf96 | 2011-10-28 14:16:49 +0200 | [diff] [blame] | 6364 | free((void *)curproxy->table.peers.name); |
| 6365 | curproxy->table.peers.p = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 6366 | cfgerr++; |
| 6367 | } |
| 6368 | else if (!curpeers->peers_fe) { |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 6369 | Alert("Proxy '%s': unable to find local peer '%s' in peers section '%s'.\n", |
| 6370 | curproxy->id, localpeer, curpeers->id); |
Willy Tarreau | d66bf96 | 2011-10-28 14:16:49 +0200 | [diff] [blame] | 6371 | curproxy->table.peers.p = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 6372 | cfgerr++; |
| 6373 | } |
| 6374 | } |
| 6375 | |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 6376 | if (curproxy->uri_auth && !(curproxy->uri_auth->flags & ST_CONVDONE) && |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 6377 | !LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) && |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6378 | (curproxy->uri_auth->userlist || curproxy->uri_auth->auth_realm )) { |
| 6379 | Alert("%s '%s': stats 'auth'/'realm' and 'http-request' can't be used at the same time.\n", |
| 6380 | "proxy", curproxy->id); |
| 6381 | cfgerr++; |
| 6382 | goto out_uri_auth_compat; |
| 6383 | } |
| 6384 | |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 6385 | 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] | 6386 | const char *uri_auth_compat_req[10]; |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 6387 | struct http_req_rule *rule; |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6388 | int i = 0; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6389 | |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6390 | /* build the ACL condition from scratch. We're relying on anonymous ACLs for that */ |
| 6391 | uri_auth_compat_req[i++] = "auth"; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6392 | |
| 6393 | if (curproxy->uri_auth->auth_realm) { |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6394 | uri_auth_compat_req[i++] = "realm"; |
| 6395 | uri_auth_compat_req[i++] = curproxy->uri_auth->auth_realm; |
| 6396 | } |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6397 | |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6398 | uri_auth_compat_req[i++] = "unless"; |
| 6399 | uri_auth_compat_req[i++] = "{"; |
| 6400 | uri_auth_compat_req[i++] = "http_auth(.internal-stats-userlist)"; |
| 6401 | uri_auth_compat_req[i++] = "}"; |
| 6402 | uri_auth_compat_req[i++] = ""; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6403 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 6404 | rule = parse_http_req_cond(uri_auth_compat_req, "internal-stats-auth-compat", 0, curproxy); |
| 6405 | if (!rule) { |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6406 | cfgerr++; |
| 6407 | break; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6408 | } |
| 6409 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 6410 | LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list); |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6411 | |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6412 | if (curproxy->uri_auth->auth_realm) { |
| 6413 | free(curproxy->uri_auth->auth_realm); |
| 6414 | curproxy->uri_auth->auth_realm = NULL; |
| 6415 | } |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 6416 | |
| 6417 | curproxy->uri_auth->flags |= ST_CONVDONE; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6418 | } |
| 6419 | out_uri_auth_compat: |
| 6420 | |
Krzysztof Piotr Oledzki | f9423ae | 2010-01-29 19:26:18 +0100 | [diff] [blame] | 6421 | cfgerr += acl_find_targets(curproxy); |
| 6422 | |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 6423 | if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) && |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6424 | (((curproxy->cap & PR_CAP_FE) && !curproxy->timeout.client) || |
Willy Tarreau | d825eef | 2007-05-12 22:35:00 +0200 | [diff] [blame] | 6425 | ((curproxy->cap & PR_CAP_BE) && (curproxy->srv) && |
Willy Tarreau | ce887fd | 2012-05-12 12:50:00 +0200 | [diff] [blame] | 6426 | (!curproxy->timeout.connect || |
| 6427 | (!curproxy->timeout.server && (curproxy->mode == PR_MODE_HTTP || !curproxy->timeout.tunnel)))))) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6428 | Warning("config : missing timeouts for %s '%s'.\n" |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 6429 | " | While not properly invalid, you will certainly encounter various problems\n" |
| 6430 | " | 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] | 6431 | " | timeouts are set to a non-zero value: 'client', 'connect', 'server'.\n", |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6432 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6433 | err_code |= ERR_WARN; |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 6434 | } |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 6435 | |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6436 | /* Historically, the tarpit and queue timeouts were inherited from contimeout. |
| 6437 | * We must still support older configurations, so let's find out whether those |
| 6438 | * parameters have been set or must be copied from contimeouts. |
| 6439 | */ |
| 6440 | if (curproxy != &defproxy) { |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6441 | if (!curproxy->timeout.tarpit || |
| 6442 | curproxy->timeout.tarpit == defproxy.timeout.tarpit) { |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6443 | /* tarpit timeout not set. We search in the following order: |
| 6444 | * default.tarpit, curr.connect, default.connect. |
| 6445 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6446 | if (defproxy.timeout.tarpit) |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6447 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6448 | else if (curproxy->timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6449 | curproxy->timeout.tarpit = curproxy->timeout.connect; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6450 | else if (defproxy.timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6451 | curproxy->timeout.tarpit = defproxy.timeout.connect; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6452 | } |
| 6453 | if ((curproxy->cap & PR_CAP_BE) && |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6454 | (!curproxy->timeout.queue || |
| 6455 | curproxy->timeout.queue == defproxy.timeout.queue)) { |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6456 | /* queue timeout not set. We search in the following order: |
| 6457 | * default.queue, curr.connect, default.connect. |
| 6458 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6459 | if (defproxy.timeout.queue) |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6460 | curproxy->timeout.queue = defproxy.timeout.queue; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6461 | else if (curproxy->timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6462 | curproxy->timeout.queue = curproxy->timeout.connect; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6463 | else if (defproxy.timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6464 | curproxy->timeout.queue = defproxy.timeout.connect; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6465 | } |
| 6466 | } |
| 6467 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 6468 | if ((curproxy->options2 & PR_O2_CHK_ANY) == PR_O2_SSL3_CHK) { |
Willy Tarreau | 137325d | 2010-02-01 16:38:17 +0100 | [diff] [blame] | 6469 | curproxy->check_len = sizeof(sslv3_client_hello_pkt) - 1; |
| 6470 | curproxy->check_req = (char *)malloc(curproxy->check_len); |
| 6471 | memcpy(curproxy->check_req, sslv3_client_hello_pkt, curproxy->check_len); |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 6472 | } |
| 6473 | |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 6474 | /* ensure that cookie capture length is not too large */ |
| 6475 | if (curproxy->capture_len >= global.tune.cookie_len) { |
| 6476 | Warning("config : truncating capture length to %d bytes for %s '%s'.\n", |
| 6477 | global.tune.cookie_len - 1, proxy_type_str(curproxy), curproxy->id); |
| 6478 | err_code |= ERR_WARN; |
| 6479 | curproxy->capture_len = global.tune.cookie_len - 1; |
| 6480 | } |
| 6481 | |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 6482 | /* The small pools required for the capture lists */ |
Willy Tarreau | 9a54e13 | 2012-03-24 08:33:05 +0100 | [diff] [blame] | 6483 | if (curproxy->nb_req_cap) { |
| 6484 | if (curproxy->mode == PR_MODE_HTTP) { |
| 6485 | curproxy->req_cap_pool = create_pool("ptrcap", |
| 6486 | curproxy->nb_req_cap * sizeof(char *), |
| 6487 | MEM_F_SHARED); |
| 6488 | } else { |
| 6489 | Warning("config : 'capture request header' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6490 | proxy_type_str(curproxy), curproxy->id); |
| 6491 | err_code |= ERR_WARN; |
| 6492 | curproxy->to_log &= ~LW_REQHDR; |
| 6493 | curproxy->nb_req_cap = 0; |
| 6494 | } |
| 6495 | } |
| 6496 | |
| 6497 | if (curproxy->nb_rsp_cap) { |
| 6498 | if (curproxy->mode == PR_MODE_HTTP) { |
| 6499 | curproxy->rsp_cap_pool = create_pool("ptrcap", |
| 6500 | curproxy->nb_rsp_cap * sizeof(char *), |
| 6501 | MEM_F_SHARED); |
| 6502 | } else { |
| 6503 | Warning("config : 'capture response header' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6504 | proxy_type_str(curproxy), curproxy->id); |
| 6505 | err_code |= ERR_WARN; |
| 6506 | curproxy->to_log &= ~LW_REQHDR; |
| 6507 | curproxy->nb_rsp_cap = 0; |
| 6508 | } |
| 6509 | } |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 6510 | |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 6511 | /* compile the log format */ |
Willy Tarreau | 99a7ca2 | 2012-05-31 19:39:23 +0200 | [diff] [blame] | 6512 | if (!(curproxy->cap & PR_CAP_FE)) { |
| 6513 | if (curproxy->logformat_string != default_http_log_format && |
| 6514 | curproxy->logformat_string != default_tcp_log_format && |
| 6515 | curproxy->logformat_string != clf_http_log_format) |
| 6516 | free(curproxy->logformat_string); |
| 6517 | curproxy->logformat_string = NULL; |
| 6518 | } |
| 6519 | |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 6520 | if (curproxy->logformat_string) |
Willy Tarreau | 6cbbdbf | 2013-02-05 18:52:25 +0100 | [diff] [blame] | 6521 | parse_logformat_string(curproxy->logformat_string, curproxy, &curproxy->logformat, LOG_OPT_MANDATORY); |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 6522 | |
| 6523 | if (curproxy->uniqueid_format_string) |
Willy Tarreau | 6cbbdbf | 2013-02-05 18:52:25 +0100 | [diff] [blame] | 6524 | parse_logformat_string(curproxy->uniqueid_format_string, curproxy, &curproxy->format_unique_id, 0); |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 6525 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6526 | /* first, we will invert the servers list order */ |
| 6527 | newsrv = NULL; |
| 6528 | while (curproxy->srv) { |
| 6529 | struct server *next; |
| 6530 | |
| 6531 | next = curproxy->srv->next; |
| 6532 | curproxy->srv->next = newsrv; |
| 6533 | newsrv = curproxy->srv; |
| 6534 | if (!next) |
| 6535 | break; |
| 6536 | curproxy->srv = next; |
| 6537 | } |
| 6538 | |
Willy Tarreau | dd70165 | 2010-05-25 23:03:02 +0200 | [diff] [blame] | 6539 | /* assign automatic UIDs to servers which don't have one yet */ |
| 6540 | next_id = 1; |
| 6541 | newsrv = curproxy->srv; |
| 6542 | while (newsrv != NULL) { |
| 6543 | if (!newsrv->puid) { |
| 6544 | /* server ID not set, use automatic numbering with first |
| 6545 | * spare entry starting with next_svid. |
| 6546 | */ |
| 6547 | next_id = get_next_id(&curproxy->conf.used_server_id, next_id); |
| 6548 | newsrv->conf.id.key = newsrv->puid = next_id; |
| 6549 | eb32_insert(&curproxy->conf.used_server_id, &newsrv->conf.id); |
| 6550 | } |
| 6551 | next_id++; |
| 6552 | newsrv = newsrv->next; |
| 6553 | } |
| 6554 | |
Willy Tarreau | 2069704 | 2007-11-15 23:26:18 +0100 | [diff] [blame] | 6555 | curproxy->lbprm.wmult = 1; /* default weight multiplier */ |
Willy Tarreau | 5dc2fa6 | 2007-11-19 19:10:18 +0100 | [diff] [blame] | 6556 | curproxy->lbprm.wdiv = 1; /* default weight divider */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6557 | |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 6558 | /* |
| 6559 | * If this server supports a maxconn parameter, it needs a dedicated |
| 6560 | * tasks to fill the emptied slots when a connection leaves. |
| 6561 | * Also, resolve deferred tracking dependency if needed. |
| 6562 | */ |
| 6563 | newsrv = curproxy->srv; |
| 6564 | while (newsrv != NULL) { |
| 6565 | if (newsrv->minconn > newsrv->maxconn) { |
| 6566 | /* Only 'minconn' was specified, or it was higher than or equal |
| 6567 | * to 'maxconn'. Let's turn this into maxconn and clean it, as |
| 6568 | * this will avoid further useless expensive computations. |
| 6569 | */ |
| 6570 | newsrv->maxconn = newsrv->minconn; |
| 6571 | } else if (newsrv->maxconn && !newsrv->minconn) { |
| 6572 | /* minconn was not specified, so we set it to maxconn */ |
| 6573 | newsrv->minconn = newsrv->maxconn; |
| 6574 | } |
| 6575 | |
Emeric Brun | 01f8e2f | 2012-05-18 16:02:00 +0200 | [diff] [blame] | 6576 | #ifdef USE_OPENSSL |
Emeric Brun | 94324a4 | 2012-10-11 14:00:19 +0200 | [diff] [blame] | 6577 | if (newsrv->use_ssl || newsrv->check.use_ssl) |
| 6578 | cfgerr += ssl_sock_prepare_srv_ctx(newsrv, curproxy); |
Emeric Brun | 01f8e2f | 2012-05-18 16:02:00 +0200 | [diff] [blame] | 6579 | #endif /* USE_OPENSSL */ |
Emeric Brun | 94324a4 | 2012-10-11 14:00:19 +0200 | [diff] [blame] | 6580 | |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 6581 | if (newsrv->trackit) { |
| 6582 | struct proxy *px; |
| 6583 | struct server *srv; |
| 6584 | char *pname, *sname; |
| 6585 | |
| 6586 | pname = newsrv->trackit; |
| 6587 | sname = strrchr(pname, '/'); |
| 6588 | |
| 6589 | if (sname) |
| 6590 | *sname++ = '\0'; |
| 6591 | else { |
| 6592 | sname = pname; |
| 6593 | pname = NULL; |
| 6594 | } |
| 6595 | |
| 6596 | if (pname) { |
| 6597 | px = findproxy(pname, PR_CAP_BE); |
| 6598 | if (!px) { |
| 6599 | Alert("config : %s '%s', server '%s': unable to find required proxy '%s' for tracking.\n", |
| 6600 | proxy_type_str(curproxy), curproxy->id, |
| 6601 | newsrv->id, pname); |
| 6602 | cfgerr++; |
| 6603 | goto next_srv; |
| 6604 | } |
| 6605 | } else |
| 6606 | px = curproxy; |
| 6607 | |
| 6608 | srv = findserver(px, sname); |
| 6609 | if (!srv) { |
| 6610 | Alert("config : %s '%s', server '%s': unable to find required server '%s' for tracking.\n", |
| 6611 | proxy_type_str(curproxy), curproxy->id, |
| 6612 | newsrv->id, sname); |
| 6613 | cfgerr++; |
| 6614 | goto next_srv; |
| 6615 | } |
| 6616 | |
| 6617 | if (!(srv->state & SRV_CHECKED)) { |
| 6618 | Alert("config : %s '%s', server '%s': unable to use %s/%s for " |
| 6619 | "tracking as it does not have checks enabled.\n", |
| 6620 | proxy_type_str(curproxy), curproxy->id, |
| 6621 | newsrv->id, px->id, srv->id); |
| 6622 | cfgerr++; |
| 6623 | goto next_srv; |
| 6624 | } |
| 6625 | |
| 6626 | if (curproxy != px && |
| 6627 | (curproxy->options & PR_O_DISABLE404) != (px->options & PR_O_DISABLE404)) { |
| 6628 | Alert("config : %s '%s', server '%s': unable to use %s/%s for" |
| 6629 | "tracking: disable-on-404 option inconsistency.\n", |
| 6630 | proxy_type_str(curproxy), curproxy->id, |
| 6631 | newsrv->id, px->id, srv->id); |
| 6632 | cfgerr++; |
| 6633 | goto next_srv; |
| 6634 | } |
| 6635 | |
| 6636 | /* if the other server is forced disabled, we have to do the same here */ |
| 6637 | if (srv->state & SRV_MAINTAIN) { |
| 6638 | newsrv->state |= SRV_MAINTAIN; |
| 6639 | newsrv->state &= ~SRV_RUNNING; |
| 6640 | newsrv->health = 0; |
| 6641 | } |
| 6642 | |
| 6643 | newsrv->track = srv; |
| 6644 | newsrv->tracknext = srv->tracknext; |
| 6645 | srv->tracknext = newsrv; |
| 6646 | |
| 6647 | free(newsrv->trackit); |
| 6648 | newsrv->trackit = NULL; |
| 6649 | } |
| 6650 | next_srv: |
| 6651 | newsrv = newsrv->next; |
| 6652 | } |
| 6653 | |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6654 | /* We have to initialize the server lookup mechanism depending |
| 6655 | * on what LB algorithm was choosen. |
| 6656 | */ |
| 6657 | |
| 6658 | curproxy->lbprm.algo &= ~(BE_LB_LKUP | BE_LB_PROP_DYN); |
| 6659 | switch (curproxy->lbprm.algo & BE_LB_KIND) { |
| 6660 | case BE_LB_KIND_RR: |
Willy Tarreau | 9757a38 | 2009-10-03 12:56:50 +0200 | [diff] [blame] | 6661 | if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_RR_STATIC) { |
| 6662 | curproxy->lbprm.algo |= BE_LB_LKUP_MAP; |
| 6663 | init_server_map(curproxy); |
| 6664 | } else { |
| 6665 | curproxy->lbprm.algo |= BE_LB_LKUP_RRTREE | BE_LB_PROP_DYN; |
| 6666 | fwrr_init_server_groups(curproxy); |
| 6667 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6668 | break; |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 6669 | |
Willy Tarreau | 3ebb116 | 2012-02-13 16:57:44 +0100 | [diff] [blame] | 6670 | case BE_LB_KIND_CB: |
Willy Tarreau | f09c660 | 2012-02-13 17:12:08 +0100 | [diff] [blame] | 6671 | if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_CB_LC) { |
| 6672 | curproxy->lbprm.algo |= BE_LB_LKUP_LCTREE | BE_LB_PROP_DYN; |
| 6673 | fwlc_init_server_tree(curproxy); |
| 6674 | } else { |
| 6675 | curproxy->lbprm.algo |= BE_LB_LKUP_FSTREE | BE_LB_PROP_DYN; |
| 6676 | fas_init_server_tree(curproxy); |
| 6677 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6678 | break; |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 6679 | |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6680 | case BE_LB_KIND_HI: |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 6681 | if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS) { |
| 6682 | curproxy->lbprm.algo |= BE_LB_LKUP_CHTREE | BE_LB_PROP_DYN; |
| 6683 | chash_init_server_tree(curproxy); |
| 6684 | } else { |
| 6685 | curproxy->lbprm.algo |= BE_LB_LKUP_MAP; |
| 6686 | init_server_map(curproxy); |
| 6687 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6688 | break; |
| 6689 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6690 | |
| 6691 | if (curproxy->options & PR_O_LOGASAP) |
| 6692 | curproxy->to_log &= ~LW_BYTES; |
| 6693 | |
Willy Tarreau | e7ded1f | 2009-08-09 10:11:45 +0200 | [diff] [blame] | 6694 | if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) && |
Willy Tarreau | d79a3b2 | 2012-12-28 09:40:16 +0100 | [diff] [blame] | 6695 | (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] | 6696 | Warning("config : log format ignored for %s '%s' since it has no log address.\n", |
| 6697 | proxy_type_str(curproxy), curproxy->id); |
| 6698 | err_code |= ERR_WARN; |
| 6699 | } |
| 6700 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 6701 | if (curproxy->mode != PR_MODE_HTTP) { |
| 6702 | int optnum; |
| 6703 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 6704 | if (curproxy->uri_auth) { |
| 6705 | Warning("config : 'stats' statement ignored for %s '%s' as it requires HTTP mode.\n", |
| 6706 | proxy_type_str(curproxy), curproxy->id); |
| 6707 | err_code |= ERR_WARN; |
| 6708 | curproxy->uri_auth = NULL; |
| 6709 | } |
| 6710 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 6711 | if (curproxy->options & (PR_O_FWDFOR | PR_O_FF_ALWAYS)) { |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 6712 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6713 | "forwardfor", proxy_type_str(curproxy), curproxy->id); |
| 6714 | err_code |= ERR_WARN; |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 6715 | curproxy->options &= ~(PR_O_FWDFOR | PR_O_FF_ALWAYS); |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 6716 | } |
| 6717 | |
| 6718 | if (curproxy->options & PR_O_ORGTO) { |
| 6719 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6720 | "originalto", proxy_type_str(curproxy), curproxy->id); |
| 6721 | err_code |= ERR_WARN; |
| 6722 | curproxy->options &= ~PR_O_ORGTO; |
| 6723 | } |
| 6724 | |
| 6725 | for (optnum = 0; cfg_opts[optnum].name; optnum++) { |
| 6726 | if (cfg_opts[optnum].mode == PR_MODE_HTTP && |
| 6727 | (curproxy->cap & cfg_opts[optnum].cap) && |
| 6728 | (curproxy->options & cfg_opts[optnum].val)) { |
| 6729 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6730 | cfg_opts[optnum].name, proxy_type_str(curproxy), curproxy->id); |
| 6731 | err_code |= ERR_WARN; |
| 6732 | curproxy->options &= ~cfg_opts[optnum].val; |
| 6733 | } |
| 6734 | } |
| 6735 | |
| 6736 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) { |
| 6737 | if (cfg_opts2[optnum].mode == PR_MODE_HTTP && |
| 6738 | (curproxy->cap & cfg_opts2[optnum].cap) && |
| 6739 | (curproxy->options2 & cfg_opts2[optnum].val)) { |
| 6740 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6741 | cfg_opts2[optnum].name, proxy_type_str(curproxy), curproxy->id); |
| 6742 | err_code |= ERR_WARN; |
| 6743 | curproxy->options2 &= ~cfg_opts2[optnum].val; |
| 6744 | } |
| 6745 | } |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6746 | |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 6747 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6748 | if (curproxy->conn_src.bind_hdr_occ) { |
| 6749 | curproxy->conn_src.bind_hdr_occ = 0; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6750 | 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] | 6751 | proxy_type_str(curproxy), curproxy->id, curproxy->conn_src.bind_hdr_name); |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6752 | err_code |= ERR_WARN; |
| 6753 | } |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 6754 | #endif |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 6755 | } |
| 6756 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6757 | /* |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 6758 | * ensure that we're not cross-dressing a TCP server into HTTP. |
| 6759 | */ |
| 6760 | newsrv = curproxy->srv; |
| 6761 | while (newsrv != NULL) { |
Willy Tarreau | 0cec331 | 2011-10-31 13:49:26 +0100 | [diff] [blame] | 6762 | if ((curproxy->mode != PR_MODE_HTTP) && newsrv->rdr_len) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6763 | Alert("config : %s '%s' : server cannot have cookie or redirect prefix in non-HTTP mode.\n", |
| 6764 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6765 | cfgerr++; |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 6766 | } |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6767 | |
Willy Tarreau | 0cec331 | 2011-10-31 13:49:26 +0100 | [diff] [blame] | 6768 | if ((curproxy->mode != PR_MODE_HTTP) && newsrv->cklen) { |
| 6769 | Warning("config : %s '%s' : ignoring cookie for server '%s' as HTTP mode is disabled.\n", |
| 6770 | proxy_type_str(curproxy), curproxy->id, newsrv->id); |
| 6771 | err_code |= ERR_WARN; |
| 6772 | } |
| 6773 | |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 6774 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6775 | if (curproxy->mode != PR_MODE_HTTP && newsrv->conn_src.bind_hdr_occ) { |
| 6776 | newsrv->conn_src.bind_hdr_occ = 0; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6777 | 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] | 6778 | 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] | 6779 | err_code |= ERR_WARN; |
| 6780 | } |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 6781 | #endif |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 6782 | newsrv = newsrv->next; |
| 6783 | } |
| 6784 | |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6785 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 6786 | if (!curproxy->accept) |
| 6787 | curproxy->accept = frontend_accept; |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 6788 | |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6789 | if (curproxy->tcp_req.inspect_delay || |
| 6790 | !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules)) |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 6791 | curproxy->fe_req_ana |= AN_REQ_INSPECT_FE; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6792 | |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 6793 | if (curproxy->mode == PR_MODE_HTTP) { |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6794 | 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] | 6795 | 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] | 6796 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6797 | |
| 6798 | /* both TCP and HTTP must check switching rules */ |
| 6799 | curproxy->fe_req_ana |= AN_REQ_SWITCHING_RULES; |
| 6800 | } |
| 6801 | |
| 6802 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 6803 | if (curproxy->tcp_req.inspect_delay || |
| 6804 | !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules)) |
| 6805 | curproxy->be_req_ana |= AN_REQ_INSPECT_BE; |
| 6806 | |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 6807 | if (!LIST_ISEMPTY(&curproxy->tcp_rep.inspect_rules)) |
| 6808 | curproxy->be_rsp_ana |= AN_RES_INSPECT; |
| 6809 | |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 6810 | if (curproxy->mode == PR_MODE_HTTP) { |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6811 | 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] | 6812 | 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] | 6813 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6814 | |
| 6815 | /* If the backend does requires RDP cookie persistence, we have to |
| 6816 | * enable the corresponding analyser. |
| 6817 | */ |
| 6818 | if (curproxy->options2 & PR_O2_RDPC_PRST) |
| 6819 | curproxy->be_req_ana |= AN_REQ_PRST_RDP_COOKIE; |
| 6820 | } |
| 6821 | |
Emeric Brun | c52962f | 2012-11-15 18:28:02 +0100 | [diff] [blame] | 6822 | #ifdef USE_OPENSSL |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 6823 | /* Configure SSL for each bind line. |
| 6824 | * Note: if configuration fails at some point, the ->ctx member |
| 6825 | * remains NULL so that listeners can later detach. |
| 6826 | */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6827 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
Emeric Brun | c52962f | 2012-11-15 18:28:02 +0100 | [diff] [blame] | 6828 | if (!bind_conf->is_ssl) { |
| 6829 | if (bind_conf->default_ctx) { |
| 6830 | Warning("Proxy '%s': A certificate was specified but SSL was not enabled on bind '%s' at [%s:%d] (use 'ssl').\n", |
| 6831 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
| 6832 | } |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6833 | continue; |
Emeric Brun | c52962f | 2012-11-15 18:28:02 +0100 | [diff] [blame] | 6834 | } |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6835 | if (!bind_conf->default_ctx) { |
Emeric Brun | fc0421f | 2012-09-07 17:30:07 +0200 | [diff] [blame] | 6836 | 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] | 6837 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 6838 | cfgerr++; |
| 6839 | continue; |
| 6840 | } |
| 6841 | |
Emeric Brun | 4b3091e | 2012-09-24 15:48:52 +0200 | [diff] [blame] | 6842 | 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] | 6843 | Alert("Unable to allocate SSL session cache.\n"); |
| 6844 | cfgerr++; |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 6845 | continue; |
| 6846 | } |
| 6847 | |
Emeric Brun | fc0421f | 2012-09-07 17:30:07 +0200 | [diff] [blame] | 6848 | /* initialize all certificate contexts */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6849 | cfgerr += ssl_sock_prepare_all_ctx(bind_conf, curproxy); |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6850 | } |
Emeric Brun | c52962f | 2012-11-15 18:28:02 +0100 | [diff] [blame] | 6851 | #endif /* USE_OPENSSL */ |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 6852 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 6853 | /* adjust this proxy's listeners */ |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6854 | next_id = 1; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 6855 | list_for_each_entry(listener, &curproxy->conf.listeners, by_fe) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6856 | if (!listener->luid) { |
| 6857 | /* listener ID not set, use automatic numbering with first |
| 6858 | * spare entry starting with next_luid. |
| 6859 | */ |
| 6860 | next_id = get_next_id(&curproxy->conf.used_listener_id, next_id); |
| 6861 | listener->conf.id.key = listener->luid = next_id; |
| 6862 | eb32_insert(&curproxy->conf.used_listener_id, &listener->conf.id); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6863 | } |
Krzysztof Piotr Oledzki | df5cb9f | 2010-02-05 20:58:27 +0100 | [diff] [blame] | 6864 | next_id++; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6865 | |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 6866 | /* enable separate counters */ |
| 6867 | if (curproxy->options2 & PR_O2_SOCKSTAT) { |
| 6868 | listener->counters = (struct licounters *)calloc(1, sizeof(struct licounters)); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6869 | if (!listener->name) |
| 6870 | memprintf(&listener->name, "sock-%d", listener->luid); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 6871 | } |
Willy Tarreau | 81796be | 2012-09-22 19:11:47 +0200 | [diff] [blame] | 6872 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 6873 | if (curproxy->options & PR_O_TCP_NOLING) |
| 6874 | listener->options |= LI_O_NOLINGER; |
Willy Tarreau | 32368ce | 2012-09-06 11:10:55 +0200 | [diff] [blame] | 6875 | if (!listener->maxconn) |
| 6876 | listener->maxconn = curproxy->maxconn; |
| 6877 | if (!listener->backlog) |
| 6878 | listener->backlog = curproxy->backlog; |
Willy Tarreau | 16a2147 | 2012-11-19 12:39:59 +0100 | [diff] [blame] | 6879 | if (!listener->maxaccept) |
| 6880 | listener->maxaccept = global.tune.maxaccept ? global.tune.maxaccept : 64; |
| 6881 | |
| 6882 | /* we want to have an optimal behaviour on single process mode to |
| 6883 | * maximize the work at once, but in multi-process we want to keep |
| 6884 | * some fairness between processes, so we target half of the max |
| 6885 | * number of events to be balanced over all the processes the proxy |
| 6886 | * is bound to. Rememeber that maxaccept = -1 must be kept as it is |
| 6887 | * used to disable the limit. |
| 6888 | */ |
| 6889 | if (listener->maxaccept > 0) { |
| 6890 | if (nbproc > 1) |
| 6891 | listener->maxaccept = (listener->maxaccept + 1) / 2; |
| 6892 | listener->maxaccept = (listener->maxaccept + nbproc - 1) / nbproc; |
| 6893 | } |
| 6894 | |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6895 | listener->timeout = &curproxy->timeout.client; |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 6896 | listener->accept = session_accept; |
Willy Tarreau | 3bc1377 | 2008-12-07 11:50:35 +0100 | [diff] [blame] | 6897 | listener->handler = process_session; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6898 | listener->analysers |= curproxy->fe_req_ana; |
Willy Tarreau | 3bc1377 | 2008-12-07 11:50:35 +0100 | [diff] [blame] | 6899 | |
Willy Tarreau | a5c0ab2 | 2010-05-31 10:30:33 +0200 | [diff] [blame] | 6900 | if (!LIST_ISEMPTY(&curproxy->tcp_req.l4_rules)) |
| 6901 | listener->options |= LI_O_TCP_RULES; |
| 6902 | |
Willy Tarreau | de3041d | 2010-05-31 10:56:17 +0200 | [diff] [blame] | 6903 | if (curproxy->mon_mask.s_addr) |
| 6904 | listener->options |= LI_O_CHK_MONNET; |
| 6905 | |
Willy Tarreau | 9ea05a7 | 2009-06-14 12:07:01 +0200 | [diff] [blame] | 6906 | /* smart accept mode is automatic in HTTP mode */ |
| 6907 | if ((curproxy->options2 & PR_O2_SMARTACC) || |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6908 | ((curproxy->mode == PR_MODE_HTTP || listener->bind_conf->is_ssl) && |
Willy Tarreau | 9ea05a7 | 2009-06-14 12:07:01 +0200 | [diff] [blame] | 6909 | !(curproxy->no_options2 & PR_O2_SMARTACC))) |
| 6910 | listener->options |= LI_O_NOQUICKACK; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 6911 | } |
| 6912 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6913 | /* Release unused SSL configs */ |
| 6914 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
| 6915 | if (bind_conf->is_ssl) |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 6916 | continue; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6917 | #ifdef USE_OPENSSL |
| 6918 | ssl_sock_free_all_ctx(bind_conf); |
Emeric Brun | fb510ea | 2012-10-05 12:00:26 +0200 | [diff] [blame] | 6919 | free(bind_conf->ca_file); |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6920 | free(bind_conf->ciphers); |
Emeric Brun | 2b58d04 | 2012-09-20 17:10:03 +0200 | [diff] [blame] | 6921 | free(bind_conf->ecdhe); |
Emeric Brun | fb510ea | 2012-10-05 12:00:26 +0200 | [diff] [blame] | 6922 | free(bind_conf->crl_file); |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 6923 | #endif /* USE_OPENSSL */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6924 | } |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 6925 | |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 6926 | /* Check multi-process mode compatibility for the current proxy */ |
| 6927 | if (global.nbproc > 1) { |
| 6928 | int nbproc = 0; |
| 6929 | if (curproxy->bind_proc) { |
| 6930 | int proc; |
| 6931 | for (proc = 0; proc < global.nbproc; proc++) { |
| 6932 | if (curproxy->bind_proc & (1 << proc)) { |
| 6933 | nbproc++; |
| 6934 | } |
| 6935 | } |
| 6936 | } else { |
| 6937 | nbproc = global.nbproc; |
| 6938 | } |
| 6939 | if (curproxy->table.peers.name) { |
| 6940 | Alert("Proxy '%s': peers can't be used in multi-process mode (nbproc > 1).\n", |
| 6941 | curproxy->id); |
| 6942 | cfgerr++; |
| 6943 | } |
| 6944 | if (nbproc > 1) { |
| 6945 | if (curproxy->uri_auth) { |
| 6946 | Warning("Proxy '%s': in multi-process mode, stats will be limited to process assigned to the current request.\n", |
| 6947 | curproxy->id); |
| 6948 | if (!LIST_ISEMPTY(&curproxy->uri_auth->admin_rules)) { |
| 6949 | Warning("Proxy '%s': stats admin will not work correctly in multi-process mode.\n", |
| 6950 | curproxy->id); |
| 6951 | } |
| 6952 | } |
| 6953 | if (curproxy->appsession_name) { |
| 6954 | Warning("Proxy '%s': appsession will not work correctly in multi-process mode.\n", |
| 6955 | curproxy->id); |
| 6956 | } |
| 6957 | if (!LIST_ISEMPTY(&curproxy->sticking_rules)) { |
| 6958 | Warning("Proxy '%s': sticking rules will not work correctly in multi-process mode.\n", |
| 6959 | curproxy->id); |
| 6960 | } |
| 6961 | } |
| 6962 | } |
Willy Tarreau | 918ff60 | 2011-07-25 16:33:49 +0200 | [diff] [blame] | 6963 | |
| 6964 | /* create the task associated with the proxy */ |
| 6965 | curproxy->task = task_new(); |
| 6966 | if (curproxy->task) { |
| 6967 | curproxy->task->context = curproxy; |
| 6968 | curproxy->task->process = manage_proxy; |
| 6969 | /* no need to queue, it will be done automatically if some |
| 6970 | * listener gets limited. |
| 6971 | */ |
| 6972 | curproxy->task->expire = TICK_ETERNITY; |
| 6973 | } else { |
| 6974 | Alert("Proxy '%s': no more memory when trying to allocate the management task\n", |
| 6975 | curproxy->id); |
| 6976 | cfgerr++; |
| 6977 | } |
| 6978 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6979 | curproxy = curproxy->next; |
| 6980 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 6981 | |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 6982 | /* Check multi-process mode compatibility */ |
| 6983 | if (global.nbproc > 1) { |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 6984 | if (global.stats_fe && !global.stats_fe->bind_proc) { |
| 6985 | 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] | 6986 | } |
| 6987 | } |
| 6988 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6989 | for (curuserlist = userlist; curuserlist; curuserlist = curuserlist->next) { |
| 6990 | struct auth_users *curuser; |
| 6991 | int g; |
| 6992 | |
| 6993 | for (curuser = curuserlist->users; curuser; curuser = curuser->next) { |
| 6994 | unsigned int group_mask = 0; |
| 6995 | char *group = NULL; |
| 6996 | |
Willy Tarreau | b4c06b7 | 2010-02-02 11:28:20 +0100 | [diff] [blame] | 6997 | if (!curuser->u.groups) |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6998 | continue; |
| 6999 | |
Willy Tarreau | b4c06b7 | 2010-02-02 11:28:20 +0100 | [diff] [blame] | 7000 | while ((group = strtok(group?NULL:curuser->u.groups, ","))) { |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 7001 | |
| 7002 | for (g = 0; g < curuserlist->grpcnt; g++) |
| 7003 | if (!strcmp(curuserlist->groups[g], group)) |
| 7004 | break; |
| 7005 | |
| 7006 | if (g == curuserlist->grpcnt) { |
| 7007 | Alert("userlist '%s': no such group '%s' specified in user '%s'\n", |
| 7008 | curuserlist->name, group, curuser->user); |
| 7009 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7010 | goto out; |
| 7011 | } |
| 7012 | |
| 7013 | group_mask |= (1 << g); |
| 7014 | } |
| 7015 | |
Willy Tarreau | b4c06b7 | 2010-02-02 11:28:20 +0100 | [diff] [blame] | 7016 | free(curuser->u.groups); |
| 7017 | curuser->u.group_mask = group_mask; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 7018 | } |
| 7019 | |
| 7020 | for (g = 0; g < curuserlist->grpcnt; g++) { |
| 7021 | char *user = NULL; |
| 7022 | |
| 7023 | if (!curuserlist->groupusers[g]) |
| 7024 | continue; |
| 7025 | |
| 7026 | while ((user = strtok(user?NULL:curuserlist->groupusers[g], ","))) { |
| 7027 | for (curuser = curuserlist->users; curuser; curuser = curuser->next) |
| 7028 | if (!strcmp(curuser->user, user)) |
| 7029 | break; |
| 7030 | |
| 7031 | if (!curuser) { |
| 7032 | Alert("userlist '%s': no such user '%s' specified in group '%s'\n", |
| 7033 | curuserlist->name, user, curuserlist->groups[g]); |
| 7034 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7035 | goto out; |
| 7036 | } |
| 7037 | |
Willy Tarreau | b4c06b7 | 2010-02-02 11:28:20 +0100 | [diff] [blame] | 7038 | curuser->u.group_mask |= (1 << g); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 7039 | } |
| 7040 | |
| 7041 | free(curuserlist->groupusers[g]); |
| 7042 | } |
| 7043 | |
| 7044 | free(curuserlist->groupusers); |
| 7045 | |
| 7046 | #ifdef DEBUG_AUTH |
| 7047 | for (g = 0; g < curuserlist->grpcnt; g++) { |
| 7048 | fprintf(stderr, "group %s, id %d, mask %08X, users:", curuserlist->groups[g], g , 1 << g); |
| 7049 | |
| 7050 | for (curuser = curuserlist->users; curuser; curuser = curuser->next) { |
Willy Tarreau | b950959 | 2012-05-10 23:25:35 +0200 | [diff] [blame] | 7051 | if (curuser->u.group_mask & (1 << g)) |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 7052 | fprintf(stderr, " %s", curuser->user); |
| 7053 | } |
| 7054 | |
| 7055 | fprintf(stderr, "\n"); |
| 7056 | } |
| 7057 | #endif |
| 7058 | |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 7059 | } |
| 7060 | |
| 7061 | /* automatically compute fullconn if not set. We must not do it in the |
| 7062 | * loop above because cross-references are not yet fully resolved. |
| 7063 | */ |
| 7064 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 7065 | /* If <fullconn> is not set, let's set it to 10% of the sum of |
| 7066 | * the possible incoming frontend's maxconns. |
| 7067 | */ |
| 7068 | if (!curproxy->fullconn && (curproxy->cap & PR_CAP_BE)) { |
| 7069 | struct proxy *fe; |
| 7070 | int total = 0; |
| 7071 | |
| 7072 | /* sum up the number of maxconns of frontends which |
| 7073 | * reference this backend at least once or which are |
| 7074 | * the same one ('listen'). |
| 7075 | */ |
| 7076 | for (fe = proxy; fe; fe = fe->next) { |
| 7077 | struct switching_rule *rule; |
| 7078 | struct hdr_exp *exp; |
| 7079 | int found = 0; |
| 7080 | |
| 7081 | if (!(fe->cap & PR_CAP_FE)) |
| 7082 | continue; |
| 7083 | |
| 7084 | if (fe == curproxy) /* we're on a "listen" instance */ |
| 7085 | found = 1; |
| 7086 | |
| 7087 | if (fe->defbe.be == curproxy) /* "default_backend" */ |
| 7088 | found = 1; |
| 7089 | |
| 7090 | /* check if a "use_backend" rule matches */ |
| 7091 | if (!found) { |
| 7092 | list_for_each_entry(rule, &fe->switching_rules, list) { |
| 7093 | if (rule->be.backend == curproxy) { |
| 7094 | found = 1; |
| 7095 | break; |
| 7096 | } |
| 7097 | } |
| 7098 | } |
| 7099 | |
| 7100 | /* check if a "reqsetbe" rule matches */ |
| 7101 | for (exp = fe->req_exp; !found && exp; exp = exp->next) { |
| 7102 | if (exp->action == ACT_SETBE && |
| 7103 | (struct proxy *)exp->replace == curproxy) { |
| 7104 | found = 1; |
| 7105 | break; |
| 7106 | } |
| 7107 | } |
| 7108 | |
| 7109 | /* now we've checked all possible ways to reference a backend |
| 7110 | * from a frontend. |
| 7111 | */ |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 7112 | if (!found) |
| 7113 | continue; |
| 7114 | total += fe->maxconn; |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 7115 | } |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 7116 | /* we have the sum of the maxconns in <total>. We only |
| 7117 | * keep 10% of that sum to set the default fullconn, with |
| 7118 | * a hard minimum of 1 (to avoid a divide by zero). |
| 7119 | */ |
| 7120 | curproxy->fullconn = (total + 9) / 10; |
| 7121 | if (!curproxy->fullconn) |
| 7122 | curproxy->fullconn = 1; |
| 7123 | } |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 7124 | } |
| 7125 | |
Willy Tarreau | 056f568 | 2010-06-06 15:51:11 +0200 | [diff] [blame] | 7126 | /* initialize stick-tables on backend capable proxies. This must not |
| 7127 | * be done earlier because the data size may be discovered while parsing |
| 7128 | * other proxies. |
| 7129 | */ |
| 7130 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) |
Willy Tarreau | c00cdc2 | 2010-06-06 16:48:26 +0200 | [diff] [blame] | 7131 | stktable_init(&curproxy->table); |
Willy Tarreau | 056f568 | 2010-06-06 15:51:11 +0200 | [diff] [blame] | 7132 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7133 | /* |
| 7134 | * Recount currently required checks. |
| 7135 | */ |
| 7136 | |
| 7137 | for (curproxy=proxy; curproxy; curproxy=curproxy->next) { |
| 7138 | int optnum; |
| 7139 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 7140 | for (optnum = 0; cfg_opts[optnum].name; optnum++) |
| 7141 | if (curproxy->options & cfg_opts[optnum].val) |
| 7142 | global.last_checks |= cfg_opts[optnum].checks; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7143 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 7144 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) |
| 7145 | if (curproxy->options2 & cfg_opts2[optnum].val) |
| 7146 | global.last_checks |= cfg_opts2[optnum].checks; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7147 | } |
| 7148 | |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 7149 | if (peers) { |
| 7150 | struct peers *curpeers = peers, **last; |
| 7151 | struct peer *p, *pb; |
| 7152 | |
| 7153 | /* Remove all peers sections which don't have a valid listener. |
| 7154 | * This can happen when a peers section is never referenced and |
| 7155 | * does not contain a local peer. |
| 7156 | */ |
| 7157 | last = &peers; |
| 7158 | while (*last) { |
| 7159 | curpeers = *last; |
| 7160 | if (curpeers->peers_fe) { |
Willy Tarreau | ca57de3 | 2012-11-23 20:08:09 +0100 | [diff] [blame] | 7161 | 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] | 7162 | last = &curpeers->next; |
| 7163 | continue; |
| 7164 | } |
| 7165 | |
| 7166 | Warning("Removing incomplete section 'peers %s' (no peer named '%s').\n", |
| 7167 | curpeers->id, localpeer); |
| 7168 | |
| 7169 | p = curpeers->remote; |
| 7170 | while (p) { |
| 7171 | pb = p->next; |
| 7172 | free(p->id); |
| 7173 | free(p); |
| 7174 | p = pb; |
| 7175 | } |
| 7176 | |
| 7177 | /* Destroy and unlink this curpeers section. |
| 7178 | * Note: curpeers is backed up into *last. |
| 7179 | */ |
| 7180 | free(curpeers->id); |
| 7181 | curpeers = curpeers->next; |
| 7182 | free(*last); |
| 7183 | *last = curpeers; |
| 7184 | } |
| 7185 | } |
| 7186 | |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 7187 | pool2_hdr_idx = create_pool("hdr_idx", |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame] | 7188 | global.tune.max_http_hdr * sizeof(struct hdr_idx_elem), |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 7189 | MEM_F_SHARED); |
| 7190 | |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 7191 | if (cfgerr > 0) |
| 7192 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7193 | out: |
| 7194 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7195 | } |
| 7196 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 7197 | /* |
| 7198 | * Registers the CFG keyword list <kwl> as a list of valid keywords for next |
| 7199 | * parsing sessions. |
| 7200 | */ |
| 7201 | void cfg_register_keywords(struct cfg_kw_list *kwl) |
| 7202 | { |
| 7203 | LIST_ADDQ(&cfg_keywords.list, &kwl->list); |
| 7204 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7205 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 7206 | /* |
| 7207 | * Unregisters the CFG keyword list <kwl> from the list of valid keywords. |
| 7208 | */ |
| 7209 | void cfg_unregister_keywords(struct cfg_kw_list *kwl) |
| 7210 | { |
| 7211 | LIST_DEL(&kwl->list); |
| 7212 | LIST_INIT(&kwl->list); |
| 7213 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7214 | |
| 7215 | /* |
| 7216 | * Local variables: |
| 7217 | * c-indent-level: 8 |
| 7218 | * c-basic-offset: 8 |
| 7219 | * End: |
| 7220 | */ |