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é | 1a0191d | 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 | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 320 | /* Report a warning if a rule is placed after a 'block' rule. |
| 321 | * Return 1 if the warning has been emitted, otherwise 0. |
| 322 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 323 | 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] | 324 | { |
Willy Tarreau | 353bc9f | 2014-04-28 22:05:31 +0200 | [diff] [blame] | 325 | if (!LIST_ISEMPTY(&proxy->block_rules)) { |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 326 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'block' rule will still be processed before.\n", |
| 327 | file, line, arg); |
| 328 | return 1; |
| 329 | } |
| 330 | return 0; |
| 331 | } |
| 332 | |
Willy Tarreau | 5002f57 | 2014-04-23 01:32:02 +0200 | [diff] [blame] | 333 | /* Report a warning if a rule is placed after an 'http_request' rule. |
| 334 | * Return 1 if the warning has been emitted, otherwise 0. |
| 335 | */ |
| 336 | int warnif_rule_after_http_req(struct proxy *proxy, const char *file, int line, const char *arg) |
| 337 | { |
| 338 | if (!LIST_ISEMPTY(&proxy->http_req_rules)) { |
| 339 | Warning("parsing [%s:%d] : a '%s' rule placed after an 'http-request' rule will still be processed before.\n", |
| 340 | file, line, arg); |
| 341 | return 1; |
| 342 | } |
| 343 | return 0; |
| 344 | } |
| 345 | |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 346 | /* Report a warning if a rule is placed after a reqrewrite rule. |
| 347 | * Return 1 if the warning has been emitted, otherwise 0. |
| 348 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 349 | 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] | 350 | { |
| 351 | if (proxy->req_exp) { |
| 352 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'reqxxx' rule will still be processed before.\n", |
| 353 | file, line, arg); |
| 354 | return 1; |
| 355 | } |
| 356 | return 0; |
| 357 | } |
| 358 | |
| 359 | /* Report a warning if a rule is placed after a reqadd 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_reqadd(struct proxy *proxy, const char *file, int line, const char *arg) |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 363 | { |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 364 | if (!LIST_ISEMPTY(&proxy->req_add)) { |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 365 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'reqadd' 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 redirect 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_redirect(struct proxy *proxy, const char *file, int line, const char *arg) |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 376 | { |
| 377 | if (!LIST_ISEMPTY(&proxy->redirect_rules)) { |
| 378 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'redirect' 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 'use_backend' 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_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] | 389 | { |
| 390 | if (!LIST_ISEMPTY(&proxy->switching_rules)) { |
| 391 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'use_backend' rule will still be processed before.\n", |
| 392 | file, line, arg); |
| 393 | return 1; |
| 394 | } |
| 395 | return 0; |
| 396 | } |
| 397 | |
Willy Tarreau | ee445d9 | 2014-04-23 01:39:04 +0200 | [diff] [blame] | 398 | /* Report a warning if a rule is placed after a 'use-server' rule. |
| 399 | * Return 1 if the warning has been emitted, otherwise 0. |
| 400 | */ |
| 401 | int warnif_rule_after_use_server(struct proxy *proxy, const char *file, int line, const char *arg) |
| 402 | { |
| 403 | if (!LIST_ISEMPTY(&proxy->server_rules)) { |
| 404 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'use-server' rule will still be processed before.\n", |
| 405 | file, line, arg); |
| 406 | return 1; |
| 407 | } |
| 408 | return 0; |
| 409 | } |
| 410 | |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 411 | /* report a warning if a block rule is dangerously placed */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 412 | 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] | 413 | { |
Willy Tarreau | 5002f57 | 2014-04-23 01:32:02 +0200 | [diff] [blame] | 414 | return warnif_rule_after_http_req(proxy, file, line, arg) || |
| 415 | warnif_rule_after_reqxxx(proxy, file, line, arg) || |
| 416 | warnif_rule_after_reqadd(proxy, file, line, arg) || |
| 417 | warnif_rule_after_redirect(proxy, file, line, arg) || |
Willy Tarreau | ee445d9 | 2014-04-23 01:39:04 +0200 | [diff] [blame] | 418 | warnif_rule_after_use_backend(proxy, file, line, arg) || |
| 419 | warnif_rule_after_use_server(proxy, file, line, arg); |
Willy Tarreau | 5002f57 | 2014-04-23 01:32:02 +0200 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | /* report a warning if an http-request rule is dangerously placed */ |
| 423 | int warnif_misplaced_http_req(struct proxy *proxy, const char *file, int line, const char *arg) |
| 424 | { |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 425 | return warnif_rule_after_reqxxx(proxy, file, line, arg) || |
| 426 | warnif_rule_after_reqadd(proxy, file, line, arg) || |
| 427 | warnif_rule_after_redirect(proxy, file, line, arg) || |
Willy Tarreau | ee445d9 | 2014-04-23 01:39:04 +0200 | [diff] [blame] | 428 | warnif_rule_after_use_backend(proxy, file, line, arg) || |
| 429 | warnif_rule_after_use_server(proxy, file, line, arg); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 430 | } |
| 431 | |
| 432 | /* report a warning if a reqxxx rule is dangerously placed */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 433 | 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] | 434 | { |
| 435 | return warnif_rule_after_reqadd(proxy, file, line, arg) || |
| 436 | warnif_rule_after_redirect(proxy, file, line, arg) || |
Willy Tarreau | ee445d9 | 2014-04-23 01:39:04 +0200 | [diff] [blame] | 437 | warnif_rule_after_use_backend(proxy, file, line, arg) || |
| 438 | warnif_rule_after_use_server(proxy, file, line, arg); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 439 | } |
| 440 | |
| 441 | /* report a warning if a reqadd rule is dangerously placed */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 442 | 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] | 443 | { |
| 444 | return warnif_rule_after_redirect(proxy, file, line, arg) || |
Willy Tarreau | ee445d9 | 2014-04-23 01:39:04 +0200 | [diff] [blame] | 445 | warnif_rule_after_use_backend(proxy, file, line, arg) || |
| 446 | warnif_rule_after_use_server(proxy, file, line, arg); |
| 447 | } |
| 448 | |
| 449 | /* report a warning if a redirect rule is dangerously placed */ |
| 450 | int warnif_misplaced_redirect(struct proxy *proxy, const char *file, int line, const char *arg) |
| 451 | { |
| 452 | return warnif_rule_after_use_backend(proxy, file, line, arg) || |
| 453 | warnif_rule_after_use_server(proxy, file, line, arg); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 454 | } |
| 455 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 456 | /* Report it if a request ACL condition uses some keywords that are incompatible |
| 457 | * with the place where the ACL is used. It returns either 0 or ERR_WARN so that |
| 458 | * its result can be or'ed with err_code. Note that <cond> may be NULL and then |
| 459 | * will be ignored. |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 460 | */ |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 461 | 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] | 462 | { |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 463 | const struct acl *acl; |
Willy Tarreau | 93fddf1 | 2013-03-31 22:59:32 +0200 | [diff] [blame] | 464 | const char *kw; |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 465 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 466 | if (!cond) |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 467 | return 0; |
| 468 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 469 | acl = acl_cond_conflicts(cond, where); |
| 470 | if (acl) { |
| 471 | if (acl->name && *acl->name) |
| 472 | Warning("parsing [%s:%d] : acl '%s' will never match because it only involves keywords that are incompatible with '%s'\n", |
| 473 | file, line, acl->name, sample_ckp_names(where)); |
| 474 | else |
| 475 | 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] | 476 | 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] | 477 | return ERR_WARN; |
| 478 | } |
| 479 | if (!acl_cond_kw_conflicts(cond, where, &acl, &kw)) |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 480 | return 0; |
| 481 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 482 | if (acl->name && *acl->name) |
| 483 | 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] | 484 | file, line, acl->name, kw, sample_ckp_names(where)); |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 485 | else |
| 486 | 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] | 487 | file, line, kw, sample_ckp_names(where)); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 488 | return ERR_WARN; |
| 489 | } |
| 490 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 491 | /* |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 492 | * parse a line in a <global> section. Returns the error code, 0 if OK, or |
| 493 | * any combination of : |
| 494 | * - ERR_ABORT: must abort ASAP |
| 495 | * - ERR_FATAL: we can continue parsing but not start the service |
| 496 | * - ERR_WARN: a warning has been emitted |
| 497 | * - ERR_ALERT: an alert has been emitted |
| 498 | * Only the two first ones can stop processing, the two others are just |
| 499 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 500 | */ |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 501 | 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] | 502 | { |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 503 | int err_code = 0; |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 504 | char *errmsg = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 505 | |
| 506 | if (!strcmp(args[0], "global")) { /* new section */ |
| 507 | /* no option, nothing special to do */ |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 508 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 509 | } |
Emeric Brun | c8e8d12 | 2012-10-02 18:42:10 +0200 | [diff] [blame] | 510 | else if (!strcmp(args[0], "ca-base")) { |
| 511 | #ifdef USE_OPENSSL |
| 512 | if (global.ca_base != NULL) { |
| 513 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 514 | err_code |= ERR_ALERT; |
| 515 | goto out; |
| 516 | } |
| 517 | if (*(args[1]) == 0) { |
| 518 | Alert("parsing [%s:%d] : '%s' expects a directory path as an argument.\n", file, linenum, args[0]); |
| 519 | err_code |= ERR_ALERT | ERR_FATAL; |
| 520 | goto out; |
| 521 | } |
| 522 | global.ca_base = strdup(args[1]); |
| 523 | #else |
| 524 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 525 | err_code |= ERR_ALERT | ERR_FATAL; |
| 526 | goto out; |
| 527 | #endif |
| 528 | } |
| 529 | else if (!strcmp(args[0], "crt-base")) { |
| 530 | #ifdef USE_OPENSSL |
| 531 | if (global.crt_base != NULL) { |
| 532 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 533 | err_code |= ERR_ALERT; |
| 534 | goto out; |
| 535 | } |
| 536 | if (*(args[1]) == 0) { |
| 537 | Alert("parsing [%s:%d] : '%s' expects a directory path as an argument.\n", file, linenum, args[0]); |
| 538 | err_code |= ERR_ALERT | ERR_FATAL; |
| 539 | goto out; |
| 540 | } |
| 541 | global.crt_base = strdup(args[1]); |
| 542 | #else |
| 543 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 544 | err_code |= ERR_ALERT | ERR_FATAL; |
| 545 | goto out; |
| 546 | #endif |
| 547 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 548 | else if (!strcmp(args[0], "daemon")) { |
| 549 | global.mode |= MODE_DAEMON; |
| 550 | } |
| 551 | else if (!strcmp(args[0], "debug")) { |
| 552 | global.mode |= MODE_DEBUG; |
| 553 | } |
| 554 | else if (!strcmp(args[0], "noepoll")) { |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 555 | global.tune.options &= ~GTUNE_USE_EPOLL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 556 | } |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 557 | else if (!strcmp(args[0], "nokqueue")) { |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 558 | global.tune.options &= ~GTUNE_USE_KQUEUE; |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 559 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 560 | else if (!strcmp(args[0], "nopoll")) { |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 561 | global.tune.options &= ~GTUNE_USE_POLL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 562 | } |
Willy Tarreau | 3ab68cf | 2009-01-25 16:03:28 +0100 | [diff] [blame] | 563 | else if (!strcmp(args[0], "nosplice")) { |
| 564 | global.tune.options &= ~GTUNE_USE_SPLICE; |
| 565 | } |
Nenad Merdanovic | 88afe03 | 2014-04-14 15:56:58 +0200 | [diff] [blame] | 566 | else if (!strcmp(args[0], "nogetaddrinfo")) { |
| 567 | global.tune.options &= ~GTUNE_USE_GAI; |
| 568 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 569 | else if (!strcmp(args[0], "quiet")) { |
| 570 | global.mode |= MODE_QUIET; |
| 571 | } |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 572 | else if (!strcmp(args[0], "tune.maxpollevents")) { |
| 573 | if (global.tune.maxpollevents != 0) { |
| 574 | 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] | 575 | err_code |= ERR_ALERT; |
| 576 | goto out; |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 577 | } |
| 578 | if (*(args[1]) == 0) { |
| 579 | 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] | 580 | err_code |= ERR_ALERT | ERR_FATAL; |
| 581 | goto out; |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 582 | } |
| 583 | global.tune.maxpollevents = atol(args[1]); |
| 584 | } |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 585 | else if (!strcmp(args[0], "tune.maxaccept")) { |
| 586 | if (global.tune.maxaccept != 0) { |
| 587 | 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] | 588 | err_code |= ERR_ALERT; |
| 589 | goto out; |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 590 | } |
| 591 | if (*(args[1]) == 0) { |
| 592 | 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] | 593 | err_code |= ERR_ALERT | ERR_FATAL; |
| 594 | goto out; |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 595 | } |
| 596 | global.tune.maxaccept = atol(args[1]); |
| 597 | } |
Willy Tarreau | 43961d5 | 2010-10-04 20:39:20 +0200 | [diff] [blame] | 598 | else if (!strcmp(args[0], "tune.chksize")) { |
| 599 | if (*(args[1]) == 0) { |
| 600 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 601 | err_code |= ERR_ALERT | ERR_FATAL; |
| 602 | goto out; |
| 603 | } |
| 604 | global.tune.chksize = atol(args[1]); |
| 605 | } |
Emeric Brun | fc32aca | 2012-09-03 12:10:29 +0200 | [diff] [blame] | 606 | #ifdef USE_OPENSSL |
Emeric Brun | 8dc6039 | 2014-05-09 13:52:00 +0200 | [diff] [blame] | 607 | else if (!strcmp(args[0], "tune.ssl.force-private-cache")) { |
| 608 | global.tune.sslprivatecache = 1; |
| 609 | } |
Willy Tarreau | 6ec58db | 2012-11-16 16:32:15 +0100 | [diff] [blame] | 610 | else if (!strcmp(args[0], "tune.ssl.cachesize")) { |
Emeric Brun | fc32aca | 2012-09-03 12:10:29 +0200 | [diff] [blame] | 611 | if (*(args[1]) == 0) { |
| 612 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 613 | err_code |= ERR_ALERT | ERR_FATAL; |
| 614 | goto out; |
| 615 | } |
| 616 | global.tune.sslcachesize = atol(args[1]); |
| 617 | } |
Emeric Brun | 4f65bff | 2012-11-16 15:11:00 +0100 | [diff] [blame] | 618 | else if (!strcmp(args[0], "tune.ssl.lifetime")) { |
| 619 | unsigned int ssllifetime; |
| 620 | const char *res; |
| 621 | |
| 622 | if (*(args[1]) == 0) { |
| 623 | Alert("parsing [%s:%d] : '%s' expects ssl sessions <lifetime> in seconds as argument.\n", file, linenum, args[0]); |
| 624 | err_code |= ERR_ALERT | ERR_FATAL; |
| 625 | goto out; |
| 626 | } |
| 627 | |
| 628 | res = parse_time_err(args[1], &ssllifetime, TIME_UNIT_S); |
| 629 | if (res) { |
| 630 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 631 | file, linenum, *res, args[0]); |
| 632 | err_code |= ERR_ALERT | ERR_FATAL; |
| 633 | goto out; |
| 634 | } |
| 635 | |
| 636 | global.tune.ssllifetime = ssllifetime; |
| 637 | } |
Willy Tarreau | bfd5946 | 2013-02-21 07:46:09 +0100 | [diff] [blame] | 638 | else if (!strcmp(args[0], "tune.ssl.maxrecord")) { |
| 639 | if (*(args[1]) == 0) { |
| 640 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 641 | err_code |= ERR_ALERT | ERR_FATAL; |
| 642 | goto out; |
| 643 | } |
| 644 | global.tune.ssl_max_record = atol(args[1]); |
| 645 | } |
Remi Gacogne | f46cd6e | 2014-06-12 14:58:40 +0200 | [diff] [blame] | 646 | else if (!strcmp(args[0], "tune.ssl.default-dh-param")) { |
| 647 | if (*(args[1]) == 0) { |
| 648 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 649 | err_code |= ERR_ALERT | ERR_FATAL; |
| 650 | goto out; |
| 651 | } |
| 652 | global.tune.ssl_default_dh_param = atol(args[1]); |
| 653 | if (global.tune.ssl_default_dh_param < 1024) { |
| 654 | Alert("parsing [%s:%d] : '%s' expects a value >= 1024.\n", file, linenum, args[0]); |
| 655 | err_code |= ERR_ALERT | ERR_FATAL; |
| 656 | goto out; |
| 657 | } |
| 658 | } |
Emeric Brun | fc32aca | 2012-09-03 12:10:29 +0200 | [diff] [blame] | 659 | #endif |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 660 | else if (!strcmp(args[0], "tune.bufsize")) { |
| 661 | if (*(args[1]) == 0) { |
| 662 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 663 | err_code |= ERR_ALERT | ERR_FATAL; |
| 664 | goto out; |
| 665 | } |
| 666 | global.tune.bufsize = atol(args[1]); |
| 667 | if (global.tune.maxrewrite >= global.tune.bufsize / 2) |
| 668 | global.tune.maxrewrite = global.tune.bufsize / 2; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 669 | chunk_init(&trash, realloc(trash.str, global.tune.bufsize), global.tune.bufsize); |
Willy Tarreau | 2819e99 | 2013-12-13 14:41:10 +0100 | [diff] [blame] | 670 | alloc_trash_buffers(global.tune.bufsize); |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 671 | } |
| 672 | else if (!strcmp(args[0], "tune.maxrewrite")) { |
| 673 | if (*(args[1]) == 0) { |
| 674 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 675 | err_code |= ERR_ALERT | ERR_FATAL; |
| 676 | goto out; |
| 677 | } |
| 678 | global.tune.maxrewrite = atol(args[1]); |
| 679 | if (global.tune.maxrewrite >= global.tune.bufsize / 2) |
| 680 | global.tune.maxrewrite = global.tune.bufsize / 2; |
| 681 | } |
Willy Tarreau | 7e31273 | 2014-02-12 16:35:14 +0100 | [diff] [blame] | 682 | else if (!strcmp(args[0], "tune.idletimer")) { |
| 683 | unsigned int idle; |
| 684 | const char *res; |
| 685 | |
| 686 | if (*(args[1]) == 0) { |
| 687 | Alert("parsing [%s:%d] : '%s' expects a timer value between 0 and 65535 ms.\n", file, linenum, args[0]); |
| 688 | err_code |= ERR_ALERT | ERR_FATAL; |
| 689 | goto out; |
| 690 | } |
| 691 | |
| 692 | res = parse_time_err(args[1], &idle, TIME_UNIT_MS); |
| 693 | if (res) { |
| 694 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 695 | file, linenum, *res, args[0]); |
| 696 | err_code |= ERR_ALERT | ERR_FATAL; |
| 697 | goto out; |
| 698 | } |
| 699 | |
| 700 | if (idle > 65535) { |
| 701 | Alert("parsing [%s:%d] : '%s' expects a timer value between 0 and 65535 ms.\n", file, linenum, args[0]); |
| 702 | err_code |= ERR_ALERT | ERR_FATAL; |
| 703 | goto out; |
| 704 | } |
| 705 | global.tune.idle_timer = idle; |
| 706 | } |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 707 | else if (!strcmp(args[0], "tune.rcvbuf.client")) { |
| 708 | if (global.tune.client_rcvbuf != 0) { |
| 709 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 710 | err_code |= ERR_ALERT; |
| 711 | goto out; |
| 712 | } |
| 713 | if (*(args[1]) == 0) { |
| 714 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 715 | err_code |= ERR_ALERT | ERR_FATAL; |
| 716 | goto out; |
| 717 | } |
| 718 | global.tune.client_rcvbuf = atol(args[1]); |
| 719 | } |
| 720 | else if (!strcmp(args[0], "tune.rcvbuf.server")) { |
| 721 | if (global.tune.server_rcvbuf != 0) { |
| 722 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 723 | err_code |= ERR_ALERT; |
| 724 | goto out; |
| 725 | } |
| 726 | if (*(args[1]) == 0) { |
| 727 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 728 | err_code |= ERR_ALERT | ERR_FATAL; |
| 729 | goto out; |
| 730 | } |
| 731 | global.tune.server_rcvbuf = atol(args[1]); |
| 732 | } |
| 733 | else if (!strcmp(args[0], "tune.sndbuf.client")) { |
| 734 | if (global.tune.client_sndbuf != 0) { |
| 735 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 736 | err_code |= ERR_ALERT; |
| 737 | goto out; |
| 738 | } |
| 739 | if (*(args[1]) == 0) { |
| 740 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 741 | err_code |= ERR_ALERT | ERR_FATAL; |
| 742 | goto out; |
| 743 | } |
| 744 | global.tune.client_sndbuf = atol(args[1]); |
| 745 | } |
| 746 | else if (!strcmp(args[0], "tune.sndbuf.server")) { |
| 747 | if (global.tune.server_sndbuf != 0) { |
| 748 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 749 | err_code |= ERR_ALERT; |
| 750 | goto out; |
| 751 | } |
| 752 | if (*(args[1]) == 0) { |
| 753 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 754 | err_code |= ERR_ALERT | ERR_FATAL; |
| 755 | goto out; |
| 756 | } |
| 757 | global.tune.server_sndbuf = atol(args[1]); |
| 758 | } |
Willy Tarreau | bd9a0a7 | 2011-10-23 21:14:29 +0200 | [diff] [blame] | 759 | else if (!strcmp(args[0], "tune.pipesize")) { |
| 760 | if (*(args[1]) == 0) { |
| 761 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 762 | err_code |= ERR_ALERT | ERR_FATAL; |
| 763 | goto out; |
| 764 | } |
| 765 | global.tune.pipesize = atol(args[1]); |
| 766 | } |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 767 | else if (!strcmp(args[0], "tune.http.cookielen")) { |
| 768 | if (*(args[1]) == 0) { |
| 769 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 770 | err_code |= ERR_ALERT | ERR_FATAL; |
| 771 | goto out; |
| 772 | } |
| 773 | global.tune.cookie_len = atol(args[1]) + 1; |
| 774 | } |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame] | 775 | else if (!strcmp(args[0], "tune.http.maxhdr")) { |
| 776 | if (*(args[1]) == 0) { |
| 777 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 778 | err_code |= ERR_ALERT | ERR_FATAL; |
| 779 | goto out; |
| 780 | } |
| 781 | global.tune.max_http_hdr = atol(args[1]); |
| 782 | } |
William Lallemand | a509e4c | 2012-11-07 16:54:34 +0100 | [diff] [blame] | 783 | else if (!strcmp(args[0], "tune.zlib.memlevel")) { |
| 784 | #ifdef USE_ZLIB |
| 785 | if (*args[1]) { |
| 786 | global.tune.zlibmemlevel = atoi(args[1]); |
| 787 | if (global.tune.zlibmemlevel < 1 || global.tune.zlibmemlevel > 9) { |
| 788 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n", |
| 789 | file, linenum, args[0]); |
| 790 | err_code |= ERR_ALERT | ERR_FATAL; |
| 791 | goto out; |
| 792 | } |
| 793 | } else { |
| 794 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n", |
| 795 | file, linenum, args[0]); |
| 796 | err_code |= ERR_ALERT | ERR_FATAL; |
| 797 | goto out; |
| 798 | } |
| 799 | #else |
| 800 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 801 | err_code |= ERR_ALERT | ERR_FATAL; |
| 802 | goto out; |
| 803 | #endif |
| 804 | } |
| 805 | else if (!strcmp(args[0], "tune.zlib.windowsize")) { |
| 806 | #ifdef USE_ZLIB |
| 807 | if (*args[1]) { |
| 808 | global.tune.zlibwindowsize = atoi(args[1]); |
| 809 | if (global.tune.zlibwindowsize < 8 || global.tune.zlibwindowsize > 15) { |
| 810 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 8 and 15\n", |
| 811 | file, linenum, args[0]); |
| 812 | err_code |= ERR_ALERT | ERR_FATAL; |
| 813 | goto out; |
| 814 | } |
| 815 | } else { |
| 816 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 8 and 15\n", |
| 817 | file, linenum, args[0]); |
| 818 | err_code |= ERR_ALERT | ERR_FATAL; |
| 819 | goto out; |
| 820 | } |
| 821 | #else |
| 822 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 823 | err_code |= ERR_ALERT | ERR_FATAL; |
| 824 | goto out; |
| 825 | #endif |
| 826 | } |
William Lallemand | f374783 | 2012-11-09 12:33:10 +0100 | [diff] [blame] | 827 | else if (!strcmp(args[0], "tune.comp.maxlevel")) { |
| 828 | if (*args[1]) { |
| 829 | global.tune.comp_maxlevel = atoi(args[1]); |
| 830 | if (global.tune.comp_maxlevel < 1 || global.tune.comp_maxlevel > 9) { |
| 831 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n", |
| 832 | file, linenum, args[0]); |
| 833 | err_code |= ERR_ALERT | ERR_FATAL; |
| 834 | goto out; |
| 835 | } |
| 836 | } else { |
| 837 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n", |
| 838 | file, linenum, args[0]); |
| 839 | err_code |= ERR_ALERT | ERR_FATAL; |
| 840 | goto out; |
| 841 | } |
| 842 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 843 | else if (!strcmp(args[0], "uid")) { |
| 844 | if (global.uid != 0) { |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 845 | Alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 846 | err_code |= ERR_ALERT; |
| 847 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 848 | } |
| 849 | if (*(args[1]) == 0) { |
| 850 | 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] | 851 | err_code |= ERR_ALERT | ERR_FATAL; |
| 852 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 853 | } |
| 854 | global.uid = atol(args[1]); |
| 855 | } |
| 856 | else if (!strcmp(args[0], "gid")) { |
| 857 | if (global.gid != 0) { |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 858 | Alert("parsing [%s:%d] : group/gid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 859 | err_code |= ERR_ALERT; |
| 860 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 861 | } |
| 862 | if (*(args[1]) == 0) { |
| 863 | 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] | 864 | err_code |= ERR_ALERT | ERR_FATAL; |
| 865 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 866 | } |
| 867 | global.gid = atol(args[1]); |
| 868 | } |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 869 | else if (!strcmp(args[0], "external-check")) { |
| 870 | global.external_check = 1; |
| 871 | } |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 872 | /* user/group name handling */ |
| 873 | else if (!strcmp(args[0], "user")) { |
| 874 | struct passwd *ha_user; |
| 875 | if (global.uid != 0) { |
| 876 | Alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 877 | err_code |= ERR_ALERT; |
| 878 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 879 | } |
| 880 | errno = 0; |
| 881 | ha_user = getpwnam(args[1]); |
| 882 | if (ha_user != NULL) { |
| 883 | global.uid = (int)ha_user->pw_uid; |
| 884 | } |
| 885 | else { |
| 886 | 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] | 887 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 888 | } |
| 889 | } |
| 890 | else if (!strcmp(args[0], "group")) { |
| 891 | struct group *ha_group; |
| 892 | if (global.gid != 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 893 | 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] | 894 | err_code |= ERR_ALERT; |
| 895 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 896 | } |
| 897 | errno = 0; |
| 898 | ha_group = getgrnam(args[1]); |
| 899 | if (ha_group != NULL) { |
| 900 | global.gid = (int)ha_group->gr_gid; |
| 901 | } |
| 902 | else { |
| 903 | 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] | 904 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 905 | } |
| 906 | } |
| 907 | /* end of user/group name handling*/ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 908 | else if (!strcmp(args[0], "nbproc")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 909 | if (*(args[1]) == 0) { |
| 910 | 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] | 911 | err_code |= ERR_ALERT | ERR_FATAL; |
| 912 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 913 | } |
| 914 | global.nbproc = atol(args[1]); |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 915 | if (global.nbproc < 1 || global.nbproc > LONGBITS) { |
| 916 | Alert("parsing [%s:%d] : '%s' must be between 1 and %d (was %d).\n", |
| 917 | file, linenum, args[0], LONGBITS, global.nbproc); |
| 918 | err_code |= ERR_ALERT | ERR_FATAL; |
| 919 | goto out; |
| 920 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 921 | } |
| 922 | else if (!strcmp(args[0], "maxconn")) { |
| 923 | if (global.maxconn != 0) { |
| 924 | 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] | 925 | err_code |= ERR_ALERT; |
| 926 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 927 | } |
| 928 | if (*(args[1]) == 0) { |
| 929 | 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] | 930 | err_code |= ERR_ALERT | ERR_FATAL; |
| 931 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 932 | } |
| 933 | global.maxconn = atol(args[1]); |
| 934 | #ifdef SYSTEM_MAXCONN |
| 935 | if (global.maxconn > DEFAULT_MAXCONN && cfg_maxconn <= DEFAULT_MAXCONN) { |
| 936 | 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); |
| 937 | global.maxconn = DEFAULT_MAXCONN; |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 938 | err_code |= ERR_ALERT; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 939 | } |
| 940 | #endif /* SYSTEM_MAXCONN */ |
| 941 | } |
Willy Tarreau | 403edff | 2012-09-06 11:58:37 +0200 | [diff] [blame] | 942 | else if (!strcmp(args[0], "maxsslconn")) { |
| 943 | #ifdef USE_OPENSSL |
| 944 | if (*(args[1]) == 0) { |
| 945 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 946 | err_code |= ERR_ALERT | ERR_FATAL; |
| 947 | goto out; |
| 948 | } |
| 949 | global.maxsslconn = atol(args[1]); |
| 950 | #else |
Emeric Brun | 0914df8 | 2012-10-02 18:45:42 +0200 | [diff] [blame] | 951 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 952 | err_code |= ERR_ALERT | ERR_FATAL; |
| 953 | goto out; |
Willy Tarreau | 403edff | 2012-09-06 11:58:37 +0200 | [diff] [blame] | 954 | #endif |
| 955 | } |
Willy Tarreau | 610f04b | 2014-02-13 11:36:41 +0100 | [diff] [blame] | 956 | else if (!strcmp(args[0], "ssl-default-bind-ciphers")) { |
| 957 | #ifdef USE_OPENSSL |
| 958 | if (*(args[1]) == 0) { |
| 959 | Alert("parsing [%s:%d] : '%s' expects a cipher suite as an argument.\n", file, linenum, args[0]); |
| 960 | err_code |= ERR_ALERT | ERR_FATAL; |
| 961 | goto out; |
| 962 | } |
| 963 | free(global.listen_default_ciphers); |
| 964 | global.listen_default_ciphers = strdup(args[1]); |
| 965 | #else |
| 966 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 967 | err_code |= ERR_ALERT | ERR_FATAL; |
| 968 | goto out; |
| 969 | #endif |
| 970 | } |
| 971 | else if (!strcmp(args[0], "ssl-default-server-ciphers")) { |
| 972 | #ifdef USE_OPENSSL |
| 973 | if (*(args[1]) == 0) { |
| 974 | Alert("parsing [%s:%d] : '%s' expects a cipher suite as an argument.\n", file, linenum, args[0]); |
| 975 | err_code |= ERR_ALERT | ERR_FATAL; |
| 976 | goto out; |
| 977 | } |
| 978 | free(global.connect_default_ciphers); |
| 979 | global.connect_default_ciphers = strdup(args[1]); |
| 980 | #else |
| 981 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 982 | err_code |= ERR_ALERT | ERR_FATAL; |
| 983 | goto out; |
| 984 | #endif |
| 985 | } |
Emeric Brun | 850efd5 | 2014-01-29 12:24:34 +0100 | [diff] [blame] | 986 | else if (!strcmp(args[0], "ssl-server-verify")) { |
| 987 | if (*(args[1]) == 0) { |
| 988 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 989 | err_code |= ERR_ALERT | ERR_FATAL; |
| 990 | goto out; |
| 991 | } |
| 992 | if (strcmp(args[1],"none") == 0) |
| 993 | global.ssl_server_verify = SSL_SERVER_VERIFY_NONE; |
| 994 | else if (strcmp(args[1],"required") == 0) |
| 995 | global.ssl_server_verify = SSL_SERVER_VERIFY_REQUIRED; |
| 996 | else { |
| 997 | Alert("parsing [%s:%d] : '%s' expects 'none' or 'required' as argument.\n", file, linenum, args[0]); |
| 998 | err_code |= ERR_ALERT | ERR_FATAL; |
| 999 | goto out; |
| 1000 | } |
| 1001 | } |
Willy Tarreau | 81c25d0 | 2011-09-07 15:17:21 +0200 | [diff] [blame] | 1002 | else if (!strcmp(args[0], "maxconnrate")) { |
| 1003 | if (global.cps_lim != 0) { |
| 1004 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 1005 | err_code |= ERR_ALERT; |
| 1006 | goto out; |
| 1007 | } |
| 1008 | if (*(args[1]) == 0) { |
| 1009 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1010 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1011 | goto out; |
| 1012 | } |
| 1013 | global.cps_lim = atol(args[1]); |
| 1014 | } |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1015 | else if (!strcmp(args[0], "maxsessrate")) { |
| 1016 | if (global.sps_lim != 0) { |
| 1017 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 1018 | err_code |= ERR_ALERT; |
| 1019 | goto out; |
| 1020 | } |
| 1021 | if (*(args[1]) == 0) { |
| 1022 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1023 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1024 | goto out; |
| 1025 | } |
| 1026 | global.sps_lim = atol(args[1]); |
| 1027 | } |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 1028 | else if (!strcmp(args[0], "maxsslrate")) { |
| 1029 | if (global.ssl_lim != 0) { |
| 1030 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 1031 | err_code |= ERR_ALERT; |
| 1032 | goto out; |
| 1033 | } |
| 1034 | if (*(args[1]) == 0) { |
| 1035 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1036 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1037 | goto out; |
| 1038 | } |
| 1039 | global.ssl_lim = atol(args[1]); |
| 1040 | } |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1041 | else if (!strcmp(args[0], "maxcomprate")) { |
| 1042 | if (*(args[1]) == 0) { |
| 1043 | Alert("parsing [%s:%d] : '%s' expects an integer argument in kb/s.\n", file, linenum, args[0]); |
| 1044 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1045 | goto out; |
| 1046 | } |
| 1047 | global.comp_rate_lim = atoi(args[1]) * 1024; |
| 1048 | } |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 1049 | else if (!strcmp(args[0], "maxpipes")) { |
| 1050 | if (global.maxpipes != 0) { |
| 1051 | 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] | 1052 | err_code |= ERR_ALERT; |
| 1053 | goto out; |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 1054 | } |
| 1055 | if (*(args[1]) == 0) { |
| 1056 | 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] | 1057 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1058 | goto out; |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 1059 | } |
| 1060 | global.maxpipes = atol(args[1]); |
| 1061 | } |
William Lallemand | 9d5f548 | 2012-11-07 16:12:57 +0100 | [diff] [blame] | 1062 | else if (!strcmp(args[0], "maxzlibmem")) { |
| 1063 | if (*(args[1]) == 0) { |
| 1064 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1065 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1066 | goto out; |
| 1067 | } |
William Lallemand | e3a7d99 | 2012-11-20 11:25:20 +0100 | [diff] [blame] | 1068 | global.maxzlibmem = atol(args[1]) * 1024L * 1024L; |
William Lallemand | 9d5f548 | 2012-11-07 16:12:57 +0100 | [diff] [blame] | 1069 | } |
William Lallemand | 072a2bf | 2012-11-20 17:01:01 +0100 | [diff] [blame] | 1070 | else if (!strcmp(args[0], "maxcompcpuusage")) { |
| 1071 | if (*(args[1]) == 0) { |
| 1072 | Alert("parsing [%s:%d] : '%s' expects an integer argument between 0 and 100.\n", file, linenum, args[0]); |
| 1073 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1074 | goto out; |
| 1075 | } |
| 1076 | compress_min_idle = 100 - atoi(args[1]); |
Willy Tarreau | cb2699a | 2013-01-24 16:25:38 +0100 | [diff] [blame] | 1077 | if (compress_min_idle > 100) { |
William Lallemand | 072a2bf | 2012-11-20 17:01:01 +0100 | [diff] [blame] | 1078 | Alert("parsing [%s:%d] : '%s' expects an integer argument between 0 and 100.\n", file, linenum, args[0]); |
| 1079 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1080 | goto out; |
| 1081 | } |
| 1082 | } |
| 1083 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1084 | else if (!strcmp(args[0], "ulimit-n")) { |
| 1085 | if (global.rlimit_nofile != 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 | baaee00 | 2006-06-26 02:48:02 +0200 | [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 | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1094 | } |
| 1095 | global.rlimit_nofile = atol(args[1]); |
| 1096 | } |
| 1097 | else if (!strcmp(args[0], "chroot")) { |
| 1098 | if (global.chroot != NULL) { |
| 1099 | 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] | 1100 | err_code |= ERR_ALERT; |
| 1101 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1102 | } |
| 1103 | if (*(args[1]) == 0) { |
| 1104 | 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] | 1105 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1106 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1107 | } |
| 1108 | global.chroot = strdup(args[1]); |
| 1109 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1110 | else if (!strcmp(args[0], "description")) { |
| 1111 | int i, len=0; |
| 1112 | char *d; |
| 1113 | |
| 1114 | if (!*args[1]) { |
| 1115 | Alert("parsing [%s:%d]: '%s' expects a string argument.\n", |
| 1116 | file, linenum, args[0]); |
| 1117 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1118 | goto out; |
| 1119 | } |
| 1120 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 1121 | for (i = 1; *args[i]; i++) |
| 1122 | len += strlen(args[i]) + 1; |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1123 | |
| 1124 | if (global.desc) |
| 1125 | free(global.desc); |
| 1126 | |
| 1127 | global.desc = d = (char *)calloc(1, len); |
| 1128 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 1129 | d += snprintf(d, global.desc + len - d, "%s", args[1]); |
| 1130 | for (i = 2; *args[i]; i++) |
| 1131 | d += snprintf(d, global.desc + len - d, " %s", args[i]); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1132 | } |
| 1133 | else if (!strcmp(args[0], "node")) { |
| 1134 | int i; |
| 1135 | char c; |
| 1136 | |
| 1137 | for (i=0; args[1][i]; i++) { |
| 1138 | c = args[1][i]; |
Willy Tarreau | 88e0581 | 2010-03-03 00:16:00 +0100 | [diff] [blame] | 1139 | if (!isupper((unsigned char)c) && !islower((unsigned char)c) && |
| 1140 | !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.') |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1141 | break; |
| 1142 | } |
| 1143 | |
| 1144 | if (!i || args[1][i]) { |
| 1145 | Alert("parsing [%s:%d]: '%s' requires valid node name - non-empty string" |
| 1146 | " with digits(0-9), letters(A-Z, a-z), dot(.), hyphen(-) or underscode(_).\n", |
| 1147 | file, linenum, args[0]); |
| 1148 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1149 | goto out; |
| 1150 | } |
| 1151 | |
| 1152 | if (global.node) |
| 1153 | free(global.node); |
| 1154 | |
| 1155 | global.node = strdup(args[1]); |
| 1156 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1157 | else if (!strcmp(args[0], "pidfile")) { |
| 1158 | if (global.pidfile != NULL) { |
| 1159 | 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] | 1160 | err_code |= ERR_ALERT; |
| 1161 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1162 | } |
| 1163 | if (*(args[1]) == 0) { |
| 1164 | 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] | 1165 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1166 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1167 | } |
| 1168 | global.pidfile = strdup(args[1]); |
| 1169 | } |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 1170 | else if (!strcmp(args[0], "unix-bind")) { |
| 1171 | int cur_arg = 1; |
| 1172 | while (*(args[cur_arg])) { |
| 1173 | if (!strcmp(args[cur_arg], "prefix")) { |
| 1174 | if (global.unix_bind.prefix != NULL) { |
| 1175 | Alert("parsing [%s:%d] : unix-bind '%s' already specified. Continuing.\n", file, linenum, args[cur_arg]); |
| 1176 | err_code |= ERR_ALERT; |
| 1177 | cur_arg += 2; |
| 1178 | continue; |
| 1179 | } |
| 1180 | |
| 1181 | if (*(args[cur_arg+1]) == 0) { |
| 1182 | Alert("parsing [%s:%d] : unix_bind '%s' expects a path as an argument.\n", file, linenum, args[cur_arg]); |
| 1183 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1184 | goto out; |
| 1185 | } |
| 1186 | global.unix_bind.prefix = strdup(args[cur_arg+1]); |
| 1187 | cur_arg += 2; |
| 1188 | continue; |
| 1189 | } |
| 1190 | |
| 1191 | if (!strcmp(args[cur_arg], "mode")) { |
| 1192 | |
| 1193 | global.unix_bind.ux.mode = strtol(args[cur_arg + 1], NULL, 8); |
| 1194 | cur_arg += 2; |
| 1195 | continue; |
| 1196 | } |
| 1197 | |
| 1198 | if (!strcmp(args[cur_arg], "uid")) { |
| 1199 | |
| 1200 | global.unix_bind.ux.uid = atol(args[cur_arg + 1 ]); |
| 1201 | cur_arg += 2; |
| 1202 | continue; |
| 1203 | } |
| 1204 | |
| 1205 | if (!strcmp(args[cur_arg], "gid")) { |
| 1206 | |
| 1207 | global.unix_bind.ux.gid = atol(args[cur_arg + 1 ]); |
| 1208 | cur_arg += 2; |
| 1209 | continue; |
| 1210 | } |
| 1211 | |
| 1212 | if (!strcmp(args[cur_arg], "user")) { |
| 1213 | struct passwd *user; |
| 1214 | |
| 1215 | user = getpwnam(args[cur_arg + 1]); |
| 1216 | if (!user) { |
| 1217 | Alert("parsing [%s:%d] : '%s' : '%s' unknown user.\n", |
| 1218 | file, linenum, args[0], args[cur_arg + 1 ]); |
| 1219 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1220 | goto out; |
| 1221 | } |
| 1222 | |
| 1223 | global.unix_bind.ux.uid = user->pw_uid; |
| 1224 | cur_arg += 2; |
| 1225 | continue; |
| 1226 | } |
| 1227 | |
| 1228 | if (!strcmp(args[cur_arg], "group")) { |
| 1229 | struct group *group; |
| 1230 | |
| 1231 | group = getgrnam(args[cur_arg + 1]); |
| 1232 | if (!group) { |
| 1233 | Alert("parsing [%s:%d] : '%s' : '%s' unknown group.\n", |
| 1234 | file, linenum, args[0], args[cur_arg + 1 ]); |
| 1235 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1236 | goto out; |
| 1237 | } |
| 1238 | |
| 1239 | global.unix_bind.ux.gid = group->gr_gid; |
| 1240 | cur_arg += 2; |
| 1241 | continue; |
| 1242 | } |
| 1243 | |
Willy Tarreau | b48f958 | 2011-09-05 01:17:06 +0200 | [diff] [blame] | 1244 | 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] | 1245 | file, linenum, args[0]); |
| 1246 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1247 | goto out; |
| 1248 | } |
| 1249 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1250 | else if (!strcmp(args[0], "log") && kwm == KWM_NO) { /* no log */ |
| 1251 | /* delete previous herited or defined syslog servers */ |
| 1252 | struct logsrv *back; |
| 1253 | struct logsrv *tmp; |
| 1254 | |
| 1255 | if (*(args[1]) != 0) { |
| 1256 | Alert("parsing [%s:%d]:%s : 'no log' does not expect arguments.\n", file, linenum, args[1]); |
| 1257 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1258 | goto out; |
| 1259 | } |
| 1260 | |
| 1261 | list_for_each_entry_safe(tmp, back, &global.logsrvs, list) { |
| 1262 | LIST_DEL(&tmp->list); |
| 1263 | free(tmp); |
| 1264 | } |
| 1265 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1266 | else if (!strcmp(args[0], "log")) { /* syslog server address */ |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1267 | struct sockaddr_storage *sk; |
| 1268 | int port1, port2; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1269 | struct logsrv *logsrv; |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1270 | int arg = 0; |
| 1271 | int len = 0; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1272 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1273 | if (*(args[1]) == 0 || *(args[2]) == 0) { |
| 1274 | 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] | 1275 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1276 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1277 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1278 | |
| 1279 | logsrv = calloc(1, sizeof(struct logsrv)); |
| 1280 | |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1281 | /* just after the address, a length may be specified */ |
| 1282 | if (strcmp(args[arg+2], "len") == 0) { |
| 1283 | len = atoi(args[arg+3]); |
| 1284 | if (len < 80 || len > 65535) { |
| 1285 | Alert("parsing [%s:%d] : invalid log length '%s', must be between 80 and 65535.\n", |
| 1286 | file, linenum, args[arg+3]); |
| 1287 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1288 | goto out; |
| 1289 | } |
| 1290 | logsrv->maxlen = len; |
| 1291 | |
| 1292 | /* skip these two args */ |
| 1293 | arg += 2; |
| 1294 | } |
| 1295 | else |
| 1296 | logsrv->maxlen = MAX_SYSLOG_LEN; |
| 1297 | |
| 1298 | if (logsrv->maxlen > global.max_syslog_len) { |
| 1299 | global.max_syslog_len = logsrv->maxlen; |
| 1300 | logline = realloc(logline, global.max_syslog_len + 1); |
| 1301 | } |
| 1302 | |
| 1303 | logsrv->facility = get_log_facility(args[arg+2]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1304 | if (logsrv->facility < 0) { |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1305 | 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] | 1306 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1307 | logsrv->facility = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1308 | } |
| 1309 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1310 | logsrv->level = 7; /* max syslog level = debug */ |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1311 | if (*(args[arg+3])) { |
| 1312 | logsrv->level = get_log_level(args[arg+3]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1313 | if (logsrv->level < 0) { |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1314 | 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] | 1315 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1316 | logsrv->level = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1317 | } |
| 1318 | } |
| 1319 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1320 | logsrv->minlvl = 0; /* limit syslog level to this level (emerg) */ |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1321 | if (*(args[arg+4])) { |
| 1322 | logsrv->minlvl = get_log_level(args[arg+4]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1323 | if (logsrv->minlvl < 0) { |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1324 | 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] | 1325 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1326 | logsrv->minlvl = 0; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 1327 | } |
| 1328 | } |
| 1329 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1330 | sk = str2sa_range(args[1], &port1, &port2, &errmsg, NULL); |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1331 | if (!sk) { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1332 | Alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1333 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1334 | free(logsrv); |
| 1335 | goto out; |
| 1336 | } |
| 1337 | logsrv->addr = *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 1338 | |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1339 | if (sk->ss_family == AF_INET || sk->ss_family == AF_INET6) { |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 1340 | if (port1 != port2) { |
| 1341 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 1342 | file, linenum, args[0], args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 1343 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1344 | free(logsrv); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 1345 | goto out; |
| 1346 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 1347 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1348 | logsrv->addr = *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 1349 | if (!port1) |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1350 | set_host_port(&logsrv->addr, SYSLOG_PORT); |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 1351 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1352 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1353 | LIST_ADDQ(&global.logsrvs, &logsrv->list); |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1354 | } |
Joe Williams | df5b38f | 2010-12-29 17:05:48 +0100 | [diff] [blame] | 1355 | else if (!strcmp(args[0], "log-send-hostname")) { /* set the hostname in syslog header */ |
| 1356 | char *name; |
| 1357 | int len; |
| 1358 | |
| 1359 | if (global.log_send_hostname != NULL) { |
| 1360 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 1361 | err_code |= ERR_ALERT; |
| 1362 | goto out; |
| 1363 | } |
| 1364 | |
| 1365 | if (*(args[1])) |
| 1366 | name = args[1]; |
| 1367 | else |
| 1368 | name = hostname; |
| 1369 | |
| 1370 | len = strlen(name); |
| 1371 | |
| 1372 | /* We'll add a space after the name to respect the log format */ |
| 1373 | free(global.log_send_hostname); |
| 1374 | global.log_send_hostname = malloc(len + 2); |
| 1375 | snprintf(global.log_send_hostname, len + 2, "%s ", name); |
| 1376 | } |
Kevinm | 48936af | 2010-12-22 16:08:21 +0000 | [diff] [blame] | 1377 | else if (!strcmp(args[0], "log-tag")) { /* tag to report to syslog */ |
| 1378 | if (*(args[1]) == 0) { |
| 1379 | Alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]); |
| 1380 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1381 | goto out; |
| 1382 | } |
| 1383 | free(global.log_tag); |
| 1384 | global.log_tag = strdup(args[1]); |
| 1385 | } |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1386 | else if (!strcmp(args[0], "spread-checks")) { /* random time between checks (0-50) */ |
| 1387 | if (global.spread_checks != 0) { |
| 1388 | Alert("parsing [%s:%d]: spread-checks already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1389 | err_code |= ERR_ALERT; |
| 1390 | goto out; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1391 | } |
| 1392 | if (*(args[1]) == 0) { |
| 1393 | 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] | 1394 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1395 | goto out; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1396 | } |
| 1397 | global.spread_checks = atol(args[1]); |
| 1398 | if (global.spread_checks < 0 || global.spread_checks > 50) { |
| 1399 | 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] | 1400 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1401 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1402 | } |
Willy Tarreau | 1746eec | 2014-04-25 10:46:47 +0200 | [diff] [blame] | 1403 | else if (!strcmp(args[0], "max-spread-checks")) { /* maximum time between first and last check */ |
| 1404 | const char *err; |
| 1405 | unsigned int val; |
| 1406 | |
| 1407 | |
| 1408 | if (*(args[1]) == 0) { |
| 1409 | Alert("parsing [%s:%d]: '%s' expects an integer argument (0..50).\n", file, linenum, args[0]); |
| 1410 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1411 | goto out; |
| 1412 | } |
| 1413 | |
| 1414 | err = parse_time_err(args[1], &val, TIME_UNIT_MS); |
| 1415 | if (err) { |
| 1416 | Alert("parsing [%s:%d]: unsupported character '%c' in '%s' (wants an integer delay).\n", file, linenum, *err, args[0]); |
| 1417 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1418 | } |
| 1419 | global.max_spread_checks = val; |
| 1420 | if (global.max_spread_checks < 0) { |
| 1421 | Alert("parsing [%s:%d]: '%s' needs a positive delay in milliseconds.\n",file, linenum, args[0]); |
| 1422 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1423 | } |
| 1424 | } |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1425 | else if (strcmp(args[0], "cpu-map") == 0) { /* map a process list to a CPU set */ |
| 1426 | #ifdef USE_CPU_AFFINITY |
| 1427 | int cur_arg, i; |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1428 | unsigned long proc = 0; |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1429 | unsigned long cpus = 0; |
| 1430 | |
| 1431 | if (strcmp(args[1], "all") == 0) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1432 | proc = ~0UL; |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1433 | else if (strcmp(args[1], "odd") == 0) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1434 | proc = ~0UL/3UL; /* 0x555....555 */ |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1435 | else if (strcmp(args[1], "even") == 0) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1436 | proc = (~0UL/3UL) << 1; /* 0xAAA...AAA */ |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1437 | else { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1438 | proc = atol(args[1]); |
| 1439 | if (proc >= 1 && proc <= LONGBITS) |
| 1440 | proc = 1UL << (proc - 1); |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1441 | } |
| 1442 | |
| 1443 | if (!proc || !*args[2]) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1444 | 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", |
| 1445 | file, linenum, args[0], LONGBITS, LONGBITS - 1); |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1446 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1447 | goto out; |
| 1448 | } |
| 1449 | |
| 1450 | cur_arg = 2; |
| 1451 | while (*args[cur_arg]) { |
| 1452 | unsigned int low, high; |
| 1453 | |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 1454 | if (isdigit((int)*args[cur_arg])) { |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1455 | char *dash = strchr(args[cur_arg], '-'); |
| 1456 | |
| 1457 | low = high = str2uic(args[cur_arg]); |
| 1458 | if (dash) |
| 1459 | high = str2uic(dash + 1); |
| 1460 | |
| 1461 | if (high < low) { |
| 1462 | unsigned int swap = low; |
| 1463 | low = high; |
| 1464 | high = swap; |
| 1465 | } |
| 1466 | |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1467 | if (high >= LONGBITS) { |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1468 | 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] | 1469 | file, linenum, args[0], LONGBITS - 1); |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1470 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1471 | goto out; |
| 1472 | } |
| 1473 | |
| 1474 | while (low <= high) |
| 1475 | cpus |= 1UL << low++; |
| 1476 | } |
| 1477 | else { |
| 1478 | Alert("parsing [%s:%d]: %s : '%s' is not a CPU range.\n", |
| 1479 | file, linenum, args[0], args[cur_arg]); |
| 1480 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1481 | goto out; |
| 1482 | } |
| 1483 | cur_arg++; |
| 1484 | } |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1485 | for (i = 0; i < LONGBITS; i++) |
| 1486 | if (proc & (1UL << i)) |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1487 | global.cpu_map[i] = cpus; |
| 1488 | #else |
| 1489 | Alert("parsing [%s:%d] : '%s' is not enabled, please check build options for USE_CPU_AFFINITY.\n", file, linenum, args[0]); |
| 1490 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1491 | goto out; |
| 1492 | #endif |
| 1493 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1494 | else { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1495 | struct cfg_kw_list *kwl; |
| 1496 | int index; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1497 | int rc; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1498 | |
| 1499 | list_for_each_entry(kwl, &cfg_keywords.list, list) { |
| 1500 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 1501 | if (kwl->kw[index].section != CFG_GLOBAL) |
| 1502 | continue; |
| 1503 | if (strcmp(kwl->kw[index].kw, args[0]) == 0) { |
Willy Tarreau | 28a47d6 | 2012-09-18 20:02:48 +0200 | [diff] [blame] | 1504 | 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] | 1505 | if (rc < 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 1506 | Alert("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1507 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1508 | } |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1509 | else if (rc > 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 1510 | Warning("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1511 | err_code |= ERR_WARN; |
| 1512 | goto out; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1513 | } |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1514 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1515 | } |
| 1516 | } |
| 1517 | } |
| 1518 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1519 | 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] | 1520 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1521 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1522 | |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1523 | out: |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 1524 | free(errmsg); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1525 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1526 | } |
| 1527 | |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 1528 | void init_default_instance() |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1529 | { |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 1530 | init_new_proxy(&defproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1531 | defproxy.mode = PR_MODE_TCP; |
| 1532 | defproxy.state = PR_STNEW; |
| 1533 | defproxy.maxconn = cfg_maxpconn; |
| 1534 | defproxy.conn_retries = CONN_RETRIES; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1535 | |
Simon Horman | 6618300 | 2013-02-23 10:16:43 +0900 | [diff] [blame] | 1536 | defproxy.defsrv.check.inter = DEF_CHKINTR; |
| 1537 | defproxy.defsrv.check.fastinter = 0; |
| 1538 | defproxy.defsrv.check.downinter = 0; |
Simon Horman | d60d691 | 2013-11-25 10:46:36 +0900 | [diff] [blame] | 1539 | defproxy.defsrv.agent.inter = DEF_CHKINTR; |
| 1540 | defproxy.defsrv.agent.fastinter = 0; |
| 1541 | defproxy.defsrv.agent.downinter = 0; |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 1542 | defproxy.defsrv.check.rise = DEF_RISETIME; |
| 1543 | defproxy.defsrv.check.fall = DEF_FALLTIME; |
| 1544 | defproxy.defsrv.agent.rise = DEF_AGENT_RISETIME; |
| 1545 | defproxy.defsrv.agent.fall = DEF_AGENT_FALLTIME; |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 1546 | defproxy.defsrv.check.port = 0; |
Simon Horman | d60d691 | 2013-11-25 10:46:36 +0900 | [diff] [blame] | 1547 | defproxy.defsrv.agent.port = 0; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1548 | defproxy.defsrv.maxqueue = 0; |
| 1549 | defproxy.defsrv.minconn = 0; |
| 1550 | defproxy.defsrv.maxconn = 0; |
| 1551 | defproxy.defsrv.slowstart = 0; |
| 1552 | defproxy.defsrv.onerror = DEF_HANA_ONERR; |
| 1553 | defproxy.defsrv.consecutive_errors_limit = DEF_HANA_ERRLIMIT; |
| 1554 | defproxy.defsrv.uweight = defproxy.defsrv.iweight = 1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1555 | } |
| 1556 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1557 | |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1558 | /* This function createss a new req* or rsp* rule to the proxy. It compiles the |
| 1559 | * regex and may return the ERR_WARN bit, and error bits such as ERR_ALERT and |
| 1560 | * ERR_FATAL in case of error. |
| 1561 | */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1562 | static int create_cond_regex_rule(const char *file, int line, |
| 1563 | struct proxy *px, int dir, int action, int flags, |
| 1564 | const char *cmd, const char *reg, const char *repl, |
| 1565 | const char **cond_start) |
| 1566 | { |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1567 | struct my_regex *preg = NULL; |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 1568 | char *errmsg = NULL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1569 | const char *err; |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1570 | char *error; |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1571 | int ret_code = 0; |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1572 | struct acl_cond *cond = NULL; |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1573 | int cs; |
| 1574 | int cap; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1575 | |
| 1576 | if (px == &defproxy) { |
| 1577 | 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] | 1578 | ret_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1579 | goto err; |
| 1580 | } |
| 1581 | |
| 1582 | if (*reg == 0) { |
| 1583 | 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] | 1584 | ret_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1585 | goto err; |
| 1586 | } |
| 1587 | |
| 1588 | if (warnifnotcap(px, PR_CAP_RS, file, line, cmd, NULL)) |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1589 | ret_code |= ERR_WARN; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1590 | |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1591 | if (cond_start && |
| 1592 | (strcmp(*cond_start, "if") == 0 || strcmp(*cond_start, "unless") == 0)) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 1593 | if ((cond = build_acl_cond(file, line, px, cond_start, &errmsg)) == NULL) { |
| 1594 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 1595 | file, line, cmd, errmsg); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1596 | ret_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1597 | goto err; |
| 1598 | } |
| 1599 | } |
| 1600 | else if (cond_start && **cond_start) { |
| 1601 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 1602 | file, line, cmd, *cond_start); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1603 | ret_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1604 | goto err; |
| 1605 | } |
| 1606 | |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1607 | ret_code |= warnif_cond_conflicts(cond, |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 1608 | (dir == SMP_OPT_DIR_REQ) ? |
| 1609 | ((px->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR) : |
| 1610 | ((px->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR), |
| 1611 | file, line); |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1612 | |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1613 | preg = calloc(1, sizeof(*preg)); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1614 | if (!preg) { |
| 1615 | 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] | 1616 | ret_code = ERR_ALERT | ERR_FATAL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1617 | goto err; |
| 1618 | } |
| 1619 | |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1620 | cs = !(flags & REG_ICASE); |
| 1621 | cap = !(flags & REG_NOSUB); |
| 1622 | error = NULL; |
| 1623 | if (!regex_comp(reg, preg, cs, cap, &error)) { |
| 1624 | Alert("parsing [%s:%d] : '%s' : regular expression '%s' : %s\n", file, line, cmd, reg, error); |
| 1625 | free(error); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1626 | ret_code = ERR_ALERT | ERR_FATAL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1627 | goto err; |
| 1628 | } |
| 1629 | |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 1630 | 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] | 1631 | preg, action, repl ? strdup(repl) : NULL, cond); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1632 | if (repl && err) { |
| 1633 | Alert("parsing [%s:%d] : '%s' : invalid character or unterminated sequence in replacement string near '%c'.\n", |
| 1634 | file, line, cmd, *err); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1635 | ret_code |= ERR_ALERT | ERR_FATAL; |
| 1636 | goto err_free; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1637 | } |
| 1638 | |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 1639 | 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] | 1640 | ret_code |= ERR_WARN; |
| 1641 | |
| 1642 | return ret_code; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1643 | |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1644 | err_free: |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1645 | regex_free(preg); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1646 | err: |
| 1647 | free(preg); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1648 | free(errmsg); |
| 1649 | return ret_code; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1650 | } |
| 1651 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1652 | /* |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1653 | * Parse a line in a <listen>, <frontend>, <backend> or <ruleset> section. |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1654 | * Returns the error code, 0 if OK, or any combination of : |
| 1655 | * - ERR_ABORT: must abort ASAP |
| 1656 | * - ERR_FATAL: we can continue parsing but not start the service |
| 1657 | * - ERR_WARN: a warning has been emitted |
| 1658 | * - ERR_ALERT: an alert has been emitted |
| 1659 | * Only the two first ones can stop processing, the two others are just |
| 1660 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1661 | */ |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1662 | int cfg_parse_peers(const char *file, int linenum, char **args, int kwm) |
| 1663 | { |
| 1664 | static struct peers *curpeers = NULL; |
| 1665 | struct peer *newpeer = NULL; |
| 1666 | const char *err; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1667 | struct bind_conf *bind_conf; |
| 1668 | struct listener *l; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1669 | int err_code = 0; |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1670 | char *errmsg = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1671 | |
| 1672 | if (strcmp(args[0], "peers") == 0) { /* new peers section */ |
Willy Tarreau | 0dbbf31 | 2013-03-05 11:31:55 +0100 | [diff] [blame] | 1673 | if (!*args[1]) { |
| 1674 | Alert("parsing [%s:%d] : missing name for peers section.\n", file, linenum); |
Willy Tarreau | 5498472 | 2014-02-16 08:20:13 +0100 | [diff] [blame] | 1675 | err_code |= ERR_ALERT | ERR_ABORT; |
Willy Tarreau | 0dbbf31 | 2013-03-05 11:31:55 +0100 | [diff] [blame] | 1676 | goto out; |
| 1677 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1678 | |
| 1679 | err = invalid_char(args[1]); |
| 1680 | if (err) { |
| 1681 | Alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 1682 | file, linenum, *err, args[0], args[1]); |
Willy Tarreau | 5498472 | 2014-02-16 08:20:13 +0100 | [diff] [blame] | 1683 | err_code |= ERR_ALERT | ERR_ABORT; |
Willy Tarreau | 0dbbf31 | 2013-03-05 11:31:55 +0100 | [diff] [blame] | 1684 | goto out; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1685 | } |
| 1686 | |
| 1687 | for (curpeers = peers; curpeers != NULL; curpeers = curpeers->next) { |
| 1688 | /* |
| 1689 | * If there are two proxies with the same name only following |
| 1690 | * combinations are allowed: |
| 1691 | */ |
| 1692 | if (strcmp(curpeers->id, args[1]) == 0) { |
| 1693 | Warning("Parsing [%s:%d]: peers '%s' has same name as another peers (declared at %s:%d).\n", |
| 1694 | file, linenum, args[1], curpeers->conf.file, curpeers->conf.line); |
| 1695 | err_code |= ERR_WARN; |
| 1696 | } |
| 1697 | } |
| 1698 | |
| 1699 | if ((curpeers = (struct peers *)calloc(1, sizeof(struct peers))) == NULL) { |
| 1700 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1701 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1702 | goto out; |
| 1703 | } |
| 1704 | |
| 1705 | curpeers->next = peers; |
| 1706 | peers = curpeers; |
Willy Tarreau | 8113a5d | 2012-10-04 08:01:43 +0200 | [diff] [blame] | 1707 | curpeers->conf.file = strdup(file); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1708 | curpeers->conf.line = linenum; |
| 1709 | curpeers->last_change = now.tv_sec; |
| 1710 | curpeers->id = strdup(args[1]); |
| 1711 | } |
| 1712 | else if (strcmp(args[0], "peer") == 0) { /* peer definition */ |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 1713 | struct sockaddr_storage *sk; |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 1714 | int port1, port2; |
Willy Tarreau | b36487e | 2013-03-10 18:37:42 +0100 | [diff] [blame] | 1715 | struct protocol *proto; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1716 | |
| 1717 | if (!*args[2]) { |
| 1718 | Alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n", |
| 1719 | file, linenum, args[0]); |
| 1720 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1721 | goto out; |
| 1722 | } |
| 1723 | |
| 1724 | err = invalid_char(args[1]); |
| 1725 | if (err) { |
| 1726 | Alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n", |
| 1727 | file, linenum, *err, args[1]); |
| 1728 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1729 | goto out; |
| 1730 | } |
| 1731 | |
| 1732 | if ((newpeer = (struct peer *)calloc(1, sizeof(struct peer))) == NULL) { |
| 1733 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1734 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1735 | goto out; |
| 1736 | } |
| 1737 | |
| 1738 | /* the peers are linked backwards first */ |
| 1739 | curpeers->count++; |
| 1740 | newpeer->next = curpeers->remote; |
| 1741 | curpeers->remote = newpeer; |
| 1742 | newpeer->peers = curpeers; |
Willy Tarreau | 8113a5d | 2012-10-04 08:01:43 +0200 | [diff] [blame] | 1743 | newpeer->conf.file = strdup(file); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1744 | newpeer->conf.line = linenum; |
| 1745 | |
| 1746 | newpeer->last_change = now.tv_sec; |
| 1747 | newpeer->id = strdup(args[1]); |
| 1748 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1749 | sk = str2sa_range(args[2], &port1, &port2, &errmsg, NULL); |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 1750 | if (!sk) { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1751 | 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] | 1752 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1753 | goto out; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1754 | } |
Willy Tarreau | b36487e | 2013-03-10 18:37:42 +0100 | [diff] [blame] | 1755 | |
| 1756 | proto = protocol_by_family(sk->ss_family); |
| 1757 | if (!proto || !proto->connect) { |
| 1758 | Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 1759 | file, linenum, args[0], args[1]); |
| 1760 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1761 | goto out; |
| 1762 | } |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 1763 | |
| 1764 | if (port1 != port2) { |
| 1765 | Alert("parsing [%s:%d] : '%s %s' : port ranges and offsets are not allowed in '%s'\n", |
| 1766 | file, linenum, args[0], args[1], args[2]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1767 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1768 | goto out; |
| 1769 | } |
| 1770 | |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 1771 | if (!port1) { |
| 1772 | Alert("parsing [%s:%d] : '%s %s' : missing or invalid port in '%s'\n", |
| 1773 | file, linenum, args[0], args[1], args[2]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1774 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1775 | goto out; |
| 1776 | } |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 1777 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1778 | newpeer->addr = *sk; |
Willy Tarreau | b36487e | 2013-03-10 18:37:42 +0100 | [diff] [blame] | 1779 | newpeer->proto = proto; |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 1780 | newpeer->xprt = &raw_sock; |
Willy Tarreau | d02394b | 2012-05-11 18:32:18 +0200 | [diff] [blame] | 1781 | newpeer->sock_init_arg = NULL; |
Willy Tarreau | 26d8c59 | 2012-05-07 18:12:14 +0200 | [diff] [blame] | 1782 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1783 | if (strcmp(newpeer->id, localpeer) == 0) { |
| 1784 | /* Current is local peer, it define a frontend */ |
| 1785 | newpeer->local = 1; |
| 1786 | |
| 1787 | if (!curpeers->peers_fe) { |
| 1788 | if ((curpeers->peers_fe = calloc(1, sizeof(struct proxy))) == NULL) { |
| 1789 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1790 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1791 | goto out; |
| 1792 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1793 | |
Willy Tarreau | 237250c | 2011-07-29 01:49:03 +0200 | [diff] [blame] | 1794 | init_new_proxy(curpeers->peers_fe); |
| 1795 | curpeers->peers_fe->parent = curpeers; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1796 | |
| 1797 | curpeers->peers_fe->last_change = now.tv_sec; |
| 1798 | curpeers->peers_fe->id = strdup(args[1]); |
| 1799 | curpeers->peers_fe->cap = PR_CAP_FE; |
Willy Tarreau | 3ae65a1 | 2011-09-07 17:40:39 +0200 | [diff] [blame] | 1800 | curpeers->peers_fe->maxconn = 0; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1801 | curpeers->peers_fe->conn_retries = CONN_RETRIES; |
| 1802 | curpeers->peers_fe->timeout.connect = 5000; |
| 1803 | curpeers->peers_fe->accept = peer_accept; |
| 1804 | 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] | 1805 | curpeers->peers_fe->conf.args.file = curpeers->peers_fe->conf.file = strdup(file); |
| 1806 | curpeers->peers_fe->conf.args.line = curpeers->peers_fe->conf.line = linenum; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1807 | |
| 1808 | bind_conf = bind_conf_alloc(&curpeers->peers_fe->conf.bind, file, linenum, args[2]); |
| 1809 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1810 | if (!str2listener(args[2], curpeers->peers_fe, bind_conf, file, linenum, &errmsg)) { |
| 1811 | if (errmsg && *errmsg) { |
| 1812 | indent_msg(&errmsg, 2); |
| 1813 | 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] | 1814 | } |
| 1815 | else |
| 1816 | Alert("parsing [%s:%d] : '%s %s' : error encountered while parsing listening address %s.\n", |
| 1817 | file, linenum, args[0], args[1], args[2]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1818 | err_code |= ERR_FATAL; |
| 1819 | goto out; |
| 1820 | } |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1821 | |
| 1822 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
Willy Tarreau | acf3bf9 | 2013-01-18 10:51:07 +0100 | [diff] [blame] | 1823 | l->maxaccept = 1; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1824 | l->maxconn = ((struct proxy *)curpeers->peers_fe)->maxconn; |
| 1825 | l->backlog = ((struct proxy *)curpeers->peers_fe)->backlog; |
| 1826 | l->timeout = &((struct proxy *)curpeers->peers_fe)->timeout.client; |
| 1827 | l->accept = session_accept; |
| 1828 | l->handler = process_session; |
| 1829 | l->analysers |= ((struct proxy *)curpeers->peers_fe)->fe_req_ana; |
| 1830 | l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */ |
| 1831 | global.maxsock += l->maxconn; |
| 1832 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1833 | } |
Willy Tarreau | 8b8fd56 | 2013-01-18 11:12:27 +0100 | [diff] [blame] | 1834 | else { |
| 1835 | Alert("parsing [%s:%d] : '%s %s' : local peer name already referenced at %s:%d.\n", |
| 1836 | file, linenum, args[0], args[1], |
| 1837 | curpeers->peers_fe->conf.file, curpeers->peers_fe->conf.line); |
| 1838 | err_code |= ERR_FATAL; |
| 1839 | goto out; |
| 1840 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1841 | } |
| 1842 | } /* neither "peer" nor "peers" */ |
| 1843 | else if (*args[0] != 0) { |
| 1844 | Alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection); |
| 1845 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1846 | goto out; |
| 1847 | } |
| 1848 | |
| 1849 | out: |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1850 | free(errmsg); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1851 | return err_code; |
| 1852 | } |
| 1853 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 1854 | 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] | 1855 | { |
| 1856 | static struct proxy *curproxy = NULL; |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 1857 | const char *err; |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1858 | char *error; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 1859 | int rc; |
| 1860 | unsigned val; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1861 | int err_code = 0; |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 1862 | struct acl_cond *cond = NULL; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 1863 | struct logsrv *tmplogsrv; |
Willy Tarreau | f4068b6 | 2012-05-08 17:37:49 +0200 | [diff] [blame] | 1864 | char *errmsg = NULL; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 1865 | struct bind_conf *bind_conf; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1866 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1867 | if (!strcmp(args[0], "listen")) |
| 1868 | rc = PR_CAP_LISTEN; |
| 1869 | else if (!strcmp(args[0], "frontend")) |
| 1870 | rc = PR_CAP_FE | PR_CAP_RS; |
| 1871 | else if (!strcmp(args[0], "backend")) |
| 1872 | rc = PR_CAP_BE | PR_CAP_RS; |
| 1873 | else if (!strcmp(args[0], "ruleset")) |
| 1874 | rc = PR_CAP_RS; |
| 1875 | else |
| 1876 | rc = PR_CAP_NONE; |
| 1877 | |
| 1878 | if (rc != PR_CAP_NONE) { /* new proxy */ |
Willy Tarreau | 7cbc915 | 2014-03-15 08:17:08 +0100 | [diff] [blame] | 1879 | struct ebpt_node *node; |
| 1880 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1881 | if (!*args[1]) { |
| 1882 | Alert("parsing [%s:%d] : '%s' expects an <id> argument and\n" |
| 1883 | " optionnally supports [addr1]:port1[-end1]{,[addr]:port[-end]}...\n", |
| 1884 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1885 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1886 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1887 | } |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 1888 | |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 1889 | err = invalid_char(args[1]); |
| 1890 | if (err) { |
| 1891 | Alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 1892 | file, linenum, *err, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1893 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 1894 | } |
| 1895 | |
Willy Tarreau | 7cbc915 | 2014-03-15 08:17:08 +0100 | [diff] [blame] | 1896 | for (node = ebis_lookup(&proxy_by_name, args[1]); node; node = ebpt_next(node)) { |
| 1897 | curproxy = container_of(node, struct proxy, conf.by_name); |
| 1898 | |
| 1899 | if (strcmp(curproxy->id, args[1]) != 0) |
| 1900 | break; |
| 1901 | |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 1902 | /* |
| 1903 | * If there are two proxies with the same name only following |
| 1904 | * combinations are allowed: |
| 1905 | * |
| 1906 | * listen backend frontend ruleset |
| 1907 | * listen - - - - |
| 1908 | * backend - - OK - |
| 1909 | * frontend - OK - - |
| 1910 | * ruleset - - - - |
| 1911 | */ |
| 1912 | |
Willy Tarreau | 7cbc915 | 2014-03-15 08:17:08 +0100 | [diff] [blame] | 1913 | if ((rc != (PR_CAP_FE|PR_CAP_RS) || curproxy->cap != (PR_CAP_BE|PR_CAP_RS)) && |
| 1914 | (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] | 1915 | Warning("Parsing [%s:%d]: %s '%s' has same name as another %s (declared at %s:%d).\n", |
| 1916 | file, linenum, proxy_cap_str(rc), args[1], proxy_type_str(curproxy), |
| 1917 | curproxy->conf.file, curproxy->conf.line); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1918 | err_code |= ERR_WARN; |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 1919 | } |
| 1920 | } |
| 1921 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1922 | if ((curproxy = (struct proxy *)calloc(1, sizeof(struct proxy))) == NULL) { |
| 1923 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1924 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1925 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1926 | } |
Willy Tarreau | 5af24ef | 2009-03-15 15:23:16 +0100 | [diff] [blame] | 1927 | |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 1928 | init_new_proxy(curproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1929 | curproxy->next = proxy; |
| 1930 | proxy = curproxy; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 1931 | curproxy->conf.args.file = curproxy->conf.file = strdup(file); |
| 1932 | curproxy->conf.args.line = curproxy->conf.line = linenum; |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 1933 | curproxy->last_change = now.tv_sec; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1934 | curproxy->id = strdup(args[1]); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1935 | curproxy->cap = rc; |
Willy Tarreau | f79d950 | 2014-03-15 07:22:35 +0100 | [diff] [blame] | 1936 | proxy_store_name(curproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1937 | |
| 1938 | /* parse the listener address if any */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1939 | if ((curproxy->cap & PR_CAP_FE) && *args[2]) { |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1940 | struct listener *l; |
Willy Tarreau | 81a8117 | 2012-09-18 20:52:35 +0200 | [diff] [blame] | 1941 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1942 | bind_conf = bind_conf_alloc(&curproxy->conf.bind, file, linenum, args[2]); |
| 1943 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1944 | if (!str2listener(args[2], curproxy, bind_conf, file, linenum, &errmsg)) { |
| 1945 | if (errmsg && *errmsg) { |
| 1946 | indent_msg(&errmsg, 2); |
| 1947 | 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] | 1948 | } |
| 1949 | else |
| 1950 | Alert("parsing [%s:%d] : '%s %s' : error encountered while parsing listening address '%s'.\n", |
| 1951 | file, linenum, args[0], args[1], args[2]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1952 | err_code |= ERR_FATAL; |
| 1953 | goto out; |
| 1954 | } |
Willy Tarreau | 81a8117 | 2012-09-18 20:52:35 +0200 | [diff] [blame] | 1955 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1956 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
Willy Tarreau | c8b1109 | 2011-02-16 11:08:57 +0100 | [diff] [blame] | 1957 | global.maxsock++; |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 1958 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1959 | } |
| 1960 | |
| 1961 | /* set default values */ |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1962 | memcpy(&curproxy->defsrv, &defproxy.defsrv, sizeof(curproxy->defsrv)); |
Willy Tarreau | 7016020 | 2010-04-07 16:06:40 +0200 | [diff] [blame] | 1963 | curproxy->defsrv.id = "default-server"; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1964 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1965 | curproxy->state = defproxy.state; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1966 | curproxy->options = defproxy.options; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 1967 | curproxy->options2 = defproxy.options2; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 1968 | curproxy->no_options = defproxy.no_options; |
| 1969 | curproxy->no_options2 = defproxy.no_options2; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 1970 | curproxy->bind_proc = defproxy.bind_proc; |
Willy Tarreau | 3168223 | 2007-11-29 15:38:04 +0100 | [diff] [blame] | 1971 | curproxy->lbprm.algo = defproxy.lbprm.algo; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 1972 | curproxy->except_net = defproxy.except_net; |
| 1973 | curproxy->except_mask = defproxy.except_mask; |
Maik Broemme | 36db02e | 2009-05-08 17:02:07 +0200 | [diff] [blame] | 1974 | curproxy->except_to = defproxy.except_to; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 1975 | curproxy->except_mask_to = defproxy.except_mask_to; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1976 | |
Willy Tarreau | 79f5fe8 | 2008-08-23 08:18:21 +0200 | [diff] [blame] | 1977 | if (defproxy.fwdfor_hdr_len) { |
| 1978 | curproxy->fwdfor_hdr_len = defproxy.fwdfor_hdr_len; |
| 1979 | curproxy->fwdfor_hdr_name = strdup(defproxy.fwdfor_hdr_name); |
| 1980 | } |
| 1981 | |
Willy Tarreau | b86db34 | 2009-11-30 11:50:16 +0100 | [diff] [blame] | 1982 | if (defproxy.orgto_hdr_len) { |
| 1983 | curproxy->orgto_hdr_len = defproxy.orgto_hdr_len; |
| 1984 | curproxy->orgto_hdr_name = strdup(defproxy.orgto_hdr_name); |
| 1985 | } |
| 1986 | |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 1987 | if (defproxy.server_id_hdr_len) { |
| 1988 | curproxy->server_id_hdr_len = defproxy.server_id_hdr_len; |
| 1989 | curproxy->server_id_hdr_name = strdup(defproxy.server_id_hdr_name); |
| 1990 | } |
| 1991 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1992 | if (curproxy->cap & PR_CAP_FE) { |
| 1993 | curproxy->maxconn = defproxy.maxconn; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 1994 | curproxy->backlog = defproxy.backlog; |
Willy Tarreau | 13a34bd | 2009-05-10 18:52:49 +0200 | [diff] [blame] | 1995 | curproxy->fe_sps_lim = defproxy.fe_sps_lim; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1996 | |
| 1997 | /* initialize error relocations */ |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1998 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) |
| 1999 | chunk_dup(&curproxy->errmsg[rc], &defproxy.errmsg[rc]); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2000 | |
| 2001 | curproxy->to_log = defproxy.to_log & ~LW_COOKIE & ~LW_REQHDR & ~ LW_RSPHDR; |
| 2002 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2003 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2004 | if (curproxy->cap & PR_CAP_BE) { |
| 2005 | curproxy->fullconn = defproxy.fullconn; |
| 2006 | curproxy->conn_retries = defproxy.conn_retries; |
Willy Tarreau | c35362a | 2014-04-25 13:58:37 +0200 | [diff] [blame] | 2007 | curproxy->max_ka_queue = defproxy.max_ka_queue; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2008 | |
Willy Tarreau | aa2f389 | 2010-10-22 16:15:31 +0200 | [diff] [blame] | 2009 | if (defproxy.check_req) { |
| 2010 | curproxy->check_req = calloc(1, defproxy.check_len); |
| 2011 | memcpy(curproxy->check_req, defproxy.check_req, defproxy.check_len); |
| 2012 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2013 | curproxy->check_len = defproxy.check_len; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2014 | |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 2015 | if (defproxy.expect_str) { |
| 2016 | curproxy->expect_str = strdup(defproxy.expect_str); |
| 2017 | if (defproxy.expect_regex) { |
| 2018 | /* note: this regex is known to be valid */ |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 2019 | curproxy->expect_regex = calloc(1, sizeof(*curproxy->expect_regex)); |
| 2020 | regex_comp(defproxy.expect_str, curproxy->expect_regex, 1, 1, NULL); |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 2021 | } |
| 2022 | } |
| 2023 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2024 | curproxy->ck_opts = defproxy.ck_opts; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2025 | if (defproxy.cookie_name) |
| 2026 | curproxy->cookie_name = strdup(defproxy.cookie_name); |
| 2027 | curproxy->cookie_len = defproxy.cookie_len; |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 2028 | if (defproxy.cookie_domain) |
| 2029 | curproxy->cookie_domain = strdup(defproxy.cookie_domain); |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 2030 | |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 2031 | if (defproxy.cookie_maxidle) |
| 2032 | curproxy->cookie_maxidle = defproxy.cookie_maxidle; |
| 2033 | |
| 2034 | if (defproxy.cookie_maxlife) |
| 2035 | curproxy->cookie_maxlife = defproxy.cookie_maxlife; |
| 2036 | |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2037 | if (defproxy.rdp_cookie_name) |
| 2038 | curproxy->rdp_cookie_name = strdup(defproxy.rdp_cookie_name); |
| 2039 | curproxy->rdp_cookie_len = defproxy.rdp_cookie_len; |
| 2040 | |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 2041 | if (defproxy.url_param_name) |
| 2042 | curproxy->url_param_name = strdup(defproxy.url_param_name); |
| 2043 | curproxy->url_param_len = defproxy.url_param_len; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 2044 | |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 2045 | if (defproxy.hh_name) |
| 2046 | curproxy->hh_name = strdup(defproxy.hh_name); |
| 2047 | curproxy->hh_len = defproxy.hh_len; |
| 2048 | curproxy->hh_match_domain = defproxy.hh_match_domain; |
| 2049 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 2050 | if (defproxy.conn_src.iface_name) |
| 2051 | curproxy->conn_src.iface_name = strdup(defproxy.conn_src.iface_name); |
| 2052 | curproxy->conn_src.iface_len = defproxy.conn_src.iface_len; |
Godbach | 9f04853 | 2013-04-23 15:27:57 +0800 | [diff] [blame] | 2053 | curproxy->conn_src.opts = defproxy.conn_src.opts; |
Pieter Baauw | d551fb5 | 2013-05-08 22:49:23 +0200 | [diff] [blame] | 2054 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_TRANSPARENT) |
Godbach | 9f04853 | 2013-04-23 15:27:57 +0800 | [diff] [blame] | 2055 | curproxy->conn_src.tproxy_addr = defproxy.conn_src.tproxy_addr; |
Willy Tarreau | c621d36 | 2013-04-25 17:35:22 +0200 | [diff] [blame] | 2056 | #endif |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2057 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2058 | |
Willy Tarreau | 3b6b1a9 | 2009-07-23 13:24:23 +0200 | [diff] [blame] | 2059 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2060 | if (defproxy.capture_name) |
| 2061 | curproxy->capture_name = strdup(defproxy.capture_name); |
| 2062 | curproxy->capture_namelen = defproxy.capture_namelen; |
| 2063 | curproxy->capture_len = defproxy.capture_len; |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 2064 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2065 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2066 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 2067 | curproxy->timeout.client = defproxy.timeout.client; |
Simone Gotti | 1b48cc9 | 2014-06-11 12:25:28 +0200 | [diff] [blame] | 2068 | curproxy->timeout.clientfin = defproxy.timeout.clientfin; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 2069 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | 036fae0 | 2008-01-06 13:24:40 +0100 | [diff] [blame] | 2070 | curproxy->timeout.httpreq = defproxy.timeout.httpreq; |
Willy Tarreau | b16a574 | 2010-01-10 14:46:16 +0100 | [diff] [blame] | 2071 | curproxy->timeout.httpka = defproxy.timeout.httpka; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2072 | curproxy->mon_net = defproxy.mon_net; |
| 2073 | curproxy->mon_mask = defproxy.mon_mask; |
| 2074 | if (defproxy.monitor_uri) |
| 2075 | curproxy->monitor_uri = strdup(defproxy.monitor_uri); |
| 2076 | curproxy->monitor_uri_len = defproxy.monitor_uri_len; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 2077 | if (defproxy.defbe.name) |
| 2078 | curproxy->defbe.name = strdup(defproxy.defbe.name); |
Willy Tarreau | 99a7ca2 | 2012-05-31 19:39:23 +0200 | [diff] [blame] | 2079 | |
| 2080 | /* 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] | 2081 | curproxy->conf.logformat_string = defproxy.conf.logformat_string; |
| 2082 | if (curproxy->conf.logformat_string && |
| 2083 | curproxy->conf.logformat_string != default_http_log_format && |
| 2084 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 2085 | curproxy->conf.logformat_string != clf_http_log_format) |
| 2086 | curproxy->conf.logformat_string = strdup(curproxy->conf.logformat_string); |
| 2087 | |
| 2088 | if (defproxy.conf.lfs_file) { |
| 2089 | curproxy->conf.lfs_file = strdup(defproxy.conf.lfs_file); |
| 2090 | curproxy->conf.lfs_line = defproxy.conf.lfs_line; |
| 2091 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2092 | } |
| 2093 | |
| 2094 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 2095 | curproxy->timeout.connect = defproxy.timeout.connect; |
| 2096 | curproxy->timeout.server = defproxy.timeout.server; |
Simone Gotti | 1b48cc9 | 2014-06-11 12:25:28 +0200 | [diff] [blame] | 2097 | curproxy->timeout.serverfin = defproxy.timeout.serverfin; |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 2098 | curproxy->timeout.check = defproxy.timeout.check; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 2099 | curproxy->timeout.queue = defproxy.timeout.queue; |
Willy Tarreau | 51c9bde | 2008-01-06 13:40:03 +0100 | [diff] [blame] | 2100 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | cd7afc0 | 2009-07-12 10:03:17 +0200 | [diff] [blame] | 2101 | curproxy->timeout.httpreq = defproxy.timeout.httpreq; |
Willy Tarreau | b16a574 | 2010-01-10 14:46:16 +0100 | [diff] [blame] | 2102 | curproxy->timeout.httpka = defproxy.timeout.httpka; |
Willy Tarreau | ce887fd | 2012-05-12 12:50:00 +0200 | [diff] [blame] | 2103 | curproxy->timeout.tunnel = defproxy.timeout.tunnel; |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 2104 | curproxy->conn_src.source_addr = defproxy.conn_src.source_addr; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2105 | } |
| 2106 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2107 | curproxy->mode = defproxy.mode; |
Willy Tarreau | ed2119c | 2014-04-24 22:10:39 +0200 | [diff] [blame] | 2108 | curproxy->uri_auth = defproxy.uri_auth; /* for stats */ |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 2109 | |
| 2110 | /* copy default logsrvs to curproxy */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 2111 | list_for_each_entry(tmplogsrv, &defproxy.logsrvs, list) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 2112 | struct logsrv *node = malloc(sizeof(struct logsrv)); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 2113 | memcpy(node, tmplogsrv, sizeof(struct logsrv)); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 2114 | LIST_INIT(&node->list); |
| 2115 | LIST_ADDQ(&curproxy->logsrvs, &node->list); |
| 2116 | } |
| 2117 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 2118 | curproxy->conf.uniqueid_format_string = defproxy.conf.uniqueid_format_string; |
| 2119 | if (curproxy->conf.uniqueid_format_string) |
| 2120 | curproxy->conf.uniqueid_format_string = strdup(curproxy->conf.uniqueid_format_string); |
| 2121 | |
| 2122 | if (defproxy.conf.uif_file) { |
| 2123 | curproxy->conf.uif_file = strdup(defproxy.conf.uif_file); |
| 2124 | curproxy->conf.uif_line = defproxy.conf.uif_line; |
| 2125 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 2126 | |
| 2127 | /* copy default header unique id */ |
| 2128 | if (defproxy.header_unique_id) |
| 2129 | curproxy->header_unique_id = strdup(defproxy.header_unique_id); |
| 2130 | |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 2131 | /* default compression options */ |
| 2132 | if (defproxy.comp != NULL) { |
| 2133 | curproxy->comp = calloc(1, sizeof(struct comp)); |
| 2134 | curproxy->comp->algos = defproxy.comp->algos; |
| 2135 | curproxy->comp->types = defproxy.comp->types; |
| 2136 | } |
| 2137 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2138 | curproxy->grace = defproxy.grace; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2139 | curproxy->conf.used_listener_id = EB_ROOT; |
| 2140 | curproxy->conf.used_server_id = EB_ROOT; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2141 | |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 2142 | if (defproxy.check_path) |
| 2143 | curproxy->check_path = strdup(defproxy.check_path); |
| 2144 | if (defproxy.check_command) |
| 2145 | curproxy->check_command = strdup(defproxy.check_command); |
| 2146 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2147 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2148 | } |
| 2149 | else if (!strcmp(args[0], "defaults")) { /* use this one to assign default values */ |
| 2150 | /* some variables may have already been initialized earlier */ |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 2151 | /* FIXME-20070101: we should do this too at the end of the |
| 2152 | * config parsing to free all default values. |
| 2153 | */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2154 | free(defproxy.check_req); |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 2155 | free(defproxy.check_command); |
| 2156 | free(defproxy.check_path); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2157 | free(defproxy.cookie_name); |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2158 | free(defproxy.rdp_cookie_name); |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 2159 | free(defproxy.cookie_domain); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2160 | free(defproxy.url_param_name); |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 2161 | free(defproxy.hh_name); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2162 | free(defproxy.capture_name); |
| 2163 | free(defproxy.monitor_uri); |
| 2164 | free(defproxy.defbe.name); |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 2165 | free(defproxy.conn_src.iface_name); |
Willy Tarreau | 79f5fe8 | 2008-08-23 08:18:21 +0200 | [diff] [blame] | 2166 | free(defproxy.fwdfor_hdr_name); |
| 2167 | defproxy.fwdfor_hdr_len = 0; |
Willy Tarreau | b86db34 | 2009-11-30 11:50:16 +0100 | [diff] [blame] | 2168 | free(defproxy.orgto_hdr_name); |
| 2169 | defproxy.orgto_hdr_len = 0; |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 2170 | free(defproxy.server_id_hdr_name); |
| 2171 | defproxy.server_id_hdr_len = 0; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 2172 | free(defproxy.expect_str); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 2173 | if (defproxy.expect_regex) { |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 2174 | regex_free(defproxy.expect_regex); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 2175 | free(defproxy.expect_regex); |
| 2176 | defproxy.expect_regex = NULL; |
| 2177 | } |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 2178 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 2179 | if (defproxy.conf.logformat_string != default_http_log_format && |
| 2180 | defproxy.conf.logformat_string != default_tcp_log_format && |
| 2181 | defproxy.conf.logformat_string != clf_http_log_format) |
| 2182 | free(defproxy.conf.logformat_string); |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 2183 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 2184 | free(defproxy.conf.uniqueid_format_string); |
| 2185 | free(defproxy.conf.lfs_file); |
| 2186 | free(defproxy.conf.uif_file); |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 2187 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2188 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2189 | chunk_destroy(&defproxy.errmsg[rc]); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 2190 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2191 | /* we cannot free uri_auth because it might already be used */ |
| 2192 | init_default_instance(); |
| 2193 | curproxy = &defproxy; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 2194 | curproxy->conf.args.file = curproxy->conf.file = strdup(file); |
| 2195 | curproxy->conf.args.line = curproxy->conf.line = linenum; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2196 | defproxy.cap = PR_CAP_LISTEN; /* all caps for now */ |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2197 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2198 | } |
| 2199 | else if (curproxy == NULL) { |
| 2200 | Alert("parsing [%s:%d] : 'listen' or 'defaults' expected.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2201 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2202 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2203 | } |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 2204 | |
| 2205 | /* update the current file and line being parsed */ |
| 2206 | curproxy->conf.args.file = curproxy->conf.file; |
| 2207 | curproxy->conf.args.line = linenum; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2208 | |
| 2209 | /* Now let's parse the proxy-specific keywords */ |
Willy Tarreau | 272adea | 2014-03-31 10:39:59 +0200 | [diff] [blame] | 2210 | if (!strcmp(args[0], "server") || !strcmp(args[0], "default-server")) { |
| 2211 | err_code |= parse_server(file, linenum, args, curproxy, &defproxy); |
| 2212 | if (err_code & ERR_FATAL) |
| 2213 | goto out; |
| 2214 | } |
| 2215 | else if (!strcmp(args[0], "bind")) { /* new listen addresses */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2216 | struct listener *l; |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 2217 | int cur_arg; |
| 2218 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2219 | if (curproxy == &defproxy) { |
| 2220 | 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] | 2221 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2222 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2223 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2224 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2225 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2226 | |
Willy Tarreau | 2470928 | 2013-03-10 21:32:12 +0100 | [diff] [blame] | 2227 | if (!*(args[1])) { |
Willy Tarreau | d55c3fe | 2010-11-09 09:50:37 +0100 | [diff] [blame] | 2228 | 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] | 2229 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2230 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2231 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2232 | } |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 2233 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 2234 | bind_conf = bind_conf_alloc(&curproxy->conf.bind, file, linenum, args[1]); |
Willy Tarreau | 8dc21fa | 2013-01-24 15:17:20 +0100 | [diff] [blame] | 2235 | |
| 2236 | /* use default settings for unix sockets */ |
| 2237 | bind_conf->ux.uid = global.unix_bind.ux.uid; |
| 2238 | bind_conf->ux.gid = global.unix_bind.ux.gid; |
| 2239 | bind_conf->ux.mode = global.unix_bind.ux.mode; |
Willy Tarreau | 8a95691 | 2010-10-15 14:27:08 +0200 | [diff] [blame] | 2240 | |
| 2241 | /* NOTE: the following line might create several listeners if there |
| 2242 | * are comma-separated IPs or port ranges. So all further processing |
| 2243 | * will have to be applied to all listeners created after last_listen. |
| 2244 | */ |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 2245 | if (!str2listener(args[1], curproxy, bind_conf, file, linenum, &errmsg)) { |
| 2246 | if (errmsg && *errmsg) { |
| 2247 | indent_msg(&errmsg, 2); |
| 2248 | Alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 2249 | } |
| 2250 | else |
| 2251 | Alert("parsing [%s:%d] : '%s' : error encountered while parsing listening address '%s'.\n", |
| 2252 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2253 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2254 | goto out; |
| 2255 | } |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 2256 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2257 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
| 2258 | /* Set default global rights and owner for unix bind */ |
Willy Tarreau | c8b1109 | 2011-02-16 11:08:57 +0100 | [diff] [blame] | 2259 | global.maxsock++; |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 2260 | } |
| 2261 | |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 2262 | cur_arg = 2; |
| 2263 | while (*(args[cur_arg])) { |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 2264 | static int bind_dumped; |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 2265 | struct bind_kw *kw; |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 2266 | char *err; |
| 2267 | |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 2268 | kw = bind_find_kw(args[cur_arg]); |
| 2269 | if (kw) { |
| 2270 | char *err = NULL; |
| 2271 | int code; |
| 2272 | |
| 2273 | if (!kw->parse) { |
Willy Tarreau | dda322d | 2012-09-18 16:34:09 +0200 | [diff] [blame] | 2274 | Alert("parsing [%s:%d] : '%s %s' : '%s' option is not implemented in this version (check build options).\n", |
| 2275 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 2276 | cur_arg += 1 + kw->skip ; |
| 2277 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2278 | goto out; |
| 2279 | } |
| 2280 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2281 | code = kw->parse(args, cur_arg, curproxy, bind_conf, &err); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 2282 | err_code |= code; |
| 2283 | |
| 2284 | if (code) { |
| 2285 | if (err && *err) { |
| 2286 | indent_msg(&err, 2); |
Willy Tarreau | dda322d | 2012-09-18 16:34:09 +0200 | [diff] [blame] | 2287 | 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] | 2288 | } |
| 2289 | else |
Willy Tarreau | dda322d | 2012-09-18 16:34:09 +0200 | [diff] [blame] | 2290 | Alert("parsing [%s:%d] : '%s %s' : error encountered while processing '%s'.\n", |
| 2291 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 2292 | if (code & ERR_FATAL) { |
| 2293 | free(err); |
| 2294 | cur_arg += 1 + kw->skip; |
| 2295 | goto out; |
| 2296 | } |
| 2297 | } |
| 2298 | free(err); |
| 2299 | cur_arg += 1 + kw->skip; |
| 2300 | continue; |
| 2301 | } |
| 2302 | |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 2303 | err = NULL; |
| 2304 | if (!bind_dumped) { |
| 2305 | bind_dump_kws(&err); |
| 2306 | indent_msg(&err, 4); |
| 2307 | bind_dumped = 1; |
| 2308 | } |
| 2309 | |
| 2310 | Alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'.%s%s\n", |
| 2311 | file, linenum, args[0], args[1], args[cur_arg], |
| 2312 | err ? " Registered keywords :" : "", err ? err : ""); |
| 2313 | free(err); |
| 2314 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2315 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2316 | goto out; |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 2317 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2318 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2319 | } |
| 2320 | 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] | 2321 | 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] | 2322 | Alert("parsing [%s:%d] : '%s' expects address[/mask].\n", |
| 2323 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2324 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2325 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2326 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2327 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2328 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2329 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2330 | /* flush useless bits */ |
| 2331 | curproxy->mon_net.s_addr &= curproxy->mon_mask.s_addr; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2332 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2333 | } |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2334 | else if (!strcmp(args[0], "monitor-uri")) { /* set the URI to intercept */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2335 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2336 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2337 | |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2338 | if (!*args[1]) { |
| 2339 | Alert("parsing [%s:%d] : '%s' expects an URI.\n", |
| 2340 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2341 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2342 | goto out; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2343 | } |
| 2344 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2345 | free(curproxy->monitor_uri); |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 2346 | curproxy->monitor_uri_len = strlen(args[1]); |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2347 | curproxy->monitor_uri = (char *)calloc(1, curproxy->monitor_uri_len + 1); |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 2348 | memcpy(curproxy->monitor_uri, args[1], curproxy->monitor_uri_len); |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2349 | curproxy->monitor_uri[curproxy->monitor_uri_len] = '\0'; |
| 2350 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2351 | goto out; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2352 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2353 | else if (!strcmp(args[0], "mode")) { /* sets the proxy mode */ |
| 2354 | if (!strcmp(args[1], "http")) curproxy->mode = PR_MODE_HTTP; |
| 2355 | else if (!strcmp(args[1], "tcp")) curproxy->mode = PR_MODE_TCP; |
| 2356 | else if (!strcmp(args[1], "health")) curproxy->mode = PR_MODE_HEALTH; |
| 2357 | else { |
| 2358 | 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] | 2359 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2360 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2361 | } |
| 2362 | } |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2363 | else if (!strcmp(args[0], "id")) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2364 | struct eb32_node *node; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2365 | |
| 2366 | if (curproxy == &defproxy) { |
| 2367 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\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; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2371 | } |
| 2372 | |
| 2373 | if (!*args[1]) { |
| 2374 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 2375 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2376 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2377 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2378 | } |
| 2379 | |
| 2380 | curproxy->uuid = atol(args[1]); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2381 | curproxy->conf.id.key = curproxy->uuid; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2382 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2383 | if (curproxy->uuid <= 0) { |
| 2384 | Alert("parsing [%s:%d]: custom id has to be > 0.\n", |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2385 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2386 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2387 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2388 | } |
| 2389 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2390 | node = eb32_lookup(&used_proxy_id, curproxy->uuid); |
| 2391 | if (node) { |
| 2392 | struct proxy *target = container_of(node, struct proxy, conf.id); |
| 2393 | Alert("parsing [%s:%d]: %s %s reuses same custom id as %s %s (declared at %s:%d).\n", |
| 2394 | file, linenum, proxy_type_str(curproxy), curproxy->id, |
| 2395 | proxy_type_str(target), target->id, target->conf.file, target->conf.line); |
| 2396 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2397 | goto out; |
| 2398 | } |
| 2399 | eb32_insert(&used_proxy_id, &curproxy->conf.id); |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2400 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 2401 | else if (!strcmp(args[0], "description")) { |
| 2402 | int i, len=0; |
| 2403 | char *d; |
| 2404 | |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 2405 | if (curproxy == &defproxy) { |
| 2406 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", |
| 2407 | file, linenum, args[0]); |
| 2408 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2409 | goto out; |
| 2410 | } |
| 2411 | |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 2412 | if (!*args[1]) { |
| 2413 | Alert("parsing [%s:%d]: '%s' expects a string argument.\n", |
| 2414 | file, linenum, args[0]); |
| 2415 | return -1; |
| 2416 | } |
| 2417 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 2418 | for (i = 1; *args[i]; i++) |
| 2419 | len += strlen(args[i]) + 1; |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 2420 | |
| 2421 | d = (char *)calloc(1, len); |
| 2422 | curproxy->desc = d; |
| 2423 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 2424 | d += snprintf(d, curproxy->desc + len - d, "%s", args[1]); |
| 2425 | for (i = 2; *args[i]; i++) |
| 2426 | d += snprintf(d, curproxy->desc + len - d, " %s", args[i]); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 2427 | |
| 2428 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2429 | else if (!strcmp(args[0], "disabled")) { /* disables this proxy */ |
| 2430 | curproxy->state = PR_STSTOPPED; |
| 2431 | } |
| 2432 | else if (!strcmp(args[0], "enabled")) { /* enables this proxy (used to revert a disabled default) */ |
| 2433 | curproxy->state = PR_STNEW; |
| 2434 | } |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2435 | else if (!strcmp(args[0], "bind-process")) { /* enable this proxy only on some processes */ |
| 2436 | int cur_arg = 1; |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 2437 | unsigned long set = 0; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2438 | |
| 2439 | while (*args[cur_arg]) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 2440 | unsigned int low, high; |
| 2441 | |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2442 | if (strcmp(args[cur_arg], "all") == 0) { |
| 2443 | set = 0; |
| 2444 | break; |
| 2445 | } |
| 2446 | else if (strcmp(args[cur_arg], "odd") == 0) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 2447 | set |= ~0UL/3UL; /* 0x555....555 */ |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2448 | } |
| 2449 | else if (strcmp(args[cur_arg], "even") == 0) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 2450 | set |= (~0UL/3UL) << 1; /* 0xAAA...AAA */ |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2451 | } |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 2452 | else if (isdigit((int)*args[cur_arg])) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 2453 | char *dash = strchr(args[cur_arg], '-'); |
| 2454 | |
| 2455 | low = high = str2uic(args[cur_arg]); |
| 2456 | if (dash) |
| 2457 | high = str2uic(dash + 1); |
| 2458 | |
| 2459 | if (high < low) { |
| 2460 | unsigned int swap = low; |
| 2461 | low = high; |
| 2462 | high = swap; |
| 2463 | } |
| 2464 | |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 2465 | if (low < 1 || high > LONGBITS) { |
| 2466 | Alert("parsing [%s:%d]: %s supports process numbers from 1 to %d.\n", |
| 2467 | file, linenum, args[0], LONGBITS); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2468 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2469 | goto out; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2470 | } |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 2471 | while (low <= high) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 2472 | set |= 1UL << (low++ - 1); |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 2473 | } |
| 2474 | else { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 2475 | Alert("parsing [%s:%d]: %s expects 'all', 'odd', 'even', or a list of process ranges with numbers from 1 to %d.\n", |
| 2476 | file, linenum, args[0], LONGBITS); |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 2477 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2478 | goto out; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2479 | } |
| 2480 | cur_arg++; |
| 2481 | } |
| 2482 | curproxy->bind_proc = set; |
| 2483 | } |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 2484 | else if (!strcmp(args[0], "acl")) { /* add an ACL */ |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2485 | if (curproxy == &defproxy) { |
| 2486 | 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] | 2487 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2488 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2489 | } |
| 2490 | |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 2491 | err = invalid_char(args[1]); |
| 2492 | if (err) { |
| 2493 | Alert("parsing [%s:%d] : character '%c' is not permitted in acl name '%s'.\n", |
| 2494 | file, linenum, *err, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2495 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 2496 | } |
| 2497 | |
Thierry FOURNIER | 0d6ba51 | 2014-02-11 03:31:34 +0100 | [diff] [blame] | 2498 | 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] | 2499 | Alert("parsing [%s:%d] : error detected while parsing ACL '%s' : %s.\n", |
| 2500 | file, linenum, args[1], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2501 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2502 | goto out; |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 2503 | } |
| 2504 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2505 | else if (!strcmp(args[0], "cookie")) { /* cookie name */ |
| 2506 | int cur_arg; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2507 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2508 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2509 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2510 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2511 | if (*(args[1]) == 0) { |
| 2512 | Alert("parsing [%s:%d] : '%s' expects <cookie_name> as argument.\n", |
| 2513 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2514 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2515 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2516 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2517 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2518 | curproxy->ck_opts = 0; |
Willy Tarreau | c63d4bb | 2010-10-23 11:37:27 +0200 | [diff] [blame] | 2519 | curproxy->cookie_maxidle = curproxy->cookie_maxlife = 0; |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 2520 | free(curproxy->cookie_domain); curproxy->cookie_domain = NULL; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2521 | free(curproxy->cookie_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2522 | curproxy->cookie_name = strdup(args[1]); |
| 2523 | curproxy->cookie_len = strlen(curproxy->cookie_name); |
Willy Tarreau | c63d4bb | 2010-10-23 11:37:27 +0200 | [diff] [blame] | 2524 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2525 | cur_arg = 2; |
| 2526 | while (*(args[cur_arg])) { |
| 2527 | if (!strcmp(args[cur_arg], "rewrite")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2528 | curproxy->ck_opts |= PR_CK_RW; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2529 | } |
| 2530 | else if (!strcmp(args[cur_arg], "indirect")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2531 | curproxy->ck_opts |= PR_CK_IND; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2532 | } |
| 2533 | else if (!strcmp(args[cur_arg], "insert")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2534 | curproxy->ck_opts |= PR_CK_INS; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2535 | } |
| 2536 | else if (!strcmp(args[cur_arg], "nocache")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2537 | curproxy->ck_opts |= PR_CK_NOC; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2538 | } |
| 2539 | else if (!strcmp(args[cur_arg], "postonly")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2540 | curproxy->ck_opts |= PR_CK_POST; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2541 | } |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 2542 | else if (!strcmp(args[cur_arg], "preserve")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2543 | curproxy->ck_opts |= PR_CK_PSV; |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 2544 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2545 | else if (!strcmp(args[cur_arg], "prefix")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2546 | curproxy->ck_opts |= PR_CK_PFX; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2547 | } |
Willy Tarreau | 4992dd2 | 2012-05-31 21:02:17 +0200 | [diff] [blame] | 2548 | else if (!strcmp(args[cur_arg], "httponly")) { |
| 2549 | curproxy->ck_opts |= PR_CK_HTTPONLY; |
| 2550 | } |
| 2551 | else if (!strcmp(args[cur_arg], "secure")) { |
| 2552 | curproxy->ck_opts |= PR_CK_SECURE; |
| 2553 | } |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2554 | else if (!strcmp(args[cur_arg], "domain")) { |
| 2555 | if (!*args[cur_arg + 1]) { |
| 2556 | Alert("parsing [%s:%d]: '%s' expects <domain> as argument.\n", |
| 2557 | file, linenum, args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2558 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2559 | goto out; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2560 | } |
| 2561 | |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 2562 | if (*args[cur_arg + 1] != '.' || !strchr(args[cur_arg + 1] + 1, '.')) { |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2563 | /* rfc2109, 4.3.2 Rejecting Cookies */ |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 2564 | Warning("parsing [%s:%d]: domain '%s' contains no embedded" |
| 2565 | " dots nor does not start with a dot." |
| 2566 | " RFC forbids it, this configuration may not work properly.\n", |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2567 | file, linenum, args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 2568 | err_code |= ERR_WARN; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2569 | } |
| 2570 | |
| 2571 | err = invalid_domainchar(args[cur_arg + 1]); |
| 2572 | if (err) { |
| 2573 | Alert("parsing [%s:%d]: character '%c' is not permitted in domain name '%s'.\n", |
| 2574 | file, linenum, *err, args[cur_arg + 1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2575 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2576 | goto out; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2577 | } |
| 2578 | |
Willy Tarreau | 68a897b | 2009-12-03 23:28:34 +0100 | [diff] [blame] | 2579 | if (!curproxy->cookie_domain) { |
| 2580 | curproxy->cookie_domain = strdup(args[cur_arg + 1]); |
| 2581 | } else { |
| 2582 | /* one domain was already specified, add another one by |
| 2583 | * building the string which will be returned along with |
| 2584 | * the cookie. |
| 2585 | */ |
| 2586 | char *new_ptr; |
| 2587 | int new_len = strlen(curproxy->cookie_domain) + |
| 2588 | strlen("; domain=") + strlen(args[cur_arg + 1]) + 1; |
| 2589 | new_ptr = malloc(new_len); |
| 2590 | snprintf(new_ptr, new_len, "%s; domain=%s", curproxy->cookie_domain, args[cur_arg+1]); |
| 2591 | free(curproxy->cookie_domain); |
| 2592 | curproxy->cookie_domain = new_ptr; |
| 2593 | } |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 2594 | cur_arg++; |
| 2595 | } |
| 2596 | else if (!strcmp(args[cur_arg], "maxidle")) { |
| 2597 | unsigned int maxidle; |
| 2598 | const char *res; |
| 2599 | |
| 2600 | if (!*args[cur_arg + 1]) { |
| 2601 | Alert("parsing [%s:%d]: '%s' expects <idletime> in seconds as argument.\n", |
| 2602 | file, linenum, args[cur_arg]); |
| 2603 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2604 | goto out; |
| 2605 | } |
| 2606 | |
| 2607 | res = parse_time_err(args[cur_arg + 1], &maxidle, TIME_UNIT_S); |
| 2608 | if (res) { |
| 2609 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 2610 | file, linenum, *res, args[cur_arg]); |
| 2611 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2612 | goto out; |
| 2613 | } |
| 2614 | curproxy->cookie_maxidle = maxidle; |
| 2615 | cur_arg++; |
| 2616 | } |
| 2617 | else if (!strcmp(args[cur_arg], "maxlife")) { |
| 2618 | unsigned int maxlife; |
| 2619 | const char *res; |
| 2620 | |
| 2621 | if (!*args[cur_arg + 1]) { |
| 2622 | Alert("parsing [%s:%d]: '%s' expects <lifetime> in seconds as argument.\n", |
| 2623 | file, linenum, args[cur_arg]); |
| 2624 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2625 | goto out; |
| 2626 | } |
| 2627 | |
| 2628 | res = parse_time_err(args[cur_arg + 1], &maxlife, TIME_UNIT_S); |
| 2629 | if (res) { |
| 2630 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 2631 | file, linenum, *res, args[cur_arg]); |
| 2632 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2633 | goto out; |
| 2634 | } |
| 2635 | curproxy->cookie_maxlife = maxlife; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2636 | cur_arg++; |
| 2637 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2638 | else { |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 2639 | 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] | 2640 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2641 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2642 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2643 | } |
| 2644 | cur_arg++; |
| 2645 | } |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2646 | if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_IND))) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2647 | Alert("parsing [%s:%d] : cookie 'rewrite' and 'indirect' modes are incompatible.\n", |
| 2648 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2649 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2650 | } |
| 2651 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2652 | 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] | 2653 | Alert("parsing [%s:%d] : cookie 'rewrite', 'insert' and 'prefix' modes are incompatible.\n", |
| 2654 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2655 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2656 | } |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 2657 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2658 | 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] | 2659 | Alert("parsing [%s:%d] : cookie 'preserve' requires at least 'insert' or 'indirect'.\n", |
| 2660 | file, linenum); |
| 2661 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2662 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2663 | }/* end else if (!strcmp(args[0], "cookie")) */ |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 2664 | else if (!strcmp(args[0], "external-check")) { |
| 2665 | if (*(args[1]) == 0) { |
| 2666 | Alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 2667 | file, linenum, args[0]); |
| 2668 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2669 | goto out; |
| 2670 | } |
| 2671 | |
| 2672 | if (!strcmp(args[1], "command")) { |
| 2673 | if (*(args[1]) == 0) { |
| 2674 | Alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 2675 | file, linenum, args[1]); |
| 2676 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2677 | goto out; |
| 2678 | } |
| 2679 | free(curproxy->check_command); |
| 2680 | curproxy->check_command = strdup(args[2]); |
| 2681 | } |
| 2682 | else if (!strcmp(args[1], "path")) { |
| 2683 | if (*(args[1]) == 0) { |
| 2684 | Alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 2685 | file, linenum, args[1]); |
| 2686 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2687 | goto out; |
| 2688 | } |
| 2689 | free(curproxy->check_path); |
| 2690 | curproxy->check_path = strdup(args[2]); |
| 2691 | } |
| 2692 | else { |
| 2693 | Alert("parsing [%s:%d] : external-check: unknown argument '%s'.\n", |
| 2694 | file, linenum, args[1]); |
| 2695 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2696 | goto out; |
| 2697 | } |
| 2698 | }/* end else if (!strcmp(args[0], "external-check")) */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2699 | else if (!strcmp(args[0], "persist")) { /* persist */ |
| 2700 | if (*(args[1]) == 0) { |
| 2701 | Alert("parsing [%s:%d] : missing persist method.\n", |
| 2702 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2703 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2704 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2705 | } |
| 2706 | |
| 2707 | if (!strncmp(args[1], "rdp-cookie", 10)) { |
| 2708 | curproxy->options2 |= PR_O2_RDPC_PRST; |
| 2709 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2710 | if (*(args[1] + 10) == '(') { /* cookie name */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2711 | const char *beg, *end; |
| 2712 | |
| 2713 | beg = args[1] + 11; |
| 2714 | end = strchr(beg, ')'); |
| 2715 | |
| 2716 | if (!end || end == beg) { |
| 2717 | Alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n", |
| 2718 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2719 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2720 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2721 | } |
| 2722 | |
| 2723 | free(curproxy->rdp_cookie_name); |
| 2724 | curproxy->rdp_cookie_name = my_strndup(beg, end - beg); |
| 2725 | curproxy->rdp_cookie_len = end-beg; |
| 2726 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2727 | else if (*(args[1] + 10) == '\0') { /* default cookie name 'msts' */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2728 | free(curproxy->rdp_cookie_name); |
| 2729 | curproxy->rdp_cookie_name = strdup("msts"); |
| 2730 | curproxy->rdp_cookie_len = strlen(curproxy->rdp_cookie_name); |
| 2731 | } |
| 2732 | else { /* syntax */ |
| 2733 | Alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\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 | } |
| 2739 | else { |
| 2740 | Alert("parsing [%s:%d] : unknown persist method.\n", |
| 2741 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2742 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2743 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2744 | } |
| 2745 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2746 | else if (!strcmp(args[0], "appsession")) { /* cookie name */ |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2747 | int cur_arg; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2748 | |
Cyril Bonté | 3b7a369 | 2010-01-10 17:01:47 +0100 | [diff] [blame] | 2749 | if (curproxy == &defproxy) { |
| 2750 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2751 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2752 | goto out; |
| 2753 | } |
| 2754 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2755 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2756 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2757 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2758 | if (*(args[5]) == 0) { |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2759 | 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] | 2760 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2761 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2762 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2763 | } |
| 2764 | have_appsession = 1; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2765 | free(curproxy->appsession_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2766 | curproxy->appsession_name = strdup(args[1]); |
| 2767 | curproxy->appsession_name_len = strlen(curproxy->appsession_name); |
| 2768 | curproxy->appsession_len = atoi(args[3]); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 2769 | err = parse_time_err(args[5], &val, TIME_UNIT_MS); |
| 2770 | if (err) { |
| 2771 | Alert("parsing [%s:%d] : unexpected character '%c' in %s timeout.\n", |
| 2772 | file, linenum, *err, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2773 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2774 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 2775 | } |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 2776 | curproxy->timeout.appsession = val; |
Willy Tarreau | ee99136 | 2007-05-14 14:37:50 +0200 | [diff] [blame] | 2777 | |
Willy Tarreau | 51041c7 | 2007-09-09 21:56:53 +0200 | [diff] [blame] | 2778 | if (appsession_hash_init(&(curproxy->htbl_proxy), destroy) == 0) { |
| 2779 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2780 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2781 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2782 | } |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2783 | |
| 2784 | cur_arg = 6; |
| 2785 | curproxy->options2 &= ~PR_O2_AS_REQL; |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2786 | curproxy->options2 &= ~PR_O2_AS_M_ANY; |
| 2787 | curproxy->options2 |= PR_O2_AS_M_PP; |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2788 | while (*(args[cur_arg])) { |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2789 | if (!strcmp(args[cur_arg], "request-learn")) { |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2790 | curproxy->options2 |= PR_O2_AS_REQL; |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2791 | } else if (!strcmp(args[cur_arg], "prefix")) { |
| 2792 | curproxy->options2 |= PR_O2_AS_PFX; |
| 2793 | } else if (!strcmp(args[cur_arg], "mode")) { |
| 2794 | if (!*args[cur_arg + 1]) { |
| 2795 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 2796 | file, linenum, args[0], args[cur_arg]); |
| 2797 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2798 | goto out; |
| 2799 | } |
| 2800 | |
| 2801 | cur_arg++; |
| 2802 | if (!strcmp(args[cur_arg], "query-string")) { |
| 2803 | curproxy->options2 &= ~PR_O2_AS_M_ANY; |
| 2804 | curproxy->options2 |= PR_O2_AS_M_QS; |
| 2805 | } else if (!strcmp(args[cur_arg], "path-parameters")) { |
| 2806 | curproxy->options2 &= ~PR_O2_AS_M_ANY; |
| 2807 | curproxy->options2 |= PR_O2_AS_M_PP; |
| 2808 | } else { |
| 2809 | Alert("parsing [%s:%d] : unknown mode '%s'\n", file, linenum, args[cur_arg]); |
| 2810 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2811 | goto out; |
| 2812 | } |
| 2813 | } |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2814 | cur_arg++; |
| 2815 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2816 | } /* Url App Session */ |
| 2817 | else if (!strcmp(args[0], "capture")) { |
Willy Tarreau | 3b6b1a9 | 2009-07-23 13:24:23 +0200 | [diff] [blame] | 2818 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2819 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2820 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2821 | if (!strcmp(args[1], "cookie")) { /* name of a cookie to capture */ |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 2822 | if (curproxy == &defproxy) { |
| 2823 | Alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
| 2824 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2825 | goto out; |
| 2826 | } |
| 2827 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2828 | if (*(args[4]) == 0) { |
| 2829 | Alert("parsing [%s:%d] : '%s' expects 'cookie' <cookie_name> 'len' <len>.\n", |
| 2830 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2831 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2832 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2833 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2834 | free(curproxy->capture_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2835 | curproxy->capture_name = strdup(args[2]); |
| 2836 | curproxy->capture_namelen = strlen(curproxy->capture_name); |
| 2837 | curproxy->capture_len = atol(args[4]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2838 | curproxy->to_log |= LW_COOKIE; |
| 2839 | } |
| 2840 | else if (!strcmp(args[1], "request") && !strcmp(args[2], "header")) { |
| 2841 | struct cap_hdr *hdr; |
| 2842 | |
| 2843 | if (curproxy == &defproxy) { |
| 2844 | 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] | 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 | if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) { |
| 2850 | Alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n", |
| 2851 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2852 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2853 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2854 | } |
| 2855 | |
| 2856 | hdr = calloc(sizeof(struct cap_hdr), 1); |
| 2857 | hdr->next = curproxy->req_cap; |
| 2858 | hdr->name = strdup(args[3]); |
| 2859 | hdr->namelen = strlen(args[3]); |
| 2860 | hdr->len = atol(args[5]); |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 2861 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2862 | hdr->index = curproxy->nb_req_cap++; |
| 2863 | curproxy->req_cap = hdr; |
| 2864 | curproxy->to_log |= LW_REQHDR; |
| 2865 | } |
| 2866 | else if (!strcmp(args[1], "response") && !strcmp(args[2], "header")) { |
| 2867 | struct cap_hdr *hdr; |
| 2868 | |
| 2869 | if (curproxy == &defproxy) { |
| 2870 | 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] | 2871 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2872 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2873 | } |
| 2874 | |
| 2875 | if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) { |
| 2876 | Alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n", |
| 2877 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2878 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2879 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2880 | } |
| 2881 | hdr = calloc(sizeof(struct cap_hdr), 1); |
| 2882 | hdr->next = curproxy->rsp_cap; |
| 2883 | hdr->name = strdup(args[3]); |
| 2884 | hdr->namelen = strlen(args[3]); |
| 2885 | hdr->len = atol(args[5]); |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 2886 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2887 | hdr->index = curproxy->nb_rsp_cap++; |
| 2888 | curproxy->rsp_cap = hdr; |
| 2889 | curproxy->to_log |= LW_RSPHDR; |
| 2890 | } |
| 2891 | else { |
| 2892 | Alert("parsing [%s:%d] : '%s' expects 'cookie' or 'request header' or 'response header'.\n", |
| 2893 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2894 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2895 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2896 | } |
| 2897 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2898 | else if (!strcmp(args[0], "retries")) { /* connection retries */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2899 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2900 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2901 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2902 | if (*(args[1]) == 0) { |
| 2903 | Alert("parsing [%s:%d] : '%s' expects an integer argument (dispatch counts for one).\n", |
| 2904 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2905 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2906 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2907 | } |
| 2908 | curproxy->conn_retries = atol(args[1]); |
| 2909 | } |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2910 | 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] | 2911 | struct http_req_rule *rule; |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2912 | |
| 2913 | if (curproxy == &defproxy) { |
| 2914 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2915 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2916 | goto out; |
| 2917 | } |
| 2918 | |
Willy Tarreau | 20b0de5 | 2012-12-24 15:45:22 +0100 | [diff] [blame] | 2919 | if (!LIST_ISEMPTY(&curproxy->http_req_rules) && |
| 2920 | !LIST_PREV(&curproxy->http_req_rules, struct http_req_rule *, list)->cond && |
| 2921 | (LIST_PREV(&curproxy->http_req_rules, struct http_req_rule *, list)->action == HTTP_REQ_ACT_ALLOW || |
| 2922 | 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] | 2923 | 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] | 2924 | LIST_PREV(&curproxy->http_req_rules, struct http_req_rule *, list)->action == HTTP_REQ_ACT_AUTH)) { |
| 2925 | 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] | 2926 | file, linenum, args[0]); |
| 2927 | err_code |= ERR_WARN; |
| 2928 | } |
| 2929 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 2930 | 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] | 2931 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 2932 | if (!rule) { |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2933 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2934 | goto out; |
| 2935 | } |
| 2936 | |
Willy Tarreau | 5002f57 | 2014-04-23 01:32:02 +0200 | [diff] [blame] | 2937 | err_code |= warnif_misplaced_http_req(curproxy, file, linenum, args[0]); |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 2938 | err_code |= warnif_cond_conflicts(rule->cond, |
| 2939 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 2940 | file, linenum); |
| 2941 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 2942 | LIST_ADDQ(&curproxy->http_req_rules, &rule->list); |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2943 | } |
Willy Tarreau | e365c0b | 2013-06-11 16:06:12 +0200 | [diff] [blame] | 2944 | else if (!strcmp(args[0], "http-response")) { /* response access control */ |
| 2945 | struct http_res_rule *rule; |
| 2946 | |
| 2947 | if (curproxy == &defproxy) { |
| 2948 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2949 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2950 | goto out; |
| 2951 | } |
| 2952 | |
| 2953 | if (!LIST_ISEMPTY(&curproxy->http_res_rules) && |
| 2954 | !LIST_PREV(&curproxy->http_res_rules, struct http_res_rule *, list)->cond && |
| 2955 | (LIST_PREV(&curproxy->http_res_rules, struct http_res_rule *, list)->action == HTTP_RES_ACT_ALLOW || |
| 2956 | LIST_PREV(&curproxy->http_res_rules, struct http_res_rule *, list)->action == HTTP_RES_ACT_DENY)) { |
| 2957 | Warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n", |
| 2958 | file, linenum, args[0]); |
| 2959 | err_code |= ERR_WARN; |
| 2960 | } |
| 2961 | |
| 2962 | rule = parse_http_res_cond((const char **)args + 1, file, linenum, curproxy); |
| 2963 | |
| 2964 | if (!rule) { |
| 2965 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2966 | goto out; |
| 2967 | } |
| 2968 | |
| 2969 | err_code |= warnif_cond_conflicts(rule->cond, |
| 2970 | (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR, |
| 2971 | file, linenum); |
| 2972 | |
| 2973 | LIST_ADDQ(&curproxy->http_res_rules, &rule->list); |
| 2974 | } |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 2975 | else if (!strcmp(args[0], "http-send-name-header")) { /* send server name in request header */ |
| 2976 | /* set the header name and length into the proxy structure */ |
| 2977 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 2978 | err_code |= ERR_WARN; |
| 2979 | |
| 2980 | if (!*args[1]) { |
| 2981 | Alert("parsing [%s:%d] : '%s' requires a header string.\n", |
| 2982 | file, linenum, args[0]); |
| 2983 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2984 | goto out; |
| 2985 | } |
| 2986 | |
| 2987 | /* set the desired header name */ |
| 2988 | free(curproxy->server_id_hdr_name); |
| 2989 | curproxy->server_id_hdr_name = strdup(args[1]); |
| 2990 | curproxy->server_id_hdr_len = strlen(curproxy->server_id_hdr_name); |
| 2991 | } |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2992 | else if (!strcmp(args[0], "block")) { /* early blocking based on ACLs */ |
Willy Tarreau | b3dc39d | 2014-04-28 22:06:57 +0200 | [diff] [blame] | 2993 | struct http_req_rule *rule; |
| 2994 | |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2995 | if (curproxy == &defproxy) { |
| 2996 | 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] | 2997 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2998 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2999 | } |
| 3000 | |
Willy Tarreau | b3dc39d | 2014-04-28 22:06:57 +0200 | [diff] [blame] | 3001 | /* emulate "block" using "http-request block". Since these rules are supposed to |
| 3002 | * be processed before all http-request rules, we put them into their own list |
| 3003 | * and will insert them at the end. |
| 3004 | */ |
| 3005 | rule = parse_http_req_cond((const char **)args, file, linenum, curproxy); |
| 3006 | if (!rule) { |
| 3007 | err_code |= ERR_ALERT | ERR_ABORT; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3008 | goto out; |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 3009 | } |
Willy Tarreau | b3dc39d | 2014-04-28 22:06:57 +0200 | [diff] [blame] | 3010 | err_code |= warnif_misplaced_block(curproxy, file, linenum, args[0]); |
| 3011 | err_code |= warnif_cond_conflicts(rule->cond, |
| 3012 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 3013 | file, linenum); |
| 3014 | LIST_ADDQ(&curproxy->block_rules, &rule->list); |
Willy Tarreau | de9d2d7 | 2014-04-28 22:28:02 +0200 | [diff] [blame] | 3015 | |
| 3016 | if (!already_warned(WARN_BLOCK_DEPRECATED)) |
| 3017 | 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]); |
| 3018 | |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 3019 | } |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3020 | else if (!strcmp(args[0], "redirect")) { |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3021 | struct redirect_rule *rule; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3022 | |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 3023 | if (curproxy == &defproxy) { |
| 3024 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3025 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3026 | goto out; |
| 3027 | } |
| 3028 | |
Thierry FOURNIER | d18cd0f | 2013-11-29 12:15:45 +0100 | [diff] [blame] | 3029 | 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] | 3030 | Alert("parsing [%s:%d] : error detected in %s '%s' while parsing redirect rule : %s.\n", |
| 3031 | file, linenum, proxy_type_str(curproxy), curproxy->id, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3032 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3033 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3034 | } |
| 3035 | |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3036 | LIST_ADDQ(&curproxy->redirect_rules, &rule->list); |
Willy Tarreau | ee445d9 | 2014-04-23 01:39:04 +0200 | [diff] [blame] | 3037 | err_code |= warnif_misplaced_redirect(curproxy, file, linenum, args[0]); |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3038 | err_code |= warnif_cond_conflicts(rule->cond, |
| 3039 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 3040 | file, linenum); |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3041 | } |
Krzysztof Piotr Oledzki | 7b723ef | 2009-01-27 21:09:41 +0100 | [diff] [blame] | 3042 | else if (!strcmp(args[0], "use_backend")) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3043 | struct switching_rule *rule; |
| 3044 | |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3045 | if (curproxy == &defproxy) { |
| 3046 | 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] | 3047 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3048 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3049 | } |
| 3050 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3051 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3052 | err_code |= ERR_WARN; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3053 | |
| 3054 | if (*(args[1]) == 0) { |
| 3055 | 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] | 3056 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3057 | goto out; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3058 | } |
| 3059 | |
Willy Tarreau | f51658d | 2014-04-23 01:21:56 +0200 | [diff] [blame] | 3060 | if (strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0) { |
| 3061 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 3062 | Alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n", |
| 3063 | file, linenum, errmsg); |
| 3064 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3065 | goto out; |
| 3066 | } |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3067 | |
Willy Tarreau | f51658d | 2014-04-23 01:21:56 +0200 | [diff] [blame] | 3068 | 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] | 3069 | } |
| 3070 | |
| 3071 | rule = (struct switching_rule *)calloc(1, sizeof(*rule)); |
| 3072 | rule->cond = cond; |
| 3073 | rule->be.name = strdup(args[1]); |
| 3074 | LIST_INIT(&rule->list); |
| 3075 | LIST_ADDQ(&curproxy->switching_rules, &rule->list); |
| 3076 | } |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 3077 | else if (strcmp(args[0], "use-server") == 0) { |
| 3078 | struct server_rule *rule; |
| 3079 | |
| 3080 | if (curproxy == &defproxy) { |
| 3081 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3082 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3083 | goto out; |
| 3084 | } |
| 3085 | |
| 3086 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 3087 | err_code |= ERR_WARN; |
| 3088 | |
| 3089 | if (*(args[1]) == 0) { |
| 3090 | Alert("parsing [%s:%d] : '%s' expects a server name.\n", file, linenum, args[0]); |
| 3091 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3092 | goto out; |
| 3093 | } |
| 3094 | |
| 3095 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
| 3096 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 3097 | file, linenum, args[0]); |
| 3098 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3099 | goto out; |
| 3100 | } |
| 3101 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 3102 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 3103 | Alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n", |
| 3104 | file, linenum, errmsg); |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 3105 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3106 | goto out; |
| 3107 | } |
| 3108 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3109 | 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] | 3110 | |
| 3111 | rule = (struct server_rule *)calloc(1, sizeof(*rule)); |
| 3112 | rule->cond = cond; |
| 3113 | rule->srv.name = strdup(args[1]); |
| 3114 | LIST_INIT(&rule->list); |
| 3115 | LIST_ADDQ(&curproxy->server_rules, &rule->list); |
| 3116 | curproxy->be_req_ana |= AN_REQ_SRV_RULES; |
| 3117 | } |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 3118 | else if ((!strcmp(args[0], "force-persist")) || |
| 3119 | (!strcmp(args[0], "ignore-persist"))) { |
| 3120 | struct persist_rule *rule; |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 3121 | |
| 3122 | if (curproxy == &defproxy) { |
| 3123 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3124 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3125 | goto out; |
| 3126 | } |
| 3127 | |
| 3128 | if (warnifnotcap(curproxy, PR_CAP_FE|PR_CAP_BE, file, linenum, args[0], NULL)) |
| 3129 | err_code |= ERR_WARN; |
| 3130 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 3131 | if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) { |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 3132 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 3133 | file, linenum, args[0]); |
| 3134 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3135 | goto out; |
| 3136 | } |
| 3137 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 3138 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 1, &errmsg)) == NULL) { |
| 3139 | Alert("parsing [%s:%d] : error detected while parsing a '%s' rule : %s.\n", |
| 3140 | file, linenum, args[0], errmsg); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 3141 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3142 | goto out; |
| 3143 | } |
| 3144 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3145 | /* note: BE_REQ_CNT is the first one after FE_SET_BCK, which is |
| 3146 | * where force-persist is applied. |
| 3147 | */ |
| 3148 | 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] | 3149 | |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 3150 | rule = (struct persist_rule *)calloc(1, sizeof(*rule)); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 3151 | rule->cond = cond; |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 3152 | if (!strcmp(args[0], "force-persist")) { |
| 3153 | rule->type = PERSIST_TYPE_FORCE; |
| 3154 | } else { |
| 3155 | rule->type = PERSIST_TYPE_IGNORE; |
| 3156 | } |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 3157 | LIST_INIT(&rule->list); |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 3158 | LIST_ADDQ(&curproxy->persist_rules, &rule->list); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 3159 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3160 | else if (!strcmp(args[0], "stick-table")) { |
| 3161 | int myidx = 1; |
| 3162 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 3163 | curproxy->table.id = curproxy->id; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3164 | curproxy->table.type = (unsigned int)-1; |
| 3165 | while (*args[myidx]) { |
| 3166 | const char *err; |
| 3167 | |
| 3168 | if (strcmp(args[myidx], "size") == 0) { |
| 3169 | myidx++; |
| 3170 | if (!*(args[myidx])) { |
| 3171 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 3172 | file, linenum, args[myidx-1]); |
| 3173 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3174 | goto out; |
| 3175 | } |
| 3176 | if ((err = parse_size_err(args[myidx], &curproxy->table.size))) { |
| 3177 | Alert("parsing [%s:%d] : stick-table: unexpected character '%c' in argument of '%s'.\n", |
| 3178 | file, linenum, *err, args[myidx-1]); |
| 3179 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3180 | goto out; |
| 3181 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 3182 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3183 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 3184 | else if (strcmp(args[myidx], "peers") == 0) { |
| 3185 | myidx++; |
Godbach | 5052316 | 2013-12-11 19:48:57 +0800 | [diff] [blame] | 3186 | if (!*(args[myidx])) { |
Godbach | ff11554 | 2014-04-21 21:52:23 +0800 | [diff] [blame] | 3187 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 3188 | file, linenum, args[myidx-1]); |
| 3189 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3190 | goto out; |
Godbach | 5052316 | 2013-12-11 19:48:57 +0800 | [diff] [blame] | 3191 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 3192 | curproxy->table.peers.name = strdup(args[myidx++]); |
| 3193 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3194 | else if (strcmp(args[myidx], "expire") == 0) { |
| 3195 | myidx++; |
| 3196 | if (!*(args[myidx])) { |
| 3197 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 3198 | file, linenum, args[myidx-1]); |
| 3199 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3200 | goto out; |
| 3201 | } |
| 3202 | err = parse_time_err(args[myidx], &val, TIME_UNIT_MS); |
| 3203 | if (err) { |
| 3204 | Alert("parsing [%s:%d] : stick-table: unexpected character '%c' in argument of '%s'.\n", |
| 3205 | file, linenum, *err, args[myidx-1]); |
| 3206 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3207 | goto out; |
| 3208 | } |
| 3209 | curproxy->table.expire = val; |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 3210 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3211 | } |
| 3212 | else if (strcmp(args[myidx], "nopurge") == 0) { |
| 3213 | curproxy->table.nopurge = 1; |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 3214 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3215 | } |
| 3216 | else if (strcmp(args[myidx], "type") == 0) { |
| 3217 | myidx++; |
| 3218 | if (stktable_parse_type(args, &myidx, &curproxy->table.type, &curproxy->table.key_size) != 0) { |
| 3219 | Alert("parsing [%s:%d] : stick-table: unknown type '%s'.\n", |
| 3220 | file, linenum, args[myidx]); |
| 3221 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3222 | goto out; |
| 3223 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 3224 | /* myidx already points to next arg */ |
| 3225 | } |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 3226 | else if (strcmp(args[myidx], "store") == 0) { |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 3227 | int type, err; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 3228 | char *cw, *nw, *sa; |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 3229 | |
| 3230 | myidx++; |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 3231 | nw = args[myidx]; |
| 3232 | while (*nw) { |
| 3233 | /* the "store" keyword supports a comma-separated list */ |
| 3234 | cw = nw; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 3235 | sa = NULL; /* store arg */ |
| 3236 | while (*nw && *nw != ',') { |
| 3237 | if (*nw == '(') { |
| 3238 | *nw = 0; |
| 3239 | sa = ++nw; |
| 3240 | while (*nw != ')') { |
| 3241 | if (!*nw) { |
| 3242 | Alert("parsing [%s:%d] : %s: missing closing parenthesis after store option '%s'.\n", |
| 3243 | file, linenum, args[0], cw); |
| 3244 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3245 | goto out; |
| 3246 | } |
| 3247 | nw++; |
| 3248 | } |
| 3249 | *nw = '\0'; |
| 3250 | } |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 3251 | nw++; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 3252 | } |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 3253 | if (*nw) |
| 3254 | *nw++ = '\0'; |
| 3255 | type = stktable_get_data_type(cw); |
| 3256 | if (type < 0) { |
| 3257 | Alert("parsing [%s:%d] : %s: unknown store option '%s'.\n", |
| 3258 | file, linenum, args[0], cw); |
| 3259 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3260 | goto out; |
| 3261 | } |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 3262 | |
| 3263 | err = stktable_alloc_data_type(&curproxy->table, type, sa); |
| 3264 | switch (err) { |
| 3265 | case PE_NONE: break; |
| 3266 | case PE_EXIST: |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 3267 | Warning("parsing [%s:%d]: %s: store option '%s' already enabled, ignored.\n", |
| 3268 | file, linenum, args[0], cw); |
| 3269 | err_code |= ERR_WARN; |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 3270 | break; |
| 3271 | |
| 3272 | case PE_ARG_MISSING: |
| 3273 | Alert("parsing [%s:%d] : %s: missing argument to store option '%s'.\n", |
| 3274 | file, linenum, args[0], cw); |
| 3275 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3276 | goto out; |
| 3277 | |
| 3278 | case PE_ARG_NOT_USED: |
| 3279 | Alert("parsing [%s:%d] : %s: unexpected argument to store option '%s'.\n", |
| 3280 | file, linenum, args[0], cw); |
| 3281 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3282 | goto out; |
| 3283 | |
| 3284 | default: |
| 3285 | Alert("parsing [%s:%d] : %s: error when processing store option '%s'.\n", |
| 3286 | file, linenum, args[0], cw); |
| 3287 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3288 | goto out; |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 3289 | } |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 3290 | } |
| 3291 | myidx++; |
| 3292 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 3293 | else { |
| 3294 | Alert("parsing [%s:%d] : stick-table: unknown argument '%s'.\n", |
| 3295 | file, linenum, args[myidx]); |
| 3296 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3297 | goto out; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3298 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3299 | } |
| 3300 | |
| 3301 | if (!curproxy->table.size) { |
| 3302 | Alert("parsing [%s:%d] : stick-table: missing size.\n", |
| 3303 | file, linenum); |
| 3304 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3305 | goto out; |
| 3306 | } |
| 3307 | |
| 3308 | if (curproxy->table.type == (unsigned int)-1) { |
| 3309 | Alert("parsing [%s:%d] : stick-table: missing type.\n", |
| 3310 | file, linenum); |
| 3311 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3312 | goto out; |
| 3313 | } |
| 3314 | } |
| 3315 | else if (!strcmp(args[0], "stick")) { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3316 | struct sticking_rule *rule; |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 3317 | struct sample_expr *expr; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3318 | int myidx = 0; |
| 3319 | const char *name = NULL; |
| 3320 | int flags; |
| 3321 | |
| 3322 | if (curproxy == &defproxy) { |
| 3323 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3324 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3325 | goto out; |
| 3326 | } |
| 3327 | |
| 3328 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) { |
| 3329 | err_code |= ERR_WARN; |
| 3330 | goto out; |
| 3331 | } |
| 3332 | |
| 3333 | myidx++; |
| 3334 | if ((strcmp(args[myidx], "store") == 0) || |
| 3335 | (strcmp(args[myidx], "store-request") == 0)) { |
| 3336 | myidx++; |
| 3337 | flags = STK_IS_STORE; |
| 3338 | } |
| 3339 | else if (strcmp(args[myidx], "store-response") == 0) { |
| 3340 | myidx++; |
| 3341 | flags = STK_IS_STORE | STK_ON_RSP; |
| 3342 | } |
| 3343 | else if (strcmp(args[myidx], "match") == 0) { |
| 3344 | myidx++; |
| 3345 | flags = STK_IS_MATCH; |
| 3346 | } |
| 3347 | else if (strcmp(args[myidx], "on") == 0) { |
| 3348 | myidx++; |
| 3349 | flags = STK_IS_MATCH | STK_IS_STORE; |
| 3350 | } |
| 3351 | else { |
| 3352 | Alert("parsing [%s:%d] : '%s' expects 'on', 'match', or 'store'.\n", file, linenum, args[0]); |
| 3353 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3354 | goto out; |
| 3355 | } |
| 3356 | |
| 3357 | if (*(args[myidx]) == 0) { |
| 3358 | Alert("parsing [%s:%d] : '%s' expects a fetch method.\n", file, linenum, args[0]); |
| 3359 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3360 | goto out; |
| 3361 | } |
| 3362 | |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 3363 | curproxy->conf.args.ctx = ARGC_STK; |
Thierry FOURNIER | eeaa951 | 2014-02-11 14:00:19 +0100 | [diff] [blame] | 3364 | expr = sample_parse_expr(args, &myidx, file, linenum, &errmsg, &curproxy->conf.args); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3365 | if (!expr) { |
Willy Tarreau | 975c178 | 2013-12-12 23:16:54 +0100 | [diff] [blame] | 3366 | Alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3367 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3368 | goto out; |
| 3369 | } |
| 3370 | |
| 3371 | if (flags & STK_ON_RSP) { |
Willy Tarreau | 80aca90 | 2013-01-07 15:42:20 +0100 | [diff] [blame] | 3372 | if (!(expr->fetch->val & SMP_VAL_BE_STO_RUL)) { |
| 3373 | Alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available for 'store-response'.\n", |
| 3374 | 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] | 3375 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 3376 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3377 | goto out; |
| 3378 | } |
| 3379 | } else { |
Willy Tarreau | 80aca90 | 2013-01-07 15:42:20 +0100 | [diff] [blame] | 3380 | if (!(expr->fetch->val & SMP_VAL_BE_SET_SRV)) { |
| 3381 | Alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available during request.\n", |
| 3382 | 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] | 3383 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 3384 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3385 | goto out; |
| 3386 | } |
| 3387 | } |
| 3388 | |
Willy Tarreau | 1b6c00c | 2012-10-05 22:41:26 +0200 | [diff] [blame] | 3389 | /* 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] | 3390 | curproxy->http_needed |= !!(expr->fetch->use & SMP_USE_HTTP_ANY); |
Willy Tarreau | 1b6c00c | 2012-10-05 22:41:26 +0200 | [diff] [blame] | 3391 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3392 | if (strcmp(args[myidx], "table") == 0) { |
| 3393 | myidx++; |
| 3394 | name = args[myidx++]; |
| 3395 | } |
| 3396 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 3397 | if (strcmp(args[myidx], "if") == 0 || strcmp(args[myidx], "unless") == 0) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 3398 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + myidx, &errmsg)) == NULL) { |
| 3399 | Alert("parsing [%s:%d] : '%s': error detected while parsing sticking condition : %s.\n", |
| 3400 | file, linenum, args[0], errmsg); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3401 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 3402 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3403 | goto out; |
| 3404 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3405 | } |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 3406 | else if (*(args[myidx])) { |
| 3407 | Alert("parsing [%s:%d] : '%s': unknown keyword '%s'.\n", |
| 3408 | file, linenum, args[0], args[myidx]); |
| 3409 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 3410 | free(expr); |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 3411 | goto out; |
| 3412 | } |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 3413 | if (flags & STK_ON_RSP) |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3414 | 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] | 3415 | else |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3416 | 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] | 3417 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3418 | rule = (struct sticking_rule *)calloc(1, sizeof(*rule)); |
| 3419 | rule->cond = cond; |
| 3420 | rule->expr = expr; |
| 3421 | rule->flags = flags; |
| 3422 | rule->table.name = name ? strdup(name) : NULL; |
| 3423 | LIST_INIT(&rule->list); |
| 3424 | if (flags & STK_ON_RSP) |
| 3425 | LIST_ADDQ(&curproxy->storersp_rules, &rule->list); |
| 3426 | else |
| 3427 | LIST_ADDQ(&curproxy->sticking_rules, &rule->list); |
| 3428 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3429 | else if (!strcmp(args[0], "stats")) { |
| 3430 | if (curproxy != &defproxy && curproxy->uri_auth == defproxy.uri_auth) |
| 3431 | curproxy->uri_auth = NULL; /* we must detach from the default config */ |
| 3432 | |
Krzysztof Piotr Oledzki | 260a3bb | 2010-01-06 16:25:05 +0100 | [diff] [blame] | 3433 | if (!*args[1]) { |
| 3434 | goto stats_error_parsing; |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3435 | } else if (!strcmp(args[1], "admin")) { |
| 3436 | struct stats_admin_rule *rule; |
| 3437 | |
| 3438 | if (curproxy == &defproxy) { |
| 3439 | Alert("parsing [%s:%d]: '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
| 3440 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3441 | goto out; |
| 3442 | } |
| 3443 | |
| 3444 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 3445 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3446 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3447 | goto out; |
| 3448 | } |
| 3449 | |
| 3450 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
| 3451 | Alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n", |
| 3452 | file, linenum, args[0], args[1]); |
| 3453 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3454 | goto out; |
| 3455 | } |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 3456 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 3457 | Alert("parsing [%s:%d] : error detected while parsing a '%s %s' rule : %s.\n", |
| 3458 | file, linenum, args[0], args[1], errmsg); |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3459 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3460 | goto out; |
| 3461 | } |
| 3462 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3463 | err_code |= warnif_cond_conflicts(cond, |
| 3464 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 3465 | file, linenum); |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3466 | |
| 3467 | rule = (struct stats_admin_rule *)calloc(1, sizeof(*rule)); |
| 3468 | rule->cond = cond; |
| 3469 | LIST_INIT(&rule->list); |
| 3470 | LIST_ADDQ(&curproxy->uri_auth->admin_rules, &rule->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3471 | } else if (!strcmp(args[1], "uri")) { |
| 3472 | if (*(args[2]) == 0) { |
| 3473 | Alert("parsing [%s:%d] : 'uri' needs an URI prefix.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3474 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3475 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3476 | } else if (!stats_set_uri(&curproxy->uri_auth, args[2])) { |
| 3477 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3478 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3479 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3480 | } |
| 3481 | } else if (!strcmp(args[1], "realm")) { |
| 3482 | if (*(args[2]) == 0) { |
| 3483 | Alert("parsing [%s:%d] : 'realm' needs an realm name.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3484 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3485 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3486 | } else if (!stats_set_realm(&curproxy->uri_auth, args[2])) { |
| 3487 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3488 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3489 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3490 | } |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 3491 | } else if (!strcmp(args[1], "refresh")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 3492 | unsigned interval; |
| 3493 | |
| 3494 | err = parse_time_err(args[2], &interval, TIME_UNIT_S); |
| 3495 | if (err) { |
| 3496 | Alert("parsing [%s:%d] : unexpected character '%c' in stats refresh interval.\n", |
| 3497 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3498 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3499 | goto out; |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 3500 | } else if (!stats_set_refresh(&curproxy->uri_auth, interval)) { |
| 3501 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3502 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3503 | goto out; |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 3504 | } |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3505 | } 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] | 3506 | struct http_req_rule *rule; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3507 | |
| 3508 | if (curproxy == &defproxy) { |
| 3509 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3510 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3511 | goto out; |
| 3512 | } |
| 3513 | |
| 3514 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 3515 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3516 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3517 | goto out; |
| 3518 | } |
| 3519 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3520 | if (!LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) && |
| 3521 | !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] | 3522 | Warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n", |
| 3523 | file, linenum, args[0]); |
| 3524 | err_code |= ERR_WARN; |
| 3525 | } |
| 3526 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3527 | 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] | 3528 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3529 | if (!rule) { |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3530 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3531 | goto out; |
| 3532 | } |
| 3533 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3534 | err_code |= warnif_cond_conflicts(rule->cond, |
| 3535 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 3536 | file, linenum); |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3537 | LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list); |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3538 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3539 | } else if (!strcmp(args[1], "auth")) { |
| 3540 | if (*(args[2]) == 0) { |
| 3541 | 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] | 3542 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3543 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3544 | } else if (!stats_add_auth(&curproxy->uri_auth, args[2])) { |
| 3545 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3546 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3547 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3548 | } |
| 3549 | } else if (!strcmp(args[1], "scope")) { |
| 3550 | if (*(args[2]) == 0) { |
| 3551 | Alert("parsing [%s:%d] : 'scope' needs a proxy name.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3552 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3553 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3554 | } else if (!stats_add_scope(&curproxy->uri_auth, args[2])) { |
| 3555 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3556 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3557 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3558 | } |
| 3559 | } else if (!strcmp(args[1], "enable")) { |
| 3560 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 3561 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3562 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3563 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3564 | } |
Krzysztof Oledzki | d9db927 | 2007-10-15 10:05:11 +0200 | [diff] [blame] | 3565 | } else if (!strcmp(args[1], "hide-version")) { |
| 3566 | if (!stats_set_flag(&curproxy->uri_auth, ST_HIDEVER)) { |
| 3567 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3568 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3569 | goto out; |
Krzysztof Oledzki | d9db927 | 2007-10-15 10:05:11 +0200 | [diff] [blame] | 3570 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3571 | } else if (!strcmp(args[1], "show-legends")) { |
| 3572 | if (!stats_set_flag(&curproxy->uri_auth, ST_SHLGNDS)) { |
| 3573 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3574 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3575 | goto out; |
| 3576 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3577 | } else if (!strcmp(args[1], "show-node")) { |
| 3578 | |
| 3579 | if (*args[2]) { |
| 3580 | int i; |
| 3581 | char c; |
| 3582 | |
| 3583 | for (i=0; args[2][i]; i++) { |
| 3584 | c = args[2][i]; |
Willy Tarreau | 88e0581 | 2010-03-03 00:16:00 +0100 | [diff] [blame] | 3585 | if (!isupper((unsigned char)c) && !islower((unsigned char)c) && |
| 3586 | !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.') |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3587 | break; |
| 3588 | } |
| 3589 | |
| 3590 | if (!i || args[2][i]) { |
| 3591 | Alert("parsing [%s:%d]: '%s %s' invalid node name - should be a string" |
| 3592 | "with digits(0-9), letters(A-Z, a-z), hyphen(-) or underscode(_).\n", |
| 3593 | file, linenum, args[0], args[1]); |
| 3594 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3595 | goto out; |
| 3596 | } |
| 3597 | } |
| 3598 | |
| 3599 | if (!stats_set_node(&curproxy->uri_auth, args[2])) { |
| 3600 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3601 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3602 | goto out; |
| 3603 | } |
| 3604 | } else if (!strcmp(args[1], "show-desc")) { |
| 3605 | char *desc = NULL; |
| 3606 | |
| 3607 | if (*args[2]) { |
| 3608 | int i, len=0; |
| 3609 | char *d; |
| 3610 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 3611 | for (i = 2; *args[i]; i++) |
| 3612 | len += strlen(args[i]) + 1; |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3613 | |
| 3614 | desc = d = (char *)calloc(1, len); |
| 3615 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 3616 | d += snprintf(d, desc + len - d, "%s", args[2]); |
| 3617 | for (i = 3; *args[i]; i++) |
| 3618 | d += snprintf(d, desc + len - d, " %s", args[i]); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3619 | } |
| 3620 | |
| 3621 | if (!*args[2] && !global.desc) |
| 3622 | Warning("parsing [%s:%d]: '%s' requires a parameter or 'desc' to be set in the global section.\n", |
| 3623 | file, linenum, args[1]); |
| 3624 | else { |
| 3625 | if (!stats_set_desc(&curproxy->uri_auth, desc)) { |
| 3626 | free(desc); |
| 3627 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3628 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3629 | goto out; |
| 3630 | } |
| 3631 | free(desc); |
| 3632 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3633 | } else { |
Krzysztof Piotr Oledzki | 260a3bb | 2010-01-06 16:25:05 +0100 | [diff] [blame] | 3634 | stats_error_parsing: |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3635 | 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] | 3636 | 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] | 3637 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3638 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3639 | } |
| 3640 | } |
| 3641 | else if (!strcmp(args[0], "option")) { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3642 | int optnum; |
| 3643 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3644 | if (*(args[1]) == '\0') { |
| 3645 | Alert("parsing [%s:%d]: '%s' expects an option name.\n", |
| 3646 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3647 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3648 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3649 | } |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3650 | |
| 3651 | for (optnum = 0; cfg_opts[optnum].name; optnum++) { |
| 3652 | if (!strcmp(args[1], cfg_opts[optnum].name)) { |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 3653 | if (cfg_opts[optnum].cap == PR_CAP_NONE) { |
| 3654 | Alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n", |
| 3655 | file, linenum, cfg_opts[optnum].name); |
| 3656 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3657 | goto out; |
| 3658 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3659 | if (warnifnotcap(curproxy, cfg_opts[optnum].cap, file, linenum, args[1], NULL)) { |
| 3660 | err_code |= ERR_WARN; |
| 3661 | goto out; |
| 3662 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3663 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 3664 | curproxy->no_options &= ~cfg_opts[optnum].val; |
| 3665 | curproxy->options &= ~cfg_opts[optnum].val; |
| 3666 | |
| 3667 | switch (kwm) { |
| 3668 | case KWM_STD: |
| 3669 | curproxy->options |= cfg_opts[optnum].val; |
| 3670 | break; |
| 3671 | case KWM_NO: |
| 3672 | curproxy->no_options |= cfg_opts[optnum].val; |
| 3673 | break; |
| 3674 | case KWM_DEF: /* already cleared */ |
| 3675 | break; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 3676 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3677 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3678 | goto out; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3679 | } |
| 3680 | } |
| 3681 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 3682 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) { |
| 3683 | if (!strcmp(args[1], cfg_opts2[optnum].name)) { |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 3684 | if (cfg_opts2[optnum].cap == PR_CAP_NONE) { |
| 3685 | Alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n", |
| 3686 | file, linenum, cfg_opts2[optnum].name); |
| 3687 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3688 | goto out; |
| 3689 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3690 | if (warnifnotcap(curproxy, cfg_opts2[optnum].cap, file, linenum, args[1], NULL)) { |
| 3691 | err_code |= ERR_WARN; |
| 3692 | goto out; |
| 3693 | } |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 3694 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 3695 | curproxy->no_options2 &= ~cfg_opts2[optnum].val; |
| 3696 | curproxy->options2 &= ~cfg_opts2[optnum].val; |
| 3697 | |
| 3698 | switch (kwm) { |
| 3699 | case KWM_STD: |
| 3700 | curproxy->options2 |= cfg_opts2[optnum].val; |
| 3701 | break; |
| 3702 | case KWM_NO: |
| 3703 | curproxy->no_options2 |= cfg_opts2[optnum].val; |
| 3704 | break; |
| 3705 | case KWM_DEF: /* already cleared */ |
| 3706 | break; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 3707 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3708 | goto out; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 3709 | } |
| 3710 | } |
| 3711 | |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 3712 | /* HTTP options override each other. They can be cancelled using |
| 3713 | * "no option xxx" which only switches to default mode if the mode |
| 3714 | * was this one (useful for cancelling options set in defaults |
| 3715 | * sections). |
| 3716 | */ |
| 3717 | if (strcmp(args[1], "httpclose") == 0) { |
| 3718 | if (kwm == KWM_STD) { |
| 3719 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3720 | curproxy->options |= PR_O_HTTP_PCL; |
| 3721 | goto out; |
| 3722 | } |
| 3723 | else if (kwm == KWM_NO) { |
| 3724 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_PCL) |
| 3725 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3726 | goto out; |
| 3727 | } |
| 3728 | } |
| 3729 | else if (strcmp(args[1], "forceclose") == 0) { |
| 3730 | if (kwm == KWM_STD) { |
| 3731 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3732 | curproxy->options |= PR_O_HTTP_FCL; |
| 3733 | goto out; |
| 3734 | } |
| 3735 | else if (kwm == KWM_NO) { |
| 3736 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_FCL) |
| 3737 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3738 | goto out; |
| 3739 | } |
| 3740 | } |
| 3741 | else if (strcmp(args[1], "http-server-close") == 0) { |
| 3742 | if (kwm == KWM_STD) { |
| 3743 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3744 | curproxy->options |= PR_O_HTTP_SCL; |
| 3745 | goto out; |
| 3746 | } |
| 3747 | else if (kwm == KWM_NO) { |
| 3748 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_SCL) |
| 3749 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3750 | goto out; |
| 3751 | } |
| 3752 | } |
| 3753 | else if (strcmp(args[1], "http-keep-alive") == 0) { |
| 3754 | if (kwm == KWM_STD) { |
| 3755 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3756 | curproxy->options |= PR_O_HTTP_KAL; |
| 3757 | goto out; |
| 3758 | } |
| 3759 | else if (kwm == KWM_NO) { |
| 3760 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_KAL) |
| 3761 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3762 | goto out; |
| 3763 | } |
| 3764 | } |
| 3765 | else if (strcmp(args[1], "http-tunnel") == 0) { |
| 3766 | if (kwm == KWM_STD) { |
| 3767 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3768 | curproxy->options |= PR_O_HTTP_TUN; |
| 3769 | goto out; |
| 3770 | } |
| 3771 | else if (kwm == KWM_NO) { |
| 3772 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_TUN) |
| 3773 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3774 | goto out; |
| 3775 | } |
| 3776 | } |
| 3777 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 3778 | if (kwm != KWM_STD) { |
| 3779 | 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] | 3780 | file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3781 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3782 | goto out; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3783 | } |
| 3784 | |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3785 | if (!strcmp(args[1], "httplog")) { |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 3786 | char *logformat; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3787 | /* generate a complete HTTP log */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 3788 | logformat = default_http_log_format; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3789 | if (*(args[2]) != '\0') { |
| 3790 | if (!strcmp(args[2], "clf")) { |
| 3791 | curproxy->options2 |= PR_O2_CLFLOG; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 3792 | logformat = clf_http_log_format; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3793 | } else { |
| 3794 | 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] | 3795 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3796 | goto out; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3797 | } |
| 3798 | } |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 3799 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 3800 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 3801 | curproxy->conf.logformat_string != clf_http_log_format) |
| 3802 | free(curproxy->conf.logformat_string); |
| 3803 | curproxy->conf.logformat_string = logformat; |
| 3804 | |
| 3805 | free(curproxy->conf.lfs_file); |
| 3806 | curproxy->conf.lfs_file = strdup(curproxy->conf.args.file); |
| 3807 | curproxy->conf.lfs_line = curproxy->conf.args.line; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3808 | } |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 3809 | else if (!strcmp(args[1], "tcplog")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3810 | /* generate a detailed TCP log */ |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 3811 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 3812 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 3813 | curproxy->conf.logformat_string != clf_http_log_format) |
| 3814 | free(curproxy->conf.logformat_string); |
| 3815 | curproxy->conf.logformat_string = default_tcp_log_format; |
| 3816 | |
| 3817 | free(curproxy->conf.lfs_file); |
| 3818 | curproxy->conf.lfs_file = strdup(curproxy->conf.args.file); |
| 3819 | curproxy->conf.lfs_line = curproxy->conf.args.line; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 3820 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3821 | else if (!strcmp(args[1], "tcpka")) { |
| 3822 | /* enable TCP keep-alives on client and server sessions */ |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3823 | 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] | 3824 | err_code |= ERR_WARN; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3825 | |
| 3826 | if (curproxy->cap & PR_CAP_FE) |
| 3827 | curproxy->options |= PR_O_TCP_CLI_KA; |
| 3828 | if (curproxy->cap & PR_CAP_BE) |
| 3829 | curproxy->options |= PR_O_TCP_SRV_KA; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3830 | } |
| 3831 | else if (!strcmp(args[1], "httpchk")) { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3832 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3833 | err_code |= ERR_WARN; |
| 3834 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3835 | /* use HTTP request to check servers' health */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3836 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 3837 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3838 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 3839 | curproxy->options2 |= PR_O2_HTTP_CHK; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3840 | if (!*args[2]) { /* no argument */ |
| 3841 | curproxy->check_req = strdup(DEF_CHECK_REQ); /* default request */ |
| 3842 | curproxy->check_len = strlen(DEF_CHECK_REQ); |
| 3843 | } else if (!*args[3]) { /* one argument : URI */ |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3844 | 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] | 3845 | curproxy->check_req = (char *)malloc(reqlen); |
| 3846 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3847 | "OPTIONS %s HTTP/1.0\r\n", args[2]); /* URI to use */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3848 | } else { /* more arguments : METHOD URI [HTTP_VER] */ |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3849 | int reqlen = strlen(args[2]) + strlen(args[3]) + 3 + strlen("\r\n"); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3850 | if (*args[4]) |
| 3851 | reqlen += strlen(args[4]); |
| 3852 | else |
| 3853 | reqlen += strlen("HTTP/1.0"); |
| 3854 | |
| 3855 | curproxy->check_req = (char *)malloc(reqlen); |
| 3856 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3857 | "%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] | 3858 | } |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 3859 | } |
| 3860 | else if (!strcmp(args[1], "ssl-hello-chk")) { |
| 3861 | /* use SSLv3 CLIENT HELLO to check servers' health */ |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3862 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3863 | err_code |= ERR_WARN; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3864 | |
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; |
Willy Tarreau | 07a5490 | 2010-03-29 18:33:29 +0200 | [diff] [blame] | 3868 | curproxy->options2 |= PR_O2_SSL3_CHK; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3869 | } |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 3870 | else if (!strcmp(args[1], "smtpchk")) { |
| 3871 | /* use SMTP request to check servers' health */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3872 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 3873 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3874 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 3875 | curproxy->options2 |= PR_O2_SMTP_CHK; |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 3876 | |
| 3877 | if (!*args[2] || !*args[3]) { /* no argument or incomplete EHLO host */ |
| 3878 | curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */ |
| 3879 | curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ); |
| 3880 | } else { /* ESMTP EHLO, or SMTP HELO, and a hostname */ |
| 3881 | if (!strcmp(args[2], "EHLO") || !strcmp(args[2], "HELO")) { |
| 3882 | int reqlen = strlen(args[2]) + strlen(args[3]) + strlen(" \r\n") + 1; |
| 3883 | curproxy->check_req = (char *)malloc(reqlen); |
| 3884 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
| 3885 | "%s %s\r\n", args[2], args[3]); /* HELO hostname */ |
| 3886 | } else { |
| 3887 | /* this just hits the default for now, but you could potentially expand it to allow for other stuff |
| 3888 | though, it's unlikely you'd want to send anything other than an EHLO or HELO */ |
| 3889 | curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */ |
| 3890 | curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ); |
| 3891 | } |
| 3892 | } |
| 3893 | } |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 3894 | else if (!strcmp(args[1], "pgsql-check")) { |
| 3895 | /* use PostgreSQL request to check servers' health */ |
| 3896 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 3897 | err_code |= ERR_WARN; |
| 3898 | |
| 3899 | free(curproxy->check_req); |
| 3900 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3901 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 3902 | curproxy->options2 |= PR_O2_PGSQL_CHK; |
| 3903 | |
| 3904 | if (*(args[2])) { |
| 3905 | int cur_arg = 2; |
| 3906 | |
| 3907 | while (*(args[cur_arg])) { |
| 3908 | if (strcmp(args[cur_arg], "user") == 0) { |
| 3909 | char * packet; |
| 3910 | uint32_t packet_len; |
| 3911 | uint32_t pv; |
| 3912 | |
| 3913 | /* suboption header - needs additional argument for it */ |
| 3914 | if (*(args[cur_arg+1]) == 0) { |
| 3915 | Alert("parsing [%s:%d] : '%s %s %s' expects <username> as argument.\n", |
| 3916 | file, linenum, args[0], args[1], args[cur_arg]); |
| 3917 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3918 | goto out; |
| 3919 | } |
| 3920 | |
| 3921 | /* uint32_t + uint32_t + strlen("user")+1 + strlen(username)+1 + 1 */ |
| 3922 | packet_len = 4 + 4 + 5 + strlen(args[cur_arg + 1])+1 +1; |
| 3923 | pv = htonl(0x30000); /* protocol version 3.0 */ |
| 3924 | |
| 3925 | packet = (char*) calloc(1, packet_len); |
| 3926 | |
| 3927 | memcpy(packet + 4, &pv, 4); |
| 3928 | |
| 3929 | /* copy "user" */ |
| 3930 | memcpy(packet + 8, "user", 4); |
| 3931 | |
| 3932 | /* copy username */ |
| 3933 | memcpy(packet + 13, args[cur_arg+1], strlen(args[cur_arg+1])); |
| 3934 | |
| 3935 | free(curproxy->check_req); |
| 3936 | curproxy->check_req = packet; |
| 3937 | curproxy->check_len = packet_len; |
| 3938 | |
| 3939 | packet_len = htonl(packet_len); |
| 3940 | memcpy(packet, &packet_len, 4); |
| 3941 | cur_arg += 2; |
| 3942 | } else { |
| 3943 | /* unknown suboption - catchall */ |
| 3944 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'user'.\n", |
| 3945 | file, linenum, args[0], args[1]); |
| 3946 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3947 | goto out; |
| 3948 | } |
| 3949 | } /* end while loop */ |
| 3950 | } |
| 3951 | } |
| 3952 | |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 3953 | else if (!strcmp(args[1], "redis-check")) { |
| 3954 | /* use REDIS PING request to check servers' health */ |
| 3955 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 3956 | err_code |= ERR_WARN; |
| 3957 | |
| 3958 | free(curproxy->check_req); |
| 3959 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3960 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 3961 | curproxy->options2 |= PR_O2_REDIS_CHK; |
| 3962 | |
| 3963 | curproxy->check_req = (char *) malloc(sizeof(DEF_REDIS_CHECK_REQ) - 1); |
| 3964 | memcpy(curproxy->check_req, DEF_REDIS_CHECK_REQ, sizeof(DEF_REDIS_CHECK_REQ) - 1); |
| 3965 | curproxy->check_len = sizeof(DEF_REDIS_CHECK_REQ) - 1; |
| 3966 | } |
| 3967 | |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 3968 | else if (!strcmp(args[1], "mysql-check")) { |
| 3969 | /* use MYSQL request to check servers' health */ |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 3970 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 3971 | err_code |= ERR_WARN; |
| 3972 | |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 3973 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 3974 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3975 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 3976 | curproxy->options2 |= PR_O2_MYSQL_CHK; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 3977 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 3978 | /* 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] | 3979 | * const char mysql40_client_auth_pkt[] = { |
| 3980 | * "\x0e\x00\x00" // packet length |
| 3981 | * "\x01" // packet number |
| 3982 | * "\x00\x00" // client capabilities |
| 3983 | * "\x00\x00\x01" // max packet |
| 3984 | * "haproxy\x00" // username (null terminated string) |
| 3985 | * "\x00" // filler (always 0x00) |
| 3986 | * "\x01\x00\x00" // packet length |
| 3987 | * "\x00" // packet number |
| 3988 | * "\x01" // COM_QUIT command |
| 3989 | * }; |
| 3990 | */ |
| 3991 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 3992 | /* This is an example of a MySQL >=4.1 client Authentication packet provided by Nenad Merdanovic. |
| 3993 | * const char mysql41_client_auth_pkt[] = { |
| 3994 | * "\x0e\x00\x00\" // packet length |
| 3995 | * "\x01" // packet number |
| 3996 | * "\x00\x00\x00\x00" // client capabilities |
| 3997 | * "\x00\x00\x00\x01" // max packet |
| 3998 | * "\x21" // character set (UTF-8) |
| 3999 | * char[23] // All zeroes |
| 4000 | * "haproxy\x00" // username (null terminated string) |
| 4001 | * "\x00" // filler (always 0x00) |
| 4002 | * "\x01\x00\x00" // packet length |
| 4003 | * "\x00" // packet number |
| 4004 | * "\x01" // COM_QUIT command |
| 4005 | * }; |
| 4006 | */ |
| 4007 | |
| 4008 | |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 4009 | if (*(args[2])) { |
| 4010 | int cur_arg = 2; |
| 4011 | |
| 4012 | while (*(args[cur_arg])) { |
| 4013 | if (strcmp(args[cur_arg], "user") == 0) { |
| 4014 | char *mysqluser; |
| 4015 | int packetlen, reqlen, userlen; |
| 4016 | |
| 4017 | /* suboption header - needs additional argument for it */ |
| 4018 | if (*(args[cur_arg+1]) == 0) { |
| 4019 | Alert("parsing [%s:%d] : '%s %s %s' expects <username> as argument.\n", |
| 4020 | file, linenum, args[0], args[1], args[cur_arg]); |
| 4021 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4022 | goto out; |
| 4023 | } |
| 4024 | mysqluser = args[cur_arg + 1]; |
| 4025 | userlen = strlen(mysqluser); |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 4026 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 4027 | if (*(args[cur_arg+2])) { |
| 4028 | if (!strcmp(args[cur_arg+2], "post-41")) { |
| 4029 | packetlen = userlen + 7 + 27; |
| 4030 | reqlen = packetlen + 9; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 4031 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 4032 | free(curproxy->check_req); |
| 4033 | curproxy->check_req = (char *)calloc(1, reqlen); |
| 4034 | curproxy->check_len = reqlen; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 4035 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 4036 | snprintf(curproxy->check_req, 4, "%c%c%c", |
| 4037 | ((unsigned char) packetlen & 0xff), |
| 4038 | ((unsigned char) (packetlen >> 8) & 0xff), |
| 4039 | ((unsigned char) (packetlen >> 16) & 0xff)); |
| 4040 | |
| 4041 | curproxy->check_req[3] = 1; |
| 4042 | curproxy->check_req[5] = 130; |
| 4043 | curproxy->check_req[11] = 1; |
| 4044 | curproxy->check_req[12] = 33; |
| 4045 | memcpy(&curproxy->check_req[36], mysqluser, userlen); |
| 4046 | curproxy->check_req[36 + userlen + 1 + 1] = 1; |
| 4047 | curproxy->check_req[36 + userlen + 1 + 1 + 4] = 1; |
| 4048 | cur_arg += 3; |
| 4049 | } else { |
| 4050 | Alert("parsing [%s:%d] : keyword '%s' only supports option 'post-41'.\n", file, linenum, args[cur_arg+2]); |
| 4051 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4052 | goto out; |
| 4053 | } |
| 4054 | } else { |
| 4055 | packetlen = userlen + 7; |
| 4056 | reqlen = packetlen + 9; |
| 4057 | |
| 4058 | free(curproxy->check_req); |
| 4059 | curproxy->check_req = (char *)calloc(1, reqlen); |
| 4060 | curproxy->check_len = reqlen; |
| 4061 | |
| 4062 | snprintf(curproxy->check_req, 4, "%c%c%c", |
| 4063 | ((unsigned char) packetlen & 0xff), |
| 4064 | ((unsigned char) (packetlen >> 8) & 0xff), |
| 4065 | ((unsigned char) (packetlen >> 16) & 0xff)); |
| 4066 | |
| 4067 | curproxy->check_req[3] = 1; |
| 4068 | curproxy->check_req[5] = 128; |
| 4069 | curproxy->check_req[8] = 1; |
| 4070 | memcpy(&curproxy->check_req[9], mysqluser, userlen); |
| 4071 | curproxy->check_req[9 + userlen + 1 + 1] = 1; |
| 4072 | curproxy->check_req[9 + userlen + 1 + 1 + 4] = 1; |
| 4073 | cur_arg += 2; |
| 4074 | } |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 4075 | } else { |
| 4076 | /* unknown suboption - catchall */ |
| 4077 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'user'.\n", |
| 4078 | file, linenum, args[0], args[1]); |
| 4079 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4080 | goto out; |
| 4081 | } |
| 4082 | } /* end while loop */ |
| 4083 | } |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 4084 | } |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 4085 | else if (!strcmp(args[1], "ldap-check")) { |
| 4086 | /* use LDAP request to check servers' health */ |
| 4087 | free(curproxy->check_req); |
| 4088 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4089 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 4090 | curproxy->options2 |= PR_O2_LDAP_CHK; |
| 4091 | |
| 4092 | curproxy->check_req = (char *) malloc(sizeof(DEF_LDAP_CHECK_REQ) - 1); |
| 4093 | memcpy(curproxy->check_req, DEF_LDAP_CHECK_REQ, sizeof(DEF_LDAP_CHECK_REQ) - 1); |
| 4094 | curproxy->check_len = sizeof(DEF_LDAP_CHECK_REQ) - 1; |
| 4095 | } |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 4096 | else if (!strcmp(args[1], "tcp-check")) { |
| 4097 | /* use raw TCPCHK send/expect to check servers' health */ |
| 4098 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 4099 | err_code |= ERR_WARN; |
| 4100 | |
| 4101 | free(curproxy->check_req); |
| 4102 | curproxy->check_req = NULL; |
| 4103 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 4104 | curproxy->options2 |= PR_O2_TCPCHK_CHK; |
| 4105 | } |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 4106 | else if (!strcmp(args[1], "external-check")) { |
| 4107 | /* excute an external command to check servers' health */ |
| 4108 | free(curproxy->check_req); |
| 4109 | curproxy->check_req = NULL; |
| 4110 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 4111 | curproxy->options2 |= PR_O2_EXT_CHK; |
| 4112 | } |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 4113 | else if (!strcmp(args[1], "forwardfor")) { |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 4114 | int cur_arg; |
| 4115 | |
| 4116 | /* insert x-forwarded-for field, but not for the IP address listed as an except. |
| 4117 | * set default options (ie: bitfield, header name, etc) |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 4118 | */ |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 4119 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 4120 | curproxy->options |= PR_O_FWDFOR | PR_O_FF_ALWAYS; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 4121 | |
| 4122 | free(curproxy->fwdfor_hdr_name); |
| 4123 | curproxy->fwdfor_hdr_name = strdup(DEF_XFORWARDFOR_HDR); |
| 4124 | curproxy->fwdfor_hdr_len = strlen(DEF_XFORWARDFOR_HDR); |
| 4125 | |
| 4126 | /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */ |
| 4127 | cur_arg = 2; |
| 4128 | while (*(args[cur_arg])) { |
| 4129 | if (!strcmp(args[cur_arg], "except")) { |
| 4130 | /* suboption except - needs additional argument for it */ |
Thierry FOURNIER | fc7ac7b | 2014-02-11 15:23:04 +0100 | [diff] [blame] | 4131 | 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] | 4132 | Alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n", |
| 4133 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4134 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4135 | goto out; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 4136 | } |
| 4137 | /* flush useless bits */ |
| 4138 | curproxy->except_net.s_addr &= curproxy->except_mask.s_addr; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 4139 | cur_arg += 2; |
| 4140 | } else if (!strcmp(args[cur_arg], "header")) { |
| 4141 | /* suboption header - needs additional argument for it */ |
| 4142 | if (*(args[cur_arg+1]) == 0) { |
| 4143 | Alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 4144 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4145 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4146 | goto out; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 4147 | } |
| 4148 | free(curproxy->fwdfor_hdr_name); |
| 4149 | curproxy->fwdfor_hdr_name = strdup(args[cur_arg+1]); |
| 4150 | curproxy->fwdfor_hdr_len = strlen(curproxy->fwdfor_hdr_name); |
| 4151 | cur_arg += 2; |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 4152 | } else if (!strcmp(args[cur_arg], "if-none")) { |
| 4153 | curproxy->options &= ~PR_O_FF_ALWAYS; |
| 4154 | cur_arg += 1; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 4155 | } else { |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 4156 | /* unknown suboption - catchall */ |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 4157 | 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] | 4158 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4159 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4160 | goto out; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 4161 | } |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 4162 | } /* end while loop */ |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 4163 | } |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 4164 | else if (!strcmp(args[1], "originalto")) { |
| 4165 | int cur_arg; |
| 4166 | |
| 4167 | /* insert x-original-to field, but not for the IP address listed as an except. |
| 4168 | * set default options (ie: bitfield, header name, etc) |
| 4169 | */ |
| 4170 | |
| 4171 | curproxy->options |= PR_O_ORGTO; |
| 4172 | |
| 4173 | free(curproxy->orgto_hdr_name); |
| 4174 | curproxy->orgto_hdr_name = strdup(DEF_XORIGINALTO_HDR); |
| 4175 | curproxy->orgto_hdr_len = strlen(DEF_XORIGINALTO_HDR); |
| 4176 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 4177 | /* 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] | 4178 | cur_arg = 2; |
| 4179 | while (*(args[cur_arg])) { |
| 4180 | if (!strcmp(args[cur_arg], "except")) { |
| 4181 | /* suboption except - needs additional argument for it */ |
Thierry FOURNIER | fc7ac7b | 2014-02-11 15:23:04 +0100 | [diff] [blame] | 4182 | 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] | 4183 | Alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n", |
| 4184 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4185 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4186 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 4187 | } |
| 4188 | /* flush useless bits */ |
| 4189 | curproxy->except_to.s_addr &= curproxy->except_mask_to.s_addr; |
| 4190 | cur_arg += 2; |
| 4191 | } else if (!strcmp(args[cur_arg], "header")) { |
| 4192 | /* suboption header - needs additional argument for it */ |
| 4193 | if (*(args[cur_arg+1]) == 0) { |
| 4194 | Alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 4195 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4196 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4197 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 4198 | } |
| 4199 | free(curproxy->orgto_hdr_name); |
| 4200 | curproxy->orgto_hdr_name = strdup(args[cur_arg+1]); |
| 4201 | curproxy->orgto_hdr_len = strlen(curproxy->orgto_hdr_name); |
| 4202 | cur_arg += 2; |
| 4203 | } else { |
| 4204 | /* unknown suboption - catchall */ |
| 4205 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n", |
| 4206 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4207 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4208 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 4209 | } |
| 4210 | } /* end while loop */ |
| 4211 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4212 | else { |
| 4213 | Alert("parsing [%s:%d] : unknown option '%s'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4214 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4215 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4216 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4217 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4218 | } |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 4219 | else if (!strcmp(args[0], "default_backend")) { |
| 4220 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4221 | err_code |= ERR_WARN; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 4222 | |
| 4223 | if (*(args[1]) == 0) { |
| 4224 | 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] | 4225 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4226 | goto out; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 4227 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 4228 | free(curproxy->defbe.name); |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 4229 | curproxy->defbe.name = strdup(args[1]); |
| 4230 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4231 | else if (!strcmp(args[0], "redispatch") || !strcmp(args[0], "redisp")) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4232 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4233 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4234 | |
Willy Tarreau | a3c504c | 2014-04-28 22:37:32 +0200 | [diff] [blame] | 4235 | if (!already_warned(WARN_REDISPATCH_DEPRECATED)) |
| 4236 | 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] | 4237 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4238 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4239 | /* enable reconnections to dispatch */ |
| 4240 | curproxy->options |= PR_O_REDISP; |
| 4241 | } |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 4242 | else if (!strcmp(args[0], "http-check")) { |
| 4243 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4244 | err_code |= ERR_WARN; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 4245 | |
| 4246 | if (strcmp(args[1], "disable-on-404") == 0) { |
| 4247 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 4248 | curproxy->options |= PR_O_DISABLE404; |
| 4249 | } |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 4250 | else if (strcmp(args[1], "send-state") == 0) { |
| 4251 | /* enable emission of the apparent state of a server in HTTP checks */ |
| 4252 | curproxy->options2 |= PR_O2_CHK_SNDST; |
| 4253 | } |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 4254 | else if (strcmp(args[1], "expect") == 0) { |
| 4255 | const char *ptr_arg; |
| 4256 | int cur_arg; |
| 4257 | |
| 4258 | if (curproxy->options2 & PR_O2_EXP_TYPE) { |
| 4259 | Alert("parsing [%s:%d] : '%s %s' already specified.\n", file, linenum, args[0], args[1]); |
| 4260 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4261 | goto out; |
| 4262 | } |
| 4263 | |
| 4264 | cur_arg = 2; |
| 4265 | /* consider exclamation marks, sole or at the beginning of a word */ |
| 4266 | while (*(ptr_arg = args[cur_arg])) { |
| 4267 | while (*ptr_arg == '!') { |
| 4268 | curproxy->options2 ^= PR_O2_EXP_INV; |
| 4269 | ptr_arg++; |
| 4270 | } |
| 4271 | if (*ptr_arg) |
| 4272 | break; |
| 4273 | cur_arg++; |
| 4274 | } |
| 4275 | /* now ptr_arg points to the beginning of a word past any possible |
| 4276 | * exclamation mark, and cur_arg is the argument which holds this word. |
| 4277 | */ |
| 4278 | if (strcmp(ptr_arg, "status") == 0) { |
| 4279 | if (!*(args[cur_arg + 1])) { |
| 4280 | Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 4281 | file, linenum, args[0], args[1], ptr_arg); |
| 4282 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4283 | goto out; |
| 4284 | } |
| 4285 | curproxy->options2 |= PR_O2_EXP_STS; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 4286 | free(curproxy->expect_str); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 4287 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
| 4288 | } |
| 4289 | else if (strcmp(ptr_arg, "string") == 0) { |
| 4290 | if (!*(args[cur_arg + 1])) { |
| 4291 | Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 4292 | file, linenum, args[0], args[1], ptr_arg); |
| 4293 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4294 | goto out; |
| 4295 | } |
| 4296 | curproxy->options2 |= PR_O2_EXP_STR; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 4297 | free(curproxy->expect_str); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 4298 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
| 4299 | } |
| 4300 | else if (strcmp(ptr_arg, "rstatus") == 0) { |
| 4301 | if (!*(args[cur_arg + 1])) { |
| 4302 | Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 4303 | file, linenum, args[0], args[1], ptr_arg); |
| 4304 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4305 | goto out; |
| 4306 | } |
| 4307 | curproxy->options2 |= PR_O2_EXP_RSTS; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 4308 | free(curproxy->expect_str); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 4309 | if (curproxy->expect_regex) { |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 4310 | regex_free(curproxy->expect_regex); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 4311 | free(curproxy->expect_regex); |
| 4312 | curproxy->expect_regex = NULL; |
| 4313 | } |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 4314 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 4315 | curproxy->expect_regex = calloc(1, sizeof(*curproxy->expect_regex)); |
| 4316 | error = NULL; |
| 4317 | if (!regex_comp(args[cur_arg + 1], curproxy->expect_regex, 1, 1, &error)) { |
| 4318 | Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s': %s.\n", |
| 4319 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1], error); |
| 4320 | free(error); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 4321 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4322 | goto out; |
| 4323 | } |
| 4324 | } |
| 4325 | else if (strcmp(ptr_arg, "rstring") == 0) { |
| 4326 | if (!*(args[cur_arg + 1])) { |
| 4327 | Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 4328 | file, linenum, args[0], args[1], ptr_arg); |
| 4329 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4330 | goto out; |
| 4331 | } |
| 4332 | curproxy->options2 |= PR_O2_EXP_RSTR; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 4333 | free(curproxy->expect_str); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 4334 | if (curproxy->expect_regex) { |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 4335 | regex_free(curproxy->expect_regex); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 4336 | free(curproxy->expect_regex); |
| 4337 | curproxy->expect_regex = NULL; |
| 4338 | } |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 4339 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 4340 | curproxy->expect_regex = calloc(1, sizeof(*curproxy->expect_regex)); |
| 4341 | error = NULL; |
| 4342 | if (!regex_comp(args[cur_arg + 1], curproxy->expect_regex, 1, 1, &error)) { |
| 4343 | Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s': %s.\n", |
| 4344 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1], error); |
| 4345 | free(error); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 4346 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4347 | goto out; |
| 4348 | } |
| 4349 | } |
| 4350 | else { |
| 4351 | Alert("parsing [%s:%d] : '%s %s' only supports [!] 'status', 'string', 'rstatus', 'rstring', found '%s'.\n", |
| 4352 | file, linenum, args[0], args[1], ptr_arg); |
| 4353 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4354 | goto out; |
| 4355 | } |
| 4356 | } |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 4357 | else { |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 4358 | 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] | 4359 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4360 | goto out; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 4361 | } |
| 4362 | } |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 4363 | else if (!strcmp(args[0], "tcp-check")) { |
| 4364 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 4365 | err_code |= ERR_WARN; |
| 4366 | |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 4367 | if (strcmp(args[1], "connect") == 0) { |
| 4368 | const char *ptr_arg; |
| 4369 | int cur_arg; |
| 4370 | struct tcpcheck_rule *tcpcheck; |
| 4371 | struct list *l; |
| 4372 | |
| 4373 | /* check if first rule is also a 'connect' action */ |
| 4374 | l = (struct list *)&curproxy->tcpcheck_rules; |
| 4375 | if (l->p != l->n) { |
| 4376 | tcpcheck = (struct tcpcheck_rule *)l->n; |
| 4377 | if (tcpcheck && tcpcheck->action != TCPCHK_ACT_CONNECT) { |
| 4378 | Alert("parsing [%s:%d] : first step MUST also be a 'connect' when there is a 'connect' step in the tcp-check ruleset.\n", |
| 4379 | file, linenum); |
| 4380 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4381 | goto out; |
| 4382 | } |
| 4383 | } |
| 4384 | |
| 4385 | cur_arg = 2; |
| 4386 | tcpcheck = (struct tcpcheck_rule *)calloc(1, sizeof(*tcpcheck)); |
| 4387 | tcpcheck->action = TCPCHK_ACT_CONNECT; |
| 4388 | |
| 4389 | /* parsing each parameters to fill up the rule */ |
| 4390 | while (*(ptr_arg = args[cur_arg])) { |
| 4391 | /* tcp port */ |
| 4392 | if (strcmp(args[cur_arg], "port") == 0) { |
| 4393 | if ( (atol(args[cur_arg + 1]) > 65535) || |
| 4394 | (atol(args[cur_arg + 1]) < 1) ){ |
| 4395 | Alert("parsing [%s:%d] : '%s %s %s' expects a valid TCP port (from range 1 to 65535), got %s.\n", |
| 4396 | file, linenum, args[0], args[1], "port", args[cur_arg + 1]); |
| 4397 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4398 | goto out; |
| 4399 | } |
| 4400 | tcpcheck->port = atol(args[cur_arg + 1]); |
| 4401 | cur_arg += 2; |
| 4402 | } |
| 4403 | /* send proxy protocol */ |
| 4404 | else if (strcmp(args[cur_arg], "send-proxy") == 0) { |
| 4405 | tcpcheck->conn_opts |= TCPCHK_OPT_SEND_PROXY; |
| 4406 | cur_arg++; |
| 4407 | } |
| 4408 | #ifdef USE_OPENSSL |
| 4409 | else if (strcmp(args[cur_arg], "ssl") == 0) { |
| 4410 | curproxy->options |= PR_O_TCPCHK_SSL; |
| 4411 | tcpcheck->conn_opts |= TCPCHK_OPT_SSL; |
| 4412 | cur_arg++; |
| 4413 | } |
| 4414 | #endif /* USE_OPENSSL */ |
| 4415 | else { |
| 4416 | #ifdef USE_OPENSSL |
| 4417 | Alert("parsing [%s:%d] : '%s %s' expects 'port', 'send-proxy' or 'ssl' but got '%s' as argument.\n", |
| 4418 | #else /* USE_OPENSSL */ |
| 4419 | Alert("parsing [%s:%d] : '%s %s' expects 'port', 'send-proxy' or but got '%s' as argument.\n", |
| 4420 | #endif /* USE_OPENSSL */ |
| 4421 | file, linenum, args[0], args[1], args[cur_arg]); |
| 4422 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4423 | goto out; |
| 4424 | } |
| 4425 | |
| 4426 | } |
| 4427 | |
| 4428 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 4429 | } |
| 4430 | else if (strcmp(args[1], "send") == 0) { |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 4431 | if (! *(args[2]) ) { |
| 4432 | /* SEND string expected */ |
| 4433 | Alert("parsing [%s:%d] : '%s %s %s' expects <STRING> as argument.\n", |
| 4434 | file, linenum, args[0], args[1], args[2]); |
| 4435 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4436 | goto out; |
| 4437 | } else { |
| 4438 | struct tcpcheck_rule *tcpcheck; |
| 4439 | |
| 4440 | tcpcheck = (struct tcpcheck_rule *)calloc(1, sizeof(*tcpcheck)); |
| 4441 | |
| 4442 | tcpcheck->action = TCPCHK_ACT_SEND; |
| 4443 | tcpcheck->string_len = strlen(args[2]); |
| 4444 | tcpcheck->string = strdup(args[2]); |
| 4445 | tcpcheck->expect_regex = NULL; |
| 4446 | |
| 4447 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 4448 | } |
| 4449 | } |
| 4450 | else if (strcmp(args[1], "send-binary") == 0) { |
| 4451 | if (! *(args[2]) ) { |
| 4452 | /* SEND binary string expected */ |
| 4453 | Alert("parsing [%s:%d] : '%s %s %s' expects <BINARY STRING> as argument.\n", |
| 4454 | file, linenum, args[0], args[1], args[2]); |
| 4455 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4456 | goto out; |
| 4457 | } else { |
| 4458 | struct tcpcheck_rule *tcpcheck; |
| 4459 | char *err = NULL; |
| 4460 | |
| 4461 | tcpcheck = (struct tcpcheck_rule *)calloc(1, sizeof(*tcpcheck)); |
| 4462 | |
| 4463 | tcpcheck->action = TCPCHK_ACT_SEND; |
| 4464 | if (parse_binary(args[2], &tcpcheck->string, &tcpcheck->string_len, &err) == 0) { |
| 4465 | Alert("parsing [%s:%d] : '%s %s %s' expects <BINARY STRING> as argument, but %s\n", |
| 4466 | file, linenum, args[0], args[1], args[2], err); |
| 4467 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4468 | goto out; |
| 4469 | } |
| 4470 | tcpcheck->expect_regex = NULL; |
| 4471 | |
| 4472 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 4473 | } |
| 4474 | } |
| 4475 | else if (strcmp(args[1], "expect") == 0) { |
| 4476 | const char *ptr_arg; |
| 4477 | int cur_arg; |
| 4478 | int inverse = 0; |
| 4479 | |
| 4480 | if (curproxy->options2 & PR_O2_EXP_TYPE) { |
| 4481 | Alert("parsing [%s:%d] : '%s %s' already specified.\n", file, linenum, args[0], args[1]); |
| 4482 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4483 | goto out; |
| 4484 | } |
| 4485 | |
| 4486 | cur_arg = 2; |
| 4487 | /* consider exclamation marks, sole or at the beginning of a word */ |
| 4488 | while (*(ptr_arg = args[cur_arg])) { |
| 4489 | while (*ptr_arg == '!') { |
| 4490 | inverse = !inverse; |
| 4491 | ptr_arg++; |
| 4492 | } |
| 4493 | if (*ptr_arg) |
| 4494 | break; |
| 4495 | cur_arg++; |
| 4496 | } |
| 4497 | /* now ptr_arg points to the beginning of a word past any possible |
| 4498 | * exclamation mark, and cur_arg is the argument which holds this word. |
| 4499 | */ |
| 4500 | if (strcmp(ptr_arg, "binary") == 0) { |
| 4501 | if (!*(args[cur_arg + 1])) { |
| 4502 | Alert("parsing [%s:%d] : '%s %s %s' expects <binary string> as an argument.\n", |
| 4503 | file, linenum, args[0], args[1], ptr_arg); |
| 4504 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4505 | goto out; |
| 4506 | } |
| 4507 | struct tcpcheck_rule *tcpcheck; |
| 4508 | char *err = NULL; |
| 4509 | |
| 4510 | tcpcheck = (struct tcpcheck_rule *)calloc(1, sizeof(*tcpcheck)); |
| 4511 | |
| 4512 | tcpcheck->action = TCPCHK_ACT_EXPECT; |
| 4513 | if (parse_binary(args[cur_arg + 1], &tcpcheck->string, &tcpcheck->string_len, &err) == 0) { |
| 4514 | Alert("parsing [%s:%d] : '%s %s %s' expects <BINARY STRING> as argument, but %s\n", |
| 4515 | file, linenum, args[0], args[1], args[2], err); |
| 4516 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4517 | goto out; |
| 4518 | } |
| 4519 | tcpcheck->expect_regex = NULL; |
| 4520 | tcpcheck->inverse = inverse; |
| 4521 | |
| 4522 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 4523 | } |
| 4524 | else if (strcmp(ptr_arg, "string") == 0) { |
| 4525 | if (!*(args[cur_arg + 1])) { |
| 4526 | Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 4527 | file, linenum, args[0], args[1], ptr_arg); |
| 4528 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4529 | goto out; |
| 4530 | } |
| 4531 | struct tcpcheck_rule *tcpcheck; |
| 4532 | |
| 4533 | tcpcheck = (struct tcpcheck_rule *)calloc(1, sizeof(*tcpcheck)); |
| 4534 | |
| 4535 | tcpcheck->action = TCPCHK_ACT_EXPECT; |
| 4536 | tcpcheck->string_len = strlen(args[cur_arg + 1]); |
| 4537 | tcpcheck->string = strdup(args[cur_arg + 1]); |
| 4538 | tcpcheck->expect_regex = NULL; |
| 4539 | tcpcheck->inverse = inverse; |
| 4540 | |
| 4541 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 4542 | } |
| 4543 | else if (strcmp(ptr_arg, "rstring") == 0) { |
| 4544 | if (!*(args[cur_arg + 1])) { |
| 4545 | Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 4546 | file, linenum, args[0], args[1], ptr_arg); |
| 4547 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4548 | goto out; |
| 4549 | } |
| 4550 | struct tcpcheck_rule *tcpcheck; |
| 4551 | |
| 4552 | tcpcheck = (struct tcpcheck_rule *)calloc(1, sizeof(*tcpcheck)); |
| 4553 | |
| 4554 | tcpcheck->action = TCPCHK_ACT_EXPECT; |
| 4555 | tcpcheck->string_len = 0; |
| 4556 | tcpcheck->string = NULL; |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 4557 | tcpcheck->expect_regex = calloc(1, sizeof(*tcpcheck->expect_regex)); |
| 4558 | error = NULL; |
| 4559 | if (!regex_comp(args[cur_arg + 1], tcpcheck->expect_regex, 1, 1, &error)) { |
| 4560 | Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s': %s.\n", |
| 4561 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1], error); |
| 4562 | free(error); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 4563 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4564 | goto out; |
| 4565 | } |
| 4566 | tcpcheck->inverse = inverse; |
| 4567 | |
| 4568 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 4569 | } |
| 4570 | else { |
| 4571 | Alert("parsing [%s:%d] : '%s %s' only supports [!] 'binary', 'string', 'rstring', found '%s'.\n", |
| 4572 | file, linenum, args[0], args[1], ptr_arg); |
| 4573 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4574 | goto out; |
| 4575 | } |
| 4576 | } |
| 4577 | else { |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 4578 | 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] | 4579 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4580 | goto out; |
| 4581 | } |
| 4582 | } |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 4583 | else if (!strcmp(args[0], "monitor")) { |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 4584 | if (curproxy == &defproxy) { |
| 4585 | 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] | 4586 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4587 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 4588 | } |
| 4589 | |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 4590 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4591 | err_code |= ERR_WARN; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 4592 | |
| 4593 | if (strcmp(args[1], "fail") == 0) { |
| 4594 | /* add a condition to fail monitor requests */ |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 4595 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 4596 | Alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n", |
| 4597 | file, linenum, args[0], args[1]); |
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 | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 4602 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 4603 | Alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition : %s.\n", |
| 4604 | file, linenum, args[0], args[1], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4605 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4606 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 4607 | } |
| 4608 | LIST_ADDQ(&curproxy->mon_fail_cond, &cond->list); |
| 4609 | } |
| 4610 | else { |
| 4611 | 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] | 4612 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4613 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 4614 | } |
| 4615 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4616 | #ifdef TPROXY |
| 4617 | else if (!strcmp(args[0], "transparent")) { |
| 4618 | /* enable transparent proxy connections */ |
| 4619 | curproxy->options |= PR_O_TRANSP; |
| 4620 | } |
| 4621 | #endif |
| 4622 | else if (!strcmp(args[0], "maxconn")) { /* maxconn */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4623 | 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] | 4624 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4625 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4626 | if (*(args[1]) == 0) { |
| 4627 | 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] | 4628 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4629 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4630 | } |
| 4631 | curproxy->maxconn = atol(args[1]); |
| 4632 | } |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 4633 | else if (!strcmp(args[0], "backlog")) { /* backlog */ |
| 4634 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4635 | err_code |= ERR_WARN; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 4636 | |
| 4637 | if (*(args[1]) == 0) { |
| 4638 | 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] | 4639 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4640 | goto out; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 4641 | } |
| 4642 | curproxy->backlog = atol(args[1]); |
| 4643 | } |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 4644 | else if (!strcmp(args[0], "fullconn")) { /* fullconn */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4645 | 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] | 4646 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4647 | |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 4648 | if (*(args[1]) == 0) { |
| 4649 | 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] | 4650 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4651 | goto out; |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 4652 | } |
| 4653 | curproxy->fullconn = atol(args[1]); |
| 4654 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4655 | else if (!strcmp(args[0], "grace")) { /* grace time (ms) */ |
| 4656 | if (*(args[1]) == 0) { |
| 4657 | 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] | 4658 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4659 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4660 | } |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4661 | err = parse_time_err(args[1], &val, TIME_UNIT_MS); |
| 4662 | if (err) { |
| 4663 | Alert("parsing [%s:%d] : unexpected character '%c' in grace time.\n", |
| 4664 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4665 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4666 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4667 | } |
| 4668 | curproxy->grace = val; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4669 | } |
| 4670 | else if (!strcmp(args[0], "dispatch")) { /* dispatch address */ |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4671 | struct sockaddr_storage *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4672 | int port1, port2; |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 4673 | struct protocol *proto; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4674 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4675 | if (curproxy == &defproxy) { |
| 4676 | 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] | 4677 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4678 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4679 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4680 | else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4681 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4682 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 4683 | sk = str2sa_range(args[1], &port1, &port2, &errmsg, NULL); |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4684 | if (!sk) { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 4685 | Alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 4686 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 4687 | goto out; |
| 4688 | } |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 4689 | |
| 4690 | proto = protocol_by_family(sk->ss_family); |
| 4691 | if (!proto || !proto->connect) { |
| 4692 | Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 4693 | file, linenum, args[0], args[1]); |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4694 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4695 | goto out; |
| 4696 | } |
| 4697 | |
| 4698 | if (port1 != port2) { |
| 4699 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'.\n", |
| 4700 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4701 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4702 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4703 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4704 | |
| 4705 | if (!port1) { |
| 4706 | Alert("parsing [%s:%d] : '%s' : missing port number in '%s', <addr:port> expected.\n", |
| 4707 | file, linenum, args[0], args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4708 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4709 | goto out; |
| 4710 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4711 | |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4712 | curproxy->dispatch_addr = *sk; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4713 | curproxy->options |= PR_O_DISPATCH; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4714 | } |
| 4715 | else if (!strcmp(args[0], "balance")) { /* set balancing with optional algorithm */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4716 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4717 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4718 | |
Willy Tarreau | a93c74b | 2012-05-08 18:14:39 +0200 | [diff] [blame] | 4719 | if (backend_parse_balance((const char **)args + 1, &errmsg, curproxy) < 0) { |
| 4720 | Alert("parsing [%s:%d] : %s %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4721 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4722 | goto out; |
Willy Tarreau | 2fcb500 | 2007-05-08 13:35:26 +0200 | [diff] [blame] | 4723 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4724 | } |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 4725 | else if (!strcmp(args[0], "hash-type")) { /* set hashing method */ |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 4726 | /** |
| 4727 | * The syntax for hash-type config element is |
| 4728 | * hash-type {map-based|consistent} [[<algo>] avalanche] |
| 4729 | * |
| 4730 | * The default hash function is sdbm for map-based and sdbm+avalanche for consistent. |
| 4731 | */ |
| 4732 | 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] | 4733 | |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 4734 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 4735 | err_code |= ERR_WARN; |
| 4736 | |
| 4737 | if (strcmp(args[1], "consistent") == 0) { /* use consistent hashing */ |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 4738 | curproxy->lbprm.algo |= BE_LB_HASH_CONS; |
| 4739 | } |
| 4740 | else if (strcmp(args[1], "map-based") == 0) { /* use map-based hashing */ |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 4741 | curproxy->lbprm.algo |= BE_LB_HASH_MAP; |
| 4742 | } |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 4743 | else if (strcmp(args[1], "avalanche") == 0) { |
| 4744 | 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]); |
| 4745 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4746 | goto out; |
Willy Tarreau | 798a39c | 2010-11-24 15:04:29 +0100 | [diff] [blame] | 4747 | } |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 4748 | else { |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 4749 | 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] | 4750 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4751 | goto out; |
| 4752 | } |
Bhaskar | 98634f0 | 2013-10-29 23:30:51 -0400 | [diff] [blame] | 4753 | |
| 4754 | /* set the hash function to use */ |
| 4755 | if (!*args[2]) { |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 4756 | /* the default algo is sdbm */ |
Bhaskar | 98634f0 | 2013-10-29 23:30:51 -0400 | [diff] [blame] | 4757 | curproxy->lbprm.algo |= BE_LB_HFCN_SDBM; |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 4758 | |
| 4759 | /* if consistent with no argument, then avalanche modifier is also applied */ |
| 4760 | if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS) |
| 4761 | curproxy->lbprm.algo |= BE_LB_HMOD_AVAL; |
Bhaskar | 98634f0 | 2013-10-29 23:30:51 -0400 | [diff] [blame] | 4762 | } else { |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 4763 | /* set the hash function */ |
| 4764 | if (!strcmp(args[2], "sdbm")) { |
| 4765 | curproxy->lbprm.algo |= BE_LB_HFCN_SDBM; |
| 4766 | } |
| 4767 | else if (!strcmp(args[2], "djb2")) { |
| 4768 | curproxy->lbprm.algo |= BE_LB_HFCN_DJB2; |
Willy Tarreau | a0f4271 | 2013-11-14 14:30:35 +0100 | [diff] [blame] | 4769 | } else if (!strcmp(args[2], "wt6")) { |
| 4770 | curproxy->lbprm.algo |= BE_LB_HFCN_WT6; |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 4771 | } |
| 4772 | else { |
Willy Tarreau | a0f4271 | 2013-11-14 14:30:35 +0100 | [diff] [blame] | 4773 | 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] | 4774 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4775 | goto out; |
| 4776 | } |
| 4777 | |
| 4778 | /* set the hash modifier */ |
| 4779 | if (!strcmp(args[3], "avalanche")) { |
| 4780 | curproxy->lbprm.algo |= BE_LB_HMOD_AVAL; |
| 4781 | } |
| 4782 | else if (*args[3]) { |
| 4783 | Alert("parsing [%s:%d] : '%s' only supports 'avalanche' as a modifier for hash functions.\n", file, linenum, args[0]); |
| 4784 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4785 | goto out; |
| 4786 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4787 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 4788 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 4789 | else if (strcmp(args[0], "unique-id-format") == 0) { |
| 4790 | if (!*(args[1])) { |
| 4791 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 4792 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4793 | goto out; |
| 4794 | } |
William Lallemand | 3203ff4 | 2012-11-11 17:30:56 +0100 | [diff] [blame] | 4795 | if (*(args[2])) { |
| 4796 | Alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]); |
| 4797 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4798 | goto out; |
| 4799 | } |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 4800 | free(curproxy->conf.uniqueid_format_string); |
| 4801 | curproxy->conf.uniqueid_format_string = strdup(args[1]); |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 4802 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 4803 | free(curproxy->conf.uif_file); |
| 4804 | curproxy->conf.uif_file = strdup(curproxy->conf.args.file); |
| 4805 | curproxy->conf.uif_line = curproxy->conf.args.line; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4806 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 4807 | |
| 4808 | else if (strcmp(args[0], "unique-id-header") == 0) { |
| 4809 | if (!*(args[1])) { |
| 4810 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 4811 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4812 | goto out; |
| 4813 | } |
| 4814 | free(curproxy->header_unique_id); |
| 4815 | curproxy->header_unique_id = strdup(args[1]); |
| 4816 | } |
| 4817 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4818 | else if (strcmp(args[0], "log-format") == 0) { |
| 4819 | if (!*(args[1])) { |
| 4820 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 4821 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4822 | goto out; |
| 4823 | } |
William Lallemand | 3203ff4 | 2012-11-11 17:30:56 +0100 | [diff] [blame] | 4824 | if (*(args[2])) { |
| 4825 | Alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]); |
| 4826 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4827 | goto out; |
| 4828 | } |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 4829 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 4830 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 4831 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 4832 | curproxy->conf.logformat_string != clf_http_log_format) |
| 4833 | free(curproxy->conf.logformat_string); |
| 4834 | curproxy->conf.logformat_string = strdup(args[1]); |
| 4835 | |
| 4836 | free(curproxy->conf.lfs_file); |
| 4837 | curproxy->conf.lfs_file = strdup(curproxy->conf.args.file); |
| 4838 | curproxy->conf.lfs_line = curproxy->conf.args.line; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 4839 | |
| 4840 | /* get a chance to improve log-format error reporting by |
| 4841 | * reporting the correct line-number when possible. |
| 4842 | */ |
| 4843 | if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) { |
| 4844 | Warning("parsing [%s:%d] : backend '%s' : 'log-format' directive is ignored in backends.\n", |
| 4845 | file, linenum, curproxy->id); |
| 4846 | err_code |= ERR_WARN; |
| 4847 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4848 | } |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4849 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4850 | else if (!strcmp(args[0], "log") && kwm == KWM_NO) { |
| 4851 | /* delete previous herited or defined syslog servers */ |
| 4852 | struct logsrv *back; |
| 4853 | |
| 4854 | if (*(args[1]) != 0) { |
| 4855 | Alert("parsing [%s:%d]:%s : 'no log' does not expect arguments.\n", file, linenum, args[1]); |
| 4856 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4857 | goto out; |
| 4858 | } |
| 4859 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4860 | list_for_each_entry_safe(tmplogsrv, back, &curproxy->logsrvs, list) { |
| 4861 | LIST_DEL(&tmplogsrv->list); |
| 4862 | free(tmplogsrv); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4863 | } |
| 4864 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4865 | else if (!strcmp(args[0], "log")) { /* syslog server address */ |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4866 | struct logsrv *logsrv; |
| 4867 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4868 | if (*(args[1]) && *(args[2]) == 0 && !strcmp(args[1], "global")) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4869 | /* copy global.logrsvs linked list to the end of curproxy->logsrvs */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4870 | list_for_each_entry(tmplogsrv, &global.logsrvs, list) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4871 | struct logsrv *node = malloc(sizeof(struct logsrv)); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4872 | memcpy(node, tmplogsrv, sizeof(struct logsrv)); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4873 | LIST_INIT(&node->list); |
| 4874 | LIST_ADDQ(&curproxy->logsrvs, &node->list); |
| 4875 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4876 | } |
| 4877 | else if (*(args[1]) && *(args[2])) { |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 4878 | struct sockaddr_storage *sk; |
| 4879 | int port1, port2; |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 4880 | int arg = 0; |
| 4881 | int len = 0; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4882 | |
| 4883 | logsrv = calloc(1, sizeof(struct logsrv)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4884 | |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 4885 | /* just after the address, a length may be specified */ |
| 4886 | if (strcmp(args[arg+2], "len") == 0) { |
| 4887 | len = atoi(args[arg+3]); |
| 4888 | if (len < 80 || len > 65535) { |
| 4889 | Alert("parsing [%s:%d] : invalid log length '%s', must be between 80 and 65535.\n", |
| 4890 | file, linenum, args[arg+3]); |
| 4891 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4892 | goto out; |
| 4893 | } |
| 4894 | logsrv->maxlen = len; |
| 4895 | |
| 4896 | /* skip these two args */ |
| 4897 | arg += 2; |
| 4898 | } |
| 4899 | else |
| 4900 | logsrv->maxlen = MAX_SYSLOG_LEN; |
| 4901 | |
| 4902 | if (logsrv->maxlen > global.max_syslog_len) { |
| 4903 | global.max_syslog_len = logsrv->maxlen; |
| 4904 | logline = realloc(logline, global.max_syslog_len + 1); |
| 4905 | } |
| 4906 | |
| 4907 | logsrv->facility = get_log_facility(args[arg+2]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4908 | if (logsrv->facility < 0) { |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 4909 | 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] | 4910 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4911 | goto out; |
| 4912 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4913 | } |
| 4914 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4915 | logsrv->level = 7; /* max syslog level = debug */ |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 4916 | if (*(args[arg+3])) { |
| 4917 | logsrv->level = get_log_level(args[arg+3]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4918 | if (logsrv->level < 0) { |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 4919 | 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] | 4920 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4921 | goto out; |
| 4922 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4923 | } |
| 4924 | } |
| 4925 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4926 | logsrv->minlvl = 0; /* limit syslog level to this level (emerg) */ |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 4927 | if (*(args[arg+4])) { |
| 4928 | logsrv->minlvl = get_log_level(args[arg+4]); |
Willy Tarreau | f7f057b | 2013-01-24 00:31:24 +0100 | [diff] [blame] | 4929 | if (logsrv->minlvl < 0) { |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 4930 | 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] | 4931 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4932 | goto out; |
| 4933 | |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 4934 | } |
| 4935 | } |
| 4936 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 4937 | sk = str2sa_range(args[1], &port1, &port2, &errmsg, NULL); |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 4938 | if (!sk) { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 4939 | Alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 4940 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 4941 | goto out; |
| 4942 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4943 | |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 4944 | logsrv->addr = *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4945 | |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 4946 | if (sk->ss_family == AF_INET || sk->ss_family == AF_INET6) { |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4947 | if (port1 != port2) { |
| 4948 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 4949 | file, linenum, args[0], args[1]); |
| 4950 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4951 | goto out; |
| 4952 | } |
| 4953 | |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4954 | if (!port1) |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4955 | set_host_port(&logsrv->addr, SYSLOG_PORT); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4956 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4957 | |
| 4958 | LIST_ADDQ(&curproxy->logsrvs, &logsrv->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4959 | } |
| 4960 | else { |
| 4961 | Alert("parsing [%s:%d] : 'log' expects either <address[:port]> and <facility> or 'global' as arguments.\n", |
| 4962 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4963 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4964 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4965 | } |
| 4966 | } |
| 4967 | 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] | 4968 | int cur_arg; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4969 | int port1, port2; |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4970 | struct sockaddr_storage *sk; |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 4971 | struct protocol *proto; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4972 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4973 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4974 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4975 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4976 | if (!*args[1]) { |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4977 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optionally '%s' <addr>, and '%s' <name>.\n", |
| 4978 | file, linenum, "source", "usesrc", "interface"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4979 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4980 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4981 | } |
Willy Tarreau | 368480c | 2009-03-01 08:27:21 +0100 | [diff] [blame] | 4982 | |
| 4983 | /* we must first clear any optional default setting */ |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4984 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 4985 | free(curproxy->conn_src.iface_name); |
| 4986 | curproxy->conn_src.iface_name = NULL; |
| 4987 | curproxy->conn_src.iface_len = 0; |
Willy Tarreau | 368480c | 2009-03-01 08:27:21 +0100 | [diff] [blame] | 4988 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 4989 | sk = str2sa_range(args[1], &port1, &port2, &errmsg, NULL); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4990 | if (!sk) { |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 4991 | Alert("parsing [%s:%d] : '%s %s' : %s\n", |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 4992 | file, linenum, args[0], args[1], errmsg); |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 4993 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 4994 | goto out; |
| 4995 | } |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 4996 | |
| 4997 | proto = protocol_by_family(sk->ss_family); |
| 4998 | if (!proto || !proto->connect) { |
| 4999 | 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] | 5000 | file, linenum, args[0], args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 5001 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5002 | goto out; |
| 5003 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5004 | |
| 5005 | if (port1 != port2) { |
| 5006 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 5007 | file, linenum, args[0], args[1]); |
| 5008 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5009 | goto out; |
| 5010 | } |
| 5011 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 5012 | curproxy->conn_src.source_addr = *sk; |
| 5013 | curproxy->conn_src.opts |= CO_SRC_BIND; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5014 | |
| 5015 | cur_arg = 2; |
| 5016 | while (*(args[cur_arg])) { |
| 5017 | if (!strcmp(args[cur_arg], "usesrc")) { /* address to use outside */ |
Pieter Baauw | d551fb5 | 2013-05-08 22:49:23 +0200 | [diff] [blame] | 5018 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_TRANSPARENT) |
| 5019 | #if !defined(CONFIG_HAP_TRANSPARENT) |
Willy Tarreau | 9cf8d3f | 2014-05-09 22:56:10 +0200 | [diff] [blame] | 5020 | if (!is_inet_addr(&curproxy->conn_src.source_addr)) { |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5021 | Alert("parsing [%s:%d] : '%s' requires an explicit 'source' address.\n", |
| 5022 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5023 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5024 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5025 | } |
| 5026 | #endif |
| 5027 | if (!*args[cur_arg + 1]) { |
| 5028 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n", |
| 5029 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5030 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5031 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5032 | } |
| 5033 | |
| 5034 | if (!strcmp(args[cur_arg + 1], "client")) { |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 5035 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 5036 | curproxy->conn_src.opts |= CO_SRC_TPROXY_CLI; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5037 | } else if (!strcmp(args[cur_arg + 1], "clientip")) { |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 5038 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 5039 | curproxy->conn_src.opts |= CO_SRC_TPROXY_CIP; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 5040 | } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) { |
| 5041 | char *name, *end; |
| 5042 | |
| 5043 | name = args[cur_arg+1] + 7; |
| 5044 | while (isspace(*name)) |
| 5045 | name++; |
| 5046 | |
| 5047 | end = name; |
| 5048 | while (*end && !isspace(*end) && *end != ',' && *end != ')') |
| 5049 | end++; |
| 5050 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 5051 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 5052 | curproxy->conn_src.opts |= CO_SRC_TPROXY_DYN; |
| 5053 | curproxy->conn_src.bind_hdr_name = calloc(1, end - name + 1); |
| 5054 | curproxy->conn_src.bind_hdr_len = end - name; |
| 5055 | memcpy(curproxy->conn_src.bind_hdr_name, name, end - name); |
| 5056 | curproxy->conn_src.bind_hdr_name[end-name] = '\0'; |
| 5057 | curproxy->conn_src.bind_hdr_occ = -1; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 5058 | |
| 5059 | /* now look for an occurrence number */ |
| 5060 | while (isspace(*end)) |
| 5061 | end++; |
| 5062 | if (*end == ',') { |
| 5063 | end++; |
| 5064 | name = end; |
| 5065 | if (*end == '-') |
| 5066 | end++; |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 5067 | while (isdigit((int)*end)) |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 5068 | end++; |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 5069 | curproxy->conn_src.bind_hdr_occ = strl2ic(name, end-name); |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 5070 | } |
| 5071 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 5072 | if (curproxy->conn_src.bind_hdr_occ < -MAX_HDR_HISTORY) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 5073 | Alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative" |
| 5074 | " occurrences values smaller than %d.\n", |
| 5075 | file, linenum, MAX_HDR_HISTORY); |
| 5076 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5077 | goto out; |
| 5078 | } |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5079 | } else { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 5080 | struct sockaddr_storage *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5081 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 5082 | sk = str2sa_range(args[cur_arg + 1], &port1, &port2, &errmsg, NULL); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 5083 | if (!sk) { |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 5084 | Alert("parsing [%s:%d] : '%s %s' : %s\n", |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 5085 | file, linenum, args[cur_arg], args[cur_arg+1], errmsg); |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 5086 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 5087 | goto out; |
| 5088 | } |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 5089 | |
| 5090 | proto = protocol_by_family(sk->ss_family); |
| 5091 | if (!proto || !proto->connect) { |
| 5092 | Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 5093 | file, linenum, args[cur_arg], args[cur_arg+1]); |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5094 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5095 | goto out; |
| 5096 | } |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 5097 | |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5098 | if (port1 != port2) { |
| 5099 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 5100 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 5101 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5102 | goto out; |
| 5103 | } |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 5104 | curproxy->conn_src.tproxy_addr = *sk; |
| 5105 | curproxy->conn_src.opts |= CO_SRC_TPROXY_ADDR; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5106 | } |
| 5107 | global.last_checks |= LSTCHK_NETADM; |
Pieter Baauw | d551fb5 | 2013-05-08 22:49:23 +0200 | [diff] [blame] | 5108 | #if !defined(CONFIG_HAP_TRANSPARENT) |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5109 | global.last_checks |= LSTCHK_CTTPROXY; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 5110 | #endif |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5111 | #else /* no TPROXY support */ |
| 5112 | 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] | 5113 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5114 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5115 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5116 | #endif |
| 5117 | cur_arg += 2; |
| 5118 | continue; |
Willy Tarreau | 77074d5 | 2006-11-12 23:57:19 +0100 | [diff] [blame] | 5119 | } |
| 5120 | |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5121 | if (!strcmp(args[cur_arg], "interface")) { /* specifically bind to this interface */ |
| 5122 | #ifdef SO_BINDTODEVICE |
| 5123 | if (!*args[cur_arg + 1]) { |
| 5124 | Alert("parsing [%s:%d] : '%s' : missing interface name.\n", |
| 5125 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5126 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5127 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5128 | } |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 5129 | free(curproxy->conn_src.iface_name); |
| 5130 | curproxy->conn_src.iface_name = strdup(args[cur_arg + 1]); |
| 5131 | curproxy->conn_src.iface_len = strlen(curproxy->conn_src.iface_name); |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5132 | global.last_checks |= LSTCHK_NETADM; |
| 5133 | #else |
| 5134 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 5135 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5136 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5137 | goto out; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 5138 | #endif |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5139 | cur_arg += 2; |
| 5140 | continue; |
| 5141 | } |
| 5142 | 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] | 5143 | file, linenum, args[0], "interface", "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5144 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5145 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 5146 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5147 | } |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 5148 | else if (!strcmp(args[0], "usesrc")) { /* address to use outside: needs "source" first */ |
| 5149 | Alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n", |
| 5150 | file, linenum, "usesrc", "source"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5151 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5152 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 5153 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5154 | 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] | 5155 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5156 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 5157 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5158 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5159 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5160 | } |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5161 | |
| 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_REPLACE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5164 | args[0], args[1], args[2], (const char **)args+3); |
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], "reqdel")) { /* delete request header from a regex */ |
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_REMOVE, 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], "reqdeny")) { /* deny 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_DENY, 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 | } |
| 5182 | 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] | 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_PASS, 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 | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5188 | } |
| 5189 | 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] | 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_ALLOW, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5192 | args[0], args[1], NULL, (const char **)args+2); |
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 | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5195 | } |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 5196 | 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] | 5197 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5198 | SMP_OPT_DIR_REQ, ACT_TARPIT, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5199 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5200 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5201 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 5202 | } |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5203 | 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] | 5204 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5205 | SMP_OPT_DIR_REQ, ACT_SETBE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5206 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5207 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5208 | goto out; |
Willy Tarreau | 40bac83 | 2014-04-28 22:37:06 +0200 | [diff] [blame] | 5209 | |
| 5210 | if (!already_warned(WARN_REQSETBE_DEPRECATED)) |
| 5211 | 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] | 5212 | } |
| 5213 | 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] | 5214 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5215 | SMP_OPT_DIR_REQ, ACT_SETBE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5216 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5217 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5218 | goto out; |
Willy Tarreau | 40bac83 | 2014-04-28 22:37:06 +0200 | [diff] [blame] | 5219 | |
| 5220 | if (!already_warned(WARN_REQSETBE_DEPRECATED)) |
| 5221 | 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] | 5222 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5223 | 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] | 5224 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5225 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 5226 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5227 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5228 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5229 | } |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5230 | |
| 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_REPLACE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5233 | args[0], args[1], args[2], (const char **)args+3); |
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], "reqidel")) { /* delete request header from a regex ignoring case */ |
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_REMOVE, 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], "reqideny")) { /* deny 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_DENY, 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 | } |
| 5251 | 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] | 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_PASS, 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 | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5257 | } |
| 5258 | 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] | 5259 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5260 | SMP_OPT_DIR_REQ, ACT_ALLOW, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5261 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5262 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5263 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5264 | } |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 5265 | 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] | 5266 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5267 | SMP_OPT_DIR_REQ, ACT_TARPIT, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5268 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5269 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5270 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 5271 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5272 | else if (!strcmp(args[0], "reqadd")) { /* add request header */ |
Willy Tarreau | f4f0412 | 2010-01-28 18:10:50 +0100 | [diff] [blame] | 5273 | struct cond_wordlist *wl; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5274 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5275 | if (curproxy == &defproxy) { |
| 5276 | 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] | 5277 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5278 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5279 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5280 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5281 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5282 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5283 | if (*(args[1]) == 0) { |
| 5284 | 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] | 5285 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5286 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5287 | } |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5288 | |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 5289 | if ((strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0)) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 5290 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args+2, &errmsg)) == NULL) { |
| 5291 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 5292 | file, linenum, args[0], errmsg); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 5293 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5294 | goto out; |
| 5295 | } |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 5296 | err_code |= warnif_cond_conflicts(cond, |
| 5297 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 5298 | file, linenum); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 5299 | } |
| 5300 | else if (*args[2]) { |
| 5301 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 5302 | file, linenum, args[0], args[2]); |
| 5303 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5304 | goto out; |
| 5305 | } |
| 5306 | |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5307 | wl = calloc(1, sizeof(*wl)); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 5308 | wl->cond = cond; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5309 | wl->s = strdup(args[1]); |
| 5310 | LIST_ADDQ(&curproxy->req_add, &wl->list); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 5311 | warnif_misplaced_reqadd(curproxy, file, linenum, args[0]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5312 | } |
| 5313 | 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] | 5314 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5315 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 5316 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5317 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5318 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5319 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5320 | |
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_REPLACE, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5323 | args[0], args[1], args[2], (const char **)args+3); |
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], "rspdel")) { /* delete response header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5328 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5329 | SMP_OPT_DIR_RES, ACT_REMOVE, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5330 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5331 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5332 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5333 | } |
| 5334 | else if (!strcmp(args[0], "rspdeny")) { /* block response header from a regex */ |
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_DENY, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5337 | args[0], args[1], NULL, (const char **)args+2); |
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], "rspirep")) { /* replace response header from a regex ignoring case */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5342 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5343 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 5344 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5345 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5346 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5347 | } |
| 5348 | |
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_REPLACE, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5351 | args[0], args[1], args[2], (const char **)args+3); |
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], "rspidel")) { /* delete response header from a regex ignoring case */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5356 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5357 | SMP_OPT_DIR_RES, ACT_REMOVE, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5358 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5359 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5360 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5361 | } |
| 5362 | 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] | 5363 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5364 | SMP_OPT_DIR_RES, ACT_DENY, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5365 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5366 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5367 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5368 | } |
| 5369 | else if (!strcmp(args[0], "rspadd")) { /* add response header */ |
Willy Tarreau | f4f0412 | 2010-01-28 18:10:50 +0100 | [diff] [blame] | 5370 | struct cond_wordlist *wl; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5371 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5372 | if (curproxy == &defproxy) { |
| 5373 | 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] | 5374 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5375 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5376 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5377 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5378 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5379 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5380 | if (*(args[1]) == 0) { |
| 5381 | 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] | 5382 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5383 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5384 | } |
| 5385 | |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5386 | if ((strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0)) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 5387 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args+2, &errmsg)) == NULL) { |
| 5388 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 5389 | file, linenum, args[0], errmsg); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5390 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5391 | goto out; |
| 5392 | } |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 5393 | err_code |= warnif_cond_conflicts(cond, |
| 5394 | (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR, |
| 5395 | file, linenum); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5396 | } |
| 5397 | else if (*args[2]) { |
| 5398 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 5399 | file, linenum, args[0], args[2]); |
| 5400 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5401 | goto out; |
| 5402 | } |
| 5403 | |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5404 | wl = calloc(1, sizeof(*wl)); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5405 | wl->cond = cond; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5406 | wl->s = strdup(args[1]); |
| 5407 | LIST_ADDQ(&curproxy->rsp_add, &wl->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5408 | } |
| 5409 | else if (!strcmp(args[0], "errorloc") || |
| 5410 | !strcmp(args[0], "errorloc302") || |
| 5411 | !strcmp(args[0], "errorloc303")) { /* error location */ |
| 5412 | int errnum, errlen; |
| 5413 | char *err; |
| 5414 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5415 | if (warnifnotcap(curproxy, PR_CAP_FE | PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5416 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5417 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5418 | if (*(args[2]) == 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 5419 | Alert("parsing [%s:%d] : <%s> expects <status_code> and <url> as arguments.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5420 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5421 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5422 | } |
| 5423 | |
| 5424 | errnum = atol(args[1]); |
| 5425 | if (!strcmp(args[0], "errorloc303")) { |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 5426 | errlen = strlen(HTTP_303) + strlen(args[2]) + 5; |
| 5427 | err = malloc(errlen); |
| 5428 | 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] | 5429 | } else { |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 5430 | errlen = strlen(HTTP_302) + strlen(args[2]) + 5; |
| 5431 | err = malloc(errlen); |
| 5432 | 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] | 5433 | } |
| 5434 | |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 5435 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) { |
| 5436 | if (http_err_codes[rc] == errnum) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 5437 | chunk_destroy(&curproxy->errmsg[rc]); |
| 5438 | chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 5439 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5440 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5441 | } |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 5442 | |
| 5443 | if (rc >= HTTP_ERR_SIZE) { |
| 5444 | Warning("parsing [%s:%d] : status code %d not handled, error relocation will be ignored.\n", |
| 5445 | file, linenum, errnum); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5446 | free(err); |
| 5447 | } |
| 5448 | } |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5449 | else if (!strcmp(args[0], "errorfile")) { /* error message from a file */ |
| 5450 | int errnum, errlen, fd; |
| 5451 | char *err; |
| 5452 | struct stat stat; |
| 5453 | |
| 5454 | 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] | 5455 | err_code |= ERR_WARN; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5456 | |
| 5457 | if (*(args[2]) == 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 5458 | 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] | 5459 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5460 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5461 | } |
| 5462 | |
| 5463 | fd = open(args[2], O_RDONLY); |
| 5464 | if ((fd < 0) || (fstat(fd, &stat) < 0)) { |
| 5465 | Alert("parsing [%s:%d] : error opening file <%s> for custom error message <%s>.\n", |
| 5466 | file, linenum, args[2], args[1]); |
| 5467 | if (fd >= 0) |
| 5468 | close(fd); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5469 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5470 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5471 | } |
| 5472 | |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 5473 | if (stat.st_size <= global.tune.bufsize) { |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5474 | errlen = stat.st_size; |
| 5475 | } else { |
| 5476 | 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] | 5477 | file, linenum, args[2], global.tune.bufsize); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5478 | err_code |= ERR_WARN; |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 5479 | errlen = global.tune.bufsize; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5480 | } |
| 5481 | |
| 5482 | err = malloc(errlen); /* malloc() must succeed during parsing */ |
| 5483 | errnum = read(fd, err, errlen); |
| 5484 | if (errnum != errlen) { |
| 5485 | Alert("parsing [%s:%d] : error reading file <%s> for custom error message <%s>.\n", |
| 5486 | file, linenum, args[2], args[1]); |
| 5487 | close(fd); |
| 5488 | free(err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5489 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5490 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5491 | } |
| 5492 | close(fd); |
| 5493 | |
| 5494 | errnum = atol(args[1]); |
| 5495 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) { |
| 5496 | if (http_err_codes[rc] == errnum) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 5497 | chunk_destroy(&curproxy->errmsg[rc]); |
| 5498 | chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen); |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5499 | break; |
| 5500 | } |
| 5501 | } |
| 5502 | |
| 5503 | if (rc >= HTTP_ERR_SIZE) { |
| 5504 | Warning("parsing [%s:%d] : status code %d not handled, error customization will be ignored.\n", |
| 5505 | file, linenum, errnum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5506 | err_code |= ERR_WARN; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5507 | free(err); |
| 5508 | } |
| 5509 | } |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5510 | else if (!strcmp(args[0], "compression")) { |
| 5511 | struct comp *comp; |
| 5512 | if (curproxy->comp == NULL) { |
| 5513 | comp = calloc(1, sizeof(struct comp)); |
| 5514 | curproxy->comp = comp; |
| 5515 | } else { |
| 5516 | comp = curproxy->comp; |
| 5517 | } |
| 5518 | |
| 5519 | if (!strcmp(args[1], "algo")) { |
| 5520 | int cur_arg; |
William Lallemand | 8b52bb3 | 2012-11-16 18:06:41 +0100 | [diff] [blame] | 5521 | struct comp_ctx *ctx; |
William Lallemand | 552df67 | 2012-11-07 13:21:47 +0100 | [diff] [blame] | 5522 | |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5523 | cur_arg = 2; |
| 5524 | if (!*args[cur_arg]) { |
| 5525 | Alert("parsing [%s:%d] : '%s' expects <algorithm>\n", |
| 5526 | file, linenum, args[0]); |
| 5527 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5528 | goto out; |
| 5529 | } |
| 5530 | while (*(args[cur_arg])) { |
| 5531 | if (comp_append_algo(comp, args[cur_arg]) < 0) { |
| 5532 | Alert("parsing [%s:%d] : '%s' : '%s' is not a supported algorithm.\n", |
| 5533 | file, linenum, args[0], args[cur_arg]); |
| 5534 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5535 | goto out; |
| 5536 | } |
William Lallemand | 552df67 | 2012-11-07 13:21:47 +0100 | [diff] [blame] | 5537 | if (curproxy->comp->algos->init(&ctx, 9) == 0) { |
| 5538 | curproxy->comp->algos->end(&ctx); |
| 5539 | } else { |
| 5540 | Alert("parsing [%s:%d] : '%s' : Can't init '%s' algorithm.\n", |
| 5541 | file, linenum, args[0], args[cur_arg]); |
| 5542 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5543 | goto out; |
| 5544 | } |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5545 | cur_arg ++; |
| 5546 | continue; |
| 5547 | } |
| 5548 | } |
Willy Tarreau | 70737d1 | 2012-10-27 00:34:28 +0200 | [diff] [blame] | 5549 | else if (!strcmp(args[1], "offload")) { |
| 5550 | comp->offload = 1; |
| 5551 | } |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5552 | else if (!strcmp(args[1], "type")) { |
| 5553 | int cur_arg; |
| 5554 | cur_arg = 2; |
| 5555 | if (!*args[cur_arg]) { |
| 5556 | Alert("parsing [%s:%d] : '%s' expects <type>\n", |
| 5557 | file, linenum, args[0]); |
| 5558 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5559 | goto out; |
| 5560 | } |
| 5561 | while (*(args[cur_arg])) { |
| 5562 | comp_append_type(comp, args[cur_arg]); |
| 5563 | cur_arg ++; |
| 5564 | continue; |
| 5565 | } |
| 5566 | } |
| 5567 | else { |
Willy Tarreau | 70737d1 | 2012-10-27 00:34:28 +0200 | [diff] [blame] | 5568 | Alert("parsing [%s:%d] : '%s' expects 'algo', 'type' or 'offload'\n", |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5569 | file, linenum, args[0]); |
| 5570 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5571 | goto out; |
| 5572 | } |
| 5573 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5574 | else { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 5575 | struct cfg_kw_list *kwl; |
| 5576 | int index; |
| 5577 | |
| 5578 | list_for_each_entry(kwl, &cfg_keywords.list, list) { |
| 5579 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 5580 | if (kwl->kw[index].section != CFG_LISTEN) |
| 5581 | continue; |
| 5582 | if (strcmp(kwl->kw[index].kw, args[0]) == 0) { |
| 5583 | /* prepare error message just in case */ |
Willy Tarreau | 28a47d6 | 2012-09-18 20:02:48 +0200 | [diff] [blame] | 5584 | 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] | 5585 | if (rc < 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 5586 | Alert("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5587 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5588 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 5589 | } |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 5590 | else if (rc > 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 5591 | Warning("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5592 | err_code |= ERR_WARN; |
| 5593 | goto out; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 5594 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5595 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 5596 | } |
| 5597 | } |
| 5598 | } |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5599 | |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5600 | 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] | 5601 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5602 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5603 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5604 | out: |
Willy Tarreau | f4068b6 | 2012-05-08 17:37:49 +0200 | [diff] [blame] | 5605 | free(errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5606 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5607 | } |
| 5608 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5609 | int |
| 5610 | cfg_parse_users(const char *file, int linenum, char **args, int kwm) |
| 5611 | { |
| 5612 | |
| 5613 | int err_code = 0; |
| 5614 | const char *err; |
| 5615 | |
| 5616 | if (!strcmp(args[0], "userlist")) { /* new userlist */ |
| 5617 | struct userlist *newul; |
| 5618 | |
| 5619 | if (!*args[1]) { |
| 5620 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 5621 | file, linenum, args[0]); |
| 5622 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5623 | goto out; |
| 5624 | } |
| 5625 | |
| 5626 | err = invalid_char(args[1]); |
| 5627 | if (err) { |
| 5628 | Alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 5629 | file, linenum, *err, args[0], args[1]); |
| 5630 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5631 | goto out; |
| 5632 | } |
| 5633 | |
| 5634 | for (newul = userlist; newul; newul = newul->next) |
| 5635 | if (!strcmp(newul->name, args[1])) { |
| 5636 | Warning("parsing [%s:%d]: ignoring duplicated userlist '%s'.\n", |
| 5637 | file, linenum, args[1]); |
| 5638 | err_code |= ERR_WARN; |
| 5639 | goto out; |
| 5640 | } |
| 5641 | |
| 5642 | newul = (struct userlist *)calloc(1, sizeof(struct userlist)); |
| 5643 | if (!newul) { |
| 5644 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 5645 | err_code |= ERR_ALERT | ERR_ABORT; |
| 5646 | goto out; |
| 5647 | } |
| 5648 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5649 | newul->name = strdup(args[1]); |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 5650 | if (!newul->name) { |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5651 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 5652 | err_code |= ERR_ALERT | ERR_ABORT; |
| 5653 | goto out; |
| 5654 | } |
| 5655 | |
| 5656 | newul->next = userlist; |
| 5657 | userlist = newul; |
| 5658 | |
| 5659 | } else if (!strcmp(args[0], "group")) { /* new group */ |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 5660 | int cur_arg; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5661 | const char *err; |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 5662 | struct auth_groups *ag; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5663 | |
| 5664 | if (!*args[1]) { |
| 5665 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 5666 | file, linenum, args[0]); |
| 5667 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5668 | goto out; |
| 5669 | } |
| 5670 | |
| 5671 | err = invalid_char(args[1]); |
| 5672 | if (err) { |
| 5673 | Alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 5674 | file, linenum, *err, args[0], args[1]); |
| 5675 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5676 | goto out; |
| 5677 | } |
| 5678 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 5679 | for (ag = userlist->groups; ag; ag = ag->next) |
| 5680 | if (!strcmp(ag->name, args[1])) { |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5681 | Warning("parsing [%s:%d]: ignoring duplicated group '%s' in userlist '%s'.\n", |
| 5682 | file, linenum, args[1], userlist->name); |
| 5683 | err_code |= ERR_ALERT; |
| 5684 | goto out; |
| 5685 | } |
| 5686 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 5687 | ag = calloc(1, sizeof(*ag)); |
| 5688 | if (!ag) { |
| 5689 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 5690 | err_code |= ERR_ALERT | ERR_ABORT; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5691 | goto out; |
| 5692 | } |
| 5693 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 5694 | ag->name = strdup(args[1]); |
| 5695 | if (!ag) { |
| 5696 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 5697 | err_code |= ERR_ALERT | ERR_ABORT; |
| 5698 | goto out; |
| 5699 | } |
| 5700 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5701 | cur_arg = 2; |
| 5702 | |
| 5703 | while (*args[cur_arg]) { |
| 5704 | if (!strcmp(args[cur_arg], "users")) { |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 5705 | ag->groupusers = strdup(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5706 | cur_arg += 2; |
| 5707 | continue; |
| 5708 | } else { |
| 5709 | Alert("parsing [%s:%d]: '%s' only supports 'users' option.\n", |
| 5710 | file, linenum, args[0]); |
| 5711 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5712 | goto out; |
| 5713 | } |
| 5714 | } |
| 5715 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 5716 | ag->next = userlist->groups; |
| 5717 | userlist->groups = ag; |
| 5718 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5719 | } else if (!strcmp(args[0], "user")) { /* new user */ |
| 5720 | struct auth_users *newuser; |
| 5721 | int cur_arg; |
| 5722 | |
| 5723 | if (!*args[1]) { |
| 5724 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 5725 | file, linenum, args[0]); |
| 5726 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5727 | goto out; |
| 5728 | } |
| 5729 | |
| 5730 | for (newuser = userlist->users; newuser; newuser = newuser->next) |
| 5731 | if (!strcmp(newuser->user, args[1])) { |
| 5732 | Warning("parsing [%s:%d]: ignoring duplicated user '%s' in userlist '%s'.\n", |
| 5733 | file, linenum, args[1], userlist->name); |
| 5734 | err_code |= ERR_ALERT; |
| 5735 | goto out; |
| 5736 | } |
| 5737 | |
| 5738 | newuser = (struct auth_users *)calloc(1, sizeof(struct auth_users)); |
| 5739 | if (!newuser) { |
| 5740 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 5741 | err_code |= ERR_ALERT | ERR_ABORT; |
| 5742 | goto out; |
| 5743 | } |
| 5744 | |
| 5745 | newuser->user = strdup(args[1]); |
| 5746 | |
| 5747 | newuser->next = userlist->users; |
| 5748 | userlist->users = newuser; |
| 5749 | |
| 5750 | cur_arg = 2; |
| 5751 | |
| 5752 | while (*args[cur_arg]) { |
| 5753 | if (!strcmp(args[cur_arg], "password")) { |
Cyril Bonté | 1a0191d | 2014-08-29 20:20:02 +0200 | [diff] [blame] | 5754 | #ifdef CONFIG_HAP_CRYPT |
| 5755 | if (!crypt("", args[cur_arg + 1])) { |
| 5756 | Alert("parsing [%s:%d]: the encrypted password used for user '%s' is not supported by crypt(3).\n", |
| 5757 | file, linenum, newuser->user); |
| 5758 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5759 | goto out; |
| 5760 | } |
| 5761 | #else |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5762 | Warning("parsing [%s:%d]: no crypt(3) support compiled, encrypted passwords will not work.\n", |
| 5763 | file, linenum); |
| 5764 | err_code |= ERR_ALERT; |
| 5765 | #endif |
| 5766 | newuser->pass = strdup(args[cur_arg + 1]); |
| 5767 | cur_arg += 2; |
| 5768 | continue; |
| 5769 | } else if (!strcmp(args[cur_arg], "insecure-password")) { |
| 5770 | newuser->pass = strdup(args[cur_arg + 1]); |
| 5771 | newuser->flags |= AU_O_INSECURE; |
| 5772 | cur_arg += 2; |
| 5773 | continue; |
| 5774 | } else if (!strcmp(args[cur_arg], "groups")) { |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 5775 | newuser->u.groups_names = strdup(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5776 | cur_arg += 2; |
| 5777 | continue; |
| 5778 | } else { |
| 5779 | Alert("parsing [%s:%d]: '%s' only supports 'password', 'insecure-password' and 'groups' options.\n", |
| 5780 | file, linenum, args[0]); |
| 5781 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5782 | goto out; |
| 5783 | } |
| 5784 | } |
| 5785 | } else { |
| 5786 | Alert("parsing [%s:%d]: unknown keyword '%s' in '%s' section\n", file, linenum, args[0], "users"); |
| 5787 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5788 | } |
| 5789 | |
| 5790 | out: |
| 5791 | return err_code; |
| 5792 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5793 | |
| 5794 | /* |
| 5795 | * This function reads and parses the configuration file given in the argument. |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5796 | * Returns the error code, 0 if OK, or any combination of : |
| 5797 | * - ERR_ABORT: must abort ASAP |
| 5798 | * - ERR_FATAL: we can continue parsing but not start the service |
| 5799 | * - ERR_WARN: a warning has been emitted |
| 5800 | * - ERR_ALERT: an alert has been emitted |
| 5801 | * Only the two first ones can stop processing, the two others are just |
| 5802 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5803 | */ |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 5804 | int readcfgfile(const char *file) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5805 | { |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5806 | char thisline[LINESIZE]; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5807 | FILE *f; |
| 5808 | int linenum = 0; |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5809 | int err_code = 0; |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 5810 | struct cfg_section *cs = NULL; |
| 5811 | struct cfg_section *ics; |
| 5812 | |
| 5813 | /* Register internal sections */ |
| 5814 | if (!cfg_register_section("listen", cfg_parse_listen) || |
| 5815 | !cfg_register_section("frontend", cfg_parse_listen) || |
| 5816 | !cfg_register_section("backend", cfg_parse_listen) || |
| 5817 | !cfg_register_section("ruleset", cfg_parse_listen) || |
| 5818 | !cfg_register_section("defaults", cfg_parse_listen) || |
| 5819 | !cfg_register_section("global", cfg_parse_global) || |
| 5820 | !cfg_register_section("userlist", cfg_parse_users) || |
| 5821 | !cfg_register_section("peers", cfg_parse_peers)) |
| 5822 | return -1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5823 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5824 | if ((f=fopen(file,"r")) == NULL) |
| 5825 | return -1; |
| 5826 | |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5827 | while (fgets(thisline, sizeof(thisline), f) != NULL) { |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 5828 | int arg, kwm = KWM_STD; |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5829 | char *end; |
| 5830 | char *args[MAX_LINE_ARGS + 1]; |
| 5831 | char *line = thisline; |
| 5832 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5833 | linenum++; |
| 5834 | |
| 5835 | end = line + strlen(line); |
| 5836 | |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5837 | if (end-line == sizeof(thisline)-1 && *(end-1) != '\n') { |
| 5838 | /* Check if we reached the limit and the last char is not \n. |
| 5839 | * Watch out for the last line without the terminating '\n'! |
| 5840 | */ |
| 5841 | Alert("parsing [%s:%d]: line too long, limit: %d.\n", |
Willy Tarreau | 5e4a6f1 | 2009-04-11 19:42:49 +0200 | [diff] [blame] | 5842 | file, linenum, (int)sizeof(thisline)-1); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5843 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5844 | } |
| 5845 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5846 | /* skip leading spaces */ |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 5847 | while (isspace((unsigned char)*line)) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5848 | line++; |
| 5849 | |
| 5850 | arg = 0; |
| 5851 | args[arg] = line; |
| 5852 | |
| 5853 | while (*line && arg < MAX_LINE_ARGS) { |
| 5854 | /* first, we'll replace \\, \<space>, \#, \r, \n, \t, \xXX with their |
| 5855 | * C equivalent value. Other combinations left unchanged (eg: \1). |
| 5856 | */ |
| 5857 | if (*line == '\\') { |
| 5858 | int skip = 0; |
| 5859 | if (line[1] == ' ' || line[1] == '\\' || line[1] == '#') { |
| 5860 | *line = line[1]; |
| 5861 | skip = 1; |
| 5862 | } |
| 5863 | else if (line[1] == 'r') { |
| 5864 | *line = '\r'; |
| 5865 | skip = 1; |
| 5866 | } |
| 5867 | else if (line[1] == 'n') { |
| 5868 | *line = '\n'; |
| 5869 | skip = 1; |
| 5870 | } |
| 5871 | else if (line[1] == 't') { |
| 5872 | *line = '\t'; |
| 5873 | skip = 1; |
| 5874 | } |
| 5875 | else if (line[1] == 'x') { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5876 | if ((line + 3 < end) && ishex(line[2]) && ishex(line[3])) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5877 | unsigned char hex1, hex2; |
| 5878 | hex1 = toupper(line[2]) - '0'; |
| 5879 | hex2 = toupper(line[3]) - '0'; |
| 5880 | if (hex1 > 9) hex1 -= 'A' - '9' - 1; |
| 5881 | if (hex2 > 9) hex2 -= 'A' - '9' - 1; |
| 5882 | *line = (hex1<<4) + hex2; |
| 5883 | skip = 3; |
| 5884 | } |
| 5885 | else { |
| 5886 | 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] | 5887 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5888 | } |
| 5889 | } |
| 5890 | if (skip) { |
Cyril Bonté | dd1b01d | 2009-12-06 13:43:42 +0100 | [diff] [blame] | 5891 | memmove(line + 1, line + 1 + skip, end - (line + skip)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5892 | end -= skip; |
| 5893 | } |
| 5894 | line++; |
| 5895 | } |
| 5896 | else if (*line == '#' || *line == '\n' || *line == '\r') { |
| 5897 | /* end of string, end of loop */ |
| 5898 | *line = 0; |
| 5899 | break; |
| 5900 | } |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 5901 | else if (isspace((unsigned char)*line)) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5902 | /* a non-escaped space is an argument separator */ |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5903 | *line++ = '\0'; |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 5904 | while (isspace((unsigned char)*line)) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5905 | line++; |
| 5906 | args[++arg] = line; |
| 5907 | } |
| 5908 | else { |
| 5909 | line++; |
| 5910 | } |
| 5911 | } |
| 5912 | |
| 5913 | /* empty line */ |
| 5914 | if (!**args) |
| 5915 | continue; |
| 5916 | |
Willy Tarreau | 7bb651e | 2009-11-09 21:16:53 +0100 | [diff] [blame] | 5917 | if (*line) { |
| 5918 | /* we had to stop due to too many args. |
| 5919 | * Let's terminate the string, print the offending part then cut the |
| 5920 | * last arg. |
| 5921 | */ |
| 5922 | while (*line && *line != '#' && *line != '\n' && *line != '\r') |
| 5923 | line++; |
| 5924 | *line = '\0'; |
| 5925 | |
Krzysztof Piotr Oledzki | 500b8f0 | 2009-12-15 22:34:51 +0100 | [diff] [blame] | 5926 | 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] | 5927 | file, linenum, arg + 1, (long)(args[arg] - thisline + 1), args[arg]); |
Willy Tarreau | 7bb651e | 2009-11-09 21:16:53 +0100 | [diff] [blame] | 5928 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5929 | args[arg] = line; |
| 5930 | } |
| 5931 | |
Willy Tarreau | 540abe4 | 2007-05-02 20:50:16 +0200 | [diff] [blame] | 5932 | /* zero out remaining args and ensure that at least one entry |
| 5933 | * is zeroed out. |
| 5934 | */ |
| 5935 | while (++arg <= MAX_LINE_ARGS) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5936 | args[arg] = line; |
| 5937 | } |
| 5938 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 5939 | /* check for keyword modifiers "no" and "default" */ |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5940 | if (!strcmp(args[0], "no")) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5941 | char *tmp; |
| 5942 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 5943 | kwm = KWM_NO; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5944 | tmp = args[0]; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5945 | for (arg=0; *args[arg+1]; arg++) |
| 5946 | args[arg] = args[arg+1]; // shift args after inversion |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5947 | *tmp = '\0'; // fix the next arg to \0 |
| 5948 | args[arg] = tmp; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5949 | } |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 5950 | else if (!strcmp(args[0], "default")) { |
| 5951 | kwm = KWM_DEF; |
| 5952 | for (arg=0; *args[arg+1]; arg++) |
| 5953 | args[arg] = args[arg+1]; // shift args after inversion |
| 5954 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5955 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5956 | if (kwm != KWM_STD && strcmp(args[0], "option") != 0 && \ |
| 5957 | strcmp(args[0], "log") != 0) { |
| 5958 | 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] | 5959 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5960 | } |
| 5961 | |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 5962 | /* detect section start */ |
| 5963 | list_for_each_entry(ics, §ions, list) { |
| 5964 | if (strcmp(args[0], ics->section_name) == 0) { |
| 5965 | cursection = ics->section_name; |
| 5966 | cs = ics; |
| 5967 | break; |
| 5968 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 5969 | } |
| 5970 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5971 | /* else it's a section keyword */ |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 5972 | if (cs) |
| 5973 | err_code |= cs->section_parser(file, linenum, args, kwm); |
| 5974 | else { |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5975 | 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] | 5976 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5977 | } |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5978 | |
| 5979 | if (err_code & ERR_ABORT) |
| 5980 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5981 | } |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5982 | cursection = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5983 | fclose(f); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5984 | return err_code; |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5985 | } |
| 5986 | |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 5987 | /* This function propagates processes from frontend <from> to backend <to> so |
| 5988 | * that it is always guaranteed that a backend pointed to by a frontend is |
| 5989 | * bound to all of its processes. After that, if the target is a "listen" |
| 5990 | * instance, the function recursively descends the target's own targets along |
| 5991 | * default_backend, use_backend rules, and reqsetbe rules. Since the bits are |
| 5992 | * checked first to ensure that <to> is already bound to all processes of |
| 5993 | * <from>, there is no risk of looping and we ensure to follow the shortest |
| 5994 | * path to the destination. |
| 5995 | * |
| 5996 | * It is possible to set <to> to NULL for the first call so that the function |
| 5997 | * takes care of visiting the initial frontend in <from>. |
| 5998 | * |
| 5999 | * It is important to note that the function relies on the fact that all names |
| 6000 | * have already been resolved. |
| 6001 | */ |
| 6002 | void propagate_processes(struct proxy *from, struct proxy *to) |
| 6003 | { |
| 6004 | struct switching_rule *rule; |
| 6005 | struct hdr_exp *exp; |
| 6006 | |
| 6007 | if (to) { |
| 6008 | /* check whether we need to go down */ |
| 6009 | if (from->bind_proc && |
| 6010 | (from->bind_proc & to->bind_proc) == from->bind_proc) |
| 6011 | return; |
| 6012 | |
| 6013 | if (!from->bind_proc && !to->bind_proc) |
| 6014 | return; |
| 6015 | |
| 6016 | to->bind_proc = from->bind_proc ? |
| 6017 | (to->bind_proc | from->bind_proc) : 0; |
| 6018 | |
| 6019 | /* now propagate down */ |
| 6020 | from = to; |
| 6021 | } |
| 6022 | |
| 6023 | if (!from->cap & PR_CAP_FE) |
| 6024 | return; |
| 6025 | |
| 6026 | /* default_backend */ |
| 6027 | if (from->defbe.be) |
| 6028 | propagate_processes(from, from->defbe.be); |
| 6029 | |
| 6030 | /* use_backend */ |
| 6031 | list_for_each_entry(rule, &from->switching_rules, list) { |
| 6032 | to = rule->be.backend; |
| 6033 | propagate_processes(from, to); |
| 6034 | } |
| 6035 | |
| 6036 | /* reqsetbe */ |
| 6037 | for (exp = from->req_exp; exp != NULL; exp = exp->next) { |
| 6038 | if (exp->action != ACT_SETBE) |
| 6039 | continue; |
| 6040 | to = (struct proxy *)exp->replace; |
| 6041 | propagate_processes(from, to); |
| 6042 | } |
| 6043 | } |
| 6044 | |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6045 | /* |
| 6046 | * Returns the error code, 0 if OK, or any combination of : |
| 6047 | * - ERR_ABORT: must abort ASAP |
| 6048 | * - ERR_FATAL: we can continue parsing but not start the service |
| 6049 | * - ERR_WARN: a warning has been emitted |
| 6050 | * - ERR_ALERT: an alert has been emitted |
| 6051 | * Only the two first ones can stop processing, the two others are just |
| 6052 | * indicators. |
| 6053 | */ |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6054 | int check_config_validity() |
| 6055 | { |
| 6056 | int cfgerr = 0; |
| 6057 | struct proxy *curproxy = NULL; |
| 6058 | struct server *newsrv = NULL; |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6059 | int err_code = 0; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6060 | unsigned int next_pxid = 1; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6061 | struct bind_conf *bind_conf; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6062 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6063 | bind_conf = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6064 | /* |
| 6065 | * Now, check for the integrity of all that we have collected. |
| 6066 | */ |
| 6067 | |
| 6068 | /* will be needed further to delay some tasks */ |
Willy Tarreau | b0b37bc | 2008-06-23 14:00:57 +0200 | [diff] [blame] | 6069 | tv_update_date(0,1); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6070 | |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 6071 | if (!global.tune.max_http_hdr) |
| 6072 | global.tune.max_http_hdr = MAX_HTTP_HDR; |
| 6073 | |
| 6074 | if (!global.tune.cookie_len) |
| 6075 | global.tune.cookie_len = CAPTURE_LEN; |
| 6076 | |
| 6077 | pool2_capture = create_pool("capture", global.tune.cookie_len, MEM_F_SHARED); |
| 6078 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6079 | /* Post initialisation of the users and groups lists. */ |
| 6080 | err_code = userlist_postinit(); |
| 6081 | if (err_code != ERR_NONE) |
| 6082 | goto out; |
| 6083 | |
Willy Tarreau | 55bc0f8 | 2009-03-15 14:51:53 +0100 | [diff] [blame] | 6084 | /* first, we will invert the proxy list order */ |
| 6085 | curproxy = NULL; |
| 6086 | while (proxy) { |
| 6087 | struct proxy *next; |
| 6088 | |
| 6089 | next = proxy->next; |
| 6090 | proxy->next = curproxy; |
| 6091 | curproxy = proxy; |
| 6092 | if (!next) |
| 6093 | break; |
| 6094 | proxy = next; |
| 6095 | } |
| 6096 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6097 | while (curproxy != NULL) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6098 | struct switching_rule *rule; |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 6099 | struct server_rule *srule; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6100 | struct sticking_rule *mrule; |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 6101 | struct tcp_rule *trule; |
Willy Tarreau | 09448f7 | 2014-06-25 18:12:15 +0200 | [diff] [blame] | 6102 | struct http_req_rule *hrqrule; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 6103 | struct listener *listener; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6104 | unsigned int next_id; |
Willy Tarreau | 16a2147 | 2012-11-19 12:39:59 +0100 | [diff] [blame] | 6105 | int nbproc; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6106 | |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 6107 | if (curproxy->uuid < 0) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6108 | /* proxy ID not set, use automatic numbering with first |
| 6109 | * spare entry starting with next_pxid. |
| 6110 | */ |
| 6111 | next_pxid = get_next_id(&used_proxy_id, next_pxid); |
| 6112 | curproxy->conf.id.key = curproxy->uuid = next_pxid; |
| 6113 | eb32_insert(&used_proxy_id, &curproxy->conf.id); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6114 | } |
Krzysztof Piotr Oledzki | df5cb9f | 2010-02-05 20:58:27 +0100 | [diff] [blame] | 6115 | next_pxid++; |
| 6116 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6117 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6118 | if (curproxy->state == PR_STSTOPPED) { |
Willy Tarreau | da250db | 2008-10-12 12:07:48 +0200 | [diff] [blame] | 6119 | /* ensure we don't keep listeners uselessly bound */ |
| 6120 | stop_proxy(curproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6121 | curproxy = curproxy->next; |
| 6122 | continue; |
| 6123 | } |
| 6124 | |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 6125 | /* Check multi-process mode compatibility for the current proxy */ |
| 6126 | |
| 6127 | if (curproxy->bind_proc) { |
| 6128 | /* an explicit bind-process was specified, let's check how many |
| 6129 | * processes remain. |
| 6130 | */ |
| 6131 | nbproc = popcount(curproxy->bind_proc); |
| 6132 | |
| 6133 | curproxy->bind_proc &= nbits(global.nbproc); |
| 6134 | if (!curproxy->bind_proc && nbproc == 1) { |
| 6135 | 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); |
| 6136 | curproxy->bind_proc = 1; |
| 6137 | } |
| 6138 | else if (!curproxy->bind_proc && nbproc > 1) { |
| 6139 | 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); |
| 6140 | curproxy->bind_proc = 0; |
| 6141 | } |
| 6142 | } |
| 6143 | |
Willy Tarreau | 3d20958 | 2014-05-09 17:06:11 +0200 | [diff] [blame] | 6144 | /* check and reduce the bind-proc of each listener */ |
| 6145 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
| 6146 | unsigned long mask; |
| 6147 | |
| 6148 | if (!bind_conf->bind_proc) |
| 6149 | continue; |
| 6150 | |
| 6151 | mask = nbits(global.nbproc); |
| 6152 | if (curproxy->bind_proc) |
| 6153 | mask &= curproxy->bind_proc; |
| 6154 | /* mask cannot be null here thanks to the previous checks */ |
| 6155 | |
| 6156 | nbproc = popcount(bind_conf->bind_proc); |
| 6157 | bind_conf->bind_proc &= mask; |
| 6158 | |
| 6159 | if (!bind_conf->bind_proc && nbproc == 1) { |
| 6160 | 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", |
| 6161 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
| 6162 | bind_conf->bind_proc = mask & ~(mask - 1); |
| 6163 | } |
| 6164 | else if (!bind_conf->bind_proc && nbproc > 1) { |
| 6165 | 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", |
| 6166 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
| 6167 | bind_conf->bind_proc = 0; |
| 6168 | } |
| 6169 | } |
| 6170 | |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 6171 | /* here, if bind_proc is null, it means no limit, otherwise it's explicit. |
| 6172 | * We now check how many processes the proxy will effectively run on. |
| 6173 | */ |
| 6174 | |
| 6175 | nbproc = global.nbproc; |
| 6176 | if (curproxy->bind_proc) |
| 6177 | nbproc = popcount(curproxy->bind_proc & nbits(global.nbproc)); |
| 6178 | |
| 6179 | if (global.nbproc > 1 && curproxy->table.peers.name) { |
| 6180 | Alert("Proxy '%s': peers can't be used in multi-process mode (nbproc > 1).\n", |
| 6181 | curproxy->id); |
| 6182 | cfgerr++; |
| 6183 | } |
Willy Tarreau | 16a2147 | 2012-11-19 12:39:59 +0100 | [diff] [blame] | 6184 | |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 6185 | switch (curproxy->mode) { |
| 6186 | case PR_MODE_HEALTH: |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6187 | cfgerr += proxy_cfg_ensure_no_http(curproxy); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 6188 | if (!(curproxy->cap & PR_CAP_FE)) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6189 | Alert("config : %s '%s' cannot be in health mode as it has no frontend capability.\n", |
| 6190 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 6191 | cfgerr++; |
| 6192 | } |
| 6193 | |
| 6194 | if (curproxy->srv != NULL) |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6195 | Warning("config : servers will be ignored for %s '%s'.\n", |
| 6196 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 6197 | break; |
| 6198 | |
| 6199 | case PR_MODE_TCP: |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6200 | cfgerr += proxy_cfg_ensure_no_http(curproxy); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 6201 | break; |
| 6202 | |
| 6203 | case PR_MODE_HTTP: |
Willy Tarreau | 25320b2 | 2013-03-24 07:22:08 +0100 | [diff] [blame] | 6204 | curproxy->http_needed = 1; |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 6205 | break; |
| 6206 | } |
| 6207 | |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 6208 | if ((curproxy->cap & PR_CAP_BE) && (curproxy->mode != PR_MODE_HEALTH)) { |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6209 | if (curproxy->lbprm.algo & BE_LB_KIND) { |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 6210 | if (curproxy->options & PR_O_TRANSP) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6211 | Alert("config : %s '%s' cannot use both transparent and balance mode.\n", |
| 6212 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 6213 | cfgerr++; |
| 6214 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6215 | #ifdef WE_DONT_SUPPORT_SERVERLESS_LISTENERS |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 6216 | else if (curproxy->srv == NULL) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6217 | Alert("config : %s '%s' needs at least 1 server in balance mode.\n", |
| 6218 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 6219 | cfgerr++; |
| 6220 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6221 | #endif |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 6222 | else if (curproxy->options & PR_O_DISPATCH) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6223 | Warning("config : dispatch address of %s '%s' will be ignored in balance mode.\n", |
| 6224 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6225 | err_code |= ERR_WARN; |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 6226 | } |
| 6227 | } |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 6228 | 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] | 6229 | /* If no LB algo is set in a backend, and we're not in |
| 6230 | * transparent mode, dispatch mode nor proxy mode, we |
| 6231 | * want to use balance roundrobin by default. |
| 6232 | */ |
| 6233 | curproxy->lbprm.algo &= ~BE_LB_ALGO; |
| 6234 | curproxy->lbprm.algo |= BE_LB_ALGO_RR; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6235 | } |
| 6236 | } |
Willy Tarreau | 193cf93 | 2007-09-17 10:17:23 +0200 | [diff] [blame] | 6237 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 6238 | if (curproxy->options & PR_O_DISPATCH) |
| 6239 | curproxy->options &= ~(PR_O_TRANSP | PR_O_HTTP_PROXY); |
| 6240 | else if (curproxy->options & PR_O_HTTP_PROXY) |
| 6241 | curproxy->options &= ~(PR_O_DISPATCH | PR_O_TRANSP); |
| 6242 | else if (curproxy->options & PR_O_TRANSP) |
| 6243 | curproxy->options &= ~(PR_O_DISPATCH | PR_O_HTTP_PROXY); |
Willy Tarreau | 8293658 | 2007-11-30 15:20:09 +0100 | [diff] [blame] | 6244 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 6245 | if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_HTTP_CHK) { |
| 6246 | if (curproxy->options & PR_O_DISABLE404) { |
| 6247 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n", |
| 6248 | "disable-on-404", proxy_type_str(curproxy), curproxy->id); |
| 6249 | err_code |= ERR_WARN; |
| 6250 | curproxy->options &= ~PR_O_DISABLE404; |
| 6251 | } |
| 6252 | if (curproxy->options2 & PR_O2_CHK_SNDST) { |
| 6253 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n", |
| 6254 | "send-state", proxy_type_str(curproxy), curproxy->id); |
| 6255 | err_code |= ERR_WARN; |
| 6256 | curproxy->options &= ~PR_O2_CHK_SNDST; |
| 6257 | } |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 6258 | } |
| 6259 | |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 6260 | if ((curproxy->options2 & PR_O2_CHK_ANY) == PR_O2_EXT_CHK) { |
| 6261 | if (!global.external_check) { |
| 6262 | Alert("Proxy '%s' : '%s' unable to find required 'global.external-check'.\n", |
| 6263 | curproxy->id, "option external-check"); |
| 6264 | cfgerr++; |
| 6265 | } |
| 6266 | if (!curproxy->check_command) { |
| 6267 | Alert("Proxy '%s' : '%s' unable to find required 'external-check command'.\n", |
| 6268 | curproxy->id, "option external-check"); |
| 6269 | cfgerr++; |
| 6270 | } |
| 6271 | } |
| 6272 | |
| 6273 | if (curproxy->check_command) { |
| 6274 | int clear = 0; |
| 6275 | if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_EXT_CHK) { |
| 6276 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option external-check').\n", |
| 6277 | "external-check command", proxy_type_str(curproxy), curproxy->id); |
| 6278 | err_code |= ERR_WARN; |
| 6279 | clear = 1; |
| 6280 | } |
| 6281 | if (curproxy->check_command[0] != '/' && !curproxy->check_path) { |
| 6282 | Alert("Proxy '%s': '%s' does not have a leading '/' and 'external-command path' is not set.\n", |
| 6283 | curproxy->id, "external-check command"); |
| 6284 | cfgerr++; |
| 6285 | } |
| 6286 | if (clear) { |
| 6287 | free(curproxy->check_command); |
| 6288 | curproxy->check_command = NULL; |
| 6289 | } |
| 6290 | } |
| 6291 | |
| 6292 | if (curproxy->check_path) { |
| 6293 | if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_EXT_CHK) { |
| 6294 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option external-check').\n", |
| 6295 | "external-check path", proxy_type_str(curproxy), curproxy->id); |
| 6296 | err_code |= ERR_WARN; |
| 6297 | free(curproxy->check_path); |
| 6298 | curproxy->check_path = NULL; |
| 6299 | } |
| 6300 | } |
| 6301 | |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 6302 | /* if a default backend was specified, let's find it */ |
| 6303 | if (curproxy->defbe.name) { |
| 6304 | struct proxy *target; |
| 6305 | |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 6306 | target = findproxy_mode(curproxy->defbe.name, curproxy->mode, PR_CAP_BE); |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6307 | if (!target) { |
| 6308 | Alert("Proxy '%s': unable to find required default_backend: '%s'.\n", |
| 6309 | curproxy->id, curproxy->defbe.name); |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 6310 | cfgerr++; |
| 6311 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6312 | Alert("Proxy '%s': loop detected for default_backend: '%s'.\n", |
| 6313 | curproxy->id, curproxy->defbe.name); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6314 | cfgerr++; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 6315 | } else { |
| 6316 | free(curproxy->defbe.name); |
| 6317 | curproxy->defbe.be = target; |
Willy Tarreau | ff67813 | 2012-02-13 14:32:34 +0100 | [diff] [blame] | 6318 | |
| 6319 | /* Emit a warning if this proxy also has some servers */ |
| 6320 | if (curproxy->srv) { |
| 6321 | Warning("In proxy '%s', the 'default_backend' rule always has precedence over the servers, which will never be used.\n", |
| 6322 | curproxy->id); |
| 6323 | err_code |= ERR_WARN; |
| 6324 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6325 | } |
| 6326 | } |
| 6327 | |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 6328 | /* find the target proxy in setbe */ |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 6329 | if (curproxy->mode == PR_MODE_HTTP && curproxy->req_exp != NULL) { |
| 6330 | /* map jump target for ACT_SETBE in req_rep chain */ |
| 6331 | struct hdr_exp *exp; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 6332 | for (exp = curproxy->req_exp; exp != NULL; exp = exp->next) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6333 | struct proxy *target; |
| 6334 | |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 6335 | if (exp->action != ACT_SETBE) |
| 6336 | continue; |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6337 | |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 6338 | target = findproxy_mode(exp->replace, PR_MODE_HTTP, PR_CAP_BE); |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6339 | if (!target) { |
| 6340 | Alert("Proxy '%s': unable to find required setbe: '%s'.\n", |
| 6341 | curproxy->id, exp->replace); |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 6342 | cfgerr++; |
| 6343 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6344 | Alert("Proxy '%s': loop detected for setbe: '%s'.\n", |
| 6345 | curproxy->id, exp->replace); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 6346 | cfgerr++; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 6347 | } else { |
| 6348 | free((void *)exp->replace); |
| 6349 | exp->replace = (const char *)target; |
| 6350 | } |
| 6351 | } |
| 6352 | } |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6353 | |
| 6354 | /* find the target proxy for 'use_backend' rules */ |
| 6355 | list_for_each_entry(rule, &curproxy->switching_rules, list) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6356 | struct proxy *target; |
Bertrand Jacquin | 702d44f | 2013-11-19 11:43:06 +0100 | [diff] [blame] | 6357 | struct logformat_node *node; |
| 6358 | char *pxname; |
| 6359 | |
| 6360 | /* Try to parse the string as a log format expression. If the result |
| 6361 | * of the parsing is only one entry containing a simple string, then |
| 6362 | * it's a standard string corresponding to a static rule, thus the |
| 6363 | * parsing is cancelled and be.name is restored to be resolved. |
| 6364 | */ |
| 6365 | pxname = rule->be.name; |
| 6366 | LIST_INIT(&rule->be.expr); |
| 6367 | parse_logformat_string(pxname, curproxy, &rule->be.expr, 0, SMP_VAL_FE_HRQ_HDR, |
| 6368 | curproxy->conf.args.file, curproxy->conf.args.line); |
| 6369 | node = LIST_NEXT(&rule->be.expr, struct logformat_node *, list); |
| 6370 | |
| 6371 | if (!LIST_ISEMPTY(&rule->be.expr)) { |
| 6372 | if (node->type != LOG_FMT_TEXT || node->list.n != &rule->be.expr) { |
| 6373 | rule->dynamic = 1; |
| 6374 | free(pxname); |
| 6375 | continue; |
| 6376 | } |
| 6377 | /* simple string: free the expression and fall back to static rule */ |
| 6378 | free(node->arg); |
| 6379 | free(node); |
| 6380 | } |
| 6381 | |
| 6382 | rule->dynamic = 0; |
| 6383 | rule->be.name = pxname; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6384 | |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 6385 | target = findproxy_mode(rule->be.name, curproxy->mode, PR_CAP_BE); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6386 | |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6387 | if (!target) { |
| 6388 | Alert("Proxy '%s': unable to find required use_backend: '%s'.\n", |
| 6389 | curproxy->id, rule->be.name); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6390 | cfgerr++; |
| 6391 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6392 | Alert("Proxy '%s': loop detected for use_backend: '%s'.\n", |
| 6393 | curproxy->id, rule->be.name); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6394 | cfgerr++; |
| 6395 | } else { |
| 6396 | free((void *)rule->be.name); |
| 6397 | rule->be.backend = target; |
| 6398 | } |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 6399 | } |
| 6400 | |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 6401 | /* find the target server for 'use_server' rules */ |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 6402 | list_for_each_entry(srule, &curproxy->server_rules, list) { |
| 6403 | struct server *target = findserver(curproxy, srule->srv.name); |
| 6404 | |
| 6405 | if (!target) { |
| 6406 | Alert("config : %s '%s' : unable to find server '%s' referenced in a 'use-server' rule.\n", |
| 6407 | proxy_type_str(curproxy), curproxy->id, srule->srv.name); |
| 6408 | cfgerr++; |
| 6409 | continue; |
| 6410 | } |
| 6411 | free((void *)srule->srv.name); |
| 6412 | srule->srv.ptr = target; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6413 | } |
| 6414 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6415 | /* find the target table for 'stick' rules */ |
| 6416 | list_for_each_entry(mrule, &curproxy->sticking_rules, list) { |
| 6417 | struct proxy *target; |
| 6418 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 6419 | curproxy->be_req_ana |= AN_REQ_STICKING_RULES; |
| 6420 | if (mrule->flags & STK_IS_STORE) |
| 6421 | curproxy->be_rsp_ana |= AN_RES_STORE_RULES; |
| 6422 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6423 | if (mrule->table.name) |
Willy Tarreau | c00cdc2 | 2010-06-06 16:48:26 +0200 | [diff] [blame] | 6424 | target = findproxy(mrule->table.name, 0); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6425 | else |
| 6426 | target = curproxy; |
| 6427 | |
| 6428 | if (!target) { |
| 6429 | Alert("Proxy '%s': unable to find stick-table '%s'.\n", |
| 6430 | curproxy->id, mrule->table.name); |
| 6431 | cfgerr++; |
| 6432 | } |
| 6433 | else if (target->table.size == 0) { |
| 6434 | Alert("Proxy '%s': stick-table '%s' used but not configured.\n", |
| 6435 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 6436 | cfgerr++; |
| 6437 | } |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 6438 | else if (!stktable_compatible_sample(mrule->expr, target->table.type)) { |
| 6439 | 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] | 6440 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 6441 | cfgerr++; |
| 6442 | } |
| 6443 | else { |
| 6444 | free((void *)mrule->table.name); |
| 6445 | mrule->table.t = &(target->table); |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 6446 | stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID, NULL); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6447 | } |
| 6448 | } |
| 6449 | |
| 6450 | /* find the target table for 'store response' rules */ |
| 6451 | list_for_each_entry(mrule, &curproxy->storersp_rules, list) { |
| 6452 | struct proxy *target; |
| 6453 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 6454 | curproxy->be_rsp_ana |= AN_RES_STORE_RULES; |
| 6455 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6456 | if (mrule->table.name) |
Willy Tarreau | c00cdc2 | 2010-06-06 16:48:26 +0200 | [diff] [blame] | 6457 | target = findproxy(mrule->table.name, 0); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6458 | else |
| 6459 | target = curproxy; |
| 6460 | |
| 6461 | if (!target) { |
| 6462 | Alert("Proxy '%s': unable to find store table '%s'.\n", |
| 6463 | curproxy->id, mrule->table.name); |
| 6464 | cfgerr++; |
| 6465 | } |
| 6466 | else if (target->table.size == 0) { |
| 6467 | Alert("Proxy '%s': stick-table '%s' used but not configured.\n", |
| 6468 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 6469 | cfgerr++; |
| 6470 | } |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 6471 | else if (!stktable_compatible_sample(mrule->expr, target->table.type)) { |
| 6472 | 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] | 6473 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 6474 | cfgerr++; |
| 6475 | } |
| 6476 | else { |
| 6477 | free((void *)mrule->table.name); |
| 6478 | mrule->table.t = &(target->table); |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 6479 | stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID, NULL); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6480 | } |
| 6481 | } |
| 6482 | |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 6483 | /* find the target table for 'tcp-request' layer 4 rules */ |
| 6484 | list_for_each_entry(trule, &curproxy->tcp_req.l4_rules, list) { |
| 6485 | struct proxy *target; |
| 6486 | |
Willy Tarreau | b4c8493 | 2013-07-23 19:15:30 +0200 | [diff] [blame] | 6487 | 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] | 6488 | continue; |
| 6489 | |
| 6490 | if (trule->act_prm.trk_ctr.table.n) |
| 6491 | target = findproxy(trule->act_prm.trk_ctr.table.n, 0); |
| 6492 | else |
| 6493 | target = curproxy; |
| 6494 | |
| 6495 | if (!target) { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6496 | Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n", |
| 6497 | curproxy->id, trule->act_prm.trk_ctr.table.n, |
Willy Tarreau | 34c2fb6 | 2013-12-02 23:29:05 +0100 | [diff] [blame] | 6498 | tcp_trk_idx(trule->action)); |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 6499 | cfgerr++; |
| 6500 | } |
| 6501 | else if (target->table.size == 0) { |
| 6502 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
| 6503 | curproxy->id, trule->act_prm.trk_ctr.table.n ? trule->act_prm.trk_ctr.table.n : curproxy->id); |
| 6504 | cfgerr++; |
| 6505 | } |
Willy Tarreau | 5f53de7 | 2012-12-12 00:25:44 +0100 | [diff] [blame] | 6506 | else if (!stktable_compatible_sample(trule->act_prm.trk_ctr.expr, target->table.type)) { |
| 6507 | Alert("Proxy '%s': stick-table '%s' uses a type incompatible with the 'track-sc%d' rule.\n", |
| 6508 | 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] | 6509 | tcp_trk_idx(trule->action)); |
Willy Tarreau | 5f53de7 | 2012-12-12 00:25:44 +0100 | [diff] [blame] | 6510 | cfgerr++; |
| 6511 | } |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 6512 | else { |
| 6513 | free(trule->act_prm.trk_ctr.table.n); |
| 6514 | trule->act_prm.trk_ctr.table.t = &target->table; |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6515 | /* 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] | 6516 | * to pass a list of counters to track and allocate them right here using |
| 6517 | * stktable_alloc_data_type(). |
| 6518 | */ |
| 6519 | } |
| 6520 | } |
| 6521 | |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 6522 | /* find the target table for 'tcp-request' layer 6 rules */ |
| 6523 | list_for_each_entry(trule, &curproxy->tcp_req.inspect_rules, list) { |
| 6524 | struct proxy *target; |
| 6525 | |
Willy Tarreau | b4c8493 | 2013-07-23 19:15:30 +0200 | [diff] [blame] | 6526 | 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] | 6527 | continue; |
| 6528 | |
| 6529 | if (trule->act_prm.trk_ctr.table.n) |
| 6530 | target = findproxy(trule->act_prm.trk_ctr.table.n, 0); |
| 6531 | else |
| 6532 | target = curproxy; |
| 6533 | |
| 6534 | if (!target) { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6535 | Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n", |
| 6536 | curproxy->id, trule->act_prm.trk_ctr.table.n, |
Willy Tarreau | 34c2fb6 | 2013-12-02 23:29:05 +0100 | [diff] [blame] | 6537 | tcp_trk_idx(trule->action)); |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 6538 | cfgerr++; |
| 6539 | } |
| 6540 | else if (target->table.size == 0) { |
| 6541 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
| 6542 | curproxy->id, trule->act_prm.trk_ctr.table.n ? trule->act_prm.trk_ctr.table.n : curproxy->id); |
| 6543 | cfgerr++; |
| 6544 | } |
Willy Tarreau | 5f53de7 | 2012-12-12 00:25:44 +0100 | [diff] [blame] | 6545 | else if (!stktable_compatible_sample(trule->act_prm.trk_ctr.expr, target->table.type)) { |
| 6546 | Alert("Proxy '%s': stick-table '%s' uses a type incompatible with the 'track-sc%d' rule.\n", |
| 6547 | 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] | 6548 | tcp_trk_idx(trule->action)); |
Willy Tarreau | 5f53de7 | 2012-12-12 00:25:44 +0100 | [diff] [blame] | 6549 | cfgerr++; |
| 6550 | } |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 6551 | else { |
| 6552 | free(trule->act_prm.trk_ctr.table.n); |
| 6553 | trule->act_prm.trk_ctr.table.t = &target->table; |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6554 | /* 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] | 6555 | * to pass a list of counters to track and allocate them right here using |
| 6556 | * stktable_alloc_data_type(). |
| 6557 | */ |
| 6558 | } |
| 6559 | } |
| 6560 | |
Willy Tarreau | 09448f7 | 2014-06-25 18:12:15 +0200 | [diff] [blame] | 6561 | /* find the target table for 'http-request' layer 7 rules */ |
| 6562 | list_for_each_entry(hrqrule, &curproxy->http_req_rules, list) { |
| 6563 | struct proxy *target; |
| 6564 | |
| 6565 | if (hrqrule->action < HTTP_REQ_ACT_TRK_SC0 || hrqrule->action > HTTP_REQ_ACT_TRK_SCMAX) |
| 6566 | continue; |
| 6567 | |
| 6568 | if (hrqrule->act_prm.trk_ctr.table.n) |
| 6569 | target = findproxy(hrqrule->act_prm.trk_ctr.table.n, 0); |
| 6570 | else |
| 6571 | target = curproxy; |
| 6572 | |
| 6573 | if (!target) { |
| 6574 | Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n", |
| 6575 | curproxy->id, hrqrule->act_prm.trk_ctr.table.n, |
| 6576 | http_req_trk_idx(hrqrule->action)); |
| 6577 | cfgerr++; |
| 6578 | } |
| 6579 | else if (target->table.size == 0) { |
| 6580 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
| 6581 | curproxy->id, hrqrule->act_prm.trk_ctr.table.n ? hrqrule->act_prm.trk_ctr.table.n : curproxy->id); |
| 6582 | cfgerr++; |
| 6583 | } |
| 6584 | else if (!stktable_compatible_sample(hrqrule->act_prm.trk_ctr.expr, target->table.type)) { |
| 6585 | Alert("Proxy '%s': stick-table '%s' uses a type incompatible with the 'track-sc%d' rule.\n", |
| 6586 | curproxy->id, hrqrule->act_prm.trk_ctr.table.n ? hrqrule->act_prm.trk_ctr.table.n : curproxy->id, |
| 6587 | http_req_trk_idx(hrqrule->action)); |
| 6588 | cfgerr++; |
| 6589 | } |
| 6590 | else { |
| 6591 | free(hrqrule->act_prm.trk_ctr.table.n); |
| 6592 | hrqrule->act_prm.trk_ctr.table.t = &target->table; |
| 6593 | /* Note: if we decide to enhance the track-sc syntax, we may be able |
| 6594 | * to pass a list of counters to track and allocate them right here using |
| 6595 | * stktable_alloc_data_type(). |
| 6596 | */ |
| 6597 | } |
| 6598 | } |
| 6599 | |
Willy Tarreau | b3dc39d | 2014-04-28 22:06:57 +0200 | [diff] [blame] | 6600 | /* move any "block" rules at the beginning of the http-request rules */ |
| 6601 | if (!LIST_ISEMPTY(&curproxy->block_rules)) { |
| 6602 | /* insert block_rules into http_req_rules at the beginning */ |
| 6603 | curproxy->block_rules.p->n = curproxy->http_req_rules.n; |
| 6604 | curproxy->http_req_rules.n->p = curproxy->block_rules.p; |
| 6605 | curproxy->block_rules.n->p = &curproxy->http_req_rules; |
| 6606 | curproxy->http_req_rules.n = curproxy->block_rules.n; |
| 6607 | LIST_INIT(&curproxy->block_rules); |
| 6608 | } |
| 6609 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 6610 | if (curproxy->table.peers.name) { |
| 6611 | struct peers *curpeers = peers; |
| 6612 | |
| 6613 | for (curpeers = peers; curpeers; curpeers = curpeers->next) { |
| 6614 | if (strcmp(curpeers->id, curproxy->table.peers.name) == 0) { |
| 6615 | free((void *)curproxy->table.peers.name); |
Willy Tarreau | 973ca49 | 2013-01-17 21:34:52 +0100 | [diff] [blame] | 6616 | curproxy->table.peers.p = curpeers; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 6617 | break; |
| 6618 | } |
| 6619 | } |
| 6620 | |
| 6621 | if (!curpeers) { |
| 6622 | Alert("Proxy '%s': unable to find sync peers '%s'.\n", |
| 6623 | curproxy->id, curproxy->table.peers.name); |
Willy Tarreau | d66bf96 | 2011-10-28 14:16:49 +0200 | [diff] [blame] | 6624 | free((void *)curproxy->table.peers.name); |
| 6625 | curproxy->table.peers.p = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 6626 | cfgerr++; |
| 6627 | } |
| 6628 | else if (!curpeers->peers_fe) { |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 6629 | Alert("Proxy '%s': unable to find local peer '%s' in peers section '%s'.\n", |
| 6630 | curproxy->id, localpeer, curpeers->id); |
Willy Tarreau | d66bf96 | 2011-10-28 14:16:49 +0200 | [diff] [blame] | 6631 | curproxy->table.peers.p = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 6632 | cfgerr++; |
| 6633 | } |
| 6634 | } |
| 6635 | |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 6636 | if (curproxy->uri_auth && !(curproxy->uri_auth->flags & ST_CONVDONE) && |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 6637 | !LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) && |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6638 | (curproxy->uri_auth->userlist || curproxy->uri_auth->auth_realm )) { |
| 6639 | Alert("%s '%s': stats 'auth'/'realm' and 'http-request' can't be used at the same time.\n", |
| 6640 | "proxy", curproxy->id); |
| 6641 | cfgerr++; |
| 6642 | goto out_uri_auth_compat; |
| 6643 | } |
| 6644 | |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 6645 | 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] | 6646 | const char *uri_auth_compat_req[10]; |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 6647 | struct http_req_rule *rule; |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6648 | int i = 0; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6649 | |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6650 | /* build the ACL condition from scratch. We're relying on anonymous ACLs for that */ |
| 6651 | uri_auth_compat_req[i++] = "auth"; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6652 | |
| 6653 | if (curproxy->uri_auth->auth_realm) { |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6654 | uri_auth_compat_req[i++] = "realm"; |
| 6655 | uri_auth_compat_req[i++] = curproxy->uri_auth->auth_realm; |
| 6656 | } |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6657 | |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6658 | uri_auth_compat_req[i++] = "unless"; |
| 6659 | uri_auth_compat_req[i++] = "{"; |
| 6660 | uri_auth_compat_req[i++] = "http_auth(.internal-stats-userlist)"; |
| 6661 | uri_auth_compat_req[i++] = "}"; |
| 6662 | uri_auth_compat_req[i++] = ""; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6663 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 6664 | rule = parse_http_req_cond(uri_auth_compat_req, "internal-stats-auth-compat", 0, curproxy); |
| 6665 | if (!rule) { |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6666 | cfgerr++; |
| 6667 | break; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6668 | } |
| 6669 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 6670 | LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list); |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6671 | |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6672 | if (curproxy->uri_auth->auth_realm) { |
| 6673 | free(curproxy->uri_auth->auth_realm); |
| 6674 | curproxy->uri_auth->auth_realm = NULL; |
| 6675 | } |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 6676 | |
| 6677 | curproxy->uri_auth->flags |= ST_CONVDONE; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6678 | } |
| 6679 | out_uri_auth_compat: |
| 6680 | |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 6681 | /* compile the log format */ |
| 6682 | if (!(curproxy->cap & PR_CAP_FE)) { |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 6683 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 6684 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 6685 | curproxy->conf.logformat_string != clf_http_log_format) |
| 6686 | free(curproxy->conf.logformat_string); |
| 6687 | curproxy->conf.logformat_string = NULL; |
| 6688 | free(curproxy->conf.lfs_file); |
| 6689 | curproxy->conf.lfs_file = NULL; |
| 6690 | curproxy->conf.lfs_line = 0; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 6691 | } |
| 6692 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 6693 | if (curproxy->conf.logformat_string) { |
| 6694 | curproxy->conf.args.ctx = ARGC_LOG; |
| 6695 | curproxy->conf.args.file = curproxy->conf.lfs_file; |
| 6696 | curproxy->conf.args.line = curproxy->conf.lfs_line; |
| 6697 | 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] | 6698 | 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] | 6699 | curproxy->conf.args.file = NULL; |
| 6700 | curproxy->conf.args.line = 0; |
| 6701 | } |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 6702 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 6703 | if (curproxy->conf.uniqueid_format_string) { |
| 6704 | curproxy->conf.args.ctx = ARGC_UIF; |
| 6705 | curproxy->conf.args.file = curproxy->conf.uif_file; |
| 6706 | curproxy->conf.args.line = curproxy->conf.uif_line; |
Thierry FOURNIER | d048d8b | 2014-03-13 16:46:18 +0100 | [diff] [blame] | 6707 | parse_logformat_string(curproxy->conf.uniqueid_format_string, curproxy, &curproxy->format_unique_id, LOG_OPT_HTTP, |
Thierry FOURNIER | eeaa951 | 2014-02-11 14:00:19 +0100 | [diff] [blame] | 6708 | (proxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 6709 | curproxy->conf.uif_file, curproxy->conf.uif_line); |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 6710 | curproxy->conf.args.file = NULL; |
| 6711 | curproxy->conf.args.line = 0; |
| 6712 | } |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 6713 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6714 | /* only now we can check if some args remain unresolved. |
| 6715 | * This must be done after the users and groups resolution. |
| 6716 | */ |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 6717 | cfgerr += smp_resolve_args(curproxy); |
| 6718 | if (!cfgerr) |
| 6719 | cfgerr += acl_find_targets(curproxy); |
Krzysztof Piotr Oledzki | f9423ae | 2010-01-29 19:26:18 +0100 | [diff] [blame] | 6720 | |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 6721 | if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) && |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6722 | (((curproxy->cap & PR_CAP_FE) && !curproxy->timeout.client) || |
Willy Tarreau | d825eef | 2007-05-12 22:35:00 +0200 | [diff] [blame] | 6723 | ((curproxy->cap & PR_CAP_BE) && (curproxy->srv) && |
Willy Tarreau | ce887fd | 2012-05-12 12:50:00 +0200 | [diff] [blame] | 6724 | (!curproxy->timeout.connect || |
| 6725 | (!curproxy->timeout.server && (curproxy->mode == PR_MODE_HTTP || !curproxy->timeout.tunnel)))))) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6726 | Warning("config : missing timeouts for %s '%s'.\n" |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 6727 | " | While not properly invalid, you will certainly encounter various problems\n" |
| 6728 | " | 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] | 6729 | " | timeouts are set to a non-zero value: 'client', 'connect', 'server'.\n", |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6730 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6731 | err_code |= ERR_WARN; |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 6732 | } |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 6733 | |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6734 | /* Historically, the tarpit and queue timeouts were inherited from contimeout. |
| 6735 | * We must still support older configurations, so let's find out whether those |
| 6736 | * parameters have been set or must be copied from contimeouts. |
| 6737 | */ |
| 6738 | if (curproxy != &defproxy) { |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6739 | if (!curproxy->timeout.tarpit || |
| 6740 | curproxy->timeout.tarpit == defproxy.timeout.tarpit) { |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6741 | /* tarpit timeout not set. We search in the following order: |
| 6742 | * default.tarpit, curr.connect, default.connect. |
| 6743 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6744 | if (defproxy.timeout.tarpit) |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6745 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6746 | else if (curproxy->timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6747 | curproxy->timeout.tarpit = curproxy->timeout.connect; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6748 | else if (defproxy.timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6749 | curproxy->timeout.tarpit = defproxy.timeout.connect; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6750 | } |
| 6751 | if ((curproxy->cap & PR_CAP_BE) && |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6752 | (!curproxy->timeout.queue || |
| 6753 | curproxy->timeout.queue == defproxy.timeout.queue)) { |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6754 | /* queue timeout not set. We search in the following order: |
| 6755 | * default.queue, curr.connect, default.connect. |
| 6756 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6757 | if (defproxy.timeout.queue) |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6758 | curproxy->timeout.queue = defproxy.timeout.queue; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6759 | else if (curproxy->timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6760 | curproxy->timeout.queue = curproxy->timeout.connect; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6761 | else if (defproxy.timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6762 | curproxy->timeout.queue = defproxy.timeout.connect; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6763 | } |
| 6764 | } |
| 6765 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 6766 | if ((curproxy->options2 & PR_O2_CHK_ANY) == PR_O2_SSL3_CHK) { |
Willy Tarreau | 137325d | 2010-02-01 16:38:17 +0100 | [diff] [blame] | 6767 | curproxy->check_len = sizeof(sslv3_client_hello_pkt) - 1; |
| 6768 | curproxy->check_req = (char *)malloc(curproxy->check_len); |
| 6769 | memcpy(curproxy->check_req, sslv3_client_hello_pkt, curproxy->check_len); |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 6770 | } |
| 6771 | |
Willy Tarreau | 215663d | 2014-06-13 18:30:23 +0200 | [diff] [blame] | 6772 | if (!LIST_ISEMPTY(&curproxy->tcpcheck_rules) && |
| 6773 | (curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_TCPCHK_CHK) { |
| 6774 | Warning("config : %s '%s' uses tcp-check rules without 'option tcp-check', so the rules are ignored.\n", |
| 6775 | proxy_type_str(curproxy), curproxy->id); |
| 6776 | err_code |= ERR_WARN; |
| 6777 | } |
| 6778 | |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 6779 | /* ensure that cookie capture length is not too large */ |
| 6780 | if (curproxy->capture_len >= global.tune.cookie_len) { |
| 6781 | Warning("config : truncating capture length to %d bytes for %s '%s'.\n", |
| 6782 | global.tune.cookie_len - 1, proxy_type_str(curproxy), curproxy->id); |
| 6783 | err_code |= ERR_WARN; |
| 6784 | curproxy->capture_len = global.tune.cookie_len - 1; |
| 6785 | } |
| 6786 | |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 6787 | /* The small pools required for the capture lists */ |
Willy Tarreau | 9a54e13 | 2012-03-24 08:33:05 +0100 | [diff] [blame] | 6788 | if (curproxy->nb_req_cap) { |
Willy Tarreau | d9ed3d2 | 2014-06-13 12:23:06 +0200 | [diff] [blame] | 6789 | curproxy->req_cap_pool = create_pool("ptrcap", |
| 6790 | curproxy->nb_req_cap * sizeof(char *), |
| 6791 | MEM_F_SHARED); |
Willy Tarreau | 9a54e13 | 2012-03-24 08:33:05 +0100 | [diff] [blame] | 6792 | } |
| 6793 | |
| 6794 | if (curproxy->nb_rsp_cap) { |
Willy Tarreau | d9ed3d2 | 2014-06-13 12:23:06 +0200 | [diff] [blame] | 6795 | curproxy->rsp_cap_pool = create_pool("ptrcap", |
| 6796 | curproxy->nb_rsp_cap * sizeof(char *), |
| 6797 | MEM_F_SHARED); |
Willy Tarreau | 9a54e13 | 2012-03-24 08:33:05 +0100 | [diff] [blame] | 6798 | } |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 6799 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6800 | /* first, we will invert the servers list order */ |
| 6801 | newsrv = NULL; |
| 6802 | while (curproxy->srv) { |
| 6803 | struct server *next; |
| 6804 | |
| 6805 | next = curproxy->srv->next; |
| 6806 | curproxy->srv->next = newsrv; |
| 6807 | newsrv = curproxy->srv; |
| 6808 | if (!next) |
| 6809 | break; |
| 6810 | curproxy->srv = next; |
| 6811 | } |
| 6812 | |
Willy Tarreau | 17edc81 | 2014-01-03 12:14:34 +0100 | [diff] [blame] | 6813 | /* Check that no server name conflicts. This causes trouble in the stats. |
| 6814 | * We only emit a warning for the first conflict affecting each server, |
| 6815 | * in order to avoid combinatory explosion if all servers have the same |
| 6816 | * name. We do that only for servers which do not have an explicit ID, |
| 6817 | * because these IDs were made also for distinguishing them and we don't |
| 6818 | * want to annoy people who correctly manage them. |
| 6819 | */ |
| 6820 | for (newsrv = curproxy->srv; newsrv; newsrv = newsrv->next) { |
| 6821 | struct server *other_srv; |
| 6822 | |
| 6823 | if (newsrv->puid) |
| 6824 | continue; |
| 6825 | |
| 6826 | for (other_srv = curproxy->srv; other_srv && other_srv != newsrv; other_srv = other_srv->next) { |
| 6827 | if (!other_srv->puid && strcmp(other_srv->id, newsrv->id) == 0) { |
| 6828 | Warning("parsing [%s:%d] : %s '%s', another server named '%s' was defined without an explicit ID at line %d, this is not recommended.\n", |
| 6829 | newsrv->conf.file, newsrv->conf.line, |
| 6830 | proxy_type_str(curproxy), curproxy->id, |
| 6831 | newsrv->id, other_srv->conf.line); |
| 6832 | break; |
| 6833 | } |
| 6834 | } |
| 6835 | } |
| 6836 | |
Willy Tarreau | dd70165 | 2010-05-25 23:03:02 +0200 | [diff] [blame] | 6837 | /* assign automatic UIDs to servers which don't have one yet */ |
| 6838 | next_id = 1; |
| 6839 | newsrv = curproxy->srv; |
| 6840 | while (newsrv != NULL) { |
| 6841 | if (!newsrv->puid) { |
| 6842 | /* server ID not set, use automatic numbering with first |
| 6843 | * spare entry starting with next_svid. |
| 6844 | */ |
| 6845 | next_id = get_next_id(&curproxy->conf.used_server_id, next_id); |
| 6846 | newsrv->conf.id.key = newsrv->puid = next_id; |
| 6847 | eb32_insert(&curproxy->conf.used_server_id, &newsrv->conf.id); |
| 6848 | } |
| 6849 | next_id++; |
| 6850 | newsrv = newsrv->next; |
| 6851 | } |
| 6852 | |
Willy Tarreau | 2069704 | 2007-11-15 23:26:18 +0100 | [diff] [blame] | 6853 | curproxy->lbprm.wmult = 1; /* default weight multiplier */ |
Willy Tarreau | 5dc2fa6 | 2007-11-19 19:10:18 +0100 | [diff] [blame] | 6854 | curproxy->lbprm.wdiv = 1; /* default weight divider */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6855 | |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 6856 | /* |
| 6857 | * If this server supports a maxconn parameter, it needs a dedicated |
| 6858 | * tasks to fill the emptied slots when a connection leaves. |
| 6859 | * Also, resolve deferred tracking dependency if needed. |
| 6860 | */ |
| 6861 | newsrv = curproxy->srv; |
| 6862 | while (newsrv != NULL) { |
| 6863 | if (newsrv->minconn > newsrv->maxconn) { |
| 6864 | /* Only 'minconn' was specified, or it was higher than or equal |
| 6865 | * to 'maxconn'. Let's turn this into maxconn and clean it, as |
| 6866 | * this will avoid further useless expensive computations. |
| 6867 | */ |
| 6868 | newsrv->maxconn = newsrv->minconn; |
| 6869 | } else if (newsrv->maxconn && !newsrv->minconn) { |
| 6870 | /* minconn was not specified, so we set it to maxconn */ |
| 6871 | newsrv->minconn = newsrv->maxconn; |
| 6872 | } |
| 6873 | |
Emeric Brun | 01f8e2f | 2012-05-18 16:02:00 +0200 | [diff] [blame] | 6874 | #ifdef USE_OPENSSL |
Emeric Brun | 94324a4 | 2012-10-11 14:00:19 +0200 | [diff] [blame] | 6875 | if (newsrv->use_ssl || newsrv->check.use_ssl) |
| 6876 | cfgerr += ssl_sock_prepare_srv_ctx(newsrv, curproxy); |
Emeric Brun | 01f8e2f | 2012-05-18 16:02:00 +0200 | [diff] [blame] | 6877 | #endif /* USE_OPENSSL */ |
Emeric Brun | 94324a4 | 2012-10-11 14:00:19 +0200 | [diff] [blame] | 6878 | |
Willy Tarreau | 2f075e9 | 2013-12-03 11:11:34 +0100 | [diff] [blame] | 6879 | /* set the check type on the server */ |
| 6880 | newsrv->check.type = curproxy->options2 & PR_O2_CHK_ANY; |
| 6881 | |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 6882 | if (newsrv->trackit) { |
| 6883 | struct proxy *px; |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 6884 | struct server *srv, *loop; |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 6885 | char *pname, *sname; |
| 6886 | |
| 6887 | pname = newsrv->trackit; |
| 6888 | sname = strrchr(pname, '/'); |
| 6889 | |
| 6890 | if (sname) |
| 6891 | *sname++ = '\0'; |
| 6892 | else { |
| 6893 | sname = pname; |
| 6894 | pname = NULL; |
| 6895 | } |
| 6896 | |
| 6897 | if (pname) { |
| 6898 | px = findproxy(pname, PR_CAP_BE); |
| 6899 | if (!px) { |
| 6900 | Alert("config : %s '%s', server '%s': unable to find required proxy '%s' for tracking.\n", |
| 6901 | proxy_type_str(curproxy), curproxy->id, |
| 6902 | newsrv->id, pname); |
| 6903 | cfgerr++; |
| 6904 | goto next_srv; |
| 6905 | } |
| 6906 | } else |
| 6907 | px = curproxy; |
| 6908 | |
| 6909 | srv = findserver(px, sname); |
| 6910 | if (!srv) { |
| 6911 | Alert("config : %s '%s', server '%s': unable to find required server '%s' for tracking.\n", |
| 6912 | proxy_type_str(curproxy), curproxy->id, |
| 6913 | newsrv->id, sname); |
| 6914 | cfgerr++; |
| 6915 | goto next_srv; |
| 6916 | } |
| 6917 | |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 6918 | if (!(srv->check.state & CHK_ST_CONFIGURED) && |
| 6919 | !(srv->agent.state & CHK_ST_CONFIGURED) && |
| 6920 | !srv->track && !srv->trackit) { |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 6921 | Alert("config : %s '%s', server '%s': unable to use %s/%s for " |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 6922 | "tracking as it does not have any check nor agent enabled.\n", |
| 6923 | proxy_type_str(curproxy), curproxy->id, |
| 6924 | newsrv->id, px->id, srv->id); |
| 6925 | cfgerr++; |
| 6926 | goto next_srv; |
| 6927 | } |
| 6928 | |
| 6929 | for (loop = srv->track; loop && loop != newsrv; loop = loop->track); |
| 6930 | |
| 6931 | if (loop) { |
| 6932 | Alert("config : %s '%s', server '%s': unable to track %s/%s as it " |
| 6933 | "belongs to a tracking chain looping back to %s/%s.\n", |
| 6934 | proxy_type_str(curproxy), curproxy->id, |
| 6935 | newsrv->id, px->id, srv->id, px->id, loop->id); |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 6936 | cfgerr++; |
| 6937 | goto next_srv; |
| 6938 | } |
| 6939 | |
| 6940 | if (curproxy != px && |
| 6941 | (curproxy->options & PR_O_DISABLE404) != (px->options & PR_O_DISABLE404)) { |
| 6942 | Alert("config : %s '%s', server '%s': unable to use %s/%s for" |
| 6943 | "tracking: disable-on-404 option inconsistency.\n", |
| 6944 | proxy_type_str(curproxy), curproxy->id, |
| 6945 | newsrv->id, px->id, srv->id); |
| 6946 | cfgerr++; |
| 6947 | goto next_srv; |
| 6948 | } |
| 6949 | |
| 6950 | /* 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] | 6951 | if (srv->admin & SRV_ADMF_MAINT) { |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 6952 | newsrv->admin |= SRV_ADMF_IMAINT; |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 6953 | newsrv->state = SRV_ST_STOPPED; |
Simon Horman | 125d099 | 2013-02-24 17:23:38 +0900 | [diff] [blame] | 6954 | newsrv->check.health = 0; |
Simon Horman | d60d691 | 2013-11-25 10:46:36 +0900 | [diff] [blame] | 6955 | newsrv->agent.health = 0; |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 6956 | } |
| 6957 | |
| 6958 | newsrv->track = srv; |
Willy Tarreau | 1a53a3a | 2013-12-11 15:27:05 +0100 | [diff] [blame] | 6959 | newsrv->tracknext = srv->trackers; |
| 6960 | srv->trackers = newsrv; |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 6961 | |
| 6962 | free(newsrv->trackit); |
| 6963 | newsrv->trackit = NULL; |
| 6964 | } |
| 6965 | next_srv: |
| 6966 | newsrv = newsrv->next; |
| 6967 | } |
| 6968 | |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6969 | /* We have to initialize the server lookup mechanism depending |
| 6970 | * on what LB algorithm was choosen. |
| 6971 | */ |
| 6972 | |
| 6973 | curproxy->lbprm.algo &= ~(BE_LB_LKUP | BE_LB_PROP_DYN); |
| 6974 | switch (curproxy->lbprm.algo & BE_LB_KIND) { |
| 6975 | case BE_LB_KIND_RR: |
Willy Tarreau | 9757a38 | 2009-10-03 12:56:50 +0200 | [diff] [blame] | 6976 | if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_RR_STATIC) { |
| 6977 | curproxy->lbprm.algo |= BE_LB_LKUP_MAP; |
| 6978 | init_server_map(curproxy); |
| 6979 | } else { |
| 6980 | curproxy->lbprm.algo |= BE_LB_LKUP_RRTREE | BE_LB_PROP_DYN; |
| 6981 | fwrr_init_server_groups(curproxy); |
| 6982 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6983 | break; |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 6984 | |
Willy Tarreau | 3ebb116 | 2012-02-13 16:57:44 +0100 | [diff] [blame] | 6985 | case BE_LB_KIND_CB: |
Willy Tarreau | f09c660 | 2012-02-13 17:12:08 +0100 | [diff] [blame] | 6986 | if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_CB_LC) { |
| 6987 | curproxy->lbprm.algo |= BE_LB_LKUP_LCTREE | BE_LB_PROP_DYN; |
| 6988 | fwlc_init_server_tree(curproxy); |
| 6989 | } else { |
| 6990 | curproxy->lbprm.algo |= BE_LB_LKUP_FSTREE | BE_LB_PROP_DYN; |
| 6991 | fas_init_server_tree(curproxy); |
| 6992 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6993 | break; |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 6994 | |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6995 | case BE_LB_KIND_HI: |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 6996 | if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS) { |
| 6997 | curproxy->lbprm.algo |= BE_LB_LKUP_CHTREE | BE_LB_PROP_DYN; |
| 6998 | chash_init_server_tree(curproxy); |
| 6999 | } else { |
| 7000 | curproxy->lbprm.algo |= BE_LB_LKUP_MAP; |
| 7001 | init_server_map(curproxy); |
| 7002 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 7003 | break; |
| 7004 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7005 | |
| 7006 | if (curproxy->options & PR_O_LOGASAP) |
| 7007 | curproxy->to_log &= ~LW_BYTES; |
| 7008 | |
Willy Tarreau | e7ded1f | 2009-08-09 10:11:45 +0200 | [diff] [blame] | 7009 | if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) && |
Willy Tarreau | d79a3b2 | 2012-12-28 09:40:16 +0100 | [diff] [blame] | 7010 | (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] | 7011 | Warning("config : log format ignored for %s '%s' since it has no log address.\n", |
| 7012 | proxy_type_str(curproxy), curproxy->id); |
| 7013 | err_code |= ERR_WARN; |
| 7014 | } |
| 7015 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 7016 | if (curproxy->mode != PR_MODE_HTTP) { |
| 7017 | int optnum; |
| 7018 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 7019 | if (curproxy->uri_auth) { |
| 7020 | Warning("config : 'stats' statement ignored for %s '%s' as it requires HTTP mode.\n", |
| 7021 | proxy_type_str(curproxy), curproxy->id); |
| 7022 | err_code |= ERR_WARN; |
| 7023 | curproxy->uri_auth = NULL; |
| 7024 | } |
| 7025 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 7026 | if (curproxy->options & (PR_O_FWDFOR | PR_O_FF_ALWAYS)) { |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 7027 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 7028 | "forwardfor", proxy_type_str(curproxy), curproxy->id); |
| 7029 | err_code |= ERR_WARN; |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 7030 | curproxy->options &= ~(PR_O_FWDFOR | PR_O_FF_ALWAYS); |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 7031 | } |
| 7032 | |
| 7033 | if (curproxy->options & PR_O_ORGTO) { |
| 7034 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 7035 | "originalto", proxy_type_str(curproxy), curproxy->id); |
| 7036 | err_code |= ERR_WARN; |
| 7037 | curproxy->options &= ~PR_O_ORGTO; |
| 7038 | } |
| 7039 | |
| 7040 | for (optnum = 0; cfg_opts[optnum].name; optnum++) { |
| 7041 | if (cfg_opts[optnum].mode == PR_MODE_HTTP && |
| 7042 | (curproxy->cap & cfg_opts[optnum].cap) && |
| 7043 | (curproxy->options & cfg_opts[optnum].val)) { |
| 7044 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 7045 | cfg_opts[optnum].name, proxy_type_str(curproxy), curproxy->id); |
| 7046 | err_code |= ERR_WARN; |
| 7047 | curproxy->options &= ~cfg_opts[optnum].val; |
| 7048 | } |
| 7049 | } |
| 7050 | |
| 7051 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) { |
| 7052 | if (cfg_opts2[optnum].mode == PR_MODE_HTTP && |
| 7053 | (curproxy->cap & cfg_opts2[optnum].cap) && |
| 7054 | (curproxy->options2 & cfg_opts2[optnum].val)) { |
| 7055 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 7056 | cfg_opts2[optnum].name, proxy_type_str(curproxy), curproxy->id); |
| 7057 | err_code |= ERR_WARN; |
| 7058 | curproxy->options2 &= ~cfg_opts2[optnum].val; |
| 7059 | } |
| 7060 | } |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 7061 | |
Pieter Baauw | d551fb5 | 2013-05-08 22:49:23 +0200 | [diff] [blame] | 7062 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_TRANSPARENT) |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 7063 | if (curproxy->conn_src.bind_hdr_occ) { |
| 7064 | curproxy->conn_src.bind_hdr_occ = 0; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 7065 | 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] | 7066 | proxy_type_str(curproxy), curproxy->id, curproxy->conn_src.bind_hdr_name); |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 7067 | err_code |= ERR_WARN; |
| 7068 | } |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 7069 | #endif |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 7070 | } |
| 7071 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7072 | /* |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 7073 | * ensure that we're not cross-dressing a TCP server into HTTP. |
| 7074 | */ |
| 7075 | newsrv = curproxy->srv; |
| 7076 | while (newsrv != NULL) { |
Willy Tarreau | 0cec331 | 2011-10-31 13:49:26 +0100 | [diff] [blame] | 7077 | if ((curproxy->mode != PR_MODE_HTTP) && newsrv->rdr_len) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7078 | Alert("config : %s '%s' : server cannot have cookie or redirect prefix in non-HTTP mode.\n", |
| 7079 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 7080 | cfgerr++; |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 7081 | } |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 7082 | |
Willy Tarreau | 0cec331 | 2011-10-31 13:49:26 +0100 | [diff] [blame] | 7083 | if ((curproxy->mode != PR_MODE_HTTP) && newsrv->cklen) { |
| 7084 | Warning("config : %s '%s' : ignoring cookie for server '%s' as HTTP mode is disabled.\n", |
| 7085 | proxy_type_str(curproxy), curproxy->id, newsrv->id); |
| 7086 | err_code |= ERR_WARN; |
| 7087 | } |
| 7088 | |
Willy Tarreau | c93cd16 | 2014-05-13 15:54:22 +0200 | [diff] [blame] | 7089 | if ((newsrv->flags & SRV_F_MAPPORTS) && (curproxy->options2 & PR_O2_RDPC_PRST)) { |
Willy Tarreau | 82ffa39 | 2013-08-13 17:19:08 +0200 | [diff] [blame] | 7090 | Warning("config : %s '%s' : RDP cookie persistence will not work for server '%s' because it lacks an explicit port number.\n", |
| 7091 | proxy_type_str(curproxy), curproxy->id, newsrv->id); |
| 7092 | err_code |= ERR_WARN; |
| 7093 | } |
| 7094 | |
Pieter Baauw | d551fb5 | 2013-05-08 22:49:23 +0200 | [diff] [blame] | 7095 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_TRANSPARENT) |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 7096 | if (curproxy->mode != PR_MODE_HTTP && newsrv->conn_src.bind_hdr_occ) { |
| 7097 | newsrv->conn_src.bind_hdr_occ = 0; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 7098 | 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] | 7099 | 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] | 7100 | err_code |= ERR_WARN; |
| 7101 | } |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 7102 | #endif |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 7103 | newsrv = newsrv->next; |
| 7104 | } |
| 7105 | |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 7106 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 7107 | if (!curproxy->accept) |
| 7108 | curproxy->accept = frontend_accept; |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 7109 | |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 7110 | if (curproxy->tcp_req.inspect_delay || |
| 7111 | !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules)) |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 7112 | curproxy->fe_req_ana |= AN_REQ_INSPECT_FE; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 7113 | |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 7114 | if (curproxy->mode == PR_MODE_HTTP) { |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 7115 | 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] | 7116 | 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] | 7117 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 7118 | |
| 7119 | /* both TCP and HTTP must check switching rules */ |
| 7120 | curproxy->fe_req_ana |= AN_REQ_SWITCHING_RULES; |
| 7121 | } |
| 7122 | |
| 7123 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 7124 | if (curproxy->tcp_req.inspect_delay || |
| 7125 | !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules)) |
| 7126 | curproxy->be_req_ana |= AN_REQ_INSPECT_BE; |
| 7127 | |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 7128 | if (!LIST_ISEMPTY(&curproxy->tcp_rep.inspect_rules)) |
| 7129 | curproxy->be_rsp_ana |= AN_RES_INSPECT; |
| 7130 | |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 7131 | if (curproxy->mode == PR_MODE_HTTP) { |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 7132 | 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] | 7133 | 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] | 7134 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 7135 | |
| 7136 | /* If the backend does requires RDP cookie persistence, we have to |
| 7137 | * enable the corresponding analyser. |
| 7138 | */ |
| 7139 | if (curproxy->options2 & PR_O2_RDPC_PRST) |
| 7140 | curproxy->be_req_ana |= AN_REQ_PRST_RDP_COOKIE; |
| 7141 | } |
| 7142 | |
Emeric Brun | c52962f | 2012-11-15 18:28:02 +0100 | [diff] [blame] | 7143 | #ifdef USE_OPENSSL |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 7144 | /* Configure SSL for each bind line. |
| 7145 | * Note: if configuration fails at some point, the ->ctx member |
| 7146 | * remains NULL so that listeners can later detach. |
| 7147 | */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7148 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
Emeric Brun | caa19cc | 2014-05-07 16:10:18 +0200 | [diff] [blame] | 7149 | int alloc_ctx; |
| 7150 | |
Emeric Brun | c52962f | 2012-11-15 18:28:02 +0100 | [diff] [blame] | 7151 | if (!bind_conf->is_ssl) { |
| 7152 | if (bind_conf->default_ctx) { |
| 7153 | Warning("Proxy '%s': A certificate was specified but SSL was not enabled on bind '%s' at [%s:%d] (use 'ssl').\n", |
| 7154 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
| 7155 | } |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7156 | continue; |
Emeric Brun | c52962f | 2012-11-15 18:28:02 +0100 | [diff] [blame] | 7157 | } |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7158 | if (!bind_conf->default_ctx) { |
Emeric Brun | fc0421f | 2012-09-07 17:30:07 +0200 | [diff] [blame] | 7159 | 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] | 7160 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 7161 | cfgerr++; |
| 7162 | continue; |
| 7163 | } |
| 7164 | |
Emeric Brun | 8dc6039 | 2014-05-09 13:52:00 +0200 | [diff] [blame] | 7165 | 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] | 7166 | if (alloc_ctx < 0) { |
Emeric Brun | 93ee249 | 2014-05-09 14:01:48 +0200 | [diff] [blame] | 7167 | if (alloc_ctx == SHCTX_E_INIT_LOCK) |
| 7168 | 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"); |
| 7169 | else |
Emeric Brun | caa19cc | 2014-05-07 16:10:18 +0200 | [diff] [blame] | 7170 | Alert("Unable to allocate SSL session cache.\n"); |
Emeric Brun | 93ee249 | 2014-05-09 14:01:48 +0200 | [diff] [blame] | 7171 | cfgerr++; |
| 7172 | continue; |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 7173 | } |
| 7174 | |
Emeric Brun | fc0421f | 2012-09-07 17:30:07 +0200 | [diff] [blame] | 7175 | /* initialize all certificate contexts */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7176 | cfgerr += ssl_sock_prepare_all_ctx(bind_conf, curproxy); |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7177 | } |
Emeric Brun | c52962f | 2012-11-15 18:28:02 +0100 | [diff] [blame] | 7178 | #endif /* USE_OPENSSL */ |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 7179 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 7180 | /* adjust this proxy's listeners */ |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7181 | next_id = 1; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 7182 | list_for_each_entry(listener, &curproxy->conf.listeners, by_fe) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7183 | if (!listener->luid) { |
| 7184 | /* listener ID not set, use automatic numbering with first |
| 7185 | * spare entry starting with next_luid. |
| 7186 | */ |
| 7187 | next_id = get_next_id(&curproxy->conf.used_listener_id, next_id); |
| 7188 | listener->conf.id.key = listener->luid = next_id; |
| 7189 | eb32_insert(&curproxy->conf.used_listener_id, &listener->conf.id); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7190 | } |
Krzysztof Piotr Oledzki | df5cb9f | 2010-02-05 20:58:27 +0100 | [diff] [blame] | 7191 | next_id++; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7192 | |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 7193 | /* enable separate counters */ |
| 7194 | if (curproxy->options2 & PR_O2_SOCKSTAT) { |
| 7195 | listener->counters = (struct licounters *)calloc(1, sizeof(struct licounters)); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 7196 | if (!listener->name) |
| 7197 | memprintf(&listener->name, "sock-%d", listener->luid); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 7198 | } |
Willy Tarreau | 81796be | 2012-09-22 19:11:47 +0200 | [diff] [blame] | 7199 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 7200 | if (curproxy->options & PR_O_TCP_NOLING) |
| 7201 | listener->options |= LI_O_NOLINGER; |
Willy Tarreau | 32368ce | 2012-09-06 11:10:55 +0200 | [diff] [blame] | 7202 | if (!listener->maxconn) |
| 7203 | listener->maxconn = curproxy->maxconn; |
| 7204 | if (!listener->backlog) |
| 7205 | listener->backlog = curproxy->backlog; |
Willy Tarreau | 16a2147 | 2012-11-19 12:39:59 +0100 | [diff] [blame] | 7206 | if (!listener->maxaccept) |
| 7207 | listener->maxaccept = global.tune.maxaccept ? global.tune.maxaccept : 64; |
| 7208 | |
| 7209 | /* we want to have an optimal behaviour on single process mode to |
| 7210 | * maximize the work at once, but in multi-process we want to keep |
| 7211 | * some fairness between processes, so we target half of the max |
| 7212 | * number of events to be balanced over all the processes the proxy |
| 7213 | * is bound to. Rememeber that maxaccept = -1 must be kept as it is |
| 7214 | * used to disable the limit. |
| 7215 | */ |
| 7216 | if (listener->maxaccept > 0) { |
| 7217 | if (nbproc > 1) |
| 7218 | listener->maxaccept = (listener->maxaccept + 1) / 2; |
| 7219 | listener->maxaccept = (listener->maxaccept + nbproc - 1) / nbproc; |
| 7220 | } |
| 7221 | |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 7222 | listener->timeout = &curproxy->timeout.client; |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 7223 | listener->accept = session_accept; |
Willy Tarreau | 3bc1377 | 2008-12-07 11:50:35 +0100 | [diff] [blame] | 7224 | listener->handler = process_session; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 7225 | listener->analysers |= curproxy->fe_req_ana; |
Willy Tarreau | 3bc1377 | 2008-12-07 11:50:35 +0100 | [diff] [blame] | 7226 | |
Willy Tarreau | a5c0ab2 | 2010-05-31 10:30:33 +0200 | [diff] [blame] | 7227 | if (!LIST_ISEMPTY(&curproxy->tcp_req.l4_rules)) |
| 7228 | listener->options |= LI_O_TCP_RULES; |
| 7229 | |
Willy Tarreau | de3041d | 2010-05-31 10:56:17 +0200 | [diff] [blame] | 7230 | if (curproxy->mon_mask.s_addr) |
| 7231 | listener->options |= LI_O_CHK_MONNET; |
| 7232 | |
Willy Tarreau | 9ea05a7 | 2009-06-14 12:07:01 +0200 | [diff] [blame] | 7233 | /* smart accept mode is automatic in HTTP mode */ |
| 7234 | if ((curproxy->options2 & PR_O2_SMARTACC) || |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7235 | ((curproxy->mode == PR_MODE_HTTP || listener->bind_conf->is_ssl) && |
Willy Tarreau | 9ea05a7 | 2009-06-14 12:07:01 +0200 | [diff] [blame] | 7236 | !(curproxy->no_options2 & PR_O2_SMARTACC))) |
| 7237 | listener->options |= LI_O_NOQUICKACK; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 7238 | } |
| 7239 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7240 | /* Release unused SSL configs */ |
| 7241 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
| 7242 | if (bind_conf->is_ssl) |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 7243 | continue; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7244 | #ifdef USE_OPENSSL |
| 7245 | ssl_sock_free_all_ctx(bind_conf); |
Emeric Brun | fb510ea | 2012-10-05 12:00:26 +0200 | [diff] [blame] | 7246 | free(bind_conf->ca_file); |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7247 | free(bind_conf->ciphers); |
Emeric Brun | 2b58d04 | 2012-09-20 17:10:03 +0200 | [diff] [blame] | 7248 | free(bind_conf->ecdhe); |
Emeric Brun | fb510ea | 2012-10-05 12:00:26 +0200 | [diff] [blame] | 7249 | free(bind_conf->crl_file); |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 7250 | #endif /* USE_OPENSSL */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7251 | } |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 7252 | |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 7253 | if (nbproc > 1) { |
| 7254 | if (curproxy->uri_auth) { |
| 7255 | Warning("Proxy '%s': in multi-process mode, stats will be limited to process assigned to the current request.\n", |
| 7256 | curproxy->id); |
| 7257 | if (!LIST_ISEMPTY(&curproxy->uri_auth->admin_rules)) { |
| 7258 | Warning("Proxy '%s': stats admin will not work correctly in multi-process mode.\n", |
| 7259 | curproxy->id); |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 7260 | } |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 7261 | } |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 7262 | if (curproxy->appsession_name) { |
| 7263 | Warning("Proxy '%s': appsession will not work correctly in multi-process mode.\n", |
| 7264 | curproxy->id); |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 7265 | } |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 7266 | if (!LIST_ISEMPTY(&curproxy->sticking_rules)) { |
| 7267 | Warning("Proxy '%s': sticking rules will not work correctly in multi-process mode.\n", |
| 7268 | curproxy->id); |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 7269 | } |
| 7270 | } |
Willy Tarreau | 918ff60 | 2011-07-25 16:33:49 +0200 | [diff] [blame] | 7271 | |
| 7272 | /* create the task associated with the proxy */ |
| 7273 | curproxy->task = task_new(); |
| 7274 | if (curproxy->task) { |
| 7275 | curproxy->task->context = curproxy; |
| 7276 | curproxy->task->process = manage_proxy; |
| 7277 | /* no need to queue, it will be done automatically if some |
| 7278 | * listener gets limited. |
| 7279 | */ |
| 7280 | curproxy->task->expire = TICK_ETERNITY; |
| 7281 | } else { |
| 7282 | Alert("Proxy '%s': no more memory when trying to allocate the management task\n", |
| 7283 | curproxy->id); |
| 7284 | cfgerr++; |
| 7285 | } |
| 7286 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7287 | curproxy = curproxy->next; |
| 7288 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7289 | |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 7290 | /* Check multi-process mode compatibility */ |
Willy Tarreau | 4e5ed29 | 2014-05-13 13:37:54 +0200 | [diff] [blame] | 7291 | if (global.nbproc > 1 && global.stats_fe) { |
Willy Tarreau | 67c2abc | 2014-05-09 18:48:46 +0200 | [diff] [blame] | 7292 | list_for_each_entry(bind_conf, &global.stats_fe->conf.bind, by_fe) { |
| 7293 | unsigned long mask; |
| 7294 | |
| 7295 | mask = nbits(global.nbproc); |
| 7296 | if (global.stats_fe->bind_proc) |
| 7297 | mask &= global.stats_fe->bind_proc; |
| 7298 | |
| 7299 | if (bind_conf->bind_proc) |
| 7300 | mask &= bind_conf->bind_proc; |
| 7301 | |
| 7302 | /* stop here if more than one process is used */ |
| 7303 | if (popcount(mask) > 1) |
| 7304 | break; |
| 7305 | } |
| 7306 | if (&bind_conf->by_fe != &global.stats_fe->conf.bind) { |
| 7307 | 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"); |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 7308 | } |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 7309 | } |
| 7310 | |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7311 | /* At this point, target names have already been resolved */ |
Willy Tarreau | b369a04 | 2014-09-16 13:21:03 +0200 | [diff] [blame^] | 7312 | |
| 7313 | /* Make each frontend inherit bind-process from its listeners when not specified. */ |
| 7314 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 7315 | if (curproxy->bind_proc) |
| 7316 | continue; |
| 7317 | |
| 7318 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
| 7319 | unsigned long mask; |
| 7320 | |
| 7321 | mask = bind_conf->bind_proc ? bind_conf->bind_proc : ~0UL; |
| 7322 | curproxy->bind_proc |= mask; |
| 7323 | } |
| 7324 | |
| 7325 | if (!curproxy->bind_proc) |
| 7326 | curproxy->bind_proc = ~0UL; |
| 7327 | } |
| 7328 | |
| 7329 | if (global.stats_fe) { |
| 7330 | list_for_each_entry(bind_conf, &global.stats_fe->conf.bind, by_fe) { |
| 7331 | unsigned long mask; |
| 7332 | |
| 7333 | mask = bind_conf->bind_proc ? bind_conf->bind_proc : ~0UL; |
| 7334 | global.stats_fe->bind_proc |= mask; |
| 7335 | } |
| 7336 | if (!global.stats_fe->bind_proc) |
| 7337 | global.stats_fe->bind_proc = ~0UL; |
| 7338 | } |
| 7339 | |
| 7340 | /* propagate bindings from frontends to backends */ |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7341 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 7342 | if (curproxy->cap & PR_CAP_FE) |
| 7343 | propagate_processes(curproxy, NULL); |
| 7344 | } |
| 7345 | |
Willy Tarreau | b369a04 | 2014-09-16 13:21:03 +0200 | [diff] [blame^] | 7346 | /* Bind each unbound backend to all processes when not specified. */ |
| 7347 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 7348 | if (curproxy->bind_proc) |
| 7349 | continue; |
| 7350 | curproxy->bind_proc = ~0UL; |
| 7351 | } |
| 7352 | |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 7353 | /* automatically compute fullconn if not set. We must not do it in the |
| 7354 | * loop above because cross-references are not yet fully resolved. |
| 7355 | */ |
| 7356 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 7357 | /* If <fullconn> is not set, let's set it to 10% of the sum of |
| 7358 | * the possible incoming frontend's maxconns. |
| 7359 | */ |
| 7360 | if (!curproxy->fullconn && (curproxy->cap & PR_CAP_BE)) { |
| 7361 | struct proxy *fe; |
| 7362 | int total = 0; |
| 7363 | |
| 7364 | /* sum up the number of maxconns of frontends which |
| 7365 | * reference this backend at least once or which are |
| 7366 | * the same one ('listen'). |
| 7367 | */ |
| 7368 | for (fe = proxy; fe; fe = fe->next) { |
| 7369 | struct switching_rule *rule; |
| 7370 | struct hdr_exp *exp; |
| 7371 | int found = 0; |
| 7372 | |
| 7373 | if (!(fe->cap & PR_CAP_FE)) |
| 7374 | continue; |
| 7375 | |
| 7376 | if (fe == curproxy) /* we're on a "listen" instance */ |
| 7377 | found = 1; |
| 7378 | |
| 7379 | if (fe->defbe.be == curproxy) /* "default_backend" */ |
| 7380 | found = 1; |
| 7381 | |
| 7382 | /* check if a "use_backend" rule matches */ |
| 7383 | if (!found) { |
| 7384 | list_for_each_entry(rule, &fe->switching_rules, list) { |
Bertrand Jacquin | 702d44f | 2013-11-19 11:43:06 +0100 | [diff] [blame] | 7385 | if (!rule->dynamic && rule->be.backend == curproxy) { |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 7386 | found = 1; |
| 7387 | break; |
| 7388 | } |
| 7389 | } |
| 7390 | } |
| 7391 | |
| 7392 | /* check if a "reqsetbe" rule matches */ |
| 7393 | for (exp = fe->req_exp; !found && exp; exp = exp->next) { |
| 7394 | if (exp->action == ACT_SETBE && |
| 7395 | (struct proxy *)exp->replace == curproxy) { |
| 7396 | found = 1; |
| 7397 | break; |
| 7398 | } |
| 7399 | } |
| 7400 | |
| 7401 | /* now we've checked all possible ways to reference a backend |
| 7402 | * from a frontend. |
| 7403 | */ |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 7404 | if (!found) |
| 7405 | continue; |
| 7406 | total += fe->maxconn; |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 7407 | } |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 7408 | /* we have the sum of the maxconns in <total>. We only |
| 7409 | * keep 10% of that sum to set the default fullconn, with |
| 7410 | * a hard minimum of 1 (to avoid a divide by zero). |
| 7411 | */ |
| 7412 | curproxy->fullconn = (total + 9) / 10; |
| 7413 | if (!curproxy->fullconn) |
| 7414 | curproxy->fullconn = 1; |
| 7415 | } |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 7416 | } |
| 7417 | |
Willy Tarreau | 056f568 | 2010-06-06 15:51:11 +0200 | [diff] [blame] | 7418 | /* initialize stick-tables on backend capable proxies. This must not |
| 7419 | * be done earlier because the data size may be discovered while parsing |
| 7420 | * other proxies. |
| 7421 | */ |
Godbach | 9703e66 | 2013-12-11 21:11:41 +0800 | [diff] [blame] | 7422 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
Willy Tarreau | 5830213 | 2014-02-24 20:59:47 +0100 | [diff] [blame] | 7423 | if (curproxy->state == PR_STSTOPPED) |
| 7424 | continue; |
| 7425 | |
Godbach | 9703e66 | 2013-12-11 21:11:41 +0800 | [diff] [blame] | 7426 | if (!stktable_init(&curproxy->table)) { |
| 7427 | Alert("Proxy '%s': failed to initialize stick-table.\n", curproxy->id); |
| 7428 | cfgerr++; |
| 7429 | } |
| 7430 | } |
Willy Tarreau | 056f568 | 2010-06-06 15:51:11 +0200 | [diff] [blame] | 7431 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7432 | /* |
| 7433 | * Recount currently required checks. |
| 7434 | */ |
| 7435 | |
| 7436 | for (curproxy=proxy; curproxy; curproxy=curproxy->next) { |
| 7437 | int optnum; |
| 7438 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 7439 | for (optnum = 0; cfg_opts[optnum].name; optnum++) |
| 7440 | if (curproxy->options & cfg_opts[optnum].val) |
| 7441 | global.last_checks |= cfg_opts[optnum].checks; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7442 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 7443 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) |
| 7444 | if (curproxy->options2 & cfg_opts2[optnum].val) |
| 7445 | global.last_checks |= cfg_opts2[optnum].checks; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7446 | } |
| 7447 | |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 7448 | if (peers) { |
| 7449 | struct peers *curpeers = peers, **last; |
| 7450 | struct peer *p, *pb; |
| 7451 | |
| 7452 | /* Remove all peers sections which don't have a valid listener. |
| 7453 | * This can happen when a peers section is never referenced and |
| 7454 | * does not contain a local peer. |
| 7455 | */ |
| 7456 | last = &peers; |
| 7457 | while (*last) { |
| 7458 | curpeers = *last; |
| 7459 | if (curpeers->peers_fe) { |
| 7460 | last = &curpeers->next; |
| 7461 | continue; |
| 7462 | } |
| 7463 | |
| 7464 | Warning("Removing incomplete section 'peers %s' (no peer named '%s').\n", |
| 7465 | curpeers->id, localpeer); |
| 7466 | |
| 7467 | p = curpeers->remote; |
| 7468 | while (p) { |
| 7469 | pb = p->next; |
| 7470 | free(p->id); |
| 7471 | free(p); |
| 7472 | p = pb; |
| 7473 | } |
| 7474 | |
| 7475 | /* Destroy and unlink this curpeers section. |
| 7476 | * Note: curpeers is backed up into *last. |
| 7477 | */ |
| 7478 | free(curpeers->id); |
| 7479 | curpeers = curpeers->next; |
| 7480 | free(*last); |
| 7481 | *last = curpeers; |
| 7482 | } |
| 7483 | } |
| 7484 | |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 7485 | pool2_hdr_idx = create_pool("hdr_idx", |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame] | 7486 | global.tune.max_http_hdr * sizeof(struct hdr_idx_elem), |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 7487 | MEM_F_SHARED); |
| 7488 | |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 7489 | if (cfgerr > 0) |
| 7490 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7491 | out: |
| 7492 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7493 | } |
| 7494 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 7495 | /* |
| 7496 | * Registers the CFG keyword list <kwl> as a list of valid keywords for next |
| 7497 | * parsing sessions. |
| 7498 | */ |
| 7499 | void cfg_register_keywords(struct cfg_kw_list *kwl) |
| 7500 | { |
| 7501 | LIST_ADDQ(&cfg_keywords.list, &kwl->list); |
| 7502 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7503 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 7504 | /* |
| 7505 | * Unregisters the CFG keyword list <kwl> from the list of valid keywords. |
| 7506 | */ |
| 7507 | void cfg_unregister_keywords(struct cfg_kw_list *kwl) |
| 7508 | { |
| 7509 | LIST_DEL(&kwl->list); |
| 7510 | LIST_INIT(&kwl->list); |
| 7511 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7512 | |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 7513 | /* this function register new section in the haproxy configuration file. |
| 7514 | * <section_name> is the name of this new section and <section_parser> |
| 7515 | * is the called parser. If two section declaration have the same name, |
| 7516 | * only the first declared is used. |
| 7517 | */ |
| 7518 | int cfg_register_section(char *section_name, |
| 7519 | int (*section_parser)(const char *, int, char **, int)) |
| 7520 | { |
| 7521 | struct cfg_section *cs; |
| 7522 | |
| 7523 | cs = calloc(1, sizeof(*cs)); |
| 7524 | if (!cs) { |
| 7525 | Alert("register section '%s': out of memory.\n", section_name); |
| 7526 | return 0; |
| 7527 | } |
| 7528 | |
| 7529 | cs->section_name = section_name; |
| 7530 | cs->section_parser = section_parser; |
| 7531 | |
| 7532 | LIST_ADDQ(§ions, &cs->list); |
| 7533 | |
| 7534 | return 1; |
| 7535 | } |
| 7536 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7537 | /* |
| 7538 | * Local variables: |
| 7539 | * c-indent-level: 8 |
| 7540 | * c-basic-offset: 8 |
| 7541 | * End: |
| 7542 | */ |