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 | 1c3a612 | 2015-05-01 15:37:53 +0200 | [diff] [blame] | 154 | { "http-ignore-probes", PR_O_IGNORE_PRB, PR_CAP_FE, 0, PR_MODE_HTTP }, |
Willy Tarreau | 9420b12 | 2013-12-15 18:58:25 +0100 | [diff] [blame] | 155 | { "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] | 156 | { "logasap", PR_O_LOGASAP, PR_CAP_FE, 0, 0 }, |
| 157 | { "nolinger", PR_O_TCP_NOLING, PR_CAP_FE | PR_CAP_BE, 0, 0 }, |
| 158 | { "persist", PR_O_PERSIST, PR_CAP_BE, 0, 0 }, |
| 159 | { "redispatch", PR_O_REDISP, PR_CAP_BE, 0, 0 }, |
| 160 | { "srvtcpka", PR_O_TCP_SRV_KA, PR_CAP_BE, 0, 0 }, |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 161 | #ifdef TPROXY |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 162 | { "transparent", PR_O_TRANSP, PR_CAP_BE, 0, 0 }, |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 163 | #else |
| 164 | { "transparent", 0, 0, 0, 0 }, |
Willy Tarreau | 8f922fc | 2007-01-06 21:11:49 +0100 | [diff] [blame] | 165 | #endif |
| 166 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 167 | { NULL, 0, 0, 0, 0 } |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 168 | }; |
| 169 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 170 | /* proxy->options2 */ |
| 171 | static const struct cfg_opt cfg_opts2[] = |
| 172 | { |
| 173 | #ifdef CONFIG_HAP_LINUX_SPLICE |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 174 | { "splice-request", PR_O2_SPLIC_REQ, PR_CAP_FE|PR_CAP_BE, 0, 0 }, |
| 175 | { "splice-response", PR_O2_SPLIC_RTR, PR_CAP_FE|PR_CAP_BE, 0, 0 }, |
| 176 | { "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] | 177 | #else |
| 178 | { "splice-request", 0, 0, 0, 0 }, |
| 179 | { "splice-response", 0, 0, 0, 0 }, |
| 180 | { "splice-auto", 0, 0, 0, 0 }, |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 181 | #endif |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 182 | { "accept-invalid-http-request", PR_O2_REQBUG_OK, PR_CAP_FE, 0, PR_MODE_HTTP }, |
| 183 | { "accept-invalid-http-response", PR_O2_RSPBUG_OK, PR_CAP_BE, 0, PR_MODE_HTTP }, |
| 184 | { "dontlog-normal", PR_O2_NOLOGNORM, PR_CAP_FE, 0, 0 }, |
| 185 | { "log-separate-errors", PR_O2_LOGERRORS, PR_CAP_FE, 0, 0 }, |
| 186 | { "log-health-checks", PR_O2_LOGHCHKS, PR_CAP_BE, 0, 0 }, |
| 187 | { "socket-stats", PR_O2_SOCKSTAT, PR_CAP_FE, 0, 0 }, |
| 188 | { "tcp-smart-accept", PR_O2_SMARTACC, PR_CAP_FE, 0, 0 }, |
| 189 | { "tcp-smart-connect", PR_O2_SMARTCON, PR_CAP_BE, 0, 0 }, |
| 190 | { "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] | 191 | { "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] | 192 | { "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] | 193 | { "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] | 194 | { "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] | 195 | { NULL, 0, 0, 0 } |
| 196 | }; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 197 | |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 198 | static char *cursection = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 199 | static struct proxy defproxy; /* fake proxy used to assign default values on all instances */ |
| 200 | int cfg_maxpconn = DEFAULT_MAXCONN; /* # of simultaneous connections per proxy (-N) */ |
Willy Tarreau | 5af24ef | 2009-03-15 15:23:16 +0100 | [diff] [blame] | 201 | int cfg_maxconn = 0; /* # of simultaneous connections, (-n) */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 202 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 203 | /* List head of all known configuration keywords */ |
| 204 | static struct cfg_kw_list cfg_keywords = { |
| 205 | .list = LIST_HEAD_INIT(cfg_keywords.list) |
| 206 | }; |
| 207 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 208 | /* |
| 209 | * converts <str> to a list of listeners which are dynamically allocated. |
| 210 | * The format is "{addr|'*'}:port[-end][,{addr|'*'}:port[-end]]*", where : |
| 211 | * - <addr> can be empty or "*" to indicate INADDR_ANY ; |
| 212 | * - <port> is a numerical port from 1 to 65535 ; |
| 213 | * - <end> indicates to use the range from <port> to <end> instead (inclusive). |
| 214 | * 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] | 215 | * Function returns 1 for success or 0 if error. In case of errors, if <err> is |
| 216 | * not NULL, it must be a valid pointer to either NULL or a freeable area that |
| 217 | * will be replaced with an error message. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 218 | */ |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 219 | 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] | 220 | { |
| 221 | struct listener *l; |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 222 | char *next, *dupstr; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 223 | int port, end; |
| 224 | |
| 225 | next = dupstr = strdup(str); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 226 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 227 | while (next && *next) { |
Willy Tarreau | 12eb2a6 | 2013-03-06 15:45:03 +0100 | [diff] [blame] | 228 | struct sockaddr_storage ss, *ss2; |
Willy Tarreau | 40aa070 | 2013-03-10 23:51:38 +0100 | [diff] [blame] | 229 | int fd = -1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 230 | |
| 231 | str = next; |
| 232 | /* 1) look for the end of the first address */ |
Krzysztof Piotr Oledzki | 52d522b | 2009-01-27 16:57:08 +0100 | [diff] [blame] | 233 | if ((next = strchr(str, ',')) != NULL) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 234 | *next++ = 0; |
| 235 | } |
| 236 | |
Willy Tarreau | 12eb2a6 | 2013-03-06 15:45:03 +0100 | [diff] [blame] | 237 | ss2 = str2sa_range(str, &port, &end, err, |
| 238 | curproxy == global.stats_fe ? NULL : global.unix_bind.prefix); |
| 239 | if (!ss2) |
| 240 | goto fail; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 241 | |
Willy Tarreau | 12eb2a6 | 2013-03-06 15:45:03 +0100 | [diff] [blame] | 242 | if (ss2->ss_family == AF_INET || ss2->ss_family == AF_INET6) { |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 243 | if (!port && !end) { |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 244 | memprintf(err, "missing port number: '%s'\n", str); |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 245 | goto fail; |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 246 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 247 | |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 248 | if (!port || !end) { |
| 249 | memprintf(err, "port offsets are not allowed in 'bind': '%s'\n", str); |
| 250 | goto fail; |
| 251 | } |
| 252 | |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 253 | if (port < 1 || port > 65535) { |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 254 | memprintf(err, "invalid port '%d' specified for address '%s'.\n", port, str); |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 255 | goto fail; |
| 256 | } |
| 257 | |
| 258 | if (end < 1 || end > 65535) { |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 259 | memprintf(err, "invalid port '%d' specified for address '%s'.\n", end, str); |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 260 | goto fail; |
| 261 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 262 | } |
Willy Tarreau | 40aa070 | 2013-03-10 23:51:38 +0100 | [diff] [blame] | 263 | else if (ss2->ss_family == AF_UNSPEC) { |
| 264 | socklen_t addr_len; |
| 265 | |
| 266 | /* We want to attach to an already bound fd whose number |
| 267 | * is in the addr part of ss2 when cast to sockaddr_in. |
| 268 | * Note that by definition there is a single listener. |
| 269 | * We still have to determine the address family to |
| 270 | * register the correct protocol. |
| 271 | */ |
| 272 | fd = ((struct sockaddr_in *)ss2)->sin_addr.s_addr; |
| 273 | addr_len = sizeof(*ss2); |
| 274 | if (getsockname(fd, (struct sockaddr *)ss2, &addr_len) == -1) { |
| 275 | memprintf(err, "cannot use file descriptor '%d' : %s.\n", fd, strerror(errno)); |
| 276 | goto fail; |
| 277 | } |
| 278 | |
| 279 | port = end = get_host_port(ss2); |
| 280 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 281 | |
Willy Tarreau | 12eb2a6 | 2013-03-06 15:45:03 +0100 | [diff] [blame] | 282 | /* OK the address looks correct */ |
Vincent Bernat | a72d390 | 2016-05-19 11:15:51 +0200 | [diff] [blame^] | 283 | memcpy(&ss, ss2, sizeof(ss)); |
Willy Tarreau | 12eb2a6 | 2013-03-06 15:45:03 +0100 | [diff] [blame] | 284 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 285 | for (; port <= end; port++) { |
| 286 | l = (struct listener *)calloc(1, sizeof(struct listener)); |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 287 | l->obj_type = OBJ_TYPE_LISTENER; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 288 | LIST_ADDQ(&curproxy->conf.listeners, &l->by_fe); |
| 289 | LIST_ADDQ(&bind_conf->listeners, &l->by_bind); |
| 290 | l->frontend = curproxy; |
| 291 | l->bind_conf = bind_conf; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 292 | |
Willy Tarreau | 40aa070 | 2013-03-10 23:51:38 +0100 | [diff] [blame] | 293 | l->fd = fd; |
Vincent Bernat | a72d390 | 2016-05-19 11:15:51 +0200 | [diff] [blame^] | 294 | memcpy(&l->addr, &ss, sizeof(ss)); |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 295 | l->xprt = &raw_sock; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 296 | l->state = LI_INIT; |
| 297 | |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 298 | if (ss.ss_family == AF_INET) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 299 | ((struct sockaddr_in *)(&l->addr))->sin_port = htons(port); |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 300 | tcpv4_add_listener(l); |
| 301 | } |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 302 | else if (ss.ss_family == AF_INET6) { |
| 303 | ((struct sockaddr_in6 *)(&l->addr))->sin6_port = htons(port); |
| 304 | tcpv6_add_listener(l); |
| 305 | } |
| 306 | else { |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 307 | uxst_add_listener(l); |
| 308 | } |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 309 | |
Willy Tarreau | af7ad00 | 2010-08-31 15:39:26 +0200 | [diff] [blame] | 310 | jobs++; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 311 | listeners++; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 312 | } /* end for(port) */ |
| 313 | } /* end while(next) */ |
| 314 | free(dupstr); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 315 | return 1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 316 | fail: |
| 317 | free(dupstr); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 318 | return 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 319 | } |
| 320 | |
Willy Tarreau | 8b3c808 | 2014-09-16 15:39:51 +0200 | [diff] [blame] | 321 | /* Report a warning if a rule is placed after a 'tcp-request content' rule. |
| 322 | * Return 1 if the warning has been emitted, otherwise 0. |
| 323 | */ |
| 324 | int warnif_rule_after_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg) |
| 325 | { |
| 326 | if (!LIST_ISEMPTY(&proxy->tcp_req.inspect_rules)) { |
| 327 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'tcp-request content' rule will still be processed before.\n", |
| 328 | file, line, arg); |
| 329 | return 1; |
| 330 | } |
| 331 | return 0; |
| 332 | } |
| 333 | |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 334 | /* Report a warning if a rule is placed after a 'block' rule. |
| 335 | * Return 1 if the warning has been emitted, otherwise 0. |
| 336 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 337 | 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] | 338 | { |
Willy Tarreau | 353bc9f | 2014-04-28 22:05:31 +0200 | [diff] [blame] | 339 | if (!LIST_ISEMPTY(&proxy->block_rules)) { |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 340 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'block' rule will still be processed before.\n", |
| 341 | file, line, arg); |
| 342 | return 1; |
| 343 | } |
| 344 | return 0; |
| 345 | } |
| 346 | |
Willy Tarreau | 5002f57 | 2014-04-23 01:32:02 +0200 | [diff] [blame] | 347 | /* Report a warning if a rule is placed after an 'http_request' rule. |
| 348 | * Return 1 if the warning has been emitted, otherwise 0. |
| 349 | */ |
| 350 | int warnif_rule_after_http_req(struct proxy *proxy, const char *file, int line, const char *arg) |
| 351 | { |
| 352 | if (!LIST_ISEMPTY(&proxy->http_req_rules)) { |
| 353 | Warning("parsing [%s:%d] : a '%s' rule placed after an 'http-request' rule will still be processed before.\n", |
| 354 | file, line, arg); |
| 355 | return 1; |
| 356 | } |
| 357 | return 0; |
| 358 | } |
| 359 | |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 360 | /* Report a warning if a rule is placed after a reqrewrite rule. |
| 361 | * Return 1 if the warning has been emitted, otherwise 0. |
| 362 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 363 | 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] | 364 | { |
| 365 | if (proxy->req_exp) { |
| 366 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'reqxxx' rule will still be processed before.\n", |
| 367 | file, line, arg); |
| 368 | return 1; |
| 369 | } |
| 370 | return 0; |
| 371 | } |
| 372 | |
| 373 | /* Report a warning if a rule is placed after a reqadd rule. |
| 374 | * Return 1 if the warning has been emitted, otherwise 0. |
| 375 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 376 | 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] | 377 | { |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 378 | if (!LIST_ISEMPTY(&proxy->req_add)) { |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 379 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'reqadd' rule will still be processed before.\n", |
| 380 | file, line, arg); |
| 381 | return 1; |
| 382 | } |
| 383 | return 0; |
| 384 | } |
| 385 | |
| 386 | /* Report a warning if a rule is placed after a redirect rule. |
| 387 | * Return 1 if the warning has been emitted, otherwise 0. |
| 388 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 389 | 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] | 390 | { |
| 391 | if (!LIST_ISEMPTY(&proxy->redirect_rules)) { |
| 392 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'redirect' rule will still be processed before.\n", |
| 393 | file, line, arg); |
| 394 | return 1; |
| 395 | } |
| 396 | return 0; |
| 397 | } |
| 398 | |
| 399 | /* Report a warning if a rule is placed after a 'use_backend' rule. |
| 400 | * Return 1 if the warning has been emitted, otherwise 0. |
| 401 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 402 | 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] | 403 | { |
| 404 | if (!LIST_ISEMPTY(&proxy->switching_rules)) { |
| 405 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'use_backend' rule will still be processed before.\n", |
| 406 | file, line, arg); |
| 407 | return 1; |
| 408 | } |
| 409 | return 0; |
| 410 | } |
| 411 | |
Willy Tarreau | ee445d9 | 2014-04-23 01:39:04 +0200 | [diff] [blame] | 412 | /* Report a warning if a rule is placed after a 'use-server' rule. |
| 413 | * Return 1 if the warning has been emitted, otherwise 0. |
| 414 | */ |
| 415 | int warnif_rule_after_use_server(struct proxy *proxy, const char *file, int line, const char *arg) |
| 416 | { |
| 417 | if (!LIST_ISEMPTY(&proxy->server_rules)) { |
| 418 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'use-server' rule will still be processed before.\n", |
| 419 | file, line, arg); |
| 420 | return 1; |
| 421 | } |
| 422 | return 0; |
| 423 | } |
| 424 | |
Willy Tarreau | 8b3c808 | 2014-09-16 15:39:51 +0200 | [diff] [blame] | 425 | /* report a warning if a "tcp request connection" rule is dangerously placed */ |
| 426 | int warnif_misplaced_tcp_conn(struct proxy *proxy, const char *file, int line, const char *arg) |
| 427 | { |
| 428 | return warnif_rule_after_tcp_cont(proxy, file, line, arg) || |
| 429 | warnif_rule_after_block(proxy, file, line, arg) || |
| 430 | warnif_rule_after_http_req(proxy, file, line, arg) || |
| 431 | warnif_rule_after_reqxxx(proxy, file, line, arg) || |
| 432 | warnif_rule_after_reqadd(proxy, file, line, arg) || |
| 433 | warnif_rule_after_redirect(proxy, file, line, arg) || |
| 434 | warnif_rule_after_use_backend(proxy, file, line, arg) || |
| 435 | warnif_rule_after_use_server(proxy, file, line, arg); |
| 436 | } |
| 437 | |
| 438 | /* report a warning if a "tcp request content" rule is dangerously placed */ |
| 439 | int warnif_misplaced_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg) |
| 440 | { |
| 441 | return warnif_rule_after_block(proxy, file, line, arg) || |
| 442 | warnif_rule_after_http_req(proxy, file, line, arg) || |
| 443 | warnif_rule_after_reqxxx(proxy, file, line, arg) || |
| 444 | warnif_rule_after_reqadd(proxy, file, line, arg) || |
| 445 | warnif_rule_after_redirect(proxy, file, line, arg) || |
| 446 | warnif_rule_after_use_backend(proxy, file, line, arg) || |
| 447 | warnif_rule_after_use_server(proxy, file, line, arg); |
| 448 | } |
| 449 | |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 450 | /* report a warning if a block rule is dangerously placed */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 451 | 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] | 452 | { |
Willy Tarreau | 5002f57 | 2014-04-23 01:32:02 +0200 | [diff] [blame] | 453 | return warnif_rule_after_http_req(proxy, file, line, arg) || |
| 454 | warnif_rule_after_reqxxx(proxy, file, line, arg) || |
| 455 | warnif_rule_after_reqadd(proxy, file, line, arg) || |
| 456 | warnif_rule_after_redirect(proxy, file, line, arg) || |
Willy Tarreau | ee445d9 | 2014-04-23 01:39:04 +0200 | [diff] [blame] | 457 | warnif_rule_after_use_backend(proxy, file, line, arg) || |
| 458 | warnif_rule_after_use_server(proxy, file, line, arg); |
Willy Tarreau | 5002f57 | 2014-04-23 01:32:02 +0200 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | /* report a warning if an http-request rule is dangerously placed */ |
| 462 | int warnif_misplaced_http_req(struct proxy *proxy, const char *file, int line, const char *arg) |
| 463 | { |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 464 | return warnif_rule_after_reqxxx(proxy, file, line, arg) || |
| 465 | warnif_rule_after_reqadd(proxy, file, line, arg) || |
| 466 | warnif_rule_after_redirect(proxy, file, line, arg) || |
Willy Tarreau | ee445d9 | 2014-04-23 01:39:04 +0200 | [diff] [blame] | 467 | warnif_rule_after_use_backend(proxy, file, line, arg) || |
| 468 | warnif_rule_after_use_server(proxy, file, line, arg); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 469 | } |
| 470 | |
| 471 | /* report a warning if a reqxxx rule is dangerously placed */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 472 | 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] | 473 | { |
| 474 | return warnif_rule_after_reqadd(proxy, file, line, arg) || |
| 475 | warnif_rule_after_redirect(proxy, file, line, arg) || |
Willy Tarreau | ee445d9 | 2014-04-23 01:39:04 +0200 | [diff] [blame] | 476 | warnif_rule_after_use_backend(proxy, file, line, arg) || |
| 477 | warnif_rule_after_use_server(proxy, file, line, arg); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 478 | } |
| 479 | |
| 480 | /* report a warning if a reqadd rule is dangerously placed */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 481 | 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] | 482 | { |
| 483 | return warnif_rule_after_redirect(proxy, file, line, arg) || |
Willy Tarreau | ee445d9 | 2014-04-23 01:39:04 +0200 | [diff] [blame] | 484 | warnif_rule_after_use_backend(proxy, file, line, arg) || |
| 485 | warnif_rule_after_use_server(proxy, file, line, arg); |
| 486 | } |
| 487 | |
| 488 | /* report a warning if a redirect rule is dangerously placed */ |
| 489 | int warnif_misplaced_redirect(struct proxy *proxy, const char *file, int line, const char *arg) |
| 490 | { |
| 491 | return warnif_rule_after_use_backend(proxy, file, line, arg) || |
| 492 | warnif_rule_after_use_server(proxy, file, line, arg); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 493 | } |
| 494 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 495 | /* Report it if a request ACL condition uses some keywords that are incompatible |
| 496 | * with the place where the ACL is used. It returns either 0 or ERR_WARN so that |
| 497 | * its result can be or'ed with err_code. Note that <cond> may be NULL and then |
| 498 | * will be ignored. |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 499 | */ |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 500 | 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] | 501 | { |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 502 | const struct acl *acl; |
Willy Tarreau | 93fddf1 | 2013-03-31 22:59:32 +0200 | [diff] [blame] | 503 | const char *kw; |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 504 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 505 | if (!cond) |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 506 | return 0; |
| 507 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 508 | acl = acl_cond_conflicts(cond, where); |
| 509 | if (acl) { |
| 510 | if (acl->name && *acl->name) |
| 511 | Warning("parsing [%s:%d] : acl '%s' will never match because it only involves keywords that are incompatible with '%s'\n", |
| 512 | file, line, acl->name, sample_ckp_names(where)); |
| 513 | else |
| 514 | 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] | 515 | 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] | 516 | return ERR_WARN; |
| 517 | } |
| 518 | if (!acl_cond_kw_conflicts(cond, where, &acl, &kw)) |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 519 | return 0; |
| 520 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 521 | if (acl->name && *acl->name) |
| 522 | 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] | 523 | file, line, acl->name, kw, sample_ckp_names(where)); |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 524 | else |
| 525 | 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] | 526 | file, line, kw, sample_ckp_names(where)); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 527 | return ERR_WARN; |
| 528 | } |
| 529 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 530 | /* |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 531 | * parse a line in a <global> section. Returns the error code, 0 if OK, or |
| 532 | * any combination of : |
| 533 | * - ERR_ABORT: must abort ASAP |
| 534 | * - ERR_FATAL: we can continue parsing but not start the service |
| 535 | * - ERR_WARN: a warning has been emitted |
| 536 | * - ERR_ALERT: an alert has been emitted |
| 537 | * Only the two first ones can stop processing, the two others are just |
| 538 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 539 | */ |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 540 | 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] | 541 | { |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 542 | int err_code = 0; |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 543 | char *errmsg = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 544 | |
| 545 | if (!strcmp(args[0], "global")) { /* new section */ |
| 546 | /* no option, nothing special to do */ |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 547 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 548 | } |
Emeric Brun | c8e8d12 | 2012-10-02 18:42:10 +0200 | [diff] [blame] | 549 | else if (!strcmp(args[0], "ca-base")) { |
| 550 | #ifdef USE_OPENSSL |
| 551 | if (global.ca_base != NULL) { |
| 552 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 553 | err_code |= ERR_ALERT; |
| 554 | goto out; |
| 555 | } |
| 556 | if (*(args[1]) == 0) { |
| 557 | Alert("parsing [%s:%d] : '%s' expects a directory path as an argument.\n", file, linenum, args[0]); |
| 558 | err_code |= ERR_ALERT | ERR_FATAL; |
| 559 | goto out; |
| 560 | } |
| 561 | global.ca_base = strdup(args[1]); |
| 562 | #else |
| 563 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 564 | err_code |= ERR_ALERT | ERR_FATAL; |
| 565 | goto out; |
| 566 | #endif |
| 567 | } |
| 568 | else if (!strcmp(args[0], "crt-base")) { |
| 569 | #ifdef USE_OPENSSL |
| 570 | if (global.crt_base != NULL) { |
| 571 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 572 | err_code |= ERR_ALERT; |
| 573 | goto out; |
| 574 | } |
| 575 | if (*(args[1]) == 0) { |
| 576 | Alert("parsing [%s:%d] : '%s' expects a directory path as an argument.\n", file, linenum, args[0]); |
| 577 | err_code |= ERR_ALERT | ERR_FATAL; |
| 578 | goto out; |
| 579 | } |
| 580 | global.crt_base = strdup(args[1]); |
| 581 | #else |
| 582 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 583 | err_code |= ERR_ALERT | ERR_FATAL; |
| 584 | goto out; |
| 585 | #endif |
| 586 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 587 | else if (!strcmp(args[0], "daemon")) { |
| 588 | global.mode |= MODE_DAEMON; |
| 589 | } |
| 590 | else if (!strcmp(args[0], "debug")) { |
| 591 | global.mode |= MODE_DEBUG; |
| 592 | } |
| 593 | else if (!strcmp(args[0], "noepoll")) { |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 594 | global.tune.options &= ~GTUNE_USE_EPOLL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 595 | } |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 596 | else if (!strcmp(args[0], "nokqueue")) { |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 597 | global.tune.options &= ~GTUNE_USE_KQUEUE; |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 598 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 599 | else if (!strcmp(args[0], "nopoll")) { |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 600 | global.tune.options &= ~GTUNE_USE_POLL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 601 | } |
Willy Tarreau | 3ab68cf | 2009-01-25 16:03:28 +0100 | [diff] [blame] | 602 | else if (!strcmp(args[0], "nosplice")) { |
| 603 | global.tune.options &= ~GTUNE_USE_SPLICE; |
| 604 | } |
Nenad Merdanovic | 88afe03 | 2014-04-14 15:56:58 +0200 | [diff] [blame] | 605 | else if (!strcmp(args[0], "nogetaddrinfo")) { |
| 606 | global.tune.options &= ~GTUNE_USE_GAI; |
| 607 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 608 | else if (!strcmp(args[0], "quiet")) { |
| 609 | global.mode |= MODE_QUIET; |
| 610 | } |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 611 | else if (!strcmp(args[0], "tune.maxpollevents")) { |
| 612 | if (global.tune.maxpollevents != 0) { |
| 613 | 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] | 614 | err_code |= ERR_ALERT; |
| 615 | goto out; |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 616 | } |
| 617 | if (*(args[1]) == 0) { |
| 618 | 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] | 619 | err_code |= ERR_ALERT | ERR_FATAL; |
| 620 | goto out; |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 621 | } |
| 622 | global.tune.maxpollevents = atol(args[1]); |
| 623 | } |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 624 | else if (!strcmp(args[0], "tune.maxaccept")) { |
| 625 | if (global.tune.maxaccept != 0) { |
| 626 | 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] | 627 | err_code |= ERR_ALERT; |
| 628 | goto out; |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 629 | } |
| 630 | if (*(args[1]) == 0) { |
| 631 | 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] | 632 | err_code |= ERR_ALERT | ERR_FATAL; |
| 633 | goto out; |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 634 | } |
| 635 | global.tune.maxaccept = atol(args[1]); |
| 636 | } |
Willy Tarreau | 43961d5 | 2010-10-04 20:39:20 +0200 | [diff] [blame] | 637 | else if (!strcmp(args[0], "tune.chksize")) { |
| 638 | if (*(args[1]) == 0) { |
| 639 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 640 | err_code |= ERR_ALERT | ERR_FATAL; |
| 641 | goto out; |
| 642 | } |
| 643 | global.tune.chksize = atol(args[1]); |
| 644 | } |
Emeric Brun | fc32aca | 2012-09-03 12:10:29 +0200 | [diff] [blame] | 645 | #ifdef USE_OPENSSL |
Emeric Brun | 8dc6039 | 2014-05-09 13:52:00 +0200 | [diff] [blame] | 646 | else if (!strcmp(args[0], "tune.ssl.force-private-cache")) { |
| 647 | global.tune.sslprivatecache = 1; |
| 648 | } |
Willy Tarreau | 6ec58db | 2012-11-16 16:32:15 +0100 | [diff] [blame] | 649 | else if (!strcmp(args[0], "tune.ssl.cachesize")) { |
Emeric Brun | fc32aca | 2012-09-03 12:10:29 +0200 | [diff] [blame] | 650 | if (*(args[1]) == 0) { |
| 651 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 652 | err_code |= ERR_ALERT | ERR_FATAL; |
| 653 | goto out; |
| 654 | } |
| 655 | global.tune.sslcachesize = atol(args[1]); |
| 656 | } |
Emeric Brun | 4f65bff | 2012-11-16 15:11:00 +0100 | [diff] [blame] | 657 | else if (!strcmp(args[0], "tune.ssl.lifetime")) { |
| 658 | unsigned int ssllifetime; |
| 659 | const char *res; |
| 660 | |
| 661 | if (*(args[1]) == 0) { |
| 662 | Alert("parsing [%s:%d] : '%s' expects ssl sessions <lifetime> in seconds as argument.\n", file, linenum, args[0]); |
| 663 | err_code |= ERR_ALERT | ERR_FATAL; |
| 664 | goto out; |
| 665 | } |
| 666 | |
| 667 | res = parse_time_err(args[1], &ssllifetime, TIME_UNIT_S); |
| 668 | if (res) { |
| 669 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 670 | file, linenum, *res, args[0]); |
| 671 | err_code |= ERR_ALERT | ERR_FATAL; |
| 672 | goto out; |
| 673 | } |
| 674 | |
| 675 | global.tune.ssllifetime = ssllifetime; |
| 676 | } |
Willy Tarreau | bfd5946 | 2013-02-21 07:46:09 +0100 | [diff] [blame] | 677 | else if (!strcmp(args[0], "tune.ssl.maxrecord")) { |
| 678 | if (*(args[1]) == 0) { |
| 679 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 680 | err_code |= ERR_ALERT | ERR_FATAL; |
| 681 | goto out; |
| 682 | } |
| 683 | global.tune.ssl_max_record = atol(args[1]); |
| 684 | } |
Remi Gacogne | f46cd6e | 2014-06-12 14:58:40 +0200 | [diff] [blame] | 685 | else if (!strcmp(args[0], "tune.ssl.default-dh-param")) { |
| 686 | if (*(args[1]) == 0) { |
| 687 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 688 | err_code |= ERR_ALERT | ERR_FATAL; |
| 689 | goto out; |
| 690 | } |
| 691 | global.tune.ssl_default_dh_param = atol(args[1]); |
| 692 | if (global.tune.ssl_default_dh_param < 1024) { |
| 693 | Alert("parsing [%s:%d] : '%s' expects a value >= 1024.\n", file, linenum, args[0]); |
| 694 | err_code |= ERR_ALERT | ERR_FATAL; |
| 695 | goto out; |
| 696 | } |
| 697 | } |
Emeric Brun | fc32aca | 2012-09-03 12:10:29 +0200 | [diff] [blame] | 698 | #endif |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 699 | else if (!strcmp(args[0], "tune.bufsize")) { |
| 700 | if (*(args[1]) == 0) { |
| 701 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 702 | err_code |= ERR_ALERT | ERR_FATAL; |
| 703 | goto out; |
| 704 | } |
| 705 | global.tune.bufsize = atol(args[1]); |
Willy Tarreau | 47c7d63 | 2015-09-28 13:49:53 +0200 | [diff] [blame] | 706 | if (global.tune.bufsize <= 0) { |
| 707 | Alert("parsing [%s:%d] : '%s' expects a positive integer argument.\n", file, linenum, args[0]); |
| 708 | err_code |= ERR_ALERT | ERR_FATAL; |
| 709 | goto out; |
| 710 | } |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 711 | if (global.tune.maxrewrite >= global.tune.bufsize / 2) |
| 712 | global.tune.maxrewrite = global.tune.bufsize / 2; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 713 | chunk_init(&trash, realloc(trash.str, global.tune.bufsize), global.tune.bufsize); |
Willy Tarreau | 2819e99 | 2013-12-13 14:41:10 +0100 | [diff] [blame] | 714 | alloc_trash_buffers(global.tune.bufsize); |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 715 | } |
| 716 | else if (!strcmp(args[0], "tune.maxrewrite")) { |
| 717 | if (*(args[1]) == 0) { |
| 718 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 719 | err_code |= ERR_ALERT | ERR_FATAL; |
| 720 | goto out; |
| 721 | } |
| 722 | global.tune.maxrewrite = atol(args[1]); |
| 723 | if (global.tune.maxrewrite >= global.tune.bufsize / 2) |
| 724 | global.tune.maxrewrite = global.tune.bufsize / 2; |
| 725 | } |
Willy Tarreau | 7e31273 | 2014-02-12 16:35:14 +0100 | [diff] [blame] | 726 | else if (!strcmp(args[0], "tune.idletimer")) { |
| 727 | unsigned int idle; |
| 728 | const char *res; |
| 729 | |
| 730 | if (*(args[1]) == 0) { |
| 731 | Alert("parsing [%s:%d] : '%s' expects a timer value between 0 and 65535 ms.\n", file, linenum, args[0]); |
| 732 | err_code |= ERR_ALERT | ERR_FATAL; |
| 733 | goto out; |
| 734 | } |
| 735 | |
| 736 | res = parse_time_err(args[1], &idle, TIME_UNIT_MS); |
| 737 | if (res) { |
| 738 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 739 | file, linenum, *res, args[0]); |
| 740 | err_code |= ERR_ALERT | ERR_FATAL; |
| 741 | goto out; |
| 742 | } |
| 743 | |
| 744 | if (idle > 65535) { |
| 745 | Alert("parsing [%s:%d] : '%s' expects a timer value between 0 and 65535 ms.\n", file, linenum, args[0]); |
| 746 | err_code |= ERR_ALERT | ERR_FATAL; |
| 747 | goto out; |
| 748 | } |
| 749 | global.tune.idle_timer = idle; |
| 750 | } |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 751 | else if (!strcmp(args[0], "tune.rcvbuf.client")) { |
| 752 | if (global.tune.client_rcvbuf != 0) { |
| 753 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 754 | err_code |= ERR_ALERT; |
| 755 | goto out; |
| 756 | } |
| 757 | if (*(args[1]) == 0) { |
| 758 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 759 | err_code |= ERR_ALERT | ERR_FATAL; |
| 760 | goto out; |
| 761 | } |
| 762 | global.tune.client_rcvbuf = atol(args[1]); |
| 763 | } |
| 764 | else if (!strcmp(args[0], "tune.rcvbuf.server")) { |
| 765 | if (global.tune.server_rcvbuf != 0) { |
| 766 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 767 | err_code |= ERR_ALERT; |
| 768 | goto out; |
| 769 | } |
| 770 | if (*(args[1]) == 0) { |
| 771 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 772 | err_code |= ERR_ALERT | ERR_FATAL; |
| 773 | goto out; |
| 774 | } |
| 775 | global.tune.server_rcvbuf = atol(args[1]); |
| 776 | } |
| 777 | else if (!strcmp(args[0], "tune.sndbuf.client")) { |
| 778 | if (global.tune.client_sndbuf != 0) { |
| 779 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 780 | err_code |= ERR_ALERT; |
| 781 | goto out; |
| 782 | } |
| 783 | if (*(args[1]) == 0) { |
| 784 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 785 | err_code |= ERR_ALERT | ERR_FATAL; |
| 786 | goto out; |
| 787 | } |
| 788 | global.tune.client_sndbuf = atol(args[1]); |
| 789 | } |
| 790 | else if (!strcmp(args[0], "tune.sndbuf.server")) { |
| 791 | if (global.tune.server_sndbuf != 0) { |
| 792 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 793 | err_code |= ERR_ALERT; |
| 794 | goto out; |
| 795 | } |
| 796 | if (*(args[1]) == 0) { |
| 797 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 798 | err_code |= ERR_ALERT | ERR_FATAL; |
| 799 | goto out; |
| 800 | } |
| 801 | global.tune.server_sndbuf = atol(args[1]); |
| 802 | } |
Willy Tarreau | bd9a0a7 | 2011-10-23 21:14:29 +0200 | [diff] [blame] | 803 | else if (!strcmp(args[0], "tune.pipesize")) { |
| 804 | if (*(args[1]) == 0) { |
| 805 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 806 | err_code |= ERR_ALERT | ERR_FATAL; |
| 807 | goto out; |
| 808 | } |
| 809 | global.tune.pipesize = atol(args[1]); |
| 810 | } |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 811 | else if (!strcmp(args[0], "tune.http.cookielen")) { |
| 812 | if (*(args[1]) == 0) { |
| 813 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 814 | err_code |= ERR_ALERT | ERR_FATAL; |
| 815 | goto out; |
| 816 | } |
| 817 | global.tune.cookie_len = atol(args[1]) + 1; |
| 818 | } |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame] | 819 | else if (!strcmp(args[0], "tune.http.maxhdr")) { |
| 820 | if (*(args[1]) == 0) { |
| 821 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 822 | err_code |= ERR_ALERT | ERR_FATAL; |
| 823 | goto out; |
| 824 | } |
| 825 | global.tune.max_http_hdr = atol(args[1]); |
| 826 | } |
William Lallemand | a509e4c | 2012-11-07 16:54:34 +0100 | [diff] [blame] | 827 | else if (!strcmp(args[0], "tune.zlib.memlevel")) { |
| 828 | #ifdef USE_ZLIB |
| 829 | if (*args[1]) { |
| 830 | global.tune.zlibmemlevel = atoi(args[1]); |
| 831 | if (global.tune.zlibmemlevel < 1 || global.tune.zlibmemlevel > 9) { |
| 832 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n", |
| 833 | file, linenum, args[0]); |
| 834 | err_code |= ERR_ALERT | ERR_FATAL; |
| 835 | goto out; |
| 836 | } |
| 837 | } else { |
| 838 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n", |
| 839 | file, linenum, args[0]); |
| 840 | err_code |= ERR_ALERT | ERR_FATAL; |
| 841 | goto out; |
| 842 | } |
| 843 | #else |
| 844 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 845 | err_code |= ERR_ALERT | ERR_FATAL; |
| 846 | goto out; |
| 847 | #endif |
| 848 | } |
| 849 | else if (!strcmp(args[0], "tune.zlib.windowsize")) { |
| 850 | #ifdef USE_ZLIB |
| 851 | if (*args[1]) { |
| 852 | global.tune.zlibwindowsize = atoi(args[1]); |
| 853 | if (global.tune.zlibwindowsize < 8 || global.tune.zlibwindowsize > 15) { |
| 854 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 8 and 15\n", |
| 855 | file, linenum, args[0]); |
| 856 | err_code |= ERR_ALERT | ERR_FATAL; |
| 857 | goto out; |
| 858 | } |
| 859 | } else { |
| 860 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 8 and 15\n", |
| 861 | file, linenum, args[0]); |
| 862 | err_code |= ERR_ALERT | ERR_FATAL; |
| 863 | goto out; |
| 864 | } |
| 865 | #else |
| 866 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 867 | err_code |= ERR_ALERT | ERR_FATAL; |
| 868 | goto out; |
| 869 | #endif |
| 870 | } |
William Lallemand | f374783 | 2012-11-09 12:33:10 +0100 | [diff] [blame] | 871 | else if (!strcmp(args[0], "tune.comp.maxlevel")) { |
| 872 | if (*args[1]) { |
| 873 | global.tune.comp_maxlevel = atoi(args[1]); |
| 874 | if (global.tune.comp_maxlevel < 1 || global.tune.comp_maxlevel > 9) { |
| 875 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n", |
| 876 | file, linenum, args[0]); |
| 877 | err_code |= ERR_ALERT | ERR_FATAL; |
| 878 | goto out; |
| 879 | } |
| 880 | } else { |
| 881 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n", |
| 882 | file, linenum, args[0]); |
| 883 | err_code |= ERR_ALERT | ERR_FATAL; |
| 884 | goto out; |
| 885 | } |
| 886 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 887 | else if (!strcmp(args[0], "uid")) { |
| 888 | if (global.uid != 0) { |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 889 | Alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 890 | err_code |= ERR_ALERT; |
| 891 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 892 | } |
| 893 | if (*(args[1]) == 0) { |
| 894 | 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] | 895 | err_code |= ERR_ALERT | ERR_FATAL; |
| 896 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 897 | } |
Baptiste Assmann | 2b42993 | 2016-03-11 17:10:04 +0100 | [diff] [blame] | 898 | if (strl2irc(args[1], strlen(args[1]), &global.uid) != 0) { |
| 899 | Warning("parsing [%s:%d] : uid: string '%s' is not a number.\n | You might want to use the 'user' parameter to use a system user name.\n", file, linenum, args[1]); |
| 900 | err_code |= ERR_WARN; |
| 901 | goto out; |
| 902 | } |
| 903 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 904 | } |
| 905 | else if (!strcmp(args[0], "gid")) { |
| 906 | if (global.gid != 0) { |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 907 | Alert("parsing [%s:%d] : group/gid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 908 | err_code |= ERR_ALERT; |
| 909 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 910 | } |
| 911 | if (*(args[1]) == 0) { |
| 912 | 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] | 913 | err_code |= ERR_ALERT | ERR_FATAL; |
| 914 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 915 | } |
Baptiste Assmann | d5760be | 2016-03-11 17:21:15 +0100 | [diff] [blame] | 916 | if (strl2irc(args[1], strlen(args[1]), &global.gid) != 0) { |
| 917 | Warning("parsing [%s:%d] : gid: string '%s' is not a number.\n | You might want to use the 'group' parameter to use a system group name.\n", file, linenum, args[1]); |
| 918 | err_code |= ERR_WARN; |
| 919 | goto out; |
| 920 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 921 | } |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 922 | /* user/group name handling */ |
| 923 | else if (!strcmp(args[0], "user")) { |
| 924 | struct passwd *ha_user; |
| 925 | if (global.uid != 0) { |
| 926 | Alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 927 | err_code |= ERR_ALERT; |
| 928 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 929 | } |
| 930 | errno = 0; |
| 931 | ha_user = getpwnam(args[1]); |
| 932 | if (ha_user != NULL) { |
| 933 | global.uid = (int)ha_user->pw_uid; |
| 934 | } |
| 935 | else { |
| 936 | 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] | 937 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 938 | } |
| 939 | } |
| 940 | else if (!strcmp(args[0], "group")) { |
| 941 | struct group *ha_group; |
| 942 | if (global.gid != 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 943 | 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] | 944 | err_code |= ERR_ALERT; |
| 945 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 946 | } |
| 947 | errno = 0; |
| 948 | ha_group = getgrnam(args[1]); |
| 949 | if (ha_group != NULL) { |
| 950 | global.gid = (int)ha_group->gr_gid; |
| 951 | } |
| 952 | else { |
| 953 | 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] | 954 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 955 | } |
| 956 | } |
| 957 | /* end of user/group name handling*/ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 958 | else if (!strcmp(args[0], "nbproc")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 959 | if (*(args[1]) == 0) { |
| 960 | 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] | 961 | err_code |= ERR_ALERT | ERR_FATAL; |
| 962 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 963 | } |
| 964 | global.nbproc = atol(args[1]); |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 965 | if (global.nbproc < 1 || global.nbproc > LONGBITS) { |
| 966 | Alert("parsing [%s:%d] : '%s' must be between 1 and %d (was %d).\n", |
| 967 | file, linenum, args[0], LONGBITS, global.nbproc); |
| 968 | err_code |= ERR_ALERT | ERR_FATAL; |
| 969 | goto out; |
| 970 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 971 | } |
| 972 | else if (!strcmp(args[0], "maxconn")) { |
| 973 | if (global.maxconn != 0) { |
| 974 | 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] | 975 | err_code |= ERR_ALERT; |
| 976 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 977 | } |
| 978 | if (*(args[1]) == 0) { |
| 979 | 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] | 980 | err_code |= ERR_ALERT | ERR_FATAL; |
| 981 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 982 | } |
| 983 | global.maxconn = atol(args[1]); |
| 984 | #ifdef SYSTEM_MAXCONN |
| 985 | if (global.maxconn > DEFAULT_MAXCONN && cfg_maxconn <= DEFAULT_MAXCONN) { |
| 986 | 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); |
| 987 | global.maxconn = DEFAULT_MAXCONN; |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 988 | err_code |= ERR_ALERT; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 989 | } |
| 990 | #endif /* SYSTEM_MAXCONN */ |
| 991 | } |
Willy Tarreau | 403edff | 2012-09-06 11:58:37 +0200 | [diff] [blame] | 992 | else if (!strcmp(args[0], "maxsslconn")) { |
| 993 | #ifdef USE_OPENSSL |
| 994 | if (*(args[1]) == 0) { |
| 995 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 996 | err_code |= ERR_ALERT | ERR_FATAL; |
| 997 | goto out; |
| 998 | } |
| 999 | global.maxsslconn = atol(args[1]); |
| 1000 | #else |
Emeric Brun | 0914df8 | 2012-10-02 18:45:42 +0200 | [diff] [blame] | 1001 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 1002 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1003 | goto out; |
Willy Tarreau | 403edff | 2012-09-06 11:58:37 +0200 | [diff] [blame] | 1004 | #endif |
| 1005 | } |
Willy Tarreau | 610f04b | 2014-02-13 11:36:41 +0100 | [diff] [blame] | 1006 | else if (!strcmp(args[0], "ssl-default-bind-ciphers")) { |
| 1007 | #ifdef USE_OPENSSL |
| 1008 | if (*(args[1]) == 0) { |
| 1009 | Alert("parsing [%s:%d] : '%s' expects a cipher suite as an argument.\n", file, linenum, args[0]); |
| 1010 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1011 | goto out; |
| 1012 | } |
| 1013 | free(global.listen_default_ciphers); |
| 1014 | global.listen_default_ciphers = strdup(args[1]); |
| 1015 | #else |
| 1016 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 1017 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1018 | goto out; |
| 1019 | #endif |
| 1020 | } |
| 1021 | else if (!strcmp(args[0], "ssl-default-server-ciphers")) { |
| 1022 | #ifdef USE_OPENSSL |
| 1023 | if (*(args[1]) == 0) { |
| 1024 | Alert("parsing [%s:%d] : '%s' expects a cipher suite as an argument.\n", file, linenum, args[0]); |
| 1025 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1026 | goto out; |
| 1027 | } |
| 1028 | free(global.connect_default_ciphers); |
| 1029 | global.connect_default_ciphers = strdup(args[1]); |
| 1030 | #else |
| 1031 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 1032 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1033 | goto out; |
| 1034 | #endif |
| 1035 | } |
Emeric Brun | 850efd5 | 2014-01-29 12:24:34 +0100 | [diff] [blame] | 1036 | else if (!strcmp(args[0], "ssl-server-verify")) { |
| 1037 | if (*(args[1]) == 0) { |
| 1038 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1039 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1040 | goto out; |
| 1041 | } |
| 1042 | if (strcmp(args[1],"none") == 0) |
| 1043 | global.ssl_server_verify = SSL_SERVER_VERIFY_NONE; |
| 1044 | else if (strcmp(args[1],"required") == 0) |
| 1045 | global.ssl_server_verify = SSL_SERVER_VERIFY_REQUIRED; |
| 1046 | else { |
| 1047 | Alert("parsing [%s:%d] : '%s' expects 'none' or 'required' as argument.\n", file, linenum, args[0]); |
| 1048 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1049 | goto out; |
| 1050 | } |
| 1051 | } |
Willy Tarreau | 81c25d0 | 2011-09-07 15:17:21 +0200 | [diff] [blame] | 1052 | else if (!strcmp(args[0], "maxconnrate")) { |
| 1053 | if (global.cps_lim != 0) { |
| 1054 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 1055 | err_code |= ERR_ALERT; |
| 1056 | goto out; |
| 1057 | } |
| 1058 | if (*(args[1]) == 0) { |
| 1059 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1060 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1061 | goto out; |
| 1062 | } |
| 1063 | global.cps_lim = atol(args[1]); |
| 1064 | } |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1065 | else if (!strcmp(args[0], "maxsessrate")) { |
| 1066 | if (global.sps_lim != 0) { |
| 1067 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 1068 | err_code |= ERR_ALERT; |
| 1069 | goto out; |
| 1070 | } |
| 1071 | if (*(args[1]) == 0) { |
| 1072 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1073 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1074 | goto out; |
| 1075 | } |
| 1076 | global.sps_lim = atol(args[1]); |
| 1077 | } |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 1078 | else if (!strcmp(args[0], "maxsslrate")) { |
| 1079 | if (global.ssl_lim != 0) { |
| 1080 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 1081 | err_code |= ERR_ALERT; |
| 1082 | goto out; |
| 1083 | } |
| 1084 | if (*(args[1]) == 0) { |
| 1085 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1086 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1087 | goto out; |
| 1088 | } |
| 1089 | global.ssl_lim = atol(args[1]); |
| 1090 | } |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1091 | else if (!strcmp(args[0], "maxcomprate")) { |
| 1092 | if (*(args[1]) == 0) { |
| 1093 | Alert("parsing [%s:%d] : '%s' expects an integer argument in kb/s.\n", file, linenum, args[0]); |
| 1094 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1095 | goto out; |
| 1096 | } |
| 1097 | global.comp_rate_lim = atoi(args[1]) * 1024; |
| 1098 | } |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 1099 | else if (!strcmp(args[0], "maxpipes")) { |
| 1100 | if (global.maxpipes != 0) { |
| 1101 | 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] | 1102 | err_code |= ERR_ALERT; |
| 1103 | goto out; |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 1104 | } |
| 1105 | if (*(args[1]) == 0) { |
| 1106 | 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] | 1107 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1108 | goto out; |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 1109 | } |
| 1110 | global.maxpipes = atol(args[1]); |
| 1111 | } |
William Lallemand | 9d5f548 | 2012-11-07 16:12:57 +0100 | [diff] [blame] | 1112 | else if (!strcmp(args[0], "maxzlibmem")) { |
| 1113 | if (*(args[1]) == 0) { |
| 1114 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1115 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1116 | goto out; |
| 1117 | } |
William Lallemand | e3a7d99 | 2012-11-20 11:25:20 +0100 | [diff] [blame] | 1118 | global.maxzlibmem = atol(args[1]) * 1024L * 1024L; |
William Lallemand | 9d5f548 | 2012-11-07 16:12:57 +0100 | [diff] [blame] | 1119 | } |
William Lallemand | 072a2bf | 2012-11-20 17:01:01 +0100 | [diff] [blame] | 1120 | else if (!strcmp(args[0], "maxcompcpuusage")) { |
| 1121 | if (*(args[1]) == 0) { |
| 1122 | Alert("parsing [%s:%d] : '%s' expects an integer argument between 0 and 100.\n", file, linenum, args[0]); |
| 1123 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1124 | goto out; |
| 1125 | } |
| 1126 | compress_min_idle = 100 - atoi(args[1]); |
Willy Tarreau | cb2699a | 2013-01-24 16:25:38 +0100 | [diff] [blame] | 1127 | if (compress_min_idle > 100) { |
William Lallemand | 072a2bf | 2012-11-20 17:01:01 +0100 | [diff] [blame] | 1128 | Alert("parsing [%s:%d] : '%s' expects an integer argument between 0 and 100.\n", file, linenum, args[0]); |
| 1129 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1130 | goto out; |
| 1131 | } |
| 1132 | } |
| 1133 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1134 | else if (!strcmp(args[0], "ulimit-n")) { |
| 1135 | if (global.rlimit_nofile != 0) { |
| 1136 | 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] | 1137 | err_code |= ERR_ALERT; |
| 1138 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1139 | } |
| 1140 | if (*(args[1]) == 0) { |
| 1141 | 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] | 1142 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1143 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1144 | } |
| 1145 | global.rlimit_nofile = atol(args[1]); |
| 1146 | } |
| 1147 | else if (!strcmp(args[0], "chroot")) { |
| 1148 | if (global.chroot != NULL) { |
| 1149 | 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] | 1150 | err_code |= ERR_ALERT; |
| 1151 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1152 | } |
| 1153 | if (*(args[1]) == 0) { |
| 1154 | 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] | 1155 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1156 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1157 | } |
| 1158 | global.chroot = strdup(args[1]); |
| 1159 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1160 | else if (!strcmp(args[0], "description")) { |
| 1161 | int i, len=0; |
| 1162 | char *d; |
| 1163 | |
| 1164 | if (!*args[1]) { |
| 1165 | Alert("parsing [%s:%d]: '%s' expects a string argument.\n", |
| 1166 | file, linenum, args[0]); |
| 1167 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1168 | goto out; |
| 1169 | } |
| 1170 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 1171 | for (i = 1; *args[i]; i++) |
| 1172 | len += strlen(args[i]) + 1; |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1173 | |
| 1174 | if (global.desc) |
| 1175 | free(global.desc); |
| 1176 | |
| 1177 | global.desc = d = (char *)calloc(1, len); |
| 1178 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 1179 | d += snprintf(d, global.desc + len - d, "%s", args[1]); |
| 1180 | for (i = 2; *args[i]; i++) |
| 1181 | d += snprintf(d, global.desc + len - d, " %s", args[i]); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1182 | } |
| 1183 | else if (!strcmp(args[0], "node")) { |
| 1184 | int i; |
| 1185 | char c; |
| 1186 | |
| 1187 | for (i=0; args[1][i]; i++) { |
| 1188 | c = args[1][i]; |
Willy Tarreau | 88e0581 | 2010-03-03 00:16:00 +0100 | [diff] [blame] | 1189 | if (!isupper((unsigned char)c) && !islower((unsigned char)c) && |
| 1190 | !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.') |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1191 | break; |
| 1192 | } |
| 1193 | |
| 1194 | if (!i || args[1][i]) { |
| 1195 | Alert("parsing [%s:%d]: '%s' requires valid node name - non-empty string" |
| 1196 | " with digits(0-9), letters(A-Z, a-z), dot(.), hyphen(-) or underscode(_).\n", |
| 1197 | file, linenum, args[0]); |
| 1198 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1199 | goto out; |
| 1200 | } |
| 1201 | |
| 1202 | if (global.node) |
| 1203 | free(global.node); |
| 1204 | |
| 1205 | global.node = strdup(args[1]); |
| 1206 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1207 | else if (!strcmp(args[0], "pidfile")) { |
| 1208 | if (global.pidfile != NULL) { |
| 1209 | 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] | 1210 | err_code |= ERR_ALERT; |
| 1211 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1212 | } |
| 1213 | if (*(args[1]) == 0) { |
| 1214 | 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] | 1215 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1216 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1217 | } |
| 1218 | global.pidfile = strdup(args[1]); |
| 1219 | } |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 1220 | else if (!strcmp(args[0], "unix-bind")) { |
| 1221 | int cur_arg = 1; |
| 1222 | while (*(args[cur_arg])) { |
| 1223 | if (!strcmp(args[cur_arg], "prefix")) { |
| 1224 | if (global.unix_bind.prefix != NULL) { |
| 1225 | Alert("parsing [%s:%d] : unix-bind '%s' already specified. Continuing.\n", file, linenum, args[cur_arg]); |
| 1226 | err_code |= ERR_ALERT; |
| 1227 | cur_arg += 2; |
| 1228 | continue; |
| 1229 | } |
| 1230 | |
| 1231 | if (*(args[cur_arg+1]) == 0) { |
| 1232 | Alert("parsing [%s:%d] : unix_bind '%s' expects a path as an argument.\n", file, linenum, args[cur_arg]); |
| 1233 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1234 | goto out; |
| 1235 | } |
| 1236 | global.unix_bind.prefix = strdup(args[cur_arg+1]); |
| 1237 | cur_arg += 2; |
| 1238 | continue; |
| 1239 | } |
| 1240 | |
| 1241 | if (!strcmp(args[cur_arg], "mode")) { |
| 1242 | |
| 1243 | global.unix_bind.ux.mode = strtol(args[cur_arg + 1], NULL, 8); |
| 1244 | cur_arg += 2; |
| 1245 | continue; |
| 1246 | } |
| 1247 | |
| 1248 | if (!strcmp(args[cur_arg], "uid")) { |
| 1249 | |
| 1250 | global.unix_bind.ux.uid = atol(args[cur_arg + 1 ]); |
| 1251 | cur_arg += 2; |
| 1252 | continue; |
| 1253 | } |
| 1254 | |
| 1255 | if (!strcmp(args[cur_arg], "gid")) { |
| 1256 | |
| 1257 | global.unix_bind.ux.gid = atol(args[cur_arg + 1 ]); |
| 1258 | cur_arg += 2; |
| 1259 | continue; |
| 1260 | } |
| 1261 | |
| 1262 | if (!strcmp(args[cur_arg], "user")) { |
| 1263 | struct passwd *user; |
| 1264 | |
| 1265 | user = getpwnam(args[cur_arg + 1]); |
| 1266 | if (!user) { |
| 1267 | Alert("parsing [%s:%d] : '%s' : '%s' unknown user.\n", |
| 1268 | file, linenum, args[0], args[cur_arg + 1 ]); |
| 1269 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1270 | goto out; |
| 1271 | } |
| 1272 | |
| 1273 | global.unix_bind.ux.uid = user->pw_uid; |
| 1274 | cur_arg += 2; |
| 1275 | continue; |
| 1276 | } |
| 1277 | |
| 1278 | if (!strcmp(args[cur_arg], "group")) { |
| 1279 | struct group *group; |
| 1280 | |
| 1281 | group = getgrnam(args[cur_arg + 1]); |
| 1282 | if (!group) { |
| 1283 | Alert("parsing [%s:%d] : '%s' : '%s' unknown group.\n", |
| 1284 | file, linenum, args[0], args[cur_arg + 1 ]); |
| 1285 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1286 | goto out; |
| 1287 | } |
| 1288 | |
| 1289 | global.unix_bind.ux.gid = group->gr_gid; |
| 1290 | cur_arg += 2; |
| 1291 | continue; |
| 1292 | } |
| 1293 | |
Willy Tarreau | b48f958 | 2011-09-05 01:17:06 +0200 | [diff] [blame] | 1294 | 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] | 1295 | file, linenum, args[0]); |
| 1296 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1297 | goto out; |
| 1298 | } |
| 1299 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1300 | else if (!strcmp(args[0], "log") && kwm == KWM_NO) { /* no log */ |
| 1301 | /* delete previous herited or defined syslog servers */ |
| 1302 | struct logsrv *back; |
| 1303 | struct logsrv *tmp; |
| 1304 | |
| 1305 | if (*(args[1]) != 0) { |
| 1306 | Alert("parsing [%s:%d]:%s : 'no log' does not expect arguments.\n", file, linenum, args[1]); |
| 1307 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1308 | goto out; |
| 1309 | } |
| 1310 | |
| 1311 | list_for_each_entry_safe(tmp, back, &global.logsrvs, list) { |
| 1312 | LIST_DEL(&tmp->list); |
| 1313 | free(tmp); |
| 1314 | } |
| 1315 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1316 | else if (!strcmp(args[0], "log")) { /* syslog server address */ |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1317 | struct sockaddr_storage *sk; |
| 1318 | int port1, port2; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1319 | struct logsrv *logsrv; |
Willy Tarreau | dc2695c | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1320 | int arg = 0; |
| 1321 | int len = 0; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1322 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1323 | if (*(args[1]) == 0 || *(args[2]) == 0) { |
| 1324 | 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] | 1325 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1326 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1327 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1328 | |
| 1329 | logsrv = calloc(1, sizeof(struct logsrv)); |
| 1330 | |
Willy Tarreau | dc2695c | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1331 | /* just after the address, a length may be specified */ |
| 1332 | if (strcmp(args[arg+2], "len") == 0) { |
| 1333 | len = atoi(args[arg+3]); |
| 1334 | if (len < 80 || len > 65535) { |
| 1335 | Alert("parsing [%s:%d] : invalid log length '%s', must be between 80 and 65535.\n", |
| 1336 | file, linenum, args[arg+3]); |
| 1337 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1338 | goto out; |
| 1339 | } |
| 1340 | logsrv->maxlen = len; |
| 1341 | |
| 1342 | /* skip these two args */ |
| 1343 | arg += 2; |
| 1344 | } |
| 1345 | else |
| 1346 | logsrv->maxlen = MAX_SYSLOG_LEN; |
| 1347 | |
| 1348 | if (logsrv->maxlen > global.max_syslog_len) { |
| 1349 | global.max_syslog_len = logsrv->maxlen; |
| 1350 | logline = realloc(logline, global.max_syslog_len + 1); |
| 1351 | } |
| 1352 | |
| 1353 | logsrv->facility = get_log_facility(args[arg+2]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1354 | if (logsrv->facility < 0) { |
Willy Tarreau | dc2695c | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1355 | 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] | 1356 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1357 | logsrv->facility = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1358 | } |
| 1359 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1360 | logsrv->level = 7; /* max syslog level = debug */ |
Willy Tarreau | dc2695c | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1361 | if (*(args[arg+3])) { |
| 1362 | logsrv->level = get_log_level(args[arg+3]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1363 | if (logsrv->level < 0) { |
Willy Tarreau | dc2695c | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1364 | 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] | 1365 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1366 | logsrv->level = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1367 | } |
| 1368 | } |
| 1369 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1370 | logsrv->minlvl = 0; /* limit syslog level to this level (emerg) */ |
Willy Tarreau | dc2695c | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1371 | if (*(args[arg+4])) { |
| 1372 | logsrv->minlvl = get_log_level(args[arg+4]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1373 | if (logsrv->minlvl < 0) { |
Willy Tarreau | dc2695c | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1374 | 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] | 1375 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1376 | logsrv->minlvl = 0; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 1377 | } |
| 1378 | } |
| 1379 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1380 | sk = str2sa_range(args[1], &port1, &port2, &errmsg, NULL); |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1381 | if (!sk) { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1382 | Alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1383 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1384 | free(logsrv); |
| 1385 | goto out; |
| 1386 | } |
| 1387 | logsrv->addr = *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 1388 | |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1389 | if (sk->ss_family == AF_INET || sk->ss_family == AF_INET6) { |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 1390 | if (port1 != port2) { |
| 1391 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 1392 | file, linenum, args[0], args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 1393 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1394 | free(logsrv); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 1395 | goto out; |
| 1396 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 1397 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1398 | logsrv->addr = *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 1399 | if (!port1) |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1400 | set_host_port(&logsrv->addr, SYSLOG_PORT); |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 1401 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1402 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1403 | LIST_ADDQ(&global.logsrvs, &logsrv->list); |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1404 | } |
Joe Williams | df5b38f | 2010-12-29 17:05:48 +0100 | [diff] [blame] | 1405 | else if (!strcmp(args[0], "log-send-hostname")) { /* set the hostname in syslog header */ |
| 1406 | char *name; |
| 1407 | int len; |
| 1408 | |
| 1409 | if (global.log_send_hostname != NULL) { |
| 1410 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 1411 | err_code |= ERR_ALERT; |
| 1412 | goto out; |
| 1413 | } |
| 1414 | |
| 1415 | if (*(args[1])) |
| 1416 | name = args[1]; |
| 1417 | else |
| 1418 | name = hostname; |
| 1419 | |
| 1420 | len = strlen(name); |
| 1421 | |
| 1422 | /* We'll add a space after the name to respect the log format */ |
| 1423 | free(global.log_send_hostname); |
| 1424 | global.log_send_hostname = malloc(len + 2); |
| 1425 | snprintf(global.log_send_hostname, len + 2, "%s ", name); |
| 1426 | } |
Kevinm | 48936af | 2010-12-22 16:08:21 +0000 | [diff] [blame] | 1427 | else if (!strcmp(args[0], "log-tag")) { /* tag to report to syslog */ |
| 1428 | if (*(args[1]) == 0) { |
| 1429 | Alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]); |
| 1430 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1431 | goto out; |
| 1432 | } |
| 1433 | free(global.log_tag); |
| 1434 | global.log_tag = strdup(args[1]); |
| 1435 | } |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1436 | else if (!strcmp(args[0], "spread-checks")) { /* random time between checks (0-50) */ |
| 1437 | if (global.spread_checks != 0) { |
| 1438 | Alert("parsing [%s:%d]: spread-checks already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1439 | err_code |= ERR_ALERT; |
| 1440 | goto out; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1441 | } |
| 1442 | if (*(args[1]) == 0) { |
| 1443 | 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] | 1444 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1445 | goto out; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1446 | } |
| 1447 | global.spread_checks = atol(args[1]); |
| 1448 | if (global.spread_checks < 0 || global.spread_checks > 50) { |
| 1449 | 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] | 1450 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1451 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1452 | } |
Willy Tarreau | 1746eec | 2014-04-25 10:46:47 +0200 | [diff] [blame] | 1453 | else if (!strcmp(args[0], "max-spread-checks")) { /* maximum time between first and last check */ |
| 1454 | const char *err; |
| 1455 | unsigned int val; |
| 1456 | |
| 1457 | |
| 1458 | if (*(args[1]) == 0) { |
| 1459 | Alert("parsing [%s:%d]: '%s' expects an integer argument (0..50).\n", file, linenum, args[0]); |
| 1460 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1461 | goto out; |
| 1462 | } |
| 1463 | |
| 1464 | err = parse_time_err(args[1], &val, TIME_UNIT_MS); |
| 1465 | if (err) { |
| 1466 | Alert("parsing [%s:%d]: unsupported character '%c' in '%s' (wants an integer delay).\n", file, linenum, *err, args[0]); |
| 1467 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1468 | } |
| 1469 | global.max_spread_checks = val; |
| 1470 | if (global.max_spread_checks < 0) { |
| 1471 | Alert("parsing [%s:%d]: '%s' needs a positive delay in milliseconds.\n",file, linenum, args[0]); |
| 1472 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1473 | } |
| 1474 | } |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1475 | else if (strcmp(args[0], "cpu-map") == 0) { /* map a process list to a CPU set */ |
| 1476 | #ifdef USE_CPU_AFFINITY |
| 1477 | int cur_arg, i; |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1478 | unsigned long proc = 0; |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1479 | unsigned long cpus = 0; |
| 1480 | |
| 1481 | if (strcmp(args[1], "all") == 0) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1482 | proc = ~0UL; |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1483 | else if (strcmp(args[1], "odd") == 0) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1484 | proc = ~0UL/3UL; /* 0x555....555 */ |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1485 | else if (strcmp(args[1], "even") == 0) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1486 | proc = (~0UL/3UL) << 1; /* 0xAAA...AAA */ |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1487 | else { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1488 | proc = atol(args[1]); |
| 1489 | if (proc >= 1 && proc <= LONGBITS) |
| 1490 | proc = 1UL << (proc - 1); |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1491 | } |
| 1492 | |
| 1493 | if (!proc || !*args[2]) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1494 | 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", |
| 1495 | file, linenum, args[0], LONGBITS, LONGBITS - 1); |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1496 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1497 | goto out; |
| 1498 | } |
| 1499 | |
| 1500 | cur_arg = 2; |
| 1501 | while (*args[cur_arg]) { |
| 1502 | unsigned int low, high; |
| 1503 | |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 1504 | if (isdigit((int)*args[cur_arg])) { |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1505 | char *dash = strchr(args[cur_arg], '-'); |
| 1506 | |
| 1507 | low = high = str2uic(args[cur_arg]); |
| 1508 | if (dash) |
| 1509 | high = str2uic(dash + 1); |
| 1510 | |
| 1511 | if (high < low) { |
| 1512 | unsigned int swap = low; |
| 1513 | low = high; |
| 1514 | high = swap; |
| 1515 | } |
| 1516 | |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1517 | if (high >= LONGBITS) { |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1518 | 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] | 1519 | file, linenum, args[0], LONGBITS - 1); |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1520 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1521 | goto out; |
| 1522 | } |
| 1523 | |
| 1524 | while (low <= high) |
| 1525 | cpus |= 1UL << low++; |
| 1526 | } |
| 1527 | else { |
| 1528 | Alert("parsing [%s:%d]: %s : '%s' is not a CPU range.\n", |
| 1529 | file, linenum, args[0], args[cur_arg]); |
| 1530 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1531 | goto out; |
| 1532 | } |
| 1533 | cur_arg++; |
| 1534 | } |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1535 | for (i = 0; i < LONGBITS; i++) |
| 1536 | if (proc & (1UL << i)) |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1537 | global.cpu_map[i] = cpus; |
| 1538 | #else |
| 1539 | Alert("parsing [%s:%d] : '%s' is not enabled, please check build options for USE_CPU_AFFINITY.\n", file, linenum, args[0]); |
| 1540 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1541 | goto out; |
| 1542 | #endif |
| 1543 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1544 | else { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1545 | struct cfg_kw_list *kwl; |
| 1546 | int index; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1547 | int rc; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1548 | |
| 1549 | list_for_each_entry(kwl, &cfg_keywords.list, list) { |
| 1550 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 1551 | if (kwl->kw[index].section != CFG_GLOBAL) |
| 1552 | continue; |
| 1553 | if (strcmp(kwl->kw[index].kw, args[0]) == 0) { |
Willy Tarreau | 28a47d6 | 2012-09-18 20:02:48 +0200 | [diff] [blame] | 1554 | 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] | 1555 | if (rc < 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 1556 | Alert("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1557 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1558 | } |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1559 | else if (rc > 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 1560 | Warning("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1561 | err_code |= ERR_WARN; |
| 1562 | goto out; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1563 | } |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1564 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1565 | } |
| 1566 | } |
| 1567 | } |
| 1568 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1569 | 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] | 1570 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1571 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1572 | |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1573 | out: |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 1574 | free(errmsg); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1575 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1576 | } |
| 1577 | |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 1578 | void init_default_instance() |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1579 | { |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 1580 | init_new_proxy(&defproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1581 | defproxy.mode = PR_MODE_TCP; |
| 1582 | defproxy.state = PR_STNEW; |
| 1583 | defproxy.maxconn = cfg_maxpconn; |
| 1584 | defproxy.conn_retries = CONN_RETRIES; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1585 | |
Simon Horman | 6618300 | 2013-02-23 10:16:43 +0900 | [diff] [blame] | 1586 | defproxy.defsrv.check.inter = DEF_CHKINTR; |
| 1587 | defproxy.defsrv.check.fastinter = 0; |
| 1588 | defproxy.defsrv.check.downinter = 0; |
Simon Horman | d60d691 | 2013-11-25 10:46:36 +0900 | [diff] [blame] | 1589 | defproxy.defsrv.agent.inter = DEF_CHKINTR; |
| 1590 | defproxy.defsrv.agent.fastinter = 0; |
| 1591 | defproxy.defsrv.agent.downinter = 0; |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 1592 | defproxy.defsrv.check.rise = DEF_RISETIME; |
| 1593 | defproxy.defsrv.check.fall = DEF_FALLTIME; |
| 1594 | defproxy.defsrv.agent.rise = DEF_AGENT_RISETIME; |
| 1595 | defproxy.defsrv.agent.fall = DEF_AGENT_FALLTIME; |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 1596 | defproxy.defsrv.check.port = 0; |
Simon Horman | d60d691 | 2013-11-25 10:46:36 +0900 | [diff] [blame] | 1597 | defproxy.defsrv.agent.port = 0; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1598 | defproxy.defsrv.maxqueue = 0; |
| 1599 | defproxy.defsrv.minconn = 0; |
| 1600 | defproxy.defsrv.maxconn = 0; |
| 1601 | defproxy.defsrv.slowstart = 0; |
| 1602 | defproxy.defsrv.onerror = DEF_HANA_ONERR; |
| 1603 | defproxy.defsrv.consecutive_errors_limit = DEF_HANA_ERRLIMIT; |
| 1604 | defproxy.defsrv.uweight = defproxy.defsrv.iweight = 1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1605 | } |
| 1606 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1607 | |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1608 | /* This function createss a new req* or rsp* rule to the proxy. It compiles the |
| 1609 | * regex and may return the ERR_WARN bit, and error bits such as ERR_ALERT and |
| 1610 | * ERR_FATAL in case of error. |
| 1611 | */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1612 | static int create_cond_regex_rule(const char *file, int line, |
| 1613 | struct proxy *px, int dir, int action, int flags, |
| 1614 | const char *cmd, const char *reg, const char *repl, |
| 1615 | const char **cond_start) |
| 1616 | { |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1617 | struct my_regex *preg = NULL; |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 1618 | char *errmsg = NULL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1619 | const char *err; |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1620 | char *error; |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1621 | int ret_code = 0; |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1622 | struct acl_cond *cond = NULL; |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1623 | int cs; |
| 1624 | int cap; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1625 | |
| 1626 | if (px == &defproxy) { |
| 1627 | 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] | 1628 | ret_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1629 | goto err; |
| 1630 | } |
| 1631 | |
| 1632 | if (*reg == 0) { |
| 1633 | 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] | 1634 | ret_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1635 | goto err; |
| 1636 | } |
| 1637 | |
| 1638 | if (warnifnotcap(px, PR_CAP_RS, file, line, cmd, NULL)) |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1639 | ret_code |= ERR_WARN; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1640 | |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1641 | if (cond_start && |
| 1642 | (strcmp(*cond_start, "if") == 0 || strcmp(*cond_start, "unless") == 0)) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 1643 | if ((cond = build_acl_cond(file, line, px, cond_start, &errmsg)) == NULL) { |
| 1644 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 1645 | file, line, cmd, errmsg); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1646 | ret_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1647 | goto err; |
| 1648 | } |
| 1649 | } |
| 1650 | else if (cond_start && **cond_start) { |
| 1651 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 1652 | file, line, cmd, *cond_start); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1653 | ret_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1654 | goto err; |
| 1655 | } |
| 1656 | |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1657 | ret_code |= warnif_cond_conflicts(cond, |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 1658 | (dir == SMP_OPT_DIR_REQ) ? |
| 1659 | ((px->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR) : |
| 1660 | ((px->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR), |
| 1661 | file, line); |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1662 | |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1663 | preg = calloc(1, sizeof(*preg)); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1664 | if (!preg) { |
| 1665 | 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] | 1666 | ret_code = ERR_ALERT | ERR_FATAL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1667 | goto err; |
| 1668 | } |
| 1669 | |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1670 | cs = !(flags & REG_ICASE); |
| 1671 | cap = !(flags & REG_NOSUB); |
| 1672 | error = NULL; |
| 1673 | if (!regex_comp(reg, preg, cs, cap, &error)) { |
| 1674 | Alert("parsing [%s:%d] : '%s' : regular expression '%s' : %s\n", file, line, cmd, reg, error); |
| 1675 | free(error); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1676 | ret_code = ERR_ALERT | ERR_FATAL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1677 | goto err; |
| 1678 | } |
| 1679 | |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 1680 | 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] | 1681 | preg, action, repl ? strdup(repl) : NULL, cond); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1682 | if (repl && err) { |
| 1683 | Alert("parsing [%s:%d] : '%s' : invalid character or unterminated sequence in replacement string near '%c'.\n", |
| 1684 | file, line, cmd, *err); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1685 | ret_code |= ERR_ALERT | ERR_FATAL; |
| 1686 | goto err_free; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1687 | } |
| 1688 | |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 1689 | 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] | 1690 | ret_code |= ERR_WARN; |
| 1691 | |
| 1692 | return ret_code; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1693 | |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1694 | err_free: |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1695 | regex_free(preg); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1696 | err: |
| 1697 | free(preg); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1698 | free(errmsg); |
| 1699 | return ret_code; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1700 | } |
| 1701 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1702 | /* |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1703 | * Parse a line in a <listen>, <frontend>, <backend> or <ruleset> section. |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1704 | * Returns the error code, 0 if OK, or any combination of : |
| 1705 | * - ERR_ABORT: must abort ASAP |
| 1706 | * - ERR_FATAL: we can continue parsing but not start the service |
| 1707 | * - ERR_WARN: a warning has been emitted |
| 1708 | * - ERR_ALERT: an alert has been emitted |
| 1709 | * Only the two first ones can stop processing, the two others are just |
| 1710 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1711 | */ |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1712 | int cfg_parse_peers(const char *file, int linenum, char **args, int kwm) |
| 1713 | { |
| 1714 | static struct peers *curpeers = NULL; |
| 1715 | struct peer *newpeer = NULL; |
| 1716 | const char *err; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1717 | struct bind_conf *bind_conf; |
| 1718 | struct listener *l; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1719 | int err_code = 0; |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1720 | char *errmsg = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1721 | |
| 1722 | if (strcmp(args[0], "peers") == 0) { /* new peers section */ |
Willy Tarreau | 0dbbf31 | 2013-03-05 11:31:55 +0100 | [diff] [blame] | 1723 | if (!*args[1]) { |
| 1724 | Alert("parsing [%s:%d] : missing name for peers section.\n", file, linenum); |
Willy Tarreau | 5498472 | 2014-02-16 08:20:13 +0100 | [diff] [blame] | 1725 | err_code |= ERR_ALERT | ERR_ABORT; |
Willy Tarreau | 0dbbf31 | 2013-03-05 11:31:55 +0100 | [diff] [blame] | 1726 | goto out; |
| 1727 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1728 | |
| 1729 | err = invalid_char(args[1]); |
| 1730 | if (err) { |
| 1731 | Alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 1732 | file, linenum, *err, args[0], args[1]); |
Willy Tarreau | 5498472 | 2014-02-16 08:20:13 +0100 | [diff] [blame] | 1733 | err_code |= ERR_ALERT | ERR_ABORT; |
Willy Tarreau | 0dbbf31 | 2013-03-05 11:31:55 +0100 | [diff] [blame] | 1734 | goto out; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1735 | } |
| 1736 | |
| 1737 | for (curpeers = peers; curpeers != NULL; curpeers = curpeers->next) { |
| 1738 | /* |
| 1739 | * If there are two proxies with the same name only following |
| 1740 | * combinations are allowed: |
| 1741 | */ |
| 1742 | if (strcmp(curpeers->id, args[1]) == 0) { |
| 1743 | Warning("Parsing [%s:%d]: peers '%s' has same name as another peers (declared at %s:%d).\n", |
| 1744 | file, linenum, args[1], curpeers->conf.file, curpeers->conf.line); |
| 1745 | err_code |= ERR_WARN; |
| 1746 | } |
| 1747 | } |
| 1748 | |
| 1749 | if ((curpeers = (struct peers *)calloc(1, sizeof(struct peers))) == NULL) { |
| 1750 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1751 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1752 | goto out; |
| 1753 | } |
| 1754 | |
| 1755 | curpeers->next = peers; |
| 1756 | peers = curpeers; |
Willy Tarreau | 8113a5d | 2012-10-04 08:01:43 +0200 | [diff] [blame] | 1757 | curpeers->conf.file = strdup(file); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1758 | curpeers->conf.line = linenum; |
| 1759 | curpeers->last_change = now.tv_sec; |
| 1760 | curpeers->id = strdup(args[1]); |
Willy Tarreau | 34d05b0 | 2015-05-01 20:02:17 +0200 | [diff] [blame] | 1761 | curpeers->state = PR_STNEW; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1762 | } |
| 1763 | else if (strcmp(args[0], "peer") == 0) { /* peer definition */ |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 1764 | struct sockaddr_storage *sk; |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 1765 | int port1, port2; |
Willy Tarreau | b36487e | 2013-03-10 18:37:42 +0100 | [diff] [blame] | 1766 | struct protocol *proto; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1767 | |
| 1768 | if (!*args[2]) { |
| 1769 | Alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n", |
| 1770 | file, linenum, args[0]); |
| 1771 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1772 | goto out; |
| 1773 | } |
| 1774 | |
| 1775 | err = invalid_char(args[1]); |
| 1776 | if (err) { |
| 1777 | Alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n", |
| 1778 | file, linenum, *err, args[1]); |
| 1779 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1780 | goto out; |
| 1781 | } |
| 1782 | |
| 1783 | if ((newpeer = (struct peer *)calloc(1, sizeof(struct peer))) == NULL) { |
| 1784 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1785 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1786 | goto out; |
| 1787 | } |
| 1788 | |
| 1789 | /* the peers are linked backwards first */ |
| 1790 | curpeers->count++; |
| 1791 | newpeer->next = curpeers->remote; |
| 1792 | curpeers->remote = newpeer; |
| 1793 | newpeer->peers = curpeers; |
Willy Tarreau | 8113a5d | 2012-10-04 08:01:43 +0200 | [diff] [blame] | 1794 | newpeer->conf.file = strdup(file); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1795 | newpeer->conf.line = linenum; |
| 1796 | |
| 1797 | newpeer->last_change = now.tv_sec; |
| 1798 | newpeer->id = strdup(args[1]); |
| 1799 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1800 | sk = str2sa_range(args[2], &port1, &port2, &errmsg, NULL); |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 1801 | if (!sk) { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1802 | 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] | 1803 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1804 | goto out; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1805 | } |
Willy Tarreau | b36487e | 2013-03-10 18:37:42 +0100 | [diff] [blame] | 1806 | |
| 1807 | proto = protocol_by_family(sk->ss_family); |
| 1808 | if (!proto || !proto->connect) { |
| 1809 | Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 1810 | file, linenum, args[0], args[1]); |
| 1811 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1812 | goto out; |
| 1813 | } |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 1814 | |
| 1815 | if (port1 != port2) { |
| 1816 | Alert("parsing [%s:%d] : '%s %s' : port ranges and offsets are not allowed in '%s'\n", |
| 1817 | file, linenum, args[0], args[1], args[2]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1818 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1819 | goto out; |
| 1820 | } |
| 1821 | |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 1822 | if (!port1) { |
| 1823 | Alert("parsing [%s:%d] : '%s %s' : missing or invalid port in '%s'\n", |
| 1824 | file, linenum, args[0], args[1], args[2]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1825 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1826 | goto out; |
| 1827 | } |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 1828 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1829 | newpeer->addr = *sk; |
Willy Tarreau | b36487e | 2013-03-10 18:37:42 +0100 | [diff] [blame] | 1830 | newpeer->proto = proto; |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 1831 | newpeer->xprt = &raw_sock; |
Willy Tarreau | d02394b | 2012-05-11 18:32:18 +0200 | [diff] [blame] | 1832 | newpeer->sock_init_arg = NULL; |
Willy Tarreau | 26d8c59 | 2012-05-07 18:12:14 +0200 | [diff] [blame] | 1833 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1834 | if (strcmp(newpeer->id, localpeer) == 0) { |
| 1835 | /* Current is local peer, it define a frontend */ |
| 1836 | newpeer->local = 1; |
| 1837 | |
| 1838 | if (!curpeers->peers_fe) { |
| 1839 | if ((curpeers->peers_fe = calloc(1, sizeof(struct proxy))) == NULL) { |
| 1840 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1841 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1842 | goto out; |
| 1843 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1844 | |
Willy Tarreau | 237250c | 2011-07-29 01:49:03 +0200 | [diff] [blame] | 1845 | init_new_proxy(curpeers->peers_fe); |
| 1846 | curpeers->peers_fe->parent = curpeers; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1847 | |
| 1848 | curpeers->peers_fe->last_change = now.tv_sec; |
| 1849 | curpeers->peers_fe->id = strdup(args[1]); |
| 1850 | curpeers->peers_fe->cap = PR_CAP_FE; |
Willy Tarreau | 3ae65a1 | 2011-09-07 17:40:39 +0200 | [diff] [blame] | 1851 | curpeers->peers_fe->maxconn = 0; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1852 | curpeers->peers_fe->conn_retries = CONN_RETRIES; |
Willy Tarreau | fc940eb | 2015-03-13 16:18:25 +0100 | [diff] [blame] | 1853 | curpeers->peers_fe->timeout.client = MS_TO_TICKS(5000); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1854 | curpeers->peers_fe->accept = peer_accept; |
| 1855 | 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] | 1856 | curpeers->peers_fe->conf.args.file = curpeers->peers_fe->conf.file = strdup(file); |
| 1857 | curpeers->peers_fe->conf.args.line = curpeers->peers_fe->conf.line = linenum; |
Willy Tarreau | cdb5e92 | 2015-05-01 19:12:05 +0200 | [diff] [blame] | 1858 | curpeers->peers_fe->bind_proc = 0; /* will be filled by users */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1859 | |
| 1860 | bind_conf = bind_conf_alloc(&curpeers->peers_fe->conf.bind, file, linenum, args[2]); |
| 1861 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1862 | if (!str2listener(args[2], curpeers->peers_fe, bind_conf, file, linenum, &errmsg)) { |
| 1863 | if (errmsg && *errmsg) { |
| 1864 | indent_msg(&errmsg, 2); |
| 1865 | 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] | 1866 | } |
| 1867 | else |
| 1868 | Alert("parsing [%s:%d] : '%s %s' : error encountered while parsing listening address %s.\n", |
| 1869 | file, linenum, args[0], args[1], args[2]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1870 | err_code |= ERR_FATAL; |
| 1871 | goto out; |
| 1872 | } |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1873 | |
| 1874 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
Willy Tarreau | acf3bf9 | 2013-01-18 10:51:07 +0100 | [diff] [blame] | 1875 | l->maxaccept = 1; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1876 | l->maxconn = ((struct proxy *)curpeers->peers_fe)->maxconn; |
| 1877 | l->backlog = ((struct proxy *)curpeers->peers_fe)->backlog; |
| 1878 | l->timeout = &((struct proxy *)curpeers->peers_fe)->timeout.client; |
| 1879 | l->accept = session_accept; |
| 1880 | l->handler = process_session; |
| 1881 | l->analysers |= ((struct proxy *)curpeers->peers_fe)->fe_req_ana; |
| 1882 | l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */ |
| 1883 | global.maxsock += l->maxconn; |
| 1884 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1885 | } |
Willy Tarreau | 8b8fd56 | 2013-01-18 11:12:27 +0100 | [diff] [blame] | 1886 | else { |
| 1887 | Alert("parsing [%s:%d] : '%s %s' : local peer name already referenced at %s:%d.\n", |
| 1888 | file, linenum, args[0], args[1], |
| 1889 | curpeers->peers_fe->conf.file, curpeers->peers_fe->conf.line); |
| 1890 | err_code |= ERR_FATAL; |
| 1891 | goto out; |
| 1892 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1893 | } |
| 1894 | } /* neither "peer" nor "peers" */ |
Willy Tarreau | 34d05b0 | 2015-05-01 20:02:17 +0200 | [diff] [blame] | 1895 | else if (!strcmp(args[0], "disabled")) { /* disables this peers section */ |
| 1896 | curpeers->state = PR_STSTOPPED; |
| 1897 | } |
| 1898 | else if (!strcmp(args[0], "enabled")) { /* enables this peers section (used to revert a disabled default) */ |
| 1899 | curpeers->state = PR_STNEW; |
| 1900 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1901 | else if (*args[0] != 0) { |
| 1902 | Alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection); |
| 1903 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1904 | goto out; |
| 1905 | } |
| 1906 | |
| 1907 | out: |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1908 | free(errmsg); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1909 | return err_code; |
| 1910 | } |
| 1911 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 1912 | 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] | 1913 | { |
| 1914 | static struct proxy *curproxy = NULL; |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 1915 | const char *err; |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1916 | char *error; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 1917 | int rc; |
| 1918 | unsigned val; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1919 | int err_code = 0; |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 1920 | struct acl_cond *cond = NULL; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 1921 | struct logsrv *tmplogsrv; |
Willy Tarreau | f4068b6 | 2012-05-08 17:37:49 +0200 | [diff] [blame] | 1922 | char *errmsg = NULL; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 1923 | struct bind_conf *bind_conf; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1924 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1925 | if (!strcmp(args[0], "listen")) |
| 1926 | rc = PR_CAP_LISTEN; |
| 1927 | else if (!strcmp(args[0], "frontend")) |
| 1928 | rc = PR_CAP_FE | PR_CAP_RS; |
| 1929 | else if (!strcmp(args[0], "backend")) |
| 1930 | rc = PR_CAP_BE | PR_CAP_RS; |
| 1931 | else if (!strcmp(args[0], "ruleset")) |
| 1932 | rc = PR_CAP_RS; |
| 1933 | else |
| 1934 | rc = PR_CAP_NONE; |
| 1935 | |
| 1936 | if (rc != PR_CAP_NONE) { /* new proxy */ |
Willy Tarreau | 7cbc915 | 2014-03-15 08:17:08 +0100 | [diff] [blame] | 1937 | struct ebpt_node *node; |
| 1938 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1939 | if (!*args[1]) { |
| 1940 | Alert("parsing [%s:%d] : '%s' expects an <id> argument and\n" |
| 1941 | " optionnally supports [addr1]:port1[-end1]{,[addr]:port[-end]}...\n", |
| 1942 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1943 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1944 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1945 | } |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 1946 | |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 1947 | err = invalid_char(args[1]); |
| 1948 | if (err) { |
| 1949 | Alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 1950 | file, linenum, *err, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1951 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 1952 | } |
| 1953 | |
Willy Tarreau | 7cbc915 | 2014-03-15 08:17:08 +0100 | [diff] [blame] | 1954 | for (node = ebis_lookup(&proxy_by_name, args[1]); node; node = ebpt_next(node)) { |
| 1955 | curproxy = container_of(node, struct proxy, conf.by_name); |
| 1956 | |
| 1957 | if (strcmp(curproxy->id, args[1]) != 0) |
| 1958 | break; |
| 1959 | |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 1960 | /* |
| 1961 | * If there are two proxies with the same name only following |
| 1962 | * combinations are allowed: |
| 1963 | * |
| 1964 | * listen backend frontend ruleset |
| 1965 | * listen - - - - |
| 1966 | * backend - - OK - |
| 1967 | * frontend - OK - - |
| 1968 | * ruleset - - - - |
| 1969 | */ |
| 1970 | |
Willy Tarreau | 7cbc915 | 2014-03-15 08:17:08 +0100 | [diff] [blame] | 1971 | if ((rc != (PR_CAP_FE|PR_CAP_RS) || curproxy->cap != (PR_CAP_BE|PR_CAP_RS)) && |
| 1972 | (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] | 1973 | Warning("Parsing [%s:%d]: %s '%s' has same name as another %s (declared at %s:%d).\n", |
| 1974 | file, linenum, proxy_cap_str(rc), args[1], proxy_type_str(curproxy), |
| 1975 | curproxy->conf.file, curproxy->conf.line); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1976 | err_code |= ERR_WARN; |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 1977 | } |
| 1978 | } |
| 1979 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1980 | if ((curproxy = (struct proxy *)calloc(1, sizeof(struct proxy))) == NULL) { |
| 1981 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1982 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1983 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1984 | } |
Willy Tarreau | 5af24ef | 2009-03-15 15:23:16 +0100 | [diff] [blame] | 1985 | |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 1986 | init_new_proxy(curproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1987 | curproxy->next = proxy; |
| 1988 | proxy = curproxy; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 1989 | curproxy->conf.args.file = curproxy->conf.file = strdup(file); |
| 1990 | curproxy->conf.args.line = curproxy->conf.line = linenum; |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 1991 | curproxy->last_change = now.tv_sec; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1992 | curproxy->id = strdup(args[1]); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1993 | curproxy->cap = rc; |
Willy Tarreau | f79d950 | 2014-03-15 07:22:35 +0100 | [diff] [blame] | 1994 | proxy_store_name(curproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1995 | |
| 1996 | /* parse the listener address if any */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1997 | if ((curproxy->cap & PR_CAP_FE) && *args[2]) { |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1998 | struct listener *l; |
Willy Tarreau | 81a8117 | 2012-09-18 20:52:35 +0200 | [diff] [blame] | 1999 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2000 | bind_conf = bind_conf_alloc(&curproxy->conf.bind, file, linenum, args[2]); |
| 2001 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 2002 | if (!str2listener(args[2], curproxy, bind_conf, file, linenum, &errmsg)) { |
| 2003 | if (errmsg && *errmsg) { |
| 2004 | indent_msg(&errmsg, 2); |
| 2005 | 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] | 2006 | } |
| 2007 | else |
| 2008 | Alert("parsing [%s:%d] : '%s %s' : error encountered while parsing listening address '%s'.\n", |
| 2009 | file, linenum, args[0], args[1], args[2]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2010 | err_code |= ERR_FATAL; |
| 2011 | goto out; |
| 2012 | } |
Willy Tarreau | 81a8117 | 2012-09-18 20:52:35 +0200 | [diff] [blame] | 2013 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2014 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
Willy Tarreau | c8b1109 | 2011-02-16 11:08:57 +0100 | [diff] [blame] | 2015 | global.maxsock++; |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 2016 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2017 | } |
| 2018 | |
| 2019 | /* set default values */ |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 2020 | memcpy(&curproxy->defsrv, &defproxy.defsrv, sizeof(curproxy->defsrv)); |
Willy Tarreau | 7016020 | 2010-04-07 16:06:40 +0200 | [diff] [blame] | 2021 | curproxy->defsrv.id = "default-server"; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 2022 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2023 | curproxy->state = defproxy.state; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2024 | curproxy->options = defproxy.options; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 2025 | curproxy->options2 = defproxy.options2; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 2026 | curproxy->no_options = defproxy.no_options; |
| 2027 | curproxy->no_options2 = defproxy.no_options2; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2028 | curproxy->bind_proc = defproxy.bind_proc; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 2029 | curproxy->except_net = defproxy.except_net; |
| 2030 | curproxy->except_mask = defproxy.except_mask; |
Maik Broemme | 36db02e | 2009-05-08 17:02:07 +0200 | [diff] [blame] | 2031 | curproxy->except_to = defproxy.except_to; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 2032 | curproxy->except_mask_to = defproxy.except_mask_to; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2033 | |
Willy Tarreau | 79f5fe8 | 2008-08-23 08:18:21 +0200 | [diff] [blame] | 2034 | if (defproxy.fwdfor_hdr_len) { |
| 2035 | curproxy->fwdfor_hdr_len = defproxy.fwdfor_hdr_len; |
| 2036 | curproxy->fwdfor_hdr_name = strdup(defproxy.fwdfor_hdr_name); |
| 2037 | } |
| 2038 | |
Willy Tarreau | b86db34 | 2009-11-30 11:50:16 +0100 | [diff] [blame] | 2039 | if (defproxy.orgto_hdr_len) { |
| 2040 | curproxy->orgto_hdr_len = defproxy.orgto_hdr_len; |
| 2041 | curproxy->orgto_hdr_name = strdup(defproxy.orgto_hdr_name); |
| 2042 | } |
| 2043 | |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 2044 | if (defproxy.server_id_hdr_len) { |
| 2045 | curproxy->server_id_hdr_len = defproxy.server_id_hdr_len; |
| 2046 | curproxy->server_id_hdr_name = strdup(defproxy.server_id_hdr_name); |
| 2047 | } |
| 2048 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2049 | if (curproxy->cap & PR_CAP_FE) { |
| 2050 | curproxy->maxconn = defproxy.maxconn; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 2051 | curproxy->backlog = defproxy.backlog; |
Willy Tarreau | 13a34bd | 2009-05-10 18:52:49 +0200 | [diff] [blame] | 2052 | curproxy->fe_sps_lim = defproxy.fe_sps_lim; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2053 | |
| 2054 | /* initialize error relocations */ |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2055 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) |
| 2056 | chunk_dup(&curproxy->errmsg[rc], &defproxy.errmsg[rc]); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2057 | |
| 2058 | curproxy->to_log = defproxy.to_log & ~LW_COOKIE & ~LW_REQHDR & ~ LW_RSPHDR; |
| 2059 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2060 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2061 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | cac307c | 2014-11-18 15:04:29 +0100 | [diff] [blame] | 2062 | curproxy->lbprm.algo = defproxy.lbprm.algo; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2063 | curproxy->fullconn = defproxy.fullconn; |
| 2064 | curproxy->conn_retries = defproxy.conn_retries; |
Willy Tarreau | c35362a | 2014-04-25 13:58:37 +0200 | [diff] [blame] | 2065 | curproxy->max_ka_queue = defproxy.max_ka_queue; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2066 | |
Willy Tarreau | aa2f389 | 2010-10-22 16:15:31 +0200 | [diff] [blame] | 2067 | if (defproxy.check_req) { |
| 2068 | curproxy->check_req = calloc(1, defproxy.check_len); |
| 2069 | memcpy(curproxy->check_req, defproxy.check_req, defproxy.check_len); |
| 2070 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2071 | curproxy->check_len = defproxy.check_len; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2072 | |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 2073 | if (defproxy.expect_str) { |
| 2074 | curproxy->expect_str = strdup(defproxy.expect_str); |
| 2075 | if (defproxy.expect_regex) { |
| 2076 | /* note: this regex is known to be valid */ |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 2077 | curproxy->expect_regex = calloc(1, sizeof(*curproxy->expect_regex)); |
| 2078 | regex_comp(defproxy.expect_str, curproxy->expect_regex, 1, 1, NULL); |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 2079 | } |
| 2080 | } |
| 2081 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2082 | curproxy->ck_opts = defproxy.ck_opts; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2083 | if (defproxy.cookie_name) |
| 2084 | curproxy->cookie_name = strdup(defproxy.cookie_name); |
| 2085 | curproxy->cookie_len = defproxy.cookie_len; |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 2086 | if (defproxy.cookie_domain) |
| 2087 | curproxy->cookie_domain = strdup(defproxy.cookie_domain); |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 2088 | |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 2089 | if (defproxy.cookie_maxidle) |
| 2090 | curproxy->cookie_maxidle = defproxy.cookie_maxidle; |
| 2091 | |
| 2092 | if (defproxy.cookie_maxlife) |
| 2093 | curproxy->cookie_maxlife = defproxy.cookie_maxlife; |
| 2094 | |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2095 | if (defproxy.rdp_cookie_name) |
| 2096 | curproxy->rdp_cookie_name = strdup(defproxy.rdp_cookie_name); |
| 2097 | curproxy->rdp_cookie_len = defproxy.rdp_cookie_len; |
| 2098 | |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 2099 | if (defproxy.url_param_name) |
| 2100 | curproxy->url_param_name = strdup(defproxy.url_param_name); |
| 2101 | curproxy->url_param_len = defproxy.url_param_len; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 2102 | |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 2103 | if (defproxy.hh_name) |
| 2104 | curproxy->hh_name = strdup(defproxy.hh_name); |
| 2105 | curproxy->hh_len = defproxy.hh_len; |
| 2106 | curproxy->hh_match_domain = defproxy.hh_match_domain; |
| 2107 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 2108 | if (defproxy.conn_src.iface_name) |
| 2109 | curproxy->conn_src.iface_name = strdup(defproxy.conn_src.iface_name); |
| 2110 | curproxy->conn_src.iface_len = defproxy.conn_src.iface_len; |
Godbach | 9f04853 | 2013-04-23 15:27:57 +0800 | [diff] [blame] | 2111 | curproxy->conn_src.opts = defproxy.conn_src.opts; |
Pieter Baauw | d551fb5 | 2013-05-08 22:49:23 +0200 | [diff] [blame] | 2112 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_TRANSPARENT) |
Godbach | 9f04853 | 2013-04-23 15:27:57 +0800 | [diff] [blame] | 2113 | curproxy->conn_src.tproxy_addr = defproxy.conn_src.tproxy_addr; |
Willy Tarreau | c621d36 | 2013-04-25 17:35:22 +0200 | [diff] [blame] | 2114 | #endif |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2115 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2116 | |
Willy Tarreau | 3b6b1a9 | 2009-07-23 13:24:23 +0200 | [diff] [blame] | 2117 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2118 | if (defproxy.capture_name) |
| 2119 | curproxy->capture_name = strdup(defproxy.capture_name); |
| 2120 | curproxy->capture_namelen = defproxy.capture_namelen; |
| 2121 | curproxy->capture_len = defproxy.capture_len; |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 2122 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2123 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2124 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 2125 | curproxy->timeout.client = defproxy.timeout.client; |
Simone Gotti | 1b48cc9 | 2014-06-11 12:25:28 +0200 | [diff] [blame] | 2126 | curproxy->timeout.clientfin = defproxy.timeout.clientfin; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 2127 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | 036fae0 | 2008-01-06 13:24:40 +0100 | [diff] [blame] | 2128 | curproxy->timeout.httpreq = defproxy.timeout.httpreq; |
Willy Tarreau | b16a574 | 2010-01-10 14:46:16 +0100 | [diff] [blame] | 2129 | curproxy->timeout.httpka = defproxy.timeout.httpka; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2130 | curproxy->mon_net = defproxy.mon_net; |
| 2131 | curproxy->mon_mask = defproxy.mon_mask; |
| 2132 | if (defproxy.monitor_uri) |
| 2133 | curproxy->monitor_uri = strdup(defproxy.monitor_uri); |
| 2134 | curproxy->monitor_uri_len = defproxy.monitor_uri_len; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 2135 | if (defproxy.defbe.name) |
| 2136 | curproxy->defbe.name = strdup(defproxy.defbe.name); |
Willy Tarreau | 99a7ca2 | 2012-05-31 19:39:23 +0200 | [diff] [blame] | 2137 | |
| 2138 | /* 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] | 2139 | curproxy->conf.logformat_string = defproxy.conf.logformat_string; |
| 2140 | if (curproxy->conf.logformat_string && |
| 2141 | curproxy->conf.logformat_string != default_http_log_format && |
| 2142 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 2143 | curproxy->conf.logformat_string != clf_http_log_format) |
| 2144 | curproxy->conf.logformat_string = strdup(curproxy->conf.logformat_string); |
| 2145 | |
| 2146 | if (defproxy.conf.lfs_file) { |
| 2147 | curproxy->conf.lfs_file = strdup(defproxy.conf.lfs_file); |
| 2148 | curproxy->conf.lfs_line = defproxy.conf.lfs_line; |
| 2149 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2150 | } |
| 2151 | |
| 2152 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 2153 | curproxy->timeout.connect = defproxy.timeout.connect; |
| 2154 | curproxy->timeout.server = defproxy.timeout.server; |
Simone Gotti | 1b48cc9 | 2014-06-11 12:25:28 +0200 | [diff] [blame] | 2155 | curproxy->timeout.serverfin = defproxy.timeout.serverfin; |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 2156 | curproxy->timeout.check = defproxy.timeout.check; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 2157 | curproxy->timeout.queue = defproxy.timeout.queue; |
Willy Tarreau | 51c9bde | 2008-01-06 13:40:03 +0100 | [diff] [blame] | 2158 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | cd7afc0 | 2009-07-12 10:03:17 +0200 | [diff] [blame] | 2159 | curproxy->timeout.httpreq = defproxy.timeout.httpreq; |
Willy Tarreau | b16a574 | 2010-01-10 14:46:16 +0100 | [diff] [blame] | 2160 | curproxy->timeout.httpka = defproxy.timeout.httpka; |
Willy Tarreau | ce887fd | 2012-05-12 12:50:00 +0200 | [diff] [blame] | 2161 | curproxy->timeout.tunnel = defproxy.timeout.tunnel; |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 2162 | curproxy->conn_src.source_addr = defproxy.conn_src.source_addr; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2163 | } |
| 2164 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2165 | curproxy->mode = defproxy.mode; |
Willy Tarreau | ed2119c | 2014-04-24 22:10:39 +0200 | [diff] [blame] | 2166 | curproxy->uri_auth = defproxy.uri_auth; /* for stats */ |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 2167 | |
| 2168 | /* copy default logsrvs to curproxy */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 2169 | list_for_each_entry(tmplogsrv, &defproxy.logsrvs, list) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 2170 | struct logsrv *node = malloc(sizeof(struct logsrv)); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 2171 | memcpy(node, tmplogsrv, sizeof(struct logsrv)); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 2172 | LIST_INIT(&node->list); |
| 2173 | LIST_ADDQ(&curproxy->logsrvs, &node->list); |
| 2174 | } |
| 2175 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 2176 | curproxy->conf.uniqueid_format_string = defproxy.conf.uniqueid_format_string; |
| 2177 | if (curproxy->conf.uniqueid_format_string) |
| 2178 | curproxy->conf.uniqueid_format_string = strdup(curproxy->conf.uniqueid_format_string); |
| 2179 | |
| 2180 | if (defproxy.conf.uif_file) { |
| 2181 | curproxy->conf.uif_file = strdup(defproxy.conf.uif_file); |
| 2182 | curproxy->conf.uif_line = defproxy.conf.uif_line; |
| 2183 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 2184 | |
| 2185 | /* copy default header unique id */ |
| 2186 | if (defproxy.header_unique_id) |
| 2187 | curproxy->header_unique_id = strdup(defproxy.header_unique_id); |
| 2188 | |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 2189 | /* default compression options */ |
| 2190 | if (defproxy.comp != NULL) { |
| 2191 | curproxy->comp = calloc(1, sizeof(struct comp)); |
| 2192 | curproxy->comp->algos = defproxy.comp->algos; |
| 2193 | curproxy->comp->types = defproxy.comp->types; |
| 2194 | } |
| 2195 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2196 | curproxy->grace = defproxy.grace; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2197 | curproxy->conf.used_listener_id = EB_ROOT; |
| 2198 | curproxy->conf.used_server_id = EB_ROOT; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2199 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2200 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2201 | } |
| 2202 | else if (!strcmp(args[0], "defaults")) { /* use this one to assign default values */ |
| 2203 | /* some variables may have already been initialized earlier */ |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 2204 | /* FIXME-20070101: we should do this too at the end of the |
| 2205 | * config parsing to free all default values. |
| 2206 | */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2207 | free(defproxy.check_req); |
| 2208 | free(defproxy.cookie_name); |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2209 | free(defproxy.rdp_cookie_name); |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 2210 | free(defproxy.cookie_domain); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2211 | free(defproxy.url_param_name); |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 2212 | free(defproxy.hh_name); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2213 | free(defproxy.capture_name); |
| 2214 | free(defproxy.monitor_uri); |
| 2215 | free(defproxy.defbe.name); |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 2216 | free(defproxy.conn_src.iface_name); |
Willy Tarreau | 79f5fe8 | 2008-08-23 08:18:21 +0200 | [diff] [blame] | 2217 | free(defproxy.fwdfor_hdr_name); |
| 2218 | defproxy.fwdfor_hdr_len = 0; |
Willy Tarreau | b86db34 | 2009-11-30 11:50:16 +0100 | [diff] [blame] | 2219 | free(defproxy.orgto_hdr_name); |
| 2220 | defproxy.orgto_hdr_len = 0; |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 2221 | free(defproxy.server_id_hdr_name); |
| 2222 | defproxy.server_id_hdr_len = 0; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 2223 | free(defproxy.expect_str); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 2224 | if (defproxy.expect_regex) { |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 2225 | regex_free(defproxy.expect_regex); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 2226 | free(defproxy.expect_regex); |
| 2227 | defproxy.expect_regex = NULL; |
| 2228 | } |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 2229 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 2230 | if (defproxy.conf.logformat_string != default_http_log_format && |
| 2231 | defproxy.conf.logformat_string != default_tcp_log_format && |
| 2232 | defproxy.conf.logformat_string != clf_http_log_format) |
| 2233 | free(defproxy.conf.logformat_string); |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 2234 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 2235 | free(defproxy.conf.uniqueid_format_string); |
| 2236 | free(defproxy.conf.lfs_file); |
| 2237 | free(defproxy.conf.uif_file); |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 2238 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2239 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2240 | chunk_destroy(&defproxy.errmsg[rc]); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 2241 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2242 | /* we cannot free uri_auth because it might already be used */ |
| 2243 | init_default_instance(); |
| 2244 | curproxy = &defproxy; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 2245 | curproxy->conf.args.file = curproxy->conf.file = strdup(file); |
| 2246 | curproxy->conf.args.line = curproxy->conf.line = linenum; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2247 | defproxy.cap = PR_CAP_LISTEN; /* all caps for now */ |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2248 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2249 | } |
| 2250 | else if (curproxy == NULL) { |
| 2251 | Alert("parsing [%s:%d] : 'listen' or 'defaults' expected.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2252 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2253 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2254 | } |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 2255 | |
| 2256 | /* update the current file and line being parsed */ |
| 2257 | curproxy->conf.args.file = curproxy->conf.file; |
| 2258 | curproxy->conf.args.line = linenum; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2259 | |
| 2260 | /* Now let's parse the proxy-specific keywords */ |
Willy Tarreau | 272adea | 2014-03-31 10:39:59 +0200 | [diff] [blame] | 2261 | if (!strcmp(args[0], "server") || !strcmp(args[0], "default-server")) { |
| 2262 | err_code |= parse_server(file, linenum, args, curproxy, &defproxy); |
| 2263 | if (err_code & ERR_FATAL) |
| 2264 | goto out; |
| 2265 | } |
| 2266 | else if (!strcmp(args[0], "bind")) { /* new listen addresses */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2267 | struct listener *l; |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 2268 | int cur_arg; |
| 2269 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2270 | if (curproxy == &defproxy) { |
| 2271 | 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] | 2272 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2273 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2274 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2275 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2276 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2277 | |
Willy Tarreau | 2470928 | 2013-03-10 21:32:12 +0100 | [diff] [blame] | 2278 | if (!*(args[1])) { |
Willy Tarreau | d55c3fe | 2010-11-09 09:50:37 +0100 | [diff] [blame] | 2279 | 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] | 2280 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2281 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2282 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2283 | } |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 2284 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 2285 | bind_conf = bind_conf_alloc(&curproxy->conf.bind, file, linenum, args[1]); |
Willy Tarreau | 8dc21fa | 2013-01-24 15:17:20 +0100 | [diff] [blame] | 2286 | |
| 2287 | /* use default settings for unix sockets */ |
| 2288 | bind_conf->ux.uid = global.unix_bind.ux.uid; |
| 2289 | bind_conf->ux.gid = global.unix_bind.ux.gid; |
| 2290 | bind_conf->ux.mode = global.unix_bind.ux.mode; |
Willy Tarreau | 8a95691 | 2010-10-15 14:27:08 +0200 | [diff] [blame] | 2291 | |
| 2292 | /* NOTE: the following line might create several listeners if there |
| 2293 | * are comma-separated IPs or port ranges. So all further processing |
| 2294 | * will have to be applied to all listeners created after last_listen. |
| 2295 | */ |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 2296 | if (!str2listener(args[1], curproxy, bind_conf, file, linenum, &errmsg)) { |
| 2297 | if (errmsg && *errmsg) { |
| 2298 | indent_msg(&errmsg, 2); |
| 2299 | Alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 2300 | } |
| 2301 | else |
| 2302 | Alert("parsing [%s:%d] : '%s' : error encountered while parsing listening address '%s'.\n", |
| 2303 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2304 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2305 | goto out; |
| 2306 | } |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 2307 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2308 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
| 2309 | /* Set default global rights and owner for unix bind */ |
Willy Tarreau | c8b1109 | 2011-02-16 11:08:57 +0100 | [diff] [blame] | 2310 | global.maxsock++; |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 2311 | } |
| 2312 | |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 2313 | cur_arg = 2; |
| 2314 | while (*(args[cur_arg])) { |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 2315 | static int bind_dumped; |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 2316 | struct bind_kw *kw; |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 2317 | char *err; |
| 2318 | |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 2319 | kw = bind_find_kw(args[cur_arg]); |
| 2320 | if (kw) { |
| 2321 | char *err = NULL; |
| 2322 | int code; |
| 2323 | |
| 2324 | if (!kw->parse) { |
Willy Tarreau | dda322d | 2012-09-18 16:34:09 +0200 | [diff] [blame] | 2325 | Alert("parsing [%s:%d] : '%s %s' : '%s' option is not implemented in this version (check build options).\n", |
| 2326 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 2327 | cur_arg += 1 + kw->skip ; |
| 2328 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2329 | goto out; |
| 2330 | } |
| 2331 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2332 | code = kw->parse(args, cur_arg, curproxy, bind_conf, &err); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 2333 | err_code |= code; |
| 2334 | |
| 2335 | if (code) { |
| 2336 | if (err && *err) { |
| 2337 | indent_msg(&err, 2); |
Willy Tarreau | dda322d | 2012-09-18 16:34:09 +0200 | [diff] [blame] | 2338 | 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] | 2339 | } |
| 2340 | else |
Willy Tarreau | dda322d | 2012-09-18 16:34:09 +0200 | [diff] [blame] | 2341 | Alert("parsing [%s:%d] : '%s %s' : error encountered while processing '%s'.\n", |
| 2342 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 2343 | if (code & ERR_FATAL) { |
| 2344 | free(err); |
| 2345 | cur_arg += 1 + kw->skip; |
| 2346 | goto out; |
| 2347 | } |
| 2348 | } |
| 2349 | free(err); |
| 2350 | cur_arg += 1 + kw->skip; |
| 2351 | continue; |
| 2352 | } |
| 2353 | |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 2354 | err = NULL; |
| 2355 | if (!bind_dumped) { |
| 2356 | bind_dump_kws(&err); |
| 2357 | indent_msg(&err, 4); |
| 2358 | bind_dumped = 1; |
| 2359 | } |
| 2360 | |
| 2361 | Alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'.%s%s\n", |
| 2362 | file, linenum, args[0], args[1], args[cur_arg], |
| 2363 | err ? " Registered keywords :" : "", err ? err : ""); |
| 2364 | free(err); |
| 2365 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2366 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2367 | goto out; |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 2368 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2369 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2370 | } |
| 2371 | 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] | 2372 | 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] | 2373 | Alert("parsing [%s:%d] : '%s' expects address[/mask].\n", |
| 2374 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2375 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2376 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2377 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2378 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2379 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2380 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2381 | /* flush useless bits */ |
| 2382 | curproxy->mon_net.s_addr &= curproxy->mon_mask.s_addr; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2383 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2384 | } |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2385 | else if (!strcmp(args[0], "monitor-uri")) { /* set the URI to intercept */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2386 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2387 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2388 | |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2389 | if (!*args[1]) { |
| 2390 | Alert("parsing [%s:%d] : '%s' expects an URI.\n", |
| 2391 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2392 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2393 | goto out; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2394 | } |
| 2395 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2396 | free(curproxy->monitor_uri); |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 2397 | curproxy->monitor_uri_len = strlen(args[1]); |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2398 | curproxy->monitor_uri = (char *)calloc(1, curproxy->monitor_uri_len + 1); |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 2399 | memcpy(curproxy->monitor_uri, args[1], curproxy->monitor_uri_len); |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2400 | curproxy->monitor_uri[curproxy->monitor_uri_len] = '\0'; |
| 2401 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2402 | goto out; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2403 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2404 | else if (!strcmp(args[0], "mode")) { /* sets the proxy mode */ |
| 2405 | if (!strcmp(args[1], "http")) curproxy->mode = PR_MODE_HTTP; |
| 2406 | else if (!strcmp(args[1], "tcp")) curproxy->mode = PR_MODE_TCP; |
| 2407 | else if (!strcmp(args[1], "health")) curproxy->mode = PR_MODE_HEALTH; |
| 2408 | else { |
| 2409 | 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] | 2410 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2411 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2412 | } |
| 2413 | } |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2414 | else if (!strcmp(args[0], "id")) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2415 | struct eb32_node *node; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2416 | |
| 2417 | if (curproxy == &defproxy) { |
| 2418 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", |
| 2419 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2420 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2421 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2422 | } |
| 2423 | |
| 2424 | if (!*args[1]) { |
| 2425 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 2426 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2427 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2428 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2429 | } |
| 2430 | |
| 2431 | curproxy->uuid = atol(args[1]); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2432 | curproxy->conf.id.key = curproxy->uuid; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2433 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2434 | if (curproxy->uuid <= 0) { |
| 2435 | Alert("parsing [%s:%d]: custom id has to be > 0.\n", |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2436 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2437 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2438 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2439 | } |
| 2440 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2441 | node = eb32_lookup(&used_proxy_id, curproxy->uuid); |
| 2442 | if (node) { |
| 2443 | struct proxy *target = container_of(node, struct proxy, conf.id); |
| 2444 | Alert("parsing [%s:%d]: %s %s reuses same custom id as %s %s (declared at %s:%d).\n", |
| 2445 | file, linenum, proxy_type_str(curproxy), curproxy->id, |
| 2446 | proxy_type_str(target), target->id, target->conf.file, target->conf.line); |
| 2447 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2448 | goto out; |
| 2449 | } |
| 2450 | eb32_insert(&used_proxy_id, &curproxy->conf.id); |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2451 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 2452 | else if (!strcmp(args[0], "description")) { |
| 2453 | int i, len=0; |
| 2454 | char *d; |
| 2455 | |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 2456 | if (curproxy == &defproxy) { |
| 2457 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", |
| 2458 | file, linenum, args[0]); |
| 2459 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2460 | goto out; |
| 2461 | } |
| 2462 | |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 2463 | if (!*args[1]) { |
| 2464 | Alert("parsing [%s:%d]: '%s' expects a string argument.\n", |
| 2465 | file, linenum, args[0]); |
| 2466 | return -1; |
| 2467 | } |
| 2468 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 2469 | for (i = 1; *args[i]; i++) |
| 2470 | len += strlen(args[i]) + 1; |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 2471 | |
| 2472 | d = (char *)calloc(1, len); |
| 2473 | curproxy->desc = d; |
| 2474 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 2475 | d += snprintf(d, curproxy->desc + len - d, "%s", args[1]); |
| 2476 | for (i = 2; *args[i]; i++) |
| 2477 | d += snprintf(d, curproxy->desc + len - d, " %s", args[i]); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 2478 | |
| 2479 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2480 | else if (!strcmp(args[0], "disabled")) { /* disables this proxy */ |
| 2481 | curproxy->state = PR_STSTOPPED; |
| 2482 | } |
| 2483 | else if (!strcmp(args[0], "enabled")) { /* enables this proxy (used to revert a disabled default) */ |
| 2484 | curproxy->state = PR_STNEW; |
| 2485 | } |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2486 | else if (!strcmp(args[0], "bind-process")) { /* enable this proxy only on some processes */ |
| 2487 | int cur_arg = 1; |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 2488 | unsigned long set = 0; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2489 | |
| 2490 | while (*args[cur_arg]) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 2491 | unsigned int low, high; |
| 2492 | |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2493 | if (strcmp(args[cur_arg], "all") == 0) { |
| 2494 | set = 0; |
| 2495 | break; |
| 2496 | } |
| 2497 | else if (strcmp(args[cur_arg], "odd") == 0) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 2498 | set |= ~0UL/3UL; /* 0x555....555 */ |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2499 | } |
| 2500 | else if (strcmp(args[cur_arg], "even") == 0) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 2501 | set |= (~0UL/3UL) << 1; /* 0xAAA...AAA */ |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2502 | } |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 2503 | else if (isdigit((int)*args[cur_arg])) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 2504 | char *dash = strchr(args[cur_arg], '-'); |
| 2505 | |
| 2506 | low = high = str2uic(args[cur_arg]); |
| 2507 | if (dash) |
| 2508 | high = str2uic(dash + 1); |
| 2509 | |
| 2510 | if (high < low) { |
| 2511 | unsigned int swap = low; |
| 2512 | low = high; |
| 2513 | high = swap; |
| 2514 | } |
| 2515 | |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 2516 | if (low < 1 || high > LONGBITS) { |
| 2517 | Alert("parsing [%s:%d]: %s supports process numbers from 1 to %d.\n", |
| 2518 | file, linenum, args[0], LONGBITS); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2519 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2520 | goto out; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2521 | } |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 2522 | while (low <= high) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 2523 | set |= 1UL << (low++ - 1); |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 2524 | } |
| 2525 | else { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 2526 | Alert("parsing [%s:%d]: %s expects 'all', 'odd', 'even', or a list of process ranges with numbers from 1 to %d.\n", |
| 2527 | file, linenum, args[0], LONGBITS); |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 2528 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2529 | goto out; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2530 | } |
| 2531 | cur_arg++; |
| 2532 | } |
| 2533 | curproxy->bind_proc = set; |
| 2534 | } |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 2535 | else if (!strcmp(args[0], "acl")) { /* add an ACL */ |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2536 | if (curproxy == &defproxy) { |
| 2537 | 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] | 2538 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2539 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2540 | } |
| 2541 | |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 2542 | err = invalid_char(args[1]); |
| 2543 | if (err) { |
| 2544 | Alert("parsing [%s:%d] : character '%c' is not permitted in acl name '%s'.\n", |
| 2545 | file, linenum, *err, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2546 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 2547 | } |
| 2548 | |
Thierry FOURNIER | 0d6ba51 | 2014-02-11 03:31:34 +0100 | [diff] [blame] | 2549 | 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] | 2550 | Alert("parsing [%s:%d] : error detected while parsing ACL '%s' : %s.\n", |
| 2551 | file, linenum, args[1], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2552 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2553 | goto out; |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 2554 | } |
| 2555 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2556 | else if (!strcmp(args[0], "cookie")) { /* cookie name */ |
| 2557 | int cur_arg; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2558 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2559 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2560 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2561 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2562 | if (*(args[1]) == 0) { |
| 2563 | Alert("parsing [%s:%d] : '%s' expects <cookie_name> as argument.\n", |
| 2564 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2565 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2566 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2567 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2568 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2569 | curproxy->ck_opts = 0; |
Willy Tarreau | c63d4bb | 2010-10-23 11:37:27 +0200 | [diff] [blame] | 2570 | curproxy->cookie_maxidle = curproxy->cookie_maxlife = 0; |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 2571 | free(curproxy->cookie_domain); curproxy->cookie_domain = NULL; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2572 | free(curproxy->cookie_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2573 | curproxy->cookie_name = strdup(args[1]); |
| 2574 | curproxy->cookie_len = strlen(curproxy->cookie_name); |
Willy Tarreau | c63d4bb | 2010-10-23 11:37:27 +0200 | [diff] [blame] | 2575 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2576 | cur_arg = 2; |
| 2577 | while (*(args[cur_arg])) { |
| 2578 | if (!strcmp(args[cur_arg], "rewrite")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2579 | curproxy->ck_opts |= PR_CK_RW; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2580 | } |
| 2581 | else if (!strcmp(args[cur_arg], "indirect")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2582 | curproxy->ck_opts |= PR_CK_IND; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2583 | } |
| 2584 | else if (!strcmp(args[cur_arg], "insert")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2585 | curproxy->ck_opts |= PR_CK_INS; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2586 | } |
| 2587 | else if (!strcmp(args[cur_arg], "nocache")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2588 | curproxy->ck_opts |= PR_CK_NOC; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2589 | } |
| 2590 | else if (!strcmp(args[cur_arg], "postonly")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2591 | curproxy->ck_opts |= PR_CK_POST; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2592 | } |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 2593 | else if (!strcmp(args[cur_arg], "preserve")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2594 | curproxy->ck_opts |= PR_CK_PSV; |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 2595 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2596 | else if (!strcmp(args[cur_arg], "prefix")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2597 | curproxy->ck_opts |= PR_CK_PFX; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2598 | } |
Willy Tarreau | 4992dd2 | 2012-05-31 21:02:17 +0200 | [diff] [blame] | 2599 | else if (!strcmp(args[cur_arg], "httponly")) { |
| 2600 | curproxy->ck_opts |= PR_CK_HTTPONLY; |
| 2601 | } |
| 2602 | else if (!strcmp(args[cur_arg], "secure")) { |
| 2603 | curproxy->ck_opts |= PR_CK_SECURE; |
| 2604 | } |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2605 | else if (!strcmp(args[cur_arg], "domain")) { |
| 2606 | if (!*args[cur_arg + 1]) { |
| 2607 | Alert("parsing [%s:%d]: '%s' expects <domain> as argument.\n", |
| 2608 | file, linenum, args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2609 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2610 | goto out; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2611 | } |
| 2612 | |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 2613 | if (*args[cur_arg + 1] != '.' || !strchr(args[cur_arg + 1] + 1, '.')) { |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2614 | /* rfc2109, 4.3.2 Rejecting Cookies */ |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 2615 | Warning("parsing [%s:%d]: domain '%s' contains no embedded" |
| 2616 | " dots nor does not start with a dot." |
| 2617 | " RFC forbids it, this configuration may not work properly.\n", |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2618 | file, linenum, args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 2619 | err_code |= ERR_WARN; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2620 | } |
| 2621 | |
| 2622 | err = invalid_domainchar(args[cur_arg + 1]); |
| 2623 | if (err) { |
| 2624 | Alert("parsing [%s:%d]: character '%c' is not permitted in domain name '%s'.\n", |
| 2625 | file, linenum, *err, args[cur_arg + 1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2626 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2627 | goto out; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2628 | } |
| 2629 | |
Willy Tarreau | 68a897b | 2009-12-03 23:28:34 +0100 | [diff] [blame] | 2630 | if (!curproxy->cookie_domain) { |
| 2631 | curproxy->cookie_domain = strdup(args[cur_arg + 1]); |
| 2632 | } else { |
| 2633 | /* one domain was already specified, add another one by |
| 2634 | * building the string which will be returned along with |
| 2635 | * the cookie. |
| 2636 | */ |
| 2637 | char *new_ptr; |
| 2638 | int new_len = strlen(curproxy->cookie_domain) + |
| 2639 | strlen("; domain=") + strlen(args[cur_arg + 1]) + 1; |
| 2640 | new_ptr = malloc(new_len); |
| 2641 | snprintf(new_ptr, new_len, "%s; domain=%s", curproxy->cookie_domain, args[cur_arg+1]); |
| 2642 | free(curproxy->cookie_domain); |
| 2643 | curproxy->cookie_domain = new_ptr; |
| 2644 | } |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 2645 | cur_arg++; |
| 2646 | } |
| 2647 | else if (!strcmp(args[cur_arg], "maxidle")) { |
| 2648 | unsigned int maxidle; |
| 2649 | const char *res; |
| 2650 | |
| 2651 | if (!*args[cur_arg + 1]) { |
| 2652 | Alert("parsing [%s:%d]: '%s' expects <idletime> in seconds as argument.\n", |
| 2653 | file, linenum, args[cur_arg]); |
| 2654 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2655 | goto out; |
| 2656 | } |
| 2657 | |
| 2658 | res = parse_time_err(args[cur_arg + 1], &maxidle, TIME_UNIT_S); |
| 2659 | if (res) { |
| 2660 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 2661 | file, linenum, *res, args[cur_arg]); |
| 2662 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2663 | goto out; |
| 2664 | } |
| 2665 | curproxy->cookie_maxidle = maxidle; |
| 2666 | cur_arg++; |
| 2667 | } |
| 2668 | else if (!strcmp(args[cur_arg], "maxlife")) { |
| 2669 | unsigned int maxlife; |
| 2670 | const char *res; |
| 2671 | |
| 2672 | if (!*args[cur_arg + 1]) { |
| 2673 | Alert("parsing [%s:%d]: '%s' expects <lifetime> in seconds as argument.\n", |
| 2674 | file, linenum, args[cur_arg]); |
| 2675 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2676 | goto out; |
| 2677 | } |
| 2678 | |
| 2679 | res = parse_time_err(args[cur_arg + 1], &maxlife, TIME_UNIT_S); |
| 2680 | if (res) { |
| 2681 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 2682 | file, linenum, *res, args[cur_arg]); |
| 2683 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2684 | goto out; |
| 2685 | } |
| 2686 | curproxy->cookie_maxlife = maxlife; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2687 | cur_arg++; |
| 2688 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2689 | else { |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 2690 | 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] | 2691 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2692 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2693 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2694 | } |
| 2695 | cur_arg++; |
| 2696 | } |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2697 | if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_IND))) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2698 | Alert("parsing [%s:%d] : cookie 'rewrite' and 'indirect' modes are incompatible.\n", |
| 2699 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2700 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2701 | } |
| 2702 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2703 | 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] | 2704 | Alert("parsing [%s:%d] : cookie 'rewrite', 'insert' and 'prefix' modes are incompatible.\n", |
| 2705 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2706 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2707 | } |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 2708 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2709 | 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] | 2710 | Alert("parsing [%s:%d] : cookie 'preserve' requires at least 'insert' or 'indirect'.\n", |
| 2711 | file, linenum); |
| 2712 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2713 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2714 | }/* end else if (!strcmp(args[0], "cookie")) */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2715 | else if (!strcmp(args[0], "persist")) { /* persist */ |
| 2716 | if (*(args[1]) == 0) { |
| 2717 | Alert("parsing [%s:%d] : missing persist method.\n", |
| 2718 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2719 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2720 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2721 | } |
| 2722 | |
| 2723 | if (!strncmp(args[1], "rdp-cookie", 10)) { |
| 2724 | curproxy->options2 |= PR_O2_RDPC_PRST; |
| 2725 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2726 | if (*(args[1] + 10) == '(') { /* cookie name */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2727 | const char *beg, *end; |
| 2728 | |
| 2729 | beg = args[1] + 11; |
| 2730 | end = strchr(beg, ')'); |
| 2731 | |
| 2732 | if (!end || end == beg) { |
| 2733 | Alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n", |
| 2734 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2735 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2736 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2737 | } |
| 2738 | |
| 2739 | free(curproxy->rdp_cookie_name); |
| 2740 | curproxy->rdp_cookie_name = my_strndup(beg, end - beg); |
| 2741 | curproxy->rdp_cookie_len = end-beg; |
| 2742 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2743 | else if (*(args[1] + 10) == '\0') { /* default cookie name 'msts' */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2744 | free(curproxy->rdp_cookie_name); |
| 2745 | curproxy->rdp_cookie_name = strdup("msts"); |
| 2746 | curproxy->rdp_cookie_len = strlen(curproxy->rdp_cookie_name); |
| 2747 | } |
| 2748 | else { /* syntax */ |
| 2749 | Alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n", |
| 2750 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2751 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2752 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2753 | } |
| 2754 | } |
| 2755 | else { |
| 2756 | Alert("parsing [%s:%d] : unknown persist method.\n", |
| 2757 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2758 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2759 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2760 | } |
| 2761 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2762 | else if (!strcmp(args[0], "appsession")) { /* cookie name */ |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2763 | int cur_arg; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2764 | |
Cyril Bonté | 3b7a369 | 2010-01-10 17:01:47 +0100 | [diff] [blame] | 2765 | if (curproxy == &defproxy) { |
| 2766 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2767 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2768 | goto out; |
| 2769 | } |
| 2770 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2771 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2772 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2773 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2774 | if (*(args[5]) == 0) { |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2775 | 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] | 2776 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2777 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2778 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2779 | } |
| 2780 | have_appsession = 1; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2781 | free(curproxy->appsession_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2782 | curproxy->appsession_name = strdup(args[1]); |
| 2783 | curproxy->appsession_name_len = strlen(curproxy->appsession_name); |
| 2784 | curproxy->appsession_len = atoi(args[3]); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 2785 | err = parse_time_err(args[5], &val, TIME_UNIT_MS); |
| 2786 | if (err) { |
| 2787 | Alert("parsing [%s:%d] : unexpected character '%c' in %s timeout.\n", |
| 2788 | file, linenum, *err, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2789 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2790 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 2791 | } |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 2792 | curproxy->timeout.appsession = val; |
Willy Tarreau | ee99136 | 2007-05-14 14:37:50 +0200 | [diff] [blame] | 2793 | |
Willy Tarreau | 51041c7 | 2007-09-09 21:56:53 +0200 | [diff] [blame] | 2794 | if (appsession_hash_init(&(curproxy->htbl_proxy), destroy) == 0) { |
| 2795 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2796 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2797 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2798 | } |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2799 | |
| 2800 | cur_arg = 6; |
| 2801 | curproxy->options2 &= ~PR_O2_AS_REQL; |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2802 | curproxy->options2 &= ~PR_O2_AS_M_ANY; |
| 2803 | curproxy->options2 |= PR_O2_AS_M_PP; |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2804 | while (*(args[cur_arg])) { |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2805 | if (!strcmp(args[cur_arg], "request-learn")) { |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2806 | curproxy->options2 |= PR_O2_AS_REQL; |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2807 | } else if (!strcmp(args[cur_arg], "prefix")) { |
| 2808 | curproxy->options2 |= PR_O2_AS_PFX; |
| 2809 | } else if (!strcmp(args[cur_arg], "mode")) { |
| 2810 | if (!*args[cur_arg + 1]) { |
| 2811 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 2812 | file, linenum, args[0], args[cur_arg]); |
| 2813 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2814 | goto out; |
| 2815 | } |
| 2816 | |
| 2817 | cur_arg++; |
| 2818 | if (!strcmp(args[cur_arg], "query-string")) { |
| 2819 | curproxy->options2 &= ~PR_O2_AS_M_ANY; |
| 2820 | curproxy->options2 |= PR_O2_AS_M_QS; |
| 2821 | } else if (!strcmp(args[cur_arg], "path-parameters")) { |
| 2822 | curproxy->options2 &= ~PR_O2_AS_M_ANY; |
| 2823 | curproxy->options2 |= PR_O2_AS_M_PP; |
| 2824 | } else { |
| 2825 | Alert("parsing [%s:%d] : unknown mode '%s'\n", file, linenum, args[cur_arg]); |
| 2826 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2827 | goto out; |
| 2828 | } |
| 2829 | } |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2830 | cur_arg++; |
| 2831 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2832 | } /* Url App Session */ |
| 2833 | else if (!strcmp(args[0], "capture")) { |
Willy Tarreau | 3b6b1a9 | 2009-07-23 13:24:23 +0200 | [diff] [blame] | 2834 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2835 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2836 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2837 | if (!strcmp(args[1], "cookie")) { /* name of a cookie to capture */ |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 2838 | if (curproxy == &defproxy) { |
| 2839 | Alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
| 2840 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2841 | goto out; |
| 2842 | } |
| 2843 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2844 | if (*(args[4]) == 0) { |
| 2845 | Alert("parsing [%s:%d] : '%s' expects 'cookie' <cookie_name> 'len' <len>.\n", |
| 2846 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2847 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2848 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2849 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2850 | free(curproxy->capture_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2851 | curproxy->capture_name = strdup(args[2]); |
| 2852 | curproxy->capture_namelen = strlen(curproxy->capture_name); |
| 2853 | curproxy->capture_len = atol(args[4]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2854 | curproxy->to_log |= LW_COOKIE; |
| 2855 | } |
| 2856 | else if (!strcmp(args[1], "request") && !strcmp(args[2], "header")) { |
| 2857 | struct cap_hdr *hdr; |
| 2858 | |
| 2859 | if (curproxy == &defproxy) { |
| 2860 | 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] | 2861 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2862 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2863 | } |
| 2864 | |
| 2865 | if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) { |
| 2866 | Alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n", |
| 2867 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2868 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2869 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2870 | } |
| 2871 | |
| 2872 | hdr = calloc(sizeof(struct cap_hdr), 1); |
| 2873 | hdr->next = curproxy->req_cap; |
| 2874 | hdr->name = strdup(args[3]); |
| 2875 | hdr->namelen = strlen(args[3]); |
| 2876 | hdr->len = atol(args[5]); |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 2877 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2878 | hdr->index = curproxy->nb_req_cap++; |
| 2879 | curproxy->req_cap = hdr; |
| 2880 | curproxy->to_log |= LW_REQHDR; |
| 2881 | } |
| 2882 | else if (!strcmp(args[1], "response") && !strcmp(args[2], "header")) { |
| 2883 | struct cap_hdr *hdr; |
| 2884 | |
| 2885 | if (curproxy == &defproxy) { |
| 2886 | 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] | 2887 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2888 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2889 | } |
| 2890 | |
| 2891 | if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) { |
| 2892 | Alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n", |
| 2893 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2894 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2895 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2896 | } |
| 2897 | hdr = calloc(sizeof(struct cap_hdr), 1); |
| 2898 | hdr->next = curproxy->rsp_cap; |
| 2899 | hdr->name = strdup(args[3]); |
| 2900 | hdr->namelen = strlen(args[3]); |
| 2901 | hdr->len = atol(args[5]); |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 2902 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2903 | hdr->index = curproxy->nb_rsp_cap++; |
| 2904 | curproxy->rsp_cap = hdr; |
| 2905 | curproxy->to_log |= LW_RSPHDR; |
| 2906 | } |
| 2907 | else { |
| 2908 | Alert("parsing [%s:%d] : '%s' expects 'cookie' or 'request header' or 'response header'.\n", |
| 2909 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2910 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2911 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2912 | } |
| 2913 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2914 | else if (!strcmp(args[0], "retries")) { /* connection retries */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2915 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2916 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2917 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2918 | if (*(args[1]) == 0) { |
| 2919 | Alert("parsing [%s:%d] : '%s' expects an integer argument (dispatch counts for one).\n", |
| 2920 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2921 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2922 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2923 | } |
| 2924 | curproxy->conn_retries = atol(args[1]); |
| 2925 | } |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2926 | 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] | 2927 | struct http_req_rule *rule; |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2928 | |
| 2929 | if (curproxy == &defproxy) { |
| 2930 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2931 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2932 | goto out; |
| 2933 | } |
| 2934 | |
Willy Tarreau | 20b0de5 | 2012-12-24 15:45:22 +0100 | [diff] [blame] | 2935 | if (!LIST_ISEMPTY(&curproxy->http_req_rules) && |
| 2936 | !LIST_PREV(&curproxy->http_req_rules, struct http_req_rule *, list)->cond && |
| 2937 | (LIST_PREV(&curproxy->http_req_rules, struct http_req_rule *, list)->action == HTTP_REQ_ACT_ALLOW || |
| 2938 | 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] | 2939 | 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] | 2940 | LIST_PREV(&curproxy->http_req_rules, struct http_req_rule *, list)->action == HTTP_REQ_ACT_AUTH)) { |
| 2941 | 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] | 2942 | file, linenum, args[0]); |
| 2943 | err_code |= ERR_WARN; |
| 2944 | } |
| 2945 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 2946 | 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] | 2947 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 2948 | if (!rule) { |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2949 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2950 | goto out; |
| 2951 | } |
| 2952 | |
Willy Tarreau | 5002f57 | 2014-04-23 01:32:02 +0200 | [diff] [blame] | 2953 | err_code |= warnif_misplaced_http_req(curproxy, file, linenum, args[0]); |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 2954 | err_code |= warnif_cond_conflicts(rule->cond, |
| 2955 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 2956 | file, linenum); |
| 2957 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 2958 | LIST_ADDQ(&curproxy->http_req_rules, &rule->list); |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2959 | } |
Willy Tarreau | e365c0b | 2013-06-11 16:06:12 +0200 | [diff] [blame] | 2960 | else if (!strcmp(args[0], "http-response")) { /* response access control */ |
| 2961 | struct http_res_rule *rule; |
| 2962 | |
| 2963 | if (curproxy == &defproxy) { |
| 2964 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2965 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2966 | goto out; |
| 2967 | } |
| 2968 | |
| 2969 | if (!LIST_ISEMPTY(&curproxy->http_res_rules) && |
| 2970 | !LIST_PREV(&curproxy->http_res_rules, struct http_res_rule *, list)->cond && |
| 2971 | (LIST_PREV(&curproxy->http_res_rules, struct http_res_rule *, list)->action == HTTP_RES_ACT_ALLOW || |
| 2972 | LIST_PREV(&curproxy->http_res_rules, struct http_res_rule *, list)->action == HTTP_RES_ACT_DENY)) { |
| 2973 | Warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n", |
| 2974 | file, linenum, args[0]); |
| 2975 | err_code |= ERR_WARN; |
| 2976 | } |
| 2977 | |
| 2978 | rule = parse_http_res_cond((const char **)args + 1, file, linenum, curproxy); |
| 2979 | |
| 2980 | if (!rule) { |
| 2981 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2982 | goto out; |
| 2983 | } |
| 2984 | |
| 2985 | err_code |= warnif_cond_conflicts(rule->cond, |
| 2986 | (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR, |
| 2987 | file, linenum); |
| 2988 | |
| 2989 | LIST_ADDQ(&curproxy->http_res_rules, &rule->list); |
| 2990 | } |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 2991 | else if (!strcmp(args[0], "http-send-name-header")) { /* send server name in request header */ |
| 2992 | /* set the header name and length into the proxy structure */ |
| 2993 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 2994 | err_code |= ERR_WARN; |
| 2995 | |
| 2996 | if (!*args[1]) { |
| 2997 | Alert("parsing [%s:%d] : '%s' requires a header string.\n", |
| 2998 | file, linenum, args[0]); |
| 2999 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3000 | goto out; |
| 3001 | } |
| 3002 | |
| 3003 | /* set the desired header name */ |
| 3004 | free(curproxy->server_id_hdr_name); |
| 3005 | curproxy->server_id_hdr_name = strdup(args[1]); |
| 3006 | curproxy->server_id_hdr_len = strlen(curproxy->server_id_hdr_name); |
| 3007 | } |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 3008 | else if (!strcmp(args[0], "block")) { /* early blocking based on ACLs */ |
Willy Tarreau | b3dc39d | 2014-04-28 22:06:57 +0200 | [diff] [blame] | 3009 | struct http_req_rule *rule; |
| 3010 | |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3011 | if (curproxy == &defproxy) { |
| 3012 | 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] | 3013 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3014 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3015 | } |
| 3016 | |
Willy Tarreau | b3dc39d | 2014-04-28 22:06:57 +0200 | [diff] [blame] | 3017 | /* emulate "block" using "http-request block". Since these rules are supposed to |
| 3018 | * be processed before all http-request rules, we put them into their own list |
| 3019 | * and will insert them at the end. |
| 3020 | */ |
| 3021 | rule = parse_http_req_cond((const char **)args, file, linenum, curproxy); |
| 3022 | if (!rule) { |
| 3023 | err_code |= ERR_ALERT | ERR_ABORT; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3024 | goto out; |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 3025 | } |
Willy Tarreau | b3dc39d | 2014-04-28 22:06:57 +0200 | [diff] [blame] | 3026 | err_code |= warnif_misplaced_block(curproxy, file, linenum, args[0]); |
| 3027 | err_code |= warnif_cond_conflicts(rule->cond, |
| 3028 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 3029 | file, linenum); |
| 3030 | LIST_ADDQ(&curproxy->block_rules, &rule->list); |
Willy Tarreau | de9d2d7 | 2014-04-28 22:28:02 +0200 | [diff] [blame] | 3031 | |
| 3032 | if (!already_warned(WARN_BLOCK_DEPRECATED)) |
| 3033 | 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]); |
| 3034 | |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 3035 | } |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3036 | else if (!strcmp(args[0], "redirect")) { |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3037 | struct redirect_rule *rule; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3038 | |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 3039 | if (curproxy == &defproxy) { |
| 3040 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3041 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3042 | goto out; |
| 3043 | } |
| 3044 | |
Thierry FOURNIER | d18cd0f | 2013-11-29 12:15:45 +0100 | [diff] [blame] | 3045 | 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] | 3046 | Alert("parsing [%s:%d] : error detected in %s '%s' while parsing redirect rule : %s.\n", |
| 3047 | file, linenum, proxy_type_str(curproxy), curproxy->id, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3048 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3049 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3050 | } |
| 3051 | |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3052 | LIST_ADDQ(&curproxy->redirect_rules, &rule->list); |
Willy Tarreau | ee445d9 | 2014-04-23 01:39:04 +0200 | [diff] [blame] | 3053 | err_code |= warnif_misplaced_redirect(curproxy, file, linenum, args[0]); |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3054 | err_code |= warnif_cond_conflicts(rule->cond, |
| 3055 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 3056 | file, linenum); |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3057 | } |
Krzysztof Piotr Oledzki | 7b723ef | 2009-01-27 21:09:41 +0100 | [diff] [blame] | 3058 | else if (!strcmp(args[0], "use_backend")) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3059 | struct switching_rule *rule; |
| 3060 | |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3061 | if (curproxy == &defproxy) { |
| 3062 | 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] | 3063 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3064 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3065 | } |
| 3066 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3067 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3068 | err_code |= ERR_WARN; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3069 | |
| 3070 | if (*(args[1]) == 0) { |
| 3071 | 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] | 3072 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3073 | goto out; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3074 | } |
| 3075 | |
Willy Tarreau | f51658d | 2014-04-23 01:21:56 +0200 | [diff] [blame] | 3076 | if (strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0) { |
| 3077 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 3078 | Alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n", |
| 3079 | file, linenum, errmsg); |
| 3080 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3081 | goto out; |
| 3082 | } |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3083 | |
Willy Tarreau | f51658d | 2014-04-23 01:21:56 +0200 | [diff] [blame] | 3084 | 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] | 3085 | } |
| 3086 | |
| 3087 | rule = (struct switching_rule *)calloc(1, sizeof(*rule)); |
| 3088 | rule->cond = cond; |
| 3089 | rule->be.name = strdup(args[1]); |
| 3090 | LIST_INIT(&rule->list); |
| 3091 | LIST_ADDQ(&curproxy->switching_rules, &rule->list); |
| 3092 | } |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 3093 | else if (strcmp(args[0], "use-server") == 0) { |
| 3094 | struct server_rule *rule; |
| 3095 | |
| 3096 | if (curproxy == &defproxy) { |
| 3097 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3098 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3099 | goto out; |
| 3100 | } |
| 3101 | |
| 3102 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 3103 | err_code |= ERR_WARN; |
| 3104 | |
| 3105 | if (*(args[1]) == 0) { |
| 3106 | Alert("parsing [%s:%d] : '%s' expects a server name.\n", file, linenum, args[0]); |
| 3107 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3108 | goto out; |
| 3109 | } |
| 3110 | |
| 3111 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
| 3112 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 3113 | file, linenum, args[0]); |
| 3114 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3115 | goto out; |
| 3116 | } |
| 3117 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 3118 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 3119 | Alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n", |
| 3120 | file, linenum, errmsg); |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 3121 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3122 | goto out; |
| 3123 | } |
| 3124 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3125 | 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] | 3126 | |
| 3127 | rule = (struct server_rule *)calloc(1, sizeof(*rule)); |
| 3128 | rule->cond = cond; |
| 3129 | rule->srv.name = strdup(args[1]); |
| 3130 | LIST_INIT(&rule->list); |
| 3131 | LIST_ADDQ(&curproxy->server_rules, &rule->list); |
| 3132 | curproxy->be_req_ana |= AN_REQ_SRV_RULES; |
| 3133 | } |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 3134 | else if ((!strcmp(args[0], "force-persist")) || |
| 3135 | (!strcmp(args[0], "ignore-persist"))) { |
| 3136 | struct persist_rule *rule; |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 3137 | |
| 3138 | if (curproxy == &defproxy) { |
| 3139 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3140 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3141 | goto out; |
| 3142 | } |
| 3143 | |
| 3144 | if (warnifnotcap(curproxy, PR_CAP_FE|PR_CAP_BE, file, linenum, args[0], NULL)) |
| 3145 | err_code |= ERR_WARN; |
| 3146 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 3147 | if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) { |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 3148 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 3149 | file, linenum, args[0]); |
| 3150 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3151 | goto out; |
| 3152 | } |
| 3153 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 3154 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 1, &errmsg)) == NULL) { |
| 3155 | Alert("parsing [%s:%d] : error detected while parsing a '%s' rule : %s.\n", |
| 3156 | file, linenum, args[0], errmsg); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 3157 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3158 | goto out; |
| 3159 | } |
| 3160 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3161 | /* note: BE_REQ_CNT is the first one after FE_SET_BCK, which is |
| 3162 | * where force-persist is applied. |
| 3163 | */ |
| 3164 | 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] | 3165 | |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 3166 | rule = (struct persist_rule *)calloc(1, sizeof(*rule)); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 3167 | rule->cond = cond; |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 3168 | if (!strcmp(args[0], "force-persist")) { |
| 3169 | rule->type = PERSIST_TYPE_FORCE; |
| 3170 | } else { |
| 3171 | rule->type = PERSIST_TYPE_IGNORE; |
| 3172 | } |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 3173 | LIST_INIT(&rule->list); |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 3174 | LIST_ADDQ(&curproxy->persist_rules, &rule->list); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 3175 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3176 | else if (!strcmp(args[0], "stick-table")) { |
| 3177 | int myidx = 1; |
| 3178 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 3179 | curproxy->table.id = curproxy->id; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3180 | curproxy->table.type = (unsigned int)-1; |
| 3181 | while (*args[myidx]) { |
| 3182 | const char *err; |
| 3183 | |
| 3184 | if (strcmp(args[myidx], "size") == 0) { |
| 3185 | myidx++; |
| 3186 | if (!*(args[myidx])) { |
| 3187 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 3188 | file, linenum, args[myidx-1]); |
| 3189 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3190 | goto out; |
| 3191 | } |
| 3192 | if ((err = parse_size_err(args[myidx], &curproxy->table.size))) { |
| 3193 | Alert("parsing [%s:%d] : stick-table: unexpected character '%c' in argument of '%s'.\n", |
| 3194 | file, linenum, *err, args[myidx-1]); |
| 3195 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3196 | goto out; |
| 3197 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 3198 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3199 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 3200 | else if (strcmp(args[myidx], "peers") == 0) { |
| 3201 | myidx++; |
Godbach | 5052316 | 2013-12-11 19:48:57 +0800 | [diff] [blame] | 3202 | if (!*(args[myidx])) { |
Godbach | ff11554 | 2014-04-21 21:52:23 +0800 | [diff] [blame] | 3203 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 3204 | file, linenum, args[myidx-1]); |
| 3205 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3206 | goto out; |
Godbach | 5052316 | 2013-12-11 19:48:57 +0800 | [diff] [blame] | 3207 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 3208 | curproxy->table.peers.name = strdup(args[myidx++]); |
| 3209 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3210 | else if (strcmp(args[myidx], "expire") == 0) { |
| 3211 | myidx++; |
| 3212 | if (!*(args[myidx])) { |
| 3213 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 3214 | file, linenum, args[myidx-1]); |
| 3215 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3216 | goto out; |
| 3217 | } |
| 3218 | err = parse_time_err(args[myidx], &val, TIME_UNIT_MS); |
| 3219 | if (err) { |
| 3220 | Alert("parsing [%s:%d] : stick-table: unexpected character '%c' in argument of '%s'.\n", |
| 3221 | file, linenum, *err, args[myidx-1]); |
| 3222 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3223 | goto out; |
| 3224 | } |
Ben Cabot | 85a1c18 | 2016-01-20 09:44:39 +0000 | [diff] [blame] | 3225 | if (val > INT_MAX) { |
| 3226 | Alert("parsing [%s:%d] : Expire value [%u]ms exceeds maxmimum value of 24.85 days.\n", |
| 3227 | file, linenum, val); |
| 3228 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3229 | goto out; |
| 3230 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3231 | curproxy->table.expire = val; |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 3232 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3233 | } |
| 3234 | else if (strcmp(args[myidx], "nopurge") == 0) { |
| 3235 | curproxy->table.nopurge = 1; |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 3236 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3237 | } |
| 3238 | else if (strcmp(args[myidx], "type") == 0) { |
| 3239 | myidx++; |
| 3240 | if (stktable_parse_type(args, &myidx, &curproxy->table.type, &curproxy->table.key_size) != 0) { |
| 3241 | Alert("parsing [%s:%d] : stick-table: unknown type '%s'.\n", |
| 3242 | file, linenum, args[myidx]); |
| 3243 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3244 | goto out; |
| 3245 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 3246 | /* myidx already points to next arg */ |
| 3247 | } |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 3248 | else if (strcmp(args[myidx], "store") == 0) { |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 3249 | int type, err; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 3250 | char *cw, *nw, *sa; |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 3251 | |
| 3252 | myidx++; |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 3253 | nw = args[myidx]; |
| 3254 | while (*nw) { |
| 3255 | /* the "store" keyword supports a comma-separated list */ |
| 3256 | cw = nw; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 3257 | sa = NULL; /* store arg */ |
| 3258 | while (*nw && *nw != ',') { |
| 3259 | if (*nw == '(') { |
| 3260 | *nw = 0; |
| 3261 | sa = ++nw; |
| 3262 | while (*nw != ')') { |
| 3263 | if (!*nw) { |
| 3264 | Alert("parsing [%s:%d] : %s: missing closing parenthesis after store option '%s'.\n", |
| 3265 | file, linenum, args[0], cw); |
| 3266 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3267 | goto out; |
| 3268 | } |
| 3269 | nw++; |
| 3270 | } |
| 3271 | *nw = '\0'; |
| 3272 | } |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 3273 | nw++; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 3274 | } |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 3275 | if (*nw) |
| 3276 | *nw++ = '\0'; |
| 3277 | type = stktable_get_data_type(cw); |
| 3278 | if (type < 0) { |
| 3279 | Alert("parsing [%s:%d] : %s: unknown store option '%s'.\n", |
| 3280 | file, linenum, args[0], cw); |
| 3281 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3282 | goto out; |
| 3283 | } |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 3284 | |
| 3285 | err = stktable_alloc_data_type(&curproxy->table, type, sa); |
| 3286 | switch (err) { |
| 3287 | case PE_NONE: break; |
| 3288 | case PE_EXIST: |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 3289 | Warning("parsing [%s:%d]: %s: store option '%s' already enabled, ignored.\n", |
| 3290 | file, linenum, args[0], cw); |
| 3291 | err_code |= ERR_WARN; |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 3292 | break; |
| 3293 | |
| 3294 | case PE_ARG_MISSING: |
| 3295 | Alert("parsing [%s:%d] : %s: missing argument to store option '%s'.\n", |
| 3296 | file, linenum, args[0], cw); |
| 3297 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3298 | goto out; |
| 3299 | |
| 3300 | case PE_ARG_NOT_USED: |
| 3301 | Alert("parsing [%s:%d] : %s: unexpected argument to store option '%s'.\n", |
| 3302 | file, linenum, args[0], cw); |
| 3303 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3304 | goto out; |
| 3305 | |
| 3306 | default: |
| 3307 | Alert("parsing [%s:%d] : %s: error when processing store option '%s'.\n", |
| 3308 | file, linenum, args[0], cw); |
| 3309 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3310 | goto out; |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 3311 | } |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 3312 | } |
| 3313 | myidx++; |
| 3314 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 3315 | else { |
| 3316 | Alert("parsing [%s:%d] : stick-table: unknown argument '%s'.\n", |
| 3317 | file, linenum, args[myidx]); |
| 3318 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3319 | goto out; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3320 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3321 | } |
| 3322 | |
| 3323 | if (!curproxy->table.size) { |
| 3324 | Alert("parsing [%s:%d] : stick-table: missing size.\n", |
| 3325 | file, linenum); |
| 3326 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3327 | goto out; |
| 3328 | } |
| 3329 | |
| 3330 | if (curproxy->table.type == (unsigned int)-1) { |
| 3331 | Alert("parsing [%s:%d] : stick-table: missing type.\n", |
| 3332 | file, linenum); |
| 3333 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3334 | goto out; |
| 3335 | } |
| 3336 | } |
| 3337 | else if (!strcmp(args[0], "stick")) { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3338 | struct sticking_rule *rule; |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 3339 | struct sample_expr *expr; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3340 | int myidx = 0; |
| 3341 | const char *name = NULL; |
| 3342 | int flags; |
| 3343 | |
| 3344 | if (curproxy == &defproxy) { |
| 3345 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3346 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3347 | goto out; |
| 3348 | } |
| 3349 | |
| 3350 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) { |
| 3351 | err_code |= ERR_WARN; |
| 3352 | goto out; |
| 3353 | } |
| 3354 | |
| 3355 | myidx++; |
| 3356 | if ((strcmp(args[myidx], "store") == 0) || |
| 3357 | (strcmp(args[myidx], "store-request") == 0)) { |
| 3358 | myidx++; |
| 3359 | flags = STK_IS_STORE; |
| 3360 | } |
| 3361 | else if (strcmp(args[myidx], "store-response") == 0) { |
| 3362 | myidx++; |
| 3363 | flags = STK_IS_STORE | STK_ON_RSP; |
| 3364 | } |
| 3365 | else if (strcmp(args[myidx], "match") == 0) { |
| 3366 | myidx++; |
| 3367 | flags = STK_IS_MATCH; |
| 3368 | } |
| 3369 | else if (strcmp(args[myidx], "on") == 0) { |
| 3370 | myidx++; |
| 3371 | flags = STK_IS_MATCH | STK_IS_STORE; |
| 3372 | } |
| 3373 | else { |
| 3374 | Alert("parsing [%s:%d] : '%s' expects 'on', 'match', or 'store'.\n", file, linenum, args[0]); |
| 3375 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3376 | goto out; |
| 3377 | } |
| 3378 | |
| 3379 | if (*(args[myidx]) == 0) { |
| 3380 | Alert("parsing [%s:%d] : '%s' expects a fetch method.\n", file, linenum, args[0]); |
| 3381 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3382 | goto out; |
| 3383 | } |
| 3384 | |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 3385 | curproxy->conf.args.ctx = ARGC_STK; |
Thierry FOURNIER | eeaa951 | 2014-02-11 14:00:19 +0100 | [diff] [blame] | 3386 | expr = sample_parse_expr(args, &myidx, file, linenum, &errmsg, &curproxy->conf.args); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3387 | if (!expr) { |
Willy Tarreau | 975c178 | 2013-12-12 23:16:54 +0100 | [diff] [blame] | 3388 | Alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3389 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3390 | goto out; |
| 3391 | } |
| 3392 | |
| 3393 | if (flags & STK_ON_RSP) { |
Willy Tarreau | 80aca90 | 2013-01-07 15:42:20 +0100 | [diff] [blame] | 3394 | if (!(expr->fetch->val & SMP_VAL_BE_STO_RUL)) { |
| 3395 | Alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available for 'store-response'.\n", |
| 3396 | 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] | 3397 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 3398 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3399 | goto out; |
| 3400 | } |
| 3401 | } else { |
Willy Tarreau | 80aca90 | 2013-01-07 15:42:20 +0100 | [diff] [blame] | 3402 | if (!(expr->fetch->val & SMP_VAL_BE_SET_SRV)) { |
| 3403 | Alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available during request.\n", |
| 3404 | 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] | 3405 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 3406 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3407 | goto out; |
| 3408 | } |
| 3409 | } |
| 3410 | |
Willy Tarreau | 1b6c00c | 2012-10-05 22:41:26 +0200 | [diff] [blame] | 3411 | /* 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] | 3412 | curproxy->http_needed |= !!(expr->fetch->use & SMP_USE_HTTP_ANY); |
Willy Tarreau | 1b6c00c | 2012-10-05 22:41:26 +0200 | [diff] [blame] | 3413 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3414 | if (strcmp(args[myidx], "table") == 0) { |
| 3415 | myidx++; |
| 3416 | name = args[myidx++]; |
| 3417 | } |
| 3418 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 3419 | if (strcmp(args[myidx], "if") == 0 || strcmp(args[myidx], "unless") == 0) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 3420 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + myidx, &errmsg)) == NULL) { |
| 3421 | Alert("parsing [%s:%d] : '%s': error detected while parsing sticking condition : %s.\n", |
| 3422 | file, linenum, args[0], errmsg); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3423 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 3424 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3425 | goto out; |
| 3426 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3427 | } |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 3428 | else if (*(args[myidx])) { |
| 3429 | Alert("parsing [%s:%d] : '%s': unknown keyword '%s'.\n", |
| 3430 | file, linenum, args[0], args[myidx]); |
| 3431 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 3432 | free(expr); |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 3433 | goto out; |
| 3434 | } |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 3435 | if (flags & STK_ON_RSP) |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3436 | 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] | 3437 | else |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3438 | 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] | 3439 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3440 | rule = (struct sticking_rule *)calloc(1, sizeof(*rule)); |
| 3441 | rule->cond = cond; |
| 3442 | rule->expr = expr; |
| 3443 | rule->flags = flags; |
| 3444 | rule->table.name = name ? strdup(name) : NULL; |
| 3445 | LIST_INIT(&rule->list); |
| 3446 | if (flags & STK_ON_RSP) |
| 3447 | LIST_ADDQ(&curproxy->storersp_rules, &rule->list); |
| 3448 | else |
| 3449 | LIST_ADDQ(&curproxy->sticking_rules, &rule->list); |
| 3450 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3451 | else if (!strcmp(args[0], "stats")) { |
| 3452 | if (curproxy != &defproxy && curproxy->uri_auth == defproxy.uri_auth) |
| 3453 | curproxy->uri_auth = NULL; /* we must detach from the default config */ |
| 3454 | |
Krzysztof Piotr Oledzki | 260a3bb | 2010-01-06 16:25:05 +0100 | [diff] [blame] | 3455 | if (!*args[1]) { |
| 3456 | goto stats_error_parsing; |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3457 | } else if (!strcmp(args[1], "admin")) { |
| 3458 | struct stats_admin_rule *rule; |
| 3459 | |
| 3460 | if (curproxy == &defproxy) { |
| 3461 | Alert("parsing [%s:%d]: '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
| 3462 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3463 | goto out; |
| 3464 | } |
| 3465 | |
| 3466 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 3467 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3468 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3469 | goto out; |
| 3470 | } |
| 3471 | |
| 3472 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
| 3473 | Alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n", |
| 3474 | file, linenum, args[0], args[1]); |
| 3475 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3476 | goto out; |
| 3477 | } |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 3478 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 3479 | Alert("parsing [%s:%d] : error detected while parsing a '%s %s' rule : %s.\n", |
| 3480 | file, linenum, args[0], args[1], errmsg); |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3481 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3482 | goto out; |
| 3483 | } |
| 3484 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3485 | err_code |= warnif_cond_conflicts(cond, |
| 3486 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 3487 | file, linenum); |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3488 | |
| 3489 | rule = (struct stats_admin_rule *)calloc(1, sizeof(*rule)); |
| 3490 | rule->cond = cond; |
| 3491 | LIST_INIT(&rule->list); |
| 3492 | LIST_ADDQ(&curproxy->uri_auth->admin_rules, &rule->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3493 | } else if (!strcmp(args[1], "uri")) { |
| 3494 | if (*(args[2]) == 0) { |
| 3495 | Alert("parsing [%s:%d] : 'uri' needs an URI prefix.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3496 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3497 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3498 | } else if (!stats_set_uri(&curproxy->uri_auth, args[2])) { |
| 3499 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3500 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3501 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3502 | } |
| 3503 | } else if (!strcmp(args[1], "realm")) { |
| 3504 | if (*(args[2]) == 0) { |
| 3505 | Alert("parsing [%s:%d] : 'realm' needs an realm name.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3506 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3507 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3508 | } else if (!stats_set_realm(&curproxy->uri_auth, args[2])) { |
| 3509 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3510 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3511 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3512 | } |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 3513 | } else if (!strcmp(args[1], "refresh")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 3514 | unsigned interval; |
| 3515 | |
| 3516 | err = parse_time_err(args[2], &interval, TIME_UNIT_S); |
| 3517 | if (err) { |
| 3518 | Alert("parsing [%s:%d] : unexpected character '%c' in stats refresh interval.\n", |
| 3519 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3520 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3521 | goto out; |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 3522 | } else if (!stats_set_refresh(&curproxy->uri_auth, interval)) { |
| 3523 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3524 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3525 | goto out; |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 3526 | } |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3527 | } 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] | 3528 | struct http_req_rule *rule; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3529 | |
| 3530 | if (curproxy == &defproxy) { |
| 3531 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3532 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3533 | goto out; |
| 3534 | } |
| 3535 | |
| 3536 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 3537 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3538 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3539 | goto out; |
| 3540 | } |
| 3541 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3542 | if (!LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) && |
| 3543 | !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] | 3544 | Warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n", |
| 3545 | file, linenum, args[0]); |
| 3546 | err_code |= ERR_WARN; |
| 3547 | } |
| 3548 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3549 | 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] | 3550 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3551 | if (!rule) { |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3552 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3553 | goto out; |
| 3554 | } |
| 3555 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3556 | err_code |= warnif_cond_conflicts(rule->cond, |
| 3557 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 3558 | file, linenum); |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3559 | LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list); |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3560 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3561 | } else if (!strcmp(args[1], "auth")) { |
| 3562 | if (*(args[2]) == 0) { |
| 3563 | 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] | 3564 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3565 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3566 | } else if (!stats_add_auth(&curproxy->uri_auth, args[2])) { |
| 3567 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3568 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3569 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3570 | } |
| 3571 | } else if (!strcmp(args[1], "scope")) { |
| 3572 | if (*(args[2]) == 0) { |
| 3573 | Alert("parsing [%s:%d] : 'scope' needs a proxy name.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3574 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3575 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3576 | } else if (!stats_add_scope(&curproxy->uri_auth, args[2])) { |
| 3577 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3578 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3579 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3580 | } |
| 3581 | } else if (!strcmp(args[1], "enable")) { |
| 3582 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 3583 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3584 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3585 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3586 | } |
Krzysztof Oledzki | d9db927 | 2007-10-15 10:05:11 +0200 | [diff] [blame] | 3587 | } else if (!strcmp(args[1], "hide-version")) { |
| 3588 | if (!stats_set_flag(&curproxy->uri_auth, ST_HIDEVER)) { |
| 3589 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3590 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3591 | goto out; |
Krzysztof Oledzki | d9db927 | 2007-10-15 10:05:11 +0200 | [diff] [blame] | 3592 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3593 | } else if (!strcmp(args[1], "show-legends")) { |
| 3594 | if (!stats_set_flag(&curproxy->uri_auth, ST_SHLGNDS)) { |
| 3595 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3596 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3597 | goto out; |
| 3598 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3599 | } else if (!strcmp(args[1], "show-node")) { |
| 3600 | |
| 3601 | if (*args[2]) { |
| 3602 | int i; |
| 3603 | char c; |
| 3604 | |
| 3605 | for (i=0; args[2][i]; i++) { |
| 3606 | c = args[2][i]; |
Willy Tarreau | 88e0581 | 2010-03-03 00:16:00 +0100 | [diff] [blame] | 3607 | if (!isupper((unsigned char)c) && !islower((unsigned char)c) && |
| 3608 | !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.') |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3609 | break; |
| 3610 | } |
| 3611 | |
| 3612 | if (!i || args[2][i]) { |
| 3613 | Alert("parsing [%s:%d]: '%s %s' invalid node name - should be a string" |
| 3614 | "with digits(0-9), letters(A-Z, a-z), hyphen(-) or underscode(_).\n", |
| 3615 | file, linenum, args[0], args[1]); |
| 3616 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3617 | goto out; |
| 3618 | } |
| 3619 | } |
| 3620 | |
| 3621 | if (!stats_set_node(&curproxy->uri_auth, args[2])) { |
| 3622 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3623 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3624 | goto out; |
| 3625 | } |
| 3626 | } else if (!strcmp(args[1], "show-desc")) { |
| 3627 | char *desc = NULL; |
| 3628 | |
| 3629 | if (*args[2]) { |
| 3630 | int i, len=0; |
| 3631 | char *d; |
| 3632 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 3633 | for (i = 2; *args[i]; i++) |
| 3634 | len += strlen(args[i]) + 1; |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3635 | |
| 3636 | desc = d = (char *)calloc(1, len); |
| 3637 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 3638 | d += snprintf(d, desc + len - d, "%s", args[2]); |
| 3639 | for (i = 3; *args[i]; i++) |
| 3640 | d += snprintf(d, desc + len - d, " %s", args[i]); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3641 | } |
| 3642 | |
| 3643 | if (!*args[2] && !global.desc) |
| 3644 | Warning("parsing [%s:%d]: '%s' requires a parameter or 'desc' to be set in the global section.\n", |
| 3645 | file, linenum, args[1]); |
| 3646 | else { |
| 3647 | if (!stats_set_desc(&curproxy->uri_auth, desc)) { |
| 3648 | free(desc); |
| 3649 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3650 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3651 | goto out; |
| 3652 | } |
| 3653 | free(desc); |
| 3654 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3655 | } else { |
Krzysztof Piotr Oledzki | 260a3bb | 2010-01-06 16:25:05 +0100 | [diff] [blame] | 3656 | stats_error_parsing: |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3657 | 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] | 3658 | 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] | 3659 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3660 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3661 | } |
| 3662 | } |
| 3663 | else if (!strcmp(args[0], "option")) { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3664 | int optnum; |
| 3665 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3666 | if (*(args[1]) == '\0') { |
| 3667 | Alert("parsing [%s:%d]: '%s' expects an option name.\n", |
| 3668 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3669 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3670 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3671 | } |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3672 | |
| 3673 | for (optnum = 0; cfg_opts[optnum].name; optnum++) { |
| 3674 | if (!strcmp(args[1], cfg_opts[optnum].name)) { |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 3675 | if (cfg_opts[optnum].cap == PR_CAP_NONE) { |
| 3676 | Alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n", |
| 3677 | file, linenum, cfg_opts[optnum].name); |
| 3678 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3679 | goto out; |
| 3680 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3681 | if (warnifnotcap(curproxy, cfg_opts[optnum].cap, file, linenum, args[1], NULL)) { |
| 3682 | err_code |= ERR_WARN; |
| 3683 | goto out; |
| 3684 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3685 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 3686 | curproxy->no_options &= ~cfg_opts[optnum].val; |
| 3687 | curproxy->options &= ~cfg_opts[optnum].val; |
| 3688 | |
| 3689 | switch (kwm) { |
| 3690 | case KWM_STD: |
| 3691 | curproxy->options |= cfg_opts[optnum].val; |
| 3692 | break; |
| 3693 | case KWM_NO: |
| 3694 | curproxy->no_options |= cfg_opts[optnum].val; |
| 3695 | break; |
| 3696 | case KWM_DEF: /* already cleared */ |
| 3697 | break; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 3698 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3699 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3700 | goto out; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3701 | } |
| 3702 | } |
| 3703 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 3704 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) { |
| 3705 | if (!strcmp(args[1], cfg_opts2[optnum].name)) { |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 3706 | if (cfg_opts2[optnum].cap == PR_CAP_NONE) { |
| 3707 | Alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n", |
| 3708 | file, linenum, cfg_opts2[optnum].name); |
| 3709 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3710 | goto out; |
| 3711 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3712 | if (warnifnotcap(curproxy, cfg_opts2[optnum].cap, file, linenum, args[1], NULL)) { |
| 3713 | err_code |= ERR_WARN; |
| 3714 | goto out; |
| 3715 | } |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 3716 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 3717 | curproxy->no_options2 &= ~cfg_opts2[optnum].val; |
| 3718 | curproxy->options2 &= ~cfg_opts2[optnum].val; |
| 3719 | |
| 3720 | switch (kwm) { |
| 3721 | case KWM_STD: |
| 3722 | curproxy->options2 |= cfg_opts2[optnum].val; |
| 3723 | break; |
| 3724 | case KWM_NO: |
| 3725 | curproxy->no_options2 |= cfg_opts2[optnum].val; |
| 3726 | break; |
| 3727 | case KWM_DEF: /* already cleared */ |
| 3728 | break; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 3729 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3730 | goto out; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 3731 | } |
| 3732 | } |
| 3733 | |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 3734 | /* HTTP options override each other. They can be cancelled using |
| 3735 | * "no option xxx" which only switches to default mode if the mode |
| 3736 | * was this one (useful for cancelling options set in defaults |
| 3737 | * sections). |
| 3738 | */ |
| 3739 | if (strcmp(args[1], "httpclose") == 0) { |
| 3740 | if (kwm == KWM_STD) { |
| 3741 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3742 | curproxy->options |= PR_O_HTTP_PCL; |
| 3743 | goto out; |
| 3744 | } |
| 3745 | else if (kwm == KWM_NO) { |
| 3746 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_PCL) |
| 3747 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3748 | goto out; |
| 3749 | } |
| 3750 | } |
| 3751 | else if (strcmp(args[1], "forceclose") == 0) { |
| 3752 | if (kwm == KWM_STD) { |
| 3753 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3754 | curproxy->options |= PR_O_HTTP_FCL; |
| 3755 | goto out; |
| 3756 | } |
| 3757 | else if (kwm == KWM_NO) { |
| 3758 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_FCL) |
| 3759 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3760 | goto out; |
| 3761 | } |
| 3762 | } |
| 3763 | else if (strcmp(args[1], "http-server-close") == 0) { |
| 3764 | if (kwm == KWM_STD) { |
| 3765 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3766 | curproxy->options |= PR_O_HTTP_SCL; |
| 3767 | goto out; |
| 3768 | } |
| 3769 | else if (kwm == KWM_NO) { |
| 3770 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_SCL) |
| 3771 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3772 | goto out; |
| 3773 | } |
| 3774 | } |
| 3775 | else if (strcmp(args[1], "http-keep-alive") == 0) { |
| 3776 | if (kwm == KWM_STD) { |
| 3777 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3778 | curproxy->options |= PR_O_HTTP_KAL; |
| 3779 | goto out; |
| 3780 | } |
| 3781 | else if (kwm == KWM_NO) { |
| 3782 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_KAL) |
| 3783 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3784 | goto out; |
| 3785 | } |
| 3786 | } |
| 3787 | else if (strcmp(args[1], "http-tunnel") == 0) { |
| 3788 | if (kwm == KWM_STD) { |
| 3789 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3790 | curproxy->options |= PR_O_HTTP_TUN; |
| 3791 | goto out; |
| 3792 | } |
| 3793 | else if (kwm == KWM_NO) { |
| 3794 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_TUN) |
| 3795 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3796 | goto out; |
| 3797 | } |
| 3798 | } |
| 3799 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 3800 | if (kwm != KWM_STD) { |
| 3801 | 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] | 3802 | file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3803 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3804 | goto out; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3805 | } |
| 3806 | |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3807 | if (!strcmp(args[1], "httplog")) { |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 3808 | char *logformat; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3809 | /* generate a complete HTTP log */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 3810 | logformat = default_http_log_format; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3811 | if (*(args[2]) != '\0') { |
| 3812 | if (!strcmp(args[2], "clf")) { |
| 3813 | curproxy->options2 |= PR_O2_CLFLOG; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 3814 | logformat = clf_http_log_format; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3815 | } else { |
William Lallemand | 629b1c0 | 2015-05-28 18:02:48 +0200 | [diff] [blame] | 3816 | Alert("parsing [%s:%d] : keyword '%s' only supports option 'clf'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3817 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3818 | goto out; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3819 | } |
| 3820 | } |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 3821 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 3822 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 3823 | curproxy->conf.logformat_string != clf_http_log_format) |
| 3824 | free(curproxy->conf.logformat_string); |
| 3825 | curproxy->conf.logformat_string = logformat; |
| 3826 | |
| 3827 | free(curproxy->conf.lfs_file); |
| 3828 | curproxy->conf.lfs_file = strdup(curproxy->conf.args.file); |
| 3829 | curproxy->conf.lfs_line = curproxy->conf.args.line; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3830 | } |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 3831 | else if (!strcmp(args[1], "tcplog")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3832 | /* generate a detailed TCP log */ |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 3833 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 3834 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 3835 | curproxy->conf.logformat_string != clf_http_log_format) |
| 3836 | free(curproxy->conf.logformat_string); |
| 3837 | curproxy->conf.logformat_string = default_tcp_log_format; |
| 3838 | |
| 3839 | free(curproxy->conf.lfs_file); |
| 3840 | curproxy->conf.lfs_file = strdup(curproxy->conf.args.file); |
| 3841 | curproxy->conf.lfs_line = curproxy->conf.args.line; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 3842 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3843 | else if (!strcmp(args[1], "tcpka")) { |
| 3844 | /* enable TCP keep-alives on client and server sessions */ |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3845 | 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] | 3846 | err_code |= ERR_WARN; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3847 | |
| 3848 | if (curproxy->cap & PR_CAP_FE) |
| 3849 | curproxy->options |= PR_O_TCP_CLI_KA; |
| 3850 | if (curproxy->cap & PR_CAP_BE) |
| 3851 | curproxy->options |= PR_O_TCP_SRV_KA; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3852 | } |
| 3853 | else if (!strcmp(args[1], "httpchk")) { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3854 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3855 | err_code |= ERR_WARN; |
| 3856 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3857 | /* use HTTP request to check servers' health */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3858 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 3859 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3860 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 3861 | curproxy->options2 |= PR_O2_HTTP_CHK; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3862 | if (!*args[2]) { /* no argument */ |
| 3863 | curproxy->check_req = strdup(DEF_CHECK_REQ); /* default request */ |
| 3864 | curproxy->check_len = strlen(DEF_CHECK_REQ); |
| 3865 | } else if (!*args[3]) { /* one argument : URI */ |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3866 | 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] | 3867 | curproxy->check_req = (char *)malloc(reqlen); |
| 3868 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3869 | "OPTIONS %s HTTP/1.0\r\n", args[2]); /* URI to use */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3870 | } else { /* more arguments : METHOD URI [HTTP_VER] */ |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3871 | int reqlen = strlen(args[2]) + strlen(args[3]) + 3 + strlen("\r\n"); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3872 | if (*args[4]) |
| 3873 | reqlen += strlen(args[4]); |
| 3874 | else |
| 3875 | reqlen += strlen("HTTP/1.0"); |
| 3876 | |
| 3877 | curproxy->check_req = (char *)malloc(reqlen); |
| 3878 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3879 | "%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] | 3880 | } |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 3881 | } |
| 3882 | else if (!strcmp(args[1], "ssl-hello-chk")) { |
| 3883 | /* use SSLv3 CLIENT HELLO to check servers' health */ |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3884 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3885 | err_code |= ERR_WARN; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3886 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3887 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 3888 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3889 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Willy Tarreau | 07a5490 | 2010-03-29 18:33:29 +0200 | [diff] [blame] | 3890 | curproxy->options2 |= PR_O2_SSL3_CHK; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3891 | } |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 3892 | else if (!strcmp(args[1], "smtpchk")) { |
| 3893 | /* use SMTP request to check servers' health */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3894 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 3895 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3896 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 3897 | curproxy->options2 |= PR_O2_SMTP_CHK; |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 3898 | |
| 3899 | if (!*args[2] || !*args[3]) { /* no argument or incomplete EHLO host */ |
| 3900 | curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */ |
| 3901 | curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ); |
| 3902 | } else { /* ESMTP EHLO, or SMTP HELO, and a hostname */ |
| 3903 | if (!strcmp(args[2], "EHLO") || !strcmp(args[2], "HELO")) { |
| 3904 | int reqlen = strlen(args[2]) + strlen(args[3]) + strlen(" \r\n") + 1; |
| 3905 | curproxy->check_req = (char *)malloc(reqlen); |
| 3906 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
| 3907 | "%s %s\r\n", args[2], args[3]); /* HELO hostname */ |
| 3908 | } else { |
| 3909 | /* this just hits the default for now, but you could potentially expand it to allow for other stuff |
| 3910 | though, it's unlikely you'd want to send anything other than an EHLO or HELO */ |
| 3911 | curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */ |
| 3912 | curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ); |
| 3913 | } |
| 3914 | } |
| 3915 | } |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 3916 | else if (!strcmp(args[1], "pgsql-check")) { |
| 3917 | /* use PostgreSQL request to check servers' health */ |
| 3918 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 3919 | err_code |= ERR_WARN; |
| 3920 | |
| 3921 | free(curproxy->check_req); |
| 3922 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3923 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 3924 | curproxy->options2 |= PR_O2_PGSQL_CHK; |
| 3925 | |
| 3926 | if (*(args[2])) { |
| 3927 | int cur_arg = 2; |
| 3928 | |
| 3929 | while (*(args[cur_arg])) { |
| 3930 | if (strcmp(args[cur_arg], "user") == 0) { |
| 3931 | char * packet; |
| 3932 | uint32_t packet_len; |
| 3933 | uint32_t pv; |
| 3934 | |
| 3935 | /* suboption header - needs additional argument for it */ |
| 3936 | if (*(args[cur_arg+1]) == 0) { |
| 3937 | Alert("parsing [%s:%d] : '%s %s %s' expects <username> as argument.\n", |
| 3938 | file, linenum, args[0], args[1], args[cur_arg]); |
| 3939 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3940 | goto out; |
| 3941 | } |
| 3942 | |
| 3943 | /* uint32_t + uint32_t + strlen("user")+1 + strlen(username)+1 + 1 */ |
| 3944 | packet_len = 4 + 4 + 5 + strlen(args[cur_arg + 1])+1 +1; |
| 3945 | pv = htonl(0x30000); /* protocol version 3.0 */ |
| 3946 | |
| 3947 | packet = (char*) calloc(1, packet_len); |
| 3948 | |
| 3949 | memcpy(packet + 4, &pv, 4); |
| 3950 | |
| 3951 | /* copy "user" */ |
| 3952 | memcpy(packet + 8, "user", 4); |
| 3953 | |
| 3954 | /* copy username */ |
| 3955 | memcpy(packet + 13, args[cur_arg+1], strlen(args[cur_arg+1])); |
| 3956 | |
| 3957 | free(curproxy->check_req); |
| 3958 | curproxy->check_req = packet; |
| 3959 | curproxy->check_len = packet_len; |
| 3960 | |
| 3961 | packet_len = htonl(packet_len); |
| 3962 | memcpy(packet, &packet_len, 4); |
| 3963 | cur_arg += 2; |
| 3964 | } else { |
| 3965 | /* unknown suboption - catchall */ |
| 3966 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'user'.\n", |
| 3967 | file, linenum, args[0], args[1]); |
| 3968 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3969 | goto out; |
| 3970 | } |
| 3971 | } /* end while loop */ |
| 3972 | } |
| 3973 | } |
| 3974 | |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 3975 | else if (!strcmp(args[1], "redis-check")) { |
| 3976 | /* use REDIS PING request to check servers' health */ |
| 3977 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 3978 | err_code |= ERR_WARN; |
| 3979 | |
| 3980 | free(curproxy->check_req); |
| 3981 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3982 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 3983 | curproxy->options2 |= PR_O2_REDIS_CHK; |
| 3984 | |
| 3985 | curproxy->check_req = (char *) malloc(sizeof(DEF_REDIS_CHECK_REQ) - 1); |
| 3986 | memcpy(curproxy->check_req, DEF_REDIS_CHECK_REQ, sizeof(DEF_REDIS_CHECK_REQ) - 1); |
| 3987 | curproxy->check_len = sizeof(DEF_REDIS_CHECK_REQ) - 1; |
| 3988 | } |
| 3989 | |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 3990 | else if (!strcmp(args[1], "mysql-check")) { |
| 3991 | /* use MYSQL request to check servers' health */ |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 3992 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 3993 | err_code |= ERR_WARN; |
| 3994 | |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 3995 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 3996 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3997 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 3998 | curproxy->options2 |= PR_O2_MYSQL_CHK; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 3999 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 4000 | /* 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] | 4001 | * const char mysql40_client_auth_pkt[] = { |
| 4002 | * "\x0e\x00\x00" // packet length |
| 4003 | * "\x01" // packet number |
| 4004 | * "\x00\x00" // client capabilities |
| 4005 | * "\x00\x00\x01" // max packet |
| 4006 | * "haproxy\x00" // username (null terminated string) |
| 4007 | * "\x00" // filler (always 0x00) |
| 4008 | * "\x01\x00\x00" // packet length |
| 4009 | * "\x00" // packet number |
| 4010 | * "\x01" // COM_QUIT command |
| 4011 | * }; |
| 4012 | */ |
| 4013 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 4014 | /* This is an example of a MySQL >=4.1 client Authentication packet provided by Nenad Merdanovic. |
| 4015 | * const char mysql41_client_auth_pkt[] = { |
| 4016 | * "\x0e\x00\x00\" // packet length |
| 4017 | * "\x01" // packet number |
| 4018 | * "\x00\x00\x00\x00" // client capabilities |
| 4019 | * "\x00\x00\x00\x01" // max packet |
| 4020 | * "\x21" // character set (UTF-8) |
| 4021 | * char[23] // All zeroes |
| 4022 | * "haproxy\x00" // username (null terminated string) |
| 4023 | * "\x00" // filler (always 0x00) |
| 4024 | * "\x01\x00\x00" // packet length |
| 4025 | * "\x00" // packet number |
| 4026 | * "\x01" // COM_QUIT command |
| 4027 | * }; |
| 4028 | */ |
| 4029 | |
| 4030 | |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 4031 | if (*(args[2])) { |
| 4032 | int cur_arg = 2; |
| 4033 | |
| 4034 | while (*(args[cur_arg])) { |
| 4035 | if (strcmp(args[cur_arg], "user") == 0) { |
| 4036 | char *mysqluser; |
| 4037 | int packetlen, reqlen, userlen; |
| 4038 | |
| 4039 | /* suboption header - needs additional argument for it */ |
| 4040 | if (*(args[cur_arg+1]) == 0) { |
| 4041 | Alert("parsing [%s:%d] : '%s %s %s' expects <username> as argument.\n", |
| 4042 | file, linenum, args[0], args[1], args[cur_arg]); |
| 4043 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4044 | goto out; |
| 4045 | } |
| 4046 | mysqluser = args[cur_arg + 1]; |
| 4047 | userlen = strlen(mysqluser); |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 4048 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 4049 | if (*(args[cur_arg+2])) { |
| 4050 | if (!strcmp(args[cur_arg+2], "post-41")) { |
| 4051 | packetlen = userlen + 7 + 27; |
| 4052 | reqlen = packetlen + 9; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 4053 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 4054 | free(curproxy->check_req); |
| 4055 | curproxy->check_req = (char *)calloc(1, reqlen); |
| 4056 | curproxy->check_len = reqlen; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 4057 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 4058 | snprintf(curproxy->check_req, 4, "%c%c%c", |
| 4059 | ((unsigned char) packetlen & 0xff), |
| 4060 | ((unsigned char) (packetlen >> 8) & 0xff), |
| 4061 | ((unsigned char) (packetlen >> 16) & 0xff)); |
| 4062 | |
| 4063 | curproxy->check_req[3] = 1; |
| 4064 | curproxy->check_req[5] = 130; |
| 4065 | curproxy->check_req[11] = 1; |
| 4066 | curproxy->check_req[12] = 33; |
| 4067 | memcpy(&curproxy->check_req[36], mysqluser, userlen); |
| 4068 | curproxy->check_req[36 + userlen + 1 + 1] = 1; |
| 4069 | curproxy->check_req[36 + userlen + 1 + 1 + 4] = 1; |
| 4070 | cur_arg += 3; |
| 4071 | } else { |
| 4072 | Alert("parsing [%s:%d] : keyword '%s' only supports option 'post-41'.\n", file, linenum, args[cur_arg+2]); |
| 4073 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4074 | goto out; |
| 4075 | } |
| 4076 | } else { |
| 4077 | packetlen = userlen + 7; |
| 4078 | reqlen = packetlen + 9; |
| 4079 | |
| 4080 | free(curproxy->check_req); |
| 4081 | curproxy->check_req = (char *)calloc(1, reqlen); |
| 4082 | curproxy->check_len = reqlen; |
| 4083 | |
| 4084 | snprintf(curproxy->check_req, 4, "%c%c%c", |
| 4085 | ((unsigned char) packetlen & 0xff), |
| 4086 | ((unsigned char) (packetlen >> 8) & 0xff), |
| 4087 | ((unsigned char) (packetlen >> 16) & 0xff)); |
| 4088 | |
| 4089 | curproxy->check_req[3] = 1; |
| 4090 | curproxy->check_req[5] = 128; |
| 4091 | curproxy->check_req[8] = 1; |
| 4092 | memcpy(&curproxy->check_req[9], mysqluser, userlen); |
| 4093 | curproxy->check_req[9 + userlen + 1 + 1] = 1; |
| 4094 | curproxy->check_req[9 + userlen + 1 + 1 + 4] = 1; |
| 4095 | cur_arg += 2; |
| 4096 | } |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 4097 | } else { |
| 4098 | /* unknown suboption - catchall */ |
| 4099 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'user'.\n", |
| 4100 | file, linenum, args[0], args[1]); |
| 4101 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4102 | goto out; |
| 4103 | } |
| 4104 | } /* end while loop */ |
| 4105 | } |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 4106 | } |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 4107 | else if (!strcmp(args[1], "ldap-check")) { |
| 4108 | /* use LDAP request to check servers' health */ |
| 4109 | free(curproxy->check_req); |
| 4110 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4111 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 4112 | curproxy->options2 |= PR_O2_LDAP_CHK; |
| 4113 | |
| 4114 | curproxy->check_req = (char *) malloc(sizeof(DEF_LDAP_CHECK_REQ) - 1); |
| 4115 | memcpy(curproxy->check_req, DEF_LDAP_CHECK_REQ, sizeof(DEF_LDAP_CHECK_REQ) - 1); |
| 4116 | curproxy->check_len = sizeof(DEF_LDAP_CHECK_REQ) - 1; |
| 4117 | } |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 4118 | else if (!strcmp(args[1], "tcp-check")) { |
| 4119 | /* use raw TCPCHK send/expect to check servers' health */ |
| 4120 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 4121 | err_code |= ERR_WARN; |
| 4122 | |
| 4123 | free(curproxy->check_req); |
| 4124 | curproxy->check_req = NULL; |
| 4125 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 4126 | curproxy->options2 |= PR_O2_TCPCHK_CHK; |
| 4127 | } |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 4128 | else if (!strcmp(args[1], "forwardfor")) { |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 4129 | int cur_arg; |
| 4130 | |
| 4131 | /* insert x-forwarded-for field, but not for the IP address listed as an except. |
| 4132 | * set default options (ie: bitfield, header name, etc) |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 4133 | */ |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 4134 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 4135 | curproxy->options |= PR_O_FWDFOR | PR_O_FF_ALWAYS; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 4136 | |
| 4137 | free(curproxy->fwdfor_hdr_name); |
| 4138 | curproxy->fwdfor_hdr_name = strdup(DEF_XFORWARDFOR_HDR); |
| 4139 | curproxy->fwdfor_hdr_len = strlen(DEF_XFORWARDFOR_HDR); |
| 4140 | |
| 4141 | /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */ |
| 4142 | cur_arg = 2; |
| 4143 | while (*(args[cur_arg])) { |
| 4144 | if (!strcmp(args[cur_arg], "except")) { |
| 4145 | /* suboption except - needs additional argument for it */ |
Thierry FOURNIER | fc7ac7b | 2014-02-11 15:23:04 +0100 | [diff] [blame] | 4146 | 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] | 4147 | Alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n", |
| 4148 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4149 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4150 | goto out; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 4151 | } |
| 4152 | /* flush useless bits */ |
| 4153 | curproxy->except_net.s_addr &= curproxy->except_mask.s_addr; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 4154 | cur_arg += 2; |
| 4155 | } else if (!strcmp(args[cur_arg], "header")) { |
| 4156 | /* suboption header - needs additional argument for it */ |
| 4157 | if (*(args[cur_arg+1]) == 0) { |
| 4158 | Alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 4159 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4160 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4161 | goto out; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 4162 | } |
| 4163 | free(curproxy->fwdfor_hdr_name); |
| 4164 | curproxy->fwdfor_hdr_name = strdup(args[cur_arg+1]); |
| 4165 | curproxy->fwdfor_hdr_len = strlen(curproxy->fwdfor_hdr_name); |
| 4166 | cur_arg += 2; |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 4167 | } else if (!strcmp(args[cur_arg], "if-none")) { |
| 4168 | curproxy->options &= ~PR_O_FF_ALWAYS; |
| 4169 | cur_arg += 1; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 4170 | } else { |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 4171 | /* unknown suboption - catchall */ |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 4172 | 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] | 4173 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4174 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4175 | goto out; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 4176 | } |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 4177 | } /* end while loop */ |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 4178 | } |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 4179 | else if (!strcmp(args[1], "originalto")) { |
| 4180 | int cur_arg; |
| 4181 | |
| 4182 | /* insert x-original-to field, but not for the IP address listed as an except. |
| 4183 | * set default options (ie: bitfield, header name, etc) |
| 4184 | */ |
| 4185 | |
| 4186 | curproxy->options |= PR_O_ORGTO; |
| 4187 | |
| 4188 | free(curproxy->orgto_hdr_name); |
| 4189 | curproxy->orgto_hdr_name = strdup(DEF_XORIGINALTO_HDR); |
| 4190 | curproxy->orgto_hdr_len = strlen(DEF_XORIGINALTO_HDR); |
| 4191 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 4192 | /* 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] | 4193 | cur_arg = 2; |
| 4194 | while (*(args[cur_arg])) { |
| 4195 | if (!strcmp(args[cur_arg], "except")) { |
| 4196 | /* suboption except - needs additional argument for it */ |
Thierry FOURNIER | fc7ac7b | 2014-02-11 15:23:04 +0100 | [diff] [blame] | 4197 | 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] | 4198 | Alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n", |
| 4199 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4200 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4201 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 4202 | } |
| 4203 | /* flush useless bits */ |
| 4204 | curproxy->except_to.s_addr &= curproxy->except_mask_to.s_addr; |
| 4205 | cur_arg += 2; |
| 4206 | } else if (!strcmp(args[cur_arg], "header")) { |
| 4207 | /* suboption header - needs additional argument for it */ |
| 4208 | if (*(args[cur_arg+1]) == 0) { |
| 4209 | Alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 4210 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4211 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4212 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 4213 | } |
| 4214 | free(curproxy->orgto_hdr_name); |
| 4215 | curproxy->orgto_hdr_name = strdup(args[cur_arg+1]); |
| 4216 | curproxy->orgto_hdr_len = strlen(curproxy->orgto_hdr_name); |
| 4217 | cur_arg += 2; |
| 4218 | } else { |
| 4219 | /* unknown suboption - catchall */ |
| 4220 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n", |
| 4221 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4222 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4223 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 4224 | } |
| 4225 | } /* end while loop */ |
| 4226 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4227 | else { |
| 4228 | Alert("parsing [%s:%d] : unknown option '%s'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4229 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4230 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4231 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4232 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4233 | } |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 4234 | else if (!strcmp(args[0], "default_backend")) { |
| 4235 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4236 | err_code |= ERR_WARN; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 4237 | |
| 4238 | if (*(args[1]) == 0) { |
| 4239 | 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] | 4240 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4241 | goto out; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 4242 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 4243 | free(curproxy->defbe.name); |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 4244 | curproxy->defbe.name = strdup(args[1]); |
| 4245 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4246 | else if (!strcmp(args[0], "redispatch") || !strcmp(args[0], "redisp")) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4247 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4248 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4249 | |
Willy Tarreau | a3c504c | 2014-04-28 22:37:32 +0200 | [diff] [blame] | 4250 | if (!already_warned(WARN_REDISPATCH_DEPRECATED)) |
| 4251 | 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] | 4252 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4253 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4254 | /* enable reconnections to dispatch */ |
| 4255 | curproxy->options |= PR_O_REDISP; |
| 4256 | } |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 4257 | else if (!strcmp(args[0], "http-check")) { |
| 4258 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4259 | err_code |= ERR_WARN; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 4260 | |
| 4261 | if (strcmp(args[1], "disable-on-404") == 0) { |
| 4262 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 4263 | curproxy->options |= PR_O_DISABLE404; |
| 4264 | } |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 4265 | else if (strcmp(args[1], "send-state") == 0) { |
| 4266 | /* enable emission of the apparent state of a server in HTTP checks */ |
| 4267 | curproxy->options2 |= PR_O2_CHK_SNDST; |
| 4268 | } |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 4269 | else if (strcmp(args[1], "expect") == 0) { |
| 4270 | const char *ptr_arg; |
| 4271 | int cur_arg; |
| 4272 | |
| 4273 | if (curproxy->options2 & PR_O2_EXP_TYPE) { |
| 4274 | Alert("parsing [%s:%d] : '%s %s' already specified.\n", file, linenum, args[0], args[1]); |
| 4275 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4276 | goto out; |
| 4277 | } |
| 4278 | |
| 4279 | cur_arg = 2; |
| 4280 | /* consider exclamation marks, sole or at the beginning of a word */ |
| 4281 | while (*(ptr_arg = args[cur_arg])) { |
| 4282 | while (*ptr_arg == '!') { |
| 4283 | curproxy->options2 ^= PR_O2_EXP_INV; |
| 4284 | ptr_arg++; |
| 4285 | } |
| 4286 | if (*ptr_arg) |
| 4287 | break; |
| 4288 | cur_arg++; |
| 4289 | } |
| 4290 | /* now ptr_arg points to the beginning of a word past any possible |
| 4291 | * exclamation mark, and cur_arg is the argument which holds this word. |
| 4292 | */ |
| 4293 | if (strcmp(ptr_arg, "status") == 0) { |
| 4294 | if (!*(args[cur_arg + 1])) { |
| 4295 | Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 4296 | file, linenum, args[0], args[1], ptr_arg); |
| 4297 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4298 | goto out; |
| 4299 | } |
| 4300 | curproxy->options2 |= PR_O2_EXP_STS; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 4301 | free(curproxy->expect_str); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 4302 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
| 4303 | } |
| 4304 | else if (strcmp(ptr_arg, "string") == 0) { |
| 4305 | if (!*(args[cur_arg + 1])) { |
| 4306 | Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 4307 | file, linenum, args[0], args[1], ptr_arg); |
| 4308 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4309 | goto out; |
| 4310 | } |
| 4311 | curproxy->options2 |= PR_O2_EXP_STR; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 4312 | free(curproxy->expect_str); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 4313 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
| 4314 | } |
| 4315 | else if (strcmp(ptr_arg, "rstatus") == 0) { |
| 4316 | if (!*(args[cur_arg + 1])) { |
| 4317 | Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 4318 | file, linenum, args[0], args[1], ptr_arg); |
| 4319 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4320 | goto out; |
| 4321 | } |
| 4322 | curproxy->options2 |= PR_O2_EXP_RSTS; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 4323 | free(curproxy->expect_str); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 4324 | if (curproxy->expect_regex) { |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 4325 | regex_free(curproxy->expect_regex); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 4326 | free(curproxy->expect_regex); |
| 4327 | curproxy->expect_regex = NULL; |
| 4328 | } |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 4329 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 4330 | curproxy->expect_regex = calloc(1, sizeof(*curproxy->expect_regex)); |
| 4331 | error = NULL; |
| 4332 | if (!regex_comp(args[cur_arg + 1], curproxy->expect_regex, 1, 1, &error)) { |
| 4333 | Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s': %s.\n", |
| 4334 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1], error); |
| 4335 | free(error); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 4336 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4337 | goto out; |
| 4338 | } |
| 4339 | } |
| 4340 | else if (strcmp(ptr_arg, "rstring") == 0) { |
| 4341 | if (!*(args[cur_arg + 1])) { |
| 4342 | Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 4343 | file, linenum, args[0], args[1], ptr_arg); |
| 4344 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4345 | goto out; |
| 4346 | } |
| 4347 | curproxy->options2 |= PR_O2_EXP_RSTR; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 4348 | free(curproxy->expect_str); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 4349 | if (curproxy->expect_regex) { |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 4350 | regex_free(curproxy->expect_regex); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 4351 | free(curproxy->expect_regex); |
| 4352 | curproxy->expect_regex = NULL; |
| 4353 | } |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 4354 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 4355 | curproxy->expect_regex = calloc(1, sizeof(*curproxy->expect_regex)); |
| 4356 | error = NULL; |
| 4357 | if (!regex_comp(args[cur_arg + 1], curproxy->expect_regex, 1, 1, &error)) { |
| 4358 | Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s': %s.\n", |
| 4359 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1], error); |
| 4360 | free(error); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 4361 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4362 | goto out; |
| 4363 | } |
| 4364 | } |
| 4365 | else { |
| 4366 | Alert("parsing [%s:%d] : '%s %s' only supports [!] 'status', 'string', 'rstatus', 'rstring', found '%s'.\n", |
| 4367 | file, linenum, args[0], args[1], ptr_arg); |
| 4368 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4369 | goto out; |
| 4370 | } |
| 4371 | } |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 4372 | else { |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 4373 | 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] | 4374 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4375 | goto out; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 4376 | } |
| 4377 | } |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 4378 | else if (!strcmp(args[0], "tcp-check")) { |
| 4379 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 4380 | err_code |= ERR_WARN; |
| 4381 | |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 4382 | if (strcmp(args[1], "connect") == 0) { |
| 4383 | const char *ptr_arg; |
| 4384 | int cur_arg; |
| 4385 | struct tcpcheck_rule *tcpcheck; |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 4386 | |
| 4387 | /* check if first rule is also a 'connect' action */ |
Willy Tarreau | 5bff059 | 2015-05-13 12:24:53 +0200 | [diff] [blame] | 4388 | tcpcheck = LIST_NEXT(&curproxy->tcpcheck_rules, struct tcpcheck_rule *, list); |
Willy Tarreau | 97fccc8 | 2015-05-13 12:08:21 +0200 | [diff] [blame] | 4389 | |
Willy Tarreau | 5bff059 | 2015-05-13 12:24:53 +0200 | [diff] [blame] | 4390 | if (&tcpcheck->list != &curproxy->tcpcheck_rules |
| 4391 | && tcpcheck->action != TCPCHK_ACT_CONNECT) { |
| 4392 | Alert("parsing [%s:%d] : first step MUST also be a 'connect' when there is a 'connect' step in the tcp-check ruleset.\n", |
| 4393 | file, linenum); |
| 4394 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4395 | goto out; |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 4396 | } |
| 4397 | |
| 4398 | cur_arg = 2; |
| 4399 | tcpcheck = (struct tcpcheck_rule *)calloc(1, sizeof(*tcpcheck)); |
| 4400 | tcpcheck->action = TCPCHK_ACT_CONNECT; |
| 4401 | |
| 4402 | /* parsing each parameters to fill up the rule */ |
| 4403 | while (*(ptr_arg = args[cur_arg])) { |
| 4404 | /* tcp port */ |
| 4405 | if (strcmp(args[cur_arg], "port") == 0) { |
| 4406 | if ( (atol(args[cur_arg + 1]) > 65535) || |
| 4407 | (atol(args[cur_arg + 1]) < 1) ){ |
| 4408 | Alert("parsing [%s:%d] : '%s %s %s' expects a valid TCP port (from range 1 to 65535), got %s.\n", |
| 4409 | file, linenum, args[0], args[1], "port", args[cur_arg + 1]); |
| 4410 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4411 | goto out; |
| 4412 | } |
| 4413 | tcpcheck->port = atol(args[cur_arg + 1]); |
| 4414 | cur_arg += 2; |
| 4415 | } |
| 4416 | /* send proxy protocol */ |
| 4417 | else if (strcmp(args[cur_arg], "send-proxy") == 0) { |
| 4418 | tcpcheck->conn_opts |= TCPCHK_OPT_SEND_PROXY; |
| 4419 | cur_arg++; |
| 4420 | } |
| 4421 | #ifdef USE_OPENSSL |
| 4422 | else if (strcmp(args[cur_arg], "ssl") == 0) { |
| 4423 | curproxy->options |= PR_O_TCPCHK_SSL; |
| 4424 | tcpcheck->conn_opts |= TCPCHK_OPT_SSL; |
| 4425 | cur_arg++; |
| 4426 | } |
| 4427 | #endif /* USE_OPENSSL */ |
| 4428 | else { |
| 4429 | #ifdef USE_OPENSSL |
| 4430 | Alert("parsing [%s:%d] : '%s %s' expects 'port', 'send-proxy' or 'ssl' but got '%s' as argument.\n", |
| 4431 | #else /* USE_OPENSSL */ |
| 4432 | Alert("parsing [%s:%d] : '%s %s' expects 'port', 'send-proxy' or but got '%s' as argument.\n", |
| 4433 | #endif /* USE_OPENSSL */ |
| 4434 | file, linenum, args[0], args[1], args[cur_arg]); |
| 4435 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4436 | goto out; |
| 4437 | } |
| 4438 | |
| 4439 | } |
| 4440 | |
| 4441 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 4442 | } |
| 4443 | else if (strcmp(args[1], "send") == 0) { |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 4444 | if (! *(args[2]) ) { |
| 4445 | /* SEND string expected */ |
| 4446 | Alert("parsing [%s:%d] : '%s %s %s' expects <STRING> as argument.\n", |
| 4447 | file, linenum, args[0], args[1], args[2]); |
| 4448 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4449 | goto out; |
| 4450 | } else { |
| 4451 | struct tcpcheck_rule *tcpcheck; |
| 4452 | |
| 4453 | tcpcheck = (struct tcpcheck_rule *)calloc(1, sizeof(*tcpcheck)); |
| 4454 | |
| 4455 | tcpcheck->action = TCPCHK_ACT_SEND; |
| 4456 | tcpcheck->string_len = strlen(args[2]); |
| 4457 | tcpcheck->string = strdup(args[2]); |
| 4458 | tcpcheck->expect_regex = NULL; |
| 4459 | |
| 4460 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 4461 | } |
| 4462 | } |
| 4463 | else if (strcmp(args[1], "send-binary") == 0) { |
| 4464 | if (! *(args[2]) ) { |
| 4465 | /* SEND binary string expected */ |
| 4466 | Alert("parsing [%s:%d] : '%s %s %s' expects <BINARY STRING> as argument.\n", |
| 4467 | file, linenum, args[0], args[1], args[2]); |
| 4468 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4469 | goto out; |
| 4470 | } else { |
| 4471 | struct tcpcheck_rule *tcpcheck; |
| 4472 | char *err = NULL; |
| 4473 | |
| 4474 | tcpcheck = (struct tcpcheck_rule *)calloc(1, sizeof(*tcpcheck)); |
| 4475 | |
| 4476 | tcpcheck->action = TCPCHK_ACT_SEND; |
| 4477 | if (parse_binary(args[2], &tcpcheck->string, &tcpcheck->string_len, &err) == 0) { |
| 4478 | Alert("parsing [%s:%d] : '%s %s %s' expects <BINARY STRING> as argument, but %s\n", |
| 4479 | file, linenum, args[0], args[1], args[2], err); |
| 4480 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4481 | goto out; |
| 4482 | } |
| 4483 | tcpcheck->expect_regex = NULL; |
| 4484 | |
| 4485 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 4486 | } |
| 4487 | } |
| 4488 | else if (strcmp(args[1], "expect") == 0) { |
| 4489 | const char *ptr_arg; |
| 4490 | int cur_arg; |
| 4491 | int inverse = 0; |
| 4492 | |
| 4493 | if (curproxy->options2 & PR_O2_EXP_TYPE) { |
| 4494 | Alert("parsing [%s:%d] : '%s %s' already specified.\n", file, linenum, args[0], args[1]); |
| 4495 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4496 | goto out; |
| 4497 | } |
| 4498 | |
| 4499 | cur_arg = 2; |
| 4500 | /* consider exclamation marks, sole or at the beginning of a word */ |
| 4501 | while (*(ptr_arg = args[cur_arg])) { |
| 4502 | while (*ptr_arg == '!') { |
| 4503 | inverse = !inverse; |
| 4504 | ptr_arg++; |
| 4505 | } |
| 4506 | if (*ptr_arg) |
| 4507 | break; |
| 4508 | cur_arg++; |
| 4509 | } |
| 4510 | /* now ptr_arg points to the beginning of a word past any possible |
| 4511 | * exclamation mark, and cur_arg is the argument which holds this word. |
| 4512 | */ |
| 4513 | if (strcmp(ptr_arg, "binary") == 0) { |
| 4514 | if (!*(args[cur_arg + 1])) { |
| 4515 | Alert("parsing [%s:%d] : '%s %s %s' expects <binary string> as an argument.\n", |
| 4516 | file, linenum, args[0], args[1], ptr_arg); |
| 4517 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4518 | goto out; |
| 4519 | } |
| 4520 | struct tcpcheck_rule *tcpcheck; |
| 4521 | char *err = NULL; |
| 4522 | |
| 4523 | tcpcheck = (struct tcpcheck_rule *)calloc(1, sizeof(*tcpcheck)); |
| 4524 | |
| 4525 | tcpcheck->action = TCPCHK_ACT_EXPECT; |
| 4526 | if (parse_binary(args[cur_arg + 1], &tcpcheck->string, &tcpcheck->string_len, &err) == 0) { |
| 4527 | Alert("parsing [%s:%d] : '%s %s %s' expects <BINARY STRING> as argument, but %s\n", |
| 4528 | file, linenum, args[0], args[1], args[2], err); |
| 4529 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4530 | goto out; |
| 4531 | } |
| 4532 | tcpcheck->expect_regex = NULL; |
| 4533 | tcpcheck->inverse = inverse; |
| 4534 | |
| 4535 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 4536 | } |
| 4537 | else if (strcmp(ptr_arg, "string") == 0) { |
| 4538 | if (!*(args[cur_arg + 1])) { |
| 4539 | Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 4540 | file, linenum, args[0], args[1], ptr_arg); |
| 4541 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4542 | goto out; |
| 4543 | } |
| 4544 | struct tcpcheck_rule *tcpcheck; |
| 4545 | |
| 4546 | tcpcheck = (struct tcpcheck_rule *)calloc(1, sizeof(*tcpcheck)); |
| 4547 | |
| 4548 | tcpcheck->action = TCPCHK_ACT_EXPECT; |
| 4549 | tcpcheck->string_len = strlen(args[cur_arg + 1]); |
| 4550 | tcpcheck->string = strdup(args[cur_arg + 1]); |
| 4551 | tcpcheck->expect_regex = NULL; |
| 4552 | tcpcheck->inverse = inverse; |
| 4553 | |
| 4554 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 4555 | } |
| 4556 | else if (strcmp(ptr_arg, "rstring") == 0) { |
| 4557 | if (!*(args[cur_arg + 1])) { |
| 4558 | Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 4559 | file, linenum, args[0], args[1], ptr_arg); |
| 4560 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4561 | goto out; |
| 4562 | } |
| 4563 | struct tcpcheck_rule *tcpcheck; |
| 4564 | |
| 4565 | tcpcheck = (struct tcpcheck_rule *)calloc(1, sizeof(*tcpcheck)); |
| 4566 | |
| 4567 | tcpcheck->action = TCPCHK_ACT_EXPECT; |
| 4568 | tcpcheck->string_len = 0; |
| 4569 | tcpcheck->string = NULL; |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 4570 | tcpcheck->expect_regex = calloc(1, sizeof(*tcpcheck->expect_regex)); |
| 4571 | error = NULL; |
| 4572 | if (!regex_comp(args[cur_arg + 1], tcpcheck->expect_regex, 1, 1, &error)) { |
| 4573 | Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s': %s.\n", |
| 4574 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1], error); |
| 4575 | free(error); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 4576 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4577 | goto out; |
| 4578 | } |
| 4579 | tcpcheck->inverse = inverse; |
| 4580 | |
| 4581 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 4582 | } |
| 4583 | else { |
| 4584 | Alert("parsing [%s:%d] : '%s %s' only supports [!] 'binary', 'string', 'rstring', found '%s'.\n", |
| 4585 | file, linenum, args[0], args[1], ptr_arg); |
| 4586 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4587 | goto out; |
| 4588 | } |
| 4589 | } |
| 4590 | else { |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 4591 | 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] | 4592 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4593 | goto out; |
| 4594 | } |
| 4595 | } |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 4596 | else if (!strcmp(args[0], "monitor")) { |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 4597 | if (curproxy == &defproxy) { |
| 4598 | 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] | 4599 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4600 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 4601 | } |
| 4602 | |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 4603 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4604 | err_code |= ERR_WARN; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 4605 | |
| 4606 | if (strcmp(args[1], "fail") == 0) { |
| 4607 | /* add a condition to fail monitor requests */ |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 4608 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 4609 | Alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n", |
| 4610 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4611 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4612 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 4613 | } |
| 4614 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 4615 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 4616 | Alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition : %s.\n", |
| 4617 | file, linenum, args[0], args[1], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4618 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4619 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 4620 | } |
| 4621 | LIST_ADDQ(&curproxy->mon_fail_cond, &cond->list); |
| 4622 | } |
| 4623 | else { |
| 4624 | 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] | 4625 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4626 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 4627 | } |
| 4628 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4629 | #ifdef TPROXY |
| 4630 | else if (!strcmp(args[0], "transparent")) { |
| 4631 | /* enable transparent proxy connections */ |
| 4632 | curproxy->options |= PR_O_TRANSP; |
| 4633 | } |
| 4634 | #endif |
| 4635 | else if (!strcmp(args[0], "maxconn")) { /* maxconn */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4636 | 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] | 4637 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4638 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4639 | if (*(args[1]) == 0) { |
| 4640 | 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] | 4641 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4642 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4643 | } |
| 4644 | curproxy->maxconn = atol(args[1]); |
| 4645 | } |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 4646 | else if (!strcmp(args[0], "backlog")) { /* backlog */ |
| 4647 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4648 | err_code |= ERR_WARN; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 4649 | |
| 4650 | if (*(args[1]) == 0) { |
| 4651 | 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] | 4652 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4653 | goto out; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 4654 | } |
| 4655 | curproxy->backlog = atol(args[1]); |
| 4656 | } |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 4657 | else if (!strcmp(args[0], "fullconn")) { /* fullconn */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4658 | 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] | 4659 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4660 | |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 4661 | if (*(args[1]) == 0) { |
| 4662 | 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] | 4663 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4664 | goto out; |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 4665 | } |
| 4666 | curproxy->fullconn = atol(args[1]); |
| 4667 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4668 | else if (!strcmp(args[0], "grace")) { /* grace time (ms) */ |
| 4669 | if (*(args[1]) == 0) { |
| 4670 | 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] | 4671 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4672 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4673 | } |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4674 | err = parse_time_err(args[1], &val, TIME_UNIT_MS); |
| 4675 | if (err) { |
| 4676 | Alert("parsing [%s:%d] : unexpected character '%c' in grace time.\n", |
| 4677 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4678 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4679 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4680 | } |
| 4681 | curproxy->grace = val; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4682 | } |
| 4683 | else if (!strcmp(args[0], "dispatch")) { /* dispatch address */ |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4684 | struct sockaddr_storage *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4685 | int port1, port2; |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 4686 | struct protocol *proto; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4687 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4688 | if (curproxy == &defproxy) { |
| 4689 | 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] | 4690 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4691 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4692 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4693 | else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4694 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4695 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 4696 | sk = str2sa_range(args[1], &port1, &port2, &errmsg, NULL); |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4697 | if (!sk) { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 4698 | Alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 4699 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 4700 | goto out; |
| 4701 | } |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 4702 | |
| 4703 | proto = protocol_by_family(sk->ss_family); |
| 4704 | if (!proto || !proto->connect) { |
| 4705 | Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 4706 | file, linenum, args[0], args[1]); |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4707 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4708 | goto out; |
| 4709 | } |
| 4710 | |
| 4711 | if (port1 != port2) { |
| 4712 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'.\n", |
| 4713 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4714 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4715 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4716 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4717 | |
| 4718 | if (!port1) { |
| 4719 | Alert("parsing [%s:%d] : '%s' : missing port number in '%s', <addr:port> expected.\n", |
| 4720 | file, linenum, args[0], args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4721 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4722 | goto out; |
| 4723 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4724 | |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4725 | curproxy->dispatch_addr = *sk; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4726 | curproxy->options |= PR_O_DISPATCH; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4727 | } |
| 4728 | else if (!strcmp(args[0], "balance")) { /* set balancing with optional algorithm */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4729 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4730 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4731 | |
Willy Tarreau | a93c74b | 2012-05-08 18:14:39 +0200 | [diff] [blame] | 4732 | if (backend_parse_balance((const char **)args + 1, &errmsg, curproxy) < 0) { |
| 4733 | Alert("parsing [%s:%d] : %s %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4734 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4735 | goto out; |
Willy Tarreau | 2fcb500 | 2007-05-08 13:35:26 +0200 | [diff] [blame] | 4736 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4737 | } |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 4738 | else if (!strcmp(args[0], "hash-type")) { /* set hashing method */ |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 4739 | /** |
| 4740 | * The syntax for hash-type config element is |
| 4741 | * hash-type {map-based|consistent} [[<algo>] avalanche] |
| 4742 | * |
| 4743 | * The default hash function is sdbm for map-based and sdbm+avalanche for consistent. |
| 4744 | */ |
| 4745 | 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] | 4746 | |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 4747 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 4748 | err_code |= ERR_WARN; |
| 4749 | |
| 4750 | if (strcmp(args[1], "consistent") == 0) { /* use consistent hashing */ |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 4751 | curproxy->lbprm.algo |= BE_LB_HASH_CONS; |
| 4752 | } |
| 4753 | else if (strcmp(args[1], "map-based") == 0) { /* use map-based hashing */ |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 4754 | curproxy->lbprm.algo |= BE_LB_HASH_MAP; |
| 4755 | } |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 4756 | else if (strcmp(args[1], "avalanche") == 0) { |
| 4757 | 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]); |
| 4758 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4759 | goto out; |
Willy Tarreau | 798a39c | 2010-11-24 15:04:29 +0100 | [diff] [blame] | 4760 | } |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 4761 | else { |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 4762 | 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] | 4763 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4764 | goto out; |
| 4765 | } |
Bhaskar | 98634f0 | 2013-10-29 23:30:51 -0400 | [diff] [blame] | 4766 | |
| 4767 | /* set the hash function to use */ |
| 4768 | if (!*args[2]) { |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 4769 | /* the default algo is sdbm */ |
Bhaskar | 98634f0 | 2013-10-29 23:30:51 -0400 | [diff] [blame] | 4770 | curproxy->lbprm.algo |= BE_LB_HFCN_SDBM; |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 4771 | |
| 4772 | /* if consistent with no argument, then avalanche modifier is also applied */ |
| 4773 | if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS) |
| 4774 | curproxy->lbprm.algo |= BE_LB_HMOD_AVAL; |
Bhaskar | 98634f0 | 2013-10-29 23:30:51 -0400 | [diff] [blame] | 4775 | } else { |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 4776 | /* set the hash function */ |
| 4777 | if (!strcmp(args[2], "sdbm")) { |
| 4778 | curproxy->lbprm.algo |= BE_LB_HFCN_SDBM; |
| 4779 | } |
| 4780 | else if (!strcmp(args[2], "djb2")) { |
| 4781 | curproxy->lbprm.algo |= BE_LB_HFCN_DJB2; |
Willy Tarreau | a0f4271 | 2013-11-14 14:30:35 +0100 | [diff] [blame] | 4782 | } else if (!strcmp(args[2], "wt6")) { |
| 4783 | curproxy->lbprm.algo |= BE_LB_HFCN_WT6; |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 4784 | } |
| 4785 | else { |
Willy Tarreau | a0f4271 | 2013-11-14 14:30:35 +0100 | [diff] [blame] | 4786 | 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] | 4787 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4788 | goto out; |
| 4789 | } |
| 4790 | |
| 4791 | /* set the hash modifier */ |
| 4792 | if (!strcmp(args[3], "avalanche")) { |
| 4793 | curproxy->lbprm.algo |= BE_LB_HMOD_AVAL; |
| 4794 | } |
| 4795 | else if (*args[3]) { |
| 4796 | Alert("parsing [%s:%d] : '%s' only supports 'avalanche' as a modifier for hash functions.\n", file, linenum, args[0]); |
| 4797 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4798 | goto out; |
| 4799 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4800 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 4801 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 4802 | else if (strcmp(args[0], "unique-id-format") == 0) { |
| 4803 | if (!*(args[1])) { |
| 4804 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 4805 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4806 | goto out; |
| 4807 | } |
William Lallemand | 3203ff4 | 2012-11-11 17:30:56 +0100 | [diff] [blame] | 4808 | if (*(args[2])) { |
| 4809 | Alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]); |
| 4810 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4811 | goto out; |
| 4812 | } |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 4813 | free(curproxy->conf.uniqueid_format_string); |
| 4814 | curproxy->conf.uniqueid_format_string = strdup(args[1]); |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 4815 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 4816 | free(curproxy->conf.uif_file); |
| 4817 | curproxy->conf.uif_file = strdup(curproxy->conf.args.file); |
| 4818 | curproxy->conf.uif_line = curproxy->conf.args.line; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4819 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 4820 | |
| 4821 | else if (strcmp(args[0], "unique-id-header") == 0) { |
| 4822 | if (!*(args[1])) { |
| 4823 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 4824 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4825 | goto out; |
| 4826 | } |
| 4827 | free(curproxy->header_unique_id); |
| 4828 | curproxy->header_unique_id = strdup(args[1]); |
| 4829 | } |
| 4830 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4831 | else if (strcmp(args[0], "log-format") == 0) { |
| 4832 | if (!*(args[1])) { |
| 4833 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 4834 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4835 | goto out; |
| 4836 | } |
William Lallemand | 3203ff4 | 2012-11-11 17:30:56 +0100 | [diff] [blame] | 4837 | if (*(args[2])) { |
| 4838 | Alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]); |
| 4839 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4840 | goto out; |
| 4841 | } |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 4842 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 4843 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 4844 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 4845 | curproxy->conf.logformat_string != clf_http_log_format) |
| 4846 | free(curproxy->conf.logformat_string); |
| 4847 | curproxy->conf.logformat_string = strdup(args[1]); |
| 4848 | |
| 4849 | free(curproxy->conf.lfs_file); |
| 4850 | curproxy->conf.lfs_file = strdup(curproxy->conf.args.file); |
| 4851 | curproxy->conf.lfs_line = curproxy->conf.args.line; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 4852 | |
| 4853 | /* get a chance to improve log-format error reporting by |
| 4854 | * reporting the correct line-number when possible. |
| 4855 | */ |
| 4856 | if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) { |
| 4857 | Warning("parsing [%s:%d] : backend '%s' : 'log-format' directive is ignored in backends.\n", |
| 4858 | file, linenum, curproxy->id); |
| 4859 | err_code |= ERR_WARN; |
| 4860 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4861 | } |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4862 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4863 | else if (!strcmp(args[0], "log") && kwm == KWM_NO) { |
| 4864 | /* delete previous herited or defined syslog servers */ |
| 4865 | struct logsrv *back; |
| 4866 | |
| 4867 | if (*(args[1]) != 0) { |
| 4868 | Alert("parsing [%s:%d]:%s : 'no log' does not expect arguments.\n", file, linenum, args[1]); |
| 4869 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4870 | goto out; |
| 4871 | } |
| 4872 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4873 | list_for_each_entry_safe(tmplogsrv, back, &curproxy->logsrvs, list) { |
| 4874 | LIST_DEL(&tmplogsrv->list); |
| 4875 | free(tmplogsrv); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4876 | } |
| 4877 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4878 | else if (!strcmp(args[0], "log")) { /* syslog server address */ |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4879 | struct logsrv *logsrv; |
| 4880 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4881 | if (*(args[1]) && *(args[2]) == 0 && !strcmp(args[1], "global")) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4882 | /* copy global.logrsvs linked list to the end of curproxy->logsrvs */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4883 | list_for_each_entry(tmplogsrv, &global.logsrvs, list) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4884 | struct logsrv *node = malloc(sizeof(struct logsrv)); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4885 | memcpy(node, tmplogsrv, sizeof(struct logsrv)); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4886 | LIST_INIT(&node->list); |
| 4887 | LIST_ADDQ(&curproxy->logsrvs, &node->list); |
| 4888 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4889 | } |
| 4890 | else if (*(args[1]) && *(args[2])) { |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 4891 | struct sockaddr_storage *sk; |
| 4892 | int port1, port2; |
Willy Tarreau | dc2695c | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 4893 | int arg = 0; |
| 4894 | int len = 0; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4895 | |
| 4896 | logsrv = calloc(1, sizeof(struct logsrv)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4897 | |
Willy Tarreau | dc2695c | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 4898 | /* just after the address, a length may be specified */ |
| 4899 | if (strcmp(args[arg+2], "len") == 0) { |
| 4900 | len = atoi(args[arg+3]); |
| 4901 | if (len < 80 || len > 65535) { |
| 4902 | Alert("parsing [%s:%d] : invalid log length '%s', must be between 80 and 65535.\n", |
| 4903 | file, linenum, args[arg+3]); |
| 4904 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4905 | goto out; |
| 4906 | } |
| 4907 | logsrv->maxlen = len; |
| 4908 | |
| 4909 | /* skip these two args */ |
| 4910 | arg += 2; |
| 4911 | } |
| 4912 | else |
| 4913 | logsrv->maxlen = MAX_SYSLOG_LEN; |
| 4914 | |
| 4915 | if (logsrv->maxlen > global.max_syslog_len) { |
| 4916 | global.max_syslog_len = logsrv->maxlen; |
| 4917 | logline = realloc(logline, global.max_syslog_len + 1); |
| 4918 | } |
| 4919 | |
| 4920 | logsrv->facility = get_log_facility(args[arg+2]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4921 | if (logsrv->facility < 0) { |
Willy Tarreau | dc2695c | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 4922 | 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] | 4923 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4924 | goto out; |
| 4925 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4926 | } |
| 4927 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4928 | logsrv->level = 7; /* max syslog level = debug */ |
Willy Tarreau | dc2695c | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 4929 | if (*(args[arg+3])) { |
| 4930 | logsrv->level = get_log_level(args[arg+3]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4931 | if (logsrv->level < 0) { |
Willy Tarreau | dc2695c | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 4932 | 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] | 4933 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4934 | goto out; |
| 4935 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4936 | } |
| 4937 | } |
| 4938 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4939 | logsrv->minlvl = 0; /* limit syslog level to this level (emerg) */ |
Willy Tarreau | dc2695c | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 4940 | if (*(args[arg+4])) { |
| 4941 | logsrv->minlvl = get_log_level(args[arg+4]); |
Willy Tarreau | f7f057b | 2013-01-24 00:31:24 +0100 | [diff] [blame] | 4942 | if (logsrv->minlvl < 0) { |
Willy Tarreau | dc2695c | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 4943 | 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] | 4944 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4945 | goto out; |
| 4946 | |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 4947 | } |
| 4948 | } |
| 4949 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 4950 | sk = str2sa_range(args[1], &port1, &port2, &errmsg, NULL); |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 4951 | if (!sk) { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 4952 | Alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 4953 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 4954 | goto out; |
| 4955 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4956 | |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 4957 | logsrv->addr = *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4958 | |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 4959 | if (sk->ss_family == AF_INET || sk->ss_family == AF_INET6) { |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4960 | if (port1 != port2) { |
| 4961 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 4962 | file, linenum, args[0], args[1]); |
| 4963 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4964 | goto out; |
| 4965 | } |
| 4966 | |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4967 | if (!port1) |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4968 | set_host_port(&logsrv->addr, SYSLOG_PORT); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4969 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4970 | |
| 4971 | LIST_ADDQ(&curproxy->logsrvs, &logsrv->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4972 | } |
| 4973 | else { |
| 4974 | Alert("parsing [%s:%d] : 'log' expects either <address[:port]> and <facility> or 'global' as arguments.\n", |
| 4975 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4976 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4977 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4978 | } |
| 4979 | } |
| 4980 | 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] | 4981 | int cur_arg; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4982 | int port1, port2; |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4983 | struct sockaddr_storage *sk; |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 4984 | struct protocol *proto; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4985 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4986 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4987 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4988 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4989 | if (!*args[1]) { |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4990 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optionally '%s' <addr>, and '%s' <name>.\n", |
| 4991 | file, linenum, "source", "usesrc", "interface"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4992 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4993 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4994 | } |
Willy Tarreau | 368480c | 2009-03-01 08:27:21 +0100 | [diff] [blame] | 4995 | |
| 4996 | /* we must first clear any optional default setting */ |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4997 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 4998 | free(curproxy->conn_src.iface_name); |
| 4999 | curproxy->conn_src.iface_name = NULL; |
| 5000 | curproxy->conn_src.iface_len = 0; |
Willy Tarreau | 368480c | 2009-03-01 08:27:21 +0100 | [diff] [blame] | 5001 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 5002 | sk = str2sa_range(args[1], &port1, &port2, &errmsg, NULL); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 5003 | if (!sk) { |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 5004 | Alert("parsing [%s:%d] : '%s %s' : %s\n", |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 5005 | file, linenum, args[0], args[1], errmsg); |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 5006 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 5007 | goto out; |
| 5008 | } |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 5009 | |
| 5010 | proto = protocol_by_family(sk->ss_family); |
| 5011 | if (!proto || !proto->connect) { |
| 5012 | 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] | 5013 | file, linenum, args[0], args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 5014 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5015 | goto out; |
| 5016 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5017 | |
| 5018 | if (port1 != port2) { |
| 5019 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 5020 | file, linenum, args[0], args[1]); |
| 5021 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5022 | goto out; |
| 5023 | } |
| 5024 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 5025 | curproxy->conn_src.source_addr = *sk; |
| 5026 | curproxy->conn_src.opts |= CO_SRC_BIND; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5027 | |
| 5028 | cur_arg = 2; |
| 5029 | while (*(args[cur_arg])) { |
| 5030 | if (!strcmp(args[cur_arg], "usesrc")) { /* address to use outside */ |
Pieter Baauw | d551fb5 | 2013-05-08 22:49:23 +0200 | [diff] [blame] | 5031 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_TRANSPARENT) |
| 5032 | #if !defined(CONFIG_HAP_TRANSPARENT) |
Willy Tarreau | 9cf8d3f | 2014-05-09 22:56:10 +0200 | [diff] [blame] | 5033 | if (!is_inet_addr(&curproxy->conn_src.source_addr)) { |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5034 | Alert("parsing [%s:%d] : '%s' requires an explicit 'source' address.\n", |
| 5035 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5036 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5037 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5038 | } |
| 5039 | #endif |
| 5040 | if (!*args[cur_arg + 1]) { |
| 5041 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n", |
| 5042 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5043 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5044 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5045 | } |
| 5046 | |
| 5047 | if (!strcmp(args[cur_arg + 1], "client")) { |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 5048 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 5049 | curproxy->conn_src.opts |= CO_SRC_TPROXY_CLI; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5050 | } else if (!strcmp(args[cur_arg + 1], "clientip")) { |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 5051 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 5052 | curproxy->conn_src.opts |= CO_SRC_TPROXY_CIP; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 5053 | } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) { |
| 5054 | char *name, *end; |
| 5055 | |
| 5056 | name = args[cur_arg+1] + 7; |
| 5057 | while (isspace(*name)) |
| 5058 | name++; |
| 5059 | |
| 5060 | end = name; |
| 5061 | while (*end && !isspace(*end) && *end != ',' && *end != ')') |
| 5062 | end++; |
| 5063 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 5064 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 5065 | curproxy->conn_src.opts |= CO_SRC_TPROXY_DYN; |
| 5066 | curproxy->conn_src.bind_hdr_name = calloc(1, end - name + 1); |
| 5067 | curproxy->conn_src.bind_hdr_len = end - name; |
| 5068 | memcpy(curproxy->conn_src.bind_hdr_name, name, end - name); |
| 5069 | curproxy->conn_src.bind_hdr_name[end-name] = '\0'; |
| 5070 | curproxy->conn_src.bind_hdr_occ = -1; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 5071 | |
| 5072 | /* now look for an occurrence number */ |
| 5073 | while (isspace(*end)) |
| 5074 | end++; |
| 5075 | if (*end == ',') { |
| 5076 | end++; |
| 5077 | name = end; |
| 5078 | if (*end == '-') |
| 5079 | end++; |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 5080 | while (isdigit((int)*end)) |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 5081 | end++; |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 5082 | curproxy->conn_src.bind_hdr_occ = strl2ic(name, end-name); |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 5083 | } |
| 5084 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 5085 | if (curproxy->conn_src.bind_hdr_occ < -MAX_HDR_HISTORY) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 5086 | Alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative" |
| 5087 | " occurrences values smaller than %d.\n", |
| 5088 | file, linenum, MAX_HDR_HISTORY); |
| 5089 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5090 | goto out; |
| 5091 | } |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5092 | } else { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 5093 | struct sockaddr_storage *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5094 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 5095 | sk = str2sa_range(args[cur_arg + 1], &port1, &port2, &errmsg, NULL); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 5096 | if (!sk) { |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 5097 | Alert("parsing [%s:%d] : '%s %s' : %s\n", |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 5098 | file, linenum, args[cur_arg], args[cur_arg+1], errmsg); |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 5099 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 5100 | goto out; |
| 5101 | } |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 5102 | |
| 5103 | proto = protocol_by_family(sk->ss_family); |
| 5104 | if (!proto || !proto->connect) { |
| 5105 | Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 5106 | file, linenum, args[cur_arg], args[cur_arg+1]); |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5107 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5108 | goto out; |
| 5109 | } |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 5110 | |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5111 | if (port1 != port2) { |
| 5112 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 5113 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 5114 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5115 | goto out; |
| 5116 | } |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 5117 | curproxy->conn_src.tproxy_addr = *sk; |
| 5118 | curproxy->conn_src.opts |= CO_SRC_TPROXY_ADDR; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5119 | } |
| 5120 | global.last_checks |= LSTCHK_NETADM; |
Pieter Baauw | d551fb5 | 2013-05-08 22:49:23 +0200 | [diff] [blame] | 5121 | #if !defined(CONFIG_HAP_TRANSPARENT) |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5122 | global.last_checks |= LSTCHK_CTTPROXY; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 5123 | #endif |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5124 | #else /* no TPROXY support */ |
| 5125 | 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] | 5126 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5127 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5128 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5129 | #endif |
| 5130 | cur_arg += 2; |
| 5131 | continue; |
Willy Tarreau | 77074d5 | 2006-11-12 23:57:19 +0100 | [diff] [blame] | 5132 | } |
| 5133 | |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5134 | if (!strcmp(args[cur_arg], "interface")) { /* specifically bind to this interface */ |
| 5135 | #ifdef SO_BINDTODEVICE |
| 5136 | if (!*args[cur_arg + 1]) { |
| 5137 | Alert("parsing [%s:%d] : '%s' : missing interface name.\n", |
| 5138 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5139 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5140 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5141 | } |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 5142 | free(curproxy->conn_src.iface_name); |
| 5143 | curproxy->conn_src.iface_name = strdup(args[cur_arg + 1]); |
| 5144 | curproxy->conn_src.iface_len = strlen(curproxy->conn_src.iface_name); |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5145 | global.last_checks |= LSTCHK_NETADM; |
| 5146 | #else |
| 5147 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 5148 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5149 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5150 | goto out; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 5151 | #endif |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5152 | cur_arg += 2; |
| 5153 | continue; |
| 5154 | } |
| 5155 | 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] | 5156 | file, linenum, args[0], "interface", "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5157 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5158 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 5159 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5160 | } |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 5161 | else if (!strcmp(args[0], "usesrc")) { /* address to use outside: needs "source" first */ |
| 5162 | Alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n", |
| 5163 | file, linenum, "usesrc", "source"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5164 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5165 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 5166 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5167 | 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] | 5168 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5169 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 5170 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5171 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5172 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5173 | } |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5174 | |
| 5175 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5176 | SMP_OPT_DIR_REQ, ACT_REPLACE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5177 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5178 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5179 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5180 | } |
| 5181 | else if (!strcmp(args[0], "reqdel")) { /* delete request header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5182 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5183 | SMP_OPT_DIR_REQ, ACT_REMOVE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5184 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5185 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5186 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5187 | } |
| 5188 | 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] | 5189 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5190 | SMP_OPT_DIR_REQ, ACT_DENY, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5191 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5192 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5193 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5194 | } |
| 5195 | 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] | 5196 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5197 | SMP_OPT_DIR_REQ, ACT_PASS, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5198 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5199 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5200 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5201 | } |
| 5202 | 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] | 5203 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5204 | SMP_OPT_DIR_REQ, ACT_ALLOW, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5205 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5206 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5207 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5208 | } |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 5209 | 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] | 5210 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5211 | SMP_OPT_DIR_REQ, ACT_TARPIT, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5212 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5213 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5214 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 5215 | } |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5216 | 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] | 5217 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5218 | SMP_OPT_DIR_REQ, ACT_SETBE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5219 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5220 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5221 | goto out; |
Willy Tarreau | 40bac83 | 2014-04-28 22:37:06 +0200 | [diff] [blame] | 5222 | |
| 5223 | if (!already_warned(WARN_REQSETBE_DEPRECATED)) |
| 5224 | 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] | 5225 | } |
| 5226 | 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] | 5227 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5228 | SMP_OPT_DIR_REQ, ACT_SETBE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5229 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5230 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5231 | goto out; |
Willy Tarreau | 40bac83 | 2014-04-28 22:37:06 +0200 | [diff] [blame] | 5232 | |
| 5233 | if (!already_warned(WARN_REQSETBE_DEPRECATED)) |
| 5234 | 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] | 5235 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5236 | 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] | 5237 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5238 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 5239 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5240 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5241 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5242 | } |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5243 | |
| 5244 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5245 | SMP_OPT_DIR_REQ, ACT_REPLACE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5246 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5247 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5248 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5249 | } |
| 5250 | 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] | 5251 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5252 | SMP_OPT_DIR_REQ, ACT_REMOVE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5253 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5254 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5255 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5256 | } |
| 5257 | 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] | 5258 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5259 | SMP_OPT_DIR_REQ, ACT_DENY, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5260 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5261 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5262 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5263 | } |
| 5264 | 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] | 5265 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5266 | SMP_OPT_DIR_REQ, ACT_PASS, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5267 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5268 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5269 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5270 | } |
| 5271 | 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] | 5272 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5273 | SMP_OPT_DIR_REQ, ACT_ALLOW, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5274 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5275 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5276 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5277 | } |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 5278 | 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] | 5279 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5280 | SMP_OPT_DIR_REQ, ACT_TARPIT, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5281 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5282 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5283 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 5284 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5285 | else if (!strcmp(args[0], "reqadd")) { /* add request header */ |
Willy Tarreau | f4f0412 | 2010-01-28 18:10:50 +0100 | [diff] [blame] | 5286 | struct cond_wordlist *wl; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5287 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5288 | if (curproxy == &defproxy) { |
| 5289 | 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] | 5290 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5291 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5292 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5293 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5294 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5295 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5296 | if (*(args[1]) == 0) { |
| 5297 | 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] | 5298 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5299 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5300 | } |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5301 | |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 5302 | if ((strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0)) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 5303 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args+2, &errmsg)) == NULL) { |
| 5304 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 5305 | file, linenum, args[0], errmsg); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 5306 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5307 | goto out; |
| 5308 | } |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 5309 | err_code |= warnif_cond_conflicts(cond, |
| 5310 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 5311 | file, linenum); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 5312 | } |
| 5313 | else if (*args[2]) { |
| 5314 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 5315 | file, linenum, args[0], args[2]); |
| 5316 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5317 | goto out; |
| 5318 | } |
| 5319 | |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5320 | wl = calloc(1, sizeof(*wl)); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 5321 | wl->cond = cond; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5322 | wl->s = strdup(args[1]); |
| 5323 | LIST_ADDQ(&curproxy->req_add, &wl->list); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 5324 | warnif_misplaced_reqadd(curproxy, file, linenum, args[0]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5325 | } |
| 5326 | 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] | 5327 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5328 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 5329 | 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 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5333 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5334 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5335 | SMP_OPT_DIR_RES, ACT_REPLACE, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5336 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5337 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5338 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5339 | } |
| 5340 | else if (!strcmp(args[0], "rspdel")) { /* delete response header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5341 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5342 | SMP_OPT_DIR_RES, ACT_REMOVE, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5343 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5344 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5345 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5346 | } |
| 5347 | else if (!strcmp(args[0], "rspdeny")) { /* block response header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5348 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5349 | SMP_OPT_DIR_RES, ACT_DENY, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5350 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5351 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5352 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5353 | } |
| 5354 | 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] | 5355 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5356 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 5357 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5358 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5359 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5360 | } |
| 5361 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5362 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5363 | SMP_OPT_DIR_RES, ACT_REPLACE, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5364 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5365 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5366 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5367 | } |
| 5368 | 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] | 5369 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5370 | SMP_OPT_DIR_RES, ACT_REMOVE, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5371 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5372 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5373 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5374 | } |
| 5375 | 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] | 5376 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5377 | SMP_OPT_DIR_RES, ACT_DENY, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5378 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5379 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5380 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5381 | } |
| 5382 | else if (!strcmp(args[0], "rspadd")) { /* add response header */ |
Willy Tarreau | f4f0412 | 2010-01-28 18:10:50 +0100 | [diff] [blame] | 5383 | struct cond_wordlist *wl; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5384 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5385 | if (curproxy == &defproxy) { |
| 5386 | 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] | 5387 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5388 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5389 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5390 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5391 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5392 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5393 | if (*(args[1]) == 0) { |
| 5394 | 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] | 5395 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5396 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5397 | } |
| 5398 | |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5399 | if ((strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0)) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 5400 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args+2, &errmsg)) == NULL) { |
| 5401 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 5402 | file, linenum, args[0], errmsg); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5403 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5404 | goto out; |
| 5405 | } |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 5406 | err_code |= warnif_cond_conflicts(cond, |
| 5407 | (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR, |
| 5408 | file, linenum); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5409 | } |
| 5410 | else if (*args[2]) { |
| 5411 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 5412 | file, linenum, args[0], args[2]); |
| 5413 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5414 | goto out; |
| 5415 | } |
| 5416 | |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5417 | wl = calloc(1, sizeof(*wl)); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5418 | wl->cond = cond; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5419 | wl->s = strdup(args[1]); |
| 5420 | LIST_ADDQ(&curproxy->rsp_add, &wl->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5421 | } |
| 5422 | else if (!strcmp(args[0], "errorloc") || |
| 5423 | !strcmp(args[0], "errorloc302") || |
| 5424 | !strcmp(args[0], "errorloc303")) { /* error location */ |
| 5425 | int errnum, errlen; |
| 5426 | char *err; |
| 5427 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5428 | 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] | 5429 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5430 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5431 | if (*(args[2]) == 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 5432 | 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] | 5433 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5434 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5435 | } |
| 5436 | |
| 5437 | errnum = atol(args[1]); |
| 5438 | if (!strcmp(args[0], "errorloc303")) { |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 5439 | errlen = strlen(HTTP_303) + strlen(args[2]) + 5; |
| 5440 | err = malloc(errlen); |
| 5441 | 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] | 5442 | } else { |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 5443 | errlen = strlen(HTTP_302) + strlen(args[2]) + 5; |
| 5444 | err = malloc(errlen); |
| 5445 | 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] | 5446 | } |
| 5447 | |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 5448 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) { |
| 5449 | if (http_err_codes[rc] == errnum) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 5450 | chunk_destroy(&curproxy->errmsg[rc]); |
| 5451 | chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 5452 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5453 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5454 | } |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 5455 | |
| 5456 | if (rc >= HTTP_ERR_SIZE) { |
Willy Tarreau | 09a4a0a | 2015-09-27 15:13:30 +0200 | [diff] [blame] | 5457 | Warning("parsing [%s:%d] : status code %d not handled by '%s', error relocation will be ignored.\n", |
| 5458 | file, linenum, errnum, args[0]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5459 | free(err); |
| 5460 | } |
| 5461 | } |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5462 | else if (!strcmp(args[0], "errorfile")) { /* error message from a file */ |
| 5463 | int errnum, errlen, fd; |
| 5464 | char *err; |
| 5465 | struct stat stat; |
| 5466 | |
| 5467 | 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] | 5468 | err_code |= ERR_WARN; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5469 | |
| 5470 | if (*(args[2]) == 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 5471 | 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] | 5472 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5473 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5474 | } |
| 5475 | |
| 5476 | fd = open(args[2], O_RDONLY); |
| 5477 | if ((fd < 0) || (fstat(fd, &stat) < 0)) { |
| 5478 | Alert("parsing [%s:%d] : error opening file <%s> for custom error message <%s>.\n", |
| 5479 | file, linenum, args[2], args[1]); |
| 5480 | if (fd >= 0) |
| 5481 | close(fd); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5482 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5483 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5484 | } |
| 5485 | |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 5486 | if (stat.st_size <= global.tune.bufsize) { |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5487 | errlen = stat.st_size; |
| 5488 | } else { |
| 5489 | 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] | 5490 | file, linenum, args[2], global.tune.bufsize); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5491 | err_code |= ERR_WARN; |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 5492 | errlen = global.tune.bufsize; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5493 | } |
| 5494 | |
| 5495 | err = malloc(errlen); /* malloc() must succeed during parsing */ |
| 5496 | errnum = read(fd, err, errlen); |
| 5497 | if (errnum != errlen) { |
| 5498 | Alert("parsing [%s:%d] : error reading file <%s> for custom error message <%s>.\n", |
| 5499 | file, linenum, args[2], args[1]); |
| 5500 | close(fd); |
| 5501 | free(err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5502 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5503 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5504 | } |
| 5505 | close(fd); |
| 5506 | |
| 5507 | errnum = atol(args[1]); |
| 5508 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) { |
| 5509 | if (http_err_codes[rc] == errnum) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 5510 | chunk_destroy(&curproxy->errmsg[rc]); |
| 5511 | chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen); |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5512 | break; |
| 5513 | } |
| 5514 | } |
| 5515 | |
| 5516 | if (rc >= HTTP_ERR_SIZE) { |
Willy Tarreau | 09a4a0a | 2015-09-27 15:13:30 +0200 | [diff] [blame] | 5517 | Warning("parsing [%s:%d] : status code %d not handled by '%s', error customization will be ignored.\n", |
| 5518 | file, linenum, errnum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5519 | err_code |= ERR_WARN; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5520 | free(err); |
| 5521 | } |
| 5522 | } |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5523 | else if (!strcmp(args[0], "compression")) { |
| 5524 | struct comp *comp; |
| 5525 | if (curproxy->comp == NULL) { |
| 5526 | comp = calloc(1, sizeof(struct comp)); |
| 5527 | curproxy->comp = comp; |
| 5528 | } else { |
| 5529 | comp = curproxy->comp; |
| 5530 | } |
| 5531 | |
| 5532 | if (!strcmp(args[1], "algo")) { |
| 5533 | int cur_arg; |
William Lallemand | 8b52bb3 | 2012-11-16 18:06:41 +0100 | [diff] [blame] | 5534 | struct comp_ctx *ctx; |
William Lallemand | 552df67 | 2012-11-07 13:21:47 +0100 | [diff] [blame] | 5535 | |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5536 | cur_arg = 2; |
| 5537 | if (!*args[cur_arg]) { |
| 5538 | Alert("parsing [%s:%d] : '%s' expects <algorithm>\n", |
| 5539 | file, linenum, args[0]); |
| 5540 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5541 | goto out; |
| 5542 | } |
| 5543 | while (*(args[cur_arg])) { |
| 5544 | if (comp_append_algo(comp, args[cur_arg]) < 0) { |
| 5545 | Alert("parsing [%s:%d] : '%s' : '%s' is not a supported algorithm.\n", |
| 5546 | file, linenum, args[0], args[cur_arg]); |
| 5547 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5548 | goto out; |
| 5549 | } |
William Lallemand | 552df67 | 2012-11-07 13:21:47 +0100 | [diff] [blame] | 5550 | if (curproxy->comp->algos->init(&ctx, 9) == 0) { |
| 5551 | curproxy->comp->algos->end(&ctx); |
| 5552 | } else { |
| 5553 | Alert("parsing [%s:%d] : '%s' : Can't init '%s' algorithm.\n", |
| 5554 | file, linenum, args[0], args[cur_arg]); |
| 5555 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5556 | goto out; |
| 5557 | } |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5558 | cur_arg ++; |
| 5559 | continue; |
| 5560 | } |
| 5561 | } |
Willy Tarreau | 70737d1 | 2012-10-27 00:34:28 +0200 | [diff] [blame] | 5562 | else if (!strcmp(args[1], "offload")) { |
| 5563 | comp->offload = 1; |
| 5564 | } |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5565 | else if (!strcmp(args[1], "type")) { |
| 5566 | int cur_arg; |
| 5567 | cur_arg = 2; |
| 5568 | if (!*args[cur_arg]) { |
| 5569 | Alert("parsing [%s:%d] : '%s' expects <type>\n", |
| 5570 | file, linenum, args[0]); |
| 5571 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5572 | goto out; |
| 5573 | } |
| 5574 | while (*(args[cur_arg])) { |
| 5575 | comp_append_type(comp, args[cur_arg]); |
| 5576 | cur_arg ++; |
| 5577 | continue; |
| 5578 | } |
| 5579 | } |
| 5580 | else { |
Willy Tarreau | 70737d1 | 2012-10-27 00:34:28 +0200 | [diff] [blame] | 5581 | Alert("parsing [%s:%d] : '%s' expects 'algo', 'type' or 'offload'\n", |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5582 | file, linenum, args[0]); |
| 5583 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5584 | goto out; |
| 5585 | } |
| 5586 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5587 | else { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 5588 | struct cfg_kw_list *kwl; |
| 5589 | int index; |
| 5590 | |
| 5591 | list_for_each_entry(kwl, &cfg_keywords.list, list) { |
| 5592 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 5593 | if (kwl->kw[index].section != CFG_LISTEN) |
| 5594 | continue; |
| 5595 | if (strcmp(kwl->kw[index].kw, args[0]) == 0) { |
| 5596 | /* prepare error message just in case */ |
Willy Tarreau | 28a47d6 | 2012-09-18 20:02:48 +0200 | [diff] [blame] | 5597 | 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] | 5598 | if (rc < 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 5599 | Alert("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5600 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5601 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 5602 | } |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 5603 | else if (rc > 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 5604 | Warning("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5605 | err_code |= ERR_WARN; |
| 5606 | goto out; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 5607 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5608 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 5609 | } |
| 5610 | } |
| 5611 | } |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5612 | |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5613 | 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] | 5614 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5615 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5616 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5617 | out: |
Willy Tarreau | f4068b6 | 2012-05-08 17:37:49 +0200 | [diff] [blame] | 5618 | free(errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5619 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5620 | } |
| 5621 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5622 | int |
| 5623 | cfg_parse_users(const char *file, int linenum, char **args, int kwm) |
| 5624 | { |
| 5625 | |
| 5626 | int err_code = 0; |
| 5627 | const char *err; |
| 5628 | |
| 5629 | if (!strcmp(args[0], "userlist")) { /* new userlist */ |
| 5630 | struct userlist *newul; |
| 5631 | |
| 5632 | if (!*args[1]) { |
| 5633 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 5634 | file, linenum, args[0]); |
| 5635 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5636 | goto out; |
| 5637 | } |
| 5638 | |
| 5639 | err = invalid_char(args[1]); |
| 5640 | if (err) { |
| 5641 | Alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 5642 | file, linenum, *err, args[0], args[1]); |
| 5643 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5644 | goto out; |
| 5645 | } |
| 5646 | |
| 5647 | for (newul = userlist; newul; newul = newul->next) |
| 5648 | if (!strcmp(newul->name, args[1])) { |
| 5649 | Warning("parsing [%s:%d]: ignoring duplicated userlist '%s'.\n", |
| 5650 | file, linenum, args[1]); |
| 5651 | err_code |= ERR_WARN; |
| 5652 | goto out; |
| 5653 | } |
| 5654 | |
| 5655 | newul = (struct userlist *)calloc(1, sizeof(struct userlist)); |
| 5656 | if (!newul) { |
| 5657 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 5658 | err_code |= ERR_ALERT | ERR_ABORT; |
| 5659 | goto out; |
| 5660 | } |
| 5661 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5662 | newul->name = strdup(args[1]); |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 5663 | if (!newul->name) { |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5664 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 5665 | err_code |= ERR_ALERT | ERR_ABORT; |
| 5666 | goto out; |
| 5667 | } |
| 5668 | |
| 5669 | newul->next = userlist; |
| 5670 | userlist = newul; |
| 5671 | |
| 5672 | } else if (!strcmp(args[0], "group")) { /* new group */ |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 5673 | int cur_arg; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5674 | const char *err; |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 5675 | struct auth_groups *ag; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5676 | |
| 5677 | if (!*args[1]) { |
| 5678 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 5679 | file, linenum, args[0]); |
| 5680 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5681 | goto out; |
| 5682 | } |
| 5683 | |
| 5684 | err = invalid_char(args[1]); |
| 5685 | if (err) { |
| 5686 | Alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 5687 | file, linenum, *err, args[0], args[1]); |
| 5688 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5689 | goto out; |
| 5690 | } |
| 5691 | |
William Lallemand | faf3315 | 2015-05-28 18:03:51 +0200 | [diff] [blame] | 5692 | if (!userlist) |
| 5693 | goto out; |
| 5694 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 5695 | for (ag = userlist->groups; ag; ag = ag->next) |
| 5696 | if (!strcmp(ag->name, args[1])) { |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5697 | Warning("parsing [%s:%d]: ignoring duplicated group '%s' in userlist '%s'.\n", |
| 5698 | file, linenum, args[1], userlist->name); |
| 5699 | err_code |= ERR_ALERT; |
| 5700 | goto out; |
| 5701 | } |
| 5702 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 5703 | ag = calloc(1, sizeof(*ag)); |
| 5704 | if (!ag) { |
| 5705 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 5706 | err_code |= ERR_ALERT | ERR_ABORT; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5707 | goto out; |
| 5708 | } |
| 5709 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 5710 | ag->name = strdup(args[1]); |
| 5711 | if (!ag) { |
| 5712 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 5713 | err_code |= ERR_ALERT | ERR_ABORT; |
| 5714 | goto out; |
| 5715 | } |
| 5716 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5717 | cur_arg = 2; |
| 5718 | |
| 5719 | while (*args[cur_arg]) { |
| 5720 | if (!strcmp(args[cur_arg], "users")) { |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 5721 | ag->groupusers = strdup(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5722 | cur_arg += 2; |
| 5723 | continue; |
| 5724 | } else { |
| 5725 | Alert("parsing [%s:%d]: '%s' only supports 'users' option.\n", |
| 5726 | file, linenum, args[0]); |
| 5727 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5728 | goto out; |
| 5729 | } |
| 5730 | } |
| 5731 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 5732 | ag->next = userlist->groups; |
| 5733 | userlist->groups = ag; |
| 5734 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5735 | } else if (!strcmp(args[0], "user")) { /* new user */ |
| 5736 | struct auth_users *newuser; |
| 5737 | int cur_arg; |
| 5738 | |
| 5739 | if (!*args[1]) { |
| 5740 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 5741 | file, linenum, args[0]); |
| 5742 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5743 | goto out; |
| 5744 | } |
William Lallemand | faf3315 | 2015-05-28 18:03:51 +0200 | [diff] [blame] | 5745 | if (!userlist) |
| 5746 | goto out; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5747 | |
| 5748 | for (newuser = userlist->users; newuser; newuser = newuser->next) |
| 5749 | if (!strcmp(newuser->user, args[1])) { |
| 5750 | Warning("parsing [%s:%d]: ignoring duplicated user '%s' in userlist '%s'.\n", |
| 5751 | file, linenum, args[1], userlist->name); |
| 5752 | err_code |= ERR_ALERT; |
| 5753 | goto out; |
| 5754 | } |
| 5755 | |
| 5756 | newuser = (struct auth_users *)calloc(1, sizeof(struct auth_users)); |
| 5757 | if (!newuser) { |
| 5758 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 5759 | err_code |= ERR_ALERT | ERR_ABORT; |
| 5760 | goto out; |
| 5761 | } |
| 5762 | |
| 5763 | newuser->user = strdup(args[1]); |
| 5764 | |
| 5765 | newuser->next = userlist->users; |
| 5766 | userlist->users = newuser; |
| 5767 | |
| 5768 | cur_arg = 2; |
| 5769 | |
| 5770 | while (*args[cur_arg]) { |
| 5771 | if (!strcmp(args[cur_arg], "password")) { |
Cyril Bonté | 2c8d700 | 2014-08-29 20:20:02 +0200 | [diff] [blame] | 5772 | #ifdef CONFIG_HAP_CRYPT |
| 5773 | if (!crypt("", args[cur_arg + 1])) { |
| 5774 | Alert("parsing [%s:%d]: the encrypted password used for user '%s' is not supported by crypt(3).\n", |
| 5775 | file, linenum, newuser->user); |
| 5776 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5777 | goto out; |
| 5778 | } |
| 5779 | #else |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5780 | Warning("parsing [%s:%d]: no crypt(3) support compiled, encrypted passwords will not work.\n", |
| 5781 | file, linenum); |
| 5782 | err_code |= ERR_ALERT; |
| 5783 | #endif |
| 5784 | newuser->pass = strdup(args[cur_arg + 1]); |
| 5785 | cur_arg += 2; |
| 5786 | continue; |
| 5787 | } else if (!strcmp(args[cur_arg], "insecure-password")) { |
| 5788 | newuser->pass = strdup(args[cur_arg + 1]); |
| 5789 | newuser->flags |= AU_O_INSECURE; |
| 5790 | cur_arg += 2; |
| 5791 | continue; |
| 5792 | } else if (!strcmp(args[cur_arg], "groups")) { |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 5793 | newuser->u.groups_names = strdup(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5794 | cur_arg += 2; |
| 5795 | continue; |
| 5796 | } else { |
| 5797 | Alert("parsing [%s:%d]: '%s' only supports 'password', 'insecure-password' and 'groups' options.\n", |
| 5798 | file, linenum, args[0]); |
| 5799 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5800 | goto out; |
| 5801 | } |
| 5802 | } |
| 5803 | } else { |
| 5804 | Alert("parsing [%s:%d]: unknown keyword '%s' in '%s' section\n", file, linenum, args[0], "users"); |
| 5805 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5806 | } |
| 5807 | |
| 5808 | out: |
| 5809 | return err_code; |
| 5810 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5811 | |
| 5812 | /* |
| 5813 | * This function reads and parses the configuration file given in the argument. |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5814 | * Returns the error code, 0 if OK, or any combination of : |
| 5815 | * - ERR_ABORT: must abort ASAP |
| 5816 | * - ERR_FATAL: we can continue parsing but not start the service |
| 5817 | * - ERR_WARN: a warning has been emitted |
| 5818 | * - ERR_ALERT: an alert has been emitted |
| 5819 | * Only the two first ones can stop processing, the two others are just |
| 5820 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5821 | */ |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 5822 | int readcfgfile(const char *file) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5823 | { |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5824 | char thisline[LINESIZE]; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5825 | FILE *f; |
| 5826 | int linenum = 0; |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5827 | int err_code = 0; |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 5828 | struct cfg_section *cs = NULL; |
| 5829 | struct cfg_section *ics; |
| 5830 | |
| 5831 | /* Register internal sections */ |
| 5832 | if (!cfg_register_section("listen", cfg_parse_listen) || |
| 5833 | !cfg_register_section("frontend", cfg_parse_listen) || |
| 5834 | !cfg_register_section("backend", cfg_parse_listen) || |
| 5835 | !cfg_register_section("ruleset", cfg_parse_listen) || |
| 5836 | !cfg_register_section("defaults", cfg_parse_listen) || |
| 5837 | !cfg_register_section("global", cfg_parse_global) || |
| 5838 | !cfg_register_section("userlist", cfg_parse_users) || |
| 5839 | !cfg_register_section("peers", cfg_parse_peers)) |
| 5840 | return -1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5841 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5842 | if ((f=fopen(file,"r")) == NULL) |
| 5843 | return -1; |
| 5844 | |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5845 | while (fgets(thisline, sizeof(thisline), f) != NULL) { |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 5846 | int arg, kwm = KWM_STD; |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5847 | char *end; |
| 5848 | char *args[MAX_LINE_ARGS + 1]; |
| 5849 | char *line = thisline; |
| 5850 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5851 | linenum++; |
| 5852 | |
| 5853 | end = line + strlen(line); |
| 5854 | |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5855 | if (end-line == sizeof(thisline)-1 && *(end-1) != '\n') { |
| 5856 | /* Check if we reached the limit and the last char is not \n. |
| 5857 | * Watch out for the last line without the terminating '\n'! |
| 5858 | */ |
| 5859 | Alert("parsing [%s:%d]: line too long, limit: %d.\n", |
Willy Tarreau | 5e4a6f1 | 2009-04-11 19:42:49 +0200 | [diff] [blame] | 5860 | file, linenum, (int)sizeof(thisline)-1); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5861 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5862 | } |
| 5863 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5864 | /* skip leading spaces */ |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 5865 | while (isspace((unsigned char)*line)) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5866 | line++; |
| 5867 | |
| 5868 | arg = 0; |
| 5869 | args[arg] = line; |
| 5870 | |
| 5871 | while (*line && arg < MAX_LINE_ARGS) { |
| 5872 | /* first, we'll replace \\, \<space>, \#, \r, \n, \t, \xXX with their |
| 5873 | * C equivalent value. Other combinations left unchanged (eg: \1). |
| 5874 | */ |
| 5875 | if (*line == '\\') { |
| 5876 | int skip = 0; |
| 5877 | if (line[1] == ' ' || line[1] == '\\' || line[1] == '#') { |
| 5878 | *line = line[1]; |
| 5879 | skip = 1; |
| 5880 | } |
| 5881 | else if (line[1] == 'r') { |
| 5882 | *line = '\r'; |
| 5883 | skip = 1; |
| 5884 | } |
| 5885 | else if (line[1] == 'n') { |
| 5886 | *line = '\n'; |
| 5887 | skip = 1; |
| 5888 | } |
| 5889 | else if (line[1] == 't') { |
| 5890 | *line = '\t'; |
| 5891 | skip = 1; |
| 5892 | } |
| 5893 | else if (line[1] == 'x') { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5894 | if ((line + 3 < end) && ishex(line[2]) && ishex(line[3])) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5895 | unsigned char hex1, hex2; |
| 5896 | hex1 = toupper(line[2]) - '0'; |
| 5897 | hex2 = toupper(line[3]) - '0'; |
| 5898 | if (hex1 > 9) hex1 -= 'A' - '9' - 1; |
| 5899 | if (hex2 > 9) hex2 -= 'A' - '9' - 1; |
| 5900 | *line = (hex1<<4) + hex2; |
| 5901 | skip = 3; |
| 5902 | } |
| 5903 | else { |
| 5904 | 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] | 5905 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5906 | } |
| 5907 | } |
| 5908 | if (skip) { |
Cyril Bonté | dd1b01d | 2009-12-06 13:43:42 +0100 | [diff] [blame] | 5909 | memmove(line + 1, line + 1 + skip, end - (line + skip)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5910 | end -= skip; |
| 5911 | } |
| 5912 | line++; |
| 5913 | } |
| 5914 | else if (*line == '#' || *line == '\n' || *line == '\r') { |
| 5915 | /* end of string, end of loop */ |
| 5916 | *line = 0; |
| 5917 | break; |
| 5918 | } |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 5919 | else if (isspace((unsigned char)*line)) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5920 | /* a non-escaped space is an argument separator */ |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5921 | *line++ = '\0'; |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 5922 | while (isspace((unsigned char)*line)) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5923 | line++; |
| 5924 | args[++arg] = line; |
| 5925 | } |
| 5926 | else { |
| 5927 | line++; |
| 5928 | } |
| 5929 | } |
| 5930 | |
| 5931 | /* empty line */ |
| 5932 | if (!**args) |
| 5933 | continue; |
| 5934 | |
Willy Tarreau | 7bb651e | 2009-11-09 21:16:53 +0100 | [diff] [blame] | 5935 | if (*line) { |
| 5936 | /* we had to stop due to too many args. |
| 5937 | * Let's terminate the string, print the offending part then cut the |
| 5938 | * last arg. |
| 5939 | */ |
| 5940 | while (*line && *line != '#' && *line != '\n' && *line != '\r') |
| 5941 | line++; |
| 5942 | *line = '\0'; |
| 5943 | |
Krzysztof Piotr Oledzki | 500b8f0 | 2009-12-15 22:34:51 +0100 | [diff] [blame] | 5944 | 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] | 5945 | file, linenum, arg + 1, (long)(args[arg] - thisline + 1), args[arg]); |
Willy Tarreau | 7bb651e | 2009-11-09 21:16:53 +0100 | [diff] [blame] | 5946 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5947 | args[arg] = line; |
| 5948 | } |
| 5949 | |
Willy Tarreau | 540abe4 | 2007-05-02 20:50:16 +0200 | [diff] [blame] | 5950 | /* zero out remaining args and ensure that at least one entry |
| 5951 | * is zeroed out. |
| 5952 | */ |
| 5953 | while (++arg <= MAX_LINE_ARGS) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5954 | args[arg] = line; |
| 5955 | } |
| 5956 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 5957 | /* check for keyword modifiers "no" and "default" */ |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5958 | if (!strcmp(args[0], "no")) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5959 | char *tmp; |
| 5960 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 5961 | kwm = KWM_NO; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5962 | tmp = args[0]; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5963 | for (arg=0; *args[arg+1]; arg++) |
| 5964 | args[arg] = args[arg+1]; // shift args after inversion |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5965 | *tmp = '\0'; // fix the next arg to \0 |
| 5966 | args[arg] = tmp; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5967 | } |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 5968 | else if (!strcmp(args[0], "default")) { |
| 5969 | kwm = KWM_DEF; |
| 5970 | for (arg=0; *args[arg+1]; arg++) |
| 5971 | args[arg] = args[arg+1]; // shift args after inversion |
| 5972 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5973 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5974 | if (kwm != KWM_STD && strcmp(args[0], "option") != 0 && \ |
| 5975 | strcmp(args[0], "log") != 0) { |
| 5976 | 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] | 5977 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5978 | } |
| 5979 | |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 5980 | /* detect section start */ |
| 5981 | list_for_each_entry(ics, §ions, list) { |
| 5982 | if (strcmp(args[0], ics->section_name) == 0) { |
| 5983 | cursection = ics->section_name; |
| 5984 | cs = ics; |
| 5985 | break; |
| 5986 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 5987 | } |
| 5988 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5989 | /* else it's a section keyword */ |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 5990 | if (cs) |
| 5991 | err_code |= cs->section_parser(file, linenum, args, kwm); |
| 5992 | else { |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5993 | 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] | 5994 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5995 | } |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5996 | |
| 5997 | if (err_code & ERR_ABORT) |
| 5998 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5999 | } |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 6000 | cursection = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6001 | fclose(f); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 6002 | return err_code; |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6003 | } |
| 6004 | |
Willy Tarreau | 5436afc | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 6005 | /* This function propagates processes from frontend <from> to backend <to> so |
| 6006 | * that it is always guaranteed that a backend pointed to by a frontend is |
| 6007 | * bound to all of its processes. After that, if the target is a "listen" |
| 6008 | * instance, the function recursively descends the target's own targets along |
| 6009 | * default_backend, use_backend rules, and reqsetbe rules. Since the bits are |
| 6010 | * checked first to ensure that <to> is already bound to all processes of |
| 6011 | * <from>, there is no risk of looping and we ensure to follow the shortest |
| 6012 | * path to the destination. |
| 6013 | * |
| 6014 | * It is possible to set <to> to NULL for the first call so that the function |
| 6015 | * takes care of visiting the initial frontend in <from>. |
| 6016 | * |
| 6017 | * It is important to note that the function relies on the fact that all names |
| 6018 | * have already been resolved. |
| 6019 | */ |
| 6020 | void propagate_processes(struct proxy *from, struct proxy *to) |
| 6021 | { |
| 6022 | struct switching_rule *rule; |
| 6023 | struct hdr_exp *exp; |
| 6024 | |
| 6025 | if (to) { |
| 6026 | /* check whether we need to go down */ |
| 6027 | if (from->bind_proc && |
| 6028 | (from->bind_proc & to->bind_proc) == from->bind_proc) |
| 6029 | return; |
| 6030 | |
| 6031 | if (!from->bind_proc && !to->bind_proc) |
| 6032 | return; |
| 6033 | |
| 6034 | to->bind_proc = from->bind_proc ? |
| 6035 | (to->bind_proc | from->bind_proc) : 0; |
| 6036 | |
| 6037 | /* now propagate down */ |
| 6038 | from = to; |
| 6039 | } |
| 6040 | |
Willy Tarreau | 7110f38 | 2014-12-18 13:56:26 +0100 | [diff] [blame] | 6041 | if (!(from->cap & PR_CAP_FE)) |
Willy Tarreau | 5436afc | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 6042 | return; |
| 6043 | |
Willy Tarreau | ed061c0 | 2014-12-18 14:00:43 +0100 | [diff] [blame] | 6044 | if (from->state == PR_STSTOPPED) |
| 6045 | return; |
| 6046 | |
Willy Tarreau | 5436afc | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 6047 | /* default_backend */ |
| 6048 | if (from->defbe.be) |
| 6049 | propagate_processes(from, from->defbe.be); |
| 6050 | |
| 6051 | /* use_backend */ |
| 6052 | list_for_each_entry(rule, &from->switching_rules, list) { |
Cyril Bonté | c8d57de | 2014-10-02 19:56:25 +0200 | [diff] [blame] | 6053 | if (rule->dynamic) |
| 6054 | continue; |
Willy Tarreau | 5436afc | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 6055 | to = rule->be.backend; |
| 6056 | propagate_processes(from, to); |
| 6057 | } |
| 6058 | |
| 6059 | /* reqsetbe */ |
| 6060 | for (exp = from->req_exp; exp != NULL; exp = exp->next) { |
| 6061 | if (exp->action != ACT_SETBE) |
| 6062 | continue; |
| 6063 | to = (struct proxy *)exp->replace; |
| 6064 | propagate_processes(from, to); |
| 6065 | } |
| 6066 | } |
| 6067 | |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6068 | /* |
| 6069 | * Returns the error code, 0 if OK, or any combination of : |
| 6070 | * - ERR_ABORT: must abort ASAP |
| 6071 | * - ERR_FATAL: we can continue parsing but not start the service |
| 6072 | * - ERR_WARN: a warning has been emitted |
| 6073 | * - ERR_ALERT: an alert has been emitted |
| 6074 | * Only the two first ones can stop processing, the two others are just |
| 6075 | * indicators. |
| 6076 | */ |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6077 | int check_config_validity() |
| 6078 | { |
| 6079 | int cfgerr = 0; |
| 6080 | struct proxy *curproxy = NULL; |
| 6081 | struct server *newsrv = NULL; |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6082 | int err_code = 0; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6083 | unsigned int next_pxid = 1; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6084 | struct bind_conf *bind_conf; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6085 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6086 | bind_conf = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6087 | /* |
| 6088 | * Now, check for the integrity of all that we have collected. |
| 6089 | */ |
| 6090 | |
| 6091 | /* will be needed further to delay some tasks */ |
Willy Tarreau | b0b37bc | 2008-06-23 14:00:57 +0200 | [diff] [blame] | 6092 | tv_update_date(0,1); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6093 | |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 6094 | if (!global.tune.max_http_hdr) |
| 6095 | global.tune.max_http_hdr = MAX_HTTP_HDR; |
| 6096 | |
| 6097 | if (!global.tune.cookie_len) |
| 6098 | global.tune.cookie_len = CAPTURE_LEN; |
| 6099 | |
| 6100 | pool2_capture = create_pool("capture", global.tune.cookie_len, MEM_F_SHARED); |
| 6101 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6102 | /* Post initialisation of the users and groups lists. */ |
| 6103 | err_code = userlist_postinit(); |
| 6104 | if (err_code != ERR_NONE) |
| 6105 | goto out; |
| 6106 | |
Willy Tarreau | 55bc0f8 | 2009-03-15 14:51:53 +0100 | [diff] [blame] | 6107 | /* first, we will invert the proxy list order */ |
| 6108 | curproxy = NULL; |
| 6109 | while (proxy) { |
| 6110 | struct proxy *next; |
| 6111 | |
| 6112 | next = proxy->next; |
| 6113 | proxy->next = curproxy; |
| 6114 | curproxy = proxy; |
| 6115 | if (!next) |
| 6116 | break; |
| 6117 | proxy = next; |
| 6118 | } |
| 6119 | |
Willy Tarreau | 91b00c2 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 6120 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6121 | struct switching_rule *rule; |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 6122 | struct server_rule *srule; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6123 | struct sticking_rule *mrule; |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 6124 | struct tcp_rule *trule; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6125 | unsigned int next_id; |
Willy Tarreau | 16a2147 | 2012-11-19 12:39:59 +0100 | [diff] [blame] | 6126 | int nbproc; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6127 | |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 6128 | if (curproxy->uuid < 0) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6129 | /* proxy ID not set, use automatic numbering with first |
| 6130 | * spare entry starting with next_pxid. |
| 6131 | */ |
| 6132 | next_pxid = get_next_id(&used_proxy_id, next_pxid); |
| 6133 | curproxy->conf.id.key = curproxy->uuid = next_pxid; |
| 6134 | eb32_insert(&used_proxy_id, &curproxy->conf.id); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6135 | } |
Krzysztof Piotr Oledzki | df5cb9f | 2010-02-05 20:58:27 +0100 | [diff] [blame] | 6136 | next_pxid++; |
| 6137 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6138 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6139 | if (curproxy->state == PR_STSTOPPED) { |
Willy Tarreau | da250db | 2008-10-12 12:07:48 +0200 | [diff] [blame] | 6140 | /* ensure we don't keep listeners uselessly bound */ |
| 6141 | stop_proxy(curproxy); |
Willy Tarreau | d72af0a | 2015-05-01 19:59:56 +0200 | [diff] [blame] | 6142 | free((void *)curproxy->table.peers.name); |
| 6143 | curproxy->table.peers.p = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6144 | continue; |
| 6145 | } |
| 6146 | |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 6147 | /* Check multi-process mode compatibility for the current proxy */ |
| 6148 | |
| 6149 | if (curproxy->bind_proc) { |
| 6150 | /* an explicit bind-process was specified, let's check how many |
| 6151 | * processes remain. |
| 6152 | */ |
David Carlier | 6de4c2f | 2015-07-02 07:00:17 +0000 | [diff] [blame] | 6153 | nbproc = my_popcountl(curproxy->bind_proc); |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 6154 | |
| 6155 | curproxy->bind_proc &= nbits(global.nbproc); |
| 6156 | if (!curproxy->bind_proc && nbproc == 1) { |
| 6157 | 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); |
| 6158 | curproxy->bind_proc = 1; |
| 6159 | } |
| 6160 | else if (!curproxy->bind_proc && nbproc > 1) { |
| 6161 | 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); |
| 6162 | curproxy->bind_proc = 0; |
| 6163 | } |
| 6164 | } |
| 6165 | |
Willy Tarreau | 3d20958 | 2014-05-09 17:06:11 +0200 | [diff] [blame] | 6166 | /* check and reduce the bind-proc of each listener */ |
| 6167 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
| 6168 | unsigned long mask; |
| 6169 | |
| 6170 | if (!bind_conf->bind_proc) |
| 6171 | continue; |
| 6172 | |
| 6173 | mask = nbits(global.nbproc); |
| 6174 | if (curproxy->bind_proc) |
| 6175 | mask &= curproxy->bind_proc; |
| 6176 | /* mask cannot be null here thanks to the previous checks */ |
| 6177 | |
David Carlier | 6de4c2f | 2015-07-02 07:00:17 +0000 | [diff] [blame] | 6178 | nbproc = my_popcountl(bind_conf->bind_proc); |
Willy Tarreau | 3d20958 | 2014-05-09 17:06:11 +0200 | [diff] [blame] | 6179 | bind_conf->bind_proc &= mask; |
| 6180 | |
| 6181 | if (!bind_conf->bind_proc && nbproc == 1) { |
| 6182 | 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", |
| 6183 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
| 6184 | bind_conf->bind_proc = mask & ~(mask - 1); |
| 6185 | } |
| 6186 | else if (!bind_conf->bind_proc && nbproc > 1) { |
| 6187 | 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", |
| 6188 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
| 6189 | bind_conf->bind_proc = 0; |
| 6190 | } |
| 6191 | } |
| 6192 | |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 6193 | switch (curproxy->mode) { |
| 6194 | case PR_MODE_HEALTH: |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6195 | cfgerr += proxy_cfg_ensure_no_http(curproxy); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 6196 | if (!(curproxy->cap & PR_CAP_FE)) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6197 | Alert("config : %s '%s' cannot be in health mode as it has no frontend capability.\n", |
| 6198 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 6199 | cfgerr++; |
| 6200 | } |
| 6201 | |
| 6202 | if (curproxy->srv != NULL) |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6203 | Warning("config : servers will be ignored for %s '%s'.\n", |
| 6204 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 6205 | break; |
| 6206 | |
| 6207 | case PR_MODE_TCP: |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6208 | cfgerr += proxy_cfg_ensure_no_http(curproxy); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 6209 | break; |
| 6210 | |
| 6211 | case PR_MODE_HTTP: |
Willy Tarreau | 25320b2 | 2013-03-24 07:22:08 +0100 | [diff] [blame] | 6212 | curproxy->http_needed = 1; |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 6213 | break; |
| 6214 | } |
| 6215 | |
Willy Tarreau | c7c1e55 | 2015-08-11 11:36:45 +0200 | [diff] [blame] | 6216 | if ((curproxy->cap & PR_CAP_FE) && LIST_ISEMPTY(&curproxy->conf.listeners)) { |
| 6217 | Warning("config : %s '%s' has no 'bind' directive. Please declare it as a backend if this was intended.\n", |
| 6218 | proxy_type_str(curproxy), curproxy->id); |
| 6219 | err_code |= ERR_WARN; |
| 6220 | } |
| 6221 | |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 6222 | if ((curproxy->cap & PR_CAP_BE) && (curproxy->mode != PR_MODE_HEALTH)) { |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6223 | if (curproxy->lbprm.algo & BE_LB_KIND) { |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 6224 | if (curproxy->options & PR_O_TRANSP) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6225 | Alert("config : %s '%s' cannot use both transparent and balance mode.\n", |
| 6226 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 6227 | cfgerr++; |
| 6228 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6229 | #ifdef WE_DONT_SUPPORT_SERVERLESS_LISTENERS |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 6230 | else if (curproxy->srv == NULL) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6231 | Alert("config : %s '%s' needs at least 1 server in balance mode.\n", |
| 6232 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 6233 | cfgerr++; |
| 6234 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6235 | #endif |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 6236 | else if (curproxy->options & PR_O_DISPATCH) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6237 | Warning("config : dispatch address of %s '%s' will be ignored in balance mode.\n", |
| 6238 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6239 | err_code |= ERR_WARN; |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 6240 | } |
| 6241 | } |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 6242 | 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] | 6243 | /* If no LB algo is set in a backend, and we're not in |
| 6244 | * transparent mode, dispatch mode nor proxy mode, we |
| 6245 | * want to use balance roundrobin by default. |
| 6246 | */ |
| 6247 | curproxy->lbprm.algo &= ~BE_LB_ALGO; |
| 6248 | curproxy->lbprm.algo |= BE_LB_ALGO_RR; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6249 | } |
| 6250 | } |
Willy Tarreau | 193cf93 | 2007-09-17 10:17:23 +0200 | [diff] [blame] | 6251 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 6252 | if (curproxy->options & PR_O_DISPATCH) |
| 6253 | curproxy->options &= ~(PR_O_TRANSP | PR_O_HTTP_PROXY); |
| 6254 | else if (curproxy->options & PR_O_HTTP_PROXY) |
| 6255 | curproxy->options &= ~(PR_O_DISPATCH | PR_O_TRANSP); |
| 6256 | else if (curproxy->options & PR_O_TRANSP) |
| 6257 | curproxy->options &= ~(PR_O_DISPATCH | PR_O_HTTP_PROXY); |
Willy Tarreau | 8293658 | 2007-11-30 15:20:09 +0100 | [diff] [blame] | 6258 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 6259 | if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_HTTP_CHK) { |
| 6260 | if (curproxy->options & PR_O_DISABLE404) { |
| 6261 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n", |
| 6262 | "disable-on-404", proxy_type_str(curproxy), curproxy->id); |
| 6263 | err_code |= ERR_WARN; |
| 6264 | curproxy->options &= ~PR_O_DISABLE404; |
| 6265 | } |
| 6266 | if (curproxy->options2 & PR_O2_CHK_SNDST) { |
| 6267 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n", |
| 6268 | "send-state", proxy_type_str(curproxy), curproxy->id); |
| 6269 | err_code |= ERR_WARN; |
| 6270 | curproxy->options &= ~PR_O2_CHK_SNDST; |
| 6271 | } |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 6272 | } |
| 6273 | |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 6274 | /* if a default backend was specified, let's find it */ |
| 6275 | if (curproxy->defbe.name) { |
| 6276 | struct proxy *target; |
| 6277 | |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 6278 | target = findproxy_mode(curproxy->defbe.name, curproxy->mode, PR_CAP_BE); |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6279 | if (!target) { |
| 6280 | Alert("Proxy '%s': unable to find required default_backend: '%s'.\n", |
| 6281 | curproxy->id, curproxy->defbe.name); |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 6282 | cfgerr++; |
| 6283 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6284 | Alert("Proxy '%s': loop detected for default_backend: '%s'.\n", |
| 6285 | curproxy->id, curproxy->defbe.name); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6286 | cfgerr++; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 6287 | } else { |
| 6288 | free(curproxy->defbe.name); |
| 6289 | curproxy->defbe.be = target; |
Willy Tarreau | ff67813 | 2012-02-13 14:32:34 +0100 | [diff] [blame] | 6290 | |
| 6291 | /* Emit a warning if this proxy also has some servers */ |
| 6292 | if (curproxy->srv) { |
| 6293 | Warning("In proxy '%s', the 'default_backend' rule always has precedence over the servers, which will never be used.\n", |
| 6294 | curproxy->id); |
| 6295 | err_code |= ERR_WARN; |
| 6296 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6297 | } |
| 6298 | } |
| 6299 | |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 6300 | /* find the target proxy in setbe */ |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 6301 | if (curproxy->mode == PR_MODE_HTTP && curproxy->req_exp != NULL) { |
| 6302 | /* map jump target for ACT_SETBE in req_rep chain */ |
| 6303 | struct hdr_exp *exp; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 6304 | for (exp = curproxy->req_exp; exp != NULL; exp = exp->next) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6305 | struct proxy *target; |
| 6306 | |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 6307 | if (exp->action != ACT_SETBE) |
| 6308 | continue; |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6309 | |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 6310 | target = findproxy_mode(exp->replace, PR_MODE_HTTP, PR_CAP_BE); |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6311 | if (!target) { |
| 6312 | Alert("Proxy '%s': unable to find required setbe: '%s'.\n", |
| 6313 | curproxy->id, exp->replace); |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 6314 | cfgerr++; |
| 6315 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6316 | Alert("Proxy '%s': loop detected for setbe: '%s'.\n", |
| 6317 | curproxy->id, exp->replace); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 6318 | cfgerr++; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 6319 | } else { |
| 6320 | free((void *)exp->replace); |
| 6321 | exp->replace = (const char *)target; |
| 6322 | } |
| 6323 | } |
| 6324 | } |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6325 | |
| 6326 | /* find the target proxy for 'use_backend' rules */ |
| 6327 | list_for_each_entry(rule, &curproxy->switching_rules, list) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6328 | struct proxy *target; |
Bertrand Jacquin | 702d44f | 2013-11-19 11:43:06 +0100 | [diff] [blame] | 6329 | struct logformat_node *node; |
| 6330 | char *pxname; |
| 6331 | |
| 6332 | /* Try to parse the string as a log format expression. If the result |
| 6333 | * of the parsing is only one entry containing a simple string, then |
| 6334 | * it's a standard string corresponding to a static rule, thus the |
| 6335 | * parsing is cancelled and be.name is restored to be resolved. |
| 6336 | */ |
| 6337 | pxname = rule->be.name; |
| 6338 | LIST_INIT(&rule->be.expr); |
| 6339 | parse_logformat_string(pxname, curproxy, &rule->be.expr, 0, SMP_VAL_FE_HRQ_HDR, |
| 6340 | curproxy->conf.args.file, curproxy->conf.args.line); |
| 6341 | node = LIST_NEXT(&rule->be.expr, struct logformat_node *, list); |
| 6342 | |
| 6343 | if (!LIST_ISEMPTY(&rule->be.expr)) { |
| 6344 | if (node->type != LOG_FMT_TEXT || node->list.n != &rule->be.expr) { |
| 6345 | rule->dynamic = 1; |
| 6346 | free(pxname); |
| 6347 | continue; |
| 6348 | } |
| 6349 | /* simple string: free the expression and fall back to static rule */ |
| 6350 | free(node->arg); |
| 6351 | free(node); |
| 6352 | } |
| 6353 | |
| 6354 | rule->dynamic = 0; |
| 6355 | rule->be.name = pxname; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6356 | |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 6357 | target = findproxy_mode(rule->be.name, curproxy->mode, PR_CAP_BE); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6358 | |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6359 | if (!target) { |
| 6360 | Alert("Proxy '%s': unable to find required use_backend: '%s'.\n", |
| 6361 | curproxy->id, rule->be.name); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6362 | cfgerr++; |
| 6363 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6364 | Alert("Proxy '%s': loop detected for use_backend: '%s'.\n", |
| 6365 | curproxy->id, rule->be.name); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6366 | cfgerr++; |
| 6367 | } else { |
| 6368 | free((void *)rule->be.name); |
| 6369 | rule->be.backend = target; |
| 6370 | } |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 6371 | } |
| 6372 | |
Willy Tarreau | 5436afc | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 6373 | /* find the target server for 'use_server' rules */ |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 6374 | list_for_each_entry(srule, &curproxy->server_rules, list) { |
| 6375 | struct server *target = findserver(curproxy, srule->srv.name); |
| 6376 | |
| 6377 | if (!target) { |
| 6378 | Alert("config : %s '%s' : unable to find server '%s' referenced in a 'use-server' rule.\n", |
| 6379 | proxy_type_str(curproxy), curproxy->id, srule->srv.name); |
| 6380 | cfgerr++; |
| 6381 | continue; |
| 6382 | } |
| 6383 | free((void *)srule->srv.name); |
| 6384 | srule->srv.ptr = target; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6385 | } |
| 6386 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6387 | /* find the target table for 'stick' rules */ |
| 6388 | list_for_each_entry(mrule, &curproxy->sticking_rules, list) { |
| 6389 | struct proxy *target; |
| 6390 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 6391 | curproxy->be_req_ana |= AN_REQ_STICKING_RULES; |
| 6392 | if (mrule->flags & STK_IS_STORE) |
| 6393 | curproxy->be_rsp_ana |= AN_RES_STORE_RULES; |
| 6394 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6395 | if (mrule->table.name) |
Willy Tarreau | c00cdc2 | 2010-06-06 16:48:26 +0200 | [diff] [blame] | 6396 | target = findproxy(mrule->table.name, 0); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6397 | else |
| 6398 | target = curproxy; |
| 6399 | |
| 6400 | if (!target) { |
| 6401 | Alert("Proxy '%s': unable to find stick-table '%s'.\n", |
| 6402 | curproxy->id, mrule->table.name); |
| 6403 | cfgerr++; |
| 6404 | } |
| 6405 | else if (target->table.size == 0) { |
| 6406 | Alert("Proxy '%s': stick-table '%s' used but not configured.\n", |
| 6407 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 6408 | cfgerr++; |
| 6409 | } |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 6410 | else if (!stktable_compatible_sample(mrule->expr, target->table.type)) { |
| 6411 | 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] | 6412 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 6413 | cfgerr++; |
| 6414 | } |
| 6415 | else { |
| 6416 | free((void *)mrule->table.name); |
| 6417 | mrule->table.t = &(target->table); |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 6418 | stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID, NULL); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6419 | } |
| 6420 | } |
| 6421 | |
| 6422 | /* find the target table for 'store response' rules */ |
| 6423 | list_for_each_entry(mrule, &curproxy->storersp_rules, list) { |
| 6424 | struct proxy *target; |
| 6425 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 6426 | curproxy->be_rsp_ana |= AN_RES_STORE_RULES; |
| 6427 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6428 | if (mrule->table.name) |
Willy Tarreau | c00cdc2 | 2010-06-06 16:48:26 +0200 | [diff] [blame] | 6429 | target = findproxy(mrule->table.name, 0); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6430 | else |
| 6431 | target = curproxy; |
| 6432 | |
| 6433 | if (!target) { |
| 6434 | Alert("Proxy '%s': unable to find store table '%s'.\n", |
| 6435 | curproxy->id, mrule->table.name); |
| 6436 | cfgerr++; |
| 6437 | } |
| 6438 | else if (target->table.size == 0) { |
| 6439 | Alert("Proxy '%s': stick-table '%s' used but not configured.\n", |
| 6440 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 6441 | cfgerr++; |
| 6442 | } |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 6443 | else if (!stktable_compatible_sample(mrule->expr, target->table.type)) { |
| 6444 | 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] | 6445 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 6446 | cfgerr++; |
| 6447 | } |
| 6448 | else { |
| 6449 | free((void *)mrule->table.name); |
| 6450 | mrule->table.t = &(target->table); |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 6451 | stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID, NULL); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6452 | } |
| 6453 | } |
| 6454 | |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 6455 | /* find the target table for 'tcp-request' layer 4 rules */ |
| 6456 | list_for_each_entry(trule, &curproxy->tcp_req.l4_rules, list) { |
| 6457 | struct proxy *target; |
| 6458 | |
Willy Tarreau | b4c8493 | 2013-07-23 19:15:30 +0200 | [diff] [blame] | 6459 | 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] | 6460 | continue; |
| 6461 | |
| 6462 | if (trule->act_prm.trk_ctr.table.n) |
| 6463 | target = findproxy(trule->act_prm.trk_ctr.table.n, 0); |
| 6464 | else |
| 6465 | target = curproxy; |
| 6466 | |
| 6467 | if (!target) { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6468 | Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n", |
| 6469 | curproxy->id, trule->act_prm.trk_ctr.table.n, |
Willy Tarreau | 34c2fb6 | 2013-12-02 23:29:05 +0100 | [diff] [blame] | 6470 | tcp_trk_idx(trule->action)); |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 6471 | cfgerr++; |
| 6472 | } |
| 6473 | else if (target->table.size == 0) { |
| 6474 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
| 6475 | curproxy->id, trule->act_prm.trk_ctr.table.n ? trule->act_prm.trk_ctr.table.n : curproxy->id); |
| 6476 | cfgerr++; |
| 6477 | } |
Willy Tarreau | 5f53de7 | 2012-12-12 00:25:44 +0100 | [diff] [blame] | 6478 | else if (!stktable_compatible_sample(trule->act_prm.trk_ctr.expr, target->table.type)) { |
| 6479 | Alert("Proxy '%s': stick-table '%s' uses a type incompatible with the 'track-sc%d' rule.\n", |
| 6480 | 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] | 6481 | tcp_trk_idx(trule->action)); |
Willy Tarreau | 5f53de7 | 2012-12-12 00:25:44 +0100 | [diff] [blame] | 6482 | cfgerr++; |
| 6483 | } |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 6484 | else { |
| 6485 | free(trule->act_prm.trk_ctr.table.n); |
| 6486 | trule->act_prm.trk_ctr.table.t = &target->table; |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6487 | /* 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] | 6488 | * to pass a list of counters to track and allocate them right here using |
| 6489 | * stktable_alloc_data_type(). |
| 6490 | */ |
| 6491 | } |
| 6492 | } |
| 6493 | |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 6494 | /* find the target table for 'tcp-request' layer 6 rules */ |
| 6495 | list_for_each_entry(trule, &curproxy->tcp_req.inspect_rules, list) { |
| 6496 | struct proxy *target; |
| 6497 | |
Willy Tarreau | b4c8493 | 2013-07-23 19:15:30 +0200 | [diff] [blame] | 6498 | 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] | 6499 | continue; |
| 6500 | |
| 6501 | if (trule->act_prm.trk_ctr.table.n) |
| 6502 | target = findproxy(trule->act_prm.trk_ctr.table.n, 0); |
| 6503 | else |
| 6504 | target = curproxy; |
| 6505 | |
| 6506 | if (!target) { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6507 | Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n", |
| 6508 | curproxy->id, trule->act_prm.trk_ctr.table.n, |
Willy Tarreau | 34c2fb6 | 2013-12-02 23:29:05 +0100 | [diff] [blame] | 6509 | tcp_trk_idx(trule->action)); |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 6510 | cfgerr++; |
| 6511 | } |
| 6512 | else if (target->table.size == 0) { |
| 6513 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
| 6514 | curproxy->id, trule->act_prm.trk_ctr.table.n ? trule->act_prm.trk_ctr.table.n : curproxy->id); |
| 6515 | cfgerr++; |
| 6516 | } |
Willy Tarreau | 5f53de7 | 2012-12-12 00:25:44 +0100 | [diff] [blame] | 6517 | else if (!stktable_compatible_sample(trule->act_prm.trk_ctr.expr, target->table.type)) { |
| 6518 | Alert("Proxy '%s': stick-table '%s' uses a type incompatible with the 'track-sc%d' rule.\n", |
| 6519 | 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] | 6520 | tcp_trk_idx(trule->action)); |
Willy Tarreau | 5f53de7 | 2012-12-12 00:25:44 +0100 | [diff] [blame] | 6521 | cfgerr++; |
| 6522 | } |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 6523 | else { |
| 6524 | free(trule->act_prm.trk_ctr.table.n); |
| 6525 | trule->act_prm.trk_ctr.table.t = &target->table; |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6526 | /* 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] | 6527 | * to pass a list of counters to track and allocate them right here using |
| 6528 | * stktable_alloc_data_type(). |
| 6529 | */ |
| 6530 | } |
| 6531 | } |
| 6532 | |
Willy Tarreau | b3dc39d | 2014-04-28 22:06:57 +0200 | [diff] [blame] | 6533 | /* move any "block" rules at the beginning of the http-request rules */ |
| 6534 | if (!LIST_ISEMPTY(&curproxy->block_rules)) { |
| 6535 | /* insert block_rules into http_req_rules at the beginning */ |
| 6536 | curproxy->block_rules.p->n = curproxy->http_req_rules.n; |
| 6537 | curproxy->http_req_rules.n->p = curproxy->block_rules.p; |
| 6538 | curproxy->block_rules.n->p = &curproxy->http_req_rules; |
| 6539 | curproxy->http_req_rules.n = curproxy->block_rules.n; |
| 6540 | LIST_INIT(&curproxy->block_rules); |
| 6541 | } |
| 6542 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 6543 | if (curproxy->table.peers.name) { |
| 6544 | struct peers *curpeers = peers; |
| 6545 | |
| 6546 | for (curpeers = peers; curpeers; curpeers = curpeers->next) { |
| 6547 | if (strcmp(curpeers->id, curproxy->table.peers.name) == 0) { |
| 6548 | free((void *)curproxy->table.peers.name); |
Willy Tarreau | 973ca49 | 2013-01-17 21:34:52 +0100 | [diff] [blame] | 6549 | curproxy->table.peers.p = curpeers; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 6550 | break; |
| 6551 | } |
| 6552 | } |
| 6553 | |
| 6554 | if (!curpeers) { |
| 6555 | Alert("Proxy '%s': unable to find sync peers '%s'.\n", |
| 6556 | curproxy->id, curproxy->table.peers.name); |
Willy Tarreau | d66bf96 | 2011-10-28 14:16:49 +0200 | [diff] [blame] | 6557 | free((void *)curproxy->table.peers.name); |
| 6558 | curproxy->table.peers.p = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 6559 | cfgerr++; |
| 6560 | } |
Willy Tarreau | 34d05b0 | 2015-05-01 20:02:17 +0200 | [diff] [blame] | 6561 | else if (curpeers->state == PR_STSTOPPED) { |
| 6562 | /* silently disable this peers section */ |
| 6563 | curproxy->table.peers.p = NULL; |
| 6564 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 6565 | else if (!curpeers->peers_fe) { |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 6566 | Alert("Proxy '%s': unable to find local peer '%s' in peers section '%s'.\n", |
| 6567 | curproxy->id, localpeer, curpeers->id); |
Willy Tarreau | d66bf96 | 2011-10-28 14:16:49 +0200 | [diff] [blame] | 6568 | curproxy->table.peers.p = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 6569 | cfgerr++; |
| 6570 | } |
| 6571 | } |
| 6572 | |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 6573 | if (curproxy->uri_auth && !(curproxy->uri_auth->flags & ST_CONVDONE) && |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 6574 | !LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) && |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6575 | (curproxy->uri_auth->userlist || curproxy->uri_auth->auth_realm )) { |
| 6576 | Alert("%s '%s': stats 'auth'/'realm' and 'http-request' can't be used at the same time.\n", |
| 6577 | "proxy", curproxy->id); |
| 6578 | cfgerr++; |
| 6579 | goto out_uri_auth_compat; |
| 6580 | } |
| 6581 | |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 6582 | 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] | 6583 | const char *uri_auth_compat_req[10]; |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 6584 | struct http_req_rule *rule; |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6585 | int i = 0; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6586 | |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6587 | /* build the ACL condition from scratch. We're relying on anonymous ACLs for that */ |
| 6588 | uri_auth_compat_req[i++] = "auth"; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6589 | |
| 6590 | if (curproxy->uri_auth->auth_realm) { |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6591 | uri_auth_compat_req[i++] = "realm"; |
| 6592 | uri_auth_compat_req[i++] = curproxy->uri_auth->auth_realm; |
| 6593 | } |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6594 | |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6595 | uri_auth_compat_req[i++] = "unless"; |
| 6596 | uri_auth_compat_req[i++] = "{"; |
| 6597 | uri_auth_compat_req[i++] = "http_auth(.internal-stats-userlist)"; |
| 6598 | uri_auth_compat_req[i++] = "}"; |
| 6599 | uri_auth_compat_req[i++] = ""; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6600 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 6601 | rule = parse_http_req_cond(uri_auth_compat_req, "internal-stats-auth-compat", 0, curproxy); |
| 6602 | if (!rule) { |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6603 | cfgerr++; |
| 6604 | break; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6605 | } |
| 6606 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 6607 | LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list); |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6608 | |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6609 | if (curproxy->uri_auth->auth_realm) { |
| 6610 | free(curproxy->uri_auth->auth_realm); |
| 6611 | curproxy->uri_auth->auth_realm = NULL; |
| 6612 | } |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 6613 | |
| 6614 | curproxy->uri_auth->flags |= ST_CONVDONE; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6615 | } |
| 6616 | out_uri_auth_compat: |
| 6617 | |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 6618 | /* compile the log format */ |
| 6619 | if (!(curproxy->cap & PR_CAP_FE)) { |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 6620 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 6621 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 6622 | curproxy->conf.logformat_string != clf_http_log_format) |
| 6623 | free(curproxy->conf.logformat_string); |
| 6624 | curproxy->conf.logformat_string = NULL; |
| 6625 | free(curproxy->conf.lfs_file); |
| 6626 | curproxy->conf.lfs_file = NULL; |
| 6627 | curproxy->conf.lfs_line = 0; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 6628 | } |
| 6629 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 6630 | if (curproxy->conf.logformat_string) { |
| 6631 | curproxy->conf.args.ctx = ARGC_LOG; |
| 6632 | curproxy->conf.args.file = curproxy->conf.lfs_file; |
| 6633 | curproxy->conf.args.line = curproxy->conf.lfs_line; |
| 6634 | 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] | 6635 | 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] | 6636 | curproxy->conf.args.file = NULL; |
| 6637 | curproxy->conf.args.line = 0; |
| 6638 | } |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 6639 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 6640 | if (curproxy->conf.uniqueid_format_string) { |
| 6641 | curproxy->conf.args.ctx = ARGC_UIF; |
| 6642 | curproxy->conf.args.file = curproxy->conf.uif_file; |
| 6643 | curproxy->conf.args.line = curproxy->conf.uif_line; |
Thierry FOURNIER | d048d8b | 2014-03-13 16:46:18 +0100 | [diff] [blame] | 6644 | parse_logformat_string(curproxy->conf.uniqueid_format_string, curproxy, &curproxy->format_unique_id, LOG_OPT_HTTP, |
Godbach | 543b978 | 2014-12-18 15:44:58 +0800 | [diff] [blame] | 6645 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
Thierry FOURNIER | eeaa951 | 2014-02-11 14:00:19 +0100 | [diff] [blame] | 6646 | curproxy->conf.uif_file, curproxy->conf.uif_line); |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 6647 | curproxy->conf.args.file = NULL; |
| 6648 | curproxy->conf.args.line = 0; |
| 6649 | } |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 6650 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6651 | /* only now we can check if some args remain unresolved. |
| 6652 | * This must be done after the users and groups resolution. |
| 6653 | */ |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 6654 | cfgerr += smp_resolve_args(curproxy); |
| 6655 | if (!cfgerr) |
| 6656 | cfgerr += acl_find_targets(curproxy); |
Krzysztof Piotr Oledzki | f9423ae | 2010-01-29 19:26:18 +0100 | [diff] [blame] | 6657 | |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 6658 | if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) && |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6659 | (((curproxy->cap & PR_CAP_FE) && !curproxy->timeout.client) || |
Willy Tarreau | d825eef | 2007-05-12 22:35:00 +0200 | [diff] [blame] | 6660 | ((curproxy->cap & PR_CAP_BE) && (curproxy->srv) && |
Willy Tarreau | ce887fd | 2012-05-12 12:50:00 +0200 | [diff] [blame] | 6661 | (!curproxy->timeout.connect || |
| 6662 | (!curproxy->timeout.server && (curproxy->mode == PR_MODE_HTTP || !curproxy->timeout.tunnel)))))) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6663 | Warning("config : missing timeouts for %s '%s'.\n" |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 6664 | " | While not properly invalid, you will certainly encounter various problems\n" |
| 6665 | " | 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] | 6666 | " | timeouts are set to a non-zero value: 'client', 'connect', 'server'.\n", |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6667 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6668 | err_code |= ERR_WARN; |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 6669 | } |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 6670 | |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6671 | /* Historically, the tarpit and queue timeouts were inherited from contimeout. |
| 6672 | * We must still support older configurations, so let's find out whether those |
| 6673 | * parameters have been set or must be copied from contimeouts. |
| 6674 | */ |
| 6675 | if (curproxy != &defproxy) { |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6676 | if (!curproxy->timeout.tarpit || |
| 6677 | curproxy->timeout.tarpit == defproxy.timeout.tarpit) { |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6678 | /* tarpit timeout not set. We search in the following order: |
| 6679 | * default.tarpit, curr.connect, default.connect. |
| 6680 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6681 | if (defproxy.timeout.tarpit) |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6682 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6683 | else if (curproxy->timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6684 | curproxy->timeout.tarpit = curproxy->timeout.connect; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6685 | else if (defproxy.timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6686 | curproxy->timeout.tarpit = defproxy.timeout.connect; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6687 | } |
| 6688 | if ((curproxy->cap & PR_CAP_BE) && |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6689 | (!curproxy->timeout.queue || |
| 6690 | curproxy->timeout.queue == defproxy.timeout.queue)) { |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6691 | /* queue timeout not set. We search in the following order: |
| 6692 | * default.queue, curr.connect, default.connect. |
| 6693 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6694 | if (defproxy.timeout.queue) |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6695 | curproxy->timeout.queue = defproxy.timeout.queue; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6696 | else if (curproxy->timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6697 | curproxy->timeout.queue = curproxy->timeout.connect; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6698 | else if (defproxy.timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6699 | curproxy->timeout.queue = defproxy.timeout.connect; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6700 | } |
| 6701 | } |
| 6702 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 6703 | if ((curproxy->options2 & PR_O2_CHK_ANY) == PR_O2_SSL3_CHK) { |
Willy Tarreau | 137325d | 2010-02-01 16:38:17 +0100 | [diff] [blame] | 6704 | curproxy->check_len = sizeof(sslv3_client_hello_pkt) - 1; |
| 6705 | curproxy->check_req = (char *)malloc(curproxy->check_len); |
| 6706 | memcpy(curproxy->check_req, sslv3_client_hello_pkt, curproxy->check_len); |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 6707 | } |
| 6708 | |
Willy Tarreau | 215663d | 2014-06-13 18:30:23 +0200 | [diff] [blame] | 6709 | if (!LIST_ISEMPTY(&curproxy->tcpcheck_rules) && |
| 6710 | (curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_TCPCHK_CHK) { |
| 6711 | Warning("config : %s '%s' uses tcp-check rules without 'option tcp-check', so the rules are ignored.\n", |
| 6712 | proxy_type_str(curproxy), curproxy->id); |
| 6713 | err_code |= ERR_WARN; |
| 6714 | } |
| 6715 | |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 6716 | /* ensure that cookie capture length is not too large */ |
| 6717 | if (curproxy->capture_len >= global.tune.cookie_len) { |
| 6718 | Warning("config : truncating capture length to %d bytes for %s '%s'.\n", |
| 6719 | global.tune.cookie_len - 1, proxy_type_str(curproxy), curproxy->id); |
| 6720 | err_code |= ERR_WARN; |
| 6721 | curproxy->capture_len = global.tune.cookie_len - 1; |
| 6722 | } |
| 6723 | |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 6724 | /* The small pools required for the capture lists */ |
Willy Tarreau | 9a54e13 | 2012-03-24 08:33:05 +0100 | [diff] [blame] | 6725 | if (curproxy->nb_req_cap) { |
Willy Tarreau | d9ed3d2 | 2014-06-13 12:23:06 +0200 | [diff] [blame] | 6726 | curproxy->req_cap_pool = create_pool("ptrcap", |
| 6727 | curproxy->nb_req_cap * sizeof(char *), |
| 6728 | MEM_F_SHARED); |
Willy Tarreau | 9a54e13 | 2012-03-24 08:33:05 +0100 | [diff] [blame] | 6729 | } |
| 6730 | |
| 6731 | if (curproxy->nb_rsp_cap) { |
Willy Tarreau | d9ed3d2 | 2014-06-13 12:23:06 +0200 | [diff] [blame] | 6732 | curproxy->rsp_cap_pool = create_pool("ptrcap", |
| 6733 | curproxy->nb_rsp_cap * sizeof(char *), |
| 6734 | MEM_F_SHARED); |
Willy Tarreau | 9a54e13 | 2012-03-24 08:33:05 +0100 | [diff] [blame] | 6735 | } |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 6736 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6737 | /* first, we will invert the servers list order */ |
| 6738 | newsrv = NULL; |
| 6739 | while (curproxy->srv) { |
| 6740 | struct server *next; |
| 6741 | |
| 6742 | next = curproxy->srv->next; |
| 6743 | curproxy->srv->next = newsrv; |
| 6744 | newsrv = curproxy->srv; |
| 6745 | if (!next) |
| 6746 | break; |
| 6747 | curproxy->srv = next; |
| 6748 | } |
| 6749 | |
Willy Tarreau | 17edc81 | 2014-01-03 12:14:34 +0100 | [diff] [blame] | 6750 | /* Check that no server name conflicts. This causes trouble in the stats. |
| 6751 | * We only emit a warning for the first conflict affecting each server, |
| 6752 | * in order to avoid combinatory explosion if all servers have the same |
| 6753 | * name. We do that only for servers which do not have an explicit ID, |
| 6754 | * because these IDs were made also for distinguishing them and we don't |
| 6755 | * want to annoy people who correctly manage them. |
| 6756 | */ |
| 6757 | for (newsrv = curproxy->srv; newsrv; newsrv = newsrv->next) { |
| 6758 | struct server *other_srv; |
| 6759 | |
| 6760 | if (newsrv->puid) |
| 6761 | continue; |
| 6762 | |
| 6763 | for (other_srv = curproxy->srv; other_srv && other_srv != newsrv; other_srv = other_srv->next) { |
| 6764 | if (!other_srv->puid && strcmp(other_srv->id, newsrv->id) == 0) { |
| 6765 | Warning("parsing [%s:%d] : %s '%s', another server named '%s' was defined without an explicit ID at line %d, this is not recommended.\n", |
| 6766 | newsrv->conf.file, newsrv->conf.line, |
| 6767 | proxy_type_str(curproxy), curproxy->id, |
| 6768 | newsrv->id, other_srv->conf.line); |
| 6769 | break; |
| 6770 | } |
| 6771 | } |
| 6772 | } |
| 6773 | |
Willy Tarreau | dd70165 | 2010-05-25 23:03:02 +0200 | [diff] [blame] | 6774 | /* assign automatic UIDs to servers which don't have one yet */ |
| 6775 | next_id = 1; |
| 6776 | newsrv = curproxy->srv; |
| 6777 | while (newsrv != NULL) { |
| 6778 | if (!newsrv->puid) { |
| 6779 | /* server ID not set, use automatic numbering with first |
| 6780 | * spare entry starting with next_svid. |
| 6781 | */ |
| 6782 | next_id = get_next_id(&curproxy->conf.used_server_id, next_id); |
| 6783 | newsrv->conf.id.key = newsrv->puid = next_id; |
| 6784 | eb32_insert(&curproxy->conf.used_server_id, &newsrv->conf.id); |
| 6785 | } |
| 6786 | next_id++; |
| 6787 | newsrv = newsrv->next; |
| 6788 | } |
| 6789 | |
Willy Tarreau | 2069704 | 2007-11-15 23:26:18 +0100 | [diff] [blame] | 6790 | curproxy->lbprm.wmult = 1; /* default weight multiplier */ |
Willy Tarreau | 5dc2fa6 | 2007-11-19 19:10:18 +0100 | [diff] [blame] | 6791 | curproxy->lbprm.wdiv = 1; /* default weight divider */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6792 | |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 6793 | /* |
| 6794 | * If this server supports a maxconn parameter, it needs a dedicated |
| 6795 | * tasks to fill the emptied slots when a connection leaves. |
| 6796 | * Also, resolve deferred tracking dependency if needed. |
| 6797 | */ |
| 6798 | newsrv = curproxy->srv; |
| 6799 | while (newsrv != NULL) { |
| 6800 | if (newsrv->minconn > newsrv->maxconn) { |
| 6801 | /* Only 'minconn' was specified, or it was higher than or equal |
| 6802 | * to 'maxconn'. Let's turn this into maxconn and clean it, as |
| 6803 | * this will avoid further useless expensive computations. |
| 6804 | */ |
| 6805 | newsrv->maxconn = newsrv->minconn; |
| 6806 | } else if (newsrv->maxconn && !newsrv->minconn) { |
| 6807 | /* minconn was not specified, so we set it to maxconn */ |
| 6808 | newsrv->minconn = newsrv->maxconn; |
| 6809 | } |
| 6810 | |
Emeric Brun | 01f8e2f | 2012-05-18 16:02:00 +0200 | [diff] [blame] | 6811 | #ifdef USE_OPENSSL |
Emeric Brun | 94324a4 | 2012-10-11 14:00:19 +0200 | [diff] [blame] | 6812 | if (newsrv->use_ssl || newsrv->check.use_ssl) |
| 6813 | cfgerr += ssl_sock_prepare_srv_ctx(newsrv, curproxy); |
Emeric Brun | 01f8e2f | 2012-05-18 16:02:00 +0200 | [diff] [blame] | 6814 | #endif /* USE_OPENSSL */ |
Emeric Brun | 94324a4 | 2012-10-11 14:00:19 +0200 | [diff] [blame] | 6815 | |
Willy Tarreau | 2f075e9 | 2013-12-03 11:11:34 +0100 | [diff] [blame] | 6816 | /* set the check type on the server */ |
| 6817 | newsrv->check.type = curproxy->options2 & PR_O2_CHK_ANY; |
| 6818 | |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 6819 | if (newsrv->trackit) { |
| 6820 | struct proxy *px; |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 6821 | struct server *srv, *loop; |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 6822 | char *pname, *sname; |
| 6823 | |
| 6824 | pname = newsrv->trackit; |
| 6825 | sname = strrchr(pname, '/'); |
| 6826 | |
| 6827 | if (sname) |
| 6828 | *sname++ = '\0'; |
| 6829 | else { |
| 6830 | sname = pname; |
| 6831 | pname = NULL; |
| 6832 | } |
| 6833 | |
| 6834 | if (pname) { |
| 6835 | px = findproxy(pname, PR_CAP_BE); |
| 6836 | if (!px) { |
| 6837 | Alert("config : %s '%s', server '%s': unable to find required proxy '%s' for tracking.\n", |
| 6838 | proxy_type_str(curproxy), curproxy->id, |
| 6839 | newsrv->id, pname); |
| 6840 | cfgerr++; |
| 6841 | goto next_srv; |
| 6842 | } |
| 6843 | } else |
| 6844 | px = curproxy; |
| 6845 | |
| 6846 | srv = findserver(px, sname); |
| 6847 | if (!srv) { |
| 6848 | Alert("config : %s '%s', server '%s': unable to find required server '%s' for tracking.\n", |
| 6849 | proxy_type_str(curproxy), curproxy->id, |
| 6850 | newsrv->id, sname); |
| 6851 | cfgerr++; |
| 6852 | goto next_srv; |
| 6853 | } |
| 6854 | |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 6855 | if (!(srv->check.state & CHK_ST_CONFIGURED) && |
| 6856 | !(srv->agent.state & CHK_ST_CONFIGURED) && |
| 6857 | !srv->track && !srv->trackit) { |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 6858 | Alert("config : %s '%s', server '%s': unable to use %s/%s for " |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 6859 | "tracking as it does not have any check nor agent enabled.\n", |
| 6860 | proxy_type_str(curproxy), curproxy->id, |
| 6861 | newsrv->id, px->id, srv->id); |
| 6862 | cfgerr++; |
| 6863 | goto next_srv; |
| 6864 | } |
| 6865 | |
| 6866 | for (loop = srv->track; loop && loop != newsrv; loop = loop->track); |
| 6867 | |
| 6868 | if (loop) { |
| 6869 | Alert("config : %s '%s', server '%s': unable to track %s/%s as it " |
| 6870 | "belongs to a tracking chain looping back to %s/%s.\n", |
| 6871 | proxy_type_str(curproxy), curproxy->id, |
| 6872 | newsrv->id, px->id, srv->id, px->id, loop->id); |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 6873 | cfgerr++; |
| 6874 | goto next_srv; |
| 6875 | } |
| 6876 | |
| 6877 | if (curproxy != px && |
| 6878 | (curproxy->options & PR_O_DISABLE404) != (px->options & PR_O_DISABLE404)) { |
| 6879 | Alert("config : %s '%s', server '%s': unable to use %s/%s for" |
| 6880 | "tracking: disable-on-404 option inconsistency.\n", |
| 6881 | proxy_type_str(curproxy), curproxy->id, |
| 6882 | newsrv->id, px->id, srv->id); |
| 6883 | cfgerr++; |
| 6884 | goto next_srv; |
| 6885 | } |
| 6886 | |
| 6887 | /* 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] | 6888 | if (srv->admin & SRV_ADMF_MAINT) { |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 6889 | newsrv->admin |= SRV_ADMF_IMAINT; |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 6890 | newsrv->state = SRV_ST_STOPPED; |
Simon Horman | 125d099 | 2013-02-24 17:23:38 +0900 | [diff] [blame] | 6891 | newsrv->check.health = 0; |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 6892 | } |
| 6893 | |
| 6894 | newsrv->track = srv; |
Willy Tarreau | 1a53a3a | 2013-12-11 15:27:05 +0100 | [diff] [blame] | 6895 | newsrv->tracknext = srv->trackers; |
| 6896 | srv->trackers = newsrv; |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 6897 | |
| 6898 | free(newsrv->trackit); |
| 6899 | newsrv->trackit = NULL; |
| 6900 | } |
| 6901 | next_srv: |
| 6902 | newsrv = newsrv->next; |
| 6903 | } |
| 6904 | |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6905 | /* We have to initialize the server lookup mechanism depending |
| 6906 | * on what LB algorithm was choosen. |
| 6907 | */ |
| 6908 | |
| 6909 | curproxy->lbprm.algo &= ~(BE_LB_LKUP | BE_LB_PROP_DYN); |
| 6910 | switch (curproxy->lbprm.algo & BE_LB_KIND) { |
| 6911 | case BE_LB_KIND_RR: |
Willy Tarreau | 9757a38 | 2009-10-03 12:56:50 +0200 | [diff] [blame] | 6912 | if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_RR_STATIC) { |
| 6913 | curproxy->lbprm.algo |= BE_LB_LKUP_MAP; |
| 6914 | init_server_map(curproxy); |
| 6915 | } else { |
| 6916 | curproxy->lbprm.algo |= BE_LB_LKUP_RRTREE | BE_LB_PROP_DYN; |
| 6917 | fwrr_init_server_groups(curproxy); |
| 6918 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6919 | break; |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 6920 | |
Willy Tarreau | 3ebb116 | 2012-02-13 16:57:44 +0100 | [diff] [blame] | 6921 | case BE_LB_KIND_CB: |
Willy Tarreau | f09c660 | 2012-02-13 17:12:08 +0100 | [diff] [blame] | 6922 | if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_CB_LC) { |
| 6923 | curproxy->lbprm.algo |= BE_LB_LKUP_LCTREE | BE_LB_PROP_DYN; |
| 6924 | fwlc_init_server_tree(curproxy); |
| 6925 | } else { |
| 6926 | curproxy->lbprm.algo |= BE_LB_LKUP_FSTREE | BE_LB_PROP_DYN; |
| 6927 | fas_init_server_tree(curproxy); |
| 6928 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6929 | break; |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 6930 | |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6931 | case BE_LB_KIND_HI: |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 6932 | if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS) { |
| 6933 | curproxy->lbprm.algo |= BE_LB_LKUP_CHTREE | BE_LB_PROP_DYN; |
| 6934 | chash_init_server_tree(curproxy); |
| 6935 | } else { |
| 6936 | curproxy->lbprm.algo |= BE_LB_LKUP_MAP; |
| 6937 | init_server_map(curproxy); |
| 6938 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6939 | break; |
| 6940 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6941 | |
| 6942 | if (curproxy->options & PR_O_LOGASAP) |
| 6943 | curproxy->to_log &= ~LW_BYTES; |
| 6944 | |
Willy Tarreau | e7ded1f | 2009-08-09 10:11:45 +0200 | [diff] [blame] | 6945 | if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) && |
Willy Tarreau | d79a3b2 | 2012-12-28 09:40:16 +0100 | [diff] [blame] | 6946 | (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] | 6947 | Warning("config : log format ignored for %s '%s' since it has no log address.\n", |
| 6948 | proxy_type_str(curproxy), curproxy->id); |
| 6949 | err_code |= ERR_WARN; |
| 6950 | } |
| 6951 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 6952 | if (curproxy->mode != PR_MODE_HTTP) { |
| 6953 | int optnum; |
| 6954 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 6955 | if (curproxy->uri_auth) { |
| 6956 | Warning("config : 'stats' statement ignored for %s '%s' as it requires HTTP mode.\n", |
| 6957 | proxy_type_str(curproxy), curproxy->id); |
| 6958 | err_code |= ERR_WARN; |
| 6959 | curproxy->uri_auth = NULL; |
| 6960 | } |
| 6961 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 6962 | if (curproxy->options & (PR_O_FWDFOR | PR_O_FF_ALWAYS)) { |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 6963 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6964 | "forwardfor", proxy_type_str(curproxy), curproxy->id); |
| 6965 | err_code |= ERR_WARN; |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 6966 | curproxy->options &= ~(PR_O_FWDFOR | PR_O_FF_ALWAYS); |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 6967 | } |
| 6968 | |
| 6969 | if (curproxy->options & PR_O_ORGTO) { |
| 6970 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6971 | "originalto", proxy_type_str(curproxy), curproxy->id); |
| 6972 | err_code |= ERR_WARN; |
| 6973 | curproxy->options &= ~PR_O_ORGTO; |
| 6974 | } |
| 6975 | |
| 6976 | for (optnum = 0; cfg_opts[optnum].name; optnum++) { |
| 6977 | if (cfg_opts[optnum].mode == PR_MODE_HTTP && |
| 6978 | (curproxy->cap & cfg_opts[optnum].cap) && |
| 6979 | (curproxy->options & cfg_opts[optnum].val)) { |
| 6980 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6981 | cfg_opts[optnum].name, proxy_type_str(curproxy), curproxy->id); |
| 6982 | err_code |= ERR_WARN; |
| 6983 | curproxy->options &= ~cfg_opts[optnum].val; |
| 6984 | } |
| 6985 | } |
| 6986 | |
| 6987 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) { |
| 6988 | if (cfg_opts2[optnum].mode == PR_MODE_HTTP && |
| 6989 | (curproxy->cap & cfg_opts2[optnum].cap) && |
| 6990 | (curproxy->options2 & cfg_opts2[optnum].val)) { |
| 6991 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6992 | cfg_opts2[optnum].name, proxy_type_str(curproxy), curproxy->id); |
| 6993 | err_code |= ERR_WARN; |
| 6994 | curproxy->options2 &= ~cfg_opts2[optnum].val; |
| 6995 | } |
| 6996 | } |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6997 | |
Pieter Baauw | d551fb5 | 2013-05-08 22:49:23 +0200 | [diff] [blame] | 6998 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_TRANSPARENT) |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6999 | if (curproxy->conn_src.bind_hdr_occ) { |
| 7000 | curproxy->conn_src.bind_hdr_occ = 0; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 7001 | 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] | 7002 | proxy_type_str(curproxy), curproxy->id, curproxy->conn_src.bind_hdr_name); |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 7003 | err_code |= ERR_WARN; |
| 7004 | } |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 7005 | #endif |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 7006 | } |
| 7007 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7008 | /* |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 7009 | * ensure that we're not cross-dressing a TCP server into HTTP. |
| 7010 | */ |
| 7011 | newsrv = curproxy->srv; |
| 7012 | while (newsrv != NULL) { |
Willy Tarreau | 0cec331 | 2011-10-31 13:49:26 +0100 | [diff] [blame] | 7013 | if ((curproxy->mode != PR_MODE_HTTP) && newsrv->rdr_len) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7014 | Alert("config : %s '%s' : server cannot have cookie or redirect prefix in non-HTTP mode.\n", |
| 7015 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 7016 | cfgerr++; |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 7017 | } |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 7018 | |
Willy Tarreau | 0cec331 | 2011-10-31 13:49:26 +0100 | [diff] [blame] | 7019 | if ((curproxy->mode != PR_MODE_HTTP) && newsrv->cklen) { |
| 7020 | Warning("config : %s '%s' : ignoring cookie for server '%s' as HTTP mode is disabled.\n", |
| 7021 | proxy_type_str(curproxy), curproxy->id, newsrv->id); |
| 7022 | err_code |= ERR_WARN; |
| 7023 | } |
| 7024 | |
Willy Tarreau | c93cd16 | 2014-05-13 15:54:22 +0200 | [diff] [blame] | 7025 | if ((newsrv->flags & SRV_F_MAPPORTS) && (curproxy->options2 & PR_O2_RDPC_PRST)) { |
Willy Tarreau | 82ffa39 | 2013-08-13 17:19:08 +0200 | [diff] [blame] | 7026 | Warning("config : %s '%s' : RDP cookie persistence will not work for server '%s' because it lacks an explicit port number.\n", |
| 7027 | proxy_type_str(curproxy), curproxy->id, newsrv->id); |
| 7028 | err_code |= ERR_WARN; |
| 7029 | } |
| 7030 | |
Pieter Baauw | d551fb5 | 2013-05-08 22:49:23 +0200 | [diff] [blame] | 7031 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_TRANSPARENT) |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 7032 | if (curproxy->mode != PR_MODE_HTTP && newsrv->conn_src.bind_hdr_occ) { |
| 7033 | newsrv->conn_src.bind_hdr_occ = 0; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 7034 | 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] | 7035 | 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] | 7036 | err_code |= ERR_WARN; |
| 7037 | } |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 7038 | #endif |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 7039 | newsrv = newsrv->next; |
| 7040 | } |
| 7041 | |
Willy Tarreau | 7fc7ebd | 2014-09-16 16:21:19 +0200 | [diff] [blame] | 7042 | /* check if we have a frontend with "tcp-request content" looking at L7 |
| 7043 | * with no inspect-delay |
| 7044 | */ |
| 7045 | if ((curproxy->cap & PR_CAP_FE) && !curproxy->tcp_req.inspect_delay) { |
| 7046 | list_for_each_entry(trule, &curproxy->tcp_req.inspect_rules, list) { |
| 7047 | if (trule->action == TCP_ACT_CAPTURE && |
| 7048 | !(trule->act_prm.cap.expr->fetch->val & SMP_VAL_FE_SES_ACC)) |
| 7049 | break; |
| 7050 | if ((trule->action >= TCP_ACT_TRK_SC0 && trule->action <= TCP_ACT_TRK_SCMAX) && |
| 7051 | !(trule->act_prm.trk_ctr.expr->fetch->val & SMP_VAL_FE_SES_ACC)) |
| 7052 | break; |
| 7053 | } |
| 7054 | |
| 7055 | if (&trule->list != &curproxy->tcp_req.inspect_rules) { |
| 7056 | Warning("config : %s '%s' : some 'tcp-request content' rules explicitly depending on request" |
| 7057 | " contents were found in a frontend without any 'tcp-request inspect-delay' setting." |
| 7058 | " This means that these rules will randomly find their contents. This can be fixed by" |
| 7059 | " setting the tcp-request inspect-delay.\n", |
| 7060 | proxy_type_str(curproxy), curproxy->id); |
| 7061 | err_code |= ERR_WARN; |
| 7062 | } |
| 7063 | } |
| 7064 | |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 7065 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 7066 | if (!curproxy->accept) |
| 7067 | curproxy->accept = frontend_accept; |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 7068 | |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 7069 | if (curproxy->tcp_req.inspect_delay || |
| 7070 | !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules)) |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 7071 | curproxy->fe_req_ana |= AN_REQ_INSPECT_FE; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 7072 | |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 7073 | if (curproxy->mode == PR_MODE_HTTP) { |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 7074 | 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] | 7075 | 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] | 7076 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 7077 | |
| 7078 | /* both TCP and HTTP must check switching rules */ |
| 7079 | curproxy->fe_req_ana |= AN_REQ_SWITCHING_RULES; |
| 7080 | } |
| 7081 | |
| 7082 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 7083 | if (curproxy->tcp_req.inspect_delay || |
| 7084 | !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules)) |
| 7085 | curproxy->be_req_ana |= AN_REQ_INSPECT_BE; |
| 7086 | |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 7087 | if (!LIST_ISEMPTY(&curproxy->tcp_rep.inspect_rules)) |
| 7088 | curproxy->be_rsp_ana |= AN_RES_INSPECT; |
| 7089 | |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 7090 | if (curproxy->mode == PR_MODE_HTTP) { |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 7091 | 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] | 7092 | 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] | 7093 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 7094 | |
| 7095 | /* If the backend does requires RDP cookie persistence, we have to |
| 7096 | * enable the corresponding analyser. |
| 7097 | */ |
| 7098 | if (curproxy->options2 & PR_O2_RDPC_PRST) |
| 7099 | curproxy->be_req_ana |= AN_REQ_PRST_RDP_COOKIE; |
| 7100 | } |
Willy Tarreau | 91b00c2 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 7101 | } |
| 7102 | |
| 7103 | /***********************************************************/ |
| 7104 | /* At this point, target names have already been resolved. */ |
| 7105 | /***********************************************************/ |
| 7106 | |
| 7107 | /* Check multi-process mode compatibility */ |
| 7108 | |
| 7109 | if (global.nbproc > 1 && global.stats_fe) { |
| 7110 | list_for_each_entry(bind_conf, &global.stats_fe->conf.bind, by_fe) { |
| 7111 | unsigned long mask; |
| 7112 | |
| 7113 | mask = nbits(global.nbproc); |
| 7114 | if (global.stats_fe->bind_proc) |
| 7115 | mask &= global.stats_fe->bind_proc; |
| 7116 | |
| 7117 | if (bind_conf->bind_proc) |
| 7118 | mask &= bind_conf->bind_proc; |
| 7119 | |
| 7120 | /* stop here if more than one process is used */ |
David Carlier | 6de4c2f | 2015-07-02 07:00:17 +0000 | [diff] [blame] | 7121 | if (my_popcountl(mask) > 1) |
Willy Tarreau | 91b00c2 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 7122 | break; |
| 7123 | } |
| 7124 | if (&bind_conf->by_fe != &global.stats_fe->conf.bind) { |
| 7125 | 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"); |
| 7126 | } |
| 7127 | } |
| 7128 | |
| 7129 | /* Make each frontend inherit bind-process from its listeners when not specified. */ |
| 7130 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 7131 | if (curproxy->bind_proc) |
| 7132 | continue; |
| 7133 | |
| 7134 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
| 7135 | unsigned long mask; |
| 7136 | |
Willy Tarreau | 01760ad | 2015-05-04 21:57:58 +0200 | [diff] [blame] | 7137 | mask = bind_conf->bind_proc ? bind_conf->bind_proc : nbits(global.nbproc); |
Willy Tarreau | 91b00c2 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 7138 | curproxy->bind_proc |= mask; |
| 7139 | } |
| 7140 | |
| 7141 | if (!curproxy->bind_proc) |
Willy Tarreau | 01760ad | 2015-05-04 21:57:58 +0200 | [diff] [blame] | 7142 | curproxy->bind_proc = nbits(global.nbproc); |
Willy Tarreau | 91b00c2 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 7143 | } |
| 7144 | |
| 7145 | if (global.stats_fe) { |
| 7146 | list_for_each_entry(bind_conf, &global.stats_fe->conf.bind, by_fe) { |
| 7147 | unsigned long mask; |
| 7148 | |
Cyril Bonté | 32e4f25 | 2016-02-24 00:14:54 +0100 | [diff] [blame] | 7149 | mask = bind_conf->bind_proc ? bind_conf->bind_proc : 0; |
Willy Tarreau | 91b00c2 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 7150 | global.stats_fe->bind_proc |= mask; |
| 7151 | } |
| 7152 | if (!global.stats_fe->bind_proc) |
Willy Tarreau | 01760ad | 2015-05-04 21:57:58 +0200 | [diff] [blame] | 7153 | global.stats_fe->bind_proc = nbits(global.nbproc); |
Willy Tarreau | 91b00c2 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 7154 | } |
| 7155 | |
Willy Tarreau | b3228c8 | 2014-10-01 20:50:17 +0200 | [diff] [blame] | 7156 | /* propagate bindings from frontends to backends. Don't do it if there |
| 7157 | * are any fatal errors as we must not call it with unresolved proxies. |
| 7158 | */ |
| 7159 | if (!cfgerr) { |
| 7160 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 7161 | if (curproxy->cap & PR_CAP_FE) |
| 7162 | propagate_processes(curproxy, NULL); |
| 7163 | } |
Willy Tarreau | 91b00c2 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 7164 | } |
| 7165 | |
| 7166 | /* Bind each unbound backend to all processes when not specified. */ |
| 7167 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 7168 | if (curproxy->bind_proc) |
| 7169 | continue; |
Willy Tarreau | 01760ad | 2015-05-04 21:57:58 +0200 | [diff] [blame] | 7170 | curproxy->bind_proc = nbits(global.nbproc); |
Willy Tarreau | 91b00c2 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 7171 | } |
| 7172 | |
| 7173 | /*******************************************************/ |
| 7174 | /* At this step, all proxies have a non-null bind_proc */ |
| 7175 | /*******************************************************/ |
| 7176 | |
| 7177 | /* perform the final checks before creating tasks */ |
| 7178 | |
| 7179 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 7180 | struct listener *listener; |
| 7181 | unsigned int next_id; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 7182 | |
Emeric Brun | c52962f | 2012-11-15 18:28:02 +0100 | [diff] [blame] | 7183 | #ifdef USE_OPENSSL |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 7184 | /* Configure SSL for each bind line. |
| 7185 | * Note: if configuration fails at some point, the ->ctx member |
| 7186 | * remains NULL so that listeners can later detach. |
| 7187 | */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7188 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
Emeric Brun | caa19cc | 2014-05-07 16:10:18 +0200 | [diff] [blame] | 7189 | int alloc_ctx; |
| 7190 | |
Emeric Brun | c52962f | 2012-11-15 18:28:02 +0100 | [diff] [blame] | 7191 | if (!bind_conf->is_ssl) { |
| 7192 | if (bind_conf->default_ctx) { |
| 7193 | Warning("Proxy '%s': A certificate was specified but SSL was not enabled on bind '%s' at [%s:%d] (use 'ssl').\n", |
| 7194 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
| 7195 | } |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7196 | continue; |
Emeric Brun | c52962f | 2012-11-15 18:28:02 +0100 | [diff] [blame] | 7197 | } |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7198 | if (!bind_conf->default_ctx) { |
Emeric Brun | fc0421f | 2012-09-07 17:30:07 +0200 | [diff] [blame] | 7199 | 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] | 7200 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 7201 | cfgerr++; |
| 7202 | continue; |
| 7203 | } |
| 7204 | |
Emeric Brun | 8dc6039 | 2014-05-09 13:52:00 +0200 | [diff] [blame] | 7205 | 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] | 7206 | if (alloc_ctx < 0) { |
Emeric Brun | 93ee249 | 2014-05-09 14:01:48 +0200 | [diff] [blame] | 7207 | if (alloc_ctx == SHCTX_E_INIT_LOCK) |
| 7208 | 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"); |
| 7209 | else |
Emeric Brun | caa19cc | 2014-05-07 16:10:18 +0200 | [diff] [blame] | 7210 | Alert("Unable to allocate SSL session cache.\n"); |
Emeric Brun | 93ee249 | 2014-05-09 14:01:48 +0200 | [diff] [blame] | 7211 | cfgerr++; |
| 7212 | continue; |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 7213 | } |
| 7214 | |
Emeric Brun | fc0421f | 2012-09-07 17:30:07 +0200 | [diff] [blame] | 7215 | /* initialize all certificate contexts */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7216 | cfgerr += ssl_sock_prepare_all_ctx(bind_conf, curproxy); |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7217 | } |
Emeric Brun | c52962f | 2012-11-15 18:28:02 +0100 | [diff] [blame] | 7218 | #endif /* USE_OPENSSL */ |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 7219 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 7220 | /* adjust this proxy's listeners */ |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7221 | next_id = 1; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 7222 | list_for_each_entry(listener, &curproxy->conf.listeners, by_fe) { |
Willy Tarreau | 434bc8d | 2016-04-14 11:47:38 +0200 | [diff] [blame] | 7223 | int nbproc; |
| 7224 | |
| 7225 | nbproc = my_popcountl(curproxy->bind_proc & |
Cyril Bonté | c6d173f | 2016-04-15 07:58:43 +0200 | [diff] [blame] | 7226 | (listener->bind_conf->bind_proc ? listener->bind_conf->bind_proc : curproxy->bind_proc) & |
Willy Tarreau | 434bc8d | 2016-04-14 11:47:38 +0200 | [diff] [blame] | 7227 | nbits(global.nbproc)); |
| 7228 | |
| 7229 | if (!nbproc) /* no intersection between listener and frontend */ |
| 7230 | nbproc = 1; |
| 7231 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7232 | if (!listener->luid) { |
| 7233 | /* listener ID not set, use automatic numbering with first |
| 7234 | * spare entry starting with next_luid. |
| 7235 | */ |
| 7236 | next_id = get_next_id(&curproxy->conf.used_listener_id, next_id); |
| 7237 | listener->conf.id.key = listener->luid = next_id; |
| 7238 | eb32_insert(&curproxy->conf.used_listener_id, &listener->conf.id); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7239 | } |
Krzysztof Piotr Oledzki | df5cb9f | 2010-02-05 20:58:27 +0100 | [diff] [blame] | 7240 | next_id++; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7241 | |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 7242 | /* enable separate counters */ |
| 7243 | if (curproxy->options2 & PR_O2_SOCKSTAT) { |
| 7244 | listener->counters = (struct licounters *)calloc(1, sizeof(struct licounters)); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 7245 | if (!listener->name) |
| 7246 | memprintf(&listener->name, "sock-%d", listener->luid); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 7247 | } |
Willy Tarreau | 81796be | 2012-09-22 19:11:47 +0200 | [diff] [blame] | 7248 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 7249 | if (curproxy->options & PR_O_TCP_NOLING) |
| 7250 | listener->options |= LI_O_NOLINGER; |
Willy Tarreau | 32368ce | 2012-09-06 11:10:55 +0200 | [diff] [blame] | 7251 | if (!listener->maxconn) |
| 7252 | listener->maxconn = curproxy->maxconn; |
| 7253 | if (!listener->backlog) |
| 7254 | listener->backlog = curproxy->backlog; |
Willy Tarreau | 16a2147 | 2012-11-19 12:39:59 +0100 | [diff] [blame] | 7255 | if (!listener->maxaccept) |
| 7256 | listener->maxaccept = global.tune.maxaccept ? global.tune.maxaccept : 64; |
| 7257 | |
| 7258 | /* we want to have an optimal behaviour on single process mode to |
| 7259 | * maximize the work at once, but in multi-process we want to keep |
| 7260 | * some fairness between processes, so we target half of the max |
| 7261 | * number of events to be balanced over all the processes the proxy |
| 7262 | * is bound to. Rememeber that maxaccept = -1 must be kept as it is |
| 7263 | * used to disable the limit. |
| 7264 | */ |
| 7265 | if (listener->maxaccept > 0) { |
| 7266 | if (nbproc > 1) |
| 7267 | listener->maxaccept = (listener->maxaccept + 1) / 2; |
| 7268 | listener->maxaccept = (listener->maxaccept + nbproc - 1) / nbproc; |
| 7269 | } |
| 7270 | |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 7271 | listener->timeout = &curproxy->timeout.client; |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 7272 | listener->accept = session_accept; |
Willy Tarreau | 3bc1377 | 2008-12-07 11:50:35 +0100 | [diff] [blame] | 7273 | listener->handler = process_session; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 7274 | listener->analysers |= curproxy->fe_req_ana; |
Willy Tarreau | 3bc1377 | 2008-12-07 11:50:35 +0100 | [diff] [blame] | 7275 | |
Willy Tarreau | a5c0ab2 | 2010-05-31 10:30:33 +0200 | [diff] [blame] | 7276 | if (!LIST_ISEMPTY(&curproxy->tcp_req.l4_rules)) |
| 7277 | listener->options |= LI_O_TCP_RULES; |
| 7278 | |
Willy Tarreau | de3041d | 2010-05-31 10:56:17 +0200 | [diff] [blame] | 7279 | if (curproxy->mon_mask.s_addr) |
| 7280 | listener->options |= LI_O_CHK_MONNET; |
| 7281 | |
Willy Tarreau | 9ea05a7 | 2009-06-14 12:07:01 +0200 | [diff] [blame] | 7282 | /* smart accept mode is automatic in HTTP mode */ |
| 7283 | if ((curproxy->options2 & PR_O2_SMARTACC) || |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7284 | ((curproxy->mode == PR_MODE_HTTP || listener->bind_conf->is_ssl) && |
Willy Tarreau | 9ea05a7 | 2009-06-14 12:07:01 +0200 | [diff] [blame] | 7285 | !(curproxy->no_options2 & PR_O2_SMARTACC))) |
| 7286 | listener->options |= LI_O_NOQUICKACK; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 7287 | } |
| 7288 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7289 | /* Release unused SSL configs */ |
| 7290 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
| 7291 | if (bind_conf->is_ssl) |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 7292 | continue; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7293 | #ifdef USE_OPENSSL |
| 7294 | ssl_sock_free_all_ctx(bind_conf); |
Emeric Brun | fb510ea | 2012-10-05 12:00:26 +0200 | [diff] [blame] | 7295 | free(bind_conf->ca_file); |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7296 | free(bind_conf->ciphers); |
Emeric Brun | 2b58d04 | 2012-09-20 17:10:03 +0200 | [diff] [blame] | 7297 | free(bind_conf->ecdhe); |
Emeric Brun | fb510ea | 2012-10-05 12:00:26 +0200 | [diff] [blame] | 7298 | free(bind_conf->crl_file); |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 7299 | #endif /* USE_OPENSSL */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7300 | } |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 7301 | |
Willy Tarreau | 434bc8d | 2016-04-14 11:47:38 +0200 | [diff] [blame] | 7302 | if (my_popcountl(curproxy->bind_proc & nbits(global.nbproc)) > 1) { |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 7303 | if (curproxy->uri_auth) { |
Willy Tarreau | 036a83e | 2014-09-16 15:11:04 +0200 | [diff] [blame] | 7304 | int count, maxproc = 0; |
| 7305 | |
| 7306 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
David Carlier | 6de4c2f | 2015-07-02 07:00:17 +0000 | [diff] [blame] | 7307 | count = my_popcountl(bind_conf->bind_proc); |
Willy Tarreau | 036a83e | 2014-09-16 15:11:04 +0200 | [diff] [blame] | 7308 | if (count > maxproc) |
| 7309 | maxproc = count; |
| 7310 | } |
| 7311 | /* backends have 0, frontends have 1 or more */ |
| 7312 | if (maxproc != 1) |
| 7313 | Warning("Proxy '%s': in multi-process mode, stats will be" |
| 7314 | " limited to process assigned to the current request.\n", |
| 7315 | curproxy->id); |
| 7316 | |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 7317 | if (!LIST_ISEMPTY(&curproxy->uri_auth->admin_rules)) { |
| 7318 | Warning("Proxy '%s': stats admin will not work correctly in multi-process mode.\n", |
| 7319 | curproxy->id); |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 7320 | } |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 7321 | } |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 7322 | if (curproxy->appsession_name) { |
| 7323 | Warning("Proxy '%s': appsession will not work correctly in multi-process mode.\n", |
| 7324 | curproxy->id); |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 7325 | } |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 7326 | if (!LIST_ISEMPTY(&curproxy->sticking_rules)) { |
| 7327 | Warning("Proxy '%s': sticking rules will not work correctly in multi-process mode.\n", |
| 7328 | curproxy->id); |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 7329 | } |
| 7330 | } |
Willy Tarreau | 918ff60 | 2011-07-25 16:33:49 +0200 | [diff] [blame] | 7331 | |
| 7332 | /* create the task associated with the proxy */ |
| 7333 | curproxy->task = task_new(); |
| 7334 | if (curproxy->task) { |
| 7335 | curproxy->task->context = curproxy; |
| 7336 | curproxy->task->process = manage_proxy; |
| 7337 | /* no need to queue, it will be done automatically if some |
| 7338 | * listener gets limited. |
| 7339 | */ |
| 7340 | curproxy->task->expire = TICK_ETERNITY; |
| 7341 | } else { |
| 7342 | Alert("Proxy '%s': no more memory when trying to allocate the management task\n", |
| 7343 | curproxy->id); |
| 7344 | cfgerr++; |
| 7345 | } |
Willy Tarreau | e56c4f1 | 2014-09-16 13:21:03 +0200 | [diff] [blame] | 7346 | } |
| 7347 | |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 7348 | /* automatically compute fullconn if not set. We must not do it in the |
| 7349 | * loop above because cross-references are not yet fully resolved. |
| 7350 | */ |
| 7351 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 7352 | /* If <fullconn> is not set, let's set it to 10% of the sum of |
| 7353 | * the possible incoming frontend's maxconns. |
| 7354 | */ |
| 7355 | if (!curproxy->fullconn && (curproxy->cap & PR_CAP_BE)) { |
| 7356 | struct proxy *fe; |
| 7357 | int total = 0; |
| 7358 | |
| 7359 | /* sum up the number of maxconns of frontends which |
| 7360 | * reference this backend at least once or which are |
| 7361 | * the same one ('listen'). |
| 7362 | */ |
| 7363 | for (fe = proxy; fe; fe = fe->next) { |
| 7364 | struct switching_rule *rule; |
| 7365 | struct hdr_exp *exp; |
| 7366 | int found = 0; |
| 7367 | |
| 7368 | if (!(fe->cap & PR_CAP_FE)) |
| 7369 | continue; |
| 7370 | |
| 7371 | if (fe == curproxy) /* we're on a "listen" instance */ |
| 7372 | found = 1; |
| 7373 | |
| 7374 | if (fe->defbe.be == curproxy) /* "default_backend" */ |
| 7375 | found = 1; |
| 7376 | |
| 7377 | /* check if a "use_backend" rule matches */ |
| 7378 | if (!found) { |
| 7379 | list_for_each_entry(rule, &fe->switching_rules, list) { |
Bertrand Jacquin | 702d44f | 2013-11-19 11:43:06 +0100 | [diff] [blame] | 7380 | if (!rule->dynamic && rule->be.backend == curproxy) { |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 7381 | found = 1; |
| 7382 | break; |
| 7383 | } |
| 7384 | } |
| 7385 | } |
| 7386 | |
| 7387 | /* check if a "reqsetbe" rule matches */ |
| 7388 | for (exp = fe->req_exp; !found && exp; exp = exp->next) { |
| 7389 | if (exp->action == ACT_SETBE && |
| 7390 | (struct proxy *)exp->replace == curproxy) { |
| 7391 | found = 1; |
| 7392 | break; |
| 7393 | } |
| 7394 | } |
| 7395 | |
| 7396 | /* now we've checked all possible ways to reference a backend |
| 7397 | * from a frontend. |
| 7398 | */ |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 7399 | if (!found) |
| 7400 | continue; |
| 7401 | total += fe->maxconn; |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 7402 | } |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 7403 | /* we have the sum of the maxconns in <total>. We only |
| 7404 | * keep 10% of that sum to set the default fullconn, with |
| 7405 | * a hard minimum of 1 (to avoid a divide by zero). |
| 7406 | */ |
| 7407 | curproxy->fullconn = (total + 9) / 10; |
| 7408 | if (!curproxy->fullconn) |
| 7409 | curproxy->fullconn = 1; |
| 7410 | } |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 7411 | } |
| 7412 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7413 | /* |
| 7414 | * Recount currently required checks. |
| 7415 | */ |
| 7416 | |
| 7417 | for (curproxy=proxy; curproxy; curproxy=curproxy->next) { |
| 7418 | int optnum; |
| 7419 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 7420 | for (optnum = 0; cfg_opts[optnum].name; optnum++) |
| 7421 | if (curproxy->options & cfg_opts[optnum].val) |
| 7422 | global.last_checks |= cfg_opts[optnum].checks; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7423 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 7424 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) |
| 7425 | if (curproxy->options2 & cfg_opts2[optnum].val) |
| 7426 | global.last_checks |= cfg_opts2[optnum].checks; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7427 | } |
| 7428 | |
Willy Tarreau | cdb5e92 | 2015-05-01 19:12:05 +0200 | [diff] [blame] | 7429 | /* compute the required process bindings for the peers */ |
| 7430 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) |
| 7431 | if (curproxy->table.peers.p) |
| 7432 | curproxy->table.peers.p->peers_fe->bind_proc |= curproxy->bind_proc; |
| 7433 | |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 7434 | if (peers) { |
| 7435 | struct peers *curpeers = peers, **last; |
| 7436 | struct peer *p, *pb; |
| 7437 | |
Willy Tarreau | ab0419d | 2015-05-01 19:15:17 +0200 | [diff] [blame] | 7438 | /* Remove all peers sections which don't have a valid listener, |
| 7439 | * which are not used by any table, or which are bound to more |
| 7440 | * than one process. |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 7441 | */ |
| 7442 | last = &peers; |
| 7443 | while (*last) { |
| 7444 | curpeers = *last; |
Willy Tarreau | 34d05b0 | 2015-05-01 20:02:17 +0200 | [diff] [blame] | 7445 | |
| 7446 | if (curpeers->state == PR_STSTOPPED) { |
| 7447 | /* the "disabled" keyword was present */ |
| 7448 | if (curpeers->peers_fe) |
| 7449 | stop_proxy(curpeers->peers_fe); |
| 7450 | curpeers->peers_fe = NULL; |
| 7451 | } |
| 7452 | else if (!curpeers->peers_fe) { |
| 7453 | Warning("Removing incomplete section 'peers %s' (no peer named '%s').\n", |
| 7454 | curpeers->id, localpeer); |
| 7455 | } |
David Carlier | 6de4c2f | 2015-07-02 07:00:17 +0000 | [diff] [blame] | 7456 | else if (my_popcountl(curpeers->peers_fe->bind_proc) != 1) { |
Willy Tarreau | ab0419d | 2015-05-01 19:15:17 +0200 | [diff] [blame] | 7457 | /* either it's totally stopped or too much used */ |
| 7458 | if (curpeers->peers_fe->bind_proc) { |
| 7459 | Alert("Peers section '%s': peers referenced by sections " |
Willy Tarreau | a5d7d07 | 2015-05-04 21:48:51 +0200 | [diff] [blame] | 7460 | "running in different processes (%d different ones). " |
| 7461 | "Check global.nbproc and all tables' bind-process " |
David Carlier | 6de4c2f | 2015-07-02 07:00:17 +0000 | [diff] [blame] | 7462 | "settings.\n", curpeers->id, my_popcountl(curpeers->peers_fe->bind_proc)); |
Willy Tarreau | ab0419d | 2015-05-01 19:15:17 +0200 | [diff] [blame] | 7463 | cfgerr++; |
| 7464 | } |
| 7465 | stop_proxy(curpeers->peers_fe); |
| 7466 | curpeers->peers_fe = NULL; |
| 7467 | } |
Willy Tarreau | 34d05b0 | 2015-05-01 20:02:17 +0200 | [diff] [blame] | 7468 | else { |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 7469 | last = &curpeers->next; |
| 7470 | continue; |
| 7471 | } |
| 7472 | |
Willy Tarreau | 34d05b0 | 2015-05-01 20:02:17 +0200 | [diff] [blame] | 7473 | /* clean what has been detected above */ |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 7474 | p = curpeers->remote; |
| 7475 | while (p) { |
| 7476 | pb = p->next; |
| 7477 | free(p->id); |
| 7478 | free(p); |
| 7479 | p = pb; |
| 7480 | } |
| 7481 | |
| 7482 | /* Destroy and unlink this curpeers section. |
| 7483 | * Note: curpeers is backed up into *last. |
| 7484 | */ |
| 7485 | free(curpeers->id); |
| 7486 | curpeers = curpeers->next; |
| 7487 | free(*last); |
| 7488 | *last = curpeers; |
| 7489 | } |
| 7490 | } |
| 7491 | |
Willy Tarreau | f2df7ef | 2015-05-01 19:09:08 +0200 | [diff] [blame] | 7492 | /* initialize stick-tables on backend capable proxies. This must not |
| 7493 | * be done earlier because the data size may be discovered while parsing |
| 7494 | * other proxies. |
| 7495 | */ |
| 7496 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 7497 | if (curproxy->state == PR_STSTOPPED) |
| 7498 | continue; |
| 7499 | |
| 7500 | if (!stktable_init(&curproxy->table)) { |
| 7501 | Alert("Proxy '%s': failed to initialize stick-table.\n", curproxy->id); |
| 7502 | cfgerr++; |
| 7503 | } |
| 7504 | } |
| 7505 | |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 7506 | pool2_hdr_idx = create_pool("hdr_idx", |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame] | 7507 | global.tune.max_http_hdr * sizeof(struct hdr_idx_elem), |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 7508 | MEM_F_SHARED); |
| 7509 | |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 7510 | if (cfgerr > 0) |
| 7511 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7512 | out: |
| 7513 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7514 | } |
| 7515 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 7516 | /* |
| 7517 | * Registers the CFG keyword list <kwl> as a list of valid keywords for next |
| 7518 | * parsing sessions. |
| 7519 | */ |
| 7520 | void cfg_register_keywords(struct cfg_kw_list *kwl) |
| 7521 | { |
| 7522 | LIST_ADDQ(&cfg_keywords.list, &kwl->list); |
| 7523 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7524 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 7525 | /* |
| 7526 | * Unregisters the CFG keyword list <kwl> from the list of valid keywords. |
| 7527 | */ |
| 7528 | void cfg_unregister_keywords(struct cfg_kw_list *kwl) |
| 7529 | { |
| 7530 | LIST_DEL(&kwl->list); |
| 7531 | LIST_INIT(&kwl->list); |
| 7532 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7533 | |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 7534 | /* this function register new section in the haproxy configuration file. |
| 7535 | * <section_name> is the name of this new section and <section_parser> |
| 7536 | * is the called parser. If two section declaration have the same name, |
| 7537 | * only the first declared is used. |
| 7538 | */ |
| 7539 | int cfg_register_section(char *section_name, |
| 7540 | int (*section_parser)(const char *, int, char **, int)) |
| 7541 | { |
| 7542 | struct cfg_section *cs; |
| 7543 | |
| 7544 | cs = calloc(1, sizeof(*cs)); |
| 7545 | if (!cs) { |
| 7546 | Alert("register section '%s': out of memory.\n", section_name); |
| 7547 | return 0; |
| 7548 | } |
| 7549 | |
| 7550 | cs->section_name = section_name; |
| 7551 | cs->section_parser = section_parser; |
| 7552 | |
| 7553 | LIST_ADDQ(§ions, &cs->list); |
| 7554 | |
| 7555 | return 1; |
| 7556 | } |
| 7557 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7558 | /* |
| 7559 | * Local variables: |
| 7560 | * c-indent-level: 8 |
| 7561 | * c-basic-offset: 8 |
| 7562 | * End: |
| 7563 | */ |