Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Configuration parser |
| 3 | * |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 4 | * Copyright 2000-2011 Willy Tarreau <w@1wt.eu> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * as published by the Free Software Foundation; either version |
| 9 | * 2 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | */ |
| 12 | |
Cyril Bonté | 2c8d700 | 2014-08-29 20:20:02 +0200 | [diff] [blame^] | 13 | #ifdef CONFIG_HAP_CRYPT |
| 14 | /* This is to have crypt() defined on Linux */ |
| 15 | #define _GNU_SOURCE |
| 16 | |
| 17 | #ifdef NEED_CRYPT_H |
| 18 | /* some platforms such as Solaris need this */ |
| 19 | #include <crypt.h> |
| 20 | #endif |
| 21 | #endif /* CONFIG_HAP_CRYPT */ |
| 22 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 23 | #include <stdio.h> |
| 24 | #include <stdlib.h> |
| 25 | #include <string.h> |
| 26 | #include <netdb.h> |
| 27 | #include <ctype.h> |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 28 | #include <pwd.h> |
| 29 | #include <grp.h> |
Willy Tarreau | 0b4ed90 | 2007-03-26 00:18:40 +0200 | [diff] [blame] | 30 | #include <errno.h> |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 31 | #include <sys/types.h> |
| 32 | #include <sys/stat.h> |
| 33 | #include <fcntl.h> |
| 34 | #include <unistd.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 35 | |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 36 | #include <common/cfgparse.h> |
Willy Tarreau | c7e4238 | 2012-08-24 19:22:53 +0200 | [diff] [blame] | 37 | #include <common/chunk.h> |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 38 | #include <common/config.h> |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 39 | #include <common/errors.h> |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 40 | #include <common/memory.h> |
| 41 | #include <common/standard.h> |
| 42 | #include <common/time.h> |
| 43 | #include <common/uri_auth.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 44 | |
| 45 | #include <types/capture.h> |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 46 | #include <types/compression.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 47 | #include <types/global.h> |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 48 | #include <types/obj_type.h> |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 49 | #include <types/peers.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 50 | |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 51 | #include <proto/acl.h> |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 52 | #include <proto/auth.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 53 | #include <proto/backend.h> |
Willy Tarreau | c7e4238 | 2012-08-24 19:22:53 +0200 | [diff] [blame] | 54 | #include <proto/channel.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 55 | #include <proto/checks.h> |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 56 | #include <proto/compression.h> |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 57 | #include <proto/dumpstats.h> |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 58 | #include <proto/frontend.h> |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 59 | #include <proto/hdr_idx.h> |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 60 | #include <proto/lb_chash.h> |
Willy Tarreau | f09c660 | 2012-02-13 17:12:08 +0100 | [diff] [blame] | 61 | #include <proto/lb_fas.h> |
Willy Tarreau | f89c187 | 2009-10-01 11:19:37 +0200 | [diff] [blame] | 62 | #include <proto/lb_fwlc.h> |
| 63 | #include <proto/lb_fwrr.h> |
| 64 | #include <proto/lb_map.h> |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 65 | #include <proto/listener.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 66 | #include <proto/log.h> |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 67 | #include <proto/protocol.h> |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 68 | #include <proto/proto_tcp.h> |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 69 | #include <proto/proto_uxst.h> |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 70 | #include <proto/proto_http.h> |
Willy Tarreau | 2b5652f | 2006-12-31 17:46:05 +0100 | [diff] [blame] | 71 | #include <proto/proxy.h> |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 72 | #include <proto/peers.h> |
Willy Tarreau | cd3b094 | 2012-04-27 21:52:18 +0200 | [diff] [blame] | 73 | #include <proto/sample.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 74 | #include <proto/server.h> |
Willy Tarreau | 3bc1377 | 2008-12-07 11:50:35 +0100 | [diff] [blame] | 75 | #include <proto/session.h> |
Willy Tarreau | 75bf2c9 | 2012-08-20 17:01:35 +0200 | [diff] [blame] | 76 | #include <proto/raw_sock.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 77 | #include <proto/task.h> |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 78 | #include <proto/stick_table.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 79 | |
Emeric Brun | fc0421f | 2012-09-07 17:30:07 +0200 | [diff] [blame] | 80 | #ifdef USE_OPENSSL |
| 81 | #include <types/ssl_sock.h> |
| 82 | #include <proto/ssl_sock.h> |
| 83 | #include <proto/shctx.h> |
| 84 | #endif /*USE_OPENSSL */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 85 | |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 86 | /* This is the SSLv3 CLIENT HELLO packet used in conjunction with the |
| 87 | * ssl-hello-chk option to ensure that the remote server speaks SSL. |
| 88 | * |
| 89 | * Check RFC 2246 (TLSv1.0) sections A.3 and A.4 for details. |
| 90 | */ |
| 91 | const char sslv3_client_hello_pkt[] = { |
| 92 | "\x16" /* ContentType : 0x16 = Hanshake */ |
| 93 | "\x03\x00" /* ProtocolVersion : 0x0300 = SSLv3 */ |
| 94 | "\x00\x79" /* ContentLength : 0x79 bytes after this one */ |
| 95 | "\x01" /* HanshakeType : 0x01 = CLIENT HELLO */ |
| 96 | "\x00\x00\x75" /* HandshakeLength : 0x75 bytes after this one */ |
| 97 | "\x03\x00" /* Hello Version : 0x0300 = v3 */ |
| 98 | "\x00\x00\x00\x00" /* Unix GMT Time (s) : filled with <now> (@0x0B) */ |
| 99 | "HAPROXYSSLCHK\nHAPROXYSSLCHK\n" /* Random : must be exactly 28 bytes */ |
| 100 | "\x00" /* Session ID length : empty (no session ID) */ |
| 101 | "\x00\x4E" /* Cipher Suite Length : 78 bytes after this one */ |
| 102 | "\x00\x01" "\x00\x02" "\x00\x03" "\x00\x04" /* 39 most common ciphers : */ |
| 103 | "\x00\x05" "\x00\x06" "\x00\x07" "\x00\x08" /* 0x01...0x1B, 0x2F...0x3A */ |
| 104 | "\x00\x09" "\x00\x0A" "\x00\x0B" "\x00\x0C" /* This covers RSA/DH, */ |
| 105 | "\x00\x0D" "\x00\x0E" "\x00\x0F" "\x00\x10" /* various bit lengths, */ |
| 106 | "\x00\x11" "\x00\x12" "\x00\x13" "\x00\x14" /* SHA1/MD5, DES/3DES/AES... */ |
| 107 | "\x00\x15" "\x00\x16" "\x00\x17" "\x00\x18" |
| 108 | "\x00\x19" "\x00\x1A" "\x00\x1B" "\x00\x2F" |
| 109 | "\x00\x30" "\x00\x31" "\x00\x32" "\x00\x33" |
| 110 | "\x00\x34" "\x00\x35" "\x00\x36" "\x00\x37" |
| 111 | "\x00\x38" "\x00\x39" "\x00\x3A" |
| 112 | "\x01" /* Compression Length : 0x01 = 1 byte for types */ |
| 113 | "\x00" /* Compression Type : 0x00 = NULL compression */ |
| 114 | }; |
| 115 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 116 | /* various keyword modifiers */ |
| 117 | enum kw_mod { |
| 118 | KWM_STD = 0, /* normal */ |
| 119 | KWM_NO, /* "no" prefixed before the keyword */ |
| 120 | KWM_DEF, /* "default" prefixed before the keyword */ |
| 121 | }; |
| 122 | |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 123 | /* permit to store configuration section */ |
| 124 | struct cfg_section { |
| 125 | struct list list; |
| 126 | char *section_name; |
| 127 | int (*section_parser)(const char *, int, char **, int); |
| 128 | }; |
| 129 | |
| 130 | /* Used to chain configuration sections definitions. This list |
| 131 | * stores struct cfg_section |
| 132 | */ |
| 133 | struct list sections = LIST_HEAD_INIT(sections); |
| 134 | |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 135 | /* some of the most common options which are also the easiest to handle */ |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 136 | struct cfg_opt { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 137 | const char *name; |
| 138 | unsigned int val; |
| 139 | unsigned int cap; |
Willy Tarreau | 4fee4e9 | 2007-01-06 21:09:17 +0100 | [diff] [blame] | 140 | unsigned int checks; |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 141 | unsigned int mode; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 142 | }; |
| 143 | |
| 144 | /* proxy->options */ |
| 145 | static const struct cfg_opt cfg_opts[] = |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 146 | { |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 147 | { "abortonclose", PR_O_ABRT_CLOSE, PR_CAP_BE, 0, 0 }, |
| 148 | { "allbackups", PR_O_USE_ALL_BK, PR_CAP_BE, 0, 0 }, |
| 149 | { "checkcache", PR_O_CHK_CACHE, PR_CAP_BE, 0, PR_MODE_HTTP }, |
| 150 | { "clitcpka", PR_O_TCP_CLI_KA, PR_CAP_FE, 0, 0 }, |
| 151 | { "contstats", PR_O_CONTSTATS, PR_CAP_FE, 0, 0 }, |
| 152 | { "dontlognull", PR_O_NULLNOLOG, PR_CAP_FE, 0, 0 }, |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 153 | { "http_proxy", PR_O_HTTP_PROXY, PR_CAP_FE | PR_CAP_BE, 0, PR_MODE_HTTP }, |
Willy Tarreau | 9420b12 | 2013-12-15 18:58:25 +0100 | [diff] [blame] | 154 | { "prefer-last-server", PR_O_PREF_LAST, PR_CAP_BE, 0, PR_MODE_HTTP }, |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 155 | { "logasap", PR_O_LOGASAP, PR_CAP_FE, 0, 0 }, |
| 156 | { "nolinger", PR_O_TCP_NOLING, PR_CAP_FE | PR_CAP_BE, 0, 0 }, |
| 157 | { "persist", PR_O_PERSIST, PR_CAP_BE, 0, 0 }, |
| 158 | { "redispatch", PR_O_REDISP, PR_CAP_BE, 0, 0 }, |
| 159 | { "srvtcpka", PR_O_TCP_SRV_KA, PR_CAP_BE, 0, 0 }, |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 160 | #ifdef TPROXY |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 161 | { "transparent", PR_O_TRANSP, PR_CAP_BE, 0, 0 }, |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 162 | #else |
| 163 | { "transparent", 0, 0, 0, 0 }, |
Willy Tarreau | 8f922fc | 2007-01-06 21:11:49 +0100 | [diff] [blame] | 164 | #endif |
| 165 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 166 | { NULL, 0, 0, 0, 0 } |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 167 | }; |
| 168 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 169 | /* proxy->options2 */ |
| 170 | static const struct cfg_opt cfg_opts2[] = |
| 171 | { |
| 172 | #ifdef CONFIG_HAP_LINUX_SPLICE |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 173 | { "splice-request", PR_O2_SPLIC_REQ, PR_CAP_FE|PR_CAP_BE, 0, 0 }, |
| 174 | { "splice-response", PR_O2_SPLIC_RTR, PR_CAP_FE|PR_CAP_BE, 0, 0 }, |
| 175 | { "splice-auto", PR_O2_SPLIC_AUT, PR_CAP_FE|PR_CAP_BE, 0, 0 }, |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 176 | #else |
| 177 | { "splice-request", 0, 0, 0, 0 }, |
| 178 | { "splice-response", 0, 0, 0, 0 }, |
| 179 | { "splice-auto", 0, 0, 0, 0 }, |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 180 | #endif |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 181 | { "accept-invalid-http-request", PR_O2_REQBUG_OK, PR_CAP_FE, 0, PR_MODE_HTTP }, |
| 182 | { "accept-invalid-http-response", PR_O2_RSPBUG_OK, PR_CAP_BE, 0, PR_MODE_HTTP }, |
| 183 | { "dontlog-normal", PR_O2_NOLOGNORM, PR_CAP_FE, 0, 0 }, |
| 184 | { "log-separate-errors", PR_O2_LOGERRORS, PR_CAP_FE, 0, 0 }, |
| 185 | { "log-health-checks", PR_O2_LOGHCHKS, PR_CAP_BE, 0, 0 }, |
| 186 | { "socket-stats", PR_O2_SOCKSTAT, PR_CAP_FE, 0, 0 }, |
| 187 | { "tcp-smart-accept", PR_O2_SMARTACC, PR_CAP_FE, 0, 0 }, |
| 188 | { "tcp-smart-connect", PR_O2_SMARTCON, PR_CAP_BE, 0, 0 }, |
| 189 | { "independant-streams", PR_O2_INDEPSTR, PR_CAP_FE|PR_CAP_BE, 0, 0 }, |
Jamie Gloudon | 801a0a3 | 2012-08-25 00:18:33 -0400 | [diff] [blame] | 190 | { "independent-streams", PR_O2_INDEPSTR, PR_CAP_FE|PR_CAP_BE, 0, 0 }, |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 191 | { "http-use-proxy-header", PR_O2_USE_PXHDR, PR_CAP_FE, 0, PR_MODE_HTTP }, |
Willy Tarreau | e52564c | 2010-04-27 22:19:14 +0200 | [diff] [blame] | 192 | { "http-pretend-keepalive", PR_O2_FAKE_KA, PR_CAP_FE|PR_CAP_BE, 0, PR_MODE_HTTP }, |
Willy Tarreau | 96e3121 | 2011-05-30 18:10:30 +0200 | [diff] [blame] | 193 | { "http-no-delay", PR_O2_NODELAY, PR_CAP_FE|PR_CAP_BE, 0, PR_MODE_HTTP }, |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 194 | { NULL, 0, 0, 0 } |
| 195 | }; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 196 | |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 197 | static char *cursection = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 198 | static struct proxy defproxy; /* fake proxy used to assign default values on all instances */ |
| 199 | int cfg_maxpconn = DEFAULT_MAXCONN; /* # of simultaneous connections per proxy (-N) */ |
Willy Tarreau | 5af24ef | 2009-03-15 15:23:16 +0100 | [diff] [blame] | 200 | int cfg_maxconn = 0; /* # of simultaneous connections, (-n) */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 201 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 202 | /* List head of all known configuration keywords */ |
| 203 | static struct cfg_kw_list cfg_keywords = { |
| 204 | .list = LIST_HEAD_INIT(cfg_keywords.list) |
| 205 | }; |
| 206 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 207 | /* |
| 208 | * converts <str> to a list of listeners which are dynamically allocated. |
| 209 | * The format is "{addr|'*'}:port[-end][,{addr|'*'}:port[-end]]*", where : |
| 210 | * - <addr> can be empty or "*" to indicate INADDR_ANY ; |
| 211 | * - <port> is a numerical port from 1 to 65535 ; |
| 212 | * - <end> indicates to use the range from <port> to <end> instead (inclusive). |
| 213 | * This can be repeated as many times as necessary, separated by a coma. |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 214 | * Function returns 1 for success or 0 if error. In case of errors, if <err> is |
| 215 | * not NULL, it must be a valid pointer to either NULL or a freeable area that |
| 216 | * will be replaced with an error message. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 217 | */ |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 218 | int str2listener(char *str, struct proxy *curproxy, struct bind_conf *bind_conf, const char *file, int line, char **err) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 219 | { |
| 220 | struct listener *l; |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 221 | char *next, *dupstr; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 222 | int port, end; |
| 223 | |
| 224 | next = dupstr = strdup(str); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 225 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 226 | while (next && *next) { |
Willy Tarreau | 12eb2a6 | 2013-03-06 15:45:03 +0100 | [diff] [blame] | 227 | struct sockaddr_storage ss, *ss2; |
Willy Tarreau | 40aa070 | 2013-03-10 23:51:38 +0100 | [diff] [blame] | 228 | int fd = -1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 229 | |
| 230 | str = next; |
| 231 | /* 1) look for the end of the first address */ |
Krzysztof Piotr Oledzki | 52d522b | 2009-01-27 16:57:08 +0100 | [diff] [blame] | 232 | if ((next = strchr(str, ',')) != NULL) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 233 | *next++ = 0; |
| 234 | } |
| 235 | |
Willy Tarreau | 12eb2a6 | 2013-03-06 15:45:03 +0100 | [diff] [blame] | 236 | ss2 = str2sa_range(str, &port, &end, err, |
| 237 | curproxy == global.stats_fe ? NULL : global.unix_bind.prefix); |
| 238 | if (!ss2) |
| 239 | goto fail; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 240 | |
Willy Tarreau | 12eb2a6 | 2013-03-06 15:45:03 +0100 | [diff] [blame] | 241 | if (ss2->ss_family == AF_INET || ss2->ss_family == AF_INET6) { |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 242 | if (!port && !end) { |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 243 | memprintf(err, "missing port number: '%s'\n", str); |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 244 | goto fail; |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 245 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 246 | |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 247 | if (!port || !end) { |
| 248 | memprintf(err, "port offsets are not allowed in 'bind': '%s'\n", str); |
| 249 | goto fail; |
| 250 | } |
| 251 | |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 252 | if (port < 1 || port > 65535) { |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 253 | memprintf(err, "invalid port '%d' specified for address '%s'.\n", port, str); |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 254 | goto fail; |
| 255 | } |
| 256 | |
| 257 | if (end < 1 || end > 65535) { |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 258 | memprintf(err, "invalid port '%d' specified for address '%s'.\n", end, str); |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 259 | goto fail; |
| 260 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 261 | } |
Willy Tarreau | 40aa070 | 2013-03-10 23:51:38 +0100 | [diff] [blame] | 262 | else if (ss2->ss_family == AF_UNSPEC) { |
| 263 | socklen_t addr_len; |
| 264 | |
| 265 | /* We want to attach to an already bound fd whose number |
| 266 | * is in the addr part of ss2 when cast to sockaddr_in. |
| 267 | * Note that by definition there is a single listener. |
| 268 | * We still have to determine the address family to |
| 269 | * register the correct protocol. |
| 270 | */ |
| 271 | fd = ((struct sockaddr_in *)ss2)->sin_addr.s_addr; |
| 272 | addr_len = sizeof(*ss2); |
| 273 | if (getsockname(fd, (struct sockaddr *)ss2, &addr_len) == -1) { |
| 274 | memprintf(err, "cannot use file descriptor '%d' : %s.\n", fd, strerror(errno)); |
| 275 | goto fail; |
| 276 | } |
| 277 | |
| 278 | port = end = get_host_port(ss2); |
| 279 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 280 | |
Willy Tarreau | 12eb2a6 | 2013-03-06 15:45:03 +0100 | [diff] [blame] | 281 | /* OK the address looks correct */ |
| 282 | ss = *ss2; |
| 283 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 284 | for (; port <= end; port++) { |
| 285 | l = (struct listener *)calloc(1, sizeof(struct listener)); |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 286 | l->obj_type = OBJ_TYPE_LISTENER; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 287 | LIST_ADDQ(&curproxy->conf.listeners, &l->by_fe); |
| 288 | LIST_ADDQ(&bind_conf->listeners, &l->by_bind); |
| 289 | l->frontend = curproxy; |
| 290 | l->bind_conf = bind_conf; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 291 | |
Willy Tarreau | 40aa070 | 2013-03-10 23:51:38 +0100 | [diff] [blame] | 292 | l->fd = fd; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 293 | l->addr = ss; |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 294 | l->xprt = &raw_sock; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 295 | l->state = LI_INIT; |
| 296 | |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 297 | if (ss.ss_family == AF_INET) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 298 | ((struct sockaddr_in *)(&l->addr))->sin_port = htons(port); |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 299 | tcpv4_add_listener(l); |
| 300 | } |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 301 | else if (ss.ss_family == AF_INET6) { |
| 302 | ((struct sockaddr_in6 *)(&l->addr))->sin6_port = htons(port); |
| 303 | tcpv6_add_listener(l); |
| 304 | } |
| 305 | else { |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 306 | uxst_add_listener(l); |
| 307 | } |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 308 | |
Willy Tarreau | af7ad00 | 2010-08-31 15:39:26 +0200 | [diff] [blame] | 309 | jobs++; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 310 | listeners++; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 311 | } /* end for(port) */ |
| 312 | } /* end while(next) */ |
| 313 | free(dupstr); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 314 | return 1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 315 | fail: |
| 316 | free(dupstr); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 317 | return 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 318 | } |
| 319 | |
Willy Tarreau | 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 | } |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 869 | /* user/group name handling */ |
| 870 | else if (!strcmp(args[0], "user")) { |
| 871 | struct passwd *ha_user; |
| 872 | if (global.uid != 0) { |
| 873 | Alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 874 | err_code |= ERR_ALERT; |
| 875 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 876 | } |
| 877 | errno = 0; |
| 878 | ha_user = getpwnam(args[1]); |
| 879 | if (ha_user != NULL) { |
| 880 | global.uid = (int)ha_user->pw_uid; |
| 881 | } |
| 882 | else { |
| 883 | 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] | 884 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 885 | } |
| 886 | } |
| 887 | else if (!strcmp(args[0], "group")) { |
| 888 | struct group *ha_group; |
| 889 | if (global.gid != 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 890 | 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] | 891 | err_code |= ERR_ALERT; |
| 892 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 893 | } |
| 894 | errno = 0; |
| 895 | ha_group = getgrnam(args[1]); |
| 896 | if (ha_group != NULL) { |
| 897 | global.gid = (int)ha_group->gr_gid; |
| 898 | } |
| 899 | else { |
| 900 | 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] | 901 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 902 | } |
| 903 | } |
| 904 | /* end of user/group name handling*/ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 905 | else if (!strcmp(args[0], "nbproc")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 906 | if (*(args[1]) == 0) { |
| 907 | 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] | 908 | err_code |= ERR_ALERT | ERR_FATAL; |
| 909 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 910 | } |
| 911 | global.nbproc = atol(args[1]); |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 912 | if (global.nbproc < 1 || global.nbproc > LONGBITS) { |
| 913 | Alert("parsing [%s:%d] : '%s' must be between 1 and %d (was %d).\n", |
| 914 | file, linenum, args[0], LONGBITS, global.nbproc); |
| 915 | err_code |= ERR_ALERT | ERR_FATAL; |
| 916 | goto out; |
| 917 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 918 | } |
| 919 | else if (!strcmp(args[0], "maxconn")) { |
| 920 | if (global.maxconn != 0) { |
| 921 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 922 | err_code |= ERR_ALERT; |
| 923 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 924 | } |
| 925 | if (*(args[1]) == 0) { |
| 926 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 927 | err_code |= ERR_ALERT | ERR_FATAL; |
| 928 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 929 | } |
| 930 | global.maxconn = atol(args[1]); |
| 931 | #ifdef SYSTEM_MAXCONN |
| 932 | if (global.maxconn > DEFAULT_MAXCONN && cfg_maxconn <= DEFAULT_MAXCONN) { |
| 933 | 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); |
| 934 | global.maxconn = DEFAULT_MAXCONN; |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 935 | err_code |= ERR_ALERT; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 936 | } |
| 937 | #endif /* SYSTEM_MAXCONN */ |
| 938 | } |
Willy Tarreau | 403edff | 2012-09-06 11:58:37 +0200 | [diff] [blame] | 939 | else if (!strcmp(args[0], "maxsslconn")) { |
| 940 | #ifdef USE_OPENSSL |
| 941 | if (*(args[1]) == 0) { |
| 942 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 943 | err_code |= ERR_ALERT | ERR_FATAL; |
| 944 | goto out; |
| 945 | } |
| 946 | global.maxsslconn = atol(args[1]); |
| 947 | #else |
Emeric Brun | 0914df8 | 2012-10-02 18:45:42 +0200 | [diff] [blame] | 948 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 949 | err_code |= ERR_ALERT | ERR_FATAL; |
| 950 | goto out; |
Willy Tarreau | 403edff | 2012-09-06 11:58:37 +0200 | [diff] [blame] | 951 | #endif |
| 952 | } |
Willy Tarreau | 610f04b | 2014-02-13 11:36:41 +0100 | [diff] [blame] | 953 | else if (!strcmp(args[0], "ssl-default-bind-ciphers")) { |
| 954 | #ifdef USE_OPENSSL |
| 955 | if (*(args[1]) == 0) { |
| 956 | Alert("parsing [%s:%d] : '%s' expects a cipher suite as an argument.\n", file, linenum, args[0]); |
| 957 | err_code |= ERR_ALERT | ERR_FATAL; |
| 958 | goto out; |
| 959 | } |
| 960 | free(global.listen_default_ciphers); |
| 961 | global.listen_default_ciphers = strdup(args[1]); |
| 962 | #else |
| 963 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 964 | err_code |= ERR_ALERT | ERR_FATAL; |
| 965 | goto out; |
| 966 | #endif |
| 967 | } |
| 968 | else if (!strcmp(args[0], "ssl-default-server-ciphers")) { |
| 969 | #ifdef USE_OPENSSL |
| 970 | if (*(args[1]) == 0) { |
| 971 | Alert("parsing [%s:%d] : '%s' expects a cipher suite as an argument.\n", file, linenum, args[0]); |
| 972 | err_code |= ERR_ALERT | ERR_FATAL; |
| 973 | goto out; |
| 974 | } |
| 975 | free(global.connect_default_ciphers); |
| 976 | global.connect_default_ciphers = strdup(args[1]); |
| 977 | #else |
| 978 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 979 | err_code |= ERR_ALERT | ERR_FATAL; |
| 980 | goto out; |
| 981 | #endif |
| 982 | } |
Emeric Brun | 850efd5 | 2014-01-29 12:24:34 +0100 | [diff] [blame] | 983 | else if (!strcmp(args[0], "ssl-server-verify")) { |
| 984 | if (*(args[1]) == 0) { |
| 985 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 986 | err_code |= ERR_ALERT | ERR_FATAL; |
| 987 | goto out; |
| 988 | } |
| 989 | if (strcmp(args[1],"none") == 0) |
| 990 | global.ssl_server_verify = SSL_SERVER_VERIFY_NONE; |
| 991 | else if (strcmp(args[1],"required") == 0) |
| 992 | global.ssl_server_verify = SSL_SERVER_VERIFY_REQUIRED; |
| 993 | else { |
| 994 | Alert("parsing [%s:%d] : '%s' expects 'none' or 'required' as argument.\n", file, linenum, args[0]); |
| 995 | err_code |= ERR_ALERT | ERR_FATAL; |
| 996 | goto out; |
| 997 | } |
| 998 | } |
Willy Tarreau | 81c25d0 | 2011-09-07 15:17:21 +0200 | [diff] [blame] | 999 | else if (!strcmp(args[0], "maxconnrate")) { |
| 1000 | if (global.cps_lim != 0) { |
| 1001 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 1002 | err_code |= ERR_ALERT; |
| 1003 | goto out; |
| 1004 | } |
| 1005 | if (*(args[1]) == 0) { |
| 1006 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1007 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1008 | goto out; |
| 1009 | } |
| 1010 | global.cps_lim = atol(args[1]); |
| 1011 | } |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1012 | else if (!strcmp(args[0], "maxsessrate")) { |
| 1013 | if (global.sps_lim != 0) { |
| 1014 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 1015 | err_code |= ERR_ALERT; |
| 1016 | goto out; |
| 1017 | } |
| 1018 | if (*(args[1]) == 0) { |
| 1019 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1020 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1021 | goto out; |
| 1022 | } |
| 1023 | global.sps_lim = atol(args[1]); |
| 1024 | } |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 1025 | else if (!strcmp(args[0], "maxsslrate")) { |
| 1026 | if (global.ssl_lim != 0) { |
| 1027 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 1028 | err_code |= ERR_ALERT; |
| 1029 | goto out; |
| 1030 | } |
| 1031 | if (*(args[1]) == 0) { |
| 1032 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1033 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1034 | goto out; |
| 1035 | } |
| 1036 | global.ssl_lim = atol(args[1]); |
| 1037 | } |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1038 | else if (!strcmp(args[0], "maxcomprate")) { |
| 1039 | if (*(args[1]) == 0) { |
| 1040 | Alert("parsing [%s:%d] : '%s' expects an integer argument in kb/s.\n", file, linenum, args[0]); |
| 1041 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1042 | goto out; |
| 1043 | } |
| 1044 | global.comp_rate_lim = atoi(args[1]) * 1024; |
| 1045 | } |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 1046 | else if (!strcmp(args[0], "maxpipes")) { |
| 1047 | if (global.maxpipes != 0) { |
| 1048 | 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] | 1049 | err_code |= ERR_ALERT; |
| 1050 | goto out; |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 1051 | } |
| 1052 | if (*(args[1]) == 0) { |
| 1053 | 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] | 1054 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1055 | goto out; |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 1056 | } |
| 1057 | global.maxpipes = atol(args[1]); |
| 1058 | } |
William Lallemand | 9d5f548 | 2012-11-07 16:12:57 +0100 | [diff] [blame] | 1059 | else if (!strcmp(args[0], "maxzlibmem")) { |
| 1060 | if (*(args[1]) == 0) { |
| 1061 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1062 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1063 | goto out; |
| 1064 | } |
William Lallemand | e3a7d99 | 2012-11-20 11:25:20 +0100 | [diff] [blame] | 1065 | global.maxzlibmem = atol(args[1]) * 1024L * 1024L; |
William Lallemand | 9d5f548 | 2012-11-07 16:12:57 +0100 | [diff] [blame] | 1066 | } |
William Lallemand | 072a2bf | 2012-11-20 17:01:01 +0100 | [diff] [blame] | 1067 | else if (!strcmp(args[0], "maxcompcpuusage")) { |
| 1068 | if (*(args[1]) == 0) { |
| 1069 | Alert("parsing [%s:%d] : '%s' expects an integer argument between 0 and 100.\n", file, linenum, args[0]); |
| 1070 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1071 | goto out; |
| 1072 | } |
| 1073 | compress_min_idle = 100 - atoi(args[1]); |
Willy Tarreau | cb2699a | 2013-01-24 16:25:38 +0100 | [diff] [blame] | 1074 | if (compress_min_idle > 100) { |
William Lallemand | 072a2bf | 2012-11-20 17:01:01 +0100 | [diff] [blame] | 1075 | Alert("parsing [%s:%d] : '%s' expects an integer argument between 0 and 100.\n", file, linenum, args[0]); |
| 1076 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1077 | goto out; |
| 1078 | } |
| 1079 | } |
| 1080 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1081 | else if (!strcmp(args[0], "ulimit-n")) { |
| 1082 | if (global.rlimit_nofile != 0) { |
| 1083 | 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] | 1084 | err_code |= ERR_ALERT; |
| 1085 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1086 | } |
| 1087 | if (*(args[1]) == 0) { |
| 1088 | 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] | 1089 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1090 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1091 | } |
| 1092 | global.rlimit_nofile = atol(args[1]); |
| 1093 | } |
| 1094 | else if (!strcmp(args[0], "chroot")) { |
| 1095 | if (global.chroot != NULL) { |
| 1096 | 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] | 1097 | err_code |= ERR_ALERT; |
| 1098 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1099 | } |
| 1100 | if (*(args[1]) == 0) { |
| 1101 | 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] | 1102 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1103 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1104 | } |
| 1105 | global.chroot = strdup(args[1]); |
| 1106 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1107 | else if (!strcmp(args[0], "description")) { |
| 1108 | int i, len=0; |
| 1109 | char *d; |
| 1110 | |
| 1111 | if (!*args[1]) { |
| 1112 | Alert("parsing [%s:%d]: '%s' expects a string argument.\n", |
| 1113 | file, linenum, args[0]); |
| 1114 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1115 | goto out; |
| 1116 | } |
| 1117 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 1118 | for (i = 1; *args[i]; i++) |
| 1119 | len += strlen(args[i]) + 1; |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1120 | |
| 1121 | if (global.desc) |
| 1122 | free(global.desc); |
| 1123 | |
| 1124 | global.desc = d = (char *)calloc(1, len); |
| 1125 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 1126 | d += snprintf(d, global.desc + len - d, "%s", args[1]); |
| 1127 | for (i = 2; *args[i]; i++) |
| 1128 | d += snprintf(d, global.desc + len - d, " %s", args[i]); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1129 | } |
| 1130 | else if (!strcmp(args[0], "node")) { |
| 1131 | int i; |
| 1132 | char c; |
| 1133 | |
| 1134 | for (i=0; args[1][i]; i++) { |
| 1135 | c = args[1][i]; |
Willy Tarreau | 88e0581 | 2010-03-03 00:16:00 +0100 | [diff] [blame] | 1136 | if (!isupper((unsigned char)c) && !islower((unsigned char)c) && |
| 1137 | !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.') |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1138 | break; |
| 1139 | } |
| 1140 | |
| 1141 | if (!i || args[1][i]) { |
| 1142 | Alert("parsing [%s:%d]: '%s' requires valid node name - non-empty string" |
| 1143 | " with digits(0-9), letters(A-Z, a-z), dot(.), hyphen(-) or underscode(_).\n", |
| 1144 | file, linenum, args[0]); |
| 1145 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1146 | goto out; |
| 1147 | } |
| 1148 | |
| 1149 | if (global.node) |
| 1150 | free(global.node); |
| 1151 | |
| 1152 | global.node = strdup(args[1]); |
| 1153 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1154 | else if (!strcmp(args[0], "pidfile")) { |
| 1155 | if (global.pidfile != NULL) { |
| 1156 | 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] | 1157 | err_code |= ERR_ALERT; |
| 1158 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1159 | } |
| 1160 | if (*(args[1]) == 0) { |
| 1161 | 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] | 1162 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1163 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1164 | } |
| 1165 | global.pidfile = strdup(args[1]); |
| 1166 | } |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 1167 | else if (!strcmp(args[0], "unix-bind")) { |
| 1168 | int cur_arg = 1; |
| 1169 | while (*(args[cur_arg])) { |
| 1170 | if (!strcmp(args[cur_arg], "prefix")) { |
| 1171 | if (global.unix_bind.prefix != NULL) { |
| 1172 | Alert("parsing [%s:%d] : unix-bind '%s' already specified. Continuing.\n", file, linenum, args[cur_arg]); |
| 1173 | err_code |= ERR_ALERT; |
| 1174 | cur_arg += 2; |
| 1175 | continue; |
| 1176 | } |
| 1177 | |
| 1178 | if (*(args[cur_arg+1]) == 0) { |
| 1179 | Alert("parsing [%s:%d] : unix_bind '%s' expects a path as an argument.\n", file, linenum, args[cur_arg]); |
| 1180 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1181 | goto out; |
| 1182 | } |
| 1183 | global.unix_bind.prefix = strdup(args[cur_arg+1]); |
| 1184 | cur_arg += 2; |
| 1185 | continue; |
| 1186 | } |
| 1187 | |
| 1188 | if (!strcmp(args[cur_arg], "mode")) { |
| 1189 | |
| 1190 | global.unix_bind.ux.mode = strtol(args[cur_arg + 1], NULL, 8); |
| 1191 | cur_arg += 2; |
| 1192 | continue; |
| 1193 | } |
| 1194 | |
| 1195 | if (!strcmp(args[cur_arg], "uid")) { |
| 1196 | |
| 1197 | global.unix_bind.ux.uid = atol(args[cur_arg + 1 ]); |
| 1198 | cur_arg += 2; |
| 1199 | continue; |
| 1200 | } |
| 1201 | |
| 1202 | if (!strcmp(args[cur_arg], "gid")) { |
| 1203 | |
| 1204 | global.unix_bind.ux.gid = atol(args[cur_arg + 1 ]); |
| 1205 | cur_arg += 2; |
| 1206 | continue; |
| 1207 | } |
| 1208 | |
| 1209 | if (!strcmp(args[cur_arg], "user")) { |
| 1210 | struct passwd *user; |
| 1211 | |
| 1212 | user = getpwnam(args[cur_arg + 1]); |
| 1213 | if (!user) { |
| 1214 | Alert("parsing [%s:%d] : '%s' : '%s' unknown user.\n", |
| 1215 | file, linenum, args[0], args[cur_arg + 1 ]); |
| 1216 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1217 | goto out; |
| 1218 | } |
| 1219 | |
| 1220 | global.unix_bind.ux.uid = user->pw_uid; |
| 1221 | cur_arg += 2; |
| 1222 | continue; |
| 1223 | } |
| 1224 | |
| 1225 | if (!strcmp(args[cur_arg], "group")) { |
| 1226 | struct group *group; |
| 1227 | |
| 1228 | group = getgrnam(args[cur_arg + 1]); |
| 1229 | if (!group) { |
| 1230 | Alert("parsing [%s:%d] : '%s' : '%s' unknown group.\n", |
| 1231 | file, linenum, args[0], args[cur_arg + 1 ]); |
| 1232 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1233 | goto out; |
| 1234 | } |
| 1235 | |
| 1236 | global.unix_bind.ux.gid = group->gr_gid; |
| 1237 | cur_arg += 2; |
| 1238 | continue; |
| 1239 | } |
| 1240 | |
Willy Tarreau | b48f958 | 2011-09-05 01:17:06 +0200 | [diff] [blame] | 1241 | 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] | 1242 | file, linenum, args[0]); |
| 1243 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1244 | goto out; |
| 1245 | } |
| 1246 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1247 | else if (!strcmp(args[0], "log") && kwm == KWM_NO) { /* no log */ |
| 1248 | /* delete previous herited or defined syslog servers */ |
| 1249 | struct logsrv *back; |
| 1250 | struct logsrv *tmp; |
| 1251 | |
| 1252 | if (*(args[1]) != 0) { |
| 1253 | Alert("parsing [%s:%d]:%s : 'no log' does not expect arguments.\n", file, linenum, args[1]); |
| 1254 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1255 | goto out; |
| 1256 | } |
| 1257 | |
| 1258 | list_for_each_entry_safe(tmp, back, &global.logsrvs, list) { |
| 1259 | LIST_DEL(&tmp->list); |
| 1260 | free(tmp); |
| 1261 | } |
| 1262 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1263 | else if (!strcmp(args[0], "log")) { /* syslog server address */ |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1264 | struct sockaddr_storage *sk; |
| 1265 | int port1, port2; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1266 | struct logsrv *logsrv; |
Willy Tarreau | dc2695c | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1267 | int arg = 0; |
| 1268 | int len = 0; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1269 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1270 | if (*(args[1]) == 0 || *(args[2]) == 0) { |
| 1271 | 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] | 1272 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1273 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1274 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1275 | |
| 1276 | logsrv = calloc(1, sizeof(struct logsrv)); |
| 1277 | |
Willy Tarreau | dc2695c | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1278 | /* just after the address, a length may be specified */ |
| 1279 | if (strcmp(args[arg+2], "len") == 0) { |
| 1280 | len = atoi(args[arg+3]); |
| 1281 | if (len < 80 || len > 65535) { |
| 1282 | Alert("parsing [%s:%d] : invalid log length '%s', must be between 80 and 65535.\n", |
| 1283 | file, linenum, args[arg+3]); |
| 1284 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1285 | goto out; |
| 1286 | } |
| 1287 | logsrv->maxlen = len; |
| 1288 | |
| 1289 | /* skip these two args */ |
| 1290 | arg += 2; |
| 1291 | } |
| 1292 | else |
| 1293 | logsrv->maxlen = MAX_SYSLOG_LEN; |
| 1294 | |
| 1295 | if (logsrv->maxlen > global.max_syslog_len) { |
| 1296 | global.max_syslog_len = logsrv->maxlen; |
| 1297 | logline = realloc(logline, global.max_syslog_len + 1); |
| 1298 | } |
| 1299 | |
| 1300 | logsrv->facility = get_log_facility(args[arg+2]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1301 | if (logsrv->facility < 0) { |
Willy Tarreau | dc2695c | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1302 | 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] | 1303 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1304 | logsrv->facility = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1305 | } |
| 1306 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1307 | logsrv->level = 7; /* max syslog level = debug */ |
Willy Tarreau | dc2695c | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1308 | if (*(args[arg+3])) { |
| 1309 | logsrv->level = get_log_level(args[arg+3]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1310 | if (logsrv->level < 0) { |
Willy Tarreau | dc2695c | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1311 | 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] | 1312 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1313 | logsrv->level = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1314 | } |
| 1315 | } |
| 1316 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1317 | logsrv->minlvl = 0; /* limit syslog level to this level (emerg) */ |
Willy Tarreau | dc2695c | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1318 | if (*(args[arg+4])) { |
| 1319 | logsrv->minlvl = get_log_level(args[arg+4]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1320 | if (logsrv->minlvl < 0) { |
Willy Tarreau | dc2695c | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1321 | 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] | 1322 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1323 | logsrv->minlvl = 0; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 1324 | } |
| 1325 | } |
| 1326 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1327 | sk = str2sa_range(args[1], &port1, &port2, &errmsg, NULL); |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1328 | if (!sk) { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1329 | Alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1330 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1331 | free(logsrv); |
| 1332 | goto out; |
| 1333 | } |
| 1334 | logsrv->addr = *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 1335 | |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1336 | if (sk->ss_family == AF_INET || sk->ss_family == AF_INET6) { |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 1337 | if (port1 != port2) { |
| 1338 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 1339 | file, linenum, args[0], args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 1340 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1341 | free(logsrv); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 1342 | goto out; |
| 1343 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 1344 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1345 | logsrv->addr = *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 1346 | if (!port1) |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1347 | set_host_port(&logsrv->addr, SYSLOG_PORT); |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 1348 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1349 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1350 | LIST_ADDQ(&global.logsrvs, &logsrv->list); |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1351 | } |
Joe Williams | df5b38f | 2010-12-29 17:05:48 +0100 | [diff] [blame] | 1352 | else if (!strcmp(args[0], "log-send-hostname")) { /* set the hostname in syslog header */ |
| 1353 | char *name; |
| 1354 | int len; |
| 1355 | |
| 1356 | if (global.log_send_hostname != NULL) { |
| 1357 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 1358 | err_code |= ERR_ALERT; |
| 1359 | goto out; |
| 1360 | } |
| 1361 | |
| 1362 | if (*(args[1])) |
| 1363 | name = args[1]; |
| 1364 | else |
| 1365 | name = hostname; |
| 1366 | |
| 1367 | len = strlen(name); |
| 1368 | |
| 1369 | /* We'll add a space after the name to respect the log format */ |
| 1370 | free(global.log_send_hostname); |
| 1371 | global.log_send_hostname = malloc(len + 2); |
| 1372 | snprintf(global.log_send_hostname, len + 2, "%s ", name); |
| 1373 | } |
Kevinm | 48936af | 2010-12-22 16:08:21 +0000 | [diff] [blame] | 1374 | else if (!strcmp(args[0], "log-tag")) { /* tag to report to syslog */ |
| 1375 | if (*(args[1]) == 0) { |
| 1376 | Alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]); |
| 1377 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1378 | goto out; |
| 1379 | } |
| 1380 | free(global.log_tag); |
| 1381 | global.log_tag = strdup(args[1]); |
| 1382 | } |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1383 | else if (!strcmp(args[0], "spread-checks")) { /* random time between checks (0-50) */ |
| 1384 | if (global.spread_checks != 0) { |
| 1385 | Alert("parsing [%s:%d]: spread-checks already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1386 | err_code |= ERR_ALERT; |
| 1387 | goto out; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1388 | } |
| 1389 | if (*(args[1]) == 0) { |
| 1390 | 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] | 1391 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1392 | goto out; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1393 | } |
| 1394 | global.spread_checks = atol(args[1]); |
| 1395 | if (global.spread_checks < 0 || global.spread_checks > 50) { |
| 1396 | 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] | 1397 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1398 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1399 | } |
Willy Tarreau | 1746eec | 2014-04-25 10:46:47 +0200 | [diff] [blame] | 1400 | else if (!strcmp(args[0], "max-spread-checks")) { /* maximum time between first and last check */ |
| 1401 | const char *err; |
| 1402 | unsigned int val; |
| 1403 | |
| 1404 | |
| 1405 | if (*(args[1]) == 0) { |
| 1406 | Alert("parsing [%s:%d]: '%s' expects an integer argument (0..50).\n", file, linenum, args[0]); |
| 1407 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1408 | goto out; |
| 1409 | } |
| 1410 | |
| 1411 | err = parse_time_err(args[1], &val, TIME_UNIT_MS); |
| 1412 | if (err) { |
| 1413 | Alert("parsing [%s:%d]: unsupported character '%c' in '%s' (wants an integer delay).\n", file, linenum, *err, args[0]); |
| 1414 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1415 | } |
| 1416 | global.max_spread_checks = val; |
| 1417 | if (global.max_spread_checks < 0) { |
| 1418 | Alert("parsing [%s:%d]: '%s' needs a positive delay in milliseconds.\n",file, linenum, args[0]); |
| 1419 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1420 | } |
| 1421 | } |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1422 | else if (strcmp(args[0], "cpu-map") == 0) { /* map a process list to a CPU set */ |
| 1423 | #ifdef USE_CPU_AFFINITY |
| 1424 | int cur_arg, i; |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1425 | unsigned long proc = 0; |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1426 | unsigned long cpus = 0; |
| 1427 | |
| 1428 | if (strcmp(args[1], "all") == 0) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1429 | proc = ~0UL; |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1430 | else if (strcmp(args[1], "odd") == 0) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1431 | proc = ~0UL/3UL; /* 0x555....555 */ |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1432 | else if (strcmp(args[1], "even") == 0) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1433 | proc = (~0UL/3UL) << 1; /* 0xAAA...AAA */ |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1434 | else { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1435 | proc = atol(args[1]); |
| 1436 | if (proc >= 1 && proc <= LONGBITS) |
| 1437 | proc = 1UL << (proc - 1); |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1438 | } |
| 1439 | |
| 1440 | if (!proc || !*args[2]) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1441 | 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", |
| 1442 | file, linenum, args[0], LONGBITS, LONGBITS - 1); |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1443 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1444 | goto out; |
| 1445 | } |
| 1446 | |
| 1447 | cur_arg = 2; |
| 1448 | while (*args[cur_arg]) { |
| 1449 | unsigned int low, high; |
| 1450 | |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 1451 | if (isdigit((int)*args[cur_arg])) { |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1452 | char *dash = strchr(args[cur_arg], '-'); |
| 1453 | |
| 1454 | low = high = str2uic(args[cur_arg]); |
| 1455 | if (dash) |
| 1456 | high = str2uic(dash + 1); |
| 1457 | |
| 1458 | if (high < low) { |
| 1459 | unsigned int swap = low; |
| 1460 | low = high; |
| 1461 | high = swap; |
| 1462 | } |
| 1463 | |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1464 | if (high >= LONGBITS) { |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1465 | 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] | 1466 | file, linenum, args[0], LONGBITS - 1); |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1467 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1468 | goto out; |
| 1469 | } |
| 1470 | |
| 1471 | while (low <= high) |
| 1472 | cpus |= 1UL << low++; |
| 1473 | } |
| 1474 | else { |
| 1475 | Alert("parsing [%s:%d]: %s : '%s' is not a CPU range.\n", |
| 1476 | file, linenum, args[0], args[cur_arg]); |
| 1477 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1478 | goto out; |
| 1479 | } |
| 1480 | cur_arg++; |
| 1481 | } |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1482 | for (i = 0; i < LONGBITS; i++) |
| 1483 | if (proc & (1UL << i)) |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1484 | global.cpu_map[i] = cpus; |
| 1485 | #else |
| 1486 | Alert("parsing [%s:%d] : '%s' is not enabled, please check build options for USE_CPU_AFFINITY.\n", file, linenum, args[0]); |
| 1487 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1488 | goto out; |
| 1489 | #endif |
| 1490 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1491 | else { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1492 | struct cfg_kw_list *kwl; |
| 1493 | int index; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1494 | int rc; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1495 | |
| 1496 | list_for_each_entry(kwl, &cfg_keywords.list, list) { |
| 1497 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 1498 | if (kwl->kw[index].section != CFG_GLOBAL) |
| 1499 | continue; |
| 1500 | if (strcmp(kwl->kw[index].kw, args[0]) == 0) { |
Willy Tarreau | 28a47d6 | 2012-09-18 20:02:48 +0200 | [diff] [blame] | 1501 | 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] | 1502 | if (rc < 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 1503 | Alert("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1504 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1505 | } |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1506 | else if (rc > 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 1507 | Warning("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1508 | err_code |= ERR_WARN; |
| 1509 | goto out; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1510 | } |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1511 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1512 | } |
| 1513 | } |
| 1514 | } |
| 1515 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1516 | 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] | 1517 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1518 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1519 | |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1520 | out: |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 1521 | free(errmsg); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1522 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1523 | } |
| 1524 | |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 1525 | void init_default_instance() |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1526 | { |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 1527 | init_new_proxy(&defproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1528 | defproxy.mode = PR_MODE_TCP; |
| 1529 | defproxy.state = PR_STNEW; |
| 1530 | defproxy.maxconn = cfg_maxpconn; |
| 1531 | defproxy.conn_retries = CONN_RETRIES; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1532 | |
Simon Horman | 6618300 | 2013-02-23 10:16:43 +0900 | [diff] [blame] | 1533 | defproxy.defsrv.check.inter = DEF_CHKINTR; |
| 1534 | defproxy.defsrv.check.fastinter = 0; |
| 1535 | defproxy.defsrv.check.downinter = 0; |
Simon Horman | d60d691 | 2013-11-25 10:46:36 +0900 | [diff] [blame] | 1536 | defproxy.defsrv.agent.inter = DEF_CHKINTR; |
| 1537 | defproxy.defsrv.agent.fastinter = 0; |
| 1538 | defproxy.defsrv.agent.downinter = 0; |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 1539 | defproxy.defsrv.check.rise = DEF_RISETIME; |
| 1540 | defproxy.defsrv.check.fall = DEF_FALLTIME; |
| 1541 | defproxy.defsrv.agent.rise = DEF_AGENT_RISETIME; |
| 1542 | defproxy.defsrv.agent.fall = DEF_AGENT_FALLTIME; |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 1543 | defproxy.defsrv.check.port = 0; |
Simon Horman | d60d691 | 2013-11-25 10:46:36 +0900 | [diff] [blame] | 1544 | defproxy.defsrv.agent.port = 0; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1545 | defproxy.defsrv.maxqueue = 0; |
| 1546 | defproxy.defsrv.minconn = 0; |
| 1547 | defproxy.defsrv.maxconn = 0; |
| 1548 | defproxy.defsrv.slowstart = 0; |
| 1549 | defproxy.defsrv.onerror = DEF_HANA_ONERR; |
| 1550 | defproxy.defsrv.consecutive_errors_limit = DEF_HANA_ERRLIMIT; |
| 1551 | defproxy.defsrv.uweight = defproxy.defsrv.iweight = 1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1552 | } |
| 1553 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1554 | |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1555 | /* This function createss a new req* or rsp* rule to the proxy. It compiles the |
| 1556 | * regex and may return the ERR_WARN bit, and error bits such as ERR_ALERT and |
| 1557 | * ERR_FATAL in case of error. |
| 1558 | */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1559 | static int create_cond_regex_rule(const char *file, int line, |
| 1560 | struct proxy *px, int dir, int action, int flags, |
| 1561 | const char *cmd, const char *reg, const char *repl, |
| 1562 | const char **cond_start) |
| 1563 | { |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1564 | struct my_regex *preg = NULL; |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 1565 | char *errmsg = NULL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1566 | const char *err; |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1567 | char *error; |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1568 | int ret_code = 0; |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1569 | struct acl_cond *cond = NULL; |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1570 | int cs; |
| 1571 | int cap; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1572 | |
| 1573 | if (px == &defproxy) { |
| 1574 | 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] | 1575 | ret_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1576 | goto err; |
| 1577 | } |
| 1578 | |
| 1579 | if (*reg == 0) { |
| 1580 | 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] | 1581 | ret_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1582 | goto err; |
| 1583 | } |
| 1584 | |
| 1585 | if (warnifnotcap(px, PR_CAP_RS, file, line, cmd, NULL)) |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1586 | ret_code |= ERR_WARN; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1587 | |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1588 | if (cond_start && |
| 1589 | (strcmp(*cond_start, "if") == 0 || strcmp(*cond_start, "unless") == 0)) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 1590 | if ((cond = build_acl_cond(file, line, px, cond_start, &errmsg)) == NULL) { |
| 1591 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 1592 | file, line, cmd, errmsg); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1593 | ret_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1594 | goto err; |
| 1595 | } |
| 1596 | } |
| 1597 | else if (cond_start && **cond_start) { |
| 1598 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 1599 | file, line, cmd, *cond_start); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1600 | ret_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1601 | goto err; |
| 1602 | } |
| 1603 | |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1604 | ret_code |= warnif_cond_conflicts(cond, |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 1605 | (dir == SMP_OPT_DIR_REQ) ? |
| 1606 | ((px->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR) : |
| 1607 | ((px->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR), |
| 1608 | file, line); |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1609 | |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1610 | preg = calloc(1, sizeof(*preg)); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1611 | if (!preg) { |
| 1612 | 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] | 1613 | ret_code = ERR_ALERT | ERR_FATAL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1614 | goto err; |
| 1615 | } |
| 1616 | |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1617 | cs = !(flags & REG_ICASE); |
| 1618 | cap = !(flags & REG_NOSUB); |
| 1619 | error = NULL; |
| 1620 | if (!regex_comp(reg, preg, cs, cap, &error)) { |
| 1621 | Alert("parsing [%s:%d] : '%s' : regular expression '%s' : %s\n", file, line, cmd, reg, error); |
| 1622 | free(error); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1623 | ret_code = ERR_ALERT | ERR_FATAL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1624 | goto err; |
| 1625 | } |
| 1626 | |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 1627 | 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] | 1628 | preg, action, repl ? strdup(repl) : NULL, cond); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1629 | if (repl && err) { |
| 1630 | Alert("parsing [%s:%d] : '%s' : invalid character or unterminated sequence in replacement string near '%c'.\n", |
| 1631 | file, line, cmd, *err); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1632 | ret_code |= ERR_ALERT | ERR_FATAL; |
| 1633 | goto err_free; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1634 | } |
| 1635 | |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 1636 | 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] | 1637 | ret_code |= ERR_WARN; |
| 1638 | |
| 1639 | return ret_code; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1640 | |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1641 | err_free: |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1642 | regex_free(preg); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1643 | err: |
| 1644 | free(preg); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1645 | free(errmsg); |
| 1646 | return ret_code; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1647 | } |
| 1648 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1649 | /* |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1650 | * Parse a line in a <listen>, <frontend>, <backend> or <ruleset> section. |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1651 | * Returns the error code, 0 if OK, or any combination of : |
| 1652 | * - ERR_ABORT: must abort ASAP |
| 1653 | * - ERR_FATAL: we can continue parsing but not start the service |
| 1654 | * - ERR_WARN: a warning has been emitted |
| 1655 | * - ERR_ALERT: an alert has been emitted |
| 1656 | * Only the two first ones can stop processing, the two others are just |
| 1657 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1658 | */ |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1659 | int cfg_parse_peers(const char *file, int linenum, char **args, int kwm) |
| 1660 | { |
| 1661 | static struct peers *curpeers = NULL; |
| 1662 | struct peer *newpeer = NULL; |
| 1663 | const char *err; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1664 | struct bind_conf *bind_conf; |
| 1665 | struct listener *l; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1666 | int err_code = 0; |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1667 | char *errmsg = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1668 | |
| 1669 | if (strcmp(args[0], "peers") == 0) { /* new peers section */ |
Willy Tarreau | 0dbbf31 | 2013-03-05 11:31:55 +0100 | [diff] [blame] | 1670 | if (!*args[1]) { |
| 1671 | Alert("parsing [%s:%d] : missing name for peers section.\n", file, linenum); |
Willy Tarreau | 5498472 | 2014-02-16 08:20:13 +0100 | [diff] [blame] | 1672 | err_code |= ERR_ALERT | ERR_ABORT; |
Willy Tarreau | 0dbbf31 | 2013-03-05 11:31:55 +0100 | [diff] [blame] | 1673 | goto out; |
| 1674 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1675 | |
| 1676 | err = invalid_char(args[1]); |
| 1677 | if (err) { |
| 1678 | Alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 1679 | file, linenum, *err, args[0], args[1]); |
Willy Tarreau | 5498472 | 2014-02-16 08:20:13 +0100 | [diff] [blame] | 1680 | err_code |= ERR_ALERT | ERR_ABORT; |
Willy Tarreau | 0dbbf31 | 2013-03-05 11:31:55 +0100 | [diff] [blame] | 1681 | goto out; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1682 | } |
| 1683 | |
| 1684 | for (curpeers = peers; curpeers != NULL; curpeers = curpeers->next) { |
| 1685 | /* |
| 1686 | * If there are two proxies with the same name only following |
| 1687 | * combinations are allowed: |
| 1688 | */ |
| 1689 | if (strcmp(curpeers->id, args[1]) == 0) { |
| 1690 | Warning("Parsing [%s:%d]: peers '%s' has same name as another peers (declared at %s:%d).\n", |
| 1691 | file, linenum, args[1], curpeers->conf.file, curpeers->conf.line); |
| 1692 | err_code |= ERR_WARN; |
| 1693 | } |
| 1694 | } |
| 1695 | |
| 1696 | if ((curpeers = (struct peers *)calloc(1, sizeof(struct peers))) == NULL) { |
| 1697 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1698 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1699 | goto out; |
| 1700 | } |
| 1701 | |
| 1702 | curpeers->next = peers; |
| 1703 | peers = curpeers; |
Willy Tarreau | 8113a5d | 2012-10-04 08:01:43 +0200 | [diff] [blame] | 1704 | curpeers->conf.file = strdup(file); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1705 | curpeers->conf.line = linenum; |
| 1706 | curpeers->last_change = now.tv_sec; |
| 1707 | curpeers->id = strdup(args[1]); |
| 1708 | } |
| 1709 | else if (strcmp(args[0], "peer") == 0) { /* peer definition */ |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 1710 | struct sockaddr_storage *sk; |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 1711 | int port1, port2; |
Willy Tarreau | b36487e | 2013-03-10 18:37:42 +0100 | [diff] [blame] | 1712 | struct protocol *proto; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1713 | |
| 1714 | if (!*args[2]) { |
| 1715 | Alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n", |
| 1716 | file, linenum, args[0]); |
| 1717 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1718 | goto out; |
| 1719 | } |
| 1720 | |
| 1721 | err = invalid_char(args[1]); |
| 1722 | if (err) { |
| 1723 | Alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n", |
| 1724 | file, linenum, *err, args[1]); |
| 1725 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1726 | goto out; |
| 1727 | } |
| 1728 | |
| 1729 | if ((newpeer = (struct peer *)calloc(1, sizeof(struct peer))) == NULL) { |
| 1730 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1731 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1732 | goto out; |
| 1733 | } |
| 1734 | |
| 1735 | /* the peers are linked backwards first */ |
| 1736 | curpeers->count++; |
| 1737 | newpeer->next = curpeers->remote; |
| 1738 | curpeers->remote = newpeer; |
| 1739 | newpeer->peers = curpeers; |
Willy Tarreau | 8113a5d | 2012-10-04 08:01:43 +0200 | [diff] [blame] | 1740 | newpeer->conf.file = strdup(file); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1741 | newpeer->conf.line = linenum; |
| 1742 | |
| 1743 | newpeer->last_change = now.tv_sec; |
| 1744 | newpeer->id = strdup(args[1]); |
| 1745 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1746 | sk = str2sa_range(args[2], &port1, &port2, &errmsg, NULL); |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 1747 | if (!sk) { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1748 | 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] | 1749 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1750 | goto out; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1751 | } |
Willy Tarreau | b36487e | 2013-03-10 18:37:42 +0100 | [diff] [blame] | 1752 | |
| 1753 | proto = protocol_by_family(sk->ss_family); |
| 1754 | if (!proto || !proto->connect) { |
| 1755 | Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 1756 | file, linenum, args[0], args[1]); |
| 1757 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1758 | goto out; |
| 1759 | } |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 1760 | |
| 1761 | if (port1 != port2) { |
| 1762 | Alert("parsing [%s:%d] : '%s %s' : port ranges and offsets are not allowed in '%s'\n", |
| 1763 | file, linenum, args[0], args[1], args[2]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1764 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1765 | goto out; |
| 1766 | } |
| 1767 | |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 1768 | if (!port1) { |
| 1769 | Alert("parsing [%s:%d] : '%s %s' : missing or invalid port in '%s'\n", |
| 1770 | file, linenum, args[0], args[1], args[2]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1771 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1772 | goto out; |
| 1773 | } |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 1774 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1775 | newpeer->addr = *sk; |
Willy Tarreau | b36487e | 2013-03-10 18:37:42 +0100 | [diff] [blame] | 1776 | newpeer->proto = proto; |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 1777 | newpeer->xprt = &raw_sock; |
Willy Tarreau | d02394b | 2012-05-11 18:32:18 +0200 | [diff] [blame] | 1778 | newpeer->sock_init_arg = NULL; |
Willy Tarreau | 26d8c59 | 2012-05-07 18:12:14 +0200 | [diff] [blame] | 1779 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1780 | if (strcmp(newpeer->id, localpeer) == 0) { |
| 1781 | /* Current is local peer, it define a frontend */ |
| 1782 | newpeer->local = 1; |
| 1783 | |
| 1784 | if (!curpeers->peers_fe) { |
| 1785 | if ((curpeers->peers_fe = calloc(1, sizeof(struct proxy))) == NULL) { |
| 1786 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1787 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1788 | goto out; |
| 1789 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1790 | |
Willy Tarreau | 237250c | 2011-07-29 01:49:03 +0200 | [diff] [blame] | 1791 | init_new_proxy(curpeers->peers_fe); |
| 1792 | curpeers->peers_fe->parent = curpeers; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1793 | |
| 1794 | curpeers->peers_fe->last_change = now.tv_sec; |
| 1795 | curpeers->peers_fe->id = strdup(args[1]); |
| 1796 | curpeers->peers_fe->cap = PR_CAP_FE; |
Willy Tarreau | 3ae65a1 | 2011-09-07 17:40:39 +0200 | [diff] [blame] | 1797 | curpeers->peers_fe->maxconn = 0; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1798 | curpeers->peers_fe->conn_retries = CONN_RETRIES; |
| 1799 | curpeers->peers_fe->timeout.connect = 5000; |
| 1800 | curpeers->peers_fe->accept = peer_accept; |
| 1801 | 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] | 1802 | curpeers->peers_fe->conf.args.file = curpeers->peers_fe->conf.file = strdup(file); |
| 1803 | curpeers->peers_fe->conf.args.line = curpeers->peers_fe->conf.line = linenum; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1804 | |
| 1805 | bind_conf = bind_conf_alloc(&curpeers->peers_fe->conf.bind, file, linenum, args[2]); |
| 1806 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1807 | if (!str2listener(args[2], curpeers->peers_fe, bind_conf, file, linenum, &errmsg)) { |
| 1808 | if (errmsg && *errmsg) { |
| 1809 | indent_msg(&errmsg, 2); |
| 1810 | 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] | 1811 | } |
| 1812 | else |
| 1813 | Alert("parsing [%s:%d] : '%s %s' : error encountered while parsing listening address %s.\n", |
| 1814 | file, linenum, args[0], args[1], args[2]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1815 | err_code |= ERR_FATAL; |
| 1816 | goto out; |
| 1817 | } |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1818 | |
| 1819 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
Willy Tarreau | acf3bf9 | 2013-01-18 10:51:07 +0100 | [diff] [blame] | 1820 | l->maxaccept = 1; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1821 | l->maxconn = ((struct proxy *)curpeers->peers_fe)->maxconn; |
| 1822 | l->backlog = ((struct proxy *)curpeers->peers_fe)->backlog; |
| 1823 | l->timeout = &((struct proxy *)curpeers->peers_fe)->timeout.client; |
| 1824 | l->accept = session_accept; |
| 1825 | l->handler = process_session; |
| 1826 | l->analysers |= ((struct proxy *)curpeers->peers_fe)->fe_req_ana; |
| 1827 | l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */ |
| 1828 | global.maxsock += l->maxconn; |
| 1829 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1830 | } |
Willy Tarreau | 8b8fd56 | 2013-01-18 11:12:27 +0100 | [diff] [blame] | 1831 | else { |
| 1832 | Alert("parsing [%s:%d] : '%s %s' : local peer name already referenced at %s:%d.\n", |
| 1833 | file, linenum, args[0], args[1], |
| 1834 | curpeers->peers_fe->conf.file, curpeers->peers_fe->conf.line); |
| 1835 | err_code |= ERR_FATAL; |
| 1836 | goto out; |
| 1837 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1838 | } |
| 1839 | } /* neither "peer" nor "peers" */ |
| 1840 | else if (*args[0] != 0) { |
| 1841 | Alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection); |
| 1842 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1843 | goto out; |
| 1844 | } |
| 1845 | |
| 1846 | out: |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1847 | free(errmsg); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1848 | return err_code; |
| 1849 | } |
| 1850 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 1851 | 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] | 1852 | { |
| 1853 | static struct proxy *curproxy = NULL; |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 1854 | const char *err; |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1855 | char *error; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 1856 | int rc; |
| 1857 | unsigned val; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1858 | int err_code = 0; |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 1859 | struct acl_cond *cond = NULL; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 1860 | struct logsrv *tmplogsrv; |
Willy Tarreau | f4068b6 | 2012-05-08 17:37:49 +0200 | [diff] [blame] | 1861 | char *errmsg = NULL; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 1862 | struct bind_conf *bind_conf; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1863 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1864 | if (!strcmp(args[0], "listen")) |
| 1865 | rc = PR_CAP_LISTEN; |
| 1866 | else if (!strcmp(args[0], "frontend")) |
| 1867 | rc = PR_CAP_FE | PR_CAP_RS; |
| 1868 | else if (!strcmp(args[0], "backend")) |
| 1869 | rc = PR_CAP_BE | PR_CAP_RS; |
| 1870 | else if (!strcmp(args[0], "ruleset")) |
| 1871 | rc = PR_CAP_RS; |
| 1872 | else |
| 1873 | rc = PR_CAP_NONE; |
| 1874 | |
| 1875 | if (rc != PR_CAP_NONE) { /* new proxy */ |
Willy Tarreau | 7cbc915 | 2014-03-15 08:17:08 +0100 | [diff] [blame] | 1876 | struct ebpt_node *node; |
| 1877 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1878 | if (!*args[1]) { |
| 1879 | Alert("parsing [%s:%d] : '%s' expects an <id> argument and\n" |
| 1880 | " optionnally supports [addr1]:port1[-end1]{,[addr]:port[-end]}...\n", |
| 1881 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1882 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1883 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1884 | } |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 1885 | |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 1886 | err = invalid_char(args[1]); |
| 1887 | if (err) { |
| 1888 | Alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 1889 | file, linenum, *err, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1890 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 1891 | } |
| 1892 | |
Willy Tarreau | 7cbc915 | 2014-03-15 08:17:08 +0100 | [diff] [blame] | 1893 | for (node = ebis_lookup(&proxy_by_name, args[1]); node; node = ebpt_next(node)) { |
| 1894 | curproxy = container_of(node, struct proxy, conf.by_name); |
| 1895 | |
| 1896 | if (strcmp(curproxy->id, args[1]) != 0) |
| 1897 | break; |
| 1898 | |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 1899 | /* |
| 1900 | * If there are two proxies with the same name only following |
| 1901 | * combinations are allowed: |
| 1902 | * |
| 1903 | * listen backend frontend ruleset |
| 1904 | * listen - - - - |
| 1905 | * backend - - OK - |
| 1906 | * frontend - OK - - |
| 1907 | * ruleset - - - - |
| 1908 | */ |
| 1909 | |
Willy Tarreau | 7cbc915 | 2014-03-15 08:17:08 +0100 | [diff] [blame] | 1910 | if ((rc != (PR_CAP_FE|PR_CAP_RS) || curproxy->cap != (PR_CAP_BE|PR_CAP_RS)) && |
| 1911 | (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] | 1912 | Warning("Parsing [%s:%d]: %s '%s' has same name as another %s (declared at %s:%d).\n", |
| 1913 | file, linenum, proxy_cap_str(rc), args[1], proxy_type_str(curproxy), |
| 1914 | curproxy->conf.file, curproxy->conf.line); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1915 | err_code |= ERR_WARN; |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 1916 | } |
| 1917 | } |
| 1918 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1919 | if ((curproxy = (struct proxy *)calloc(1, sizeof(struct proxy))) == NULL) { |
| 1920 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1921 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1922 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1923 | } |
Willy Tarreau | 5af24ef | 2009-03-15 15:23:16 +0100 | [diff] [blame] | 1924 | |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 1925 | init_new_proxy(curproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1926 | curproxy->next = proxy; |
| 1927 | proxy = curproxy; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 1928 | curproxy->conf.args.file = curproxy->conf.file = strdup(file); |
| 1929 | curproxy->conf.args.line = curproxy->conf.line = linenum; |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 1930 | curproxy->last_change = now.tv_sec; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1931 | curproxy->id = strdup(args[1]); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1932 | curproxy->cap = rc; |
Willy Tarreau | f79d950 | 2014-03-15 07:22:35 +0100 | [diff] [blame] | 1933 | proxy_store_name(curproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1934 | |
| 1935 | /* parse the listener address if any */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1936 | if ((curproxy->cap & PR_CAP_FE) && *args[2]) { |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1937 | struct listener *l; |
Willy Tarreau | 81a8117 | 2012-09-18 20:52:35 +0200 | [diff] [blame] | 1938 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1939 | bind_conf = bind_conf_alloc(&curproxy->conf.bind, file, linenum, args[2]); |
| 1940 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1941 | if (!str2listener(args[2], curproxy, bind_conf, file, linenum, &errmsg)) { |
| 1942 | if (errmsg && *errmsg) { |
| 1943 | indent_msg(&errmsg, 2); |
| 1944 | 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] | 1945 | } |
| 1946 | else |
| 1947 | Alert("parsing [%s:%d] : '%s %s' : error encountered while parsing listening address '%s'.\n", |
| 1948 | file, linenum, args[0], args[1], args[2]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1949 | err_code |= ERR_FATAL; |
| 1950 | goto out; |
| 1951 | } |
Willy Tarreau | 81a8117 | 2012-09-18 20:52:35 +0200 | [diff] [blame] | 1952 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1953 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
Willy Tarreau | c8b1109 | 2011-02-16 11:08:57 +0100 | [diff] [blame] | 1954 | global.maxsock++; |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 1955 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1956 | } |
| 1957 | |
| 1958 | /* set default values */ |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1959 | memcpy(&curproxy->defsrv, &defproxy.defsrv, sizeof(curproxy->defsrv)); |
Willy Tarreau | 7016020 | 2010-04-07 16:06:40 +0200 | [diff] [blame] | 1960 | curproxy->defsrv.id = "default-server"; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1961 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1962 | curproxy->state = defproxy.state; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1963 | curproxy->options = defproxy.options; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 1964 | curproxy->options2 = defproxy.options2; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 1965 | curproxy->no_options = defproxy.no_options; |
| 1966 | curproxy->no_options2 = defproxy.no_options2; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 1967 | curproxy->bind_proc = defproxy.bind_proc; |
Willy Tarreau | 3168223 | 2007-11-29 15:38:04 +0100 | [diff] [blame] | 1968 | curproxy->lbprm.algo = defproxy.lbprm.algo; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 1969 | curproxy->except_net = defproxy.except_net; |
| 1970 | curproxy->except_mask = defproxy.except_mask; |
Maik Broemme | 36db02e | 2009-05-08 17:02:07 +0200 | [diff] [blame] | 1971 | curproxy->except_to = defproxy.except_to; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 1972 | curproxy->except_mask_to = defproxy.except_mask_to; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1973 | |
Willy Tarreau | 79f5fe8 | 2008-08-23 08:18:21 +0200 | [diff] [blame] | 1974 | if (defproxy.fwdfor_hdr_len) { |
| 1975 | curproxy->fwdfor_hdr_len = defproxy.fwdfor_hdr_len; |
| 1976 | curproxy->fwdfor_hdr_name = strdup(defproxy.fwdfor_hdr_name); |
| 1977 | } |
| 1978 | |
Willy Tarreau | b86db34 | 2009-11-30 11:50:16 +0100 | [diff] [blame] | 1979 | if (defproxy.orgto_hdr_len) { |
| 1980 | curproxy->orgto_hdr_len = defproxy.orgto_hdr_len; |
| 1981 | curproxy->orgto_hdr_name = strdup(defproxy.orgto_hdr_name); |
| 1982 | } |
| 1983 | |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 1984 | if (defproxy.server_id_hdr_len) { |
| 1985 | curproxy->server_id_hdr_len = defproxy.server_id_hdr_len; |
| 1986 | curproxy->server_id_hdr_name = strdup(defproxy.server_id_hdr_name); |
| 1987 | } |
| 1988 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1989 | if (curproxy->cap & PR_CAP_FE) { |
| 1990 | curproxy->maxconn = defproxy.maxconn; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 1991 | curproxy->backlog = defproxy.backlog; |
Willy Tarreau | 13a34bd | 2009-05-10 18:52:49 +0200 | [diff] [blame] | 1992 | curproxy->fe_sps_lim = defproxy.fe_sps_lim; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1993 | |
| 1994 | /* initialize error relocations */ |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1995 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) |
| 1996 | chunk_dup(&curproxy->errmsg[rc], &defproxy.errmsg[rc]); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1997 | |
| 1998 | curproxy->to_log = defproxy.to_log & ~LW_COOKIE & ~LW_REQHDR & ~ LW_RSPHDR; |
| 1999 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2000 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2001 | if (curproxy->cap & PR_CAP_BE) { |
| 2002 | curproxy->fullconn = defproxy.fullconn; |
| 2003 | curproxy->conn_retries = defproxy.conn_retries; |
Willy Tarreau | c35362a | 2014-04-25 13:58:37 +0200 | [diff] [blame] | 2004 | curproxy->max_ka_queue = defproxy.max_ka_queue; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2005 | |
Willy Tarreau | aa2f389 | 2010-10-22 16:15:31 +0200 | [diff] [blame] | 2006 | if (defproxy.check_req) { |
| 2007 | curproxy->check_req = calloc(1, defproxy.check_len); |
| 2008 | memcpy(curproxy->check_req, defproxy.check_req, defproxy.check_len); |
| 2009 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2010 | curproxy->check_len = defproxy.check_len; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2011 | |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 2012 | if (defproxy.expect_str) { |
| 2013 | curproxy->expect_str = strdup(defproxy.expect_str); |
| 2014 | if (defproxy.expect_regex) { |
| 2015 | /* note: this regex is known to be valid */ |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 2016 | curproxy->expect_regex = calloc(1, sizeof(*curproxy->expect_regex)); |
| 2017 | regex_comp(defproxy.expect_str, curproxy->expect_regex, 1, 1, NULL); |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 2018 | } |
| 2019 | } |
| 2020 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2021 | curproxy->ck_opts = defproxy.ck_opts; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2022 | if (defproxy.cookie_name) |
| 2023 | curproxy->cookie_name = strdup(defproxy.cookie_name); |
| 2024 | curproxy->cookie_len = defproxy.cookie_len; |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 2025 | if (defproxy.cookie_domain) |
| 2026 | curproxy->cookie_domain = strdup(defproxy.cookie_domain); |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 2027 | |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 2028 | if (defproxy.cookie_maxidle) |
| 2029 | curproxy->cookie_maxidle = defproxy.cookie_maxidle; |
| 2030 | |
| 2031 | if (defproxy.cookie_maxlife) |
| 2032 | curproxy->cookie_maxlife = defproxy.cookie_maxlife; |
| 2033 | |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2034 | if (defproxy.rdp_cookie_name) |
| 2035 | curproxy->rdp_cookie_name = strdup(defproxy.rdp_cookie_name); |
| 2036 | curproxy->rdp_cookie_len = defproxy.rdp_cookie_len; |
| 2037 | |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 2038 | if (defproxy.url_param_name) |
| 2039 | curproxy->url_param_name = strdup(defproxy.url_param_name); |
| 2040 | curproxy->url_param_len = defproxy.url_param_len; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 2041 | |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 2042 | if (defproxy.hh_name) |
| 2043 | curproxy->hh_name = strdup(defproxy.hh_name); |
| 2044 | curproxy->hh_len = defproxy.hh_len; |
| 2045 | curproxy->hh_match_domain = defproxy.hh_match_domain; |
| 2046 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 2047 | if (defproxy.conn_src.iface_name) |
| 2048 | curproxy->conn_src.iface_name = strdup(defproxy.conn_src.iface_name); |
| 2049 | curproxy->conn_src.iface_len = defproxy.conn_src.iface_len; |
Godbach | 9f04853 | 2013-04-23 15:27:57 +0800 | [diff] [blame] | 2050 | curproxy->conn_src.opts = defproxy.conn_src.opts; |
Pieter Baauw | d551fb5 | 2013-05-08 22:49:23 +0200 | [diff] [blame] | 2051 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_TRANSPARENT) |
Godbach | 9f04853 | 2013-04-23 15:27:57 +0800 | [diff] [blame] | 2052 | curproxy->conn_src.tproxy_addr = defproxy.conn_src.tproxy_addr; |
Willy Tarreau | c621d36 | 2013-04-25 17:35:22 +0200 | [diff] [blame] | 2053 | #endif |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2054 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2055 | |
Willy Tarreau | 3b6b1a9 | 2009-07-23 13:24:23 +0200 | [diff] [blame] | 2056 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2057 | if (defproxy.capture_name) |
| 2058 | curproxy->capture_name = strdup(defproxy.capture_name); |
| 2059 | curproxy->capture_namelen = defproxy.capture_namelen; |
| 2060 | curproxy->capture_len = defproxy.capture_len; |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 2061 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2062 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2063 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 2064 | curproxy->timeout.client = defproxy.timeout.client; |
Simone Gotti | 1b48cc9 | 2014-06-11 12:25:28 +0200 | [diff] [blame] | 2065 | curproxy->timeout.clientfin = defproxy.timeout.clientfin; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 2066 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | 036fae0 | 2008-01-06 13:24:40 +0100 | [diff] [blame] | 2067 | curproxy->timeout.httpreq = defproxy.timeout.httpreq; |
Willy Tarreau | b16a574 | 2010-01-10 14:46:16 +0100 | [diff] [blame] | 2068 | curproxy->timeout.httpka = defproxy.timeout.httpka; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2069 | curproxy->mon_net = defproxy.mon_net; |
| 2070 | curproxy->mon_mask = defproxy.mon_mask; |
| 2071 | if (defproxy.monitor_uri) |
| 2072 | curproxy->monitor_uri = strdup(defproxy.monitor_uri); |
| 2073 | curproxy->monitor_uri_len = defproxy.monitor_uri_len; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 2074 | if (defproxy.defbe.name) |
| 2075 | curproxy->defbe.name = strdup(defproxy.defbe.name); |
Willy Tarreau | 99a7ca2 | 2012-05-31 19:39:23 +0200 | [diff] [blame] | 2076 | |
| 2077 | /* 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] | 2078 | curproxy->conf.logformat_string = defproxy.conf.logformat_string; |
| 2079 | if (curproxy->conf.logformat_string && |
| 2080 | curproxy->conf.logformat_string != default_http_log_format && |
| 2081 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 2082 | curproxy->conf.logformat_string != clf_http_log_format) |
| 2083 | curproxy->conf.logformat_string = strdup(curproxy->conf.logformat_string); |
| 2084 | |
| 2085 | if (defproxy.conf.lfs_file) { |
| 2086 | curproxy->conf.lfs_file = strdup(defproxy.conf.lfs_file); |
| 2087 | curproxy->conf.lfs_line = defproxy.conf.lfs_line; |
| 2088 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2089 | } |
| 2090 | |
| 2091 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 2092 | curproxy->timeout.connect = defproxy.timeout.connect; |
| 2093 | curproxy->timeout.server = defproxy.timeout.server; |
Simone Gotti | 1b48cc9 | 2014-06-11 12:25:28 +0200 | [diff] [blame] | 2094 | curproxy->timeout.serverfin = defproxy.timeout.serverfin; |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 2095 | curproxy->timeout.check = defproxy.timeout.check; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 2096 | curproxy->timeout.queue = defproxy.timeout.queue; |
Willy Tarreau | 51c9bde | 2008-01-06 13:40:03 +0100 | [diff] [blame] | 2097 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | cd7afc0 | 2009-07-12 10:03:17 +0200 | [diff] [blame] | 2098 | curproxy->timeout.httpreq = defproxy.timeout.httpreq; |
Willy Tarreau | b16a574 | 2010-01-10 14:46:16 +0100 | [diff] [blame] | 2099 | curproxy->timeout.httpka = defproxy.timeout.httpka; |
Willy Tarreau | ce887fd | 2012-05-12 12:50:00 +0200 | [diff] [blame] | 2100 | curproxy->timeout.tunnel = defproxy.timeout.tunnel; |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 2101 | curproxy->conn_src.source_addr = defproxy.conn_src.source_addr; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2102 | } |
| 2103 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2104 | curproxy->mode = defproxy.mode; |
Willy Tarreau | ed2119c | 2014-04-24 22:10:39 +0200 | [diff] [blame] | 2105 | curproxy->uri_auth = defproxy.uri_auth; /* for stats */ |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 2106 | |
| 2107 | /* copy default logsrvs to curproxy */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 2108 | list_for_each_entry(tmplogsrv, &defproxy.logsrvs, list) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 2109 | struct logsrv *node = malloc(sizeof(struct logsrv)); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 2110 | memcpy(node, tmplogsrv, sizeof(struct logsrv)); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 2111 | LIST_INIT(&node->list); |
| 2112 | LIST_ADDQ(&curproxy->logsrvs, &node->list); |
| 2113 | } |
| 2114 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 2115 | curproxy->conf.uniqueid_format_string = defproxy.conf.uniqueid_format_string; |
| 2116 | if (curproxy->conf.uniqueid_format_string) |
| 2117 | curproxy->conf.uniqueid_format_string = strdup(curproxy->conf.uniqueid_format_string); |
| 2118 | |
| 2119 | if (defproxy.conf.uif_file) { |
| 2120 | curproxy->conf.uif_file = strdup(defproxy.conf.uif_file); |
| 2121 | curproxy->conf.uif_line = defproxy.conf.uif_line; |
| 2122 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 2123 | |
| 2124 | /* copy default header unique id */ |
| 2125 | if (defproxy.header_unique_id) |
| 2126 | curproxy->header_unique_id = strdup(defproxy.header_unique_id); |
| 2127 | |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 2128 | /* default compression options */ |
| 2129 | if (defproxy.comp != NULL) { |
| 2130 | curproxy->comp = calloc(1, sizeof(struct comp)); |
| 2131 | curproxy->comp->algos = defproxy.comp->algos; |
| 2132 | curproxy->comp->types = defproxy.comp->types; |
| 2133 | } |
| 2134 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2135 | curproxy->grace = defproxy.grace; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2136 | curproxy->conf.used_listener_id = EB_ROOT; |
| 2137 | curproxy->conf.used_server_id = EB_ROOT; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2138 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2139 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2140 | } |
| 2141 | else if (!strcmp(args[0], "defaults")) { /* use this one to assign default values */ |
| 2142 | /* some variables may have already been initialized earlier */ |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 2143 | /* FIXME-20070101: we should do this too at the end of the |
| 2144 | * config parsing to free all default values. |
| 2145 | */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2146 | free(defproxy.check_req); |
| 2147 | free(defproxy.cookie_name); |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2148 | free(defproxy.rdp_cookie_name); |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 2149 | free(defproxy.cookie_domain); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2150 | free(defproxy.url_param_name); |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 2151 | free(defproxy.hh_name); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2152 | free(defproxy.capture_name); |
| 2153 | free(defproxy.monitor_uri); |
| 2154 | free(defproxy.defbe.name); |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 2155 | free(defproxy.conn_src.iface_name); |
Willy Tarreau | 79f5fe8 | 2008-08-23 08:18:21 +0200 | [diff] [blame] | 2156 | free(defproxy.fwdfor_hdr_name); |
| 2157 | defproxy.fwdfor_hdr_len = 0; |
Willy Tarreau | b86db34 | 2009-11-30 11:50:16 +0100 | [diff] [blame] | 2158 | free(defproxy.orgto_hdr_name); |
| 2159 | defproxy.orgto_hdr_len = 0; |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 2160 | free(defproxy.server_id_hdr_name); |
| 2161 | defproxy.server_id_hdr_len = 0; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 2162 | free(defproxy.expect_str); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 2163 | if (defproxy.expect_regex) { |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 2164 | regex_free(defproxy.expect_regex); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 2165 | free(defproxy.expect_regex); |
| 2166 | defproxy.expect_regex = NULL; |
| 2167 | } |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 2168 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 2169 | if (defproxy.conf.logformat_string != default_http_log_format && |
| 2170 | defproxy.conf.logformat_string != default_tcp_log_format && |
| 2171 | defproxy.conf.logformat_string != clf_http_log_format) |
| 2172 | free(defproxy.conf.logformat_string); |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 2173 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 2174 | free(defproxy.conf.uniqueid_format_string); |
| 2175 | free(defproxy.conf.lfs_file); |
| 2176 | free(defproxy.conf.uif_file); |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 2177 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2178 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2179 | chunk_destroy(&defproxy.errmsg[rc]); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 2180 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2181 | /* we cannot free uri_auth because it might already be used */ |
| 2182 | init_default_instance(); |
| 2183 | curproxy = &defproxy; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 2184 | curproxy->conf.args.file = curproxy->conf.file = strdup(file); |
| 2185 | curproxy->conf.args.line = curproxy->conf.line = linenum; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2186 | defproxy.cap = PR_CAP_LISTEN; /* all caps for now */ |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2187 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2188 | } |
| 2189 | else if (curproxy == NULL) { |
| 2190 | Alert("parsing [%s:%d] : 'listen' or 'defaults' expected.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2191 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2192 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2193 | } |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 2194 | |
| 2195 | /* update the current file and line being parsed */ |
| 2196 | curproxy->conf.args.file = curproxy->conf.file; |
| 2197 | curproxy->conf.args.line = linenum; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2198 | |
| 2199 | /* Now let's parse the proxy-specific keywords */ |
Willy Tarreau | 272adea | 2014-03-31 10:39:59 +0200 | [diff] [blame] | 2200 | if (!strcmp(args[0], "server") || !strcmp(args[0], "default-server")) { |
| 2201 | err_code |= parse_server(file, linenum, args, curproxy, &defproxy); |
| 2202 | if (err_code & ERR_FATAL) |
| 2203 | goto out; |
| 2204 | } |
| 2205 | else if (!strcmp(args[0], "bind")) { /* new listen addresses */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2206 | struct listener *l; |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 2207 | int cur_arg; |
| 2208 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2209 | if (curproxy == &defproxy) { |
| 2210 | 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] | 2211 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2212 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2213 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2214 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2215 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2216 | |
Willy Tarreau | 2470928 | 2013-03-10 21:32:12 +0100 | [diff] [blame] | 2217 | if (!*(args[1])) { |
Willy Tarreau | d55c3fe | 2010-11-09 09:50:37 +0100 | [diff] [blame] | 2218 | 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] | 2219 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2220 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2221 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2222 | } |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 2223 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 2224 | bind_conf = bind_conf_alloc(&curproxy->conf.bind, file, linenum, args[1]); |
Willy Tarreau | 8dc21fa | 2013-01-24 15:17:20 +0100 | [diff] [blame] | 2225 | |
| 2226 | /* use default settings for unix sockets */ |
| 2227 | bind_conf->ux.uid = global.unix_bind.ux.uid; |
| 2228 | bind_conf->ux.gid = global.unix_bind.ux.gid; |
| 2229 | bind_conf->ux.mode = global.unix_bind.ux.mode; |
Willy Tarreau | 8a95691 | 2010-10-15 14:27:08 +0200 | [diff] [blame] | 2230 | |
| 2231 | /* NOTE: the following line might create several listeners if there |
| 2232 | * are comma-separated IPs or port ranges. So all further processing |
| 2233 | * will have to be applied to all listeners created after last_listen. |
| 2234 | */ |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 2235 | if (!str2listener(args[1], curproxy, bind_conf, file, linenum, &errmsg)) { |
| 2236 | if (errmsg && *errmsg) { |
| 2237 | indent_msg(&errmsg, 2); |
| 2238 | Alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 2239 | } |
| 2240 | else |
| 2241 | Alert("parsing [%s:%d] : '%s' : error encountered while parsing listening address '%s'.\n", |
| 2242 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2243 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2244 | goto out; |
| 2245 | } |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 2246 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2247 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
| 2248 | /* Set default global rights and owner for unix bind */ |
Willy Tarreau | c8b1109 | 2011-02-16 11:08:57 +0100 | [diff] [blame] | 2249 | global.maxsock++; |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 2250 | } |
| 2251 | |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 2252 | cur_arg = 2; |
| 2253 | while (*(args[cur_arg])) { |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 2254 | static int bind_dumped; |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 2255 | struct bind_kw *kw; |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 2256 | char *err; |
| 2257 | |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 2258 | kw = bind_find_kw(args[cur_arg]); |
| 2259 | if (kw) { |
| 2260 | char *err = NULL; |
| 2261 | int code; |
| 2262 | |
| 2263 | if (!kw->parse) { |
Willy Tarreau | dda322d | 2012-09-18 16:34:09 +0200 | [diff] [blame] | 2264 | Alert("parsing [%s:%d] : '%s %s' : '%s' option is not implemented in this version (check build options).\n", |
| 2265 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 2266 | cur_arg += 1 + kw->skip ; |
| 2267 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2268 | goto out; |
| 2269 | } |
| 2270 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2271 | code = kw->parse(args, cur_arg, curproxy, bind_conf, &err); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 2272 | err_code |= code; |
| 2273 | |
| 2274 | if (code) { |
| 2275 | if (err && *err) { |
| 2276 | indent_msg(&err, 2); |
Willy Tarreau | dda322d | 2012-09-18 16:34:09 +0200 | [diff] [blame] | 2277 | 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] | 2278 | } |
| 2279 | else |
Willy Tarreau | dda322d | 2012-09-18 16:34:09 +0200 | [diff] [blame] | 2280 | Alert("parsing [%s:%d] : '%s %s' : error encountered while processing '%s'.\n", |
| 2281 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 2282 | if (code & ERR_FATAL) { |
| 2283 | free(err); |
| 2284 | cur_arg += 1 + kw->skip; |
| 2285 | goto out; |
| 2286 | } |
| 2287 | } |
| 2288 | free(err); |
| 2289 | cur_arg += 1 + kw->skip; |
| 2290 | continue; |
| 2291 | } |
| 2292 | |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 2293 | err = NULL; |
| 2294 | if (!bind_dumped) { |
| 2295 | bind_dump_kws(&err); |
| 2296 | indent_msg(&err, 4); |
| 2297 | bind_dumped = 1; |
| 2298 | } |
| 2299 | |
| 2300 | Alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'.%s%s\n", |
| 2301 | file, linenum, args[0], args[1], args[cur_arg], |
| 2302 | err ? " Registered keywords :" : "", err ? err : ""); |
| 2303 | free(err); |
| 2304 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2305 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2306 | goto out; |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 2307 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2308 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2309 | } |
| 2310 | 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] | 2311 | 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] | 2312 | Alert("parsing [%s:%d] : '%s' expects address[/mask].\n", |
| 2313 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2314 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2315 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2316 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2317 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2318 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2319 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2320 | /* flush useless bits */ |
| 2321 | curproxy->mon_net.s_addr &= curproxy->mon_mask.s_addr; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2322 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2323 | } |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2324 | else if (!strcmp(args[0], "monitor-uri")) { /* set the URI to intercept */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2325 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2326 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2327 | |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2328 | if (!*args[1]) { |
| 2329 | Alert("parsing [%s:%d] : '%s' expects an URI.\n", |
| 2330 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2331 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2332 | goto out; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2333 | } |
| 2334 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2335 | free(curproxy->monitor_uri); |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 2336 | curproxy->monitor_uri_len = strlen(args[1]); |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2337 | curproxy->monitor_uri = (char *)calloc(1, curproxy->monitor_uri_len + 1); |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 2338 | memcpy(curproxy->monitor_uri, args[1], curproxy->monitor_uri_len); |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2339 | curproxy->monitor_uri[curproxy->monitor_uri_len] = '\0'; |
| 2340 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2341 | goto out; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2342 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2343 | else if (!strcmp(args[0], "mode")) { /* sets the proxy mode */ |
| 2344 | if (!strcmp(args[1], "http")) curproxy->mode = PR_MODE_HTTP; |
| 2345 | else if (!strcmp(args[1], "tcp")) curproxy->mode = PR_MODE_TCP; |
| 2346 | else if (!strcmp(args[1], "health")) curproxy->mode = PR_MODE_HEALTH; |
| 2347 | else { |
| 2348 | 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] | 2349 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2350 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2351 | } |
| 2352 | } |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2353 | else if (!strcmp(args[0], "id")) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2354 | struct eb32_node *node; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2355 | |
| 2356 | if (curproxy == &defproxy) { |
| 2357 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", |
| 2358 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2359 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2360 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2361 | } |
| 2362 | |
| 2363 | if (!*args[1]) { |
| 2364 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 2365 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2366 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2367 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2368 | } |
| 2369 | |
| 2370 | curproxy->uuid = atol(args[1]); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2371 | curproxy->conf.id.key = curproxy->uuid; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2372 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2373 | if (curproxy->uuid <= 0) { |
| 2374 | Alert("parsing [%s:%d]: custom id has to be > 0.\n", |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2375 | file, linenum); |
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 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2380 | node = eb32_lookup(&used_proxy_id, curproxy->uuid); |
| 2381 | if (node) { |
| 2382 | struct proxy *target = container_of(node, struct proxy, conf.id); |
| 2383 | Alert("parsing [%s:%d]: %s %s reuses same custom id as %s %s (declared at %s:%d).\n", |
| 2384 | file, linenum, proxy_type_str(curproxy), curproxy->id, |
| 2385 | proxy_type_str(target), target->id, target->conf.file, target->conf.line); |
| 2386 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2387 | goto out; |
| 2388 | } |
| 2389 | eb32_insert(&used_proxy_id, &curproxy->conf.id); |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2390 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 2391 | else if (!strcmp(args[0], "description")) { |
| 2392 | int i, len=0; |
| 2393 | char *d; |
| 2394 | |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 2395 | if (curproxy == &defproxy) { |
| 2396 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", |
| 2397 | file, linenum, args[0]); |
| 2398 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2399 | goto out; |
| 2400 | } |
| 2401 | |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 2402 | if (!*args[1]) { |
| 2403 | Alert("parsing [%s:%d]: '%s' expects a string argument.\n", |
| 2404 | file, linenum, args[0]); |
| 2405 | return -1; |
| 2406 | } |
| 2407 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 2408 | for (i = 1; *args[i]; i++) |
| 2409 | len += strlen(args[i]) + 1; |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 2410 | |
| 2411 | d = (char *)calloc(1, len); |
| 2412 | curproxy->desc = d; |
| 2413 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 2414 | d += snprintf(d, curproxy->desc + len - d, "%s", args[1]); |
| 2415 | for (i = 2; *args[i]; i++) |
| 2416 | d += snprintf(d, curproxy->desc + len - d, " %s", args[i]); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 2417 | |
| 2418 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2419 | else if (!strcmp(args[0], "disabled")) { /* disables this proxy */ |
| 2420 | curproxy->state = PR_STSTOPPED; |
| 2421 | } |
| 2422 | else if (!strcmp(args[0], "enabled")) { /* enables this proxy (used to revert a disabled default) */ |
| 2423 | curproxy->state = PR_STNEW; |
| 2424 | } |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2425 | else if (!strcmp(args[0], "bind-process")) { /* enable this proxy only on some processes */ |
| 2426 | int cur_arg = 1; |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 2427 | unsigned long set = 0; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2428 | |
| 2429 | while (*args[cur_arg]) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 2430 | unsigned int low, high; |
| 2431 | |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2432 | if (strcmp(args[cur_arg], "all") == 0) { |
| 2433 | set = 0; |
| 2434 | break; |
| 2435 | } |
| 2436 | else if (strcmp(args[cur_arg], "odd") == 0) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 2437 | set |= ~0UL/3UL; /* 0x555....555 */ |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2438 | } |
| 2439 | else if (strcmp(args[cur_arg], "even") == 0) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 2440 | set |= (~0UL/3UL) << 1; /* 0xAAA...AAA */ |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2441 | } |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 2442 | else if (isdigit((int)*args[cur_arg])) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 2443 | char *dash = strchr(args[cur_arg], '-'); |
| 2444 | |
| 2445 | low = high = str2uic(args[cur_arg]); |
| 2446 | if (dash) |
| 2447 | high = str2uic(dash + 1); |
| 2448 | |
| 2449 | if (high < low) { |
| 2450 | unsigned int swap = low; |
| 2451 | low = high; |
| 2452 | high = swap; |
| 2453 | } |
| 2454 | |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 2455 | if (low < 1 || high > LONGBITS) { |
| 2456 | Alert("parsing [%s:%d]: %s supports process numbers from 1 to %d.\n", |
| 2457 | file, linenum, args[0], LONGBITS); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2458 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2459 | goto out; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2460 | } |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 2461 | while (low <= high) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 2462 | set |= 1UL << (low++ - 1); |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 2463 | } |
| 2464 | else { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 2465 | Alert("parsing [%s:%d]: %s expects 'all', 'odd', 'even', or a list of process ranges with numbers from 1 to %d.\n", |
| 2466 | file, linenum, args[0], LONGBITS); |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 2467 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2468 | goto out; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2469 | } |
| 2470 | cur_arg++; |
| 2471 | } |
| 2472 | curproxy->bind_proc = set; |
| 2473 | } |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 2474 | else if (!strcmp(args[0], "acl")) { /* add an ACL */ |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2475 | if (curproxy == &defproxy) { |
| 2476 | 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] | 2477 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2478 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2479 | } |
| 2480 | |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 2481 | err = invalid_char(args[1]); |
| 2482 | if (err) { |
| 2483 | Alert("parsing [%s:%d] : character '%c' is not permitted in acl name '%s'.\n", |
| 2484 | file, linenum, *err, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2485 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 2486 | } |
| 2487 | |
Thierry FOURNIER | 0d6ba51 | 2014-02-11 03:31:34 +0100 | [diff] [blame] | 2488 | 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] | 2489 | Alert("parsing [%s:%d] : error detected while parsing ACL '%s' : %s.\n", |
| 2490 | file, linenum, args[1], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2491 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2492 | goto out; |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 2493 | } |
| 2494 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2495 | else if (!strcmp(args[0], "cookie")) { /* cookie name */ |
| 2496 | int cur_arg; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2497 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2498 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2499 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2500 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2501 | if (*(args[1]) == 0) { |
| 2502 | Alert("parsing [%s:%d] : '%s' expects <cookie_name> as argument.\n", |
| 2503 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2504 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2505 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2506 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2507 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2508 | curproxy->ck_opts = 0; |
Willy Tarreau | c63d4bb | 2010-10-23 11:37:27 +0200 | [diff] [blame] | 2509 | curproxy->cookie_maxidle = curproxy->cookie_maxlife = 0; |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 2510 | free(curproxy->cookie_domain); curproxy->cookie_domain = NULL; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2511 | free(curproxy->cookie_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2512 | curproxy->cookie_name = strdup(args[1]); |
| 2513 | curproxy->cookie_len = strlen(curproxy->cookie_name); |
Willy Tarreau | c63d4bb | 2010-10-23 11:37:27 +0200 | [diff] [blame] | 2514 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2515 | cur_arg = 2; |
| 2516 | while (*(args[cur_arg])) { |
| 2517 | if (!strcmp(args[cur_arg], "rewrite")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2518 | curproxy->ck_opts |= PR_CK_RW; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2519 | } |
| 2520 | else if (!strcmp(args[cur_arg], "indirect")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2521 | curproxy->ck_opts |= PR_CK_IND; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2522 | } |
| 2523 | else if (!strcmp(args[cur_arg], "insert")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2524 | curproxy->ck_opts |= PR_CK_INS; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2525 | } |
| 2526 | else if (!strcmp(args[cur_arg], "nocache")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2527 | curproxy->ck_opts |= PR_CK_NOC; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2528 | } |
| 2529 | else if (!strcmp(args[cur_arg], "postonly")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2530 | curproxy->ck_opts |= PR_CK_POST; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2531 | } |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 2532 | else if (!strcmp(args[cur_arg], "preserve")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2533 | curproxy->ck_opts |= PR_CK_PSV; |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 2534 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2535 | else if (!strcmp(args[cur_arg], "prefix")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2536 | curproxy->ck_opts |= PR_CK_PFX; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2537 | } |
Willy Tarreau | 4992dd2 | 2012-05-31 21:02:17 +0200 | [diff] [blame] | 2538 | else if (!strcmp(args[cur_arg], "httponly")) { |
| 2539 | curproxy->ck_opts |= PR_CK_HTTPONLY; |
| 2540 | } |
| 2541 | else if (!strcmp(args[cur_arg], "secure")) { |
| 2542 | curproxy->ck_opts |= PR_CK_SECURE; |
| 2543 | } |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2544 | else if (!strcmp(args[cur_arg], "domain")) { |
| 2545 | if (!*args[cur_arg + 1]) { |
| 2546 | Alert("parsing [%s:%d]: '%s' expects <domain> as argument.\n", |
| 2547 | file, linenum, args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2548 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2549 | goto out; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2550 | } |
| 2551 | |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 2552 | if (*args[cur_arg + 1] != '.' || !strchr(args[cur_arg + 1] + 1, '.')) { |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2553 | /* rfc2109, 4.3.2 Rejecting Cookies */ |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 2554 | Warning("parsing [%s:%d]: domain '%s' contains no embedded" |
| 2555 | " dots nor does not start with a dot." |
| 2556 | " RFC forbids it, this configuration may not work properly.\n", |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2557 | file, linenum, args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 2558 | err_code |= ERR_WARN; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2559 | } |
| 2560 | |
| 2561 | err = invalid_domainchar(args[cur_arg + 1]); |
| 2562 | if (err) { |
| 2563 | Alert("parsing [%s:%d]: character '%c' is not permitted in domain name '%s'.\n", |
| 2564 | file, linenum, *err, args[cur_arg + 1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2565 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2566 | goto out; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2567 | } |
| 2568 | |
Willy Tarreau | 68a897b | 2009-12-03 23:28:34 +0100 | [diff] [blame] | 2569 | if (!curproxy->cookie_domain) { |
| 2570 | curproxy->cookie_domain = strdup(args[cur_arg + 1]); |
| 2571 | } else { |
| 2572 | /* one domain was already specified, add another one by |
| 2573 | * building the string which will be returned along with |
| 2574 | * the cookie. |
| 2575 | */ |
| 2576 | char *new_ptr; |
| 2577 | int new_len = strlen(curproxy->cookie_domain) + |
| 2578 | strlen("; domain=") + strlen(args[cur_arg + 1]) + 1; |
| 2579 | new_ptr = malloc(new_len); |
| 2580 | snprintf(new_ptr, new_len, "%s; domain=%s", curproxy->cookie_domain, args[cur_arg+1]); |
| 2581 | free(curproxy->cookie_domain); |
| 2582 | curproxy->cookie_domain = new_ptr; |
| 2583 | } |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 2584 | cur_arg++; |
| 2585 | } |
| 2586 | else if (!strcmp(args[cur_arg], "maxidle")) { |
| 2587 | unsigned int maxidle; |
| 2588 | const char *res; |
| 2589 | |
| 2590 | if (!*args[cur_arg + 1]) { |
| 2591 | Alert("parsing [%s:%d]: '%s' expects <idletime> in seconds as argument.\n", |
| 2592 | file, linenum, args[cur_arg]); |
| 2593 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2594 | goto out; |
| 2595 | } |
| 2596 | |
| 2597 | res = parse_time_err(args[cur_arg + 1], &maxidle, TIME_UNIT_S); |
| 2598 | if (res) { |
| 2599 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 2600 | file, linenum, *res, args[cur_arg]); |
| 2601 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2602 | goto out; |
| 2603 | } |
| 2604 | curproxy->cookie_maxidle = maxidle; |
| 2605 | cur_arg++; |
| 2606 | } |
| 2607 | else if (!strcmp(args[cur_arg], "maxlife")) { |
| 2608 | unsigned int maxlife; |
| 2609 | const char *res; |
| 2610 | |
| 2611 | if (!*args[cur_arg + 1]) { |
| 2612 | Alert("parsing [%s:%d]: '%s' expects <lifetime> in seconds as argument.\n", |
| 2613 | file, linenum, args[cur_arg]); |
| 2614 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2615 | goto out; |
| 2616 | } |
| 2617 | |
| 2618 | res = parse_time_err(args[cur_arg + 1], &maxlife, TIME_UNIT_S); |
| 2619 | if (res) { |
| 2620 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 2621 | file, linenum, *res, args[cur_arg]); |
| 2622 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2623 | goto out; |
| 2624 | } |
| 2625 | curproxy->cookie_maxlife = maxlife; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2626 | cur_arg++; |
| 2627 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2628 | else { |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 2629 | 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] | 2630 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2631 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2632 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2633 | } |
| 2634 | cur_arg++; |
| 2635 | } |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2636 | if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_IND))) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2637 | Alert("parsing [%s:%d] : cookie 'rewrite' and 'indirect' modes are incompatible.\n", |
| 2638 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2639 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2640 | } |
| 2641 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2642 | 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] | 2643 | Alert("parsing [%s:%d] : cookie 'rewrite', 'insert' and 'prefix' modes are incompatible.\n", |
| 2644 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2645 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2646 | } |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 2647 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2648 | 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] | 2649 | Alert("parsing [%s:%d] : cookie 'preserve' requires at least 'insert' or 'indirect'.\n", |
| 2650 | file, linenum); |
| 2651 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2652 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2653 | }/* end else if (!strcmp(args[0], "cookie")) */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2654 | else if (!strcmp(args[0], "persist")) { /* persist */ |
| 2655 | if (*(args[1]) == 0) { |
| 2656 | Alert("parsing [%s:%d] : missing persist method.\n", |
| 2657 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2658 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2659 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2660 | } |
| 2661 | |
| 2662 | if (!strncmp(args[1], "rdp-cookie", 10)) { |
| 2663 | curproxy->options2 |= PR_O2_RDPC_PRST; |
| 2664 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2665 | if (*(args[1] + 10) == '(') { /* cookie name */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2666 | const char *beg, *end; |
| 2667 | |
| 2668 | beg = args[1] + 11; |
| 2669 | end = strchr(beg, ')'); |
| 2670 | |
| 2671 | if (!end || end == beg) { |
| 2672 | Alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n", |
| 2673 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2674 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2675 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2676 | } |
| 2677 | |
| 2678 | free(curproxy->rdp_cookie_name); |
| 2679 | curproxy->rdp_cookie_name = my_strndup(beg, end - beg); |
| 2680 | curproxy->rdp_cookie_len = end-beg; |
| 2681 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2682 | else if (*(args[1] + 10) == '\0') { /* default cookie name 'msts' */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2683 | free(curproxy->rdp_cookie_name); |
| 2684 | curproxy->rdp_cookie_name = strdup("msts"); |
| 2685 | curproxy->rdp_cookie_len = strlen(curproxy->rdp_cookie_name); |
| 2686 | } |
| 2687 | else { /* syntax */ |
| 2688 | Alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n", |
| 2689 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2690 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2691 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2692 | } |
| 2693 | } |
| 2694 | else { |
| 2695 | Alert("parsing [%s:%d] : unknown persist method.\n", |
| 2696 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2697 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2698 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2699 | } |
| 2700 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2701 | else if (!strcmp(args[0], "appsession")) { /* cookie name */ |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2702 | int cur_arg; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2703 | |
Cyril Bonté | 3b7a369 | 2010-01-10 17:01:47 +0100 | [diff] [blame] | 2704 | if (curproxy == &defproxy) { |
| 2705 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2706 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2707 | goto out; |
| 2708 | } |
| 2709 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2710 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2711 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2712 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2713 | if (*(args[5]) == 0) { |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2714 | 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] | 2715 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2716 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2717 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2718 | } |
| 2719 | have_appsession = 1; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2720 | free(curproxy->appsession_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2721 | curproxy->appsession_name = strdup(args[1]); |
| 2722 | curproxy->appsession_name_len = strlen(curproxy->appsession_name); |
| 2723 | curproxy->appsession_len = atoi(args[3]); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 2724 | err = parse_time_err(args[5], &val, TIME_UNIT_MS); |
| 2725 | if (err) { |
| 2726 | Alert("parsing [%s:%d] : unexpected character '%c' in %s timeout.\n", |
| 2727 | file, linenum, *err, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2728 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2729 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 2730 | } |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 2731 | curproxy->timeout.appsession = val; |
Willy Tarreau | ee99136 | 2007-05-14 14:37:50 +0200 | [diff] [blame] | 2732 | |
Willy Tarreau | 51041c7 | 2007-09-09 21:56:53 +0200 | [diff] [blame] | 2733 | if (appsession_hash_init(&(curproxy->htbl_proxy), destroy) == 0) { |
| 2734 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2735 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2736 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2737 | } |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2738 | |
| 2739 | cur_arg = 6; |
| 2740 | curproxy->options2 &= ~PR_O2_AS_REQL; |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2741 | curproxy->options2 &= ~PR_O2_AS_M_ANY; |
| 2742 | curproxy->options2 |= PR_O2_AS_M_PP; |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2743 | while (*(args[cur_arg])) { |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2744 | if (!strcmp(args[cur_arg], "request-learn")) { |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2745 | curproxy->options2 |= PR_O2_AS_REQL; |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2746 | } else if (!strcmp(args[cur_arg], "prefix")) { |
| 2747 | curproxy->options2 |= PR_O2_AS_PFX; |
| 2748 | } else if (!strcmp(args[cur_arg], "mode")) { |
| 2749 | if (!*args[cur_arg + 1]) { |
| 2750 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 2751 | file, linenum, args[0], args[cur_arg]); |
| 2752 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2753 | goto out; |
| 2754 | } |
| 2755 | |
| 2756 | cur_arg++; |
| 2757 | if (!strcmp(args[cur_arg], "query-string")) { |
| 2758 | curproxy->options2 &= ~PR_O2_AS_M_ANY; |
| 2759 | curproxy->options2 |= PR_O2_AS_M_QS; |
| 2760 | } else if (!strcmp(args[cur_arg], "path-parameters")) { |
| 2761 | curproxy->options2 &= ~PR_O2_AS_M_ANY; |
| 2762 | curproxy->options2 |= PR_O2_AS_M_PP; |
| 2763 | } else { |
| 2764 | Alert("parsing [%s:%d] : unknown mode '%s'\n", file, linenum, args[cur_arg]); |
| 2765 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2766 | goto out; |
| 2767 | } |
| 2768 | } |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2769 | cur_arg++; |
| 2770 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2771 | } /* Url App Session */ |
| 2772 | else if (!strcmp(args[0], "capture")) { |
Willy Tarreau | 3b6b1a9 | 2009-07-23 13:24:23 +0200 | [diff] [blame] | 2773 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2774 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2775 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2776 | if (!strcmp(args[1], "cookie")) { /* name of a cookie to capture */ |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 2777 | if (curproxy == &defproxy) { |
| 2778 | Alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
| 2779 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2780 | goto out; |
| 2781 | } |
| 2782 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2783 | if (*(args[4]) == 0) { |
| 2784 | Alert("parsing [%s:%d] : '%s' expects 'cookie' <cookie_name> 'len' <len>.\n", |
| 2785 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2786 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2787 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2788 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2789 | free(curproxy->capture_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2790 | curproxy->capture_name = strdup(args[2]); |
| 2791 | curproxy->capture_namelen = strlen(curproxy->capture_name); |
| 2792 | curproxy->capture_len = atol(args[4]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2793 | curproxy->to_log |= LW_COOKIE; |
| 2794 | } |
| 2795 | else if (!strcmp(args[1], "request") && !strcmp(args[2], "header")) { |
| 2796 | struct cap_hdr *hdr; |
| 2797 | |
| 2798 | if (curproxy == &defproxy) { |
| 2799 | 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] | 2800 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2801 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2802 | } |
| 2803 | |
| 2804 | if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) { |
| 2805 | Alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n", |
| 2806 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2807 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2808 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2809 | } |
| 2810 | |
| 2811 | hdr = calloc(sizeof(struct cap_hdr), 1); |
| 2812 | hdr->next = curproxy->req_cap; |
| 2813 | hdr->name = strdup(args[3]); |
| 2814 | hdr->namelen = strlen(args[3]); |
| 2815 | hdr->len = atol(args[5]); |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 2816 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2817 | hdr->index = curproxy->nb_req_cap++; |
| 2818 | curproxy->req_cap = hdr; |
| 2819 | curproxy->to_log |= LW_REQHDR; |
| 2820 | } |
| 2821 | else if (!strcmp(args[1], "response") && !strcmp(args[2], "header")) { |
| 2822 | struct cap_hdr *hdr; |
| 2823 | |
| 2824 | if (curproxy == &defproxy) { |
| 2825 | 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] | 2826 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2827 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2828 | } |
| 2829 | |
| 2830 | if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) { |
| 2831 | Alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n", |
| 2832 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2833 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2834 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2835 | } |
| 2836 | hdr = calloc(sizeof(struct cap_hdr), 1); |
| 2837 | hdr->next = curproxy->rsp_cap; |
| 2838 | hdr->name = strdup(args[3]); |
| 2839 | hdr->namelen = strlen(args[3]); |
| 2840 | hdr->len = atol(args[5]); |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 2841 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2842 | hdr->index = curproxy->nb_rsp_cap++; |
| 2843 | curproxy->rsp_cap = hdr; |
| 2844 | curproxy->to_log |= LW_RSPHDR; |
| 2845 | } |
| 2846 | else { |
| 2847 | Alert("parsing [%s:%d] : '%s' expects 'cookie' or 'request header' or 'response header'.\n", |
| 2848 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2849 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2850 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2851 | } |
| 2852 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2853 | else if (!strcmp(args[0], "retries")) { /* connection retries */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2854 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2855 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2856 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2857 | if (*(args[1]) == 0) { |
| 2858 | Alert("parsing [%s:%d] : '%s' expects an integer argument (dispatch counts for one).\n", |
| 2859 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2860 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2861 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2862 | } |
| 2863 | curproxy->conn_retries = atol(args[1]); |
| 2864 | } |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2865 | 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] | 2866 | struct http_req_rule *rule; |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2867 | |
| 2868 | if (curproxy == &defproxy) { |
| 2869 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2870 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2871 | goto out; |
| 2872 | } |
| 2873 | |
Willy Tarreau | 20b0de5 | 2012-12-24 15:45:22 +0100 | [diff] [blame] | 2874 | if (!LIST_ISEMPTY(&curproxy->http_req_rules) && |
| 2875 | !LIST_PREV(&curproxy->http_req_rules, struct http_req_rule *, list)->cond && |
| 2876 | (LIST_PREV(&curproxy->http_req_rules, struct http_req_rule *, list)->action == HTTP_REQ_ACT_ALLOW || |
| 2877 | 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] | 2878 | 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] | 2879 | LIST_PREV(&curproxy->http_req_rules, struct http_req_rule *, list)->action == HTTP_REQ_ACT_AUTH)) { |
| 2880 | 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] | 2881 | file, linenum, args[0]); |
| 2882 | err_code |= ERR_WARN; |
| 2883 | } |
| 2884 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 2885 | 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] | 2886 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 2887 | if (!rule) { |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2888 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2889 | goto out; |
| 2890 | } |
| 2891 | |
Willy Tarreau | 5002f57 | 2014-04-23 01:32:02 +0200 | [diff] [blame] | 2892 | err_code |= warnif_misplaced_http_req(curproxy, file, linenum, args[0]); |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 2893 | err_code |= warnif_cond_conflicts(rule->cond, |
| 2894 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 2895 | file, linenum); |
| 2896 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 2897 | LIST_ADDQ(&curproxy->http_req_rules, &rule->list); |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2898 | } |
Willy Tarreau | e365c0b | 2013-06-11 16:06:12 +0200 | [diff] [blame] | 2899 | else if (!strcmp(args[0], "http-response")) { /* response access control */ |
| 2900 | struct http_res_rule *rule; |
| 2901 | |
| 2902 | if (curproxy == &defproxy) { |
| 2903 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2904 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2905 | goto out; |
| 2906 | } |
| 2907 | |
| 2908 | if (!LIST_ISEMPTY(&curproxy->http_res_rules) && |
| 2909 | !LIST_PREV(&curproxy->http_res_rules, struct http_res_rule *, list)->cond && |
| 2910 | (LIST_PREV(&curproxy->http_res_rules, struct http_res_rule *, list)->action == HTTP_RES_ACT_ALLOW || |
| 2911 | LIST_PREV(&curproxy->http_res_rules, struct http_res_rule *, list)->action == HTTP_RES_ACT_DENY)) { |
| 2912 | Warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n", |
| 2913 | file, linenum, args[0]); |
| 2914 | err_code |= ERR_WARN; |
| 2915 | } |
| 2916 | |
| 2917 | rule = parse_http_res_cond((const char **)args + 1, file, linenum, curproxy); |
| 2918 | |
| 2919 | if (!rule) { |
| 2920 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2921 | goto out; |
| 2922 | } |
| 2923 | |
| 2924 | err_code |= warnif_cond_conflicts(rule->cond, |
| 2925 | (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR, |
| 2926 | file, linenum); |
| 2927 | |
| 2928 | LIST_ADDQ(&curproxy->http_res_rules, &rule->list); |
| 2929 | } |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 2930 | else if (!strcmp(args[0], "http-send-name-header")) { /* send server name in request header */ |
| 2931 | /* set the header name and length into the proxy structure */ |
| 2932 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 2933 | err_code |= ERR_WARN; |
| 2934 | |
| 2935 | if (!*args[1]) { |
| 2936 | Alert("parsing [%s:%d] : '%s' requires a header string.\n", |
| 2937 | file, linenum, args[0]); |
| 2938 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2939 | goto out; |
| 2940 | } |
| 2941 | |
| 2942 | /* set the desired header name */ |
| 2943 | free(curproxy->server_id_hdr_name); |
| 2944 | curproxy->server_id_hdr_name = strdup(args[1]); |
| 2945 | curproxy->server_id_hdr_len = strlen(curproxy->server_id_hdr_name); |
| 2946 | } |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2947 | else if (!strcmp(args[0], "block")) { /* early blocking based on ACLs */ |
Willy Tarreau | b3dc39d | 2014-04-28 22:06:57 +0200 | [diff] [blame] | 2948 | struct http_req_rule *rule; |
| 2949 | |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2950 | if (curproxy == &defproxy) { |
| 2951 | 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] | 2952 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2953 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2954 | } |
| 2955 | |
Willy Tarreau | b3dc39d | 2014-04-28 22:06:57 +0200 | [diff] [blame] | 2956 | /* emulate "block" using "http-request block". Since these rules are supposed to |
| 2957 | * be processed before all http-request rules, we put them into their own list |
| 2958 | * and will insert them at the end. |
| 2959 | */ |
| 2960 | rule = parse_http_req_cond((const char **)args, file, linenum, curproxy); |
| 2961 | if (!rule) { |
| 2962 | err_code |= ERR_ALERT | ERR_ABORT; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2963 | goto out; |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2964 | } |
Willy Tarreau | b3dc39d | 2014-04-28 22:06:57 +0200 | [diff] [blame] | 2965 | err_code |= warnif_misplaced_block(curproxy, file, linenum, args[0]); |
| 2966 | err_code |= warnif_cond_conflicts(rule->cond, |
| 2967 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 2968 | file, linenum); |
| 2969 | LIST_ADDQ(&curproxy->block_rules, &rule->list); |
Willy Tarreau | de9d2d7 | 2014-04-28 22:28:02 +0200 | [diff] [blame] | 2970 | |
| 2971 | if (!already_warned(WARN_BLOCK_DEPRECATED)) |
| 2972 | 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]); |
| 2973 | |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2974 | } |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2975 | else if (!strcmp(args[0], "redirect")) { |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2976 | struct redirect_rule *rule; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2977 | |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 2978 | if (curproxy == &defproxy) { |
| 2979 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2980 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2981 | goto out; |
| 2982 | } |
| 2983 | |
Thierry FOURNIER | d18cd0f | 2013-11-29 12:15:45 +0100 | [diff] [blame] | 2984 | 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] | 2985 | Alert("parsing [%s:%d] : error detected in %s '%s' while parsing redirect rule : %s.\n", |
| 2986 | file, linenum, proxy_type_str(curproxy), curproxy->id, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2987 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2988 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2989 | } |
| 2990 | |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2991 | LIST_ADDQ(&curproxy->redirect_rules, &rule->list); |
Willy Tarreau | ee445d9 | 2014-04-23 01:39:04 +0200 | [diff] [blame] | 2992 | err_code |= warnif_misplaced_redirect(curproxy, file, linenum, args[0]); |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 2993 | err_code |= warnif_cond_conflicts(rule->cond, |
| 2994 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 2995 | file, linenum); |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2996 | } |
Krzysztof Piotr Oledzki | 7b723ef | 2009-01-27 21:09:41 +0100 | [diff] [blame] | 2997 | else if (!strcmp(args[0], "use_backend")) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2998 | struct switching_rule *rule; |
| 2999 | |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3000 | if (curproxy == &defproxy) { |
| 3001 | 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] | 3002 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3003 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3004 | } |
| 3005 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3006 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3007 | err_code |= ERR_WARN; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3008 | |
| 3009 | if (*(args[1]) == 0) { |
| 3010 | 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] | 3011 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3012 | goto out; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3013 | } |
| 3014 | |
Willy Tarreau | f51658d | 2014-04-23 01:21:56 +0200 | [diff] [blame] | 3015 | if (strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0) { |
| 3016 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 3017 | Alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n", |
| 3018 | file, linenum, errmsg); |
| 3019 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3020 | goto out; |
| 3021 | } |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3022 | |
Willy Tarreau | f51658d | 2014-04-23 01:21:56 +0200 | [diff] [blame] | 3023 | 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] | 3024 | } |
| 3025 | |
| 3026 | rule = (struct switching_rule *)calloc(1, sizeof(*rule)); |
| 3027 | rule->cond = cond; |
| 3028 | rule->be.name = strdup(args[1]); |
| 3029 | LIST_INIT(&rule->list); |
| 3030 | LIST_ADDQ(&curproxy->switching_rules, &rule->list); |
| 3031 | } |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 3032 | else if (strcmp(args[0], "use-server") == 0) { |
| 3033 | struct server_rule *rule; |
| 3034 | |
| 3035 | if (curproxy == &defproxy) { |
| 3036 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3037 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3038 | goto out; |
| 3039 | } |
| 3040 | |
| 3041 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 3042 | err_code |= ERR_WARN; |
| 3043 | |
| 3044 | if (*(args[1]) == 0) { |
| 3045 | Alert("parsing [%s:%d] : '%s' expects a server name.\n", file, linenum, args[0]); |
| 3046 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3047 | goto out; |
| 3048 | } |
| 3049 | |
| 3050 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
| 3051 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 3052 | file, linenum, args[0]); |
| 3053 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3054 | goto out; |
| 3055 | } |
| 3056 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 3057 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 3058 | Alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n", |
| 3059 | file, linenum, errmsg); |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 3060 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3061 | goto out; |
| 3062 | } |
| 3063 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3064 | 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] | 3065 | |
| 3066 | rule = (struct server_rule *)calloc(1, sizeof(*rule)); |
| 3067 | rule->cond = cond; |
| 3068 | rule->srv.name = strdup(args[1]); |
| 3069 | LIST_INIT(&rule->list); |
| 3070 | LIST_ADDQ(&curproxy->server_rules, &rule->list); |
| 3071 | curproxy->be_req_ana |= AN_REQ_SRV_RULES; |
| 3072 | } |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 3073 | else if ((!strcmp(args[0], "force-persist")) || |
| 3074 | (!strcmp(args[0], "ignore-persist"))) { |
| 3075 | struct persist_rule *rule; |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 3076 | |
| 3077 | if (curproxy == &defproxy) { |
| 3078 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3079 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3080 | goto out; |
| 3081 | } |
| 3082 | |
| 3083 | if (warnifnotcap(curproxy, PR_CAP_FE|PR_CAP_BE, file, linenum, args[0], NULL)) |
| 3084 | err_code |= ERR_WARN; |
| 3085 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 3086 | if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) { |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 3087 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 3088 | file, linenum, args[0]); |
| 3089 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3090 | goto out; |
| 3091 | } |
| 3092 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 3093 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 1, &errmsg)) == NULL) { |
| 3094 | Alert("parsing [%s:%d] : error detected while parsing a '%s' rule : %s.\n", |
| 3095 | file, linenum, args[0], errmsg); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 3096 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3097 | goto out; |
| 3098 | } |
| 3099 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3100 | /* note: BE_REQ_CNT is the first one after FE_SET_BCK, which is |
| 3101 | * where force-persist is applied. |
| 3102 | */ |
| 3103 | 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] | 3104 | |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 3105 | rule = (struct persist_rule *)calloc(1, sizeof(*rule)); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 3106 | rule->cond = cond; |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 3107 | if (!strcmp(args[0], "force-persist")) { |
| 3108 | rule->type = PERSIST_TYPE_FORCE; |
| 3109 | } else { |
| 3110 | rule->type = PERSIST_TYPE_IGNORE; |
| 3111 | } |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 3112 | LIST_INIT(&rule->list); |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 3113 | LIST_ADDQ(&curproxy->persist_rules, &rule->list); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 3114 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3115 | else if (!strcmp(args[0], "stick-table")) { |
| 3116 | int myidx = 1; |
| 3117 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 3118 | curproxy->table.id = curproxy->id; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3119 | curproxy->table.type = (unsigned int)-1; |
| 3120 | while (*args[myidx]) { |
| 3121 | const char *err; |
| 3122 | |
| 3123 | if (strcmp(args[myidx], "size") == 0) { |
| 3124 | myidx++; |
| 3125 | if (!*(args[myidx])) { |
| 3126 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 3127 | file, linenum, args[myidx-1]); |
| 3128 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3129 | goto out; |
| 3130 | } |
| 3131 | if ((err = parse_size_err(args[myidx], &curproxy->table.size))) { |
| 3132 | Alert("parsing [%s:%d] : stick-table: unexpected character '%c' in argument of '%s'.\n", |
| 3133 | file, linenum, *err, args[myidx-1]); |
| 3134 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3135 | goto out; |
| 3136 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 3137 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3138 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 3139 | else if (strcmp(args[myidx], "peers") == 0) { |
| 3140 | myidx++; |
Godbach | 5052316 | 2013-12-11 19:48:57 +0800 | [diff] [blame] | 3141 | if (!*(args[myidx])) { |
Godbach | ff11554 | 2014-04-21 21:52:23 +0800 | [diff] [blame] | 3142 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 3143 | file, linenum, args[myidx-1]); |
| 3144 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3145 | goto out; |
Godbach | 5052316 | 2013-12-11 19:48:57 +0800 | [diff] [blame] | 3146 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 3147 | curproxy->table.peers.name = strdup(args[myidx++]); |
| 3148 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3149 | else if (strcmp(args[myidx], "expire") == 0) { |
| 3150 | myidx++; |
| 3151 | if (!*(args[myidx])) { |
| 3152 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 3153 | file, linenum, args[myidx-1]); |
| 3154 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3155 | goto out; |
| 3156 | } |
| 3157 | err = parse_time_err(args[myidx], &val, TIME_UNIT_MS); |
| 3158 | if (err) { |
| 3159 | Alert("parsing [%s:%d] : stick-table: unexpected character '%c' in argument of '%s'.\n", |
| 3160 | file, linenum, *err, args[myidx-1]); |
| 3161 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3162 | goto out; |
| 3163 | } |
| 3164 | curproxy->table.expire = val; |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 3165 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3166 | } |
| 3167 | else if (strcmp(args[myidx], "nopurge") == 0) { |
| 3168 | curproxy->table.nopurge = 1; |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 3169 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3170 | } |
| 3171 | else if (strcmp(args[myidx], "type") == 0) { |
| 3172 | myidx++; |
| 3173 | if (stktable_parse_type(args, &myidx, &curproxy->table.type, &curproxy->table.key_size) != 0) { |
| 3174 | Alert("parsing [%s:%d] : stick-table: unknown type '%s'.\n", |
| 3175 | file, linenum, args[myidx]); |
| 3176 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3177 | goto out; |
| 3178 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 3179 | /* myidx already points to next arg */ |
| 3180 | } |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 3181 | else if (strcmp(args[myidx], "store") == 0) { |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 3182 | int type, err; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 3183 | char *cw, *nw, *sa; |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 3184 | |
| 3185 | myidx++; |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 3186 | nw = args[myidx]; |
| 3187 | while (*nw) { |
| 3188 | /* the "store" keyword supports a comma-separated list */ |
| 3189 | cw = nw; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 3190 | sa = NULL; /* store arg */ |
| 3191 | while (*nw && *nw != ',') { |
| 3192 | if (*nw == '(') { |
| 3193 | *nw = 0; |
| 3194 | sa = ++nw; |
| 3195 | while (*nw != ')') { |
| 3196 | if (!*nw) { |
| 3197 | Alert("parsing [%s:%d] : %s: missing closing parenthesis after store option '%s'.\n", |
| 3198 | file, linenum, args[0], cw); |
| 3199 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3200 | goto out; |
| 3201 | } |
| 3202 | nw++; |
| 3203 | } |
| 3204 | *nw = '\0'; |
| 3205 | } |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 3206 | nw++; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 3207 | } |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 3208 | if (*nw) |
| 3209 | *nw++ = '\0'; |
| 3210 | type = stktable_get_data_type(cw); |
| 3211 | if (type < 0) { |
| 3212 | Alert("parsing [%s:%d] : %s: unknown store option '%s'.\n", |
| 3213 | file, linenum, args[0], cw); |
| 3214 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3215 | goto out; |
| 3216 | } |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 3217 | |
| 3218 | err = stktable_alloc_data_type(&curproxy->table, type, sa); |
| 3219 | switch (err) { |
| 3220 | case PE_NONE: break; |
| 3221 | case PE_EXIST: |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 3222 | Warning("parsing [%s:%d]: %s: store option '%s' already enabled, ignored.\n", |
| 3223 | file, linenum, args[0], cw); |
| 3224 | err_code |= ERR_WARN; |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 3225 | break; |
| 3226 | |
| 3227 | case PE_ARG_MISSING: |
| 3228 | Alert("parsing [%s:%d] : %s: missing argument to store option '%s'.\n", |
| 3229 | file, linenum, args[0], cw); |
| 3230 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3231 | goto out; |
| 3232 | |
| 3233 | case PE_ARG_NOT_USED: |
| 3234 | Alert("parsing [%s:%d] : %s: unexpected argument to store option '%s'.\n", |
| 3235 | file, linenum, args[0], cw); |
| 3236 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3237 | goto out; |
| 3238 | |
| 3239 | default: |
| 3240 | Alert("parsing [%s:%d] : %s: error when processing store option '%s'.\n", |
| 3241 | file, linenum, args[0], cw); |
| 3242 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3243 | goto out; |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 3244 | } |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 3245 | } |
| 3246 | myidx++; |
| 3247 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 3248 | else { |
| 3249 | Alert("parsing [%s:%d] : stick-table: unknown argument '%s'.\n", |
| 3250 | file, linenum, args[myidx]); |
| 3251 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3252 | goto out; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3253 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3254 | } |
| 3255 | |
| 3256 | if (!curproxy->table.size) { |
| 3257 | Alert("parsing [%s:%d] : stick-table: missing size.\n", |
| 3258 | file, linenum); |
| 3259 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3260 | goto out; |
| 3261 | } |
| 3262 | |
| 3263 | if (curproxy->table.type == (unsigned int)-1) { |
| 3264 | Alert("parsing [%s:%d] : stick-table: missing type.\n", |
| 3265 | file, linenum); |
| 3266 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3267 | goto out; |
| 3268 | } |
| 3269 | } |
| 3270 | else if (!strcmp(args[0], "stick")) { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3271 | struct sticking_rule *rule; |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 3272 | struct sample_expr *expr; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3273 | int myidx = 0; |
| 3274 | const char *name = NULL; |
| 3275 | int flags; |
| 3276 | |
| 3277 | if (curproxy == &defproxy) { |
| 3278 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3279 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3280 | goto out; |
| 3281 | } |
| 3282 | |
| 3283 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) { |
| 3284 | err_code |= ERR_WARN; |
| 3285 | goto out; |
| 3286 | } |
| 3287 | |
| 3288 | myidx++; |
| 3289 | if ((strcmp(args[myidx], "store") == 0) || |
| 3290 | (strcmp(args[myidx], "store-request") == 0)) { |
| 3291 | myidx++; |
| 3292 | flags = STK_IS_STORE; |
| 3293 | } |
| 3294 | else if (strcmp(args[myidx], "store-response") == 0) { |
| 3295 | myidx++; |
| 3296 | flags = STK_IS_STORE | STK_ON_RSP; |
| 3297 | } |
| 3298 | else if (strcmp(args[myidx], "match") == 0) { |
| 3299 | myidx++; |
| 3300 | flags = STK_IS_MATCH; |
| 3301 | } |
| 3302 | else if (strcmp(args[myidx], "on") == 0) { |
| 3303 | myidx++; |
| 3304 | flags = STK_IS_MATCH | STK_IS_STORE; |
| 3305 | } |
| 3306 | else { |
| 3307 | Alert("parsing [%s:%d] : '%s' expects 'on', 'match', or 'store'.\n", file, linenum, args[0]); |
| 3308 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3309 | goto out; |
| 3310 | } |
| 3311 | |
| 3312 | if (*(args[myidx]) == 0) { |
| 3313 | Alert("parsing [%s:%d] : '%s' expects a fetch method.\n", file, linenum, args[0]); |
| 3314 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3315 | goto out; |
| 3316 | } |
| 3317 | |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 3318 | curproxy->conf.args.ctx = ARGC_STK; |
Thierry FOURNIER | eeaa951 | 2014-02-11 14:00:19 +0100 | [diff] [blame] | 3319 | expr = sample_parse_expr(args, &myidx, file, linenum, &errmsg, &curproxy->conf.args); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3320 | if (!expr) { |
Willy Tarreau | 975c178 | 2013-12-12 23:16:54 +0100 | [diff] [blame] | 3321 | Alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3322 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3323 | goto out; |
| 3324 | } |
| 3325 | |
| 3326 | if (flags & STK_ON_RSP) { |
Willy Tarreau | 80aca90 | 2013-01-07 15:42:20 +0100 | [diff] [blame] | 3327 | if (!(expr->fetch->val & SMP_VAL_BE_STO_RUL)) { |
| 3328 | Alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available for 'store-response'.\n", |
| 3329 | 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] | 3330 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 3331 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3332 | goto out; |
| 3333 | } |
| 3334 | } else { |
Willy Tarreau | 80aca90 | 2013-01-07 15:42:20 +0100 | [diff] [blame] | 3335 | if (!(expr->fetch->val & SMP_VAL_BE_SET_SRV)) { |
| 3336 | Alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available during request.\n", |
| 3337 | 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] | 3338 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 3339 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3340 | goto out; |
| 3341 | } |
| 3342 | } |
| 3343 | |
Willy Tarreau | 1b6c00c | 2012-10-05 22:41:26 +0200 | [diff] [blame] | 3344 | /* 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] | 3345 | curproxy->http_needed |= !!(expr->fetch->use & SMP_USE_HTTP_ANY); |
Willy Tarreau | 1b6c00c | 2012-10-05 22:41:26 +0200 | [diff] [blame] | 3346 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3347 | if (strcmp(args[myidx], "table") == 0) { |
| 3348 | myidx++; |
| 3349 | name = args[myidx++]; |
| 3350 | } |
| 3351 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 3352 | if (strcmp(args[myidx], "if") == 0 || strcmp(args[myidx], "unless") == 0) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 3353 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + myidx, &errmsg)) == NULL) { |
| 3354 | Alert("parsing [%s:%d] : '%s': error detected while parsing sticking condition : %s.\n", |
| 3355 | file, linenum, args[0], errmsg); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3356 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 3357 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3358 | goto out; |
| 3359 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3360 | } |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 3361 | else if (*(args[myidx])) { |
| 3362 | Alert("parsing [%s:%d] : '%s': unknown keyword '%s'.\n", |
| 3363 | file, linenum, args[0], args[myidx]); |
| 3364 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 3365 | free(expr); |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 3366 | goto out; |
| 3367 | } |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 3368 | if (flags & STK_ON_RSP) |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3369 | 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] | 3370 | else |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3371 | 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] | 3372 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3373 | rule = (struct sticking_rule *)calloc(1, sizeof(*rule)); |
| 3374 | rule->cond = cond; |
| 3375 | rule->expr = expr; |
| 3376 | rule->flags = flags; |
| 3377 | rule->table.name = name ? strdup(name) : NULL; |
| 3378 | LIST_INIT(&rule->list); |
| 3379 | if (flags & STK_ON_RSP) |
| 3380 | LIST_ADDQ(&curproxy->storersp_rules, &rule->list); |
| 3381 | else |
| 3382 | LIST_ADDQ(&curproxy->sticking_rules, &rule->list); |
| 3383 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3384 | else if (!strcmp(args[0], "stats")) { |
| 3385 | if (curproxy != &defproxy && curproxy->uri_auth == defproxy.uri_auth) |
| 3386 | curproxy->uri_auth = NULL; /* we must detach from the default config */ |
| 3387 | |
Krzysztof Piotr Oledzki | 260a3bb | 2010-01-06 16:25:05 +0100 | [diff] [blame] | 3388 | if (!*args[1]) { |
| 3389 | goto stats_error_parsing; |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3390 | } else if (!strcmp(args[1], "admin")) { |
| 3391 | struct stats_admin_rule *rule; |
| 3392 | |
| 3393 | if (curproxy == &defproxy) { |
| 3394 | Alert("parsing [%s:%d]: '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
| 3395 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3396 | goto out; |
| 3397 | } |
| 3398 | |
| 3399 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 3400 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3401 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3402 | goto out; |
| 3403 | } |
| 3404 | |
| 3405 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
| 3406 | Alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n", |
| 3407 | file, linenum, args[0], args[1]); |
| 3408 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3409 | goto out; |
| 3410 | } |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 3411 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 3412 | Alert("parsing [%s:%d] : error detected while parsing a '%s %s' rule : %s.\n", |
| 3413 | file, linenum, args[0], args[1], errmsg); |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3414 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3415 | goto out; |
| 3416 | } |
| 3417 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3418 | err_code |= warnif_cond_conflicts(cond, |
| 3419 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 3420 | file, linenum); |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3421 | |
| 3422 | rule = (struct stats_admin_rule *)calloc(1, sizeof(*rule)); |
| 3423 | rule->cond = cond; |
| 3424 | LIST_INIT(&rule->list); |
| 3425 | LIST_ADDQ(&curproxy->uri_auth->admin_rules, &rule->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3426 | } else if (!strcmp(args[1], "uri")) { |
| 3427 | if (*(args[2]) == 0) { |
| 3428 | Alert("parsing [%s:%d] : 'uri' needs an URI prefix.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3429 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3430 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3431 | } else if (!stats_set_uri(&curproxy->uri_auth, args[2])) { |
| 3432 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3433 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3434 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3435 | } |
| 3436 | } else if (!strcmp(args[1], "realm")) { |
| 3437 | if (*(args[2]) == 0) { |
| 3438 | Alert("parsing [%s:%d] : 'realm' needs an realm name.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3439 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3440 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3441 | } else if (!stats_set_realm(&curproxy->uri_auth, args[2])) { |
| 3442 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3443 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3444 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3445 | } |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 3446 | } else if (!strcmp(args[1], "refresh")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 3447 | unsigned interval; |
| 3448 | |
| 3449 | err = parse_time_err(args[2], &interval, TIME_UNIT_S); |
| 3450 | if (err) { |
| 3451 | Alert("parsing [%s:%d] : unexpected character '%c' in stats refresh interval.\n", |
| 3452 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3453 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3454 | goto out; |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 3455 | } else if (!stats_set_refresh(&curproxy->uri_auth, interval)) { |
| 3456 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3457 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3458 | goto out; |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 3459 | } |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3460 | } 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] | 3461 | struct http_req_rule *rule; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3462 | |
| 3463 | if (curproxy == &defproxy) { |
| 3464 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3465 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3466 | goto out; |
| 3467 | } |
| 3468 | |
| 3469 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 3470 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3471 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3472 | goto out; |
| 3473 | } |
| 3474 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3475 | if (!LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) && |
| 3476 | !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] | 3477 | Warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n", |
| 3478 | file, linenum, args[0]); |
| 3479 | err_code |= ERR_WARN; |
| 3480 | } |
| 3481 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3482 | 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] | 3483 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3484 | if (!rule) { |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3485 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3486 | goto out; |
| 3487 | } |
| 3488 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3489 | err_code |= warnif_cond_conflicts(rule->cond, |
| 3490 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 3491 | file, linenum); |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3492 | LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list); |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3493 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3494 | } else if (!strcmp(args[1], "auth")) { |
| 3495 | if (*(args[2]) == 0) { |
| 3496 | 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] | 3497 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3498 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3499 | } else if (!stats_add_auth(&curproxy->uri_auth, args[2])) { |
| 3500 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3501 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3502 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3503 | } |
| 3504 | } else if (!strcmp(args[1], "scope")) { |
| 3505 | if (*(args[2]) == 0) { |
| 3506 | Alert("parsing [%s:%d] : 'scope' needs a proxy name.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3507 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3508 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3509 | } else if (!stats_add_scope(&curproxy->uri_auth, args[2])) { |
| 3510 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3511 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3512 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3513 | } |
| 3514 | } else if (!strcmp(args[1], "enable")) { |
| 3515 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 3516 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3517 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3518 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3519 | } |
Krzysztof Oledzki | d9db927 | 2007-10-15 10:05:11 +0200 | [diff] [blame] | 3520 | } else if (!strcmp(args[1], "hide-version")) { |
| 3521 | if (!stats_set_flag(&curproxy->uri_auth, ST_HIDEVER)) { |
| 3522 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3523 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3524 | goto out; |
Krzysztof Oledzki | d9db927 | 2007-10-15 10:05:11 +0200 | [diff] [blame] | 3525 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3526 | } else if (!strcmp(args[1], "show-legends")) { |
| 3527 | if (!stats_set_flag(&curproxy->uri_auth, ST_SHLGNDS)) { |
| 3528 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3529 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3530 | goto out; |
| 3531 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3532 | } else if (!strcmp(args[1], "show-node")) { |
| 3533 | |
| 3534 | if (*args[2]) { |
| 3535 | int i; |
| 3536 | char c; |
| 3537 | |
| 3538 | for (i=0; args[2][i]; i++) { |
| 3539 | c = args[2][i]; |
Willy Tarreau | 88e0581 | 2010-03-03 00:16:00 +0100 | [diff] [blame] | 3540 | if (!isupper((unsigned char)c) && !islower((unsigned char)c) && |
| 3541 | !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.') |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3542 | break; |
| 3543 | } |
| 3544 | |
| 3545 | if (!i || args[2][i]) { |
| 3546 | Alert("parsing [%s:%d]: '%s %s' invalid node name - should be a string" |
| 3547 | "with digits(0-9), letters(A-Z, a-z), hyphen(-) or underscode(_).\n", |
| 3548 | file, linenum, args[0], args[1]); |
| 3549 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3550 | goto out; |
| 3551 | } |
| 3552 | } |
| 3553 | |
| 3554 | if (!stats_set_node(&curproxy->uri_auth, args[2])) { |
| 3555 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3556 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3557 | goto out; |
| 3558 | } |
| 3559 | } else if (!strcmp(args[1], "show-desc")) { |
| 3560 | char *desc = NULL; |
| 3561 | |
| 3562 | if (*args[2]) { |
| 3563 | int i, len=0; |
| 3564 | char *d; |
| 3565 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 3566 | for (i = 2; *args[i]; i++) |
| 3567 | len += strlen(args[i]) + 1; |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3568 | |
| 3569 | desc = d = (char *)calloc(1, len); |
| 3570 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 3571 | d += snprintf(d, desc + len - d, "%s", args[2]); |
| 3572 | for (i = 3; *args[i]; i++) |
| 3573 | d += snprintf(d, desc + len - d, " %s", args[i]); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3574 | } |
| 3575 | |
| 3576 | if (!*args[2] && !global.desc) |
| 3577 | Warning("parsing [%s:%d]: '%s' requires a parameter or 'desc' to be set in the global section.\n", |
| 3578 | file, linenum, args[1]); |
| 3579 | else { |
| 3580 | if (!stats_set_desc(&curproxy->uri_auth, desc)) { |
| 3581 | free(desc); |
| 3582 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3583 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3584 | goto out; |
| 3585 | } |
| 3586 | free(desc); |
| 3587 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3588 | } else { |
Krzysztof Piotr Oledzki | 260a3bb | 2010-01-06 16:25:05 +0100 | [diff] [blame] | 3589 | stats_error_parsing: |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3590 | 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] | 3591 | 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] | 3592 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3593 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3594 | } |
| 3595 | } |
| 3596 | else if (!strcmp(args[0], "option")) { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3597 | int optnum; |
| 3598 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3599 | if (*(args[1]) == '\0') { |
| 3600 | Alert("parsing [%s:%d]: '%s' expects an option name.\n", |
| 3601 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3602 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3603 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3604 | } |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3605 | |
| 3606 | for (optnum = 0; cfg_opts[optnum].name; optnum++) { |
| 3607 | if (!strcmp(args[1], cfg_opts[optnum].name)) { |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 3608 | if (cfg_opts[optnum].cap == PR_CAP_NONE) { |
| 3609 | Alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n", |
| 3610 | file, linenum, cfg_opts[optnum].name); |
| 3611 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3612 | goto out; |
| 3613 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3614 | if (warnifnotcap(curproxy, cfg_opts[optnum].cap, file, linenum, args[1], NULL)) { |
| 3615 | err_code |= ERR_WARN; |
| 3616 | goto out; |
| 3617 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3618 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 3619 | curproxy->no_options &= ~cfg_opts[optnum].val; |
| 3620 | curproxy->options &= ~cfg_opts[optnum].val; |
| 3621 | |
| 3622 | switch (kwm) { |
| 3623 | case KWM_STD: |
| 3624 | curproxy->options |= cfg_opts[optnum].val; |
| 3625 | break; |
| 3626 | case KWM_NO: |
| 3627 | curproxy->no_options |= cfg_opts[optnum].val; |
| 3628 | break; |
| 3629 | case KWM_DEF: /* already cleared */ |
| 3630 | break; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 3631 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3632 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3633 | goto out; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3634 | } |
| 3635 | } |
| 3636 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 3637 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) { |
| 3638 | if (!strcmp(args[1], cfg_opts2[optnum].name)) { |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 3639 | if (cfg_opts2[optnum].cap == PR_CAP_NONE) { |
| 3640 | Alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n", |
| 3641 | file, linenum, cfg_opts2[optnum].name); |
| 3642 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3643 | goto out; |
| 3644 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3645 | if (warnifnotcap(curproxy, cfg_opts2[optnum].cap, file, linenum, args[1], NULL)) { |
| 3646 | err_code |= ERR_WARN; |
| 3647 | goto out; |
| 3648 | } |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 3649 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 3650 | curproxy->no_options2 &= ~cfg_opts2[optnum].val; |
| 3651 | curproxy->options2 &= ~cfg_opts2[optnum].val; |
| 3652 | |
| 3653 | switch (kwm) { |
| 3654 | case KWM_STD: |
| 3655 | curproxy->options2 |= cfg_opts2[optnum].val; |
| 3656 | break; |
| 3657 | case KWM_NO: |
| 3658 | curproxy->no_options2 |= cfg_opts2[optnum].val; |
| 3659 | break; |
| 3660 | case KWM_DEF: /* already cleared */ |
| 3661 | break; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 3662 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3663 | goto out; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 3664 | } |
| 3665 | } |
| 3666 | |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 3667 | /* HTTP options override each other. They can be cancelled using |
| 3668 | * "no option xxx" which only switches to default mode if the mode |
| 3669 | * was this one (useful for cancelling options set in defaults |
| 3670 | * sections). |
| 3671 | */ |
| 3672 | if (strcmp(args[1], "httpclose") == 0) { |
| 3673 | if (kwm == KWM_STD) { |
| 3674 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3675 | curproxy->options |= PR_O_HTTP_PCL; |
| 3676 | goto out; |
| 3677 | } |
| 3678 | else if (kwm == KWM_NO) { |
| 3679 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_PCL) |
| 3680 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3681 | goto out; |
| 3682 | } |
| 3683 | } |
| 3684 | else if (strcmp(args[1], "forceclose") == 0) { |
| 3685 | if (kwm == KWM_STD) { |
| 3686 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3687 | curproxy->options |= PR_O_HTTP_FCL; |
| 3688 | goto out; |
| 3689 | } |
| 3690 | else if (kwm == KWM_NO) { |
| 3691 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_FCL) |
| 3692 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3693 | goto out; |
| 3694 | } |
| 3695 | } |
| 3696 | else if (strcmp(args[1], "http-server-close") == 0) { |
| 3697 | if (kwm == KWM_STD) { |
| 3698 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3699 | curproxy->options |= PR_O_HTTP_SCL; |
| 3700 | goto out; |
| 3701 | } |
| 3702 | else if (kwm == KWM_NO) { |
| 3703 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_SCL) |
| 3704 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3705 | goto out; |
| 3706 | } |
| 3707 | } |
| 3708 | else if (strcmp(args[1], "http-keep-alive") == 0) { |
| 3709 | if (kwm == KWM_STD) { |
| 3710 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3711 | curproxy->options |= PR_O_HTTP_KAL; |
| 3712 | goto out; |
| 3713 | } |
| 3714 | else if (kwm == KWM_NO) { |
| 3715 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_KAL) |
| 3716 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3717 | goto out; |
| 3718 | } |
| 3719 | } |
| 3720 | else if (strcmp(args[1], "http-tunnel") == 0) { |
| 3721 | if (kwm == KWM_STD) { |
| 3722 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3723 | curproxy->options |= PR_O_HTTP_TUN; |
| 3724 | goto out; |
| 3725 | } |
| 3726 | else if (kwm == KWM_NO) { |
| 3727 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_TUN) |
| 3728 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3729 | goto out; |
| 3730 | } |
| 3731 | } |
| 3732 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 3733 | if (kwm != KWM_STD) { |
| 3734 | 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] | 3735 | file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3736 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3737 | goto out; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3738 | } |
| 3739 | |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3740 | if (!strcmp(args[1], "httplog")) { |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 3741 | char *logformat; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3742 | /* generate a complete HTTP log */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 3743 | logformat = default_http_log_format; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3744 | if (*(args[2]) != '\0') { |
| 3745 | if (!strcmp(args[2], "clf")) { |
| 3746 | curproxy->options2 |= PR_O2_CLFLOG; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 3747 | logformat = clf_http_log_format; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3748 | } else { |
| 3749 | 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] | 3750 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3751 | goto out; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3752 | } |
| 3753 | } |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 3754 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 3755 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 3756 | curproxy->conf.logformat_string != clf_http_log_format) |
| 3757 | free(curproxy->conf.logformat_string); |
| 3758 | curproxy->conf.logformat_string = logformat; |
| 3759 | |
| 3760 | free(curproxy->conf.lfs_file); |
| 3761 | curproxy->conf.lfs_file = strdup(curproxy->conf.args.file); |
| 3762 | curproxy->conf.lfs_line = curproxy->conf.args.line; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3763 | } |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 3764 | else if (!strcmp(args[1], "tcplog")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3765 | /* generate a detailed TCP log */ |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 3766 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 3767 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 3768 | curproxy->conf.logformat_string != clf_http_log_format) |
| 3769 | free(curproxy->conf.logformat_string); |
| 3770 | curproxy->conf.logformat_string = default_tcp_log_format; |
| 3771 | |
| 3772 | free(curproxy->conf.lfs_file); |
| 3773 | curproxy->conf.lfs_file = strdup(curproxy->conf.args.file); |
| 3774 | curproxy->conf.lfs_line = curproxy->conf.args.line; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 3775 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3776 | else if (!strcmp(args[1], "tcpka")) { |
| 3777 | /* enable TCP keep-alives on client and server sessions */ |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3778 | 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] | 3779 | err_code |= ERR_WARN; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3780 | |
| 3781 | if (curproxy->cap & PR_CAP_FE) |
| 3782 | curproxy->options |= PR_O_TCP_CLI_KA; |
| 3783 | if (curproxy->cap & PR_CAP_BE) |
| 3784 | curproxy->options |= PR_O_TCP_SRV_KA; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3785 | } |
| 3786 | else if (!strcmp(args[1], "httpchk")) { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3787 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3788 | err_code |= ERR_WARN; |
| 3789 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3790 | /* use HTTP request to check servers' health */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3791 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 3792 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3793 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 3794 | curproxy->options2 |= PR_O2_HTTP_CHK; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3795 | if (!*args[2]) { /* no argument */ |
| 3796 | curproxy->check_req = strdup(DEF_CHECK_REQ); /* default request */ |
| 3797 | curproxy->check_len = strlen(DEF_CHECK_REQ); |
| 3798 | } else if (!*args[3]) { /* one argument : URI */ |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3799 | 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] | 3800 | curproxy->check_req = (char *)malloc(reqlen); |
| 3801 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3802 | "OPTIONS %s HTTP/1.0\r\n", args[2]); /* URI to use */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3803 | } else { /* more arguments : METHOD URI [HTTP_VER] */ |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3804 | int reqlen = strlen(args[2]) + strlen(args[3]) + 3 + strlen("\r\n"); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3805 | if (*args[4]) |
| 3806 | reqlen += strlen(args[4]); |
| 3807 | else |
| 3808 | reqlen += strlen("HTTP/1.0"); |
| 3809 | |
| 3810 | curproxy->check_req = (char *)malloc(reqlen); |
| 3811 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3812 | "%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] | 3813 | } |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 3814 | } |
| 3815 | else if (!strcmp(args[1], "ssl-hello-chk")) { |
| 3816 | /* use SSLv3 CLIENT HELLO to check servers' health */ |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3817 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3818 | err_code |= ERR_WARN; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3819 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3820 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 3821 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3822 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Willy Tarreau | 07a5490 | 2010-03-29 18:33:29 +0200 | [diff] [blame] | 3823 | curproxy->options2 |= PR_O2_SSL3_CHK; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3824 | } |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 3825 | else if (!strcmp(args[1], "smtpchk")) { |
| 3826 | /* use SMTP request to check servers' health */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3827 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 3828 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3829 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 3830 | curproxy->options2 |= PR_O2_SMTP_CHK; |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 3831 | |
| 3832 | if (!*args[2] || !*args[3]) { /* no argument or incomplete EHLO host */ |
| 3833 | curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */ |
| 3834 | curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ); |
| 3835 | } else { /* ESMTP EHLO, or SMTP HELO, and a hostname */ |
| 3836 | if (!strcmp(args[2], "EHLO") || !strcmp(args[2], "HELO")) { |
| 3837 | int reqlen = strlen(args[2]) + strlen(args[3]) + strlen(" \r\n") + 1; |
| 3838 | curproxy->check_req = (char *)malloc(reqlen); |
| 3839 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
| 3840 | "%s %s\r\n", args[2], args[3]); /* HELO hostname */ |
| 3841 | } else { |
| 3842 | /* this just hits the default for now, but you could potentially expand it to allow for other stuff |
| 3843 | though, it's unlikely you'd want to send anything other than an EHLO or HELO */ |
| 3844 | curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */ |
| 3845 | curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ); |
| 3846 | } |
| 3847 | } |
| 3848 | } |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 3849 | else if (!strcmp(args[1], "pgsql-check")) { |
| 3850 | /* use PostgreSQL request to check servers' health */ |
| 3851 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 3852 | err_code |= ERR_WARN; |
| 3853 | |
| 3854 | free(curproxy->check_req); |
| 3855 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3856 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 3857 | curproxy->options2 |= PR_O2_PGSQL_CHK; |
| 3858 | |
| 3859 | if (*(args[2])) { |
| 3860 | int cur_arg = 2; |
| 3861 | |
| 3862 | while (*(args[cur_arg])) { |
| 3863 | if (strcmp(args[cur_arg], "user") == 0) { |
| 3864 | char * packet; |
| 3865 | uint32_t packet_len; |
| 3866 | uint32_t pv; |
| 3867 | |
| 3868 | /* suboption header - needs additional argument for it */ |
| 3869 | if (*(args[cur_arg+1]) == 0) { |
| 3870 | Alert("parsing [%s:%d] : '%s %s %s' expects <username> as argument.\n", |
| 3871 | file, linenum, args[0], args[1], args[cur_arg]); |
| 3872 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3873 | goto out; |
| 3874 | } |
| 3875 | |
| 3876 | /* uint32_t + uint32_t + strlen("user")+1 + strlen(username)+1 + 1 */ |
| 3877 | packet_len = 4 + 4 + 5 + strlen(args[cur_arg + 1])+1 +1; |
| 3878 | pv = htonl(0x30000); /* protocol version 3.0 */ |
| 3879 | |
| 3880 | packet = (char*) calloc(1, packet_len); |
| 3881 | |
| 3882 | memcpy(packet + 4, &pv, 4); |
| 3883 | |
| 3884 | /* copy "user" */ |
| 3885 | memcpy(packet + 8, "user", 4); |
| 3886 | |
| 3887 | /* copy username */ |
| 3888 | memcpy(packet + 13, args[cur_arg+1], strlen(args[cur_arg+1])); |
| 3889 | |
| 3890 | free(curproxy->check_req); |
| 3891 | curproxy->check_req = packet; |
| 3892 | curproxy->check_len = packet_len; |
| 3893 | |
| 3894 | packet_len = htonl(packet_len); |
| 3895 | memcpy(packet, &packet_len, 4); |
| 3896 | cur_arg += 2; |
| 3897 | } else { |
| 3898 | /* unknown suboption - catchall */ |
| 3899 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'user'.\n", |
| 3900 | file, linenum, args[0], args[1]); |
| 3901 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3902 | goto out; |
| 3903 | } |
| 3904 | } /* end while loop */ |
| 3905 | } |
| 3906 | } |
| 3907 | |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 3908 | else if (!strcmp(args[1], "redis-check")) { |
| 3909 | /* use REDIS PING request to check servers' health */ |
| 3910 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 3911 | err_code |= ERR_WARN; |
| 3912 | |
| 3913 | free(curproxy->check_req); |
| 3914 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3915 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 3916 | curproxy->options2 |= PR_O2_REDIS_CHK; |
| 3917 | |
| 3918 | curproxy->check_req = (char *) malloc(sizeof(DEF_REDIS_CHECK_REQ) - 1); |
| 3919 | memcpy(curproxy->check_req, DEF_REDIS_CHECK_REQ, sizeof(DEF_REDIS_CHECK_REQ) - 1); |
| 3920 | curproxy->check_len = sizeof(DEF_REDIS_CHECK_REQ) - 1; |
| 3921 | } |
| 3922 | |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 3923 | else if (!strcmp(args[1], "mysql-check")) { |
| 3924 | /* use MYSQL request to check servers' health */ |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 3925 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 3926 | err_code |= ERR_WARN; |
| 3927 | |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 3928 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 3929 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3930 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 3931 | curproxy->options2 |= PR_O2_MYSQL_CHK; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 3932 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 3933 | /* 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] | 3934 | * const char mysql40_client_auth_pkt[] = { |
| 3935 | * "\x0e\x00\x00" // packet length |
| 3936 | * "\x01" // packet number |
| 3937 | * "\x00\x00" // client capabilities |
| 3938 | * "\x00\x00\x01" // max packet |
| 3939 | * "haproxy\x00" // username (null terminated string) |
| 3940 | * "\x00" // filler (always 0x00) |
| 3941 | * "\x01\x00\x00" // packet length |
| 3942 | * "\x00" // packet number |
| 3943 | * "\x01" // COM_QUIT command |
| 3944 | * }; |
| 3945 | */ |
| 3946 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 3947 | /* This is an example of a MySQL >=4.1 client Authentication packet provided by Nenad Merdanovic. |
| 3948 | * const char mysql41_client_auth_pkt[] = { |
| 3949 | * "\x0e\x00\x00\" // packet length |
| 3950 | * "\x01" // packet number |
| 3951 | * "\x00\x00\x00\x00" // client capabilities |
| 3952 | * "\x00\x00\x00\x01" // max packet |
| 3953 | * "\x21" // character set (UTF-8) |
| 3954 | * char[23] // All zeroes |
| 3955 | * "haproxy\x00" // username (null terminated string) |
| 3956 | * "\x00" // filler (always 0x00) |
| 3957 | * "\x01\x00\x00" // packet length |
| 3958 | * "\x00" // packet number |
| 3959 | * "\x01" // COM_QUIT command |
| 3960 | * }; |
| 3961 | */ |
| 3962 | |
| 3963 | |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 3964 | if (*(args[2])) { |
| 3965 | int cur_arg = 2; |
| 3966 | |
| 3967 | while (*(args[cur_arg])) { |
| 3968 | if (strcmp(args[cur_arg], "user") == 0) { |
| 3969 | char *mysqluser; |
| 3970 | int packetlen, reqlen, userlen; |
| 3971 | |
| 3972 | /* suboption header - needs additional argument for it */ |
| 3973 | if (*(args[cur_arg+1]) == 0) { |
| 3974 | Alert("parsing [%s:%d] : '%s %s %s' expects <username> as argument.\n", |
| 3975 | file, linenum, args[0], args[1], args[cur_arg]); |
| 3976 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3977 | goto out; |
| 3978 | } |
| 3979 | mysqluser = args[cur_arg + 1]; |
| 3980 | userlen = strlen(mysqluser); |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 3981 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 3982 | if (*(args[cur_arg+2])) { |
| 3983 | if (!strcmp(args[cur_arg+2], "post-41")) { |
| 3984 | packetlen = userlen + 7 + 27; |
| 3985 | reqlen = packetlen + 9; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 3986 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 3987 | free(curproxy->check_req); |
| 3988 | curproxy->check_req = (char *)calloc(1, reqlen); |
| 3989 | curproxy->check_len = reqlen; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 3990 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 3991 | snprintf(curproxy->check_req, 4, "%c%c%c", |
| 3992 | ((unsigned char) packetlen & 0xff), |
| 3993 | ((unsigned char) (packetlen >> 8) & 0xff), |
| 3994 | ((unsigned char) (packetlen >> 16) & 0xff)); |
| 3995 | |
| 3996 | curproxy->check_req[3] = 1; |
| 3997 | curproxy->check_req[5] = 130; |
| 3998 | curproxy->check_req[11] = 1; |
| 3999 | curproxy->check_req[12] = 33; |
| 4000 | memcpy(&curproxy->check_req[36], mysqluser, userlen); |
| 4001 | curproxy->check_req[36 + userlen + 1 + 1] = 1; |
| 4002 | curproxy->check_req[36 + userlen + 1 + 1 + 4] = 1; |
| 4003 | cur_arg += 3; |
| 4004 | } else { |
| 4005 | Alert("parsing [%s:%d] : keyword '%s' only supports option 'post-41'.\n", file, linenum, args[cur_arg+2]); |
| 4006 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4007 | goto out; |
| 4008 | } |
| 4009 | } else { |
| 4010 | packetlen = userlen + 7; |
| 4011 | reqlen = packetlen + 9; |
| 4012 | |
| 4013 | free(curproxy->check_req); |
| 4014 | curproxy->check_req = (char *)calloc(1, reqlen); |
| 4015 | curproxy->check_len = reqlen; |
| 4016 | |
| 4017 | snprintf(curproxy->check_req, 4, "%c%c%c", |
| 4018 | ((unsigned char) packetlen & 0xff), |
| 4019 | ((unsigned char) (packetlen >> 8) & 0xff), |
| 4020 | ((unsigned char) (packetlen >> 16) & 0xff)); |
| 4021 | |
| 4022 | curproxy->check_req[3] = 1; |
| 4023 | curproxy->check_req[5] = 128; |
| 4024 | curproxy->check_req[8] = 1; |
| 4025 | memcpy(&curproxy->check_req[9], mysqluser, userlen); |
| 4026 | curproxy->check_req[9 + userlen + 1 + 1] = 1; |
| 4027 | curproxy->check_req[9 + userlen + 1 + 1 + 4] = 1; |
| 4028 | cur_arg += 2; |
| 4029 | } |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 4030 | } else { |
| 4031 | /* unknown suboption - catchall */ |
| 4032 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'user'.\n", |
| 4033 | file, linenum, args[0], args[1]); |
| 4034 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4035 | goto out; |
| 4036 | } |
| 4037 | } /* end while loop */ |
| 4038 | } |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 4039 | } |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 4040 | else if (!strcmp(args[1], "ldap-check")) { |
| 4041 | /* use LDAP request to check servers' health */ |
| 4042 | free(curproxy->check_req); |
| 4043 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4044 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 4045 | curproxy->options2 |= PR_O2_LDAP_CHK; |
| 4046 | |
| 4047 | curproxy->check_req = (char *) malloc(sizeof(DEF_LDAP_CHECK_REQ) - 1); |
| 4048 | memcpy(curproxy->check_req, DEF_LDAP_CHECK_REQ, sizeof(DEF_LDAP_CHECK_REQ) - 1); |
| 4049 | curproxy->check_len = sizeof(DEF_LDAP_CHECK_REQ) - 1; |
| 4050 | } |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 4051 | else if (!strcmp(args[1], "tcp-check")) { |
| 4052 | /* use raw TCPCHK send/expect to check servers' health */ |
| 4053 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 4054 | err_code |= ERR_WARN; |
| 4055 | |
| 4056 | free(curproxy->check_req); |
| 4057 | curproxy->check_req = NULL; |
| 4058 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 4059 | curproxy->options2 |= PR_O2_TCPCHK_CHK; |
| 4060 | } |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 4061 | else if (!strcmp(args[1], "forwardfor")) { |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 4062 | int cur_arg; |
| 4063 | |
| 4064 | /* insert x-forwarded-for field, but not for the IP address listed as an except. |
| 4065 | * set default options (ie: bitfield, header name, etc) |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 4066 | */ |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 4067 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 4068 | curproxy->options |= PR_O_FWDFOR | PR_O_FF_ALWAYS; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 4069 | |
| 4070 | free(curproxy->fwdfor_hdr_name); |
| 4071 | curproxy->fwdfor_hdr_name = strdup(DEF_XFORWARDFOR_HDR); |
| 4072 | curproxy->fwdfor_hdr_len = strlen(DEF_XFORWARDFOR_HDR); |
| 4073 | |
| 4074 | /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */ |
| 4075 | cur_arg = 2; |
| 4076 | while (*(args[cur_arg])) { |
| 4077 | if (!strcmp(args[cur_arg], "except")) { |
| 4078 | /* suboption except - needs additional argument for it */ |
Thierry FOURNIER | fc7ac7b | 2014-02-11 15:23:04 +0100 | [diff] [blame] | 4079 | 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] | 4080 | Alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n", |
| 4081 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4082 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4083 | goto out; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 4084 | } |
| 4085 | /* flush useless bits */ |
| 4086 | curproxy->except_net.s_addr &= curproxy->except_mask.s_addr; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 4087 | cur_arg += 2; |
| 4088 | } else if (!strcmp(args[cur_arg], "header")) { |
| 4089 | /* suboption header - needs additional argument for it */ |
| 4090 | if (*(args[cur_arg+1]) == 0) { |
| 4091 | Alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 4092 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4093 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4094 | goto out; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 4095 | } |
| 4096 | free(curproxy->fwdfor_hdr_name); |
| 4097 | curproxy->fwdfor_hdr_name = strdup(args[cur_arg+1]); |
| 4098 | curproxy->fwdfor_hdr_len = strlen(curproxy->fwdfor_hdr_name); |
| 4099 | cur_arg += 2; |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 4100 | } else if (!strcmp(args[cur_arg], "if-none")) { |
| 4101 | curproxy->options &= ~PR_O_FF_ALWAYS; |
| 4102 | cur_arg += 1; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 4103 | } else { |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 4104 | /* unknown suboption - catchall */ |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 4105 | 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] | 4106 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4107 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4108 | goto out; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 4109 | } |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 4110 | } /* end while loop */ |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 4111 | } |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 4112 | else if (!strcmp(args[1], "originalto")) { |
| 4113 | int cur_arg; |
| 4114 | |
| 4115 | /* insert x-original-to field, but not for the IP address listed as an except. |
| 4116 | * set default options (ie: bitfield, header name, etc) |
| 4117 | */ |
| 4118 | |
| 4119 | curproxy->options |= PR_O_ORGTO; |
| 4120 | |
| 4121 | free(curproxy->orgto_hdr_name); |
| 4122 | curproxy->orgto_hdr_name = strdup(DEF_XORIGINALTO_HDR); |
| 4123 | curproxy->orgto_hdr_len = strlen(DEF_XORIGINALTO_HDR); |
| 4124 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 4125 | /* 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] | 4126 | cur_arg = 2; |
| 4127 | while (*(args[cur_arg])) { |
| 4128 | if (!strcmp(args[cur_arg], "except")) { |
| 4129 | /* suboption except - needs additional argument for it */ |
Thierry FOURNIER | fc7ac7b | 2014-02-11 15:23:04 +0100 | [diff] [blame] | 4130 | 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] | 4131 | Alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n", |
| 4132 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4133 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4134 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 4135 | } |
| 4136 | /* flush useless bits */ |
| 4137 | curproxy->except_to.s_addr &= curproxy->except_mask_to.s_addr; |
| 4138 | cur_arg += 2; |
| 4139 | } else if (!strcmp(args[cur_arg], "header")) { |
| 4140 | /* suboption header - needs additional argument for it */ |
| 4141 | if (*(args[cur_arg+1]) == 0) { |
| 4142 | Alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 4143 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4144 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4145 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 4146 | } |
| 4147 | free(curproxy->orgto_hdr_name); |
| 4148 | curproxy->orgto_hdr_name = strdup(args[cur_arg+1]); |
| 4149 | curproxy->orgto_hdr_len = strlen(curproxy->orgto_hdr_name); |
| 4150 | cur_arg += 2; |
| 4151 | } else { |
| 4152 | /* unknown suboption - catchall */ |
| 4153 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n", |
| 4154 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4155 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4156 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 4157 | } |
| 4158 | } /* end while loop */ |
| 4159 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4160 | else { |
| 4161 | Alert("parsing [%s:%d] : unknown option '%s'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4162 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4163 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4164 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4165 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4166 | } |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 4167 | else if (!strcmp(args[0], "default_backend")) { |
| 4168 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4169 | err_code |= ERR_WARN; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 4170 | |
| 4171 | if (*(args[1]) == 0) { |
| 4172 | 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] | 4173 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4174 | goto out; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 4175 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 4176 | free(curproxy->defbe.name); |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 4177 | curproxy->defbe.name = strdup(args[1]); |
| 4178 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4179 | else if (!strcmp(args[0], "redispatch") || !strcmp(args[0], "redisp")) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4180 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4181 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4182 | |
Willy Tarreau | a3c504c | 2014-04-28 22:37:32 +0200 | [diff] [blame] | 4183 | if (!already_warned(WARN_REDISPATCH_DEPRECATED)) |
| 4184 | 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] | 4185 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4186 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4187 | /* enable reconnections to dispatch */ |
| 4188 | curproxy->options |= PR_O_REDISP; |
| 4189 | } |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 4190 | else if (!strcmp(args[0], "http-check")) { |
| 4191 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4192 | err_code |= ERR_WARN; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 4193 | |
| 4194 | if (strcmp(args[1], "disable-on-404") == 0) { |
| 4195 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 4196 | curproxy->options |= PR_O_DISABLE404; |
| 4197 | } |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 4198 | else if (strcmp(args[1], "send-state") == 0) { |
| 4199 | /* enable emission of the apparent state of a server in HTTP checks */ |
| 4200 | curproxy->options2 |= PR_O2_CHK_SNDST; |
| 4201 | } |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 4202 | else if (strcmp(args[1], "expect") == 0) { |
| 4203 | const char *ptr_arg; |
| 4204 | int cur_arg; |
| 4205 | |
| 4206 | if (curproxy->options2 & PR_O2_EXP_TYPE) { |
| 4207 | Alert("parsing [%s:%d] : '%s %s' already specified.\n", file, linenum, args[0], args[1]); |
| 4208 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4209 | goto out; |
| 4210 | } |
| 4211 | |
| 4212 | cur_arg = 2; |
| 4213 | /* consider exclamation marks, sole or at the beginning of a word */ |
| 4214 | while (*(ptr_arg = args[cur_arg])) { |
| 4215 | while (*ptr_arg == '!') { |
| 4216 | curproxy->options2 ^= PR_O2_EXP_INV; |
| 4217 | ptr_arg++; |
| 4218 | } |
| 4219 | if (*ptr_arg) |
| 4220 | break; |
| 4221 | cur_arg++; |
| 4222 | } |
| 4223 | /* now ptr_arg points to the beginning of a word past any possible |
| 4224 | * exclamation mark, and cur_arg is the argument which holds this word. |
| 4225 | */ |
| 4226 | if (strcmp(ptr_arg, "status") == 0) { |
| 4227 | if (!*(args[cur_arg + 1])) { |
| 4228 | Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 4229 | file, linenum, args[0], args[1], ptr_arg); |
| 4230 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4231 | goto out; |
| 4232 | } |
| 4233 | curproxy->options2 |= PR_O2_EXP_STS; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 4234 | free(curproxy->expect_str); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 4235 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
| 4236 | } |
| 4237 | else if (strcmp(ptr_arg, "string") == 0) { |
| 4238 | if (!*(args[cur_arg + 1])) { |
| 4239 | Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 4240 | file, linenum, args[0], args[1], ptr_arg); |
| 4241 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4242 | goto out; |
| 4243 | } |
| 4244 | curproxy->options2 |= PR_O2_EXP_STR; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 4245 | free(curproxy->expect_str); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 4246 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
| 4247 | } |
| 4248 | else if (strcmp(ptr_arg, "rstatus") == 0) { |
| 4249 | if (!*(args[cur_arg + 1])) { |
| 4250 | Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 4251 | file, linenum, args[0], args[1], ptr_arg); |
| 4252 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4253 | goto out; |
| 4254 | } |
| 4255 | curproxy->options2 |= PR_O2_EXP_RSTS; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 4256 | free(curproxy->expect_str); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 4257 | if (curproxy->expect_regex) { |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 4258 | regex_free(curproxy->expect_regex); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 4259 | free(curproxy->expect_regex); |
| 4260 | curproxy->expect_regex = NULL; |
| 4261 | } |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 4262 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 4263 | curproxy->expect_regex = calloc(1, sizeof(*curproxy->expect_regex)); |
| 4264 | error = NULL; |
| 4265 | if (!regex_comp(args[cur_arg + 1], curproxy->expect_regex, 1, 1, &error)) { |
| 4266 | Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s': %s.\n", |
| 4267 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1], error); |
| 4268 | free(error); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 4269 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4270 | goto out; |
| 4271 | } |
| 4272 | } |
| 4273 | else if (strcmp(ptr_arg, "rstring") == 0) { |
| 4274 | if (!*(args[cur_arg + 1])) { |
| 4275 | Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 4276 | file, linenum, args[0], args[1], ptr_arg); |
| 4277 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4278 | goto out; |
| 4279 | } |
| 4280 | curproxy->options2 |= PR_O2_EXP_RSTR; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 4281 | free(curproxy->expect_str); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 4282 | if (curproxy->expect_regex) { |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 4283 | regex_free(curproxy->expect_regex); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 4284 | free(curproxy->expect_regex); |
| 4285 | curproxy->expect_regex = NULL; |
| 4286 | } |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 4287 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 4288 | curproxy->expect_regex = calloc(1, sizeof(*curproxy->expect_regex)); |
| 4289 | error = NULL; |
| 4290 | if (!regex_comp(args[cur_arg + 1], curproxy->expect_regex, 1, 1, &error)) { |
| 4291 | Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s': %s.\n", |
| 4292 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1], error); |
| 4293 | free(error); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 4294 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4295 | goto out; |
| 4296 | } |
| 4297 | } |
| 4298 | else { |
| 4299 | Alert("parsing [%s:%d] : '%s %s' only supports [!] 'status', 'string', 'rstatus', 'rstring', found '%s'.\n", |
| 4300 | file, linenum, args[0], args[1], ptr_arg); |
| 4301 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4302 | goto out; |
| 4303 | } |
| 4304 | } |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 4305 | else { |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 4306 | 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] | 4307 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4308 | goto out; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 4309 | } |
| 4310 | } |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 4311 | else if (!strcmp(args[0], "tcp-check")) { |
| 4312 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 4313 | err_code |= ERR_WARN; |
| 4314 | |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 4315 | if (strcmp(args[1], "connect") == 0) { |
| 4316 | const char *ptr_arg; |
| 4317 | int cur_arg; |
| 4318 | struct tcpcheck_rule *tcpcheck; |
| 4319 | struct list *l; |
| 4320 | |
| 4321 | /* check if first rule is also a 'connect' action */ |
| 4322 | l = (struct list *)&curproxy->tcpcheck_rules; |
| 4323 | if (l->p != l->n) { |
| 4324 | tcpcheck = (struct tcpcheck_rule *)l->n; |
| 4325 | if (tcpcheck && tcpcheck->action != TCPCHK_ACT_CONNECT) { |
| 4326 | Alert("parsing [%s:%d] : first step MUST also be a 'connect' when there is a 'connect' step in the tcp-check ruleset.\n", |
| 4327 | file, linenum); |
| 4328 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4329 | goto out; |
| 4330 | } |
| 4331 | } |
| 4332 | |
| 4333 | cur_arg = 2; |
| 4334 | tcpcheck = (struct tcpcheck_rule *)calloc(1, sizeof(*tcpcheck)); |
| 4335 | tcpcheck->action = TCPCHK_ACT_CONNECT; |
| 4336 | |
| 4337 | /* parsing each parameters to fill up the rule */ |
| 4338 | while (*(ptr_arg = args[cur_arg])) { |
| 4339 | /* tcp port */ |
| 4340 | if (strcmp(args[cur_arg], "port") == 0) { |
| 4341 | if ( (atol(args[cur_arg + 1]) > 65535) || |
| 4342 | (atol(args[cur_arg + 1]) < 1) ){ |
| 4343 | Alert("parsing [%s:%d] : '%s %s %s' expects a valid TCP port (from range 1 to 65535), got %s.\n", |
| 4344 | file, linenum, args[0], args[1], "port", args[cur_arg + 1]); |
| 4345 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4346 | goto out; |
| 4347 | } |
| 4348 | tcpcheck->port = atol(args[cur_arg + 1]); |
| 4349 | cur_arg += 2; |
| 4350 | } |
| 4351 | /* send proxy protocol */ |
| 4352 | else if (strcmp(args[cur_arg], "send-proxy") == 0) { |
| 4353 | tcpcheck->conn_opts |= TCPCHK_OPT_SEND_PROXY; |
| 4354 | cur_arg++; |
| 4355 | } |
| 4356 | #ifdef USE_OPENSSL |
| 4357 | else if (strcmp(args[cur_arg], "ssl") == 0) { |
| 4358 | curproxy->options |= PR_O_TCPCHK_SSL; |
| 4359 | tcpcheck->conn_opts |= TCPCHK_OPT_SSL; |
| 4360 | cur_arg++; |
| 4361 | } |
| 4362 | #endif /* USE_OPENSSL */ |
| 4363 | else { |
| 4364 | #ifdef USE_OPENSSL |
| 4365 | Alert("parsing [%s:%d] : '%s %s' expects 'port', 'send-proxy' or 'ssl' but got '%s' as argument.\n", |
| 4366 | #else /* USE_OPENSSL */ |
| 4367 | Alert("parsing [%s:%d] : '%s %s' expects 'port', 'send-proxy' or but got '%s' as argument.\n", |
| 4368 | #endif /* USE_OPENSSL */ |
| 4369 | file, linenum, args[0], args[1], args[cur_arg]); |
| 4370 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4371 | goto out; |
| 4372 | } |
| 4373 | |
| 4374 | } |
| 4375 | |
| 4376 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 4377 | } |
| 4378 | else if (strcmp(args[1], "send") == 0) { |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 4379 | if (! *(args[2]) ) { |
| 4380 | /* SEND string expected */ |
| 4381 | Alert("parsing [%s:%d] : '%s %s %s' expects <STRING> as argument.\n", |
| 4382 | file, linenum, args[0], args[1], args[2]); |
| 4383 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4384 | goto out; |
| 4385 | } else { |
| 4386 | struct tcpcheck_rule *tcpcheck; |
| 4387 | |
| 4388 | tcpcheck = (struct tcpcheck_rule *)calloc(1, sizeof(*tcpcheck)); |
| 4389 | |
| 4390 | tcpcheck->action = TCPCHK_ACT_SEND; |
| 4391 | tcpcheck->string_len = strlen(args[2]); |
| 4392 | tcpcheck->string = strdup(args[2]); |
| 4393 | tcpcheck->expect_regex = NULL; |
| 4394 | |
| 4395 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 4396 | } |
| 4397 | } |
| 4398 | else if (strcmp(args[1], "send-binary") == 0) { |
| 4399 | if (! *(args[2]) ) { |
| 4400 | /* SEND binary string expected */ |
| 4401 | Alert("parsing [%s:%d] : '%s %s %s' expects <BINARY STRING> as argument.\n", |
| 4402 | file, linenum, args[0], args[1], args[2]); |
| 4403 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4404 | goto out; |
| 4405 | } else { |
| 4406 | struct tcpcheck_rule *tcpcheck; |
| 4407 | char *err = NULL; |
| 4408 | |
| 4409 | tcpcheck = (struct tcpcheck_rule *)calloc(1, sizeof(*tcpcheck)); |
| 4410 | |
| 4411 | tcpcheck->action = TCPCHK_ACT_SEND; |
| 4412 | if (parse_binary(args[2], &tcpcheck->string, &tcpcheck->string_len, &err) == 0) { |
| 4413 | Alert("parsing [%s:%d] : '%s %s %s' expects <BINARY STRING> as argument, but %s\n", |
| 4414 | file, linenum, args[0], args[1], args[2], err); |
| 4415 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4416 | goto out; |
| 4417 | } |
| 4418 | tcpcheck->expect_regex = NULL; |
| 4419 | |
| 4420 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 4421 | } |
| 4422 | } |
| 4423 | else if (strcmp(args[1], "expect") == 0) { |
| 4424 | const char *ptr_arg; |
| 4425 | int cur_arg; |
| 4426 | int inverse = 0; |
| 4427 | |
| 4428 | if (curproxy->options2 & PR_O2_EXP_TYPE) { |
| 4429 | Alert("parsing [%s:%d] : '%s %s' already specified.\n", file, linenum, args[0], args[1]); |
| 4430 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4431 | goto out; |
| 4432 | } |
| 4433 | |
| 4434 | cur_arg = 2; |
| 4435 | /* consider exclamation marks, sole or at the beginning of a word */ |
| 4436 | while (*(ptr_arg = args[cur_arg])) { |
| 4437 | while (*ptr_arg == '!') { |
| 4438 | inverse = !inverse; |
| 4439 | ptr_arg++; |
| 4440 | } |
| 4441 | if (*ptr_arg) |
| 4442 | break; |
| 4443 | cur_arg++; |
| 4444 | } |
| 4445 | /* now ptr_arg points to the beginning of a word past any possible |
| 4446 | * exclamation mark, and cur_arg is the argument which holds this word. |
| 4447 | */ |
| 4448 | if (strcmp(ptr_arg, "binary") == 0) { |
| 4449 | if (!*(args[cur_arg + 1])) { |
| 4450 | Alert("parsing [%s:%d] : '%s %s %s' expects <binary string> as an argument.\n", |
| 4451 | file, linenum, args[0], args[1], ptr_arg); |
| 4452 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4453 | goto out; |
| 4454 | } |
| 4455 | struct tcpcheck_rule *tcpcheck; |
| 4456 | char *err = NULL; |
| 4457 | |
| 4458 | tcpcheck = (struct tcpcheck_rule *)calloc(1, sizeof(*tcpcheck)); |
| 4459 | |
| 4460 | tcpcheck->action = TCPCHK_ACT_EXPECT; |
| 4461 | if (parse_binary(args[cur_arg + 1], &tcpcheck->string, &tcpcheck->string_len, &err) == 0) { |
| 4462 | Alert("parsing [%s:%d] : '%s %s %s' expects <BINARY STRING> as argument, but %s\n", |
| 4463 | file, linenum, args[0], args[1], args[2], err); |
| 4464 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4465 | goto out; |
| 4466 | } |
| 4467 | tcpcheck->expect_regex = NULL; |
| 4468 | tcpcheck->inverse = inverse; |
| 4469 | |
| 4470 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 4471 | } |
| 4472 | else if (strcmp(ptr_arg, "string") == 0) { |
| 4473 | if (!*(args[cur_arg + 1])) { |
| 4474 | Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 4475 | file, linenum, args[0], args[1], ptr_arg); |
| 4476 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4477 | goto out; |
| 4478 | } |
| 4479 | struct tcpcheck_rule *tcpcheck; |
| 4480 | |
| 4481 | tcpcheck = (struct tcpcheck_rule *)calloc(1, sizeof(*tcpcheck)); |
| 4482 | |
| 4483 | tcpcheck->action = TCPCHK_ACT_EXPECT; |
| 4484 | tcpcheck->string_len = strlen(args[cur_arg + 1]); |
| 4485 | tcpcheck->string = strdup(args[cur_arg + 1]); |
| 4486 | tcpcheck->expect_regex = NULL; |
| 4487 | tcpcheck->inverse = inverse; |
| 4488 | |
| 4489 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 4490 | } |
| 4491 | else if (strcmp(ptr_arg, "rstring") == 0) { |
| 4492 | if (!*(args[cur_arg + 1])) { |
| 4493 | Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 4494 | file, linenum, args[0], args[1], ptr_arg); |
| 4495 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4496 | goto out; |
| 4497 | } |
| 4498 | struct tcpcheck_rule *tcpcheck; |
| 4499 | |
| 4500 | tcpcheck = (struct tcpcheck_rule *)calloc(1, sizeof(*tcpcheck)); |
| 4501 | |
| 4502 | tcpcheck->action = TCPCHK_ACT_EXPECT; |
| 4503 | tcpcheck->string_len = 0; |
| 4504 | tcpcheck->string = NULL; |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 4505 | tcpcheck->expect_regex = calloc(1, sizeof(*tcpcheck->expect_regex)); |
| 4506 | error = NULL; |
| 4507 | if (!regex_comp(args[cur_arg + 1], tcpcheck->expect_regex, 1, 1, &error)) { |
| 4508 | Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s': %s.\n", |
| 4509 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1], error); |
| 4510 | free(error); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 4511 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4512 | goto out; |
| 4513 | } |
| 4514 | tcpcheck->inverse = inverse; |
| 4515 | |
| 4516 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 4517 | } |
| 4518 | else { |
| 4519 | Alert("parsing [%s:%d] : '%s %s' only supports [!] 'binary', 'string', 'rstring', found '%s'.\n", |
| 4520 | file, linenum, args[0], args[1], ptr_arg); |
| 4521 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4522 | goto out; |
| 4523 | } |
| 4524 | } |
| 4525 | else { |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 4526 | 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] | 4527 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4528 | goto out; |
| 4529 | } |
| 4530 | } |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 4531 | else if (!strcmp(args[0], "monitor")) { |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 4532 | if (curproxy == &defproxy) { |
| 4533 | 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] | 4534 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4535 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 4536 | } |
| 4537 | |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 4538 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4539 | err_code |= ERR_WARN; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 4540 | |
| 4541 | if (strcmp(args[1], "fail") == 0) { |
| 4542 | /* add a condition to fail monitor requests */ |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 4543 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 4544 | Alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n", |
| 4545 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4546 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4547 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 4548 | } |
| 4549 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 4550 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 4551 | Alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition : %s.\n", |
| 4552 | file, linenum, args[0], args[1], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4553 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4554 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 4555 | } |
| 4556 | LIST_ADDQ(&curproxy->mon_fail_cond, &cond->list); |
| 4557 | } |
| 4558 | else { |
| 4559 | 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] | 4560 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4561 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 4562 | } |
| 4563 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4564 | #ifdef TPROXY |
| 4565 | else if (!strcmp(args[0], "transparent")) { |
| 4566 | /* enable transparent proxy connections */ |
| 4567 | curproxy->options |= PR_O_TRANSP; |
| 4568 | } |
| 4569 | #endif |
| 4570 | else if (!strcmp(args[0], "maxconn")) { /* maxconn */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4571 | 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] | 4572 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4573 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4574 | if (*(args[1]) == 0) { |
| 4575 | 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] | 4576 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4577 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4578 | } |
| 4579 | curproxy->maxconn = atol(args[1]); |
| 4580 | } |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 4581 | else if (!strcmp(args[0], "backlog")) { /* backlog */ |
| 4582 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4583 | err_code |= ERR_WARN; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 4584 | |
| 4585 | if (*(args[1]) == 0) { |
| 4586 | 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] | 4587 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4588 | goto out; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 4589 | } |
| 4590 | curproxy->backlog = atol(args[1]); |
| 4591 | } |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 4592 | else if (!strcmp(args[0], "fullconn")) { /* fullconn */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4593 | 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] | 4594 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4595 | |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 4596 | if (*(args[1]) == 0) { |
| 4597 | 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] | 4598 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4599 | goto out; |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 4600 | } |
| 4601 | curproxy->fullconn = atol(args[1]); |
| 4602 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4603 | else if (!strcmp(args[0], "grace")) { /* grace time (ms) */ |
| 4604 | if (*(args[1]) == 0) { |
| 4605 | 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] | 4606 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4607 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4608 | } |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4609 | err = parse_time_err(args[1], &val, TIME_UNIT_MS); |
| 4610 | if (err) { |
| 4611 | Alert("parsing [%s:%d] : unexpected character '%c' in grace time.\n", |
| 4612 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4613 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4614 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4615 | } |
| 4616 | curproxy->grace = val; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4617 | } |
| 4618 | else if (!strcmp(args[0], "dispatch")) { /* dispatch address */ |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4619 | struct sockaddr_storage *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4620 | int port1, port2; |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 4621 | struct protocol *proto; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4622 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4623 | if (curproxy == &defproxy) { |
| 4624 | 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] | 4625 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4626 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4627 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4628 | else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4629 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4630 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 4631 | sk = str2sa_range(args[1], &port1, &port2, &errmsg, NULL); |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4632 | if (!sk) { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 4633 | Alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 4634 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 4635 | goto out; |
| 4636 | } |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 4637 | |
| 4638 | proto = protocol_by_family(sk->ss_family); |
| 4639 | if (!proto || !proto->connect) { |
| 4640 | Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 4641 | file, linenum, args[0], args[1]); |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4642 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4643 | goto out; |
| 4644 | } |
| 4645 | |
| 4646 | if (port1 != port2) { |
| 4647 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'.\n", |
| 4648 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4649 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4650 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4651 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4652 | |
| 4653 | if (!port1) { |
| 4654 | Alert("parsing [%s:%d] : '%s' : missing port number in '%s', <addr:port> expected.\n", |
| 4655 | file, linenum, args[0], args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4656 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4657 | goto out; |
| 4658 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4659 | |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4660 | curproxy->dispatch_addr = *sk; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4661 | curproxy->options |= PR_O_DISPATCH; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4662 | } |
| 4663 | else if (!strcmp(args[0], "balance")) { /* set balancing with optional algorithm */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4664 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4665 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4666 | |
Willy Tarreau | a93c74b | 2012-05-08 18:14:39 +0200 | [diff] [blame] | 4667 | if (backend_parse_balance((const char **)args + 1, &errmsg, curproxy) < 0) { |
| 4668 | Alert("parsing [%s:%d] : %s %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4669 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4670 | goto out; |
Willy Tarreau | 2fcb500 | 2007-05-08 13:35:26 +0200 | [diff] [blame] | 4671 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4672 | } |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 4673 | else if (!strcmp(args[0], "hash-type")) { /* set hashing method */ |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 4674 | /** |
| 4675 | * The syntax for hash-type config element is |
| 4676 | * hash-type {map-based|consistent} [[<algo>] avalanche] |
| 4677 | * |
| 4678 | * The default hash function is sdbm for map-based and sdbm+avalanche for consistent. |
| 4679 | */ |
| 4680 | 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] | 4681 | |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 4682 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 4683 | err_code |= ERR_WARN; |
| 4684 | |
| 4685 | if (strcmp(args[1], "consistent") == 0) { /* use consistent hashing */ |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 4686 | curproxy->lbprm.algo |= BE_LB_HASH_CONS; |
| 4687 | } |
| 4688 | else if (strcmp(args[1], "map-based") == 0) { /* use map-based hashing */ |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 4689 | curproxy->lbprm.algo |= BE_LB_HASH_MAP; |
| 4690 | } |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 4691 | else if (strcmp(args[1], "avalanche") == 0) { |
| 4692 | 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]); |
| 4693 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4694 | goto out; |
Willy Tarreau | 798a39c | 2010-11-24 15:04:29 +0100 | [diff] [blame] | 4695 | } |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 4696 | else { |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 4697 | 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] | 4698 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4699 | goto out; |
| 4700 | } |
Bhaskar | 98634f0 | 2013-10-29 23:30:51 -0400 | [diff] [blame] | 4701 | |
| 4702 | /* set the hash function to use */ |
| 4703 | if (!*args[2]) { |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 4704 | /* the default algo is sdbm */ |
Bhaskar | 98634f0 | 2013-10-29 23:30:51 -0400 | [diff] [blame] | 4705 | curproxy->lbprm.algo |= BE_LB_HFCN_SDBM; |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 4706 | |
| 4707 | /* if consistent with no argument, then avalanche modifier is also applied */ |
| 4708 | if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS) |
| 4709 | curproxy->lbprm.algo |= BE_LB_HMOD_AVAL; |
Bhaskar | 98634f0 | 2013-10-29 23:30:51 -0400 | [diff] [blame] | 4710 | } else { |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 4711 | /* set the hash function */ |
| 4712 | if (!strcmp(args[2], "sdbm")) { |
| 4713 | curproxy->lbprm.algo |= BE_LB_HFCN_SDBM; |
| 4714 | } |
| 4715 | else if (!strcmp(args[2], "djb2")) { |
| 4716 | curproxy->lbprm.algo |= BE_LB_HFCN_DJB2; |
Willy Tarreau | a0f4271 | 2013-11-14 14:30:35 +0100 | [diff] [blame] | 4717 | } else if (!strcmp(args[2], "wt6")) { |
| 4718 | curproxy->lbprm.algo |= BE_LB_HFCN_WT6; |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 4719 | } |
| 4720 | else { |
Willy Tarreau | a0f4271 | 2013-11-14 14:30:35 +0100 | [diff] [blame] | 4721 | 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] | 4722 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4723 | goto out; |
| 4724 | } |
| 4725 | |
| 4726 | /* set the hash modifier */ |
| 4727 | if (!strcmp(args[3], "avalanche")) { |
| 4728 | curproxy->lbprm.algo |= BE_LB_HMOD_AVAL; |
| 4729 | } |
| 4730 | else if (*args[3]) { |
| 4731 | Alert("parsing [%s:%d] : '%s' only supports 'avalanche' as a modifier for hash functions.\n", file, linenum, args[0]); |
| 4732 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4733 | goto out; |
| 4734 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4735 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 4736 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 4737 | else if (strcmp(args[0], "unique-id-format") == 0) { |
| 4738 | if (!*(args[1])) { |
| 4739 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 4740 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4741 | goto out; |
| 4742 | } |
William Lallemand | 3203ff4 | 2012-11-11 17:30:56 +0100 | [diff] [blame] | 4743 | if (*(args[2])) { |
| 4744 | Alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]); |
| 4745 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4746 | goto out; |
| 4747 | } |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 4748 | free(curproxy->conf.uniqueid_format_string); |
| 4749 | curproxy->conf.uniqueid_format_string = strdup(args[1]); |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 4750 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 4751 | free(curproxy->conf.uif_file); |
| 4752 | curproxy->conf.uif_file = strdup(curproxy->conf.args.file); |
| 4753 | curproxy->conf.uif_line = curproxy->conf.args.line; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4754 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 4755 | |
| 4756 | else if (strcmp(args[0], "unique-id-header") == 0) { |
| 4757 | if (!*(args[1])) { |
| 4758 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 4759 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4760 | goto out; |
| 4761 | } |
| 4762 | free(curproxy->header_unique_id); |
| 4763 | curproxy->header_unique_id = strdup(args[1]); |
| 4764 | } |
| 4765 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4766 | else if (strcmp(args[0], "log-format") == 0) { |
| 4767 | if (!*(args[1])) { |
| 4768 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 4769 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4770 | goto out; |
| 4771 | } |
William Lallemand | 3203ff4 | 2012-11-11 17:30:56 +0100 | [diff] [blame] | 4772 | if (*(args[2])) { |
| 4773 | Alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]); |
| 4774 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4775 | goto out; |
| 4776 | } |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 4777 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 4778 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 4779 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 4780 | curproxy->conf.logformat_string != clf_http_log_format) |
| 4781 | free(curproxy->conf.logformat_string); |
| 4782 | curproxy->conf.logformat_string = strdup(args[1]); |
| 4783 | |
| 4784 | free(curproxy->conf.lfs_file); |
| 4785 | curproxy->conf.lfs_file = strdup(curproxy->conf.args.file); |
| 4786 | curproxy->conf.lfs_line = curproxy->conf.args.line; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 4787 | |
| 4788 | /* get a chance to improve log-format error reporting by |
| 4789 | * reporting the correct line-number when possible. |
| 4790 | */ |
| 4791 | if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) { |
| 4792 | Warning("parsing [%s:%d] : backend '%s' : 'log-format' directive is ignored in backends.\n", |
| 4793 | file, linenum, curproxy->id); |
| 4794 | err_code |= ERR_WARN; |
| 4795 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4796 | } |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4797 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4798 | else if (!strcmp(args[0], "log") && kwm == KWM_NO) { |
| 4799 | /* delete previous herited or defined syslog servers */ |
| 4800 | struct logsrv *back; |
| 4801 | |
| 4802 | if (*(args[1]) != 0) { |
| 4803 | Alert("parsing [%s:%d]:%s : 'no log' does not expect arguments.\n", file, linenum, args[1]); |
| 4804 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4805 | goto out; |
| 4806 | } |
| 4807 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4808 | list_for_each_entry_safe(tmplogsrv, back, &curproxy->logsrvs, list) { |
| 4809 | LIST_DEL(&tmplogsrv->list); |
| 4810 | free(tmplogsrv); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4811 | } |
| 4812 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4813 | else if (!strcmp(args[0], "log")) { /* syslog server address */ |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4814 | struct logsrv *logsrv; |
| 4815 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4816 | if (*(args[1]) && *(args[2]) == 0 && !strcmp(args[1], "global")) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4817 | /* copy global.logrsvs linked list to the end of curproxy->logsrvs */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4818 | list_for_each_entry(tmplogsrv, &global.logsrvs, list) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4819 | struct logsrv *node = malloc(sizeof(struct logsrv)); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4820 | memcpy(node, tmplogsrv, sizeof(struct logsrv)); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4821 | LIST_INIT(&node->list); |
| 4822 | LIST_ADDQ(&curproxy->logsrvs, &node->list); |
| 4823 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4824 | } |
| 4825 | else if (*(args[1]) && *(args[2])) { |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 4826 | struct sockaddr_storage *sk; |
| 4827 | int port1, port2; |
Willy Tarreau | dc2695c | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 4828 | int arg = 0; |
| 4829 | int len = 0; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4830 | |
| 4831 | logsrv = calloc(1, sizeof(struct logsrv)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4832 | |
Willy Tarreau | dc2695c | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 4833 | /* just after the address, a length may be specified */ |
| 4834 | if (strcmp(args[arg+2], "len") == 0) { |
| 4835 | len = atoi(args[arg+3]); |
| 4836 | if (len < 80 || len > 65535) { |
| 4837 | Alert("parsing [%s:%d] : invalid log length '%s', must be between 80 and 65535.\n", |
| 4838 | file, linenum, args[arg+3]); |
| 4839 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4840 | goto out; |
| 4841 | } |
| 4842 | logsrv->maxlen = len; |
| 4843 | |
| 4844 | /* skip these two args */ |
| 4845 | arg += 2; |
| 4846 | } |
| 4847 | else |
| 4848 | logsrv->maxlen = MAX_SYSLOG_LEN; |
| 4849 | |
| 4850 | if (logsrv->maxlen > global.max_syslog_len) { |
| 4851 | global.max_syslog_len = logsrv->maxlen; |
| 4852 | logline = realloc(logline, global.max_syslog_len + 1); |
| 4853 | } |
| 4854 | |
| 4855 | logsrv->facility = get_log_facility(args[arg+2]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4856 | if (logsrv->facility < 0) { |
Willy Tarreau | dc2695c | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 4857 | 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] | 4858 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4859 | goto out; |
| 4860 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4861 | } |
| 4862 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4863 | logsrv->level = 7; /* max syslog level = debug */ |
Willy Tarreau | dc2695c | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 4864 | if (*(args[arg+3])) { |
| 4865 | logsrv->level = get_log_level(args[arg+3]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4866 | if (logsrv->level < 0) { |
Willy Tarreau | dc2695c | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 4867 | 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] | 4868 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4869 | goto out; |
| 4870 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4871 | } |
| 4872 | } |
| 4873 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4874 | logsrv->minlvl = 0; /* limit syslog level to this level (emerg) */ |
Willy Tarreau | dc2695c | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 4875 | if (*(args[arg+4])) { |
| 4876 | logsrv->minlvl = get_log_level(args[arg+4]); |
Willy Tarreau | f7f057b | 2013-01-24 00:31:24 +0100 | [diff] [blame] | 4877 | if (logsrv->minlvl < 0) { |
Willy Tarreau | dc2695c | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 4878 | 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] | 4879 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4880 | goto out; |
| 4881 | |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 4882 | } |
| 4883 | } |
| 4884 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 4885 | sk = str2sa_range(args[1], &port1, &port2, &errmsg, NULL); |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 4886 | if (!sk) { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 4887 | Alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 4888 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 4889 | goto out; |
| 4890 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4891 | |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 4892 | logsrv->addr = *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4893 | |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 4894 | if (sk->ss_family == AF_INET || sk->ss_family == AF_INET6) { |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4895 | if (port1 != port2) { |
| 4896 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 4897 | file, linenum, args[0], args[1]); |
| 4898 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4899 | goto out; |
| 4900 | } |
| 4901 | |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4902 | if (!port1) |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4903 | set_host_port(&logsrv->addr, SYSLOG_PORT); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4904 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4905 | |
| 4906 | LIST_ADDQ(&curproxy->logsrvs, &logsrv->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4907 | } |
| 4908 | else { |
| 4909 | Alert("parsing [%s:%d] : 'log' expects either <address[:port]> and <facility> or 'global' as arguments.\n", |
| 4910 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4911 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4912 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4913 | } |
| 4914 | } |
| 4915 | 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] | 4916 | int cur_arg; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4917 | int port1, port2; |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4918 | struct sockaddr_storage *sk; |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 4919 | struct protocol *proto; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4920 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4921 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4922 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4923 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4924 | if (!*args[1]) { |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4925 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optionally '%s' <addr>, and '%s' <name>.\n", |
| 4926 | file, linenum, "source", "usesrc", "interface"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4927 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4928 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4929 | } |
Willy Tarreau | 368480c | 2009-03-01 08:27:21 +0100 | [diff] [blame] | 4930 | |
| 4931 | /* we must first clear any optional default setting */ |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4932 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 4933 | free(curproxy->conn_src.iface_name); |
| 4934 | curproxy->conn_src.iface_name = NULL; |
| 4935 | curproxy->conn_src.iface_len = 0; |
Willy Tarreau | 368480c | 2009-03-01 08:27:21 +0100 | [diff] [blame] | 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 | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4938 | if (!sk) { |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 4939 | Alert("parsing [%s:%d] : '%s %s' : %s\n", |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 4940 | file, linenum, args[0], args[1], errmsg); |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 4941 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 4942 | goto out; |
| 4943 | } |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 4944 | |
| 4945 | proto = protocol_by_family(sk->ss_family); |
| 4946 | if (!proto || !proto->connect) { |
| 4947 | 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] | 4948 | file, linenum, args[0], args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4949 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4950 | goto out; |
| 4951 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4952 | |
| 4953 | if (port1 != port2) { |
| 4954 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 4955 | file, linenum, args[0], args[1]); |
| 4956 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4957 | goto out; |
| 4958 | } |
| 4959 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4960 | curproxy->conn_src.source_addr = *sk; |
| 4961 | curproxy->conn_src.opts |= CO_SRC_BIND; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4962 | |
| 4963 | cur_arg = 2; |
| 4964 | while (*(args[cur_arg])) { |
| 4965 | if (!strcmp(args[cur_arg], "usesrc")) { /* address to use outside */ |
Pieter Baauw | d551fb5 | 2013-05-08 22:49:23 +0200 | [diff] [blame] | 4966 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_TRANSPARENT) |
| 4967 | #if !defined(CONFIG_HAP_TRANSPARENT) |
Willy Tarreau | 9cf8d3f | 2014-05-09 22:56:10 +0200 | [diff] [blame] | 4968 | if (!is_inet_addr(&curproxy->conn_src.source_addr)) { |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4969 | Alert("parsing [%s:%d] : '%s' requires an explicit 'source' address.\n", |
| 4970 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4971 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4972 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4973 | } |
| 4974 | #endif |
| 4975 | if (!*args[cur_arg + 1]) { |
| 4976 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n", |
| 4977 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4978 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4979 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4980 | } |
| 4981 | |
| 4982 | if (!strcmp(args[cur_arg + 1], "client")) { |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4983 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 4984 | curproxy->conn_src.opts |= CO_SRC_TPROXY_CLI; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4985 | } else if (!strcmp(args[cur_arg + 1], "clientip")) { |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4986 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 4987 | curproxy->conn_src.opts |= CO_SRC_TPROXY_CIP; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4988 | } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) { |
| 4989 | char *name, *end; |
| 4990 | |
| 4991 | name = args[cur_arg+1] + 7; |
| 4992 | while (isspace(*name)) |
| 4993 | name++; |
| 4994 | |
| 4995 | end = name; |
| 4996 | while (*end && !isspace(*end) && *end != ',' && *end != ')') |
| 4997 | end++; |
| 4998 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4999 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 5000 | curproxy->conn_src.opts |= CO_SRC_TPROXY_DYN; |
| 5001 | curproxy->conn_src.bind_hdr_name = calloc(1, end - name + 1); |
| 5002 | curproxy->conn_src.bind_hdr_len = end - name; |
| 5003 | memcpy(curproxy->conn_src.bind_hdr_name, name, end - name); |
| 5004 | curproxy->conn_src.bind_hdr_name[end-name] = '\0'; |
| 5005 | curproxy->conn_src.bind_hdr_occ = -1; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 5006 | |
| 5007 | /* now look for an occurrence number */ |
| 5008 | while (isspace(*end)) |
| 5009 | end++; |
| 5010 | if (*end == ',') { |
| 5011 | end++; |
| 5012 | name = end; |
| 5013 | if (*end == '-') |
| 5014 | end++; |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 5015 | while (isdigit((int)*end)) |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 5016 | end++; |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 5017 | curproxy->conn_src.bind_hdr_occ = strl2ic(name, end-name); |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 5018 | } |
| 5019 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 5020 | if (curproxy->conn_src.bind_hdr_occ < -MAX_HDR_HISTORY) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 5021 | Alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative" |
| 5022 | " occurrences values smaller than %d.\n", |
| 5023 | file, linenum, MAX_HDR_HISTORY); |
| 5024 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5025 | goto out; |
| 5026 | } |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5027 | } else { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 5028 | struct sockaddr_storage *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5029 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 5030 | sk = str2sa_range(args[cur_arg + 1], &port1, &port2, &errmsg, NULL); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 5031 | if (!sk) { |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 5032 | Alert("parsing [%s:%d] : '%s %s' : %s\n", |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 5033 | file, linenum, args[cur_arg], args[cur_arg+1], errmsg); |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 5034 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 5035 | goto out; |
| 5036 | } |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 5037 | |
| 5038 | proto = protocol_by_family(sk->ss_family); |
| 5039 | if (!proto || !proto->connect) { |
| 5040 | Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 5041 | file, linenum, args[cur_arg], args[cur_arg+1]); |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5042 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5043 | goto out; |
| 5044 | } |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 5045 | |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5046 | if (port1 != port2) { |
| 5047 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 5048 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 5049 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5050 | goto out; |
| 5051 | } |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 5052 | curproxy->conn_src.tproxy_addr = *sk; |
| 5053 | curproxy->conn_src.opts |= CO_SRC_TPROXY_ADDR; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5054 | } |
| 5055 | global.last_checks |= LSTCHK_NETADM; |
Pieter Baauw | d551fb5 | 2013-05-08 22:49:23 +0200 | [diff] [blame] | 5056 | #if !defined(CONFIG_HAP_TRANSPARENT) |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5057 | global.last_checks |= LSTCHK_CTTPROXY; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 5058 | #endif |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5059 | #else /* no TPROXY support */ |
| 5060 | 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] | 5061 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5062 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5063 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5064 | #endif |
| 5065 | cur_arg += 2; |
| 5066 | continue; |
Willy Tarreau | 77074d5 | 2006-11-12 23:57:19 +0100 | [diff] [blame] | 5067 | } |
| 5068 | |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5069 | if (!strcmp(args[cur_arg], "interface")) { /* specifically bind to this interface */ |
| 5070 | #ifdef SO_BINDTODEVICE |
| 5071 | if (!*args[cur_arg + 1]) { |
| 5072 | Alert("parsing [%s:%d] : '%s' : missing interface name.\n", |
| 5073 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5074 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5075 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5076 | } |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 5077 | free(curproxy->conn_src.iface_name); |
| 5078 | curproxy->conn_src.iface_name = strdup(args[cur_arg + 1]); |
| 5079 | curproxy->conn_src.iface_len = strlen(curproxy->conn_src.iface_name); |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5080 | global.last_checks |= LSTCHK_NETADM; |
| 5081 | #else |
| 5082 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 5083 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5084 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5085 | goto out; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 5086 | #endif |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5087 | cur_arg += 2; |
| 5088 | continue; |
| 5089 | } |
| 5090 | 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] | 5091 | file, linenum, args[0], "interface", "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5092 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5093 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 5094 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5095 | } |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 5096 | else if (!strcmp(args[0], "usesrc")) { /* address to use outside: needs "source" first */ |
| 5097 | Alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n", |
| 5098 | file, linenum, "usesrc", "source"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5099 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5100 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 5101 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5102 | 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] | 5103 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5104 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 5105 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5106 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5107 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5108 | } |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5109 | |
| 5110 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5111 | SMP_OPT_DIR_REQ, ACT_REPLACE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5112 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5113 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5114 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5115 | } |
| 5116 | else if (!strcmp(args[0], "reqdel")) { /* delete request header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5117 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5118 | SMP_OPT_DIR_REQ, ACT_REMOVE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5119 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5120 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5121 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5122 | } |
| 5123 | 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] | 5124 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5125 | SMP_OPT_DIR_REQ, ACT_DENY, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5126 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5127 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5128 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5129 | } |
| 5130 | 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] | 5131 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5132 | SMP_OPT_DIR_REQ, ACT_PASS, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5133 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5134 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5135 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5136 | } |
| 5137 | 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] | 5138 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5139 | SMP_OPT_DIR_REQ, ACT_ALLOW, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5140 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5141 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5142 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5143 | } |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 5144 | 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] | 5145 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5146 | SMP_OPT_DIR_REQ, ACT_TARPIT, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5147 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5148 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5149 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 5150 | } |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5151 | 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] | 5152 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5153 | SMP_OPT_DIR_REQ, ACT_SETBE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5154 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5155 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5156 | goto out; |
Willy Tarreau | 40bac83 | 2014-04-28 22:37:06 +0200 | [diff] [blame] | 5157 | |
| 5158 | if (!already_warned(WARN_REQSETBE_DEPRECATED)) |
| 5159 | 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] | 5160 | } |
| 5161 | 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] | 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_SETBE, REG_ICASE, |
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 | 40bac83 | 2014-04-28 22:37:06 +0200 | [diff] [blame] | 5167 | |
| 5168 | if (!already_warned(WARN_REQSETBE_DEPRECATED)) |
| 5169 | 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] | 5170 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5171 | 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] | 5172 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5173 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 5174 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5175 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5176 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5177 | } |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5178 | |
| 5179 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5180 | SMP_OPT_DIR_REQ, ACT_REPLACE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5181 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5182 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5183 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5184 | } |
| 5185 | 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] | 5186 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5187 | SMP_OPT_DIR_REQ, ACT_REMOVE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5188 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5189 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5190 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5191 | } |
| 5192 | 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] | 5193 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5194 | SMP_OPT_DIR_REQ, ACT_DENY, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5195 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5196 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5197 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5198 | } |
| 5199 | 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] | 5200 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5201 | SMP_OPT_DIR_REQ, ACT_PASS, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5202 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5203 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5204 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5205 | } |
| 5206 | 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] | 5207 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5208 | SMP_OPT_DIR_REQ, ACT_ALLOW, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5209 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5210 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5211 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5212 | } |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 5213 | 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] | 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_TARPIT, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5216 | args[0], args[1], NULL, (const char **)args+2); |
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 | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 5219 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5220 | else if (!strcmp(args[0], "reqadd")) { /* add request header */ |
Willy Tarreau | f4f0412 | 2010-01-28 18:10:50 +0100 | [diff] [blame] | 5221 | struct cond_wordlist *wl; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5222 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5223 | if (curproxy == &defproxy) { |
| 5224 | 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] | 5225 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5226 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5227 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5228 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5229 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5230 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5231 | if (*(args[1]) == 0) { |
| 5232 | 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] | 5233 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5234 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5235 | } |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5236 | |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 5237 | if ((strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0)) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 5238 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args+2, &errmsg)) == NULL) { |
| 5239 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 5240 | file, linenum, args[0], errmsg); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 5241 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5242 | goto out; |
| 5243 | } |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 5244 | err_code |= warnif_cond_conflicts(cond, |
| 5245 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 5246 | file, linenum); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 5247 | } |
| 5248 | else if (*args[2]) { |
| 5249 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 5250 | file, linenum, args[0], args[2]); |
| 5251 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5252 | goto out; |
| 5253 | } |
| 5254 | |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5255 | wl = calloc(1, sizeof(*wl)); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 5256 | wl->cond = cond; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5257 | wl->s = strdup(args[1]); |
| 5258 | LIST_ADDQ(&curproxy->req_add, &wl->list); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 5259 | warnif_misplaced_reqadd(curproxy, file, linenum, args[0]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5260 | } |
| 5261 | 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] | 5262 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5263 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 5264 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5265 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5266 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5267 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5268 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5269 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5270 | SMP_OPT_DIR_RES, ACT_REPLACE, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5271 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5272 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5273 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5274 | } |
| 5275 | else if (!strcmp(args[0], "rspdel")) { /* delete response header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5276 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5277 | SMP_OPT_DIR_RES, ACT_REMOVE, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5278 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5279 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5280 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5281 | } |
| 5282 | else if (!strcmp(args[0], "rspdeny")) { /* block response header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5283 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5284 | SMP_OPT_DIR_RES, ACT_DENY, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5285 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5286 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5287 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5288 | } |
| 5289 | 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] | 5290 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5291 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 5292 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5293 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5294 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5295 | } |
| 5296 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5297 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5298 | SMP_OPT_DIR_RES, ACT_REPLACE, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5299 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5300 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5301 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5302 | } |
| 5303 | 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] | 5304 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5305 | SMP_OPT_DIR_RES, ACT_REMOVE, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5306 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5307 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5308 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5309 | } |
| 5310 | 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] | 5311 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5312 | SMP_OPT_DIR_RES, ACT_DENY, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5313 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5314 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5315 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5316 | } |
| 5317 | else if (!strcmp(args[0], "rspadd")) { /* add response header */ |
Willy Tarreau | f4f0412 | 2010-01-28 18:10:50 +0100 | [diff] [blame] | 5318 | struct cond_wordlist *wl; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5319 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5320 | if (curproxy == &defproxy) { |
| 5321 | 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] | 5322 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5323 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5324 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5325 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5326 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5327 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5328 | if (*(args[1]) == 0) { |
| 5329 | 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] | 5330 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5331 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5332 | } |
| 5333 | |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5334 | if ((strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0)) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 5335 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args+2, &errmsg)) == NULL) { |
| 5336 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 5337 | file, linenum, args[0], errmsg); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5338 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5339 | goto out; |
| 5340 | } |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 5341 | err_code |= warnif_cond_conflicts(cond, |
| 5342 | (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR, |
| 5343 | file, linenum); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5344 | } |
| 5345 | else if (*args[2]) { |
| 5346 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 5347 | file, linenum, args[0], args[2]); |
| 5348 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5349 | goto out; |
| 5350 | } |
| 5351 | |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5352 | wl = calloc(1, sizeof(*wl)); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5353 | wl->cond = cond; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5354 | wl->s = strdup(args[1]); |
| 5355 | LIST_ADDQ(&curproxy->rsp_add, &wl->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5356 | } |
| 5357 | else if (!strcmp(args[0], "errorloc") || |
| 5358 | !strcmp(args[0], "errorloc302") || |
| 5359 | !strcmp(args[0], "errorloc303")) { /* error location */ |
| 5360 | int errnum, errlen; |
| 5361 | char *err; |
| 5362 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5363 | 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] | 5364 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5365 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5366 | if (*(args[2]) == 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 5367 | 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] | 5368 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5369 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5370 | } |
| 5371 | |
| 5372 | errnum = atol(args[1]); |
| 5373 | if (!strcmp(args[0], "errorloc303")) { |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 5374 | errlen = strlen(HTTP_303) + strlen(args[2]) + 5; |
| 5375 | err = malloc(errlen); |
| 5376 | 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] | 5377 | } else { |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 5378 | errlen = strlen(HTTP_302) + strlen(args[2]) + 5; |
| 5379 | err = malloc(errlen); |
| 5380 | 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] | 5381 | } |
| 5382 | |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 5383 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) { |
| 5384 | if (http_err_codes[rc] == errnum) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 5385 | chunk_destroy(&curproxy->errmsg[rc]); |
| 5386 | chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 5387 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5388 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5389 | } |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 5390 | |
| 5391 | if (rc >= HTTP_ERR_SIZE) { |
| 5392 | Warning("parsing [%s:%d] : status code %d not handled, error relocation will be ignored.\n", |
| 5393 | file, linenum, errnum); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5394 | free(err); |
| 5395 | } |
| 5396 | } |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5397 | else if (!strcmp(args[0], "errorfile")) { /* error message from a file */ |
| 5398 | int errnum, errlen, fd; |
| 5399 | char *err; |
| 5400 | struct stat stat; |
| 5401 | |
| 5402 | 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] | 5403 | err_code |= ERR_WARN; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5404 | |
| 5405 | if (*(args[2]) == 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 5406 | 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] | 5407 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5408 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5409 | } |
| 5410 | |
| 5411 | fd = open(args[2], O_RDONLY); |
| 5412 | if ((fd < 0) || (fstat(fd, &stat) < 0)) { |
| 5413 | Alert("parsing [%s:%d] : error opening file <%s> for custom error message <%s>.\n", |
| 5414 | file, linenum, args[2], args[1]); |
| 5415 | if (fd >= 0) |
| 5416 | close(fd); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5417 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5418 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5419 | } |
| 5420 | |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 5421 | if (stat.st_size <= global.tune.bufsize) { |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5422 | errlen = stat.st_size; |
| 5423 | } else { |
| 5424 | 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] | 5425 | file, linenum, args[2], global.tune.bufsize); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5426 | err_code |= ERR_WARN; |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 5427 | errlen = global.tune.bufsize; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5428 | } |
| 5429 | |
| 5430 | err = malloc(errlen); /* malloc() must succeed during parsing */ |
| 5431 | errnum = read(fd, err, errlen); |
| 5432 | if (errnum != errlen) { |
| 5433 | Alert("parsing [%s:%d] : error reading file <%s> for custom error message <%s>.\n", |
| 5434 | file, linenum, args[2], args[1]); |
| 5435 | close(fd); |
| 5436 | free(err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5437 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5438 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5439 | } |
| 5440 | close(fd); |
| 5441 | |
| 5442 | errnum = atol(args[1]); |
| 5443 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) { |
| 5444 | if (http_err_codes[rc] == errnum) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 5445 | chunk_destroy(&curproxy->errmsg[rc]); |
| 5446 | chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen); |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5447 | break; |
| 5448 | } |
| 5449 | } |
| 5450 | |
| 5451 | if (rc >= HTTP_ERR_SIZE) { |
| 5452 | Warning("parsing [%s:%d] : status code %d not handled, error customization will be ignored.\n", |
| 5453 | file, linenum, errnum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5454 | err_code |= ERR_WARN; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5455 | free(err); |
| 5456 | } |
| 5457 | } |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5458 | else if (!strcmp(args[0], "compression")) { |
| 5459 | struct comp *comp; |
| 5460 | if (curproxy->comp == NULL) { |
| 5461 | comp = calloc(1, sizeof(struct comp)); |
| 5462 | curproxy->comp = comp; |
| 5463 | } else { |
| 5464 | comp = curproxy->comp; |
| 5465 | } |
| 5466 | |
| 5467 | if (!strcmp(args[1], "algo")) { |
| 5468 | int cur_arg; |
William Lallemand | 8b52bb3 | 2012-11-16 18:06:41 +0100 | [diff] [blame] | 5469 | struct comp_ctx *ctx; |
William Lallemand | 552df67 | 2012-11-07 13:21:47 +0100 | [diff] [blame] | 5470 | |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5471 | cur_arg = 2; |
| 5472 | if (!*args[cur_arg]) { |
| 5473 | Alert("parsing [%s:%d] : '%s' expects <algorithm>\n", |
| 5474 | file, linenum, args[0]); |
| 5475 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5476 | goto out; |
| 5477 | } |
| 5478 | while (*(args[cur_arg])) { |
| 5479 | if (comp_append_algo(comp, args[cur_arg]) < 0) { |
| 5480 | Alert("parsing [%s:%d] : '%s' : '%s' is not a supported algorithm.\n", |
| 5481 | file, linenum, args[0], args[cur_arg]); |
| 5482 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5483 | goto out; |
| 5484 | } |
William Lallemand | 552df67 | 2012-11-07 13:21:47 +0100 | [diff] [blame] | 5485 | if (curproxy->comp->algos->init(&ctx, 9) == 0) { |
| 5486 | curproxy->comp->algos->end(&ctx); |
| 5487 | } else { |
| 5488 | Alert("parsing [%s:%d] : '%s' : Can't init '%s' algorithm.\n", |
| 5489 | file, linenum, args[0], args[cur_arg]); |
| 5490 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5491 | goto out; |
| 5492 | } |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5493 | cur_arg ++; |
| 5494 | continue; |
| 5495 | } |
| 5496 | } |
Willy Tarreau | 70737d1 | 2012-10-27 00:34:28 +0200 | [diff] [blame] | 5497 | else if (!strcmp(args[1], "offload")) { |
| 5498 | comp->offload = 1; |
| 5499 | } |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5500 | else if (!strcmp(args[1], "type")) { |
| 5501 | int cur_arg; |
| 5502 | cur_arg = 2; |
| 5503 | if (!*args[cur_arg]) { |
| 5504 | Alert("parsing [%s:%d] : '%s' expects <type>\n", |
| 5505 | file, linenum, args[0]); |
| 5506 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5507 | goto out; |
| 5508 | } |
| 5509 | while (*(args[cur_arg])) { |
| 5510 | comp_append_type(comp, args[cur_arg]); |
| 5511 | cur_arg ++; |
| 5512 | continue; |
| 5513 | } |
| 5514 | } |
| 5515 | else { |
Willy Tarreau | 70737d1 | 2012-10-27 00:34:28 +0200 | [diff] [blame] | 5516 | Alert("parsing [%s:%d] : '%s' expects 'algo', 'type' or 'offload'\n", |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5517 | file, linenum, args[0]); |
| 5518 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5519 | goto out; |
| 5520 | } |
| 5521 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5522 | else { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 5523 | struct cfg_kw_list *kwl; |
| 5524 | int index; |
| 5525 | |
| 5526 | list_for_each_entry(kwl, &cfg_keywords.list, list) { |
| 5527 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 5528 | if (kwl->kw[index].section != CFG_LISTEN) |
| 5529 | continue; |
| 5530 | if (strcmp(kwl->kw[index].kw, args[0]) == 0) { |
| 5531 | /* prepare error message just in case */ |
Willy Tarreau | 28a47d6 | 2012-09-18 20:02:48 +0200 | [diff] [blame] | 5532 | 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] | 5533 | if (rc < 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 5534 | Alert("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5535 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5536 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 5537 | } |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 5538 | else if (rc > 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 5539 | Warning("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5540 | err_code |= ERR_WARN; |
| 5541 | goto out; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 5542 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5543 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 5544 | } |
| 5545 | } |
| 5546 | } |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5547 | |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5548 | 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] | 5549 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5550 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5551 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5552 | out: |
Willy Tarreau | f4068b6 | 2012-05-08 17:37:49 +0200 | [diff] [blame] | 5553 | free(errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5554 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5555 | } |
| 5556 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5557 | int |
| 5558 | cfg_parse_users(const char *file, int linenum, char **args, int kwm) |
| 5559 | { |
| 5560 | |
| 5561 | int err_code = 0; |
| 5562 | const char *err; |
| 5563 | |
| 5564 | if (!strcmp(args[0], "userlist")) { /* new userlist */ |
| 5565 | struct userlist *newul; |
| 5566 | |
| 5567 | if (!*args[1]) { |
| 5568 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 5569 | file, linenum, args[0]); |
| 5570 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5571 | goto out; |
| 5572 | } |
| 5573 | |
| 5574 | err = invalid_char(args[1]); |
| 5575 | if (err) { |
| 5576 | Alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 5577 | file, linenum, *err, args[0], args[1]); |
| 5578 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5579 | goto out; |
| 5580 | } |
| 5581 | |
| 5582 | for (newul = userlist; newul; newul = newul->next) |
| 5583 | if (!strcmp(newul->name, args[1])) { |
| 5584 | Warning("parsing [%s:%d]: ignoring duplicated userlist '%s'.\n", |
| 5585 | file, linenum, args[1]); |
| 5586 | err_code |= ERR_WARN; |
| 5587 | goto out; |
| 5588 | } |
| 5589 | |
| 5590 | newul = (struct userlist *)calloc(1, sizeof(struct userlist)); |
| 5591 | if (!newul) { |
| 5592 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 5593 | err_code |= ERR_ALERT | ERR_ABORT; |
| 5594 | goto out; |
| 5595 | } |
| 5596 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5597 | newul->name = strdup(args[1]); |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 5598 | if (!newul->name) { |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5599 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 5600 | err_code |= ERR_ALERT | ERR_ABORT; |
| 5601 | goto out; |
| 5602 | } |
| 5603 | |
| 5604 | newul->next = userlist; |
| 5605 | userlist = newul; |
| 5606 | |
| 5607 | } else if (!strcmp(args[0], "group")) { /* new group */ |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 5608 | int cur_arg; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5609 | const char *err; |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 5610 | struct auth_groups *ag; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5611 | |
| 5612 | if (!*args[1]) { |
| 5613 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 5614 | file, linenum, args[0]); |
| 5615 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5616 | goto out; |
| 5617 | } |
| 5618 | |
| 5619 | err = invalid_char(args[1]); |
| 5620 | if (err) { |
| 5621 | Alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 5622 | file, linenum, *err, args[0], args[1]); |
| 5623 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5624 | goto out; |
| 5625 | } |
| 5626 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 5627 | for (ag = userlist->groups; ag; ag = ag->next) |
| 5628 | if (!strcmp(ag->name, args[1])) { |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5629 | Warning("parsing [%s:%d]: ignoring duplicated group '%s' in userlist '%s'.\n", |
| 5630 | file, linenum, args[1], userlist->name); |
| 5631 | err_code |= ERR_ALERT; |
| 5632 | goto out; |
| 5633 | } |
| 5634 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 5635 | ag = calloc(1, sizeof(*ag)); |
| 5636 | if (!ag) { |
| 5637 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 5638 | err_code |= ERR_ALERT | ERR_ABORT; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5639 | goto out; |
| 5640 | } |
| 5641 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 5642 | ag->name = strdup(args[1]); |
| 5643 | if (!ag) { |
| 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 | cur_arg = 2; |
| 5650 | |
| 5651 | while (*args[cur_arg]) { |
| 5652 | if (!strcmp(args[cur_arg], "users")) { |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 5653 | ag->groupusers = strdup(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5654 | cur_arg += 2; |
| 5655 | continue; |
| 5656 | } else { |
| 5657 | Alert("parsing [%s:%d]: '%s' only supports 'users' option.\n", |
| 5658 | file, linenum, args[0]); |
| 5659 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5660 | goto out; |
| 5661 | } |
| 5662 | } |
| 5663 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 5664 | ag->next = userlist->groups; |
| 5665 | userlist->groups = ag; |
| 5666 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5667 | } else if (!strcmp(args[0], "user")) { /* new user */ |
| 5668 | struct auth_users *newuser; |
| 5669 | int cur_arg; |
| 5670 | |
| 5671 | if (!*args[1]) { |
| 5672 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 5673 | file, linenum, args[0]); |
| 5674 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5675 | goto out; |
| 5676 | } |
| 5677 | |
| 5678 | for (newuser = userlist->users; newuser; newuser = newuser->next) |
| 5679 | if (!strcmp(newuser->user, args[1])) { |
| 5680 | Warning("parsing [%s:%d]: ignoring duplicated user '%s' in userlist '%s'.\n", |
| 5681 | file, linenum, args[1], userlist->name); |
| 5682 | err_code |= ERR_ALERT; |
| 5683 | goto out; |
| 5684 | } |
| 5685 | |
| 5686 | newuser = (struct auth_users *)calloc(1, sizeof(struct auth_users)); |
| 5687 | if (!newuser) { |
| 5688 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 5689 | err_code |= ERR_ALERT | ERR_ABORT; |
| 5690 | goto out; |
| 5691 | } |
| 5692 | |
| 5693 | newuser->user = strdup(args[1]); |
| 5694 | |
| 5695 | newuser->next = userlist->users; |
| 5696 | userlist->users = newuser; |
| 5697 | |
| 5698 | cur_arg = 2; |
| 5699 | |
| 5700 | while (*args[cur_arg]) { |
| 5701 | if (!strcmp(args[cur_arg], "password")) { |
Cyril Bonté | 2c8d700 | 2014-08-29 20:20:02 +0200 | [diff] [blame^] | 5702 | #ifdef CONFIG_HAP_CRYPT |
| 5703 | if (!crypt("", args[cur_arg + 1])) { |
| 5704 | Alert("parsing [%s:%d]: the encrypted password used for user '%s' is not supported by crypt(3).\n", |
| 5705 | file, linenum, newuser->user); |
| 5706 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5707 | goto out; |
| 5708 | } |
| 5709 | #else |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5710 | Warning("parsing [%s:%d]: no crypt(3) support compiled, encrypted passwords will not work.\n", |
| 5711 | file, linenum); |
| 5712 | err_code |= ERR_ALERT; |
| 5713 | #endif |
| 5714 | newuser->pass = strdup(args[cur_arg + 1]); |
| 5715 | cur_arg += 2; |
| 5716 | continue; |
| 5717 | } else if (!strcmp(args[cur_arg], "insecure-password")) { |
| 5718 | newuser->pass = strdup(args[cur_arg + 1]); |
| 5719 | newuser->flags |= AU_O_INSECURE; |
| 5720 | cur_arg += 2; |
| 5721 | continue; |
| 5722 | } else if (!strcmp(args[cur_arg], "groups")) { |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 5723 | newuser->u.groups_names = strdup(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5724 | cur_arg += 2; |
| 5725 | continue; |
| 5726 | } else { |
| 5727 | Alert("parsing [%s:%d]: '%s' only supports 'password', 'insecure-password' and 'groups' options.\n", |
| 5728 | file, linenum, args[0]); |
| 5729 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5730 | goto out; |
| 5731 | } |
| 5732 | } |
| 5733 | } else { |
| 5734 | Alert("parsing [%s:%d]: unknown keyword '%s' in '%s' section\n", file, linenum, args[0], "users"); |
| 5735 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5736 | } |
| 5737 | |
| 5738 | out: |
| 5739 | return err_code; |
| 5740 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5741 | |
| 5742 | /* |
| 5743 | * This function reads and parses the configuration file given in the argument. |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5744 | * Returns the error code, 0 if OK, or any combination of : |
| 5745 | * - ERR_ABORT: must abort ASAP |
| 5746 | * - ERR_FATAL: we can continue parsing but not start the service |
| 5747 | * - ERR_WARN: a warning has been emitted |
| 5748 | * - ERR_ALERT: an alert has been emitted |
| 5749 | * Only the two first ones can stop processing, the two others are just |
| 5750 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5751 | */ |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 5752 | int readcfgfile(const char *file) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5753 | { |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5754 | char thisline[LINESIZE]; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5755 | FILE *f; |
| 5756 | int linenum = 0; |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5757 | int err_code = 0; |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 5758 | struct cfg_section *cs = NULL; |
| 5759 | struct cfg_section *ics; |
| 5760 | |
| 5761 | /* Register internal sections */ |
| 5762 | if (!cfg_register_section("listen", cfg_parse_listen) || |
| 5763 | !cfg_register_section("frontend", cfg_parse_listen) || |
| 5764 | !cfg_register_section("backend", cfg_parse_listen) || |
| 5765 | !cfg_register_section("ruleset", cfg_parse_listen) || |
| 5766 | !cfg_register_section("defaults", cfg_parse_listen) || |
| 5767 | !cfg_register_section("global", cfg_parse_global) || |
| 5768 | !cfg_register_section("userlist", cfg_parse_users) || |
| 5769 | !cfg_register_section("peers", cfg_parse_peers)) |
| 5770 | return -1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5771 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5772 | if ((f=fopen(file,"r")) == NULL) |
| 5773 | return -1; |
| 5774 | |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5775 | while (fgets(thisline, sizeof(thisline), f) != NULL) { |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 5776 | int arg, kwm = KWM_STD; |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5777 | char *end; |
| 5778 | char *args[MAX_LINE_ARGS + 1]; |
| 5779 | char *line = thisline; |
| 5780 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5781 | linenum++; |
| 5782 | |
| 5783 | end = line + strlen(line); |
| 5784 | |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5785 | if (end-line == sizeof(thisline)-1 && *(end-1) != '\n') { |
| 5786 | /* Check if we reached the limit and the last char is not \n. |
| 5787 | * Watch out for the last line without the terminating '\n'! |
| 5788 | */ |
| 5789 | Alert("parsing [%s:%d]: line too long, limit: %d.\n", |
Willy Tarreau | 5e4a6f1 | 2009-04-11 19:42:49 +0200 | [diff] [blame] | 5790 | file, linenum, (int)sizeof(thisline)-1); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5791 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5792 | } |
| 5793 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5794 | /* skip leading spaces */ |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 5795 | while (isspace((unsigned char)*line)) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5796 | line++; |
| 5797 | |
| 5798 | arg = 0; |
| 5799 | args[arg] = line; |
| 5800 | |
| 5801 | while (*line && arg < MAX_LINE_ARGS) { |
| 5802 | /* first, we'll replace \\, \<space>, \#, \r, \n, \t, \xXX with their |
| 5803 | * C equivalent value. Other combinations left unchanged (eg: \1). |
| 5804 | */ |
| 5805 | if (*line == '\\') { |
| 5806 | int skip = 0; |
| 5807 | if (line[1] == ' ' || line[1] == '\\' || line[1] == '#') { |
| 5808 | *line = line[1]; |
| 5809 | skip = 1; |
| 5810 | } |
| 5811 | else if (line[1] == 'r') { |
| 5812 | *line = '\r'; |
| 5813 | skip = 1; |
| 5814 | } |
| 5815 | else if (line[1] == 'n') { |
| 5816 | *line = '\n'; |
| 5817 | skip = 1; |
| 5818 | } |
| 5819 | else if (line[1] == 't') { |
| 5820 | *line = '\t'; |
| 5821 | skip = 1; |
| 5822 | } |
| 5823 | else if (line[1] == 'x') { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5824 | if ((line + 3 < end) && ishex(line[2]) && ishex(line[3])) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5825 | unsigned char hex1, hex2; |
| 5826 | hex1 = toupper(line[2]) - '0'; |
| 5827 | hex2 = toupper(line[3]) - '0'; |
| 5828 | if (hex1 > 9) hex1 -= 'A' - '9' - 1; |
| 5829 | if (hex2 > 9) hex2 -= 'A' - '9' - 1; |
| 5830 | *line = (hex1<<4) + hex2; |
| 5831 | skip = 3; |
| 5832 | } |
| 5833 | else { |
| 5834 | 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] | 5835 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5836 | } |
| 5837 | } |
| 5838 | if (skip) { |
Cyril Bonté | dd1b01d | 2009-12-06 13:43:42 +0100 | [diff] [blame] | 5839 | memmove(line + 1, line + 1 + skip, end - (line + skip)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5840 | end -= skip; |
| 5841 | } |
| 5842 | line++; |
| 5843 | } |
| 5844 | else if (*line == '#' || *line == '\n' || *line == '\r') { |
| 5845 | /* end of string, end of loop */ |
| 5846 | *line = 0; |
| 5847 | break; |
| 5848 | } |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 5849 | else if (isspace((unsigned char)*line)) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5850 | /* a non-escaped space is an argument separator */ |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5851 | *line++ = '\0'; |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 5852 | while (isspace((unsigned char)*line)) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5853 | line++; |
| 5854 | args[++arg] = line; |
| 5855 | } |
| 5856 | else { |
| 5857 | line++; |
| 5858 | } |
| 5859 | } |
| 5860 | |
| 5861 | /* empty line */ |
| 5862 | if (!**args) |
| 5863 | continue; |
| 5864 | |
Willy Tarreau | 7bb651e | 2009-11-09 21:16:53 +0100 | [diff] [blame] | 5865 | if (*line) { |
| 5866 | /* we had to stop due to too many args. |
| 5867 | * Let's terminate the string, print the offending part then cut the |
| 5868 | * last arg. |
| 5869 | */ |
| 5870 | while (*line && *line != '#' && *line != '\n' && *line != '\r') |
| 5871 | line++; |
| 5872 | *line = '\0'; |
| 5873 | |
Krzysztof Piotr Oledzki | 500b8f0 | 2009-12-15 22:34:51 +0100 | [diff] [blame] | 5874 | 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] | 5875 | file, linenum, arg + 1, (long)(args[arg] - thisline + 1), args[arg]); |
Willy Tarreau | 7bb651e | 2009-11-09 21:16:53 +0100 | [diff] [blame] | 5876 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5877 | args[arg] = line; |
| 5878 | } |
| 5879 | |
Willy Tarreau | 540abe4 | 2007-05-02 20:50:16 +0200 | [diff] [blame] | 5880 | /* zero out remaining args and ensure that at least one entry |
| 5881 | * is zeroed out. |
| 5882 | */ |
| 5883 | while (++arg <= MAX_LINE_ARGS) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5884 | args[arg] = line; |
| 5885 | } |
| 5886 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 5887 | /* check for keyword modifiers "no" and "default" */ |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5888 | if (!strcmp(args[0], "no")) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5889 | char *tmp; |
| 5890 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 5891 | kwm = KWM_NO; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5892 | tmp = args[0]; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5893 | for (arg=0; *args[arg+1]; arg++) |
| 5894 | args[arg] = args[arg+1]; // shift args after inversion |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5895 | *tmp = '\0'; // fix the next arg to \0 |
| 5896 | args[arg] = tmp; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5897 | } |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 5898 | else if (!strcmp(args[0], "default")) { |
| 5899 | kwm = KWM_DEF; |
| 5900 | for (arg=0; *args[arg+1]; arg++) |
| 5901 | args[arg] = args[arg+1]; // shift args after inversion |
| 5902 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5903 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5904 | if (kwm != KWM_STD && strcmp(args[0], "option") != 0 && \ |
| 5905 | strcmp(args[0], "log") != 0) { |
| 5906 | 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] | 5907 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5908 | } |
| 5909 | |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 5910 | /* detect section start */ |
| 5911 | list_for_each_entry(ics, §ions, list) { |
| 5912 | if (strcmp(args[0], ics->section_name) == 0) { |
| 5913 | cursection = ics->section_name; |
| 5914 | cs = ics; |
| 5915 | break; |
| 5916 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 5917 | } |
| 5918 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5919 | /* else it's a section keyword */ |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 5920 | if (cs) |
| 5921 | err_code |= cs->section_parser(file, linenum, args, kwm); |
| 5922 | else { |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5923 | 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] | 5924 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5925 | } |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5926 | |
| 5927 | if (err_code & ERR_ABORT) |
| 5928 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5929 | } |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5930 | cursection = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5931 | fclose(f); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5932 | return err_code; |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5933 | } |
| 5934 | |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 5935 | /* |
| 5936 | * Returns the error code, 0 if OK, or any combination of : |
| 5937 | * - ERR_ABORT: must abort ASAP |
| 5938 | * - ERR_FATAL: we can continue parsing but not start the service |
| 5939 | * - ERR_WARN: a warning has been emitted |
| 5940 | * - ERR_ALERT: an alert has been emitted |
| 5941 | * Only the two first ones can stop processing, the two others are just |
| 5942 | * indicators. |
| 5943 | */ |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5944 | int check_config_validity() |
| 5945 | { |
| 5946 | int cfgerr = 0; |
| 5947 | struct proxy *curproxy = NULL; |
| 5948 | struct server *newsrv = NULL; |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 5949 | int err_code = 0; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 5950 | unsigned int next_pxid = 1; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 5951 | struct bind_conf *bind_conf; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5952 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 5953 | bind_conf = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5954 | /* |
| 5955 | * Now, check for the integrity of all that we have collected. |
| 5956 | */ |
| 5957 | |
| 5958 | /* will be needed further to delay some tasks */ |
Willy Tarreau | b0b37bc | 2008-06-23 14:00:57 +0200 | [diff] [blame] | 5959 | tv_update_date(0,1); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5960 | |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 5961 | if (!global.tune.max_http_hdr) |
| 5962 | global.tune.max_http_hdr = MAX_HTTP_HDR; |
| 5963 | |
| 5964 | if (!global.tune.cookie_len) |
| 5965 | global.tune.cookie_len = CAPTURE_LEN; |
| 5966 | |
| 5967 | pool2_capture = create_pool("capture", global.tune.cookie_len, MEM_F_SHARED); |
| 5968 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 5969 | /* Post initialisation of the users and groups lists. */ |
| 5970 | err_code = userlist_postinit(); |
| 5971 | if (err_code != ERR_NONE) |
| 5972 | goto out; |
| 5973 | |
Willy Tarreau | 55bc0f8 | 2009-03-15 14:51:53 +0100 | [diff] [blame] | 5974 | /* first, we will invert the proxy list order */ |
| 5975 | curproxy = NULL; |
| 5976 | while (proxy) { |
| 5977 | struct proxy *next; |
| 5978 | |
| 5979 | next = proxy->next; |
| 5980 | proxy->next = curproxy; |
| 5981 | curproxy = proxy; |
| 5982 | if (!next) |
| 5983 | break; |
| 5984 | proxy = next; |
| 5985 | } |
| 5986 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5987 | while (curproxy != NULL) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 5988 | struct switching_rule *rule; |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 5989 | struct server_rule *srule; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5990 | struct sticking_rule *mrule; |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 5991 | struct tcp_rule *trule; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 5992 | struct listener *listener; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 5993 | unsigned int next_id; |
Willy Tarreau | 16a2147 | 2012-11-19 12:39:59 +0100 | [diff] [blame] | 5994 | int nbproc; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 5995 | |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 5996 | if (curproxy->uuid < 0) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 5997 | /* proxy ID not set, use automatic numbering with first |
| 5998 | * spare entry starting with next_pxid. |
| 5999 | */ |
| 6000 | next_pxid = get_next_id(&used_proxy_id, next_pxid); |
| 6001 | curproxy->conf.id.key = curproxy->uuid = next_pxid; |
| 6002 | eb32_insert(&used_proxy_id, &curproxy->conf.id); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6003 | } |
Krzysztof Piotr Oledzki | df5cb9f | 2010-02-05 20:58:27 +0100 | [diff] [blame] | 6004 | next_pxid++; |
| 6005 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6006 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6007 | if (curproxy->state == PR_STSTOPPED) { |
Willy Tarreau | da250db | 2008-10-12 12:07:48 +0200 | [diff] [blame] | 6008 | /* ensure we don't keep listeners uselessly bound */ |
| 6009 | stop_proxy(curproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6010 | curproxy = curproxy->next; |
| 6011 | continue; |
| 6012 | } |
| 6013 | |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 6014 | /* Check multi-process mode compatibility for the current proxy */ |
| 6015 | |
| 6016 | if (curproxy->bind_proc) { |
| 6017 | /* an explicit bind-process was specified, let's check how many |
| 6018 | * processes remain. |
| 6019 | */ |
| 6020 | nbproc = popcount(curproxy->bind_proc); |
| 6021 | |
| 6022 | curproxy->bind_proc &= nbits(global.nbproc); |
| 6023 | if (!curproxy->bind_proc && nbproc == 1) { |
| 6024 | 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); |
| 6025 | curproxy->bind_proc = 1; |
| 6026 | } |
| 6027 | else if (!curproxy->bind_proc && nbproc > 1) { |
| 6028 | 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); |
| 6029 | curproxy->bind_proc = 0; |
| 6030 | } |
| 6031 | } |
| 6032 | |
Willy Tarreau | 3d20958 | 2014-05-09 17:06:11 +0200 | [diff] [blame] | 6033 | /* check and reduce the bind-proc of each listener */ |
| 6034 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
| 6035 | unsigned long mask; |
| 6036 | |
| 6037 | if (!bind_conf->bind_proc) |
| 6038 | continue; |
| 6039 | |
| 6040 | mask = nbits(global.nbproc); |
| 6041 | if (curproxy->bind_proc) |
| 6042 | mask &= curproxy->bind_proc; |
| 6043 | /* mask cannot be null here thanks to the previous checks */ |
| 6044 | |
| 6045 | nbproc = popcount(bind_conf->bind_proc); |
| 6046 | bind_conf->bind_proc &= mask; |
| 6047 | |
| 6048 | if (!bind_conf->bind_proc && nbproc == 1) { |
| 6049 | 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", |
| 6050 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
| 6051 | bind_conf->bind_proc = mask & ~(mask - 1); |
| 6052 | } |
| 6053 | else if (!bind_conf->bind_proc && nbproc > 1) { |
| 6054 | 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", |
| 6055 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
| 6056 | bind_conf->bind_proc = 0; |
| 6057 | } |
| 6058 | } |
| 6059 | |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 6060 | /* here, if bind_proc is null, it means no limit, otherwise it's explicit. |
| 6061 | * We now check how many processes the proxy will effectively run on. |
| 6062 | */ |
| 6063 | |
| 6064 | nbproc = global.nbproc; |
| 6065 | if (curproxy->bind_proc) |
| 6066 | nbproc = popcount(curproxy->bind_proc & nbits(global.nbproc)); |
| 6067 | |
| 6068 | if (global.nbproc > 1 && curproxy->table.peers.name) { |
| 6069 | Alert("Proxy '%s': peers can't be used in multi-process mode (nbproc > 1).\n", |
| 6070 | curproxy->id); |
| 6071 | cfgerr++; |
| 6072 | } |
Willy Tarreau | 16a2147 | 2012-11-19 12:39:59 +0100 | [diff] [blame] | 6073 | |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 6074 | switch (curproxy->mode) { |
| 6075 | case PR_MODE_HEALTH: |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6076 | cfgerr += proxy_cfg_ensure_no_http(curproxy); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 6077 | if (!(curproxy->cap & PR_CAP_FE)) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6078 | Alert("config : %s '%s' cannot be in health mode as it has no frontend capability.\n", |
| 6079 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 6080 | cfgerr++; |
| 6081 | } |
| 6082 | |
| 6083 | if (curproxy->srv != NULL) |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6084 | Warning("config : servers will be ignored for %s '%s'.\n", |
| 6085 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 6086 | break; |
| 6087 | |
| 6088 | case PR_MODE_TCP: |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6089 | cfgerr += proxy_cfg_ensure_no_http(curproxy); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 6090 | break; |
| 6091 | |
| 6092 | case PR_MODE_HTTP: |
Willy Tarreau | 25320b2 | 2013-03-24 07:22:08 +0100 | [diff] [blame] | 6093 | curproxy->http_needed = 1; |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 6094 | break; |
| 6095 | } |
| 6096 | |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 6097 | if ((curproxy->cap & PR_CAP_BE) && (curproxy->mode != PR_MODE_HEALTH)) { |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6098 | if (curproxy->lbprm.algo & BE_LB_KIND) { |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 6099 | if (curproxy->options & PR_O_TRANSP) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6100 | Alert("config : %s '%s' cannot use both transparent and balance mode.\n", |
| 6101 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 6102 | cfgerr++; |
| 6103 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6104 | #ifdef WE_DONT_SUPPORT_SERVERLESS_LISTENERS |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 6105 | else if (curproxy->srv == NULL) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6106 | Alert("config : %s '%s' needs at least 1 server in balance mode.\n", |
| 6107 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 6108 | cfgerr++; |
| 6109 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6110 | #endif |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 6111 | else if (curproxy->options & PR_O_DISPATCH) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6112 | Warning("config : dispatch address of %s '%s' will be ignored in balance mode.\n", |
| 6113 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6114 | err_code |= ERR_WARN; |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 6115 | } |
| 6116 | } |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 6117 | 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] | 6118 | /* If no LB algo is set in a backend, and we're not in |
| 6119 | * transparent mode, dispatch mode nor proxy mode, we |
| 6120 | * want to use balance roundrobin by default. |
| 6121 | */ |
| 6122 | curproxy->lbprm.algo &= ~BE_LB_ALGO; |
| 6123 | curproxy->lbprm.algo |= BE_LB_ALGO_RR; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6124 | } |
| 6125 | } |
Willy Tarreau | 193cf93 | 2007-09-17 10:17:23 +0200 | [diff] [blame] | 6126 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 6127 | if (curproxy->options & PR_O_DISPATCH) |
| 6128 | curproxy->options &= ~(PR_O_TRANSP | PR_O_HTTP_PROXY); |
| 6129 | else if (curproxy->options & PR_O_HTTP_PROXY) |
| 6130 | curproxy->options &= ~(PR_O_DISPATCH | PR_O_TRANSP); |
| 6131 | else if (curproxy->options & PR_O_TRANSP) |
| 6132 | curproxy->options &= ~(PR_O_DISPATCH | PR_O_HTTP_PROXY); |
Willy Tarreau | 8293658 | 2007-11-30 15:20:09 +0100 | [diff] [blame] | 6133 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 6134 | if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_HTTP_CHK) { |
| 6135 | if (curproxy->options & PR_O_DISABLE404) { |
| 6136 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n", |
| 6137 | "disable-on-404", proxy_type_str(curproxy), curproxy->id); |
| 6138 | err_code |= ERR_WARN; |
| 6139 | curproxy->options &= ~PR_O_DISABLE404; |
| 6140 | } |
| 6141 | if (curproxy->options2 & PR_O2_CHK_SNDST) { |
| 6142 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n", |
| 6143 | "send-state", proxy_type_str(curproxy), curproxy->id); |
| 6144 | err_code |= ERR_WARN; |
| 6145 | curproxy->options &= ~PR_O2_CHK_SNDST; |
| 6146 | } |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 6147 | } |
| 6148 | |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 6149 | /* if a default backend was specified, let's find it */ |
| 6150 | if (curproxy->defbe.name) { |
| 6151 | struct proxy *target; |
| 6152 | |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 6153 | target = findproxy_mode(curproxy->defbe.name, curproxy->mode, PR_CAP_BE); |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6154 | if (!target) { |
| 6155 | Alert("Proxy '%s': unable to find required default_backend: '%s'.\n", |
| 6156 | curproxy->id, curproxy->defbe.name); |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 6157 | cfgerr++; |
| 6158 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6159 | Alert("Proxy '%s': loop detected for default_backend: '%s'.\n", |
| 6160 | curproxy->id, curproxy->defbe.name); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6161 | cfgerr++; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 6162 | } else { |
| 6163 | free(curproxy->defbe.name); |
| 6164 | curproxy->defbe.be = target; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 6165 | /* we force the backend to be present on at least all of |
| 6166 | * the frontend's processes. |
| 6167 | */ |
Willy Tarreau | 3507d5d | 2014-05-09 13:54:22 +0200 | [diff] [blame] | 6168 | if (target->bind_proc) |
| 6169 | target->bind_proc = curproxy->bind_proc ? |
| 6170 | (target->bind_proc | curproxy->bind_proc) : 0; |
Willy Tarreau | ff67813 | 2012-02-13 14:32:34 +0100 | [diff] [blame] | 6171 | |
| 6172 | /* Emit a warning if this proxy also has some servers */ |
| 6173 | if (curproxy->srv) { |
| 6174 | Warning("In proxy '%s', the 'default_backend' rule always has precedence over the servers, which will never be used.\n", |
| 6175 | curproxy->id); |
| 6176 | err_code |= ERR_WARN; |
| 6177 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6178 | } |
| 6179 | } |
| 6180 | |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 6181 | /* find the target proxy in setbe */ |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 6182 | if (curproxy->mode == PR_MODE_HTTP && curproxy->req_exp != NULL) { |
| 6183 | /* map jump target for ACT_SETBE in req_rep chain */ |
| 6184 | struct hdr_exp *exp; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 6185 | for (exp = curproxy->req_exp; exp != NULL; exp = exp->next) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6186 | struct proxy *target; |
| 6187 | |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 6188 | if (exp->action != ACT_SETBE) |
| 6189 | continue; |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6190 | |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 6191 | target = findproxy_mode(exp->replace, PR_MODE_HTTP, PR_CAP_BE); |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6192 | if (!target) { |
| 6193 | Alert("Proxy '%s': unable to find required setbe: '%s'.\n", |
| 6194 | curproxy->id, exp->replace); |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 6195 | cfgerr++; |
| 6196 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6197 | Alert("Proxy '%s': loop detected for setbe: '%s'.\n", |
| 6198 | curproxy->id, exp->replace); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 6199 | cfgerr++; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 6200 | } else { |
| 6201 | free((void *)exp->replace); |
| 6202 | exp->replace = (const char *)target; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 6203 | /* we force the backend to be present on at least all of |
| 6204 | * the frontend's processes. |
| 6205 | */ |
Willy Tarreau | 3507d5d | 2014-05-09 13:54:22 +0200 | [diff] [blame] | 6206 | if (target->bind_proc) |
| 6207 | target->bind_proc = curproxy->bind_proc ? |
| 6208 | (target->bind_proc | curproxy->bind_proc) : 0; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 6209 | } |
| 6210 | } |
| 6211 | } |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6212 | |
| 6213 | /* find the target proxy for 'use_backend' rules */ |
| 6214 | list_for_each_entry(rule, &curproxy->switching_rules, list) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6215 | struct proxy *target; |
Bertrand Jacquin | 702d44f | 2013-11-19 11:43:06 +0100 | [diff] [blame] | 6216 | struct logformat_node *node; |
| 6217 | char *pxname; |
| 6218 | |
| 6219 | /* Try to parse the string as a log format expression. If the result |
| 6220 | * of the parsing is only one entry containing a simple string, then |
| 6221 | * it's a standard string corresponding to a static rule, thus the |
| 6222 | * parsing is cancelled and be.name is restored to be resolved. |
| 6223 | */ |
| 6224 | pxname = rule->be.name; |
| 6225 | LIST_INIT(&rule->be.expr); |
| 6226 | parse_logformat_string(pxname, curproxy, &rule->be.expr, 0, SMP_VAL_FE_HRQ_HDR, |
| 6227 | curproxy->conf.args.file, curproxy->conf.args.line); |
| 6228 | node = LIST_NEXT(&rule->be.expr, struct logformat_node *, list); |
| 6229 | |
| 6230 | if (!LIST_ISEMPTY(&rule->be.expr)) { |
| 6231 | if (node->type != LOG_FMT_TEXT || node->list.n != &rule->be.expr) { |
| 6232 | rule->dynamic = 1; |
| 6233 | free(pxname); |
| 6234 | continue; |
| 6235 | } |
| 6236 | /* simple string: free the expression and fall back to static rule */ |
| 6237 | free(node->arg); |
| 6238 | free(node); |
| 6239 | } |
| 6240 | |
| 6241 | rule->dynamic = 0; |
| 6242 | rule->be.name = pxname; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6243 | |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 6244 | target = findproxy_mode(rule->be.name, curproxy->mode, PR_CAP_BE); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6245 | |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6246 | if (!target) { |
| 6247 | Alert("Proxy '%s': unable to find required use_backend: '%s'.\n", |
| 6248 | curproxy->id, rule->be.name); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6249 | cfgerr++; |
| 6250 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6251 | Alert("Proxy '%s': loop detected for use_backend: '%s'.\n", |
| 6252 | curproxy->id, rule->be.name); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6253 | cfgerr++; |
| 6254 | } else { |
| 6255 | free((void *)rule->be.name); |
| 6256 | rule->be.backend = target; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 6257 | /* we force the backend to be present on at least all of |
| 6258 | * the frontend's processes. |
| 6259 | */ |
Willy Tarreau | 3507d5d | 2014-05-09 13:54:22 +0200 | [diff] [blame] | 6260 | if (target->bind_proc) |
| 6261 | target->bind_proc = curproxy->bind_proc ? |
| 6262 | (target->bind_proc | curproxy->bind_proc) : 0; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6263 | } |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 6264 | } |
| 6265 | |
| 6266 | /* find the target proxy for 'use_backend' rules */ |
| 6267 | list_for_each_entry(srule, &curproxy->server_rules, list) { |
| 6268 | struct server *target = findserver(curproxy, srule->srv.name); |
| 6269 | |
| 6270 | if (!target) { |
| 6271 | Alert("config : %s '%s' : unable to find server '%s' referenced in a 'use-server' rule.\n", |
| 6272 | proxy_type_str(curproxy), curproxy->id, srule->srv.name); |
| 6273 | cfgerr++; |
| 6274 | continue; |
| 6275 | } |
| 6276 | free((void *)srule->srv.name); |
| 6277 | srule->srv.ptr = target; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6278 | } |
| 6279 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6280 | /* find the target table for 'stick' rules */ |
| 6281 | list_for_each_entry(mrule, &curproxy->sticking_rules, list) { |
| 6282 | struct proxy *target; |
| 6283 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 6284 | curproxy->be_req_ana |= AN_REQ_STICKING_RULES; |
| 6285 | if (mrule->flags & STK_IS_STORE) |
| 6286 | curproxy->be_rsp_ana |= AN_RES_STORE_RULES; |
| 6287 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6288 | if (mrule->table.name) |
Willy Tarreau | c00cdc2 | 2010-06-06 16:48:26 +0200 | [diff] [blame] | 6289 | target = findproxy(mrule->table.name, 0); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6290 | else |
| 6291 | target = curproxy; |
| 6292 | |
| 6293 | if (!target) { |
| 6294 | Alert("Proxy '%s': unable to find stick-table '%s'.\n", |
| 6295 | curproxy->id, mrule->table.name); |
| 6296 | cfgerr++; |
| 6297 | } |
| 6298 | else if (target->table.size == 0) { |
| 6299 | Alert("Proxy '%s': stick-table '%s' used but not configured.\n", |
| 6300 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 6301 | cfgerr++; |
| 6302 | } |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 6303 | else if (!stktable_compatible_sample(mrule->expr, target->table.type)) { |
| 6304 | 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] | 6305 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 6306 | cfgerr++; |
| 6307 | } |
| 6308 | else { |
| 6309 | free((void *)mrule->table.name); |
| 6310 | mrule->table.t = &(target->table); |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 6311 | stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID, NULL); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6312 | } |
| 6313 | } |
| 6314 | |
| 6315 | /* find the target table for 'store response' rules */ |
| 6316 | list_for_each_entry(mrule, &curproxy->storersp_rules, list) { |
| 6317 | struct proxy *target; |
| 6318 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 6319 | curproxy->be_rsp_ana |= AN_RES_STORE_RULES; |
| 6320 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6321 | if (mrule->table.name) |
Willy Tarreau | c00cdc2 | 2010-06-06 16:48:26 +0200 | [diff] [blame] | 6322 | target = findproxy(mrule->table.name, 0); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6323 | else |
| 6324 | target = curproxy; |
| 6325 | |
| 6326 | if (!target) { |
| 6327 | Alert("Proxy '%s': unable to find store table '%s'.\n", |
| 6328 | curproxy->id, mrule->table.name); |
| 6329 | cfgerr++; |
| 6330 | } |
| 6331 | else if (target->table.size == 0) { |
| 6332 | Alert("Proxy '%s': stick-table '%s' used but not configured.\n", |
| 6333 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 6334 | cfgerr++; |
| 6335 | } |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 6336 | else if (!stktable_compatible_sample(mrule->expr, target->table.type)) { |
| 6337 | 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] | 6338 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 6339 | cfgerr++; |
| 6340 | } |
| 6341 | else { |
| 6342 | free((void *)mrule->table.name); |
| 6343 | mrule->table.t = &(target->table); |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 6344 | stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID, NULL); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6345 | } |
| 6346 | } |
| 6347 | |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 6348 | /* find the target table for 'tcp-request' layer 4 rules */ |
| 6349 | list_for_each_entry(trule, &curproxy->tcp_req.l4_rules, list) { |
| 6350 | struct proxy *target; |
| 6351 | |
Willy Tarreau | b4c8493 | 2013-07-23 19:15:30 +0200 | [diff] [blame] | 6352 | 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] | 6353 | continue; |
| 6354 | |
| 6355 | if (trule->act_prm.trk_ctr.table.n) |
| 6356 | target = findproxy(trule->act_prm.trk_ctr.table.n, 0); |
| 6357 | else |
| 6358 | target = curproxy; |
| 6359 | |
| 6360 | if (!target) { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6361 | Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n", |
| 6362 | curproxy->id, trule->act_prm.trk_ctr.table.n, |
Willy Tarreau | 34c2fb6 | 2013-12-02 23:29:05 +0100 | [diff] [blame] | 6363 | tcp_trk_idx(trule->action)); |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 6364 | cfgerr++; |
| 6365 | } |
| 6366 | else if (target->table.size == 0) { |
| 6367 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
| 6368 | curproxy->id, trule->act_prm.trk_ctr.table.n ? trule->act_prm.trk_ctr.table.n : curproxy->id); |
| 6369 | cfgerr++; |
| 6370 | } |
Willy Tarreau | 5f53de7 | 2012-12-12 00:25:44 +0100 | [diff] [blame] | 6371 | else if (!stktable_compatible_sample(trule->act_prm.trk_ctr.expr, target->table.type)) { |
| 6372 | Alert("Proxy '%s': stick-table '%s' uses a type incompatible with the 'track-sc%d' rule.\n", |
| 6373 | 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] | 6374 | tcp_trk_idx(trule->action)); |
Willy Tarreau | 5f53de7 | 2012-12-12 00:25:44 +0100 | [diff] [blame] | 6375 | cfgerr++; |
| 6376 | } |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 6377 | else { |
| 6378 | free(trule->act_prm.trk_ctr.table.n); |
| 6379 | trule->act_prm.trk_ctr.table.t = &target->table; |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6380 | /* 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] | 6381 | * to pass a list of counters to track and allocate them right here using |
| 6382 | * stktable_alloc_data_type(). |
| 6383 | */ |
| 6384 | } |
| 6385 | } |
| 6386 | |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 6387 | /* find the target table for 'tcp-request' layer 6 rules */ |
| 6388 | list_for_each_entry(trule, &curproxy->tcp_req.inspect_rules, list) { |
| 6389 | struct proxy *target; |
| 6390 | |
Willy Tarreau | b4c8493 | 2013-07-23 19:15:30 +0200 | [diff] [blame] | 6391 | 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] | 6392 | continue; |
| 6393 | |
| 6394 | if (trule->act_prm.trk_ctr.table.n) |
| 6395 | target = findproxy(trule->act_prm.trk_ctr.table.n, 0); |
| 6396 | else |
| 6397 | target = curproxy; |
| 6398 | |
| 6399 | if (!target) { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6400 | Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n", |
| 6401 | curproxy->id, trule->act_prm.trk_ctr.table.n, |
Willy Tarreau | 34c2fb6 | 2013-12-02 23:29:05 +0100 | [diff] [blame] | 6402 | tcp_trk_idx(trule->action)); |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 6403 | cfgerr++; |
| 6404 | } |
| 6405 | else if (target->table.size == 0) { |
| 6406 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
| 6407 | curproxy->id, trule->act_prm.trk_ctr.table.n ? trule->act_prm.trk_ctr.table.n : curproxy->id); |
| 6408 | cfgerr++; |
| 6409 | } |
Willy Tarreau | 5f53de7 | 2012-12-12 00:25:44 +0100 | [diff] [blame] | 6410 | else if (!stktable_compatible_sample(trule->act_prm.trk_ctr.expr, target->table.type)) { |
| 6411 | Alert("Proxy '%s': stick-table '%s' uses a type incompatible with the 'track-sc%d' rule.\n", |
| 6412 | 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] | 6413 | tcp_trk_idx(trule->action)); |
Willy Tarreau | 5f53de7 | 2012-12-12 00:25:44 +0100 | [diff] [blame] | 6414 | cfgerr++; |
| 6415 | } |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 6416 | else { |
| 6417 | free(trule->act_prm.trk_ctr.table.n); |
| 6418 | trule->act_prm.trk_ctr.table.t = &target->table; |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6419 | /* 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] | 6420 | * to pass a list of counters to track and allocate them right here using |
| 6421 | * stktable_alloc_data_type(). |
| 6422 | */ |
| 6423 | } |
| 6424 | } |
| 6425 | |
Willy Tarreau | b3dc39d | 2014-04-28 22:06:57 +0200 | [diff] [blame] | 6426 | /* move any "block" rules at the beginning of the http-request rules */ |
| 6427 | if (!LIST_ISEMPTY(&curproxy->block_rules)) { |
| 6428 | /* insert block_rules into http_req_rules at the beginning */ |
| 6429 | curproxy->block_rules.p->n = curproxy->http_req_rules.n; |
| 6430 | curproxy->http_req_rules.n->p = curproxy->block_rules.p; |
| 6431 | curproxy->block_rules.n->p = &curproxy->http_req_rules; |
| 6432 | curproxy->http_req_rules.n = curproxy->block_rules.n; |
| 6433 | LIST_INIT(&curproxy->block_rules); |
| 6434 | } |
| 6435 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 6436 | if (curproxy->table.peers.name) { |
| 6437 | struct peers *curpeers = peers; |
| 6438 | |
| 6439 | for (curpeers = peers; curpeers; curpeers = curpeers->next) { |
| 6440 | if (strcmp(curpeers->id, curproxy->table.peers.name) == 0) { |
| 6441 | free((void *)curproxy->table.peers.name); |
Willy Tarreau | 973ca49 | 2013-01-17 21:34:52 +0100 | [diff] [blame] | 6442 | curproxy->table.peers.p = curpeers; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 6443 | break; |
| 6444 | } |
| 6445 | } |
| 6446 | |
| 6447 | if (!curpeers) { |
| 6448 | Alert("Proxy '%s': unable to find sync peers '%s'.\n", |
| 6449 | curproxy->id, curproxy->table.peers.name); |
Willy Tarreau | d66bf96 | 2011-10-28 14:16:49 +0200 | [diff] [blame] | 6450 | free((void *)curproxy->table.peers.name); |
| 6451 | curproxy->table.peers.p = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 6452 | cfgerr++; |
| 6453 | } |
| 6454 | else if (!curpeers->peers_fe) { |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 6455 | Alert("Proxy '%s': unable to find local peer '%s' in peers section '%s'.\n", |
| 6456 | curproxy->id, localpeer, curpeers->id); |
Willy Tarreau | d66bf96 | 2011-10-28 14:16:49 +0200 | [diff] [blame] | 6457 | curproxy->table.peers.p = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 6458 | cfgerr++; |
| 6459 | } |
| 6460 | } |
| 6461 | |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 6462 | if (curproxy->uri_auth && !(curproxy->uri_auth->flags & ST_CONVDONE) && |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 6463 | !LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) && |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6464 | (curproxy->uri_auth->userlist || curproxy->uri_auth->auth_realm )) { |
| 6465 | Alert("%s '%s': stats 'auth'/'realm' and 'http-request' can't be used at the same time.\n", |
| 6466 | "proxy", curproxy->id); |
| 6467 | cfgerr++; |
| 6468 | goto out_uri_auth_compat; |
| 6469 | } |
| 6470 | |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 6471 | 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] | 6472 | const char *uri_auth_compat_req[10]; |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 6473 | struct http_req_rule *rule; |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6474 | int i = 0; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6475 | |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6476 | /* build the ACL condition from scratch. We're relying on anonymous ACLs for that */ |
| 6477 | uri_auth_compat_req[i++] = "auth"; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6478 | |
| 6479 | if (curproxy->uri_auth->auth_realm) { |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6480 | uri_auth_compat_req[i++] = "realm"; |
| 6481 | uri_auth_compat_req[i++] = curproxy->uri_auth->auth_realm; |
| 6482 | } |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6483 | |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6484 | uri_auth_compat_req[i++] = "unless"; |
| 6485 | uri_auth_compat_req[i++] = "{"; |
| 6486 | uri_auth_compat_req[i++] = "http_auth(.internal-stats-userlist)"; |
| 6487 | uri_auth_compat_req[i++] = "}"; |
| 6488 | uri_auth_compat_req[i++] = ""; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6489 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 6490 | rule = parse_http_req_cond(uri_auth_compat_req, "internal-stats-auth-compat", 0, curproxy); |
| 6491 | if (!rule) { |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6492 | cfgerr++; |
| 6493 | break; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6494 | } |
| 6495 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 6496 | LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list); |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6497 | |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6498 | if (curproxy->uri_auth->auth_realm) { |
| 6499 | free(curproxy->uri_auth->auth_realm); |
| 6500 | curproxy->uri_auth->auth_realm = NULL; |
| 6501 | } |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 6502 | |
| 6503 | curproxy->uri_auth->flags |= ST_CONVDONE; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6504 | } |
| 6505 | out_uri_auth_compat: |
| 6506 | |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 6507 | /* compile the log format */ |
| 6508 | if (!(curproxy->cap & PR_CAP_FE)) { |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 6509 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 6510 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 6511 | curproxy->conf.logformat_string != clf_http_log_format) |
| 6512 | free(curproxy->conf.logformat_string); |
| 6513 | curproxy->conf.logformat_string = NULL; |
| 6514 | free(curproxy->conf.lfs_file); |
| 6515 | curproxy->conf.lfs_file = NULL; |
| 6516 | curproxy->conf.lfs_line = 0; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 6517 | } |
| 6518 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 6519 | if (curproxy->conf.logformat_string) { |
| 6520 | curproxy->conf.args.ctx = ARGC_LOG; |
| 6521 | curproxy->conf.args.file = curproxy->conf.lfs_file; |
| 6522 | curproxy->conf.args.line = curproxy->conf.lfs_line; |
| 6523 | 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] | 6524 | 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] | 6525 | curproxy->conf.args.file = NULL; |
| 6526 | curproxy->conf.args.line = 0; |
| 6527 | } |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 6528 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 6529 | if (curproxy->conf.uniqueid_format_string) { |
| 6530 | curproxy->conf.args.ctx = ARGC_UIF; |
| 6531 | curproxy->conf.args.file = curproxy->conf.uif_file; |
| 6532 | curproxy->conf.args.line = curproxy->conf.uif_line; |
Thierry FOURNIER | d048d8b | 2014-03-13 16:46:18 +0100 | [diff] [blame] | 6533 | 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] | 6534 | (proxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 6535 | curproxy->conf.uif_file, curproxy->conf.uif_line); |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 6536 | curproxy->conf.args.file = NULL; |
| 6537 | curproxy->conf.args.line = 0; |
| 6538 | } |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 6539 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6540 | /* only now we can check if some args remain unresolved. |
| 6541 | * This must be done after the users and groups resolution. |
| 6542 | */ |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 6543 | cfgerr += smp_resolve_args(curproxy); |
| 6544 | if (!cfgerr) |
| 6545 | cfgerr += acl_find_targets(curproxy); |
Krzysztof Piotr Oledzki | f9423ae | 2010-01-29 19:26:18 +0100 | [diff] [blame] | 6546 | |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 6547 | if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) && |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6548 | (((curproxy->cap & PR_CAP_FE) && !curproxy->timeout.client) || |
Willy Tarreau | d825eef | 2007-05-12 22:35:00 +0200 | [diff] [blame] | 6549 | ((curproxy->cap & PR_CAP_BE) && (curproxy->srv) && |
Willy Tarreau | ce887fd | 2012-05-12 12:50:00 +0200 | [diff] [blame] | 6550 | (!curproxy->timeout.connect || |
| 6551 | (!curproxy->timeout.server && (curproxy->mode == PR_MODE_HTTP || !curproxy->timeout.tunnel)))))) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6552 | Warning("config : missing timeouts for %s '%s'.\n" |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 6553 | " | While not properly invalid, you will certainly encounter various problems\n" |
| 6554 | " | 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] | 6555 | " | timeouts are set to a non-zero value: 'client', 'connect', 'server'.\n", |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6556 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6557 | err_code |= ERR_WARN; |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 6558 | } |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 6559 | |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6560 | /* Historically, the tarpit and queue timeouts were inherited from contimeout. |
| 6561 | * We must still support older configurations, so let's find out whether those |
| 6562 | * parameters have been set or must be copied from contimeouts. |
| 6563 | */ |
| 6564 | if (curproxy != &defproxy) { |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6565 | if (!curproxy->timeout.tarpit || |
| 6566 | curproxy->timeout.tarpit == defproxy.timeout.tarpit) { |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6567 | /* tarpit timeout not set. We search in the following order: |
| 6568 | * default.tarpit, curr.connect, default.connect. |
| 6569 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6570 | if (defproxy.timeout.tarpit) |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6571 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6572 | else if (curproxy->timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6573 | curproxy->timeout.tarpit = curproxy->timeout.connect; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6574 | else if (defproxy.timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6575 | curproxy->timeout.tarpit = defproxy.timeout.connect; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6576 | } |
| 6577 | if ((curproxy->cap & PR_CAP_BE) && |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6578 | (!curproxy->timeout.queue || |
| 6579 | curproxy->timeout.queue == defproxy.timeout.queue)) { |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6580 | /* queue timeout not set. We search in the following order: |
| 6581 | * default.queue, curr.connect, default.connect. |
| 6582 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6583 | if (defproxy.timeout.queue) |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6584 | curproxy->timeout.queue = defproxy.timeout.queue; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6585 | else if (curproxy->timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6586 | curproxy->timeout.queue = curproxy->timeout.connect; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6587 | else if (defproxy.timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6588 | curproxy->timeout.queue = defproxy.timeout.connect; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6589 | } |
| 6590 | } |
| 6591 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 6592 | if ((curproxy->options2 & PR_O2_CHK_ANY) == PR_O2_SSL3_CHK) { |
Willy Tarreau | 137325d | 2010-02-01 16:38:17 +0100 | [diff] [blame] | 6593 | curproxy->check_len = sizeof(sslv3_client_hello_pkt) - 1; |
| 6594 | curproxy->check_req = (char *)malloc(curproxy->check_len); |
| 6595 | memcpy(curproxy->check_req, sslv3_client_hello_pkt, curproxy->check_len); |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 6596 | } |
| 6597 | |
Willy Tarreau | 215663d | 2014-06-13 18:30:23 +0200 | [diff] [blame] | 6598 | if (!LIST_ISEMPTY(&curproxy->tcpcheck_rules) && |
| 6599 | (curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_TCPCHK_CHK) { |
| 6600 | Warning("config : %s '%s' uses tcp-check rules without 'option tcp-check', so the rules are ignored.\n", |
| 6601 | proxy_type_str(curproxy), curproxy->id); |
| 6602 | err_code |= ERR_WARN; |
| 6603 | } |
| 6604 | |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 6605 | /* ensure that cookie capture length is not too large */ |
| 6606 | if (curproxy->capture_len >= global.tune.cookie_len) { |
| 6607 | Warning("config : truncating capture length to %d bytes for %s '%s'.\n", |
| 6608 | global.tune.cookie_len - 1, proxy_type_str(curproxy), curproxy->id); |
| 6609 | err_code |= ERR_WARN; |
| 6610 | curproxy->capture_len = global.tune.cookie_len - 1; |
| 6611 | } |
| 6612 | |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 6613 | /* The small pools required for the capture lists */ |
Willy Tarreau | 9a54e13 | 2012-03-24 08:33:05 +0100 | [diff] [blame] | 6614 | if (curproxy->nb_req_cap) { |
Willy Tarreau | d9ed3d2 | 2014-06-13 12:23:06 +0200 | [diff] [blame] | 6615 | curproxy->req_cap_pool = create_pool("ptrcap", |
| 6616 | curproxy->nb_req_cap * sizeof(char *), |
| 6617 | MEM_F_SHARED); |
Willy Tarreau | 9a54e13 | 2012-03-24 08:33:05 +0100 | [diff] [blame] | 6618 | } |
| 6619 | |
| 6620 | if (curproxy->nb_rsp_cap) { |
Willy Tarreau | d9ed3d2 | 2014-06-13 12:23:06 +0200 | [diff] [blame] | 6621 | curproxy->rsp_cap_pool = create_pool("ptrcap", |
| 6622 | curproxy->nb_rsp_cap * sizeof(char *), |
| 6623 | MEM_F_SHARED); |
Willy Tarreau | 9a54e13 | 2012-03-24 08:33:05 +0100 | [diff] [blame] | 6624 | } |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 6625 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6626 | /* first, we will invert the servers list order */ |
| 6627 | newsrv = NULL; |
| 6628 | while (curproxy->srv) { |
| 6629 | struct server *next; |
| 6630 | |
| 6631 | next = curproxy->srv->next; |
| 6632 | curproxy->srv->next = newsrv; |
| 6633 | newsrv = curproxy->srv; |
| 6634 | if (!next) |
| 6635 | break; |
| 6636 | curproxy->srv = next; |
| 6637 | } |
| 6638 | |
Willy Tarreau | 17edc81 | 2014-01-03 12:14:34 +0100 | [diff] [blame] | 6639 | /* Check that no server name conflicts. This causes trouble in the stats. |
| 6640 | * We only emit a warning for the first conflict affecting each server, |
| 6641 | * in order to avoid combinatory explosion if all servers have the same |
| 6642 | * name. We do that only for servers which do not have an explicit ID, |
| 6643 | * because these IDs were made also for distinguishing them and we don't |
| 6644 | * want to annoy people who correctly manage them. |
| 6645 | */ |
| 6646 | for (newsrv = curproxy->srv; newsrv; newsrv = newsrv->next) { |
| 6647 | struct server *other_srv; |
| 6648 | |
| 6649 | if (newsrv->puid) |
| 6650 | continue; |
| 6651 | |
| 6652 | for (other_srv = curproxy->srv; other_srv && other_srv != newsrv; other_srv = other_srv->next) { |
| 6653 | if (!other_srv->puid && strcmp(other_srv->id, newsrv->id) == 0) { |
| 6654 | Warning("parsing [%s:%d] : %s '%s', another server named '%s' was defined without an explicit ID at line %d, this is not recommended.\n", |
| 6655 | newsrv->conf.file, newsrv->conf.line, |
| 6656 | proxy_type_str(curproxy), curproxy->id, |
| 6657 | newsrv->id, other_srv->conf.line); |
| 6658 | break; |
| 6659 | } |
| 6660 | } |
| 6661 | } |
| 6662 | |
Willy Tarreau | dd70165 | 2010-05-25 23:03:02 +0200 | [diff] [blame] | 6663 | /* assign automatic UIDs to servers which don't have one yet */ |
| 6664 | next_id = 1; |
| 6665 | newsrv = curproxy->srv; |
| 6666 | while (newsrv != NULL) { |
| 6667 | if (!newsrv->puid) { |
| 6668 | /* server ID not set, use automatic numbering with first |
| 6669 | * spare entry starting with next_svid. |
| 6670 | */ |
| 6671 | next_id = get_next_id(&curproxy->conf.used_server_id, next_id); |
| 6672 | newsrv->conf.id.key = newsrv->puid = next_id; |
| 6673 | eb32_insert(&curproxy->conf.used_server_id, &newsrv->conf.id); |
| 6674 | } |
| 6675 | next_id++; |
| 6676 | newsrv = newsrv->next; |
| 6677 | } |
| 6678 | |
Willy Tarreau | 2069704 | 2007-11-15 23:26:18 +0100 | [diff] [blame] | 6679 | curproxy->lbprm.wmult = 1; /* default weight multiplier */ |
Willy Tarreau | 5dc2fa6 | 2007-11-19 19:10:18 +0100 | [diff] [blame] | 6680 | curproxy->lbprm.wdiv = 1; /* default weight divider */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6681 | |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 6682 | /* |
| 6683 | * If this server supports a maxconn parameter, it needs a dedicated |
| 6684 | * tasks to fill the emptied slots when a connection leaves. |
| 6685 | * Also, resolve deferred tracking dependency if needed. |
| 6686 | */ |
| 6687 | newsrv = curproxy->srv; |
| 6688 | while (newsrv != NULL) { |
| 6689 | if (newsrv->minconn > newsrv->maxconn) { |
| 6690 | /* Only 'minconn' was specified, or it was higher than or equal |
| 6691 | * to 'maxconn'. Let's turn this into maxconn and clean it, as |
| 6692 | * this will avoid further useless expensive computations. |
| 6693 | */ |
| 6694 | newsrv->maxconn = newsrv->minconn; |
| 6695 | } else if (newsrv->maxconn && !newsrv->minconn) { |
| 6696 | /* minconn was not specified, so we set it to maxconn */ |
| 6697 | newsrv->minconn = newsrv->maxconn; |
| 6698 | } |
| 6699 | |
Emeric Brun | 01f8e2f | 2012-05-18 16:02:00 +0200 | [diff] [blame] | 6700 | #ifdef USE_OPENSSL |
Emeric Brun | 94324a4 | 2012-10-11 14:00:19 +0200 | [diff] [blame] | 6701 | if (newsrv->use_ssl || newsrv->check.use_ssl) |
| 6702 | cfgerr += ssl_sock_prepare_srv_ctx(newsrv, curproxy); |
Emeric Brun | 01f8e2f | 2012-05-18 16:02:00 +0200 | [diff] [blame] | 6703 | #endif /* USE_OPENSSL */ |
Emeric Brun | 94324a4 | 2012-10-11 14:00:19 +0200 | [diff] [blame] | 6704 | |
Willy Tarreau | 2f075e9 | 2013-12-03 11:11:34 +0100 | [diff] [blame] | 6705 | /* set the check type on the server */ |
| 6706 | newsrv->check.type = curproxy->options2 & PR_O2_CHK_ANY; |
| 6707 | |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 6708 | if (newsrv->trackit) { |
| 6709 | struct proxy *px; |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 6710 | struct server *srv, *loop; |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 6711 | char *pname, *sname; |
| 6712 | |
| 6713 | pname = newsrv->trackit; |
| 6714 | sname = strrchr(pname, '/'); |
| 6715 | |
| 6716 | if (sname) |
| 6717 | *sname++ = '\0'; |
| 6718 | else { |
| 6719 | sname = pname; |
| 6720 | pname = NULL; |
| 6721 | } |
| 6722 | |
| 6723 | if (pname) { |
| 6724 | px = findproxy(pname, PR_CAP_BE); |
| 6725 | if (!px) { |
| 6726 | Alert("config : %s '%s', server '%s': unable to find required proxy '%s' for tracking.\n", |
| 6727 | proxy_type_str(curproxy), curproxy->id, |
| 6728 | newsrv->id, pname); |
| 6729 | cfgerr++; |
| 6730 | goto next_srv; |
| 6731 | } |
| 6732 | } else |
| 6733 | px = curproxy; |
| 6734 | |
| 6735 | srv = findserver(px, sname); |
| 6736 | if (!srv) { |
| 6737 | Alert("config : %s '%s', server '%s': unable to find required server '%s' for tracking.\n", |
| 6738 | proxy_type_str(curproxy), curproxy->id, |
| 6739 | newsrv->id, sname); |
| 6740 | cfgerr++; |
| 6741 | goto next_srv; |
| 6742 | } |
| 6743 | |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 6744 | if (!(srv->check.state & CHK_ST_CONFIGURED) && |
| 6745 | !(srv->agent.state & CHK_ST_CONFIGURED) && |
| 6746 | !srv->track && !srv->trackit) { |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 6747 | Alert("config : %s '%s', server '%s': unable to use %s/%s for " |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 6748 | "tracking as it does not have any check nor agent enabled.\n", |
| 6749 | proxy_type_str(curproxy), curproxy->id, |
| 6750 | newsrv->id, px->id, srv->id); |
| 6751 | cfgerr++; |
| 6752 | goto next_srv; |
| 6753 | } |
| 6754 | |
| 6755 | for (loop = srv->track; loop && loop != newsrv; loop = loop->track); |
| 6756 | |
| 6757 | if (loop) { |
| 6758 | Alert("config : %s '%s', server '%s': unable to track %s/%s as it " |
| 6759 | "belongs to a tracking chain looping back to %s/%s.\n", |
| 6760 | proxy_type_str(curproxy), curproxy->id, |
| 6761 | newsrv->id, px->id, srv->id, px->id, loop->id); |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 6762 | cfgerr++; |
| 6763 | goto next_srv; |
| 6764 | } |
| 6765 | |
| 6766 | if (curproxy != px && |
| 6767 | (curproxy->options & PR_O_DISABLE404) != (px->options & PR_O_DISABLE404)) { |
| 6768 | Alert("config : %s '%s', server '%s': unable to use %s/%s for" |
| 6769 | "tracking: disable-on-404 option inconsistency.\n", |
| 6770 | proxy_type_str(curproxy), curproxy->id, |
| 6771 | newsrv->id, px->id, srv->id); |
| 6772 | cfgerr++; |
| 6773 | goto next_srv; |
| 6774 | } |
| 6775 | |
| 6776 | /* 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] | 6777 | if (srv->admin & SRV_ADMF_MAINT) { |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 6778 | newsrv->admin |= SRV_ADMF_IMAINT; |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 6779 | newsrv->state = SRV_ST_STOPPED; |
Simon Horman | 125d099 | 2013-02-24 17:23:38 +0900 | [diff] [blame] | 6780 | newsrv->check.health = 0; |
Simon Horman | d60d691 | 2013-11-25 10:46:36 +0900 | [diff] [blame] | 6781 | newsrv->agent.health = 0; |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 6782 | } |
| 6783 | |
| 6784 | newsrv->track = srv; |
Willy Tarreau | 1a53a3a | 2013-12-11 15:27:05 +0100 | [diff] [blame] | 6785 | newsrv->tracknext = srv->trackers; |
| 6786 | srv->trackers = newsrv; |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 6787 | |
| 6788 | free(newsrv->trackit); |
| 6789 | newsrv->trackit = NULL; |
| 6790 | } |
| 6791 | next_srv: |
| 6792 | newsrv = newsrv->next; |
| 6793 | } |
| 6794 | |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6795 | /* We have to initialize the server lookup mechanism depending |
| 6796 | * on what LB algorithm was choosen. |
| 6797 | */ |
| 6798 | |
| 6799 | curproxy->lbprm.algo &= ~(BE_LB_LKUP | BE_LB_PROP_DYN); |
| 6800 | switch (curproxy->lbprm.algo & BE_LB_KIND) { |
| 6801 | case BE_LB_KIND_RR: |
Willy Tarreau | 9757a38 | 2009-10-03 12:56:50 +0200 | [diff] [blame] | 6802 | if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_RR_STATIC) { |
| 6803 | curproxy->lbprm.algo |= BE_LB_LKUP_MAP; |
| 6804 | init_server_map(curproxy); |
| 6805 | } else { |
| 6806 | curproxy->lbprm.algo |= BE_LB_LKUP_RRTREE | BE_LB_PROP_DYN; |
| 6807 | fwrr_init_server_groups(curproxy); |
| 6808 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6809 | break; |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 6810 | |
Willy Tarreau | 3ebb116 | 2012-02-13 16:57:44 +0100 | [diff] [blame] | 6811 | case BE_LB_KIND_CB: |
Willy Tarreau | f09c660 | 2012-02-13 17:12:08 +0100 | [diff] [blame] | 6812 | if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_CB_LC) { |
| 6813 | curproxy->lbprm.algo |= BE_LB_LKUP_LCTREE | BE_LB_PROP_DYN; |
| 6814 | fwlc_init_server_tree(curproxy); |
| 6815 | } else { |
| 6816 | curproxy->lbprm.algo |= BE_LB_LKUP_FSTREE | BE_LB_PROP_DYN; |
| 6817 | fas_init_server_tree(curproxy); |
| 6818 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6819 | break; |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 6820 | |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6821 | case BE_LB_KIND_HI: |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 6822 | if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS) { |
| 6823 | curproxy->lbprm.algo |= BE_LB_LKUP_CHTREE | BE_LB_PROP_DYN; |
| 6824 | chash_init_server_tree(curproxy); |
| 6825 | } else { |
| 6826 | curproxy->lbprm.algo |= BE_LB_LKUP_MAP; |
| 6827 | init_server_map(curproxy); |
| 6828 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6829 | break; |
| 6830 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6831 | |
| 6832 | if (curproxy->options & PR_O_LOGASAP) |
| 6833 | curproxy->to_log &= ~LW_BYTES; |
| 6834 | |
Willy Tarreau | e7ded1f | 2009-08-09 10:11:45 +0200 | [diff] [blame] | 6835 | if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) && |
Willy Tarreau | d79a3b2 | 2012-12-28 09:40:16 +0100 | [diff] [blame] | 6836 | (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] | 6837 | Warning("config : log format ignored for %s '%s' since it has no log address.\n", |
| 6838 | proxy_type_str(curproxy), curproxy->id); |
| 6839 | err_code |= ERR_WARN; |
| 6840 | } |
| 6841 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 6842 | if (curproxy->mode != PR_MODE_HTTP) { |
| 6843 | int optnum; |
| 6844 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 6845 | if (curproxy->uri_auth) { |
| 6846 | Warning("config : 'stats' statement ignored for %s '%s' as it requires HTTP mode.\n", |
| 6847 | proxy_type_str(curproxy), curproxy->id); |
| 6848 | err_code |= ERR_WARN; |
| 6849 | curproxy->uri_auth = NULL; |
| 6850 | } |
| 6851 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 6852 | if (curproxy->options & (PR_O_FWDFOR | PR_O_FF_ALWAYS)) { |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 6853 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6854 | "forwardfor", proxy_type_str(curproxy), curproxy->id); |
| 6855 | err_code |= ERR_WARN; |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 6856 | curproxy->options &= ~(PR_O_FWDFOR | PR_O_FF_ALWAYS); |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 6857 | } |
| 6858 | |
| 6859 | if (curproxy->options & PR_O_ORGTO) { |
| 6860 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6861 | "originalto", proxy_type_str(curproxy), curproxy->id); |
| 6862 | err_code |= ERR_WARN; |
| 6863 | curproxy->options &= ~PR_O_ORGTO; |
| 6864 | } |
| 6865 | |
| 6866 | for (optnum = 0; cfg_opts[optnum].name; optnum++) { |
| 6867 | if (cfg_opts[optnum].mode == PR_MODE_HTTP && |
| 6868 | (curproxy->cap & cfg_opts[optnum].cap) && |
| 6869 | (curproxy->options & cfg_opts[optnum].val)) { |
| 6870 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6871 | cfg_opts[optnum].name, proxy_type_str(curproxy), curproxy->id); |
| 6872 | err_code |= ERR_WARN; |
| 6873 | curproxy->options &= ~cfg_opts[optnum].val; |
| 6874 | } |
| 6875 | } |
| 6876 | |
| 6877 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) { |
| 6878 | if (cfg_opts2[optnum].mode == PR_MODE_HTTP && |
| 6879 | (curproxy->cap & cfg_opts2[optnum].cap) && |
| 6880 | (curproxy->options2 & cfg_opts2[optnum].val)) { |
| 6881 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6882 | cfg_opts2[optnum].name, proxy_type_str(curproxy), curproxy->id); |
| 6883 | err_code |= ERR_WARN; |
| 6884 | curproxy->options2 &= ~cfg_opts2[optnum].val; |
| 6885 | } |
| 6886 | } |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6887 | |
Pieter Baauw | d551fb5 | 2013-05-08 22:49:23 +0200 | [diff] [blame] | 6888 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_TRANSPARENT) |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6889 | if (curproxy->conn_src.bind_hdr_occ) { |
| 6890 | curproxy->conn_src.bind_hdr_occ = 0; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6891 | 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] | 6892 | proxy_type_str(curproxy), curproxy->id, curproxy->conn_src.bind_hdr_name); |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6893 | err_code |= ERR_WARN; |
| 6894 | } |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 6895 | #endif |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 6896 | } |
| 6897 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6898 | /* |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 6899 | * ensure that we're not cross-dressing a TCP server into HTTP. |
| 6900 | */ |
| 6901 | newsrv = curproxy->srv; |
| 6902 | while (newsrv != NULL) { |
Willy Tarreau | 0cec331 | 2011-10-31 13:49:26 +0100 | [diff] [blame] | 6903 | if ((curproxy->mode != PR_MODE_HTTP) && newsrv->rdr_len) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6904 | Alert("config : %s '%s' : server cannot have cookie or redirect prefix in non-HTTP mode.\n", |
| 6905 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6906 | cfgerr++; |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 6907 | } |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6908 | |
Willy Tarreau | 0cec331 | 2011-10-31 13:49:26 +0100 | [diff] [blame] | 6909 | if ((curproxy->mode != PR_MODE_HTTP) && newsrv->cklen) { |
| 6910 | Warning("config : %s '%s' : ignoring cookie for server '%s' as HTTP mode is disabled.\n", |
| 6911 | proxy_type_str(curproxy), curproxy->id, newsrv->id); |
| 6912 | err_code |= ERR_WARN; |
| 6913 | } |
| 6914 | |
Willy Tarreau | c93cd16 | 2014-05-13 15:54:22 +0200 | [diff] [blame] | 6915 | if ((newsrv->flags & SRV_F_MAPPORTS) && (curproxy->options2 & PR_O2_RDPC_PRST)) { |
Willy Tarreau | 82ffa39 | 2013-08-13 17:19:08 +0200 | [diff] [blame] | 6916 | Warning("config : %s '%s' : RDP cookie persistence will not work for server '%s' because it lacks an explicit port number.\n", |
| 6917 | proxy_type_str(curproxy), curproxy->id, newsrv->id); |
| 6918 | err_code |= ERR_WARN; |
| 6919 | } |
| 6920 | |
Pieter Baauw | d551fb5 | 2013-05-08 22:49:23 +0200 | [diff] [blame] | 6921 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_TRANSPARENT) |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6922 | if (curproxy->mode != PR_MODE_HTTP && newsrv->conn_src.bind_hdr_occ) { |
| 6923 | newsrv->conn_src.bind_hdr_occ = 0; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6924 | 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] | 6925 | 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] | 6926 | err_code |= ERR_WARN; |
| 6927 | } |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 6928 | #endif |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 6929 | newsrv = newsrv->next; |
| 6930 | } |
| 6931 | |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6932 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 6933 | if (!curproxy->accept) |
| 6934 | curproxy->accept = frontend_accept; |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 6935 | |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6936 | if (curproxy->tcp_req.inspect_delay || |
| 6937 | !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules)) |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 6938 | curproxy->fe_req_ana |= AN_REQ_INSPECT_FE; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6939 | |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 6940 | if (curproxy->mode == PR_MODE_HTTP) { |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6941 | 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] | 6942 | 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] | 6943 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6944 | |
| 6945 | /* both TCP and HTTP must check switching rules */ |
| 6946 | curproxy->fe_req_ana |= AN_REQ_SWITCHING_RULES; |
| 6947 | } |
| 6948 | |
| 6949 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 6950 | if (curproxy->tcp_req.inspect_delay || |
| 6951 | !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules)) |
| 6952 | curproxy->be_req_ana |= AN_REQ_INSPECT_BE; |
| 6953 | |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 6954 | if (!LIST_ISEMPTY(&curproxy->tcp_rep.inspect_rules)) |
| 6955 | curproxy->be_rsp_ana |= AN_RES_INSPECT; |
| 6956 | |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 6957 | if (curproxy->mode == PR_MODE_HTTP) { |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6958 | 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] | 6959 | 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] | 6960 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6961 | |
| 6962 | /* If the backend does requires RDP cookie persistence, we have to |
| 6963 | * enable the corresponding analyser. |
| 6964 | */ |
| 6965 | if (curproxy->options2 & PR_O2_RDPC_PRST) |
| 6966 | curproxy->be_req_ana |= AN_REQ_PRST_RDP_COOKIE; |
| 6967 | } |
| 6968 | |
Emeric Brun | c52962f | 2012-11-15 18:28:02 +0100 | [diff] [blame] | 6969 | #ifdef USE_OPENSSL |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 6970 | /* Configure SSL for each bind line. |
| 6971 | * Note: if configuration fails at some point, the ->ctx member |
| 6972 | * remains NULL so that listeners can later detach. |
| 6973 | */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6974 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
Emeric Brun | caa19cc | 2014-05-07 16:10:18 +0200 | [diff] [blame] | 6975 | int alloc_ctx; |
| 6976 | |
Emeric Brun | c52962f | 2012-11-15 18:28:02 +0100 | [diff] [blame] | 6977 | if (!bind_conf->is_ssl) { |
| 6978 | if (bind_conf->default_ctx) { |
| 6979 | Warning("Proxy '%s': A certificate was specified but SSL was not enabled on bind '%s' at [%s:%d] (use 'ssl').\n", |
| 6980 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
| 6981 | } |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6982 | continue; |
Emeric Brun | c52962f | 2012-11-15 18:28:02 +0100 | [diff] [blame] | 6983 | } |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6984 | if (!bind_conf->default_ctx) { |
Emeric Brun | fc0421f | 2012-09-07 17:30:07 +0200 | [diff] [blame] | 6985 | 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] | 6986 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 6987 | cfgerr++; |
| 6988 | continue; |
| 6989 | } |
| 6990 | |
Emeric Brun | 8dc6039 | 2014-05-09 13:52:00 +0200 | [diff] [blame] | 6991 | 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] | 6992 | if (alloc_ctx < 0) { |
Emeric Brun | 93ee249 | 2014-05-09 14:01:48 +0200 | [diff] [blame] | 6993 | if (alloc_ctx == SHCTX_E_INIT_LOCK) |
| 6994 | 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"); |
| 6995 | else |
Emeric Brun | caa19cc | 2014-05-07 16:10:18 +0200 | [diff] [blame] | 6996 | Alert("Unable to allocate SSL session cache.\n"); |
Emeric Brun | 93ee249 | 2014-05-09 14:01:48 +0200 | [diff] [blame] | 6997 | cfgerr++; |
| 6998 | continue; |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 6999 | } |
| 7000 | |
Emeric Brun | fc0421f | 2012-09-07 17:30:07 +0200 | [diff] [blame] | 7001 | /* initialize all certificate contexts */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7002 | cfgerr += ssl_sock_prepare_all_ctx(bind_conf, curproxy); |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7003 | } |
Emeric Brun | c52962f | 2012-11-15 18:28:02 +0100 | [diff] [blame] | 7004 | #endif /* USE_OPENSSL */ |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 7005 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 7006 | /* adjust this proxy's listeners */ |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7007 | next_id = 1; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 7008 | list_for_each_entry(listener, &curproxy->conf.listeners, by_fe) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7009 | if (!listener->luid) { |
| 7010 | /* listener ID not set, use automatic numbering with first |
| 7011 | * spare entry starting with next_luid. |
| 7012 | */ |
| 7013 | next_id = get_next_id(&curproxy->conf.used_listener_id, next_id); |
| 7014 | listener->conf.id.key = listener->luid = next_id; |
| 7015 | eb32_insert(&curproxy->conf.used_listener_id, &listener->conf.id); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7016 | } |
Krzysztof Piotr Oledzki | df5cb9f | 2010-02-05 20:58:27 +0100 | [diff] [blame] | 7017 | next_id++; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7018 | |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 7019 | /* enable separate counters */ |
| 7020 | if (curproxy->options2 & PR_O2_SOCKSTAT) { |
| 7021 | listener->counters = (struct licounters *)calloc(1, sizeof(struct licounters)); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 7022 | if (!listener->name) |
| 7023 | memprintf(&listener->name, "sock-%d", listener->luid); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 7024 | } |
Willy Tarreau | 81796be | 2012-09-22 19:11:47 +0200 | [diff] [blame] | 7025 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 7026 | if (curproxy->options & PR_O_TCP_NOLING) |
| 7027 | listener->options |= LI_O_NOLINGER; |
Willy Tarreau | 32368ce | 2012-09-06 11:10:55 +0200 | [diff] [blame] | 7028 | if (!listener->maxconn) |
| 7029 | listener->maxconn = curproxy->maxconn; |
| 7030 | if (!listener->backlog) |
| 7031 | listener->backlog = curproxy->backlog; |
Willy Tarreau | 16a2147 | 2012-11-19 12:39:59 +0100 | [diff] [blame] | 7032 | if (!listener->maxaccept) |
| 7033 | listener->maxaccept = global.tune.maxaccept ? global.tune.maxaccept : 64; |
| 7034 | |
| 7035 | /* we want to have an optimal behaviour on single process mode to |
| 7036 | * maximize the work at once, but in multi-process we want to keep |
| 7037 | * some fairness between processes, so we target half of the max |
| 7038 | * number of events to be balanced over all the processes the proxy |
| 7039 | * is bound to. Rememeber that maxaccept = -1 must be kept as it is |
| 7040 | * used to disable the limit. |
| 7041 | */ |
| 7042 | if (listener->maxaccept > 0) { |
| 7043 | if (nbproc > 1) |
| 7044 | listener->maxaccept = (listener->maxaccept + 1) / 2; |
| 7045 | listener->maxaccept = (listener->maxaccept + nbproc - 1) / nbproc; |
| 7046 | } |
| 7047 | |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 7048 | listener->timeout = &curproxy->timeout.client; |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 7049 | listener->accept = session_accept; |
Willy Tarreau | 3bc1377 | 2008-12-07 11:50:35 +0100 | [diff] [blame] | 7050 | listener->handler = process_session; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 7051 | listener->analysers |= curproxy->fe_req_ana; |
Willy Tarreau | 3bc1377 | 2008-12-07 11:50:35 +0100 | [diff] [blame] | 7052 | |
Willy Tarreau | a5c0ab2 | 2010-05-31 10:30:33 +0200 | [diff] [blame] | 7053 | if (!LIST_ISEMPTY(&curproxy->tcp_req.l4_rules)) |
| 7054 | listener->options |= LI_O_TCP_RULES; |
| 7055 | |
Willy Tarreau | de3041d | 2010-05-31 10:56:17 +0200 | [diff] [blame] | 7056 | if (curproxy->mon_mask.s_addr) |
| 7057 | listener->options |= LI_O_CHK_MONNET; |
| 7058 | |
Willy Tarreau | 9ea05a7 | 2009-06-14 12:07:01 +0200 | [diff] [blame] | 7059 | /* smart accept mode is automatic in HTTP mode */ |
| 7060 | if ((curproxy->options2 & PR_O2_SMARTACC) || |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7061 | ((curproxy->mode == PR_MODE_HTTP || listener->bind_conf->is_ssl) && |
Willy Tarreau | 9ea05a7 | 2009-06-14 12:07:01 +0200 | [diff] [blame] | 7062 | !(curproxy->no_options2 & PR_O2_SMARTACC))) |
| 7063 | listener->options |= LI_O_NOQUICKACK; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 7064 | } |
| 7065 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7066 | /* Release unused SSL configs */ |
| 7067 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
| 7068 | if (bind_conf->is_ssl) |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 7069 | continue; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7070 | #ifdef USE_OPENSSL |
| 7071 | ssl_sock_free_all_ctx(bind_conf); |
Emeric Brun | fb510ea | 2012-10-05 12:00:26 +0200 | [diff] [blame] | 7072 | free(bind_conf->ca_file); |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7073 | free(bind_conf->ciphers); |
Emeric Brun | 2b58d04 | 2012-09-20 17:10:03 +0200 | [diff] [blame] | 7074 | free(bind_conf->ecdhe); |
Emeric Brun | fb510ea | 2012-10-05 12:00:26 +0200 | [diff] [blame] | 7075 | free(bind_conf->crl_file); |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 7076 | #endif /* USE_OPENSSL */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7077 | } |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 7078 | |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 7079 | if (nbproc > 1) { |
| 7080 | if (curproxy->uri_auth) { |
| 7081 | Warning("Proxy '%s': in multi-process mode, stats will be limited to process assigned to the current request.\n", |
| 7082 | curproxy->id); |
| 7083 | if (!LIST_ISEMPTY(&curproxy->uri_auth->admin_rules)) { |
| 7084 | Warning("Proxy '%s': stats admin will not work correctly in multi-process mode.\n", |
| 7085 | curproxy->id); |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 7086 | } |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 7087 | } |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 7088 | if (curproxy->appsession_name) { |
| 7089 | Warning("Proxy '%s': appsession will not work correctly in multi-process mode.\n", |
| 7090 | curproxy->id); |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 7091 | } |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 7092 | if (!LIST_ISEMPTY(&curproxy->sticking_rules)) { |
| 7093 | Warning("Proxy '%s': sticking rules will not work correctly in multi-process mode.\n", |
| 7094 | curproxy->id); |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 7095 | } |
| 7096 | } |
Willy Tarreau | 918ff60 | 2011-07-25 16:33:49 +0200 | [diff] [blame] | 7097 | |
| 7098 | /* create the task associated with the proxy */ |
| 7099 | curproxy->task = task_new(); |
| 7100 | if (curproxy->task) { |
| 7101 | curproxy->task->context = curproxy; |
| 7102 | curproxy->task->process = manage_proxy; |
| 7103 | /* no need to queue, it will be done automatically if some |
| 7104 | * listener gets limited. |
| 7105 | */ |
| 7106 | curproxy->task->expire = TICK_ETERNITY; |
| 7107 | } else { |
| 7108 | Alert("Proxy '%s': no more memory when trying to allocate the management task\n", |
| 7109 | curproxy->id); |
| 7110 | cfgerr++; |
| 7111 | } |
| 7112 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7113 | curproxy = curproxy->next; |
| 7114 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7115 | |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 7116 | /* Check multi-process mode compatibility */ |
Willy Tarreau | 4e5ed29 | 2014-05-13 13:37:54 +0200 | [diff] [blame] | 7117 | if (global.nbproc > 1 && global.stats_fe) { |
Willy Tarreau | 67c2abc | 2014-05-09 18:48:46 +0200 | [diff] [blame] | 7118 | list_for_each_entry(bind_conf, &global.stats_fe->conf.bind, by_fe) { |
| 7119 | unsigned long mask; |
| 7120 | |
| 7121 | mask = nbits(global.nbproc); |
| 7122 | if (global.stats_fe->bind_proc) |
| 7123 | mask &= global.stats_fe->bind_proc; |
| 7124 | |
| 7125 | if (bind_conf->bind_proc) |
| 7126 | mask &= bind_conf->bind_proc; |
| 7127 | |
| 7128 | /* stop here if more than one process is used */ |
| 7129 | if (popcount(mask) > 1) |
| 7130 | break; |
| 7131 | } |
| 7132 | if (&bind_conf->by_fe != &global.stats_fe->conf.bind) { |
| 7133 | 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] | 7134 | } |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 7135 | } |
| 7136 | |
| 7137 | /* automatically compute fullconn if not set. We must not do it in the |
| 7138 | * loop above because cross-references are not yet fully resolved. |
| 7139 | */ |
| 7140 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 7141 | /* If <fullconn> is not set, let's set it to 10% of the sum of |
| 7142 | * the possible incoming frontend's maxconns. |
| 7143 | */ |
| 7144 | if (!curproxy->fullconn && (curproxy->cap & PR_CAP_BE)) { |
| 7145 | struct proxy *fe; |
| 7146 | int total = 0; |
| 7147 | |
| 7148 | /* sum up the number of maxconns of frontends which |
| 7149 | * reference this backend at least once or which are |
| 7150 | * the same one ('listen'). |
| 7151 | */ |
| 7152 | for (fe = proxy; fe; fe = fe->next) { |
| 7153 | struct switching_rule *rule; |
| 7154 | struct hdr_exp *exp; |
| 7155 | int found = 0; |
| 7156 | |
| 7157 | if (!(fe->cap & PR_CAP_FE)) |
| 7158 | continue; |
| 7159 | |
| 7160 | if (fe == curproxy) /* we're on a "listen" instance */ |
| 7161 | found = 1; |
| 7162 | |
| 7163 | if (fe->defbe.be == curproxy) /* "default_backend" */ |
| 7164 | found = 1; |
| 7165 | |
| 7166 | /* check if a "use_backend" rule matches */ |
| 7167 | if (!found) { |
| 7168 | list_for_each_entry(rule, &fe->switching_rules, list) { |
Bertrand Jacquin | 702d44f | 2013-11-19 11:43:06 +0100 | [diff] [blame] | 7169 | if (!rule->dynamic && rule->be.backend == curproxy) { |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 7170 | found = 1; |
| 7171 | break; |
| 7172 | } |
| 7173 | } |
| 7174 | } |
| 7175 | |
| 7176 | /* check if a "reqsetbe" rule matches */ |
| 7177 | for (exp = fe->req_exp; !found && exp; exp = exp->next) { |
| 7178 | if (exp->action == ACT_SETBE && |
| 7179 | (struct proxy *)exp->replace == curproxy) { |
| 7180 | found = 1; |
| 7181 | break; |
| 7182 | } |
| 7183 | } |
| 7184 | |
| 7185 | /* now we've checked all possible ways to reference a backend |
| 7186 | * from a frontend. |
| 7187 | */ |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 7188 | if (!found) |
| 7189 | continue; |
| 7190 | total += fe->maxconn; |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 7191 | } |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 7192 | /* we have the sum of the maxconns in <total>. We only |
| 7193 | * keep 10% of that sum to set the default fullconn, with |
| 7194 | * a hard minimum of 1 (to avoid a divide by zero). |
| 7195 | */ |
| 7196 | curproxy->fullconn = (total + 9) / 10; |
| 7197 | if (!curproxy->fullconn) |
| 7198 | curproxy->fullconn = 1; |
| 7199 | } |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 7200 | } |
| 7201 | |
Willy Tarreau | 056f568 | 2010-06-06 15:51:11 +0200 | [diff] [blame] | 7202 | /* initialize stick-tables on backend capable proxies. This must not |
| 7203 | * be done earlier because the data size may be discovered while parsing |
| 7204 | * other proxies. |
| 7205 | */ |
Godbach | 9703e66 | 2013-12-11 21:11:41 +0800 | [diff] [blame] | 7206 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
Willy Tarreau | 5830213 | 2014-02-24 20:59:47 +0100 | [diff] [blame] | 7207 | if (curproxy->state == PR_STSTOPPED) |
| 7208 | continue; |
| 7209 | |
Godbach | 9703e66 | 2013-12-11 21:11:41 +0800 | [diff] [blame] | 7210 | if (!stktable_init(&curproxy->table)) { |
| 7211 | Alert("Proxy '%s': failed to initialize stick-table.\n", curproxy->id); |
| 7212 | cfgerr++; |
| 7213 | } |
| 7214 | } |
Willy Tarreau | 056f568 | 2010-06-06 15:51:11 +0200 | [diff] [blame] | 7215 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7216 | /* |
| 7217 | * Recount currently required checks. |
| 7218 | */ |
| 7219 | |
| 7220 | for (curproxy=proxy; curproxy; curproxy=curproxy->next) { |
| 7221 | int optnum; |
| 7222 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 7223 | for (optnum = 0; cfg_opts[optnum].name; optnum++) |
| 7224 | if (curproxy->options & cfg_opts[optnum].val) |
| 7225 | global.last_checks |= cfg_opts[optnum].checks; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7226 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 7227 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) |
| 7228 | if (curproxy->options2 & cfg_opts2[optnum].val) |
| 7229 | global.last_checks |= cfg_opts2[optnum].checks; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7230 | } |
| 7231 | |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 7232 | if (peers) { |
| 7233 | struct peers *curpeers = peers, **last; |
| 7234 | struct peer *p, *pb; |
| 7235 | |
| 7236 | /* Remove all peers sections which don't have a valid listener. |
| 7237 | * This can happen when a peers section is never referenced and |
| 7238 | * does not contain a local peer. |
| 7239 | */ |
| 7240 | last = &peers; |
| 7241 | while (*last) { |
| 7242 | curpeers = *last; |
| 7243 | if (curpeers->peers_fe) { |
| 7244 | last = &curpeers->next; |
| 7245 | continue; |
| 7246 | } |
| 7247 | |
| 7248 | Warning("Removing incomplete section 'peers %s' (no peer named '%s').\n", |
| 7249 | curpeers->id, localpeer); |
| 7250 | |
| 7251 | p = curpeers->remote; |
| 7252 | while (p) { |
| 7253 | pb = p->next; |
| 7254 | free(p->id); |
| 7255 | free(p); |
| 7256 | p = pb; |
| 7257 | } |
| 7258 | |
| 7259 | /* Destroy and unlink this curpeers section. |
| 7260 | * Note: curpeers is backed up into *last. |
| 7261 | */ |
| 7262 | free(curpeers->id); |
| 7263 | curpeers = curpeers->next; |
| 7264 | free(*last); |
| 7265 | *last = curpeers; |
| 7266 | } |
| 7267 | } |
| 7268 | |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 7269 | pool2_hdr_idx = create_pool("hdr_idx", |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame] | 7270 | global.tune.max_http_hdr * sizeof(struct hdr_idx_elem), |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 7271 | MEM_F_SHARED); |
| 7272 | |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 7273 | if (cfgerr > 0) |
| 7274 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7275 | out: |
| 7276 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7277 | } |
| 7278 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 7279 | /* |
| 7280 | * Registers the CFG keyword list <kwl> as a list of valid keywords for next |
| 7281 | * parsing sessions. |
| 7282 | */ |
| 7283 | void cfg_register_keywords(struct cfg_kw_list *kwl) |
| 7284 | { |
| 7285 | LIST_ADDQ(&cfg_keywords.list, &kwl->list); |
| 7286 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7287 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 7288 | /* |
| 7289 | * Unregisters the CFG keyword list <kwl> from the list of valid keywords. |
| 7290 | */ |
| 7291 | void cfg_unregister_keywords(struct cfg_kw_list *kwl) |
| 7292 | { |
| 7293 | LIST_DEL(&kwl->list); |
| 7294 | LIST_INIT(&kwl->list); |
| 7295 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7296 | |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 7297 | /* this function register new section in the haproxy configuration file. |
| 7298 | * <section_name> is the name of this new section and <section_parser> |
| 7299 | * is the called parser. If two section declaration have the same name, |
| 7300 | * only the first declared is used. |
| 7301 | */ |
| 7302 | int cfg_register_section(char *section_name, |
| 7303 | int (*section_parser)(const char *, int, char **, int)) |
| 7304 | { |
| 7305 | struct cfg_section *cs; |
| 7306 | |
| 7307 | cs = calloc(1, sizeof(*cs)); |
| 7308 | if (!cs) { |
| 7309 | Alert("register section '%s': out of memory.\n", section_name); |
| 7310 | return 0; |
| 7311 | } |
| 7312 | |
| 7313 | cs->section_name = section_name; |
| 7314 | cs->section_parser = section_parser; |
| 7315 | |
| 7316 | LIST_ADDQ(§ions, &cs->list); |
| 7317 | |
| 7318 | return 1; |
| 7319 | } |
| 7320 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7321 | /* |
| 7322 | * Local variables: |
| 7323 | * c-indent-level: 8 |
| 7324 | * c-basic-offset: 8 |
| 7325 | * End: |
| 7326 | */ |