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 | |
Cyril Bonté | 2c8d700 | 2014-08-29 20:20:02 +0200 | [diff] [blame] | 13 | #ifdef CONFIG_HAP_CRYPT |
| 14 | /* This is to have crypt() defined on Linux */ |
| 15 | #define _GNU_SOURCE |
| 16 | |
| 17 | #ifdef NEED_CRYPT_H |
| 18 | /* some platforms such as Solaris need this */ |
| 19 | #include <crypt.h> |
| 20 | #endif |
| 21 | #endif /* CONFIG_HAP_CRYPT */ |
| 22 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 23 | #include <stdio.h> |
| 24 | #include <stdlib.h> |
| 25 | #include <string.h> |
| 26 | #include <netdb.h> |
| 27 | #include <ctype.h> |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 28 | #include <pwd.h> |
| 29 | #include <grp.h> |
Willy Tarreau | 0b4ed90 | 2007-03-26 00:18:40 +0200 | [diff] [blame] | 30 | #include <errno.h> |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 31 | #include <sys/types.h> |
| 32 | #include <sys/stat.h> |
| 33 | #include <fcntl.h> |
| 34 | #include <unistd.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 35 | |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 36 | #include <common/cfgparse.h> |
Willy Tarreau | c7e4238 | 2012-08-24 19:22:53 +0200 | [diff] [blame] | 37 | #include <common/chunk.h> |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 38 | #include <common/config.h> |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 39 | #include <common/errors.h> |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 40 | #include <common/memory.h> |
| 41 | #include <common/standard.h> |
| 42 | #include <common/time.h> |
| 43 | #include <common/uri_auth.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 44 | |
| 45 | #include <types/capture.h> |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 46 | #include <types/compression.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 47 | #include <types/global.h> |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 48 | #include <types/obj_type.h> |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 49 | #include <types/peers.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 50 | |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 51 | #include <proto/acl.h> |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 52 | #include <proto/auth.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 53 | #include <proto/backend.h> |
Willy Tarreau | c7e4238 | 2012-08-24 19:22:53 +0200 | [diff] [blame] | 54 | #include <proto/channel.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 55 | #include <proto/checks.h> |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 56 | #include <proto/compression.h> |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 57 | #include <proto/dumpstats.h> |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 58 | #include <proto/frontend.h> |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 59 | #include <proto/hdr_idx.h> |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 60 | #include <proto/lb_chash.h> |
Willy Tarreau | f09c660 | 2012-02-13 17:12:08 +0100 | [diff] [blame] | 61 | #include <proto/lb_fas.h> |
Willy Tarreau | f89c187 | 2009-10-01 11:19:37 +0200 | [diff] [blame] | 62 | #include <proto/lb_fwlc.h> |
| 63 | #include <proto/lb_fwrr.h> |
| 64 | #include <proto/lb_map.h> |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 65 | #include <proto/listener.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 66 | #include <proto/log.h> |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 67 | #include <proto/protocol.h> |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 68 | #include <proto/proto_tcp.h> |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 69 | #include <proto/proto_uxst.h> |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 70 | #include <proto/proto_http.h> |
Willy Tarreau | 2b5652f | 2006-12-31 17:46:05 +0100 | [diff] [blame] | 71 | #include <proto/proxy.h> |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 72 | #include <proto/peers.h> |
Willy Tarreau | cd3b094 | 2012-04-27 21:52:18 +0200 | [diff] [blame] | 73 | #include <proto/sample.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 74 | #include <proto/server.h> |
Willy Tarreau | 3bc1377 | 2008-12-07 11:50:35 +0100 | [diff] [blame] | 75 | #include <proto/session.h> |
Willy Tarreau | 75bf2c9 | 2012-08-20 17:01:35 +0200 | [diff] [blame] | 76 | #include <proto/raw_sock.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 77 | #include <proto/task.h> |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 78 | #include <proto/stick_table.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 79 | |
Emeric Brun | fc0421f | 2012-09-07 17:30:07 +0200 | [diff] [blame] | 80 | #ifdef USE_OPENSSL |
| 81 | #include <types/ssl_sock.h> |
| 82 | #include <proto/ssl_sock.h> |
| 83 | #include <proto/shctx.h> |
| 84 | #endif /*USE_OPENSSL */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 85 | |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 86 | /* This is the SSLv3 CLIENT HELLO packet used in conjunction with the |
| 87 | * ssl-hello-chk option to ensure that the remote server speaks SSL. |
| 88 | * |
| 89 | * Check RFC 2246 (TLSv1.0) sections A.3 and A.4 for details. |
| 90 | */ |
| 91 | const char sslv3_client_hello_pkt[] = { |
| 92 | "\x16" /* ContentType : 0x16 = Hanshake */ |
| 93 | "\x03\x00" /* ProtocolVersion : 0x0300 = SSLv3 */ |
| 94 | "\x00\x79" /* ContentLength : 0x79 bytes after this one */ |
| 95 | "\x01" /* HanshakeType : 0x01 = CLIENT HELLO */ |
| 96 | "\x00\x00\x75" /* HandshakeLength : 0x75 bytes after this one */ |
| 97 | "\x03\x00" /* Hello Version : 0x0300 = v3 */ |
| 98 | "\x00\x00\x00\x00" /* Unix GMT Time (s) : filled with <now> (@0x0B) */ |
| 99 | "HAPROXYSSLCHK\nHAPROXYSSLCHK\n" /* Random : must be exactly 28 bytes */ |
| 100 | "\x00" /* Session ID length : empty (no session ID) */ |
| 101 | "\x00\x4E" /* Cipher Suite Length : 78 bytes after this one */ |
| 102 | "\x00\x01" "\x00\x02" "\x00\x03" "\x00\x04" /* 39 most common ciphers : */ |
| 103 | "\x00\x05" "\x00\x06" "\x00\x07" "\x00\x08" /* 0x01...0x1B, 0x2F...0x3A */ |
| 104 | "\x00\x09" "\x00\x0A" "\x00\x0B" "\x00\x0C" /* This covers RSA/DH, */ |
| 105 | "\x00\x0D" "\x00\x0E" "\x00\x0F" "\x00\x10" /* various bit lengths, */ |
| 106 | "\x00\x11" "\x00\x12" "\x00\x13" "\x00\x14" /* SHA1/MD5, DES/3DES/AES... */ |
| 107 | "\x00\x15" "\x00\x16" "\x00\x17" "\x00\x18" |
| 108 | "\x00\x19" "\x00\x1A" "\x00\x1B" "\x00\x2F" |
| 109 | "\x00\x30" "\x00\x31" "\x00\x32" "\x00\x33" |
| 110 | "\x00\x34" "\x00\x35" "\x00\x36" "\x00\x37" |
| 111 | "\x00\x38" "\x00\x39" "\x00\x3A" |
| 112 | "\x01" /* Compression Length : 0x01 = 1 byte for types */ |
| 113 | "\x00" /* Compression Type : 0x00 = NULL compression */ |
| 114 | }; |
| 115 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 116 | /* various keyword modifiers */ |
| 117 | enum kw_mod { |
| 118 | KWM_STD = 0, /* normal */ |
| 119 | KWM_NO, /* "no" prefixed before the keyword */ |
| 120 | KWM_DEF, /* "default" prefixed before the keyword */ |
| 121 | }; |
| 122 | |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 123 | /* permit to store configuration section */ |
| 124 | struct cfg_section { |
| 125 | struct list list; |
| 126 | char *section_name; |
| 127 | int (*section_parser)(const char *, int, char **, int); |
| 128 | }; |
| 129 | |
| 130 | /* Used to chain configuration sections definitions. This list |
| 131 | * stores struct cfg_section |
| 132 | */ |
| 133 | struct list sections = LIST_HEAD_INIT(sections); |
| 134 | |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 135 | /* 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] | 136 | struct cfg_opt { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 137 | const char *name; |
| 138 | unsigned int val; |
| 139 | unsigned int cap; |
Willy Tarreau | 4fee4e9 | 2007-01-06 21:09:17 +0100 | [diff] [blame] | 140 | unsigned int checks; |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 141 | unsigned int mode; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 142 | }; |
| 143 | |
| 144 | /* proxy->options */ |
| 145 | static const struct cfg_opt cfg_opts[] = |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 146 | { |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 147 | { "abortonclose", PR_O_ABRT_CLOSE, PR_CAP_BE, 0, 0 }, |
| 148 | { "allbackups", PR_O_USE_ALL_BK, PR_CAP_BE, 0, 0 }, |
| 149 | { "checkcache", PR_O_CHK_CACHE, PR_CAP_BE, 0, PR_MODE_HTTP }, |
| 150 | { "clitcpka", PR_O_TCP_CLI_KA, PR_CAP_FE, 0, 0 }, |
| 151 | { "contstats", PR_O_CONTSTATS, PR_CAP_FE, 0, 0 }, |
| 152 | { "dontlognull", PR_O_NULLNOLOG, PR_CAP_FE, 0, 0 }, |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 153 | { "http_proxy", PR_O_HTTP_PROXY, PR_CAP_FE | PR_CAP_BE, 0, PR_MODE_HTTP }, |
Willy Tarreau | 9420b12 | 2013-12-15 18:58:25 +0100 | [diff] [blame] | 154 | { "prefer-last-server", PR_O_PREF_LAST, PR_CAP_BE, 0, PR_MODE_HTTP }, |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 155 | { "logasap", PR_O_LOGASAP, PR_CAP_FE, 0, 0 }, |
| 156 | { "nolinger", PR_O_TCP_NOLING, PR_CAP_FE | PR_CAP_BE, 0, 0 }, |
| 157 | { "persist", PR_O_PERSIST, PR_CAP_BE, 0, 0 }, |
| 158 | { "redispatch", PR_O_REDISP, PR_CAP_BE, 0, 0 }, |
| 159 | { "srvtcpka", PR_O_TCP_SRV_KA, PR_CAP_BE, 0, 0 }, |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 160 | #ifdef TPROXY |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 161 | { "transparent", PR_O_TRANSP, PR_CAP_BE, 0, 0 }, |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 162 | #else |
| 163 | { "transparent", 0, 0, 0, 0 }, |
Willy Tarreau | 8f922fc | 2007-01-06 21:11:49 +0100 | [diff] [blame] | 164 | #endif |
| 165 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 166 | { NULL, 0, 0, 0, 0 } |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 167 | }; |
| 168 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 169 | /* proxy->options2 */ |
| 170 | static const struct cfg_opt cfg_opts2[] = |
| 171 | { |
| 172 | #ifdef CONFIG_HAP_LINUX_SPLICE |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 173 | { "splice-request", PR_O2_SPLIC_REQ, PR_CAP_FE|PR_CAP_BE, 0, 0 }, |
| 174 | { "splice-response", PR_O2_SPLIC_RTR, PR_CAP_FE|PR_CAP_BE, 0, 0 }, |
| 175 | { "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] | 176 | #else |
| 177 | { "splice-request", 0, 0, 0, 0 }, |
| 178 | { "splice-response", 0, 0, 0, 0 }, |
| 179 | { "splice-auto", 0, 0, 0, 0 }, |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 180 | #endif |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 181 | { "accept-invalid-http-request", PR_O2_REQBUG_OK, PR_CAP_FE, 0, PR_MODE_HTTP }, |
| 182 | { "accept-invalid-http-response", PR_O2_RSPBUG_OK, PR_CAP_BE, 0, PR_MODE_HTTP }, |
| 183 | { "dontlog-normal", PR_O2_NOLOGNORM, PR_CAP_FE, 0, 0 }, |
| 184 | { "log-separate-errors", PR_O2_LOGERRORS, PR_CAP_FE, 0, 0 }, |
| 185 | { "log-health-checks", PR_O2_LOGHCHKS, PR_CAP_BE, 0, 0 }, |
| 186 | { "socket-stats", PR_O2_SOCKSTAT, PR_CAP_FE, 0, 0 }, |
| 187 | { "tcp-smart-accept", PR_O2_SMARTACC, PR_CAP_FE, 0, 0 }, |
| 188 | { "tcp-smart-connect", PR_O2_SMARTCON, PR_CAP_BE, 0, 0 }, |
| 189 | { "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] | 190 | { "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] | 191 | { "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] | 192 | { "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] | 193 | { "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] | 194 | { NULL, 0, 0, 0 } |
| 195 | }; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 196 | |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 197 | static char *cursection = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 198 | static struct proxy defproxy; /* fake proxy used to assign default values on all instances */ |
| 199 | int cfg_maxpconn = DEFAULT_MAXCONN; /* # of simultaneous connections per proxy (-N) */ |
Willy Tarreau | 5af24ef | 2009-03-15 15:23:16 +0100 | [diff] [blame] | 200 | int cfg_maxconn = 0; /* # of simultaneous connections, (-n) */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 201 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 202 | /* List head of all known configuration keywords */ |
| 203 | static struct cfg_kw_list cfg_keywords = { |
| 204 | .list = LIST_HEAD_INIT(cfg_keywords.list) |
| 205 | }; |
| 206 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 207 | /* |
| 208 | * converts <str> to a list of listeners which are dynamically allocated. |
| 209 | * The format is "{addr|'*'}:port[-end][,{addr|'*'}:port[-end]]*", where : |
| 210 | * - <addr> can be empty or "*" to indicate INADDR_ANY ; |
| 211 | * - <port> is a numerical port from 1 to 65535 ; |
| 212 | * - <end> indicates to use the range from <port> to <end> instead (inclusive). |
| 213 | * 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] | 214 | * Function returns 1 for success or 0 if error. In case of errors, if <err> is |
| 215 | * not NULL, it must be a valid pointer to either NULL or a freeable area that |
| 216 | * will be replaced with an error message. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 217 | */ |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 218 | 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] | 219 | { |
| 220 | struct listener *l; |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 221 | char *next, *dupstr; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 222 | int port, end; |
| 223 | |
| 224 | next = dupstr = strdup(str); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 225 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 226 | while (next && *next) { |
Willy Tarreau | 12eb2a6 | 2013-03-06 15:45:03 +0100 | [diff] [blame] | 227 | struct sockaddr_storage ss, *ss2; |
Willy Tarreau | 40aa070 | 2013-03-10 23:51:38 +0100 | [diff] [blame] | 228 | int fd = -1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 229 | |
| 230 | str = next; |
| 231 | /* 1) look for the end of the first address */ |
Krzysztof Piotr Oledzki | 52d522b | 2009-01-27 16:57:08 +0100 | [diff] [blame] | 232 | if ((next = strchr(str, ',')) != NULL) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 233 | *next++ = 0; |
| 234 | } |
| 235 | |
Willy Tarreau | 12eb2a6 | 2013-03-06 15:45:03 +0100 | [diff] [blame] | 236 | ss2 = str2sa_range(str, &port, &end, err, |
| 237 | curproxy == global.stats_fe ? NULL : global.unix_bind.prefix); |
| 238 | if (!ss2) |
| 239 | goto fail; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 240 | |
Willy Tarreau | 12eb2a6 | 2013-03-06 15:45:03 +0100 | [diff] [blame] | 241 | if (ss2->ss_family == AF_INET || ss2->ss_family == AF_INET6) { |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 242 | if (!port && !end) { |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 243 | memprintf(err, "missing port number: '%s'\n", str); |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 244 | goto fail; |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 245 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 246 | |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 247 | if (!port || !end) { |
| 248 | memprintf(err, "port offsets are not allowed in 'bind': '%s'\n", str); |
| 249 | goto fail; |
| 250 | } |
| 251 | |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 252 | if (port < 1 || port > 65535) { |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 253 | memprintf(err, "invalid port '%d' specified for address '%s'.\n", port, str); |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 254 | goto fail; |
| 255 | } |
| 256 | |
| 257 | if (end < 1 || end > 65535) { |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 258 | memprintf(err, "invalid port '%d' specified for address '%s'.\n", end, str); |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 259 | goto fail; |
| 260 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 261 | } |
Willy Tarreau | 40aa070 | 2013-03-10 23:51:38 +0100 | [diff] [blame] | 262 | else if (ss2->ss_family == AF_UNSPEC) { |
| 263 | socklen_t addr_len; |
| 264 | |
| 265 | /* We want to attach to an already bound fd whose number |
| 266 | * is in the addr part of ss2 when cast to sockaddr_in. |
| 267 | * Note that by definition there is a single listener. |
| 268 | * We still have to determine the address family to |
| 269 | * register the correct protocol. |
| 270 | */ |
| 271 | fd = ((struct sockaddr_in *)ss2)->sin_addr.s_addr; |
| 272 | addr_len = sizeof(*ss2); |
| 273 | if (getsockname(fd, (struct sockaddr *)ss2, &addr_len) == -1) { |
| 274 | memprintf(err, "cannot use file descriptor '%d' : %s.\n", fd, strerror(errno)); |
| 275 | goto fail; |
| 276 | } |
| 277 | |
| 278 | port = end = get_host_port(ss2); |
| 279 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 280 | |
Willy Tarreau | 12eb2a6 | 2013-03-06 15:45:03 +0100 | [diff] [blame] | 281 | /* OK the address looks correct */ |
| 282 | ss = *ss2; |
| 283 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 284 | for (; port <= end; port++) { |
| 285 | l = (struct listener *)calloc(1, sizeof(struct listener)); |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 286 | l->obj_type = OBJ_TYPE_LISTENER; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 287 | LIST_ADDQ(&curproxy->conf.listeners, &l->by_fe); |
| 288 | LIST_ADDQ(&bind_conf->listeners, &l->by_bind); |
| 289 | l->frontend = curproxy; |
| 290 | l->bind_conf = bind_conf; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 291 | |
Willy Tarreau | 40aa070 | 2013-03-10 23:51:38 +0100 | [diff] [blame] | 292 | l->fd = fd; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 293 | l->addr = ss; |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 294 | l->xprt = &raw_sock; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 295 | l->state = LI_INIT; |
| 296 | |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 297 | if (ss.ss_family == AF_INET) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 298 | ((struct sockaddr_in *)(&l->addr))->sin_port = htons(port); |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 299 | tcpv4_add_listener(l); |
| 300 | } |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 301 | else if (ss.ss_family == AF_INET6) { |
| 302 | ((struct sockaddr_in6 *)(&l->addr))->sin6_port = htons(port); |
| 303 | tcpv6_add_listener(l); |
| 304 | } |
| 305 | else { |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 306 | uxst_add_listener(l); |
| 307 | } |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 308 | |
Willy Tarreau | af7ad00 | 2010-08-31 15:39:26 +0200 | [diff] [blame] | 309 | jobs++; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 310 | listeners++; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 311 | } /* end for(port) */ |
| 312 | } /* end while(next) */ |
| 313 | free(dupstr); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 314 | return 1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 315 | fail: |
| 316 | free(dupstr); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 317 | return 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 318 | } |
| 319 | |
Willy Tarreau | 8b3c808 | 2014-09-16 15:39:51 +0200 | [diff] [blame] | 320 | /* Report a warning if a rule is placed after a 'tcp-request content' rule. |
| 321 | * Return 1 if the warning has been emitted, otherwise 0. |
| 322 | */ |
| 323 | int warnif_rule_after_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg) |
| 324 | { |
| 325 | if (!LIST_ISEMPTY(&proxy->tcp_req.inspect_rules)) { |
| 326 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'tcp-request content' rule will still be processed before.\n", |
| 327 | file, line, arg); |
| 328 | return 1; |
| 329 | } |
| 330 | return 0; |
| 331 | } |
| 332 | |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 333 | /* Report a warning if a rule is placed after a 'block' rule. |
| 334 | * Return 1 if the warning has been emitted, otherwise 0. |
| 335 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 336 | 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] | 337 | { |
Willy Tarreau | 353bc9f | 2014-04-28 22:05:31 +0200 | [diff] [blame] | 338 | if (!LIST_ISEMPTY(&proxy->block_rules)) { |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 339 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'block' rule will still be processed before.\n", |
| 340 | file, line, arg); |
| 341 | return 1; |
| 342 | } |
| 343 | return 0; |
| 344 | } |
| 345 | |
Willy Tarreau | 5002f57 | 2014-04-23 01:32:02 +0200 | [diff] [blame] | 346 | /* Report a warning if a rule is placed after an 'http_request' rule. |
| 347 | * Return 1 if the warning has been emitted, otherwise 0. |
| 348 | */ |
| 349 | int warnif_rule_after_http_req(struct proxy *proxy, const char *file, int line, const char *arg) |
| 350 | { |
| 351 | if (!LIST_ISEMPTY(&proxy->http_req_rules)) { |
| 352 | Warning("parsing [%s:%d] : a '%s' rule placed after an 'http-request' rule will still be processed before.\n", |
| 353 | file, line, arg); |
| 354 | return 1; |
| 355 | } |
| 356 | return 0; |
| 357 | } |
| 358 | |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 359 | /* Report a warning if a rule is placed after a reqrewrite rule. |
| 360 | * Return 1 if the warning has been emitted, otherwise 0. |
| 361 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 362 | 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] | 363 | { |
| 364 | if (proxy->req_exp) { |
| 365 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'reqxxx' rule will still be processed before.\n", |
| 366 | file, line, arg); |
| 367 | return 1; |
| 368 | } |
| 369 | return 0; |
| 370 | } |
| 371 | |
| 372 | /* Report a warning if a rule is placed after a reqadd rule. |
| 373 | * Return 1 if the warning has been emitted, otherwise 0. |
| 374 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 375 | 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] | 376 | { |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 377 | if (!LIST_ISEMPTY(&proxy->req_add)) { |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 378 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'reqadd' rule will still be processed before.\n", |
| 379 | file, line, arg); |
| 380 | return 1; |
| 381 | } |
| 382 | return 0; |
| 383 | } |
| 384 | |
| 385 | /* Report a warning if a rule is placed after a redirect rule. |
| 386 | * Return 1 if the warning has been emitted, otherwise 0. |
| 387 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 388 | 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] | 389 | { |
| 390 | if (!LIST_ISEMPTY(&proxy->redirect_rules)) { |
| 391 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'redirect' rule will still be processed before.\n", |
| 392 | file, line, arg); |
| 393 | return 1; |
| 394 | } |
| 395 | return 0; |
| 396 | } |
| 397 | |
| 398 | /* Report a warning if a rule is placed after a 'use_backend' rule. |
| 399 | * Return 1 if the warning has been emitted, otherwise 0. |
| 400 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 401 | 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] | 402 | { |
| 403 | if (!LIST_ISEMPTY(&proxy->switching_rules)) { |
| 404 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'use_backend' rule will still be processed before.\n", |
| 405 | file, line, arg); |
| 406 | return 1; |
| 407 | } |
| 408 | return 0; |
| 409 | } |
| 410 | |
Willy Tarreau | ee445d9 | 2014-04-23 01:39:04 +0200 | [diff] [blame] | 411 | /* Report a warning if a rule is placed after a 'use-server' rule. |
| 412 | * Return 1 if the warning has been emitted, otherwise 0. |
| 413 | */ |
| 414 | int warnif_rule_after_use_server(struct proxy *proxy, const char *file, int line, const char *arg) |
| 415 | { |
| 416 | if (!LIST_ISEMPTY(&proxy->server_rules)) { |
| 417 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'use-server' rule will still be processed before.\n", |
| 418 | file, line, arg); |
| 419 | return 1; |
| 420 | } |
| 421 | return 0; |
| 422 | } |
| 423 | |
Willy Tarreau | 8b3c808 | 2014-09-16 15:39:51 +0200 | [diff] [blame] | 424 | /* report a warning if a "tcp request connection" rule is dangerously placed */ |
| 425 | int warnif_misplaced_tcp_conn(struct proxy *proxy, const char *file, int line, const char *arg) |
| 426 | { |
| 427 | return warnif_rule_after_tcp_cont(proxy, file, line, arg) || |
| 428 | warnif_rule_after_block(proxy, file, line, arg) || |
| 429 | warnif_rule_after_http_req(proxy, file, line, arg) || |
| 430 | warnif_rule_after_reqxxx(proxy, file, line, arg) || |
| 431 | warnif_rule_after_reqadd(proxy, file, line, arg) || |
| 432 | warnif_rule_after_redirect(proxy, file, line, arg) || |
| 433 | warnif_rule_after_use_backend(proxy, file, line, arg) || |
| 434 | warnif_rule_after_use_server(proxy, file, line, arg); |
| 435 | } |
| 436 | |
| 437 | /* report a warning if a "tcp request content" rule is dangerously placed */ |
| 438 | int warnif_misplaced_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg) |
| 439 | { |
| 440 | return warnif_rule_after_block(proxy, file, line, arg) || |
| 441 | warnif_rule_after_http_req(proxy, file, line, arg) || |
| 442 | warnif_rule_after_reqxxx(proxy, file, line, arg) || |
| 443 | warnif_rule_after_reqadd(proxy, file, line, arg) || |
| 444 | warnif_rule_after_redirect(proxy, file, line, arg) || |
| 445 | warnif_rule_after_use_backend(proxy, file, line, arg) || |
| 446 | warnif_rule_after_use_server(proxy, file, line, arg); |
| 447 | } |
| 448 | |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 449 | /* report a warning if a block rule is dangerously placed */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 450 | 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] | 451 | { |
Willy Tarreau | 5002f57 | 2014-04-23 01:32:02 +0200 | [diff] [blame] | 452 | return warnif_rule_after_http_req(proxy, file, line, arg) || |
| 453 | warnif_rule_after_reqxxx(proxy, file, line, arg) || |
| 454 | warnif_rule_after_reqadd(proxy, file, line, arg) || |
| 455 | warnif_rule_after_redirect(proxy, file, line, arg) || |
Willy Tarreau | ee445d9 | 2014-04-23 01:39:04 +0200 | [diff] [blame] | 456 | warnif_rule_after_use_backend(proxy, file, line, arg) || |
| 457 | warnif_rule_after_use_server(proxy, file, line, arg); |
Willy Tarreau | 5002f57 | 2014-04-23 01:32:02 +0200 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | /* report a warning if an http-request rule is dangerously placed */ |
| 461 | int warnif_misplaced_http_req(struct proxy *proxy, const char *file, int line, const char *arg) |
| 462 | { |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 463 | return warnif_rule_after_reqxxx(proxy, file, line, arg) || |
| 464 | warnif_rule_after_reqadd(proxy, file, line, arg) || |
| 465 | warnif_rule_after_redirect(proxy, file, line, arg) || |
Willy Tarreau | ee445d9 | 2014-04-23 01:39:04 +0200 | [diff] [blame] | 466 | warnif_rule_after_use_backend(proxy, file, line, arg) || |
| 467 | warnif_rule_after_use_server(proxy, file, line, arg); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 468 | } |
| 469 | |
| 470 | /* report a warning if a reqxxx rule is dangerously placed */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 471 | 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] | 472 | { |
| 473 | return warnif_rule_after_reqadd(proxy, file, line, arg) || |
| 474 | warnif_rule_after_redirect(proxy, file, line, arg) || |
Willy Tarreau | ee445d9 | 2014-04-23 01:39:04 +0200 | [diff] [blame] | 475 | warnif_rule_after_use_backend(proxy, file, line, arg) || |
| 476 | warnif_rule_after_use_server(proxy, file, line, arg); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | /* report a warning if a reqadd rule is dangerously placed */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 480 | 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] | 481 | { |
| 482 | return warnif_rule_after_redirect(proxy, file, line, arg) || |
Willy Tarreau | ee445d9 | 2014-04-23 01:39:04 +0200 | [diff] [blame] | 483 | warnif_rule_after_use_backend(proxy, file, line, arg) || |
| 484 | warnif_rule_after_use_server(proxy, file, line, arg); |
| 485 | } |
| 486 | |
| 487 | /* report a warning if a redirect rule is dangerously placed */ |
| 488 | int warnif_misplaced_redirect(struct proxy *proxy, const char *file, int line, const char *arg) |
| 489 | { |
| 490 | return warnif_rule_after_use_backend(proxy, file, line, arg) || |
| 491 | warnif_rule_after_use_server(proxy, file, line, arg); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 492 | } |
| 493 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 494 | /* Report it if a request ACL condition uses some keywords that are incompatible |
| 495 | * with the place where the ACL is used. It returns either 0 or ERR_WARN so that |
| 496 | * its result can be or'ed with err_code. Note that <cond> may be NULL and then |
| 497 | * will be ignored. |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 498 | */ |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 499 | static int warnif_cond_conflicts(const struct acl_cond *cond, unsigned int where, const char *file, int line) |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 500 | { |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 501 | const struct acl *acl; |
Willy Tarreau | 93fddf1 | 2013-03-31 22:59:32 +0200 | [diff] [blame] | 502 | const char *kw; |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 503 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 504 | if (!cond) |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 505 | return 0; |
| 506 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 507 | acl = acl_cond_conflicts(cond, where); |
| 508 | if (acl) { |
| 509 | if (acl->name && *acl->name) |
| 510 | Warning("parsing [%s:%d] : acl '%s' will never match because it only involves keywords that are incompatible with '%s'\n", |
| 511 | file, line, acl->name, sample_ckp_names(where)); |
| 512 | else |
| 513 | Warning("parsing [%s:%d] : anonymous acl will never match because it uses keyword '%s' which is incompatible with '%s'\n", |
Willy Tarreau | 93fddf1 | 2013-03-31 22:59:32 +0200 | [diff] [blame] | 514 | file, line, LIST_ELEM(acl->expr.n, struct acl_expr *, list)->kw, sample_ckp_names(where)); |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 515 | return ERR_WARN; |
| 516 | } |
| 517 | if (!acl_cond_kw_conflicts(cond, where, &acl, &kw)) |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 518 | return 0; |
| 519 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 520 | if (acl->name && *acl->name) |
| 521 | Warning("parsing [%s:%d] : acl '%s' involves keywords '%s' which is incompatible with '%s'\n", |
Willy Tarreau | 93fddf1 | 2013-03-31 22:59:32 +0200 | [diff] [blame] | 522 | file, line, acl->name, kw, sample_ckp_names(where)); |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 523 | else |
| 524 | Warning("parsing [%s:%d] : anonymous acl involves keyword '%s' which is incompatible with '%s'\n", |
Willy Tarreau | 93fddf1 | 2013-03-31 22:59:32 +0200 | [diff] [blame] | 525 | file, line, kw, sample_ckp_names(where)); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 526 | return ERR_WARN; |
| 527 | } |
| 528 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 529 | /* |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 530 | * parse a line in a <global> section. Returns the error code, 0 if OK, or |
| 531 | * any combination of : |
| 532 | * - ERR_ABORT: must abort ASAP |
| 533 | * - ERR_FATAL: we can continue parsing but not start the service |
| 534 | * - ERR_WARN: a warning has been emitted |
| 535 | * - ERR_ALERT: an alert has been emitted |
| 536 | * Only the two first ones can stop processing, the two others are just |
| 537 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 538 | */ |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 539 | 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] | 540 | { |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 541 | int err_code = 0; |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 542 | char *errmsg = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 543 | |
| 544 | if (!strcmp(args[0], "global")) { /* new section */ |
| 545 | /* no option, nothing special to do */ |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 546 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 547 | } |
Emeric Brun | c8e8d12 | 2012-10-02 18:42:10 +0200 | [diff] [blame] | 548 | else if (!strcmp(args[0], "ca-base")) { |
| 549 | #ifdef USE_OPENSSL |
| 550 | if (global.ca_base != NULL) { |
| 551 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 552 | err_code |= ERR_ALERT; |
| 553 | goto out; |
| 554 | } |
| 555 | if (*(args[1]) == 0) { |
| 556 | Alert("parsing [%s:%d] : '%s' expects a directory path as an argument.\n", file, linenum, args[0]); |
| 557 | err_code |= ERR_ALERT | ERR_FATAL; |
| 558 | goto out; |
| 559 | } |
| 560 | global.ca_base = strdup(args[1]); |
| 561 | #else |
| 562 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 563 | err_code |= ERR_ALERT | ERR_FATAL; |
| 564 | goto out; |
| 565 | #endif |
| 566 | } |
| 567 | else if (!strcmp(args[0], "crt-base")) { |
| 568 | #ifdef USE_OPENSSL |
| 569 | if (global.crt_base != NULL) { |
| 570 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 571 | err_code |= ERR_ALERT; |
| 572 | goto out; |
| 573 | } |
| 574 | if (*(args[1]) == 0) { |
| 575 | Alert("parsing [%s:%d] : '%s' expects a directory path as an argument.\n", file, linenum, args[0]); |
| 576 | err_code |= ERR_ALERT | ERR_FATAL; |
| 577 | goto out; |
| 578 | } |
| 579 | global.crt_base = strdup(args[1]); |
| 580 | #else |
| 581 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 582 | err_code |= ERR_ALERT | ERR_FATAL; |
| 583 | goto out; |
| 584 | #endif |
| 585 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 586 | else if (!strcmp(args[0], "daemon")) { |
| 587 | global.mode |= MODE_DAEMON; |
| 588 | } |
| 589 | else if (!strcmp(args[0], "debug")) { |
| 590 | global.mode |= MODE_DEBUG; |
| 591 | } |
| 592 | else if (!strcmp(args[0], "noepoll")) { |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 593 | global.tune.options &= ~GTUNE_USE_EPOLL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 594 | } |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 595 | else if (!strcmp(args[0], "nokqueue")) { |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 596 | global.tune.options &= ~GTUNE_USE_KQUEUE; |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 597 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 598 | else if (!strcmp(args[0], "nopoll")) { |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 599 | global.tune.options &= ~GTUNE_USE_POLL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 600 | } |
Willy Tarreau | 3ab68cf | 2009-01-25 16:03:28 +0100 | [diff] [blame] | 601 | else if (!strcmp(args[0], "nosplice")) { |
| 602 | global.tune.options &= ~GTUNE_USE_SPLICE; |
| 603 | } |
Nenad Merdanovic | 88afe03 | 2014-04-14 15:56:58 +0200 | [diff] [blame] | 604 | else if (!strcmp(args[0], "nogetaddrinfo")) { |
| 605 | global.tune.options &= ~GTUNE_USE_GAI; |
| 606 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 607 | else if (!strcmp(args[0], "quiet")) { |
| 608 | global.mode |= MODE_QUIET; |
| 609 | } |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 610 | else if (!strcmp(args[0], "tune.maxpollevents")) { |
| 611 | if (global.tune.maxpollevents != 0) { |
| 612 | 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] | 613 | err_code |= ERR_ALERT; |
| 614 | goto out; |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 615 | } |
| 616 | if (*(args[1]) == 0) { |
| 617 | 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] | 618 | err_code |= ERR_ALERT | ERR_FATAL; |
| 619 | goto out; |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 620 | } |
| 621 | global.tune.maxpollevents = atol(args[1]); |
| 622 | } |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 623 | else if (!strcmp(args[0], "tune.maxaccept")) { |
| 624 | if (global.tune.maxaccept != 0) { |
| 625 | 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] | 626 | err_code |= ERR_ALERT; |
| 627 | goto out; |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 628 | } |
| 629 | if (*(args[1]) == 0) { |
| 630 | 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] | 631 | err_code |= ERR_ALERT | ERR_FATAL; |
| 632 | goto out; |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 633 | } |
| 634 | global.tune.maxaccept = atol(args[1]); |
| 635 | } |
Willy Tarreau | 43961d5 | 2010-10-04 20:39:20 +0200 | [diff] [blame] | 636 | else if (!strcmp(args[0], "tune.chksize")) { |
| 637 | if (*(args[1]) == 0) { |
| 638 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 639 | err_code |= ERR_ALERT | ERR_FATAL; |
| 640 | goto out; |
| 641 | } |
| 642 | global.tune.chksize = atol(args[1]); |
| 643 | } |
Emeric Brun | fc32aca | 2012-09-03 12:10:29 +0200 | [diff] [blame] | 644 | #ifdef USE_OPENSSL |
Emeric Brun | 8dc6039 | 2014-05-09 13:52:00 +0200 | [diff] [blame] | 645 | else if (!strcmp(args[0], "tune.ssl.force-private-cache")) { |
| 646 | global.tune.sslprivatecache = 1; |
| 647 | } |
Willy Tarreau | 6ec58db | 2012-11-16 16:32:15 +0100 | [diff] [blame] | 648 | else if (!strcmp(args[0], "tune.ssl.cachesize")) { |
Emeric Brun | fc32aca | 2012-09-03 12:10:29 +0200 | [diff] [blame] | 649 | if (*(args[1]) == 0) { |
| 650 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 651 | err_code |= ERR_ALERT | ERR_FATAL; |
| 652 | goto out; |
| 653 | } |
| 654 | global.tune.sslcachesize = atol(args[1]); |
| 655 | } |
Emeric Brun | 4f65bff | 2012-11-16 15:11:00 +0100 | [diff] [blame] | 656 | else if (!strcmp(args[0], "tune.ssl.lifetime")) { |
| 657 | unsigned int ssllifetime; |
| 658 | const char *res; |
| 659 | |
| 660 | if (*(args[1]) == 0) { |
| 661 | Alert("parsing [%s:%d] : '%s' expects ssl sessions <lifetime> in seconds as argument.\n", file, linenum, args[0]); |
| 662 | err_code |= ERR_ALERT | ERR_FATAL; |
| 663 | goto out; |
| 664 | } |
| 665 | |
| 666 | res = parse_time_err(args[1], &ssllifetime, TIME_UNIT_S); |
| 667 | if (res) { |
| 668 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 669 | file, linenum, *res, args[0]); |
| 670 | err_code |= ERR_ALERT | ERR_FATAL; |
| 671 | goto out; |
| 672 | } |
| 673 | |
| 674 | global.tune.ssllifetime = ssllifetime; |
| 675 | } |
Willy Tarreau | bfd5946 | 2013-02-21 07:46:09 +0100 | [diff] [blame] | 676 | else if (!strcmp(args[0], "tune.ssl.maxrecord")) { |
| 677 | if (*(args[1]) == 0) { |
| 678 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 679 | err_code |= ERR_ALERT | ERR_FATAL; |
| 680 | goto out; |
| 681 | } |
| 682 | global.tune.ssl_max_record = atol(args[1]); |
| 683 | } |
Remi Gacogne | f46cd6e | 2014-06-12 14:58:40 +0200 | [diff] [blame] | 684 | else if (!strcmp(args[0], "tune.ssl.default-dh-param")) { |
| 685 | if (*(args[1]) == 0) { |
| 686 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 687 | err_code |= ERR_ALERT | ERR_FATAL; |
| 688 | goto out; |
| 689 | } |
| 690 | global.tune.ssl_default_dh_param = atol(args[1]); |
| 691 | if (global.tune.ssl_default_dh_param < 1024) { |
| 692 | Alert("parsing [%s:%d] : '%s' expects a value >= 1024.\n", file, linenum, args[0]); |
| 693 | err_code |= ERR_ALERT | ERR_FATAL; |
| 694 | goto out; |
| 695 | } |
| 696 | } |
Emeric Brun | fc32aca | 2012-09-03 12:10:29 +0200 | [diff] [blame] | 697 | #endif |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 698 | else if (!strcmp(args[0], "tune.bufsize")) { |
| 699 | if (*(args[1]) == 0) { |
| 700 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 701 | err_code |= ERR_ALERT | ERR_FATAL; |
| 702 | goto out; |
| 703 | } |
| 704 | global.tune.bufsize = atol(args[1]); |
| 705 | if (global.tune.maxrewrite >= global.tune.bufsize / 2) |
| 706 | global.tune.maxrewrite = global.tune.bufsize / 2; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 707 | chunk_init(&trash, realloc(trash.str, global.tune.bufsize), global.tune.bufsize); |
Willy Tarreau | 2819e99 | 2013-12-13 14:41:10 +0100 | [diff] [blame] | 708 | alloc_trash_buffers(global.tune.bufsize); |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 709 | } |
| 710 | else if (!strcmp(args[0], "tune.maxrewrite")) { |
| 711 | if (*(args[1]) == 0) { |
| 712 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 713 | err_code |= ERR_ALERT | ERR_FATAL; |
| 714 | goto out; |
| 715 | } |
| 716 | global.tune.maxrewrite = atol(args[1]); |
| 717 | if (global.tune.maxrewrite >= global.tune.bufsize / 2) |
| 718 | global.tune.maxrewrite = global.tune.bufsize / 2; |
| 719 | } |
Willy Tarreau | 7e31273 | 2014-02-12 16:35:14 +0100 | [diff] [blame] | 720 | else if (!strcmp(args[0], "tune.idletimer")) { |
| 721 | unsigned int idle; |
| 722 | const char *res; |
| 723 | |
| 724 | if (*(args[1]) == 0) { |
| 725 | Alert("parsing [%s:%d] : '%s' expects a timer value between 0 and 65535 ms.\n", file, linenum, args[0]); |
| 726 | err_code |= ERR_ALERT | ERR_FATAL; |
| 727 | goto out; |
| 728 | } |
| 729 | |
| 730 | res = parse_time_err(args[1], &idle, TIME_UNIT_MS); |
| 731 | if (res) { |
| 732 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 733 | file, linenum, *res, args[0]); |
| 734 | err_code |= ERR_ALERT | ERR_FATAL; |
| 735 | goto out; |
| 736 | } |
| 737 | |
| 738 | if (idle > 65535) { |
| 739 | Alert("parsing [%s:%d] : '%s' expects a timer value between 0 and 65535 ms.\n", file, linenum, args[0]); |
| 740 | err_code |= ERR_ALERT | ERR_FATAL; |
| 741 | goto out; |
| 742 | } |
| 743 | global.tune.idle_timer = idle; |
| 744 | } |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 745 | else if (!strcmp(args[0], "tune.rcvbuf.client")) { |
| 746 | if (global.tune.client_rcvbuf != 0) { |
| 747 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 748 | err_code |= ERR_ALERT; |
| 749 | goto out; |
| 750 | } |
| 751 | if (*(args[1]) == 0) { |
| 752 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 753 | err_code |= ERR_ALERT | ERR_FATAL; |
| 754 | goto out; |
| 755 | } |
| 756 | global.tune.client_rcvbuf = atol(args[1]); |
| 757 | } |
| 758 | else if (!strcmp(args[0], "tune.rcvbuf.server")) { |
| 759 | if (global.tune.server_rcvbuf != 0) { |
| 760 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 761 | err_code |= ERR_ALERT; |
| 762 | goto out; |
| 763 | } |
| 764 | if (*(args[1]) == 0) { |
| 765 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 766 | err_code |= ERR_ALERT | ERR_FATAL; |
| 767 | goto out; |
| 768 | } |
| 769 | global.tune.server_rcvbuf = atol(args[1]); |
| 770 | } |
| 771 | else if (!strcmp(args[0], "tune.sndbuf.client")) { |
| 772 | if (global.tune.client_sndbuf != 0) { |
| 773 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 774 | err_code |= ERR_ALERT; |
| 775 | goto out; |
| 776 | } |
| 777 | if (*(args[1]) == 0) { |
| 778 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 779 | err_code |= ERR_ALERT | ERR_FATAL; |
| 780 | goto out; |
| 781 | } |
| 782 | global.tune.client_sndbuf = atol(args[1]); |
| 783 | } |
| 784 | else if (!strcmp(args[0], "tune.sndbuf.server")) { |
| 785 | if (global.tune.server_sndbuf != 0) { |
| 786 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 787 | err_code |= ERR_ALERT; |
| 788 | goto out; |
| 789 | } |
| 790 | if (*(args[1]) == 0) { |
| 791 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 792 | err_code |= ERR_ALERT | ERR_FATAL; |
| 793 | goto out; |
| 794 | } |
| 795 | global.tune.server_sndbuf = atol(args[1]); |
| 796 | } |
Willy Tarreau | bd9a0a7 | 2011-10-23 21:14:29 +0200 | [diff] [blame] | 797 | else if (!strcmp(args[0], "tune.pipesize")) { |
| 798 | if (*(args[1]) == 0) { |
| 799 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 800 | err_code |= ERR_ALERT | ERR_FATAL; |
| 801 | goto out; |
| 802 | } |
| 803 | global.tune.pipesize = atol(args[1]); |
| 804 | } |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 805 | else if (!strcmp(args[0], "tune.http.cookielen")) { |
| 806 | if (*(args[1]) == 0) { |
| 807 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 808 | err_code |= ERR_ALERT | ERR_FATAL; |
| 809 | goto out; |
| 810 | } |
| 811 | global.tune.cookie_len = atol(args[1]) + 1; |
| 812 | } |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame] | 813 | else if (!strcmp(args[0], "tune.http.maxhdr")) { |
| 814 | if (*(args[1]) == 0) { |
| 815 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 816 | err_code |= ERR_ALERT | ERR_FATAL; |
| 817 | goto out; |
| 818 | } |
| 819 | global.tune.max_http_hdr = atol(args[1]); |
| 820 | } |
William Lallemand | a509e4c | 2012-11-07 16:54:34 +0100 | [diff] [blame] | 821 | else if (!strcmp(args[0], "tune.zlib.memlevel")) { |
| 822 | #ifdef USE_ZLIB |
| 823 | if (*args[1]) { |
| 824 | global.tune.zlibmemlevel = atoi(args[1]); |
| 825 | if (global.tune.zlibmemlevel < 1 || global.tune.zlibmemlevel > 9) { |
| 826 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n", |
| 827 | file, linenum, args[0]); |
| 828 | err_code |= ERR_ALERT | ERR_FATAL; |
| 829 | goto out; |
| 830 | } |
| 831 | } else { |
| 832 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n", |
| 833 | file, linenum, args[0]); |
| 834 | err_code |= ERR_ALERT | ERR_FATAL; |
| 835 | goto out; |
| 836 | } |
| 837 | #else |
| 838 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 839 | err_code |= ERR_ALERT | ERR_FATAL; |
| 840 | goto out; |
| 841 | #endif |
| 842 | } |
| 843 | else if (!strcmp(args[0], "tune.zlib.windowsize")) { |
| 844 | #ifdef USE_ZLIB |
| 845 | if (*args[1]) { |
| 846 | global.tune.zlibwindowsize = atoi(args[1]); |
| 847 | if (global.tune.zlibwindowsize < 8 || global.tune.zlibwindowsize > 15) { |
| 848 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 8 and 15\n", |
| 849 | file, linenum, args[0]); |
| 850 | err_code |= ERR_ALERT | ERR_FATAL; |
| 851 | goto out; |
| 852 | } |
| 853 | } else { |
| 854 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 8 and 15\n", |
| 855 | file, linenum, args[0]); |
| 856 | err_code |= ERR_ALERT | ERR_FATAL; |
| 857 | goto out; |
| 858 | } |
| 859 | #else |
| 860 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 861 | err_code |= ERR_ALERT | ERR_FATAL; |
| 862 | goto out; |
| 863 | #endif |
| 864 | } |
William Lallemand | f374783 | 2012-11-09 12:33:10 +0100 | [diff] [blame] | 865 | else if (!strcmp(args[0], "tune.comp.maxlevel")) { |
| 866 | if (*args[1]) { |
| 867 | global.tune.comp_maxlevel = atoi(args[1]); |
| 868 | if (global.tune.comp_maxlevel < 1 || global.tune.comp_maxlevel > 9) { |
| 869 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n", |
| 870 | file, linenum, args[0]); |
| 871 | err_code |= ERR_ALERT | ERR_FATAL; |
| 872 | goto out; |
| 873 | } |
| 874 | } else { |
| 875 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n", |
| 876 | file, linenum, args[0]); |
| 877 | err_code |= ERR_ALERT | ERR_FATAL; |
| 878 | goto out; |
| 879 | } |
| 880 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 881 | else if (!strcmp(args[0], "uid")) { |
| 882 | if (global.uid != 0) { |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 883 | Alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 884 | err_code |= ERR_ALERT; |
| 885 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 886 | } |
| 887 | if (*(args[1]) == 0) { |
| 888 | 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] | 889 | err_code |= ERR_ALERT | ERR_FATAL; |
| 890 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 891 | } |
| 892 | global.uid = atol(args[1]); |
| 893 | } |
| 894 | else if (!strcmp(args[0], "gid")) { |
| 895 | if (global.gid != 0) { |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 896 | Alert("parsing [%s:%d] : group/gid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 897 | err_code |= ERR_ALERT; |
| 898 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 899 | } |
| 900 | if (*(args[1]) == 0) { |
| 901 | 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] | 902 | err_code |= ERR_ALERT | ERR_FATAL; |
| 903 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 904 | } |
| 905 | global.gid = atol(args[1]); |
| 906 | } |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 907 | /* user/group name handling */ |
| 908 | else if (!strcmp(args[0], "user")) { |
| 909 | struct passwd *ha_user; |
| 910 | if (global.uid != 0) { |
| 911 | Alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 912 | err_code |= ERR_ALERT; |
| 913 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 914 | } |
| 915 | errno = 0; |
| 916 | ha_user = getpwnam(args[1]); |
| 917 | if (ha_user != NULL) { |
| 918 | global.uid = (int)ha_user->pw_uid; |
| 919 | } |
| 920 | else { |
| 921 | 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] | 922 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 923 | } |
| 924 | } |
| 925 | else if (!strcmp(args[0], "group")) { |
| 926 | struct group *ha_group; |
| 927 | if (global.gid != 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 928 | 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] | 929 | err_code |= ERR_ALERT; |
| 930 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 931 | } |
| 932 | errno = 0; |
| 933 | ha_group = getgrnam(args[1]); |
| 934 | if (ha_group != NULL) { |
| 935 | global.gid = (int)ha_group->gr_gid; |
| 936 | } |
| 937 | else { |
| 938 | 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] | 939 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 940 | } |
| 941 | } |
| 942 | /* end of user/group name handling*/ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 943 | else if (!strcmp(args[0], "nbproc")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 944 | if (*(args[1]) == 0) { |
| 945 | 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] | 946 | err_code |= ERR_ALERT | ERR_FATAL; |
| 947 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 948 | } |
| 949 | global.nbproc = atol(args[1]); |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 950 | if (global.nbproc < 1 || global.nbproc > LONGBITS) { |
| 951 | Alert("parsing [%s:%d] : '%s' must be between 1 and %d (was %d).\n", |
| 952 | file, linenum, args[0], LONGBITS, global.nbproc); |
| 953 | err_code |= ERR_ALERT | ERR_FATAL; |
| 954 | goto out; |
| 955 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 956 | } |
| 957 | else if (!strcmp(args[0], "maxconn")) { |
| 958 | if (global.maxconn != 0) { |
| 959 | 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] | 960 | err_code |= ERR_ALERT; |
| 961 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 962 | } |
| 963 | if (*(args[1]) == 0) { |
| 964 | 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] | 965 | err_code |= ERR_ALERT | ERR_FATAL; |
| 966 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 967 | } |
| 968 | global.maxconn = atol(args[1]); |
| 969 | #ifdef SYSTEM_MAXCONN |
| 970 | if (global.maxconn > DEFAULT_MAXCONN && cfg_maxconn <= DEFAULT_MAXCONN) { |
| 971 | 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); |
| 972 | global.maxconn = DEFAULT_MAXCONN; |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 973 | err_code |= ERR_ALERT; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 974 | } |
| 975 | #endif /* SYSTEM_MAXCONN */ |
| 976 | } |
Willy Tarreau | 403edff | 2012-09-06 11:58:37 +0200 | [diff] [blame] | 977 | else if (!strcmp(args[0], "maxsslconn")) { |
| 978 | #ifdef USE_OPENSSL |
| 979 | if (*(args[1]) == 0) { |
| 980 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 981 | err_code |= ERR_ALERT | ERR_FATAL; |
| 982 | goto out; |
| 983 | } |
| 984 | global.maxsslconn = atol(args[1]); |
| 985 | #else |
Emeric Brun | 0914df8 | 2012-10-02 18:45:42 +0200 | [diff] [blame] | 986 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 987 | err_code |= ERR_ALERT | ERR_FATAL; |
| 988 | goto out; |
Willy Tarreau | 403edff | 2012-09-06 11:58:37 +0200 | [diff] [blame] | 989 | #endif |
| 990 | } |
Willy Tarreau | 610f04b | 2014-02-13 11:36:41 +0100 | [diff] [blame] | 991 | else if (!strcmp(args[0], "ssl-default-bind-ciphers")) { |
| 992 | #ifdef USE_OPENSSL |
| 993 | if (*(args[1]) == 0) { |
| 994 | Alert("parsing [%s:%d] : '%s' expects a cipher suite as an argument.\n", file, linenum, args[0]); |
| 995 | err_code |= ERR_ALERT | ERR_FATAL; |
| 996 | goto out; |
| 997 | } |
| 998 | free(global.listen_default_ciphers); |
| 999 | global.listen_default_ciphers = strdup(args[1]); |
| 1000 | #else |
| 1001 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 1002 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1003 | goto out; |
| 1004 | #endif |
| 1005 | } |
| 1006 | else if (!strcmp(args[0], "ssl-default-server-ciphers")) { |
| 1007 | #ifdef USE_OPENSSL |
| 1008 | if (*(args[1]) == 0) { |
| 1009 | Alert("parsing [%s:%d] : '%s' expects a cipher suite as an argument.\n", file, linenum, args[0]); |
| 1010 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1011 | goto out; |
| 1012 | } |
| 1013 | free(global.connect_default_ciphers); |
| 1014 | global.connect_default_ciphers = strdup(args[1]); |
| 1015 | #else |
| 1016 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 1017 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1018 | goto out; |
| 1019 | #endif |
| 1020 | } |
Emeric Brun | 850efd5 | 2014-01-29 12:24:34 +0100 | [diff] [blame] | 1021 | else if (!strcmp(args[0], "ssl-server-verify")) { |
| 1022 | if (*(args[1]) == 0) { |
| 1023 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1024 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1025 | goto out; |
| 1026 | } |
| 1027 | if (strcmp(args[1],"none") == 0) |
| 1028 | global.ssl_server_verify = SSL_SERVER_VERIFY_NONE; |
| 1029 | else if (strcmp(args[1],"required") == 0) |
| 1030 | global.ssl_server_verify = SSL_SERVER_VERIFY_REQUIRED; |
| 1031 | else { |
| 1032 | Alert("parsing [%s:%d] : '%s' expects 'none' or 'required' as argument.\n", file, linenum, args[0]); |
| 1033 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1034 | goto out; |
| 1035 | } |
| 1036 | } |
Willy Tarreau | 81c25d0 | 2011-09-07 15:17:21 +0200 | [diff] [blame] | 1037 | else if (!strcmp(args[0], "maxconnrate")) { |
| 1038 | if (global.cps_lim != 0) { |
| 1039 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 1040 | err_code |= ERR_ALERT; |
| 1041 | goto out; |
| 1042 | } |
| 1043 | if (*(args[1]) == 0) { |
| 1044 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1045 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1046 | goto out; |
| 1047 | } |
| 1048 | global.cps_lim = atol(args[1]); |
| 1049 | } |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1050 | else if (!strcmp(args[0], "maxsessrate")) { |
| 1051 | if (global.sps_lim != 0) { |
| 1052 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 1053 | err_code |= ERR_ALERT; |
| 1054 | goto out; |
| 1055 | } |
| 1056 | if (*(args[1]) == 0) { |
| 1057 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1058 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1059 | goto out; |
| 1060 | } |
| 1061 | global.sps_lim = atol(args[1]); |
| 1062 | } |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 1063 | else if (!strcmp(args[0], "maxsslrate")) { |
| 1064 | if (global.ssl_lim != 0) { |
| 1065 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 1066 | err_code |= ERR_ALERT; |
| 1067 | goto out; |
| 1068 | } |
| 1069 | if (*(args[1]) == 0) { |
| 1070 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1071 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1072 | goto out; |
| 1073 | } |
| 1074 | global.ssl_lim = atol(args[1]); |
| 1075 | } |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1076 | else if (!strcmp(args[0], "maxcomprate")) { |
| 1077 | if (*(args[1]) == 0) { |
| 1078 | Alert("parsing [%s:%d] : '%s' expects an integer argument in kb/s.\n", file, linenum, args[0]); |
| 1079 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1080 | goto out; |
| 1081 | } |
| 1082 | global.comp_rate_lim = atoi(args[1]) * 1024; |
| 1083 | } |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 1084 | else if (!strcmp(args[0], "maxpipes")) { |
| 1085 | if (global.maxpipes != 0) { |
| 1086 | 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] | 1087 | err_code |= ERR_ALERT; |
| 1088 | goto out; |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 1089 | } |
| 1090 | if (*(args[1]) == 0) { |
| 1091 | 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] | 1092 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1093 | goto out; |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 1094 | } |
| 1095 | global.maxpipes = atol(args[1]); |
| 1096 | } |
William Lallemand | 9d5f548 | 2012-11-07 16:12:57 +0100 | [diff] [blame] | 1097 | else if (!strcmp(args[0], "maxzlibmem")) { |
| 1098 | if (*(args[1]) == 0) { |
| 1099 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1100 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1101 | goto out; |
| 1102 | } |
William Lallemand | e3a7d99 | 2012-11-20 11:25:20 +0100 | [diff] [blame] | 1103 | global.maxzlibmem = atol(args[1]) * 1024L * 1024L; |
William Lallemand | 9d5f548 | 2012-11-07 16:12:57 +0100 | [diff] [blame] | 1104 | } |
William Lallemand | 072a2bf | 2012-11-20 17:01:01 +0100 | [diff] [blame] | 1105 | else if (!strcmp(args[0], "maxcompcpuusage")) { |
| 1106 | if (*(args[1]) == 0) { |
| 1107 | Alert("parsing [%s:%d] : '%s' expects an integer argument between 0 and 100.\n", file, linenum, args[0]); |
| 1108 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1109 | goto out; |
| 1110 | } |
| 1111 | compress_min_idle = 100 - atoi(args[1]); |
Willy Tarreau | cb2699a | 2013-01-24 16:25:38 +0100 | [diff] [blame] | 1112 | if (compress_min_idle > 100) { |
William Lallemand | 072a2bf | 2012-11-20 17:01:01 +0100 | [diff] [blame] | 1113 | Alert("parsing [%s:%d] : '%s' expects an integer argument between 0 and 100.\n", file, linenum, args[0]); |
| 1114 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1115 | goto out; |
| 1116 | } |
| 1117 | } |
| 1118 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1119 | else if (!strcmp(args[0], "ulimit-n")) { |
| 1120 | if (global.rlimit_nofile != 0) { |
| 1121 | 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] | 1122 | err_code |= ERR_ALERT; |
| 1123 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1124 | } |
| 1125 | if (*(args[1]) == 0) { |
| 1126 | 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] | 1127 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1128 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1129 | } |
| 1130 | global.rlimit_nofile = atol(args[1]); |
| 1131 | } |
| 1132 | else if (!strcmp(args[0], "chroot")) { |
| 1133 | if (global.chroot != NULL) { |
| 1134 | 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] | 1135 | err_code |= ERR_ALERT; |
| 1136 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1137 | } |
| 1138 | if (*(args[1]) == 0) { |
| 1139 | 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] | 1140 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1141 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1142 | } |
| 1143 | global.chroot = strdup(args[1]); |
| 1144 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1145 | else if (!strcmp(args[0], "description")) { |
| 1146 | int i, len=0; |
| 1147 | char *d; |
| 1148 | |
| 1149 | if (!*args[1]) { |
| 1150 | Alert("parsing [%s:%d]: '%s' expects a string argument.\n", |
| 1151 | file, linenum, args[0]); |
| 1152 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1153 | goto out; |
| 1154 | } |
| 1155 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 1156 | for (i = 1; *args[i]; i++) |
| 1157 | len += strlen(args[i]) + 1; |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1158 | |
| 1159 | if (global.desc) |
| 1160 | free(global.desc); |
| 1161 | |
| 1162 | global.desc = d = (char *)calloc(1, len); |
| 1163 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 1164 | d += snprintf(d, global.desc + len - d, "%s", args[1]); |
| 1165 | for (i = 2; *args[i]; i++) |
| 1166 | d += snprintf(d, global.desc + len - d, " %s", args[i]); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1167 | } |
| 1168 | else if (!strcmp(args[0], "node")) { |
| 1169 | int i; |
| 1170 | char c; |
| 1171 | |
| 1172 | for (i=0; args[1][i]; i++) { |
| 1173 | c = args[1][i]; |
Willy Tarreau | 88e0581 | 2010-03-03 00:16:00 +0100 | [diff] [blame] | 1174 | if (!isupper((unsigned char)c) && !islower((unsigned char)c) && |
| 1175 | !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.') |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1176 | break; |
| 1177 | } |
| 1178 | |
| 1179 | if (!i || args[1][i]) { |
| 1180 | Alert("parsing [%s:%d]: '%s' requires valid node name - non-empty string" |
| 1181 | " with digits(0-9), letters(A-Z, a-z), dot(.), hyphen(-) or underscode(_).\n", |
| 1182 | file, linenum, args[0]); |
| 1183 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1184 | goto out; |
| 1185 | } |
| 1186 | |
| 1187 | if (global.node) |
| 1188 | free(global.node); |
| 1189 | |
| 1190 | global.node = strdup(args[1]); |
| 1191 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1192 | else if (!strcmp(args[0], "pidfile")) { |
| 1193 | if (global.pidfile != NULL) { |
| 1194 | 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] | 1195 | err_code |= ERR_ALERT; |
| 1196 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1197 | } |
| 1198 | if (*(args[1]) == 0) { |
| 1199 | 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] | 1200 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1201 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1202 | } |
| 1203 | global.pidfile = strdup(args[1]); |
| 1204 | } |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 1205 | else if (!strcmp(args[0], "unix-bind")) { |
| 1206 | int cur_arg = 1; |
| 1207 | while (*(args[cur_arg])) { |
| 1208 | if (!strcmp(args[cur_arg], "prefix")) { |
| 1209 | if (global.unix_bind.prefix != NULL) { |
| 1210 | Alert("parsing [%s:%d] : unix-bind '%s' already specified. Continuing.\n", file, linenum, args[cur_arg]); |
| 1211 | err_code |= ERR_ALERT; |
| 1212 | cur_arg += 2; |
| 1213 | continue; |
| 1214 | } |
| 1215 | |
| 1216 | if (*(args[cur_arg+1]) == 0) { |
| 1217 | Alert("parsing [%s:%d] : unix_bind '%s' expects a path as an argument.\n", file, linenum, args[cur_arg]); |
| 1218 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1219 | goto out; |
| 1220 | } |
| 1221 | global.unix_bind.prefix = strdup(args[cur_arg+1]); |
| 1222 | cur_arg += 2; |
| 1223 | continue; |
| 1224 | } |
| 1225 | |
| 1226 | if (!strcmp(args[cur_arg], "mode")) { |
| 1227 | |
| 1228 | global.unix_bind.ux.mode = strtol(args[cur_arg + 1], NULL, 8); |
| 1229 | cur_arg += 2; |
| 1230 | continue; |
| 1231 | } |
| 1232 | |
| 1233 | if (!strcmp(args[cur_arg], "uid")) { |
| 1234 | |
| 1235 | global.unix_bind.ux.uid = atol(args[cur_arg + 1 ]); |
| 1236 | cur_arg += 2; |
| 1237 | continue; |
| 1238 | } |
| 1239 | |
| 1240 | if (!strcmp(args[cur_arg], "gid")) { |
| 1241 | |
| 1242 | global.unix_bind.ux.gid = atol(args[cur_arg + 1 ]); |
| 1243 | cur_arg += 2; |
| 1244 | continue; |
| 1245 | } |
| 1246 | |
| 1247 | if (!strcmp(args[cur_arg], "user")) { |
| 1248 | struct passwd *user; |
| 1249 | |
| 1250 | user = getpwnam(args[cur_arg + 1]); |
| 1251 | if (!user) { |
| 1252 | Alert("parsing [%s:%d] : '%s' : '%s' unknown user.\n", |
| 1253 | file, linenum, args[0], args[cur_arg + 1 ]); |
| 1254 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1255 | goto out; |
| 1256 | } |
| 1257 | |
| 1258 | global.unix_bind.ux.uid = user->pw_uid; |
| 1259 | cur_arg += 2; |
| 1260 | continue; |
| 1261 | } |
| 1262 | |
| 1263 | if (!strcmp(args[cur_arg], "group")) { |
| 1264 | struct group *group; |
| 1265 | |
| 1266 | group = getgrnam(args[cur_arg + 1]); |
| 1267 | if (!group) { |
| 1268 | Alert("parsing [%s:%d] : '%s' : '%s' unknown group.\n", |
| 1269 | file, linenum, args[0], args[cur_arg + 1 ]); |
| 1270 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1271 | goto out; |
| 1272 | } |
| 1273 | |
| 1274 | global.unix_bind.ux.gid = group->gr_gid; |
| 1275 | cur_arg += 2; |
| 1276 | continue; |
| 1277 | } |
| 1278 | |
Willy Tarreau | b48f958 | 2011-09-05 01:17:06 +0200 | [diff] [blame] | 1279 | 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] | 1280 | file, linenum, args[0]); |
| 1281 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1282 | goto out; |
| 1283 | } |
| 1284 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1285 | else if (!strcmp(args[0], "log") && kwm == KWM_NO) { /* no log */ |
| 1286 | /* delete previous herited or defined syslog servers */ |
| 1287 | struct logsrv *back; |
| 1288 | struct logsrv *tmp; |
| 1289 | |
| 1290 | if (*(args[1]) != 0) { |
| 1291 | Alert("parsing [%s:%d]:%s : 'no log' does not expect arguments.\n", file, linenum, args[1]); |
| 1292 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1293 | goto out; |
| 1294 | } |
| 1295 | |
| 1296 | list_for_each_entry_safe(tmp, back, &global.logsrvs, list) { |
| 1297 | LIST_DEL(&tmp->list); |
| 1298 | free(tmp); |
| 1299 | } |
| 1300 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1301 | else if (!strcmp(args[0], "log")) { /* syslog server address */ |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1302 | struct sockaddr_storage *sk; |
| 1303 | int port1, port2; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1304 | struct logsrv *logsrv; |
Willy Tarreau | dc2695c | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1305 | int arg = 0; |
| 1306 | int len = 0; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1307 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1308 | if (*(args[1]) == 0 || *(args[2]) == 0) { |
| 1309 | 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] | 1310 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1311 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1312 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1313 | |
| 1314 | logsrv = calloc(1, sizeof(struct logsrv)); |
| 1315 | |
Willy Tarreau | dc2695c | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1316 | /* just after the address, a length may be specified */ |
| 1317 | if (strcmp(args[arg+2], "len") == 0) { |
| 1318 | len = atoi(args[arg+3]); |
| 1319 | if (len < 80 || len > 65535) { |
| 1320 | Alert("parsing [%s:%d] : invalid log length '%s', must be between 80 and 65535.\n", |
| 1321 | file, linenum, args[arg+3]); |
| 1322 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1323 | goto out; |
| 1324 | } |
| 1325 | logsrv->maxlen = len; |
| 1326 | |
| 1327 | /* skip these two args */ |
| 1328 | arg += 2; |
| 1329 | } |
| 1330 | else |
| 1331 | logsrv->maxlen = MAX_SYSLOG_LEN; |
| 1332 | |
| 1333 | if (logsrv->maxlen > global.max_syslog_len) { |
| 1334 | global.max_syslog_len = logsrv->maxlen; |
| 1335 | logline = realloc(logline, global.max_syslog_len + 1); |
| 1336 | } |
| 1337 | |
| 1338 | logsrv->facility = get_log_facility(args[arg+2]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1339 | if (logsrv->facility < 0) { |
Willy Tarreau | dc2695c | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1340 | Alert("parsing [%s:%d] : unknown log facility '%s'\n", file, linenum, args[arg+2]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1341 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1342 | logsrv->facility = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1343 | } |
| 1344 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1345 | logsrv->level = 7; /* max syslog level = debug */ |
Willy Tarreau | dc2695c | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1346 | if (*(args[arg+3])) { |
| 1347 | logsrv->level = get_log_level(args[arg+3]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1348 | if (logsrv->level < 0) { |
Willy Tarreau | dc2695c | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1349 | Alert("parsing [%s:%d] : unknown optional log level '%s'\n", file, linenum, args[arg+3]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1350 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1351 | logsrv->level = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1352 | } |
| 1353 | } |
| 1354 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1355 | logsrv->minlvl = 0; /* limit syslog level to this level (emerg) */ |
Willy Tarreau | dc2695c | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1356 | if (*(args[arg+4])) { |
| 1357 | logsrv->minlvl = get_log_level(args[arg+4]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1358 | if (logsrv->minlvl < 0) { |
Willy Tarreau | dc2695c | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1359 | Alert("parsing [%s:%d] : unknown optional minimum log level '%s'\n", file, linenum, args[arg+4]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1360 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1361 | logsrv->minlvl = 0; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 1362 | } |
| 1363 | } |
| 1364 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1365 | sk = str2sa_range(args[1], &port1, &port2, &errmsg, NULL); |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1366 | if (!sk) { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1367 | Alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1368 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1369 | free(logsrv); |
| 1370 | goto out; |
| 1371 | } |
| 1372 | logsrv->addr = *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 1373 | |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1374 | if (sk->ss_family == AF_INET || sk->ss_family == AF_INET6) { |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 1375 | if (port1 != port2) { |
| 1376 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 1377 | file, linenum, args[0], args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 1378 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1379 | free(logsrv); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 1380 | goto out; |
| 1381 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 1382 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1383 | logsrv->addr = *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 1384 | if (!port1) |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1385 | set_host_port(&logsrv->addr, SYSLOG_PORT); |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 1386 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1387 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1388 | LIST_ADDQ(&global.logsrvs, &logsrv->list); |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1389 | } |
Joe Williams | df5b38f | 2010-12-29 17:05:48 +0100 | [diff] [blame] | 1390 | else if (!strcmp(args[0], "log-send-hostname")) { /* set the hostname in syslog header */ |
| 1391 | char *name; |
| 1392 | int len; |
| 1393 | |
| 1394 | if (global.log_send_hostname != NULL) { |
| 1395 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 1396 | err_code |= ERR_ALERT; |
| 1397 | goto out; |
| 1398 | } |
| 1399 | |
| 1400 | if (*(args[1])) |
| 1401 | name = args[1]; |
| 1402 | else |
| 1403 | name = hostname; |
| 1404 | |
| 1405 | len = strlen(name); |
| 1406 | |
| 1407 | /* We'll add a space after the name to respect the log format */ |
| 1408 | free(global.log_send_hostname); |
| 1409 | global.log_send_hostname = malloc(len + 2); |
| 1410 | snprintf(global.log_send_hostname, len + 2, "%s ", name); |
| 1411 | } |
Kevinm | 48936af | 2010-12-22 16:08:21 +0000 | [diff] [blame] | 1412 | else if (!strcmp(args[0], "log-tag")) { /* tag to report to syslog */ |
| 1413 | if (*(args[1]) == 0) { |
| 1414 | Alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]); |
| 1415 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1416 | goto out; |
| 1417 | } |
| 1418 | free(global.log_tag); |
| 1419 | global.log_tag = strdup(args[1]); |
| 1420 | } |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1421 | else if (!strcmp(args[0], "spread-checks")) { /* random time between checks (0-50) */ |
| 1422 | if (global.spread_checks != 0) { |
| 1423 | Alert("parsing [%s:%d]: spread-checks already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1424 | err_code |= ERR_ALERT; |
| 1425 | goto out; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1426 | } |
| 1427 | if (*(args[1]) == 0) { |
| 1428 | 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] | 1429 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1430 | goto out; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1431 | } |
| 1432 | global.spread_checks = atol(args[1]); |
| 1433 | if (global.spread_checks < 0 || global.spread_checks > 50) { |
| 1434 | 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] | 1435 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1436 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1437 | } |
Willy Tarreau | 1746eec | 2014-04-25 10:46:47 +0200 | [diff] [blame] | 1438 | else if (!strcmp(args[0], "max-spread-checks")) { /* maximum time between first and last check */ |
| 1439 | const char *err; |
| 1440 | unsigned int val; |
| 1441 | |
| 1442 | |
| 1443 | if (*(args[1]) == 0) { |
| 1444 | Alert("parsing [%s:%d]: '%s' expects an integer argument (0..50).\n", file, linenum, args[0]); |
| 1445 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1446 | goto out; |
| 1447 | } |
| 1448 | |
| 1449 | err = parse_time_err(args[1], &val, TIME_UNIT_MS); |
| 1450 | if (err) { |
| 1451 | Alert("parsing [%s:%d]: unsupported character '%c' in '%s' (wants an integer delay).\n", file, linenum, *err, args[0]); |
| 1452 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1453 | } |
| 1454 | global.max_spread_checks = val; |
| 1455 | if (global.max_spread_checks < 0) { |
| 1456 | Alert("parsing [%s:%d]: '%s' needs a positive delay in milliseconds.\n",file, linenum, args[0]); |
| 1457 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1458 | } |
| 1459 | } |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1460 | else if (strcmp(args[0], "cpu-map") == 0) { /* map a process list to a CPU set */ |
| 1461 | #ifdef USE_CPU_AFFINITY |
| 1462 | int cur_arg, i; |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1463 | unsigned long proc = 0; |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1464 | unsigned long cpus = 0; |
| 1465 | |
| 1466 | if (strcmp(args[1], "all") == 0) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1467 | proc = ~0UL; |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1468 | else if (strcmp(args[1], "odd") == 0) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1469 | proc = ~0UL/3UL; /* 0x555....555 */ |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1470 | else if (strcmp(args[1], "even") == 0) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1471 | proc = (~0UL/3UL) << 1; /* 0xAAA...AAA */ |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1472 | else { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1473 | proc = atol(args[1]); |
| 1474 | if (proc >= 1 && proc <= LONGBITS) |
| 1475 | proc = 1UL << (proc - 1); |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1476 | } |
| 1477 | |
| 1478 | if (!proc || !*args[2]) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1479 | Alert("parsing [%s:%d]: %s expects a process number including 'all', 'odd', 'even', or a number from 1 to %d, followed by a list of CPU ranges with numbers from 0 to %d.\n", |
| 1480 | file, linenum, args[0], LONGBITS, LONGBITS - 1); |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1481 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1482 | goto out; |
| 1483 | } |
| 1484 | |
| 1485 | cur_arg = 2; |
| 1486 | while (*args[cur_arg]) { |
| 1487 | unsigned int low, high; |
| 1488 | |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 1489 | if (isdigit((int)*args[cur_arg])) { |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1490 | char *dash = strchr(args[cur_arg], '-'); |
| 1491 | |
| 1492 | low = high = str2uic(args[cur_arg]); |
| 1493 | if (dash) |
| 1494 | high = str2uic(dash + 1); |
| 1495 | |
| 1496 | if (high < low) { |
| 1497 | unsigned int swap = low; |
| 1498 | low = high; |
| 1499 | high = swap; |
| 1500 | } |
| 1501 | |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1502 | if (high >= LONGBITS) { |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1503 | Alert("parsing [%s:%d]: %s supports CPU numbers from 0 to %d.\n", |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1504 | file, linenum, args[0], LONGBITS - 1); |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1505 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1506 | goto out; |
| 1507 | } |
| 1508 | |
| 1509 | while (low <= high) |
| 1510 | cpus |= 1UL << low++; |
| 1511 | } |
| 1512 | else { |
| 1513 | Alert("parsing [%s:%d]: %s : '%s' is not a CPU range.\n", |
| 1514 | file, linenum, args[0], args[cur_arg]); |
| 1515 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1516 | goto out; |
| 1517 | } |
| 1518 | cur_arg++; |
| 1519 | } |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1520 | for (i = 0; i < LONGBITS; i++) |
| 1521 | if (proc & (1UL << i)) |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1522 | global.cpu_map[i] = cpus; |
| 1523 | #else |
| 1524 | Alert("parsing [%s:%d] : '%s' is not enabled, please check build options for USE_CPU_AFFINITY.\n", file, linenum, args[0]); |
| 1525 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1526 | goto out; |
| 1527 | #endif |
| 1528 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1529 | else { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1530 | struct cfg_kw_list *kwl; |
| 1531 | int index; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1532 | int rc; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1533 | |
| 1534 | list_for_each_entry(kwl, &cfg_keywords.list, list) { |
| 1535 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 1536 | if (kwl->kw[index].section != CFG_GLOBAL) |
| 1537 | continue; |
| 1538 | if (strcmp(kwl->kw[index].kw, args[0]) == 0) { |
Willy Tarreau | 28a47d6 | 2012-09-18 20:02:48 +0200 | [diff] [blame] | 1539 | 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] | 1540 | if (rc < 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 1541 | Alert("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1542 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1543 | } |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1544 | else if (rc > 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 1545 | Warning("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1546 | err_code |= ERR_WARN; |
| 1547 | goto out; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1548 | } |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1549 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1550 | } |
| 1551 | } |
| 1552 | } |
| 1553 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1554 | 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] | 1555 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1556 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1557 | |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1558 | out: |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 1559 | free(errmsg); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1560 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1561 | } |
| 1562 | |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 1563 | void init_default_instance() |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1564 | { |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 1565 | init_new_proxy(&defproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1566 | defproxy.mode = PR_MODE_TCP; |
| 1567 | defproxy.state = PR_STNEW; |
| 1568 | defproxy.maxconn = cfg_maxpconn; |
| 1569 | defproxy.conn_retries = CONN_RETRIES; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1570 | |
Simon Horman | 6618300 | 2013-02-23 10:16:43 +0900 | [diff] [blame] | 1571 | defproxy.defsrv.check.inter = DEF_CHKINTR; |
| 1572 | defproxy.defsrv.check.fastinter = 0; |
| 1573 | defproxy.defsrv.check.downinter = 0; |
Simon Horman | d60d691 | 2013-11-25 10:46:36 +0900 | [diff] [blame] | 1574 | defproxy.defsrv.agent.inter = DEF_CHKINTR; |
| 1575 | defproxy.defsrv.agent.fastinter = 0; |
| 1576 | defproxy.defsrv.agent.downinter = 0; |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 1577 | defproxy.defsrv.check.rise = DEF_RISETIME; |
| 1578 | defproxy.defsrv.check.fall = DEF_FALLTIME; |
| 1579 | defproxy.defsrv.agent.rise = DEF_AGENT_RISETIME; |
| 1580 | defproxy.defsrv.agent.fall = DEF_AGENT_FALLTIME; |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 1581 | defproxy.defsrv.check.port = 0; |
Simon Horman | d60d691 | 2013-11-25 10:46:36 +0900 | [diff] [blame] | 1582 | defproxy.defsrv.agent.port = 0; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1583 | defproxy.defsrv.maxqueue = 0; |
| 1584 | defproxy.defsrv.minconn = 0; |
| 1585 | defproxy.defsrv.maxconn = 0; |
| 1586 | defproxy.defsrv.slowstart = 0; |
| 1587 | defproxy.defsrv.onerror = DEF_HANA_ONERR; |
| 1588 | defproxy.defsrv.consecutive_errors_limit = DEF_HANA_ERRLIMIT; |
| 1589 | defproxy.defsrv.uweight = defproxy.defsrv.iweight = 1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1590 | } |
| 1591 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1592 | |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1593 | /* This function createss a new req* or rsp* rule to the proxy. It compiles the |
| 1594 | * regex and may return the ERR_WARN bit, and error bits such as ERR_ALERT and |
| 1595 | * ERR_FATAL in case of error. |
| 1596 | */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1597 | static int create_cond_regex_rule(const char *file, int line, |
| 1598 | struct proxy *px, int dir, int action, int flags, |
| 1599 | const char *cmd, const char *reg, const char *repl, |
| 1600 | const char **cond_start) |
| 1601 | { |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1602 | struct my_regex *preg = NULL; |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 1603 | char *errmsg = NULL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1604 | const char *err; |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1605 | char *error; |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1606 | int ret_code = 0; |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1607 | struct acl_cond *cond = NULL; |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1608 | int cs; |
| 1609 | int cap; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1610 | |
| 1611 | if (px == &defproxy) { |
| 1612 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, line, cmd); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1613 | ret_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1614 | goto err; |
| 1615 | } |
| 1616 | |
| 1617 | if (*reg == 0) { |
| 1618 | Alert("parsing [%s:%d] : '%s' expects <regex> as an argument.\n", file, line, cmd); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1619 | ret_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1620 | goto err; |
| 1621 | } |
| 1622 | |
| 1623 | if (warnifnotcap(px, PR_CAP_RS, file, line, cmd, NULL)) |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1624 | ret_code |= ERR_WARN; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1625 | |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1626 | if (cond_start && |
| 1627 | (strcmp(*cond_start, "if") == 0 || strcmp(*cond_start, "unless") == 0)) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 1628 | if ((cond = build_acl_cond(file, line, px, cond_start, &errmsg)) == NULL) { |
| 1629 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 1630 | file, line, cmd, errmsg); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1631 | ret_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1632 | goto err; |
| 1633 | } |
| 1634 | } |
| 1635 | else if (cond_start && **cond_start) { |
| 1636 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 1637 | file, line, cmd, *cond_start); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1638 | ret_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1639 | goto err; |
| 1640 | } |
| 1641 | |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1642 | ret_code |= warnif_cond_conflicts(cond, |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 1643 | (dir == SMP_OPT_DIR_REQ) ? |
| 1644 | ((px->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR) : |
| 1645 | ((px->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR), |
| 1646 | file, line); |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1647 | |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1648 | preg = calloc(1, sizeof(*preg)); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1649 | if (!preg) { |
| 1650 | Alert("parsing [%s:%d] : '%s' : not enough memory to build regex.\n", file, line, cmd); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1651 | ret_code = ERR_ALERT | ERR_FATAL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1652 | goto err; |
| 1653 | } |
| 1654 | |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1655 | cs = !(flags & REG_ICASE); |
| 1656 | cap = !(flags & REG_NOSUB); |
| 1657 | error = NULL; |
| 1658 | if (!regex_comp(reg, preg, cs, cap, &error)) { |
| 1659 | Alert("parsing [%s:%d] : '%s' : regular expression '%s' : %s\n", file, line, cmd, reg, error); |
| 1660 | free(error); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1661 | ret_code = ERR_ALERT | ERR_FATAL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1662 | goto err; |
| 1663 | } |
| 1664 | |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 1665 | 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] | 1666 | preg, action, repl ? strdup(repl) : NULL, cond); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1667 | if (repl && err) { |
| 1668 | Alert("parsing [%s:%d] : '%s' : invalid character or unterminated sequence in replacement string near '%c'.\n", |
| 1669 | file, line, cmd, *err); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1670 | ret_code |= ERR_ALERT | ERR_FATAL; |
| 1671 | goto err_free; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1672 | } |
| 1673 | |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 1674 | if (dir == SMP_OPT_DIR_REQ && warnif_misplaced_reqxxx(px, file, line, cmd)) |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1675 | ret_code |= ERR_WARN; |
| 1676 | |
| 1677 | return ret_code; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1678 | |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1679 | err_free: |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1680 | regex_free(preg); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1681 | err: |
| 1682 | free(preg); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1683 | free(errmsg); |
| 1684 | return ret_code; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1685 | } |
| 1686 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1687 | /* |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1688 | * Parse a line in a <listen>, <frontend>, <backend> or <ruleset> section. |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1689 | * Returns the error code, 0 if OK, or any combination of : |
| 1690 | * - ERR_ABORT: must abort ASAP |
| 1691 | * - ERR_FATAL: we can continue parsing but not start the service |
| 1692 | * - ERR_WARN: a warning has been emitted |
| 1693 | * - ERR_ALERT: an alert has been emitted |
| 1694 | * Only the two first ones can stop processing, the two others are just |
| 1695 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1696 | */ |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1697 | int cfg_parse_peers(const char *file, int linenum, char **args, int kwm) |
| 1698 | { |
| 1699 | static struct peers *curpeers = NULL; |
| 1700 | struct peer *newpeer = NULL; |
| 1701 | const char *err; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1702 | struct bind_conf *bind_conf; |
| 1703 | struct listener *l; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1704 | int err_code = 0; |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1705 | char *errmsg = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1706 | |
| 1707 | if (strcmp(args[0], "peers") == 0) { /* new peers section */ |
Willy Tarreau | 0dbbf31 | 2013-03-05 11:31:55 +0100 | [diff] [blame] | 1708 | if (!*args[1]) { |
| 1709 | Alert("parsing [%s:%d] : missing name for peers section.\n", file, linenum); |
Willy Tarreau | 5498472 | 2014-02-16 08:20:13 +0100 | [diff] [blame] | 1710 | err_code |= ERR_ALERT | ERR_ABORT; |
Willy Tarreau | 0dbbf31 | 2013-03-05 11:31:55 +0100 | [diff] [blame] | 1711 | goto out; |
| 1712 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1713 | |
| 1714 | err = invalid_char(args[1]); |
| 1715 | if (err) { |
| 1716 | Alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 1717 | file, linenum, *err, args[0], args[1]); |
Willy Tarreau | 5498472 | 2014-02-16 08:20:13 +0100 | [diff] [blame] | 1718 | err_code |= ERR_ALERT | ERR_ABORT; |
Willy Tarreau | 0dbbf31 | 2013-03-05 11:31:55 +0100 | [diff] [blame] | 1719 | goto out; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1720 | } |
| 1721 | |
| 1722 | for (curpeers = peers; curpeers != NULL; curpeers = curpeers->next) { |
| 1723 | /* |
| 1724 | * If there are two proxies with the same name only following |
| 1725 | * combinations are allowed: |
| 1726 | */ |
| 1727 | if (strcmp(curpeers->id, args[1]) == 0) { |
| 1728 | Warning("Parsing [%s:%d]: peers '%s' has same name as another peers (declared at %s:%d).\n", |
| 1729 | file, linenum, args[1], curpeers->conf.file, curpeers->conf.line); |
| 1730 | err_code |= ERR_WARN; |
| 1731 | } |
| 1732 | } |
| 1733 | |
| 1734 | if ((curpeers = (struct peers *)calloc(1, sizeof(struct peers))) == NULL) { |
| 1735 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1736 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1737 | goto out; |
| 1738 | } |
| 1739 | |
| 1740 | curpeers->next = peers; |
| 1741 | peers = curpeers; |
Willy Tarreau | 8113a5d | 2012-10-04 08:01:43 +0200 | [diff] [blame] | 1742 | curpeers->conf.file = strdup(file); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1743 | curpeers->conf.line = linenum; |
| 1744 | curpeers->last_change = now.tv_sec; |
| 1745 | curpeers->id = strdup(args[1]); |
| 1746 | } |
| 1747 | else if (strcmp(args[0], "peer") == 0) { /* peer definition */ |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 1748 | struct sockaddr_storage *sk; |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 1749 | int port1, port2; |
Willy Tarreau | b36487e | 2013-03-10 18:37:42 +0100 | [diff] [blame] | 1750 | struct protocol *proto; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1751 | |
| 1752 | if (!*args[2]) { |
| 1753 | Alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n", |
| 1754 | file, linenum, args[0]); |
| 1755 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1756 | goto out; |
| 1757 | } |
| 1758 | |
| 1759 | err = invalid_char(args[1]); |
| 1760 | if (err) { |
| 1761 | Alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n", |
| 1762 | file, linenum, *err, args[1]); |
| 1763 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1764 | goto out; |
| 1765 | } |
| 1766 | |
| 1767 | if ((newpeer = (struct peer *)calloc(1, sizeof(struct peer))) == NULL) { |
| 1768 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1769 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1770 | goto out; |
| 1771 | } |
| 1772 | |
| 1773 | /* the peers are linked backwards first */ |
| 1774 | curpeers->count++; |
| 1775 | newpeer->next = curpeers->remote; |
| 1776 | curpeers->remote = newpeer; |
| 1777 | newpeer->peers = curpeers; |
Willy Tarreau | 8113a5d | 2012-10-04 08:01:43 +0200 | [diff] [blame] | 1778 | newpeer->conf.file = strdup(file); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1779 | newpeer->conf.line = linenum; |
| 1780 | |
| 1781 | newpeer->last_change = now.tv_sec; |
| 1782 | newpeer->id = strdup(args[1]); |
| 1783 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1784 | sk = str2sa_range(args[2], &port1, &port2, &errmsg, NULL); |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 1785 | if (!sk) { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1786 | 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] | 1787 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1788 | goto out; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1789 | } |
Willy Tarreau | b36487e | 2013-03-10 18:37:42 +0100 | [diff] [blame] | 1790 | |
| 1791 | proto = protocol_by_family(sk->ss_family); |
| 1792 | if (!proto || !proto->connect) { |
| 1793 | Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 1794 | file, linenum, args[0], args[1]); |
| 1795 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1796 | goto out; |
| 1797 | } |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 1798 | |
| 1799 | if (port1 != port2) { |
| 1800 | Alert("parsing [%s:%d] : '%s %s' : port ranges and offsets are not allowed in '%s'\n", |
| 1801 | file, linenum, args[0], args[1], args[2]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1802 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1803 | goto out; |
| 1804 | } |
| 1805 | |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 1806 | if (!port1) { |
| 1807 | Alert("parsing [%s:%d] : '%s %s' : missing or invalid port in '%s'\n", |
| 1808 | file, linenum, args[0], args[1], args[2]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1809 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1810 | goto out; |
| 1811 | } |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 1812 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1813 | newpeer->addr = *sk; |
Willy Tarreau | b36487e | 2013-03-10 18:37:42 +0100 | [diff] [blame] | 1814 | newpeer->proto = proto; |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 1815 | newpeer->xprt = &raw_sock; |
Willy Tarreau | d02394b | 2012-05-11 18:32:18 +0200 | [diff] [blame] | 1816 | newpeer->sock_init_arg = NULL; |
Willy Tarreau | 26d8c59 | 2012-05-07 18:12:14 +0200 | [diff] [blame] | 1817 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1818 | if (strcmp(newpeer->id, localpeer) == 0) { |
| 1819 | /* Current is local peer, it define a frontend */ |
| 1820 | newpeer->local = 1; |
| 1821 | |
| 1822 | if (!curpeers->peers_fe) { |
| 1823 | if ((curpeers->peers_fe = calloc(1, sizeof(struct proxy))) == NULL) { |
| 1824 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1825 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1826 | goto out; |
| 1827 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1828 | |
Willy Tarreau | 237250c | 2011-07-29 01:49:03 +0200 | [diff] [blame] | 1829 | init_new_proxy(curpeers->peers_fe); |
| 1830 | curpeers->peers_fe->parent = curpeers; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1831 | |
| 1832 | curpeers->peers_fe->last_change = now.tv_sec; |
| 1833 | curpeers->peers_fe->id = strdup(args[1]); |
| 1834 | curpeers->peers_fe->cap = PR_CAP_FE; |
Willy Tarreau | 3ae65a1 | 2011-09-07 17:40:39 +0200 | [diff] [blame] | 1835 | curpeers->peers_fe->maxconn = 0; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1836 | curpeers->peers_fe->conn_retries = CONN_RETRIES; |
Willy Tarreau | fc940eb | 2015-03-13 16:18:25 +0100 | [diff] [blame] | 1837 | curpeers->peers_fe->timeout.client = MS_TO_TICKS(5000); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1838 | curpeers->peers_fe->accept = peer_accept; |
| 1839 | curpeers->peers_fe->options2 |= PR_O2_INDEPSTR | PR_O2_SMARTCON | PR_O2_SMARTACC; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 1840 | curpeers->peers_fe->conf.args.file = curpeers->peers_fe->conf.file = strdup(file); |
| 1841 | curpeers->peers_fe->conf.args.line = curpeers->peers_fe->conf.line = linenum; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1842 | |
| 1843 | bind_conf = bind_conf_alloc(&curpeers->peers_fe->conf.bind, file, linenum, args[2]); |
| 1844 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1845 | if (!str2listener(args[2], curpeers->peers_fe, bind_conf, file, linenum, &errmsg)) { |
| 1846 | if (errmsg && *errmsg) { |
| 1847 | indent_msg(&errmsg, 2); |
| 1848 | 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] | 1849 | } |
| 1850 | else |
| 1851 | Alert("parsing [%s:%d] : '%s %s' : error encountered while parsing listening address %s.\n", |
| 1852 | file, linenum, args[0], args[1], args[2]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1853 | err_code |= ERR_FATAL; |
| 1854 | goto out; |
| 1855 | } |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1856 | |
| 1857 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
Willy Tarreau | acf3bf9 | 2013-01-18 10:51:07 +0100 | [diff] [blame] | 1858 | l->maxaccept = 1; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1859 | l->maxconn = ((struct proxy *)curpeers->peers_fe)->maxconn; |
| 1860 | l->backlog = ((struct proxy *)curpeers->peers_fe)->backlog; |
| 1861 | l->timeout = &((struct proxy *)curpeers->peers_fe)->timeout.client; |
| 1862 | l->accept = session_accept; |
| 1863 | l->handler = process_session; |
| 1864 | l->analysers |= ((struct proxy *)curpeers->peers_fe)->fe_req_ana; |
| 1865 | l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */ |
| 1866 | global.maxsock += l->maxconn; |
| 1867 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1868 | } |
Willy Tarreau | 8b8fd56 | 2013-01-18 11:12:27 +0100 | [diff] [blame] | 1869 | else { |
| 1870 | Alert("parsing [%s:%d] : '%s %s' : local peer name already referenced at %s:%d.\n", |
| 1871 | file, linenum, args[0], args[1], |
| 1872 | curpeers->peers_fe->conf.file, curpeers->peers_fe->conf.line); |
| 1873 | err_code |= ERR_FATAL; |
| 1874 | goto out; |
| 1875 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1876 | } |
| 1877 | } /* neither "peer" nor "peers" */ |
| 1878 | else if (*args[0] != 0) { |
| 1879 | Alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection); |
| 1880 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1881 | goto out; |
| 1882 | } |
| 1883 | |
| 1884 | out: |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1885 | free(errmsg); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1886 | return err_code; |
| 1887 | } |
| 1888 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 1889 | 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] | 1890 | { |
| 1891 | static struct proxy *curproxy = NULL; |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 1892 | const char *err; |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1893 | char *error; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 1894 | int rc; |
| 1895 | unsigned val; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1896 | int err_code = 0; |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 1897 | struct acl_cond *cond = NULL; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 1898 | struct logsrv *tmplogsrv; |
Willy Tarreau | f4068b6 | 2012-05-08 17:37:49 +0200 | [diff] [blame] | 1899 | char *errmsg = NULL; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 1900 | struct bind_conf *bind_conf; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1901 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1902 | if (!strcmp(args[0], "listen")) |
| 1903 | rc = PR_CAP_LISTEN; |
| 1904 | else if (!strcmp(args[0], "frontend")) |
| 1905 | rc = PR_CAP_FE | PR_CAP_RS; |
| 1906 | else if (!strcmp(args[0], "backend")) |
| 1907 | rc = PR_CAP_BE | PR_CAP_RS; |
| 1908 | else if (!strcmp(args[0], "ruleset")) |
| 1909 | rc = PR_CAP_RS; |
| 1910 | else |
| 1911 | rc = PR_CAP_NONE; |
| 1912 | |
| 1913 | if (rc != PR_CAP_NONE) { /* new proxy */ |
Willy Tarreau | 7cbc915 | 2014-03-15 08:17:08 +0100 | [diff] [blame] | 1914 | struct ebpt_node *node; |
| 1915 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1916 | if (!*args[1]) { |
| 1917 | Alert("parsing [%s:%d] : '%s' expects an <id> argument and\n" |
| 1918 | " optionnally supports [addr1]:port1[-end1]{,[addr]:port[-end]}...\n", |
| 1919 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1920 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1921 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1922 | } |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 1923 | |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 1924 | err = invalid_char(args[1]); |
| 1925 | if (err) { |
| 1926 | Alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 1927 | file, linenum, *err, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1928 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 1929 | } |
| 1930 | |
Willy Tarreau | 7cbc915 | 2014-03-15 08:17:08 +0100 | [diff] [blame] | 1931 | for (node = ebis_lookup(&proxy_by_name, args[1]); node; node = ebpt_next(node)) { |
| 1932 | curproxy = container_of(node, struct proxy, conf.by_name); |
| 1933 | |
| 1934 | if (strcmp(curproxy->id, args[1]) != 0) |
| 1935 | break; |
| 1936 | |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 1937 | /* |
| 1938 | * If there are two proxies with the same name only following |
| 1939 | * combinations are allowed: |
| 1940 | * |
| 1941 | * listen backend frontend ruleset |
| 1942 | * listen - - - - |
| 1943 | * backend - - OK - |
| 1944 | * frontend - OK - - |
| 1945 | * ruleset - - - - |
| 1946 | */ |
| 1947 | |
Willy Tarreau | 7cbc915 | 2014-03-15 08:17:08 +0100 | [diff] [blame] | 1948 | if ((rc != (PR_CAP_FE|PR_CAP_RS) || curproxy->cap != (PR_CAP_BE|PR_CAP_RS)) && |
| 1949 | (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] | 1950 | Warning("Parsing [%s:%d]: %s '%s' has same name as another %s (declared at %s:%d).\n", |
| 1951 | file, linenum, proxy_cap_str(rc), args[1], proxy_type_str(curproxy), |
| 1952 | curproxy->conf.file, curproxy->conf.line); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1953 | err_code |= ERR_WARN; |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 1954 | } |
| 1955 | } |
| 1956 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1957 | if ((curproxy = (struct proxy *)calloc(1, sizeof(struct proxy))) == NULL) { |
| 1958 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1959 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1960 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1961 | } |
Willy Tarreau | 5af24ef | 2009-03-15 15:23:16 +0100 | [diff] [blame] | 1962 | |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 1963 | init_new_proxy(curproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1964 | curproxy->next = proxy; |
| 1965 | proxy = curproxy; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 1966 | curproxy->conf.args.file = curproxy->conf.file = strdup(file); |
| 1967 | curproxy->conf.args.line = curproxy->conf.line = linenum; |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 1968 | curproxy->last_change = now.tv_sec; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1969 | curproxy->id = strdup(args[1]); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1970 | curproxy->cap = rc; |
Willy Tarreau | f79d950 | 2014-03-15 07:22:35 +0100 | [diff] [blame] | 1971 | proxy_store_name(curproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1972 | |
| 1973 | /* parse the listener address if any */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1974 | if ((curproxy->cap & PR_CAP_FE) && *args[2]) { |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1975 | struct listener *l; |
Willy Tarreau | 81a8117 | 2012-09-18 20:52:35 +0200 | [diff] [blame] | 1976 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1977 | bind_conf = bind_conf_alloc(&curproxy->conf.bind, file, linenum, args[2]); |
| 1978 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1979 | if (!str2listener(args[2], curproxy, bind_conf, file, linenum, &errmsg)) { |
| 1980 | if (errmsg && *errmsg) { |
| 1981 | indent_msg(&errmsg, 2); |
| 1982 | 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] | 1983 | } |
| 1984 | else |
| 1985 | Alert("parsing [%s:%d] : '%s %s' : error encountered while parsing listening address '%s'.\n", |
| 1986 | file, linenum, args[0], args[1], args[2]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1987 | err_code |= ERR_FATAL; |
| 1988 | goto out; |
| 1989 | } |
Willy Tarreau | 81a8117 | 2012-09-18 20:52:35 +0200 | [diff] [blame] | 1990 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1991 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
Willy Tarreau | c8b1109 | 2011-02-16 11:08:57 +0100 | [diff] [blame] | 1992 | global.maxsock++; |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 1993 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1994 | } |
| 1995 | |
| 1996 | /* set default values */ |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1997 | memcpy(&curproxy->defsrv, &defproxy.defsrv, sizeof(curproxy->defsrv)); |
Willy Tarreau | 7016020 | 2010-04-07 16:06:40 +0200 | [diff] [blame] | 1998 | curproxy->defsrv.id = "default-server"; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1999 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2000 | curproxy->state = defproxy.state; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2001 | curproxy->options = defproxy.options; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 2002 | curproxy->options2 = defproxy.options2; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 2003 | curproxy->no_options = defproxy.no_options; |
| 2004 | curproxy->no_options2 = defproxy.no_options2; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2005 | curproxy->bind_proc = defproxy.bind_proc; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 2006 | curproxy->except_net = defproxy.except_net; |
| 2007 | curproxy->except_mask = defproxy.except_mask; |
Maik Broemme | 36db02e | 2009-05-08 17:02:07 +0200 | [diff] [blame] | 2008 | curproxy->except_to = defproxy.except_to; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 2009 | curproxy->except_mask_to = defproxy.except_mask_to; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2010 | |
Willy Tarreau | 79f5fe8 | 2008-08-23 08:18:21 +0200 | [diff] [blame] | 2011 | if (defproxy.fwdfor_hdr_len) { |
| 2012 | curproxy->fwdfor_hdr_len = defproxy.fwdfor_hdr_len; |
| 2013 | curproxy->fwdfor_hdr_name = strdup(defproxy.fwdfor_hdr_name); |
| 2014 | } |
| 2015 | |
Willy Tarreau | b86db34 | 2009-11-30 11:50:16 +0100 | [diff] [blame] | 2016 | if (defproxy.orgto_hdr_len) { |
| 2017 | curproxy->orgto_hdr_len = defproxy.orgto_hdr_len; |
| 2018 | curproxy->orgto_hdr_name = strdup(defproxy.orgto_hdr_name); |
| 2019 | } |
| 2020 | |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 2021 | if (defproxy.server_id_hdr_len) { |
| 2022 | curproxy->server_id_hdr_len = defproxy.server_id_hdr_len; |
| 2023 | curproxy->server_id_hdr_name = strdup(defproxy.server_id_hdr_name); |
| 2024 | } |
| 2025 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2026 | if (curproxy->cap & PR_CAP_FE) { |
| 2027 | curproxy->maxconn = defproxy.maxconn; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 2028 | curproxy->backlog = defproxy.backlog; |
Willy Tarreau | 13a34bd | 2009-05-10 18:52:49 +0200 | [diff] [blame] | 2029 | curproxy->fe_sps_lim = defproxy.fe_sps_lim; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2030 | |
| 2031 | /* initialize error relocations */ |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2032 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) |
| 2033 | chunk_dup(&curproxy->errmsg[rc], &defproxy.errmsg[rc]); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2034 | |
| 2035 | curproxy->to_log = defproxy.to_log & ~LW_COOKIE & ~LW_REQHDR & ~ LW_RSPHDR; |
| 2036 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2037 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2038 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | cac307c | 2014-11-18 15:04:29 +0100 | [diff] [blame] | 2039 | curproxy->lbprm.algo = defproxy.lbprm.algo; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2040 | curproxy->fullconn = defproxy.fullconn; |
| 2041 | curproxy->conn_retries = defproxy.conn_retries; |
Willy Tarreau | c35362a | 2014-04-25 13:58:37 +0200 | [diff] [blame] | 2042 | curproxy->max_ka_queue = defproxy.max_ka_queue; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2043 | |
Willy Tarreau | aa2f389 | 2010-10-22 16:15:31 +0200 | [diff] [blame] | 2044 | if (defproxy.check_req) { |
| 2045 | curproxy->check_req = calloc(1, defproxy.check_len); |
| 2046 | memcpy(curproxy->check_req, defproxy.check_req, defproxy.check_len); |
| 2047 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2048 | curproxy->check_len = defproxy.check_len; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2049 | |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 2050 | if (defproxy.expect_str) { |
| 2051 | curproxy->expect_str = strdup(defproxy.expect_str); |
| 2052 | if (defproxy.expect_regex) { |
| 2053 | /* note: this regex is known to be valid */ |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 2054 | curproxy->expect_regex = calloc(1, sizeof(*curproxy->expect_regex)); |
| 2055 | regex_comp(defproxy.expect_str, curproxy->expect_regex, 1, 1, NULL); |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 2056 | } |
| 2057 | } |
| 2058 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2059 | curproxy->ck_opts = defproxy.ck_opts; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2060 | if (defproxy.cookie_name) |
| 2061 | curproxy->cookie_name = strdup(defproxy.cookie_name); |
| 2062 | curproxy->cookie_len = defproxy.cookie_len; |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 2063 | if (defproxy.cookie_domain) |
| 2064 | curproxy->cookie_domain = strdup(defproxy.cookie_domain); |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 2065 | |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 2066 | if (defproxy.cookie_maxidle) |
| 2067 | curproxy->cookie_maxidle = defproxy.cookie_maxidle; |
| 2068 | |
| 2069 | if (defproxy.cookie_maxlife) |
| 2070 | curproxy->cookie_maxlife = defproxy.cookie_maxlife; |
| 2071 | |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2072 | if (defproxy.rdp_cookie_name) |
| 2073 | curproxy->rdp_cookie_name = strdup(defproxy.rdp_cookie_name); |
| 2074 | curproxy->rdp_cookie_len = defproxy.rdp_cookie_len; |
| 2075 | |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 2076 | if (defproxy.url_param_name) |
| 2077 | curproxy->url_param_name = strdup(defproxy.url_param_name); |
| 2078 | curproxy->url_param_len = defproxy.url_param_len; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 2079 | |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 2080 | if (defproxy.hh_name) |
| 2081 | curproxy->hh_name = strdup(defproxy.hh_name); |
| 2082 | curproxy->hh_len = defproxy.hh_len; |
| 2083 | curproxy->hh_match_domain = defproxy.hh_match_domain; |
| 2084 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 2085 | if (defproxy.conn_src.iface_name) |
| 2086 | curproxy->conn_src.iface_name = strdup(defproxy.conn_src.iface_name); |
| 2087 | curproxy->conn_src.iface_len = defproxy.conn_src.iface_len; |
Godbach | 9f04853 | 2013-04-23 15:27:57 +0800 | [diff] [blame] | 2088 | curproxy->conn_src.opts = defproxy.conn_src.opts; |
Pieter Baauw | d551fb5 | 2013-05-08 22:49:23 +0200 | [diff] [blame] | 2089 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_TRANSPARENT) |
Godbach | 9f04853 | 2013-04-23 15:27:57 +0800 | [diff] [blame] | 2090 | curproxy->conn_src.tproxy_addr = defproxy.conn_src.tproxy_addr; |
Willy Tarreau | c621d36 | 2013-04-25 17:35:22 +0200 | [diff] [blame] | 2091 | #endif |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2092 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2093 | |
Willy Tarreau | 3b6b1a9 | 2009-07-23 13:24:23 +0200 | [diff] [blame] | 2094 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2095 | if (defproxy.capture_name) |
| 2096 | curproxy->capture_name = strdup(defproxy.capture_name); |
| 2097 | curproxy->capture_namelen = defproxy.capture_namelen; |
| 2098 | curproxy->capture_len = defproxy.capture_len; |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 2099 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2100 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2101 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 2102 | curproxy->timeout.client = defproxy.timeout.client; |
Simone Gotti | 1b48cc9 | 2014-06-11 12:25:28 +0200 | [diff] [blame] | 2103 | curproxy->timeout.clientfin = defproxy.timeout.clientfin; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 2104 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | 036fae0 | 2008-01-06 13:24:40 +0100 | [diff] [blame] | 2105 | curproxy->timeout.httpreq = defproxy.timeout.httpreq; |
Willy Tarreau | b16a574 | 2010-01-10 14:46:16 +0100 | [diff] [blame] | 2106 | curproxy->timeout.httpka = defproxy.timeout.httpka; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2107 | curproxy->mon_net = defproxy.mon_net; |
| 2108 | curproxy->mon_mask = defproxy.mon_mask; |
| 2109 | if (defproxy.monitor_uri) |
| 2110 | curproxy->monitor_uri = strdup(defproxy.monitor_uri); |
| 2111 | curproxy->monitor_uri_len = defproxy.monitor_uri_len; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 2112 | if (defproxy.defbe.name) |
| 2113 | curproxy->defbe.name = strdup(defproxy.defbe.name); |
Willy Tarreau | 99a7ca2 | 2012-05-31 19:39:23 +0200 | [diff] [blame] | 2114 | |
| 2115 | /* get either a pointer to the logformat string or a copy of it */ |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 2116 | curproxy->conf.logformat_string = defproxy.conf.logformat_string; |
| 2117 | if (curproxy->conf.logformat_string && |
| 2118 | curproxy->conf.logformat_string != default_http_log_format && |
| 2119 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 2120 | curproxy->conf.logformat_string != clf_http_log_format) |
| 2121 | curproxy->conf.logformat_string = strdup(curproxy->conf.logformat_string); |
| 2122 | |
| 2123 | if (defproxy.conf.lfs_file) { |
| 2124 | curproxy->conf.lfs_file = strdup(defproxy.conf.lfs_file); |
| 2125 | curproxy->conf.lfs_line = defproxy.conf.lfs_line; |
| 2126 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2127 | } |
| 2128 | |
| 2129 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 2130 | curproxy->timeout.connect = defproxy.timeout.connect; |
| 2131 | curproxy->timeout.server = defproxy.timeout.server; |
Simone Gotti | 1b48cc9 | 2014-06-11 12:25:28 +0200 | [diff] [blame] | 2132 | curproxy->timeout.serverfin = defproxy.timeout.serverfin; |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 2133 | curproxy->timeout.check = defproxy.timeout.check; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 2134 | curproxy->timeout.queue = defproxy.timeout.queue; |
Willy Tarreau | 51c9bde | 2008-01-06 13:40:03 +0100 | [diff] [blame] | 2135 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | cd7afc0 | 2009-07-12 10:03:17 +0200 | [diff] [blame] | 2136 | curproxy->timeout.httpreq = defproxy.timeout.httpreq; |
Willy Tarreau | b16a574 | 2010-01-10 14:46:16 +0100 | [diff] [blame] | 2137 | curproxy->timeout.httpka = defproxy.timeout.httpka; |
Willy Tarreau | ce887fd | 2012-05-12 12:50:00 +0200 | [diff] [blame] | 2138 | curproxy->timeout.tunnel = defproxy.timeout.tunnel; |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 2139 | curproxy->conn_src.source_addr = defproxy.conn_src.source_addr; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2140 | } |
| 2141 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2142 | curproxy->mode = defproxy.mode; |
Willy Tarreau | ed2119c | 2014-04-24 22:10:39 +0200 | [diff] [blame] | 2143 | curproxy->uri_auth = defproxy.uri_auth; /* for stats */ |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 2144 | |
| 2145 | /* copy default logsrvs to curproxy */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 2146 | list_for_each_entry(tmplogsrv, &defproxy.logsrvs, list) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 2147 | struct logsrv *node = malloc(sizeof(struct logsrv)); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 2148 | memcpy(node, tmplogsrv, sizeof(struct logsrv)); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 2149 | LIST_INIT(&node->list); |
| 2150 | LIST_ADDQ(&curproxy->logsrvs, &node->list); |
| 2151 | } |
| 2152 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 2153 | curproxy->conf.uniqueid_format_string = defproxy.conf.uniqueid_format_string; |
| 2154 | if (curproxy->conf.uniqueid_format_string) |
| 2155 | curproxy->conf.uniqueid_format_string = strdup(curproxy->conf.uniqueid_format_string); |
| 2156 | |
| 2157 | if (defproxy.conf.uif_file) { |
| 2158 | curproxy->conf.uif_file = strdup(defproxy.conf.uif_file); |
| 2159 | curproxy->conf.uif_line = defproxy.conf.uif_line; |
| 2160 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 2161 | |
| 2162 | /* copy default header unique id */ |
| 2163 | if (defproxy.header_unique_id) |
| 2164 | curproxy->header_unique_id = strdup(defproxy.header_unique_id); |
| 2165 | |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 2166 | /* default compression options */ |
| 2167 | if (defproxy.comp != NULL) { |
| 2168 | curproxy->comp = calloc(1, sizeof(struct comp)); |
| 2169 | curproxy->comp->algos = defproxy.comp->algos; |
| 2170 | curproxy->comp->types = defproxy.comp->types; |
| 2171 | } |
| 2172 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2173 | curproxy->grace = defproxy.grace; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2174 | curproxy->conf.used_listener_id = EB_ROOT; |
| 2175 | curproxy->conf.used_server_id = EB_ROOT; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2176 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2177 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2178 | } |
| 2179 | else if (!strcmp(args[0], "defaults")) { /* use this one to assign default values */ |
| 2180 | /* some variables may have already been initialized earlier */ |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 2181 | /* FIXME-20070101: we should do this too at the end of the |
| 2182 | * config parsing to free all default values. |
| 2183 | */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2184 | free(defproxy.check_req); |
| 2185 | free(defproxy.cookie_name); |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2186 | free(defproxy.rdp_cookie_name); |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 2187 | free(defproxy.cookie_domain); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2188 | free(defproxy.url_param_name); |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 2189 | free(defproxy.hh_name); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2190 | free(defproxy.capture_name); |
| 2191 | free(defproxy.monitor_uri); |
| 2192 | free(defproxy.defbe.name); |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 2193 | free(defproxy.conn_src.iface_name); |
Willy Tarreau | 79f5fe8 | 2008-08-23 08:18:21 +0200 | [diff] [blame] | 2194 | free(defproxy.fwdfor_hdr_name); |
| 2195 | defproxy.fwdfor_hdr_len = 0; |
Willy Tarreau | b86db34 | 2009-11-30 11:50:16 +0100 | [diff] [blame] | 2196 | free(defproxy.orgto_hdr_name); |
| 2197 | defproxy.orgto_hdr_len = 0; |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 2198 | free(defproxy.server_id_hdr_name); |
| 2199 | defproxy.server_id_hdr_len = 0; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 2200 | free(defproxy.expect_str); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 2201 | if (defproxy.expect_regex) { |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 2202 | regex_free(defproxy.expect_regex); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 2203 | free(defproxy.expect_regex); |
| 2204 | defproxy.expect_regex = NULL; |
| 2205 | } |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 2206 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 2207 | if (defproxy.conf.logformat_string != default_http_log_format && |
| 2208 | defproxy.conf.logformat_string != default_tcp_log_format && |
| 2209 | defproxy.conf.logformat_string != clf_http_log_format) |
| 2210 | free(defproxy.conf.logformat_string); |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 2211 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 2212 | free(defproxy.conf.uniqueid_format_string); |
| 2213 | free(defproxy.conf.lfs_file); |
| 2214 | free(defproxy.conf.uif_file); |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 2215 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2216 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2217 | chunk_destroy(&defproxy.errmsg[rc]); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 2218 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2219 | /* we cannot free uri_auth because it might already be used */ |
| 2220 | init_default_instance(); |
| 2221 | curproxy = &defproxy; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 2222 | curproxy->conf.args.file = curproxy->conf.file = strdup(file); |
| 2223 | curproxy->conf.args.line = curproxy->conf.line = linenum; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2224 | defproxy.cap = PR_CAP_LISTEN; /* all caps for now */ |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2225 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2226 | } |
| 2227 | else if (curproxy == NULL) { |
| 2228 | Alert("parsing [%s:%d] : 'listen' or 'defaults' expected.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2229 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2230 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2231 | } |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 2232 | |
| 2233 | /* update the current file and line being parsed */ |
| 2234 | curproxy->conf.args.file = curproxy->conf.file; |
| 2235 | curproxy->conf.args.line = linenum; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2236 | |
| 2237 | /* Now let's parse the proxy-specific keywords */ |
Willy Tarreau | 272adea | 2014-03-31 10:39:59 +0200 | [diff] [blame] | 2238 | if (!strcmp(args[0], "server") || !strcmp(args[0], "default-server")) { |
| 2239 | err_code |= parse_server(file, linenum, args, curproxy, &defproxy); |
| 2240 | if (err_code & ERR_FATAL) |
| 2241 | goto out; |
| 2242 | } |
| 2243 | else if (!strcmp(args[0], "bind")) { /* new listen addresses */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2244 | struct listener *l; |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 2245 | int cur_arg; |
| 2246 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2247 | if (curproxy == &defproxy) { |
| 2248 | 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] | 2249 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2250 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2251 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2252 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2253 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2254 | |
Willy Tarreau | 2470928 | 2013-03-10 21:32:12 +0100 | [diff] [blame] | 2255 | if (!*(args[1])) { |
Willy Tarreau | d55c3fe | 2010-11-09 09:50:37 +0100 | [diff] [blame] | 2256 | 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] | 2257 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2258 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2259 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2260 | } |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 2261 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 2262 | bind_conf = bind_conf_alloc(&curproxy->conf.bind, file, linenum, args[1]); |
Willy Tarreau | 8dc21fa | 2013-01-24 15:17:20 +0100 | [diff] [blame] | 2263 | |
| 2264 | /* use default settings for unix sockets */ |
| 2265 | bind_conf->ux.uid = global.unix_bind.ux.uid; |
| 2266 | bind_conf->ux.gid = global.unix_bind.ux.gid; |
| 2267 | bind_conf->ux.mode = global.unix_bind.ux.mode; |
Willy Tarreau | 8a95691 | 2010-10-15 14:27:08 +0200 | [diff] [blame] | 2268 | |
| 2269 | /* NOTE: the following line might create several listeners if there |
| 2270 | * are comma-separated IPs or port ranges. So all further processing |
| 2271 | * will have to be applied to all listeners created after last_listen. |
| 2272 | */ |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 2273 | if (!str2listener(args[1], curproxy, bind_conf, file, linenum, &errmsg)) { |
| 2274 | if (errmsg && *errmsg) { |
| 2275 | indent_msg(&errmsg, 2); |
| 2276 | Alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 2277 | } |
| 2278 | else |
| 2279 | Alert("parsing [%s:%d] : '%s' : error encountered while parsing listening address '%s'.\n", |
| 2280 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2281 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2282 | goto out; |
| 2283 | } |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 2284 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2285 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
| 2286 | /* Set default global rights and owner for unix bind */ |
Willy Tarreau | c8b1109 | 2011-02-16 11:08:57 +0100 | [diff] [blame] | 2287 | global.maxsock++; |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 2288 | } |
| 2289 | |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 2290 | cur_arg = 2; |
| 2291 | while (*(args[cur_arg])) { |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 2292 | static int bind_dumped; |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 2293 | struct bind_kw *kw; |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 2294 | char *err; |
| 2295 | |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 2296 | kw = bind_find_kw(args[cur_arg]); |
| 2297 | if (kw) { |
| 2298 | char *err = NULL; |
| 2299 | int code; |
| 2300 | |
| 2301 | if (!kw->parse) { |
Willy Tarreau | dda322d | 2012-09-18 16:34:09 +0200 | [diff] [blame] | 2302 | Alert("parsing [%s:%d] : '%s %s' : '%s' option is not implemented in this version (check build options).\n", |
| 2303 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 2304 | cur_arg += 1 + kw->skip ; |
| 2305 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2306 | goto out; |
| 2307 | } |
| 2308 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2309 | code = kw->parse(args, cur_arg, curproxy, bind_conf, &err); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 2310 | err_code |= code; |
| 2311 | |
| 2312 | if (code) { |
| 2313 | if (err && *err) { |
| 2314 | indent_msg(&err, 2); |
Willy Tarreau | dda322d | 2012-09-18 16:34:09 +0200 | [diff] [blame] | 2315 | 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] | 2316 | } |
| 2317 | else |
Willy Tarreau | dda322d | 2012-09-18 16:34:09 +0200 | [diff] [blame] | 2318 | Alert("parsing [%s:%d] : '%s %s' : error encountered while processing '%s'.\n", |
| 2319 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 2320 | if (code & ERR_FATAL) { |
| 2321 | free(err); |
| 2322 | cur_arg += 1 + kw->skip; |
| 2323 | goto out; |
| 2324 | } |
| 2325 | } |
| 2326 | free(err); |
| 2327 | cur_arg += 1 + kw->skip; |
| 2328 | continue; |
| 2329 | } |
| 2330 | |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 2331 | err = NULL; |
| 2332 | if (!bind_dumped) { |
| 2333 | bind_dump_kws(&err); |
| 2334 | indent_msg(&err, 4); |
| 2335 | bind_dumped = 1; |
| 2336 | } |
| 2337 | |
| 2338 | Alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'.%s%s\n", |
| 2339 | file, linenum, args[0], args[1], args[cur_arg], |
| 2340 | err ? " Registered keywords :" : "", err ? err : ""); |
| 2341 | free(err); |
| 2342 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2343 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2344 | goto out; |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 2345 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2346 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2347 | } |
| 2348 | else if (!strcmp(args[0], "monitor-net")) { /* set the range of IPs to ignore */ |
Thierry FOURNIER | fc7ac7b | 2014-02-11 15:23:04 +0100 | [diff] [blame] | 2349 | if (!*args[1] || !str2net(args[1], 1, &curproxy->mon_net, &curproxy->mon_mask)) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2350 | Alert("parsing [%s:%d] : '%s' expects address[/mask].\n", |
| 2351 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2352 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2353 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2354 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2355 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2356 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2357 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2358 | /* flush useless bits */ |
| 2359 | curproxy->mon_net.s_addr &= curproxy->mon_mask.s_addr; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2360 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2361 | } |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2362 | else if (!strcmp(args[0], "monitor-uri")) { /* set the URI to intercept */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2363 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2364 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2365 | |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2366 | if (!*args[1]) { |
| 2367 | Alert("parsing [%s:%d] : '%s' expects an URI.\n", |
| 2368 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2369 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2370 | goto out; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2371 | } |
| 2372 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2373 | free(curproxy->monitor_uri); |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 2374 | curproxy->monitor_uri_len = strlen(args[1]); |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2375 | curproxy->monitor_uri = (char *)calloc(1, curproxy->monitor_uri_len + 1); |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 2376 | memcpy(curproxy->monitor_uri, args[1], curproxy->monitor_uri_len); |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2377 | curproxy->monitor_uri[curproxy->monitor_uri_len] = '\0'; |
| 2378 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2379 | goto out; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2380 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2381 | else if (!strcmp(args[0], "mode")) { /* sets the proxy mode */ |
| 2382 | if (!strcmp(args[1], "http")) curproxy->mode = PR_MODE_HTTP; |
| 2383 | else if (!strcmp(args[1], "tcp")) curproxy->mode = PR_MODE_TCP; |
| 2384 | else if (!strcmp(args[1], "health")) curproxy->mode = PR_MODE_HEALTH; |
| 2385 | else { |
| 2386 | 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] | 2387 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2388 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2389 | } |
| 2390 | } |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2391 | else if (!strcmp(args[0], "id")) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2392 | struct eb32_node *node; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2393 | |
| 2394 | if (curproxy == &defproxy) { |
| 2395 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", |
| 2396 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2397 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2398 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2399 | } |
| 2400 | |
| 2401 | if (!*args[1]) { |
| 2402 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 2403 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2404 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2405 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2406 | } |
| 2407 | |
| 2408 | curproxy->uuid = atol(args[1]); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2409 | curproxy->conf.id.key = curproxy->uuid; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2410 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2411 | if (curproxy->uuid <= 0) { |
| 2412 | Alert("parsing [%s:%d]: custom id has to be > 0.\n", |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2413 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2414 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2415 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2416 | } |
| 2417 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2418 | node = eb32_lookup(&used_proxy_id, curproxy->uuid); |
| 2419 | if (node) { |
| 2420 | struct proxy *target = container_of(node, struct proxy, conf.id); |
| 2421 | Alert("parsing [%s:%d]: %s %s reuses same custom id as %s %s (declared at %s:%d).\n", |
| 2422 | file, linenum, proxy_type_str(curproxy), curproxy->id, |
| 2423 | proxy_type_str(target), target->id, target->conf.file, target->conf.line); |
| 2424 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2425 | goto out; |
| 2426 | } |
| 2427 | eb32_insert(&used_proxy_id, &curproxy->conf.id); |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2428 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 2429 | else if (!strcmp(args[0], "description")) { |
| 2430 | int i, len=0; |
| 2431 | char *d; |
| 2432 | |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 2433 | if (curproxy == &defproxy) { |
| 2434 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", |
| 2435 | file, linenum, args[0]); |
| 2436 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2437 | goto out; |
| 2438 | } |
| 2439 | |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 2440 | if (!*args[1]) { |
| 2441 | Alert("parsing [%s:%d]: '%s' expects a string argument.\n", |
| 2442 | file, linenum, args[0]); |
| 2443 | return -1; |
| 2444 | } |
| 2445 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 2446 | for (i = 1; *args[i]; i++) |
| 2447 | len += strlen(args[i]) + 1; |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 2448 | |
| 2449 | d = (char *)calloc(1, len); |
| 2450 | curproxy->desc = d; |
| 2451 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 2452 | d += snprintf(d, curproxy->desc + len - d, "%s", args[1]); |
| 2453 | for (i = 2; *args[i]; i++) |
| 2454 | d += snprintf(d, curproxy->desc + len - d, " %s", args[i]); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 2455 | |
| 2456 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2457 | else if (!strcmp(args[0], "disabled")) { /* disables this proxy */ |
| 2458 | curproxy->state = PR_STSTOPPED; |
| 2459 | } |
| 2460 | else if (!strcmp(args[0], "enabled")) { /* enables this proxy (used to revert a disabled default) */ |
| 2461 | curproxy->state = PR_STNEW; |
| 2462 | } |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2463 | else if (!strcmp(args[0], "bind-process")) { /* enable this proxy only on some processes */ |
| 2464 | int cur_arg = 1; |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 2465 | unsigned long set = 0; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2466 | |
| 2467 | while (*args[cur_arg]) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 2468 | unsigned int low, high; |
| 2469 | |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2470 | if (strcmp(args[cur_arg], "all") == 0) { |
| 2471 | set = 0; |
| 2472 | break; |
| 2473 | } |
| 2474 | else if (strcmp(args[cur_arg], "odd") == 0) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 2475 | set |= ~0UL/3UL; /* 0x555....555 */ |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2476 | } |
| 2477 | else if (strcmp(args[cur_arg], "even") == 0) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 2478 | set |= (~0UL/3UL) << 1; /* 0xAAA...AAA */ |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2479 | } |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 2480 | else if (isdigit((int)*args[cur_arg])) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 2481 | char *dash = strchr(args[cur_arg], '-'); |
| 2482 | |
| 2483 | low = high = str2uic(args[cur_arg]); |
| 2484 | if (dash) |
| 2485 | high = str2uic(dash + 1); |
| 2486 | |
| 2487 | if (high < low) { |
| 2488 | unsigned int swap = low; |
| 2489 | low = high; |
| 2490 | high = swap; |
| 2491 | } |
| 2492 | |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 2493 | if (low < 1 || high > LONGBITS) { |
| 2494 | Alert("parsing [%s:%d]: %s supports process numbers from 1 to %d.\n", |
| 2495 | file, linenum, args[0], LONGBITS); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2496 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2497 | goto out; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2498 | } |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 2499 | while (low <= high) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 2500 | set |= 1UL << (low++ - 1); |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 2501 | } |
| 2502 | else { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 2503 | Alert("parsing [%s:%d]: %s expects 'all', 'odd', 'even', or a list of process ranges with numbers from 1 to %d.\n", |
| 2504 | file, linenum, args[0], LONGBITS); |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 2505 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2506 | goto out; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2507 | } |
| 2508 | cur_arg++; |
| 2509 | } |
| 2510 | curproxy->bind_proc = set; |
| 2511 | } |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 2512 | else if (!strcmp(args[0], "acl")) { /* add an ACL */ |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2513 | if (curproxy == &defproxy) { |
| 2514 | 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] | 2515 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2516 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2517 | } |
| 2518 | |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 2519 | err = invalid_char(args[1]); |
| 2520 | if (err) { |
| 2521 | Alert("parsing [%s:%d] : character '%c' is not permitted in acl name '%s'.\n", |
| 2522 | file, linenum, *err, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2523 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 2524 | } |
| 2525 | |
Thierry FOURNIER | 0d6ba51 | 2014-02-11 03:31:34 +0100 | [diff] [blame] | 2526 | if (parse_acl((const char **)args + 1, &curproxy->acl, &errmsg, &curproxy->conf.args, file, linenum) == NULL) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 2527 | Alert("parsing [%s:%d] : error detected while parsing ACL '%s' : %s.\n", |
| 2528 | file, linenum, args[1], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2529 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2530 | goto out; |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 2531 | } |
| 2532 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2533 | else if (!strcmp(args[0], "cookie")) { /* cookie name */ |
| 2534 | int cur_arg; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2535 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2536 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2537 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2538 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2539 | if (*(args[1]) == 0) { |
| 2540 | Alert("parsing [%s:%d] : '%s' expects <cookie_name> as argument.\n", |
| 2541 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2542 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2543 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2544 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2545 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2546 | curproxy->ck_opts = 0; |
Willy Tarreau | c63d4bb | 2010-10-23 11:37:27 +0200 | [diff] [blame] | 2547 | curproxy->cookie_maxidle = curproxy->cookie_maxlife = 0; |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 2548 | free(curproxy->cookie_domain); curproxy->cookie_domain = NULL; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2549 | free(curproxy->cookie_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2550 | curproxy->cookie_name = strdup(args[1]); |
| 2551 | curproxy->cookie_len = strlen(curproxy->cookie_name); |
Willy Tarreau | c63d4bb | 2010-10-23 11:37:27 +0200 | [diff] [blame] | 2552 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2553 | cur_arg = 2; |
| 2554 | while (*(args[cur_arg])) { |
| 2555 | if (!strcmp(args[cur_arg], "rewrite")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2556 | curproxy->ck_opts |= PR_CK_RW; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2557 | } |
| 2558 | else if (!strcmp(args[cur_arg], "indirect")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2559 | curproxy->ck_opts |= PR_CK_IND; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2560 | } |
| 2561 | else if (!strcmp(args[cur_arg], "insert")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2562 | curproxy->ck_opts |= PR_CK_INS; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2563 | } |
| 2564 | else if (!strcmp(args[cur_arg], "nocache")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2565 | curproxy->ck_opts |= PR_CK_NOC; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2566 | } |
| 2567 | else if (!strcmp(args[cur_arg], "postonly")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2568 | curproxy->ck_opts |= PR_CK_POST; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2569 | } |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 2570 | else if (!strcmp(args[cur_arg], "preserve")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2571 | curproxy->ck_opts |= PR_CK_PSV; |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 2572 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2573 | else if (!strcmp(args[cur_arg], "prefix")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2574 | curproxy->ck_opts |= PR_CK_PFX; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2575 | } |
Willy Tarreau | 4992dd2 | 2012-05-31 21:02:17 +0200 | [diff] [blame] | 2576 | else if (!strcmp(args[cur_arg], "httponly")) { |
| 2577 | curproxy->ck_opts |= PR_CK_HTTPONLY; |
| 2578 | } |
| 2579 | else if (!strcmp(args[cur_arg], "secure")) { |
| 2580 | curproxy->ck_opts |= PR_CK_SECURE; |
| 2581 | } |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2582 | else if (!strcmp(args[cur_arg], "domain")) { |
| 2583 | if (!*args[cur_arg + 1]) { |
| 2584 | Alert("parsing [%s:%d]: '%s' expects <domain> as argument.\n", |
| 2585 | file, linenum, args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2586 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2587 | goto out; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2588 | } |
| 2589 | |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 2590 | if (*args[cur_arg + 1] != '.' || !strchr(args[cur_arg + 1] + 1, '.')) { |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2591 | /* rfc2109, 4.3.2 Rejecting Cookies */ |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 2592 | Warning("parsing [%s:%d]: domain '%s' contains no embedded" |
| 2593 | " dots nor does not start with a dot." |
| 2594 | " RFC forbids it, this configuration may not work properly.\n", |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2595 | file, linenum, args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 2596 | err_code |= ERR_WARN; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2597 | } |
| 2598 | |
| 2599 | err = invalid_domainchar(args[cur_arg + 1]); |
| 2600 | if (err) { |
| 2601 | Alert("parsing [%s:%d]: character '%c' is not permitted in domain name '%s'.\n", |
| 2602 | file, linenum, *err, args[cur_arg + 1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2603 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2604 | goto out; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2605 | } |
| 2606 | |
Willy Tarreau | 68a897b | 2009-12-03 23:28:34 +0100 | [diff] [blame] | 2607 | if (!curproxy->cookie_domain) { |
| 2608 | curproxy->cookie_domain = strdup(args[cur_arg + 1]); |
| 2609 | } else { |
| 2610 | /* one domain was already specified, add another one by |
| 2611 | * building the string which will be returned along with |
| 2612 | * the cookie. |
| 2613 | */ |
| 2614 | char *new_ptr; |
| 2615 | int new_len = strlen(curproxy->cookie_domain) + |
| 2616 | strlen("; domain=") + strlen(args[cur_arg + 1]) + 1; |
| 2617 | new_ptr = malloc(new_len); |
| 2618 | snprintf(new_ptr, new_len, "%s; domain=%s", curproxy->cookie_domain, args[cur_arg+1]); |
| 2619 | free(curproxy->cookie_domain); |
| 2620 | curproxy->cookie_domain = new_ptr; |
| 2621 | } |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 2622 | cur_arg++; |
| 2623 | } |
| 2624 | else if (!strcmp(args[cur_arg], "maxidle")) { |
| 2625 | unsigned int maxidle; |
| 2626 | const char *res; |
| 2627 | |
| 2628 | if (!*args[cur_arg + 1]) { |
| 2629 | Alert("parsing [%s:%d]: '%s' expects <idletime> in seconds as argument.\n", |
| 2630 | file, linenum, args[cur_arg]); |
| 2631 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2632 | goto out; |
| 2633 | } |
| 2634 | |
| 2635 | res = parse_time_err(args[cur_arg + 1], &maxidle, TIME_UNIT_S); |
| 2636 | if (res) { |
| 2637 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 2638 | file, linenum, *res, args[cur_arg]); |
| 2639 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2640 | goto out; |
| 2641 | } |
| 2642 | curproxy->cookie_maxidle = maxidle; |
| 2643 | cur_arg++; |
| 2644 | } |
| 2645 | else if (!strcmp(args[cur_arg], "maxlife")) { |
| 2646 | unsigned int maxlife; |
| 2647 | const char *res; |
| 2648 | |
| 2649 | if (!*args[cur_arg + 1]) { |
| 2650 | Alert("parsing [%s:%d]: '%s' expects <lifetime> in seconds as argument.\n", |
| 2651 | file, linenum, args[cur_arg]); |
| 2652 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2653 | goto out; |
| 2654 | } |
| 2655 | |
| 2656 | res = parse_time_err(args[cur_arg + 1], &maxlife, TIME_UNIT_S); |
| 2657 | if (res) { |
| 2658 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 2659 | file, linenum, *res, args[cur_arg]); |
| 2660 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2661 | goto out; |
| 2662 | } |
| 2663 | curproxy->cookie_maxlife = maxlife; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2664 | cur_arg++; |
| 2665 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2666 | else { |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 2667 | 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] | 2668 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2669 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2670 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2671 | } |
| 2672 | cur_arg++; |
| 2673 | } |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2674 | if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_IND))) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2675 | Alert("parsing [%s:%d] : cookie 'rewrite' and 'indirect' modes are incompatible.\n", |
| 2676 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2677 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2678 | } |
| 2679 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2680 | 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] | 2681 | Alert("parsing [%s:%d] : cookie 'rewrite', 'insert' and 'prefix' modes are incompatible.\n", |
| 2682 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2683 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2684 | } |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 2685 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2686 | 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] | 2687 | Alert("parsing [%s:%d] : cookie 'preserve' requires at least 'insert' or 'indirect'.\n", |
| 2688 | file, linenum); |
| 2689 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2690 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2691 | }/* end else if (!strcmp(args[0], "cookie")) */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2692 | else if (!strcmp(args[0], "persist")) { /* persist */ |
| 2693 | if (*(args[1]) == 0) { |
| 2694 | Alert("parsing [%s:%d] : missing persist method.\n", |
| 2695 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2696 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2697 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2698 | } |
| 2699 | |
| 2700 | if (!strncmp(args[1], "rdp-cookie", 10)) { |
| 2701 | curproxy->options2 |= PR_O2_RDPC_PRST; |
| 2702 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2703 | if (*(args[1] + 10) == '(') { /* cookie name */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2704 | const char *beg, *end; |
| 2705 | |
| 2706 | beg = args[1] + 11; |
| 2707 | end = strchr(beg, ')'); |
| 2708 | |
| 2709 | if (!end || end == beg) { |
| 2710 | Alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n", |
| 2711 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2712 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2713 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2714 | } |
| 2715 | |
| 2716 | free(curproxy->rdp_cookie_name); |
| 2717 | curproxy->rdp_cookie_name = my_strndup(beg, end - beg); |
| 2718 | curproxy->rdp_cookie_len = end-beg; |
| 2719 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2720 | else if (*(args[1] + 10) == '\0') { /* default cookie name 'msts' */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2721 | free(curproxy->rdp_cookie_name); |
| 2722 | curproxy->rdp_cookie_name = strdup("msts"); |
| 2723 | curproxy->rdp_cookie_len = strlen(curproxy->rdp_cookie_name); |
| 2724 | } |
| 2725 | else { /* syntax */ |
| 2726 | Alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n", |
| 2727 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2728 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2729 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2730 | } |
| 2731 | } |
| 2732 | else { |
| 2733 | Alert("parsing [%s:%d] : unknown persist method.\n", |
| 2734 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2735 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2736 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2737 | } |
| 2738 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2739 | else if (!strcmp(args[0], "appsession")) { /* cookie name */ |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2740 | int cur_arg; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2741 | |
Cyril Bonté | 3b7a369 | 2010-01-10 17:01:47 +0100 | [diff] [blame] | 2742 | if (curproxy == &defproxy) { |
| 2743 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2744 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2745 | goto out; |
| 2746 | } |
| 2747 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2748 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2749 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2750 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2751 | if (*(args[5]) == 0) { |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2752 | 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] | 2753 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2754 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2755 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2756 | } |
| 2757 | have_appsession = 1; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2758 | free(curproxy->appsession_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2759 | curproxy->appsession_name = strdup(args[1]); |
| 2760 | curproxy->appsession_name_len = strlen(curproxy->appsession_name); |
| 2761 | curproxy->appsession_len = atoi(args[3]); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 2762 | err = parse_time_err(args[5], &val, TIME_UNIT_MS); |
| 2763 | if (err) { |
| 2764 | Alert("parsing [%s:%d] : unexpected character '%c' in %s timeout.\n", |
| 2765 | file, linenum, *err, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2766 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2767 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 2768 | } |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 2769 | curproxy->timeout.appsession = val; |
Willy Tarreau | ee99136 | 2007-05-14 14:37:50 +0200 | [diff] [blame] | 2770 | |
Willy Tarreau | 51041c7 | 2007-09-09 21:56:53 +0200 | [diff] [blame] | 2771 | if (appsession_hash_init(&(curproxy->htbl_proxy), destroy) == 0) { |
| 2772 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2773 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2774 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2775 | } |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2776 | |
| 2777 | cur_arg = 6; |
| 2778 | curproxy->options2 &= ~PR_O2_AS_REQL; |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2779 | curproxy->options2 &= ~PR_O2_AS_M_ANY; |
| 2780 | curproxy->options2 |= PR_O2_AS_M_PP; |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2781 | while (*(args[cur_arg])) { |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2782 | if (!strcmp(args[cur_arg], "request-learn")) { |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2783 | curproxy->options2 |= PR_O2_AS_REQL; |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2784 | } else if (!strcmp(args[cur_arg], "prefix")) { |
| 2785 | curproxy->options2 |= PR_O2_AS_PFX; |
| 2786 | } else if (!strcmp(args[cur_arg], "mode")) { |
| 2787 | if (!*args[cur_arg + 1]) { |
| 2788 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 2789 | file, linenum, args[0], args[cur_arg]); |
| 2790 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2791 | goto out; |
| 2792 | } |
| 2793 | |
| 2794 | cur_arg++; |
| 2795 | if (!strcmp(args[cur_arg], "query-string")) { |
| 2796 | curproxy->options2 &= ~PR_O2_AS_M_ANY; |
| 2797 | curproxy->options2 |= PR_O2_AS_M_QS; |
| 2798 | } else if (!strcmp(args[cur_arg], "path-parameters")) { |
| 2799 | curproxy->options2 &= ~PR_O2_AS_M_ANY; |
| 2800 | curproxy->options2 |= PR_O2_AS_M_PP; |
| 2801 | } else { |
| 2802 | Alert("parsing [%s:%d] : unknown mode '%s'\n", file, linenum, args[cur_arg]); |
| 2803 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2804 | goto out; |
| 2805 | } |
| 2806 | } |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2807 | cur_arg++; |
| 2808 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2809 | } /* Url App Session */ |
| 2810 | else if (!strcmp(args[0], "capture")) { |
Willy Tarreau | 3b6b1a9 | 2009-07-23 13:24:23 +0200 | [diff] [blame] | 2811 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2812 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2813 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2814 | if (!strcmp(args[1], "cookie")) { /* name of a cookie to capture */ |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 2815 | if (curproxy == &defproxy) { |
| 2816 | Alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
| 2817 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2818 | goto out; |
| 2819 | } |
| 2820 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2821 | if (*(args[4]) == 0) { |
| 2822 | Alert("parsing [%s:%d] : '%s' expects 'cookie' <cookie_name> 'len' <len>.\n", |
| 2823 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2824 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2825 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2826 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2827 | free(curproxy->capture_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2828 | curproxy->capture_name = strdup(args[2]); |
| 2829 | curproxy->capture_namelen = strlen(curproxy->capture_name); |
| 2830 | curproxy->capture_len = atol(args[4]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2831 | curproxy->to_log |= LW_COOKIE; |
| 2832 | } |
| 2833 | else if (!strcmp(args[1], "request") && !strcmp(args[2], "header")) { |
| 2834 | struct cap_hdr *hdr; |
| 2835 | |
| 2836 | if (curproxy == &defproxy) { |
| 2837 | 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] | 2838 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2839 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2840 | } |
| 2841 | |
| 2842 | if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) { |
| 2843 | Alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n", |
| 2844 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2845 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2846 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2847 | } |
| 2848 | |
| 2849 | hdr = calloc(sizeof(struct cap_hdr), 1); |
| 2850 | hdr->next = curproxy->req_cap; |
| 2851 | hdr->name = strdup(args[3]); |
| 2852 | hdr->namelen = strlen(args[3]); |
| 2853 | hdr->len = atol(args[5]); |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 2854 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2855 | hdr->index = curproxy->nb_req_cap++; |
| 2856 | curproxy->req_cap = hdr; |
| 2857 | curproxy->to_log |= LW_REQHDR; |
| 2858 | } |
| 2859 | else if (!strcmp(args[1], "response") && !strcmp(args[2], "header")) { |
| 2860 | struct cap_hdr *hdr; |
| 2861 | |
| 2862 | if (curproxy == &defproxy) { |
| 2863 | 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] | 2864 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2865 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2866 | } |
| 2867 | |
| 2868 | if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) { |
| 2869 | Alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n", |
| 2870 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2871 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2872 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2873 | } |
| 2874 | hdr = calloc(sizeof(struct cap_hdr), 1); |
| 2875 | hdr->next = curproxy->rsp_cap; |
| 2876 | hdr->name = strdup(args[3]); |
| 2877 | hdr->namelen = strlen(args[3]); |
| 2878 | hdr->len = atol(args[5]); |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 2879 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2880 | hdr->index = curproxy->nb_rsp_cap++; |
| 2881 | curproxy->rsp_cap = hdr; |
| 2882 | curproxy->to_log |= LW_RSPHDR; |
| 2883 | } |
| 2884 | else { |
| 2885 | Alert("parsing [%s:%d] : '%s' expects 'cookie' or 'request header' or 'response header'.\n", |
| 2886 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2887 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2888 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2889 | } |
| 2890 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2891 | else if (!strcmp(args[0], "retries")) { /* connection retries */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2892 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2893 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2894 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2895 | if (*(args[1]) == 0) { |
| 2896 | Alert("parsing [%s:%d] : '%s' expects an integer argument (dispatch counts for one).\n", |
| 2897 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2898 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2899 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2900 | } |
| 2901 | curproxy->conn_retries = atol(args[1]); |
| 2902 | } |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2903 | 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] | 2904 | struct http_req_rule *rule; |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2905 | |
| 2906 | if (curproxy == &defproxy) { |
| 2907 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2908 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2909 | goto out; |
| 2910 | } |
| 2911 | |
Willy Tarreau | 20b0de5 | 2012-12-24 15:45:22 +0100 | [diff] [blame] | 2912 | if (!LIST_ISEMPTY(&curproxy->http_req_rules) && |
| 2913 | !LIST_PREV(&curproxy->http_req_rules, struct http_req_rule *, list)->cond && |
| 2914 | (LIST_PREV(&curproxy->http_req_rules, struct http_req_rule *, list)->action == HTTP_REQ_ACT_ALLOW || |
| 2915 | LIST_PREV(&curproxy->http_req_rules, struct http_req_rule *, list)->action == HTTP_REQ_ACT_DENY || |
Willy Tarreau | e365c0b | 2013-06-11 16:06:12 +0200 | [diff] [blame] | 2916 | LIST_PREV(&curproxy->http_req_rules, struct http_req_rule *, list)->action == HTTP_REQ_ACT_REDIR || |
Willy Tarreau | 20b0de5 | 2012-12-24 15:45:22 +0100 | [diff] [blame] | 2917 | LIST_PREV(&curproxy->http_req_rules, struct http_req_rule *, list)->action == HTTP_REQ_ACT_AUTH)) { |
| 2918 | 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] | 2919 | file, linenum, args[0]); |
| 2920 | err_code |= ERR_WARN; |
| 2921 | } |
| 2922 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 2923 | 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] | 2924 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 2925 | if (!rule) { |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2926 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2927 | goto out; |
| 2928 | } |
| 2929 | |
Willy Tarreau | 5002f57 | 2014-04-23 01:32:02 +0200 | [diff] [blame] | 2930 | err_code |= warnif_misplaced_http_req(curproxy, file, linenum, args[0]); |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 2931 | err_code |= warnif_cond_conflicts(rule->cond, |
| 2932 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 2933 | file, linenum); |
| 2934 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 2935 | LIST_ADDQ(&curproxy->http_req_rules, &rule->list); |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2936 | } |
Willy Tarreau | e365c0b | 2013-06-11 16:06:12 +0200 | [diff] [blame] | 2937 | else if (!strcmp(args[0], "http-response")) { /* response access control */ |
| 2938 | struct http_res_rule *rule; |
| 2939 | |
| 2940 | if (curproxy == &defproxy) { |
| 2941 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2942 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2943 | goto out; |
| 2944 | } |
| 2945 | |
| 2946 | if (!LIST_ISEMPTY(&curproxy->http_res_rules) && |
| 2947 | !LIST_PREV(&curproxy->http_res_rules, struct http_res_rule *, list)->cond && |
| 2948 | (LIST_PREV(&curproxy->http_res_rules, struct http_res_rule *, list)->action == HTTP_RES_ACT_ALLOW || |
| 2949 | LIST_PREV(&curproxy->http_res_rules, struct http_res_rule *, list)->action == HTTP_RES_ACT_DENY)) { |
| 2950 | Warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n", |
| 2951 | file, linenum, args[0]); |
| 2952 | err_code |= ERR_WARN; |
| 2953 | } |
| 2954 | |
| 2955 | rule = parse_http_res_cond((const char **)args + 1, file, linenum, curproxy); |
| 2956 | |
| 2957 | if (!rule) { |
| 2958 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2959 | goto out; |
| 2960 | } |
| 2961 | |
| 2962 | err_code |= warnif_cond_conflicts(rule->cond, |
| 2963 | (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR, |
| 2964 | file, linenum); |
| 2965 | |
| 2966 | LIST_ADDQ(&curproxy->http_res_rules, &rule->list); |
| 2967 | } |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 2968 | else if (!strcmp(args[0], "http-send-name-header")) { /* send server name in request header */ |
| 2969 | /* set the header name and length into the proxy structure */ |
| 2970 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 2971 | err_code |= ERR_WARN; |
| 2972 | |
| 2973 | if (!*args[1]) { |
| 2974 | Alert("parsing [%s:%d] : '%s' requires a header string.\n", |
| 2975 | file, linenum, args[0]); |
| 2976 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2977 | goto out; |
| 2978 | } |
| 2979 | |
| 2980 | /* set the desired header name */ |
| 2981 | free(curproxy->server_id_hdr_name); |
| 2982 | curproxy->server_id_hdr_name = strdup(args[1]); |
| 2983 | curproxy->server_id_hdr_len = strlen(curproxy->server_id_hdr_name); |
| 2984 | } |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2985 | else if (!strcmp(args[0], "block")) { /* early blocking based on ACLs */ |
Willy Tarreau | b3dc39d | 2014-04-28 22:06:57 +0200 | [diff] [blame] | 2986 | struct http_req_rule *rule; |
| 2987 | |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2988 | if (curproxy == &defproxy) { |
| 2989 | 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] | 2990 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2991 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2992 | } |
| 2993 | |
Willy Tarreau | b3dc39d | 2014-04-28 22:06:57 +0200 | [diff] [blame] | 2994 | /* emulate "block" using "http-request block". Since these rules are supposed to |
| 2995 | * be processed before all http-request rules, we put them into their own list |
| 2996 | * and will insert them at the end. |
| 2997 | */ |
| 2998 | rule = parse_http_req_cond((const char **)args, file, linenum, curproxy); |
| 2999 | if (!rule) { |
| 3000 | err_code |= ERR_ALERT | ERR_ABORT; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3001 | goto out; |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 3002 | } |
Willy Tarreau | b3dc39d | 2014-04-28 22:06:57 +0200 | [diff] [blame] | 3003 | err_code |= warnif_misplaced_block(curproxy, file, linenum, args[0]); |
| 3004 | err_code |= warnif_cond_conflicts(rule->cond, |
| 3005 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 3006 | file, linenum); |
| 3007 | LIST_ADDQ(&curproxy->block_rules, &rule->list); |
Willy Tarreau | de9d2d7 | 2014-04-28 22:28:02 +0200 | [diff] [blame] | 3008 | |
| 3009 | if (!already_warned(WARN_BLOCK_DEPRECATED)) |
| 3010 | Warning("parsing [%s:%d] : The '%s' directive is now deprecated in favor of 'http-request deny' which uses the exact same syntax. The rules are translated but support might disappear in a future version.\n", file, linenum, args[0]); |
| 3011 | |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 3012 | } |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3013 | else if (!strcmp(args[0], "redirect")) { |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3014 | struct redirect_rule *rule; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3015 | |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 3016 | if (curproxy == &defproxy) { |
| 3017 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3018 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3019 | goto out; |
| 3020 | } |
| 3021 | |
Thierry FOURNIER | d18cd0f | 2013-11-29 12:15:45 +0100 | [diff] [blame] | 3022 | if ((rule = http_parse_redirect_rule(file, linenum, curproxy, (const char **)args + 1, &errmsg, 0)) == NULL) { |
Willy Tarreau | 4baae24 | 2012-12-27 12:00:31 +0100 | [diff] [blame] | 3023 | Alert("parsing [%s:%d] : error detected in %s '%s' while parsing redirect rule : %s.\n", |
| 3024 | file, linenum, proxy_type_str(curproxy), curproxy->id, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3025 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3026 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3027 | } |
| 3028 | |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3029 | LIST_ADDQ(&curproxy->redirect_rules, &rule->list); |
Willy Tarreau | ee445d9 | 2014-04-23 01:39:04 +0200 | [diff] [blame] | 3030 | err_code |= warnif_misplaced_redirect(curproxy, file, linenum, args[0]); |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3031 | err_code |= warnif_cond_conflicts(rule->cond, |
| 3032 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 3033 | file, linenum); |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3034 | } |
Krzysztof Piotr Oledzki | 7b723ef | 2009-01-27 21:09:41 +0100 | [diff] [blame] | 3035 | else if (!strcmp(args[0], "use_backend")) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3036 | struct switching_rule *rule; |
| 3037 | |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3038 | if (curproxy == &defproxy) { |
| 3039 | 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] | 3040 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3041 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3042 | } |
| 3043 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3044 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3045 | err_code |= ERR_WARN; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3046 | |
| 3047 | if (*(args[1]) == 0) { |
| 3048 | 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] | 3049 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3050 | goto out; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3051 | } |
| 3052 | |
Willy Tarreau | f51658d | 2014-04-23 01:21:56 +0200 | [diff] [blame] | 3053 | if (strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0) { |
| 3054 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 3055 | Alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n", |
| 3056 | file, linenum, errmsg); |
| 3057 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3058 | goto out; |
| 3059 | } |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3060 | |
Willy Tarreau | f51658d | 2014-04-23 01:21:56 +0200 | [diff] [blame] | 3061 | err_code |= warnif_cond_conflicts(cond, SMP_VAL_FE_SET_BCK, file, linenum); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3062 | } |
| 3063 | |
| 3064 | rule = (struct switching_rule *)calloc(1, sizeof(*rule)); |
| 3065 | rule->cond = cond; |
| 3066 | rule->be.name = strdup(args[1]); |
| 3067 | LIST_INIT(&rule->list); |
| 3068 | LIST_ADDQ(&curproxy->switching_rules, &rule->list); |
| 3069 | } |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 3070 | else if (strcmp(args[0], "use-server") == 0) { |
| 3071 | struct server_rule *rule; |
| 3072 | |
| 3073 | if (curproxy == &defproxy) { |
| 3074 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3075 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3076 | goto out; |
| 3077 | } |
| 3078 | |
| 3079 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 3080 | err_code |= ERR_WARN; |
| 3081 | |
| 3082 | if (*(args[1]) == 0) { |
| 3083 | Alert("parsing [%s:%d] : '%s' expects a server name.\n", file, linenum, args[0]); |
| 3084 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3085 | goto out; |
| 3086 | } |
| 3087 | |
| 3088 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
| 3089 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 3090 | file, linenum, args[0]); |
| 3091 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3092 | goto out; |
| 3093 | } |
| 3094 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 3095 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 3096 | Alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n", |
| 3097 | file, linenum, errmsg); |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 3098 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3099 | goto out; |
| 3100 | } |
| 3101 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3102 | err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum); |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 3103 | |
| 3104 | rule = (struct server_rule *)calloc(1, sizeof(*rule)); |
| 3105 | rule->cond = cond; |
| 3106 | rule->srv.name = strdup(args[1]); |
| 3107 | LIST_INIT(&rule->list); |
| 3108 | LIST_ADDQ(&curproxy->server_rules, &rule->list); |
| 3109 | curproxy->be_req_ana |= AN_REQ_SRV_RULES; |
| 3110 | } |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 3111 | else if ((!strcmp(args[0], "force-persist")) || |
| 3112 | (!strcmp(args[0], "ignore-persist"))) { |
| 3113 | struct persist_rule *rule; |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 3114 | |
| 3115 | if (curproxy == &defproxy) { |
| 3116 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3117 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3118 | goto out; |
| 3119 | } |
| 3120 | |
| 3121 | if (warnifnotcap(curproxy, PR_CAP_FE|PR_CAP_BE, file, linenum, args[0], NULL)) |
| 3122 | err_code |= ERR_WARN; |
| 3123 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 3124 | if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) { |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 3125 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 3126 | file, linenum, args[0]); |
| 3127 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3128 | goto out; |
| 3129 | } |
| 3130 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 3131 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 1, &errmsg)) == NULL) { |
| 3132 | Alert("parsing [%s:%d] : error detected while parsing a '%s' rule : %s.\n", |
| 3133 | file, linenum, args[0], errmsg); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 3134 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3135 | goto out; |
| 3136 | } |
| 3137 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3138 | /* note: BE_REQ_CNT is the first one after FE_SET_BCK, which is |
| 3139 | * where force-persist is applied. |
| 3140 | */ |
| 3141 | err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_REQ_CNT, file, linenum); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 3142 | |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 3143 | rule = (struct persist_rule *)calloc(1, sizeof(*rule)); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 3144 | rule->cond = cond; |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 3145 | if (!strcmp(args[0], "force-persist")) { |
| 3146 | rule->type = PERSIST_TYPE_FORCE; |
| 3147 | } else { |
| 3148 | rule->type = PERSIST_TYPE_IGNORE; |
| 3149 | } |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 3150 | LIST_INIT(&rule->list); |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 3151 | LIST_ADDQ(&curproxy->persist_rules, &rule->list); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 3152 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3153 | else if (!strcmp(args[0], "stick-table")) { |
| 3154 | int myidx = 1; |
| 3155 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 3156 | curproxy->table.id = curproxy->id; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3157 | curproxy->table.type = (unsigned int)-1; |
| 3158 | while (*args[myidx]) { |
| 3159 | const char *err; |
| 3160 | |
| 3161 | if (strcmp(args[myidx], "size") == 0) { |
| 3162 | myidx++; |
| 3163 | if (!*(args[myidx])) { |
| 3164 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 3165 | file, linenum, args[myidx-1]); |
| 3166 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3167 | goto out; |
| 3168 | } |
| 3169 | if ((err = parse_size_err(args[myidx], &curproxy->table.size))) { |
| 3170 | Alert("parsing [%s:%d] : stick-table: unexpected character '%c' in argument of '%s'.\n", |
| 3171 | file, linenum, *err, args[myidx-1]); |
| 3172 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3173 | goto out; |
| 3174 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 3175 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3176 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 3177 | else if (strcmp(args[myidx], "peers") == 0) { |
| 3178 | myidx++; |
Godbach | 5052316 | 2013-12-11 19:48:57 +0800 | [diff] [blame] | 3179 | if (!*(args[myidx])) { |
Godbach | ff11554 | 2014-04-21 21:52:23 +0800 | [diff] [blame] | 3180 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 3181 | file, linenum, args[myidx-1]); |
| 3182 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3183 | goto out; |
Godbach | 5052316 | 2013-12-11 19:48:57 +0800 | [diff] [blame] | 3184 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 3185 | curproxy->table.peers.name = strdup(args[myidx++]); |
| 3186 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3187 | else if (strcmp(args[myidx], "expire") == 0) { |
| 3188 | myidx++; |
| 3189 | if (!*(args[myidx])) { |
| 3190 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 3191 | file, linenum, args[myidx-1]); |
| 3192 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3193 | goto out; |
| 3194 | } |
| 3195 | err = parse_time_err(args[myidx], &val, TIME_UNIT_MS); |
| 3196 | if (err) { |
| 3197 | Alert("parsing [%s:%d] : stick-table: unexpected character '%c' in argument of '%s'.\n", |
| 3198 | file, linenum, *err, args[myidx-1]); |
| 3199 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3200 | goto out; |
| 3201 | } |
| 3202 | curproxy->table.expire = val; |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 3203 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3204 | } |
| 3205 | else if (strcmp(args[myidx], "nopurge") == 0) { |
| 3206 | curproxy->table.nopurge = 1; |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 3207 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3208 | } |
| 3209 | else if (strcmp(args[myidx], "type") == 0) { |
| 3210 | myidx++; |
| 3211 | if (stktable_parse_type(args, &myidx, &curproxy->table.type, &curproxy->table.key_size) != 0) { |
| 3212 | Alert("parsing [%s:%d] : stick-table: unknown type '%s'.\n", |
| 3213 | file, linenum, args[myidx]); |
| 3214 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3215 | goto out; |
| 3216 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 3217 | /* myidx already points to next arg */ |
| 3218 | } |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 3219 | else if (strcmp(args[myidx], "store") == 0) { |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 3220 | int type, err; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 3221 | char *cw, *nw, *sa; |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 3222 | |
| 3223 | myidx++; |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 3224 | nw = args[myidx]; |
| 3225 | while (*nw) { |
| 3226 | /* the "store" keyword supports a comma-separated list */ |
| 3227 | cw = nw; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 3228 | sa = NULL; /* store arg */ |
| 3229 | while (*nw && *nw != ',') { |
| 3230 | if (*nw == '(') { |
| 3231 | *nw = 0; |
| 3232 | sa = ++nw; |
| 3233 | while (*nw != ')') { |
| 3234 | if (!*nw) { |
| 3235 | Alert("parsing [%s:%d] : %s: missing closing parenthesis after store option '%s'.\n", |
| 3236 | file, linenum, args[0], cw); |
| 3237 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3238 | goto out; |
| 3239 | } |
| 3240 | nw++; |
| 3241 | } |
| 3242 | *nw = '\0'; |
| 3243 | } |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 3244 | nw++; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 3245 | } |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 3246 | if (*nw) |
| 3247 | *nw++ = '\0'; |
| 3248 | type = stktable_get_data_type(cw); |
| 3249 | if (type < 0) { |
| 3250 | Alert("parsing [%s:%d] : %s: unknown store option '%s'.\n", |
| 3251 | file, linenum, args[0], cw); |
| 3252 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3253 | goto out; |
| 3254 | } |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 3255 | |
| 3256 | err = stktable_alloc_data_type(&curproxy->table, type, sa); |
| 3257 | switch (err) { |
| 3258 | case PE_NONE: break; |
| 3259 | case PE_EXIST: |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 3260 | Warning("parsing [%s:%d]: %s: store option '%s' already enabled, ignored.\n", |
| 3261 | file, linenum, args[0], cw); |
| 3262 | err_code |= ERR_WARN; |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 3263 | break; |
| 3264 | |
| 3265 | case PE_ARG_MISSING: |
| 3266 | Alert("parsing [%s:%d] : %s: missing argument to store option '%s'.\n", |
| 3267 | file, linenum, args[0], cw); |
| 3268 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3269 | goto out; |
| 3270 | |
| 3271 | case PE_ARG_NOT_USED: |
| 3272 | Alert("parsing [%s:%d] : %s: unexpected argument to store option '%s'.\n", |
| 3273 | file, linenum, args[0], cw); |
| 3274 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3275 | goto out; |
| 3276 | |
| 3277 | default: |
| 3278 | Alert("parsing [%s:%d] : %s: error when processing store option '%s'.\n", |
| 3279 | file, linenum, args[0], cw); |
| 3280 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3281 | goto out; |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 3282 | } |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 3283 | } |
| 3284 | myidx++; |
| 3285 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 3286 | else { |
| 3287 | Alert("parsing [%s:%d] : stick-table: unknown argument '%s'.\n", |
| 3288 | file, linenum, args[myidx]); |
| 3289 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3290 | goto out; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3291 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3292 | } |
| 3293 | |
| 3294 | if (!curproxy->table.size) { |
| 3295 | Alert("parsing [%s:%d] : stick-table: missing size.\n", |
| 3296 | file, linenum); |
| 3297 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3298 | goto out; |
| 3299 | } |
| 3300 | |
| 3301 | if (curproxy->table.type == (unsigned int)-1) { |
| 3302 | Alert("parsing [%s:%d] : stick-table: missing type.\n", |
| 3303 | file, linenum); |
| 3304 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3305 | goto out; |
| 3306 | } |
| 3307 | } |
| 3308 | else if (!strcmp(args[0], "stick")) { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3309 | struct sticking_rule *rule; |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 3310 | struct sample_expr *expr; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3311 | int myidx = 0; |
| 3312 | const char *name = NULL; |
| 3313 | int flags; |
| 3314 | |
| 3315 | if (curproxy == &defproxy) { |
| 3316 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3317 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3318 | goto out; |
| 3319 | } |
| 3320 | |
| 3321 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) { |
| 3322 | err_code |= ERR_WARN; |
| 3323 | goto out; |
| 3324 | } |
| 3325 | |
| 3326 | myidx++; |
| 3327 | if ((strcmp(args[myidx], "store") == 0) || |
| 3328 | (strcmp(args[myidx], "store-request") == 0)) { |
| 3329 | myidx++; |
| 3330 | flags = STK_IS_STORE; |
| 3331 | } |
| 3332 | else if (strcmp(args[myidx], "store-response") == 0) { |
| 3333 | myidx++; |
| 3334 | flags = STK_IS_STORE | STK_ON_RSP; |
| 3335 | } |
| 3336 | else if (strcmp(args[myidx], "match") == 0) { |
| 3337 | myidx++; |
| 3338 | flags = STK_IS_MATCH; |
| 3339 | } |
| 3340 | else if (strcmp(args[myidx], "on") == 0) { |
| 3341 | myidx++; |
| 3342 | flags = STK_IS_MATCH | STK_IS_STORE; |
| 3343 | } |
| 3344 | else { |
| 3345 | Alert("parsing [%s:%d] : '%s' expects 'on', 'match', or 'store'.\n", file, linenum, args[0]); |
| 3346 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3347 | goto out; |
| 3348 | } |
| 3349 | |
| 3350 | if (*(args[myidx]) == 0) { |
| 3351 | Alert("parsing [%s:%d] : '%s' expects a fetch method.\n", file, linenum, args[0]); |
| 3352 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3353 | goto out; |
| 3354 | } |
| 3355 | |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 3356 | curproxy->conf.args.ctx = ARGC_STK; |
Thierry FOURNIER | eeaa951 | 2014-02-11 14:00:19 +0100 | [diff] [blame] | 3357 | expr = sample_parse_expr(args, &myidx, file, linenum, &errmsg, &curproxy->conf.args); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3358 | if (!expr) { |
Willy Tarreau | 975c178 | 2013-12-12 23:16:54 +0100 | [diff] [blame] | 3359 | Alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3360 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3361 | goto out; |
| 3362 | } |
| 3363 | |
| 3364 | if (flags & STK_ON_RSP) { |
Willy Tarreau | 80aca90 | 2013-01-07 15:42:20 +0100 | [diff] [blame] | 3365 | if (!(expr->fetch->val & SMP_VAL_BE_STO_RUL)) { |
| 3366 | Alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available for 'store-response'.\n", |
| 3367 | file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use)); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3368 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 3369 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3370 | goto out; |
| 3371 | } |
| 3372 | } else { |
Willy Tarreau | 80aca90 | 2013-01-07 15:42:20 +0100 | [diff] [blame] | 3373 | if (!(expr->fetch->val & SMP_VAL_BE_SET_SRV)) { |
| 3374 | Alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available during request.\n", |
| 3375 | file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use)); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3376 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 3377 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3378 | goto out; |
| 3379 | } |
| 3380 | } |
| 3381 | |
Willy Tarreau | 1b6c00c | 2012-10-05 22:41:26 +0200 | [diff] [blame] | 3382 | /* check if we need to allocate an hdr_idx struct for HTTP parsing */ |
Willy Tarreau | 25320b2 | 2013-03-24 07:22:08 +0100 | [diff] [blame] | 3383 | curproxy->http_needed |= !!(expr->fetch->use & SMP_USE_HTTP_ANY); |
Willy Tarreau | 1b6c00c | 2012-10-05 22:41:26 +0200 | [diff] [blame] | 3384 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3385 | if (strcmp(args[myidx], "table") == 0) { |
| 3386 | myidx++; |
| 3387 | name = args[myidx++]; |
| 3388 | } |
| 3389 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 3390 | if (strcmp(args[myidx], "if") == 0 || strcmp(args[myidx], "unless") == 0) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 3391 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + myidx, &errmsg)) == NULL) { |
| 3392 | Alert("parsing [%s:%d] : '%s': error detected while parsing sticking condition : %s.\n", |
| 3393 | file, linenum, args[0], errmsg); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3394 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 3395 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3396 | goto out; |
| 3397 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3398 | } |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 3399 | else if (*(args[myidx])) { |
| 3400 | Alert("parsing [%s:%d] : '%s': unknown keyword '%s'.\n", |
| 3401 | file, linenum, args[0], args[myidx]); |
| 3402 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 3403 | free(expr); |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 3404 | goto out; |
| 3405 | } |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 3406 | if (flags & STK_ON_RSP) |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3407 | err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_STO_RUL, file, linenum); |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 3408 | else |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3409 | err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum); |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 3410 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3411 | rule = (struct sticking_rule *)calloc(1, sizeof(*rule)); |
| 3412 | rule->cond = cond; |
| 3413 | rule->expr = expr; |
| 3414 | rule->flags = flags; |
| 3415 | rule->table.name = name ? strdup(name) : NULL; |
| 3416 | LIST_INIT(&rule->list); |
| 3417 | if (flags & STK_ON_RSP) |
| 3418 | LIST_ADDQ(&curproxy->storersp_rules, &rule->list); |
| 3419 | else |
| 3420 | LIST_ADDQ(&curproxy->sticking_rules, &rule->list); |
| 3421 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3422 | else if (!strcmp(args[0], "stats")) { |
| 3423 | if (curproxy != &defproxy && curproxy->uri_auth == defproxy.uri_auth) |
| 3424 | curproxy->uri_auth = NULL; /* we must detach from the default config */ |
| 3425 | |
Krzysztof Piotr Oledzki | 260a3bb | 2010-01-06 16:25:05 +0100 | [diff] [blame] | 3426 | if (!*args[1]) { |
| 3427 | goto stats_error_parsing; |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3428 | } else if (!strcmp(args[1], "admin")) { |
| 3429 | struct stats_admin_rule *rule; |
| 3430 | |
| 3431 | if (curproxy == &defproxy) { |
| 3432 | Alert("parsing [%s:%d]: '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
| 3433 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3434 | goto out; |
| 3435 | } |
| 3436 | |
| 3437 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 3438 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3439 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3440 | goto out; |
| 3441 | } |
| 3442 | |
| 3443 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
| 3444 | Alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n", |
| 3445 | file, linenum, args[0], args[1]); |
| 3446 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3447 | goto out; |
| 3448 | } |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 3449 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 3450 | Alert("parsing [%s:%d] : error detected while parsing a '%s %s' rule : %s.\n", |
| 3451 | file, linenum, args[0], args[1], errmsg); |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3452 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3453 | goto out; |
| 3454 | } |
| 3455 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3456 | err_code |= warnif_cond_conflicts(cond, |
| 3457 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 3458 | file, linenum); |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3459 | |
| 3460 | rule = (struct stats_admin_rule *)calloc(1, sizeof(*rule)); |
| 3461 | rule->cond = cond; |
| 3462 | LIST_INIT(&rule->list); |
| 3463 | LIST_ADDQ(&curproxy->uri_auth->admin_rules, &rule->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3464 | } else if (!strcmp(args[1], "uri")) { |
| 3465 | if (*(args[2]) == 0) { |
| 3466 | Alert("parsing [%s:%d] : 'uri' needs an URI prefix.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3467 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3468 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3469 | } else if (!stats_set_uri(&curproxy->uri_auth, args[2])) { |
| 3470 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3471 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3472 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3473 | } |
| 3474 | } else if (!strcmp(args[1], "realm")) { |
| 3475 | if (*(args[2]) == 0) { |
| 3476 | Alert("parsing [%s:%d] : 'realm' needs an realm name.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3477 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3478 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3479 | } else if (!stats_set_realm(&curproxy->uri_auth, args[2])) { |
| 3480 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3481 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3482 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3483 | } |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 3484 | } else if (!strcmp(args[1], "refresh")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 3485 | unsigned interval; |
| 3486 | |
| 3487 | err = parse_time_err(args[2], &interval, TIME_UNIT_S); |
| 3488 | if (err) { |
| 3489 | Alert("parsing [%s:%d] : unexpected character '%c' in stats refresh interval.\n", |
| 3490 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3491 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3492 | goto out; |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 3493 | } else if (!stats_set_refresh(&curproxy->uri_auth, interval)) { |
| 3494 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3495 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3496 | goto out; |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 3497 | } |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3498 | } 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] | 3499 | struct http_req_rule *rule; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3500 | |
| 3501 | if (curproxy == &defproxy) { |
| 3502 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3503 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3504 | goto out; |
| 3505 | } |
| 3506 | |
| 3507 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 3508 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3509 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3510 | goto out; |
| 3511 | } |
| 3512 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3513 | if (!LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) && |
| 3514 | !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] | 3515 | Warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n", |
| 3516 | file, linenum, args[0]); |
| 3517 | err_code |= ERR_WARN; |
| 3518 | } |
| 3519 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3520 | 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] | 3521 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3522 | if (!rule) { |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3523 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3524 | goto out; |
| 3525 | } |
| 3526 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3527 | err_code |= warnif_cond_conflicts(rule->cond, |
| 3528 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 3529 | file, linenum); |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3530 | LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list); |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3531 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3532 | } else if (!strcmp(args[1], "auth")) { |
| 3533 | if (*(args[2]) == 0) { |
| 3534 | 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] | 3535 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3536 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3537 | } else if (!stats_add_auth(&curproxy->uri_auth, args[2])) { |
| 3538 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3539 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3540 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3541 | } |
| 3542 | } else if (!strcmp(args[1], "scope")) { |
| 3543 | if (*(args[2]) == 0) { |
| 3544 | Alert("parsing [%s:%d] : 'scope' needs a proxy name.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3545 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3546 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3547 | } else if (!stats_add_scope(&curproxy->uri_auth, args[2])) { |
| 3548 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3549 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3550 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3551 | } |
| 3552 | } else if (!strcmp(args[1], "enable")) { |
| 3553 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 3554 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3555 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3556 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3557 | } |
Krzysztof Oledzki | d9db927 | 2007-10-15 10:05:11 +0200 | [diff] [blame] | 3558 | } else if (!strcmp(args[1], "hide-version")) { |
| 3559 | if (!stats_set_flag(&curproxy->uri_auth, ST_HIDEVER)) { |
| 3560 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3561 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3562 | goto out; |
Krzysztof Oledzki | d9db927 | 2007-10-15 10:05:11 +0200 | [diff] [blame] | 3563 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3564 | } else if (!strcmp(args[1], "show-legends")) { |
| 3565 | if (!stats_set_flag(&curproxy->uri_auth, ST_SHLGNDS)) { |
| 3566 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3567 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3568 | goto out; |
| 3569 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3570 | } else if (!strcmp(args[1], "show-node")) { |
| 3571 | |
| 3572 | if (*args[2]) { |
| 3573 | int i; |
| 3574 | char c; |
| 3575 | |
| 3576 | for (i=0; args[2][i]; i++) { |
| 3577 | c = args[2][i]; |
Willy Tarreau | 88e0581 | 2010-03-03 00:16:00 +0100 | [diff] [blame] | 3578 | if (!isupper((unsigned char)c) && !islower((unsigned char)c) && |
| 3579 | !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.') |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3580 | break; |
| 3581 | } |
| 3582 | |
| 3583 | if (!i || args[2][i]) { |
| 3584 | Alert("parsing [%s:%d]: '%s %s' invalid node name - should be a string" |
| 3585 | "with digits(0-9), letters(A-Z, a-z), hyphen(-) or underscode(_).\n", |
| 3586 | file, linenum, args[0], args[1]); |
| 3587 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3588 | goto out; |
| 3589 | } |
| 3590 | } |
| 3591 | |
| 3592 | if (!stats_set_node(&curproxy->uri_auth, args[2])) { |
| 3593 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3594 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3595 | goto out; |
| 3596 | } |
| 3597 | } else if (!strcmp(args[1], "show-desc")) { |
| 3598 | char *desc = NULL; |
| 3599 | |
| 3600 | if (*args[2]) { |
| 3601 | int i, len=0; |
| 3602 | char *d; |
| 3603 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 3604 | for (i = 2; *args[i]; i++) |
| 3605 | len += strlen(args[i]) + 1; |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3606 | |
| 3607 | desc = d = (char *)calloc(1, len); |
| 3608 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 3609 | d += snprintf(d, desc + len - d, "%s", args[2]); |
| 3610 | for (i = 3; *args[i]; i++) |
| 3611 | d += snprintf(d, desc + len - d, " %s", args[i]); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3612 | } |
| 3613 | |
| 3614 | if (!*args[2] && !global.desc) |
| 3615 | Warning("parsing [%s:%d]: '%s' requires a parameter or 'desc' to be set in the global section.\n", |
| 3616 | file, linenum, args[1]); |
| 3617 | else { |
| 3618 | if (!stats_set_desc(&curproxy->uri_auth, desc)) { |
| 3619 | free(desc); |
| 3620 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3621 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3622 | goto out; |
| 3623 | } |
| 3624 | free(desc); |
| 3625 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3626 | } else { |
Krzysztof Piotr Oledzki | 260a3bb | 2010-01-06 16:25:05 +0100 | [diff] [blame] | 3627 | stats_error_parsing: |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3628 | 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] | 3629 | 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] | 3630 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3631 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3632 | } |
| 3633 | } |
| 3634 | else if (!strcmp(args[0], "option")) { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3635 | int optnum; |
| 3636 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3637 | if (*(args[1]) == '\0') { |
| 3638 | Alert("parsing [%s:%d]: '%s' expects an option name.\n", |
| 3639 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3640 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3641 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3642 | } |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3643 | |
| 3644 | for (optnum = 0; cfg_opts[optnum].name; optnum++) { |
| 3645 | if (!strcmp(args[1], cfg_opts[optnum].name)) { |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 3646 | if (cfg_opts[optnum].cap == PR_CAP_NONE) { |
| 3647 | Alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n", |
| 3648 | file, linenum, cfg_opts[optnum].name); |
| 3649 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3650 | goto out; |
| 3651 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3652 | if (warnifnotcap(curproxy, cfg_opts[optnum].cap, file, linenum, args[1], NULL)) { |
| 3653 | err_code |= ERR_WARN; |
| 3654 | goto out; |
| 3655 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3656 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 3657 | curproxy->no_options &= ~cfg_opts[optnum].val; |
| 3658 | curproxy->options &= ~cfg_opts[optnum].val; |
| 3659 | |
| 3660 | switch (kwm) { |
| 3661 | case KWM_STD: |
| 3662 | curproxy->options |= cfg_opts[optnum].val; |
| 3663 | break; |
| 3664 | case KWM_NO: |
| 3665 | curproxy->no_options |= cfg_opts[optnum].val; |
| 3666 | break; |
| 3667 | case KWM_DEF: /* already cleared */ |
| 3668 | break; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 3669 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3670 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3671 | goto out; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3672 | } |
| 3673 | } |
| 3674 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 3675 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) { |
| 3676 | if (!strcmp(args[1], cfg_opts2[optnum].name)) { |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 3677 | if (cfg_opts2[optnum].cap == PR_CAP_NONE) { |
| 3678 | Alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n", |
| 3679 | file, linenum, cfg_opts2[optnum].name); |
| 3680 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3681 | goto out; |
| 3682 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3683 | if (warnifnotcap(curproxy, cfg_opts2[optnum].cap, file, linenum, args[1], NULL)) { |
| 3684 | err_code |= ERR_WARN; |
| 3685 | goto out; |
| 3686 | } |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 3687 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 3688 | curproxy->no_options2 &= ~cfg_opts2[optnum].val; |
| 3689 | curproxy->options2 &= ~cfg_opts2[optnum].val; |
| 3690 | |
| 3691 | switch (kwm) { |
| 3692 | case KWM_STD: |
| 3693 | curproxy->options2 |= cfg_opts2[optnum].val; |
| 3694 | break; |
| 3695 | case KWM_NO: |
| 3696 | curproxy->no_options2 |= cfg_opts2[optnum].val; |
| 3697 | break; |
| 3698 | case KWM_DEF: /* already cleared */ |
| 3699 | break; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 3700 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3701 | goto out; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 3702 | } |
| 3703 | } |
| 3704 | |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 3705 | /* HTTP options override each other. They can be cancelled using |
| 3706 | * "no option xxx" which only switches to default mode if the mode |
| 3707 | * was this one (useful for cancelling options set in defaults |
| 3708 | * sections). |
| 3709 | */ |
| 3710 | if (strcmp(args[1], "httpclose") == 0) { |
| 3711 | if (kwm == KWM_STD) { |
| 3712 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3713 | curproxy->options |= PR_O_HTTP_PCL; |
| 3714 | goto out; |
| 3715 | } |
| 3716 | else if (kwm == KWM_NO) { |
| 3717 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_PCL) |
| 3718 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3719 | goto out; |
| 3720 | } |
| 3721 | } |
| 3722 | else if (strcmp(args[1], "forceclose") == 0) { |
| 3723 | if (kwm == KWM_STD) { |
| 3724 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3725 | curproxy->options |= PR_O_HTTP_FCL; |
| 3726 | goto out; |
| 3727 | } |
| 3728 | else if (kwm == KWM_NO) { |
| 3729 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_FCL) |
| 3730 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3731 | goto out; |
| 3732 | } |
| 3733 | } |
| 3734 | else if (strcmp(args[1], "http-server-close") == 0) { |
| 3735 | if (kwm == KWM_STD) { |
| 3736 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3737 | curproxy->options |= PR_O_HTTP_SCL; |
| 3738 | goto out; |
| 3739 | } |
| 3740 | else if (kwm == KWM_NO) { |
| 3741 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_SCL) |
| 3742 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3743 | goto out; |
| 3744 | } |
| 3745 | } |
| 3746 | else if (strcmp(args[1], "http-keep-alive") == 0) { |
| 3747 | if (kwm == KWM_STD) { |
| 3748 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3749 | curproxy->options |= PR_O_HTTP_KAL; |
| 3750 | goto out; |
| 3751 | } |
| 3752 | else if (kwm == KWM_NO) { |
| 3753 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_KAL) |
| 3754 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3755 | goto out; |
| 3756 | } |
| 3757 | } |
| 3758 | else if (strcmp(args[1], "http-tunnel") == 0) { |
| 3759 | if (kwm == KWM_STD) { |
| 3760 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3761 | curproxy->options |= PR_O_HTTP_TUN; |
| 3762 | goto out; |
| 3763 | } |
| 3764 | else if (kwm == KWM_NO) { |
| 3765 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_TUN) |
| 3766 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3767 | goto out; |
| 3768 | } |
| 3769 | } |
| 3770 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 3771 | if (kwm != KWM_STD) { |
| 3772 | 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] | 3773 | file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3774 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3775 | goto out; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3776 | } |
| 3777 | |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3778 | if (!strcmp(args[1], "httplog")) { |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 3779 | char *logformat; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3780 | /* generate a complete HTTP log */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 3781 | logformat = default_http_log_format; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3782 | if (*(args[2]) != '\0') { |
| 3783 | if (!strcmp(args[2], "clf")) { |
| 3784 | curproxy->options2 |= PR_O2_CLFLOG; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 3785 | logformat = clf_http_log_format; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3786 | } else { |
| 3787 | 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] | 3788 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3789 | goto out; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3790 | } |
| 3791 | } |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 3792 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 3793 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 3794 | curproxy->conf.logformat_string != clf_http_log_format) |
| 3795 | free(curproxy->conf.logformat_string); |
| 3796 | curproxy->conf.logformat_string = logformat; |
| 3797 | |
| 3798 | free(curproxy->conf.lfs_file); |
| 3799 | curproxy->conf.lfs_file = strdup(curproxy->conf.args.file); |
| 3800 | curproxy->conf.lfs_line = curproxy->conf.args.line; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3801 | } |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 3802 | else if (!strcmp(args[1], "tcplog")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3803 | /* generate a detailed TCP log */ |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 3804 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 3805 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 3806 | curproxy->conf.logformat_string != clf_http_log_format) |
| 3807 | free(curproxy->conf.logformat_string); |
| 3808 | curproxy->conf.logformat_string = default_tcp_log_format; |
| 3809 | |
| 3810 | free(curproxy->conf.lfs_file); |
| 3811 | curproxy->conf.lfs_file = strdup(curproxy->conf.args.file); |
| 3812 | curproxy->conf.lfs_line = curproxy->conf.args.line; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 3813 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3814 | else if (!strcmp(args[1], "tcpka")) { |
| 3815 | /* enable TCP keep-alives on client and server sessions */ |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3816 | 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] | 3817 | err_code |= ERR_WARN; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3818 | |
| 3819 | if (curproxy->cap & PR_CAP_FE) |
| 3820 | curproxy->options |= PR_O_TCP_CLI_KA; |
| 3821 | if (curproxy->cap & PR_CAP_BE) |
| 3822 | curproxy->options |= PR_O_TCP_SRV_KA; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3823 | } |
| 3824 | else if (!strcmp(args[1], "httpchk")) { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3825 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3826 | err_code |= ERR_WARN; |
| 3827 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3828 | /* use HTTP request to check servers' health */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3829 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 3830 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3831 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 3832 | curproxy->options2 |= PR_O2_HTTP_CHK; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3833 | if (!*args[2]) { /* no argument */ |
| 3834 | curproxy->check_req = strdup(DEF_CHECK_REQ); /* default request */ |
| 3835 | curproxy->check_len = strlen(DEF_CHECK_REQ); |
| 3836 | } else if (!*args[3]) { /* one argument : URI */ |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3837 | 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] | 3838 | curproxy->check_req = (char *)malloc(reqlen); |
| 3839 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3840 | "OPTIONS %s HTTP/1.0\r\n", args[2]); /* URI to use */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3841 | } else { /* more arguments : METHOD URI [HTTP_VER] */ |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3842 | int reqlen = strlen(args[2]) + strlen(args[3]) + 3 + strlen("\r\n"); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3843 | if (*args[4]) |
| 3844 | reqlen += strlen(args[4]); |
| 3845 | else |
| 3846 | reqlen += strlen("HTTP/1.0"); |
| 3847 | |
| 3848 | curproxy->check_req = (char *)malloc(reqlen); |
| 3849 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3850 | "%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] | 3851 | } |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 3852 | } |
| 3853 | else if (!strcmp(args[1], "ssl-hello-chk")) { |
| 3854 | /* use SSLv3 CLIENT HELLO to check servers' health */ |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3855 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3856 | err_code |= ERR_WARN; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3857 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3858 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 3859 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3860 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Willy Tarreau | 07a5490 | 2010-03-29 18:33:29 +0200 | [diff] [blame] | 3861 | curproxy->options2 |= PR_O2_SSL3_CHK; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3862 | } |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 3863 | else if (!strcmp(args[1], "smtpchk")) { |
| 3864 | /* use SMTP request to check servers' health */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3865 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 3866 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3867 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 3868 | curproxy->options2 |= PR_O2_SMTP_CHK; |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 3869 | |
| 3870 | if (!*args[2] || !*args[3]) { /* no argument or incomplete EHLO host */ |
| 3871 | curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */ |
| 3872 | curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ); |
| 3873 | } else { /* ESMTP EHLO, or SMTP HELO, and a hostname */ |
| 3874 | if (!strcmp(args[2], "EHLO") || !strcmp(args[2], "HELO")) { |
| 3875 | int reqlen = strlen(args[2]) + strlen(args[3]) + strlen(" \r\n") + 1; |
| 3876 | curproxy->check_req = (char *)malloc(reqlen); |
| 3877 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
| 3878 | "%s %s\r\n", args[2], args[3]); /* HELO hostname */ |
| 3879 | } else { |
| 3880 | /* this just hits the default for now, but you could potentially expand it to allow for other stuff |
| 3881 | though, it's unlikely you'd want to send anything other than an EHLO or HELO */ |
| 3882 | curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */ |
| 3883 | curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ); |
| 3884 | } |
| 3885 | } |
| 3886 | } |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 3887 | else if (!strcmp(args[1], "pgsql-check")) { |
| 3888 | /* use PostgreSQL request to check servers' health */ |
| 3889 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 3890 | err_code |= ERR_WARN; |
| 3891 | |
| 3892 | free(curproxy->check_req); |
| 3893 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3894 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 3895 | curproxy->options2 |= PR_O2_PGSQL_CHK; |
| 3896 | |
| 3897 | if (*(args[2])) { |
| 3898 | int cur_arg = 2; |
| 3899 | |
| 3900 | while (*(args[cur_arg])) { |
| 3901 | if (strcmp(args[cur_arg], "user") == 0) { |
| 3902 | char * packet; |
| 3903 | uint32_t packet_len; |
| 3904 | uint32_t pv; |
| 3905 | |
| 3906 | /* suboption header - needs additional argument for it */ |
| 3907 | if (*(args[cur_arg+1]) == 0) { |
| 3908 | Alert("parsing [%s:%d] : '%s %s %s' expects <username> as argument.\n", |
| 3909 | file, linenum, args[0], args[1], args[cur_arg]); |
| 3910 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3911 | goto out; |
| 3912 | } |
| 3913 | |
| 3914 | /* uint32_t + uint32_t + strlen("user")+1 + strlen(username)+1 + 1 */ |
| 3915 | packet_len = 4 + 4 + 5 + strlen(args[cur_arg + 1])+1 +1; |
| 3916 | pv = htonl(0x30000); /* protocol version 3.0 */ |
| 3917 | |
| 3918 | packet = (char*) calloc(1, packet_len); |
| 3919 | |
| 3920 | memcpy(packet + 4, &pv, 4); |
| 3921 | |
| 3922 | /* copy "user" */ |
| 3923 | memcpy(packet + 8, "user", 4); |
| 3924 | |
| 3925 | /* copy username */ |
| 3926 | memcpy(packet + 13, args[cur_arg+1], strlen(args[cur_arg+1])); |
| 3927 | |
| 3928 | free(curproxy->check_req); |
| 3929 | curproxy->check_req = packet; |
| 3930 | curproxy->check_len = packet_len; |
| 3931 | |
| 3932 | packet_len = htonl(packet_len); |
| 3933 | memcpy(packet, &packet_len, 4); |
| 3934 | cur_arg += 2; |
| 3935 | } else { |
| 3936 | /* unknown suboption - catchall */ |
| 3937 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'user'.\n", |
| 3938 | file, linenum, args[0], args[1]); |
| 3939 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3940 | goto out; |
| 3941 | } |
| 3942 | } /* end while loop */ |
| 3943 | } |
| 3944 | } |
| 3945 | |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 3946 | else if (!strcmp(args[1], "redis-check")) { |
| 3947 | /* use REDIS PING request to check servers' health */ |
| 3948 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 3949 | err_code |= ERR_WARN; |
| 3950 | |
| 3951 | free(curproxy->check_req); |
| 3952 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3953 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 3954 | curproxy->options2 |= PR_O2_REDIS_CHK; |
| 3955 | |
| 3956 | curproxy->check_req = (char *) malloc(sizeof(DEF_REDIS_CHECK_REQ) - 1); |
| 3957 | memcpy(curproxy->check_req, DEF_REDIS_CHECK_REQ, sizeof(DEF_REDIS_CHECK_REQ) - 1); |
| 3958 | curproxy->check_len = sizeof(DEF_REDIS_CHECK_REQ) - 1; |
| 3959 | } |
| 3960 | |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 3961 | else if (!strcmp(args[1], "mysql-check")) { |
| 3962 | /* use MYSQL request to check servers' health */ |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 3963 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 3964 | err_code |= ERR_WARN; |
| 3965 | |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 3966 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 3967 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3968 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 3969 | curproxy->options2 |= PR_O2_MYSQL_CHK; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 3970 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 3971 | /* This is an example of a MySQL >=4.0 client Authentication packet kindly provided by Cyril Bonte. |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 3972 | * const char mysql40_client_auth_pkt[] = { |
| 3973 | * "\x0e\x00\x00" // packet length |
| 3974 | * "\x01" // packet number |
| 3975 | * "\x00\x00" // client capabilities |
| 3976 | * "\x00\x00\x01" // max packet |
| 3977 | * "haproxy\x00" // username (null terminated string) |
| 3978 | * "\x00" // filler (always 0x00) |
| 3979 | * "\x01\x00\x00" // packet length |
| 3980 | * "\x00" // packet number |
| 3981 | * "\x01" // COM_QUIT command |
| 3982 | * }; |
| 3983 | */ |
| 3984 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 3985 | /* This is an example of a MySQL >=4.1 client Authentication packet provided by Nenad Merdanovic. |
| 3986 | * const char mysql41_client_auth_pkt[] = { |
| 3987 | * "\x0e\x00\x00\" // packet length |
| 3988 | * "\x01" // packet number |
| 3989 | * "\x00\x00\x00\x00" // client capabilities |
| 3990 | * "\x00\x00\x00\x01" // max packet |
| 3991 | * "\x21" // character set (UTF-8) |
| 3992 | * char[23] // All zeroes |
| 3993 | * "haproxy\x00" // username (null terminated string) |
| 3994 | * "\x00" // filler (always 0x00) |
| 3995 | * "\x01\x00\x00" // packet length |
| 3996 | * "\x00" // packet number |
| 3997 | * "\x01" // COM_QUIT command |
| 3998 | * }; |
| 3999 | */ |
| 4000 | |
| 4001 | |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 4002 | if (*(args[2])) { |
| 4003 | int cur_arg = 2; |
| 4004 | |
| 4005 | while (*(args[cur_arg])) { |
| 4006 | if (strcmp(args[cur_arg], "user") == 0) { |
| 4007 | char *mysqluser; |
| 4008 | int packetlen, reqlen, userlen; |
| 4009 | |
| 4010 | /* suboption header - needs additional argument for it */ |
| 4011 | if (*(args[cur_arg+1]) == 0) { |
| 4012 | Alert("parsing [%s:%d] : '%s %s %s' expects <username> as argument.\n", |
| 4013 | file, linenum, args[0], args[1], args[cur_arg]); |
| 4014 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4015 | goto out; |
| 4016 | } |
| 4017 | mysqluser = args[cur_arg + 1]; |
| 4018 | userlen = strlen(mysqluser); |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 4019 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 4020 | if (*(args[cur_arg+2])) { |
| 4021 | if (!strcmp(args[cur_arg+2], "post-41")) { |
| 4022 | packetlen = userlen + 7 + 27; |
| 4023 | reqlen = packetlen + 9; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 4024 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 4025 | free(curproxy->check_req); |
| 4026 | curproxy->check_req = (char *)calloc(1, reqlen); |
| 4027 | curproxy->check_len = reqlen; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 4028 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 4029 | snprintf(curproxy->check_req, 4, "%c%c%c", |
| 4030 | ((unsigned char) packetlen & 0xff), |
| 4031 | ((unsigned char) (packetlen >> 8) & 0xff), |
| 4032 | ((unsigned char) (packetlen >> 16) & 0xff)); |
| 4033 | |
| 4034 | curproxy->check_req[3] = 1; |
| 4035 | curproxy->check_req[5] = 130; |
| 4036 | curproxy->check_req[11] = 1; |
| 4037 | curproxy->check_req[12] = 33; |
| 4038 | memcpy(&curproxy->check_req[36], mysqluser, userlen); |
| 4039 | curproxy->check_req[36 + userlen + 1 + 1] = 1; |
| 4040 | curproxy->check_req[36 + userlen + 1 + 1 + 4] = 1; |
| 4041 | cur_arg += 3; |
| 4042 | } else { |
| 4043 | Alert("parsing [%s:%d] : keyword '%s' only supports option 'post-41'.\n", file, linenum, args[cur_arg+2]); |
| 4044 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4045 | goto out; |
| 4046 | } |
| 4047 | } else { |
| 4048 | packetlen = userlen + 7; |
| 4049 | reqlen = packetlen + 9; |
| 4050 | |
| 4051 | free(curproxy->check_req); |
| 4052 | curproxy->check_req = (char *)calloc(1, reqlen); |
| 4053 | curproxy->check_len = reqlen; |
| 4054 | |
| 4055 | snprintf(curproxy->check_req, 4, "%c%c%c", |
| 4056 | ((unsigned char) packetlen & 0xff), |
| 4057 | ((unsigned char) (packetlen >> 8) & 0xff), |
| 4058 | ((unsigned char) (packetlen >> 16) & 0xff)); |
| 4059 | |
| 4060 | curproxy->check_req[3] = 1; |
| 4061 | curproxy->check_req[5] = 128; |
| 4062 | curproxy->check_req[8] = 1; |
| 4063 | memcpy(&curproxy->check_req[9], mysqluser, userlen); |
| 4064 | curproxy->check_req[9 + userlen + 1 + 1] = 1; |
| 4065 | curproxy->check_req[9 + userlen + 1 + 1 + 4] = 1; |
| 4066 | cur_arg += 2; |
| 4067 | } |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 4068 | } else { |
| 4069 | /* unknown suboption - catchall */ |
| 4070 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'user'.\n", |
| 4071 | file, linenum, args[0], args[1]); |
| 4072 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4073 | goto out; |
| 4074 | } |
| 4075 | } /* end while loop */ |
| 4076 | } |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 4077 | } |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 4078 | else if (!strcmp(args[1], "ldap-check")) { |
| 4079 | /* use LDAP request to check servers' health */ |
| 4080 | free(curproxy->check_req); |
| 4081 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4082 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 4083 | curproxy->options2 |= PR_O2_LDAP_CHK; |
| 4084 | |
| 4085 | curproxy->check_req = (char *) malloc(sizeof(DEF_LDAP_CHECK_REQ) - 1); |
| 4086 | memcpy(curproxy->check_req, DEF_LDAP_CHECK_REQ, sizeof(DEF_LDAP_CHECK_REQ) - 1); |
| 4087 | curproxy->check_len = sizeof(DEF_LDAP_CHECK_REQ) - 1; |
| 4088 | } |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 4089 | else if (!strcmp(args[1], "tcp-check")) { |
| 4090 | /* use raw TCPCHK send/expect to check servers' health */ |
| 4091 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 4092 | err_code |= ERR_WARN; |
| 4093 | |
| 4094 | free(curproxy->check_req); |
| 4095 | curproxy->check_req = NULL; |
| 4096 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 4097 | curproxy->options2 |= PR_O2_TCPCHK_CHK; |
| 4098 | } |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 4099 | else if (!strcmp(args[1], "forwardfor")) { |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 4100 | int cur_arg; |
| 4101 | |
| 4102 | /* insert x-forwarded-for field, but not for the IP address listed as an except. |
| 4103 | * set default options (ie: bitfield, header name, etc) |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 4104 | */ |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 4105 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 4106 | curproxy->options |= PR_O_FWDFOR | PR_O_FF_ALWAYS; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 4107 | |
| 4108 | free(curproxy->fwdfor_hdr_name); |
| 4109 | curproxy->fwdfor_hdr_name = strdup(DEF_XFORWARDFOR_HDR); |
| 4110 | curproxy->fwdfor_hdr_len = strlen(DEF_XFORWARDFOR_HDR); |
| 4111 | |
| 4112 | /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */ |
| 4113 | cur_arg = 2; |
| 4114 | while (*(args[cur_arg])) { |
| 4115 | if (!strcmp(args[cur_arg], "except")) { |
| 4116 | /* suboption except - needs additional argument for it */ |
Thierry FOURNIER | fc7ac7b | 2014-02-11 15:23:04 +0100 | [diff] [blame] | 4117 | if (!*(args[cur_arg+1]) || !str2net(args[cur_arg+1], 1, &curproxy->except_net, &curproxy->except_mask)) { |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 4118 | Alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n", |
| 4119 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4120 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4121 | goto out; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 4122 | } |
| 4123 | /* flush useless bits */ |
| 4124 | curproxy->except_net.s_addr &= curproxy->except_mask.s_addr; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 4125 | cur_arg += 2; |
| 4126 | } else if (!strcmp(args[cur_arg], "header")) { |
| 4127 | /* suboption header - needs additional argument for it */ |
| 4128 | if (*(args[cur_arg+1]) == 0) { |
| 4129 | Alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 4130 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4131 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4132 | goto out; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 4133 | } |
| 4134 | free(curproxy->fwdfor_hdr_name); |
| 4135 | curproxy->fwdfor_hdr_name = strdup(args[cur_arg+1]); |
| 4136 | curproxy->fwdfor_hdr_len = strlen(curproxy->fwdfor_hdr_name); |
| 4137 | cur_arg += 2; |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 4138 | } else if (!strcmp(args[cur_arg], "if-none")) { |
| 4139 | curproxy->options &= ~PR_O_FF_ALWAYS; |
| 4140 | cur_arg += 1; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 4141 | } else { |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 4142 | /* unknown suboption - catchall */ |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 4143 | 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] | 4144 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4145 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4146 | goto out; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 4147 | } |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 4148 | } /* end while loop */ |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 4149 | } |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 4150 | else if (!strcmp(args[1], "originalto")) { |
| 4151 | int cur_arg; |
| 4152 | |
| 4153 | /* insert x-original-to field, but not for the IP address listed as an except. |
| 4154 | * set default options (ie: bitfield, header name, etc) |
| 4155 | */ |
| 4156 | |
| 4157 | curproxy->options |= PR_O_ORGTO; |
| 4158 | |
| 4159 | free(curproxy->orgto_hdr_name); |
| 4160 | curproxy->orgto_hdr_name = strdup(DEF_XORIGINALTO_HDR); |
| 4161 | curproxy->orgto_hdr_len = strlen(DEF_XORIGINALTO_HDR); |
| 4162 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 4163 | /* 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] | 4164 | cur_arg = 2; |
| 4165 | while (*(args[cur_arg])) { |
| 4166 | if (!strcmp(args[cur_arg], "except")) { |
| 4167 | /* suboption except - needs additional argument for it */ |
Thierry FOURNIER | fc7ac7b | 2014-02-11 15:23:04 +0100 | [diff] [blame] | 4168 | if (!*(args[cur_arg+1]) || !str2net(args[cur_arg+1], 1, &curproxy->except_to, &curproxy->except_mask_to)) { |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 4169 | Alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n", |
| 4170 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4171 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4172 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 4173 | } |
| 4174 | /* flush useless bits */ |
| 4175 | curproxy->except_to.s_addr &= curproxy->except_mask_to.s_addr; |
| 4176 | cur_arg += 2; |
| 4177 | } else if (!strcmp(args[cur_arg], "header")) { |
| 4178 | /* suboption header - needs additional argument for it */ |
| 4179 | if (*(args[cur_arg+1]) == 0) { |
| 4180 | Alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 4181 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4182 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4183 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 4184 | } |
| 4185 | free(curproxy->orgto_hdr_name); |
| 4186 | curproxy->orgto_hdr_name = strdup(args[cur_arg+1]); |
| 4187 | curproxy->orgto_hdr_len = strlen(curproxy->orgto_hdr_name); |
| 4188 | cur_arg += 2; |
| 4189 | } else { |
| 4190 | /* unknown suboption - catchall */ |
| 4191 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n", |
| 4192 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4193 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4194 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 4195 | } |
| 4196 | } /* end while loop */ |
| 4197 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4198 | else { |
| 4199 | Alert("parsing [%s:%d] : unknown option '%s'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4200 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4201 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4202 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4203 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4204 | } |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 4205 | else if (!strcmp(args[0], "default_backend")) { |
| 4206 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4207 | err_code |= ERR_WARN; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 4208 | |
| 4209 | if (*(args[1]) == 0) { |
| 4210 | 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] | 4211 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4212 | goto out; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 4213 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 4214 | free(curproxy->defbe.name); |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 4215 | curproxy->defbe.name = strdup(args[1]); |
| 4216 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4217 | else if (!strcmp(args[0], "redispatch") || !strcmp(args[0], "redisp")) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4218 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4219 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4220 | |
Willy Tarreau | a3c504c | 2014-04-28 22:37:32 +0200 | [diff] [blame] | 4221 | if (!already_warned(WARN_REDISPATCH_DEPRECATED)) |
| 4222 | Warning("parsing [%s:%d]: keyword '%s' is deprecated in favor of 'option redispatch', and will not be supported by future versions.\n", |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 4223 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4224 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4225 | /* enable reconnections to dispatch */ |
| 4226 | curproxy->options |= PR_O_REDISP; |
| 4227 | } |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 4228 | else if (!strcmp(args[0], "http-check")) { |
| 4229 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4230 | err_code |= ERR_WARN; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 4231 | |
| 4232 | if (strcmp(args[1], "disable-on-404") == 0) { |
| 4233 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 4234 | curproxy->options |= PR_O_DISABLE404; |
| 4235 | } |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 4236 | else if (strcmp(args[1], "send-state") == 0) { |
| 4237 | /* enable emission of the apparent state of a server in HTTP checks */ |
| 4238 | curproxy->options2 |= PR_O2_CHK_SNDST; |
| 4239 | } |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 4240 | else if (strcmp(args[1], "expect") == 0) { |
| 4241 | const char *ptr_arg; |
| 4242 | int cur_arg; |
| 4243 | |
| 4244 | if (curproxy->options2 & PR_O2_EXP_TYPE) { |
| 4245 | Alert("parsing [%s:%d] : '%s %s' already specified.\n", file, linenum, args[0], args[1]); |
| 4246 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4247 | goto out; |
| 4248 | } |
| 4249 | |
| 4250 | cur_arg = 2; |
| 4251 | /* consider exclamation marks, sole or at the beginning of a word */ |
| 4252 | while (*(ptr_arg = args[cur_arg])) { |
| 4253 | while (*ptr_arg == '!') { |
| 4254 | curproxy->options2 ^= PR_O2_EXP_INV; |
| 4255 | ptr_arg++; |
| 4256 | } |
| 4257 | if (*ptr_arg) |
| 4258 | break; |
| 4259 | cur_arg++; |
| 4260 | } |
| 4261 | /* now ptr_arg points to the beginning of a word past any possible |
| 4262 | * exclamation mark, and cur_arg is the argument which holds this word. |
| 4263 | */ |
| 4264 | if (strcmp(ptr_arg, "status") == 0) { |
| 4265 | if (!*(args[cur_arg + 1])) { |
| 4266 | Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 4267 | file, linenum, args[0], args[1], ptr_arg); |
| 4268 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4269 | goto out; |
| 4270 | } |
| 4271 | curproxy->options2 |= PR_O2_EXP_STS; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 4272 | free(curproxy->expect_str); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 4273 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
| 4274 | } |
| 4275 | else if (strcmp(ptr_arg, "string") == 0) { |
| 4276 | if (!*(args[cur_arg + 1])) { |
| 4277 | Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 4278 | file, linenum, args[0], args[1], ptr_arg); |
| 4279 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4280 | goto out; |
| 4281 | } |
| 4282 | curproxy->options2 |= PR_O2_EXP_STR; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 4283 | free(curproxy->expect_str); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 4284 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
| 4285 | } |
| 4286 | else if (strcmp(ptr_arg, "rstatus") == 0) { |
| 4287 | if (!*(args[cur_arg + 1])) { |
| 4288 | Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 4289 | file, linenum, args[0], args[1], ptr_arg); |
| 4290 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4291 | goto out; |
| 4292 | } |
| 4293 | curproxy->options2 |= PR_O2_EXP_RSTS; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 4294 | free(curproxy->expect_str); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 4295 | if (curproxy->expect_regex) { |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 4296 | regex_free(curproxy->expect_regex); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 4297 | free(curproxy->expect_regex); |
| 4298 | curproxy->expect_regex = NULL; |
| 4299 | } |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 4300 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 4301 | curproxy->expect_regex = calloc(1, sizeof(*curproxy->expect_regex)); |
| 4302 | error = NULL; |
| 4303 | if (!regex_comp(args[cur_arg + 1], curproxy->expect_regex, 1, 1, &error)) { |
| 4304 | Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s': %s.\n", |
| 4305 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1], error); |
| 4306 | free(error); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 4307 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4308 | goto out; |
| 4309 | } |
| 4310 | } |
| 4311 | else if (strcmp(ptr_arg, "rstring") == 0) { |
| 4312 | if (!*(args[cur_arg + 1])) { |
| 4313 | Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 4314 | file, linenum, args[0], args[1], ptr_arg); |
| 4315 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4316 | goto out; |
| 4317 | } |
| 4318 | curproxy->options2 |= PR_O2_EXP_RSTR; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 4319 | free(curproxy->expect_str); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 4320 | if (curproxy->expect_regex) { |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 4321 | regex_free(curproxy->expect_regex); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 4322 | free(curproxy->expect_regex); |
| 4323 | curproxy->expect_regex = NULL; |
| 4324 | } |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 4325 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 4326 | curproxy->expect_regex = calloc(1, sizeof(*curproxy->expect_regex)); |
| 4327 | error = NULL; |
| 4328 | if (!regex_comp(args[cur_arg + 1], curproxy->expect_regex, 1, 1, &error)) { |
| 4329 | Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s': %s.\n", |
| 4330 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1], error); |
| 4331 | free(error); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 4332 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4333 | goto out; |
| 4334 | } |
| 4335 | } |
| 4336 | else { |
| 4337 | Alert("parsing [%s:%d] : '%s %s' only supports [!] 'status', 'string', 'rstatus', 'rstring', found '%s'.\n", |
| 4338 | file, linenum, args[0], args[1], ptr_arg); |
| 4339 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4340 | goto out; |
| 4341 | } |
| 4342 | } |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 4343 | else { |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 4344 | 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] | 4345 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4346 | goto out; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 4347 | } |
| 4348 | } |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 4349 | else if (!strcmp(args[0], "tcp-check")) { |
| 4350 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 4351 | err_code |= ERR_WARN; |
| 4352 | |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 4353 | if (strcmp(args[1], "connect") == 0) { |
| 4354 | const char *ptr_arg; |
| 4355 | int cur_arg; |
| 4356 | struct tcpcheck_rule *tcpcheck; |
| 4357 | struct list *l; |
| 4358 | |
| 4359 | /* check if first rule is also a 'connect' action */ |
| 4360 | l = (struct list *)&curproxy->tcpcheck_rules; |
| 4361 | if (l->p != l->n) { |
| 4362 | tcpcheck = (struct tcpcheck_rule *)l->n; |
| 4363 | if (tcpcheck && tcpcheck->action != TCPCHK_ACT_CONNECT) { |
| 4364 | Alert("parsing [%s:%d] : first step MUST also be a 'connect' when there is a 'connect' step in the tcp-check ruleset.\n", |
| 4365 | file, linenum); |
| 4366 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4367 | goto out; |
| 4368 | } |
| 4369 | } |
| 4370 | |
| 4371 | cur_arg = 2; |
| 4372 | tcpcheck = (struct tcpcheck_rule *)calloc(1, sizeof(*tcpcheck)); |
| 4373 | tcpcheck->action = TCPCHK_ACT_CONNECT; |
| 4374 | |
| 4375 | /* parsing each parameters to fill up the rule */ |
| 4376 | while (*(ptr_arg = args[cur_arg])) { |
| 4377 | /* tcp port */ |
| 4378 | if (strcmp(args[cur_arg], "port") == 0) { |
| 4379 | if ( (atol(args[cur_arg + 1]) > 65535) || |
| 4380 | (atol(args[cur_arg + 1]) < 1) ){ |
| 4381 | Alert("parsing [%s:%d] : '%s %s %s' expects a valid TCP port (from range 1 to 65535), got %s.\n", |
| 4382 | file, linenum, args[0], args[1], "port", args[cur_arg + 1]); |
| 4383 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4384 | goto out; |
| 4385 | } |
| 4386 | tcpcheck->port = atol(args[cur_arg + 1]); |
| 4387 | cur_arg += 2; |
| 4388 | } |
| 4389 | /* send proxy protocol */ |
| 4390 | else if (strcmp(args[cur_arg], "send-proxy") == 0) { |
| 4391 | tcpcheck->conn_opts |= TCPCHK_OPT_SEND_PROXY; |
| 4392 | cur_arg++; |
| 4393 | } |
| 4394 | #ifdef USE_OPENSSL |
| 4395 | else if (strcmp(args[cur_arg], "ssl") == 0) { |
| 4396 | curproxy->options |= PR_O_TCPCHK_SSL; |
| 4397 | tcpcheck->conn_opts |= TCPCHK_OPT_SSL; |
| 4398 | cur_arg++; |
| 4399 | } |
| 4400 | #endif /* USE_OPENSSL */ |
| 4401 | else { |
| 4402 | #ifdef USE_OPENSSL |
| 4403 | Alert("parsing [%s:%d] : '%s %s' expects 'port', 'send-proxy' or 'ssl' but got '%s' as argument.\n", |
| 4404 | #else /* USE_OPENSSL */ |
| 4405 | Alert("parsing [%s:%d] : '%s %s' expects 'port', 'send-proxy' or but got '%s' as argument.\n", |
| 4406 | #endif /* USE_OPENSSL */ |
| 4407 | file, linenum, args[0], args[1], args[cur_arg]); |
| 4408 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4409 | goto out; |
| 4410 | } |
| 4411 | |
| 4412 | } |
| 4413 | |
| 4414 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 4415 | } |
| 4416 | else if (strcmp(args[1], "send") == 0) { |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 4417 | if (! *(args[2]) ) { |
| 4418 | /* SEND string expected */ |
| 4419 | Alert("parsing [%s:%d] : '%s %s %s' expects <STRING> as argument.\n", |
| 4420 | file, linenum, args[0], args[1], args[2]); |
| 4421 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4422 | goto out; |
| 4423 | } else { |
| 4424 | struct tcpcheck_rule *tcpcheck; |
| 4425 | |
| 4426 | tcpcheck = (struct tcpcheck_rule *)calloc(1, sizeof(*tcpcheck)); |
| 4427 | |
| 4428 | tcpcheck->action = TCPCHK_ACT_SEND; |
| 4429 | tcpcheck->string_len = strlen(args[2]); |
| 4430 | tcpcheck->string = strdup(args[2]); |
| 4431 | tcpcheck->expect_regex = NULL; |
| 4432 | |
| 4433 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 4434 | } |
| 4435 | } |
| 4436 | else if (strcmp(args[1], "send-binary") == 0) { |
| 4437 | if (! *(args[2]) ) { |
| 4438 | /* SEND binary string expected */ |
| 4439 | Alert("parsing [%s:%d] : '%s %s %s' expects <BINARY STRING> as argument.\n", |
| 4440 | file, linenum, args[0], args[1], args[2]); |
| 4441 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4442 | goto out; |
| 4443 | } else { |
| 4444 | struct tcpcheck_rule *tcpcheck; |
| 4445 | char *err = NULL; |
| 4446 | |
| 4447 | tcpcheck = (struct tcpcheck_rule *)calloc(1, sizeof(*tcpcheck)); |
| 4448 | |
| 4449 | tcpcheck->action = TCPCHK_ACT_SEND; |
| 4450 | if (parse_binary(args[2], &tcpcheck->string, &tcpcheck->string_len, &err) == 0) { |
| 4451 | Alert("parsing [%s:%d] : '%s %s %s' expects <BINARY STRING> as argument, but %s\n", |
| 4452 | file, linenum, args[0], args[1], args[2], err); |
| 4453 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4454 | goto out; |
| 4455 | } |
| 4456 | tcpcheck->expect_regex = NULL; |
| 4457 | |
| 4458 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 4459 | } |
| 4460 | } |
| 4461 | else if (strcmp(args[1], "expect") == 0) { |
| 4462 | const char *ptr_arg; |
| 4463 | int cur_arg; |
| 4464 | int inverse = 0; |
| 4465 | |
| 4466 | if (curproxy->options2 & PR_O2_EXP_TYPE) { |
| 4467 | Alert("parsing [%s:%d] : '%s %s' already specified.\n", file, linenum, args[0], args[1]); |
| 4468 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4469 | goto out; |
| 4470 | } |
| 4471 | |
| 4472 | cur_arg = 2; |
| 4473 | /* consider exclamation marks, sole or at the beginning of a word */ |
| 4474 | while (*(ptr_arg = args[cur_arg])) { |
| 4475 | while (*ptr_arg == '!') { |
| 4476 | inverse = !inverse; |
| 4477 | ptr_arg++; |
| 4478 | } |
| 4479 | if (*ptr_arg) |
| 4480 | break; |
| 4481 | cur_arg++; |
| 4482 | } |
| 4483 | /* now ptr_arg points to the beginning of a word past any possible |
| 4484 | * exclamation mark, and cur_arg is the argument which holds this word. |
| 4485 | */ |
| 4486 | if (strcmp(ptr_arg, "binary") == 0) { |
| 4487 | if (!*(args[cur_arg + 1])) { |
| 4488 | Alert("parsing [%s:%d] : '%s %s %s' expects <binary string> as an argument.\n", |
| 4489 | file, linenum, args[0], args[1], ptr_arg); |
| 4490 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4491 | goto out; |
| 4492 | } |
| 4493 | struct tcpcheck_rule *tcpcheck; |
| 4494 | char *err = NULL; |
| 4495 | |
| 4496 | tcpcheck = (struct tcpcheck_rule *)calloc(1, sizeof(*tcpcheck)); |
| 4497 | |
| 4498 | tcpcheck->action = TCPCHK_ACT_EXPECT; |
| 4499 | if (parse_binary(args[cur_arg + 1], &tcpcheck->string, &tcpcheck->string_len, &err) == 0) { |
| 4500 | Alert("parsing [%s:%d] : '%s %s %s' expects <BINARY STRING> as argument, but %s\n", |
| 4501 | file, linenum, args[0], args[1], args[2], err); |
| 4502 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4503 | goto out; |
| 4504 | } |
| 4505 | tcpcheck->expect_regex = NULL; |
| 4506 | tcpcheck->inverse = inverse; |
| 4507 | |
| 4508 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 4509 | } |
| 4510 | else if (strcmp(ptr_arg, "string") == 0) { |
| 4511 | if (!*(args[cur_arg + 1])) { |
| 4512 | Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 4513 | file, linenum, args[0], args[1], ptr_arg); |
| 4514 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4515 | goto out; |
| 4516 | } |
| 4517 | struct tcpcheck_rule *tcpcheck; |
| 4518 | |
| 4519 | tcpcheck = (struct tcpcheck_rule *)calloc(1, sizeof(*tcpcheck)); |
| 4520 | |
| 4521 | tcpcheck->action = TCPCHK_ACT_EXPECT; |
| 4522 | tcpcheck->string_len = strlen(args[cur_arg + 1]); |
| 4523 | tcpcheck->string = strdup(args[cur_arg + 1]); |
| 4524 | tcpcheck->expect_regex = NULL; |
| 4525 | tcpcheck->inverse = inverse; |
| 4526 | |
| 4527 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 4528 | } |
| 4529 | else if (strcmp(ptr_arg, "rstring") == 0) { |
| 4530 | if (!*(args[cur_arg + 1])) { |
| 4531 | Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 4532 | file, linenum, args[0], args[1], ptr_arg); |
| 4533 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4534 | goto out; |
| 4535 | } |
| 4536 | struct tcpcheck_rule *tcpcheck; |
| 4537 | |
| 4538 | tcpcheck = (struct tcpcheck_rule *)calloc(1, sizeof(*tcpcheck)); |
| 4539 | |
| 4540 | tcpcheck->action = TCPCHK_ACT_EXPECT; |
| 4541 | tcpcheck->string_len = 0; |
| 4542 | tcpcheck->string = NULL; |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 4543 | tcpcheck->expect_regex = calloc(1, sizeof(*tcpcheck->expect_regex)); |
| 4544 | error = NULL; |
| 4545 | if (!regex_comp(args[cur_arg + 1], tcpcheck->expect_regex, 1, 1, &error)) { |
| 4546 | Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s': %s.\n", |
| 4547 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1], error); |
| 4548 | free(error); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 4549 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4550 | goto out; |
| 4551 | } |
| 4552 | tcpcheck->inverse = inverse; |
| 4553 | |
| 4554 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 4555 | } |
| 4556 | else { |
| 4557 | Alert("parsing [%s:%d] : '%s %s' only supports [!] 'binary', 'string', 'rstring', found '%s'.\n", |
| 4558 | file, linenum, args[0], args[1], ptr_arg); |
| 4559 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4560 | goto out; |
| 4561 | } |
| 4562 | } |
| 4563 | else { |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 4564 | Alert("parsing [%s:%d] : '%s' only supports 'connect', 'send' or 'expect'.\n", file, linenum, args[0]); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 4565 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4566 | goto out; |
| 4567 | } |
| 4568 | } |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 4569 | else if (!strcmp(args[0], "monitor")) { |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 4570 | if (curproxy == &defproxy) { |
| 4571 | 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] | 4572 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4573 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 4574 | } |
| 4575 | |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 4576 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4577 | err_code |= ERR_WARN; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 4578 | |
| 4579 | if (strcmp(args[1], "fail") == 0) { |
| 4580 | /* add a condition to fail monitor requests */ |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 4581 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 4582 | Alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n", |
| 4583 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4584 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4585 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 4586 | } |
| 4587 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 4588 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 4589 | Alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition : %s.\n", |
| 4590 | file, linenum, args[0], args[1], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4591 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4592 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 4593 | } |
| 4594 | LIST_ADDQ(&curproxy->mon_fail_cond, &cond->list); |
| 4595 | } |
| 4596 | else { |
| 4597 | 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] | 4598 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4599 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 4600 | } |
| 4601 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4602 | #ifdef TPROXY |
| 4603 | else if (!strcmp(args[0], "transparent")) { |
| 4604 | /* enable transparent proxy connections */ |
| 4605 | curproxy->options |= PR_O_TRANSP; |
| 4606 | } |
| 4607 | #endif |
| 4608 | else if (!strcmp(args[0], "maxconn")) { /* maxconn */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4609 | 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] | 4610 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4611 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4612 | if (*(args[1]) == 0) { |
| 4613 | 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] | 4614 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4615 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4616 | } |
| 4617 | curproxy->maxconn = atol(args[1]); |
| 4618 | } |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 4619 | else if (!strcmp(args[0], "backlog")) { /* backlog */ |
| 4620 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4621 | err_code |= ERR_WARN; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 4622 | |
| 4623 | if (*(args[1]) == 0) { |
| 4624 | 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] | 4625 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4626 | goto out; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 4627 | } |
| 4628 | curproxy->backlog = atol(args[1]); |
| 4629 | } |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 4630 | else if (!strcmp(args[0], "fullconn")) { /* fullconn */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4631 | 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] | 4632 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4633 | |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 4634 | if (*(args[1]) == 0) { |
| 4635 | 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] | 4636 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4637 | goto out; |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 4638 | } |
| 4639 | curproxy->fullconn = atol(args[1]); |
| 4640 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4641 | else if (!strcmp(args[0], "grace")) { /* grace time (ms) */ |
| 4642 | if (*(args[1]) == 0) { |
| 4643 | 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] | 4644 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4645 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4646 | } |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4647 | err = parse_time_err(args[1], &val, TIME_UNIT_MS); |
| 4648 | if (err) { |
| 4649 | Alert("parsing [%s:%d] : unexpected character '%c' in grace time.\n", |
| 4650 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4651 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4652 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4653 | } |
| 4654 | curproxy->grace = val; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4655 | } |
| 4656 | else if (!strcmp(args[0], "dispatch")) { /* dispatch address */ |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4657 | struct sockaddr_storage *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4658 | int port1, port2; |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 4659 | struct protocol *proto; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4660 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4661 | if (curproxy == &defproxy) { |
| 4662 | 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] | 4663 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4664 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4665 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4666 | else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4667 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4668 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 4669 | sk = str2sa_range(args[1], &port1, &port2, &errmsg, NULL); |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4670 | if (!sk) { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 4671 | Alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 4672 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 4673 | goto out; |
| 4674 | } |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 4675 | |
| 4676 | proto = protocol_by_family(sk->ss_family); |
| 4677 | if (!proto || !proto->connect) { |
| 4678 | Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 4679 | file, linenum, args[0], args[1]); |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4680 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4681 | goto out; |
| 4682 | } |
| 4683 | |
| 4684 | if (port1 != port2) { |
| 4685 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'.\n", |
| 4686 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4687 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4688 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4689 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4690 | |
| 4691 | if (!port1) { |
| 4692 | Alert("parsing [%s:%d] : '%s' : missing port number in '%s', <addr:port> expected.\n", |
| 4693 | file, linenum, args[0], args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4694 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4695 | goto out; |
| 4696 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4697 | |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4698 | curproxy->dispatch_addr = *sk; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4699 | curproxy->options |= PR_O_DISPATCH; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4700 | } |
| 4701 | else if (!strcmp(args[0], "balance")) { /* set balancing with optional algorithm */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4702 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4703 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4704 | |
Willy Tarreau | a93c74b | 2012-05-08 18:14:39 +0200 | [diff] [blame] | 4705 | if (backend_parse_balance((const char **)args + 1, &errmsg, curproxy) < 0) { |
| 4706 | Alert("parsing [%s:%d] : %s %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4707 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4708 | goto out; |
Willy Tarreau | 2fcb500 | 2007-05-08 13:35:26 +0200 | [diff] [blame] | 4709 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4710 | } |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 4711 | else if (!strcmp(args[0], "hash-type")) { /* set hashing method */ |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 4712 | /** |
| 4713 | * The syntax for hash-type config element is |
| 4714 | * hash-type {map-based|consistent} [[<algo>] avalanche] |
| 4715 | * |
| 4716 | * The default hash function is sdbm for map-based and sdbm+avalanche for consistent. |
| 4717 | */ |
| 4718 | curproxy->lbprm.algo &= ~(BE_LB_HASH_TYPE | BE_LB_HASH_FUNC | BE_LB_HASH_MOD); |
Bhaskar | 98634f0 | 2013-10-29 23:30:51 -0400 | [diff] [blame] | 4719 | |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 4720 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 4721 | err_code |= ERR_WARN; |
| 4722 | |
| 4723 | if (strcmp(args[1], "consistent") == 0) { /* use consistent hashing */ |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 4724 | curproxy->lbprm.algo |= BE_LB_HASH_CONS; |
| 4725 | } |
| 4726 | else if (strcmp(args[1], "map-based") == 0) { /* use map-based hashing */ |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 4727 | curproxy->lbprm.algo |= BE_LB_HASH_MAP; |
| 4728 | } |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 4729 | else if (strcmp(args[1], "avalanche") == 0) { |
| 4730 | Alert("parsing [%s:%d] : experimental feature '%s %s' is not supported anymore, please use '%s map-based sdbm avalanche' instead.\n", file, linenum, args[0], args[1], args[0]); |
| 4731 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4732 | goto out; |
Willy Tarreau | 798a39c | 2010-11-24 15:04:29 +0100 | [diff] [blame] | 4733 | } |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 4734 | else { |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 4735 | Alert("parsing [%s:%d] : '%s' only supports 'consistent' and 'map-based'.\n", file, linenum, args[0]); |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 4736 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4737 | goto out; |
| 4738 | } |
Bhaskar | 98634f0 | 2013-10-29 23:30:51 -0400 | [diff] [blame] | 4739 | |
| 4740 | /* set the hash function to use */ |
| 4741 | if (!*args[2]) { |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 4742 | /* the default algo is sdbm */ |
Bhaskar | 98634f0 | 2013-10-29 23:30:51 -0400 | [diff] [blame] | 4743 | curproxy->lbprm.algo |= BE_LB_HFCN_SDBM; |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 4744 | |
| 4745 | /* if consistent with no argument, then avalanche modifier is also applied */ |
| 4746 | if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS) |
| 4747 | curproxy->lbprm.algo |= BE_LB_HMOD_AVAL; |
Bhaskar | 98634f0 | 2013-10-29 23:30:51 -0400 | [diff] [blame] | 4748 | } else { |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 4749 | /* set the hash function */ |
| 4750 | if (!strcmp(args[2], "sdbm")) { |
| 4751 | curproxy->lbprm.algo |= BE_LB_HFCN_SDBM; |
| 4752 | } |
| 4753 | else if (!strcmp(args[2], "djb2")) { |
| 4754 | curproxy->lbprm.algo |= BE_LB_HFCN_DJB2; |
Willy Tarreau | a0f4271 | 2013-11-14 14:30:35 +0100 | [diff] [blame] | 4755 | } else if (!strcmp(args[2], "wt6")) { |
| 4756 | curproxy->lbprm.algo |= BE_LB_HFCN_WT6; |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 4757 | } |
| 4758 | else { |
Willy Tarreau | a0f4271 | 2013-11-14 14:30:35 +0100 | [diff] [blame] | 4759 | Alert("parsing [%s:%d] : '%s' only supports 'sdbm', 'djb2' or 'wt6' hash functions.\n", file, linenum, args[0]); |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 4760 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4761 | goto out; |
| 4762 | } |
| 4763 | |
| 4764 | /* set the hash modifier */ |
| 4765 | if (!strcmp(args[3], "avalanche")) { |
| 4766 | curproxy->lbprm.algo |= BE_LB_HMOD_AVAL; |
| 4767 | } |
| 4768 | else if (*args[3]) { |
| 4769 | Alert("parsing [%s:%d] : '%s' only supports 'avalanche' as a modifier for hash functions.\n", file, linenum, args[0]); |
| 4770 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4771 | goto out; |
| 4772 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4773 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 4774 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 4775 | else if (strcmp(args[0], "unique-id-format") == 0) { |
| 4776 | if (!*(args[1])) { |
| 4777 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 4778 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4779 | goto out; |
| 4780 | } |
William Lallemand | 3203ff4 | 2012-11-11 17:30:56 +0100 | [diff] [blame] | 4781 | if (*(args[2])) { |
| 4782 | Alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]); |
| 4783 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4784 | goto out; |
| 4785 | } |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 4786 | free(curproxy->conf.uniqueid_format_string); |
| 4787 | curproxy->conf.uniqueid_format_string = strdup(args[1]); |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 4788 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 4789 | free(curproxy->conf.uif_file); |
| 4790 | curproxy->conf.uif_file = strdup(curproxy->conf.args.file); |
| 4791 | curproxy->conf.uif_line = curproxy->conf.args.line; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4792 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 4793 | |
| 4794 | else if (strcmp(args[0], "unique-id-header") == 0) { |
| 4795 | if (!*(args[1])) { |
| 4796 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 4797 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4798 | goto out; |
| 4799 | } |
| 4800 | free(curproxy->header_unique_id); |
| 4801 | curproxy->header_unique_id = strdup(args[1]); |
| 4802 | } |
| 4803 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4804 | else if (strcmp(args[0], "log-format") == 0) { |
| 4805 | if (!*(args[1])) { |
| 4806 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 4807 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4808 | goto out; |
| 4809 | } |
William Lallemand | 3203ff4 | 2012-11-11 17:30:56 +0100 | [diff] [blame] | 4810 | if (*(args[2])) { |
| 4811 | Alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]); |
| 4812 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4813 | goto out; |
| 4814 | } |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 4815 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 4816 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 4817 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 4818 | curproxy->conf.logformat_string != clf_http_log_format) |
| 4819 | free(curproxy->conf.logformat_string); |
| 4820 | curproxy->conf.logformat_string = strdup(args[1]); |
| 4821 | |
| 4822 | free(curproxy->conf.lfs_file); |
| 4823 | curproxy->conf.lfs_file = strdup(curproxy->conf.args.file); |
| 4824 | curproxy->conf.lfs_line = curproxy->conf.args.line; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 4825 | |
| 4826 | /* get a chance to improve log-format error reporting by |
| 4827 | * reporting the correct line-number when possible. |
| 4828 | */ |
| 4829 | if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) { |
| 4830 | Warning("parsing [%s:%d] : backend '%s' : 'log-format' directive is ignored in backends.\n", |
| 4831 | file, linenum, curproxy->id); |
| 4832 | err_code |= ERR_WARN; |
| 4833 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4834 | } |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4835 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4836 | else if (!strcmp(args[0], "log") && kwm == KWM_NO) { |
| 4837 | /* delete previous herited or defined syslog servers */ |
| 4838 | struct logsrv *back; |
| 4839 | |
| 4840 | if (*(args[1]) != 0) { |
| 4841 | Alert("parsing [%s:%d]:%s : 'no log' does not expect arguments.\n", file, linenum, args[1]); |
| 4842 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4843 | goto out; |
| 4844 | } |
| 4845 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4846 | list_for_each_entry_safe(tmplogsrv, back, &curproxy->logsrvs, list) { |
| 4847 | LIST_DEL(&tmplogsrv->list); |
| 4848 | free(tmplogsrv); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4849 | } |
| 4850 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4851 | else if (!strcmp(args[0], "log")) { /* syslog server address */ |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4852 | struct logsrv *logsrv; |
| 4853 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4854 | if (*(args[1]) && *(args[2]) == 0 && !strcmp(args[1], "global")) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4855 | /* copy global.logrsvs linked list to the end of curproxy->logsrvs */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4856 | list_for_each_entry(tmplogsrv, &global.logsrvs, list) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4857 | struct logsrv *node = malloc(sizeof(struct logsrv)); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4858 | memcpy(node, tmplogsrv, sizeof(struct logsrv)); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4859 | LIST_INIT(&node->list); |
| 4860 | LIST_ADDQ(&curproxy->logsrvs, &node->list); |
| 4861 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4862 | } |
| 4863 | else if (*(args[1]) && *(args[2])) { |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 4864 | struct sockaddr_storage *sk; |
| 4865 | int port1, port2; |
Willy Tarreau | dc2695c | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 4866 | int arg = 0; |
| 4867 | int len = 0; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4868 | |
| 4869 | logsrv = calloc(1, sizeof(struct logsrv)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4870 | |
Willy Tarreau | dc2695c | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 4871 | /* just after the address, a length may be specified */ |
| 4872 | if (strcmp(args[arg+2], "len") == 0) { |
| 4873 | len = atoi(args[arg+3]); |
| 4874 | if (len < 80 || len > 65535) { |
| 4875 | Alert("parsing [%s:%d] : invalid log length '%s', must be between 80 and 65535.\n", |
| 4876 | file, linenum, args[arg+3]); |
| 4877 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4878 | goto out; |
| 4879 | } |
| 4880 | logsrv->maxlen = len; |
| 4881 | |
| 4882 | /* skip these two args */ |
| 4883 | arg += 2; |
| 4884 | } |
| 4885 | else |
| 4886 | logsrv->maxlen = MAX_SYSLOG_LEN; |
| 4887 | |
| 4888 | if (logsrv->maxlen > global.max_syslog_len) { |
| 4889 | global.max_syslog_len = logsrv->maxlen; |
| 4890 | logline = realloc(logline, global.max_syslog_len + 1); |
| 4891 | } |
| 4892 | |
| 4893 | logsrv->facility = get_log_facility(args[arg+2]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4894 | if (logsrv->facility < 0) { |
Willy Tarreau | dc2695c | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 4895 | Alert("parsing [%s:%d] : unknown log facility '%s'\n", file, linenum, args[arg+2]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4896 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4897 | goto out; |
| 4898 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4899 | } |
| 4900 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4901 | logsrv->level = 7; /* max syslog level = debug */ |
Willy Tarreau | dc2695c | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 4902 | if (*(args[arg+3])) { |
| 4903 | logsrv->level = get_log_level(args[arg+3]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4904 | if (logsrv->level < 0) { |
Willy Tarreau | dc2695c | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 4905 | Alert("parsing [%s:%d] : unknown optional log level '%s'\n", file, linenum, args[arg+3]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4906 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4907 | goto out; |
| 4908 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4909 | } |
| 4910 | } |
| 4911 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4912 | logsrv->minlvl = 0; /* limit syslog level to this level (emerg) */ |
Willy Tarreau | dc2695c | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 4913 | if (*(args[arg+4])) { |
| 4914 | logsrv->minlvl = get_log_level(args[arg+4]); |
Willy Tarreau | f7f057b | 2013-01-24 00:31:24 +0100 | [diff] [blame] | 4915 | if (logsrv->minlvl < 0) { |
Willy Tarreau | dc2695c | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 4916 | Alert("parsing [%s:%d] : unknown optional minimum log level '%s'\n", file, linenum, args[arg+4]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4917 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4918 | goto out; |
| 4919 | |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 4920 | } |
| 4921 | } |
| 4922 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 4923 | sk = str2sa_range(args[1], &port1, &port2, &errmsg, NULL); |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 4924 | if (!sk) { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 4925 | Alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 4926 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 4927 | goto out; |
| 4928 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4929 | |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 4930 | logsrv->addr = *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4931 | |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 4932 | if (sk->ss_family == AF_INET || sk->ss_family == AF_INET6) { |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4933 | if (port1 != port2) { |
| 4934 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 4935 | file, linenum, args[0], args[1]); |
| 4936 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4937 | goto out; |
| 4938 | } |
| 4939 | |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4940 | if (!port1) |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4941 | set_host_port(&logsrv->addr, SYSLOG_PORT); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4942 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4943 | |
| 4944 | LIST_ADDQ(&curproxy->logsrvs, &logsrv->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4945 | } |
| 4946 | else { |
| 4947 | Alert("parsing [%s:%d] : 'log' expects either <address[:port]> and <facility> or 'global' as arguments.\n", |
| 4948 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4949 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4950 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4951 | } |
| 4952 | } |
| 4953 | 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] | 4954 | int cur_arg; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4955 | int port1, port2; |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4956 | struct sockaddr_storage *sk; |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 4957 | struct protocol *proto; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4958 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4959 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4960 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4961 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4962 | if (!*args[1]) { |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4963 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optionally '%s' <addr>, and '%s' <name>.\n", |
| 4964 | file, linenum, "source", "usesrc", "interface"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4965 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4966 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4967 | } |
Willy Tarreau | 368480c | 2009-03-01 08:27:21 +0100 | [diff] [blame] | 4968 | |
| 4969 | /* we must first clear any optional default setting */ |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4970 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 4971 | free(curproxy->conn_src.iface_name); |
| 4972 | curproxy->conn_src.iface_name = NULL; |
| 4973 | curproxy->conn_src.iface_len = 0; |
Willy Tarreau | 368480c | 2009-03-01 08:27:21 +0100 | [diff] [blame] | 4974 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 4975 | sk = str2sa_range(args[1], &port1, &port2, &errmsg, NULL); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4976 | if (!sk) { |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 4977 | Alert("parsing [%s:%d] : '%s %s' : %s\n", |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 4978 | file, linenum, args[0], args[1], errmsg); |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 4979 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 4980 | goto out; |
| 4981 | } |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 4982 | |
| 4983 | proto = protocol_by_family(sk->ss_family); |
| 4984 | if (!proto || !proto->connect) { |
| 4985 | 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] | 4986 | file, linenum, args[0], args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4987 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4988 | goto out; |
| 4989 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4990 | |
| 4991 | if (port1 != port2) { |
| 4992 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 4993 | file, linenum, args[0], args[1]); |
| 4994 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4995 | goto out; |
| 4996 | } |
| 4997 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4998 | curproxy->conn_src.source_addr = *sk; |
| 4999 | curproxy->conn_src.opts |= CO_SRC_BIND; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5000 | |
| 5001 | cur_arg = 2; |
| 5002 | while (*(args[cur_arg])) { |
| 5003 | if (!strcmp(args[cur_arg], "usesrc")) { /* address to use outside */ |
Pieter Baauw | d551fb5 | 2013-05-08 22:49:23 +0200 | [diff] [blame] | 5004 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_TRANSPARENT) |
| 5005 | #if !defined(CONFIG_HAP_TRANSPARENT) |
Willy Tarreau | 9cf8d3f | 2014-05-09 22:56:10 +0200 | [diff] [blame] | 5006 | if (!is_inet_addr(&curproxy->conn_src.source_addr)) { |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5007 | Alert("parsing [%s:%d] : '%s' requires an explicit 'source' address.\n", |
| 5008 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5009 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5010 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5011 | } |
| 5012 | #endif |
| 5013 | if (!*args[cur_arg + 1]) { |
| 5014 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n", |
| 5015 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5016 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5017 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5018 | } |
| 5019 | |
| 5020 | if (!strcmp(args[cur_arg + 1], "client")) { |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 5021 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 5022 | curproxy->conn_src.opts |= CO_SRC_TPROXY_CLI; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5023 | } else if (!strcmp(args[cur_arg + 1], "clientip")) { |
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_CIP; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 5026 | } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) { |
| 5027 | char *name, *end; |
| 5028 | |
| 5029 | name = args[cur_arg+1] + 7; |
| 5030 | while (isspace(*name)) |
| 5031 | name++; |
| 5032 | |
| 5033 | end = name; |
| 5034 | while (*end && !isspace(*end) && *end != ',' && *end != ')') |
| 5035 | end++; |
| 5036 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 5037 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 5038 | curproxy->conn_src.opts |= CO_SRC_TPROXY_DYN; |
| 5039 | curproxy->conn_src.bind_hdr_name = calloc(1, end - name + 1); |
| 5040 | curproxy->conn_src.bind_hdr_len = end - name; |
| 5041 | memcpy(curproxy->conn_src.bind_hdr_name, name, end - name); |
| 5042 | curproxy->conn_src.bind_hdr_name[end-name] = '\0'; |
| 5043 | curproxy->conn_src.bind_hdr_occ = -1; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 5044 | |
| 5045 | /* now look for an occurrence number */ |
| 5046 | while (isspace(*end)) |
| 5047 | end++; |
| 5048 | if (*end == ',') { |
| 5049 | end++; |
| 5050 | name = end; |
| 5051 | if (*end == '-') |
| 5052 | end++; |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 5053 | while (isdigit((int)*end)) |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 5054 | end++; |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 5055 | curproxy->conn_src.bind_hdr_occ = strl2ic(name, end-name); |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 5056 | } |
| 5057 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 5058 | if (curproxy->conn_src.bind_hdr_occ < -MAX_HDR_HISTORY) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 5059 | Alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative" |
| 5060 | " occurrences values smaller than %d.\n", |
| 5061 | file, linenum, MAX_HDR_HISTORY); |
| 5062 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5063 | goto out; |
| 5064 | } |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5065 | } else { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 5066 | struct sockaddr_storage *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5067 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 5068 | sk = str2sa_range(args[cur_arg + 1], &port1, &port2, &errmsg, NULL); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 5069 | if (!sk) { |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 5070 | Alert("parsing [%s:%d] : '%s %s' : %s\n", |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 5071 | file, linenum, args[cur_arg], args[cur_arg+1], errmsg); |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 5072 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 5073 | goto out; |
| 5074 | } |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 5075 | |
| 5076 | proto = protocol_by_family(sk->ss_family); |
| 5077 | if (!proto || !proto->connect) { |
| 5078 | Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 5079 | file, linenum, args[cur_arg], args[cur_arg+1]); |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5080 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5081 | goto out; |
| 5082 | } |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 5083 | |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5084 | if (port1 != port2) { |
| 5085 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 5086 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 5087 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5088 | goto out; |
| 5089 | } |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 5090 | curproxy->conn_src.tproxy_addr = *sk; |
| 5091 | curproxy->conn_src.opts |= CO_SRC_TPROXY_ADDR; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5092 | } |
| 5093 | global.last_checks |= LSTCHK_NETADM; |
Pieter Baauw | d551fb5 | 2013-05-08 22:49:23 +0200 | [diff] [blame] | 5094 | #if !defined(CONFIG_HAP_TRANSPARENT) |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5095 | global.last_checks |= LSTCHK_CTTPROXY; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 5096 | #endif |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5097 | #else /* no TPROXY support */ |
| 5098 | 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] | 5099 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5100 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5101 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5102 | #endif |
| 5103 | cur_arg += 2; |
| 5104 | continue; |
Willy Tarreau | 77074d5 | 2006-11-12 23:57:19 +0100 | [diff] [blame] | 5105 | } |
| 5106 | |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5107 | if (!strcmp(args[cur_arg], "interface")) { /* specifically bind to this interface */ |
| 5108 | #ifdef SO_BINDTODEVICE |
| 5109 | if (!*args[cur_arg + 1]) { |
| 5110 | Alert("parsing [%s:%d] : '%s' : missing interface name.\n", |
| 5111 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5112 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5113 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5114 | } |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 5115 | free(curproxy->conn_src.iface_name); |
| 5116 | curproxy->conn_src.iface_name = strdup(args[cur_arg + 1]); |
| 5117 | curproxy->conn_src.iface_len = strlen(curproxy->conn_src.iface_name); |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5118 | global.last_checks |= LSTCHK_NETADM; |
| 5119 | #else |
| 5120 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 5121 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5122 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5123 | goto out; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 5124 | #endif |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5125 | cur_arg += 2; |
| 5126 | continue; |
| 5127 | } |
| 5128 | 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] | 5129 | file, linenum, args[0], "interface", "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5130 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5131 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 5132 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5133 | } |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 5134 | else if (!strcmp(args[0], "usesrc")) { /* address to use outside: needs "source" first */ |
| 5135 | Alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n", |
| 5136 | file, linenum, "usesrc", "source"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5137 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5138 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 5139 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5140 | 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] | 5141 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5142 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 5143 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5144 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5145 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5146 | } |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5147 | |
| 5148 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5149 | SMP_OPT_DIR_REQ, ACT_REPLACE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5150 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5151 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5152 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5153 | } |
| 5154 | else if (!strcmp(args[0], "reqdel")) { /* delete request header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5155 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5156 | SMP_OPT_DIR_REQ, ACT_REMOVE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5157 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5158 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5159 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5160 | } |
| 5161 | 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] | 5162 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5163 | SMP_OPT_DIR_REQ, ACT_DENY, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5164 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5165 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5166 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5167 | } |
| 5168 | 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] | 5169 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5170 | SMP_OPT_DIR_REQ, ACT_PASS, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5171 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5172 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5173 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5174 | } |
| 5175 | 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] | 5176 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5177 | SMP_OPT_DIR_REQ, ACT_ALLOW, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5178 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5179 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5180 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5181 | } |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 5182 | 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] | 5183 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5184 | SMP_OPT_DIR_REQ, ACT_TARPIT, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5185 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5186 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5187 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 5188 | } |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5189 | 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] | 5190 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5191 | SMP_OPT_DIR_REQ, ACT_SETBE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5192 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5193 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5194 | goto out; |
Willy Tarreau | 40bac83 | 2014-04-28 22:37:06 +0200 | [diff] [blame] | 5195 | |
| 5196 | if (!already_warned(WARN_REQSETBE_DEPRECATED)) |
| 5197 | Warning("parsing [%s:%d] : The '%s' directive is now deprecated in favor of the more efficient 'use_backend' which uses a different but more powerful syntax. Future versions will not support '%s' anymore, you should convert it now!\n", file, linenum, args[0], args[0]); |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5198 | } |
| 5199 | 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] | 5200 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5201 | SMP_OPT_DIR_REQ, ACT_SETBE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5202 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5203 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5204 | goto out; |
Willy Tarreau | 40bac83 | 2014-04-28 22:37:06 +0200 | [diff] [blame] | 5205 | |
| 5206 | if (!already_warned(WARN_REQSETBE_DEPRECATED)) |
| 5207 | Warning("parsing [%s:%d] : The '%s' directive is now deprecated in favor of the more efficient 'use_backend' which uses a different but more powerful syntax. Future versions will not support '%s' anymore, you should convert it now!\n", file, linenum, args[0], args[0]); |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5208 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5209 | 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] | 5210 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5211 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 5212 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5213 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5214 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5215 | } |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5216 | |
| 5217 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5218 | SMP_OPT_DIR_REQ, ACT_REPLACE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5219 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5220 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5221 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5222 | } |
| 5223 | 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] | 5224 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5225 | SMP_OPT_DIR_REQ, ACT_REMOVE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5226 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5227 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5228 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5229 | } |
| 5230 | 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] | 5231 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5232 | SMP_OPT_DIR_REQ, ACT_DENY, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5233 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5234 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5235 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5236 | } |
| 5237 | 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] | 5238 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5239 | SMP_OPT_DIR_REQ, ACT_PASS, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5240 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5241 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5242 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5243 | } |
| 5244 | 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] | 5245 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5246 | SMP_OPT_DIR_REQ, ACT_ALLOW, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5247 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5248 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5249 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5250 | } |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 5251 | 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] | 5252 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5253 | SMP_OPT_DIR_REQ, ACT_TARPIT, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5254 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5255 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5256 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 5257 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5258 | else if (!strcmp(args[0], "reqadd")) { /* add request header */ |
Willy Tarreau | f4f0412 | 2010-01-28 18:10:50 +0100 | [diff] [blame] | 5259 | struct cond_wordlist *wl; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5260 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5261 | if (curproxy == &defproxy) { |
| 5262 | 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] | 5263 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5264 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5265 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5266 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5267 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5268 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5269 | if (*(args[1]) == 0) { |
| 5270 | 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] | 5271 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5272 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5273 | } |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5274 | |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 5275 | if ((strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0)) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 5276 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args+2, &errmsg)) == NULL) { |
| 5277 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 5278 | file, linenum, args[0], errmsg); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 5279 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5280 | goto out; |
| 5281 | } |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 5282 | err_code |= warnif_cond_conflicts(cond, |
| 5283 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 5284 | file, linenum); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 5285 | } |
| 5286 | else if (*args[2]) { |
| 5287 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 5288 | file, linenum, args[0], args[2]); |
| 5289 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5290 | goto out; |
| 5291 | } |
| 5292 | |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5293 | wl = calloc(1, sizeof(*wl)); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 5294 | wl->cond = cond; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5295 | wl->s = strdup(args[1]); |
| 5296 | LIST_ADDQ(&curproxy->req_add, &wl->list); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 5297 | warnif_misplaced_reqadd(curproxy, file, linenum, args[0]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5298 | } |
| 5299 | 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] | 5300 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5301 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 5302 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5303 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5304 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5305 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5306 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5307 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5308 | SMP_OPT_DIR_RES, ACT_REPLACE, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5309 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5310 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5311 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5312 | } |
| 5313 | else if (!strcmp(args[0], "rspdel")) { /* delete response header from a regex */ |
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_REMOVE, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5316 | args[0], args[1], NULL, (const char **)args+2); |
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], "rspdeny")) { /* block response header from a regex */ |
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_DENY, 0, |
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], "rspirep")) { /* replace response header from a regex ignoring case */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5328 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5329 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 5330 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5331 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5332 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5333 | } |
| 5334 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5335 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5336 | SMP_OPT_DIR_RES, ACT_REPLACE, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5337 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5338 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5339 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5340 | } |
| 5341 | 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] | 5342 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5343 | SMP_OPT_DIR_RES, ACT_REMOVE, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5344 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5345 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5346 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5347 | } |
| 5348 | 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] | 5349 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5350 | SMP_OPT_DIR_RES, ACT_DENY, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5351 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5352 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5353 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5354 | } |
| 5355 | else if (!strcmp(args[0], "rspadd")) { /* add response header */ |
Willy Tarreau | f4f0412 | 2010-01-28 18:10:50 +0100 | [diff] [blame] | 5356 | struct cond_wordlist *wl; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5357 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5358 | if (curproxy == &defproxy) { |
| 5359 | 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] | 5360 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5361 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5362 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5363 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5364 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5365 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5366 | if (*(args[1]) == 0) { |
| 5367 | 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] | 5368 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5369 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5370 | } |
| 5371 | |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5372 | if ((strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0)) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 5373 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args+2, &errmsg)) == NULL) { |
| 5374 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 5375 | file, linenum, args[0], errmsg); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5376 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5377 | goto out; |
| 5378 | } |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 5379 | err_code |= warnif_cond_conflicts(cond, |
| 5380 | (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR, |
| 5381 | file, linenum); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5382 | } |
| 5383 | else if (*args[2]) { |
| 5384 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 5385 | file, linenum, args[0], args[2]); |
| 5386 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5387 | goto out; |
| 5388 | } |
| 5389 | |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5390 | wl = calloc(1, sizeof(*wl)); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5391 | wl->cond = cond; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5392 | wl->s = strdup(args[1]); |
| 5393 | LIST_ADDQ(&curproxy->rsp_add, &wl->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5394 | } |
| 5395 | else if (!strcmp(args[0], "errorloc") || |
| 5396 | !strcmp(args[0], "errorloc302") || |
| 5397 | !strcmp(args[0], "errorloc303")) { /* error location */ |
| 5398 | int errnum, errlen; |
| 5399 | char *err; |
| 5400 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5401 | 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] | 5402 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5403 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5404 | if (*(args[2]) == 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 5405 | 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] | 5406 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5407 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5408 | } |
| 5409 | |
| 5410 | errnum = atol(args[1]); |
| 5411 | if (!strcmp(args[0], "errorloc303")) { |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 5412 | errlen = strlen(HTTP_303) + strlen(args[2]) + 5; |
| 5413 | err = malloc(errlen); |
| 5414 | errlen = snprintf(err, errlen, "%s%s\r\n\r\n", HTTP_303, args[2]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5415 | } else { |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 5416 | errlen = strlen(HTTP_302) + strlen(args[2]) + 5; |
| 5417 | err = malloc(errlen); |
| 5418 | errlen = snprintf(err, errlen, "%s%s\r\n\r\n", HTTP_302, args[2]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5419 | } |
| 5420 | |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 5421 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) { |
| 5422 | if (http_err_codes[rc] == errnum) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 5423 | chunk_destroy(&curproxy->errmsg[rc]); |
| 5424 | chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 5425 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5426 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5427 | } |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 5428 | |
| 5429 | if (rc >= HTTP_ERR_SIZE) { |
| 5430 | Warning("parsing [%s:%d] : status code %d not handled, error relocation will be ignored.\n", |
| 5431 | file, linenum, errnum); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5432 | free(err); |
| 5433 | } |
| 5434 | } |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5435 | else if (!strcmp(args[0], "errorfile")) { /* error message from a file */ |
| 5436 | int errnum, errlen, fd; |
| 5437 | char *err; |
| 5438 | struct stat stat; |
| 5439 | |
| 5440 | 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] | 5441 | err_code |= ERR_WARN; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5442 | |
| 5443 | if (*(args[2]) == 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 5444 | 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] | 5445 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5446 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5447 | } |
| 5448 | |
| 5449 | fd = open(args[2], O_RDONLY); |
| 5450 | if ((fd < 0) || (fstat(fd, &stat) < 0)) { |
| 5451 | Alert("parsing [%s:%d] : error opening file <%s> for custom error message <%s>.\n", |
| 5452 | file, linenum, args[2], args[1]); |
| 5453 | if (fd >= 0) |
| 5454 | close(fd); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5455 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5456 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5457 | } |
| 5458 | |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 5459 | if (stat.st_size <= global.tune.bufsize) { |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5460 | errlen = stat.st_size; |
| 5461 | } else { |
| 5462 | 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] | 5463 | file, linenum, args[2], global.tune.bufsize); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5464 | err_code |= ERR_WARN; |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 5465 | errlen = global.tune.bufsize; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5466 | } |
| 5467 | |
| 5468 | err = malloc(errlen); /* malloc() must succeed during parsing */ |
| 5469 | errnum = read(fd, err, errlen); |
| 5470 | if (errnum != errlen) { |
| 5471 | Alert("parsing [%s:%d] : error reading file <%s> for custom error message <%s>.\n", |
| 5472 | file, linenum, args[2], args[1]); |
| 5473 | close(fd); |
| 5474 | free(err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5475 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5476 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5477 | } |
| 5478 | close(fd); |
| 5479 | |
| 5480 | errnum = atol(args[1]); |
| 5481 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) { |
| 5482 | if (http_err_codes[rc] == errnum) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 5483 | chunk_destroy(&curproxy->errmsg[rc]); |
| 5484 | chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen); |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5485 | break; |
| 5486 | } |
| 5487 | } |
| 5488 | |
| 5489 | if (rc >= HTTP_ERR_SIZE) { |
| 5490 | Warning("parsing [%s:%d] : status code %d not handled, error customization will be ignored.\n", |
| 5491 | file, linenum, errnum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5492 | err_code |= ERR_WARN; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5493 | free(err); |
| 5494 | } |
| 5495 | } |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5496 | else if (!strcmp(args[0], "compression")) { |
| 5497 | struct comp *comp; |
| 5498 | if (curproxy->comp == NULL) { |
| 5499 | comp = calloc(1, sizeof(struct comp)); |
| 5500 | curproxy->comp = comp; |
| 5501 | } else { |
| 5502 | comp = curproxy->comp; |
| 5503 | } |
| 5504 | |
| 5505 | if (!strcmp(args[1], "algo")) { |
| 5506 | int cur_arg; |
William Lallemand | 8b52bb3 | 2012-11-16 18:06:41 +0100 | [diff] [blame] | 5507 | struct comp_ctx *ctx; |
William Lallemand | 552df67 | 2012-11-07 13:21:47 +0100 | [diff] [blame] | 5508 | |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5509 | cur_arg = 2; |
| 5510 | if (!*args[cur_arg]) { |
| 5511 | Alert("parsing [%s:%d] : '%s' expects <algorithm>\n", |
| 5512 | file, linenum, args[0]); |
| 5513 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5514 | goto out; |
| 5515 | } |
| 5516 | while (*(args[cur_arg])) { |
| 5517 | if (comp_append_algo(comp, args[cur_arg]) < 0) { |
| 5518 | Alert("parsing [%s:%d] : '%s' : '%s' is not a supported algorithm.\n", |
| 5519 | file, linenum, args[0], args[cur_arg]); |
| 5520 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5521 | goto out; |
| 5522 | } |
William Lallemand | 552df67 | 2012-11-07 13:21:47 +0100 | [diff] [blame] | 5523 | if (curproxy->comp->algos->init(&ctx, 9) == 0) { |
| 5524 | curproxy->comp->algos->end(&ctx); |
| 5525 | } else { |
| 5526 | Alert("parsing [%s:%d] : '%s' : Can't init '%s' algorithm.\n", |
| 5527 | file, linenum, args[0], args[cur_arg]); |
| 5528 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5529 | goto out; |
| 5530 | } |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5531 | cur_arg ++; |
| 5532 | continue; |
| 5533 | } |
| 5534 | } |
Willy Tarreau | 70737d1 | 2012-10-27 00:34:28 +0200 | [diff] [blame] | 5535 | else if (!strcmp(args[1], "offload")) { |
| 5536 | comp->offload = 1; |
| 5537 | } |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5538 | else if (!strcmp(args[1], "type")) { |
| 5539 | int cur_arg; |
| 5540 | cur_arg = 2; |
| 5541 | if (!*args[cur_arg]) { |
| 5542 | Alert("parsing [%s:%d] : '%s' expects <type>\n", |
| 5543 | file, linenum, args[0]); |
| 5544 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5545 | goto out; |
| 5546 | } |
| 5547 | while (*(args[cur_arg])) { |
| 5548 | comp_append_type(comp, args[cur_arg]); |
| 5549 | cur_arg ++; |
| 5550 | continue; |
| 5551 | } |
| 5552 | } |
| 5553 | else { |
Willy Tarreau | 70737d1 | 2012-10-27 00:34:28 +0200 | [diff] [blame] | 5554 | Alert("parsing [%s:%d] : '%s' expects 'algo', 'type' or 'offload'\n", |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5555 | file, linenum, args[0]); |
| 5556 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5557 | goto out; |
| 5558 | } |
| 5559 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5560 | else { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 5561 | struct cfg_kw_list *kwl; |
| 5562 | int index; |
| 5563 | |
| 5564 | list_for_each_entry(kwl, &cfg_keywords.list, list) { |
| 5565 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 5566 | if (kwl->kw[index].section != CFG_LISTEN) |
| 5567 | continue; |
| 5568 | if (strcmp(kwl->kw[index].kw, args[0]) == 0) { |
| 5569 | /* prepare error message just in case */ |
Willy Tarreau | 28a47d6 | 2012-09-18 20:02:48 +0200 | [diff] [blame] | 5570 | 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] | 5571 | if (rc < 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 5572 | Alert("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5573 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5574 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 5575 | } |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 5576 | else if (rc > 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 5577 | Warning("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5578 | err_code |= ERR_WARN; |
| 5579 | goto out; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 5580 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5581 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 5582 | } |
| 5583 | } |
| 5584 | } |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5585 | |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5586 | 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] | 5587 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5588 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5589 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5590 | out: |
Willy Tarreau | f4068b6 | 2012-05-08 17:37:49 +0200 | [diff] [blame] | 5591 | free(errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5592 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5593 | } |
| 5594 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5595 | int |
| 5596 | cfg_parse_users(const char *file, int linenum, char **args, int kwm) |
| 5597 | { |
| 5598 | |
| 5599 | int err_code = 0; |
| 5600 | const char *err; |
| 5601 | |
| 5602 | if (!strcmp(args[0], "userlist")) { /* new userlist */ |
| 5603 | struct userlist *newul; |
| 5604 | |
| 5605 | if (!*args[1]) { |
| 5606 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 5607 | file, linenum, args[0]); |
| 5608 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5609 | goto out; |
| 5610 | } |
| 5611 | |
| 5612 | err = invalid_char(args[1]); |
| 5613 | if (err) { |
| 5614 | Alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 5615 | file, linenum, *err, args[0], args[1]); |
| 5616 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5617 | goto out; |
| 5618 | } |
| 5619 | |
| 5620 | for (newul = userlist; newul; newul = newul->next) |
| 5621 | if (!strcmp(newul->name, args[1])) { |
| 5622 | Warning("parsing [%s:%d]: ignoring duplicated userlist '%s'.\n", |
| 5623 | file, linenum, args[1]); |
| 5624 | err_code |= ERR_WARN; |
| 5625 | goto out; |
| 5626 | } |
| 5627 | |
| 5628 | newul = (struct userlist *)calloc(1, sizeof(struct userlist)); |
| 5629 | if (!newul) { |
| 5630 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 5631 | err_code |= ERR_ALERT | ERR_ABORT; |
| 5632 | goto out; |
| 5633 | } |
| 5634 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5635 | newul->name = strdup(args[1]); |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 5636 | if (!newul->name) { |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5637 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 5638 | err_code |= ERR_ALERT | ERR_ABORT; |
| 5639 | goto out; |
| 5640 | } |
| 5641 | |
| 5642 | newul->next = userlist; |
| 5643 | userlist = newul; |
| 5644 | |
| 5645 | } else if (!strcmp(args[0], "group")) { /* new group */ |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 5646 | int cur_arg; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5647 | const char *err; |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 5648 | struct auth_groups *ag; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5649 | |
| 5650 | if (!*args[1]) { |
| 5651 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 5652 | file, linenum, args[0]); |
| 5653 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5654 | goto out; |
| 5655 | } |
| 5656 | |
| 5657 | err = invalid_char(args[1]); |
| 5658 | if (err) { |
| 5659 | Alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 5660 | file, linenum, *err, args[0], args[1]); |
| 5661 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5662 | goto out; |
| 5663 | } |
| 5664 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 5665 | for (ag = userlist->groups; ag; ag = ag->next) |
| 5666 | if (!strcmp(ag->name, args[1])) { |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5667 | Warning("parsing [%s:%d]: ignoring duplicated group '%s' in userlist '%s'.\n", |
| 5668 | file, linenum, args[1], userlist->name); |
| 5669 | err_code |= ERR_ALERT; |
| 5670 | goto out; |
| 5671 | } |
| 5672 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 5673 | ag = calloc(1, sizeof(*ag)); |
| 5674 | if (!ag) { |
| 5675 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 5676 | err_code |= ERR_ALERT | ERR_ABORT; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5677 | goto out; |
| 5678 | } |
| 5679 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 5680 | ag->name = strdup(args[1]); |
| 5681 | if (!ag) { |
| 5682 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 5683 | err_code |= ERR_ALERT | ERR_ABORT; |
| 5684 | goto out; |
| 5685 | } |
| 5686 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5687 | cur_arg = 2; |
| 5688 | |
| 5689 | while (*args[cur_arg]) { |
| 5690 | if (!strcmp(args[cur_arg], "users")) { |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 5691 | ag->groupusers = strdup(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5692 | cur_arg += 2; |
| 5693 | continue; |
| 5694 | } else { |
| 5695 | Alert("parsing [%s:%d]: '%s' only supports 'users' option.\n", |
| 5696 | file, linenum, args[0]); |
| 5697 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5698 | goto out; |
| 5699 | } |
| 5700 | } |
| 5701 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 5702 | ag->next = userlist->groups; |
| 5703 | userlist->groups = ag; |
| 5704 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5705 | } else if (!strcmp(args[0], "user")) { /* new user */ |
| 5706 | struct auth_users *newuser; |
| 5707 | int cur_arg; |
| 5708 | |
| 5709 | if (!*args[1]) { |
| 5710 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 5711 | file, linenum, args[0]); |
| 5712 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5713 | goto out; |
| 5714 | } |
| 5715 | |
| 5716 | for (newuser = userlist->users; newuser; newuser = newuser->next) |
| 5717 | if (!strcmp(newuser->user, args[1])) { |
| 5718 | Warning("parsing [%s:%d]: ignoring duplicated user '%s' in userlist '%s'.\n", |
| 5719 | file, linenum, args[1], userlist->name); |
| 5720 | err_code |= ERR_ALERT; |
| 5721 | goto out; |
| 5722 | } |
| 5723 | |
| 5724 | newuser = (struct auth_users *)calloc(1, sizeof(struct auth_users)); |
| 5725 | if (!newuser) { |
| 5726 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 5727 | err_code |= ERR_ALERT | ERR_ABORT; |
| 5728 | goto out; |
| 5729 | } |
| 5730 | |
| 5731 | newuser->user = strdup(args[1]); |
| 5732 | |
| 5733 | newuser->next = userlist->users; |
| 5734 | userlist->users = newuser; |
| 5735 | |
| 5736 | cur_arg = 2; |
| 5737 | |
| 5738 | while (*args[cur_arg]) { |
| 5739 | if (!strcmp(args[cur_arg], "password")) { |
Cyril Bonté | 2c8d700 | 2014-08-29 20:20:02 +0200 | [diff] [blame] | 5740 | #ifdef CONFIG_HAP_CRYPT |
| 5741 | if (!crypt("", args[cur_arg + 1])) { |
| 5742 | Alert("parsing [%s:%d]: the encrypted password used for user '%s' is not supported by crypt(3).\n", |
| 5743 | file, linenum, newuser->user); |
| 5744 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5745 | goto out; |
| 5746 | } |
| 5747 | #else |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5748 | Warning("parsing [%s:%d]: no crypt(3) support compiled, encrypted passwords will not work.\n", |
| 5749 | file, linenum); |
| 5750 | err_code |= ERR_ALERT; |
| 5751 | #endif |
| 5752 | newuser->pass = strdup(args[cur_arg + 1]); |
| 5753 | cur_arg += 2; |
| 5754 | continue; |
| 5755 | } else if (!strcmp(args[cur_arg], "insecure-password")) { |
| 5756 | newuser->pass = strdup(args[cur_arg + 1]); |
| 5757 | newuser->flags |= AU_O_INSECURE; |
| 5758 | cur_arg += 2; |
| 5759 | continue; |
| 5760 | } else if (!strcmp(args[cur_arg], "groups")) { |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 5761 | newuser->u.groups_names = strdup(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5762 | cur_arg += 2; |
| 5763 | continue; |
| 5764 | } else { |
| 5765 | Alert("parsing [%s:%d]: '%s' only supports 'password', 'insecure-password' and 'groups' options.\n", |
| 5766 | file, linenum, args[0]); |
| 5767 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5768 | goto out; |
| 5769 | } |
| 5770 | } |
| 5771 | } else { |
| 5772 | Alert("parsing [%s:%d]: unknown keyword '%s' in '%s' section\n", file, linenum, args[0], "users"); |
| 5773 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5774 | } |
| 5775 | |
| 5776 | out: |
| 5777 | return err_code; |
| 5778 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5779 | |
| 5780 | /* |
| 5781 | * This function reads and parses the configuration file given in the argument. |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5782 | * Returns the error code, 0 if OK, or any combination of : |
| 5783 | * - ERR_ABORT: must abort ASAP |
| 5784 | * - ERR_FATAL: we can continue parsing but not start the service |
| 5785 | * - ERR_WARN: a warning has been emitted |
| 5786 | * - ERR_ALERT: an alert has been emitted |
| 5787 | * Only the two first ones can stop processing, the two others are just |
| 5788 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5789 | */ |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 5790 | int readcfgfile(const char *file) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5791 | { |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5792 | char thisline[LINESIZE]; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5793 | FILE *f; |
| 5794 | int linenum = 0; |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5795 | int err_code = 0; |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 5796 | struct cfg_section *cs = NULL; |
| 5797 | struct cfg_section *ics; |
| 5798 | |
| 5799 | /* Register internal sections */ |
| 5800 | if (!cfg_register_section("listen", cfg_parse_listen) || |
| 5801 | !cfg_register_section("frontend", cfg_parse_listen) || |
| 5802 | !cfg_register_section("backend", cfg_parse_listen) || |
| 5803 | !cfg_register_section("ruleset", cfg_parse_listen) || |
| 5804 | !cfg_register_section("defaults", cfg_parse_listen) || |
| 5805 | !cfg_register_section("global", cfg_parse_global) || |
| 5806 | !cfg_register_section("userlist", cfg_parse_users) || |
| 5807 | !cfg_register_section("peers", cfg_parse_peers)) |
| 5808 | return -1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5809 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5810 | if ((f=fopen(file,"r")) == NULL) |
| 5811 | return -1; |
| 5812 | |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5813 | while (fgets(thisline, sizeof(thisline), f) != NULL) { |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 5814 | int arg, kwm = KWM_STD; |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5815 | char *end; |
| 5816 | char *args[MAX_LINE_ARGS + 1]; |
| 5817 | char *line = thisline; |
| 5818 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5819 | linenum++; |
| 5820 | |
| 5821 | end = line + strlen(line); |
| 5822 | |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5823 | if (end-line == sizeof(thisline)-1 && *(end-1) != '\n') { |
| 5824 | /* Check if we reached the limit and the last char is not \n. |
| 5825 | * Watch out for the last line without the terminating '\n'! |
| 5826 | */ |
| 5827 | Alert("parsing [%s:%d]: line too long, limit: %d.\n", |
Willy Tarreau | 5e4a6f1 | 2009-04-11 19:42:49 +0200 | [diff] [blame] | 5828 | file, linenum, (int)sizeof(thisline)-1); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5829 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5830 | } |
| 5831 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5832 | /* skip leading spaces */ |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 5833 | while (isspace((unsigned char)*line)) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5834 | line++; |
| 5835 | |
| 5836 | arg = 0; |
| 5837 | args[arg] = line; |
| 5838 | |
| 5839 | while (*line && arg < MAX_LINE_ARGS) { |
| 5840 | /* first, we'll replace \\, \<space>, \#, \r, \n, \t, \xXX with their |
| 5841 | * C equivalent value. Other combinations left unchanged (eg: \1). |
| 5842 | */ |
| 5843 | if (*line == '\\') { |
| 5844 | int skip = 0; |
| 5845 | if (line[1] == ' ' || line[1] == '\\' || line[1] == '#') { |
| 5846 | *line = line[1]; |
| 5847 | skip = 1; |
| 5848 | } |
| 5849 | else if (line[1] == 'r') { |
| 5850 | *line = '\r'; |
| 5851 | skip = 1; |
| 5852 | } |
| 5853 | else if (line[1] == 'n') { |
| 5854 | *line = '\n'; |
| 5855 | skip = 1; |
| 5856 | } |
| 5857 | else if (line[1] == 't') { |
| 5858 | *line = '\t'; |
| 5859 | skip = 1; |
| 5860 | } |
| 5861 | else if (line[1] == 'x') { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5862 | if ((line + 3 < end) && ishex(line[2]) && ishex(line[3])) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5863 | unsigned char hex1, hex2; |
| 5864 | hex1 = toupper(line[2]) - '0'; |
| 5865 | hex2 = toupper(line[3]) - '0'; |
| 5866 | if (hex1 > 9) hex1 -= 'A' - '9' - 1; |
| 5867 | if (hex2 > 9) hex2 -= 'A' - '9' - 1; |
| 5868 | *line = (hex1<<4) + hex2; |
| 5869 | skip = 3; |
| 5870 | } |
| 5871 | else { |
| 5872 | 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] | 5873 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5874 | } |
| 5875 | } |
| 5876 | if (skip) { |
Cyril Bonté | dd1b01d | 2009-12-06 13:43:42 +0100 | [diff] [blame] | 5877 | memmove(line + 1, line + 1 + skip, end - (line + skip)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5878 | end -= skip; |
| 5879 | } |
| 5880 | line++; |
| 5881 | } |
| 5882 | else if (*line == '#' || *line == '\n' || *line == '\r') { |
| 5883 | /* end of string, end of loop */ |
| 5884 | *line = 0; |
| 5885 | break; |
| 5886 | } |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 5887 | else if (isspace((unsigned char)*line)) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5888 | /* a non-escaped space is an argument separator */ |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5889 | *line++ = '\0'; |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 5890 | while (isspace((unsigned char)*line)) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5891 | line++; |
| 5892 | args[++arg] = line; |
| 5893 | } |
| 5894 | else { |
| 5895 | line++; |
| 5896 | } |
| 5897 | } |
| 5898 | |
| 5899 | /* empty line */ |
| 5900 | if (!**args) |
| 5901 | continue; |
| 5902 | |
Willy Tarreau | 7bb651e | 2009-11-09 21:16:53 +0100 | [diff] [blame] | 5903 | if (*line) { |
| 5904 | /* we had to stop due to too many args. |
| 5905 | * Let's terminate the string, print the offending part then cut the |
| 5906 | * last arg. |
| 5907 | */ |
| 5908 | while (*line && *line != '#' && *line != '\n' && *line != '\r') |
| 5909 | line++; |
| 5910 | *line = '\0'; |
| 5911 | |
Krzysztof Piotr Oledzki | 500b8f0 | 2009-12-15 22:34:51 +0100 | [diff] [blame] | 5912 | 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] | 5913 | file, linenum, arg + 1, (long)(args[arg] - thisline + 1), args[arg]); |
Willy Tarreau | 7bb651e | 2009-11-09 21:16:53 +0100 | [diff] [blame] | 5914 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5915 | args[arg] = line; |
| 5916 | } |
| 5917 | |
Willy Tarreau | 540abe4 | 2007-05-02 20:50:16 +0200 | [diff] [blame] | 5918 | /* zero out remaining args and ensure that at least one entry |
| 5919 | * is zeroed out. |
| 5920 | */ |
| 5921 | while (++arg <= MAX_LINE_ARGS) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5922 | args[arg] = line; |
| 5923 | } |
| 5924 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 5925 | /* check for keyword modifiers "no" and "default" */ |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5926 | if (!strcmp(args[0], "no")) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5927 | char *tmp; |
| 5928 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 5929 | kwm = KWM_NO; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5930 | tmp = args[0]; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5931 | for (arg=0; *args[arg+1]; arg++) |
| 5932 | args[arg] = args[arg+1]; // shift args after inversion |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5933 | *tmp = '\0'; // fix the next arg to \0 |
| 5934 | args[arg] = tmp; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5935 | } |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 5936 | else if (!strcmp(args[0], "default")) { |
| 5937 | kwm = KWM_DEF; |
| 5938 | for (arg=0; *args[arg+1]; arg++) |
| 5939 | args[arg] = args[arg+1]; // shift args after inversion |
| 5940 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5941 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5942 | if (kwm != KWM_STD && strcmp(args[0], "option") != 0 && \ |
| 5943 | strcmp(args[0], "log") != 0) { |
| 5944 | 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] | 5945 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5946 | } |
| 5947 | |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 5948 | /* detect section start */ |
| 5949 | list_for_each_entry(ics, §ions, list) { |
| 5950 | if (strcmp(args[0], ics->section_name) == 0) { |
| 5951 | cursection = ics->section_name; |
| 5952 | cs = ics; |
| 5953 | break; |
| 5954 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 5955 | } |
| 5956 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5957 | /* else it's a section keyword */ |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 5958 | if (cs) |
| 5959 | err_code |= cs->section_parser(file, linenum, args, kwm); |
| 5960 | else { |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5961 | 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] | 5962 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5963 | } |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5964 | |
| 5965 | if (err_code & ERR_ABORT) |
| 5966 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5967 | } |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5968 | cursection = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5969 | fclose(f); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5970 | return err_code; |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5971 | } |
| 5972 | |
Willy Tarreau | 5436afc | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 5973 | /* This function propagates processes from frontend <from> to backend <to> so |
| 5974 | * that it is always guaranteed that a backend pointed to by a frontend is |
| 5975 | * bound to all of its processes. After that, if the target is a "listen" |
| 5976 | * instance, the function recursively descends the target's own targets along |
| 5977 | * default_backend, use_backend rules, and reqsetbe rules. Since the bits are |
| 5978 | * checked first to ensure that <to> is already bound to all processes of |
| 5979 | * <from>, there is no risk of looping and we ensure to follow the shortest |
| 5980 | * path to the destination. |
| 5981 | * |
| 5982 | * It is possible to set <to> to NULL for the first call so that the function |
| 5983 | * takes care of visiting the initial frontend in <from>. |
| 5984 | * |
| 5985 | * It is important to note that the function relies on the fact that all names |
| 5986 | * have already been resolved. |
| 5987 | */ |
| 5988 | void propagate_processes(struct proxy *from, struct proxy *to) |
| 5989 | { |
| 5990 | struct switching_rule *rule; |
| 5991 | struct hdr_exp *exp; |
| 5992 | |
| 5993 | if (to) { |
| 5994 | /* check whether we need to go down */ |
| 5995 | if (from->bind_proc && |
| 5996 | (from->bind_proc & to->bind_proc) == from->bind_proc) |
| 5997 | return; |
| 5998 | |
| 5999 | if (!from->bind_proc && !to->bind_proc) |
| 6000 | return; |
| 6001 | |
| 6002 | to->bind_proc = from->bind_proc ? |
| 6003 | (to->bind_proc | from->bind_proc) : 0; |
| 6004 | |
| 6005 | /* now propagate down */ |
| 6006 | from = to; |
| 6007 | } |
| 6008 | |
Willy Tarreau | 7110f38 | 2014-12-18 13:56:26 +0100 | [diff] [blame] | 6009 | if (!(from->cap & PR_CAP_FE)) |
Willy Tarreau | 5436afc | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 6010 | return; |
| 6011 | |
Willy Tarreau | ed061c0 | 2014-12-18 14:00:43 +0100 | [diff] [blame] | 6012 | if (from->state == PR_STSTOPPED) |
| 6013 | return; |
| 6014 | |
Willy Tarreau | 5436afc | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 6015 | /* default_backend */ |
| 6016 | if (from->defbe.be) |
| 6017 | propagate_processes(from, from->defbe.be); |
| 6018 | |
| 6019 | /* use_backend */ |
| 6020 | list_for_each_entry(rule, &from->switching_rules, list) { |
Cyril Bonté | c8d57de | 2014-10-02 19:56:25 +0200 | [diff] [blame] | 6021 | if (rule->dynamic) |
| 6022 | continue; |
Willy Tarreau | 5436afc | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 6023 | to = rule->be.backend; |
| 6024 | propagate_processes(from, to); |
| 6025 | } |
| 6026 | |
| 6027 | /* reqsetbe */ |
| 6028 | for (exp = from->req_exp; exp != NULL; exp = exp->next) { |
| 6029 | if (exp->action != ACT_SETBE) |
| 6030 | continue; |
| 6031 | to = (struct proxy *)exp->replace; |
| 6032 | propagate_processes(from, to); |
| 6033 | } |
| 6034 | } |
| 6035 | |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6036 | /* |
| 6037 | * Returns the error code, 0 if OK, or any combination of : |
| 6038 | * - ERR_ABORT: must abort ASAP |
| 6039 | * - ERR_FATAL: we can continue parsing but not start the service |
| 6040 | * - ERR_WARN: a warning has been emitted |
| 6041 | * - ERR_ALERT: an alert has been emitted |
| 6042 | * Only the two first ones can stop processing, the two others are just |
| 6043 | * indicators. |
| 6044 | */ |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6045 | int check_config_validity() |
| 6046 | { |
| 6047 | int cfgerr = 0; |
| 6048 | struct proxy *curproxy = NULL; |
| 6049 | struct server *newsrv = NULL; |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6050 | int err_code = 0; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6051 | unsigned int next_pxid = 1; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6052 | struct bind_conf *bind_conf; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6053 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6054 | bind_conf = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6055 | /* |
| 6056 | * Now, check for the integrity of all that we have collected. |
| 6057 | */ |
| 6058 | |
| 6059 | /* will be needed further to delay some tasks */ |
Willy Tarreau | b0b37bc | 2008-06-23 14:00:57 +0200 | [diff] [blame] | 6060 | tv_update_date(0,1); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6061 | |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 6062 | if (!global.tune.max_http_hdr) |
| 6063 | global.tune.max_http_hdr = MAX_HTTP_HDR; |
| 6064 | |
| 6065 | if (!global.tune.cookie_len) |
| 6066 | global.tune.cookie_len = CAPTURE_LEN; |
| 6067 | |
| 6068 | pool2_capture = create_pool("capture", global.tune.cookie_len, MEM_F_SHARED); |
| 6069 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6070 | /* Post initialisation of the users and groups lists. */ |
| 6071 | err_code = userlist_postinit(); |
| 6072 | if (err_code != ERR_NONE) |
| 6073 | goto out; |
| 6074 | |
Willy Tarreau | 55bc0f8 | 2009-03-15 14:51:53 +0100 | [diff] [blame] | 6075 | /* first, we will invert the proxy list order */ |
| 6076 | curproxy = NULL; |
| 6077 | while (proxy) { |
| 6078 | struct proxy *next; |
| 6079 | |
| 6080 | next = proxy->next; |
| 6081 | proxy->next = curproxy; |
| 6082 | curproxy = proxy; |
| 6083 | if (!next) |
| 6084 | break; |
| 6085 | proxy = next; |
| 6086 | } |
| 6087 | |
Willy Tarreau | 91b00c2 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 6088 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6089 | struct switching_rule *rule; |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 6090 | struct server_rule *srule; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6091 | struct sticking_rule *mrule; |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 6092 | struct tcp_rule *trule; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6093 | unsigned int next_id; |
Willy Tarreau | 16a2147 | 2012-11-19 12:39:59 +0100 | [diff] [blame] | 6094 | int nbproc; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6095 | |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 6096 | if (curproxy->uuid < 0) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6097 | /* proxy ID not set, use automatic numbering with first |
| 6098 | * spare entry starting with next_pxid. |
| 6099 | */ |
| 6100 | next_pxid = get_next_id(&used_proxy_id, next_pxid); |
| 6101 | curproxy->conf.id.key = curproxy->uuid = next_pxid; |
| 6102 | eb32_insert(&used_proxy_id, &curproxy->conf.id); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6103 | } |
Krzysztof Piotr Oledzki | df5cb9f | 2010-02-05 20:58:27 +0100 | [diff] [blame] | 6104 | next_pxid++; |
| 6105 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6106 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6107 | if (curproxy->state == PR_STSTOPPED) { |
Willy Tarreau | da250db | 2008-10-12 12:07:48 +0200 | [diff] [blame] | 6108 | /* ensure we don't keep listeners uselessly bound */ |
| 6109 | stop_proxy(curproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6110 | continue; |
| 6111 | } |
| 6112 | |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 6113 | /* Check multi-process mode compatibility for the current proxy */ |
| 6114 | |
| 6115 | if (curproxy->bind_proc) { |
| 6116 | /* an explicit bind-process was specified, let's check how many |
| 6117 | * processes remain. |
| 6118 | */ |
| 6119 | nbproc = popcount(curproxy->bind_proc); |
| 6120 | |
| 6121 | curproxy->bind_proc &= nbits(global.nbproc); |
| 6122 | if (!curproxy->bind_proc && nbproc == 1) { |
| 6123 | Warning("Proxy '%s': the process specified on the 'bind-process' directive refers to a process number that is higher than global.nbproc. The proxy has been forced to run on process 1 only.\n", curproxy->id); |
| 6124 | curproxy->bind_proc = 1; |
| 6125 | } |
| 6126 | else if (!curproxy->bind_proc && nbproc > 1) { |
| 6127 | Warning("Proxy '%s': all processes specified on the 'bind-process' directive refer to numbers that are all higher than global.nbproc. The directive was ignored and the proxy will run on all processes.\n", curproxy->id); |
| 6128 | curproxy->bind_proc = 0; |
| 6129 | } |
| 6130 | } |
| 6131 | |
Willy Tarreau | 3d20958 | 2014-05-09 17:06:11 +0200 | [diff] [blame] | 6132 | /* check and reduce the bind-proc of each listener */ |
| 6133 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
| 6134 | unsigned long mask; |
| 6135 | |
| 6136 | if (!bind_conf->bind_proc) |
| 6137 | continue; |
| 6138 | |
| 6139 | mask = nbits(global.nbproc); |
| 6140 | if (curproxy->bind_proc) |
| 6141 | mask &= curproxy->bind_proc; |
| 6142 | /* mask cannot be null here thanks to the previous checks */ |
| 6143 | |
| 6144 | nbproc = popcount(bind_conf->bind_proc); |
| 6145 | bind_conf->bind_proc &= mask; |
| 6146 | |
| 6147 | if (!bind_conf->bind_proc && nbproc == 1) { |
| 6148 | Warning("Proxy '%s': the process number specified on the 'process' directive of 'bind %s' at [%s:%d] refers to a process not covered by the proxy. This has been fixed by forcing it to run on the proxy's first process only.\n", |
| 6149 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
| 6150 | bind_conf->bind_proc = mask & ~(mask - 1); |
| 6151 | } |
| 6152 | else if (!bind_conf->bind_proc && nbproc > 1) { |
| 6153 | Warning("Proxy '%s': the process range specified on the 'process' directive of 'bind %s' at [%s:%d] only refers to processes not covered by the proxy. The directive was ignored so that all of the proxy's processes are used.\n", |
| 6154 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
| 6155 | bind_conf->bind_proc = 0; |
| 6156 | } |
| 6157 | } |
| 6158 | |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 6159 | if (global.nbproc > 1 && curproxy->table.peers.name) { |
| 6160 | Alert("Proxy '%s': peers can't be used in multi-process mode (nbproc > 1).\n", |
| 6161 | curproxy->id); |
| 6162 | cfgerr++; |
| 6163 | } |
Willy Tarreau | 16a2147 | 2012-11-19 12:39:59 +0100 | [diff] [blame] | 6164 | |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 6165 | switch (curproxy->mode) { |
| 6166 | case PR_MODE_HEALTH: |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6167 | cfgerr += proxy_cfg_ensure_no_http(curproxy); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 6168 | if (!(curproxy->cap & PR_CAP_FE)) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6169 | Alert("config : %s '%s' cannot be in health mode as it has no frontend capability.\n", |
| 6170 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 6171 | cfgerr++; |
| 6172 | } |
| 6173 | |
| 6174 | if (curproxy->srv != NULL) |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6175 | Warning("config : servers will be ignored for %s '%s'.\n", |
| 6176 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 6177 | break; |
| 6178 | |
| 6179 | case PR_MODE_TCP: |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6180 | cfgerr += proxy_cfg_ensure_no_http(curproxy); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 6181 | break; |
| 6182 | |
| 6183 | case PR_MODE_HTTP: |
Willy Tarreau | 25320b2 | 2013-03-24 07:22:08 +0100 | [diff] [blame] | 6184 | curproxy->http_needed = 1; |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 6185 | break; |
| 6186 | } |
| 6187 | |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 6188 | if ((curproxy->cap & PR_CAP_BE) && (curproxy->mode != PR_MODE_HEALTH)) { |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6189 | if (curproxy->lbprm.algo & BE_LB_KIND) { |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 6190 | if (curproxy->options & PR_O_TRANSP) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6191 | Alert("config : %s '%s' cannot use both transparent and balance mode.\n", |
| 6192 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 6193 | cfgerr++; |
| 6194 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6195 | #ifdef WE_DONT_SUPPORT_SERVERLESS_LISTENERS |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 6196 | else if (curproxy->srv == NULL) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6197 | Alert("config : %s '%s' needs at least 1 server in balance mode.\n", |
| 6198 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 6199 | cfgerr++; |
| 6200 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6201 | #endif |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 6202 | else if (curproxy->options & PR_O_DISPATCH) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6203 | Warning("config : dispatch address of %s '%s' will be ignored in balance mode.\n", |
| 6204 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6205 | err_code |= ERR_WARN; |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 6206 | } |
| 6207 | } |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 6208 | 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] | 6209 | /* If no LB algo is set in a backend, and we're not in |
| 6210 | * transparent mode, dispatch mode nor proxy mode, we |
| 6211 | * want to use balance roundrobin by default. |
| 6212 | */ |
| 6213 | curproxy->lbprm.algo &= ~BE_LB_ALGO; |
| 6214 | curproxy->lbprm.algo |= BE_LB_ALGO_RR; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6215 | } |
| 6216 | } |
Willy Tarreau | 193cf93 | 2007-09-17 10:17:23 +0200 | [diff] [blame] | 6217 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 6218 | if (curproxy->options & PR_O_DISPATCH) |
| 6219 | curproxy->options &= ~(PR_O_TRANSP | PR_O_HTTP_PROXY); |
| 6220 | else if (curproxy->options & PR_O_HTTP_PROXY) |
| 6221 | curproxy->options &= ~(PR_O_DISPATCH | PR_O_TRANSP); |
| 6222 | else if (curproxy->options & PR_O_TRANSP) |
| 6223 | curproxy->options &= ~(PR_O_DISPATCH | PR_O_HTTP_PROXY); |
Willy Tarreau | 8293658 | 2007-11-30 15:20:09 +0100 | [diff] [blame] | 6224 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 6225 | if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_HTTP_CHK) { |
| 6226 | if (curproxy->options & PR_O_DISABLE404) { |
| 6227 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n", |
| 6228 | "disable-on-404", proxy_type_str(curproxy), curproxy->id); |
| 6229 | err_code |= ERR_WARN; |
| 6230 | curproxy->options &= ~PR_O_DISABLE404; |
| 6231 | } |
| 6232 | if (curproxy->options2 & PR_O2_CHK_SNDST) { |
| 6233 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n", |
| 6234 | "send-state", proxy_type_str(curproxy), curproxy->id); |
| 6235 | err_code |= ERR_WARN; |
| 6236 | curproxy->options &= ~PR_O2_CHK_SNDST; |
| 6237 | } |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 6238 | } |
| 6239 | |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 6240 | /* if a default backend was specified, let's find it */ |
| 6241 | if (curproxy->defbe.name) { |
| 6242 | struct proxy *target; |
| 6243 | |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 6244 | target = findproxy_mode(curproxy->defbe.name, curproxy->mode, PR_CAP_BE); |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6245 | if (!target) { |
| 6246 | Alert("Proxy '%s': unable to find required default_backend: '%s'.\n", |
| 6247 | curproxy->id, curproxy->defbe.name); |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 6248 | cfgerr++; |
| 6249 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6250 | Alert("Proxy '%s': loop detected for default_backend: '%s'.\n", |
| 6251 | curproxy->id, curproxy->defbe.name); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6252 | cfgerr++; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 6253 | } else { |
| 6254 | free(curproxy->defbe.name); |
| 6255 | curproxy->defbe.be = target; |
Willy Tarreau | ff67813 | 2012-02-13 14:32:34 +0100 | [diff] [blame] | 6256 | |
| 6257 | /* Emit a warning if this proxy also has some servers */ |
| 6258 | if (curproxy->srv) { |
| 6259 | Warning("In proxy '%s', the 'default_backend' rule always has precedence over the servers, which will never be used.\n", |
| 6260 | curproxy->id); |
| 6261 | err_code |= ERR_WARN; |
| 6262 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6263 | } |
| 6264 | } |
| 6265 | |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 6266 | /* find the target proxy in setbe */ |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 6267 | if (curproxy->mode == PR_MODE_HTTP && curproxy->req_exp != NULL) { |
| 6268 | /* map jump target for ACT_SETBE in req_rep chain */ |
| 6269 | struct hdr_exp *exp; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 6270 | for (exp = curproxy->req_exp; exp != NULL; exp = exp->next) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6271 | struct proxy *target; |
| 6272 | |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 6273 | if (exp->action != ACT_SETBE) |
| 6274 | continue; |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6275 | |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 6276 | target = findproxy_mode(exp->replace, PR_MODE_HTTP, PR_CAP_BE); |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6277 | if (!target) { |
| 6278 | Alert("Proxy '%s': unable to find required setbe: '%s'.\n", |
| 6279 | curproxy->id, exp->replace); |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 6280 | cfgerr++; |
| 6281 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6282 | Alert("Proxy '%s': loop detected for setbe: '%s'.\n", |
| 6283 | curproxy->id, exp->replace); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 6284 | cfgerr++; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 6285 | } else { |
| 6286 | free((void *)exp->replace); |
| 6287 | exp->replace = (const char *)target; |
| 6288 | } |
| 6289 | } |
| 6290 | } |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6291 | |
| 6292 | /* find the target proxy for 'use_backend' rules */ |
| 6293 | list_for_each_entry(rule, &curproxy->switching_rules, list) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6294 | struct proxy *target; |
Bertrand Jacquin | 702d44f | 2013-11-19 11:43:06 +0100 | [diff] [blame] | 6295 | struct logformat_node *node; |
| 6296 | char *pxname; |
| 6297 | |
| 6298 | /* Try to parse the string as a log format expression. If the result |
| 6299 | * of the parsing is only one entry containing a simple string, then |
| 6300 | * it's a standard string corresponding to a static rule, thus the |
| 6301 | * parsing is cancelled and be.name is restored to be resolved. |
| 6302 | */ |
| 6303 | pxname = rule->be.name; |
| 6304 | LIST_INIT(&rule->be.expr); |
| 6305 | parse_logformat_string(pxname, curproxy, &rule->be.expr, 0, SMP_VAL_FE_HRQ_HDR, |
| 6306 | curproxy->conf.args.file, curproxy->conf.args.line); |
| 6307 | node = LIST_NEXT(&rule->be.expr, struct logformat_node *, list); |
| 6308 | |
| 6309 | if (!LIST_ISEMPTY(&rule->be.expr)) { |
| 6310 | if (node->type != LOG_FMT_TEXT || node->list.n != &rule->be.expr) { |
| 6311 | rule->dynamic = 1; |
| 6312 | free(pxname); |
| 6313 | continue; |
| 6314 | } |
| 6315 | /* simple string: free the expression and fall back to static rule */ |
| 6316 | free(node->arg); |
| 6317 | free(node); |
| 6318 | } |
| 6319 | |
| 6320 | rule->dynamic = 0; |
| 6321 | rule->be.name = pxname; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6322 | |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 6323 | target = findproxy_mode(rule->be.name, curproxy->mode, PR_CAP_BE); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6324 | |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6325 | if (!target) { |
| 6326 | Alert("Proxy '%s': unable to find required use_backend: '%s'.\n", |
| 6327 | curproxy->id, rule->be.name); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6328 | cfgerr++; |
| 6329 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6330 | Alert("Proxy '%s': loop detected for use_backend: '%s'.\n", |
| 6331 | curproxy->id, rule->be.name); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6332 | cfgerr++; |
| 6333 | } else { |
| 6334 | free((void *)rule->be.name); |
| 6335 | rule->be.backend = target; |
| 6336 | } |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 6337 | } |
| 6338 | |
Willy Tarreau | 5436afc | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 6339 | /* find the target server for 'use_server' rules */ |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 6340 | list_for_each_entry(srule, &curproxy->server_rules, list) { |
| 6341 | struct server *target = findserver(curproxy, srule->srv.name); |
| 6342 | |
| 6343 | if (!target) { |
| 6344 | Alert("config : %s '%s' : unable to find server '%s' referenced in a 'use-server' rule.\n", |
| 6345 | proxy_type_str(curproxy), curproxy->id, srule->srv.name); |
| 6346 | cfgerr++; |
| 6347 | continue; |
| 6348 | } |
| 6349 | free((void *)srule->srv.name); |
| 6350 | srule->srv.ptr = target; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6351 | } |
| 6352 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6353 | /* find the target table for 'stick' rules */ |
| 6354 | list_for_each_entry(mrule, &curproxy->sticking_rules, list) { |
| 6355 | struct proxy *target; |
| 6356 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 6357 | curproxy->be_req_ana |= AN_REQ_STICKING_RULES; |
| 6358 | if (mrule->flags & STK_IS_STORE) |
| 6359 | curproxy->be_rsp_ana |= AN_RES_STORE_RULES; |
| 6360 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6361 | if (mrule->table.name) |
Willy Tarreau | c00cdc2 | 2010-06-06 16:48:26 +0200 | [diff] [blame] | 6362 | target = findproxy(mrule->table.name, 0); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6363 | else |
| 6364 | target = curproxy; |
| 6365 | |
| 6366 | if (!target) { |
| 6367 | Alert("Proxy '%s': unable to find stick-table '%s'.\n", |
| 6368 | curproxy->id, mrule->table.name); |
| 6369 | cfgerr++; |
| 6370 | } |
| 6371 | else if (target->table.size == 0) { |
| 6372 | Alert("Proxy '%s': stick-table '%s' used but not configured.\n", |
| 6373 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 6374 | cfgerr++; |
| 6375 | } |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 6376 | else if (!stktable_compatible_sample(mrule->expr, target->table.type)) { |
| 6377 | 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] | 6378 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 6379 | cfgerr++; |
| 6380 | } |
| 6381 | else { |
| 6382 | free((void *)mrule->table.name); |
| 6383 | mrule->table.t = &(target->table); |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 6384 | stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID, NULL); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6385 | } |
| 6386 | } |
| 6387 | |
| 6388 | /* find the target table for 'store response' rules */ |
| 6389 | list_for_each_entry(mrule, &curproxy->storersp_rules, list) { |
| 6390 | struct proxy *target; |
| 6391 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 6392 | curproxy->be_rsp_ana |= AN_RES_STORE_RULES; |
| 6393 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6394 | if (mrule->table.name) |
Willy Tarreau | c00cdc2 | 2010-06-06 16:48:26 +0200 | [diff] [blame] | 6395 | target = findproxy(mrule->table.name, 0); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6396 | else |
| 6397 | target = curproxy; |
| 6398 | |
| 6399 | if (!target) { |
| 6400 | Alert("Proxy '%s': unable to find store table '%s'.\n", |
| 6401 | curproxy->id, mrule->table.name); |
| 6402 | cfgerr++; |
| 6403 | } |
| 6404 | else if (target->table.size == 0) { |
| 6405 | Alert("Proxy '%s': stick-table '%s' used but not configured.\n", |
| 6406 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 6407 | cfgerr++; |
| 6408 | } |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 6409 | else if (!stktable_compatible_sample(mrule->expr, target->table.type)) { |
| 6410 | 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] | 6411 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 6412 | cfgerr++; |
| 6413 | } |
| 6414 | else { |
| 6415 | free((void *)mrule->table.name); |
| 6416 | mrule->table.t = &(target->table); |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 6417 | stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID, NULL); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6418 | } |
| 6419 | } |
| 6420 | |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 6421 | /* find the target table for 'tcp-request' layer 4 rules */ |
| 6422 | list_for_each_entry(trule, &curproxy->tcp_req.l4_rules, list) { |
| 6423 | struct proxy *target; |
| 6424 | |
Willy Tarreau | b4c8493 | 2013-07-23 19:15:30 +0200 | [diff] [blame] | 6425 | if (trule->action < TCP_ACT_TRK_SC0 || trule->action > TCP_ACT_TRK_SCMAX) |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 6426 | continue; |
| 6427 | |
| 6428 | if (trule->act_prm.trk_ctr.table.n) |
| 6429 | target = findproxy(trule->act_prm.trk_ctr.table.n, 0); |
| 6430 | else |
| 6431 | target = curproxy; |
| 6432 | |
| 6433 | if (!target) { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6434 | Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n", |
| 6435 | curproxy->id, trule->act_prm.trk_ctr.table.n, |
Willy Tarreau | 34c2fb6 | 2013-12-02 23:29:05 +0100 | [diff] [blame] | 6436 | tcp_trk_idx(trule->action)); |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 6437 | cfgerr++; |
| 6438 | } |
| 6439 | else if (target->table.size == 0) { |
| 6440 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
| 6441 | curproxy->id, trule->act_prm.trk_ctr.table.n ? trule->act_prm.trk_ctr.table.n : curproxy->id); |
| 6442 | cfgerr++; |
| 6443 | } |
Willy Tarreau | 5f53de7 | 2012-12-12 00:25:44 +0100 | [diff] [blame] | 6444 | else if (!stktable_compatible_sample(trule->act_prm.trk_ctr.expr, target->table.type)) { |
| 6445 | Alert("Proxy '%s': stick-table '%s' uses a type incompatible with the 'track-sc%d' rule.\n", |
| 6446 | curproxy->id, trule->act_prm.trk_ctr.table.n ? trule->act_prm.trk_ctr.table.n : curproxy->id, |
Willy Tarreau | 34c2fb6 | 2013-12-02 23:29:05 +0100 | [diff] [blame] | 6447 | tcp_trk_idx(trule->action)); |
Willy Tarreau | 5f53de7 | 2012-12-12 00:25:44 +0100 | [diff] [blame] | 6448 | cfgerr++; |
| 6449 | } |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 6450 | else { |
| 6451 | free(trule->act_prm.trk_ctr.table.n); |
| 6452 | trule->act_prm.trk_ctr.table.t = &target->table; |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6453 | /* 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] | 6454 | * to pass a list of counters to track and allocate them right here using |
| 6455 | * stktable_alloc_data_type(). |
| 6456 | */ |
| 6457 | } |
| 6458 | } |
| 6459 | |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 6460 | /* find the target table for 'tcp-request' layer 6 rules */ |
| 6461 | list_for_each_entry(trule, &curproxy->tcp_req.inspect_rules, list) { |
| 6462 | struct proxy *target; |
| 6463 | |
Willy Tarreau | b4c8493 | 2013-07-23 19:15:30 +0200 | [diff] [blame] | 6464 | if (trule->action < TCP_ACT_TRK_SC0 || trule->action > TCP_ACT_TRK_SCMAX) |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 6465 | continue; |
| 6466 | |
| 6467 | if (trule->act_prm.trk_ctr.table.n) |
| 6468 | target = findproxy(trule->act_prm.trk_ctr.table.n, 0); |
| 6469 | else |
| 6470 | target = curproxy; |
| 6471 | |
| 6472 | if (!target) { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6473 | Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n", |
| 6474 | curproxy->id, trule->act_prm.trk_ctr.table.n, |
Willy Tarreau | 34c2fb6 | 2013-12-02 23:29:05 +0100 | [diff] [blame] | 6475 | tcp_trk_idx(trule->action)); |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 6476 | cfgerr++; |
| 6477 | } |
| 6478 | else if (target->table.size == 0) { |
| 6479 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
| 6480 | curproxy->id, trule->act_prm.trk_ctr.table.n ? trule->act_prm.trk_ctr.table.n : curproxy->id); |
| 6481 | cfgerr++; |
| 6482 | } |
Willy Tarreau | 5f53de7 | 2012-12-12 00:25:44 +0100 | [diff] [blame] | 6483 | else if (!stktable_compatible_sample(trule->act_prm.trk_ctr.expr, target->table.type)) { |
| 6484 | Alert("Proxy '%s': stick-table '%s' uses a type incompatible with the 'track-sc%d' rule.\n", |
| 6485 | curproxy->id, trule->act_prm.trk_ctr.table.n ? trule->act_prm.trk_ctr.table.n : curproxy->id, |
Willy Tarreau | 34c2fb6 | 2013-12-02 23:29:05 +0100 | [diff] [blame] | 6486 | tcp_trk_idx(trule->action)); |
Willy Tarreau | 5f53de7 | 2012-12-12 00:25:44 +0100 | [diff] [blame] | 6487 | cfgerr++; |
| 6488 | } |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 6489 | else { |
| 6490 | free(trule->act_prm.trk_ctr.table.n); |
| 6491 | trule->act_prm.trk_ctr.table.t = &target->table; |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6492 | /* 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] | 6493 | * to pass a list of counters to track and allocate them right here using |
| 6494 | * stktable_alloc_data_type(). |
| 6495 | */ |
| 6496 | } |
| 6497 | } |
| 6498 | |
Willy Tarreau | b3dc39d | 2014-04-28 22:06:57 +0200 | [diff] [blame] | 6499 | /* move any "block" rules at the beginning of the http-request rules */ |
| 6500 | if (!LIST_ISEMPTY(&curproxy->block_rules)) { |
| 6501 | /* insert block_rules into http_req_rules at the beginning */ |
| 6502 | curproxy->block_rules.p->n = curproxy->http_req_rules.n; |
| 6503 | curproxy->http_req_rules.n->p = curproxy->block_rules.p; |
| 6504 | curproxy->block_rules.n->p = &curproxy->http_req_rules; |
| 6505 | curproxy->http_req_rules.n = curproxy->block_rules.n; |
| 6506 | LIST_INIT(&curproxy->block_rules); |
| 6507 | } |
| 6508 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 6509 | if (curproxy->table.peers.name) { |
| 6510 | struct peers *curpeers = peers; |
| 6511 | |
| 6512 | for (curpeers = peers; curpeers; curpeers = curpeers->next) { |
| 6513 | if (strcmp(curpeers->id, curproxy->table.peers.name) == 0) { |
| 6514 | free((void *)curproxy->table.peers.name); |
Willy Tarreau | 973ca49 | 2013-01-17 21:34:52 +0100 | [diff] [blame] | 6515 | curproxy->table.peers.p = curpeers; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 6516 | break; |
| 6517 | } |
| 6518 | } |
| 6519 | |
| 6520 | if (!curpeers) { |
| 6521 | Alert("Proxy '%s': unable to find sync peers '%s'.\n", |
| 6522 | curproxy->id, curproxy->table.peers.name); |
Willy Tarreau | d66bf96 | 2011-10-28 14:16:49 +0200 | [diff] [blame] | 6523 | free((void *)curproxy->table.peers.name); |
| 6524 | curproxy->table.peers.p = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 6525 | cfgerr++; |
| 6526 | } |
| 6527 | else if (!curpeers->peers_fe) { |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 6528 | Alert("Proxy '%s': unable to find local peer '%s' in peers section '%s'.\n", |
| 6529 | curproxy->id, localpeer, curpeers->id); |
Willy Tarreau | d66bf96 | 2011-10-28 14:16:49 +0200 | [diff] [blame] | 6530 | curproxy->table.peers.p = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 6531 | cfgerr++; |
| 6532 | } |
| 6533 | } |
| 6534 | |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 6535 | if (curproxy->uri_auth && !(curproxy->uri_auth->flags & ST_CONVDONE) && |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 6536 | !LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) && |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6537 | (curproxy->uri_auth->userlist || curproxy->uri_auth->auth_realm )) { |
| 6538 | Alert("%s '%s': stats 'auth'/'realm' and 'http-request' can't be used at the same time.\n", |
| 6539 | "proxy", curproxy->id); |
| 6540 | cfgerr++; |
| 6541 | goto out_uri_auth_compat; |
| 6542 | } |
| 6543 | |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 6544 | 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] | 6545 | const char *uri_auth_compat_req[10]; |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 6546 | struct http_req_rule *rule; |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6547 | int i = 0; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6548 | |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6549 | /* build the ACL condition from scratch. We're relying on anonymous ACLs for that */ |
| 6550 | uri_auth_compat_req[i++] = "auth"; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6551 | |
| 6552 | if (curproxy->uri_auth->auth_realm) { |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6553 | uri_auth_compat_req[i++] = "realm"; |
| 6554 | uri_auth_compat_req[i++] = curproxy->uri_auth->auth_realm; |
| 6555 | } |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6556 | |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6557 | uri_auth_compat_req[i++] = "unless"; |
| 6558 | uri_auth_compat_req[i++] = "{"; |
| 6559 | uri_auth_compat_req[i++] = "http_auth(.internal-stats-userlist)"; |
| 6560 | uri_auth_compat_req[i++] = "}"; |
| 6561 | uri_auth_compat_req[i++] = ""; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6562 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 6563 | rule = parse_http_req_cond(uri_auth_compat_req, "internal-stats-auth-compat", 0, curproxy); |
| 6564 | if (!rule) { |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6565 | cfgerr++; |
| 6566 | break; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6567 | } |
| 6568 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 6569 | LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list); |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6570 | |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6571 | if (curproxy->uri_auth->auth_realm) { |
| 6572 | free(curproxy->uri_auth->auth_realm); |
| 6573 | curproxy->uri_auth->auth_realm = NULL; |
| 6574 | } |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 6575 | |
| 6576 | curproxy->uri_auth->flags |= ST_CONVDONE; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6577 | } |
| 6578 | out_uri_auth_compat: |
| 6579 | |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 6580 | /* compile the log format */ |
| 6581 | if (!(curproxy->cap & PR_CAP_FE)) { |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 6582 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 6583 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 6584 | curproxy->conf.logformat_string != clf_http_log_format) |
| 6585 | free(curproxy->conf.logformat_string); |
| 6586 | curproxy->conf.logformat_string = NULL; |
| 6587 | free(curproxy->conf.lfs_file); |
| 6588 | curproxy->conf.lfs_file = NULL; |
| 6589 | curproxy->conf.lfs_line = 0; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 6590 | } |
| 6591 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 6592 | if (curproxy->conf.logformat_string) { |
| 6593 | curproxy->conf.args.ctx = ARGC_LOG; |
| 6594 | curproxy->conf.args.file = curproxy->conf.lfs_file; |
| 6595 | curproxy->conf.args.line = curproxy->conf.lfs_line; |
| 6596 | parse_logformat_string(curproxy->conf.logformat_string, curproxy, &curproxy->logformat, LOG_OPT_MANDATORY, |
Thierry FOURNIER | eeaa951 | 2014-02-11 14:00:19 +0100 | [diff] [blame] | 6597 | SMP_VAL_FE_LOG_END, curproxy->conf.lfs_file, curproxy->conf.lfs_line); |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 6598 | curproxy->conf.args.file = NULL; |
| 6599 | curproxy->conf.args.line = 0; |
| 6600 | } |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 6601 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 6602 | if (curproxy->conf.uniqueid_format_string) { |
| 6603 | curproxy->conf.args.ctx = ARGC_UIF; |
| 6604 | curproxy->conf.args.file = curproxy->conf.uif_file; |
| 6605 | curproxy->conf.args.line = curproxy->conf.uif_line; |
Thierry FOURNIER | d048d8b | 2014-03-13 16:46:18 +0100 | [diff] [blame] | 6606 | parse_logformat_string(curproxy->conf.uniqueid_format_string, curproxy, &curproxy->format_unique_id, LOG_OPT_HTTP, |
Godbach | 543b978 | 2014-12-18 15:44:58 +0800 | [diff] [blame] | 6607 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
Thierry FOURNIER | eeaa951 | 2014-02-11 14:00:19 +0100 | [diff] [blame] | 6608 | curproxy->conf.uif_file, curproxy->conf.uif_line); |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 6609 | curproxy->conf.args.file = NULL; |
| 6610 | curproxy->conf.args.line = 0; |
| 6611 | } |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 6612 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6613 | /* only now we can check if some args remain unresolved. |
| 6614 | * This must be done after the users and groups resolution. |
| 6615 | */ |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 6616 | cfgerr += smp_resolve_args(curproxy); |
| 6617 | if (!cfgerr) |
| 6618 | cfgerr += acl_find_targets(curproxy); |
Krzysztof Piotr Oledzki | f9423ae | 2010-01-29 19:26:18 +0100 | [diff] [blame] | 6619 | |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 6620 | if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) && |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6621 | (((curproxy->cap & PR_CAP_FE) && !curproxy->timeout.client) || |
Willy Tarreau | d825eef | 2007-05-12 22:35:00 +0200 | [diff] [blame] | 6622 | ((curproxy->cap & PR_CAP_BE) && (curproxy->srv) && |
Willy Tarreau | ce887fd | 2012-05-12 12:50:00 +0200 | [diff] [blame] | 6623 | (!curproxy->timeout.connect || |
| 6624 | (!curproxy->timeout.server && (curproxy->mode == PR_MODE_HTTP || !curproxy->timeout.tunnel)))))) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6625 | Warning("config : missing timeouts for %s '%s'.\n" |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 6626 | " | While not properly invalid, you will certainly encounter various problems\n" |
| 6627 | " | 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] | 6628 | " | timeouts are set to a non-zero value: 'client', 'connect', 'server'.\n", |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6629 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6630 | err_code |= ERR_WARN; |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 6631 | } |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 6632 | |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6633 | /* Historically, the tarpit and queue timeouts were inherited from contimeout. |
| 6634 | * We must still support older configurations, so let's find out whether those |
| 6635 | * parameters have been set or must be copied from contimeouts. |
| 6636 | */ |
| 6637 | if (curproxy != &defproxy) { |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6638 | if (!curproxy->timeout.tarpit || |
| 6639 | curproxy->timeout.tarpit == defproxy.timeout.tarpit) { |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6640 | /* tarpit timeout not set. We search in the following order: |
| 6641 | * default.tarpit, curr.connect, default.connect. |
| 6642 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6643 | if (defproxy.timeout.tarpit) |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6644 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6645 | else if (curproxy->timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6646 | curproxy->timeout.tarpit = curproxy->timeout.connect; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6647 | else if (defproxy.timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6648 | curproxy->timeout.tarpit = defproxy.timeout.connect; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6649 | } |
| 6650 | if ((curproxy->cap & PR_CAP_BE) && |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6651 | (!curproxy->timeout.queue || |
| 6652 | curproxy->timeout.queue == defproxy.timeout.queue)) { |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6653 | /* queue timeout not set. We search in the following order: |
| 6654 | * default.queue, curr.connect, default.connect. |
| 6655 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6656 | if (defproxy.timeout.queue) |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6657 | curproxy->timeout.queue = defproxy.timeout.queue; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6658 | else if (curproxy->timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6659 | curproxy->timeout.queue = curproxy->timeout.connect; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6660 | else if (defproxy.timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6661 | curproxy->timeout.queue = defproxy.timeout.connect; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6662 | } |
| 6663 | } |
| 6664 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 6665 | if ((curproxy->options2 & PR_O2_CHK_ANY) == PR_O2_SSL3_CHK) { |
Willy Tarreau | 137325d | 2010-02-01 16:38:17 +0100 | [diff] [blame] | 6666 | curproxy->check_len = sizeof(sslv3_client_hello_pkt) - 1; |
| 6667 | curproxy->check_req = (char *)malloc(curproxy->check_len); |
| 6668 | memcpy(curproxy->check_req, sslv3_client_hello_pkt, curproxy->check_len); |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 6669 | } |
| 6670 | |
Willy Tarreau | 215663d | 2014-06-13 18:30:23 +0200 | [diff] [blame] | 6671 | if (!LIST_ISEMPTY(&curproxy->tcpcheck_rules) && |
| 6672 | (curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_TCPCHK_CHK) { |
| 6673 | Warning("config : %s '%s' uses tcp-check rules without 'option tcp-check', so the rules are ignored.\n", |
| 6674 | proxy_type_str(curproxy), curproxy->id); |
| 6675 | err_code |= ERR_WARN; |
| 6676 | } |
| 6677 | |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 6678 | /* ensure that cookie capture length is not too large */ |
| 6679 | if (curproxy->capture_len >= global.tune.cookie_len) { |
| 6680 | Warning("config : truncating capture length to %d bytes for %s '%s'.\n", |
| 6681 | global.tune.cookie_len - 1, proxy_type_str(curproxy), curproxy->id); |
| 6682 | err_code |= ERR_WARN; |
| 6683 | curproxy->capture_len = global.tune.cookie_len - 1; |
| 6684 | } |
| 6685 | |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 6686 | /* The small pools required for the capture lists */ |
Willy Tarreau | 9a54e13 | 2012-03-24 08:33:05 +0100 | [diff] [blame] | 6687 | if (curproxy->nb_req_cap) { |
Willy Tarreau | d9ed3d2 | 2014-06-13 12:23:06 +0200 | [diff] [blame] | 6688 | curproxy->req_cap_pool = create_pool("ptrcap", |
| 6689 | curproxy->nb_req_cap * sizeof(char *), |
| 6690 | MEM_F_SHARED); |
Willy Tarreau | 9a54e13 | 2012-03-24 08:33:05 +0100 | [diff] [blame] | 6691 | } |
| 6692 | |
| 6693 | if (curproxy->nb_rsp_cap) { |
Willy Tarreau | d9ed3d2 | 2014-06-13 12:23:06 +0200 | [diff] [blame] | 6694 | curproxy->rsp_cap_pool = create_pool("ptrcap", |
| 6695 | curproxy->nb_rsp_cap * sizeof(char *), |
| 6696 | MEM_F_SHARED); |
Willy Tarreau | 9a54e13 | 2012-03-24 08:33:05 +0100 | [diff] [blame] | 6697 | } |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 6698 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6699 | /* first, we will invert the servers list order */ |
| 6700 | newsrv = NULL; |
| 6701 | while (curproxy->srv) { |
| 6702 | struct server *next; |
| 6703 | |
| 6704 | next = curproxy->srv->next; |
| 6705 | curproxy->srv->next = newsrv; |
| 6706 | newsrv = curproxy->srv; |
| 6707 | if (!next) |
| 6708 | break; |
| 6709 | curproxy->srv = next; |
| 6710 | } |
| 6711 | |
Willy Tarreau | 17edc81 | 2014-01-03 12:14:34 +0100 | [diff] [blame] | 6712 | /* Check that no server name conflicts. This causes trouble in the stats. |
| 6713 | * We only emit a warning for the first conflict affecting each server, |
| 6714 | * in order to avoid combinatory explosion if all servers have the same |
| 6715 | * name. We do that only for servers which do not have an explicit ID, |
| 6716 | * because these IDs were made also for distinguishing them and we don't |
| 6717 | * want to annoy people who correctly manage them. |
| 6718 | */ |
| 6719 | for (newsrv = curproxy->srv; newsrv; newsrv = newsrv->next) { |
| 6720 | struct server *other_srv; |
| 6721 | |
| 6722 | if (newsrv->puid) |
| 6723 | continue; |
| 6724 | |
| 6725 | for (other_srv = curproxy->srv; other_srv && other_srv != newsrv; other_srv = other_srv->next) { |
| 6726 | if (!other_srv->puid && strcmp(other_srv->id, newsrv->id) == 0) { |
| 6727 | Warning("parsing [%s:%d] : %s '%s', another server named '%s' was defined without an explicit ID at line %d, this is not recommended.\n", |
| 6728 | newsrv->conf.file, newsrv->conf.line, |
| 6729 | proxy_type_str(curproxy), curproxy->id, |
| 6730 | newsrv->id, other_srv->conf.line); |
| 6731 | break; |
| 6732 | } |
| 6733 | } |
| 6734 | } |
| 6735 | |
Willy Tarreau | dd70165 | 2010-05-25 23:03:02 +0200 | [diff] [blame] | 6736 | /* assign automatic UIDs to servers which don't have one yet */ |
| 6737 | next_id = 1; |
| 6738 | newsrv = curproxy->srv; |
| 6739 | while (newsrv != NULL) { |
| 6740 | if (!newsrv->puid) { |
| 6741 | /* server ID not set, use automatic numbering with first |
| 6742 | * spare entry starting with next_svid. |
| 6743 | */ |
| 6744 | next_id = get_next_id(&curproxy->conf.used_server_id, next_id); |
| 6745 | newsrv->conf.id.key = newsrv->puid = next_id; |
| 6746 | eb32_insert(&curproxy->conf.used_server_id, &newsrv->conf.id); |
| 6747 | } |
| 6748 | next_id++; |
| 6749 | newsrv = newsrv->next; |
| 6750 | } |
| 6751 | |
Willy Tarreau | 2069704 | 2007-11-15 23:26:18 +0100 | [diff] [blame] | 6752 | curproxy->lbprm.wmult = 1; /* default weight multiplier */ |
Willy Tarreau | 5dc2fa6 | 2007-11-19 19:10:18 +0100 | [diff] [blame] | 6753 | curproxy->lbprm.wdiv = 1; /* default weight divider */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6754 | |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 6755 | /* |
| 6756 | * If this server supports a maxconn parameter, it needs a dedicated |
| 6757 | * tasks to fill the emptied slots when a connection leaves. |
| 6758 | * Also, resolve deferred tracking dependency if needed. |
| 6759 | */ |
| 6760 | newsrv = curproxy->srv; |
| 6761 | while (newsrv != NULL) { |
| 6762 | if (newsrv->minconn > newsrv->maxconn) { |
| 6763 | /* Only 'minconn' was specified, or it was higher than or equal |
| 6764 | * to 'maxconn'. Let's turn this into maxconn and clean it, as |
| 6765 | * this will avoid further useless expensive computations. |
| 6766 | */ |
| 6767 | newsrv->maxconn = newsrv->minconn; |
| 6768 | } else if (newsrv->maxconn && !newsrv->minconn) { |
| 6769 | /* minconn was not specified, so we set it to maxconn */ |
| 6770 | newsrv->minconn = newsrv->maxconn; |
| 6771 | } |
| 6772 | |
Emeric Brun | 01f8e2f | 2012-05-18 16:02:00 +0200 | [diff] [blame] | 6773 | #ifdef USE_OPENSSL |
Emeric Brun | 94324a4 | 2012-10-11 14:00:19 +0200 | [diff] [blame] | 6774 | if (newsrv->use_ssl || newsrv->check.use_ssl) |
| 6775 | cfgerr += ssl_sock_prepare_srv_ctx(newsrv, curproxy); |
Emeric Brun | 01f8e2f | 2012-05-18 16:02:00 +0200 | [diff] [blame] | 6776 | #endif /* USE_OPENSSL */ |
Emeric Brun | 94324a4 | 2012-10-11 14:00:19 +0200 | [diff] [blame] | 6777 | |
Willy Tarreau | 2f075e9 | 2013-12-03 11:11:34 +0100 | [diff] [blame] | 6778 | /* set the check type on the server */ |
| 6779 | newsrv->check.type = curproxy->options2 & PR_O2_CHK_ANY; |
| 6780 | |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 6781 | if (newsrv->trackit) { |
| 6782 | struct proxy *px; |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 6783 | struct server *srv, *loop; |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 6784 | char *pname, *sname; |
| 6785 | |
| 6786 | pname = newsrv->trackit; |
| 6787 | sname = strrchr(pname, '/'); |
| 6788 | |
| 6789 | if (sname) |
| 6790 | *sname++ = '\0'; |
| 6791 | else { |
| 6792 | sname = pname; |
| 6793 | pname = NULL; |
| 6794 | } |
| 6795 | |
| 6796 | if (pname) { |
| 6797 | px = findproxy(pname, PR_CAP_BE); |
| 6798 | if (!px) { |
| 6799 | Alert("config : %s '%s', server '%s': unable to find required proxy '%s' for tracking.\n", |
| 6800 | proxy_type_str(curproxy), curproxy->id, |
| 6801 | newsrv->id, pname); |
| 6802 | cfgerr++; |
| 6803 | goto next_srv; |
| 6804 | } |
| 6805 | } else |
| 6806 | px = curproxy; |
| 6807 | |
| 6808 | srv = findserver(px, sname); |
| 6809 | if (!srv) { |
| 6810 | Alert("config : %s '%s', server '%s': unable to find required server '%s' for tracking.\n", |
| 6811 | proxy_type_str(curproxy), curproxy->id, |
| 6812 | newsrv->id, sname); |
| 6813 | cfgerr++; |
| 6814 | goto next_srv; |
| 6815 | } |
| 6816 | |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 6817 | if (!(srv->check.state & CHK_ST_CONFIGURED) && |
| 6818 | !(srv->agent.state & CHK_ST_CONFIGURED) && |
| 6819 | !srv->track && !srv->trackit) { |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 6820 | Alert("config : %s '%s', server '%s': unable to use %s/%s for " |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 6821 | "tracking as it does not have any check nor agent enabled.\n", |
| 6822 | proxy_type_str(curproxy), curproxy->id, |
| 6823 | newsrv->id, px->id, srv->id); |
| 6824 | cfgerr++; |
| 6825 | goto next_srv; |
| 6826 | } |
| 6827 | |
| 6828 | for (loop = srv->track; loop && loop != newsrv; loop = loop->track); |
| 6829 | |
| 6830 | if (loop) { |
| 6831 | Alert("config : %s '%s', server '%s': unable to track %s/%s as it " |
| 6832 | "belongs to a tracking chain looping back to %s/%s.\n", |
| 6833 | proxy_type_str(curproxy), curproxy->id, |
| 6834 | newsrv->id, px->id, srv->id, px->id, loop->id); |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 6835 | cfgerr++; |
| 6836 | goto next_srv; |
| 6837 | } |
| 6838 | |
| 6839 | if (curproxy != px && |
| 6840 | (curproxy->options & PR_O_DISABLE404) != (px->options & PR_O_DISABLE404)) { |
| 6841 | Alert("config : %s '%s', server '%s': unable to use %s/%s for" |
| 6842 | "tracking: disable-on-404 option inconsistency.\n", |
| 6843 | proxy_type_str(curproxy), curproxy->id, |
| 6844 | newsrv->id, px->id, srv->id); |
| 6845 | cfgerr++; |
| 6846 | goto next_srv; |
| 6847 | } |
| 6848 | |
| 6849 | /* if the other server is forced disabled, we have to do the same here */ |
Willy Tarreau | 2012521 | 2014-05-13 19:44:56 +0200 | [diff] [blame] | 6850 | if (srv->admin & SRV_ADMF_MAINT) { |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 6851 | newsrv->admin |= SRV_ADMF_IMAINT; |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 6852 | newsrv->state = SRV_ST_STOPPED; |
Simon Horman | 125d099 | 2013-02-24 17:23:38 +0900 | [diff] [blame] | 6853 | newsrv->check.health = 0; |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 6854 | } |
| 6855 | |
| 6856 | newsrv->track = srv; |
Willy Tarreau | 1a53a3a | 2013-12-11 15:27:05 +0100 | [diff] [blame] | 6857 | newsrv->tracknext = srv->trackers; |
| 6858 | srv->trackers = newsrv; |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 6859 | |
| 6860 | free(newsrv->trackit); |
| 6861 | newsrv->trackit = NULL; |
| 6862 | } |
| 6863 | next_srv: |
| 6864 | newsrv = newsrv->next; |
| 6865 | } |
| 6866 | |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6867 | /* We have to initialize the server lookup mechanism depending |
| 6868 | * on what LB algorithm was choosen. |
| 6869 | */ |
| 6870 | |
| 6871 | curproxy->lbprm.algo &= ~(BE_LB_LKUP | BE_LB_PROP_DYN); |
| 6872 | switch (curproxy->lbprm.algo & BE_LB_KIND) { |
| 6873 | case BE_LB_KIND_RR: |
Willy Tarreau | 9757a38 | 2009-10-03 12:56:50 +0200 | [diff] [blame] | 6874 | if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_RR_STATIC) { |
| 6875 | curproxy->lbprm.algo |= BE_LB_LKUP_MAP; |
| 6876 | init_server_map(curproxy); |
| 6877 | } else { |
| 6878 | curproxy->lbprm.algo |= BE_LB_LKUP_RRTREE | BE_LB_PROP_DYN; |
| 6879 | fwrr_init_server_groups(curproxy); |
| 6880 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6881 | break; |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 6882 | |
Willy Tarreau | 3ebb116 | 2012-02-13 16:57:44 +0100 | [diff] [blame] | 6883 | case BE_LB_KIND_CB: |
Willy Tarreau | f09c660 | 2012-02-13 17:12:08 +0100 | [diff] [blame] | 6884 | if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_CB_LC) { |
| 6885 | curproxy->lbprm.algo |= BE_LB_LKUP_LCTREE | BE_LB_PROP_DYN; |
| 6886 | fwlc_init_server_tree(curproxy); |
| 6887 | } else { |
| 6888 | curproxy->lbprm.algo |= BE_LB_LKUP_FSTREE | BE_LB_PROP_DYN; |
| 6889 | fas_init_server_tree(curproxy); |
| 6890 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6891 | break; |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 6892 | |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6893 | case BE_LB_KIND_HI: |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 6894 | if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS) { |
| 6895 | curproxy->lbprm.algo |= BE_LB_LKUP_CHTREE | BE_LB_PROP_DYN; |
| 6896 | chash_init_server_tree(curproxy); |
| 6897 | } else { |
| 6898 | curproxy->lbprm.algo |= BE_LB_LKUP_MAP; |
| 6899 | init_server_map(curproxy); |
| 6900 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6901 | break; |
| 6902 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6903 | |
| 6904 | if (curproxy->options & PR_O_LOGASAP) |
| 6905 | curproxy->to_log &= ~LW_BYTES; |
| 6906 | |
Willy Tarreau | e7ded1f | 2009-08-09 10:11:45 +0200 | [diff] [blame] | 6907 | if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) && |
Willy Tarreau | d79a3b2 | 2012-12-28 09:40:16 +0100 | [diff] [blame] | 6908 | (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] | 6909 | Warning("config : log format ignored for %s '%s' since it has no log address.\n", |
| 6910 | proxy_type_str(curproxy), curproxy->id); |
| 6911 | err_code |= ERR_WARN; |
| 6912 | } |
| 6913 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 6914 | if (curproxy->mode != PR_MODE_HTTP) { |
| 6915 | int optnum; |
| 6916 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 6917 | if (curproxy->uri_auth) { |
| 6918 | Warning("config : 'stats' statement ignored for %s '%s' as it requires HTTP mode.\n", |
| 6919 | proxy_type_str(curproxy), curproxy->id); |
| 6920 | err_code |= ERR_WARN; |
| 6921 | curproxy->uri_auth = NULL; |
| 6922 | } |
| 6923 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 6924 | if (curproxy->options & (PR_O_FWDFOR | PR_O_FF_ALWAYS)) { |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 6925 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6926 | "forwardfor", proxy_type_str(curproxy), curproxy->id); |
| 6927 | err_code |= ERR_WARN; |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 6928 | curproxy->options &= ~(PR_O_FWDFOR | PR_O_FF_ALWAYS); |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 6929 | } |
| 6930 | |
| 6931 | if (curproxy->options & PR_O_ORGTO) { |
| 6932 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6933 | "originalto", proxy_type_str(curproxy), curproxy->id); |
| 6934 | err_code |= ERR_WARN; |
| 6935 | curproxy->options &= ~PR_O_ORGTO; |
| 6936 | } |
| 6937 | |
| 6938 | for (optnum = 0; cfg_opts[optnum].name; optnum++) { |
| 6939 | if (cfg_opts[optnum].mode == PR_MODE_HTTP && |
| 6940 | (curproxy->cap & cfg_opts[optnum].cap) && |
| 6941 | (curproxy->options & cfg_opts[optnum].val)) { |
| 6942 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6943 | cfg_opts[optnum].name, proxy_type_str(curproxy), curproxy->id); |
| 6944 | err_code |= ERR_WARN; |
| 6945 | curproxy->options &= ~cfg_opts[optnum].val; |
| 6946 | } |
| 6947 | } |
| 6948 | |
| 6949 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) { |
| 6950 | if (cfg_opts2[optnum].mode == PR_MODE_HTTP && |
| 6951 | (curproxy->cap & cfg_opts2[optnum].cap) && |
| 6952 | (curproxy->options2 & cfg_opts2[optnum].val)) { |
| 6953 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6954 | cfg_opts2[optnum].name, proxy_type_str(curproxy), curproxy->id); |
| 6955 | err_code |= ERR_WARN; |
| 6956 | curproxy->options2 &= ~cfg_opts2[optnum].val; |
| 6957 | } |
| 6958 | } |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6959 | |
Pieter Baauw | d551fb5 | 2013-05-08 22:49:23 +0200 | [diff] [blame] | 6960 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_TRANSPARENT) |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6961 | if (curproxy->conn_src.bind_hdr_occ) { |
| 6962 | curproxy->conn_src.bind_hdr_occ = 0; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6963 | 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] | 6964 | proxy_type_str(curproxy), curproxy->id, curproxy->conn_src.bind_hdr_name); |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6965 | err_code |= ERR_WARN; |
| 6966 | } |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 6967 | #endif |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 6968 | } |
| 6969 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6970 | /* |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 6971 | * ensure that we're not cross-dressing a TCP server into HTTP. |
| 6972 | */ |
| 6973 | newsrv = curproxy->srv; |
| 6974 | while (newsrv != NULL) { |
Willy Tarreau | 0cec331 | 2011-10-31 13:49:26 +0100 | [diff] [blame] | 6975 | if ((curproxy->mode != PR_MODE_HTTP) && newsrv->rdr_len) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6976 | Alert("config : %s '%s' : server cannot have cookie or redirect prefix in non-HTTP mode.\n", |
| 6977 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6978 | cfgerr++; |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 6979 | } |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6980 | |
Willy Tarreau | 0cec331 | 2011-10-31 13:49:26 +0100 | [diff] [blame] | 6981 | if ((curproxy->mode != PR_MODE_HTTP) && newsrv->cklen) { |
| 6982 | Warning("config : %s '%s' : ignoring cookie for server '%s' as HTTP mode is disabled.\n", |
| 6983 | proxy_type_str(curproxy), curproxy->id, newsrv->id); |
| 6984 | err_code |= ERR_WARN; |
| 6985 | } |
| 6986 | |
Willy Tarreau | c93cd16 | 2014-05-13 15:54:22 +0200 | [diff] [blame] | 6987 | if ((newsrv->flags & SRV_F_MAPPORTS) && (curproxy->options2 & PR_O2_RDPC_PRST)) { |
Willy Tarreau | 82ffa39 | 2013-08-13 17:19:08 +0200 | [diff] [blame] | 6988 | Warning("config : %s '%s' : RDP cookie persistence will not work for server '%s' because it lacks an explicit port number.\n", |
| 6989 | proxy_type_str(curproxy), curproxy->id, newsrv->id); |
| 6990 | err_code |= ERR_WARN; |
| 6991 | } |
| 6992 | |
Pieter Baauw | d551fb5 | 2013-05-08 22:49:23 +0200 | [diff] [blame] | 6993 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_TRANSPARENT) |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6994 | if (curproxy->mode != PR_MODE_HTTP && newsrv->conn_src.bind_hdr_occ) { |
| 6995 | newsrv->conn_src.bind_hdr_occ = 0; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6996 | 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] | 6997 | 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] | 6998 | err_code |= ERR_WARN; |
| 6999 | } |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 7000 | #endif |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 7001 | newsrv = newsrv->next; |
| 7002 | } |
| 7003 | |
Willy Tarreau | 7fc7ebd | 2014-09-16 16:21:19 +0200 | [diff] [blame] | 7004 | /* check if we have a frontend with "tcp-request content" looking at L7 |
| 7005 | * with no inspect-delay |
| 7006 | */ |
| 7007 | if ((curproxy->cap & PR_CAP_FE) && !curproxy->tcp_req.inspect_delay) { |
| 7008 | list_for_each_entry(trule, &curproxy->tcp_req.inspect_rules, list) { |
| 7009 | if (trule->action == TCP_ACT_CAPTURE && |
| 7010 | !(trule->act_prm.cap.expr->fetch->val & SMP_VAL_FE_SES_ACC)) |
| 7011 | break; |
| 7012 | if ((trule->action >= TCP_ACT_TRK_SC0 && trule->action <= TCP_ACT_TRK_SCMAX) && |
| 7013 | !(trule->act_prm.trk_ctr.expr->fetch->val & SMP_VAL_FE_SES_ACC)) |
| 7014 | break; |
| 7015 | } |
| 7016 | |
| 7017 | if (&trule->list != &curproxy->tcp_req.inspect_rules) { |
| 7018 | Warning("config : %s '%s' : some 'tcp-request content' rules explicitly depending on request" |
| 7019 | " contents were found in a frontend without any 'tcp-request inspect-delay' setting." |
| 7020 | " This means that these rules will randomly find their contents. This can be fixed by" |
| 7021 | " setting the tcp-request inspect-delay.\n", |
| 7022 | proxy_type_str(curproxy), curproxy->id); |
| 7023 | err_code |= ERR_WARN; |
| 7024 | } |
| 7025 | } |
| 7026 | |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 7027 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 7028 | if (!curproxy->accept) |
| 7029 | curproxy->accept = frontend_accept; |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 7030 | |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 7031 | if (curproxy->tcp_req.inspect_delay || |
| 7032 | !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules)) |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 7033 | curproxy->fe_req_ana |= AN_REQ_INSPECT_FE; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 7034 | |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 7035 | if (curproxy->mode == PR_MODE_HTTP) { |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 7036 | 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] | 7037 | 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] | 7038 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 7039 | |
| 7040 | /* both TCP and HTTP must check switching rules */ |
| 7041 | curproxy->fe_req_ana |= AN_REQ_SWITCHING_RULES; |
| 7042 | } |
| 7043 | |
| 7044 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 7045 | if (curproxy->tcp_req.inspect_delay || |
| 7046 | !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules)) |
| 7047 | curproxy->be_req_ana |= AN_REQ_INSPECT_BE; |
| 7048 | |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 7049 | if (!LIST_ISEMPTY(&curproxy->tcp_rep.inspect_rules)) |
| 7050 | curproxy->be_rsp_ana |= AN_RES_INSPECT; |
| 7051 | |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 7052 | if (curproxy->mode == PR_MODE_HTTP) { |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 7053 | 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] | 7054 | 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] | 7055 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 7056 | |
| 7057 | /* If the backend does requires RDP cookie persistence, we have to |
| 7058 | * enable the corresponding analyser. |
| 7059 | */ |
| 7060 | if (curproxy->options2 & PR_O2_RDPC_PRST) |
| 7061 | curproxy->be_req_ana |= AN_REQ_PRST_RDP_COOKIE; |
| 7062 | } |
Willy Tarreau | 91b00c2 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 7063 | } |
| 7064 | |
| 7065 | /***********************************************************/ |
| 7066 | /* At this point, target names have already been resolved. */ |
| 7067 | /***********************************************************/ |
| 7068 | |
| 7069 | /* Check multi-process mode compatibility */ |
| 7070 | |
| 7071 | if (global.nbproc > 1 && global.stats_fe) { |
| 7072 | list_for_each_entry(bind_conf, &global.stats_fe->conf.bind, by_fe) { |
| 7073 | unsigned long mask; |
| 7074 | |
| 7075 | mask = nbits(global.nbproc); |
| 7076 | if (global.stats_fe->bind_proc) |
| 7077 | mask &= global.stats_fe->bind_proc; |
| 7078 | |
| 7079 | if (bind_conf->bind_proc) |
| 7080 | mask &= bind_conf->bind_proc; |
| 7081 | |
| 7082 | /* stop here if more than one process is used */ |
| 7083 | if (popcount(mask) > 1) |
| 7084 | break; |
| 7085 | } |
| 7086 | if (&bind_conf->by_fe != &global.stats_fe->conf.bind) { |
| 7087 | Warning("stats socket will not work as expected in multi-process mode (nbproc > 1), you should force process binding globally using 'stats bind-process' or per socket using the 'process' attribute.\n"); |
| 7088 | } |
| 7089 | } |
| 7090 | |
| 7091 | /* Make each frontend inherit bind-process from its listeners when not specified. */ |
| 7092 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 7093 | if (curproxy->bind_proc) |
| 7094 | continue; |
| 7095 | |
| 7096 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
| 7097 | unsigned long mask; |
| 7098 | |
| 7099 | mask = bind_conf->bind_proc ? bind_conf->bind_proc : ~0UL; |
| 7100 | curproxy->bind_proc |= mask; |
| 7101 | } |
| 7102 | |
| 7103 | if (!curproxy->bind_proc) |
| 7104 | curproxy->bind_proc = ~0UL; |
| 7105 | } |
| 7106 | |
| 7107 | if (global.stats_fe) { |
| 7108 | list_for_each_entry(bind_conf, &global.stats_fe->conf.bind, by_fe) { |
| 7109 | unsigned long mask; |
| 7110 | |
| 7111 | mask = bind_conf->bind_proc ? bind_conf->bind_proc : ~0UL; |
| 7112 | global.stats_fe->bind_proc |= mask; |
| 7113 | } |
| 7114 | if (!global.stats_fe->bind_proc) |
| 7115 | global.stats_fe->bind_proc = ~0UL; |
| 7116 | } |
| 7117 | |
Willy Tarreau | b3228c8 | 2014-10-01 20:50:17 +0200 | [diff] [blame] | 7118 | /* propagate bindings from frontends to backends. Don't do it if there |
| 7119 | * are any fatal errors as we must not call it with unresolved proxies. |
| 7120 | */ |
| 7121 | if (!cfgerr) { |
| 7122 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 7123 | if (curproxy->cap & PR_CAP_FE) |
| 7124 | propagate_processes(curproxy, NULL); |
| 7125 | } |
Willy Tarreau | 91b00c2 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 7126 | } |
| 7127 | |
| 7128 | /* Bind each unbound backend to all processes when not specified. */ |
| 7129 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 7130 | if (curproxy->bind_proc) |
| 7131 | continue; |
| 7132 | curproxy->bind_proc = ~0UL; |
| 7133 | } |
| 7134 | |
| 7135 | /*******************************************************/ |
| 7136 | /* At this step, all proxies have a non-null bind_proc */ |
| 7137 | /*******************************************************/ |
| 7138 | |
| 7139 | /* perform the final checks before creating tasks */ |
| 7140 | |
| 7141 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 7142 | struct listener *listener; |
| 7143 | unsigned int next_id; |
| 7144 | int nbproc; |
| 7145 | |
| 7146 | nbproc = popcount(curproxy->bind_proc & nbits(global.nbproc)); |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 7147 | |
Emeric Brun | c52962f | 2012-11-15 18:28:02 +0100 | [diff] [blame] | 7148 | #ifdef USE_OPENSSL |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 7149 | /* Configure SSL for each bind line. |
| 7150 | * Note: if configuration fails at some point, the ->ctx member |
| 7151 | * remains NULL so that listeners can later detach. |
| 7152 | */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7153 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
Emeric Brun | caa19cc | 2014-05-07 16:10:18 +0200 | [diff] [blame] | 7154 | int alloc_ctx; |
| 7155 | |
Emeric Brun | c52962f | 2012-11-15 18:28:02 +0100 | [diff] [blame] | 7156 | if (!bind_conf->is_ssl) { |
| 7157 | if (bind_conf->default_ctx) { |
| 7158 | Warning("Proxy '%s': A certificate was specified but SSL was not enabled on bind '%s' at [%s:%d] (use 'ssl').\n", |
| 7159 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
| 7160 | } |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7161 | continue; |
Emeric Brun | c52962f | 2012-11-15 18:28:02 +0100 | [diff] [blame] | 7162 | } |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7163 | if (!bind_conf->default_ctx) { |
Emeric Brun | fc0421f | 2012-09-07 17:30:07 +0200 | [diff] [blame] | 7164 | 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] | 7165 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 7166 | cfgerr++; |
| 7167 | continue; |
| 7168 | } |
| 7169 | |
Emeric Brun | 8dc6039 | 2014-05-09 13:52:00 +0200 | [diff] [blame] | 7170 | alloc_ctx = shared_context_init(global.tune.sslcachesize, (!global.tune.sslprivatecache && (global.nbproc > 1)) ? 1 : 0); |
Emeric Brun | caa19cc | 2014-05-07 16:10:18 +0200 | [diff] [blame] | 7171 | if (alloc_ctx < 0) { |
Emeric Brun | 93ee249 | 2014-05-09 14:01:48 +0200 | [diff] [blame] | 7172 | if (alloc_ctx == SHCTX_E_INIT_LOCK) |
| 7173 | Alert("Unable to initialize the lock for the shared SSL session cache. You can retry using the global statement 'tune.ssl.force-private-cache' but it could increase CPU usage due to renegotiations if nbproc > 1.\n"); |
| 7174 | else |
Emeric Brun | caa19cc | 2014-05-07 16:10:18 +0200 | [diff] [blame] | 7175 | Alert("Unable to allocate SSL session cache.\n"); |
Emeric Brun | 93ee249 | 2014-05-09 14:01:48 +0200 | [diff] [blame] | 7176 | cfgerr++; |
| 7177 | continue; |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 7178 | } |
| 7179 | |
Emeric Brun | fc0421f | 2012-09-07 17:30:07 +0200 | [diff] [blame] | 7180 | /* initialize all certificate contexts */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7181 | cfgerr += ssl_sock_prepare_all_ctx(bind_conf, curproxy); |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7182 | } |
Emeric Brun | c52962f | 2012-11-15 18:28:02 +0100 | [diff] [blame] | 7183 | #endif /* USE_OPENSSL */ |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 7184 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 7185 | /* adjust this proxy's listeners */ |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7186 | next_id = 1; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 7187 | list_for_each_entry(listener, &curproxy->conf.listeners, by_fe) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7188 | if (!listener->luid) { |
| 7189 | /* listener ID not set, use automatic numbering with first |
| 7190 | * spare entry starting with next_luid. |
| 7191 | */ |
| 7192 | next_id = get_next_id(&curproxy->conf.used_listener_id, next_id); |
| 7193 | listener->conf.id.key = listener->luid = next_id; |
| 7194 | eb32_insert(&curproxy->conf.used_listener_id, &listener->conf.id); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7195 | } |
Krzysztof Piotr Oledzki | df5cb9f | 2010-02-05 20:58:27 +0100 | [diff] [blame] | 7196 | next_id++; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7197 | |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 7198 | /* enable separate counters */ |
| 7199 | if (curproxy->options2 & PR_O2_SOCKSTAT) { |
| 7200 | listener->counters = (struct licounters *)calloc(1, sizeof(struct licounters)); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 7201 | if (!listener->name) |
| 7202 | memprintf(&listener->name, "sock-%d", listener->luid); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 7203 | } |
Willy Tarreau | 81796be | 2012-09-22 19:11:47 +0200 | [diff] [blame] | 7204 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 7205 | if (curproxy->options & PR_O_TCP_NOLING) |
| 7206 | listener->options |= LI_O_NOLINGER; |
Willy Tarreau | 32368ce | 2012-09-06 11:10:55 +0200 | [diff] [blame] | 7207 | if (!listener->maxconn) |
| 7208 | listener->maxconn = curproxy->maxconn; |
| 7209 | if (!listener->backlog) |
| 7210 | listener->backlog = curproxy->backlog; |
Willy Tarreau | 16a2147 | 2012-11-19 12:39:59 +0100 | [diff] [blame] | 7211 | if (!listener->maxaccept) |
| 7212 | listener->maxaccept = global.tune.maxaccept ? global.tune.maxaccept : 64; |
| 7213 | |
| 7214 | /* we want to have an optimal behaviour on single process mode to |
| 7215 | * maximize the work at once, but in multi-process we want to keep |
| 7216 | * some fairness between processes, so we target half of the max |
| 7217 | * number of events to be balanced over all the processes the proxy |
| 7218 | * is bound to. Rememeber that maxaccept = -1 must be kept as it is |
| 7219 | * used to disable the limit. |
| 7220 | */ |
| 7221 | if (listener->maxaccept > 0) { |
| 7222 | if (nbproc > 1) |
| 7223 | listener->maxaccept = (listener->maxaccept + 1) / 2; |
| 7224 | listener->maxaccept = (listener->maxaccept + nbproc - 1) / nbproc; |
| 7225 | } |
| 7226 | |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 7227 | listener->timeout = &curproxy->timeout.client; |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 7228 | listener->accept = session_accept; |
Willy Tarreau | 3bc1377 | 2008-12-07 11:50:35 +0100 | [diff] [blame] | 7229 | listener->handler = process_session; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 7230 | listener->analysers |= curproxy->fe_req_ana; |
Willy Tarreau | 3bc1377 | 2008-12-07 11:50:35 +0100 | [diff] [blame] | 7231 | |
Willy Tarreau | a5c0ab2 | 2010-05-31 10:30:33 +0200 | [diff] [blame] | 7232 | if (!LIST_ISEMPTY(&curproxy->tcp_req.l4_rules)) |
| 7233 | listener->options |= LI_O_TCP_RULES; |
| 7234 | |
Willy Tarreau | de3041d | 2010-05-31 10:56:17 +0200 | [diff] [blame] | 7235 | if (curproxy->mon_mask.s_addr) |
| 7236 | listener->options |= LI_O_CHK_MONNET; |
| 7237 | |
Willy Tarreau | 9ea05a7 | 2009-06-14 12:07:01 +0200 | [diff] [blame] | 7238 | /* smart accept mode is automatic in HTTP mode */ |
| 7239 | if ((curproxy->options2 & PR_O2_SMARTACC) || |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7240 | ((curproxy->mode == PR_MODE_HTTP || listener->bind_conf->is_ssl) && |
Willy Tarreau | 9ea05a7 | 2009-06-14 12:07:01 +0200 | [diff] [blame] | 7241 | !(curproxy->no_options2 & PR_O2_SMARTACC))) |
| 7242 | listener->options |= LI_O_NOQUICKACK; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 7243 | } |
| 7244 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7245 | /* Release unused SSL configs */ |
| 7246 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
| 7247 | if (bind_conf->is_ssl) |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 7248 | continue; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7249 | #ifdef USE_OPENSSL |
| 7250 | ssl_sock_free_all_ctx(bind_conf); |
Emeric Brun | fb510ea | 2012-10-05 12:00:26 +0200 | [diff] [blame] | 7251 | free(bind_conf->ca_file); |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7252 | free(bind_conf->ciphers); |
Emeric Brun | 2b58d04 | 2012-09-20 17:10:03 +0200 | [diff] [blame] | 7253 | free(bind_conf->ecdhe); |
Emeric Brun | fb510ea | 2012-10-05 12:00:26 +0200 | [diff] [blame] | 7254 | free(bind_conf->crl_file); |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 7255 | #endif /* USE_OPENSSL */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7256 | } |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 7257 | |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 7258 | if (nbproc > 1) { |
| 7259 | if (curproxy->uri_auth) { |
Willy Tarreau | 036a83e | 2014-09-16 15:11:04 +0200 | [diff] [blame] | 7260 | int count, maxproc = 0; |
| 7261 | |
| 7262 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
| 7263 | count = popcount(bind_conf->bind_proc); |
| 7264 | if (count > maxproc) |
| 7265 | maxproc = count; |
| 7266 | } |
| 7267 | /* backends have 0, frontends have 1 or more */ |
| 7268 | if (maxproc != 1) |
| 7269 | Warning("Proxy '%s': in multi-process mode, stats will be" |
| 7270 | " limited to process assigned to the current request.\n", |
| 7271 | curproxy->id); |
| 7272 | |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 7273 | if (!LIST_ISEMPTY(&curproxy->uri_auth->admin_rules)) { |
| 7274 | Warning("Proxy '%s': stats admin will not work correctly in multi-process mode.\n", |
| 7275 | curproxy->id); |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 7276 | } |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 7277 | } |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 7278 | if (curproxy->appsession_name) { |
| 7279 | Warning("Proxy '%s': appsession will not work correctly in multi-process mode.\n", |
| 7280 | curproxy->id); |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 7281 | } |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 7282 | if (!LIST_ISEMPTY(&curproxy->sticking_rules)) { |
| 7283 | Warning("Proxy '%s': sticking rules will not work correctly in multi-process mode.\n", |
| 7284 | curproxy->id); |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 7285 | } |
| 7286 | } |
Willy Tarreau | 918ff60 | 2011-07-25 16:33:49 +0200 | [diff] [blame] | 7287 | |
| 7288 | /* create the task associated with the proxy */ |
| 7289 | curproxy->task = task_new(); |
| 7290 | if (curproxy->task) { |
| 7291 | curproxy->task->context = curproxy; |
| 7292 | curproxy->task->process = manage_proxy; |
| 7293 | /* no need to queue, it will be done automatically if some |
| 7294 | * listener gets limited. |
| 7295 | */ |
| 7296 | curproxy->task->expire = TICK_ETERNITY; |
| 7297 | } else { |
| 7298 | Alert("Proxy '%s': no more memory when trying to allocate the management task\n", |
| 7299 | curproxy->id); |
| 7300 | cfgerr++; |
| 7301 | } |
Willy Tarreau | e56c4f1 | 2014-09-16 13:21:03 +0200 | [diff] [blame] | 7302 | } |
| 7303 | |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 7304 | /* automatically compute fullconn if not set. We must not do it in the |
| 7305 | * loop above because cross-references are not yet fully resolved. |
| 7306 | */ |
| 7307 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 7308 | /* If <fullconn> is not set, let's set it to 10% of the sum of |
| 7309 | * the possible incoming frontend's maxconns. |
| 7310 | */ |
| 7311 | if (!curproxy->fullconn && (curproxy->cap & PR_CAP_BE)) { |
| 7312 | struct proxy *fe; |
| 7313 | int total = 0; |
| 7314 | |
| 7315 | /* sum up the number of maxconns of frontends which |
| 7316 | * reference this backend at least once or which are |
| 7317 | * the same one ('listen'). |
| 7318 | */ |
| 7319 | for (fe = proxy; fe; fe = fe->next) { |
| 7320 | struct switching_rule *rule; |
| 7321 | struct hdr_exp *exp; |
| 7322 | int found = 0; |
| 7323 | |
| 7324 | if (!(fe->cap & PR_CAP_FE)) |
| 7325 | continue; |
| 7326 | |
| 7327 | if (fe == curproxy) /* we're on a "listen" instance */ |
| 7328 | found = 1; |
| 7329 | |
| 7330 | if (fe->defbe.be == curproxy) /* "default_backend" */ |
| 7331 | found = 1; |
| 7332 | |
| 7333 | /* check if a "use_backend" rule matches */ |
| 7334 | if (!found) { |
| 7335 | list_for_each_entry(rule, &fe->switching_rules, list) { |
Bertrand Jacquin | 702d44f | 2013-11-19 11:43:06 +0100 | [diff] [blame] | 7336 | if (!rule->dynamic && rule->be.backend == curproxy) { |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 7337 | found = 1; |
| 7338 | break; |
| 7339 | } |
| 7340 | } |
| 7341 | } |
| 7342 | |
| 7343 | /* check if a "reqsetbe" rule matches */ |
| 7344 | for (exp = fe->req_exp; !found && exp; exp = exp->next) { |
| 7345 | if (exp->action == ACT_SETBE && |
| 7346 | (struct proxy *)exp->replace == curproxy) { |
| 7347 | found = 1; |
| 7348 | break; |
| 7349 | } |
| 7350 | } |
| 7351 | |
| 7352 | /* now we've checked all possible ways to reference a backend |
| 7353 | * from a frontend. |
| 7354 | */ |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 7355 | if (!found) |
| 7356 | continue; |
| 7357 | total += fe->maxconn; |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 7358 | } |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 7359 | /* we have the sum of the maxconns in <total>. We only |
| 7360 | * keep 10% of that sum to set the default fullconn, with |
| 7361 | * a hard minimum of 1 (to avoid a divide by zero). |
| 7362 | */ |
| 7363 | curproxy->fullconn = (total + 9) / 10; |
| 7364 | if (!curproxy->fullconn) |
| 7365 | curproxy->fullconn = 1; |
| 7366 | } |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 7367 | } |
| 7368 | |
Willy Tarreau | 056f568 | 2010-06-06 15:51:11 +0200 | [diff] [blame] | 7369 | /* initialize stick-tables on backend capable proxies. This must not |
| 7370 | * be done earlier because the data size may be discovered while parsing |
| 7371 | * other proxies. |
| 7372 | */ |
Godbach | 9703e66 | 2013-12-11 21:11:41 +0800 | [diff] [blame] | 7373 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
Willy Tarreau | 5830213 | 2014-02-24 20:59:47 +0100 | [diff] [blame] | 7374 | if (curproxy->state == PR_STSTOPPED) |
| 7375 | continue; |
| 7376 | |
Godbach | 9703e66 | 2013-12-11 21:11:41 +0800 | [diff] [blame] | 7377 | if (!stktable_init(&curproxy->table)) { |
| 7378 | Alert("Proxy '%s': failed to initialize stick-table.\n", curproxy->id); |
| 7379 | cfgerr++; |
| 7380 | } |
| 7381 | } |
Willy Tarreau | 056f568 | 2010-06-06 15:51:11 +0200 | [diff] [blame] | 7382 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7383 | /* |
| 7384 | * Recount currently required checks. |
| 7385 | */ |
| 7386 | |
| 7387 | for (curproxy=proxy; curproxy; curproxy=curproxy->next) { |
| 7388 | int optnum; |
| 7389 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 7390 | for (optnum = 0; cfg_opts[optnum].name; optnum++) |
| 7391 | if (curproxy->options & cfg_opts[optnum].val) |
| 7392 | global.last_checks |= cfg_opts[optnum].checks; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7393 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 7394 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) |
| 7395 | if (curproxy->options2 & cfg_opts2[optnum].val) |
| 7396 | global.last_checks |= cfg_opts2[optnum].checks; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7397 | } |
| 7398 | |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 7399 | if (peers) { |
| 7400 | struct peers *curpeers = peers, **last; |
| 7401 | struct peer *p, *pb; |
| 7402 | |
| 7403 | /* Remove all peers sections which don't have a valid listener. |
| 7404 | * This can happen when a peers section is never referenced and |
| 7405 | * does not contain a local peer. |
| 7406 | */ |
| 7407 | last = &peers; |
| 7408 | while (*last) { |
| 7409 | curpeers = *last; |
| 7410 | if (curpeers->peers_fe) { |
| 7411 | last = &curpeers->next; |
| 7412 | continue; |
| 7413 | } |
| 7414 | |
| 7415 | Warning("Removing incomplete section 'peers %s' (no peer named '%s').\n", |
| 7416 | curpeers->id, localpeer); |
| 7417 | |
| 7418 | p = curpeers->remote; |
| 7419 | while (p) { |
| 7420 | pb = p->next; |
| 7421 | free(p->id); |
| 7422 | free(p); |
| 7423 | p = pb; |
| 7424 | } |
| 7425 | |
| 7426 | /* Destroy and unlink this curpeers section. |
| 7427 | * Note: curpeers is backed up into *last. |
| 7428 | */ |
| 7429 | free(curpeers->id); |
| 7430 | curpeers = curpeers->next; |
| 7431 | free(*last); |
| 7432 | *last = curpeers; |
| 7433 | } |
| 7434 | } |
| 7435 | |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 7436 | pool2_hdr_idx = create_pool("hdr_idx", |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame] | 7437 | global.tune.max_http_hdr * sizeof(struct hdr_idx_elem), |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 7438 | MEM_F_SHARED); |
| 7439 | |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 7440 | if (cfgerr > 0) |
| 7441 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7442 | out: |
| 7443 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7444 | } |
| 7445 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 7446 | /* |
| 7447 | * Registers the CFG keyword list <kwl> as a list of valid keywords for next |
| 7448 | * parsing sessions. |
| 7449 | */ |
| 7450 | void cfg_register_keywords(struct cfg_kw_list *kwl) |
| 7451 | { |
| 7452 | LIST_ADDQ(&cfg_keywords.list, &kwl->list); |
| 7453 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7454 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 7455 | /* |
| 7456 | * Unregisters the CFG keyword list <kwl> from the list of valid keywords. |
| 7457 | */ |
| 7458 | void cfg_unregister_keywords(struct cfg_kw_list *kwl) |
| 7459 | { |
| 7460 | LIST_DEL(&kwl->list); |
| 7461 | LIST_INIT(&kwl->list); |
| 7462 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7463 | |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 7464 | /* this function register new section in the haproxy configuration file. |
| 7465 | * <section_name> is the name of this new section and <section_parser> |
| 7466 | * is the called parser. If two section declaration have the same name, |
| 7467 | * only the first declared is used. |
| 7468 | */ |
| 7469 | int cfg_register_section(char *section_name, |
| 7470 | int (*section_parser)(const char *, int, char **, int)) |
| 7471 | { |
| 7472 | struct cfg_section *cs; |
| 7473 | |
| 7474 | cs = calloc(1, sizeof(*cs)); |
| 7475 | if (!cs) { |
| 7476 | Alert("register section '%s': out of memory.\n", section_name); |
| 7477 | return 0; |
| 7478 | } |
| 7479 | |
| 7480 | cs->section_name = section_name; |
| 7481 | cs->section_parser = section_parser; |
| 7482 | |
| 7483 | LIST_ADDQ(§ions, &cs->list); |
| 7484 | |
| 7485 | return 1; |
| 7486 | } |
| 7487 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7488 | /* |
| 7489 | * Local variables: |
| 7490 | * c-indent-level: 8 |
| 7491 | * c-basic-offset: 8 |
| 7492 | * End: |
| 7493 | */ |