Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Configuration parser |
| 3 | * |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 4 | * Copyright 2000-2011 Willy Tarreau <w@1wt.eu> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * as published by the Free Software Foundation; either version |
| 9 | * 2 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | */ |
| 12 | |
Cyril Bonté | 1a0191d | 2014-08-29 20:20:02 +0200 | [diff] [blame] | 13 | #ifdef CONFIG_HAP_CRYPT |
| 14 | /* This is to have crypt() defined on Linux */ |
| 15 | #define _GNU_SOURCE |
| 16 | |
| 17 | #ifdef NEED_CRYPT_H |
| 18 | /* some platforms such as Solaris need this */ |
| 19 | #include <crypt.h> |
| 20 | #endif |
| 21 | #endif /* CONFIG_HAP_CRYPT */ |
| 22 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 23 | #include <stdio.h> |
| 24 | #include <stdlib.h> |
| 25 | #include <string.h> |
| 26 | #include <netdb.h> |
| 27 | #include <ctype.h> |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 28 | #include <pwd.h> |
| 29 | #include <grp.h> |
Willy Tarreau | 0b4ed90 | 2007-03-26 00:18:40 +0200 | [diff] [blame] | 30 | #include <errno.h> |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 31 | #include <sys/types.h> |
| 32 | #include <sys/stat.h> |
| 33 | #include <fcntl.h> |
| 34 | #include <unistd.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 35 | |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 36 | #include <common/cfgparse.h> |
Willy Tarreau | c7e4238 | 2012-08-24 19:22:53 +0200 | [diff] [blame] | 37 | #include <common/chunk.h> |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 38 | #include <common/config.h> |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 39 | #include <common/errors.h> |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 40 | #include <common/memory.h> |
| 41 | #include <common/standard.h> |
| 42 | #include <common/time.h> |
| 43 | #include <common/uri_auth.h> |
KOVACS Krisztian | b3e54fe | 2014-11-17 15:11:45 +0100 | [diff] [blame] | 44 | #include <common/namespace.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 45 | |
| 46 | #include <types/capture.h> |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 47 | #include <types/compression.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 48 | #include <types/global.h> |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 49 | #include <types/obj_type.h> |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 50 | #include <types/peers.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 51 | |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 52 | #include <proto/acl.h> |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 53 | #include <proto/auth.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 54 | #include <proto/backend.h> |
Willy Tarreau | c7e4238 | 2012-08-24 19:22:53 +0200 | [diff] [blame] | 55 | #include <proto/channel.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 56 | #include <proto/checks.h> |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 57 | #include <proto/compression.h> |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 58 | #include <proto/dumpstats.h> |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 59 | #include <proto/frontend.h> |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 60 | #include <proto/hdr_idx.h> |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 61 | #include <proto/lb_chash.h> |
Willy Tarreau | f09c660 | 2012-02-13 17:12:08 +0100 | [diff] [blame] | 62 | #include <proto/lb_fas.h> |
Willy Tarreau | f89c187 | 2009-10-01 11:19:37 +0200 | [diff] [blame] | 63 | #include <proto/lb_fwlc.h> |
| 64 | #include <proto/lb_fwrr.h> |
| 65 | #include <proto/lb_map.h> |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 66 | #include <proto/listener.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 67 | #include <proto/log.h> |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 68 | #include <proto/protocol.h> |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 69 | #include <proto/proto_tcp.h> |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 70 | #include <proto/proto_uxst.h> |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 71 | #include <proto/proto_http.h> |
Willy Tarreau | 2b5652f | 2006-12-31 17:46:05 +0100 | [diff] [blame] | 72 | #include <proto/proxy.h> |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 73 | #include <proto/peers.h> |
Willy Tarreau | cd3b094 | 2012-04-27 21:52:18 +0200 | [diff] [blame] | 74 | #include <proto/sample.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 75 | #include <proto/server.h> |
Willy Tarreau | 3bc1377 | 2008-12-07 11:50:35 +0100 | [diff] [blame] | 76 | #include <proto/session.h> |
Willy Tarreau | 75bf2c9 | 2012-08-20 17:01:35 +0200 | [diff] [blame] | 77 | #include <proto/raw_sock.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 78 | #include <proto/task.h> |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 79 | #include <proto/stick_table.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 80 | |
Emeric Brun | fc0421f | 2012-09-07 17:30:07 +0200 | [diff] [blame] | 81 | #ifdef USE_OPENSSL |
| 82 | #include <types/ssl_sock.h> |
| 83 | #include <proto/ssl_sock.h> |
| 84 | #include <proto/shctx.h> |
| 85 | #endif /*USE_OPENSSL */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 86 | |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 87 | /* This is the SSLv3 CLIENT HELLO packet used in conjunction with the |
| 88 | * ssl-hello-chk option to ensure that the remote server speaks SSL. |
| 89 | * |
| 90 | * Check RFC 2246 (TLSv1.0) sections A.3 and A.4 for details. |
| 91 | */ |
| 92 | const char sslv3_client_hello_pkt[] = { |
| 93 | "\x16" /* ContentType : 0x16 = Hanshake */ |
| 94 | "\x03\x00" /* ProtocolVersion : 0x0300 = SSLv3 */ |
| 95 | "\x00\x79" /* ContentLength : 0x79 bytes after this one */ |
| 96 | "\x01" /* HanshakeType : 0x01 = CLIENT HELLO */ |
| 97 | "\x00\x00\x75" /* HandshakeLength : 0x75 bytes after this one */ |
| 98 | "\x03\x00" /* Hello Version : 0x0300 = v3 */ |
| 99 | "\x00\x00\x00\x00" /* Unix GMT Time (s) : filled with <now> (@0x0B) */ |
| 100 | "HAPROXYSSLCHK\nHAPROXYSSLCHK\n" /* Random : must be exactly 28 bytes */ |
| 101 | "\x00" /* Session ID length : empty (no session ID) */ |
| 102 | "\x00\x4E" /* Cipher Suite Length : 78 bytes after this one */ |
| 103 | "\x00\x01" "\x00\x02" "\x00\x03" "\x00\x04" /* 39 most common ciphers : */ |
| 104 | "\x00\x05" "\x00\x06" "\x00\x07" "\x00\x08" /* 0x01...0x1B, 0x2F...0x3A */ |
| 105 | "\x00\x09" "\x00\x0A" "\x00\x0B" "\x00\x0C" /* This covers RSA/DH, */ |
| 106 | "\x00\x0D" "\x00\x0E" "\x00\x0F" "\x00\x10" /* various bit lengths, */ |
| 107 | "\x00\x11" "\x00\x12" "\x00\x13" "\x00\x14" /* SHA1/MD5, DES/3DES/AES... */ |
| 108 | "\x00\x15" "\x00\x16" "\x00\x17" "\x00\x18" |
| 109 | "\x00\x19" "\x00\x1A" "\x00\x1B" "\x00\x2F" |
| 110 | "\x00\x30" "\x00\x31" "\x00\x32" "\x00\x33" |
| 111 | "\x00\x34" "\x00\x35" "\x00\x36" "\x00\x37" |
| 112 | "\x00\x38" "\x00\x39" "\x00\x3A" |
| 113 | "\x01" /* Compression Length : 0x01 = 1 byte for types */ |
| 114 | "\x00" /* Compression Type : 0x00 = NULL compression */ |
| 115 | }; |
| 116 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 117 | /* various keyword modifiers */ |
| 118 | enum kw_mod { |
| 119 | KWM_STD = 0, /* normal */ |
| 120 | KWM_NO, /* "no" prefixed before the keyword */ |
| 121 | KWM_DEF, /* "default" prefixed before the keyword */ |
| 122 | }; |
| 123 | |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 124 | /* permit to store configuration section */ |
| 125 | struct cfg_section { |
| 126 | struct list list; |
| 127 | char *section_name; |
| 128 | int (*section_parser)(const char *, int, char **, int); |
| 129 | }; |
| 130 | |
| 131 | /* Used to chain configuration sections definitions. This list |
| 132 | * stores struct cfg_section |
| 133 | */ |
| 134 | struct list sections = LIST_HEAD_INIT(sections); |
| 135 | |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 136 | /* 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] | 137 | struct cfg_opt { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 138 | const char *name; |
| 139 | unsigned int val; |
| 140 | unsigned int cap; |
Willy Tarreau | 4fee4e9 | 2007-01-06 21:09:17 +0100 | [diff] [blame] | 141 | unsigned int checks; |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 142 | unsigned int mode; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 143 | }; |
| 144 | |
| 145 | /* proxy->options */ |
| 146 | static const struct cfg_opt cfg_opts[] = |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 147 | { |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 148 | { "abortonclose", PR_O_ABRT_CLOSE, PR_CAP_BE, 0, 0 }, |
| 149 | { "allbackups", PR_O_USE_ALL_BK, PR_CAP_BE, 0, 0 }, |
| 150 | { "checkcache", PR_O_CHK_CACHE, PR_CAP_BE, 0, PR_MODE_HTTP }, |
| 151 | { "clitcpka", PR_O_TCP_CLI_KA, PR_CAP_FE, 0, 0 }, |
| 152 | { "contstats", PR_O_CONTSTATS, PR_CAP_FE, 0, 0 }, |
| 153 | { "dontlognull", PR_O_NULLNOLOG, PR_CAP_FE, 0, 0 }, |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 154 | { "http_proxy", PR_O_HTTP_PROXY, PR_CAP_FE | PR_CAP_BE, 0, PR_MODE_HTTP }, |
Willy Tarreau | 9420b12 | 2013-12-15 18:58:25 +0100 | [diff] [blame] | 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 */ |
| 283 | ss = *ss2; |
| 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; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 294 | l->addr = 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 | 3986b9c | 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 | 3986b9c | 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 | 33cb065 | 2014-12-23 22:52:37 +0100 | [diff] [blame] | 699 | else if (!strcmp(args[0], "tune.buffers.limit")) { |
| 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.buf_limit = atol(args[1]); |
| 706 | if (global.tune.buf_limit) { |
| 707 | if (global.tune.buf_limit < 3) |
| 708 | global.tune.buf_limit = 3; |
| 709 | if (global.tune.buf_limit <= global.tune.reserved_bufs) |
| 710 | global.tune.buf_limit = global.tune.reserved_bufs + 1; |
| 711 | } |
| 712 | } |
Willy Tarreau | 1058ae7 | 2014-12-23 22:40:40 +0100 | [diff] [blame] | 713 | else if (!strcmp(args[0], "tune.buffers.reserve")) { |
| 714 | if (*(args[1]) == 0) { |
| 715 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 716 | err_code |= ERR_ALERT | ERR_FATAL; |
| 717 | goto out; |
| 718 | } |
| 719 | global.tune.reserved_bufs = atol(args[1]); |
| 720 | if (global.tune.reserved_bufs < 2) |
| 721 | global.tune.reserved_bufs = 2; |
Willy Tarreau | 33cb065 | 2014-12-23 22:52:37 +0100 | [diff] [blame] | 722 | if (global.tune.buf_limit && global.tune.buf_limit <= global.tune.reserved_bufs) |
| 723 | global.tune.buf_limit = global.tune.reserved_bufs + 1; |
Willy Tarreau | 1058ae7 | 2014-12-23 22:40:40 +0100 | [diff] [blame] | 724 | } |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 725 | else if (!strcmp(args[0], "tune.bufsize")) { |
| 726 | if (*(args[1]) == 0) { |
| 727 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 728 | err_code |= ERR_ALERT | ERR_FATAL; |
| 729 | goto out; |
| 730 | } |
| 731 | global.tune.bufsize = atol(args[1]); |
| 732 | if (global.tune.maxrewrite >= global.tune.bufsize / 2) |
| 733 | global.tune.maxrewrite = global.tune.bufsize / 2; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 734 | chunk_init(&trash, realloc(trash.str, global.tune.bufsize), global.tune.bufsize); |
Willy Tarreau | 2819e99 | 2013-12-13 14:41:10 +0100 | [diff] [blame] | 735 | alloc_trash_buffers(global.tune.bufsize); |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 736 | } |
| 737 | else if (!strcmp(args[0], "tune.maxrewrite")) { |
| 738 | if (*(args[1]) == 0) { |
| 739 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 740 | err_code |= ERR_ALERT | ERR_FATAL; |
| 741 | goto out; |
| 742 | } |
| 743 | global.tune.maxrewrite = atol(args[1]); |
| 744 | if (global.tune.maxrewrite >= global.tune.bufsize / 2) |
| 745 | global.tune.maxrewrite = global.tune.bufsize / 2; |
| 746 | } |
Willy Tarreau | 7e31273 | 2014-02-12 16:35:14 +0100 | [diff] [blame] | 747 | else if (!strcmp(args[0], "tune.idletimer")) { |
| 748 | unsigned int idle; |
| 749 | const char *res; |
| 750 | |
| 751 | if (*(args[1]) == 0) { |
| 752 | Alert("parsing [%s:%d] : '%s' expects a timer value between 0 and 65535 ms.\n", file, linenum, args[0]); |
| 753 | err_code |= ERR_ALERT | ERR_FATAL; |
| 754 | goto out; |
| 755 | } |
| 756 | |
| 757 | res = parse_time_err(args[1], &idle, TIME_UNIT_MS); |
| 758 | if (res) { |
| 759 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 760 | file, linenum, *res, args[0]); |
| 761 | err_code |= ERR_ALERT | ERR_FATAL; |
| 762 | goto out; |
| 763 | } |
| 764 | |
| 765 | if (idle > 65535) { |
| 766 | Alert("parsing [%s:%d] : '%s' expects a timer value between 0 and 65535 ms.\n", file, linenum, args[0]); |
| 767 | err_code |= ERR_ALERT | ERR_FATAL; |
| 768 | goto out; |
| 769 | } |
| 770 | global.tune.idle_timer = idle; |
| 771 | } |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 772 | else if (!strcmp(args[0], "tune.rcvbuf.client")) { |
| 773 | if (global.tune.client_rcvbuf != 0) { |
| 774 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 775 | err_code |= ERR_ALERT; |
| 776 | goto out; |
| 777 | } |
| 778 | if (*(args[1]) == 0) { |
| 779 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 780 | err_code |= ERR_ALERT | ERR_FATAL; |
| 781 | goto out; |
| 782 | } |
| 783 | global.tune.client_rcvbuf = atol(args[1]); |
| 784 | } |
| 785 | else if (!strcmp(args[0], "tune.rcvbuf.server")) { |
| 786 | if (global.tune.server_rcvbuf != 0) { |
| 787 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 788 | err_code |= ERR_ALERT; |
| 789 | goto out; |
| 790 | } |
| 791 | if (*(args[1]) == 0) { |
| 792 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 793 | err_code |= ERR_ALERT | ERR_FATAL; |
| 794 | goto out; |
| 795 | } |
| 796 | global.tune.server_rcvbuf = atol(args[1]); |
| 797 | } |
| 798 | else if (!strcmp(args[0], "tune.sndbuf.client")) { |
| 799 | if (global.tune.client_sndbuf != 0) { |
| 800 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 801 | err_code |= ERR_ALERT; |
| 802 | goto out; |
| 803 | } |
| 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.client_sndbuf = atol(args[1]); |
| 810 | } |
| 811 | else if (!strcmp(args[0], "tune.sndbuf.server")) { |
| 812 | if (global.tune.server_sndbuf != 0) { |
| 813 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 814 | err_code |= ERR_ALERT; |
| 815 | goto out; |
| 816 | } |
| 817 | if (*(args[1]) == 0) { |
| 818 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 819 | err_code |= ERR_ALERT | ERR_FATAL; |
| 820 | goto out; |
| 821 | } |
| 822 | global.tune.server_sndbuf = atol(args[1]); |
| 823 | } |
Willy Tarreau | bd9a0a7 | 2011-10-23 21:14:29 +0200 | [diff] [blame] | 824 | else if (!strcmp(args[0], "tune.pipesize")) { |
| 825 | if (*(args[1]) == 0) { |
| 826 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 827 | err_code |= ERR_ALERT | ERR_FATAL; |
| 828 | goto out; |
| 829 | } |
| 830 | global.tune.pipesize = atol(args[1]); |
| 831 | } |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 832 | else if (!strcmp(args[0], "tune.http.cookielen")) { |
| 833 | if (*(args[1]) == 0) { |
| 834 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 835 | err_code |= ERR_ALERT | ERR_FATAL; |
| 836 | goto out; |
| 837 | } |
| 838 | global.tune.cookie_len = atol(args[1]) + 1; |
| 839 | } |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame] | 840 | else if (!strcmp(args[0], "tune.http.maxhdr")) { |
| 841 | if (*(args[1]) == 0) { |
| 842 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 843 | err_code |= ERR_ALERT | ERR_FATAL; |
| 844 | goto out; |
| 845 | } |
| 846 | global.tune.max_http_hdr = atol(args[1]); |
| 847 | } |
William Lallemand | a509e4c | 2012-11-07 16:54:34 +0100 | [diff] [blame] | 848 | else if (!strcmp(args[0], "tune.zlib.memlevel")) { |
| 849 | #ifdef USE_ZLIB |
| 850 | if (*args[1]) { |
| 851 | global.tune.zlibmemlevel = atoi(args[1]); |
| 852 | if (global.tune.zlibmemlevel < 1 || global.tune.zlibmemlevel > 9) { |
| 853 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n", |
| 854 | file, linenum, args[0]); |
| 855 | err_code |= ERR_ALERT | ERR_FATAL; |
| 856 | goto out; |
| 857 | } |
| 858 | } else { |
| 859 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n", |
| 860 | file, linenum, args[0]); |
| 861 | err_code |= ERR_ALERT | ERR_FATAL; |
| 862 | goto out; |
| 863 | } |
| 864 | #else |
| 865 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 866 | err_code |= ERR_ALERT | ERR_FATAL; |
| 867 | goto out; |
| 868 | #endif |
| 869 | } |
| 870 | else if (!strcmp(args[0], "tune.zlib.windowsize")) { |
| 871 | #ifdef USE_ZLIB |
| 872 | if (*args[1]) { |
| 873 | global.tune.zlibwindowsize = atoi(args[1]); |
| 874 | if (global.tune.zlibwindowsize < 8 || global.tune.zlibwindowsize > 15) { |
| 875 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 8 and 15\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 8 and 15\n", |
| 882 | file, linenum, args[0]); |
| 883 | err_code |= ERR_ALERT | ERR_FATAL; |
| 884 | goto out; |
| 885 | } |
| 886 | #else |
| 887 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 888 | err_code |= ERR_ALERT | ERR_FATAL; |
| 889 | goto out; |
| 890 | #endif |
| 891 | } |
William Lallemand | f374783 | 2012-11-09 12:33:10 +0100 | [diff] [blame] | 892 | else if (!strcmp(args[0], "tune.comp.maxlevel")) { |
| 893 | if (*args[1]) { |
| 894 | global.tune.comp_maxlevel = atoi(args[1]); |
| 895 | if (global.tune.comp_maxlevel < 1 || global.tune.comp_maxlevel > 9) { |
| 896 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n", |
| 897 | file, linenum, args[0]); |
| 898 | err_code |= ERR_ALERT | ERR_FATAL; |
| 899 | goto out; |
| 900 | } |
| 901 | } else { |
| 902 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n", |
| 903 | file, linenum, args[0]); |
| 904 | err_code |= ERR_ALERT | ERR_FATAL; |
| 905 | goto out; |
| 906 | } |
| 907 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 908 | else if (!strcmp(args[0], "uid")) { |
| 909 | if (global.uid != 0) { |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 910 | Alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 911 | err_code |= ERR_ALERT; |
| 912 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 913 | } |
| 914 | if (*(args[1]) == 0) { |
| 915 | 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] | 916 | err_code |= ERR_ALERT | ERR_FATAL; |
| 917 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 918 | } |
| 919 | global.uid = atol(args[1]); |
| 920 | } |
| 921 | else if (!strcmp(args[0], "gid")) { |
| 922 | if (global.gid != 0) { |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 923 | Alert("parsing [%s:%d] : group/gid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 924 | err_code |= ERR_ALERT; |
| 925 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 926 | } |
| 927 | if (*(args[1]) == 0) { |
| 928 | 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] | 929 | err_code |= ERR_ALERT | ERR_FATAL; |
| 930 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 931 | } |
| 932 | global.gid = atol(args[1]); |
| 933 | } |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 934 | else if (!strcmp(args[0], "external-check")) { |
| 935 | global.external_check = 1; |
| 936 | } |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 937 | /* user/group name handling */ |
| 938 | else if (!strcmp(args[0], "user")) { |
| 939 | struct passwd *ha_user; |
| 940 | if (global.uid != 0) { |
| 941 | Alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 942 | err_code |= ERR_ALERT; |
| 943 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 944 | } |
| 945 | errno = 0; |
| 946 | ha_user = getpwnam(args[1]); |
| 947 | if (ha_user != NULL) { |
| 948 | global.uid = (int)ha_user->pw_uid; |
| 949 | } |
| 950 | else { |
| 951 | 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] | 952 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 953 | } |
| 954 | } |
| 955 | else if (!strcmp(args[0], "group")) { |
| 956 | struct group *ha_group; |
| 957 | if (global.gid != 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 958 | 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] | 959 | err_code |= ERR_ALERT; |
| 960 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 961 | } |
| 962 | errno = 0; |
| 963 | ha_group = getgrnam(args[1]); |
| 964 | if (ha_group != NULL) { |
| 965 | global.gid = (int)ha_group->gr_gid; |
| 966 | } |
| 967 | else { |
| 968 | 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] | 969 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 970 | } |
| 971 | } |
| 972 | /* end of user/group name handling*/ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 973 | else if (!strcmp(args[0], "nbproc")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 974 | if (*(args[1]) == 0) { |
| 975 | 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] | 976 | err_code |= ERR_ALERT | ERR_FATAL; |
| 977 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 978 | } |
| 979 | global.nbproc = atol(args[1]); |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 980 | if (global.nbproc < 1 || global.nbproc > LONGBITS) { |
| 981 | Alert("parsing [%s:%d] : '%s' must be between 1 and %d (was %d).\n", |
| 982 | file, linenum, args[0], LONGBITS, global.nbproc); |
| 983 | err_code |= ERR_ALERT | ERR_FATAL; |
| 984 | goto out; |
| 985 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 986 | } |
| 987 | else if (!strcmp(args[0], "maxconn")) { |
| 988 | if (global.maxconn != 0) { |
| 989 | 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] | 990 | err_code |= ERR_ALERT; |
| 991 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 992 | } |
| 993 | if (*(args[1]) == 0) { |
| 994 | 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] | 995 | err_code |= ERR_ALERT | ERR_FATAL; |
| 996 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 997 | } |
| 998 | global.maxconn = atol(args[1]); |
| 999 | #ifdef SYSTEM_MAXCONN |
| 1000 | if (global.maxconn > DEFAULT_MAXCONN && cfg_maxconn <= DEFAULT_MAXCONN) { |
| 1001 | 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); |
| 1002 | global.maxconn = DEFAULT_MAXCONN; |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1003 | err_code |= ERR_ALERT; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1004 | } |
| 1005 | #endif /* SYSTEM_MAXCONN */ |
| 1006 | } |
Willy Tarreau | 403edff | 2012-09-06 11:58:37 +0200 | [diff] [blame] | 1007 | else if (!strcmp(args[0], "maxsslconn")) { |
| 1008 | #ifdef USE_OPENSSL |
| 1009 | if (*(args[1]) == 0) { |
| 1010 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1011 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1012 | goto out; |
| 1013 | } |
| 1014 | global.maxsslconn = atol(args[1]); |
| 1015 | #else |
Emeric Brun | 0914df8 | 2012-10-02 18:45:42 +0200 | [diff] [blame] | 1016 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 1017 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1018 | goto out; |
Willy Tarreau | 403edff | 2012-09-06 11:58:37 +0200 | [diff] [blame] | 1019 | #endif |
| 1020 | } |
Willy Tarreau | 610f04b | 2014-02-13 11:36:41 +0100 | [diff] [blame] | 1021 | else if (!strcmp(args[0], "ssl-default-bind-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.listen_default_ciphers); |
| 1029 | global.listen_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 | } |
| 1036 | else if (!strcmp(args[0], "ssl-default-server-ciphers")) { |
| 1037 | #ifdef USE_OPENSSL |
| 1038 | if (*(args[1]) == 0) { |
| 1039 | Alert("parsing [%s:%d] : '%s' expects a cipher suite as an argument.\n", file, linenum, args[0]); |
| 1040 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1041 | goto out; |
| 1042 | } |
| 1043 | free(global.connect_default_ciphers); |
| 1044 | global.connect_default_ciphers = strdup(args[1]); |
| 1045 | #else |
| 1046 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 1047 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1048 | goto out; |
| 1049 | #endif |
| 1050 | } |
Emeric Brun | 850efd5 | 2014-01-29 12:24:34 +0100 | [diff] [blame] | 1051 | else if (!strcmp(args[0], "ssl-server-verify")) { |
| 1052 | if (*(args[1]) == 0) { |
| 1053 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1054 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1055 | goto out; |
| 1056 | } |
| 1057 | if (strcmp(args[1],"none") == 0) |
| 1058 | global.ssl_server_verify = SSL_SERVER_VERIFY_NONE; |
| 1059 | else if (strcmp(args[1],"required") == 0) |
| 1060 | global.ssl_server_verify = SSL_SERVER_VERIFY_REQUIRED; |
| 1061 | else { |
| 1062 | Alert("parsing [%s:%d] : '%s' expects 'none' or 'required' as argument.\n", file, linenum, args[0]); |
| 1063 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1064 | goto out; |
| 1065 | } |
| 1066 | } |
Willy Tarreau | 81c25d0 | 2011-09-07 15:17:21 +0200 | [diff] [blame] | 1067 | else if (!strcmp(args[0], "maxconnrate")) { |
| 1068 | if (global.cps_lim != 0) { |
| 1069 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 1070 | err_code |= ERR_ALERT; |
| 1071 | goto out; |
| 1072 | } |
| 1073 | if (*(args[1]) == 0) { |
| 1074 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1075 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1076 | goto out; |
| 1077 | } |
| 1078 | global.cps_lim = atol(args[1]); |
| 1079 | } |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1080 | else if (!strcmp(args[0], "maxsessrate")) { |
| 1081 | if (global.sps_lim != 0) { |
| 1082 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 1083 | err_code |= ERR_ALERT; |
| 1084 | goto out; |
| 1085 | } |
| 1086 | if (*(args[1]) == 0) { |
| 1087 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1088 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1089 | goto out; |
| 1090 | } |
| 1091 | global.sps_lim = atol(args[1]); |
| 1092 | } |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 1093 | else if (!strcmp(args[0], "maxsslrate")) { |
| 1094 | if (global.ssl_lim != 0) { |
| 1095 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 1096 | err_code |= ERR_ALERT; |
| 1097 | goto out; |
| 1098 | } |
| 1099 | if (*(args[1]) == 0) { |
| 1100 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1101 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1102 | goto out; |
| 1103 | } |
| 1104 | global.ssl_lim = atol(args[1]); |
| 1105 | } |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1106 | else if (!strcmp(args[0], "maxcomprate")) { |
| 1107 | if (*(args[1]) == 0) { |
| 1108 | Alert("parsing [%s:%d] : '%s' expects an integer argument in kb/s.\n", file, linenum, args[0]); |
| 1109 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1110 | goto out; |
| 1111 | } |
| 1112 | global.comp_rate_lim = atoi(args[1]) * 1024; |
| 1113 | } |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 1114 | else if (!strcmp(args[0], "maxpipes")) { |
| 1115 | if (global.maxpipes != 0) { |
| 1116 | 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] | 1117 | err_code |= ERR_ALERT; |
| 1118 | goto out; |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 1119 | } |
| 1120 | if (*(args[1]) == 0) { |
| 1121 | 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] | 1122 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1123 | goto out; |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 1124 | } |
| 1125 | global.maxpipes = atol(args[1]); |
| 1126 | } |
William Lallemand | 9d5f548 | 2012-11-07 16:12:57 +0100 | [diff] [blame] | 1127 | else if (!strcmp(args[0], "maxzlibmem")) { |
| 1128 | if (*(args[1]) == 0) { |
| 1129 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1130 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1131 | goto out; |
| 1132 | } |
William Lallemand | e3a7d99 | 2012-11-20 11:25:20 +0100 | [diff] [blame] | 1133 | global.maxzlibmem = atol(args[1]) * 1024L * 1024L; |
William Lallemand | 9d5f548 | 2012-11-07 16:12:57 +0100 | [diff] [blame] | 1134 | } |
William Lallemand | 072a2bf | 2012-11-20 17:01:01 +0100 | [diff] [blame] | 1135 | else if (!strcmp(args[0], "maxcompcpuusage")) { |
| 1136 | if (*(args[1]) == 0) { |
| 1137 | Alert("parsing [%s:%d] : '%s' expects an integer argument between 0 and 100.\n", file, linenum, args[0]); |
| 1138 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1139 | goto out; |
| 1140 | } |
| 1141 | compress_min_idle = 100 - atoi(args[1]); |
Willy Tarreau | cb2699a | 2013-01-24 16:25:38 +0100 | [diff] [blame] | 1142 | if (compress_min_idle > 100) { |
William Lallemand | 072a2bf | 2012-11-20 17:01:01 +0100 | [diff] [blame] | 1143 | Alert("parsing [%s:%d] : '%s' expects an integer argument between 0 and 100.\n", file, linenum, args[0]); |
| 1144 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1145 | goto out; |
| 1146 | } |
| 1147 | } |
| 1148 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1149 | else if (!strcmp(args[0], "ulimit-n")) { |
| 1150 | if (global.rlimit_nofile != 0) { |
| 1151 | 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] | 1152 | err_code |= ERR_ALERT; |
| 1153 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1154 | } |
| 1155 | if (*(args[1]) == 0) { |
| 1156 | 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] | 1157 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1158 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1159 | } |
| 1160 | global.rlimit_nofile = atol(args[1]); |
| 1161 | } |
| 1162 | else if (!strcmp(args[0], "chroot")) { |
| 1163 | if (global.chroot != NULL) { |
| 1164 | 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] | 1165 | err_code |= ERR_ALERT; |
| 1166 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1167 | } |
| 1168 | if (*(args[1]) == 0) { |
| 1169 | 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] | 1170 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1171 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1172 | } |
| 1173 | global.chroot = strdup(args[1]); |
| 1174 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1175 | else if (!strcmp(args[0], "description")) { |
| 1176 | int i, len=0; |
| 1177 | char *d; |
| 1178 | |
| 1179 | if (!*args[1]) { |
| 1180 | Alert("parsing [%s:%d]: '%s' expects a string argument.\n", |
| 1181 | file, linenum, args[0]); |
| 1182 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1183 | goto out; |
| 1184 | } |
| 1185 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 1186 | for (i = 1; *args[i]; i++) |
| 1187 | len += strlen(args[i]) + 1; |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1188 | |
| 1189 | if (global.desc) |
| 1190 | free(global.desc); |
| 1191 | |
| 1192 | global.desc = d = (char *)calloc(1, len); |
| 1193 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 1194 | d += snprintf(d, global.desc + len - d, "%s", args[1]); |
| 1195 | for (i = 2; *args[i]; i++) |
| 1196 | d += snprintf(d, global.desc + len - d, " %s", args[i]); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1197 | } |
| 1198 | else if (!strcmp(args[0], "node")) { |
| 1199 | int i; |
| 1200 | char c; |
| 1201 | |
| 1202 | for (i=0; args[1][i]; i++) { |
| 1203 | c = args[1][i]; |
Willy Tarreau | 88e0581 | 2010-03-03 00:16:00 +0100 | [diff] [blame] | 1204 | if (!isupper((unsigned char)c) && !islower((unsigned char)c) && |
| 1205 | !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.') |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1206 | break; |
| 1207 | } |
| 1208 | |
| 1209 | if (!i || args[1][i]) { |
| 1210 | Alert("parsing [%s:%d]: '%s' requires valid node name - non-empty string" |
| 1211 | " with digits(0-9), letters(A-Z, a-z), dot(.), hyphen(-) or underscode(_).\n", |
| 1212 | file, linenum, args[0]); |
| 1213 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1214 | goto out; |
| 1215 | } |
| 1216 | |
| 1217 | if (global.node) |
| 1218 | free(global.node); |
| 1219 | |
| 1220 | global.node = strdup(args[1]); |
| 1221 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1222 | else if (!strcmp(args[0], "pidfile")) { |
| 1223 | if (global.pidfile != NULL) { |
| 1224 | 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] | 1225 | err_code |= ERR_ALERT; |
| 1226 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1227 | } |
| 1228 | if (*(args[1]) == 0) { |
| 1229 | 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] | 1230 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1231 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1232 | } |
| 1233 | global.pidfile = strdup(args[1]); |
| 1234 | } |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 1235 | else if (!strcmp(args[0], "unix-bind")) { |
| 1236 | int cur_arg = 1; |
| 1237 | while (*(args[cur_arg])) { |
| 1238 | if (!strcmp(args[cur_arg], "prefix")) { |
| 1239 | if (global.unix_bind.prefix != NULL) { |
| 1240 | Alert("parsing [%s:%d] : unix-bind '%s' already specified. Continuing.\n", file, linenum, args[cur_arg]); |
| 1241 | err_code |= ERR_ALERT; |
| 1242 | cur_arg += 2; |
| 1243 | continue; |
| 1244 | } |
| 1245 | |
| 1246 | if (*(args[cur_arg+1]) == 0) { |
| 1247 | Alert("parsing [%s:%d] : unix_bind '%s' expects a path as an argument.\n", file, linenum, args[cur_arg]); |
| 1248 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1249 | goto out; |
| 1250 | } |
| 1251 | global.unix_bind.prefix = strdup(args[cur_arg+1]); |
| 1252 | cur_arg += 2; |
| 1253 | continue; |
| 1254 | } |
| 1255 | |
| 1256 | if (!strcmp(args[cur_arg], "mode")) { |
| 1257 | |
| 1258 | global.unix_bind.ux.mode = strtol(args[cur_arg + 1], NULL, 8); |
| 1259 | cur_arg += 2; |
| 1260 | continue; |
| 1261 | } |
| 1262 | |
| 1263 | if (!strcmp(args[cur_arg], "uid")) { |
| 1264 | |
| 1265 | global.unix_bind.ux.uid = atol(args[cur_arg + 1 ]); |
| 1266 | cur_arg += 2; |
| 1267 | continue; |
| 1268 | } |
| 1269 | |
| 1270 | if (!strcmp(args[cur_arg], "gid")) { |
| 1271 | |
| 1272 | global.unix_bind.ux.gid = atol(args[cur_arg + 1 ]); |
| 1273 | cur_arg += 2; |
| 1274 | continue; |
| 1275 | } |
| 1276 | |
| 1277 | if (!strcmp(args[cur_arg], "user")) { |
| 1278 | struct passwd *user; |
| 1279 | |
| 1280 | user = getpwnam(args[cur_arg + 1]); |
| 1281 | if (!user) { |
| 1282 | Alert("parsing [%s:%d] : '%s' : '%s' unknown user.\n", |
| 1283 | file, linenum, args[0], args[cur_arg + 1 ]); |
| 1284 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1285 | goto out; |
| 1286 | } |
| 1287 | |
| 1288 | global.unix_bind.ux.uid = user->pw_uid; |
| 1289 | cur_arg += 2; |
| 1290 | continue; |
| 1291 | } |
| 1292 | |
| 1293 | if (!strcmp(args[cur_arg], "group")) { |
| 1294 | struct group *group; |
| 1295 | |
| 1296 | group = getgrnam(args[cur_arg + 1]); |
| 1297 | if (!group) { |
| 1298 | Alert("parsing [%s:%d] : '%s' : '%s' unknown group.\n", |
| 1299 | file, linenum, args[0], args[cur_arg + 1 ]); |
| 1300 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1301 | goto out; |
| 1302 | } |
| 1303 | |
| 1304 | global.unix_bind.ux.gid = group->gr_gid; |
| 1305 | cur_arg += 2; |
| 1306 | continue; |
| 1307 | } |
| 1308 | |
Willy Tarreau | b48f958 | 2011-09-05 01:17:06 +0200 | [diff] [blame] | 1309 | 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] | 1310 | file, linenum, args[0]); |
| 1311 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1312 | goto out; |
| 1313 | } |
| 1314 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1315 | else if (!strcmp(args[0], "log") && kwm == KWM_NO) { /* no log */ |
| 1316 | /* delete previous herited or defined syslog servers */ |
| 1317 | struct logsrv *back; |
| 1318 | struct logsrv *tmp; |
| 1319 | |
| 1320 | if (*(args[1]) != 0) { |
| 1321 | Alert("parsing [%s:%d]:%s : 'no log' does not expect arguments.\n", file, linenum, args[1]); |
| 1322 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1323 | goto out; |
| 1324 | } |
| 1325 | |
| 1326 | list_for_each_entry_safe(tmp, back, &global.logsrvs, list) { |
| 1327 | LIST_DEL(&tmp->list); |
| 1328 | free(tmp); |
| 1329 | } |
| 1330 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1331 | else if (!strcmp(args[0], "log")) { /* syslog server address */ |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1332 | struct sockaddr_storage *sk; |
| 1333 | int port1, port2; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1334 | struct logsrv *logsrv; |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1335 | int arg = 0; |
| 1336 | int len = 0; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1337 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1338 | if (*(args[1]) == 0 || *(args[2]) == 0) { |
| 1339 | 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] | 1340 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1341 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1342 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1343 | |
| 1344 | logsrv = calloc(1, sizeof(struct logsrv)); |
| 1345 | |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1346 | /* just after the address, a length may be specified */ |
| 1347 | if (strcmp(args[arg+2], "len") == 0) { |
| 1348 | len = atoi(args[arg+3]); |
| 1349 | if (len < 80 || len > 65535) { |
| 1350 | Alert("parsing [%s:%d] : invalid log length '%s', must be between 80 and 65535.\n", |
| 1351 | file, linenum, args[arg+3]); |
| 1352 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1353 | goto out; |
| 1354 | } |
| 1355 | logsrv->maxlen = len; |
| 1356 | |
| 1357 | /* skip these two args */ |
| 1358 | arg += 2; |
| 1359 | } |
| 1360 | else |
| 1361 | logsrv->maxlen = MAX_SYSLOG_LEN; |
| 1362 | |
| 1363 | if (logsrv->maxlen > global.max_syslog_len) { |
| 1364 | global.max_syslog_len = logsrv->maxlen; |
| 1365 | logline = realloc(logline, global.max_syslog_len + 1); |
| 1366 | } |
| 1367 | |
| 1368 | logsrv->facility = get_log_facility(args[arg+2]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1369 | if (logsrv->facility < 0) { |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1370 | 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] | 1371 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1372 | logsrv->facility = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1373 | } |
| 1374 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1375 | logsrv->level = 7; /* max syslog level = debug */ |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1376 | if (*(args[arg+3])) { |
| 1377 | logsrv->level = get_log_level(args[arg+3]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1378 | if (logsrv->level < 0) { |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1379 | 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] | 1380 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1381 | logsrv->level = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1382 | } |
| 1383 | } |
| 1384 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1385 | logsrv->minlvl = 0; /* limit syslog level to this level (emerg) */ |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1386 | if (*(args[arg+4])) { |
| 1387 | logsrv->minlvl = get_log_level(args[arg+4]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1388 | if (logsrv->minlvl < 0) { |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1389 | 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] | 1390 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1391 | logsrv->minlvl = 0; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 1392 | } |
| 1393 | } |
| 1394 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1395 | sk = str2sa_range(args[1], &port1, &port2, &errmsg, NULL); |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1396 | if (!sk) { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1397 | Alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1398 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1399 | free(logsrv); |
| 1400 | goto out; |
| 1401 | } |
| 1402 | logsrv->addr = *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 1403 | |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1404 | if (sk->ss_family == AF_INET || sk->ss_family == AF_INET6) { |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 1405 | if (port1 != port2) { |
| 1406 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 1407 | file, linenum, args[0], args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 1408 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1409 | free(logsrv); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 1410 | goto out; |
| 1411 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 1412 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1413 | logsrv->addr = *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 1414 | if (!port1) |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1415 | set_host_port(&logsrv->addr, SYSLOG_PORT); |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 1416 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1417 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1418 | LIST_ADDQ(&global.logsrvs, &logsrv->list); |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1419 | } |
Joe Williams | df5b38f | 2010-12-29 17:05:48 +0100 | [diff] [blame] | 1420 | else if (!strcmp(args[0], "log-send-hostname")) { /* set the hostname in syslog header */ |
| 1421 | char *name; |
| 1422 | int len; |
| 1423 | |
| 1424 | if (global.log_send_hostname != NULL) { |
| 1425 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 1426 | err_code |= ERR_ALERT; |
| 1427 | goto out; |
| 1428 | } |
| 1429 | |
| 1430 | if (*(args[1])) |
| 1431 | name = args[1]; |
| 1432 | else |
| 1433 | name = hostname; |
| 1434 | |
| 1435 | len = strlen(name); |
| 1436 | |
| 1437 | /* We'll add a space after the name to respect the log format */ |
| 1438 | free(global.log_send_hostname); |
| 1439 | global.log_send_hostname = malloc(len + 2); |
| 1440 | snprintf(global.log_send_hostname, len + 2, "%s ", name); |
| 1441 | } |
Kevinm | 48936af | 2010-12-22 16:08:21 +0000 | [diff] [blame] | 1442 | else if (!strcmp(args[0], "log-tag")) { /* tag to report to syslog */ |
| 1443 | if (*(args[1]) == 0) { |
| 1444 | Alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]); |
| 1445 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1446 | goto out; |
| 1447 | } |
| 1448 | free(global.log_tag); |
| 1449 | global.log_tag = strdup(args[1]); |
| 1450 | } |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1451 | else if (!strcmp(args[0], "spread-checks")) { /* random time between checks (0-50) */ |
| 1452 | if (global.spread_checks != 0) { |
| 1453 | Alert("parsing [%s:%d]: spread-checks already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1454 | err_code |= ERR_ALERT; |
| 1455 | goto out; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1456 | } |
| 1457 | if (*(args[1]) == 0) { |
| 1458 | 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] | 1459 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1460 | goto out; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1461 | } |
| 1462 | global.spread_checks = atol(args[1]); |
| 1463 | if (global.spread_checks < 0 || global.spread_checks > 50) { |
| 1464 | 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] | 1465 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1466 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1467 | } |
Willy Tarreau | 1746eec | 2014-04-25 10:46:47 +0200 | [diff] [blame] | 1468 | else if (!strcmp(args[0], "max-spread-checks")) { /* maximum time between first and last check */ |
| 1469 | const char *err; |
| 1470 | unsigned int val; |
| 1471 | |
| 1472 | |
| 1473 | if (*(args[1]) == 0) { |
| 1474 | Alert("parsing [%s:%d]: '%s' expects an integer argument (0..50).\n", file, linenum, args[0]); |
| 1475 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1476 | goto out; |
| 1477 | } |
| 1478 | |
| 1479 | err = parse_time_err(args[1], &val, TIME_UNIT_MS); |
| 1480 | if (err) { |
| 1481 | Alert("parsing [%s:%d]: unsupported character '%c' in '%s' (wants an integer delay).\n", file, linenum, *err, args[0]); |
| 1482 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1483 | } |
| 1484 | global.max_spread_checks = val; |
| 1485 | if (global.max_spread_checks < 0) { |
| 1486 | Alert("parsing [%s:%d]: '%s' needs a positive delay in milliseconds.\n",file, linenum, args[0]); |
| 1487 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1488 | } |
| 1489 | } |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1490 | else if (strcmp(args[0], "cpu-map") == 0) { /* map a process list to a CPU set */ |
| 1491 | #ifdef USE_CPU_AFFINITY |
| 1492 | int cur_arg, i; |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1493 | unsigned long proc = 0; |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1494 | unsigned long cpus = 0; |
| 1495 | |
| 1496 | if (strcmp(args[1], "all") == 0) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1497 | proc = ~0UL; |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1498 | else if (strcmp(args[1], "odd") == 0) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1499 | proc = ~0UL/3UL; /* 0x555....555 */ |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1500 | else if (strcmp(args[1], "even") == 0) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1501 | proc = (~0UL/3UL) << 1; /* 0xAAA...AAA */ |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1502 | else { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1503 | proc = atol(args[1]); |
| 1504 | if (proc >= 1 && proc <= LONGBITS) |
| 1505 | proc = 1UL << (proc - 1); |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1506 | } |
| 1507 | |
| 1508 | if (!proc || !*args[2]) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1509 | 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", |
| 1510 | file, linenum, args[0], LONGBITS, LONGBITS - 1); |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1511 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1512 | goto out; |
| 1513 | } |
| 1514 | |
| 1515 | cur_arg = 2; |
| 1516 | while (*args[cur_arg]) { |
| 1517 | unsigned int low, high; |
| 1518 | |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 1519 | if (isdigit((int)*args[cur_arg])) { |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1520 | char *dash = strchr(args[cur_arg], '-'); |
| 1521 | |
| 1522 | low = high = str2uic(args[cur_arg]); |
| 1523 | if (dash) |
| 1524 | high = str2uic(dash + 1); |
| 1525 | |
| 1526 | if (high < low) { |
| 1527 | unsigned int swap = low; |
| 1528 | low = high; |
| 1529 | high = swap; |
| 1530 | } |
| 1531 | |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1532 | if (high >= LONGBITS) { |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1533 | 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] | 1534 | file, linenum, args[0], LONGBITS - 1); |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1535 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1536 | goto out; |
| 1537 | } |
| 1538 | |
| 1539 | while (low <= high) |
| 1540 | cpus |= 1UL << low++; |
| 1541 | } |
| 1542 | else { |
| 1543 | Alert("parsing [%s:%d]: %s : '%s' is not a CPU range.\n", |
| 1544 | file, linenum, args[0], args[cur_arg]); |
| 1545 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1546 | goto out; |
| 1547 | } |
| 1548 | cur_arg++; |
| 1549 | } |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1550 | for (i = 0; i < LONGBITS; i++) |
| 1551 | if (proc & (1UL << i)) |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1552 | global.cpu_map[i] = cpus; |
| 1553 | #else |
| 1554 | Alert("parsing [%s:%d] : '%s' is not enabled, please check build options for USE_CPU_AFFINITY.\n", file, linenum, args[0]); |
| 1555 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1556 | goto out; |
| 1557 | #endif |
| 1558 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1559 | else { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1560 | struct cfg_kw_list *kwl; |
| 1561 | int index; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1562 | int rc; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1563 | |
| 1564 | list_for_each_entry(kwl, &cfg_keywords.list, list) { |
| 1565 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 1566 | if (kwl->kw[index].section != CFG_GLOBAL) |
| 1567 | continue; |
| 1568 | if (strcmp(kwl->kw[index].kw, args[0]) == 0) { |
Willy Tarreau | 28a47d6 | 2012-09-18 20:02:48 +0200 | [diff] [blame] | 1569 | 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] | 1570 | if (rc < 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 1571 | Alert("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1572 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1573 | } |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1574 | else if (rc > 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 1575 | Warning("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1576 | err_code |= ERR_WARN; |
| 1577 | goto out; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1578 | } |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1579 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1580 | } |
| 1581 | } |
| 1582 | } |
| 1583 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1584 | 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] | 1585 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1586 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1587 | |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1588 | out: |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 1589 | free(errmsg); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1590 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1591 | } |
| 1592 | |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 1593 | void init_default_instance() |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1594 | { |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 1595 | init_new_proxy(&defproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1596 | defproxy.mode = PR_MODE_TCP; |
| 1597 | defproxy.state = PR_STNEW; |
| 1598 | defproxy.maxconn = cfg_maxpconn; |
| 1599 | defproxy.conn_retries = CONN_RETRIES; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1600 | |
Simon Horman | 6618300 | 2013-02-23 10:16:43 +0900 | [diff] [blame] | 1601 | defproxy.defsrv.check.inter = DEF_CHKINTR; |
| 1602 | defproxy.defsrv.check.fastinter = 0; |
| 1603 | defproxy.defsrv.check.downinter = 0; |
Simon Horman | d60d691 | 2013-11-25 10:46:36 +0900 | [diff] [blame] | 1604 | defproxy.defsrv.agent.inter = DEF_CHKINTR; |
| 1605 | defproxy.defsrv.agent.fastinter = 0; |
| 1606 | defproxy.defsrv.agent.downinter = 0; |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 1607 | defproxy.defsrv.check.rise = DEF_RISETIME; |
| 1608 | defproxy.defsrv.check.fall = DEF_FALLTIME; |
| 1609 | defproxy.defsrv.agent.rise = DEF_AGENT_RISETIME; |
| 1610 | defproxy.defsrv.agent.fall = DEF_AGENT_FALLTIME; |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 1611 | defproxy.defsrv.check.port = 0; |
Simon Horman | d60d691 | 2013-11-25 10:46:36 +0900 | [diff] [blame] | 1612 | defproxy.defsrv.agent.port = 0; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1613 | defproxy.defsrv.maxqueue = 0; |
| 1614 | defproxy.defsrv.minconn = 0; |
| 1615 | defproxy.defsrv.maxconn = 0; |
| 1616 | defproxy.defsrv.slowstart = 0; |
| 1617 | defproxy.defsrv.onerror = DEF_HANA_ONERR; |
| 1618 | defproxy.defsrv.consecutive_errors_limit = DEF_HANA_ERRLIMIT; |
| 1619 | defproxy.defsrv.uweight = defproxy.defsrv.iweight = 1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1620 | } |
| 1621 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1622 | |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1623 | /* This function createss a new req* or rsp* rule to the proxy. It compiles the |
| 1624 | * regex and may return the ERR_WARN bit, and error bits such as ERR_ALERT and |
| 1625 | * ERR_FATAL in case of error. |
| 1626 | */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1627 | static int create_cond_regex_rule(const char *file, int line, |
| 1628 | struct proxy *px, int dir, int action, int flags, |
| 1629 | const char *cmd, const char *reg, const char *repl, |
| 1630 | const char **cond_start) |
| 1631 | { |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1632 | struct my_regex *preg = NULL; |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 1633 | char *errmsg = NULL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1634 | const char *err; |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1635 | char *error; |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1636 | int ret_code = 0; |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1637 | struct acl_cond *cond = NULL; |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1638 | int cs; |
| 1639 | int cap; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1640 | |
| 1641 | if (px == &defproxy) { |
| 1642 | 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] | 1643 | ret_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1644 | goto err; |
| 1645 | } |
| 1646 | |
| 1647 | if (*reg == 0) { |
| 1648 | 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] | 1649 | ret_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1650 | goto err; |
| 1651 | } |
| 1652 | |
| 1653 | if (warnifnotcap(px, PR_CAP_RS, file, line, cmd, NULL)) |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1654 | ret_code |= ERR_WARN; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1655 | |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1656 | if (cond_start && |
| 1657 | (strcmp(*cond_start, "if") == 0 || strcmp(*cond_start, "unless") == 0)) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 1658 | if ((cond = build_acl_cond(file, line, px, cond_start, &errmsg)) == NULL) { |
| 1659 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 1660 | file, line, cmd, errmsg); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1661 | ret_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1662 | goto err; |
| 1663 | } |
| 1664 | } |
| 1665 | else if (cond_start && **cond_start) { |
| 1666 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 1667 | file, line, cmd, *cond_start); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1668 | ret_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1669 | goto err; |
| 1670 | } |
| 1671 | |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1672 | ret_code |= warnif_cond_conflicts(cond, |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 1673 | (dir == SMP_OPT_DIR_REQ) ? |
| 1674 | ((px->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR) : |
| 1675 | ((px->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR), |
| 1676 | file, line); |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1677 | |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1678 | preg = calloc(1, sizeof(*preg)); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1679 | if (!preg) { |
| 1680 | 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] | 1681 | ret_code = ERR_ALERT | ERR_FATAL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1682 | goto err; |
| 1683 | } |
| 1684 | |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1685 | cs = !(flags & REG_ICASE); |
| 1686 | cap = !(flags & REG_NOSUB); |
| 1687 | error = NULL; |
| 1688 | if (!regex_comp(reg, preg, cs, cap, &error)) { |
| 1689 | Alert("parsing [%s:%d] : '%s' : regular expression '%s' : %s\n", file, line, cmd, reg, error); |
| 1690 | free(error); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1691 | ret_code = ERR_ALERT | ERR_FATAL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1692 | goto err; |
| 1693 | } |
| 1694 | |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 1695 | 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] | 1696 | preg, action, repl ? strdup(repl) : NULL, cond); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1697 | if (repl && err) { |
| 1698 | Alert("parsing [%s:%d] : '%s' : invalid character or unterminated sequence in replacement string near '%c'.\n", |
| 1699 | file, line, cmd, *err); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1700 | ret_code |= ERR_ALERT | ERR_FATAL; |
| 1701 | goto err_free; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1702 | } |
| 1703 | |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 1704 | 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] | 1705 | ret_code |= ERR_WARN; |
| 1706 | |
| 1707 | return ret_code; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1708 | |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1709 | err_free: |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1710 | regex_free(preg); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1711 | err: |
| 1712 | free(preg); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1713 | free(errmsg); |
| 1714 | return ret_code; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1715 | } |
| 1716 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1717 | /* |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1718 | * Parse a line in a <listen>, <frontend>, <backend> or <ruleset> section. |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1719 | * Returns the error code, 0 if OK, or any combination of : |
| 1720 | * - ERR_ABORT: must abort ASAP |
| 1721 | * - ERR_FATAL: we can continue parsing but not start the service |
| 1722 | * - ERR_WARN: a warning has been emitted |
| 1723 | * - ERR_ALERT: an alert has been emitted |
| 1724 | * Only the two first ones can stop processing, the two others are just |
| 1725 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1726 | */ |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1727 | int cfg_parse_peers(const char *file, int linenum, char **args, int kwm) |
| 1728 | { |
| 1729 | static struct peers *curpeers = NULL; |
| 1730 | struct peer *newpeer = NULL; |
| 1731 | const char *err; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1732 | struct bind_conf *bind_conf; |
| 1733 | struct listener *l; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1734 | int err_code = 0; |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1735 | char *errmsg = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1736 | |
| 1737 | if (strcmp(args[0], "peers") == 0) { /* new peers section */ |
Willy Tarreau | 0dbbf31 | 2013-03-05 11:31:55 +0100 | [diff] [blame] | 1738 | if (!*args[1]) { |
| 1739 | Alert("parsing [%s:%d] : missing name for peers section.\n", file, linenum); |
Willy Tarreau | 5498472 | 2014-02-16 08:20:13 +0100 | [diff] [blame] | 1740 | err_code |= ERR_ALERT | ERR_ABORT; |
Willy Tarreau | 0dbbf31 | 2013-03-05 11:31:55 +0100 | [diff] [blame] | 1741 | goto out; |
| 1742 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1743 | |
| 1744 | err = invalid_char(args[1]); |
| 1745 | if (err) { |
| 1746 | Alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 1747 | file, linenum, *err, args[0], args[1]); |
Willy Tarreau | 5498472 | 2014-02-16 08:20:13 +0100 | [diff] [blame] | 1748 | err_code |= ERR_ALERT | ERR_ABORT; |
Willy Tarreau | 0dbbf31 | 2013-03-05 11:31:55 +0100 | [diff] [blame] | 1749 | goto out; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1750 | } |
| 1751 | |
| 1752 | for (curpeers = peers; curpeers != NULL; curpeers = curpeers->next) { |
| 1753 | /* |
| 1754 | * If there are two proxies with the same name only following |
| 1755 | * combinations are allowed: |
| 1756 | */ |
| 1757 | if (strcmp(curpeers->id, args[1]) == 0) { |
| 1758 | Warning("Parsing [%s:%d]: peers '%s' has same name as another peers (declared at %s:%d).\n", |
| 1759 | file, linenum, args[1], curpeers->conf.file, curpeers->conf.line); |
| 1760 | err_code |= ERR_WARN; |
| 1761 | } |
| 1762 | } |
| 1763 | |
| 1764 | if ((curpeers = (struct peers *)calloc(1, sizeof(struct peers))) == NULL) { |
| 1765 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1766 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1767 | goto out; |
| 1768 | } |
| 1769 | |
| 1770 | curpeers->next = peers; |
| 1771 | peers = curpeers; |
Willy Tarreau | 8113a5d | 2012-10-04 08:01:43 +0200 | [diff] [blame] | 1772 | curpeers->conf.file = strdup(file); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1773 | curpeers->conf.line = linenum; |
| 1774 | curpeers->last_change = now.tv_sec; |
| 1775 | curpeers->id = strdup(args[1]); |
| 1776 | } |
| 1777 | else if (strcmp(args[0], "peer") == 0) { /* peer definition */ |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 1778 | struct sockaddr_storage *sk; |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 1779 | int port1, port2; |
Willy Tarreau | b36487e | 2013-03-10 18:37:42 +0100 | [diff] [blame] | 1780 | struct protocol *proto; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1781 | |
| 1782 | if (!*args[2]) { |
| 1783 | Alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n", |
| 1784 | file, linenum, args[0]); |
| 1785 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1786 | goto out; |
| 1787 | } |
| 1788 | |
| 1789 | err = invalid_char(args[1]); |
| 1790 | if (err) { |
| 1791 | Alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n", |
| 1792 | file, linenum, *err, args[1]); |
| 1793 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1794 | goto out; |
| 1795 | } |
| 1796 | |
| 1797 | if ((newpeer = (struct peer *)calloc(1, sizeof(struct peer))) == NULL) { |
| 1798 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1799 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1800 | goto out; |
| 1801 | } |
| 1802 | |
| 1803 | /* the peers are linked backwards first */ |
| 1804 | curpeers->count++; |
| 1805 | newpeer->next = curpeers->remote; |
| 1806 | curpeers->remote = newpeer; |
| 1807 | newpeer->peers = curpeers; |
Willy Tarreau | 8113a5d | 2012-10-04 08:01:43 +0200 | [diff] [blame] | 1808 | newpeer->conf.file = strdup(file); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1809 | newpeer->conf.line = linenum; |
| 1810 | |
| 1811 | newpeer->last_change = now.tv_sec; |
| 1812 | newpeer->id = strdup(args[1]); |
| 1813 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1814 | sk = str2sa_range(args[2], &port1, &port2, &errmsg, NULL); |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 1815 | if (!sk) { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1816 | 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] | 1817 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1818 | goto out; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1819 | } |
Willy Tarreau | b36487e | 2013-03-10 18:37:42 +0100 | [diff] [blame] | 1820 | |
| 1821 | proto = protocol_by_family(sk->ss_family); |
| 1822 | if (!proto || !proto->connect) { |
| 1823 | Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 1824 | file, linenum, args[0], args[1]); |
| 1825 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1826 | goto out; |
| 1827 | } |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 1828 | |
| 1829 | if (port1 != port2) { |
| 1830 | Alert("parsing [%s:%d] : '%s %s' : port ranges and offsets are not allowed in '%s'\n", |
| 1831 | file, linenum, args[0], args[1], args[2]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1832 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1833 | goto out; |
| 1834 | } |
| 1835 | |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 1836 | if (!port1) { |
| 1837 | Alert("parsing [%s:%d] : '%s %s' : missing or invalid port in '%s'\n", |
| 1838 | file, linenum, args[0], args[1], args[2]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1839 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1840 | goto out; |
| 1841 | } |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 1842 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1843 | newpeer->addr = *sk; |
Willy Tarreau | b36487e | 2013-03-10 18:37:42 +0100 | [diff] [blame] | 1844 | newpeer->proto = proto; |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 1845 | newpeer->xprt = &raw_sock; |
Willy Tarreau | d02394b | 2012-05-11 18:32:18 +0200 | [diff] [blame] | 1846 | newpeer->sock_init_arg = NULL; |
Willy Tarreau | 26d8c59 | 2012-05-07 18:12:14 +0200 | [diff] [blame] | 1847 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1848 | if (strcmp(newpeer->id, localpeer) == 0) { |
| 1849 | /* Current is local peer, it define a frontend */ |
| 1850 | newpeer->local = 1; |
| 1851 | |
| 1852 | if (!curpeers->peers_fe) { |
| 1853 | if ((curpeers->peers_fe = calloc(1, sizeof(struct proxy))) == NULL) { |
| 1854 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1855 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1856 | goto out; |
| 1857 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1858 | |
Willy Tarreau | 237250c | 2011-07-29 01:49:03 +0200 | [diff] [blame] | 1859 | init_new_proxy(curpeers->peers_fe); |
| 1860 | curpeers->peers_fe->parent = curpeers; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1861 | |
| 1862 | curpeers->peers_fe->last_change = now.tv_sec; |
| 1863 | curpeers->peers_fe->id = strdup(args[1]); |
| 1864 | curpeers->peers_fe->cap = PR_CAP_FE; |
Willy Tarreau | 3ae65a1 | 2011-09-07 17:40:39 +0200 | [diff] [blame] | 1865 | curpeers->peers_fe->maxconn = 0; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1866 | curpeers->peers_fe->conn_retries = CONN_RETRIES; |
| 1867 | curpeers->peers_fe->timeout.connect = 5000; |
| 1868 | curpeers->peers_fe->accept = peer_accept; |
| 1869 | 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] | 1870 | curpeers->peers_fe->conf.args.file = curpeers->peers_fe->conf.file = strdup(file); |
| 1871 | curpeers->peers_fe->conf.args.line = curpeers->peers_fe->conf.line = linenum; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1872 | |
| 1873 | bind_conf = bind_conf_alloc(&curpeers->peers_fe->conf.bind, file, linenum, args[2]); |
| 1874 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1875 | if (!str2listener(args[2], curpeers->peers_fe, bind_conf, file, linenum, &errmsg)) { |
| 1876 | if (errmsg && *errmsg) { |
| 1877 | indent_msg(&errmsg, 2); |
| 1878 | 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] | 1879 | } |
| 1880 | else |
| 1881 | Alert("parsing [%s:%d] : '%s %s' : error encountered while parsing listening address %s.\n", |
| 1882 | file, linenum, args[0], args[1], args[2]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1883 | err_code |= ERR_FATAL; |
| 1884 | goto out; |
| 1885 | } |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1886 | |
| 1887 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
Willy Tarreau | acf3bf9 | 2013-01-18 10:51:07 +0100 | [diff] [blame] | 1888 | l->maxaccept = 1; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1889 | l->maxconn = ((struct proxy *)curpeers->peers_fe)->maxconn; |
| 1890 | l->backlog = ((struct proxy *)curpeers->peers_fe)->backlog; |
| 1891 | l->timeout = &((struct proxy *)curpeers->peers_fe)->timeout.client; |
| 1892 | l->accept = session_accept; |
| 1893 | l->handler = process_session; |
| 1894 | l->analysers |= ((struct proxy *)curpeers->peers_fe)->fe_req_ana; |
| 1895 | l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */ |
| 1896 | global.maxsock += l->maxconn; |
| 1897 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1898 | } |
Willy Tarreau | 8b8fd56 | 2013-01-18 11:12:27 +0100 | [diff] [blame] | 1899 | else { |
| 1900 | Alert("parsing [%s:%d] : '%s %s' : local peer name already referenced at %s:%d.\n", |
| 1901 | file, linenum, args[0], args[1], |
| 1902 | curpeers->peers_fe->conf.file, curpeers->peers_fe->conf.line); |
| 1903 | err_code |= ERR_FATAL; |
| 1904 | goto out; |
| 1905 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1906 | } |
| 1907 | } /* neither "peer" nor "peers" */ |
| 1908 | else if (*args[0] != 0) { |
| 1909 | Alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection); |
| 1910 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1911 | goto out; |
| 1912 | } |
| 1913 | |
| 1914 | out: |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1915 | free(errmsg); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1916 | return err_code; |
| 1917 | } |
| 1918 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 1919 | 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] | 1920 | { |
| 1921 | static struct proxy *curproxy = NULL; |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 1922 | const char *err; |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1923 | char *error; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 1924 | int rc; |
| 1925 | unsigned val; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1926 | int err_code = 0; |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 1927 | struct acl_cond *cond = NULL; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 1928 | struct logsrv *tmplogsrv; |
Willy Tarreau | f4068b6 | 2012-05-08 17:37:49 +0200 | [diff] [blame] | 1929 | char *errmsg = NULL; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 1930 | struct bind_conf *bind_conf; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1931 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1932 | if (!strcmp(args[0], "listen")) |
| 1933 | rc = PR_CAP_LISTEN; |
| 1934 | else if (!strcmp(args[0], "frontend")) |
| 1935 | rc = PR_CAP_FE | PR_CAP_RS; |
| 1936 | else if (!strcmp(args[0], "backend")) |
| 1937 | rc = PR_CAP_BE | PR_CAP_RS; |
| 1938 | else if (!strcmp(args[0], "ruleset")) |
| 1939 | rc = PR_CAP_RS; |
| 1940 | else |
| 1941 | rc = PR_CAP_NONE; |
| 1942 | |
| 1943 | if (rc != PR_CAP_NONE) { /* new proxy */ |
Willy Tarreau | 7cbc915 | 2014-03-15 08:17:08 +0100 | [diff] [blame] | 1944 | struct ebpt_node *node; |
| 1945 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1946 | if (!*args[1]) { |
| 1947 | Alert("parsing [%s:%d] : '%s' expects an <id> argument and\n" |
| 1948 | " optionnally supports [addr1]:port1[-end1]{,[addr]:port[-end]}...\n", |
| 1949 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1950 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1951 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1952 | } |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 1953 | |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 1954 | err = invalid_char(args[1]); |
| 1955 | if (err) { |
| 1956 | Alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 1957 | file, linenum, *err, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1958 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 1959 | } |
| 1960 | |
Willy Tarreau | 7cbc915 | 2014-03-15 08:17:08 +0100 | [diff] [blame] | 1961 | for (node = ebis_lookup(&proxy_by_name, args[1]); node; node = ebpt_next(node)) { |
| 1962 | curproxy = container_of(node, struct proxy, conf.by_name); |
| 1963 | |
| 1964 | if (strcmp(curproxy->id, args[1]) != 0) |
| 1965 | break; |
| 1966 | |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 1967 | /* |
| 1968 | * If there are two proxies with the same name only following |
| 1969 | * combinations are allowed: |
| 1970 | * |
| 1971 | * listen backend frontend ruleset |
| 1972 | * listen - - - - |
| 1973 | * backend - - OK - |
| 1974 | * frontend - OK - - |
| 1975 | * ruleset - - - - |
| 1976 | */ |
| 1977 | |
Willy Tarreau | 7cbc915 | 2014-03-15 08:17:08 +0100 | [diff] [blame] | 1978 | if ((rc != (PR_CAP_FE|PR_CAP_RS) || curproxy->cap != (PR_CAP_BE|PR_CAP_RS)) && |
| 1979 | (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] | 1980 | Warning("Parsing [%s:%d]: %s '%s' has same name as another %s (declared at %s:%d).\n", |
| 1981 | file, linenum, proxy_cap_str(rc), args[1], proxy_type_str(curproxy), |
| 1982 | curproxy->conf.file, curproxy->conf.line); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1983 | err_code |= ERR_WARN; |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 1984 | } |
| 1985 | } |
| 1986 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1987 | if ((curproxy = (struct proxy *)calloc(1, sizeof(struct proxy))) == NULL) { |
| 1988 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1989 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1990 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1991 | } |
Willy Tarreau | 5af24ef | 2009-03-15 15:23:16 +0100 | [diff] [blame] | 1992 | |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 1993 | init_new_proxy(curproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1994 | curproxy->next = proxy; |
| 1995 | proxy = curproxy; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 1996 | curproxy->conf.args.file = curproxy->conf.file = strdup(file); |
| 1997 | curproxy->conf.args.line = curproxy->conf.line = linenum; |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 1998 | curproxy->last_change = now.tv_sec; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1999 | curproxy->id = strdup(args[1]); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2000 | curproxy->cap = rc; |
Willy Tarreau | f79d950 | 2014-03-15 07:22:35 +0100 | [diff] [blame] | 2001 | proxy_store_name(curproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2002 | |
| 2003 | /* parse the listener address if any */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2004 | if ((curproxy->cap & PR_CAP_FE) && *args[2]) { |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2005 | struct listener *l; |
Willy Tarreau | 81a8117 | 2012-09-18 20:52:35 +0200 | [diff] [blame] | 2006 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2007 | bind_conf = bind_conf_alloc(&curproxy->conf.bind, file, linenum, args[2]); |
| 2008 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 2009 | if (!str2listener(args[2], curproxy, bind_conf, file, linenum, &errmsg)) { |
| 2010 | if (errmsg && *errmsg) { |
| 2011 | indent_msg(&errmsg, 2); |
| 2012 | 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] | 2013 | } |
| 2014 | else |
| 2015 | Alert("parsing [%s:%d] : '%s %s' : error encountered while parsing listening address '%s'.\n", |
| 2016 | file, linenum, args[0], args[1], args[2]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2017 | err_code |= ERR_FATAL; |
| 2018 | goto out; |
| 2019 | } |
Willy Tarreau | 81a8117 | 2012-09-18 20:52:35 +0200 | [diff] [blame] | 2020 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2021 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
Willy Tarreau | c8b1109 | 2011-02-16 11:08:57 +0100 | [diff] [blame] | 2022 | global.maxsock++; |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 2023 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2024 | } |
| 2025 | |
| 2026 | /* set default values */ |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 2027 | memcpy(&curproxy->defsrv, &defproxy.defsrv, sizeof(curproxy->defsrv)); |
Willy Tarreau | 7016020 | 2010-04-07 16:06:40 +0200 | [diff] [blame] | 2028 | curproxy->defsrv.id = "default-server"; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 2029 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2030 | curproxy->state = defproxy.state; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2031 | curproxy->options = defproxy.options; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 2032 | curproxy->options2 = defproxy.options2; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 2033 | curproxy->no_options = defproxy.no_options; |
| 2034 | curproxy->no_options2 = defproxy.no_options2; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2035 | curproxy->bind_proc = defproxy.bind_proc; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 2036 | curproxy->except_net = defproxy.except_net; |
| 2037 | curproxy->except_mask = defproxy.except_mask; |
Maik Broemme | 36db02e | 2009-05-08 17:02:07 +0200 | [diff] [blame] | 2038 | curproxy->except_to = defproxy.except_to; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 2039 | curproxy->except_mask_to = defproxy.except_mask_to; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2040 | |
Willy Tarreau | 79f5fe8 | 2008-08-23 08:18:21 +0200 | [diff] [blame] | 2041 | if (defproxy.fwdfor_hdr_len) { |
| 2042 | curproxy->fwdfor_hdr_len = defproxy.fwdfor_hdr_len; |
| 2043 | curproxy->fwdfor_hdr_name = strdup(defproxy.fwdfor_hdr_name); |
| 2044 | } |
| 2045 | |
Willy Tarreau | b86db34 | 2009-11-30 11:50:16 +0100 | [diff] [blame] | 2046 | if (defproxy.orgto_hdr_len) { |
| 2047 | curproxy->orgto_hdr_len = defproxy.orgto_hdr_len; |
| 2048 | curproxy->orgto_hdr_name = strdup(defproxy.orgto_hdr_name); |
| 2049 | } |
| 2050 | |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 2051 | if (defproxy.server_id_hdr_len) { |
| 2052 | curproxy->server_id_hdr_len = defproxy.server_id_hdr_len; |
| 2053 | curproxy->server_id_hdr_name = strdup(defproxy.server_id_hdr_name); |
| 2054 | } |
| 2055 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2056 | if (curproxy->cap & PR_CAP_FE) { |
| 2057 | curproxy->maxconn = defproxy.maxconn; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 2058 | curproxy->backlog = defproxy.backlog; |
Willy Tarreau | 13a34bd | 2009-05-10 18:52:49 +0200 | [diff] [blame] | 2059 | curproxy->fe_sps_lim = defproxy.fe_sps_lim; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2060 | |
| 2061 | /* initialize error relocations */ |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2062 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) |
| 2063 | chunk_dup(&curproxy->errmsg[rc], &defproxy.errmsg[rc]); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2064 | |
| 2065 | curproxy->to_log = defproxy.to_log & ~LW_COOKIE & ~LW_REQHDR & ~ LW_RSPHDR; |
| 2066 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2067 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2068 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | 743c128 | 2014-11-18 15:04:29 +0100 | [diff] [blame] | 2069 | curproxy->lbprm.algo = defproxy.lbprm.algo; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2070 | curproxy->fullconn = defproxy.fullconn; |
| 2071 | curproxy->conn_retries = defproxy.conn_retries; |
Willy Tarreau | c35362a | 2014-04-25 13:58:37 +0200 | [diff] [blame] | 2072 | curproxy->max_ka_queue = defproxy.max_ka_queue; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2073 | |
Willy Tarreau | aa2f389 | 2010-10-22 16:15:31 +0200 | [diff] [blame] | 2074 | if (defproxy.check_req) { |
| 2075 | curproxy->check_req = calloc(1, defproxy.check_len); |
| 2076 | memcpy(curproxy->check_req, defproxy.check_req, defproxy.check_len); |
| 2077 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2078 | curproxy->check_len = defproxy.check_len; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2079 | |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 2080 | if (defproxy.expect_str) { |
| 2081 | curproxy->expect_str = strdup(defproxy.expect_str); |
| 2082 | if (defproxy.expect_regex) { |
| 2083 | /* note: this regex is known to be valid */ |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 2084 | curproxy->expect_regex = calloc(1, sizeof(*curproxy->expect_regex)); |
| 2085 | regex_comp(defproxy.expect_str, curproxy->expect_regex, 1, 1, NULL); |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 2086 | } |
| 2087 | } |
| 2088 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2089 | curproxy->ck_opts = defproxy.ck_opts; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2090 | if (defproxy.cookie_name) |
| 2091 | curproxy->cookie_name = strdup(defproxy.cookie_name); |
| 2092 | curproxy->cookie_len = defproxy.cookie_len; |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 2093 | if (defproxy.cookie_domain) |
| 2094 | curproxy->cookie_domain = strdup(defproxy.cookie_domain); |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 2095 | |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 2096 | if (defproxy.cookie_maxidle) |
| 2097 | curproxy->cookie_maxidle = defproxy.cookie_maxidle; |
| 2098 | |
| 2099 | if (defproxy.cookie_maxlife) |
| 2100 | curproxy->cookie_maxlife = defproxy.cookie_maxlife; |
| 2101 | |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2102 | if (defproxy.rdp_cookie_name) |
| 2103 | curproxy->rdp_cookie_name = strdup(defproxy.rdp_cookie_name); |
| 2104 | curproxy->rdp_cookie_len = defproxy.rdp_cookie_len; |
| 2105 | |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 2106 | if (defproxy.url_param_name) |
| 2107 | curproxy->url_param_name = strdup(defproxy.url_param_name); |
| 2108 | curproxy->url_param_len = defproxy.url_param_len; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 2109 | |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 2110 | if (defproxy.hh_name) |
| 2111 | curproxy->hh_name = strdup(defproxy.hh_name); |
| 2112 | curproxy->hh_len = defproxy.hh_len; |
| 2113 | curproxy->hh_match_domain = defproxy.hh_match_domain; |
| 2114 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 2115 | if (defproxy.conn_src.iface_name) |
| 2116 | curproxy->conn_src.iface_name = strdup(defproxy.conn_src.iface_name); |
| 2117 | curproxy->conn_src.iface_len = defproxy.conn_src.iface_len; |
Godbach | 9f04853 | 2013-04-23 15:27:57 +0800 | [diff] [blame] | 2118 | curproxy->conn_src.opts = defproxy.conn_src.opts; |
Pieter Baauw | d551fb5 | 2013-05-08 22:49:23 +0200 | [diff] [blame] | 2119 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_TRANSPARENT) |
Godbach | 9f04853 | 2013-04-23 15:27:57 +0800 | [diff] [blame] | 2120 | curproxy->conn_src.tproxy_addr = defproxy.conn_src.tproxy_addr; |
Willy Tarreau | c621d36 | 2013-04-25 17:35:22 +0200 | [diff] [blame] | 2121 | #endif |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2122 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2123 | |
Willy Tarreau | 3b6b1a9 | 2009-07-23 13:24:23 +0200 | [diff] [blame] | 2124 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2125 | if (defproxy.capture_name) |
| 2126 | curproxy->capture_name = strdup(defproxy.capture_name); |
| 2127 | curproxy->capture_namelen = defproxy.capture_namelen; |
| 2128 | curproxy->capture_len = defproxy.capture_len; |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 2129 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2130 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2131 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 2132 | curproxy->timeout.client = defproxy.timeout.client; |
Simone Gotti | 1b48cc9 | 2014-06-11 12:25:28 +0200 | [diff] [blame] | 2133 | curproxy->timeout.clientfin = defproxy.timeout.clientfin; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 2134 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | 036fae0 | 2008-01-06 13:24:40 +0100 | [diff] [blame] | 2135 | curproxy->timeout.httpreq = defproxy.timeout.httpreq; |
Willy Tarreau | b16a574 | 2010-01-10 14:46:16 +0100 | [diff] [blame] | 2136 | curproxy->timeout.httpka = defproxy.timeout.httpka; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2137 | curproxy->mon_net = defproxy.mon_net; |
| 2138 | curproxy->mon_mask = defproxy.mon_mask; |
| 2139 | if (defproxy.monitor_uri) |
| 2140 | curproxy->monitor_uri = strdup(defproxy.monitor_uri); |
| 2141 | curproxy->monitor_uri_len = defproxy.monitor_uri_len; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 2142 | if (defproxy.defbe.name) |
| 2143 | curproxy->defbe.name = strdup(defproxy.defbe.name); |
Willy Tarreau | 99a7ca2 | 2012-05-31 19:39:23 +0200 | [diff] [blame] | 2144 | |
| 2145 | /* 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] | 2146 | curproxy->conf.logformat_string = defproxy.conf.logformat_string; |
| 2147 | if (curproxy->conf.logformat_string && |
| 2148 | curproxy->conf.logformat_string != default_http_log_format && |
| 2149 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 2150 | curproxy->conf.logformat_string != clf_http_log_format) |
| 2151 | curproxy->conf.logformat_string = strdup(curproxy->conf.logformat_string); |
| 2152 | |
| 2153 | if (defproxy.conf.lfs_file) { |
| 2154 | curproxy->conf.lfs_file = strdup(defproxy.conf.lfs_file); |
| 2155 | curproxy->conf.lfs_line = defproxy.conf.lfs_line; |
| 2156 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2157 | } |
| 2158 | |
| 2159 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 2160 | curproxy->timeout.connect = defproxy.timeout.connect; |
| 2161 | curproxy->timeout.server = defproxy.timeout.server; |
Simone Gotti | 1b48cc9 | 2014-06-11 12:25:28 +0200 | [diff] [blame] | 2162 | curproxy->timeout.serverfin = defproxy.timeout.serverfin; |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 2163 | curproxy->timeout.check = defproxy.timeout.check; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 2164 | curproxy->timeout.queue = defproxy.timeout.queue; |
Willy Tarreau | 51c9bde | 2008-01-06 13:40:03 +0100 | [diff] [blame] | 2165 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | cd7afc0 | 2009-07-12 10:03:17 +0200 | [diff] [blame] | 2166 | curproxy->timeout.httpreq = defproxy.timeout.httpreq; |
Willy Tarreau | b16a574 | 2010-01-10 14:46:16 +0100 | [diff] [blame] | 2167 | curproxy->timeout.httpka = defproxy.timeout.httpka; |
Willy Tarreau | ce887fd | 2012-05-12 12:50:00 +0200 | [diff] [blame] | 2168 | curproxy->timeout.tunnel = defproxy.timeout.tunnel; |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 2169 | curproxy->conn_src.source_addr = defproxy.conn_src.source_addr; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2170 | } |
| 2171 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2172 | curproxy->mode = defproxy.mode; |
Willy Tarreau | ed2119c | 2014-04-24 22:10:39 +0200 | [diff] [blame] | 2173 | curproxy->uri_auth = defproxy.uri_auth; /* for stats */ |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 2174 | |
| 2175 | /* copy default logsrvs to curproxy */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 2176 | list_for_each_entry(tmplogsrv, &defproxy.logsrvs, list) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 2177 | struct logsrv *node = malloc(sizeof(struct logsrv)); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 2178 | memcpy(node, tmplogsrv, sizeof(struct logsrv)); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 2179 | LIST_INIT(&node->list); |
| 2180 | LIST_ADDQ(&curproxy->logsrvs, &node->list); |
| 2181 | } |
| 2182 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 2183 | curproxy->conf.uniqueid_format_string = defproxy.conf.uniqueid_format_string; |
| 2184 | if (curproxy->conf.uniqueid_format_string) |
| 2185 | curproxy->conf.uniqueid_format_string = strdup(curproxy->conf.uniqueid_format_string); |
| 2186 | |
Willy Tarreau | 094af4e | 2015-01-07 15:03:42 +0100 | [diff] [blame] | 2187 | if (defproxy.log_tag) |
| 2188 | curproxy->log_tag = strdup(defproxy.log_tag); |
| 2189 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 2190 | if (defproxy.conf.uif_file) { |
| 2191 | curproxy->conf.uif_file = strdup(defproxy.conf.uif_file); |
| 2192 | curproxy->conf.uif_line = defproxy.conf.uif_line; |
| 2193 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 2194 | |
| 2195 | /* copy default header unique id */ |
| 2196 | if (defproxy.header_unique_id) |
| 2197 | curproxy->header_unique_id = strdup(defproxy.header_unique_id); |
| 2198 | |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 2199 | /* default compression options */ |
| 2200 | if (defproxy.comp != NULL) { |
| 2201 | curproxy->comp = calloc(1, sizeof(struct comp)); |
| 2202 | curproxy->comp->algos = defproxy.comp->algos; |
| 2203 | curproxy->comp->types = defproxy.comp->types; |
| 2204 | } |
| 2205 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2206 | curproxy->grace = defproxy.grace; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2207 | curproxy->conf.used_listener_id = EB_ROOT; |
| 2208 | curproxy->conf.used_server_id = EB_ROOT; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2209 | |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 2210 | if (defproxy.check_path) |
| 2211 | curproxy->check_path = strdup(defproxy.check_path); |
| 2212 | if (defproxy.check_command) |
| 2213 | curproxy->check_command = strdup(defproxy.check_command); |
| 2214 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2215 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2216 | } |
| 2217 | else if (!strcmp(args[0], "defaults")) { /* use this one to assign default values */ |
| 2218 | /* some variables may have already been initialized earlier */ |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 2219 | /* FIXME-20070101: we should do this too at the end of the |
| 2220 | * config parsing to free all default values. |
| 2221 | */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2222 | free(defproxy.check_req); |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 2223 | free(defproxy.check_command); |
| 2224 | free(defproxy.check_path); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2225 | free(defproxy.cookie_name); |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2226 | free(defproxy.rdp_cookie_name); |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 2227 | free(defproxy.cookie_domain); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2228 | free(defproxy.url_param_name); |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 2229 | free(defproxy.hh_name); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2230 | free(defproxy.capture_name); |
| 2231 | free(defproxy.monitor_uri); |
| 2232 | free(defproxy.defbe.name); |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 2233 | free(defproxy.conn_src.iface_name); |
Willy Tarreau | 79f5fe8 | 2008-08-23 08:18:21 +0200 | [diff] [blame] | 2234 | free(defproxy.fwdfor_hdr_name); |
| 2235 | defproxy.fwdfor_hdr_len = 0; |
Willy Tarreau | b86db34 | 2009-11-30 11:50:16 +0100 | [diff] [blame] | 2236 | free(defproxy.orgto_hdr_name); |
| 2237 | defproxy.orgto_hdr_len = 0; |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 2238 | free(defproxy.server_id_hdr_name); |
| 2239 | defproxy.server_id_hdr_len = 0; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 2240 | free(defproxy.expect_str); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 2241 | if (defproxy.expect_regex) { |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 2242 | regex_free(defproxy.expect_regex); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 2243 | free(defproxy.expect_regex); |
| 2244 | defproxy.expect_regex = NULL; |
| 2245 | } |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 2246 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 2247 | if (defproxy.conf.logformat_string != default_http_log_format && |
| 2248 | defproxy.conf.logformat_string != default_tcp_log_format && |
| 2249 | defproxy.conf.logformat_string != clf_http_log_format) |
| 2250 | free(defproxy.conf.logformat_string); |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 2251 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 2252 | free(defproxy.conf.uniqueid_format_string); |
| 2253 | free(defproxy.conf.lfs_file); |
| 2254 | free(defproxy.conf.uif_file); |
Willy Tarreau | 094af4e | 2015-01-07 15:03:42 +0100 | [diff] [blame] | 2255 | free(defproxy.log_tag); |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 2256 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2257 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2258 | chunk_destroy(&defproxy.errmsg[rc]); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 2259 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2260 | /* we cannot free uri_auth because it might already be used */ |
| 2261 | init_default_instance(); |
| 2262 | curproxy = &defproxy; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 2263 | curproxy->conf.args.file = curproxy->conf.file = strdup(file); |
| 2264 | curproxy->conf.args.line = curproxy->conf.line = linenum; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2265 | defproxy.cap = PR_CAP_LISTEN; /* all caps for now */ |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2266 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2267 | } |
| 2268 | else if (curproxy == NULL) { |
| 2269 | Alert("parsing [%s:%d] : 'listen' or 'defaults' expected.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2270 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2271 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2272 | } |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 2273 | |
| 2274 | /* update the current file and line being parsed */ |
| 2275 | curproxy->conf.args.file = curproxy->conf.file; |
| 2276 | curproxy->conf.args.line = linenum; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2277 | |
| 2278 | /* Now let's parse the proxy-specific keywords */ |
Willy Tarreau | 272adea | 2014-03-31 10:39:59 +0200 | [diff] [blame] | 2279 | if (!strcmp(args[0], "server") || !strcmp(args[0], "default-server")) { |
| 2280 | err_code |= parse_server(file, linenum, args, curproxy, &defproxy); |
| 2281 | if (err_code & ERR_FATAL) |
| 2282 | goto out; |
| 2283 | } |
| 2284 | else if (!strcmp(args[0], "bind")) { /* new listen addresses */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2285 | struct listener *l; |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 2286 | int cur_arg; |
| 2287 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2288 | if (curproxy == &defproxy) { |
| 2289 | 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] | 2290 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2291 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2292 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2293 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2294 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2295 | |
Willy Tarreau | 2470928 | 2013-03-10 21:32:12 +0100 | [diff] [blame] | 2296 | if (!*(args[1])) { |
Willy Tarreau | d55c3fe | 2010-11-09 09:50:37 +0100 | [diff] [blame] | 2297 | 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] | 2298 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2299 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2300 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2301 | } |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 2302 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 2303 | bind_conf = bind_conf_alloc(&curproxy->conf.bind, file, linenum, args[1]); |
Willy Tarreau | 8dc21fa | 2013-01-24 15:17:20 +0100 | [diff] [blame] | 2304 | |
| 2305 | /* use default settings for unix sockets */ |
| 2306 | bind_conf->ux.uid = global.unix_bind.ux.uid; |
| 2307 | bind_conf->ux.gid = global.unix_bind.ux.gid; |
| 2308 | bind_conf->ux.mode = global.unix_bind.ux.mode; |
Willy Tarreau | 8a95691 | 2010-10-15 14:27:08 +0200 | [diff] [blame] | 2309 | |
| 2310 | /* NOTE: the following line might create several listeners if there |
| 2311 | * are comma-separated IPs or port ranges. So all further processing |
| 2312 | * will have to be applied to all listeners created after last_listen. |
| 2313 | */ |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 2314 | if (!str2listener(args[1], curproxy, bind_conf, file, linenum, &errmsg)) { |
| 2315 | if (errmsg && *errmsg) { |
| 2316 | indent_msg(&errmsg, 2); |
| 2317 | Alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 2318 | } |
| 2319 | else |
| 2320 | Alert("parsing [%s:%d] : '%s' : error encountered while parsing listening address '%s'.\n", |
| 2321 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2322 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2323 | goto out; |
| 2324 | } |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 2325 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2326 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
| 2327 | /* Set default global rights and owner for unix bind */ |
Willy Tarreau | c8b1109 | 2011-02-16 11:08:57 +0100 | [diff] [blame] | 2328 | global.maxsock++; |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 2329 | } |
| 2330 | |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 2331 | cur_arg = 2; |
| 2332 | while (*(args[cur_arg])) { |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 2333 | static int bind_dumped; |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 2334 | struct bind_kw *kw; |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 2335 | char *err; |
| 2336 | |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 2337 | kw = bind_find_kw(args[cur_arg]); |
| 2338 | if (kw) { |
| 2339 | char *err = NULL; |
| 2340 | int code; |
| 2341 | |
| 2342 | if (!kw->parse) { |
Willy Tarreau | dda322d | 2012-09-18 16:34:09 +0200 | [diff] [blame] | 2343 | Alert("parsing [%s:%d] : '%s %s' : '%s' option is not implemented in this version (check build options).\n", |
| 2344 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 2345 | cur_arg += 1 + kw->skip ; |
| 2346 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2347 | goto out; |
| 2348 | } |
| 2349 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2350 | code = kw->parse(args, cur_arg, curproxy, bind_conf, &err); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 2351 | err_code |= code; |
| 2352 | |
| 2353 | if (code) { |
| 2354 | if (err && *err) { |
| 2355 | indent_msg(&err, 2); |
Willy Tarreau | dda322d | 2012-09-18 16:34:09 +0200 | [diff] [blame] | 2356 | 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] | 2357 | } |
| 2358 | else |
Willy Tarreau | dda322d | 2012-09-18 16:34:09 +0200 | [diff] [blame] | 2359 | Alert("parsing [%s:%d] : '%s %s' : error encountered while processing '%s'.\n", |
| 2360 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 2361 | if (code & ERR_FATAL) { |
| 2362 | free(err); |
| 2363 | cur_arg += 1 + kw->skip; |
| 2364 | goto out; |
| 2365 | } |
| 2366 | } |
| 2367 | free(err); |
| 2368 | cur_arg += 1 + kw->skip; |
| 2369 | continue; |
| 2370 | } |
| 2371 | |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 2372 | err = NULL; |
| 2373 | if (!bind_dumped) { |
| 2374 | bind_dump_kws(&err); |
| 2375 | indent_msg(&err, 4); |
| 2376 | bind_dumped = 1; |
| 2377 | } |
| 2378 | |
| 2379 | Alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'.%s%s\n", |
| 2380 | file, linenum, args[0], args[1], args[cur_arg], |
| 2381 | err ? " Registered keywords :" : "", err ? err : ""); |
| 2382 | free(err); |
| 2383 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2384 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2385 | goto out; |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 2386 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2387 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2388 | } |
| 2389 | 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] | 2390 | 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] | 2391 | Alert("parsing [%s:%d] : '%s' expects address[/mask].\n", |
| 2392 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2393 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2394 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2395 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2396 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2397 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2398 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2399 | /* flush useless bits */ |
| 2400 | curproxy->mon_net.s_addr &= curproxy->mon_mask.s_addr; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2401 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2402 | } |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2403 | else if (!strcmp(args[0], "monitor-uri")) { /* set the URI to intercept */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2404 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2405 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2406 | |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2407 | if (!*args[1]) { |
| 2408 | Alert("parsing [%s:%d] : '%s' expects an URI.\n", |
| 2409 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2410 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2411 | goto out; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2412 | } |
| 2413 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2414 | free(curproxy->monitor_uri); |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 2415 | curproxy->monitor_uri_len = strlen(args[1]); |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2416 | curproxy->monitor_uri = (char *)calloc(1, curproxy->monitor_uri_len + 1); |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 2417 | memcpy(curproxy->monitor_uri, args[1], curproxy->monitor_uri_len); |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2418 | curproxy->monitor_uri[curproxy->monitor_uri_len] = '\0'; |
| 2419 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2420 | goto out; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2421 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2422 | else if (!strcmp(args[0], "mode")) { /* sets the proxy mode */ |
| 2423 | if (!strcmp(args[1], "http")) curproxy->mode = PR_MODE_HTTP; |
| 2424 | else if (!strcmp(args[1], "tcp")) curproxy->mode = PR_MODE_TCP; |
| 2425 | else if (!strcmp(args[1], "health")) curproxy->mode = PR_MODE_HEALTH; |
| 2426 | else { |
| 2427 | 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] | 2428 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2429 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2430 | } |
| 2431 | } |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2432 | else if (!strcmp(args[0], "id")) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2433 | struct eb32_node *node; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2434 | |
| 2435 | if (curproxy == &defproxy) { |
| 2436 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", |
| 2437 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2438 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2439 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2440 | } |
| 2441 | |
| 2442 | if (!*args[1]) { |
| 2443 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 2444 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2445 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2446 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2447 | } |
| 2448 | |
| 2449 | curproxy->uuid = atol(args[1]); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2450 | curproxy->conf.id.key = curproxy->uuid; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2451 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2452 | if (curproxy->uuid <= 0) { |
| 2453 | Alert("parsing [%s:%d]: custom id has to be > 0.\n", |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2454 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2455 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2456 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2457 | } |
| 2458 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2459 | node = eb32_lookup(&used_proxy_id, curproxy->uuid); |
| 2460 | if (node) { |
| 2461 | struct proxy *target = container_of(node, struct proxy, conf.id); |
| 2462 | Alert("parsing [%s:%d]: %s %s reuses same custom id as %s %s (declared at %s:%d).\n", |
| 2463 | file, linenum, proxy_type_str(curproxy), curproxy->id, |
| 2464 | proxy_type_str(target), target->id, target->conf.file, target->conf.line); |
| 2465 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2466 | goto out; |
| 2467 | } |
| 2468 | eb32_insert(&used_proxy_id, &curproxy->conf.id); |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2469 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 2470 | else if (!strcmp(args[0], "description")) { |
| 2471 | int i, len=0; |
| 2472 | char *d; |
| 2473 | |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 2474 | if (curproxy == &defproxy) { |
| 2475 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", |
| 2476 | file, linenum, args[0]); |
| 2477 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2478 | goto out; |
| 2479 | } |
| 2480 | |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 2481 | if (!*args[1]) { |
| 2482 | Alert("parsing [%s:%d]: '%s' expects a string argument.\n", |
| 2483 | file, linenum, args[0]); |
| 2484 | return -1; |
| 2485 | } |
| 2486 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 2487 | for (i = 1; *args[i]; i++) |
| 2488 | len += strlen(args[i]) + 1; |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 2489 | |
| 2490 | d = (char *)calloc(1, len); |
| 2491 | curproxy->desc = d; |
| 2492 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 2493 | d += snprintf(d, curproxy->desc + len - d, "%s", args[1]); |
| 2494 | for (i = 2; *args[i]; i++) |
| 2495 | d += snprintf(d, curproxy->desc + len - d, " %s", args[i]); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 2496 | |
| 2497 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2498 | else if (!strcmp(args[0], "disabled")) { /* disables this proxy */ |
| 2499 | curproxy->state = PR_STSTOPPED; |
| 2500 | } |
| 2501 | else if (!strcmp(args[0], "enabled")) { /* enables this proxy (used to revert a disabled default) */ |
| 2502 | curproxy->state = PR_STNEW; |
| 2503 | } |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2504 | else if (!strcmp(args[0], "bind-process")) { /* enable this proxy only on some processes */ |
| 2505 | int cur_arg = 1; |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 2506 | unsigned long set = 0; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2507 | |
| 2508 | while (*args[cur_arg]) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 2509 | unsigned int low, high; |
| 2510 | |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2511 | if (strcmp(args[cur_arg], "all") == 0) { |
| 2512 | set = 0; |
| 2513 | break; |
| 2514 | } |
| 2515 | else if (strcmp(args[cur_arg], "odd") == 0) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 2516 | set |= ~0UL/3UL; /* 0x555....555 */ |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2517 | } |
| 2518 | else if (strcmp(args[cur_arg], "even") == 0) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 2519 | set |= (~0UL/3UL) << 1; /* 0xAAA...AAA */ |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2520 | } |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 2521 | else if (isdigit((int)*args[cur_arg])) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 2522 | char *dash = strchr(args[cur_arg], '-'); |
| 2523 | |
| 2524 | low = high = str2uic(args[cur_arg]); |
| 2525 | if (dash) |
| 2526 | high = str2uic(dash + 1); |
| 2527 | |
| 2528 | if (high < low) { |
| 2529 | unsigned int swap = low; |
| 2530 | low = high; |
| 2531 | high = swap; |
| 2532 | } |
| 2533 | |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 2534 | if (low < 1 || high > LONGBITS) { |
| 2535 | Alert("parsing [%s:%d]: %s supports process numbers from 1 to %d.\n", |
| 2536 | file, linenum, args[0], LONGBITS); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2537 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2538 | goto out; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2539 | } |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 2540 | while (low <= high) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 2541 | set |= 1UL << (low++ - 1); |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 2542 | } |
| 2543 | else { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 2544 | Alert("parsing [%s:%d]: %s expects 'all', 'odd', 'even', or a list of process ranges with numbers from 1 to %d.\n", |
| 2545 | file, linenum, args[0], LONGBITS); |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 2546 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2547 | goto out; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2548 | } |
| 2549 | cur_arg++; |
| 2550 | } |
| 2551 | curproxy->bind_proc = set; |
| 2552 | } |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 2553 | else if (!strcmp(args[0], "acl")) { /* add an ACL */ |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2554 | if (curproxy == &defproxy) { |
| 2555 | 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] | 2556 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2557 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2558 | } |
| 2559 | |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 2560 | err = invalid_char(args[1]); |
| 2561 | if (err) { |
| 2562 | Alert("parsing [%s:%d] : character '%c' is not permitted in acl name '%s'.\n", |
| 2563 | file, linenum, *err, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2564 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 2565 | } |
| 2566 | |
Thierry FOURNIER | 0d6ba51 | 2014-02-11 03:31:34 +0100 | [diff] [blame] | 2567 | 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] | 2568 | Alert("parsing [%s:%d] : error detected while parsing ACL '%s' : %s.\n", |
| 2569 | file, linenum, args[1], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2570 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2571 | goto out; |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 2572 | } |
| 2573 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2574 | else if (!strcmp(args[0], "cookie")) { /* cookie name */ |
| 2575 | int cur_arg; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2576 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2577 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2578 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2579 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2580 | if (*(args[1]) == 0) { |
| 2581 | Alert("parsing [%s:%d] : '%s' expects <cookie_name> as argument.\n", |
| 2582 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2583 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2584 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2585 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2586 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2587 | curproxy->ck_opts = 0; |
Willy Tarreau | c63d4bb | 2010-10-23 11:37:27 +0200 | [diff] [blame] | 2588 | curproxy->cookie_maxidle = curproxy->cookie_maxlife = 0; |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 2589 | free(curproxy->cookie_domain); curproxy->cookie_domain = NULL; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2590 | free(curproxy->cookie_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2591 | curproxy->cookie_name = strdup(args[1]); |
| 2592 | curproxy->cookie_len = strlen(curproxy->cookie_name); |
Willy Tarreau | c63d4bb | 2010-10-23 11:37:27 +0200 | [diff] [blame] | 2593 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2594 | cur_arg = 2; |
| 2595 | while (*(args[cur_arg])) { |
| 2596 | if (!strcmp(args[cur_arg], "rewrite")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2597 | curproxy->ck_opts |= PR_CK_RW; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2598 | } |
| 2599 | else if (!strcmp(args[cur_arg], "indirect")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2600 | curproxy->ck_opts |= PR_CK_IND; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2601 | } |
| 2602 | else if (!strcmp(args[cur_arg], "insert")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2603 | curproxy->ck_opts |= PR_CK_INS; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2604 | } |
| 2605 | else if (!strcmp(args[cur_arg], "nocache")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2606 | curproxy->ck_opts |= PR_CK_NOC; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2607 | } |
| 2608 | else if (!strcmp(args[cur_arg], "postonly")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2609 | curproxy->ck_opts |= PR_CK_POST; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2610 | } |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 2611 | else if (!strcmp(args[cur_arg], "preserve")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2612 | curproxy->ck_opts |= PR_CK_PSV; |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 2613 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2614 | else if (!strcmp(args[cur_arg], "prefix")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2615 | curproxy->ck_opts |= PR_CK_PFX; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2616 | } |
Willy Tarreau | 4992dd2 | 2012-05-31 21:02:17 +0200 | [diff] [blame] | 2617 | else if (!strcmp(args[cur_arg], "httponly")) { |
| 2618 | curproxy->ck_opts |= PR_CK_HTTPONLY; |
| 2619 | } |
| 2620 | else if (!strcmp(args[cur_arg], "secure")) { |
| 2621 | curproxy->ck_opts |= PR_CK_SECURE; |
| 2622 | } |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2623 | else if (!strcmp(args[cur_arg], "domain")) { |
| 2624 | if (!*args[cur_arg + 1]) { |
| 2625 | Alert("parsing [%s:%d]: '%s' expects <domain> as argument.\n", |
| 2626 | file, linenum, args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2627 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2628 | goto out; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2629 | } |
| 2630 | |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 2631 | if (*args[cur_arg + 1] != '.' || !strchr(args[cur_arg + 1] + 1, '.')) { |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2632 | /* rfc2109, 4.3.2 Rejecting Cookies */ |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 2633 | Warning("parsing [%s:%d]: domain '%s' contains no embedded" |
| 2634 | " dots nor does not start with a dot." |
| 2635 | " RFC forbids it, this configuration may not work properly.\n", |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2636 | file, linenum, args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 2637 | err_code |= ERR_WARN; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2638 | } |
| 2639 | |
| 2640 | err = invalid_domainchar(args[cur_arg + 1]); |
| 2641 | if (err) { |
| 2642 | Alert("parsing [%s:%d]: character '%c' is not permitted in domain name '%s'.\n", |
| 2643 | file, linenum, *err, args[cur_arg + 1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2644 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2645 | goto out; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2646 | } |
| 2647 | |
Willy Tarreau | 68a897b | 2009-12-03 23:28:34 +0100 | [diff] [blame] | 2648 | if (!curproxy->cookie_domain) { |
| 2649 | curproxy->cookie_domain = strdup(args[cur_arg + 1]); |
| 2650 | } else { |
| 2651 | /* one domain was already specified, add another one by |
| 2652 | * building the string which will be returned along with |
| 2653 | * the cookie. |
| 2654 | */ |
| 2655 | char *new_ptr; |
| 2656 | int new_len = strlen(curproxy->cookie_domain) + |
| 2657 | strlen("; domain=") + strlen(args[cur_arg + 1]) + 1; |
| 2658 | new_ptr = malloc(new_len); |
| 2659 | snprintf(new_ptr, new_len, "%s; domain=%s", curproxy->cookie_domain, args[cur_arg+1]); |
| 2660 | free(curproxy->cookie_domain); |
| 2661 | curproxy->cookie_domain = new_ptr; |
| 2662 | } |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 2663 | cur_arg++; |
| 2664 | } |
| 2665 | else if (!strcmp(args[cur_arg], "maxidle")) { |
| 2666 | unsigned int maxidle; |
| 2667 | const char *res; |
| 2668 | |
| 2669 | if (!*args[cur_arg + 1]) { |
| 2670 | Alert("parsing [%s:%d]: '%s' expects <idletime> in seconds as argument.\n", |
| 2671 | file, linenum, args[cur_arg]); |
| 2672 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2673 | goto out; |
| 2674 | } |
| 2675 | |
| 2676 | res = parse_time_err(args[cur_arg + 1], &maxidle, TIME_UNIT_S); |
| 2677 | if (res) { |
| 2678 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 2679 | file, linenum, *res, args[cur_arg]); |
| 2680 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2681 | goto out; |
| 2682 | } |
| 2683 | curproxy->cookie_maxidle = maxidle; |
| 2684 | cur_arg++; |
| 2685 | } |
| 2686 | else if (!strcmp(args[cur_arg], "maxlife")) { |
| 2687 | unsigned int maxlife; |
| 2688 | const char *res; |
| 2689 | |
| 2690 | if (!*args[cur_arg + 1]) { |
| 2691 | Alert("parsing [%s:%d]: '%s' expects <lifetime> in seconds as argument.\n", |
| 2692 | file, linenum, args[cur_arg]); |
| 2693 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2694 | goto out; |
| 2695 | } |
| 2696 | |
| 2697 | res = parse_time_err(args[cur_arg + 1], &maxlife, TIME_UNIT_S); |
| 2698 | if (res) { |
| 2699 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 2700 | file, linenum, *res, args[cur_arg]); |
| 2701 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2702 | goto out; |
| 2703 | } |
| 2704 | curproxy->cookie_maxlife = maxlife; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2705 | cur_arg++; |
| 2706 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2707 | else { |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 2708 | 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] | 2709 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2710 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2711 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2712 | } |
| 2713 | cur_arg++; |
| 2714 | } |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2715 | if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_IND))) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2716 | Alert("parsing [%s:%d] : cookie 'rewrite' and 'indirect' modes are incompatible.\n", |
| 2717 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2718 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2719 | } |
| 2720 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2721 | 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] | 2722 | Alert("parsing [%s:%d] : cookie 'rewrite', 'insert' and 'prefix' modes are incompatible.\n", |
| 2723 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2724 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2725 | } |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 2726 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2727 | 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] | 2728 | Alert("parsing [%s:%d] : cookie 'preserve' requires at least 'insert' or 'indirect'.\n", |
| 2729 | file, linenum); |
| 2730 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2731 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2732 | }/* end else if (!strcmp(args[0], "cookie")) */ |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 2733 | else if (!strcmp(args[0], "external-check")) { |
| 2734 | if (*(args[1]) == 0) { |
| 2735 | Alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 2736 | file, linenum, args[0]); |
| 2737 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2738 | goto out; |
| 2739 | } |
| 2740 | |
| 2741 | if (!strcmp(args[1], "command")) { |
| 2742 | if (*(args[1]) == 0) { |
| 2743 | Alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 2744 | file, linenum, args[1]); |
| 2745 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2746 | goto out; |
| 2747 | } |
| 2748 | free(curproxy->check_command); |
| 2749 | curproxy->check_command = strdup(args[2]); |
| 2750 | } |
| 2751 | else if (!strcmp(args[1], "path")) { |
| 2752 | if (*(args[1]) == 0) { |
| 2753 | Alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 2754 | file, linenum, args[1]); |
| 2755 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2756 | goto out; |
| 2757 | } |
| 2758 | free(curproxy->check_path); |
| 2759 | curproxy->check_path = strdup(args[2]); |
| 2760 | } |
| 2761 | else { |
| 2762 | Alert("parsing [%s:%d] : external-check: unknown argument '%s'.\n", |
| 2763 | file, linenum, args[1]); |
| 2764 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2765 | goto out; |
| 2766 | } |
| 2767 | }/* end else if (!strcmp(args[0], "external-check")) */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2768 | else if (!strcmp(args[0], "persist")) { /* persist */ |
| 2769 | if (*(args[1]) == 0) { |
| 2770 | Alert("parsing [%s:%d] : missing persist method.\n", |
| 2771 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2772 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2773 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2774 | } |
| 2775 | |
| 2776 | if (!strncmp(args[1], "rdp-cookie", 10)) { |
| 2777 | curproxy->options2 |= PR_O2_RDPC_PRST; |
| 2778 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2779 | if (*(args[1] + 10) == '(') { /* cookie name */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2780 | const char *beg, *end; |
| 2781 | |
| 2782 | beg = args[1] + 11; |
| 2783 | end = strchr(beg, ')'); |
| 2784 | |
| 2785 | if (!end || end == beg) { |
| 2786 | Alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n", |
| 2787 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2788 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2789 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2790 | } |
| 2791 | |
| 2792 | free(curproxy->rdp_cookie_name); |
| 2793 | curproxy->rdp_cookie_name = my_strndup(beg, end - beg); |
| 2794 | curproxy->rdp_cookie_len = end-beg; |
| 2795 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2796 | else if (*(args[1] + 10) == '\0') { /* default cookie name 'msts' */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2797 | free(curproxy->rdp_cookie_name); |
| 2798 | curproxy->rdp_cookie_name = strdup("msts"); |
| 2799 | curproxy->rdp_cookie_len = strlen(curproxy->rdp_cookie_name); |
| 2800 | } |
| 2801 | else { /* syntax */ |
| 2802 | Alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n", |
| 2803 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2804 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2805 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2806 | } |
| 2807 | } |
| 2808 | else { |
| 2809 | Alert("parsing [%s:%d] : unknown persist method.\n", |
| 2810 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2811 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2812 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2813 | } |
| 2814 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2815 | else if (!strcmp(args[0], "appsession")) { /* cookie name */ |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2816 | int cur_arg; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2817 | |
Cyril Bonté | 3b7a369 | 2010-01-10 17:01:47 +0100 | [diff] [blame] | 2818 | if (curproxy == &defproxy) { |
| 2819 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2820 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2821 | goto out; |
| 2822 | } |
| 2823 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2824 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2825 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2826 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2827 | if (*(args[5]) == 0) { |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2828 | 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] | 2829 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2830 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2831 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2832 | } |
| 2833 | have_appsession = 1; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2834 | free(curproxy->appsession_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2835 | curproxy->appsession_name = strdup(args[1]); |
| 2836 | curproxy->appsession_name_len = strlen(curproxy->appsession_name); |
| 2837 | curproxy->appsession_len = atoi(args[3]); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 2838 | err = parse_time_err(args[5], &val, TIME_UNIT_MS); |
| 2839 | if (err) { |
| 2840 | Alert("parsing [%s:%d] : unexpected character '%c' in %s timeout.\n", |
| 2841 | file, linenum, *err, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2842 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2843 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 2844 | } |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 2845 | curproxy->timeout.appsession = val; |
Willy Tarreau | ee99136 | 2007-05-14 14:37:50 +0200 | [diff] [blame] | 2846 | |
Willy Tarreau | 51041c7 | 2007-09-09 21:56:53 +0200 | [diff] [blame] | 2847 | if (appsession_hash_init(&(curproxy->htbl_proxy), destroy) == 0) { |
| 2848 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2849 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2850 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2851 | } |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2852 | |
| 2853 | cur_arg = 6; |
| 2854 | curproxy->options2 &= ~PR_O2_AS_REQL; |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2855 | curproxy->options2 &= ~PR_O2_AS_M_ANY; |
| 2856 | curproxy->options2 |= PR_O2_AS_M_PP; |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2857 | while (*(args[cur_arg])) { |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2858 | if (!strcmp(args[cur_arg], "request-learn")) { |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2859 | curproxy->options2 |= PR_O2_AS_REQL; |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2860 | } else if (!strcmp(args[cur_arg], "prefix")) { |
| 2861 | curproxy->options2 |= PR_O2_AS_PFX; |
| 2862 | } else if (!strcmp(args[cur_arg], "mode")) { |
| 2863 | if (!*args[cur_arg + 1]) { |
| 2864 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 2865 | file, linenum, args[0], args[cur_arg]); |
| 2866 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2867 | goto out; |
| 2868 | } |
| 2869 | |
| 2870 | cur_arg++; |
| 2871 | if (!strcmp(args[cur_arg], "query-string")) { |
| 2872 | curproxy->options2 &= ~PR_O2_AS_M_ANY; |
| 2873 | curproxy->options2 |= PR_O2_AS_M_QS; |
| 2874 | } else if (!strcmp(args[cur_arg], "path-parameters")) { |
| 2875 | curproxy->options2 &= ~PR_O2_AS_M_ANY; |
| 2876 | curproxy->options2 |= PR_O2_AS_M_PP; |
| 2877 | } else { |
| 2878 | Alert("parsing [%s:%d] : unknown mode '%s'\n", file, linenum, args[cur_arg]); |
| 2879 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2880 | goto out; |
| 2881 | } |
| 2882 | } |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2883 | cur_arg++; |
| 2884 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2885 | } /* Url App Session */ |
| 2886 | else if (!strcmp(args[0], "capture")) { |
Willy Tarreau | 3b6b1a9 | 2009-07-23 13:24:23 +0200 | [diff] [blame] | 2887 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2888 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2889 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2890 | if (!strcmp(args[1], "cookie")) { /* name of a cookie to capture */ |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 2891 | if (curproxy == &defproxy) { |
| 2892 | Alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
| 2893 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2894 | goto out; |
| 2895 | } |
| 2896 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2897 | if (*(args[4]) == 0) { |
| 2898 | Alert("parsing [%s:%d] : '%s' expects 'cookie' <cookie_name> 'len' <len>.\n", |
| 2899 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2900 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2901 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2902 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2903 | free(curproxy->capture_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2904 | curproxy->capture_name = strdup(args[2]); |
| 2905 | curproxy->capture_namelen = strlen(curproxy->capture_name); |
| 2906 | curproxy->capture_len = atol(args[4]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2907 | curproxy->to_log |= LW_COOKIE; |
| 2908 | } |
| 2909 | else if (!strcmp(args[1], "request") && !strcmp(args[2], "header")) { |
| 2910 | struct cap_hdr *hdr; |
| 2911 | |
| 2912 | if (curproxy == &defproxy) { |
| 2913 | 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] | 2914 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2915 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2916 | } |
| 2917 | |
| 2918 | if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) { |
| 2919 | Alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n", |
| 2920 | file, linenum, args[0], args[1]); |
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 | |
| 2925 | hdr = calloc(sizeof(struct cap_hdr), 1); |
| 2926 | hdr->next = curproxy->req_cap; |
| 2927 | hdr->name = strdup(args[3]); |
| 2928 | hdr->namelen = strlen(args[3]); |
| 2929 | hdr->len = atol(args[5]); |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 2930 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2931 | hdr->index = curproxy->nb_req_cap++; |
| 2932 | curproxy->req_cap = hdr; |
| 2933 | curproxy->to_log |= LW_REQHDR; |
| 2934 | } |
| 2935 | else if (!strcmp(args[1], "response") && !strcmp(args[2], "header")) { |
| 2936 | struct cap_hdr *hdr; |
| 2937 | |
| 2938 | if (curproxy == &defproxy) { |
| 2939 | 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] | 2940 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2941 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2942 | } |
| 2943 | |
| 2944 | if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) { |
| 2945 | Alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n", |
| 2946 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2947 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2948 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2949 | } |
| 2950 | hdr = calloc(sizeof(struct cap_hdr), 1); |
| 2951 | hdr->next = curproxy->rsp_cap; |
| 2952 | hdr->name = strdup(args[3]); |
| 2953 | hdr->namelen = strlen(args[3]); |
| 2954 | hdr->len = atol(args[5]); |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 2955 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2956 | hdr->index = curproxy->nb_rsp_cap++; |
| 2957 | curproxy->rsp_cap = hdr; |
| 2958 | curproxy->to_log |= LW_RSPHDR; |
| 2959 | } |
| 2960 | else { |
| 2961 | Alert("parsing [%s:%d] : '%s' expects 'cookie' or 'request header' or 'response header'.\n", |
| 2962 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2963 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2964 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2965 | } |
| 2966 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2967 | else if (!strcmp(args[0], "retries")) { /* connection retries */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2968 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2969 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2970 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2971 | if (*(args[1]) == 0) { |
| 2972 | Alert("parsing [%s:%d] : '%s' expects an integer argument (dispatch counts for one).\n", |
| 2973 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2974 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2975 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2976 | } |
| 2977 | curproxy->conn_retries = atol(args[1]); |
| 2978 | } |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2979 | 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] | 2980 | struct http_req_rule *rule; |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2981 | |
| 2982 | if (curproxy == &defproxy) { |
| 2983 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2984 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2985 | goto out; |
| 2986 | } |
| 2987 | |
Willy Tarreau | 20b0de5 | 2012-12-24 15:45:22 +0100 | [diff] [blame] | 2988 | if (!LIST_ISEMPTY(&curproxy->http_req_rules) && |
| 2989 | !LIST_PREV(&curproxy->http_req_rules, struct http_req_rule *, list)->cond && |
| 2990 | (LIST_PREV(&curproxy->http_req_rules, struct http_req_rule *, list)->action == HTTP_REQ_ACT_ALLOW || |
| 2991 | 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] | 2992 | 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] | 2993 | LIST_PREV(&curproxy->http_req_rules, struct http_req_rule *, list)->action == HTTP_REQ_ACT_AUTH)) { |
| 2994 | 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] | 2995 | file, linenum, args[0]); |
| 2996 | err_code |= ERR_WARN; |
| 2997 | } |
| 2998 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 2999 | 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] | 3000 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3001 | if (!rule) { |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 3002 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3003 | goto out; |
| 3004 | } |
| 3005 | |
Willy Tarreau | 5002f57 | 2014-04-23 01:32:02 +0200 | [diff] [blame] | 3006 | err_code |= warnif_misplaced_http_req(curproxy, file, linenum, args[0]); |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3007 | err_code |= warnif_cond_conflicts(rule->cond, |
| 3008 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 3009 | file, linenum); |
| 3010 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3011 | LIST_ADDQ(&curproxy->http_req_rules, &rule->list); |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 3012 | } |
Willy Tarreau | e365c0b | 2013-06-11 16:06:12 +0200 | [diff] [blame] | 3013 | else if (!strcmp(args[0], "http-response")) { /* response access control */ |
| 3014 | struct http_res_rule *rule; |
| 3015 | |
| 3016 | if (curproxy == &defproxy) { |
| 3017 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3018 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3019 | goto out; |
| 3020 | } |
| 3021 | |
| 3022 | if (!LIST_ISEMPTY(&curproxy->http_res_rules) && |
| 3023 | !LIST_PREV(&curproxy->http_res_rules, struct http_res_rule *, list)->cond && |
| 3024 | (LIST_PREV(&curproxy->http_res_rules, struct http_res_rule *, list)->action == HTTP_RES_ACT_ALLOW || |
| 3025 | LIST_PREV(&curproxy->http_res_rules, struct http_res_rule *, list)->action == HTTP_RES_ACT_DENY)) { |
| 3026 | Warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n", |
| 3027 | file, linenum, args[0]); |
| 3028 | err_code |= ERR_WARN; |
| 3029 | } |
| 3030 | |
| 3031 | rule = parse_http_res_cond((const char **)args + 1, file, linenum, curproxy); |
| 3032 | |
| 3033 | if (!rule) { |
| 3034 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3035 | goto out; |
| 3036 | } |
| 3037 | |
| 3038 | err_code |= warnif_cond_conflicts(rule->cond, |
| 3039 | (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR, |
| 3040 | file, linenum); |
| 3041 | |
| 3042 | LIST_ADDQ(&curproxy->http_res_rules, &rule->list); |
| 3043 | } |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 3044 | else if (!strcmp(args[0], "http-send-name-header")) { /* send server name in request header */ |
| 3045 | /* set the header name and length into the proxy structure */ |
| 3046 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 3047 | err_code |= ERR_WARN; |
| 3048 | |
| 3049 | if (!*args[1]) { |
| 3050 | Alert("parsing [%s:%d] : '%s' requires a header string.\n", |
| 3051 | file, linenum, args[0]); |
| 3052 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3053 | goto out; |
| 3054 | } |
| 3055 | |
| 3056 | /* set the desired header name */ |
| 3057 | free(curproxy->server_id_hdr_name); |
| 3058 | curproxy->server_id_hdr_name = strdup(args[1]); |
| 3059 | curproxy->server_id_hdr_len = strlen(curproxy->server_id_hdr_name); |
| 3060 | } |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 3061 | else if (!strcmp(args[0], "block")) { /* early blocking based on ACLs */ |
Willy Tarreau | b3dc39d | 2014-04-28 22:06:57 +0200 | [diff] [blame] | 3062 | struct http_req_rule *rule; |
| 3063 | |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3064 | if (curproxy == &defproxy) { |
| 3065 | 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] | 3066 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3067 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3068 | } |
| 3069 | |
Willy Tarreau | b3dc39d | 2014-04-28 22:06:57 +0200 | [diff] [blame] | 3070 | /* emulate "block" using "http-request block". Since these rules are supposed to |
| 3071 | * be processed before all http-request rules, we put them into their own list |
| 3072 | * and will insert them at the end. |
| 3073 | */ |
| 3074 | rule = parse_http_req_cond((const char **)args, file, linenum, curproxy); |
| 3075 | if (!rule) { |
| 3076 | err_code |= ERR_ALERT | ERR_ABORT; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3077 | goto out; |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 3078 | } |
Willy Tarreau | b3dc39d | 2014-04-28 22:06:57 +0200 | [diff] [blame] | 3079 | err_code |= warnif_misplaced_block(curproxy, file, linenum, args[0]); |
| 3080 | err_code |= warnif_cond_conflicts(rule->cond, |
| 3081 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 3082 | file, linenum); |
| 3083 | LIST_ADDQ(&curproxy->block_rules, &rule->list); |
Willy Tarreau | de9d2d7 | 2014-04-28 22:28:02 +0200 | [diff] [blame] | 3084 | |
| 3085 | if (!already_warned(WARN_BLOCK_DEPRECATED)) |
| 3086 | 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]); |
| 3087 | |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 3088 | } |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3089 | else if (!strcmp(args[0], "redirect")) { |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3090 | struct redirect_rule *rule; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3091 | |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 3092 | if (curproxy == &defproxy) { |
| 3093 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3094 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3095 | goto out; |
| 3096 | } |
| 3097 | |
Thierry FOURNIER | d18cd0f | 2013-11-29 12:15:45 +0100 | [diff] [blame] | 3098 | 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] | 3099 | Alert("parsing [%s:%d] : error detected in %s '%s' while parsing redirect rule : %s.\n", |
| 3100 | file, linenum, proxy_type_str(curproxy), curproxy->id, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3101 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3102 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3103 | } |
| 3104 | |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3105 | LIST_ADDQ(&curproxy->redirect_rules, &rule->list); |
Willy Tarreau | ee445d9 | 2014-04-23 01:39:04 +0200 | [diff] [blame] | 3106 | err_code |= warnif_misplaced_redirect(curproxy, file, linenum, args[0]); |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3107 | err_code |= warnif_cond_conflicts(rule->cond, |
| 3108 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 3109 | file, linenum); |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3110 | } |
Krzysztof Piotr Oledzki | 7b723ef | 2009-01-27 21:09:41 +0100 | [diff] [blame] | 3111 | else if (!strcmp(args[0], "use_backend")) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3112 | struct switching_rule *rule; |
| 3113 | |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3114 | if (curproxy == &defproxy) { |
| 3115 | 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] | 3116 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3117 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3118 | } |
| 3119 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3120 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3121 | err_code |= ERR_WARN; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3122 | |
| 3123 | if (*(args[1]) == 0) { |
| 3124 | 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] | 3125 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3126 | goto out; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3127 | } |
| 3128 | |
Willy Tarreau | f51658d | 2014-04-23 01:21:56 +0200 | [diff] [blame] | 3129 | if (strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0) { |
| 3130 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 3131 | Alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n", |
| 3132 | file, linenum, errmsg); |
| 3133 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3134 | goto out; |
| 3135 | } |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3136 | |
Willy Tarreau | f51658d | 2014-04-23 01:21:56 +0200 | [diff] [blame] | 3137 | 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] | 3138 | } |
| 3139 | |
| 3140 | rule = (struct switching_rule *)calloc(1, sizeof(*rule)); |
| 3141 | rule->cond = cond; |
| 3142 | rule->be.name = strdup(args[1]); |
| 3143 | LIST_INIT(&rule->list); |
| 3144 | LIST_ADDQ(&curproxy->switching_rules, &rule->list); |
| 3145 | } |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 3146 | else if (strcmp(args[0], "use-server") == 0) { |
| 3147 | struct server_rule *rule; |
| 3148 | |
| 3149 | if (curproxy == &defproxy) { |
| 3150 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3151 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3152 | goto out; |
| 3153 | } |
| 3154 | |
| 3155 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 3156 | err_code |= ERR_WARN; |
| 3157 | |
| 3158 | if (*(args[1]) == 0) { |
| 3159 | Alert("parsing [%s:%d] : '%s' expects a server name.\n", file, linenum, args[0]); |
| 3160 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3161 | goto out; |
| 3162 | } |
| 3163 | |
| 3164 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
| 3165 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 3166 | file, linenum, args[0]); |
| 3167 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3168 | goto out; |
| 3169 | } |
| 3170 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 3171 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 3172 | Alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n", |
| 3173 | file, linenum, errmsg); |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 3174 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3175 | goto out; |
| 3176 | } |
| 3177 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3178 | 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] | 3179 | |
| 3180 | rule = (struct server_rule *)calloc(1, sizeof(*rule)); |
| 3181 | rule->cond = cond; |
| 3182 | rule->srv.name = strdup(args[1]); |
| 3183 | LIST_INIT(&rule->list); |
| 3184 | LIST_ADDQ(&curproxy->server_rules, &rule->list); |
| 3185 | curproxy->be_req_ana |= AN_REQ_SRV_RULES; |
| 3186 | } |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 3187 | else if ((!strcmp(args[0], "force-persist")) || |
| 3188 | (!strcmp(args[0], "ignore-persist"))) { |
| 3189 | struct persist_rule *rule; |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 3190 | |
| 3191 | if (curproxy == &defproxy) { |
| 3192 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3193 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3194 | goto out; |
| 3195 | } |
| 3196 | |
| 3197 | if (warnifnotcap(curproxy, PR_CAP_FE|PR_CAP_BE, file, linenum, args[0], NULL)) |
| 3198 | err_code |= ERR_WARN; |
| 3199 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 3200 | if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) { |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 3201 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 3202 | file, linenum, args[0]); |
| 3203 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3204 | goto out; |
| 3205 | } |
| 3206 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 3207 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 1, &errmsg)) == NULL) { |
| 3208 | Alert("parsing [%s:%d] : error detected while parsing a '%s' rule : %s.\n", |
| 3209 | file, linenum, args[0], errmsg); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 3210 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3211 | goto out; |
| 3212 | } |
| 3213 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3214 | /* note: BE_REQ_CNT is the first one after FE_SET_BCK, which is |
| 3215 | * where force-persist is applied. |
| 3216 | */ |
| 3217 | 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] | 3218 | |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 3219 | rule = (struct persist_rule *)calloc(1, sizeof(*rule)); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 3220 | rule->cond = cond; |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 3221 | if (!strcmp(args[0], "force-persist")) { |
| 3222 | rule->type = PERSIST_TYPE_FORCE; |
| 3223 | } else { |
| 3224 | rule->type = PERSIST_TYPE_IGNORE; |
| 3225 | } |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 3226 | LIST_INIT(&rule->list); |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 3227 | LIST_ADDQ(&curproxy->persist_rules, &rule->list); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 3228 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3229 | else if (!strcmp(args[0], "stick-table")) { |
| 3230 | int myidx = 1; |
| 3231 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 3232 | curproxy->table.id = curproxy->id; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3233 | curproxy->table.type = (unsigned int)-1; |
| 3234 | while (*args[myidx]) { |
| 3235 | const char *err; |
| 3236 | |
| 3237 | if (strcmp(args[myidx], "size") == 0) { |
| 3238 | myidx++; |
| 3239 | if (!*(args[myidx])) { |
| 3240 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 3241 | file, linenum, args[myidx-1]); |
| 3242 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3243 | goto out; |
| 3244 | } |
| 3245 | if ((err = parse_size_err(args[myidx], &curproxy->table.size))) { |
| 3246 | Alert("parsing [%s:%d] : stick-table: unexpected character '%c' in argument of '%s'.\n", |
| 3247 | file, linenum, *err, args[myidx-1]); |
| 3248 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3249 | goto out; |
| 3250 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 3251 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3252 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 3253 | else if (strcmp(args[myidx], "peers") == 0) { |
| 3254 | myidx++; |
Godbach | 5052316 | 2013-12-11 19:48:57 +0800 | [diff] [blame] | 3255 | if (!*(args[myidx])) { |
Godbach | ff11554 | 2014-04-21 21:52:23 +0800 | [diff] [blame] | 3256 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 3257 | file, linenum, args[myidx-1]); |
| 3258 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3259 | goto out; |
Godbach | 5052316 | 2013-12-11 19:48:57 +0800 | [diff] [blame] | 3260 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 3261 | curproxy->table.peers.name = strdup(args[myidx++]); |
| 3262 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3263 | else if (strcmp(args[myidx], "expire") == 0) { |
| 3264 | myidx++; |
| 3265 | if (!*(args[myidx])) { |
| 3266 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 3267 | file, linenum, args[myidx-1]); |
| 3268 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3269 | goto out; |
| 3270 | } |
| 3271 | err = parse_time_err(args[myidx], &val, TIME_UNIT_MS); |
| 3272 | if (err) { |
| 3273 | Alert("parsing [%s:%d] : stick-table: unexpected character '%c' in argument of '%s'.\n", |
| 3274 | file, linenum, *err, args[myidx-1]); |
| 3275 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3276 | goto out; |
| 3277 | } |
| 3278 | curproxy->table.expire = val; |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 3279 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3280 | } |
| 3281 | else if (strcmp(args[myidx], "nopurge") == 0) { |
| 3282 | curproxy->table.nopurge = 1; |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 3283 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3284 | } |
| 3285 | else if (strcmp(args[myidx], "type") == 0) { |
| 3286 | myidx++; |
| 3287 | if (stktable_parse_type(args, &myidx, &curproxy->table.type, &curproxy->table.key_size) != 0) { |
| 3288 | Alert("parsing [%s:%d] : stick-table: unknown type '%s'.\n", |
| 3289 | file, linenum, args[myidx]); |
| 3290 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3291 | goto out; |
| 3292 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 3293 | /* myidx already points to next arg */ |
| 3294 | } |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 3295 | else if (strcmp(args[myidx], "store") == 0) { |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 3296 | int type, err; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 3297 | char *cw, *nw, *sa; |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 3298 | |
| 3299 | myidx++; |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 3300 | nw = args[myidx]; |
| 3301 | while (*nw) { |
| 3302 | /* the "store" keyword supports a comma-separated list */ |
| 3303 | cw = nw; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 3304 | sa = NULL; /* store arg */ |
| 3305 | while (*nw && *nw != ',') { |
| 3306 | if (*nw == '(') { |
| 3307 | *nw = 0; |
| 3308 | sa = ++nw; |
| 3309 | while (*nw != ')') { |
| 3310 | if (!*nw) { |
| 3311 | Alert("parsing [%s:%d] : %s: missing closing parenthesis after store option '%s'.\n", |
| 3312 | file, linenum, args[0], cw); |
| 3313 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3314 | goto out; |
| 3315 | } |
| 3316 | nw++; |
| 3317 | } |
| 3318 | *nw = '\0'; |
| 3319 | } |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 3320 | nw++; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 3321 | } |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 3322 | if (*nw) |
| 3323 | *nw++ = '\0'; |
| 3324 | type = stktable_get_data_type(cw); |
| 3325 | if (type < 0) { |
| 3326 | Alert("parsing [%s:%d] : %s: unknown store option '%s'.\n", |
| 3327 | file, linenum, args[0], cw); |
| 3328 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3329 | goto out; |
| 3330 | } |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 3331 | |
| 3332 | err = stktable_alloc_data_type(&curproxy->table, type, sa); |
| 3333 | switch (err) { |
| 3334 | case PE_NONE: break; |
| 3335 | case PE_EXIST: |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 3336 | Warning("parsing [%s:%d]: %s: store option '%s' already enabled, ignored.\n", |
| 3337 | file, linenum, args[0], cw); |
| 3338 | err_code |= ERR_WARN; |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 3339 | break; |
| 3340 | |
| 3341 | case PE_ARG_MISSING: |
| 3342 | Alert("parsing [%s:%d] : %s: missing argument to store option '%s'.\n", |
| 3343 | file, linenum, args[0], cw); |
| 3344 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3345 | goto out; |
| 3346 | |
| 3347 | case PE_ARG_NOT_USED: |
| 3348 | Alert("parsing [%s:%d] : %s: unexpected argument to store option '%s'.\n", |
| 3349 | file, linenum, args[0], cw); |
| 3350 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3351 | goto out; |
| 3352 | |
| 3353 | default: |
| 3354 | Alert("parsing [%s:%d] : %s: error when processing store option '%s'.\n", |
| 3355 | file, linenum, args[0], cw); |
| 3356 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3357 | goto out; |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 3358 | } |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 3359 | } |
| 3360 | myidx++; |
| 3361 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 3362 | else { |
| 3363 | Alert("parsing [%s:%d] : stick-table: unknown argument '%s'.\n", |
| 3364 | file, linenum, args[myidx]); |
| 3365 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3366 | goto out; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3367 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3368 | } |
| 3369 | |
| 3370 | if (!curproxy->table.size) { |
| 3371 | Alert("parsing [%s:%d] : stick-table: missing size.\n", |
| 3372 | file, linenum); |
| 3373 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3374 | goto out; |
| 3375 | } |
| 3376 | |
| 3377 | if (curproxy->table.type == (unsigned int)-1) { |
| 3378 | Alert("parsing [%s:%d] : stick-table: missing type.\n", |
| 3379 | file, linenum); |
| 3380 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3381 | goto out; |
| 3382 | } |
| 3383 | } |
| 3384 | else if (!strcmp(args[0], "stick")) { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3385 | struct sticking_rule *rule; |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 3386 | struct sample_expr *expr; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3387 | int myidx = 0; |
| 3388 | const char *name = NULL; |
| 3389 | int flags; |
| 3390 | |
| 3391 | if (curproxy == &defproxy) { |
| 3392 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3393 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3394 | goto out; |
| 3395 | } |
| 3396 | |
| 3397 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) { |
| 3398 | err_code |= ERR_WARN; |
| 3399 | goto out; |
| 3400 | } |
| 3401 | |
| 3402 | myidx++; |
| 3403 | if ((strcmp(args[myidx], "store") == 0) || |
| 3404 | (strcmp(args[myidx], "store-request") == 0)) { |
| 3405 | myidx++; |
| 3406 | flags = STK_IS_STORE; |
| 3407 | } |
| 3408 | else if (strcmp(args[myidx], "store-response") == 0) { |
| 3409 | myidx++; |
| 3410 | flags = STK_IS_STORE | STK_ON_RSP; |
| 3411 | } |
| 3412 | else if (strcmp(args[myidx], "match") == 0) { |
| 3413 | myidx++; |
| 3414 | flags = STK_IS_MATCH; |
| 3415 | } |
| 3416 | else if (strcmp(args[myidx], "on") == 0) { |
| 3417 | myidx++; |
| 3418 | flags = STK_IS_MATCH | STK_IS_STORE; |
| 3419 | } |
| 3420 | else { |
| 3421 | Alert("parsing [%s:%d] : '%s' expects 'on', 'match', or 'store'.\n", file, linenum, args[0]); |
| 3422 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3423 | goto out; |
| 3424 | } |
| 3425 | |
| 3426 | if (*(args[myidx]) == 0) { |
| 3427 | Alert("parsing [%s:%d] : '%s' expects a fetch method.\n", file, linenum, args[0]); |
| 3428 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3429 | goto out; |
| 3430 | } |
| 3431 | |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 3432 | curproxy->conf.args.ctx = ARGC_STK; |
Thierry FOURNIER | eeaa951 | 2014-02-11 14:00:19 +0100 | [diff] [blame] | 3433 | expr = sample_parse_expr(args, &myidx, file, linenum, &errmsg, &curproxy->conf.args); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3434 | if (!expr) { |
Willy Tarreau | 975c178 | 2013-12-12 23:16:54 +0100 | [diff] [blame] | 3435 | Alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3436 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3437 | goto out; |
| 3438 | } |
| 3439 | |
| 3440 | if (flags & STK_ON_RSP) { |
Willy Tarreau | 80aca90 | 2013-01-07 15:42:20 +0100 | [diff] [blame] | 3441 | if (!(expr->fetch->val & SMP_VAL_BE_STO_RUL)) { |
| 3442 | Alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available for 'store-response'.\n", |
| 3443 | 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] | 3444 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 3445 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3446 | goto out; |
| 3447 | } |
| 3448 | } else { |
Willy Tarreau | 80aca90 | 2013-01-07 15:42:20 +0100 | [diff] [blame] | 3449 | if (!(expr->fetch->val & SMP_VAL_BE_SET_SRV)) { |
| 3450 | Alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available during request.\n", |
| 3451 | 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] | 3452 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 3453 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3454 | goto out; |
| 3455 | } |
| 3456 | } |
| 3457 | |
Willy Tarreau | 1b6c00c | 2012-10-05 22:41:26 +0200 | [diff] [blame] | 3458 | /* 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] | 3459 | curproxy->http_needed |= !!(expr->fetch->use & SMP_USE_HTTP_ANY); |
Willy Tarreau | 1b6c00c | 2012-10-05 22:41:26 +0200 | [diff] [blame] | 3460 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3461 | if (strcmp(args[myidx], "table") == 0) { |
| 3462 | myidx++; |
| 3463 | name = args[myidx++]; |
| 3464 | } |
| 3465 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 3466 | if (strcmp(args[myidx], "if") == 0 || strcmp(args[myidx], "unless") == 0) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 3467 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + myidx, &errmsg)) == NULL) { |
| 3468 | Alert("parsing [%s:%d] : '%s': error detected while parsing sticking condition : %s.\n", |
| 3469 | file, linenum, args[0], errmsg); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3470 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 3471 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3472 | goto out; |
| 3473 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3474 | } |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 3475 | else if (*(args[myidx])) { |
| 3476 | Alert("parsing [%s:%d] : '%s': unknown keyword '%s'.\n", |
| 3477 | file, linenum, args[0], args[myidx]); |
| 3478 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 3479 | free(expr); |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 3480 | goto out; |
| 3481 | } |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 3482 | if (flags & STK_ON_RSP) |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3483 | 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] | 3484 | else |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3485 | 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] | 3486 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3487 | rule = (struct sticking_rule *)calloc(1, sizeof(*rule)); |
| 3488 | rule->cond = cond; |
| 3489 | rule->expr = expr; |
| 3490 | rule->flags = flags; |
| 3491 | rule->table.name = name ? strdup(name) : NULL; |
| 3492 | LIST_INIT(&rule->list); |
| 3493 | if (flags & STK_ON_RSP) |
| 3494 | LIST_ADDQ(&curproxy->storersp_rules, &rule->list); |
| 3495 | else |
| 3496 | LIST_ADDQ(&curproxy->sticking_rules, &rule->list); |
| 3497 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3498 | else if (!strcmp(args[0], "stats")) { |
| 3499 | if (curproxy != &defproxy && curproxy->uri_auth == defproxy.uri_auth) |
| 3500 | curproxy->uri_auth = NULL; /* we must detach from the default config */ |
| 3501 | |
Krzysztof Piotr Oledzki | 260a3bb | 2010-01-06 16:25:05 +0100 | [diff] [blame] | 3502 | if (!*args[1]) { |
| 3503 | goto stats_error_parsing; |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3504 | } else if (!strcmp(args[1], "admin")) { |
| 3505 | struct stats_admin_rule *rule; |
| 3506 | |
| 3507 | if (curproxy == &defproxy) { |
| 3508 | Alert("parsing [%s:%d]: '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
| 3509 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3510 | goto out; |
| 3511 | } |
| 3512 | |
| 3513 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 3514 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3515 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3516 | goto out; |
| 3517 | } |
| 3518 | |
| 3519 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
| 3520 | Alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n", |
| 3521 | file, linenum, args[0], args[1]); |
| 3522 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3523 | goto out; |
| 3524 | } |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 3525 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 3526 | Alert("parsing [%s:%d] : error detected while parsing a '%s %s' rule : %s.\n", |
| 3527 | file, linenum, args[0], args[1], errmsg); |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3528 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3529 | goto out; |
| 3530 | } |
| 3531 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3532 | err_code |= warnif_cond_conflicts(cond, |
| 3533 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 3534 | file, linenum); |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3535 | |
| 3536 | rule = (struct stats_admin_rule *)calloc(1, sizeof(*rule)); |
| 3537 | rule->cond = cond; |
| 3538 | LIST_INIT(&rule->list); |
| 3539 | LIST_ADDQ(&curproxy->uri_auth->admin_rules, &rule->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3540 | } else if (!strcmp(args[1], "uri")) { |
| 3541 | if (*(args[2]) == 0) { |
| 3542 | Alert("parsing [%s:%d] : 'uri' needs an URI prefix.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3543 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3544 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3545 | } else if (!stats_set_uri(&curproxy->uri_auth, args[2])) { |
| 3546 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3547 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3548 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3549 | } |
| 3550 | } else if (!strcmp(args[1], "realm")) { |
| 3551 | if (*(args[2]) == 0) { |
| 3552 | Alert("parsing [%s:%d] : 'realm' needs an realm name.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3553 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3554 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3555 | } else if (!stats_set_realm(&curproxy->uri_auth, args[2])) { |
| 3556 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3557 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3558 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3559 | } |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 3560 | } else if (!strcmp(args[1], "refresh")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 3561 | unsigned interval; |
| 3562 | |
| 3563 | err = parse_time_err(args[2], &interval, TIME_UNIT_S); |
| 3564 | if (err) { |
| 3565 | Alert("parsing [%s:%d] : unexpected character '%c' in stats refresh interval.\n", |
| 3566 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3567 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3568 | goto out; |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 3569 | } else if (!stats_set_refresh(&curproxy->uri_auth, interval)) { |
| 3570 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3571 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3572 | goto out; |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 3573 | } |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3574 | } 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] | 3575 | struct http_req_rule *rule; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3576 | |
| 3577 | if (curproxy == &defproxy) { |
| 3578 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3579 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3580 | goto out; |
| 3581 | } |
| 3582 | |
| 3583 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 3584 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3585 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3586 | goto out; |
| 3587 | } |
| 3588 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3589 | if (!LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) && |
| 3590 | !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] | 3591 | Warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n", |
| 3592 | file, linenum, args[0]); |
| 3593 | err_code |= ERR_WARN; |
| 3594 | } |
| 3595 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3596 | 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] | 3597 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3598 | if (!rule) { |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3599 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3600 | goto out; |
| 3601 | } |
| 3602 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3603 | err_code |= warnif_cond_conflicts(rule->cond, |
| 3604 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 3605 | file, linenum); |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3606 | LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list); |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3607 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3608 | } else if (!strcmp(args[1], "auth")) { |
| 3609 | if (*(args[2]) == 0) { |
| 3610 | 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] | 3611 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3612 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3613 | } else if (!stats_add_auth(&curproxy->uri_auth, args[2])) { |
| 3614 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3615 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3616 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3617 | } |
| 3618 | } else if (!strcmp(args[1], "scope")) { |
| 3619 | if (*(args[2]) == 0) { |
| 3620 | Alert("parsing [%s:%d] : 'scope' needs a proxy name.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3621 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3622 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3623 | } else if (!stats_add_scope(&curproxy->uri_auth, args[2])) { |
| 3624 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3625 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3626 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3627 | } |
| 3628 | } else if (!strcmp(args[1], "enable")) { |
| 3629 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 3630 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3631 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3632 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3633 | } |
Krzysztof Oledzki | d9db927 | 2007-10-15 10:05:11 +0200 | [diff] [blame] | 3634 | } else if (!strcmp(args[1], "hide-version")) { |
| 3635 | if (!stats_set_flag(&curproxy->uri_auth, ST_HIDEVER)) { |
| 3636 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3637 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3638 | goto out; |
Krzysztof Oledzki | d9db927 | 2007-10-15 10:05:11 +0200 | [diff] [blame] | 3639 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3640 | } else if (!strcmp(args[1], "show-legends")) { |
| 3641 | if (!stats_set_flag(&curproxy->uri_auth, ST_SHLGNDS)) { |
| 3642 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3643 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3644 | goto out; |
| 3645 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3646 | } else if (!strcmp(args[1], "show-node")) { |
| 3647 | |
| 3648 | if (*args[2]) { |
| 3649 | int i; |
| 3650 | char c; |
| 3651 | |
| 3652 | for (i=0; args[2][i]; i++) { |
| 3653 | c = args[2][i]; |
Willy Tarreau | 88e0581 | 2010-03-03 00:16:00 +0100 | [diff] [blame] | 3654 | if (!isupper((unsigned char)c) && !islower((unsigned char)c) && |
| 3655 | !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.') |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3656 | break; |
| 3657 | } |
| 3658 | |
| 3659 | if (!i || args[2][i]) { |
| 3660 | Alert("parsing [%s:%d]: '%s %s' invalid node name - should be a string" |
| 3661 | "with digits(0-9), letters(A-Z, a-z), hyphen(-) or underscode(_).\n", |
| 3662 | file, linenum, args[0], args[1]); |
| 3663 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3664 | goto out; |
| 3665 | } |
| 3666 | } |
| 3667 | |
| 3668 | if (!stats_set_node(&curproxy->uri_auth, args[2])) { |
| 3669 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3670 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3671 | goto out; |
| 3672 | } |
| 3673 | } else if (!strcmp(args[1], "show-desc")) { |
| 3674 | char *desc = NULL; |
| 3675 | |
| 3676 | if (*args[2]) { |
| 3677 | int i, len=0; |
| 3678 | char *d; |
| 3679 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 3680 | for (i = 2; *args[i]; i++) |
| 3681 | len += strlen(args[i]) + 1; |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3682 | |
| 3683 | desc = d = (char *)calloc(1, len); |
| 3684 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 3685 | d += snprintf(d, desc + len - d, "%s", args[2]); |
| 3686 | for (i = 3; *args[i]; i++) |
| 3687 | d += snprintf(d, desc + len - d, " %s", args[i]); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3688 | } |
| 3689 | |
| 3690 | if (!*args[2] && !global.desc) |
| 3691 | Warning("parsing [%s:%d]: '%s' requires a parameter or 'desc' to be set in the global section.\n", |
| 3692 | file, linenum, args[1]); |
| 3693 | else { |
| 3694 | if (!stats_set_desc(&curproxy->uri_auth, desc)) { |
| 3695 | free(desc); |
| 3696 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3697 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3698 | goto out; |
| 3699 | } |
| 3700 | free(desc); |
| 3701 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3702 | } else { |
Krzysztof Piotr Oledzki | 260a3bb | 2010-01-06 16:25:05 +0100 | [diff] [blame] | 3703 | stats_error_parsing: |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3704 | 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] | 3705 | 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] | 3706 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3707 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3708 | } |
| 3709 | } |
| 3710 | else if (!strcmp(args[0], "option")) { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3711 | int optnum; |
| 3712 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3713 | if (*(args[1]) == '\0') { |
| 3714 | Alert("parsing [%s:%d]: '%s' expects an option name.\n", |
| 3715 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3716 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3717 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3718 | } |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3719 | |
| 3720 | for (optnum = 0; cfg_opts[optnum].name; optnum++) { |
| 3721 | if (!strcmp(args[1], cfg_opts[optnum].name)) { |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 3722 | if (cfg_opts[optnum].cap == PR_CAP_NONE) { |
| 3723 | Alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n", |
| 3724 | file, linenum, cfg_opts[optnum].name); |
| 3725 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3726 | goto out; |
| 3727 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3728 | if (warnifnotcap(curproxy, cfg_opts[optnum].cap, file, linenum, args[1], NULL)) { |
| 3729 | err_code |= ERR_WARN; |
| 3730 | goto out; |
| 3731 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3732 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 3733 | curproxy->no_options &= ~cfg_opts[optnum].val; |
| 3734 | curproxy->options &= ~cfg_opts[optnum].val; |
| 3735 | |
| 3736 | switch (kwm) { |
| 3737 | case KWM_STD: |
| 3738 | curproxy->options |= cfg_opts[optnum].val; |
| 3739 | break; |
| 3740 | case KWM_NO: |
| 3741 | curproxy->no_options |= cfg_opts[optnum].val; |
| 3742 | break; |
| 3743 | case KWM_DEF: /* already cleared */ |
| 3744 | break; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 3745 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3746 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3747 | goto out; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3748 | } |
| 3749 | } |
| 3750 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 3751 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) { |
| 3752 | if (!strcmp(args[1], cfg_opts2[optnum].name)) { |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 3753 | if (cfg_opts2[optnum].cap == PR_CAP_NONE) { |
| 3754 | Alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n", |
| 3755 | file, linenum, cfg_opts2[optnum].name); |
| 3756 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3757 | goto out; |
| 3758 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3759 | if (warnifnotcap(curproxy, cfg_opts2[optnum].cap, file, linenum, args[1], NULL)) { |
| 3760 | err_code |= ERR_WARN; |
| 3761 | goto out; |
| 3762 | } |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 3763 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 3764 | curproxy->no_options2 &= ~cfg_opts2[optnum].val; |
| 3765 | curproxy->options2 &= ~cfg_opts2[optnum].val; |
| 3766 | |
| 3767 | switch (kwm) { |
| 3768 | case KWM_STD: |
| 3769 | curproxy->options2 |= cfg_opts2[optnum].val; |
| 3770 | break; |
| 3771 | case KWM_NO: |
| 3772 | curproxy->no_options2 |= cfg_opts2[optnum].val; |
| 3773 | break; |
| 3774 | case KWM_DEF: /* already cleared */ |
| 3775 | break; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 3776 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3777 | goto out; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 3778 | } |
| 3779 | } |
| 3780 | |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 3781 | /* HTTP options override each other. They can be cancelled using |
| 3782 | * "no option xxx" which only switches to default mode if the mode |
| 3783 | * was this one (useful for cancelling options set in defaults |
| 3784 | * sections). |
| 3785 | */ |
| 3786 | if (strcmp(args[1], "httpclose") == 0) { |
| 3787 | if (kwm == KWM_STD) { |
| 3788 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3789 | curproxy->options |= PR_O_HTTP_PCL; |
| 3790 | goto out; |
| 3791 | } |
| 3792 | else if (kwm == KWM_NO) { |
| 3793 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_PCL) |
| 3794 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3795 | goto out; |
| 3796 | } |
| 3797 | } |
| 3798 | else if (strcmp(args[1], "forceclose") == 0) { |
| 3799 | if (kwm == KWM_STD) { |
| 3800 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3801 | curproxy->options |= PR_O_HTTP_FCL; |
| 3802 | goto out; |
| 3803 | } |
| 3804 | else if (kwm == KWM_NO) { |
| 3805 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_FCL) |
| 3806 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3807 | goto out; |
| 3808 | } |
| 3809 | } |
| 3810 | else if (strcmp(args[1], "http-server-close") == 0) { |
| 3811 | if (kwm == KWM_STD) { |
| 3812 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3813 | curproxy->options |= PR_O_HTTP_SCL; |
| 3814 | goto out; |
| 3815 | } |
| 3816 | else if (kwm == KWM_NO) { |
| 3817 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_SCL) |
| 3818 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3819 | goto out; |
| 3820 | } |
| 3821 | } |
| 3822 | else if (strcmp(args[1], "http-keep-alive") == 0) { |
| 3823 | if (kwm == KWM_STD) { |
| 3824 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3825 | curproxy->options |= PR_O_HTTP_KAL; |
| 3826 | goto out; |
| 3827 | } |
| 3828 | else if (kwm == KWM_NO) { |
| 3829 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_KAL) |
| 3830 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3831 | goto out; |
| 3832 | } |
| 3833 | } |
| 3834 | else if (strcmp(args[1], "http-tunnel") == 0) { |
| 3835 | if (kwm == KWM_STD) { |
| 3836 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3837 | curproxy->options |= PR_O_HTTP_TUN; |
| 3838 | goto out; |
| 3839 | } |
| 3840 | else if (kwm == KWM_NO) { |
| 3841 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_TUN) |
| 3842 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3843 | goto out; |
| 3844 | } |
| 3845 | } |
| 3846 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 3847 | if (kwm != KWM_STD) { |
| 3848 | 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] | 3849 | file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3850 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3851 | goto out; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3852 | } |
| 3853 | |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3854 | if (!strcmp(args[1], "httplog")) { |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 3855 | char *logformat; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3856 | /* generate a complete HTTP log */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 3857 | logformat = default_http_log_format; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3858 | if (*(args[2]) != '\0') { |
| 3859 | if (!strcmp(args[2], "clf")) { |
| 3860 | curproxy->options2 |= PR_O2_CLFLOG; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 3861 | logformat = clf_http_log_format; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3862 | } else { |
| 3863 | Alert("parsing [%s:%d] : keyword '%s' only supports option 'clf'.\n", file, linenum, args[2]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3864 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3865 | goto out; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3866 | } |
| 3867 | } |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 3868 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 3869 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 3870 | curproxy->conf.logformat_string != clf_http_log_format) |
| 3871 | free(curproxy->conf.logformat_string); |
| 3872 | curproxy->conf.logformat_string = logformat; |
| 3873 | |
| 3874 | free(curproxy->conf.lfs_file); |
| 3875 | curproxy->conf.lfs_file = strdup(curproxy->conf.args.file); |
| 3876 | curproxy->conf.lfs_line = curproxy->conf.args.line; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3877 | } |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 3878 | else if (!strcmp(args[1], "tcplog")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3879 | /* generate a detailed TCP log */ |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 3880 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 3881 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 3882 | curproxy->conf.logformat_string != clf_http_log_format) |
| 3883 | free(curproxy->conf.logformat_string); |
| 3884 | curproxy->conf.logformat_string = default_tcp_log_format; |
| 3885 | |
| 3886 | free(curproxy->conf.lfs_file); |
| 3887 | curproxy->conf.lfs_file = strdup(curproxy->conf.args.file); |
| 3888 | curproxy->conf.lfs_line = curproxy->conf.args.line; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 3889 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3890 | else if (!strcmp(args[1], "tcpka")) { |
| 3891 | /* enable TCP keep-alives on client and server sessions */ |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3892 | 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] | 3893 | err_code |= ERR_WARN; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3894 | |
| 3895 | if (curproxy->cap & PR_CAP_FE) |
| 3896 | curproxy->options |= PR_O_TCP_CLI_KA; |
| 3897 | if (curproxy->cap & PR_CAP_BE) |
| 3898 | curproxy->options |= PR_O_TCP_SRV_KA; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3899 | } |
| 3900 | else if (!strcmp(args[1], "httpchk")) { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3901 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3902 | err_code |= ERR_WARN; |
| 3903 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3904 | /* use HTTP request to check servers' health */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3905 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 3906 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3907 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 3908 | curproxy->options2 |= PR_O2_HTTP_CHK; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3909 | if (!*args[2]) { /* no argument */ |
| 3910 | curproxy->check_req = strdup(DEF_CHECK_REQ); /* default request */ |
| 3911 | curproxy->check_len = strlen(DEF_CHECK_REQ); |
| 3912 | } else if (!*args[3]) { /* one argument : URI */ |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3913 | 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] | 3914 | curproxy->check_req = (char *)malloc(reqlen); |
| 3915 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3916 | "OPTIONS %s HTTP/1.0\r\n", args[2]); /* URI to use */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3917 | } else { /* more arguments : METHOD URI [HTTP_VER] */ |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3918 | int reqlen = strlen(args[2]) + strlen(args[3]) + 3 + strlen("\r\n"); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3919 | if (*args[4]) |
| 3920 | reqlen += strlen(args[4]); |
| 3921 | else |
| 3922 | reqlen += strlen("HTTP/1.0"); |
| 3923 | |
| 3924 | curproxy->check_req = (char *)malloc(reqlen); |
| 3925 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3926 | "%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] | 3927 | } |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 3928 | } |
| 3929 | else if (!strcmp(args[1], "ssl-hello-chk")) { |
| 3930 | /* use SSLv3 CLIENT HELLO to check servers' health */ |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3931 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3932 | err_code |= ERR_WARN; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3933 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3934 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 3935 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3936 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Willy Tarreau | 07a5490 | 2010-03-29 18:33:29 +0200 | [diff] [blame] | 3937 | curproxy->options2 |= PR_O2_SSL3_CHK; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3938 | } |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 3939 | else if (!strcmp(args[1], "smtpchk")) { |
| 3940 | /* use SMTP request to check servers' health */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3941 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 3942 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3943 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 3944 | curproxy->options2 |= PR_O2_SMTP_CHK; |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 3945 | |
| 3946 | if (!*args[2] || !*args[3]) { /* no argument or incomplete EHLO host */ |
| 3947 | curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */ |
| 3948 | curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ); |
| 3949 | } else { /* ESMTP EHLO, or SMTP HELO, and a hostname */ |
| 3950 | if (!strcmp(args[2], "EHLO") || !strcmp(args[2], "HELO")) { |
| 3951 | int reqlen = strlen(args[2]) + strlen(args[3]) + strlen(" \r\n") + 1; |
| 3952 | curproxy->check_req = (char *)malloc(reqlen); |
| 3953 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
| 3954 | "%s %s\r\n", args[2], args[3]); /* HELO hostname */ |
| 3955 | } else { |
| 3956 | /* this just hits the default for now, but you could potentially expand it to allow for other stuff |
| 3957 | though, it's unlikely you'd want to send anything other than an EHLO or HELO */ |
| 3958 | curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */ |
| 3959 | curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ); |
| 3960 | } |
| 3961 | } |
| 3962 | } |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 3963 | else if (!strcmp(args[1], "pgsql-check")) { |
| 3964 | /* use PostgreSQL request to check servers' health */ |
| 3965 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 3966 | err_code |= ERR_WARN; |
| 3967 | |
| 3968 | free(curproxy->check_req); |
| 3969 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3970 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 3971 | curproxy->options2 |= PR_O2_PGSQL_CHK; |
| 3972 | |
| 3973 | if (*(args[2])) { |
| 3974 | int cur_arg = 2; |
| 3975 | |
| 3976 | while (*(args[cur_arg])) { |
| 3977 | if (strcmp(args[cur_arg], "user") == 0) { |
| 3978 | char * packet; |
| 3979 | uint32_t packet_len; |
| 3980 | uint32_t pv; |
| 3981 | |
| 3982 | /* suboption header - needs additional argument for it */ |
| 3983 | if (*(args[cur_arg+1]) == 0) { |
| 3984 | Alert("parsing [%s:%d] : '%s %s %s' expects <username> as argument.\n", |
| 3985 | file, linenum, args[0], args[1], args[cur_arg]); |
| 3986 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3987 | goto out; |
| 3988 | } |
| 3989 | |
| 3990 | /* uint32_t + uint32_t + strlen("user")+1 + strlen(username)+1 + 1 */ |
| 3991 | packet_len = 4 + 4 + 5 + strlen(args[cur_arg + 1])+1 +1; |
| 3992 | pv = htonl(0x30000); /* protocol version 3.0 */ |
| 3993 | |
| 3994 | packet = (char*) calloc(1, packet_len); |
| 3995 | |
| 3996 | memcpy(packet + 4, &pv, 4); |
| 3997 | |
| 3998 | /* copy "user" */ |
| 3999 | memcpy(packet + 8, "user", 4); |
| 4000 | |
| 4001 | /* copy username */ |
| 4002 | memcpy(packet + 13, args[cur_arg+1], strlen(args[cur_arg+1])); |
| 4003 | |
| 4004 | free(curproxy->check_req); |
| 4005 | curproxy->check_req = packet; |
| 4006 | curproxy->check_len = packet_len; |
| 4007 | |
| 4008 | packet_len = htonl(packet_len); |
| 4009 | memcpy(packet, &packet_len, 4); |
| 4010 | cur_arg += 2; |
| 4011 | } else { |
| 4012 | /* unknown suboption - catchall */ |
| 4013 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'user'.\n", |
| 4014 | file, linenum, args[0], args[1]); |
| 4015 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4016 | goto out; |
| 4017 | } |
| 4018 | } /* end while loop */ |
| 4019 | } |
| 4020 | } |
| 4021 | |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 4022 | else if (!strcmp(args[1], "redis-check")) { |
| 4023 | /* use REDIS PING request to check servers' health */ |
| 4024 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 4025 | err_code |= ERR_WARN; |
| 4026 | |
| 4027 | free(curproxy->check_req); |
| 4028 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4029 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 4030 | curproxy->options2 |= PR_O2_REDIS_CHK; |
| 4031 | |
| 4032 | curproxy->check_req = (char *) malloc(sizeof(DEF_REDIS_CHECK_REQ) - 1); |
| 4033 | memcpy(curproxy->check_req, DEF_REDIS_CHECK_REQ, sizeof(DEF_REDIS_CHECK_REQ) - 1); |
| 4034 | curproxy->check_len = sizeof(DEF_REDIS_CHECK_REQ) - 1; |
| 4035 | } |
| 4036 | |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 4037 | else if (!strcmp(args[1], "mysql-check")) { |
| 4038 | /* use MYSQL request to check servers' health */ |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 4039 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 4040 | err_code |= ERR_WARN; |
| 4041 | |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 4042 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 4043 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4044 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 4045 | curproxy->options2 |= PR_O2_MYSQL_CHK; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 4046 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 4047 | /* 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] | 4048 | * const char mysql40_client_auth_pkt[] = { |
| 4049 | * "\x0e\x00\x00" // packet length |
| 4050 | * "\x01" // packet number |
| 4051 | * "\x00\x00" // client capabilities |
| 4052 | * "\x00\x00\x01" // max packet |
| 4053 | * "haproxy\x00" // username (null terminated string) |
| 4054 | * "\x00" // filler (always 0x00) |
| 4055 | * "\x01\x00\x00" // packet length |
| 4056 | * "\x00" // packet number |
| 4057 | * "\x01" // COM_QUIT command |
| 4058 | * }; |
| 4059 | */ |
| 4060 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 4061 | /* This is an example of a MySQL >=4.1 client Authentication packet provided by Nenad Merdanovic. |
| 4062 | * const char mysql41_client_auth_pkt[] = { |
| 4063 | * "\x0e\x00\x00\" // packet length |
| 4064 | * "\x01" // packet number |
| 4065 | * "\x00\x00\x00\x00" // client capabilities |
| 4066 | * "\x00\x00\x00\x01" // max packet |
| 4067 | * "\x21" // character set (UTF-8) |
| 4068 | * char[23] // All zeroes |
| 4069 | * "haproxy\x00" // username (null terminated string) |
| 4070 | * "\x00" // filler (always 0x00) |
| 4071 | * "\x01\x00\x00" // packet length |
| 4072 | * "\x00" // packet number |
| 4073 | * "\x01" // COM_QUIT command |
| 4074 | * }; |
| 4075 | */ |
| 4076 | |
| 4077 | |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 4078 | if (*(args[2])) { |
| 4079 | int cur_arg = 2; |
| 4080 | |
| 4081 | while (*(args[cur_arg])) { |
| 4082 | if (strcmp(args[cur_arg], "user") == 0) { |
| 4083 | char *mysqluser; |
| 4084 | int packetlen, reqlen, userlen; |
| 4085 | |
| 4086 | /* suboption header - needs additional argument for it */ |
| 4087 | if (*(args[cur_arg+1]) == 0) { |
| 4088 | Alert("parsing [%s:%d] : '%s %s %s' expects <username> as argument.\n", |
| 4089 | file, linenum, args[0], args[1], args[cur_arg]); |
| 4090 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4091 | goto out; |
| 4092 | } |
| 4093 | mysqluser = args[cur_arg + 1]; |
| 4094 | userlen = strlen(mysqluser); |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 4095 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 4096 | if (*(args[cur_arg+2])) { |
| 4097 | if (!strcmp(args[cur_arg+2], "post-41")) { |
| 4098 | packetlen = userlen + 7 + 27; |
| 4099 | reqlen = packetlen + 9; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 4100 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 4101 | free(curproxy->check_req); |
| 4102 | curproxy->check_req = (char *)calloc(1, reqlen); |
| 4103 | curproxy->check_len = reqlen; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 4104 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 4105 | snprintf(curproxy->check_req, 4, "%c%c%c", |
| 4106 | ((unsigned char) packetlen & 0xff), |
| 4107 | ((unsigned char) (packetlen >> 8) & 0xff), |
| 4108 | ((unsigned char) (packetlen >> 16) & 0xff)); |
| 4109 | |
| 4110 | curproxy->check_req[3] = 1; |
| 4111 | curproxy->check_req[5] = 130; |
| 4112 | curproxy->check_req[11] = 1; |
| 4113 | curproxy->check_req[12] = 33; |
| 4114 | memcpy(&curproxy->check_req[36], mysqluser, userlen); |
| 4115 | curproxy->check_req[36 + userlen + 1 + 1] = 1; |
| 4116 | curproxy->check_req[36 + userlen + 1 + 1 + 4] = 1; |
| 4117 | cur_arg += 3; |
| 4118 | } else { |
| 4119 | Alert("parsing [%s:%d] : keyword '%s' only supports option 'post-41'.\n", file, linenum, args[cur_arg+2]); |
| 4120 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4121 | goto out; |
| 4122 | } |
| 4123 | } else { |
| 4124 | packetlen = userlen + 7; |
| 4125 | reqlen = packetlen + 9; |
| 4126 | |
| 4127 | free(curproxy->check_req); |
| 4128 | curproxy->check_req = (char *)calloc(1, reqlen); |
| 4129 | curproxy->check_len = reqlen; |
| 4130 | |
| 4131 | snprintf(curproxy->check_req, 4, "%c%c%c", |
| 4132 | ((unsigned char) packetlen & 0xff), |
| 4133 | ((unsigned char) (packetlen >> 8) & 0xff), |
| 4134 | ((unsigned char) (packetlen >> 16) & 0xff)); |
| 4135 | |
| 4136 | curproxy->check_req[3] = 1; |
| 4137 | curproxy->check_req[5] = 128; |
| 4138 | curproxy->check_req[8] = 1; |
| 4139 | memcpy(&curproxy->check_req[9], mysqluser, userlen); |
| 4140 | curproxy->check_req[9 + userlen + 1 + 1] = 1; |
| 4141 | curproxy->check_req[9 + userlen + 1 + 1 + 4] = 1; |
| 4142 | cur_arg += 2; |
| 4143 | } |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 4144 | } else { |
| 4145 | /* unknown suboption - catchall */ |
| 4146 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'user'.\n", |
| 4147 | file, linenum, args[0], args[1]); |
| 4148 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4149 | goto out; |
| 4150 | } |
| 4151 | } /* end while loop */ |
| 4152 | } |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 4153 | } |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 4154 | else if (!strcmp(args[1], "ldap-check")) { |
| 4155 | /* use LDAP request to check servers' health */ |
| 4156 | free(curproxy->check_req); |
| 4157 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4158 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 4159 | curproxy->options2 |= PR_O2_LDAP_CHK; |
| 4160 | |
| 4161 | curproxy->check_req = (char *) malloc(sizeof(DEF_LDAP_CHECK_REQ) - 1); |
| 4162 | memcpy(curproxy->check_req, DEF_LDAP_CHECK_REQ, sizeof(DEF_LDAP_CHECK_REQ) - 1); |
| 4163 | curproxy->check_len = sizeof(DEF_LDAP_CHECK_REQ) - 1; |
| 4164 | } |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 4165 | else if (!strcmp(args[1], "tcp-check")) { |
| 4166 | /* use raw TCPCHK send/expect to check servers' health */ |
| 4167 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 4168 | err_code |= ERR_WARN; |
| 4169 | |
| 4170 | free(curproxy->check_req); |
| 4171 | curproxy->check_req = NULL; |
| 4172 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 4173 | curproxy->options2 |= PR_O2_TCPCHK_CHK; |
| 4174 | } |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 4175 | else if (!strcmp(args[1], "external-check")) { |
| 4176 | /* excute an external command to check servers' health */ |
| 4177 | free(curproxy->check_req); |
| 4178 | curproxy->check_req = NULL; |
| 4179 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 4180 | curproxy->options2 |= PR_O2_EXT_CHK; |
| 4181 | } |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 4182 | else if (!strcmp(args[1], "forwardfor")) { |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 4183 | int cur_arg; |
| 4184 | |
| 4185 | /* insert x-forwarded-for field, but not for the IP address listed as an except. |
| 4186 | * set default options (ie: bitfield, header name, etc) |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 4187 | */ |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 4188 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 4189 | curproxy->options |= PR_O_FWDFOR | PR_O_FF_ALWAYS; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 4190 | |
| 4191 | free(curproxy->fwdfor_hdr_name); |
| 4192 | curproxy->fwdfor_hdr_name = strdup(DEF_XFORWARDFOR_HDR); |
| 4193 | curproxy->fwdfor_hdr_len = strlen(DEF_XFORWARDFOR_HDR); |
| 4194 | |
| 4195 | /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */ |
| 4196 | cur_arg = 2; |
| 4197 | while (*(args[cur_arg])) { |
| 4198 | if (!strcmp(args[cur_arg], "except")) { |
| 4199 | /* suboption except - needs additional argument for it */ |
Thierry FOURNIER | fc7ac7b | 2014-02-11 15:23:04 +0100 | [diff] [blame] | 4200 | 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] | 4201 | Alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n", |
| 4202 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4203 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4204 | goto out; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 4205 | } |
| 4206 | /* flush useless bits */ |
| 4207 | curproxy->except_net.s_addr &= curproxy->except_mask.s_addr; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 4208 | cur_arg += 2; |
| 4209 | } else if (!strcmp(args[cur_arg], "header")) { |
| 4210 | /* suboption header - needs additional argument for it */ |
| 4211 | if (*(args[cur_arg+1]) == 0) { |
| 4212 | Alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 4213 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4214 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4215 | goto out; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 4216 | } |
| 4217 | free(curproxy->fwdfor_hdr_name); |
| 4218 | curproxy->fwdfor_hdr_name = strdup(args[cur_arg+1]); |
| 4219 | curproxy->fwdfor_hdr_len = strlen(curproxy->fwdfor_hdr_name); |
| 4220 | cur_arg += 2; |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 4221 | } else if (!strcmp(args[cur_arg], "if-none")) { |
| 4222 | curproxy->options &= ~PR_O_FF_ALWAYS; |
| 4223 | cur_arg += 1; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 4224 | } else { |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 4225 | /* unknown suboption - catchall */ |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 4226 | 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] | 4227 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4228 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4229 | goto out; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 4230 | } |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 4231 | } /* end while loop */ |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 4232 | } |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 4233 | else if (!strcmp(args[1], "originalto")) { |
| 4234 | int cur_arg; |
| 4235 | |
| 4236 | /* insert x-original-to field, but not for the IP address listed as an except. |
| 4237 | * set default options (ie: bitfield, header name, etc) |
| 4238 | */ |
| 4239 | |
| 4240 | curproxy->options |= PR_O_ORGTO; |
| 4241 | |
| 4242 | free(curproxy->orgto_hdr_name); |
| 4243 | curproxy->orgto_hdr_name = strdup(DEF_XORIGINALTO_HDR); |
| 4244 | curproxy->orgto_hdr_len = strlen(DEF_XORIGINALTO_HDR); |
| 4245 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 4246 | /* 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] | 4247 | cur_arg = 2; |
| 4248 | while (*(args[cur_arg])) { |
| 4249 | if (!strcmp(args[cur_arg], "except")) { |
| 4250 | /* suboption except - needs additional argument for it */ |
Thierry FOURNIER | fc7ac7b | 2014-02-11 15:23:04 +0100 | [diff] [blame] | 4251 | 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] | 4252 | Alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n", |
| 4253 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4254 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4255 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 4256 | } |
| 4257 | /* flush useless bits */ |
| 4258 | curproxy->except_to.s_addr &= curproxy->except_mask_to.s_addr; |
| 4259 | cur_arg += 2; |
| 4260 | } else if (!strcmp(args[cur_arg], "header")) { |
| 4261 | /* suboption header - needs additional argument for it */ |
| 4262 | if (*(args[cur_arg+1]) == 0) { |
| 4263 | Alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 4264 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4265 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4266 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 4267 | } |
| 4268 | free(curproxy->orgto_hdr_name); |
| 4269 | curproxy->orgto_hdr_name = strdup(args[cur_arg+1]); |
| 4270 | curproxy->orgto_hdr_len = strlen(curproxy->orgto_hdr_name); |
| 4271 | cur_arg += 2; |
| 4272 | } else { |
| 4273 | /* unknown suboption - catchall */ |
| 4274 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n", |
| 4275 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4276 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4277 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 4278 | } |
| 4279 | } /* end while loop */ |
| 4280 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4281 | else { |
| 4282 | Alert("parsing [%s:%d] : unknown option '%s'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4283 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4284 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4285 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4286 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4287 | } |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 4288 | else if (!strcmp(args[0], "default_backend")) { |
| 4289 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4290 | err_code |= ERR_WARN; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 4291 | |
| 4292 | if (*(args[1]) == 0) { |
| 4293 | 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] | 4294 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4295 | goto out; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 4296 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 4297 | free(curproxy->defbe.name); |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 4298 | curproxy->defbe.name = strdup(args[1]); |
| 4299 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4300 | else if (!strcmp(args[0], "redispatch") || !strcmp(args[0], "redisp")) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4301 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4302 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4303 | |
Willy Tarreau | a3c504c | 2014-04-28 22:37:32 +0200 | [diff] [blame] | 4304 | if (!already_warned(WARN_REDISPATCH_DEPRECATED)) |
| 4305 | 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] | 4306 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4307 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4308 | /* enable reconnections to dispatch */ |
| 4309 | curproxy->options |= PR_O_REDISP; |
| 4310 | } |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 4311 | else if (!strcmp(args[0], "http-check")) { |
| 4312 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4313 | err_code |= ERR_WARN; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 4314 | |
| 4315 | if (strcmp(args[1], "disable-on-404") == 0) { |
| 4316 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 4317 | curproxy->options |= PR_O_DISABLE404; |
| 4318 | } |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 4319 | else if (strcmp(args[1], "send-state") == 0) { |
| 4320 | /* enable emission of the apparent state of a server in HTTP checks */ |
| 4321 | curproxy->options2 |= PR_O2_CHK_SNDST; |
| 4322 | } |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 4323 | else if (strcmp(args[1], "expect") == 0) { |
| 4324 | const char *ptr_arg; |
| 4325 | int cur_arg; |
| 4326 | |
| 4327 | if (curproxy->options2 & PR_O2_EXP_TYPE) { |
| 4328 | Alert("parsing [%s:%d] : '%s %s' already specified.\n", file, linenum, args[0], args[1]); |
| 4329 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4330 | goto out; |
| 4331 | } |
| 4332 | |
| 4333 | cur_arg = 2; |
| 4334 | /* consider exclamation marks, sole or at the beginning of a word */ |
| 4335 | while (*(ptr_arg = args[cur_arg])) { |
| 4336 | while (*ptr_arg == '!') { |
| 4337 | curproxy->options2 ^= PR_O2_EXP_INV; |
| 4338 | ptr_arg++; |
| 4339 | } |
| 4340 | if (*ptr_arg) |
| 4341 | break; |
| 4342 | cur_arg++; |
| 4343 | } |
| 4344 | /* now ptr_arg points to the beginning of a word past any possible |
| 4345 | * exclamation mark, and cur_arg is the argument which holds this word. |
| 4346 | */ |
| 4347 | if (strcmp(ptr_arg, "status") == 0) { |
| 4348 | if (!*(args[cur_arg + 1])) { |
| 4349 | Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 4350 | file, linenum, args[0], args[1], ptr_arg); |
| 4351 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4352 | goto out; |
| 4353 | } |
| 4354 | curproxy->options2 |= PR_O2_EXP_STS; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 4355 | free(curproxy->expect_str); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 4356 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
| 4357 | } |
| 4358 | else if (strcmp(ptr_arg, "string") == 0) { |
| 4359 | if (!*(args[cur_arg + 1])) { |
| 4360 | Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 4361 | file, linenum, args[0], args[1], ptr_arg); |
| 4362 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4363 | goto out; |
| 4364 | } |
| 4365 | curproxy->options2 |= PR_O2_EXP_STR; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 4366 | free(curproxy->expect_str); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 4367 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
| 4368 | } |
| 4369 | else if (strcmp(ptr_arg, "rstatus") == 0) { |
| 4370 | if (!*(args[cur_arg + 1])) { |
| 4371 | Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 4372 | file, linenum, args[0], args[1], ptr_arg); |
| 4373 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4374 | goto out; |
| 4375 | } |
| 4376 | curproxy->options2 |= PR_O2_EXP_RSTS; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 4377 | free(curproxy->expect_str); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 4378 | if (curproxy->expect_regex) { |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 4379 | regex_free(curproxy->expect_regex); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 4380 | free(curproxy->expect_regex); |
| 4381 | curproxy->expect_regex = NULL; |
| 4382 | } |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 4383 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 4384 | curproxy->expect_regex = calloc(1, sizeof(*curproxy->expect_regex)); |
| 4385 | error = NULL; |
| 4386 | if (!regex_comp(args[cur_arg + 1], curproxy->expect_regex, 1, 1, &error)) { |
| 4387 | Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s': %s.\n", |
| 4388 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1], error); |
| 4389 | free(error); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 4390 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4391 | goto out; |
| 4392 | } |
| 4393 | } |
| 4394 | else if (strcmp(ptr_arg, "rstring") == 0) { |
| 4395 | if (!*(args[cur_arg + 1])) { |
| 4396 | Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 4397 | file, linenum, args[0], args[1], ptr_arg); |
| 4398 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4399 | goto out; |
| 4400 | } |
| 4401 | curproxy->options2 |= PR_O2_EXP_RSTR; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 4402 | free(curproxy->expect_str); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 4403 | if (curproxy->expect_regex) { |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 4404 | regex_free(curproxy->expect_regex); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 4405 | free(curproxy->expect_regex); |
| 4406 | curproxy->expect_regex = NULL; |
| 4407 | } |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 4408 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 4409 | curproxy->expect_regex = calloc(1, sizeof(*curproxy->expect_regex)); |
| 4410 | error = NULL; |
| 4411 | if (!regex_comp(args[cur_arg + 1], curproxy->expect_regex, 1, 1, &error)) { |
| 4412 | Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s': %s.\n", |
| 4413 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1], error); |
| 4414 | free(error); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 4415 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4416 | goto out; |
| 4417 | } |
| 4418 | } |
| 4419 | else { |
| 4420 | Alert("parsing [%s:%d] : '%s %s' only supports [!] 'status', 'string', 'rstatus', 'rstring', found '%s'.\n", |
| 4421 | file, linenum, args[0], args[1], ptr_arg); |
| 4422 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4423 | goto out; |
| 4424 | } |
| 4425 | } |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 4426 | else { |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 4427 | 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] | 4428 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4429 | goto out; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 4430 | } |
| 4431 | } |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 4432 | else if (!strcmp(args[0], "tcp-check")) { |
| 4433 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 4434 | err_code |= ERR_WARN; |
| 4435 | |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 4436 | if (strcmp(args[1], "connect") == 0) { |
| 4437 | const char *ptr_arg; |
| 4438 | int cur_arg; |
| 4439 | struct tcpcheck_rule *tcpcheck; |
| 4440 | struct list *l; |
| 4441 | |
| 4442 | /* check if first rule is also a 'connect' action */ |
| 4443 | l = (struct list *)&curproxy->tcpcheck_rules; |
| 4444 | if (l->p != l->n) { |
| 4445 | tcpcheck = (struct tcpcheck_rule *)l->n; |
| 4446 | if (tcpcheck && tcpcheck->action != TCPCHK_ACT_CONNECT) { |
| 4447 | Alert("parsing [%s:%d] : first step MUST also be a 'connect' when there is a 'connect' step in the tcp-check ruleset.\n", |
| 4448 | file, linenum); |
| 4449 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4450 | goto out; |
| 4451 | } |
| 4452 | } |
| 4453 | |
| 4454 | cur_arg = 2; |
| 4455 | tcpcheck = (struct tcpcheck_rule *)calloc(1, sizeof(*tcpcheck)); |
| 4456 | tcpcheck->action = TCPCHK_ACT_CONNECT; |
| 4457 | |
| 4458 | /* parsing each parameters to fill up the rule */ |
| 4459 | while (*(ptr_arg = args[cur_arg])) { |
| 4460 | /* tcp port */ |
| 4461 | if (strcmp(args[cur_arg], "port") == 0) { |
| 4462 | if ( (atol(args[cur_arg + 1]) > 65535) || |
| 4463 | (atol(args[cur_arg + 1]) < 1) ){ |
| 4464 | Alert("parsing [%s:%d] : '%s %s %s' expects a valid TCP port (from range 1 to 65535), got %s.\n", |
| 4465 | file, linenum, args[0], args[1], "port", args[cur_arg + 1]); |
| 4466 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4467 | goto out; |
| 4468 | } |
| 4469 | tcpcheck->port = atol(args[cur_arg + 1]); |
| 4470 | cur_arg += 2; |
| 4471 | } |
| 4472 | /* send proxy protocol */ |
| 4473 | else if (strcmp(args[cur_arg], "send-proxy") == 0) { |
| 4474 | tcpcheck->conn_opts |= TCPCHK_OPT_SEND_PROXY; |
| 4475 | cur_arg++; |
| 4476 | } |
| 4477 | #ifdef USE_OPENSSL |
| 4478 | else if (strcmp(args[cur_arg], "ssl") == 0) { |
| 4479 | curproxy->options |= PR_O_TCPCHK_SSL; |
| 4480 | tcpcheck->conn_opts |= TCPCHK_OPT_SSL; |
| 4481 | cur_arg++; |
| 4482 | } |
| 4483 | #endif /* USE_OPENSSL */ |
| 4484 | else { |
| 4485 | #ifdef USE_OPENSSL |
| 4486 | Alert("parsing [%s:%d] : '%s %s' expects 'port', 'send-proxy' or 'ssl' but got '%s' as argument.\n", |
| 4487 | #else /* USE_OPENSSL */ |
| 4488 | Alert("parsing [%s:%d] : '%s %s' expects 'port', 'send-proxy' or but got '%s' as argument.\n", |
| 4489 | #endif /* USE_OPENSSL */ |
| 4490 | file, linenum, args[0], args[1], args[cur_arg]); |
| 4491 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4492 | goto out; |
| 4493 | } |
| 4494 | |
| 4495 | } |
| 4496 | |
| 4497 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 4498 | } |
| 4499 | else if (strcmp(args[1], "send") == 0) { |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 4500 | if (! *(args[2]) ) { |
| 4501 | /* SEND string expected */ |
| 4502 | Alert("parsing [%s:%d] : '%s %s %s' expects <STRING> as argument.\n", |
| 4503 | file, linenum, args[0], args[1], args[2]); |
| 4504 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4505 | goto out; |
| 4506 | } else { |
| 4507 | struct tcpcheck_rule *tcpcheck; |
| 4508 | |
| 4509 | tcpcheck = (struct tcpcheck_rule *)calloc(1, sizeof(*tcpcheck)); |
| 4510 | |
| 4511 | tcpcheck->action = TCPCHK_ACT_SEND; |
| 4512 | tcpcheck->string_len = strlen(args[2]); |
| 4513 | tcpcheck->string = strdup(args[2]); |
| 4514 | tcpcheck->expect_regex = NULL; |
| 4515 | |
| 4516 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 4517 | } |
| 4518 | } |
| 4519 | else if (strcmp(args[1], "send-binary") == 0) { |
| 4520 | if (! *(args[2]) ) { |
| 4521 | /* SEND binary string expected */ |
| 4522 | Alert("parsing [%s:%d] : '%s %s %s' expects <BINARY STRING> as argument.\n", |
| 4523 | file, linenum, args[0], args[1], args[2]); |
| 4524 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4525 | goto out; |
| 4526 | } else { |
| 4527 | struct tcpcheck_rule *tcpcheck; |
| 4528 | char *err = NULL; |
| 4529 | |
| 4530 | tcpcheck = (struct tcpcheck_rule *)calloc(1, sizeof(*tcpcheck)); |
| 4531 | |
| 4532 | tcpcheck->action = TCPCHK_ACT_SEND; |
| 4533 | if (parse_binary(args[2], &tcpcheck->string, &tcpcheck->string_len, &err) == 0) { |
| 4534 | Alert("parsing [%s:%d] : '%s %s %s' expects <BINARY STRING> as argument, but %s\n", |
| 4535 | file, linenum, args[0], args[1], args[2], err); |
| 4536 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4537 | goto out; |
| 4538 | } |
| 4539 | tcpcheck->expect_regex = NULL; |
| 4540 | |
| 4541 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 4542 | } |
| 4543 | } |
| 4544 | else if (strcmp(args[1], "expect") == 0) { |
| 4545 | const char *ptr_arg; |
| 4546 | int cur_arg; |
| 4547 | int inverse = 0; |
| 4548 | |
| 4549 | if (curproxy->options2 & PR_O2_EXP_TYPE) { |
| 4550 | Alert("parsing [%s:%d] : '%s %s' already specified.\n", file, linenum, args[0], args[1]); |
| 4551 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4552 | goto out; |
| 4553 | } |
| 4554 | |
| 4555 | cur_arg = 2; |
| 4556 | /* consider exclamation marks, sole or at the beginning of a word */ |
| 4557 | while (*(ptr_arg = args[cur_arg])) { |
| 4558 | while (*ptr_arg == '!') { |
| 4559 | inverse = !inverse; |
| 4560 | ptr_arg++; |
| 4561 | } |
| 4562 | if (*ptr_arg) |
| 4563 | break; |
| 4564 | cur_arg++; |
| 4565 | } |
| 4566 | /* now ptr_arg points to the beginning of a word past any possible |
| 4567 | * exclamation mark, and cur_arg is the argument which holds this word. |
| 4568 | */ |
| 4569 | if (strcmp(ptr_arg, "binary") == 0) { |
| 4570 | if (!*(args[cur_arg + 1])) { |
| 4571 | Alert("parsing [%s:%d] : '%s %s %s' expects <binary string> as an argument.\n", |
| 4572 | file, linenum, args[0], args[1], ptr_arg); |
| 4573 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4574 | goto out; |
| 4575 | } |
| 4576 | struct tcpcheck_rule *tcpcheck; |
| 4577 | char *err = NULL; |
| 4578 | |
| 4579 | tcpcheck = (struct tcpcheck_rule *)calloc(1, sizeof(*tcpcheck)); |
| 4580 | |
| 4581 | tcpcheck->action = TCPCHK_ACT_EXPECT; |
| 4582 | if (parse_binary(args[cur_arg + 1], &tcpcheck->string, &tcpcheck->string_len, &err) == 0) { |
| 4583 | Alert("parsing [%s:%d] : '%s %s %s' expects <BINARY STRING> as argument, but %s\n", |
| 4584 | file, linenum, args[0], args[1], args[2], err); |
| 4585 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4586 | goto out; |
| 4587 | } |
| 4588 | tcpcheck->expect_regex = NULL; |
| 4589 | tcpcheck->inverse = inverse; |
| 4590 | |
| 4591 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 4592 | } |
| 4593 | else if (strcmp(ptr_arg, "string") == 0) { |
| 4594 | if (!*(args[cur_arg + 1])) { |
| 4595 | Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 4596 | file, linenum, args[0], args[1], ptr_arg); |
| 4597 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4598 | goto out; |
| 4599 | } |
| 4600 | struct tcpcheck_rule *tcpcheck; |
| 4601 | |
| 4602 | tcpcheck = (struct tcpcheck_rule *)calloc(1, sizeof(*tcpcheck)); |
| 4603 | |
| 4604 | tcpcheck->action = TCPCHK_ACT_EXPECT; |
| 4605 | tcpcheck->string_len = strlen(args[cur_arg + 1]); |
| 4606 | tcpcheck->string = strdup(args[cur_arg + 1]); |
| 4607 | tcpcheck->expect_regex = NULL; |
| 4608 | tcpcheck->inverse = inverse; |
| 4609 | |
| 4610 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 4611 | } |
| 4612 | else if (strcmp(ptr_arg, "rstring") == 0) { |
| 4613 | if (!*(args[cur_arg + 1])) { |
| 4614 | Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 4615 | file, linenum, args[0], args[1], ptr_arg); |
| 4616 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4617 | goto out; |
| 4618 | } |
| 4619 | struct tcpcheck_rule *tcpcheck; |
| 4620 | |
| 4621 | tcpcheck = (struct tcpcheck_rule *)calloc(1, sizeof(*tcpcheck)); |
| 4622 | |
| 4623 | tcpcheck->action = TCPCHK_ACT_EXPECT; |
| 4624 | tcpcheck->string_len = 0; |
| 4625 | tcpcheck->string = NULL; |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 4626 | tcpcheck->expect_regex = calloc(1, sizeof(*tcpcheck->expect_regex)); |
| 4627 | error = NULL; |
| 4628 | if (!regex_comp(args[cur_arg + 1], tcpcheck->expect_regex, 1, 1, &error)) { |
| 4629 | Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s': %s.\n", |
| 4630 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1], error); |
| 4631 | free(error); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 4632 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4633 | goto out; |
| 4634 | } |
| 4635 | tcpcheck->inverse = inverse; |
| 4636 | |
| 4637 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 4638 | } |
| 4639 | else { |
| 4640 | Alert("parsing [%s:%d] : '%s %s' only supports [!] 'binary', 'string', 'rstring', found '%s'.\n", |
| 4641 | file, linenum, args[0], args[1], ptr_arg); |
| 4642 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4643 | goto out; |
| 4644 | } |
| 4645 | } |
| 4646 | else { |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 4647 | 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] | 4648 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4649 | goto out; |
| 4650 | } |
| 4651 | } |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 4652 | else if (!strcmp(args[0], "monitor")) { |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 4653 | if (curproxy == &defproxy) { |
| 4654 | 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] | 4655 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4656 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 4657 | } |
| 4658 | |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 4659 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4660 | err_code |= ERR_WARN; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 4661 | |
| 4662 | if (strcmp(args[1], "fail") == 0) { |
| 4663 | /* add a condition to fail monitor requests */ |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 4664 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 4665 | Alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n", |
| 4666 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4667 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4668 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 4669 | } |
| 4670 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 4671 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 4672 | Alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition : %s.\n", |
| 4673 | file, linenum, args[0], args[1], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4674 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4675 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 4676 | } |
| 4677 | LIST_ADDQ(&curproxy->mon_fail_cond, &cond->list); |
| 4678 | } |
| 4679 | else { |
| 4680 | 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] | 4681 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4682 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 4683 | } |
| 4684 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4685 | #ifdef TPROXY |
| 4686 | else if (!strcmp(args[0], "transparent")) { |
| 4687 | /* enable transparent proxy connections */ |
| 4688 | curproxy->options |= PR_O_TRANSP; |
| 4689 | } |
| 4690 | #endif |
| 4691 | else if (!strcmp(args[0], "maxconn")) { /* maxconn */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4692 | 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] | 4693 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4694 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4695 | if (*(args[1]) == 0) { |
| 4696 | 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] | 4697 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4698 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4699 | } |
| 4700 | curproxy->maxconn = atol(args[1]); |
| 4701 | } |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 4702 | else if (!strcmp(args[0], "backlog")) { /* backlog */ |
| 4703 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4704 | err_code |= ERR_WARN; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 4705 | |
| 4706 | if (*(args[1]) == 0) { |
| 4707 | 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] | 4708 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4709 | goto out; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 4710 | } |
| 4711 | curproxy->backlog = atol(args[1]); |
| 4712 | } |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 4713 | else if (!strcmp(args[0], "fullconn")) { /* fullconn */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4714 | 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] | 4715 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4716 | |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 4717 | if (*(args[1]) == 0) { |
| 4718 | 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] | 4719 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4720 | goto out; |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 4721 | } |
| 4722 | curproxy->fullconn = atol(args[1]); |
| 4723 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4724 | else if (!strcmp(args[0], "grace")) { /* grace time (ms) */ |
| 4725 | if (*(args[1]) == 0) { |
| 4726 | 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] | 4727 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4728 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4729 | } |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4730 | err = parse_time_err(args[1], &val, TIME_UNIT_MS); |
| 4731 | if (err) { |
| 4732 | Alert("parsing [%s:%d] : unexpected character '%c' in grace time.\n", |
| 4733 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4734 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4735 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4736 | } |
| 4737 | curproxy->grace = val; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4738 | } |
| 4739 | else if (!strcmp(args[0], "dispatch")) { /* dispatch address */ |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4740 | struct sockaddr_storage *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4741 | int port1, port2; |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 4742 | struct protocol *proto; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4743 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4744 | if (curproxy == &defproxy) { |
| 4745 | 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] | 4746 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4747 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4748 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4749 | else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4750 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4751 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 4752 | sk = str2sa_range(args[1], &port1, &port2, &errmsg, NULL); |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4753 | if (!sk) { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 4754 | Alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 4755 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 4756 | goto out; |
| 4757 | } |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 4758 | |
| 4759 | proto = protocol_by_family(sk->ss_family); |
| 4760 | if (!proto || !proto->connect) { |
| 4761 | Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 4762 | file, linenum, args[0], args[1]); |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4763 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4764 | goto out; |
| 4765 | } |
| 4766 | |
| 4767 | if (port1 != port2) { |
| 4768 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'.\n", |
| 4769 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4770 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4771 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4772 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4773 | |
| 4774 | if (!port1) { |
| 4775 | Alert("parsing [%s:%d] : '%s' : missing port number in '%s', <addr:port> expected.\n", |
| 4776 | file, linenum, args[0], args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4777 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4778 | goto out; |
| 4779 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4780 | |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4781 | curproxy->dispatch_addr = *sk; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4782 | curproxy->options |= PR_O_DISPATCH; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4783 | } |
| 4784 | else if (!strcmp(args[0], "balance")) { /* set balancing with optional algorithm */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4785 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4786 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4787 | |
Willy Tarreau | a93c74b | 2012-05-08 18:14:39 +0200 | [diff] [blame] | 4788 | if (backend_parse_balance((const char **)args + 1, &errmsg, curproxy) < 0) { |
| 4789 | Alert("parsing [%s:%d] : %s %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4790 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4791 | goto out; |
Willy Tarreau | 2fcb500 | 2007-05-08 13:35:26 +0200 | [diff] [blame] | 4792 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4793 | } |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 4794 | else if (!strcmp(args[0], "hash-type")) { /* set hashing method */ |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 4795 | /** |
| 4796 | * The syntax for hash-type config element is |
| 4797 | * hash-type {map-based|consistent} [[<algo>] avalanche] |
| 4798 | * |
| 4799 | * The default hash function is sdbm for map-based and sdbm+avalanche for consistent. |
| 4800 | */ |
| 4801 | 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] | 4802 | |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 4803 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 4804 | err_code |= ERR_WARN; |
| 4805 | |
| 4806 | if (strcmp(args[1], "consistent") == 0) { /* use consistent hashing */ |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 4807 | curproxy->lbprm.algo |= BE_LB_HASH_CONS; |
| 4808 | } |
| 4809 | else if (strcmp(args[1], "map-based") == 0) { /* use map-based hashing */ |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 4810 | curproxy->lbprm.algo |= BE_LB_HASH_MAP; |
| 4811 | } |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 4812 | else if (strcmp(args[1], "avalanche") == 0) { |
| 4813 | 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]); |
| 4814 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4815 | goto out; |
Willy Tarreau | 798a39c | 2010-11-24 15:04:29 +0100 | [diff] [blame] | 4816 | } |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 4817 | else { |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 4818 | 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] | 4819 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4820 | goto out; |
| 4821 | } |
Bhaskar | 98634f0 | 2013-10-29 23:30:51 -0400 | [diff] [blame] | 4822 | |
| 4823 | /* set the hash function to use */ |
| 4824 | if (!*args[2]) { |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 4825 | /* the default algo is sdbm */ |
Bhaskar | 98634f0 | 2013-10-29 23:30:51 -0400 | [diff] [blame] | 4826 | curproxy->lbprm.algo |= BE_LB_HFCN_SDBM; |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 4827 | |
| 4828 | /* if consistent with no argument, then avalanche modifier is also applied */ |
| 4829 | if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS) |
| 4830 | curproxy->lbprm.algo |= BE_LB_HMOD_AVAL; |
Bhaskar | 98634f0 | 2013-10-29 23:30:51 -0400 | [diff] [blame] | 4831 | } else { |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 4832 | /* set the hash function */ |
| 4833 | if (!strcmp(args[2], "sdbm")) { |
| 4834 | curproxy->lbprm.algo |= BE_LB_HFCN_SDBM; |
| 4835 | } |
| 4836 | else if (!strcmp(args[2], "djb2")) { |
| 4837 | curproxy->lbprm.algo |= BE_LB_HFCN_DJB2; |
Willy Tarreau | 324f07f | 2015-01-20 19:44:50 +0100 | [diff] [blame] | 4838 | } |
| 4839 | else if (!strcmp(args[2], "wt6")) { |
Willy Tarreau | a0f4271 | 2013-11-14 14:30:35 +0100 | [diff] [blame] | 4840 | curproxy->lbprm.algo |= BE_LB_HFCN_WT6; |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 4841 | } |
Willy Tarreau | 324f07f | 2015-01-20 19:44:50 +0100 | [diff] [blame] | 4842 | else if (!strcmp(args[2], "crc32")) { |
| 4843 | curproxy->lbprm.algo |= BE_LB_HFCN_CRC32; |
| 4844 | } |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 4845 | else { |
Willy Tarreau | 324f07f | 2015-01-20 19:44:50 +0100 | [diff] [blame] | 4846 | Alert("parsing [%s:%d] : '%s' only supports 'sdbm', 'djb2', 'crc32', or 'wt6' hash functions.\n", file, linenum, args[0]); |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 4847 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4848 | goto out; |
| 4849 | } |
| 4850 | |
| 4851 | /* set the hash modifier */ |
| 4852 | if (!strcmp(args[3], "avalanche")) { |
| 4853 | curproxy->lbprm.algo |= BE_LB_HMOD_AVAL; |
| 4854 | } |
| 4855 | else if (*args[3]) { |
| 4856 | Alert("parsing [%s:%d] : '%s' only supports 'avalanche' as a modifier for hash functions.\n", file, linenum, args[0]); |
| 4857 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4858 | goto out; |
| 4859 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4860 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 4861 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 4862 | else if (strcmp(args[0], "unique-id-format") == 0) { |
| 4863 | if (!*(args[1])) { |
| 4864 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 4865 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4866 | goto out; |
| 4867 | } |
William Lallemand | 3203ff4 | 2012-11-11 17:30:56 +0100 | [diff] [blame] | 4868 | if (*(args[2])) { |
| 4869 | Alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]); |
| 4870 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4871 | goto out; |
| 4872 | } |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 4873 | free(curproxy->conf.uniqueid_format_string); |
| 4874 | curproxy->conf.uniqueid_format_string = strdup(args[1]); |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 4875 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 4876 | free(curproxy->conf.uif_file); |
| 4877 | curproxy->conf.uif_file = strdup(curproxy->conf.args.file); |
| 4878 | curproxy->conf.uif_line = curproxy->conf.args.line; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4879 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 4880 | |
| 4881 | else if (strcmp(args[0], "unique-id-header") == 0) { |
| 4882 | if (!*(args[1])) { |
| 4883 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 4884 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4885 | goto out; |
| 4886 | } |
| 4887 | free(curproxy->header_unique_id); |
| 4888 | curproxy->header_unique_id = strdup(args[1]); |
| 4889 | } |
| 4890 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4891 | else if (strcmp(args[0], "log-format") == 0) { |
| 4892 | if (!*(args[1])) { |
| 4893 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 4894 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4895 | goto out; |
| 4896 | } |
William Lallemand | 3203ff4 | 2012-11-11 17:30:56 +0100 | [diff] [blame] | 4897 | if (*(args[2])) { |
| 4898 | Alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]); |
| 4899 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4900 | goto out; |
| 4901 | } |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 4902 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 4903 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 4904 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 4905 | curproxy->conf.logformat_string != clf_http_log_format) |
| 4906 | free(curproxy->conf.logformat_string); |
| 4907 | curproxy->conf.logformat_string = strdup(args[1]); |
| 4908 | |
| 4909 | free(curproxy->conf.lfs_file); |
| 4910 | curproxy->conf.lfs_file = strdup(curproxy->conf.args.file); |
| 4911 | curproxy->conf.lfs_line = curproxy->conf.args.line; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 4912 | |
| 4913 | /* get a chance to improve log-format error reporting by |
| 4914 | * reporting the correct line-number when possible. |
| 4915 | */ |
| 4916 | if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) { |
| 4917 | Warning("parsing [%s:%d] : backend '%s' : 'log-format' directive is ignored in backends.\n", |
| 4918 | file, linenum, curproxy->id); |
| 4919 | err_code |= ERR_WARN; |
| 4920 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4921 | } |
Willy Tarreau | 094af4e | 2015-01-07 15:03:42 +0100 | [diff] [blame] | 4922 | else if (!strcmp(args[0], "log-tag")) { /* tag to report to syslog */ |
| 4923 | if (*(args[1]) == 0) { |
| 4924 | Alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]); |
| 4925 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4926 | goto out; |
| 4927 | } |
| 4928 | free(curproxy->log_tag); |
| 4929 | curproxy->log_tag = strdup(args[1]); |
| 4930 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4931 | else if (!strcmp(args[0], "log") && kwm == KWM_NO) { |
| 4932 | /* delete previous herited or defined syslog servers */ |
| 4933 | struct logsrv *back; |
| 4934 | |
| 4935 | if (*(args[1]) != 0) { |
| 4936 | Alert("parsing [%s:%d]:%s : 'no log' does not expect arguments.\n", file, linenum, args[1]); |
| 4937 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4938 | goto out; |
| 4939 | } |
| 4940 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4941 | list_for_each_entry_safe(tmplogsrv, back, &curproxy->logsrvs, list) { |
| 4942 | LIST_DEL(&tmplogsrv->list); |
| 4943 | free(tmplogsrv); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4944 | } |
| 4945 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4946 | else if (!strcmp(args[0], "log")) { /* syslog server address */ |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4947 | struct logsrv *logsrv; |
| 4948 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4949 | if (*(args[1]) && *(args[2]) == 0 && !strcmp(args[1], "global")) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4950 | /* copy global.logrsvs linked list to the end of curproxy->logsrvs */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4951 | list_for_each_entry(tmplogsrv, &global.logsrvs, list) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4952 | struct logsrv *node = malloc(sizeof(struct logsrv)); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4953 | memcpy(node, tmplogsrv, sizeof(struct logsrv)); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4954 | LIST_INIT(&node->list); |
| 4955 | LIST_ADDQ(&curproxy->logsrvs, &node->list); |
| 4956 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4957 | } |
| 4958 | else if (*(args[1]) && *(args[2])) { |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 4959 | struct sockaddr_storage *sk; |
| 4960 | int port1, port2; |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 4961 | int arg = 0; |
| 4962 | int len = 0; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4963 | |
| 4964 | logsrv = calloc(1, sizeof(struct logsrv)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4965 | |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 4966 | /* just after the address, a length may be specified */ |
| 4967 | if (strcmp(args[arg+2], "len") == 0) { |
| 4968 | len = atoi(args[arg+3]); |
| 4969 | if (len < 80 || len > 65535) { |
| 4970 | Alert("parsing [%s:%d] : invalid log length '%s', must be between 80 and 65535.\n", |
| 4971 | file, linenum, args[arg+3]); |
| 4972 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4973 | goto out; |
| 4974 | } |
| 4975 | logsrv->maxlen = len; |
| 4976 | |
| 4977 | /* skip these two args */ |
| 4978 | arg += 2; |
| 4979 | } |
| 4980 | else |
| 4981 | logsrv->maxlen = MAX_SYSLOG_LEN; |
| 4982 | |
| 4983 | if (logsrv->maxlen > global.max_syslog_len) { |
| 4984 | global.max_syslog_len = logsrv->maxlen; |
| 4985 | logline = realloc(logline, global.max_syslog_len + 1); |
| 4986 | } |
| 4987 | |
| 4988 | logsrv->facility = get_log_facility(args[arg+2]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4989 | if (logsrv->facility < 0) { |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 4990 | 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] | 4991 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4992 | goto out; |
| 4993 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4994 | } |
| 4995 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4996 | logsrv->level = 7; /* max syslog level = debug */ |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 4997 | if (*(args[arg+3])) { |
| 4998 | logsrv->level = get_log_level(args[arg+3]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4999 | if (logsrv->level < 0) { |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 5000 | 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] | 5001 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5002 | goto out; |
| 5003 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5004 | } |
| 5005 | } |
| 5006 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5007 | logsrv->minlvl = 0; /* limit syslog level to this level (emerg) */ |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 5008 | if (*(args[arg+4])) { |
| 5009 | logsrv->minlvl = get_log_level(args[arg+4]); |
Willy Tarreau | f7f057b | 2013-01-24 00:31:24 +0100 | [diff] [blame] | 5010 | if (logsrv->minlvl < 0) { |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 5011 | 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] | 5012 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5013 | goto out; |
| 5014 | |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 5015 | } |
| 5016 | } |
| 5017 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 5018 | sk = str2sa_range(args[1], &port1, &port2, &errmsg, NULL); |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 5019 | if (!sk) { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 5020 | Alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 5021 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 5022 | goto out; |
| 5023 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5024 | |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 5025 | logsrv->addr = *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5026 | |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 5027 | if (sk->ss_family == AF_INET || sk->ss_family == AF_INET6) { |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5028 | if (port1 != port2) { |
| 5029 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 5030 | file, linenum, args[0], args[1]); |
| 5031 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5032 | goto out; |
| 5033 | } |
| 5034 | |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5035 | if (!port1) |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5036 | set_host_port(&logsrv->addr, SYSLOG_PORT); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5037 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5038 | |
| 5039 | LIST_ADDQ(&curproxy->logsrvs, &logsrv->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5040 | } |
| 5041 | else { |
| 5042 | Alert("parsing [%s:%d] : 'log' expects either <address[:port]> and <facility> or 'global' as arguments.\n", |
| 5043 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5044 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5045 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5046 | } |
| 5047 | } |
| 5048 | 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] | 5049 | int cur_arg; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5050 | int port1, port2; |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 5051 | struct sockaddr_storage *sk; |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 5052 | struct protocol *proto; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5053 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5054 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5055 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5056 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5057 | if (!*args[1]) { |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5058 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optionally '%s' <addr>, and '%s' <name>.\n", |
| 5059 | file, linenum, "source", "usesrc", "interface"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5060 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5061 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5062 | } |
Willy Tarreau | 368480c | 2009-03-01 08:27:21 +0100 | [diff] [blame] | 5063 | |
| 5064 | /* we must first clear any optional default setting */ |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 5065 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 5066 | free(curproxy->conn_src.iface_name); |
| 5067 | curproxy->conn_src.iface_name = NULL; |
| 5068 | curproxy->conn_src.iface_len = 0; |
Willy Tarreau | 368480c | 2009-03-01 08:27:21 +0100 | [diff] [blame] | 5069 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 5070 | sk = str2sa_range(args[1], &port1, &port2, &errmsg, NULL); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 5071 | if (!sk) { |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 5072 | Alert("parsing [%s:%d] : '%s %s' : %s\n", |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 5073 | file, linenum, args[0], args[1], errmsg); |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 5074 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 5075 | goto out; |
| 5076 | } |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 5077 | |
| 5078 | proto = protocol_by_family(sk->ss_family); |
| 5079 | if (!proto || !proto->connect) { |
| 5080 | 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] | 5081 | file, linenum, args[0], args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 5082 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5083 | goto out; |
| 5084 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5085 | |
| 5086 | if (port1 != port2) { |
| 5087 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 5088 | file, linenum, args[0], args[1]); |
| 5089 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5090 | goto out; |
| 5091 | } |
| 5092 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 5093 | curproxy->conn_src.source_addr = *sk; |
| 5094 | curproxy->conn_src.opts |= CO_SRC_BIND; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5095 | |
| 5096 | cur_arg = 2; |
| 5097 | while (*(args[cur_arg])) { |
| 5098 | if (!strcmp(args[cur_arg], "usesrc")) { /* address to use outside */ |
Pieter Baauw | d551fb5 | 2013-05-08 22:49:23 +0200 | [diff] [blame] | 5099 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_TRANSPARENT) |
| 5100 | #if !defined(CONFIG_HAP_TRANSPARENT) |
Willy Tarreau | 9cf8d3f | 2014-05-09 22:56:10 +0200 | [diff] [blame] | 5101 | if (!is_inet_addr(&curproxy->conn_src.source_addr)) { |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5102 | Alert("parsing [%s:%d] : '%s' requires an explicit 'source' address.\n", |
| 5103 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5104 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5105 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5106 | } |
| 5107 | #endif |
| 5108 | if (!*args[cur_arg + 1]) { |
| 5109 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n", |
| 5110 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5111 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5112 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5113 | } |
| 5114 | |
| 5115 | if (!strcmp(args[cur_arg + 1], "client")) { |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 5116 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 5117 | curproxy->conn_src.opts |= CO_SRC_TPROXY_CLI; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5118 | } else if (!strcmp(args[cur_arg + 1], "clientip")) { |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 5119 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 5120 | curproxy->conn_src.opts |= CO_SRC_TPROXY_CIP; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 5121 | } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) { |
| 5122 | char *name, *end; |
| 5123 | |
| 5124 | name = args[cur_arg+1] + 7; |
| 5125 | while (isspace(*name)) |
| 5126 | name++; |
| 5127 | |
| 5128 | end = name; |
| 5129 | while (*end && !isspace(*end) && *end != ',' && *end != ')') |
| 5130 | end++; |
| 5131 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 5132 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 5133 | curproxy->conn_src.opts |= CO_SRC_TPROXY_DYN; |
| 5134 | curproxy->conn_src.bind_hdr_name = calloc(1, end - name + 1); |
| 5135 | curproxy->conn_src.bind_hdr_len = end - name; |
| 5136 | memcpy(curproxy->conn_src.bind_hdr_name, name, end - name); |
| 5137 | curproxy->conn_src.bind_hdr_name[end-name] = '\0'; |
| 5138 | curproxy->conn_src.bind_hdr_occ = -1; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 5139 | |
| 5140 | /* now look for an occurrence number */ |
| 5141 | while (isspace(*end)) |
| 5142 | end++; |
| 5143 | if (*end == ',') { |
| 5144 | end++; |
| 5145 | name = end; |
| 5146 | if (*end == '-') |
| 5147 | end++; |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 5148 | while (isdigit((int)*end)) |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 5149 | end++; |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 5150 | curproxy->conn_src.bind_hdr_occ = strl2ic(name, end-name); |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 5151 | } |
| 5152 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 5153 | if (curproxy->conn_src.bind_hdr_occ < -MAX_HDR_HISTORY) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 5154 | Alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative" |
| 5155 | " occurrences values smaller than %d.\n", |
| 5156 | file, linenum, MAX_HDR_HISTORY); |
| 5157 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5158 | goto out; |
| 5159 | } |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5160 | } else { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 5161 | struct sockaddr_storage *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5162 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 5163 | sk = str2sa_range(args[cur_arg + 1], &port1, &port2, &errmsg, NULL); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 5164 | if (!sk) { |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 5165 | Alert("parsing [%s:%d] : '%s %s' : %s\n", |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 5166 | file, linenum, args[cur_arg], args[cur_arg+1], errmsg); |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 5167 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 5168 | goto out; |
| 5169 | } |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 5170 | |
| 5171 | proto = protocol_by_family(sk->ss_family); |
| 5172 | if (!proto || !proto->connect) { |
| 5173 | Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 5174 | file, linenum, args[cur_arg], args[cur_arg+1]); |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5175 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5176 | goto out; |
| 5177 | } |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 5178 | |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5179 | if (port1 != port2) { |
| 5180 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 5181 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 5182 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5183 | goto out; |
| 5184 | } |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 5185 | curproxy->conn_src.tproxy_addr = *sk; |
| 5186 | curproxy->conn_src.opts |= CO_SRC_TPROXY_ADDR; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5187 | } |
| 5188 | global.last_checks |= LSTCHK_NETADM; |
Pieter Baauw | d551fb5 | 2013-05-08 22:49:23 +0200 | [diff] [blame] | 5189 | #if !defined(CONFIG_HAP_TRANSPARENT) |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5190 | global.last_checks |= LSTCHK_CTTPROXY; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 5191 | #endif |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5192 | #else /* no TPROXY support */ |
| 5193 | 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] | 5194 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5195 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5196 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5197 | #endif |
| 5198 | cur_arg += 2; |
| 5199 | continue; |
Willy Tarreau | 77074d5 | 2006-11-12 23:57:19 +0100 | [diff] [blame] | 5200 | } |
| 5201 | |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5202 | if (!strcmp(args[cur_arg], "interface")) { /* specifically bind to this interface */ |
| 5203 | #ifdef SO_BINDTODEVICE |
| 5204 | if (!*args[cur_arg + 1]) { |
| 5205 | Alert("parsing [%s:%d] : '%s' : missing interface name.\n", |
| 5206 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5207 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5208 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5209 | } |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 5210 | free(curproxy->conn_src.iface_name); |
| 5211 | curproxy->conn_src.iface_name = strdup(args[cur_arg + 1]); |
| 5212 | curproxy->conn_src.iface_len = strlen(curproxy->conn_src.iface_name); |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5213 | global.last_checks |= LSTCHK_NETADM; |
| 5214 | #else |
| 5215 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 5216 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5217 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5218 | goto out; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 5219 | #endif |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5220 | cur_arg += 2; |
| 5221 | continue; |
| 5222 | } |
| 5223 | 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] | 5224 | file, linenum, args[0], "interface", "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5225 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5226 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 5227 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5228 | } |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 5229 | else if (!strcmp(args[0], "usesrc")) { /* address to use outside: needs "source" first */ |
| 5230 | Alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n", |
| 5231 | file, linenum, "usesrc", "source"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5232 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5233 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 5234 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5235 | 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] | 5236 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5237 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 5238 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5239 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5240 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5241 | } |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5242 | |
| 5243 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5244 | SMP_OPT_DIR_REQ, ACT_REPLACE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5245 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5246 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5247 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5248 | } |
| 5249 | else if (!strcmp(args[0], "reqdel")) { /* delete request header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5250 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5251 | SMP_OPT_DIR_REQ, ACT_REMOVE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5252 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5253 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5254 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5255 | } |
| 5256 | 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] | 5257 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5258 | SMP_OPT_DIR_REQ, ACT_DENY, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5259 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5260 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5261 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5262 | } |
| 5263 | 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] | 5264 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5265 | SMP_OPT_DIR_REQ, ACT_PASS, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5266 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5267 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5268 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5269 | } |
| 5270 | 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] | 5271 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5272 | SMP_OPT_DIR_REQ, ACT_ALLOW, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5273 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5274 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5275 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5276 | } |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 5277 | 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] | 5278 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5279 | SMP_OPT_DIR_REQ, ACT_TARPIT, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5280 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5281 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5282 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 5283 | } |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5284 | 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] | 5285 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5286 | SMP_OPT_DIR_REQ, ACT_SETBE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5287 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5288 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5289 | goto out; |
Willy Tarreau | 40bac83 | 2014-04-28 22:37:06 +0200 | [diff] [blame] | 5290 | |
| 5291 | if (!already_warned(WARN_REQSETBE_DEPRECATED)) |
| 5292 | 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] | 5293 | } |
| 5294 | 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] | 5295 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5296 | SMP_OPT_DIR_REQ, ACT_SETBE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5297 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5298 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5299 | goto out; |
Willy Tarreau | 40bac83 | 2014-04-28 22:37:06 +0200 | [diff] [blame] | 5300 | |
| 5301 | if (!already_warned(WARN_REQSETBE_DEPRECATED)) |
| 5302 | 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] | 5303 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5304 | 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] | 5305 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5306 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 5307 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5308 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5309 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5310 | } |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5311 | |
| 5312 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5313 | SMP_OPT_DIR_REQ, ACT_REPLACE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5314 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5315 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5316 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5317 | } |
| 5318 | 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] | 5319 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5320 | SMP_OPT_DIR_REQ, ACT_REMOVE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5321 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5322 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5323 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5324 | } |
| 5325 | 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] | 5326 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5327 | SMP_OPT_DIR_REQ, ACT_DENY, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5328 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5329 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5330 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5331 | } |
| 5332 | 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] | 5333 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5334 | SMP_OPT_DIR_REQ, ACT_PASS, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5335 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5336 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5337 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5338 | } |
| 5339 | 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] | 5340 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5341 | SMP_OPT_DIR_REQ, ACT_ALLOW, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5342 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5343 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5344 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5345 | } |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 5346 | 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] | 5347 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5348 | SMP_OPT_DIR_REQ, ACT_TARPIT, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5349 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5350 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5351 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 5352 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5353 | else if (!strcmp(args[0], "reqadd")) { /* add request header */ |
Willy Tarreau | f4f0412 | 2010-01-28 18:10:50 +0100 | [diff] [blame] | 5354 | struct cond_wordlist *wl; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5355 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5356 | if (curproxy == &defproxy) { |
| 5357 | 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] | 5358 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5359 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5360 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5361 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5362 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5363 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5364 | if (*(args[1]) == 0) { |
| 5365 | 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] | 5366 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5367 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5368 | } |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5369 | |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 5370 | if ((strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0)) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 5371 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args+2, &errmsg)) == NULL) { |
| 5372 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 5373 | file, linenum, args[0], errmsg); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 5374 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5375 | goto out; |
| 5376 | } |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 5377 | err_code |= warnif_cond_conflicts(cond, |
| 5378 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 5379 | file, linenum); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 5380 | } |
| 5381 | else if (*args[2]) { |
| 5382 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 5383 | file, linenum, args[0], args[2]); |
| 5384 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5385 | goto out; |
| 5386 | } |
| 5387 | |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5388 | wl = calloc(1, sizeof(*wl)); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 5389 | wl->cond = cond; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5390 | wl->s = strdup(args[1]); |
| 5391 | LIST_ADDQ(&curproxy->req_add, &wl->list); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 5392 | warnif_misplaced_reqadd(curproxy, file, linenum, args[0]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5393 | } |
| 5394 | 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] | 5395 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5396 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 5397 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5398 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5399 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5400 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5401 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5402 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5403 | SMP_OPT_DIR_RES, ACT_REPLACE, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5404 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5405 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5406 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5407 | } |
| 5408 | else if (!strcmp(args[0], "rspdel")) { /* delete response header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5409 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5410 | SMP_OPT_DIR_RES, ACT_REMOVE, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5411 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5412 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5413 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5414 | } |
| 5415 | else if (!strcmp(args[0], "rspdeny")) { /* block response header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5416 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5417 | SMP_OPT_DIR_RES, ACT_DENY, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5418 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5419 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5420 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5421 | } |
| 5422 | 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] | 5423 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5424 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 5425 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5426 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5427 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5428 | } |
| 5429 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5430 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5431 | SMP_OPT_DIR_RES, ACT_REPLACE, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5432 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5433 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5434 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5435 | } |
| 5436 | 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] | 5437 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5438 | SMP_OPT_DIR_RES, ACT_REMOVE, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5439 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5440 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5441 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5442 | } |
| 5443 | 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] | 5444 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5445 | SMP_OPT_DIR_RES, ACT_DENY, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5446 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5447 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5448 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5449 | } |
| 5450 | else if (!strcmp(args[0], "rspadd")) { /* add response header */ |
Willy Tarreau | f4f0412 | 2010-01-28 18:10:50 +0100 | [diff] [blame] | 5451 | struct cond_wordlist *wl; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5452 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5453 | if (curproxy == &defproxy) { |
| 5454 | 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] | 5455 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5456 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5457 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5458 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5459 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5460 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5461 | if (*(args[1]) == 0) { |
| 5462 | 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] | 5463 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5464 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5465 | } |
| 5466 | |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5467 | if ((strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0)) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 5468 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args+2, &errmsg)) == NULL) { |
| 5469 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 5470 | file, linenum, args[0], errmsg); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5471 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5472 | goto out; |
| 5473 | } |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 5474 | err_code |= warnif_cond_conflicts(cond, |
| 5475 | (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR, |
| 5476 | file, linenum); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5477 | } |
| 5478 | else if (*args[2]) { |
| 5479 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 5480 | file, linenum, args[0], args[2]); |
| 5481 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5482 | goto out; |
| 5483 | } |
| 5484 | |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5485 | wl = calloc(1, sizeof(*wl)); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5486 | wl->cond = cond; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5487 | wl->s = strdup(args[1]); |
| 5488 | LIST_ADDQ(&curproxy->rsp_add, &wl->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5489 | } |
| 5490 | else if (!strcmp(args[0], "errorloc") || |
| 5491 | !strcmp(args[0], "errorloc302") || |
| 5492 | !strcmp(args[0], "errorloc303")) { /* error location */ |
| 5493 | int errnum, errlen; |
| 5494 | char *err; |
| 5495 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5496 | 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] | 5497 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5498 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5499 | if (*(args[2]) == 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 5500 | 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] | 5501 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5502 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5503 | } |
| 5504 | |
| 5505 | errnum = atol(args[1]); |
| 5506 | if (!strcmp(args[0], "errorloc303")) { |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 5507 | errlen = strlen(HTTP_303) + strlen(args[2]) + 5; |
| 5508 | err = malloc(errlen); |
| 5509 | 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] | 5510 | } else { |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 5511 | errlen = strlen(HTTP_302) + strlen(args[2]) + 5; |
| 5512 | err = malloc(errlen); |
| 5513 | 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] | 5514 | } |
| 5515 | |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 5516 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) { |
| 5517 | if (http_err_codes[rc] == errnum) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 5518 | chunk_destroy(&curproxy->errmsg[rc]); |
| 5519 | chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 5520 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5521 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5522 | } |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 5523 | |
| 5524 | if (rc >= HTTP_ERR_SIZE) { |
| 5525 | Warning("parsing [%s:%d] : status code %d not handled, error relocation will be ignored.\n", |
| 5526 | file, linenum, errnum); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5527 | free(err); |
| 5528 | } |
| 5529 | } |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5530 | else if (!strcmp(args[0], "errorfile")) { /* error message from a file */ |
| 5531 | int errnum, errlen, fd; |
| 5532 | char *err; |
| 5533 | struct stat stat; |
| 5534 | |
| 5535 | 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] | 5536 | err_code |= ERR_WARN; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5537 | |
| 5538 | if (*(args[2]) == 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 5539 | 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] | 5540 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5541 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5542 | } |
| 5543 | |
| 5544 | fd = open(args[2], O_RDONLY); |
| 5545 | if ((fd < 0) || (fstat(fd, &stat) < 0)) { |
| 5546 | Alert("parsing [%s:%d] : error opening file <%s> for custom error message <%s>.\n", |
| 5547 | file, linenum, args[2], args[1]); |
| 5548 | if (fd >= 0) |
| 5549 | close(fd); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5550 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5551 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5552 | } |
| 5553 | |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 5554 | if (stat.st_size <= global.tune.bufsize) { |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5555 | errlen = stat.st_size; |
| 5556 | } else { |
| 5557 | 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] | 5558 | file, linenum, args[2], global.tune.bufsize); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5559 | err_code |= ERR_WARN; |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 5560 | errlen = global.tune.bufsize; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5561 | } |
| 5562 | |
| 5563 | err = malloc(errlen); /* malloc() must succeed during parsing */ |
| 5564 | errnum = read(fd, err, errlen); |
| 5565 | if (errnum != errlen) { |
| 5566 | Alert("parsing [%s:%d] : error reading file <%s> for custom error message <%s>.\n", |
| 5567 | file, linenum, args[2], args[1]); |
| 5568 | close(fd); |
| 5569 | free(err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5570 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5571 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5572 | } |
| 5573 | close(fd); |
| 5574 | |
| 5575 | errnum = atol(args[1]); |
| 5576 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) { |
| 5577 | if (http_err_codes[rc] == errnum) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 5578 | chunk_destroy(&curproxy->errmsg[rc]); |
| 5579 | chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen); |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5580 | break; |
| 5581 | } |
| 5582 | } |
| 5583 | |
| 5584 | if (rc >= HTTP_ERR_SIZE) { |
| 5585 | Warning("parsing [%s:%d] : status code %d not handled, error customization will be ignored.\n", |
| 5586 | file, linenum, errnum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5587 | err_code |= ERR_WARN; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5588 | free(err); |
| 5589 | } |
| 5590 | } |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5591 | else if (!strcmp(args[0], "compression")) { |
| 5592 | struct comp *comp; |
| 5593 | if (curproxy->comp == NULL) { |
| 5594 | comp = calloc(1, sizeof(struct comp)); |
| 5595 | curproxy->comp = comp; |
| 5596 | } else { |
| 5597 | comp = curproxy->comp; |
| 5598 | } |
| 5599 | |
| 5600 | if (!strcmp(args[1], "algo")) { |
| 5601 | int cur_arg; |
William Lallemand | 8b52bb3 | 2012-11-16 18:06:41 +0100 | [diff] [blame] | 5602 | struct comp_ctx *ctx; |
William Lallemand | 552df67 | 2012-11-07 13:21:47 +0100 | [diff] [blame] | 5603 | |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5604 | cur_arg = 2; |
| 5605 | if (!*args[cur_arg]) { |
| 5606 | Alert("parsing [%s:%d] : '%s' expects <algorithm>\n", |
| 5607 | file, linenum, args[0]); |
| 5608 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5609 | goto out; |
| 5610 | } |
| 5611 | while (*(args[cur_arg])) { |
| 5612 | if (comp_append_algo(comp, args[cur_arg]) < 0) { |
| 5613 | Alert("parsing [%s:%d] : '%s' : '%s' is not a supported algorithm.\n", |
| 5614 | file, linenum, args[0], args[cur_arg]); |
| 5615 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5616 | goto out; |
| 5617 | } |
William Lallemand | 552df67 | 2012-11-07 13:21:47 +0100 | [diff] [blame] | 5618 | if (curproxy->comp->algos->init(&ctx, 9) == 0) { |
| 5619 | curproxy->comp->algos->end(&ctx); |
| 5620 | } else { |
| 5621 | Alert("parsing [%s:%d] : '%s' : Can't init '%s' algorithm.\n", |
| 5622 | file, linenum, args[0], args[cur_arg]); |
| 5623 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5624 | goto out; |
| 5625 | } |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5626 | cur_arg ++; |
| 5627 | continue; |
| 5628 | } |
| 5629 | } |
Willy Tarreau | 70737d1 | 2012-10-27 00:34:28 +0200 | [diff] [blame] | 5630 | else if (!strcmp(args[1], "offload")) { |
| 5631 | comp->offload = 1; |
| 5632 | } |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5633 | else if (!strcmp(args[1], "type")) { |
| 5634 | int cur_arg; |
| 5635 | cur_arg = 2; |
| 5636 | if (!*args[cur_arg]) { |
| 5637 | Alert("parsing [%s:%d] : '%s' expects <type>\n", |
| 5638 | file, linenum, args[0]); |
| 5639 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5640 | goto out; |
| 5641 | } |
| 5642 | while (*(args[cur_arg])) { |
| 5643 | comp_append_type(comp, args[cur_arg]); |
| 5644 | cur_arg ++; |
| 5645 | continue; |
| 5646 | } |
| 5647 | } |
| 5648 | else { |
Willy Tarreau | 70737d1 | 2012-10-27 00:34:28 +0200 | [diff] [blame] | 5649 | Alert("parsing [%s:%d] : '%s' expects 'algo', 'type' or 'offload'\n", |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5650 | file, linenum, args[0]); |
| 5651 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5652 | goto out; |
| 5653 | } |
| 5654 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5655 | else { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 5656 | struct cfg_kw_list *kwl; |
| 5657 | int index; |
| 5658 | |
| 5659 | list_for_each_entry(kwl, &cfg_keywords.list, list) { |
| 5660 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 5661 | if (kwl->kw[index].section != CFG_LISTEN) |
| 5662 | continue; |
| 5663 | if (strcmp(kwl->kw[index].kw, args[0]) == 0) { |
| 5664 | /* prepare error message just in case */ |
Willy Tarreau | 28a47d6 | 2012-09-18 20:02:48 +0200 | [diff] [blame] | 5665 | 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] | 5666 | if (rc < 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 5667 | Alert("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5668 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5669 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 5670 | } |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 5671 | else if (rc > 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 5672 | Warning("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5673 | err_code |= ERR_WARN; |
| 5674 | goto out; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 5675 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5676 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 5677 | } |
| 5678 | } |
| 5679 | } |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5680 | |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5681 | 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] | 5682 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5683 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5684 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5685 | out: |
Willy Tarreau | f4068b6 | 2012-05-08 17:37:49 +0200 | [diff] [blame] | 5686 | free(errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5687 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5688 | } |
| 5689 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5690 | int |
KOVACS Krisztian | b3e54fe | 2014-11-17 15:11:45 +0100 | [diff] [blame] | 5691 | cfg_parse_netns(const char *file, int linenum, char **args, int kwm) |
| 5692 | { |
| 5693 | #ifdef CONFIG_HAP_NS |
| 5694 | const char *err; |
| 5695 | const char *item = args[0]; |
| 5696 | |
| 5697 | if (!strcmp(item, "namespace_list")) { |
| 5698 | return 0; |
| 5699 | } |
| 5700 | else if (!strcmp(item, "namespace")) { |
| 5701 | size_t idx = 1; |
| 5702 | const char *current; |
| 5703 | while (*(current = args[idx++])) { |
| 5704 | err = invalid_char(current); |
| 5705 | if (err) { |
| 5706 | Alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 5707 | file, linenum, *err, item, current); |
| 5708 | return ERR_ALERT | ERR_FATAL; |
| 5709 | } |
| 5710 | |
| 5711 | if (netns_store_lookup(current, strlen(current))) { |
| 5712 | Alert("parsing [%s:%d]: Namespace '%s' is already added.\n", |
| 5713 | file, linenum, current); |
| 5714 | return ERR_ALERT | ERR_FATAL; |
| 5715 | } |
| 5716 | if (!netns_store_insert(current)) { |
| 5717 | Alert("parsing [%s:%d]: Cannot open namespace '%s'.\n", |
| 5718 | file, linenum, current); |
| 5719 | return ERR_ALERT | ERR_FATAL; |
| 5720 | } |
| 5721 | } |
| 5722 | } |
| 5723 | |
| 5724 | return 0; |
| 5725 | #else |
| 5726 | Alert("parsing [%s:%d]: namespace support is not compiled in.", |
| 5727 | file, linenum); |
| 5728 | return ERR_ALERT | ERR_FATAL; |
| 5729 | #endif |
| 5730 | } |
| 5731 | |
| 5732 | int |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5733 | cfg_parse_users(const char *file, int linenum, char **args, int kwm) |
| 5734 | { |
| 5735 | |
| 5736 | int err_code = 0; |
| 5737 | const char *err; |
| 5738 | |
| 5739 | if (!strcmp(args[0], "userlist")) { /* new userlist */ |
| 5740 | struct userlist *newul; |
| 5741 | |
| 5742 | if (!*args[1]) { |
| 5743 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 5744 | file, linenum, args[0]); |
| 5745 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5746 | goto out; |
| 5747 | } |
| 5748 | |
| 5749 | err = invalid_char(args[1]); |
| 5750 | if (err) { |
| 5751 | Alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 5752 | file, linenum, *err, args[0], args[1]); |
| 5753 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5754 | goto out; |
| 5755 | } |
| 5756 | |
| 5757 | for (newul = userlist; newul; newul = newul->next) |
| 5758 | if (!strcmp(newul->name, args[1])) { |
| 5759 | Warning("parsing [%s:%d]: ignoring duplicated userlist '%s'.\n", |
| 5760 | file, linenum, args[1]); |
| 5761 | err_code |= ERR_WARN; |
| 5762 | goto out; |
| 5763 | } |
| 5764 | |
| 5765 | newul = (struct userlist *)calloc(1, sizeof(struct userlist)); |
| 5766 | if (!newul) { |
| 5767 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 5768 | err_code |= ERR_ALERT | ERR_ABORT; |
| 5769 | goto out; |
| 5770 | } |
| 5771 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5772 | newul->name = strdup(args[1]); |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 5773 | if (!newul->name) { |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5774 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 5775 | err_code |= ERR_ALERT | ERR_ABORT; |
| 5776 | goto out; |
| 5777 | } |
| 5778 | |
| 5779 | newul->next = userlist; |
| 5780 | userlist = newul; |
| 5781 | |
| 5782 | } else if (!strcmp(args[0], "group")) { /* new group */ |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 5783 | int cur_arg; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5784 | const char *err; |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 5785 | struct auth_groups *ag; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5786 | |
| 5787 | if (!*args[1]) { |
| 5788 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 5789 | file, linenum, args[0]); |
| 5790 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5791 | goto out; |
| 5792 | } |
| 5793 | |
| 5794 | err = invalid_char(args[1]); |
| 5795 | if (err) { |
| 5796 | Alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 5797 | file, linenum, *err, args[0], args[1]); |
| 5798 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5799 | goto out; |
| 5800 | } |
| 5801 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 5802 | for (ag = userlist->groups; ag; ag = ag->next) |
| 5803 | if (!strcmp(ag->name, args[1])) { |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5804 | Warning("parsing [%s:%d]: ignoring duplicated group '%s' in userlist '%s'.\n", |
| 5805 | file, linenum, args[1], userlist->name); |
| 5806 | err_code |= ERR_ALERT; |
| 5807 | goto out; |
| 5808 | } |
| 5809 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 5810 | ag = calloc(1, sizeof(*ag)); |
| 5811 | if (!ag) { |
| 5812 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 5813 | err_code |= ERR_ALERT | ERR_ABORT; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5814 | goto out; |
| 5815 | } |
| 5816 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 5817 | ag->name = strdup(args[1]); |
| 5818 | if (!ag) { |
| 5819 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 5820 | err_code |= ERR_ALERT | ERR_ABORT; |
| 5821 | goto out; |
| 5822 | } |
| 5823 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5824 | cur_arg = 2; |
| 5825 | |
| 5826 | while (*args[cur_arg]) { |
| 5827 | if (!strcmp(args[cur_arg], "users")) { |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 5828 | ag->groupusers = strdup(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5829 | cur_arg += 2; |
| 5830 | continue; |
| 5831 | } else { |
| 5832 | Alert("parsing [%s:%d]: '%s' only supports 'users' option.\n", |
| 5833 | file, linenum, args[0]); |
| 5834 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5835 | goto out; |
| 5836 | } |
| 5837 | } |
| 5838 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 5839 | ag->next = userlist->groups; |
| 5840 | userlist->groups = ag; |
| 5841 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5842 | } else if (!strcmp(args[0], "user")) { /* new user */ |
| 5843 | struct auth_users *newuser; |
| 5844 | int cur_arg; |
| 5845 | |
| 5846 | if (!*args[1]) { |
| 5847 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 5848 | file, linenum, args[0]); |
| 5849 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5850 | goto out; |
| 5851 | } |
| 5852 | |
| 5853 | for (newuser = userlist->users; newuser; newuser = newuser->next) |
| 5854 | if (!strcmp(newuser->user, args[1])) { |
| 5855 | Warning("parsing [%s:%d]: ignoring duplicated user '%s' in userlist '%s'.\n", |
| 5856 | file, linenum, args[1], userlist->name); |
| 5857 | err_code |= ERR_ALERT; |
| 5858 | goto out; |
| 5859 | } |
| 5860 | |
| 5861 | newuser = (struct auth_users *)calloc(1, sizeof(struct auth_users)); |
| 5862 | if (!newuser) { |
| 5863 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 5864 | err_code |= ERR_ALERT | ERR_ABORT; |
| 5865 | goto out; |
| 5866 | } |
| 5867 | |
| 5868 | newuser->user = strdup(args[1]); |
| 5869 | |
| 5870 | newuser->next = userlist->users; |
| 5871 | userlist->users = newuser; |
| 5872 | |
| 5873 | cur_arg = 2; |
| 5874 | |
| 5875 | while (*args[cur_arg]) { |
| 5876 | if (!strcmp(args[cur_arg], "password")) { |
Cyril Bonté | 1a0191d | 2014-08-29 20:20:02 +0200 | [diff] [blame] | 5877 | #ifdef CONFIG_HAP_CRYPT |
| 5878 | if (!crypt("", args[cur_arg + 1])) { |
| 5879 | Alert("parsing [%s:%d]: the encrypted password used for user '%s' is not supported by crypt(3).\n", |
| 5880 | file, linenum, newuser->user); |
| 5881 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5882 | goto out; |
| 5883 | } |
| 5884 | #else |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5885 | Warning("parsing [%s:%d]: no crypt(3) support compiled, encrypted passwords will not work.\n", |
| 5886 | file, linenum); |
| 5887 | err_code |= ERR_ALERT; |
| 5888 | #endif |
| 5889 | newuser->pass = strdup(args[cur_arg + 1]); |
| 5890 | cur_arg += 2; |
| 5891 | continue; |
| 5892 | } else if (!strcmp(args[cur_arg], "insecure-password")) { |
| 5893 | newuser->pass = strdup(args[cur_arg + 1]); |
| 5894 | newuser->flags |= AU_O_INSECURE; |
| 5895 | cur_arg += 2; |
| 5896 | continue; |
| 5897 | } else if (!strcmp(args[cur_arg], "groups")) { |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 5898 | newuser->u.groups_names = strdup(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5899 | cur_arg += 2; |
| 5900 | continue; |
| 5901 | } else { |
| 5902 | Alert("parsing [%s:%d]: '%s' only supports 'password', 'insecure-password' and 'groups' options.\n", |
| 5903 | file, linenum, args[0]); |
| 5904 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5905 | goto out; |
| 5906 | } |
| 5907 | } |
| 5908 | } else { |
| 5909 | Alert("parsing [%s:%d]: unknown keyword '%s' in '%s' section\n", file, linenum, args[0], "users"); |
| 5910 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5911 | } |
| 5912 | |
| 5913 | out: |
| 5914 | return err_code; |
| 5915 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5916 | |
| 5917 | /* |
| 5918 | * This function reads and parses the configuration file given in the argument. |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5919 | * Returns the error code, 0 if OK, or any combination of : |
| 5920 | * - ERR_ABORT: must abort ASAP |
| 5921 | * - ERR_FATAL: we can continue parsing but not start the service |
| 5922 | * - ERR_WARN: a warning has been emitted |
| 5923 | * - ERR_ALERT: an alert has been emitted |
| 5924 | * Only the two first ones can stop processing, the two others are just |
| 5925 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5926 | */ |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 5927 | int readcfgfile(const char *file) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5928 | { |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5929 | char thisline[LINESIZE]; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5930 | FILE *f; |
| 5931 | int linenum = 0; |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5932 | int err_code = 0; |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 5933 | struct cfg_section *cs = NULL; |
| 5934 | struct cfg_section *ics; |
| 5935 | |
| 5936 | /* Register internal sections */ |
| 5937 | if (!cfg_register_section("listen", cfg_parse_listen) || |
| 5938 | !cfg_register_section("frontend", cfg_parse_listen) || |
| 5939 | !cfg_register_section("backend", cfg_parse_listen) || |
| 5940 | !cfg_register_section("ruleset", cfg_parse_listen) || |
| 5941 | !cfg_register_section("defaults", cfg_parse_listen) || |
| 5942 | !cfg_register_section("global", cfg_parse_global) || |
| 5943 | !cfg_register_section("userlist", cfg_parse_users) || |
KOVACS Krisztian | b3e54fe | 2014-11-17 15:11:45 +0100 | [diff] [blame] | 5944 | !cfg_register_section("peers", cfg_parse_peers) || |
| 5945 | !cfg_register_section("namespace_list", cfg_parse_netns)) |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 5946 | return -1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5947 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5948 | if ((f=fopen(file,"r")) == NULL) |
| 5949 | return -1; |
| 5950 | |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5951 | while (fgets(thisline, sizeof(thisline), f) != NULL) { |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 5952 | int arg, kwm = KWM_STD; |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5953 | char *end; |
| 5954 | char *args[MAX_LINE_ARGS + 1]; |
| 5955 | char *line = thisline; |
| 5956 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5957 | linenum++; |
| 5958 | |
| 5959 | end = line + strlen(line); |
| 5960 | |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5961 | if (end-line == sizeof(thisline)-1 && *(end-1) != '\n') { |
| 5962 | /* Check if we reached the limit and the last char is not \n. |
| 5963 | * Watch out for the last line without the terminating '\n'! |
| 5964 | */ |
| 5965 | Alert("parsing [%s:%d]: line too long, limit: %d.\n", |
Willy Tarreau | 5e4a6f1 | 2009-04-11 19:42:49 +0200 | [diff] [blame] | 5966 | file, linenum, (int)sizeof(thisline)-1); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5967 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5968 | } |
| 5969 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5970 | /* skip leading spaces */ |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 5971 | while (isspace((unsigned char)*line)) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5972 | line++; |
| 5973 | |
| 5974 | arg = 0; |
| 5975 | args[arg] = line; |
| 5976 | |
| 5977 | while (*line && arg < MAX_LINE_ARGS) { |
| 5978 | /* first, we'll replace \\, \<space>, \#, \r, \n, \t, \xXX with their |
| 5979 | * C equivalent value. Other combinations left unchanged (eg: \1). |
| 5980 | */ |
| 5981 | if (*line == '\\') { |
| 5982 | int skip = 0; |
| 5983 | if (line[1] == ' ' || line[1] == '\\' || line[1] == '#') { |
| 5984 | *line = line[1]; |
| 5985 | skip = 1; |
| 5986 | } |
| 5987 | else if (line[1] == 'r') { |
| 5988 | *line = '\r'; |
| 5989 | skip = 1; |
| 5990 | } |
| 5991 | else if (line[1] == 'n') { |
| 5992 | *line = '\n'; |
| 5993 | skip = 1; |
| 5994 | } |
| 5995 | else if (line[1] == 't') { |
| 5996 | *line = '\t'; |
| 5997 | skip = 1; |
| 5998 | } |
| 5999 | else if (line[1] == 'x') { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6000 | if ((line + 3 < end) && ishex(line[2]) && ishex(line[3])) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6001 | unsigned char hex1, hex2; |
| 6002 | hex1 = toupper(line[2]) - '0'; |
| 6003 | hex2 = toupper(line[3]) - '0'; |
| 6004 | if (hex1 > 9) hex1 -= 'A' - '9' - 1; |
| 6005 | if (hex2 > 9) hex2 -= 'A' - '9' - 1; |
| 6006 | *line = (hex1<<4) + hex2; |
| 6007 | skip = 3; |
| 6008 | } |
| 6009 | else { |
| 6010 | 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] | 6011 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6012 | } |
| 6013 | } |
| 6014 | if (skip) { |
Cyril Bonté | dd1b01d | 2009-12-06 13:43:42 +0100 | [diff] [blame] | 6015 | memmove(line + 1, line + 1 + skip, end - (line + skip)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6016 | end -= skip; |
| 6017 | } |
| 6018 | line++; |
| 6019 | } |
| 6020 | else if (*line == '#' || *line == '\n' || *line == '\r') { |
| 6021 | /* end of string, end of loop */ |
| 6022 | *line = 0; |
| 6023 | break; |
| 6024 | } |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 6025 | else if (isspace((unsigned char)*line)) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6026 | /* a non-escaped space is an argument separator */ |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 6027 | *line++ = '\0'; |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 6028 | while (isspace((unsigned char)*line)) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6029 | line++; |
| 6030 | args[++arg] = line; |
| 6031 | } |
| 6032 | else { |
| 6033 | line++; |
| 6034 | } |
| 6035 | } |
| 6036 | |
| 6037 | /* empty line */ |
| 6038 | if (!**args) |
| 6039 | continue; |
| 6040 | |
Willy Tarreau | 7bb651e | 2009-11-09 21:16:53 +0100 | [diff] [blame] | 6041 | if (*line) { |
| 6042 | /* we had to stop due to too many args. |
| 6043 | * Let's terminate the string, print the offending part then cut the |
| 6044 | * last arg. |
| 6045 | */ |
| 6046 | while (*line && *line != '#' && *line != '\n' && *line != '\r') |
| 6047 | line++; |
| 6048 | *line = '\0'; |
| 6049 | |
Krzysztof Piotr Oledzki | 500b8f0 | 2009-12-15 22:34:51 +0100 | [diff] [blame] | 6050 | 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] | 6051 | file, linenum, arg + 1, (long)(args[arg] - thisline + 1), args[arg]); |
Willy Tarreau | 7bb651e | 2009-11-09 21:16:53 +0100 | [diff] [blame] | 6052 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6053 | args[arg] = line; |
| 6054 | } |
| 6055 | |
Willy Tarreau | 540abe4 | 2007-05-02 20:50:16 +0200 | [diff] [blame] | 6056 | /* zero out remaining args and ensure that at least one entry |
| 6057 | * is zeroed out. |
| 6058 | */ |
| 6059 | while (++arg <= MAX_LINE_ARGS) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6060 | args[arg] = line; |
| 6061 | } |
| 6062 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 6063 | /* check for keyword modifiers "no" and "default" */ |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 6064 | if (!strcmp(args[0], "no")) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6065 | char *tmp; |
| 6066 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 6067 | kwm = KWM_NO; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6068 | tmp = args[0]; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 6069 | for (arg=0; *args[arg+1]; arg++) |
| 6070 | args[arg] = args[arg+1]; // shift args after inversion |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6071 | *tmp = '\0'; // fix the next arg to \0 |
| 6072 | args[arg] = tmp; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 6073 | } |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 6074 | else if (!strcmp(args[0], "default")) { |
| 6075 | kwm = KWM_DEF; |
| 6076 | for (arg=0; *args[arg+1]; arg++) |
| 6077 | args[arg] = args[arg+1]; // shift args after inversion |
| 6078 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 6079 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6080 | if (kwm != KWM_STD && strcmp(args[0], "option") != 0 && \ |
| 6081 | strcmp(args[0], "log") != 0) { |
| 6082 | 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] | 6083 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 6084 | } |
| 6085 | |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 6086 | /* detect section start */ |
| 6087 | list_for_each_entry(ics, §ions, list) { |
| 6088 | if (strcmp(args[0], ics->section_name) == 0) { |
| 6089 | cursection = ics->section_name; |
| 6090 | cs = ics; |
| 6091 | break; |
| 6092 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 6093 | } |
| 6094 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6095 | /* else it's a section keyword */ |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 6096 | if (cs) |
| 6097 | err_code |= cs->section_parser(file, linenum, args, kwm); |
| 6098 | else { |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6099 | 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] | 6100 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6101 | } |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 6102 | |
| 6103 | if (err_code & ERR_ABORT) |
| 6104 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6105 | } |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 6106 | cursection = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6107 | fclose(f); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 6108 | return err_code; |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6109 | } |
| 6110 | |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 6111 | /* This function propagates processes from frontend <from> to backend <to> so |
| 6112 | * that it is always guaranteed that a backend pointed to by a frontend is |
| 6113 | * bound to all of its processes. After that, if the target is a "listen" |
| 6114 | * instance, the function recursively descends the target's own targets along |
| 6115 | * default_backend, use_backend rules, and reqsetbe rules. Since the bits are |
| 6116 | * checked first to ensure that <to> is already bound to all processes of |
| 6117 | * <from>, there is no risk of looping and we ensure to follow the shortest |
| 6118 | * path to the destination. |
| 6119 | * |
| 6120 | * It is possible to set <to> to NULL for the first call so that the function |
| 6121 | * takes care of visiting the initial frontend in <from>. |
| 6122 | * |
| 6123 | * It is important to note that the function relies on the fact that all names |
| 6124 | * have already been resolved. |
| 6125 | */ |
| 6126 | void propagate_processes(struct proxy *from, struct proxy *to) |
| 6127 | { |
| 6128 | struct switching_rule *rule; |
| 6129 | struct hdr_exp *exp; |
| 6130 | |
| 6131 | if (to) { |
| 6132 | /* check whether we need to go down */ |
| 6133 | if (from->bind_proc && |
| 6134 | (from->bind_proc & to->bind_proc) == from->bind_proc) |
| 6135 | return; |
| 6136 | |
| 6137 | if (!from->bind_proc && !to->bind_proc) |
| 6138 | return; |
| 6139 | |
| 6140 | to->bind_proc = from->bind_proc ? |
| 6141 | (to->bind_proc | from->bind_proc) : 0; |
| 6142 | |
| 6143 | /* now propagate down */ |
| 6144 | from = to; |
| 6145 | } |
| 6146 | |
Willy Tarreau | 8a95d8c | 2014-12-18 13:56:26 +0100 | [diff] [blame] | 6147 | if (!(from->cap & PR_CAP_FE)) |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 6148 | return; |
| 6149 | |
Willy Tarreau | f6b7001 | 2014-12-18 14:00:43 +0100 | [diff] [blame] | 6150 | if (from->state == PR_STSTOPPED) |
| 6151 | return; |
| 6152 | |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 6153 | /* default_backend */ |
| 6154 | if (from->defbe.be) |
| 6155 | propagate_processes(from, from->defbe.be); |
| 6156 | |
| 6157 | /* use_backend */ |
| 6158 | list_for_each_entry(rule, &from->switching_rules, list) { |
Cyril Bonté | 5163969 | 2014-10-02 19:56:25 +0200 | [diff] [blame] | 6159 | if (rule->dynamic) |
| 6160 | continue; |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 6161 | to = rule->be.backend; |
| 6162 | propagate_processes(from, to); |
| 6163 | } |
| 6164 | |
| 6165 | /* reqsetbe */ |
| 6166 | for (exp = from->req_exp; exp != NULL; exp = exp->next) { |
| 6167 | if (exp->action != ACT_SETBE) |
| 6168 | continue; |
| 6169 | to = (struct proxy *)exp->replace; |
| 6170 | propagate_processes(from, to); |
| 6171 | } |
| 6172 | } |
| 6173 | |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6174 | /* |
| 6175 | * Returns the error code, 0 if OK, or any combination of : |
| 6176 | * - ERR_ABORT: must abort ASAP |
| 6177 | * - ERR_FATAL: we can continue parsing but not start the service |
| 6178 | * - ERR_WARN: a warning has been emitted |
| 6179 | * - ERR_ALERT: an alert has been emitted |
| 6180 | * Only the two first ones can stop processing, the two others are just |
| 6181 | * indicators. |
| 6182 | */ |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6183 | int check_config_validity() |
| 6184 | { |
| 6185 | int cfgerr = 0; |
| 6186 | struct proxy *curproxy = NULL; |
| 6187 | struct server *newsrv = NULL; |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6188 | int err_code = 0; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6189 | unsigned int next_pxid = 1; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6190 | struct bind_conf *bind_conf; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6191 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6192 | bind_conf = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6193 | /* |
| 6194 | * Now, check for the integrity of all that we have collected. |
| 6195 | */ |
| 6196 | |
| 6197 | /* will be needed further to delay some tasks */ |
Willy Tarreau | b0b37bc | 2008-06-23 14:00:57 +0200 | [diff] [blame] | 6198 | tv_update_date(0,1); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6199 | |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 6200 | if (!global.tune.max_http_hdr) |
| 6201 | global.tune.max_http_hdr = MAX_HTTP_HDR; |
| 6202 | |
| 6203 | if (!global.tune.cookie_len) |
| 6204 | global.tune.cookie_len = CAPTURE_LEN; |
| 6205 | |
| 6206 | pool2_capture = create_pool("capture", global.tune.cookie_len, MEM_F_SHARED); |
| 6207 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6208 | /* Post initialisation of the users and groups lists. */ |
| 6209 | err_code = userlist_postinit(); |
| 6210 | if (err_code != ERR_NONE) |
| 6211 | goto out; |
| 6212 | |
Willy Tarreau | 55bc0f8 | 2009-03-15 14:51:53 +0100 | [diff] [blame] | 6213 | /* first, we will invert the proxy list order */ |
| 6214 | curproxy = NULL; |
| 6215 | while (proxy) { |
| 6216 | struct proxy *next; |
| 6217 | |
| 6218 | next = proxy->next; |
| 6219 | proxy->next = curproxy; |
| 6220 | curproxy = proxy; |
| 6221 | if (!next) |
| 6222 | break; |
| 6223 | proxy = next; |
| 6224 | } |
| 6225 | |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 6226 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6227 | struct switching_rule *rule; |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 6228 | struct server_rule *srule; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6229 | struct sticking_rule *mrule; |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 6230 | struct tcp_rule *trule; |
Willy Tarreau | 09448f7 | 2014-06-25 18:12:15 +0200 | [diff] [blame] | 6231 | struct http_req_rule *hrqrule; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6232 | unsigned int next_id; |
Willy Tarreau | 16a2147 | 2012-11-19 12:39:59 +0100 | [diff] [blame] | 6233 | int nbproc; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6234 | |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 6235 | if (curproxy->uuid < 0) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6236 | /* proxy ID not set, use automatic numbering with first |
| 6237 | * spare entry starting with next_pxid. |
| 6238 | */ |
| 6239 | next_pxid = get_next_id(&used_proxy_id, next_pxid); |
| 6240 | curproxy->conf.id.key = curproxy->uuid = next_pxid; |
| 6241 | eb32_insert(&used_proxy_id, &curproxy->conf.id); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6242 | } |
Krzysztof Piotr Oledzki | df5cb9f | 2010-02-05 20:58:27 +0100 | [diff] [blame] | 6243 | next_pxid++; |
| 6244 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6245 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6246 | if (curproxy->state == PR_STSTOPPED) { |
Willy Tarreau | da250db | 2008-10-12 12:07:48 +0200 | [diff] [blame] | 6247 | /* ensure we don't keep listeners uselessly bound */ |
| 6248 | stop_proxy(curproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6249 | continue; |
| 6250 | } |
| 6251 | |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 6252 | /* Check multi-process mode compatibility for the current proxy */ |
| 6253 | |
| 6254 | if (curproxy->bind_proc) { |
| 6255 | /* an explicit bind-process was specified, let's check how many |
| 6256 | * processes remain. |
| 6257 | */ |
| 6258 | nbproc = popcount(curproxy->bind_proc); |
| 6259 | |
| 6260 | curproxy->bind_proc &= nbits(global.nbproc); |
| 6261 | if (!curproxy->bind_proc && nbproc == 1) { |
| 6262 | 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); |
| 6263 | curproxy->bind_proc = 1; |
| 6264 | } |
| 6265 | else if (!curproxy->bind_proc && nbproc > 1) { |
| 6266 | 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); |
| 6267 | curproxy->bind_proc = 0; |
| 6268 | } |
| 6269 | } |
| 6270 | |
Willy Tarreau | 3d20958 | 2014-05-09 17:06:11 +0200 | [diff] [blame] | 6271 | /* check and reduce the bind-proc of each listener */ |
| 6272 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
| 6273 | unsigned long mask; |
| 6274 | |
| 6275 | if (!bind_conf->bind_proc) |
| 6276 | continue; |
| 6277 | |
| 6278 | mask = nbits(global.nbproc); |
| 6279 | if (curproxy->bind_proc) |
| 6280 | mask &= curproxy->bind_proc; |
| 6281 | /* mask cannot be null here thanks to the previous checks */ |
| 6282 | |
| 6283 | nbproc = popcount(bind_conf->bind_proc); |
| 6284 | bind_conf->bind_proc &= mask; |
| 6285 | |
| 6286 | if (!bind_conf->bind_proc && nbproc == 1) { |
| 6287 | 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", |
| 6288 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
| 6289 | bind_conf->bind_proc = mask & ~(mask - 1); |
| 6290 | } |
| 6291 | else if (!bind_conf->bind_proc && nbproc > 1) { |
| 6292 | 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", |
| 6293 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
| 6294 | bind_conf->bind_proc = 0; |
| 6295 | } |
| 6296 | } |
| 6297 | |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 6298 | if (global.nbproc > 1 && curproxy->table.peers.name) { |
| 6299 | Alert("Proxy '%s': peers can't be used in multi-process mode (nbproc > 1).\n", |
| 6300 | curproxy->id); |
| 6301 | cfgerr++; |
| 6302 | } |
Willy Tarreau | 16a2147 | 2012-11-19 12:39:59 +0100 | [diff] [blame] | 6303 | |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 6304 | switch (curproxy->mode) { |
| 6305 | case PR_MODE_HEALTH: |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6306 | cfgerr += proxy_cfg_ensure_no_http(curproxy); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 6307 | if (!(curproxy->cap & PR_CAP_FE)) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6308 | Alert("config : %s '%s' cannot be in health mode as it has no frontend capability.\n", |
| 6309 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 6310 | cfgerr++; |
| 6311 | } |
| 6312 | |
| 6313 | if (curproxy->srv != NULL) |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6314 | Warning("config : servers will be ignored for %s '%s'.\n", |
| 6315 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 6316 | break; |
| 6317 | |
| 6318 | case PR_MODE_TCP: |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6319 | cfgerr += proxy_cfg_ensure_no_http(curproxy); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 6320 | break; |
| 6321 | |
| 6322 | case PR_MODE_HTTP: |
Willy Tarreau | 25320b2 | 2013-03-24 07:22:08 +0100 | [diff] [blame] | 6323 | curproxy->http_needed = 1; |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 6324 | break; |
| 6325 | } |
| 6326 | |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 6327 | if ((curproxy->cap & PR_CAP_BE) && (curproxy->mode != PR_MODE_HEALTH)) { |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6328 | if (curproxy->lbprm.algo & BE_LB_KIND) { |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 6329 | if (curproxy->options & PR_O_TRANSP) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6330 | Alert("config : %s '%s' cannot use both transparent and balance mode.\n", |
| 6331 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 6332 | cfgerr++; |
| 6333 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6334 | #ifdef WE_DONT_SUPPORT_SERVERLESS_LISTENERS |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 6335 | else if (curproxy->srv == NULL) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6336 | Alert("config : %s '%s' needs at least 1 server in balance mode.\n", |
| 6337 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 6338 | cfgerr++; |
| 6339 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6340 | #endif |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 6341 | else if (curproxy->options & PR_O_DISPATCH) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6342 | Warning("config : dispatch address of %s '%s' will be ignored in balance mode.\n", |
| 6343 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6344 | err_code |= ERR_WARN; |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 6345 | } |
| 6346 | } |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 6347 | 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] | 6348 | /* If no LB algo is set in a backend, and we're not in |
| 6349 | * transparent mode, dispatch mode nor proxy mode, we |
| 6350 | * want to use balance roundrobin by default. |
| 6351 | */ |
| 6352 | curproxy->lbprm.algo &= ~BE_LB_ALGO; |
| 6353 | curproxy->lbprm.algo |= BE_LB_ALGO_RR; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6354 | } |
| 6355 | } |
Willy Tarreau | 193cf93 | 2007-09-17 10:17:23 +0200 | [diff] [blame] | 6356 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 6357 | if (curproxy->options & PR_O_DISPATCH) |
| 6358 | curproxy->options &= ~(PR_O_TRANSP | PR_O_HTTP_PROXY); |
| 6359 | else if (curproxy->options & PR_O_HTTP_PROXY) |
| 6360 | curproxy->options &= ~(PR_O_DISPATCH | PR_O_TRANSP); |
| 6361 | else if (curproxy->options & PR_O_TRANSP) |
| 6362 | curproxy->options &= ~(PR_O_DISPATCH | PR_O_HTTP_PROXY); |
Willy Tarreau | 8293658 | 2007-11-30 15:20:09 +0100 | [diff] [blame] | 6363 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 6364 | if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_HTTP_CHK) { |
| 6365 | if (curproxy->options & PR_O_DISABLE404) { |
| 6366 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n", |
| 6367 | "disable-on-404", proxy_type_str(curproxy), curproxy->id); |
| 6368 | err_code |= ERR_WARN; |
| 6369 | curproxy->options &= ~PR_O_DISABLE404; |
| 6370 | } |
| 6371 | if (curproxy->options2 & PR_O2_CHK_SNDST) { |
| 6372 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n", |
| 6373 | "send-state", proxy_type_str(curproxy), curproxy->id); |
| 6374 | err_code |= ERR_WARN; |
| 6375 | curproxy->options &= ~PR_O2_CHK_SNDST; |
| 6376 | } |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 6377 | } |
| 6378 | |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 6379 | if ((curproxy->options2 & PR_O2_CHK_ANY) == PR_O2_EXT_CHK) { |
| 6380 | if (!global.external_check) { |
| 6381 | Alert("Proxy '%s' : '%s' unable to find required 'global.external-check'.\n", |
| 6382 | curproxy->id, "option external-check"); |
| 6383 | cfgerr++; |
| 6384 | } |
| 6385 | if (!curproxy->check_command) { |
| 6386 | Alert("Proxy '%s' : '%s' unable to find required 'external-check command'.\n", |
| 6387 | curproxy->id, "option external-check"); |
| 6388 | cfgerr++; |
| 6389 | } |
| 6390 | } |
| 6391 | |
| 6392 | if (curproxy->check_command) { |
| 6393 | int clear = 0; |
| 6394 | if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_EXT_CHK) { |
| 6395 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option external-check').\n", |
| 6396 | "external-check command", proxy_type_str(curproxy), curproxy->id); |
| 6397 | err_code |= ERR_WARN; |
| 6398 | clear = 1; |
| 6399 | } |
| 6400 | if (curproxy->check_command[0] != '/' && !curproxy->check_path) { |
| 6401 | Alert("Proxy '%s': '%s' does not have a leading '/' and 'external-command path' is not set.\n", |
| 6402 | curproxy->id, "external-check command"); |
| 6403 | cfgerr++; |
| 6404 | } |
| 6405 | if (clear) { |
| 6406 | free(curproxy->check_command); |
| 6407 | curproxy->check_command = NULL; |
| 6408 | } |
| 6409 | } |
| 6410 | |
| 6411 | if (curproxy->check_path) { |
| 6412 | if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_EXT_CHK) { |
| 6413 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option external-check').\n", |
| 6414 | "external-check path", proxy_type_str(curproxy), curproxy->id); |
| 6415 | err_code |= ERR_WARN; |
| 6416 | free(curproxy->check_path); |
| 6417 | curproxy->check_path = NULL; |
| 6418 | } |
| 6419 | } |
| 6420 | |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 6421 | /* if a default backend was specified, let's find it */ |
| 6422 | if (curproxy->defbe.name) { |
| 6423 | struct proxy *target; |
| 6424 | |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 6425 | target = findproxy_mode(curproxy->defbe.name, curproxy->mode, PR_CAP_BE); |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6426 | if (!target) { |
| 6427 | Alert("Proxy '%s': unable to find required default_backend: '%s'.\n", |
| 6428 | curproxy->id, curproxy->defbe.name); |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 6429 | cfgerr++; |
| 6430 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6431 | Alert("Proxy '%s': loop detected for default_backend: '%s'.\n", |
| 6432 | curproxy->id, curproxy->defbe.name); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6433 | cfgerr++; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 6434 | } else { |
| 6435 | free(curproxy->defbe.name); |
| 6436 | curproxy->defbe.be = target; |
Willy Tarreau | ff67813 | 2012-02-13 14:32:34 +0100 | [diff] [blame] | 6437 | |
| 6438 | /* Emit a warning if this proxy also has some servers */ |
| 6439 | if (curproxy->srv) { |
| 6440 | Warning("In proxy '%s', the 'default_backend' rule always has precedence over the servers, which will never be used.\n", |
| 6441 | curproxy->id); |
| 6442 | err_code |= ERR_WARN; |
| 6443 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6444 | } |
| 6445 | } |
| 6446 | |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 6447 | /* find the target proxy in setbe */ |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 6448 | if (curproxy->mode == PR_MODE_HTTP && curproxy->req_exp != NULL) { |
| 6449 | /* map jump target for ACT_SETBE in req_rep chain */ |
| 6450 | struct hdr_exp *exp; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 6451 | for (exp = curproxy->req_exp; exp != NULL; exp = exp->next) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6452 | struct proxy *target; |
| 6453 | |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 6454 | if (exp->action != ACT_SETBE) |
| 6455 | continue; |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6456 | |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 6457 | target = findproxy_mode(exp->replace, PR_MODE_HTTP, PR_CAP_BE); |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6458 | if (!target) { |
| 6459 | Alert("Proxy '%s': unable to find required setbe: '%s'.\n", |
| 6460 | curproxy->id, exp->replace); |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 6461 | cfgerr++; |
| 6462 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6463 | Alert("Proxy '%s': loop detected for setbe: '%s'.\n", |
| 6464 | curproxy->id, exp->replace); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 6465 | cfgerr++; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 6466 | } else { |
| 6467 | free((void *)exp->replace); |
| 6468 | exp->replace = (const char *)target; |
| 6469 | } |
| 6470 | } |
| 6471 | } |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6472 | |
| 6473 | /* find the target proxy for 'use_backend' rules */ |
| 6474 | list_for_each_entry(rule, &curproxy->switching_rules, list) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6475 | struct proxy *target; |
Bertrand Jacquin | 702d44f | 2013-11-19 11:43:06 +0100 | [diff] [blame] | 6476 | struct logformat_node *node; |
| 6477 | char *pxname; |
| 6478 | |
| 6479 | /* Try to parse the string as a log format expression. If the result |
| 6480 | * of the parsing is only one entry containing a simple string, then |
| 6481 | * it's a standard string corresponding to a static rule, thus the |
| 6482 | * parsing is cancelled and be.name is restored to be resolved. |
| 6483 | */ |
| 6484 | pxname = rule->be.name; |
| 6485 | LIST_INIT(&rule->be.expr); |
| 6486 | parse_logformat_string(pxname, curproxy, &rule->be.expr, 0, SMP_VAL_FE_HRQ_HDR, |
| 6487 | curproxy->conf.args.file, curproxy->conf.args.line); |
| 6488 | node = LIST_NEXT(&rule->be.expr, struct logformat_node *, list); |
| 6489 | |
| 6490 | if (!LIST_ISEMPTY(&rule->be.expr)) { |
| 6491 | if (node->type != LOG_FMT_TEXT || node->list.n != &rule->be.expr) { |
| 6492 | rule->dynamic = 1; |
| 6493 | free(pxname); |
| 6494 | continue; |
| 6495 | } |
| 6496 | /* simple string: free the expression and fall back to static rule */ |
| 6497 | free(node->arg); |
| 6498 | free(node); |
| 6499 | } |
| 6500 | |
| 6501 | rule->dynamic = 0; |
| 6502 | rule->be.name = pxname; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6503 | |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 6504 | target = findproxy_mode(rule->be.name, curproxy->mode, PR_CAP_BE); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6505 | |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6506 | if (!target) { |
| 6507 | Alert("Proxy '%s': unable to find required use_backend: '%s'.\n", |
| 6508 | curproxy->id, rule->be.name); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6509 | cfgerr++; |
| 6510 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6511 | Alert("Proxy '%s': loop detected for use_backend: '%s'.\n", |
| 6512 | curproxy->id, rule->be.name); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6513 | cfgerr++; |
| 6514 | } else { |
| 6515 | free((void *)rule->be.name); |
| 6516 | rule->be.backend = target; |
| 6517 | } |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 6518 | } |
| 6519 | |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 6520 | /* find the target server for 'use_server' rules */ |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 6521 | list_for_each_entry(srule, &curproxy->server_rules, list) { |
| 6522 | struct server *target = findserver(curproxy, srule->srv.name); |
| 6523 | |
| 6524 | if (!target) { |
| 6525 | Alert("config : %s '%s' : unable to find server '%s' referenced in a 'use-server' rule.\n", |
| 6526 | proxy_type_str(curproxy), curproxy->id, srule->srv.name); |
| 6527 | cfgerr++; |
| 6528 | continue; |
| 6529 | } |
| 6530 | free((void *)srule->srv.name); |
| 6531 | srule->srv.ptr = target; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6532 | } |
| 6533 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6534 | /* find the target table for 'stick' rules */ |
| 6535 | list_for_each_entry(mrule, &curproxy->sticking_rules, list) { |
| 6536 | struct proxy *target; |
| 6537 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 6538 | curproxy->be_req_ana |= AN_REQ_STICKING_RULES; |
| 6539 | if (mrule->flags & STK_IS_STORE) |
| 6540 | curproxy->be_rsp_ana |= AN_RES_STORE_RULES; |
| 6541 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6542 | if (mrule->table.name) |
Willy Tarreau | c00cdc2 | 2010-06-06 16:48:26 +0200 | [diff] [blame] | 6543 | target = findproxy(mrule->table.name, 0); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6544 | else |
| 6545 | target = curproxy; |
| 6546 | |
| 6547 | if (!target) { |
| 6548 | Alert("Proxy '%s': unable to find stick-table '%s'.\n", |
| 6549 | curproxy->id, mrule->table.name); |
| 6550 | cfgerr++; |
| 6551 | } |
| 6552 | else if (target->table.size == 0) { |
| 6553 | Alert("Proxy '%s': stick-table '%s' used but not configured.\n", |
| 6554 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 6555 | cfgerr++; |
| 6556 | } |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 6557 | else if (!stktable_compatible_sample(mrule->expr, target->table.type)) { |
| 6558 | 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] | 6559 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 6560 | cfgerr++; |
| 6561 | } |
| 6562 | else { |
| 6563 | free((void *)mrule->table.name); |
| 6564 | mrule->table.t = &(target->table); |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 6565 | stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID, NULL); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6566 | } |
| 6567 | } |
| 6568 | |
| 6569 | /* find the target table for 'store response' rules */ |
| 6570 | list_for_each_entry(mrule, &curproxy->storersp_rules, list) { |
| 6571 | struct proxy *target; |
| 6572 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 6573 | curproxy->be_rsp_ana |= AN_RES_STORE_RULES; |
| 6574 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6575 | if (mrule->table.name) |
Willy Tarreau | c00cdc2 | 2010-06-06 16:48:26 +0200 | [diff] [blame] | 6576 | target = findproxy(mrule->table.name, 0); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6577 | else |
| 6578 | target = curproxy; |
| 6579 | |
| 6580 | if (!target) { |
| 6581 | Alert("Proxy '%s': unable to find store table '%s'.\n", |
| 6582 | curproxy->id, mrule->table.name); |
| 6583 | cfgerr++; |
| 6584 | } |
| 6585 | else if (target->table.size == 0) { |
| 6586 | Alert("Proxy '%s': stick-table '%s' used but not configured.\n", |
| 6587 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 6588 | cfgerr++; |
| 6589 | } |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 6590 | else if (!stktable_compatible_sample(mrule->expr, target->table.type)) { |
| 6591 | 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] | 6592 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 6593 | cfgerr++; |
| 6594 | } |
| 6595 | else { |
| 6596 | free((void *)mrule->table.name); |
| 6597 | mrule->table.t = &(target->table); |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 6598 | stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID, NULL); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6599 | } |
| 6600 | } |
| 6601 | |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 6602 | /* find the target table for 'tcp-request' layer 4 rules */ |
| 6603 | list_for_each_entry(trule, &curproxy->tcp_req.l4_rules, list) { |
| 6604 | struct proxy *target; |
| 6605 | |
Willy Tarreau | b4c8493 | 2013-07-23 19:15:30 +0200 | [diff] [blame] | 6606 | 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] | 6607 | continue; |
| 6608 | |
| 6609 | if (trule->act_prm.trk_ctr.table.n) |
| 6610 | target = findproxy(trule->act_prm.trk_ctr.table.n, 0); |
| 6611 | else |
| 6612 | target = curproxy; |
| 6613 | |
| 6614 | if (!target) { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6615 | Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n", |
| 6616 | curproxy->id, trule->act_prm.trk_ctr.table.n, |
Willy Tarreau | 34c2fb6 | 2013-12-02 23:29:05 +0100 | [diff] [blame] | 6617 | tcp_trk_idx(trule->action)); |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 6618 | cfgerr++; |
| 6619 | } |
| 6620 | else if (target->table.size == 0) { |
| 6621 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
| 6622 | curproxy->id, trule->act_prm.trk_ctr.table.n ? trule->act_prm.trk_ctr.table.n : curproxy->id); |
| 6623 | cfgerr++; |
| 6624 | } |
Willy Tarreau | 5f53de7 | 2012-12-12 00:25:44 +0100 | [diff] [blame] | 6625 | else if (!stktable_compatible_sample(trule->act_prm.trk_ctr.expr, target->table.type)) { |
| 6626 | Alert("Proxy '%s': stick-table '%s' uses a type incompatible with the 'track-sc%d' rule.\n", |
| 6627 | 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] | 6628 | tcp_trk_idx(trule->action)); |
Willy Tarreau | 5f53de7 | 2012-12-12 00:25:44 +0100 | [diff] [blame] | 6629 | cfgerr++; |
| 6630 | } |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 6631 | else { |
| 6632 | free(trule->act_prm.trk_ctr.table.n); |
| 6633 | trule->act_prm.trk_ctr.table.t = &target->table; |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6634 | /* 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] | 6635 | * to pass a list of counters to track and allocate them right here using |
| 6636 | * stktable_alloc_data_type(). |
| 6637 | */ |
| 6638 | } |
| 6639 | } |
| 6640 | |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 6641 | /* find the target table for 'tcp-request' layer 6 rules */ |
| 6642 | list_for_each_entry(trule, &curproxy->tcp_req.inspect_rules, list) { |
| 6643 | struct proxy *target; |
| 6644 | |
Willy Tarreau | b4c8493 | 2013-07-23 19:15:30 +0200 | [diff] [blame] | 6645 | 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] | 6646 | continue; |
| 6647 | |
| 6648 | if (trule->act_prm.trk_ctr.table.n) |
| 6649 | target = findproxy(trule->act_prm.trk_ctr.table.n, 0); |
| 6650 | else |
| 6651 | target = curproxy; |
| 6652 | |
| 6653 | if (!target) { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6654 | Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n", |
| 6655 | curproxy->id, trule->act_prm.trk_ctr.table.n, |
Willy Tarreau | 34c2fb6 | 2013-12-02 23:29:05 +0100 | [diff] [blame] | 6656 | tcp_trk_idx(trule->action)); |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 6657 | cfgerr++; |
| 6658 | } |
| 6659 | else if (target->table.size == 0) { |
| 6660 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
| 6661 | curproxy->id, trule->act_prm.trk_ctr.table.n ? trule->act_prm.trk_ctr.table.n : curproxy->id); |
| 6662 | cfgerr++; |
| 6663 | } |
Willy Tarreau | 5f53de7 | 2012-12-12 00:25:44 +0100 | [diff] [blame] | 6664 | else if (!stktable_compatible_sample(trule->act_prm.trk_ctr.expr, target->table.type)) { |
| 6665 | Alert("Proxy '%s': stick-table '%s' uses a type incompatible with the 'track-sc%d' rule.\n", |
| 6666 | 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] | 6667 | tcp_trk_idx(trule->action)); |
Willy Tarreau | 5f53de7 | 2012-12-12 00:25:44 +0100 | [diff] [blame] | 6668 | cfgerr++; |
| 6669 | } |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 6670 | else { |
| 6671 | free(trule->act_prm.trk_ctr.table.n); |
| 6672 | trule->act_prm.trk_ctr.table.t = &target->table; |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6673 | /* 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] | 6674 | * to pass a list of counters to track and allocate them right here using |
| 6675 | * stktable_alloc_data_type(). |
| 6676 | */ |
| 6677 | } |
| 6678 | } |
| 6679 | |
Willy Tarreau | 09448f7 | 2014-06-25 18:12:15 +0200 | [diff] [blame] | 6680 | /* find the target table for 'http-request' layer 7 rules */ |
| 6681 | list_for_each_entry(hrqrule, &curproxy->http_req_rules, list) { |
| 6682 | struct proxy *target; |
| 6683 | |
| 6684 | if (hrqrule->action < HTTP_REQ_ACT_TRK_SC0 || hrqrule->action > HTTP_REQ_ACT_TRK_SCMAX) |
| 6685 | continue; |
| 6686 | |
| 6687 | if (hrqrule->act_prm.trk_ctr.table.n) |
| 6688 | target = findproxy(hrqrule->act_prm.trk_ctr.table.n, 0); |
| 6689 | else |
| 6690 | target = curproxy; |
| 6691 | |
| 6692 | if (!target) { |
| 6693 | Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n", |
| 6694 | curproxy->id, hrqrule->act_prm.trk_ctr.table.n, |
| 6695 | http_req_trk_idx(hrqrule->action)); |
| 6696 | cfgerr++; |
| 6697 | } |
| 6698 | else if (target->table.size == 0) { |
| 6699 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
| 6700 | curproxy->id, hrqrule->act_prm.trk_ctr.table.n ? hrqrule->act_prm.trk_ctr.table.n : curproxy->id); |
| 6701 | cfgerr++; |
| 6702 | } |
| 6703 | else if (!stktable_compatible_sample(hrqrule->act_prm.trk_ctr.expr, target->table.type)) { |
| 6704 | Alert("Proxy '%s': stick-table '%s' uses a type incompatible with the 'track-sc%d' rule.\n", |
| 6705 | curproxy->id, hrqrule->act_prm.trk_ctr.table.n ? hrqrule->act_prm.trk_ctr.table.n : curproxy->id, |
| 6706 | http_req_trk_idx(hrqrule->action)); |
| 6707 | cfgerr++; |
| 6708 | } |
| 6709 | else { |
| 6710 | free(hrqrule->act_prm.trk_ctr.table.n); |
| 6711 | hrqrule->act_prm.trk_ctr.table.t = &target->table; |
| 6712 | /* Note: if we decide to enhance the track-sc syntax, we may be able |
| 6713 | * to pass a list of counters to track and allocate them right here using |
| 6714 | * stktable_alloc_data_type(). |
| 6715 | */ |
| 6716 | } |
| 6717 | } |
| 6718 | |
Willy Tarreau | b3dc39d | 2014-04-28 22:06:57 +0200 | [diff] [blame] | 6719 | /* move any "block" rules at the beginning of the http-request rules */ |
| 6720 | if (!LIST_ISEMPTY(&curproxy->block_rules)) { |
| 6721 | /* insert block_rules into http_req_rules at the beginning */ |
| 6722 | curproxy->block_rules.p->n = curproxy->http_req_rules.n; |
| 6723 | curproxy->http_req_rules.n->p = curproxy->block_rules.p; |
| 6724 | curproxy->block_rules.n->p = &curproxy->http_req_rules; |
| 6725 | curproxy->http_req_rules.n = curproxy->block_rules.n; |
| 6726 | LIST_INIT(&curproxy->block_rules); |
| 6727 | } |
| 6728 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 6729 | if (curproxy->table.peers.name) { |
| 6730 | struct peers *curpeers = peers; |
| 6731 | |
| 6732 | for (curpeers = peers; curpeers; curpeers = curpeers->next) { |
| 6733 | if (strcmp(curpeers->id, curproxy->table.peers.name) == 0) { |
| 6734 | free((void *)curproxy->table.peers.name); |
Willy Tarreau | 973ca49 | 2013-01-17 21:34:52 +0100 | [diff] [blame] | 6735 | curproxy->table.peers.p = curpeers; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 6736 | break; |
| 6737 | } |
| 6738 | } |
| 6739 | |
| 6740 | if (!curpeers) { |
| 6741 | Alert("Proxy '%s': unable to find sync peers '%s'.\n", |
| 6742 | curproxy->id, curproxy->table.peers.name); |
Willy Tarreau | d66bf96 | 2011-10-28 14:16:49 +0200 | [diff] [blame] | 6743 | free((void *)curproxy->table.peers.name); |
| 6744 | curproxy->table.peers.p = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 6745 | cfgerr++; |
| 6746 | } |
| 6747 | else if (!curpeers->peers_fe) { |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 6748 | Alert("Proxy '%s': unable to find local peer '%s' in peers section '%s'.\n", |
| 6749 | curproxy->id, localpeer, curpeers->id); |
Willy Tarreau | d66bf96 | 2011-10-28 14:16:49 +0200 | [diff] [blame] | 6750 | curproxy->table.peers.p = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 6751 | cfgerr++; |
| 6752 | } |
| 6753 | } |
| 6754 | |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 6755 | if (curproxy->uri_auth && !(curproxy->uri_auth->flags & ST_CONVDONE) && |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 6756 | !LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) && |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6757 | (curproxy->uri_auth->userlist || curproxy->uri_auth->auth_realm )) { |
| 6758 | Alert("%s '%s': stats 'auth'/'realm' and 'http-request' can't be used at the same time.\n", |
| 6759 | "proxy", curproxy->id); |
| 6760 | cfgerr++; |
| 6761 | goto out_uri_auth_compat; |
| 6762 | } |
| 6763 | |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 6764 | 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] | 6765 | const char *uri_auth_compat_req[10]; |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 6766 | struct http_req_rule *rule; |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6767 | int i = 0; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6768 | |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6769 | /* build the ACL condition from scratch. We're relying on anonymous ACLs for that */ |
| 6770 | uri_auth_compat_req[i++] = "auth"; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6771 | |
| 6772 | if (curproxy->uri_auth->auth_realm) { |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6773 | uri_auth_compat_req[i++] = "realm"; |
| 6774 | uri_auth_compat_req[i++] = curproxy->uri_auth->auth_realm; |
| 6775 | } |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6776 | |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6777 | uri_auth_compat_req[i++] = "unless"; |
| 6778 | uri_auth_compat_req[i++] = "{"; |
| 6779 | uri_auth_compat_req[i++] = "http_auth(.internal-stats-userlist)"; |
| 6780 | uri_auth_compat_req[i++] = "}"; |
| 6781 | uri_auth_compat_req[i++] = ""; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6782 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 6783 | rule = parse_http_req_cond(uri_auth_compat_req, "internal-stats-auth-compat", 0, curproxy); |
| 6784 | if (!rule) { |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6785 | cfgerr++; |
| 6786 | break; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6787 | } |
| 6788 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 6789 | LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list); |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6790 | |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6791 | if (curproxy->uri_auth->auth_realm) { |
| 6792 | free(curproxy->uri_auth->auth_realm); |
| 6793 | curproxy->uri_auth->auth_realm = NULL; |
| 6794 | } |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 6795 | |
| 6796 | curproxy->uri_auth->flags |= ST_CONVDONE; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6797 | } |
| 6798 | out_uri_auth_compat: |
| 6799 | |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 6800 | /* compile the log format */ |
| 6801 | if (!(curproxy->cap & PR_CAP_FE)) { |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 6802 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 6803 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 6804 | curproxy->conf.logformat_string != clf_http_log_format) |
| 6805 | free(curproxy->conf.logformat_string); |
| 6806 | curproxy->conf.logformat_string = NULL; |
| 6807 | free(curproxy->conf.lfs_file); |
| 6808 | curproxy->conf.lfs_file = NULL; |
| 6809 | curproxy->conf.lfs_line = 0; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 6810 | } |
| 6811 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 6812 | if (curproxy->conf.logformat_string) { |
| 6813 | curproxy->conf.args.ctx = ARGC_LOG; |
| 6814 | curproxy->conf.args.file = curproxy->conf.lfs_file; |
| 6815 | curproxy->conf.args.line = curproxy->conf.lfs_line; |
| 6816 | 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] | 6817 | 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] | 6818 | curproxy->conf.args.file = NULL; |
| 6819 | curproxy->conf.args.line = 0; |
| 6820 | } |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 6821 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 6822 | if (curproxy->conf.uniqueid_format_string) { |
| 6823 | curproxy->conf.args.ctx = ARGC_UIF; |
| 6824 | curproxy->conf.args.file = curproxy->conf.uif_file; |
| 6825 | curproxy->conf.args.line = curproxy->conf.uif_line; |
Thierry FOURNIER | d048d8b | 2014-03-13 16:46:18 +0100 | [diff] [blame] | 6826 | parse_logformat_string(curproxy->conf.uniqueid_format_string, curproxy, &curproxy->format_unique_id, LOG_OPT_HTTP, |
Godbach | d972203 | 2014-12-18 15:44:58 +0800 | [diff] [blame] | 6827 | (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] | 6828 | curproxy->conf.uif_file, curproxy->conf.uif_line); |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 6829 | curproxy->conf.args.file = NULL; |
| 6830 | curproxy->conf.args.line = 0; |
| 6831 | } |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 6832 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6833 | /* only now we can check if some args remain unresolved. |
| 6834 | * This must be done after the users and groups resolution. |
| 6835 | */ |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 6836 | cfgerr += smp_resolve_args(curproxy); |
| 6837 | if (!cfgerr) |
| 6838 | cfgerr += acl_find_targets(curproxy); |
Krzysztof Piotr Oledzki | f9423ae | 2010-01-29 19:26:18 +0100 | [diff] [blame] | 6839 | |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 6840 | if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) && |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6841 | (((curproxy->cap & PR_CAP_FE) && !curproxy->timeout.client) || |
Willy Tarreau | d825eef | 2007-05-12 22:35:00 +0200 | [diff] [blame] | 6842 | ((curproxy->cap & PR_CAP_BE) && (curproxy->srv) && |
Willy Tarreau | ce887fd | 2012-05-12 12:50:00 +0200 | [diff] [blame] | 6843 | (!curproxy->timeout.connect || |
| 6844 | (!curproxy->timeout.server && (curproxy->mode == PR_MODE_HTTP || !curproxy->timeout.tunnel)))))) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6845 | Warning("config : missing timeouts for %s '%s'.\n" |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 6846 | " | While not properly invalid, you will certainly encounter various problems\n" |
| 6847 | " | 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] | 6848 | " | timeouts are set to a non-zero value: 'client', 'connect', 'server'.\n", |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6849 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6850 | err_code |= ERR_WARN; |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 6851 | } |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 6852 | |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6853 | /* Historically, the tarpit and queue timeouts were inherited from contimeout. |
| 6854 | * We must still support older configurations, so let's find out whether those |
| 6855 | * parameters have been set or must be copied from contimeouts. |
| 6856 | */ |
| 6857 | if (curproxy != &defproxy) { |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6858 | if (!curproxy->timeout.tarpit || |
| 6859 | curproxy->timeout.tarpit == defproxy.timeout.tarpit) { |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6860 | /* tarpit timeout not set. We search in the following order: |
| 6861 | * default.tarpit, curr.connect, default.connect. |
| 6862 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6863 | if (defproxy.timeout.tarpit) |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6864 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6865 | else if (curproxy->timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6866 | curproxy->timeout.tarpit = curproxy->timeout.connect; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6867 | else if (defproxy.timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6868 | curproxy->timeout.tarpit = defproxy.timeout.connect; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6869 | } |
| 6870 | if ((curproxy->cap & PR_CAP_BE) && |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6871 | (!curproxy->timeout.queue || |
| 6872 | curproxy->timeout.queue == defproxy.timeout.queue)) { |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6873 | /* queue timeout not set. We search in the following order: |
| 6874 | * default.queue, curr.connect, default.connect. |
| 6875 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6876 | if (defproxy.timeout.queue) |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6877 | curproxy->timeout.queue = defproxy.timeout.queue; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6878 | else if (curproxy->timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6879 | curproxy->timeout.queue = curproxy->timeout.connect; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6880 | else if (defproxy.timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6881 | curproxy->timeout.queue = defproxy.timeout.connect; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6882 | } |
| 6883 | } |
| 6884 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 6885 | if ((curproxy->options2 & PR_O2_CHK_ANY) == PR_O2_SSL3_CHK) { |
Willy Tarreau | 137325d | 2010-02-01 16:38:17 +0100 | [diff] [blame] | 6886 | curproxy->check_len = sizeof(sslv3_client_hello_pkt) - 1; |
| 6887 | curproxy->check_req = (char *)malloc(curproxy->check_len); |
| 6888 | memcpy(curproxy->check_req, sslv3_client_hello_pkt, curproxy->check_len); |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 6889 | } |
| 6890 | |
Willy Tarreau | 215663d | 2014-06-13 18:30:23 +0200 | [diff] [blame] | 6891 | if (!LIST_ISEMPTY(&curproxy->tcpcheck_rules) && |
| 6892 | (curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_TCPCHK_CHK) { |
| 6893 | Warning("config : %s '%s' uses tcp-check rules without 'option tcp-check', so the rules are ignored.\n", |
| 6894 | proxy_type_str(curproxy), curproxy->id); |
| 6895 | err_code |= ERR_WARN; |
| 6896 | } |
| 6897 | |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 6898 | /* ensure that cookie capture length is not too large */ |
| 6899 | if (curproxy->capture_len >= global.tune.cookie_len) { |
| 6900 | Warning("config : truncating capture length to %d bytes for %s '%s'.\n", |
| 6901 | global.tune.cookie_len - 1, proxy_type_str(curproxy), curproxy->id); |
| 6902 | err_code |= ERR_WARN; |
| 6903 | curproxy->capture_len = global.tune.cookie_len - 1; |
| 6904 | } |
| 6905 | |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 6906 | /* The small pools required for the capture lists */ |
Willy Tarreau | 9a54e13 | 2012-03-24 08:33:05 +0100 | [diff] [blame] | 6907 | if (curproxy->nb_req_cap) { |
Willy Tarreau | d9ed3d2 | 2014-06-13 12:23:06 +0200 | [diff] [blame] | 6908 | curproxy->req_cap_pool = create_pool("ptrcap", |
| 6909 | curproxy->nb_req_cap * sizeof(char *), |
| 6910 | MEM_F_SHARED); |
Willy Tarreau | 9a54e13 | 2012-03-24 08:33:05 +0100 | [diff] [blame] | 6911 | } |
| 6912 | |
| 6913 | if (curproxy->nb_rsp_cap) { |
Willy Tarreau | d9ed3d2 | 2014-06-13 12:23:06 +0200 | [diff] [blame] | 6914 | curproxy->rsp_cap_pool = create_pool("ptrcap", |
| 6915 | curproxy->nb_rsp_cap * sizeof(char *), |
| 6916 | MEM_F_SHARED); |
Willy Tarreau | 9a54e13 | 2012-03-24 08:33:05 +0100 | [diff] [blame] | 6917 | } |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 6918 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6919 | /* first, we will invert the servers list order */ |
| 6920 | newsrv = NULL; |
| 6921 | while (curproxy->srv) { |
| 6922 | struct server *next; |
| 6923 | |
| 6924 | next = curproxy->srv->next; |
| 6925 | curproxy->srv->next = newsrv; |
| 6926 | newsrv = curproxy->srv; |
| 6927 | if (!next) |
| 6928 | break; |
| 6929 | curproxy->srv = next; |
| 6930 | } |
| 6931 | |
Willy Tarreau | 17edc81 | 2014-01-03 12:14:34 +0100 | [diff] [blame] | 6932 | /* Check that no server name conflicts. This causes trouble in the stats. |
| 6933 | * We only emit a warning for the first conflict affecting each server, |
| 6934 | * in order to avoid combinatory explosion if all servers have the same |
| 6935 | * name. We do that only for servers which do not have an explicit ID, |
| 6936 | * because these IDs were made also for distinguishing them and we don't |
| 6937 | * want to annoy people who correctly manage them. |
| 6938 | */ |
| 6939 | for (newsrv = curproxy->srv; newsrv; newsrv = newsrv->next) { |
| 6940 | struct server *other_srv; |
| 6941 | |
| 6942 | if (newsrv->puid) |
| 6943 | continue; |
| 6944 | |
| 6945 | for (other_srv = curproxy->srv; other_srv && other_srv != newsrv; other_srv = other_srv->next) { |
| 6946 | if (!other_srv->puid && strcmp(other_srv->id, newsrv->id) == 0) { |
| 6947 | Warning("parsing [%s:%d] : %s '%s', another server named '%s' was defined without an explicit ID at line %d, this is not recommended.\n", |
| 6948 | newsrv->conf.file, newsrv->conf.line, |
| 6949 | proxy_type_str(curproxy), curproxy->id, |
| 6950 | newsrv->id, other_srv->conf.line); |
| 6951 | break; |
| 6952 | } |
| 6953 | } |
| 6954 | } |
| 6955 | |
Willy Tarreau | dd70165 | 2010-05-25 23:03:02 +0200 | [diff] [blame] | 6956 | /* assign automatic UIDs to servers which don't have one yet */ |
| 6957 | next_id = 1; |
| 6958 | newsrv = curproxy->srv; |
| 6959 | while (newsrv != NULL) { |
| 6960 | if (!newsrv->puid) { |
| 6961 | /* server ID not set, use automatic numbering with first |
| 6962 | * spare entry starting with next_svid. |
| 6963 | */ |
| 6964 | next_id = get_next_id(&curproxy->conf.used_server_id, next_id); |
| 6965 | newsrv->conf.id.key = newsrv->puid = next_id; |
| 6966 | eb32_insert(&curproxy->conf.used_server_id, &newsrv->conf.id); |
| 6967 | } |
| 6968 | next_id++; |
| 6969 | newsrv = newsrv->next; |
| 6970 | } |
| 6971 | |
Willy Tarreau | 2069704 | 2007-11-15 23:26:18 +0100 | [diff] [blame] | 6972 | curproxy->lbprm.wmult = 1; /* default weight multiplier */ |
Willy Tarreau | 5dc2fa6 | 2007-11-19 19:10:18 +0100 | [diff] [blame] | 6973 | curproxy->lbprm.wdiv = 1; /* default weight divider */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6974 | |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 6975 | /* |
| 6976 | * If this server supports a maxconn parameter, it needs a dedicated |
| 6977 | * tasks to fill the emptied slots when a connection leaves. |
| 6978 | * Also, resolve deferred tracking dependency if needed. |
| 6979 | */ |
| 6980 | newsrv = curproxy->srv; |
| 6981 | while (newsrv != NULL) { |
| 6982 | if (newsrv->minconn > newsrv->maxconn) { |
| 6983 | /* Only 'minconn' was specified, or it was higher than or equal |
| 6984 | * to 'maxconn'. Let's turn this into maxconn and clean it, as |
| 6985 | * this will avoid further useless expensive computations. |
| 6986 | */ |
| 6987 | newsrv->maxconn = newsrv->minconn; |
| 6988 | } else if (newsrv->maxconn && !newsrv->minconn) { |
| 6989 | /* minconn was not specified, so we set it to maxconn */ |
| 6990 | newsrv->minconn = newsrv->maxconn; |
| 6991 | } |
| 6992 | |
Emeric Brun | 01f8e2f | 2012-05-18 16:02:00 +0200 | [diff] [blame] | 6993 | #ifdef USE_OPENSSL |
Emeric Brun | 94324a4 | 2012-10-11 14:00:19 +0200 | [diff] [blame] | 6994 | if (newsrv->use_ssl || newsrv->check.use_ssl) |
| 6995 | cfgerr += ssl_sock_prepare_srv_ctx(newsrv, curproxy); |
Emeric Brun | 01f8e2f | 2012-05-18 16:02:00 +0200 | [diff] [blame] | 6996 | #endif /* USE_OPENSSL */ |
Emeric Brun | 94324a4 | 2012-10-11 14:00:19 +0200 | [diff] [blame] | 6997 | |
Willy Tarreau | 2f075e9 | 2013-12-03 11:11:34 +0100 | [diff] [blame] | 6998 | /* set the check type on the server */ |
| 6999 | newsrv->check.type = curproxy->options2 & PR_O2_CHK_ANY; |
| 7000 | |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 7001 | if (newsrv->trackit) { |
| 7002 | struct proxy *px; |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 7003 | struct server *srv, *loop; |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 7004 | char *pname, *sname; |
| 7005 | |
| 7006 | pname = newsrv->trackit; |
| 7007 | sname = strrchr(pname, '/'); |
| 7008 | |
| 7009 | if (sname) |
| 7010 | *sname++ = '\0'; |
| 7011 | else { |
| 7012 | sname = pname; |
| 7013 | pname = NULL; |
| 7014 | } |
| 7015 | |
| 7016 | if (pname) { |
| 7017 | px = findproxy(pname, PR_CAP_BE); |
| 7018 | if (!px) { |
| 7019 | Alert("config : %s '%s', server '%s': unable to find required proxy '%s' for tracking.\n", |
| 7020 | proxy_type_str(curproxy), curproxy->id, |
| 7021 | newsrv->id, pname); |
| 7022 | cfgerr++; |
| 7023 | goto next_srv; |
| 7024 | } |
| 7025 | } else |
| 7026 | px = curproxy; |
| 7027 | |
| 7028 | srv = findserver(px, sname); |
| 7029 | if (!srv) { |
| 7030 | Alert("config : %s '%s', server '%s': unable to find required server '%s' for tracking.\n", |
| 7031 | proxy_type_str(curproxy), curproxy->id, |
| 7032 | newsrv->id, sname); |
| 7033 | cfgerr++; |
| 7034 | goto next_srv; |
| 7035 | } |
| 7036 | |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 7037 | if (!(srv->check.state & CHK_ST_CONFIGURED) && |
| 7038 | !(srv->agent.state & CHK_ST_CONFIGURED) && |
| 7039 | !srv->track && !srv->trackit) { |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 7040 | Alert("config : %s '%s', server '%s': unable to use %s/%s for " |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 7041 | "tracking as it does not have any check nor agent enabled.\n", |
| 7042 | proxy_type_str(curproxy), curproxy->id, |
| 7043 | newsrv->id, px->id, srv->id); |
| 7044 | cfgerr++; |
| 7045 | goto next_srv; |
| 7046 | } |
| 7047 | |
| 7048 | for (loop = srv->track; loop && loop != newsrv; loop = loop->track); |
| 7049 | |
| 7050 | if (loop) { |
| 7051 | Alert("config : %s '%s', server '%s': unable to track %s/%s as it " |
| 7052 | "belongs to a tracking chain looping back to %s/%s.\n", |
| 7053 | proxy_type_str(curproxy), curproxy->id, |
| 7054 | newsrv->id, px->id, srv->id, px->id, loop->id); |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 7055 | cfgerr++; |
| 7056 | goto next_srv; |
| 7057 | } |
| 7058 | |
| 7059 | if (curproxy != px && |
| 7060 | (curproxy->options & PR_O_DISABLE404) != (px->options & PR_O_DISABLE404)) { |
| 7061 | Alert("config : %s '%s', server '%s': unable to use %s/%s for" |
| 7062 | "tracking: disable-on-404 option inconsistency.\n", |
| 7063 | proxy_type_str(curproxy), curproxy->id, |
| 7064 | newsrv->id, px->id, srv->id); |
| 7065 | cfgerr++; |
| 7066 | goto next_srv; |
| 7067 | } |
| 7068 | |
| 7069 | /* 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] | 7070 | if (srv->admin & SRV_ADMF_MAINT) { |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 7071 | newsrv->admin |= SRV_ADMF_IMAINT; |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 7072 | newsrv->state = SRV_ST_STOPPED; |
Simon Horman | 125d099 | 2013-02-24 17:23:38 +0900 | [diff] [blame] | 7073 | newsrv->check.health = 0; |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 7074 | } |
| 7075 | |
| 7076 | newsrv->track = srv; |
Willy Tarreau | 1a53a3a | 2013-12-11 15:27:05 +0100 | [diff] [blame] | 7077 | newsrv->tracknext = srv->trackers; |
| 7078 | srv->trackers = newsrv; |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 7079 | |
| 7080 | free(newsrv->trackit); |
| 7081 | newsrv->trackit = NULL; |
| 7082 | } |
| 7083 | next_srv: |
| 7084 | newsrv = newsrv->next; |
| 7085 | } |
| 7086 | |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 7087 | /* We have to initialize the server lookup mechanism depending |
| 7088 | * on what LB algorithm was choosen. |
| 7089 | */ |
| 7090 | |
| 7091 | curproxy->lbprm.algo &= ~(BE_LB_LKUP | BE_LB_PROP_DYN); |
| 7092 | switch (curproxy->lbprm.algo & BE_LB_KIND) { |
| 7093 | case BE_LB_KIND_RR: |
Willy Tarreau | 9757a38 | 2009-10-03 12:56:50 +0200 | [diff] [blame] | 7094 | if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_RR_STATIC) { |
| 7095 | curproxy->lbprm.algo |= BE_LB_LKUP_MAP; |
| 7096 | init_server_map(curproxy); |
| 7097 | } else { |
| 7098 | curproxy->lbprm.algo |= BE_LB_LKUP_RRTREE | BE_LB_PROP_DYN; |
| 7099 | fwrr_init_server_groups(curproxy); |
| 7100 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 7101 | break; |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 7102 | |
Willy Tarreau | 3ebb116 | 2012-02-13 16:57:44 +0100 | [diff] [blame] | 7103 | case BE_LB_KIND_CB: |
Willy Tarreau | f09c660 | 2012-02-13 17:12:08 +0100 | [diff] [blame] | 7104 | if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_CB_LC) { |
| 7105 | curproxy->lbprm.algo |= BE_LB_LKUP_LCTREE | BE_LB_PROP_DYN; |
| 7106 | fwlc_init_server_tree(curproxy); |
| 7107 | } else { |
| 7108 | curproxy->lbprm.algo |= BE_LB_LKUP_FSTREE | BE_LB_PROP_DYN; |
| 7109 | fas_init_server_tree(curproxy); |
| 7110 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 7111 | break; |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 7112 | |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 7113 | case BE_LB_KIND_HI: |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 7114 | if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS) { |
| 7115 | curproxy->lbprm.algo |= BE_LB_LKUP_CHTREE | BE_LB_PROP_DYN; |
| 7116 | chash_init_server_tree(curproxy); |
| 7117 | } else { |
| 7118 | curproxy->lbprm.algo |= BE_LB_LKUP_MAP; |
| 7119 | init_server_map(curproxy); |
| 7120 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 7121 | break; |
| 7122 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7123 | |
| 7124 | if (curproxy->options & PR_O_LOGASAP) |
| 7125 | curproxy->to_log &= ~LW_BYTES; |
| 7126 | |
Willy Tarreau | e7ded1f | 2009-08-09 10:11:45 +0200 | [diff] [blame] | 7127 | if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) && |
Willy Tarreau | d79a3b2 | 2012-12-28 09:40:16 +0100 | [diff] [blame] | 7128 | (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] | 7129 | Warning("config : log format ignored for %s '%s' since it has no log address.\n", |
| 7130 | proxy_type_str(curproxy), curproxy->id); |
| 7131 | err_code |= ERR_WARN; |
| 7132 | } |
| 7133 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 7134 | if (curproxy->mode != PR_MODE_HTTP) { |
| 7135 | int optnum; |
| 7136 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 7137 | if (curproxy->uri_auth) { |
| 7138 | Warning("config : 'stats' statement ignored for %s '%s' as it requires HTTP mode.\n", |
| 7139 | proxy_type_str(curproxy), curproxy->id); |
| 7140 | err_code |= ERR_WARN; |
| 7141 | curproxy->uri_auth = NULL; |
| 7142 | } |
| 7143 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 7144 | if (curproxy->options & (PR_O_FWDFOR | PR_O_FF_ALWAYS)) { |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 7145 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 7146 | "forwardfor", proxy_type_str(curproxy), curproxy->id); |
| 7147 | err_code |= ERR_WARN; |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 7148 | curproxy->options &= ~(PR_O_FWDFOR | PR_O_FF_ALWAYS); |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 7149 | } |
| 7150 | |
| 7151 | if (curproxy->options & PR_O_ORGTO) { |
| 7152 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 7153 | "originalto", proxy_type_str(curproxy), curproxy->id); |
| 7154 | err_code |= ERR_WARN; |
| 7155 | curproxy->options &= ~PR_O_ORGTO; |
| 7156 | } |
| 7157 | |
| 7158 | for (optnum = 0; cfg_opts[optnum].name; optnum++) { |
| 7159 | if (cfg_opts[optnum].mode == PR_MODE_HTTP && |
| 7160 | (curproxy->cap & cfg_opts[optnum].cap) && |
| 7161 | (curproxy->options & cfg_opts[optnum].val)) { |
| 7162 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 7163 | cfg_opts[optnum].name, proxy_type_str(curproxy), curproxy->id); |
| 7164 | err_code |= ERR_WARN; |
| 7165 | curproxy->options &= ~cfg_opts[optnum].val; |
| 7166 | } |
| 7167 | } |
| 7168 | |
| 7169 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) { |
| 7170 | if (cfg_opts2[optnum].mode == PR_MODE_HTTP && |
| 7171 | (curproxy->cap & cfg_opts2[optnum].cap) && |
| 7172 | (curproxy->options2 & cfg_opts2[optnum].val)) { |
| 7173 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 7174 | cfg_opts2[optnum].name, proxy_type_str(curproxy), curproxy->id); |
| 7175 | err_code |= ERR_WARN; |
| 7176 | curproxy->options2 &= ~cfg_opts2[optnum].val; |
| 7177 | } |
| 7178 | } |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 7179 | |
Pieter Baauw | d551fb5 | 2013-05-08 22:49:23 +0200 | [diff] [blame] | 7180 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_TRANSPARENT) |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 7181 | if (curproxy->conn_src.bind_hdr_occ) { |
| 7182 | curproxy->conn_src.bind_hdr_occ = 0; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 7183 | 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] | 7184 | proxy_type_str(curproxy), curproxy->id, curproxy->conn_src.bind_hdr_name); |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 7185 | err_code |= ERR_WARN; |
| 7186 | } |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 7187 | #endif |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 7188 | } |
| 7189 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7190 | /* |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 7191 | * ensure that we're not cross-dressing a TCP server into HTTP. |
| 7192 | */ |
| 7193 | newsrv = curproxy->srv; |
| 7194 | while (newsrv != NULL) { |
Willy Tarreau | 0cec331 | 2011-10-31 13:49:26 +0100 | [diff] [blame] | 7195 | if ((curproxy->mode != PR_MODE_HTTP) && newsrv->rdr_len) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7196 | Alert("config : %s '%s' : server cannot have cookie or redirect prefix in non-HTTP mode.\n", |
| 7197 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 7198 | cfgerr++; |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 7199 | } |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 7200 | |
Willy Tarreau | 0cec331 | 2011-10-31 13:49:26 +0100 | [diff] [blame] | 7201 | if ((curproxy->mode != PR_MODE_HTTP) && newsrv->cklen) { |
| 7202 | Warning("config : %s '%s' : ignoring cookie for server '%s' as HTTP mode is disabled.\n", |
| 7203 | proxy_type_str(curproxy), curproxy->id, newsrv->id); |
| 7204 | err_code |= ERR_WARN; |
| 7205 | } |
| 7206 | |
Willy Tarreau | c93cd16 | 2014-05-13 15:54:22 +0200 | [diff] [blame] | 7207 | if ((newsrv->flags & SRV_F_MAPPORTS) && (curproxy->options2 & PR_O2_RDPC_PRST)) { |
Willy Tarreau | 82ffa39 | 2013-08-13 17:19:08 +0200 | [diff] [blame] | 7208 | Warning("config : %s '%s' : RDP cookie persistence will not work for server '%s' because it lacks an explicit port number.\n", |
| 7209 | proxy_type_str(curproxy), curproxy->id, newsrv->id); |
| 7210 | err_code |= ERR_WARN; |
| 7211 | } |
| 7212 | |
Pieter Baauw | d551fb5 | 2013-05-08 22:49:23 +0200 | [diff] [blame] | 7213 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_TRANSPARENT) |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 7214 | if (curproxy->mode != PR_MODE_HTTP && newsrv->conn_src.bind_hdr_occ) { |
| 7215 | newsrv->conn_src.bind_hdr_occ = 0; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 7216 | 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] | 7217 | 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] | 7218 | err_code |= ERR_WARN; |
| 7219 | } |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 7220 | #endif |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 7221 | newsrv = newsrv->next; |
| 7222 | } |
| 7223 | |
Willy Tarreau | e42bd96 | 2014-09-16 16:21:19 +0200 | [diff] [blame] | 7224 | /* check if we have a frontend with "tcp-request content" looking at L7 |
| 7225 | * with no inspect-delay |
| 7226 | */ |
| 7227 | if ((curproxy->cap & PR_CAP_FE) && !curproxy->tcp_req.inspect_delay) { |
| 7228 | list_for_each_entry(trule, &curproxy->tcp_req.inspect_rules, list) { |
| 7229 | if (trule->action == TCP_ACT_CAPTURE && |
| 7230 | !(trule->act_prm.cap.expr->fetch->val & SMP_VAL_FE_SES_ACC)) |
| 7231 | break; |
| 7232 | if ((trule->action >= TCP_ACT_TRK_SC0 && trule->action <= TCP_ACT_TRK_SCMAX) && |
| 7233 | !(trule->act_prm.trk_ctr.expr->fetch->val & SMP_VAL_FE_SES_ACC)) |
| 7234 | break; |
| 7235 | } |
| 7236 | |
| 7237 | if (&trule->list != &curproxy->tcp_req.inspect_rules) { |
| 7238 | Warning("config : %s '%s' : some 'tcp-request content' rules explicitly depending on request" |
| 7239 | " contents were found in a frontend without any 'tcp-request inspect-delay' setting." |
| 7240 | " This means that these rules will randomly find their contents. This can be fixed by" |
| 7241 | " setting the tcp-request inspect-delay.\n", |
| 7242 | proxy_type_str(curproxy), curproxy->id); |
| 7243 | err_code |= ERR_WARN; |
| 7244 | } |
| 7245 | } |
| 7246 | |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 7247 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 7248 | if (!curproxy->accept) |
| 7249 | curproxy->accept = frontend_accept; |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 7250 | |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 7251 | if (curproxy->tcp_req.inspect_delay || |
| 7252 | !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules)) |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 7253 | curproxy->fe_req_ana |= AN_REQ_INSPECT_FE; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 7254 | |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 7255 | if (curproxy->mode == PR_MODE_HTTP) { |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 7256 | 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] | 7257 | 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] | 7258 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 7259 | |
| 7260 | /* both TCP and HTTP must check switching rules */ |
| 7261 | curproxy->fe_req_ana |= AN_REQ_SWITCHING_RULES; |
| 7262 | } |
| 7263 | |
| 7264 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 7265 | if (curproxy->tcp_req.inspect_delay || |
| 7266 | !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules)) |
| 7267 | curproxy->be_req_ana |= AN_REQ_INSPECT_BE; |
| 7268 | |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 7269 | if (!LIST_ISEMPTY(&curproxy->tcp_rep.inspect_rules)) |
| 7270 | curproxy->be_rsp_ana |= AN_RES_INSPECT; |
| 7271 | |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 7272 | if (curproxy->mode == PR_MODE_HTTP) { |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 7273 | 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] | 7274 | 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] | 7275 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 7276 | |
| 7277 | /* If the backend does requires RDP cookie persistence, we have to |
| 7278 | * enable the corresponding analyser. |
| 7279 | */ |
| 7280 | if (curproxy->options2 & PR_O2_RDPC_PRST) |
| 7281 | curproxy->be_req_ana |= AN_REQ_PRST_RDP_COOKIE; |
| 7282 | } |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 7283 | } |
| 7284 | |
| 7285 | /***********************************************************/ |
| 7286 | /* At this point, target names have already been resolved. */ |
| 7287 | /***********************************************************/ |
| 7288 | |
| 7289 | /* Check multi-process mode compatibility */ |
| 7290 | |
| 7291 | if (global.nbproc > 1 && global.stats_fe) { |
| 7292 | list_for_each_entry(bind_conf, &global.stats_fe->conf.bind, by_fe) { |
| 7293 | unsigned long mask; |
| 7294 | |
| 7295 | mask = nbits(global.nbproc); |
| 7296 | if (global.stats_fe->bind_proc) |
| 7297 | mask &= global.stats_fe->bind_proc; |
| 7298 | |
| 7299 | if (bind_conf->bind_proc) |
| 7300 | mask &= bind_conf->bind_proc; |
| 7301 | |
| 7302 | /* stop here if more than one process is used */ |
| 7303 | if (popcount(mask) > 1) |
| 7304 | break; |
| 7305 | } |
| 7306 | if (&bind_conf->by_fe != &global.stats_fe->conf.bind) { |
| 7307 | Warning("stats socket will not work as expected in multi-process mode (nbproc > 1), you should force process binding globally using 'stats bind-process' or per socket using the 'process' attribute.\n"); |
| 7308 | } |
| 7309 | } |
| 7310 | |
| 7311 | /* Make each frontend inherit bind-process from its listeners when not specified. */ |
| 7312 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 7313 | if (curproxy->bind_proc) |
| 7314 | continue; |
| 7315 | |
| 7316 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
| 7317 | unsigned long mask; |
| 7318 | |
| 7319 | mask = bind_conf->bind_proc ? bind_conf->bind_proc : ~0UL; |
| 7320 | curproxy->bind_proc |= mask; |
| 7321 | } |
| 7322 | |
| 7323 | if (!curproxy->bind_proc) |
| 7324 | curproxy->bind_proc = ~0UL; |
| 7325 | } |
| 7326 | |
| 7327 | if (global.stats_fe) { |
| 7328 | list_for_each_entry(bind_conf, &global.stats_fe->conf.bind, by_fe) { |
| 7329 | unsigned long mask; |
| 7330 | |
| 7331 | mask = bind_conf->bind_proc ? bind_conf->bind_proc : ~0UL; |
| 7332 | global.stats_fe->bind_proc |= mask; |
| 7333 | } |
| 7334 | if (!global.stats_fe->bind_proc) |
| 7335 | global.stats_fe->bind_proc = ~0UL; |
| 7336 | } |
| 7337 | |
Willy Tarreau | acbe8ab | 2014-10-01 20:50:17 +0200 | [diff] [blame] | 7338 | /* propagate bindings from frontends to backends. Don't do it if there |
| 7339 | * are any fatal errors as we must not call it with unresolved proxies. |
| 7340 | */ |
| 7341 | if (!cfgerr) { |
| 7342 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 7343 | if (curproxy->cap & PR_CAP_FE) |
| 7344 | propagate_processes(curproxy, NULL); |
| 7345 | } |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 7346 | } |
| 7347 | |
| 7348 | /* Bind each unbound backend to all processes when not specified. */ |
| 7349 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 7350 | if (curproxy->bind_proc) |
| 7351 | continue; |
| 7352 | curproxy->bind_proc = ~0UL; |
| 7353 | } |
| 7354 | |
| 7355 | /*******************************************************/ |
| 7356 | /* At this step, all proxies have a non-null bind_proc */ |
| 7357 | /*******************************************************/ |
| 7358 | |
| 7359 | /* perform the final checks before creating tasks */ |
| 7360 | |
| 7361 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 7362 | struct listener *listener; |
| 7363 | unsigned int next_id; |
| 7364 | int nbproc; |
| 7365 | |
| 7366 | nbproc = popcount(curproxy->bind_proc & nbits(global.nbproc)); |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 7367 | |
Emeric Brun | c52962f | 2012-11-15 18:28:02 +0100 | [diff] [blame] | 7368 | #ifdef USE_OPENSSL |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 7369 | /* Configure SSL for each bind line. |
| 7370 | * Note: if configuration fails at some point, the ->ctx member |
| 7371 | * remains NULL so that listeners can later detach. |
| 7372 | */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7373 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
Emeric Brun | caa19cc | 2014-05-07 16:10:18 +0200 | [diff] [blame] | 7374 | int alloc_ctx; |
| 7375 | |
Emeric Brun | c52962f | 2012-11-15 18:28:02 +0100 | [diff] [blame] | 7376 | if (!bind_conf->is_ssl) { |
| 7377 | if (bind_conf->default_ctx) { |
| 7378 | Warning("Proxy '%s': A certificate was specified but SSL was not enabled on bind '%s' at [%s:%d] (use 'ssl').\n", |
| 7379 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
| 7380 | } |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7381 | continue; |
Emeric Brun | c52962f | 2012-11-15 18:28:02 +0100 | [diff] [blame] | 7382 | } |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7383 | if (!bind_conf->default_ctx) { |
Emeric Brun | fc0421f | 2012-09-07 17:30:07 +0200 | [diff] [blame] | 7384 | 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] | 7385 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 7386 | cfgerr++; |
| 7387 | continue; |
| 7388 | } |
| 7389 | |
Emeric Brun | 8dc6039 | 2014-05-09 13:52:00 +0200 | [diff] [blame] | 7390 | 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] | 7391 | if (alloc_ctx < 0) { |
Emeric Brun | 93ee249 | 2014-05-09 14:01:48 +0200 | [diff] [blame] | 7392 | if (alloc_ctx == SHCTX_E_INIT_LOCK) |
| 7393 | 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"); |
| 7394 | else |
Emeric Brun | caa19cc | 2014-05-07 16:10:18 +0200 | [diff] [blame] | 7395 | Alert("Unable to allocate SSL session cache.\n"); |
Emeric Brun | 93ee249 | 2014-05-09 14:01:48 +0200 | [diff] [blame] | 7396 | cfgerr++; |
| 7397 | continue; |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 7398 | } |
| 7399 | |
Emeric Brun | fc0421f | 2012-09-07 17:30:07 +0200 | [diff] [blame] | 7400 | /* initialize all certificate contexts */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7401 | cfgerr += ssl_sock_prepare_all_ctx(bind_conf, curproxy); |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7402 | } |
Emeric Brun | c52962f | 2012-11-15 18:28:02 +0100 | [diff] [blame] | 7403 | #endif /* USE_OPENSSL */ |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 7404 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 7405 | /* adjust this proxy's listeners */ |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7406 | next_id = 1; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 7407 | list_for_each_entry(listener, &curproxy->conf.listeners, by_fe) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7408 | if (!listener->luid) { |
| 7409 | /* listener ID not set, use automatic numbering with first |
| 7410 | * spare entry starting with next_luid. |
| 7411 | */ |
| 7412 | next_id = get_next_id(&curproxy->conf.used_listener_id, next_id); |
| 7413 | listener->conf.id.key = listener->luid = next_id; |
| 7414 | eb32_insert(&curproxy->conf.used_listener_id, &listener->conf.id); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7415 | } |
Krzysztof Piotr Oledzki | df5cb9f | 2010-02-05 20:58:27 +0100 | [diff] [blame] | 7416 | next_id++; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7417 | |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 7418 | /* enable separate counters */ |
| 7419 | if (curproxy->options2 & PR_O2_SOCKSTAT) { |
| 7420 | listener->counters = (struct licounters *)calloc(1, sizeof(struct licounters)); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 7421 | if (!listener->name) |
| 7422 | memprintf(&listener->name, "sock-%d", listener->luid); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 7423 | } |
Willy Tarreau | 81796be | 2012-09-22 19:11:47 +0200 | [diff] [blame] | 7424 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 7425 | if (curproxy->options & PR_O_TCP_NOLING) |
| 7426 | listener->options |= LI_O_NOLINGER; |
Willy Tarreau | 32368ce | 2012-09-06 11:10:55 +0200 | [diff] [blame] | 7427 | if (!listener->maxconn) |
| 7428 | listener->maxconn = curproxy->maxconn; |
| 7429 | if (!listener->backlog) |
| 7430 | listener->backlog = curproxy->backlog; |
Willy Tarreau | 16a2147 | 2012-11-19 12:39:59 +0100 | [diff] [blame] | 7431 | if (!listener->maxaccept) |
| 7432 | listener->maxaccept = global.tune.maxaccept ? global.tune.maxaccept : 64; |
| 7433 | |
| 7434 | /* we want to have an optimal behaviour on single process mode to |
| 7435 | * maximize the work at once, but in multi-process we want to keep |
| 7436 | * some fairness between processes, so we target half of the max |
| 7437 | * number of events to be balanced over all the processes the proxy |
| 7438 | * is bound to. Rememeber that maxaccept = -1 must be kept as it is |
| 7439 | * used to disable the limit. |
| 7440 | */ |
| 7441 | if (listener->maxaccept > 0) { |
| 7442 | if (nbproc > 1) |
| 7443 | listener->maxaccept = (listener->maxaccept + 1) / 2; |
| 7444 | listener->maxaccept = (listener->maxaccept + nbproc - 1) / nbproc; |
| 7445 | } |
| 7446 | |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 7447 | listener->timeout = &curproxy->timeout.client; |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 7448 | listener->accept = session_accept; |
Willy Tarreau | 3bc1377 | 2008-12-07 11:50:35 +0100 | [diff] [blame] | 7449 | listener->handler = process_session; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 7450 | listener->analysers |= curproxy->fe_req_ana; |
Willy Tarreau | 3bc1377 | 2008-12-07 11:50:35 +0100 | [diff] [blame] | 7451 | |
Willy Tarreau | a5c0ab2 | 2010-05-31 10:30:33 +0200 | [diff] [blame] | 7452 | if (!LIST_ISEMPTY(&curproxy->tcp_req.l4_rules)) |
| 7453 | listener->options |= LI_O_TCP_RULES; |
| 7454 | |
Willy Tarreau | de3041d | 2010-05-31 10:56:17 +0200 | [diff] [blame] | 7455 | if (curproxy->mon_mask.s_addr) |
| 7456 | listener->options |= LI_O_CHK_MONNET; |
| 7457 | |
Willy Tarreau | 9ea05a7 | 2009-06-14 12:07:01 +0200 | [diff] [blame] | 7458 | /* smart accept mode is automatic in HTTP mode */ |
| 7459 | if ((curproxy->options2 & PR_O2_SMARTACC) || |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7460 | ((curproxy->mode == PR_MODE_HTTP || listener->bind_conf->is_ssl) && |
Willy Tarreau | 9ea05a7 | 2009-06-14 12:07:01 +0200 | [diff] [blame] | 7461 | !(curproxy->no_options2 & PR_O2_SMARTACC))) |
| 7462 | listener->options |= LI_O_NOQUICKACK; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 7463 | } |
| 7464 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7465 | /* Release unused SSL configs */ |
| 7466 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
| 7467 | if (bind_conf->is_ssl) |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 7468 | continue; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7469 | #ifdef USE_OPENSSL |
| 7470 | ssl_sock_free_all_ctx(bind_conf); |
Emeric Brun | fb510ea | 2012-10-05 12:00:26 +0200 | [diff] [blame] | 7471 | free(bind_conf->ca_file); |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7472 | free(bind_conf->ciphers); |
Emeric Brun | 2b58d04 | 2012-09-20 17:10:03 +0200 | [diff] [blame] | 7473 | free(bind_conf->ecdhe); |
Emeric Brun | fb510ea | 2012-10-05 12:00:26 +0200 | [diff] [blame] | 7474 | free(bind_conf->crl_file); |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 7475 | #endif /* USE_OPENSSL */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7476 | } |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 7477 | |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 7478 | if (nbproc > 1) { |
| 7479 | if (curproxy->uri_auth) { |
Willy Tarreau | eb791e0 | 2014-09-16 15:11:04 +0200 | [diff] [blame] | 7480 | int count, maxproc = 0; |
| 7481 | |
| 7482 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
| 7483 | count = popcount(bind_conf->bind_proc); |
| 7484 | if (count > maxproc) |
| 7485 | maxproc = count; |
| 7486 | } |
| 7487 | /* backends have 0, frontends have 1 or more */ |
| 7488 | if (maxproc != 1) |
| 7489 | Warning("Proxy '%s': in multi-process mode, stats will be" |
| 7490 | " limited to process assigned to the current request.\n", |
| 7491 | curproxy->id); |
| 7492 | |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 7493 | if (!LIST_ISEMPTY(&curproxy->uri_auth->admin_rules)) { |
| 7494 | Warning("Proxy '%s': stats admin will not work correctly in multi-process mode.\n", |
| 7495 | curproxy->id); |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 7496 | } |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 7497 | } |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 7498 | if (curproxy->appsession_name) { |
| 7499 | Warning("Proxy '%s': appsession will not work correctly in multi-process mode.\n", |
| 7500 | curproxy->id); |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 7501 | } |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 7502 | if (!LIST_ISEMPTY(&curproxy->sticking_rules)) { |
| 7503 | Warning("Proxy '%s': sticking rules will not work correctly in multi-process mode.\n", |
| 7504 | curproxy->id); |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 7505 | } |
| 7506 | } |
Willy Tarreau | 918ff60 | 2011-07-25 16:33:49 +0200 | [diff] [blame] | 7507 | |
| 7508 | /* create the task associated with the proxy */ |
| 7509 | curproxy->task = task_new(); |
| 7510 | if (curproxy->task) { |
| 7511 | curproxy->task->context = curproxy; |
| 7512 | curproxy->task->process = manage_proxy; |
| 7513 | /* no need to queue, it will be done automatically if some |
| 7514 | * listener gets limited. |
| 7515 | */ |
| 7516 | curproxy->task->expire = TICK_ETERNITY; |
| 7517 | } else { |
| 7518 | Alert("Proxy '%s': no more memory when trying to allocate the management task\n", |
| 7519 | curproxy->id); |
| 7520 | cfgerr++; |
| 7521 | } |
Willy Tarreau | b369a04 | 2014-09-16 13:21:03 +0200 | [diff] [blame] | 7522 | } |
| 7523 | |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 7524 | /* automatically compute fullconn if not set. We must not do it in the |
| 7525 | * loop above because cross-references are not yet fully resolved. |
| 7526 | */ |
| 7527 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 7528 | /* If <fullconn> is not set, let's set it to 10% of the sum of |
| 7529 | * the possible incoming frontend's maxconns. |
| 7530 | */ |
| 7531 | if (!curproxy->fullconn && (curproxy->cap & PR_CAP_BE)) { |
| 7532 | struct proxy *fe; |
| 7533 | int total = 0; |
| 7534 | |
| 7535 | /* sum up the number of maxconns of frontends which |
| 7536 | * reference this backend at least once or which are |
| 7537 | * the same one ('listen'). |
| 7538 | */ |
| 7539 | for (fe = proxy; fe; fe = fe->next) { |
| 7540 | struct switching_rule *rule; |
| 7541 | struct hdr_exp *exp; |
| 7542 | int found = 0; |
| 7543 | |
| 7544 | if (!(fe->cap & PR_CAP_FE)) |
| 7545 | continue; |
| 7546 | |
| 7547 | if (fe == curproxy) /* we're on a "listen" instance */ |
| 7548 | found = 1; |
| 7549 | |
| 7550 | if (fe->defbe.be == curproxy) /* "default_backend" */ |
| 7551 | found = 1; |
| 7552 | |
| 7553 | /* check if a "use_backend" rule matches */ |
| 7554 | if (!found) { |
| 7555 | list_for_each_entry(rule, &fe->switching_rules, list) { |
Bertrand Jacquin | 702d44f | 2013-11-19 11:43:06 +0100 | [diff] [blame] | 7556 | if (!rule->dynamic && rule->be.backend == curproxy) { |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 7557 | found = 1; |
| 7558 | break; |
| 7559 | } |
| 7560 | } |
| 7561 | } |
| 7562 | |
| 7563 | /* check if a "reqsetbe" rule matches */ |
| 7564 | for (exp = fe->req_exp; !found && exp; exp = exp->next) { |
| 7565 | if (exp->action == ACT_SETBE && |
| 7566 | (struct proxy *)exp->replace == curproxy) { |
| 7567 | found = 1; |
| 7568 | break; |
| 7569 | } |
| 7570 | } |
| 7571 | |
| 7572 | /* now we've checked all possible ways to reference a backend |
| 7573 | * from a frontend. |
| 7574 | */ |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 7575 | if (!found) |
| 7576 | continue; |
| 7577 | total += fe->maxconn; |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 7578 | } |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 7579 | /* we have the sum of the maxconns in <total>. We only |
| 7580 | * keep 10% of that sum to set the default fullconn, with |
| 7581 | * a hard minimum of 1 (to avoid a divide by zero). |
| 7582 | */ |
| 7583 | curproxy->fullconn = (total + 9) / 10; |
| 7584 | if (!curproxy->fullconn) |
| 7585 | curproxy->fullconn = 1; |
| 7586 | } |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 7587 | } |
| 7588 | |
Willy Tarreau | 056f568 | 2010-06-06 15:51:11 +0200 | [diff] [blame] | 7589 | /* initialize stick-tables on backend capable proxies. This must not |
| 7590 | * be done earlier because the data size may be discovered while parsing |
| 7591 | * other proxies. |
| 7592 | */ |
Godbach | 9703e66 | 2013-12-11 21:11:41 +0800 | [diff] [blame] | 7593 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
Willy Tarreau | 5830213 | 2014-02-24 20:59:47 +0100 | [diff] [blame] | 7594 | if (curproxy->state == PR_STSTOPPED) |
| 7595 | continue; |
| 7596 | |
Godbach | 9703e66 | 2013-12-11 21:11:41 +0800 | [diff] [blame] | 7597 | if (!stktable_init(&curproxy->table)) { |
| 7598 | Alert("Proxy '%s': failed to initialize stick-table.\n", curproxy->id); |
| 7599 | cfgerr++; |
| 7600 | } |
| 7601 | } |
Willy Tarreau | 056f568 | 2010-06-06 15:51:11 +0200 | [diff] [blame] | 7602 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7603 | /* |
| 7604 | * Recount currently required checks. |
| 7605 | */ |
| 7606 | |
| 7607 | for (curproxy=proxy; curproxy; curproxy=curproxy->next) { |
| 7608 | int optnum; |
| 7609 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 7610 | for (optnum = 0; cfg_opts[optnum].name; optnum++) |
| 7611 | if (curproxy->options & cfg_opts[optnum].val) |
| 7612 | global.last_checks |= cfg_opts[optnum].checks; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7613 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 7614 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) |
| 7615 | if (curproxy->options2 & cfg_opts2[optnum].val) |
| 7616 | global.last_checks |= cfg_opts2[optnum].checks; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7617 | } |
| 7618 | |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 7619 | if (peers) { |
| 7620 | struct peers *curpeers = peers, **last; |
| 7621 | struct peer *p, *pb; |
| 7622 | |
| 7623 | /* Remove all peers sections which don't have a valid listener. |
| 7624 | * This can happen when a peers section is never referenced and |
| 7625 | * does not contain a local peer. |
| 7626 | */ |
| 7627 | last = &peers; |
| 7628 | while (*last) { |
| 7629 | curpeers = *last; |
| 7630 | if (curpeers->peers_fe) { |
| 7631 | last = &curpeers->next; |
| 7632 | continue; |
| 7633 | } |
| 7634 | |
| 7635 | Warning("Removing incomplete section 'peers %s' (no peer named '%s').\n", |
| 7636 | curpeers->id, localpeer); |
| 7637 | |
| 7638 | p = curpeers->remote; |
| 7639 | while (p) { |
| 7640 | pb = p->next; |
| 7641 | free(p->id); |
| 7642 | free(p); |
| 7643 | p = pb; |
| 7644 | } |
| 7645 | |
| 7646 | /* Destroy and unlink this curpeers section. |
| 7647 | * Note: curpeers is backed up into *last. |
| 7648 | */ |
| 7649 | free(curpeers->id); |
| 7650 | curpeers = curpeers->next; |
| 7651 | free(*last); |
| 7652 | *last = curpeers; |
| 7653 | } |
| 7654 | } |
| 7655 | |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 7656 | pool2_hdr_idx = create_pool("hdr_idx", |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame] | 7657 | global.tune.max_http_hdr * sizeof(struct hdr_idx_elem), |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 7658 | MEM_F_SHARED); |
| 7659 | |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 7660 | if (cfgerr > 0) |
| 7661 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7662 | out: |
| 7663 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7664 | } |
| 7665 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 7666 | /* |
| 7667 | * Registers the CFG keyword list <kwl> as a list of valid keywords for next |
| 7668 | * parsing sessions. |
| 7669 | */ |
| 7670 | void cfg_register_keywords(struct cfg_kw_list *kwl) |
| 7671 | { |
| 7672 | LIST_ADDQ(&cfg_keywords.list, &kwl->list); |
| 7673 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7674 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 7675 | /* |
| 7676 | * Unregisters the CFG keyword list <kwl> from the list of valid keywords. |
| 7677 | */ |
| 7678 | void cfg_unregister_keywords(struct cfg_kw_list *kwl) |
| 7679 | { |
| 7680 | LIST_DEL(&kwl->list); |
| 7681 | LIST_INIT(&kwl->list); |
| 7682 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7683 | |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 7684 | /* this function register new section in the haproxy configuration file. |
| 7685 | * <section_name> is the name of this new section and <section_parser> |
| 7686 | * is the called parser. If two section declaration have the same name, |
| 7687 | * only the first declared is used. |
| 7688 | */ |
| 7689 | int cfg_register_section(char *section_name, |
| 7690 | int (*section_parser)(const char *, int, char **, int)) |
| 7691 | { |
| 7692 | struct cfg_section *cs; |
| 7693 | |
| 7694 | cs = calloc(1, sizeof(*cs)); |
| 7695 | if (!cs) { |
| 7696 | Alert("register section '%s': out of memory.\n", section_name); |
| 7697 | return 0; |
| 7698 | } |
| 7699 | |
| 7700 | cs->section_name = section_name; |
| 7701 | cs->section_parser = section_parser; |
| 7702 | |
| 7703 | LIST_ADDQ(§ions, &cs->list); |
| 7704 | |
| 7705 | return 1; |
| 7706 | } |
| 7707 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7708 | /* |
| 7709 | * Local variables: |
| 7710 | * c-indent-level: 8 |
| 7711 | * c-basic-offset: 8 |
| 7712 | * End: |
| 7713 | */ |