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 | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 699 | else if (!strcmp(args[0], "tune.bufsize")) { |
| 700 | if (*(args[1]) == 0) { |
| 701 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 702 | err_code |= ERR_ALERT | ERR_FATAL; |
| 703 | goto out; |
| 704 | } |
| 705 | global.tune.bufsize = atol(args[1]); |
| 706 | if (global.tune.maxrewrite >= global.tune.bufsize / 2) |
| 707 | global.tune.maxrewrite = global.tune.bufsize / 2; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 708 | chunk_init(&trash, realloc(trash.str, global.tune.bufsize), global.tune.bufsize); |
Willy Tarreau | 2819e99 | 2013-12-13 14:41:10 +0100 | [diff] [blame] | 709 | alloc_trash_buffers(global.tune.bufsize); |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 710 | } |
| 711 | else if (!strcmp(args[0], "tune.maxrewrite")) { |
| 712 | if (*(args[1]) == 0) { |
| 713 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 714 | err_code |= ERR_ALERT | ERR_FATAL; |
| 715 | goto out; |
| 716 | } |
| 717 | global.tune.maxrewrite = atol(args[1]); |
| 718 | if (global.tune.maxrewrite >= global.tune.bufsize / 2) |
| 719 | global.tune.maxrewrite = global.tune.bufsize / 2; |
| 720 | } |
Willy Tarreau | 7e31273 | 2014-02-12 16:35:14 +0100 | [diff] [blame] | 721 | else if (!strcmp(args[0], "tune.idletimer")) { |
| 722 | unsigned int idle; |
| 723 | const char *res; |
| 724 | |
| 725 | if (*(args[1]) == 0) { |
| 726 | Alert("parsing [%s:%d] : '%s' expects a timer value between 0 and 65535 ms.\n", file, linenum, args[0]); |
| 727 | err_code |= ERR_ALERT | ERR_FATAL; |
| 728 | goto out; |
| 729 | } |
| 730 | |
| 731 | res = parse_time_err(args[1], &idle, TIME_UNIT_MS); |
| 732 | if (res) { |
| 733 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 734 | file, linenum, *res, args[0]); |
| 735 | err_code |= ERR_ALERT | ERR_FATAL; |
| 736 | goto out; |
| 737 | } |
| 738 | |
| 739 | if (idle > 65535) { |
| 740 | Alert("parsing [%s:%d] : '%s' expects a timer value between 0 and 65535 ms.\n", file, linenum, args[0]); |
| 741 | err_code |= ERR_ALERT | ERR_FATAL; |
| 742 | goto out; |
| 743 | } |
| 744 | global.tune.idle_timer = idle; |
| 745 | } |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 746 | else if (!strcmp(args[0], "tune.rcvbuf.client")) { |
| 747 | if (global.tune.client_rcvbuf != 0) { |
| 748 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 749 | err_code |= ERR_ALERT; |
| 750 | goto out; |
| 751 | } |
| 752 | if (*(args[1]) == 0) { |
| 753 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 754 | err_code |= ERR_ALERT | ERR_FATAL; |
| 755 | goto out; |
| 756 | } |
| 757 | global.tune.client_rcvbuf = atol(args[1]); |
| 758 | } |
| 759 | else if (!strcmp(args[0], "tune.rcvbuf.server")) { |
| 760 | if (global.tune.server_rcvbuf != 0) { |
| 761 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 762 | err_code |= ERR_ALERT; |
| 763 | goto out; |
| 764 | } |
| 765 | if (*(args[1]) == 0) { |
| 766 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 767 | err_code |= ERR_ALERT | ERR_FATAL; |
| 768 | goto out; |
| 769 | } |
| 770 | global.tune.server_rcvbuf = atol(args[1]); |
| 771 | } |
| 772 | else if (!strcmp(args[0], "tune.sndbuf.client")) { |
| 773 | if (global.tune.client_sndbuf != 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_sndbuf = atol(args[1]); |
| 784 | } |
| 785 | else if (!strcmp(args[0], "tune.sndbuf.server")) { |
| 786 | if (global.tune.server_sndbuf != 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_sndbuf = atol(args[1]); |
| 797 | } |
Willy Tarreau | bd9a0a7 | 2011-10-23 21:14:29 +0200 | [diff] [blame] | 798 | else if (!strcmp(args[0], "tune.pipesize")) { |
| 799 | if (*(args[1]) == 0) { |
| 800 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 801 | err_code |= ERR_ALERT | ERR_FATAL; |
| 802 | goto out; |
| 803 | } |
| 804 | global.tune.pipesize = atol(args[1]); |
| 805 | } |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 806 | else if (!strcmp(args[0], "tune.http.cookielen")) { |
| 807 | if (*(args[1]) == 0) { |
| 808 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 809 | err_code |= ERR_ALERT | ERR_FATAL; |
| 810 | goto out; |
| 811 | } |
| 812 | global.tune.cookie_len = atol(args[1]) + 1; |
| 813 | } |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame] | 814 | else if (!strcmp(args[0], "tune.http.maxhdr")) { |
| 815 | if (*(args[1]) == 0) { |
| 816 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 817 | err_code |= ERR_ALERT | ERR_FATAL; |
| 818 | goto out; |
| 819 | } |
| 820 | global.tune.max_http_hdr = atol(args[1]); |
| 821 | } |
William Lallemand | a509e4c | 2012-11-07 16:54:34 +0100 | [diff] [blame] | 822 | else if (!strcmp(args[0], "tune.zlib.memlevel")) { |
| 823 | #ifdef USE_ZLIB |
| 824 | if (*args[1]) { |
| 825 | global.tune.zlibmemlevel = atoi(args[1]); |
| 826 | if (global.tune.zlibmemlevel < 1 || global.tune.zlibmemlevel > 9) { |
| 827 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n", |
| 828 | file, linenum, args[0]); |
| 829 | err_code |= ERR_ALERT | ERR_FATAL; |
| 830 | goto out; |
| 831 | } |
| 832 | } else { |
| 833 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n", |
| 834 | file, linenum, args[0]); |
| 835 | err_code |= ERR_ALERT | ERR_FATAL; |
| 836 | goto out; |
| 837 | } |
| 838 | #else |
| 839 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 840 | err_code |= ERR_ALERT | ERR_FATAL; |
| 841 | goto out; |
| 842 | #endif |
| 843 | } |
| 844 | else if (!strcmp(args[0], "tune.zlib.windowsize")) { |
| 845 | #ifdef USE_ZLIB |
| 846 | if (*args[1]) { |
| 847 | global.tune.zlibwindowsize = atoi(args[1]); |
| 848 | if (global.tune.zlibwindowsize < 8 || global.tune.zlibwindowsize > 15) { |
| 849 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 8 and 15\n", |
| 850 | file, linenum, args[0]); |
| 851 | err_code |= ERR_ALERT | ERR_FATAL; |
| 852 | goto out; |
| 853 | } |
| 854 | } else { |
| 855 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 8 and 15\n", |
| 856 | file, linenum, args[0]); |
| 857 | err_code |= ERR_ALERT | ERR_FATAL; |
| 858 | goto out; |
| 859 | } |
| 860 | #else |
| 861 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 862 | err_code |= ERR_ALERT | ERR_FATAL; |
| 863 | goto out; |
| 864 | #endif |
| 865 | } |
William Lallemand | f374783 | 2012-11-09 12:33:10 +0100 | [diff] [blame] | 866 | else if (!strcmp(args[0], "tune.comp.maxlevel")) { |
| 867 | if (*args[1]) { |
| 868 | global.tune.comp_maxlevel = atoi(args[1]); |
| 869 | if (global.tune.comp_maxlevel < 1 || global.tune.comp_maxlevel > 9) { |
| 870 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n", |
| 871 | file, linenum, args[0]); |
| 872 | err_code |= ERR_ALERT | ERR_FATAL; |
| 873 | goto out; |
| 874 | } |
| 875 | } else { |
| 876 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n", |
| 877 | file, linenum, args[0]); |
| 878 | err_code |= ERR_ALERT | ERR_FATAL; |
| 879 | goto out; |
| 880 | } |
| 881 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 882 | else if (!strcmp(args[0], "uid")) { |
| 883 | if (global.uid != 0) { |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 884 | Alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 885 | err_code |= ERR_ALERT; |
| 886 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 887 | } |
| 888 | if (*(args[1]) == 0) { |
| 889 | 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] | 890 | err_code |= ERR_ALERT | ERR_FATAL; |
| 891 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 892 | } |
| 893 | global.uid = atol(args[1]); |
| 894 | } |
| 895 | else if (!strcmp(args[0], "gid")) { |
| 896 | if (global.gid != 0) { |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 897 | Alert("parsing [%s:%d] : group/gid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 898 | err_code |= ERR_ALERT; |
| 899 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 900 | } |
| 901 | if (*(args[1]) == 0) { |
| 902 | 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] | 903 | err_code |= ERR_ALERT | ERR_FATAL; |
| 904 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 905 | } |
| 906 | global.gid = atol(args[1]); |
| 907 | } |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 908 | else if (!strcmp(args[0], "external-check")) { |
| 909 | global.external_check = 1; |
| 910 | } |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 911 | /* user/group name handling */ |
| 912 | else if (!strcmp(args[0], "user")) { |
| 913 | struct passwd *ha_user; |
| 914 | if (global.uid != 0) { |
| 915 | Alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 916 | err_code |= ERR_ALERT; |
| 917 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 918 | } |
| 919 | errno = 0; |
| 920 | ha_user = getpwnam(args[1]); |
| 921 | if (ha_user != NULL) { |
| 922 | global.uid = (int)ha_user->pw_uid; |
| 923 | } |
| 924 | else { |
| 925 | 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] | 926 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 927 | } |
| 928 | } |
| 929 | else if (!strcmp(args[0], "group")) { |
| 930 | struct group *ha_group; |
| 931 | if (global.gid != 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 932 | 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] | 933 | err_code |= ERR_ALERT; |
| 934 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 935 | } |
| 936 | errno = 0; |
| 937 | ha_group = getgrnam(args[1]); |
| 938 | if (ha_group != NULL) { |
| 939 | global.gid = (int)ha_group->gr_gid; |
| 940 | } |
| 941 | else { |
| 942 | 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] | 943 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 944 | } |
| 945 | } |
| 946 | /* end of user/group name handling*/ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 947 | else if (!strcmp(args[0], "nbproc")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 948 | if (*(args[1]) == 0) { |
| 949 | 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] | 950 | err_code |= ERR_ALERT | ERR_FATAL; |
| 951 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 952 | } |
| 953 | global.nbproc = atol(args[1]); |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 954 | if (global.nbproc < 1 || global.nbproc > LONGBITS) { |
| 955 | Alert("parsing [%s:%d] : '%s' must be between 1 and %d (was %d).\n", |
| 956 | file, linenum, args[0], LONGBITS, global.nbproc); |
| 957 | err_code |= ERR_ALERT | ERR_FATAL; |
| 958 | goto out; |
| 959 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 960 | } |
| 961 | else if (!strcmp(args[0], "maxconn")) { |
| 962 | if (global.maxconn != 0) { |
| 963 | 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] | 964 | err_code |= ERR_ALERT; |
| 965 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 966 | } |
| 967 | if (*(args[1]) == 0) { |
| 968 | 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] | 969 | err_code |= ERR_ALERT | ERR_FATAL; |
| 970 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 971 | } |
| 972 | global.maxconn = atol(args[1]); |
| 973 | #ifdef SYSTEM_MAXCONN |
| 974 | if (global.maxconn > DEFAULT_MAXCONN && cfg_maxconn <= DEFAULT_MAXCONN) { |
| 975 | 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); |
| 976 | global.maxconn = DEFAULT_MAXCONN; |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 977 | err_code |= ERR_ALERT; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 978 | } |
| 979 | #endif /* SYSTEM_MAXCONN */ |
| 980 | } |
Willy Tarreau | 403edff | 2012-09-06 11:58:37 +0200 | [diff] [blame] | 981 | else if (!strcmp(args[0], "maxsslconn")) { |
| 982 | #ifdef USE_OPENSSL |
| 983 | if (*(args[1]) == 0) { |
| 984 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 985 | err_code |= ERR_ALERT | ERR_FATAL; |
| 986 | goto out; |
| 987 | } |
| 988 | global.maxsslconn = atol(args[1]); |
| 989 | #else |
Emeric Brun | 0914df8 | 2012-10-02 18:45:42 +0200 | [diff] [blame] | 990 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 991 | err_code |= ERR_ALERT | ERR_FATAL; |
| 992 | goto out; |
Willy Tarreau | 403edff | 2012-09-06 11:58:37 +0200 | [diff] [blame] | 993 | #endif |
| 994 | } |
Willy Tarreau | 610f04b | 2014-02-13 11:36:41 +0100 | [diff] [blame] | 995 | else if (!strcmp(args[0], "ssl-default-bind-ciphers")) { |
| 996 | #ifdef USE_OPENSSL |
| 997 | if (*(args[1]) == 0) { |
| 998 | Alert("parsing [%s:%d] : '%s' expects a cipher suite as an argument.\n", file, linenum, args[0]); |
| 999 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1000 | goto out; |
| 1001 | } |
| 1002 | free(global.listen_default_ciphers); |
| 1003 | global.listen_default_ciphers = strdup(args[1]); |
| 1004 | #else |
| 1005 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 1006 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1007 | goto out; |
| 1008 | #endif |
| 1009 | } |
| 1010 | else if (!strcmp(args[0], "ssl-default-server-ciphers")) { |
| 1011 | #ifdef USE_OPENSSL |
| 1012 | if (*(args[1]) == 0) { |
| 1013 | Alert("parsing [%s:%d] : '%s' expects a cipher suite as an argument.\n", file, linenum, args[0]); |
| 1014 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1015 | goto out; |
| 1016 | } |
| 1017 | free(global.connect_default_ciphers); |
| 1018 | global.connect_default_ciphers = strdup(args[1]); |
| 1019 | #else |
| 1020 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 1021 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1022 | goto out; |
| 1023 | #endif |
| 1024 | } |
Emeric Brun | 850efd5 | 2014-01-29 12:24:34 +0100 | [diff] [blame] | 1025 | else if (!strcmp(args[0], "ssl-server-verify")) { |
| 1026 | if (*(args[1]) == 0) { |
| 1027 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1028 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1029 | goto out; |
| 1030 | } |
| 1031 | if (strcmp(args[1],"none") == 0) |
| 1032 | global.ssl_server_verify = SSL_SERVER_VERIFY_NONE; |
| 1033 | else if (strcmp(args[1],"required") == 0) |
| 1034 | global.ssl_server_verify = SSL_SERVER_VERIFY_REQUIRED; |
| 1035 | else { |
| 1036 | Alert("parsing [%s:%d] : '%s' expects 'none' or 'required' as argument.\n", file, linenum, args[0]); |
| 1037 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1038 | goto out; |
| 1039 | } |
| 1040 | } |
Willy Tarreau | 81c25d0 | 2011-09-07 15:17:21 +0200 | [diff] [blame] | 1041 | else if (!strcmp(args[0], "maxconnrate")) { |
| 1042 | if (global.cps_lim != 0) { |
| 1043 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 1044 | err_code |= ERR_ALERT; |
| 1045 | goto out; |
| 1046 | } |
| 1047 | if (*(args[1]) == 0) { |
| 1048 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1049 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1050 | goto out; |
| 1051 | } |
| 1052 | global.cps_lim = atol(args[1]); |
| 1053 | } |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1054 | else if (!strcmp(args[0], "maxsessrate")) { |
| 1055 | if (global.sps_lim != 0) { |
| 1056 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 1057 | err_code |= ERR_ALERT; |
| 1058 | goto out; |
| 1059 | } |
| 1060 | if (*(args[1]) == 0) { |
| 1061 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1062 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1063 | goto out; |
| 1064 | } |
| 1065 | global.sps_lim = atol(args[1]); |
| 1066 | } |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 1067 | else if (!strcmp(args[0], "maxsslrate")) { |
| 1068 | if (global.ssl_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.ssl_lim = atol(args[1]); |
| 1079 | } |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1080 | else if (!strcmp(args[0], "maxcomprate")) { |
| 1081 | if (*(args[1]) == 0) { |
| 1082 | Alert("parsing [%s:%d] : '%s' expects an integer argument in kb/s.\n", file, linenum, args[0]); |
| 1083 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1084 | goto out; |
| 1085 | } |
| 1086 | global.comp_rate_lim = atoi(args[1]) * 1024; |
| 1087 | } |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 1088 | else if (!strcmp(args[0], "maxpipes")) { |
| 1089 | if (global.maxpipes != 0) { |
| 1090 | 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] | 1091 | err_code |= ERR_ALERT; |
| 1092 | goto out; |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 1093 | } |
| 1094 | if (*(args[1]) == 0) { |
| 1095 | 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] | 1096 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1097 | goto out; |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 1098 | } |
| 1099 | global.maxpipes = atol(args[1]); |
| 1100 | } |
William Lallemand | 9d5f548 | 2012-11-07 16:12:57 +0100 | [diff] [blame] | 1101 | else if (!strcmp(args[0], "maxzlibmem")) { |
| 1102 | if (*(args[1]) == 0) { |
| 1103 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1104 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1105 | goto out; |
| 1106 | } |
William Lallemand | e3a7d99 | 2012-11-20 11:25:20 +0100 | [diff] [blame] | 1107 | global.maxzlibmem = atol(args[1]) * 1024L * 1024L; |
William Lallemand | 9d5f548 | 2012-11-07 16:12:57 +0100 | [diff] [blame] | 1108 | } |
William Lallemand | 072a2bf | 2012-11-20 17:01:01 +0100 | [diff] [blame] | 1109 | else if (!strcmp(args[0], "maxcompcpuusage")) { |
| 1110 | if (*(args[1]) == 0) { |
| 1111 | Alert("parsing [%s:%d] : '%s' expects an integer argument between 0 and 100.\n", file, linenum, args[0]); |
| 1112 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1113 | goto out; |
| 1114 | } |
| 1115 | compress_min_idle = 100 - atoi(args[1]); |
Willy Tarreau | cb2699a | 2013-01-24 16:25:38 +0100 | [diff] [blame] | 1116 | if (compress_min_idle > 100) { |
William Lallemand | 072a2bf | 2012-11-20 17:01:01 +0100 | [diff] [blame] | 1117 | Alert("parsing [%s:%d] : '%s' expects an integer argument between 0 and 100.\n", file, linenum, args[0]); |
| 1118 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1119 | goto out; |
| 1120 | } |
| 1121 | } |
| 1122 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1123 | else if (!strcmp(args[0], "ulimit-n")) { |
| 1124 | if (global.rlimit_nofile != 0) { |
| 1125 | 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] | 1126 | err_code |= ERR_ALERT; |
| 1127 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1128 | } |
| 1129 | if (*(args[1]) == 0) { |
| 1130 | 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] | 1131 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1132 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1133 | } |
| 1134 | global.rlimit_nofile = atol(args[1]); |
| 1135 | } |
| 1136 | else if (!strcmp(args[0], "chroot")) { |
| 1137 | if (global.chroot != NULL) { |
| 1138 | 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] | 1139 | err_code |= ERR_ALERT; |
| 1140 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1141 | } |
| 1142 | if (*(args[1]) == 0) { |
| 1143 | 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] | 1144 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1145 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1146 | } |
| 1147 | global.chroot = strdup(args[1]); |
| 1148 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1149 | else if (!strcmp(args[0], "description")) { |
| 1150 | int i, len=0; |
| 1151 | char *d; |
| 1152 | |
| 1153 | if (!*args[1]) { |
| 1154 | Alert("parsing [%s:%d]: '%s' expects a string argument.\n", |
| 1155 | file, linenum, args[0]); |
| 1156 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1157 | goto out; |
| 1158 | } |
| 1159 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 1160 | for (i = 1; *args[i]; i++) |
| 1161 | len += strlen(args[i]) + 1; |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1162 | |
| 1163 | if (global.desc) |
| 1164 | free(global.desc); |
| 1165 | |
| 1166 | global.desc = d = (char *)calloc(1, len); |
| 1167 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 1168 | d += snprintf(d, global.desc + len - d, "%s", args[1]); |
| 1169 | for (i = 2; *args[i]; i++) |
| 1170 | d += snprintf(d, global.desc + len - d, " %s", args[i]); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1171 | } |
| 1172 | else if (!strcmp(args[0], "node")) { |
| 1173 | int i; |
| 1174 | char c; |
| 1175 | |
| 1176 | for (i=0; args[1][i]; i++) { |
| 1177 | c = args[1][i]; |
Willy Tarreau | 88e0581 | 2010-03-03 00:16:00 +0100 | [diff] [blame] | 1178 | if (!isupper((unsigned char)c) && !islower((unsigned char)c) && |
| 1179 | !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.') |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1180 | break; |
| 1181 | } |
| 1182 | |
| 1183 | if (!i || args[1][i]) { |
| 1184 | Alert("parsing [%s:%d]: '%s' requires valid node name - non-empty string" |
| 1185 | " with digits(0-9), letters(A-Z, a-z), dot(.), hyphen(-) or underscode(_).\n", |
| 1186 | file, linenum, args[0]); |
| 1187 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1188 | goto out; |
| 1189 | } |
| 1190 | |
| 1191 | if (global.node) |
| 1192 | free(global.node); |
| 1193 | |
| 1194 | global.node = strdup(args[1]); |
| 1195 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1196 | else if (!strcmp(args[0], "pidfile")) { |
| 1197 | if (global.pidfile != NULL) { |
| 1198 | 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] | 1199 | err_code |= ERR_ALERT; |
| 1200 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1201 | } |
| 1202 | if (*(args[1]) == 0) { |
| 1203 | 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] | 1204 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1205 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1206 | } |
| 1207 | global.pidfile = strdup(args[1]); |
| 1208 | } |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 1209 | else if (!strcmp(args[0], "unix-bind")) { |
| 1210 | int cur_arg = 1; |
| 1211 | while (*(args[cur_arg])) { |
| 1212 | if (!strcmp(args[cur_arg], "prefix")) { |
| 1213 | if (global.unix_bind.prefix != NULL) { |
| 1214 | Alert("parsing [%s:%d] : unix-bind '%s' already specified. Continuing.\n", file, linenum, args[cur_arg]); |
| 1215 | err_code |= ERR_ALERT; |
| 1216 | cur_arg += 2; |
| 1217 | continue; |
| 1218 | } |
| 1219 | |
| 1220 | if (*(args[cur_arg+1]) == 0) { |
| 1221 | Alert("parsing [%s:%d] : unix_bind '%s' expects a path as an argument.\n", file, linenum, args[cur_arg]); |
| 1222 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1223 | goto out; |
| 1224 | } |
| 1225 | global.unix_bind.prefix = strdup(args[cur_arg+1]); |
| 1226 | cur_arg += 2; |
| 1227 | continue; |
| 1228 | } |
| 1229 | |
| 1230 | if (!strcmp(args[cur_arg], "mode")) { |
| 1231 | |
| 1232 | global.unix_bind.ux.mode = strtol(args[cur_arg + 1], NULL, 8); |
| 1233 | cur_arg += 2; |
| 1234 | continue; |
| 1235 | } |
| 1236 | |
| 1237 | if (!strcmp(args[cur_arg], "uid")) { |
| 1238 | |
| 1239 | global.unix_bind.ux.uid = atol(args[cur_arg + 1 ]); |
| 1240 | cur_arg += 2; |
| 1241 | continue; |
| 1242 | } |
| 1243 | |
| 1244 | if (!strcmp(args[cur_arg], "gid")) { |
| 1245 | |
| 1246 | global.unix_bind.ux.gid = atol(args[cur_arg + 1 ]); |
| 1247 | cur_arg += 2; |
| 1248 | continue; |
| 1249 | } |
| 1250 | |
| 1251 | if (!strcmp(args[cur_arg], "user")) { |
| 1252 | struct passwd *user; |
| 1253 | |
| 1254 | user = getpwnam(args[cur_arg + 1]); |
| 1255 | if (!user) { |
| 1256 | Alert("parsing [%s:%d] : '%s' : '%s' unknown user.\n", |
| 1257 | file, linenum, args[0], args[cur_arg + 1 ]); |
| 1258 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1259 | goto out; |
| 1260 | } |
| 1261 | |
| 1262 | global.unix_bind.ux.uid = user->pw_uid; |
| 1263 | cur_arg += 2; |
| 1264 | continue; |
| 1265 | } |
| 1266 | |
| 1267 | if (!strcmp(args[cur_arg], "group")) { |
| 1268 | struct group *group; |
| 1269 | |
| 1270 | group = getgrnam(args[cur_arg + 1]); |
| 1271 | if (!group) { |
| 1272 | Alert("parsing [%s:%d] : '%s' : '%s' unknown group.\n", |
| 1273 | file, linenum, args[0], args[cur_arg + 1 ]); |
| 1274 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1275 | goto out; |
| 1276 | } |
| 1277 | |
| 1278 | global.unix_bind.ux.gid = group->gr_gid; |
| 1279 | cur_arg += 2; |
| 1280 | continue; |
| 1281 | } |
| 1282 | |
Willy Tarreau | b48f958 | 2011-09-05 01:17:06 +0200 | [diff] [blame] | 1283 | 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] | 1284 | file, linenum, args[0]); |
| 1285 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1286 | goto out; |
| 1287 | } |
| 1288 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1289 | else if (!strcmp(args[0], "log") && kwm == KWM_NO) { /* no log */ |
| 1290 | /* delete previous herited or defined syslog servers */ |
| 1291 | struct logsrv *back; |
| 1292 | struct logsrv *tmp; |
| 1293 | |
| 1294 | if (*(args[1]) != 0) { |
| 1295 | Alert("parsing [%s:%d]:%s : 'no log' does not expect arguments.\n", file, linenum, args[1]); |
| 1296 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1297 | goto out; |
| 1298 | } |
| 1299 | |
| 1300 | list_for_each_entry_safe(tmp, back, &global.logsrvs, list) { |
| 1301 | LIST_DEL(&tmp->list); |
| 1302 | free(tmp); |
| 1303 | } |
| 1304 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1305 | else if (!strcmp(args[0], "log")) { /* syslog server address */ |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1306 | struct sockaddr_storage *sk; |
| 1307 | int port1, port2; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1308 | struct logsrv *logsrv; |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1309 | int arg = 0; |
| 1310 | int len = 0; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1311 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1312 | if (*(args[1]) == 0 || *(args[2]) == 0) { |
| 1313 | 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] | 1314 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1315 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1316 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1317 | |
| 1318 | logsrv = calloc(1, sizeof(struct logsrv)); |
| 1319 | |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1320 | /* just after the address, a length may be specified */ |
| 1321 | if (strcmp(args[arg+2], "len") == 0) { |
| 1322 | len = atoi(args[arg+3]); |
| 1323 | if (len < 80 || len > 65535) { |
| 1324 | Alert("parsing [%s:%d] : invalid log length '%s', must be between 80 and 65535.\n", |
| 1325 | file, linenum, args[arg+3]); |
| 1326 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1327 | goto out; |
| 1328 | } |
| 1329 | logsrv->maxlen = len; |
| 1330 | |
| 1331 | /* skip these two args */ |
| 1332 | arg += 2; |
| 1333 | } |
| 1334 | else |
| 1335 | logsrv->maxlen = MAX_SYSLOG_LEN; |
| 1336 | |
| 1337 | if (logsrv->maxlen > global.max_syslog_len) { |
| 1338 | global.max_syslog_len = logsrv->maxlen; |
| 1339 | logline = realloc(logline, global.max_syslog_len + 1); |
| 1340 | } |
| 1341 | |
| 1342 | logsrv->facility = get_log_facility(args[arg+2]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1343 | if (logsrv->facility < 0) { |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1344 | 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] | 1345 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1346 | logsrv->facility = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1347 | } |
| 1348 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1349 | logsrv->level = 7; /* max syslog level = debug */ |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1350 | if (*(args[arg+3])) { |
| 1351 | logsrv->level = get_log_level(args[arg+3]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1352 | if (logsrv->level < 0) { |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1353 | 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] | 1354 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1355 | logsrv->level = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1356 | } |
| 1357 | } |
| 1358 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1359 | logsrv->minlvl = 0; /* limit syslog level to this level (emerg) */ |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1360 | if (*(args[arg+4])) { |
| 1361 | logsrv->minlvl = get_log_level(args[arg+4]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1362 | if (logsrv->minlvl < 0) { |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1363 | 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] | 1364 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1365 | logsrv->minlvl = 0; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 1366 | } |
| 1367 | } |
| 1368 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1369 | sk = str2sa_range(args[1], &port1, &port2, &errmsg, NULL); |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1370 | if (!sk) { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1371 | Alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1372 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1373 | free(logsrv); |
| 1374 | goto out; |
| 1375 | } |
| 1376 | logsrv->addr = *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 1377 | |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1378 | if (sk->ss_family == AF_INET || sk->ss_family == AF_INET6) { |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 1379 | if (port1 != port2) { |
| 1380 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 1381 | file, linenum, args[0], args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 1382 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1383 | free(logsrv); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 1384 | goto out; |
| 1385 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 1386 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1387 | logsrv->addr = *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 1388 | if (!port1) |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1389 | set_host_port(&logsrv->addr, SYSLOG_PORT); |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 1390 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1391 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1392 | LIST_ADDQ(&global.logsrvs, &logsrv->list); |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1393 | } |
Joe Williams | df5b38f | 2010-12-29 17:05:48 +0100 | [diff] [blame] | 1394 | else if (!strcmp(args[0], "log-send-hostname")) { /* set the hostname in syslog header */ |
| 1395 | char *name; |
| 1396 | int len; |
| 1397 | |
| 1398 | if (global.log_send_hostname != NULL) { |
| 1399 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 1400 | err_code |= ERR_ALERT; |
| 1401 | goto out; |
| 1402 | } |
| 1403 | |
| 1404 | if (*(args[1])) |
| 1405 | name = args[1]; |
| 1406 | else |
| 1407 | name = hostname; |
| 1408 | |
| 1409 | len = strlen(name); |
| 1410 | |
| 1411 | /* We'll add a space after the name to respect the log format */ |
| 1412 | free(global.log_send_hostname); |
| 1413 | global.log_send_hostname = malloc(len + 2); |
| 1414 | snprintf(global.log_send_hostname, len + 2, "%s ", name); |
| 1415 | } |
Kevinm | 48936af | 2010-12-22 16:08:21 +0000 | [diff] [blame] | 1416 | else if (!strcmp(args[0], "log-tag")) { /* tag to report to syslog */ |
| 1417 | if (*(args[1]) == 0) { |
| 1418 | Alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]); |
| 1419 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1420 | goto out; |
| 1421 | } |
| 1422 | free(global.log_tag); |
| 1423 | global.log_tag = strdup(args[1]); |
| 1424 | } |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1425 | else if (!strcmp(args[0], "spread-checks")) { /* random time between checks (0-50) */ |
| 1426 | if (global.spread_checks != 0) { |
| 1427 | Alert("parsing [%s:%d]: spread-checks already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1428 | err_code |= ERR_ALERT; |
| 1429 | goto out; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1430 | } |
| 1431 | if (*(args[1]) == 0) { |
| 1432 | 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] | 1433 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1434 | goto out; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1435 | } |
| 1436 | global.spread_checks = atol(args[1]); |
| 1437 | if (global.spread_checks < 0 || global.spread_checks > 50) { |
| 1438 | 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] | 1439 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1440 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1441 | } |
Willy Tarreau | 1746eec | 2014-04-25 10:46:47 +0200 | [diff] [blame] | 1442 | else if (!strcmp(args[0], "max-spread-checks")) { /* maximum time between first and last check */ |
| 1443 | const char *err; |
| 1444 | unsigned int val; |
| 1445 | |
| 1446 | |
| 1447 | if (*(args[1]) == 0) { |
| 1448 | Alert("parsing [%s:%d]: '%s' expects an integer argument (0..50).\n", file, linenum, args[0]); |
| 1449 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1450 | goto out; |
| 1451 | } |
| 1452 | |
| 1453 | err = parse_time_err(args[1], &val, TIME_UNIT_MS); |
| 1454 | if (err) { |
| 1455 | Alert("parsing [%s:%d]: unsupported character '%c' in '%s' (wants an integer delay).\n", file, linenum, *err, args[0]); |
| 1456 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1457 | } |
| 1458 | global.max_spread_checks = val; |
| 1459 | if (global.max_spread_checks < 0) { |
| 1460 | Alert("parsing [%s:%d]: '%s' needs a positive delay in milliseconds.\n",file, linenum, args[0]); |
| 1461 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1462 | } |
| 1463 | } |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1464 | else if (strcmp(args[0], "cpu-map") == 0) { /* map a process list to a CPU set */ |
| 1465 | #ifdef USE_CPU_AFFINITY |
| 1466 | int cur_arg, i; |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1467 | unsigned long proc = 0; |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1468 | unsigned long cpus = 0; |
| 1469 | |
| 1470 | if (strcmp(args[1], "all") == 0) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1471 | proc = ~0UL; |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1472 | else if (strcmp(args[1], "odd") == 0) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1473 | proc = ~0UL/3UL; /* 0x555....555 */ |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1474 | else if (strcmp(args[1], "even") == 0) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1475 | proc = (~0UL/3UL) << 1; /* 0xAAA...AAA */ |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1476 | else { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1477 | proc = atol(args[1]); |
| 1478 | if (proc >= 1 && proc <= LONGBITS) |
| 1479 | proc = 1UL << (proc - 1); |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1480 | } |
| 1481 | |
| 1482 | if (!proc || !*args[2]) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1483 | 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", |
| 1484 | file, linenum, args[0], LONGBITS, LONGBITS - 1); |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1485 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1486 | goto out; |
| 1487 | } |
| 1488 | |
| 1489 | cur_arg = 2; |
| 1490 | while (*args[cur_arg]) { |
| 1491 | unsigned int low, high; |
| 1492 | |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 1493 | if (isdigit((int)*args[cur_arg])) { |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1494 | char *dash = strchr(args[cur_arg], '-'); |
| 1495 | |
| 1496 | low = high = str2uic(args[cur_arg]); |
| 1497 | if (dash) |
| 1498 | high = str2uic(dash + 1); |
| 1499 | |
| 1500 | if (high < low) { |
| 1501 | unsigned int swap = low; |
| 1502 | low = high; |
| 1503 | high = swap; |
| 1504 | } |
| 1505 | |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1506 | if (high >= LONGBITS) { |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1507 | 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] | 1508 | file, linenum, args[0], LONGBITS - 1); |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1509 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1510 | goto out; |
| 1511 | } |
| 1512 | |
| 1513 | while (low <= high) |
| 1514 | cpus |= 1UL << low++; |
| 1515 | } |
| 1516 | else { |
| 1517 | Alert("parsing [%s:%d]: %s : '%s' is not a CPU range.\n", |
| 1518 | file, linenum, args[0], args[cur_arg]); |
| 1519 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1520 | goto out; |
| 1521 | } |
| 1522 | cur_arg++; |
| 1523 | } |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1524 | for (i = 0; i < LONGBITS; i++) |
| 1525 | if (proc & (1UL << i)) |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1526 | global.cpu_map[i] = cpus; |
| 1527 | #else |
| 1528 | Alert("parsing [%s:%d] : '%s' is not enabled, please check build options for USE_CPU_AFFINITY.\n", file, linenum, args[0]); |
| 1529 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1530 | goto out; |
| 1531 | #endif |
| 1532 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1533 | else { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1534 | struct cfg_kw_list *kwl; |
| 1535 | int index; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1536 | int rc; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1537 | |
| 1538 | list_for_each_entry(kwl, &cfg_keywords.list, list) { |
| 1539 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 1540 | if (kwl->kw[index].section != CFG_GLOBAL) |
| 1541 | continue; |
| 1542 | if (strcmp(kwl->kw[index].kw, args[0]) == 0) { |
Willy Tarreau | 28a47d6 | 2012-09-18 20:02:48 +0200 | [diff] [blame] | 1543 | 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] | 1544 | if (rc < 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 1545 | Alert("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1546 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1547 | } |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1548 | else if (rc > 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 1549 | Warning("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1550 | err_code |= ERR_WARN; |
| 1551 | goto out; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1552 | } |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1553 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1554 | } |
| 1555 | } |
| 1556 | } |
| 1557 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1558 | 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] | 1559 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1560 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1561 | |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1562 | out: |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 1563 | free(errmsg); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1564 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1565 | } |
| 1566 | |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 1567 | void init_default_instance() |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1568 | { |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 1569 | init_new_proxy(&defproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1570 | defproxy.mode = PR_MODE_TCP; |
| 1571 | defproxy.state = PR_STNEW; |
| 1572 | defproxy.maxconn = cfg_maxpconn; |
| 1573 | defproxy.conn_retries = CONN_RETRIES; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1574 | |
Simon Horman | 6618300 | 2013-02-23 10:16:43 +0900 | [diff] [blame] | 1575 | defproxy.defsrv.check.inter = DEF_CHKINTR; |
| 1576 | defproxy.defsrv.check.fastinter = 0; |
| 1577 | defproxy.defsrv.check.downinter = 0; |
Simon Horman | d60d691 | 2013-11-25 10:46:36 +0900 | [diff] [blame] | 1578 | defproxy.defsrv.agent.inter = DEF_CHKINTR; |
| 1579 | defproxy.defsrv.agent.fastinter = 0; |
| 1580 | defproxy.defsrv.agent.downinter = 0; |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 1581 | defproxy.defsrv.check.rise = DEF_RISETIME; |
| 1582 | defproxy.defsrv.check.fall = DEF_FALLTIME; |
| 1583 | defproxy.defsrv.agent.rise = DEF_AGENT_RISETIME; |
| 1584 | defproxy.defsrv.agent.fall = DEF_AGENT_FALLTIME; |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 1585 | defproxy.defsrv.check.port = 0; |
Simon Horman | d60d691 | 2013-11-25 10:46:36 +0900 | [diff] [blame] | 1586 | defproxy.defsrv.agent.port = 0; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1587 | defproxy.defsrv.maxqueue = 0; |
| 1588 | defproxy.defsrv.minconn = 0; |
| 1589 | defproxy.defsrv.maxconn = 0; |
| 1590 | defproxy.defsrv.slowstart = 0; |
| 1591 | defproxy.defsrv.onerror = DEF_HANA_ONERR; |
| 1592 | defproxy.defsrv.consecutive_errors_limit = DEF_HANA_ERRLIMIT; |
| 1593 | defproxy.defsrv.uweight = defproxy.defsrv.iweight = 1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1594 | } |
| 1595 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1596 | |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1597 | /* This function createss a new req* or rsp* rule to the proxy. It compiles the |
| 1598 | * regex and may return the ERR_WARN bit, and error bits such as ERR_ALERT and |
| 1599 | * ERR_FATAL in case of error. |
| 1600 | */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1601 | static int create_cond_regex_rule(const char *file, int line, |
| 1602 | struct proxy *px, int dir, int action, int flags, |
| 1603 | const char *cmd, const char *reg, const char *repl, |
| 1604 | const char **cond_start) |
| 1605 | { |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1606 | struct my_regex *preg = NULL; |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 1607 | char *errmsg = NULL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1608 | const char *err; |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1609 | char *error; |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1610 | int ret_code = 0; |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1611 | struct acl_cond *cond = NULL; |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1612 | int cs; |
| 1613 | int cap; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1614 | |
| 1615 | if (px == &defproxy) { |
| 1616 | 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] | 1617 | ret_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1618 | goto err; |
| 1619 | } |
| 1620 | |
| 1621 | if (*reg == 0) { |
| 1622 | 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] | 1623 | ret_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1624 | goto err; |
| 1625 | } |
| 1626 | |
| 1627 | if (warnifnotcap(px, PR_CAP_RS, file, line, cmd, NULL)) |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1628 | ret_code |= ERR_WARN; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1629 | |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1630 | if (cond_start && |
| 1631 | (strcmp(*cond_start, "if") == 0 || strcmp(*cond_start, "unless") == 0)) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 1632 | if ((cond = build_acl_cond(file, line, px, cond_start, &errmsg)) == NULL) { |
| 1633 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 1634 | file, line, cmd, errmsg); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1635 | ret_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1636 | goto err; |
| 1637 | } |
| 1638 | } |
| 1639 | else if (cond_start && **cond_start) { |
| 1640 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 1641 | file, line, cmd, *cond_start); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1642 | ret_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1643 | goto err; |
| 1644 | } |
| 1645 | |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1646 | ret_code |= warnif_cond_conflicts(cond, |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 1647 | (dir == SMP_OPT_DIR_REQ) ? |
| 1648 | ((px->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR) : |
| 1649 | ((px->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR), |
| 1650 | file, line); |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1651 | |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1652 | preg = calloc(1, sizeof(*preg)); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1653 | if (!preg) { |
| 1654 | 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] | 1655 | ret_code = ERR_ALERT | ERR_FATAL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1656 | goto err; |
| 1657 | } |
| 1658 | |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1659 | cs = !(flags & REG_ICASE); |
| 1660 | cap = !(flags & REG_NOSUB); |
| 1661 | error = NULL; |
| 1662 | if (!regex_comp(reg, preg, cs, cap, &error)) { |
| 1663 | Alert("parsing [%s:%d] : '%s' : regular expression '%s' : %s\n", file, line, cmd, reg, error); |
| 1664 | free(error); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1665 | ret_code = ERR_ALERT | ERR_FATAL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1666 | goto err; |
| 1667 | } |
| 1668 | |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 1669 | 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] | 1670 | preg, action, repl ? strdup(repl) : NULL, cond); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1671 | if (repl && err) { |
| 1672 | Alert("parsing [%s:%d] : '%s' : invalid character or unterminated sequence in replacement string near '%c'.\n", |
| 1673 | file, line, cmd, *err); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1674 | ret_code |= ERR_ALERT | ERR_FATAL; |
| 1675 | goto err_free; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1676 | } |
| 1677 | |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 1678 | 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] | 1679 | ret_code |= ERR_WARN; |
| 1680 | |
| 1681 | return ret_code; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1682 | |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1683 | err_free: |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1684 | regex_free(preg); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1685 | err: |
| 1686 | free(preg); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1687 | free(errmsg); |
| 1688 | return ret_code; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1689 | } |
| 1690 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1691 | /* |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1692 | * Parse a line in a <listen>, <frontend>, <backend> or <ruleset> section. |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1693 | * Returns the error code, 0 if OK, or any combination of : |
| 1694 | * - ERR_ABORT: must abort ASAP |
| 1695 | * - ERR_FATAL: we can continue parsing but not start the service |
| 1696 | * - ERR_WARN: a warning has been emitted |
| 1697 | * - ERR_ALERT: an alert has been emitted |
| 1698 | * Only the two first ones can stop processing, the two others are just |
| 1699 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1700 | */ |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1701 | int cfg_parse_peers(const char *file, int linenum, char **args, int kwm) |
| 1702 | { |
| 1703 | static struct peers *curpeers = NULL; |
| 1704 | struct peer *newpeer = NULL; |
| 1705 | const char *err; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1706 | struct bind_conf *bind_conf; |
| 1707 | struct listener *l; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1708 | int err_code = 0; |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1709 | char *errmsg = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1710 | |
| 1711 | if (strcmp(args[0], "peers") == 0) { /* new peers section */ |
Willy Tarreau | 0dbbf31 | 2013-03-05 11:31:55 +0100 | [diff] [blame] | 1712 | if (!*args[1]) { |
| 1713 | Alert("parsing [%s:%d] : missing name for peers section.\n", file, linenum); |
Willy Tarreau | 5498472 | 2014-02-16 08:20:13 +0100 | [diff] [blame] | 1714 | err_code |= ERR_ALERT | ERR_ABORT; |
Willy Tarreau | 0dbbf31 | 2013-03-05 11:31:55 +0100 | [diff] [blame] | 1715 | goto out; |
| 1716 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1717 | |
| 1718 | err = invalid_char(args[1]); |
| 1719 | if (err) { |
| 1720 | Alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 1721 | file, linenum, *err, args[0], args[1]); |
Willy Tarreau | 5498472 | 2014-02-16 08:20:13 +0100 | [diff] [blame] | 1722 | err_code |= ERR_ALERT | ERR_ABORT; |
Willy Tarreau | 0dbbf31 | 2013-03-05 11:31:55 +0100 | [diff] [blame] | 1723 | goto out; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1724 | } |
| 1725 | |
| 1726 | for (curpeers = peers; curpeers != NULL; curpeers = curpeers->next) { |
| 1727 | /* |
| 1728 | * If there are two proxies with the same name only following |
| 1729 | * combinations are allowed: |
| 1730 | */ |
| 1731 | if (strcmp(curpeers->id, args[1]) == 0) { |
| 1732 | Warning("Parsing [%s:%d]: peers '%s' has same name as another peers (declared at %s:%d).\n", |
| 1733 | file, linenum, args[1], curpeers->conf.file, curpeers->conf.line); |
| 1734 | err_code |= ERR_WARN; |
| 1735 | } |
| 1736 | } |
| 1737 | |
| 1738 | if ((curpeers = (struct peers *)calloc(1, sizeof(struct peers))) == NULL) { |
| 1739 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1740 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1741 | goto out; |
| 1742 | } |
| 1743 | |
| 1744 | curpeers->next = peers; |
| 1745 | peers = curpeers; |
Willy Tarreau | 8113a5d | 2012-10-04 08:01:43 +0200 | [diff] [blame] | 1746 | curpeers->conf.file = strdup(file); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1747 | curpeers->conf.line = linenum; |
| 1748 | curpeers->last_change = now.tv_sec; |
| 1749 | curpeers->id = strdup(args[1]); |
| 1750 | } |
| 1751 | else if (strcmp(args[0], "peer") == 0) { /* peer definition */ |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 1752 | struct sockaddr_storage *sk; |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 1753 | int port1, port2; |
Willy Tarreau | b36487e | 2013-03-10 18:37:42 +0100 | [diff] [blame] | 1754 | struct protocol *proto; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1755 | |
| 1756 | if (!*args[2]) { |
| 1757 | Alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n", |
| 1758 | file, linenum, args[0]); |
| 1759 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1760 | goto out; |
| 1761 | } |
| 1762 | |
| 1763 | err = invalid_char(args[1]); |
| 1764 | if (err) { |
| 1765 | Alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n", |
| 1766 | file, linenum, *err, args[1]); |
| 1767 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1768 | goto out; |
| 1769 | } |
| 1770 | |
| 1771 | if ((newpeer = (struct peer *)calloc(1, sizeof(struct peer))) == NULL) { |
| 1772 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1773 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1774 | goto out; |
| 1775 | } |
| 1776 | |
| 1777 | /* the peers are linked backwards first */ |
| 1778 | curpeers->count++; |
| 1779 | newpeer->next = curpeers->remote; |
| 1780 | curpeers->remote = newpeer; |
| 1781 | newpeer->peers = curpeers; |
Willy Tarreau | 8113a5d | 2012-10-04 08:01:43 +0200 | [diff] [blame] | 1782 | newpeer->conf.file = strdup(file); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1783 | newpeer->conf.line = linenum; |
| 1784 | |
| 1785 | newpeer->last_change = now.tv_sec; |
| 1786 | newpeer->id = strdup(args[1]); |
| 1787 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1788 | sk = str2sa_range(args[2], &port1, &port2, &errmsg, NULL); |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 1789 | if (!sk) { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1790 | 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] | 1791 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1792 | goto out; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1793 | } |
Willy Tarreau | b36487e | 2013-03-10 18:37:42 +0100 | [diff] [blame] | 1794 | |
| 1795 | proto = protocol_by_family(sk->ss_family); |
| 1796 | if (!proto || !proto->connect) { |
| 1797 | Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 1798 | file, linenum, args[0], args[1]); |
| 1799 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1800 | goto out; |
| 1801 | } |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 1802 | |
| 1803 | if (port1 != port2) { |
| 1804 | Alert("parsing [%s:%d] : '%s %s' : port ranges and offsets are not allowed in '%s'\n", |
| 1805 | file, linenum, args[0], args[1], args[2]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1806 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1807 | goto out; |
| 1808 | } |
| 1809 | |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 1810 | if (!port1) { |
| 1811 | Alert("parsing [%s:%d] : '%s %s' : missing or invalid port in '%s'\n", |
| 1812 | file, linenum, args[0], args[1], args[2]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1813 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1814 | goto out; |
| 1815 | } |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 1816 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1817 | newpeer->addr = *sk; |
Willy Tarreau | b36487e | 2013-03-10 18:37:42 +0100 | [diff] [blame] | 1818 | newpeer->proto = proto; |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 1819 | newpeer->xprt = &raw_sock; |
Willy Tarreau | d02394b | 2012-05-11 18:32:18 +0200 | [diff] [blame] | 1820 | newpeer->sock_init_arg = NULL; |
Willy Tarreau | 26d8c59 | 2012-05-07 18:12:14 +0200 | [diff] [blame] | 1821 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1822 | if (strcmp(newpeer->id, localpeer) == 0) { |
| 1823 | /* Current is local peer, it define a frontend */ |
| 1824 | newpeer->local = 1; |
| 1825 | |
| 1826 | if (!curpeers->peers_fe) { |
| 1827 | if ((curpeers->peers_fe = calloc(1, sizeof(struct proxy))) == NULL) { |
| 1828 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1829 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1830 | goto out; |
| 1831 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1832 | |
Willy Tarreau | 237250c | 2011-07-29 01:49:03 +0200 | [diff] [blame] | 1833 | init_new_proxy(curpeers->peers_fe); |
| 1834 | curpeers->peers_fe->parent = curpeers; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1835 | |
| 1836 | curpeers->peers_fe->last_change = now.tv_sec; |
| 1837 | curpeers->peers_fe->id = strdup(args[1]); |
| 1838 | curpeers->peers_fe->cap = PR_CAP_FE; |
Willy Tarreau | 3ae65a1 | 2011-09-07 17:40:39 +0200 | [diff] [blame] | 1839 | curpeers->peers_fe->maxconn = 0; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1840 | curpeers->peers_fe->conn_retries = CONN_RETRIES; |
| 1841 | curpeers->peers_fe->timeout.connect = 5000; |
| 1842 | curpeers->peers_fe->accept = peer_accept; |
| 1843 | 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] | 1844 | curpeers->peers_fe->conf.args.file = curpeers->peers_fe->conf.file = strdup(file); |
| 1845 | curpeers->peers_fe->conf.args.line = curpeers->peers_fe->conf.line = linenum; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1846 | |
| 1847 | bind_conf = bind_conf_alloc(&curpeers->peers_fe->conf.bind, file, linenum, args[2]); |
| 1848 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1849 | if (!str2listener(args[2], curpeers->peers_fe, bind_conf, file, linenum, &errmsg)) { |
| 1850 | if (errmsg && *errmsg) { |
| 1851 | indent_msg(&errmsg, 2); |
| 1852 | 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] | 1853 | } |
| 1854 | else |
| 1855 | Alert("parsing [%s:%d] : '%s %s' : error encountered while parsing listening address %s.\n", |
| 1856 | file, linenum, args[0], args[1], args[2]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1857 | err_code |= ERR_FATAL; |
| 1858 | goto out; |
| 1859 | } |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1860 | |
| 1861 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
Willy Tarreau | acf3bf9 | 2013-01-18 10:51:07 +0100 | [diff] [blame] | 1862 | l->maxaccept = 1; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1863 | l->maxconn = ((struct proxy *)curpeers->peers_fe)->maxconn; |
| 1864 | l->backlog = ((struct proxy *)curpeers->peers_fe)->backlog; |
| 1865 | l->timeout = &((struct proxy *)curpeers->peers_fe)->timeout.client; |
| 1866 | l->accept = session_accept; |
| 1867 | l->handler = process_session; |
| 1868 | l->analysers |= ((struct proxy *)curpeers->peers_fe)->fe_req_ana; |
| 1869 | l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */ |
| 1870 | global.maxsock += l->maxconn; |
| 1871 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1872 | } |
Willy Tarreau | 8b8fd56 | 2013-01-18 11:12:27 +0100 | [diff] [blame] | 1873 | else { |
| 1874 | Alert("parsing [%s:%d] : '%s %s' : local peer name already referenced at %s:%d.\n", |
| 1875 | file, linenum, args[0], args[1], |
| 1876 | curpeers->peers_fe->conf.file, curpeers->peers_fe->conf.line); |
| 1877 | err_code |= ERR_FATAL; |
| 1878 | goto out; |
| 1879 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1880 | } |
| 1881 | } /* neither "peer" nor "peers" */ |
| 1882 | else if (*args[0] != 0) { |
| 1883 | Alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection); |
| 1884 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1885 | goto out; |
| 1886 | } |
| 1887 | |
| 1888 | out: |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1889 | free(errmsg); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1890 | return err_code; |
| 1891 | } |
| 1892 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 1893 | 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] | 1894 | { |
| 1895 | static struct proxy *curproxy = NULL; |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 1896 | const char *err; |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1897 | char *error; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 1898 | int rc; |
| 1899 | unsigned val; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1900 | int err_code = 0; |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 1901 | struct acl_cond *cond = NULL; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 1902 | struct logsrv *tmplogsrv; |
Willy Tarreau | f4068b6 | 2012-05-08 17:37:49 +0200 | [diff] [blame] | 1903 | char *errmsg = NULL; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 1904 | struct bind_conf *bind_conf; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1905 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1906 | if (!strcmp(args[0], "listen")) |
| 1907 | rc = PR_CAP_LISTEN; |
| 1908 | else if (!strcmp(args[0], "frontend")) |
| 1909 | rc = PR_CAP_FE | PR_CAP_RS; |
| 1910 | else if (!strcmp(args[0], "backend")) |
| 1911 | rc = PR_CAP_BE | PR_CAP_RS; |
| 1912 | else if (!strcmp(args[0], "ruleset")) |
| 1913 | rc = PR_CAP_RS; |
| 1914 | else |
| 1915 | rc = PR_CAP_NONE; |
| 1916 | |
| 1917 | if (rc != PR_CAP_NONE) { /* new proxy */ |
Willy Tarreau | 7cbc915 | 2014-03-15 08:17:08 +0100 | [diff] [blame] | 1918 | struct ebpt_node *node; |
| 1919 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1920 | if (!*args[1]) { |
| 1921 | Alert("parsing [%s:%d] : '%s' expects an <id> argument and\n" |
| 1922 | " optionnally supports [addr1]:port1[-end1]{,[addr]:port[-end]}...\n", |
| 1923 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1924 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1925 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1926 | } |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 1927 | |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 1928 | err = invalid_char(args[1]); |
| 1929 | if (err) { |
| 1930 | Alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 1931 | file, linenum, *err, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1932 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 1933 | } |
| 1934 | |
Willy Tarreau | 7cbc915 | 2014-03-15 08:17:08 +0100 | [diff] [blame] | 1935 | for (node = ebis_lookup(&proxy_by_name, args[1]); node; node = ebpt_next(node)) { |
| 1936 | curproxy = container_of(node, struct proxy, conf.by_name); |
| 1937 | |
| 1938 | if (strcmp(curproxy->id, args[1]) != 0) |
| 1939 | break; |
| 1940 | |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 1941 | /* |
| 1942 | * If there are two proxies with the same name only following |
| 1943 | * combinations are allowed: |
| 1944 | * |
| 1945 | * listen backend frontend ruleset |
| 1946 | * listen - - - - |
| 1947 | * backend - - OK - |
| 1948 | * frontend - OK - - |
| 1949 | * ruleset - - - - |
| 1950 | */ |
| 1951 | |
Willy Tarreau | 7cbc915 | 2014-03-15 08:17:08 +0100 | [diff] [blame] | 1952 | if ((rc != (PR_CAP_FE|PR_CAP_RS) || curproxy->cap != (PR_CAP_BE|PR_CAP_RS)) && |
| 1953 | (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] | 1954 | Warning("Parsing [%s:%d]: %s '%s' has same name as another %s (declared at %s:%d).\n", |
| 1955 | file, linenum, proxy_cap_str(rc), args[1], proxy_type_str(curproxy), |
| 1956 | curproxy->conf.file, curproxy->conf.line); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1957 | err_code |= ERR_WARN; |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 1958 | } |
| 1959 | } |
| 1960 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1961 | if ((curproxy = (struct proxy *)calloc(1, sizeof(struct proxy))) == NULL) { |
| 1962 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1963 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1964 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1965 | } |
Willy Tarreau | 5af24ef | 2009-03-15 15:23:16 +0100 | [diff] [blame] | 1966 | |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 1967 | init_new_proxy(curproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1968 | curproxy->next = proxy; |
| 1969 | proxy = curproxy; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 1970 | curproxy->conf.args.file = curproxy->conf.file = strdup(file); |
| 1971 | curproxy->conf.args.line = curproxy->conf.line = linenum; |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 1972 | curproxy->last_change = now.tv_sec; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1973 | curproxy->id = strdup(args[1]); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1974 | curproxy->cap = rc; |
Willy Tarreau | f79d950 | 2014-03-15 07:22:35 +0100 | [diff] [blame] | 1975 | proxy_store_name(curproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1976 | |
| 1977 | /* parse the listener address if any */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1978 | if ((curproxy->cap & PR_CAP_FE) && *args[2]) { |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1979 | struct listener *l; |
Willy Tarreau | 81a8117 | 2012-09-18 20:52:35 +0200 | [diff] [blame] | 1980 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1981 | bind_conf = bind_conf_alloc(&curproxy->conf.bind, file, linenum, args[2]); |
| 1982 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1983 | if (!str2listener(args[2], curproxy, bind_conf, file, linenum, &errmsg)) { |
| 1984 | if (errmsg && *errmsg) { |
| 1985 | indent_msg(&errmsg, 2); |
| 1986 | 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] | 1987 | } |
| 1988 | else |
| 1989 | Alert("parsing [%s:%d] : '%s %s' : error encountered while parsing listening address '%s'.\n", |
| 1990 | file, linenum, args[0], args[1], args[2]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1991 | err_code |= ERR_FATAL; |
| 1992 | goto out; |
| 1993 | } |
Willy Tarreau | 81a8117 | 2012-09-18 20:52:35 +0200 | [diff] [blame] | 1994 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1995 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
Willy Tarreau | c8b1109 | 2011-02-16 11:08:57 +0100 | [diff] [blame] | 1996 | global.maxsock++; |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 1997 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1998 | } |
| 1999 | |
| 2000 | /* set default values */ |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 2001 | memcpy(&curproxy->defsrv, &defproxy.defsrv, sizeof(curproxy->defsrv)); |
Willy Tarreau | 7016020 | 2010-04-07 16:06:40 +0200 | [diff] [blame] | 2002 | curproxy->defsrv.id = "default-server"; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 2003 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2004 | curproxy->state = defproxy.state; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2005 | curproxy->options = defproxy.options; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 2006 | curproxy->options2 = defproxy.options2; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 2007 | curproxy->no_options = defproxy.no_options; |
| 2008 | curproxy->no_options2 = defproxy.no_options2; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2009 | curproxy->bind_proc = defproxy.bind_proc; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 2010 | curproxy->except_net = defproxy.except_net; |
| 2011 | curproxy->except_mask = defproxy.except_mask; |
Maik Broemme | 36db02e | 2009-05-08 17:02:07 +0200 | [diff] [blame] | 2012 | curproxy->except_to = defproxy.except_to; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 2013 | curproxy->except_mask_to = defproxy.except_mask_to; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2014 | |
Willy Tarreau | 79f5fe8 | 2008-08-23 08:18:21 +0200 | [diff] [blame] | 2015 | if (defproxy.fwdfor_hdr_len) { |
| 2016 | curproxy->fwdfor_hdr_len = defproxy.fwdfor_hdr_len; |
| 2017 | curproxy->fwdfor_hdr_name = strdup(defproxy.fwdfor_hdr_name); |
| 2018 | } |
| 2019 | |
Willy Tarreau | b86db34 | 2009-11-30 11:50:16 +0100 | [diff] [blame] | 2020 | if (defproxy.orgto_hdr_len) { |
| 2021 | curproxy->orgto_hdr_len = defproxy.orgto_hdr_len; |
| 2022 | curproxy->orgto_hdr_name = strdup(defproxy.orgto_hdr_name); |
| 2023 | } |
| 2024 | |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 2025 | if (defproxy.server_id_hdr_len) { |
| 2026 | curproxy->server_id_hdr_len = defproxy.server_id_hdr_len; |
| 2027 | curproxy->server_id_hdr_name = strdup(defproxy.server_id_hdr_name); |
| 2028 | } |
| 2029 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2030 | if (curproxy->cap & PR_CAP_FE) { |
| 2031 | curproxy->maxconn = defproxy.maxconn; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 2032 | curproxy->backlog = defproxy.backlog; |
Willy Tarreau | 13a34bd | 2009-05-10 18:52:49 +0200 | [diff] [blame] | 2033 | curproxy->fe_sps_lim = defproxy.fe_sps_lim; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2034 | |
| 2035 | /* initialize error relocations */ |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2036 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) |
| 2037 | chunk_dup(&curproxy->errmsg[rc], &defproxy.errmsg[rc]); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2038 | |
| 2039 | curproxy->to_log = defproxy.to_log & ~LW_COOKIE & ~LW_REQHDR & ~ LW_RSPHDR; |
| 2040 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2041 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2042 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | 743c128 | 2014-11-18 15:04:29 +0100 | [diff] [blame] | 2043 | curproxy->lbprm.algo = defproxy.lbprm.algo; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2044 | curproxy->fullconn = defproxy.fullconn; |
| 2045 | curproxy->conn_retries = defproxy.conn_retries; |
Willy Tarreau | c35362a | 2014-04-25 13:58:37 +0200 | [diff] [blame] | 2046 | curproxy->max_ka_queue = defproxy.max_ka_queue; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2047 | |
Willy Tarreau | aa2f389 | 2010-10-22 16:15:31 +0200 | [diff] [blame] | 2048 | if (defproxy.check_req) { |
| 2049 | curproxy->check_req = calloc(1, defproxy.check_len); |
| 2050 | memcpy(curproxy->check_req, defproxy.check_req, defproxy.check_len); |
| 2051 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2052 | curproxy->check_len = defproxy.check_len; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2053 | |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 2054 | if (defproxy.expect_str) { |
| 2055 | curproxy->expect_str = strdup(defproxy.expect_str); |
| 2056 | if (defproxy.expect_regex) { |
| 2057 | /* note: this regex is known to be valid */ |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 2058 | curproxy->expect_regex = calloc(1, sizeof(*curproxy->expect_regex)); |
| 2059 | regex_comp(defproxy.expect_str, curproxy->expect_regex, 1, 1, NULL); |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 2060 | } |
| 2061 | } |
| 2062 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2063 | curproxy->ck_opts = defproxy.ck_opts; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2064 | if (defproxy.cookie_name) |
| 2065 | curproxy->cookie_name = strdup(defproxy.cookie_name); |
| 2066 | curproxy->cookie_len = defproxy.cookie_len; |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 2067 | if (defproxy.cookie_domain) |
| 2068 | curproxy->cookie_domain = strdup(defproxy.cookie_domain); |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 2069 | |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 2070 | if (defproxy.cookie_maxidle) |
| 2071 | curproxy->cookie_maxidle = defproxy.cookie_maxidle; |
| 2072 | |
| 2073 | if (defproxy.cookie_maxlife) |
| 2074 | curproxy->cookie_maxlife = defproxy.cookie_maxlife; |
| 2075 | |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2076 | if (defproxy.rdp_cookie_name) |
| 2077 | curproxy->rdp_cookie_name = strdup(defproxy.rdp_cookie_name); |
| 2078 | curproxy->rdp_cookie_len = defproxy.rdp_cookie_len; |
| 2079 | |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 2080 | if (defproxy.url_param_name) |
| 2081 | curproxy->url_param_name = strdup(defproxy.url_param_name); |
| 2082 | curproxy->url_param_len = defproxy.url_param_len; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 2083 | |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 2084 | if (defproxy.hh_name) |
| 2085 | curproxy->hh_name = strdup(defproxy.hh_name); |
| 2086 | curproxy->hh_len = defproxy.hh_len; |
| 2087 | curproxy->hh_match_domain = defproxy.hh_match_domain; |
| 2088 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 2089 | if (defproxy.conn_src.iface_name) |
| 2090 | curproxy->conn_src.iface_name = strdup(defproxy.conn_src.iface_name); |
| 2091 | curproxy->conn_src.iface_len = defproxy.conn_src.iface_len; |
Godbach | 9f04853 | 2013-04-23 15:27:57 +0800 | [diff] [blame] | 2092 | curproxy->conn_src.opts = defproxy.conn_src.opts; |
Pieter Baauw | d551fb5 | 2013-05-08 22:49:23 +0200 | [diff] [blame] | 2093 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_TRANSPARENT) |
Godbach | 9f04853 | 2013-04-23 15:27:57 +0800 | [diff] [blame] | 2094 | curproxy->conn_src.tproxy_addr = defproxy.conn_src.tproxy_addr; |
Willy Tarreau | c621d36 | 2013-04-25 17:35:22 +0200 | [diff] [blame] | 2095 | #endif |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2096 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2097 | |
Willy Tarreau | 3b6b1a9 | 2009-07-23 13:24:23 +0200 | [diff] [blame] | 2098 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2099 | if (defproxy.capture_name) |
| 2100 | curproxy->capture_name = strdup(defproxy.capture_name); |
| 2101 | curproxy->capture_namelen = defproxy.capture_namelen; |
| 2102 | curproxy->capture_len = defproxy.capture_len; |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 2103 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2104 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2105 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 2106 | curproxy->timeout.client = defproxy.timeout.client; |
Simone Gotti | 1b48cc9 | 2014-06-11 12:25:28 +0200 | [diff] [blame] | 2107 | curproxy->timeout.clientfin = defproxy.timeout.clientfin; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 2108 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | 036fae0 | 2008-01-06 13:24:40 +0100 | [diff] [blame] | 2109 | curproxy->timeout.httpreq = defproxy.timeout.httpreq; |
Willy Tarreau | b16a574 | 2010-01-10 14:46:16 +0100 | [diff] [blame] | 2110 | curproxy->timeout.httpka = defproxy.timeout.httpka; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2111 | curproxy->mon_net = defproxy.mon_net; |
| 2112 | curproxy->mon_mask = defproxy.mon_mask; |
| 2113 | if (defproxy.monitor_uri) |
| 2114 | curproxy->monitor_uri = strdup(defproxy.monitor_uri); |
| 2115 | curproxy->monitor_uri_len = defproxy.monitor_uri_len; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 2116 | if (defproxy.defbe.name) |
| 2117 | curproxy->defbe.name = strdup(defproxy.defbe.name); |
Willy Tarreau | 99a7ca2 | 2012-05-31 19:39:23 +0200 | [diff] [blame] | 2118 | |
| 2119 | /* 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] | 2120 | curproxy->conf.logformat_string = defproxy.conf.logformat_string; |
| 2121 | if (curproxy->conf.logformat_string && |
| 2122 | curproxy->conf.logformat_string != default_http_log_format && |
| 2123 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 2124 | curproxy->conf.logformat_string != clf_http_log_format) |
| 2125 | curproxy->conf.logformat_string = strdup(curproxy->conf.logformat_string); |
| 2126 | |
| 2127 | if (defproxy.conf.lfs_file) { |
| 2128 | curproxy->conf.lfs_file = strdup(defproxy.conf.lfs_file); |
| 2129 | curproxy->conf.lfs_line = defproxy.conf.lfs_line; |
| 2130 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2131 | } |
| 2132 | |
| 2133 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 2134 | curproxy->timeout.connect = defproxy.timeout.connect; |
| 2135 | curproxy->timeout.server = defproxy.timeout.server; |
Simone Gotti | 1b48cc9 | 2014-06-11 12:25:28 +0200 | [diff] [blame] | 2136 | curproxy->timeout.serverfin = defproxy.timeout.serverfin; |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 2137 | curproxy->timeout.check = defproxy.timeout.check; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 2138 | curproxy->timeout.queue = defproxy.timeout.queue; |
Willy Tarreau | 51c9bde | 2008-01-06 13:40:03 +0100 | [diff] [blame] | 2139 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | cd7afc0 | 2009-07-12 10:03:17 +0200 | [diff] [blame] | 2140 | curproxy->timeout.httpreq = defproxy.timeout.httpreq; |
Willy Tarreau | b16a574 | 2010-01-10 14:46:16 +0100 | [diff] [blame] | 2141 | curproxy->timeout.httpka = defproxy.timeout.httpka; |
Willy Tarreau | ce887fd | 2012-05-12 12:50:00 +0200 | [diff] [blame] | 2142 | curproxy->timeout.tunnel = defproxy.timeout.tunnel; |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 2143 | curproxy->conn_src.source_addr = defproxy.conn_src.source_addr; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2144 | } |
| 2145 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2146 | curproxy->mode = defproxy.mode; |
Willy Tarreau | ed2119c | 2014-04-24 22:10:39 +0200 | [diff] [blame] | 2147 | curproxy->uri_auth = defproxy.uri_auth; /* for stats */ |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 2148 | |
| 2149 | /* copy default logsrvs to curproxy */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 2150 | list_for_each_entry(tmplogsrv, &defproxy.logsrvs, list) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 2151 | struct logsrv *node = malloc(sizeof(struct logsrv)); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 2152 | memcpy(node, tmplogsrv, sizeof(struct logsrv)); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 2153 | LIST_INIT(&node->list); |
| 2154 | LIST_ADDQ(&curproxy->logsrvs, &node->list); |
| 2155 | } |
| 2156 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 2157 | curproxy->conf.uniqueid_format_string = defproxy.conf.uniqueid_format_string; |
| 2158 | if (curproxy->conf.uniqueid_format_string) |
| 2159 | curproxy->conf.uniqueid_format_string = strdup(curproxy->conf.uniqueid_format_string); |
| 2160 | |
| 2161 | if (defproxy.conf.uif_file) { |
| 2162 | curproxy->conf.uif_file = strdup(defproxy.conf.uif_file); |
| 2163 | curproxy->conf.uif_line = defproxy.conf.uif_line; |
| 2164 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 2165 | |
| 2166 | /* copy default header unique id */ |
| 2167 | if (defproxy.header_unique_id) |
| 2168 | curproxy->header_unique_id = strdup(defproxy.header_unique_id); |
| 2169 | |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 2170 | /* default compression options */ |
| 2171 | if (defproxy.comp != NULL) { |
| 2172 | curproxy->comp = calloc(1, sizeof(struct comp)); |
| 2173 | curproxy->comp->algos = defproxy.comp->algos; |
| 2174 | curproxy->comp->types = defproxy.comp->types; |
| 2175 | } |
| 2176 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2177 | curproxy->grace = defproxy.grace; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2178 | curproxy->conf.used_listener_id = EB_ROOT; |
| 2179 | curproxy->conf.used_server_id = EB_ROOT; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2180 | |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 2181 | if (defproxy.check_path) |
| 2182 | curproxy->check_path = strdup(defproxy.check_path); |
| 2183 | if (defproxy.check_command) |
| 2184 | curproxy->check_command = strdup(defproxy.check_command); |
| 2185 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2186 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2187 | } |
| 2188 | else if (!strcmp(args[0], "defaults")) { /* use this one to assign default values */ |
| 2189 | /* some variables may have already been initialized earlier */ |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 2190 | /* FIXME-20070101: we should do this too at the end of the |
| 2191 | * config parsing to free all default values. |
| 2192 | */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2193 | free(defproxy.check_req); |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 2194 | free(defproxy.check_command); |
| 2195 | free(defproxy.check_path); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2196 | free(defproxy.cookie_name); |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2197 | free(defproxy.rdp_cookie_name); |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 2198 | free(defproxy.cookie_domain); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2199 | free(defproxy.url_param_name); |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 2200 | free(defproxy.hh_name); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2201 | free(defproxy.capture_name); |
| 2202 | free(defproxy.monitor_uri); |
| 2203 | free(defproxy.defbe.name); |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 2204 | free(defproxy.conn_src.iface_name); |
Willy Tarreau | 79f5fe8 | 2008-08-23 08:18:21 +0200 | [diff] [blame] | 2205 | free(defproxy.fwdfor_hdr_name); |
| 2206 | defproxy.fwdfor_hdr_len = 0; |
Willy Tarreau | b86db34 | 2009-11-30 11:50:16 +0100 | [diff] [blame] | 2207 | free(defproxy.orgto_hdr_name); |
| 2208 | defproxy.orgto_hdr_len = 0; |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 2209 | free(defproxy.server_id_hdr_name); |
| 2210 | defproxy.server_id_hdr_len = 0; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 2211 | free(defproxy.expect_str); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 2212 | if (defproxy.expect_regex) { |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 2213 | regex_free(defproxy.expect_regex); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 2214 | free(defproxy.expect_regex); |
| 2215 | defproxy.expect_regex = NULL; |
| 2216 | } |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 2217 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 2218 | if (defproxy.conf.logformat_string != default_http_log_format && |
| 2219 | defproxy.conf.logformat_string != default_tcp_log_format && |
| 2220 | defproxy.conf.logformat_string != clf_http_log_format) |
| 2221 | free(defproxy.conf.logformat_string); |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 2222 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 2223 | free(defproxy.conf.uniqueid_format_string); |
| 2224 | free(defproxy.conf.lfs_file); |
| 2225 | free(defproxy.conf.uif_file); |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 2226 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2227 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2228 | chunk_destroy(&defproxy.errmsg[rc]); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 2229 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2230 | /* we cannot free uri_auth because it might already be used */ |
| 2231 | init_default_instance(); |
| 2232 | curproxy = &defproxy; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 2233 | curproxy->conf.args.file = curproxy->conf.file = strdup(file); |
| 2234 | curproxy->conf.args.line = curproxy->conf.line = linenum; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2235 | defproxy.cap = PR_CAP_LISTEN; /* all caps for now */ |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2236 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2237 | } |
| 2238 | else if (curproxy == NULL) { |
| 2239 | Alert("parsing [%s:%d] : 'listen' or 'defaults' expected.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2240 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2241 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2242 | } |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 2243 | |
| 2244 | /* update the current file and line being parsed */ |
| 2245 | curproxy->conf.args.file = curproxy->conf.file; |
| 2246 | curproxy->conf.args.line = linenum; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2247 | |
| 2248 | /* Now let's parse the proxy-specific keywords */ |
Willy Tarreau | 272adea | 2014-03-31 10:39:59 +0200 | [diff] [blame] | 2249 | if (!strcmp(args[0], "server") || !strcmp(args[0], "default-server")) { |
| 2250 | err_code |= parse_server(file, linenum, args, curproxy, &defproxy); |
| 2251 | if (err_code & ERR_FATAL) |
| 2252 | goto out; |
| 2253 | } |
| 2254 | else if (!strcmp(args[0], "bind")) { /* new listen addresses */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2255 | struct listener *l; |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 2256 | int cur_arg; |
| 2257 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2258 | if (curproxy == &defproxy) { |
| 2259 | 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] | 2260 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2261 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2262 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2263 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2264 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2265 | |
Willy Tarreau | 2470928 | 2013-03-10 21:32:12 +0100 | [diff] [blame] | 2266 | if (!*(args[1])) { |
Willy Tarreau | d55c3fe | 2010-11-09 09:50:37 +0100 | [diff] [blame] | 2267 | 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] | 2268 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2269 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2270 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2271 | } |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 2272 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 2273 | bind_conf = bind_conf_alloc(&curproxy->conf.bind, file, linenum, args[1]); |
Willy Tarreau | 8dc21fa | 2013-01-24 15:17:20 +0100 | [diff] [blame] | 2274 | |
| 2275 | /* use default settings for unix sockets */ |
| 2276 | bind_conf->ux.uid = global.unix_bind.ux.uid; |
| 2277 | bind_conf->ux.gid = global.unix_bind.ux.gid; |
| 2278 | bind_conf->ux.mode = global.unix_bind.ux.mode; |
Willy Tarreau | 8a95691 | 2010-10-15 14:27:08 +0200 | [diff] [blame] | 2279 | |
| 2280 | /* NOTE: the following line might create several listeners if there |
| 2281 | * are comma-separated IPs or port ranges. So all further processing |
| 2282 | * will have to be applied to all listeners created after last_listen. |
| 2283 | */ |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 2284 | if (!str2listener(args[1], curproxy, bind_conf, file, linenum, &errmsg)) { |
| 2285 | if (errmsg && *errmsg) { |
| 2286 | indent_msg(&errmsg, 2); |
| 2287 | Alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 2288 | } |
| 2289 | else |
| 2290 | Alert("parsing [%s:%d] : '%s' : error encountered while parsing listening address '%s'.\n", |
| 2291 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2292 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2293 | goto out; |
| 2294 | } |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 2295 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2296 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
| 2297 | /* Set default global rights and owner for unix bind */ |
Willy Tarreau | c8b1109 | 2011-02-16 11:08:57 +0100 | [diff] [blame] | 2298 | global.maxsock++; |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 2299 | } |
| 2300 | |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 2301 | cur_arg = 2; |
| 2302 | while (*(args[cur_arg])) { |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 2303 | static int bind_dumped; |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 2304 | struct bind_kw *kw; |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 2305 | char *err; |
| 2306 | |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 2307 | kw = bind_find_kw(args[cur_arg]); |
| 2308 | if (kw) { |
| 2309 | char *err = NULL; |
| 2310 | int code; |
| 2311 | |
| 2312 | if (!kw->parse) { |
Willy Tarreau | dda322d | 2012-09-18 16:34:09 +0200 | [diff] [blame] | 2313 | Alert("parsing [%s:%d] : '%s %s' : '%s' option is not implemented in this version (check build options).\n", |
| 2314 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 2315 | cur_arg += 1 + kw->skip ; |
| 2316 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2317 | goto out; |
| 2318 | } |
| 2319 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2320 | code = kw->parse(args, cur_arg, curproxy, bind_conf, &err); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 2321 | err_code |= code; |
| 2322 | |
| 2323 | if (code) { |
| 2324 | if (err && *err) { |
| 2325 | indent_msg(&err, 2); |
Willy Tarreau | dda322d | 2012-09-18 16:34:09 +0200 | [diff] [blame] | 2326 | 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] | 2327 | } |
| 2328 | else |
Willy Tarreau | dda322d | 2012-09-18 16:34:09 +0200 | [diff] [blame] | 2329 | Alert("parsing [%s:%d] : '%s %s' : error encountered while processing '%s'.\n", |
| 2330 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 2331 | if (code & ERR_FATAL) { |
| 2332 | free(err); |
| 2333 | cur_arg += 1 + kw->skip; |
| 2334 | goto out; |
| 2335 | } |
| 2336 | } |
| 2337 | free(err); |
| 2338 | cur_arg += 1 + kw->skip; |
| 2339 | continue; |
| 2340 | } |
| 2341 | |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 2342 | err = NULL; |
| 2343 | if (!bind_dumped) { |
| 2344 | bind_dump_kws(&err); |
| 2345 | indent_msg(&err, 4); |
| 2346 | bind_dumped = 1; |
| 2347 | } |
| 2348 | |
| 2349 | Alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'.%s%s\n", |
| 2350 | file, linenum, args[0], args[1], args[cur_arg], |
| 2351 | err ? " Registered keywords :" : "", err ? err : ""); |
| 2352 | free(err); |
| 2353 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2354 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2355 | goto out; |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 2356 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2357 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2358 | } |
| 2359 | 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] | 2360 | 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] | 2361 | Alert("parsing [%s:%d] : '%s' expects address[/mask].\n", |
| 2362 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2363 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2364 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2365 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2366 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2367 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2368 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2369 | /* flush useless bits */ |
| 2370 | curproxy->mon_net.s_addr &= curproxy->mon_mask.s_addr; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2371 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2372 | } |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2373 | else if (!strcmp(args[0], "monitor-uri")) { /* set the URI to intercept */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2374 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2375 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2376 | |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2377 | if (!*args[1]) { |
| 2378 | Alert("parsing [%s:%d] : '%s' expects an URI.\n", |
| 2379 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2380 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2381 | goto out; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2382 | } |
| 2383 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2384 | free(curproxy->monitor_uri); |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 2385 | curproxy->monitor_uri_len = strlen(args[1]); |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2386 | curproxy->monitor_uri = (char *)calloc(1, curproxy->monitor_uri_len + 1); |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 2387 | memcpy(curproxy->monitor_uri, args[1], curproxy->monitor_uri_len); |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2388 | curproxy->monitor_uri[curproxy->monitor_uri_len] = '\0'; |
| 2389 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2390 | goto out; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2391 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2392 | else if (!strcmp(args[0], "mode")) { /* sets the proxy mode */ |
| 2393 | if (!strcmp(args[1], "http")) curproxy->mode = PR_MODE_HTTP; |
| 2394 | else if (!strcmp(args[1], "tcp")) curproxy->mode = PR_MODE_TCP; |
| 2395 | else if (!strcmp(args[1], "health")) curproxy->mode = PR_MODE_HEALTH; |
| 2396 | else { |
| 2397 | 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] | 2398 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2399 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2400 | } |
| 2401 | } |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2402 | else if (!strcmp(args[0], "id")) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2403 | struct eb32_node *node; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2404 | |
| 2405 | if (curproxy == &defproxy) { |
| 2406 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", |
| 2407 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2408 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2409 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2410 | } |
| 2411 | |
| 2412 | if (!*args[1]) { |
| 2413 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 2414 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2415 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2416 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2417 | } |
| 2418 | |
| 2419 | curproxy->uuid = atol(args[1]); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2420 | curproxy->conf.id.key = curproxy->uuid; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2421 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2422 | if (curproxy->uuid <= 0) { |
| 2423 | Alert("parsing [%s:%d]: custom id has to be > 0.\n", |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2424 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2425 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2426 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2427 | } |
| 2428 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2429 | node = eb32_lookup(&used_proxy_id, curproxy->uuid); |
| 2430 | if (node) { |
| 2431 | struct proxy *target = container_of(node, struct proxy, conf.id); |
| 2432 | Alert("parsing [%s:%d]: %s %s reuses same custom id as %s %s (declared at %s:%d).\n", |
| 2433 | file, linenum, proxy_type_str(curproxy), curproxy->id, |
| 2434 | proxy_type_str(target), target->id, target->conf.file, target->conf.line); |
| 2435 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2436 | goto out; |
| 2437 | } |
| 2438 | eb32_insert(&used_proxy_id, &curproxy->conf.id); |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2439 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 2440 | else if (!strcmp(args[0], "description")) { |
| 2441 | int i, len=0; |
| 2442 | char *d; |
| 2443 | |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 2444 | if (curproxy == &defproxy) { |
| 2445 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", |
| 2446 | file, linenum, args[0]); |
| 2447 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2448 | goto out; |
| 2449 | } |
| 2450 | |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 2451 | if (!*args[1]) { |
| 2452 | Alert("parsing [%s:%d]: '%s' expects a string argument.\n", |
| 2453 | file, linenum, args[0]); |
| 2454 | return -1; |
| 2455 | } |
| 2456 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 2457 | for (i = 1; *args[i]; i++) |
| 2458 | len += strlen(args[i]) + 1; |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 2459 | |
| 2460 | d = (char *)calloc(1, len); |
| 2461 | curproxy->desc = d; |
| 2462 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 2463 | d += snprintf(d, curproxy->desc + len - d, "%s", args[1]); |
| 2464 | for (i = 2; *args[i]; i++) |
| 2465 | d += snprintf(d, curproxy->desc + len - d, " %s", args[i]); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 2466 | |
| 2467 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2468 | else if (!strcmp(args[0], "disabled")) { /* disables this proxy */ |
| 2469 | curproxy->state = PR_STSTOPPED; |
| 2470 | } |
| 2471 | else if (!strcmp(args[0], "enabled")) { /* enables this proxy (used to revert a disabled default) */ |
| 2472 | curproxy->state = PR_STNEW; |
| 2473 | } |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2474 | else if (!strcmp(args[0], "bind-process")) { /* enable this proxy only on some processes */ |
| 2475 | int cur_arg = 1; |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 2476 | unsigned long set = 0; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2477 | |
| 2478 | while (*args[cur_arg]) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 2479 | unsigned int low, high; |
| 2480 | |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2481 | if (strcmp(args[cur_arg], "all") == 0) { |
| 2482 | set = 0; |
| 2483 | break; |
| 2484 | } |
| 2485 | else if (strcmp(args[cur_arg], "odd") == 0) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 2486 | set |= ~0UL/3UL; /* 0x555....555 */ |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2487 | } |
| 2488 | else if (strcmp(args[cur_arg], "even") == 0) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 2489 | set |= (~0UL/3UL) << 1; /* 0xAAA...AAA */ |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2490 | } |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 2491 | else if (isdigit((int)*args[cur_arg])) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 2492 | char *dash = strchr(args[cur_arg], '-'); |
| 2493 | |
| 2494 | low = high = str2uic(args[cur_arg]); |
| 2495 | if (dash) |
| 2496 | high = str2uic(dash + 1); |
| 2497 | |
| 2498 | if (high < low) { |
| 2499 | unsigned int swap = low; |
| 2500 | low = high; |
| 2501 | high = swap; |
| 2502 | } |
| 2503 | |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 2504 | if (low < 1 || high > LONGBITS) { |
| 2505 | Alert("parsing [%s:%d]: %s supports process numbers from 1 to %d.\n", |
| 2506 | file, linenum, args[0], LONGBITS); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2507 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2508 | goto out; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2509 | } |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 2510 | while (low <= high) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 2511 | set |= 1UL << (low++ - 1); |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 2512 | } |
| 2513 | else { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 2514 | Alert("parsing [%s:%d]: %s expects 'all', 'odd', 'even', or a list of process ranges with numbers from 1 to %d.\n", |
| 2515 | file, linenum, args[0], LONGBITS); |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 2516 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2517 | goto out; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2518 | } |
| 2519 | cur_arg++; |
| 2520 | } |
| 2521 | curproxy->bind_proc = set; |
| 2522 | } |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 2523 | else if (!strcmp(args[0], "acl")) { /* add an ACL */ |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2524 | if (curproxy == &defproxy) { |
| 2525 | 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] | 2526 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2527 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2528 | } |
| 2529 | |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 2530 | err = invalid_char(args[1]); |
| 2531 | if (err) { |
| 2532 | Alert("parsing [%s:%d] : character '%c' is not permitted in acl name '%s'.\n", |
| 2533 | file, linenum, *err, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2534 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 2535 | } |
| 2536 | |
Thierry FOURNIER | 0d6ba51 | 2014-02-11 03:31:34 +0100 | [diff] [blame] | 2537 | 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] | 2538 | Alert("parsing [%s:%d] : error detected while parsing ACL '%s' : %s.\n", |
| 2539 | file, linenum, args[1], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2540 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2541 | goto out; |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 2542 | } |
| 2543 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2544 | else if (!strcmp(args[0], "cookie")) { /* cookie name */ |
| 2545 | int cur_arg; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2546 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2547 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2548 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2549 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2550 | if (*(args[1]) == 0) { |
| 2551 | Alert("parsing [%s:%d] : '%s' expects <cookie_name> as argument.\n", |
| 2552 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2553 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2554 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2555 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2556 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2557 | curproxy->ck_opts = 0; |
Willy Tarreau | c63d4bb | 2010-10-23 11:37:27 +0200 | [diff] [blame] | 2558 | curproxy->cookie_maxidle = curproxy->cookie_maxlife = 0; |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 2559 | free(curproxy->cookie_domain); curproxy->cookie_domain = NULL; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2560 | free(curproxy->cookie_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2561 | curproxy->cookie_name = strdup(args[1]); |
| 2562 | curproxy->cookie_len = strlen(curproxy->cookie_name); |
Willy Tarreau | c63d4bb | 2010-10-23 11:37:27 +0200 | [diff] [blame] | 2563 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2564 | cur_arg = 2; |
| 2565 | while (*(args[cur_arg])) { |
| 2566 | if (!strcmp(args[cur_arg], "rewrite")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2567 | curproxy->ck_opts |= PR_CK_RW; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2568 | } |
| 2569 | else if (!strcmp(args[cur_arg], "indirect")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2570 | curproxy->ck_opts |= PR_CK_IND; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2571 | } |
| 2572 | else if (!strcmp(args[cur_arg], "insert")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2573 | curproxy->ck_opts |= PR_CK_INS; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2574 | } |
| 2575 | else if (!strcmp(args[cur_arg], "nocache")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2576 | curproxy->ck_opts |= PR_CK_NOC; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2577 | } |
| 2578 | else if (!strcmp(args[cur_arg], "postonly")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2579 | curproxy->ck_opts |= PR_CK_POST; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2580 | } |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 2581 | else if (!strcmp(args[cur_arg], "preserve")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2582 | curproxy->ck_opts |= PR_CK_PSV; |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 2583 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2584 | else if (!strcmp(args[cur_arg], "prefix")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2585 | curproxy->ck_opts |= PR_CK_PFX; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2586 | } |
Willy Tarreau | 4992dd2 | 2012-05-31 21:02:17 +0200 | [diff] [blame] | 2587 | else if (!strcmp(args[cur_arg], "httponly")) { |
| 2588 | curproxy->ck_opts |= PR_CK_HTTPONLY; |
| 2589 | } |
| 2590 | else if (!strcmp(args[cur_arg], "secure")) { |
| 2591 | curproxy->ck_opts |= PR_CK_SECURE; |
| 2592 | } |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2593 | else if (!strcmp(args[cur_arg], "domain")) { |
| 2594 | if (!*args[cur_arg + 1]) { |
| 2595 | Alert("parsing [%s:%d]: '%s' expects <domain> as argument.\n", |
| 2596 | file, linenum, args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2597 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2598 | goto out; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2599 | } |
| 2600 | |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 2601 | if (*args[cur_arg + 1] != '.' || !strchr(args[cur_arg + 1] + 1, '.')) { |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2602 | /* rfc2109, 4.3.2 Rejecting Cookies */ |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 2603 | Warning("parsing [%s:%d]: domain '%s' contains no embedded" |
| 2604 | " dots nor does not start with a dot." |
| 2605 | " RFC forbids it, this configuration may not work properly.\n", |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2606 | file, linenum, args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 2607 | err_code |= ERR_WARN; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2608 | } |
| 2609 | |
| 2610 | err = invalid_domainchar(args[cur_arg + 1]); |
| 2611 | if (err) { |
| 2612 | Alert("parsing [%s:%d]: character '%c' is not permitted in domain name '%s'.\n", |
| 2613 | file, linenum, *err, args[cur_arg + 1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2614 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2615 | goto out; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2616 | } |
| 2617 | |
Willy Tarreau | 68a897b | 2009-12-03 23:28:34 +0100 | [diff] [blame] | 2618 | if (!curproxy->cookie_domain) { |
| 2619 | curproxy->cookie_domain = strdup(args[cur_arg + 1]); |
| 2620 | } else { |
| 2621 | /* one domain was already specified, add another one by |
| 2622 | * building the string which will be returned along with |
| 2623 | * the cookie. |
| 2624 | */ |
| 2625 | char *new_ptr; |
| 2626 | int new_len = strlen(curproxy->cookie_domain) + |
| 2627 | strlen("; domain=") + strlen(args[cur_arg + 1]) + 1; |
| 2628 | new_ptr = malloc(new_len); |
| 2629 | snprintf(new_ptr, new_len, "%s; domain=%s", curproxy->cookie_domain, args[cur_arg+1]); |
| 2630 | free(curproxy->cookie_domain); |
| 2631 | curproxy->cookie_domain = new_ptr; |
| 2632 | } |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 2633 | cur_arg++; |
| 2634 | } |
| 2635 | else if (!strcmp(args[cur_arg], "maxidle")) { |
| 2636 | unsigned int maxidle; |
| 2637 | const char *res; |
| 2638 | |
| 2639 | if (!*args[cur_arg + 1]) { |
| 2640 | Alert("parsing [%s:%d]: '%s' expects <idletime> in seconds as argument.\n", |
| 2641 | file, linenum, args[cur_arg]); |
| 2642 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2643 | goto out; |
| 2644 | } |
| 2645 | |
| 2646 | res = parse_time_err(args[cur_arg + 1], &maxidle, TIME_UNIT_S); |
| 2647 | if (res) { |
| 2648 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 2649 | file, linenum, *res, args[cur_arg]); |
| 2650 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2651 | goto out; |
| 2652 | } |
| 2653 | curproxy->cookie_maxidle = maxidle; |
| 2654 | cur_arg++; |
| 2655 | } |
| 2656 | else if (!strcmp(args[cur_arg], "maxlife")) { |
| 2657 | unsigned int maxlife; |
| 2658 | const char *res; |
| 2659 | |
| 2660 | if (!*args[cur_arg + 1]) { |
| 2661 | Alert("parsing [%s:%d]: '%s' expects <lifetime> in seconds as argument.\n", |
| 2662 | file, linenum, args[cur_arg]); |
| 2663 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2664 | goto out; |
| 2665 | } |
| 2666 | |
| 2667 | res = parse_time_err(args[cur_arg + 1], &maxlife, TIME_UNIT_S); |
| 2668 | if (res) { |
| 2669 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 2670 | file, linenum, *res, args[cur_arg]); |
| 2671 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2672 | goto out; |
| 2673 | } |
| 2674 | curproxy->cookie_maxlife = maxlife; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2675 | cur_arg++; |
| 2676 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2677 | else { |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 2678 | 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] | 2679 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2680 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2681 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2682 | } |
| 2683 | cur_arg++; |
| 2684 | } |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2685 | if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_IND))) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2686 | Alert("parsing [%s:%d] : cookie 'rewrite' and 'indirect' modes are incompatible.\n", |
| 2687 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2688 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2689 | } |
| 2690 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2691 | 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] | 2692 | Alert("parsing [%s:%d] : cookie 'rewrite', 'insert' and 'prefix' modes are incompatible.\n", |
| 2693 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2694 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2695 | } |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 2696 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2697 | 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] | 2698 | Alert("parsing [%s:%d] : cookie 'preserve' requires at least 'insert' or 'indirect'.\n", |
| 2699 | file, linenum); |
| 2700 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2701 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2702 | }/* end else if (!strcmp(args[0], "cookie")) */ |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 2703 | else if (!strcmp(args[0], "external-check")) { |
| 2704 | if (*(args[1]) == 0) { |
| 2705 | Alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 2706 | file, linenum, args[0]); |
| 2707 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2708 | goto out; |
| 2709 | } |
| 2710 | |
| 2711 | if (!strcmp(args[1], "command")) { |
| 2712 | if (*(args[1]) == 0) { |
| 2713 | Alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 2714 | file, linenum, args[1]); |
| 2715 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2716 | goto out; |
| 2717 | } |
| 2718 | free(curproxy->check_command); |
| 2719 | curproxy->check_command = strdup(args[2]); |
| 2720 | } |
| 2721 | else if (!strcmp(args[1], "path")) { |
| 2722 | if (*(args[1]) == 0) { |
| 2723 | Alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 2724 | file, linenum, args[1]); |
| 2725 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2726 | goto out; |
| 2727 | } |
| 2728 | free(curproxy->check_path); |
| 2729 | curproxy->check_path = strdup(args[2]); |
| 2730 | } |
| 2731 | else { |
| 2732 | Alert("parsing [%s:%d] : external-check: unknown argument '%s'.\n", |
| 2733 | file, linenum, args[1]); |
| 2734 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2735 | goto out; |
| 2736 | } |
| 2737 | }/* end else if (!strcmp(args[0], "external-check")) */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2738 | else if (!strcmp(args[0], "persist")) { /* persist */ |
| 2739 | if (*(args[1]) == 0) { |
| 2740 | Alert("parsing [%s:%d] : missing persist method.\n", |
| 2741 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2742 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2743 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2744 | } |
| 2745 | |
| 2746 | if (!strncmp(args[1], "rdp-cookie", 10)) { |
| 2747 | curproxy->options2 |= PR_O2_RDPC_PRST; |
| 2748 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2749 | if (*(args[1] + 10) == '(') { /* cookie name */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2750 | const char *beg, *end; |
| 2751 | |
| 2752 | beg = args[1] + 11; |
| 2753 | end = strchr(beg, ')'); |
| 2754 | |
| 2755 | if (!end || end == beg) { |
| 2756 | Alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n", |
| 2757 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2758 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2759 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2760 | } |
| 2761 | |
| 2762 | free(curproxy->rdp_cookie_name); |
| 2763 | curproxy->rdp_cookie_name = my_strndup(beg, end - beg); |
| 2764 | curproxy->rdp_cookie_len = end-beg; |
| 2765 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2766 | else if (*(args[1] + 10) == '\0') { /* default cookie name 'msts' */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2767 | free(curproxy->rdp_cookie_name); |
| 2768 | curproxy->rdp_cookie_name = strdup("msts"); |
| 2769 | curproxy->rdp_cookie_len = strlen(curproxy->rdp_cookie_name); |
| 2770 | } |
| 2771 | else { /* syntax */ |
| 2772 | Alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n", |
| 2773 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2774 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2775 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2776 | } |
| 2777 | } |
| 2778 | else { |
| 2779 | Alert("parsing [%s:%d] : unknown persist method.\n", |
| 2780 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2781 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2782 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2783 | } |
| 2784 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2785 | else if (!strcmp(args[0], "appsession")) { /* cookie name */ |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2786 | int cur_arg; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2787 | |
Cyril Bonté | 3b7a369 | 2010-01-10 17:01:47 +0100 | [diff] [blame] | 2788 | if (curproxy == &defproxy) { |
| 2789 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2790 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2791 | goto out; |
| 2792 | } |
| 2793 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2794 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2795 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2796 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2797 | if (*(args[5]) == 0) { |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2798 | 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] | 2799 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2800 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2801 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2802 | } |
| 2803 | have_appsession = 1; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2804 | free(curproxy->appsession_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2805 | curproxy->appsession_name = strdup(args[1]); |
| 2806 | curproxy->appsession_name_len = strlen(curproxy->appsession_name); |
| 2807 | curproxy->appsession_len = atoi(args[3]); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 2808 | err = parse_time_err(args[5], &val, TIME_UNIT_MS); |
| 2809 | if (err) { |
| 2810 | Alert("parsing [%s:%d] : unexpected character '%c' in %s timeout.\n", |
| 2811 | file, linenum, *err, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2812 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2813 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 2814 | } |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 2815 | curproxy->timeout.appsession = val; |
Willy Tarreau | ee99136 | 2007-05-14 14:37:50 +0200 | [diff] [blame] | 2816 | |
Willy Tarreau | 51041c7 | 2007-09-09 21:56:53 +0200 | [diff] [blame] | 2817 | if (appsession_hash_init(&(curproxy->htbl_proxy), destroy) == 0) { |
| 2818 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2819 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2820 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2821 | } |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2822 | |
| 2823 | cur_arg = 6; |
| 2824 | curproxy->options2 &= ~PR_O2_AS_REQL; |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2825 | curproxy->options2 &= ~PR_O2_AS_M_ANY; |
| 2826 | curproxy->options2 |= PR_O2_AS_M_PP; |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2827 | while (*(args[cur_arg])) { |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2828 | if (!strcmp(args[cur_arg], "request-learn")) { |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2829 | curproxy->options2 |= PR_O2_AS_REQL; |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2830 | } else if (!strcmp(args[cur_arg], "prefix")) { |
| 2831 | curproxy->options2 |= PR_O2_AS_PFX; |
| 2832 | } else if (!strcmp(args[cur_arg], "mode")) { |
| 2833 | if (!*args[cur_arg + 1]) { |
| 2834 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 2835 | file, linenum, args[0], args[cur_arg]); |
| 2836 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2837 | goto out; |
| 2838 | } |
| 2839 | |
| 2840 | cur_arg++; |
| 2841 | if (!strcmp(args[cur_arg], "query-string")) { |
| 2842 | curproxy->options2 &= ~PR_O2_AS_M_ANY; |
| 2843 | curproxy->options2 |= PR_O2_AS_M_QS; |
| 2844 | } else if (!strcmp(args[cur_arg], "path-parameters")) { |
| 2845 | curproxy->options2 &= ~PR_O2_AS_M_ANY; |
| 2846 | curproxy->options2 |= PR_O2_AS_M_PP; |
| 2847 | } else { |
| 2848 | Alert("parsing [%s:%d] : unknown mode '%s'\n", file, linenum, args[cur_arg]); |
| 2849 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2850 | goto out; |
| 2851 | } |
| 2852 | } |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2853 | cur_arg++; |
| 2854 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2855 | } /* Url App Session */ |
| 2856 | else if (!strcmp(args[0], "capture")) { |
Willy Tarreau | 3b6b1a9 | 2009-07-23 13:24:23 +0200 | [diff] [blame] | 2857 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2858 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2859 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2860 | if (!strcmp(args[1], "cookie")) { /* name of a cookie to capture */ |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 2861 | if (curproxy == &defproxy) { |
| 2862 | Alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
| 2863 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2864 | goto out; |
| 2865 | } |
| 2866 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2867 | if (*(args[4]) == 0) { |
| 2868 | Alert("parsing [%s:%d] : '%s' expects 'cookie' <cookie_name> 'len' <len>.\n", |
| 2869 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2870 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2871 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2872 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2873 | free(curproxy->capture_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2874 | curproxy->capture_name = strdup(args[2]); |
| 2875 | curproxy->capture_namelen = strlen(curproxy->capture_name); |
| 2876 | curproxy->capture_len = atol(args[4]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2877 | curproxy->to_log |= LW_COOKIE; |
| 2878 | } |
| 2879 | else if (!strcmp(args[1], "request") && !strcmp(args[2], "header")) { |
| 2880 | struct cap_hdr *hdr; |
| 2881 | |
| 2882 | if (curproxy == &defproxy) { |
| 2883 | 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] | 2884 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2885 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2886 | } |
| 2887 | |
| 2888 | if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) { |
| 2889 | Alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n", |
| 2890 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2891 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2892 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2893 | } |
| 2894 | |
| 2895 | hdr = calloc(sizeof(struct cap_hdr), 1); |
| 2896 | hdr->next = curproxy->req_cap; |
| 2897 | hdr->name = strdup(args[3]); |
| 2898 | hdr->namelen = strlen(args[3]); |
| 2899 | hdr->len = atol(args[5]); |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 2900 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2901 | hdr->index = curproxy->nb_req_cap++; |
| 2902 | curproxy->req_cap = hdr; |
| 2903 | curproxy->to_log |= LW_REQHDR; |
| 2904 | } |
| 2905 | else if (!strcmp(args[1], "response") && !strcmp(args[2], "header")) { |
| 2906 | struct cap_hdr *hdr; |
| 2907 | |
| 2908 | if (curproxy == &defproxy) { |
| 2909 | 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] | 2910 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2911 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2912 | } |
| 2913 | |
| 2914 | if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) { |
| 2915 | Alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n", |
| 2916 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2917 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2918 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2919 | } |
| 2920 | hdr = calloc(sizeof(struct cap_hdr), 1); |
| 2921 | hdr->next = curproxy->rsp_cap; |
| 2922 | hdr->name = strdup(args[3]); |
| 2923 | hdr->namelen = strlen(args[3]); |
| 2924 | hdr->len = atol(args[5]); |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 2925 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2926 | hdr->index = curproxy->nb_rsp_cap++; |
| 2927 | curproxy->rsp_cap = hdr; |
| 2928 | curproxy->to_log |= LW_RSPHDR; |
| 2929 | } |
| 2930 | else { |
| 2931 | Alert("parsing [%s:%d] : '%s' expects 'cookie' or 'request header' or 'response header'.\n", |
| 2932 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2933 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2934 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2935 | } |
| 2936 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2937 | else if (!strcmp(args[0], "retries")) { /* connection retries */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2938 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2939 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2940 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2941 | if (*(args[1]) == 0) { |
| 2942 | Alert("parsing [%s:%d] : '%s' expects an integer argument (dispatch counts for one).\n", |
| 2943 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2944 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2945 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2946 | } |
| 2947 | curproxy->conn_retries = atol(args[1]); |
| 2948 | } |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2949 | 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] | 2950 | struct http_req_rule *rule; |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2951 | |
| 2952 | if (curproxy == &defproxy) { |
| 2953 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2954 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2955 | goto out; |
| 2956 | } |
| 2957 | |
Willy Tarreau | 20b0de5 | 2012-12-24 15:45:22 +0100 | [diff] [blame] | 2958 | if (!LIST_ISEMPTY(&curproxy->http_req_rules) && |
| 2959 | !LIST_PREV(&curproxy->http_req_rules, struct http_req_rule *, list)->cond && |
| 2960 | (LIST_PREV(&curproxy->http_req_rules, struct http_req_rule *, list)->action == HTTP_REQ_ACT_ALLOW || |
| 2961 | 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] | 2962 | 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] | 2963 | LIST_PREV(&curproxy->http_req_rules, struct http_req_rule *, list)->action == HTTP_REQ_ACT_AUTH)) { |
| 2964 | 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] | 2965 | file, linenum, args[0]); |
| 2966 | err_code |= ERR_WARN; |
| 2967 | } |
| 2968 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 2969 | 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] | 2970 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 2971 | if (!rule) { |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2972 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2973 | goto out; |
| 2974 | } |
| 2975 | |
Willy Tarreau | 5002f57 | 2014-04-23 01:32:02 +0200 | [diff] [blame] | 2976 | err_code |= warnif_misplaced_http_req(curproxy, file, linenum, args[0]); |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 2977 | err_code |= warnif_cond_conflicts(rule->cond, |
| 2978 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 2979 | file, linenum); |
| 2980 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 2981 | LIST_ADDQ(&curproxy->http_req_rules, &rule->list); |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2982 | } |
Willy Tarreau | e365c0b | 2013-06-11 16:06:12 +0200 | [diff] [blame] | 2983 | else if (!strcmp(args[0], "http-response")) { /* response access control */ |
| 2984 | struct http_res_rule *rule; |
| 2985 | |
| 2986 | if (curproxy == &defproxy) { |
| 2987 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2988 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2989 | goto out; |
| 2990 | } |
| 2991 | |
| 2992 | if (!LIST_ISEMPTY(&curproxy->http_res_rules) && |
| 2993 | !LIST_PREV(&curproxy->http_res_rules, struct http_res_rule *, list)->cond && |
| 2994 | (LIST_PREV(&curproxy->http_res_rules, struct http_res_rule *, list)->action == HTTP_RES_ACT_ALLOW || |
| 2995 | LIST_PREV(&curproxy->http_res_rules, struct http_res_rule *, list)->action == HTTP_RES_ACT_DENY)) { |
| 2996 | Warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n", |
| 2997 | file, linenum, args[0]); |
| 2998 | err_code |= ERR_WARN; |
| 2999 | } |
| 3000 | |
| 3001 | rule = parse_http_res_cond((const char **)args + 1, file, linenum, curproxy); |
| 3002 | |
| 3003 | if (!rule) { |
| 3004 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3005 | goto out; |
| 3006 | } |
| 3007 | |
| 3008 | err_code |= warnif_cond_conflicts(rule->cond, |
| 3009 | (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR, |
| 3010 | file, linenum); |
| 3011 | |
| 3012 | LIST_ADDQ(&curproxy->http_res_rules, &rule->list); |
| 3013 | } |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 3014 | else if (!strcmp(args[0], "http-send-name-header")) { /* send server name in request header */ |
| 3015 | /* set the header name and length into the proxy structure */ |
| 3016 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 3017 | err_code |= ERR_WARN; |
| 3018 | |
| 3019 | if (!*args[1]) { |
| 3020 | Alert("parsing [%s:%d] : '%s' requires a header string.\n", |
| 3021 | file, linenum, args[0]); |
| 3022 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3023 | goto out; |
| 3024 | } |
| 3025 | |
| 3026 | /* set the desired header name */ |
| 3027 | free(curproxy->server_id_hdr_name); |
| 3028 | curproxy->server_id_hdr_name = strdup(args[1]); |
| 3029 | curproxy->server_id_hdr_len = strlen(curproxy->server_id_hdr_name); |
| 3030 | } |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 3031 | else if (!strcmp(args[0], "block")) { /* early blocking based on ACLs */ |
Willy Tarreau | b3dc39d | 2014-04-28 22:06:57 +0200 | [diff] [blame] | 3032 | struct http_req_rule *rule; |
| 3033 | |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3034 | if (curproxy == &defproxy) { |
| 3035 | 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] | 3036 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3037 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3038 | } |
| 3039 | |
Willy Tarreau | b3dc39d | 2014-04-28 22:06:57 +0200 | [diff] [blame] | 3040 | /* emulate "block" using "http-request block". Since these rules are supposed to |
| 3041 | * be processed before all http-request rules, we put them into their own list |
| 3042 | * and will insert them at the end. |
| 3043 | */ |
| 3044 | rule = parse_http_req_cond((const char **)args, file, linenum, curproxy); |
| 3045 | if (!rule) { |
| 3046 | err_code |= ERR_ALERT | ERR_ABORT; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3047 | goto out; |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 3048 | } |
Willy Tarreau | b3dc39d | 2014-04-28 22:06:57 +0200 | [diff] [blame] | 3049 | err_code |= warnif_misplaced_block(curproxy, file, linenum, args[0]); |
| 3050 | err_code |= warnif_cond_conflicts(rule->cond, |
| 3051 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 3052 | file, linenum); |
| 3053 | LIST_ADDQ(&curproxy->block_rules, &rule->list); |
Willy Tarreau | de9d2d7 | 2014-04-28 22:28:02 +0200 | [diff] [blame] | 3054 | |
| 3055 | if (!already_warned(WARN_BLOCK_DEPRECATED)) |
| 3056 | 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]); |
| 3057 | |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 3058 | } |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3059 | else if (!strcmp(args[0], "redirect")) { |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3060 | struct redirect_rule *rule; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3061 | |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 3062 | if (curproxy == &defproxy) { |
| 3063 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3064 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3065 | goto out; |
| 3066 | } |
| 3067 | |
Thierry FOURNIER | d18cd0f | 2013-11-29 12:15:45 +0100 | [diff] [blame] | 3068 | 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] | 3069 | Alert("parsing [%s:%d] : error detected in %s '%s' while parsing redirect rule : %s.\n", |
| 3070 | file, linenum, proxy_type_str(curproxy), curproxy->id, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3071 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3072 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3073 | } |
| 3074 | |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3075 | LIST_ADDQ(&curproxy->redirect_rules, &rule->list); |
Willy Tarreau | ee445d9 | 2014-04-23 01:39:04 +0200 | [diff] [blame] | 3076 | err_code |= warnif_misplaced_redirect(curproxy, file, linenum, args[0]); |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3077 | err_code |= warnif_cond_conflicts(rule->cond, |
| 3078 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 3079 | file, linenum); |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3080 | } |
Krzysztof Piotr Oledzki | 7b723ef | 2009-01-27 21:09:41 +0100 | [diff] [blame] | 3081 | else if (!strcmp(args[0], "use_backend")) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3082 | struct switching_rule *rule; |
| 3083 | |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3084 | if (curproxy == &defproxy) { |
| 3085 | 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] | 3086 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3087 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3088 | } |
| 3089 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3090 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3091 | err_code |= ERR_WARN; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3092 | |
| 3093 | if (*(args[1]) == 0) { |
| 3094 | 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] | 3095 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3096 | goto out; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3097 | } |
| 3098 | |
Willy Tarreau | f51658d | 2014-04-23 01:21:56 +0200 | [diff] [blame] | 3099 | if (strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0) { |
| 3100 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 3101 | Alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n", |
| 3102 | file, linenum, errmsg); |
| 3103 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3104 | goto out; |
| 3105 | } |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3106 | |
Willy Tarreau | f51658d | 2014-04-23 01:21:56 +0200 | [diff] [blame] | 3107 | 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] | 3108 | } |
| 3109 | |
| 3110 | rule = (struct switching_rule *)calloc(1, sizeof(*rule)); |
| 3111 | rule->cond = cond; |
| 3112 | rule->be.name = strdup(args[1]); |
| 3113 | LIST_INIT(&rule->list); |
| 3114 | LIST_ADDQ(&curproxy->switching_rules, &rule->list); |
| 3115 | } |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 3116 | else if (strcmp(args[0], "use-server") == 0) { |
| 3117 | struct server_rule *rule; |
| 3118 | |
| 3119 | if (curproxy == &defproxy) { |
| 3120 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3121 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3122 | goto out; |
| 3123 | } |
| 3124 | |
| 3125 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 3126 | err_code |= ERR_WARN; |
| 3127 | |
| 3128 | if (*(args[1]) == 0) { |
| 3129 | Alert("parsing [%s:%d] : '%s' expects a server name.\n", file, linenum, args[0]); |
| 3130 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3131 | goto out; |
| 3132 | } |
| 3133 | |
| 3134 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
| 3135 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 3136 | file, linenum, args[0]); |
| 3137 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3138 | goto out; |
| 3139 | } |
| 3140 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 3141 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 3142 | Alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n", |
| 3143 | file, linenum, errmsg); |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 3144 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3145 | goto out; |
| 3146 | } |
| 3147 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3148 | 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] | 3149 | |
| 3150 | rule = (struct server_rule *)calloc(1, sizeof(*rule)); |
| 3151 | rule->cond = cond; |
| 3152 | rule->srv.name = strdup(args[1]); |
| 3153 | LIST_INIT(&rule->list); |
| 3154 | LIST_ADDQ(&curproxy->server_rules, &rule->list); |
| 3155 | curproxy->be_req_ana |= AN_REQ_SRV_RULES; |
| 3156 | } |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 3157 | else if ((!strcmp(args[0], "force-persist")) || |
| 3158 | (!strcmp(args[0], "ignore-persist"))) { |
| 3159 | struct persist_rule *rule; |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 3160 | |
| 3161 | if (curproxy == &defproxy) { |
| 3162 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3163 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3164 | goto out; |
| 3165 | } |
| 3166 | |
| 3167 | if (warnifnotcap(curproxy, PR_CAP_FE|PR_CAP_BE, file, linenum, args[0], NULL)) |
| 3168 | err_code |= ERR_WARN; |
| 3169 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 3170 | if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) { |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 3171 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 3172 | file, linenum, args[0]); |
| 3173 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3174 | goto out; |
| 3175 | } |
| 3176 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 3177 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 1, &errmsg)) == NULL) { |
| 3178 | Alert("parsing [%s:%d] : error detected while parsing a '%s' rule : %s.\n", |
| 3179 | file, linenum, args[0], errmsg); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 3180 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3181 | goto out; |
| 3182 | } |
| 3183 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3184 | /* note: BE_REQ_CNT is the first one after FE_SET_BCK, which is |
| 3185 | * where force-persist is applied. |
| 3186 | */ |
| 3187 | 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] | 3188 | |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 3189 | rule = (struct persist_rule *)calloc(1, sizeof(*rule)); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 3190 | rule->cond = cond; |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 3191 | if (!strcmp(args[0], "force-persist")) { |
| 3192 | rule->type = PERSIST_TYPE_FORCE; |
| 3193 | } else { |
| 3194 | rule->type = PERSIST_TYPE_IGNORE; |
| 3195 | } |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 3196 | LIST_INIT(&rule->list); |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 3197 | LIST_ADDQ(&curproxy->persist_rules, &rule->list); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 3198 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3199 | else if (!strcmp(args[0], "stick-table")) { |
| 3200 | int myidx = 1; |
| 3201 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 3202 | curproxy->table.id = curproxy->id; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3203 | curproxy->table.type = (unsigned int)-1; |
| 3204 | while (*args[myidx]) { |
| 3205 | const char *err; |
| 3206 | |
| 3207 | if (strcmp(args[myidx], "size") == 0) { |
| 3208 | myidx++; |
| 3209 | if (!*(args[myidx])) { |
| 3210 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 3211 | file, linenum, args[myidx-1]); |
| 3212 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3213 | goto out; |
| 3214 | } |
| 3215 | if ((err = parse_size_err(args[myidx], &curproxy->table.size))) { |
| 3216 | Alert("parsing [%s:%d] : stick-table: unexpected character '%c' in argument of '%s'.\n", |
| 3217 | file, linenum, *err, args[myidx-1]); |
| 3218 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3219 | goto out; |
| 3220 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 3221 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3222 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 3223 | else if (strcmp(args[myidx], "peers") == 0) { |
| 3224 | myidx++; |
Godbach | 5052316 | 2013-12-11 19:48:57 +0800 | [diff] [blame] | 3225 | if (!*(args[myidx])) { |
Godbach | ff11554 | 2014-04-21 21:52:23 +0800 | [diff] [blame] | 3226 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 3227 | file, linenum, args[myidx-1]); |
| 3228 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3229 | goto out; |
Godbach | 5052316 | 2013-12-11 19:48:57 +0800 | [diff] [blame] | 3230 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 3231 | curproxy->table.peers.name = strdup(args[myidx++]); |
| 3232 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3233 | else if (strcmp(args[myidx], "expire") == 0) { |
| 3234 | myidx++; |
| 3235 | if (!*(args[myidx])) { |
| 3236 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 3237 | file, linenum, args[myidx-1]); |
| 3238 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3239 | goto out; |
| 3240 | } |
| 3241 | err = parse_time_err(args[myidx], &val, TIME_UNIT_MS); |
| 3242 | if (err) { |
| 3243 | Alert("parsing [%s:%d] : stick-table: unexpected character '%c' in argument of '%s'.\n", |
| 3244 | file, linenum, *err, args[myidx-1]); |
| 3245 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3246 | goto out; |
| 3247 | } |
| 3248 | curproxy->table.expire = val; |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 3249 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3250 | } |
| 3251 | else if (strcmp(args[myidx], "nopurge") == 0) { |
| 3252 | curproxy->table.nopurge = 1; |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 3253 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3254 | } |
| 3255 | else if (strcmp(args[myidx], "type") == 0) { |
| 3256 | myidx++; |
| 3257 | if (stktable_parse_type(args, &myidx, &curproxy->table.type, &curproxy->table.key_size) != 0) { |
| 3258 | Alert("parsing [%s:%d] : stick-table: unknown type '%s'.\n", |
| 3259 | file, linenum, args[myidx]); |
| 3260 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3261 | goto out; |
| 3262 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 3263 | /* myidx already points to next arg */ |
| 3264 | } |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 3265 | else if (strcmp(args[myidx], "store") == 0) { |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 3266 | int type, err; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 3267 | char *cw, *nw, *sa; |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 3268 | |
| 3269 | myidx++; |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 3270 | nw = args[myidx]; |
| 3271 | while (*nw) { |
| 3272 | /* the "store" keyword supports a comma-separated list */ |
| 3273 | cw = nw; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 3274 | sa = NULL; /* store arg */ |
| 3275 | while (*nw && *nw != ',') { |
| 3276 | if (*nw == '(') { |
| 3277 | *nw = 0; |
| 3278 | sa = ++nw; |
| 3279 | while (*nw != ')') { |
| 3280 | if (!*nw) { |
| 3281 | Alert("parsing [%s:%d] : %s: missing closing parenthesis after store option '%s'.\n", |
| 3282 | file, linenum, args[0], cw); |
| 3283 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3284 | goto out; |
| 3285 | } |
| 3286 | nw++; |
| 3287 | } |
| 3288 | *nw = '\0'; |
| 3289 | } |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 3290 | nw++; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 3291 | } |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 3292 | if (*nw) |
| 3293 | *nw++ = '\0'; |
| 3294 | type = stktable_get_data_type(cw); |
| 3295 | if (type < 0) { |
| 3296 | Alert("parsing [%s:%d] : %s: unknown store option '%s'.\n", |
| 3297 | file, linenum, args[0], cw); |
| 3298 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3299 | goto out; |
| 3300 | } |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 3301 | |
| 3302 | err = stktable_alloc_data_type(&curproxy->table, type, sa); |
| 3303 | switch (err) { |
| 3304 | case PE_NONE: break; |
| 3305 | case PE_EXIST: |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 3306 | Warning("parsing [%s:%d]: %s: store option '%s' already enabled, ignored.\n", |
| 3307 | file, linenum, args[0], cw); |
| 3308 | err_code |= ERR_WARN; |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 3309 | break; |
| 3310 | |
| 3311 | case PE_ARG_MISSING: |
| 3312 | Alert("parsing [%s:%d] : %s: missing argument to store option '%s'.\n", |
| 3313 | file, linenum, args[0], cw); |
| 3314 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3315 | goto out; |
| 3316 | |
| 3317 | case PE_ARG_NOT_USED: |
| 3318 | Alert("parsing [%s:%d] : %s: unexpected argument to store option '%s'.\n", |
| 3319 | file, linenum, args[0], cw); |
| 3320 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3321 | goto out; |
| 3322 | |
| 3323 | default: |
| 3324 | Alert("parsing [%s:%d] : %s: error when processing store option '%s'.\n", |
| 3325 | file, linenum, args[0], cw); |
| 3326 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3327 | goto out; |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 3328 | } |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 3329 | } |
| 3330 | myidx++; |
| 3331 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 3332 | else { |
| 3333 | Alert("parsing [%s:%d] : stick-table: unknown argument '%s'.\n", |
| 3334 | file, linenum, args[myidx]); |
| 3335 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3336 | goto out; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3337 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3338 | } |
| 3339 | |
| 3340 | if (!curproxy->table.size) { |
| 3341 | Alert("parsing [%s:%d] : stick-table: missing size.\n", |
| 3342 | file, linenum); |
| 3343 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3344 | goto out; |
| 3345 | } |
| 3346 | |
| 3347 | if (curproxy->table.type == (unsigned int)-1) { |
| 3348 | Alert("parsing [%s:%d] : stick-table: missing type.\n", |
| 3349 | file, linenum); |
| 3350 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3351 | goto out; |
| 3352 | } |
| 3353 | } |
| 3354 | else if (!strcmp(args[0], "stick")) { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3355 | struct sticking_rule *rule; |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 3356 | struct sample_expr *expr; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3357 | int myidx = 0; |
| 3358 | const char *name = NULL; |
| 3359 | int flags; |
| 3360 | |
| 3361 | if (curproxy == &defproxy) { |
| 3362 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3363 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3364 | goto out; |
| 3365 | } |
| 3366 | |
| 3367 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) { |
| 3368 | err_code |= ERR_WARN; |
| 3369 | goto out; |
| 3370 | } |
| 3371 | |
| 3372 | myidx++; |
| 3373 | if ((strcmp(args[myidx], "store") == 0) || |
| 3374 | (strcmp(args[myidx], "store-request") == 0)) { |
| 3375 | myidx++; |
| 3376 | flags = STK_IS_STORE; |
| 3377 | } |
| 3378 | else if (strcmp(args[myidx], "store-response") == 0) { |
| 3379 | myidx++; |
| 3380 | flags = STK_IS_STORE | STK_ON_RSP; |
| 3381 | } |
| 3382 | else if (strcmp(args[myidx], "match") == 0) { |
| 3383 | myidx++; |
| 3384 | flags = STK_IS_MATCH; |
| 3385 | } |
| 3386 | else if (strcmp(args[myidx], "on") == 0) { |
| 3387 | myidx++; |
| 3388 | flags = STK_IS_MATCH | STK_IS_STORE; |
| 3389 | } |
| 3390 | else { |
| 3391 | Alert("parsing [%s:%d] : '%s' expects 'on', 'match', or 'store'.\n", file, linenum, args[0]); |
| 3392 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3393 | goto out; |
| 3394 | } |
| 3395 | |
| 3396 | if (*(args[myidx]) == 0) { |
| 3397 | Alert("parsing [%s:%d] : '%s' expects a fetch method.\n", file, linenum, args[0]); |
| 3398 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3399 | goto out; |
| 3400 | } |
| 3401 | |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 3402 | curproxy->conf.args.ctx = ARGC_STK; |
Thierry FOURNIER | eeaa951 | 2014-02-11 14:00:19 +0100 | [diff] [blame] | 3403 | expr = sample_parse_expr(args, &myidx, file, linenum, &errmsg, &curproxy->conf.args); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3404 | if (!expr) { |
Willy Tarreau | 975c178 | 2013-12-12 23:16:54 +0100 | [diff] [blame] | 3405 | Alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3406 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3407 | goto out; |
| 3408 | } |
| 3409 | |
| 3410 | if (flags & STK_ON_RSP) { |
Willy Tarreau | 80aca90 | 2013-01-07 15:42:20 +0100 | [diff] [blame] | 3411 | if (!(expr->fetch->val & SMP_VAL_BE_STO_RUL)) { |
| 3412 | Alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available for 'store-response'.\n", |
| 3413 | 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] | 3414 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 3415 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3416 | goto out; |
| 3417 | } |
| 3418 | } else { |
Willy Tarreau | 80aca90 | 2013-01-07 15:42:20 +0100 | [diff] [blame] | 3419 | if (!(expr->fetch->val & SMP_VAL_BE_SET_SRV)) { |
| 3420 | Alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available during request.\n", |
| 3421 | 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] | 3422 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 3423 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3424 | goto out; |
| 3425 | } |
| 3426 | } |
| 3427 | |
Willy Tarreau | 1b6c00c | 2012-10-05 22:41:26 +0200 | [diff] [blame] | 3428 | /* 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] | 3429 | curproxy->http_needed |= !!(expr->fetch->use & SMP_USE_HTTP_ANY); |
Willy Tarreau | 1b6c00c | 2012-10-05 22:41:26 +0200 | [diff] [blame] | 3430 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3431 | if (strcmp(args[myidx], "table") == 0) { |
| 3432 | myidx++; |
| 3433 | name = args[myidx++]; |
| 3434 | } |
| 3435 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 3436 | if (strcmp(args[myidx], "if") == 0 || strcmp(args[myidx], "unless") == 0) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 3437 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + myidx, &errmsg)) == NULL) { |
| 3438 | Alert("parsing [%s:%d] : '%s': error detected while parsing sticking condition : %s.\n", |
| 3439 | file, linenum, args[0], errmsg); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3440 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 3441 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3442 | goto out; |
| 3443 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3444 | } |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 3445 | else if (*(args[myidx])) { |
| 3446 | Alert("parsing [%s:%d] : '%s': unknown keyword '%s'.\n", |
| 3447 | file, linenum, args[0], args[myidx]); |
| 3448 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 3449 | free(expr); |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 3450 | goto out; |
| 3451 | } |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 3452 | if (flags & STK_ON_RSP) |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3453 | 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] | 3454 | else |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3455 | 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] | 3456 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3457 | rule = (struct sticking_rule *)calloc(1, sizeof(*rule)); |
| 3458 | rule->cond = cond; |
| 3459 | rule->expr = expr; |
| 3460 | rule->flags = flags; |
| 3461 | rule->table.name = name ? strdup(name) : NULL; |
| 3462 | LIST_INIT(&rule->list); |
| 3463 | if (flags & STK_ON_RSP) |
| 3464 | LIST_ADDQ(&curproxy->storersp_rules, &rule->list); |
| 3465 | else |
| 3466 | LIST_ADDQ(&curproxy->sticking_rules, &rule->list); |
| 3467 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3468 | else if (!strcmp(args[0], "stats")) { |
| 3469 | if (curproxy != &defproxy && curproxy->uri_auth == defproxy.uri_auth) |
| 3470 | curproxy->uri_auth = NULL; /* we must detach from the default config */ |
| 3471 | |
Krzysztof Piotr Oledzki | 260a3bb | 2010-01-06 16:25:05 +0100 | [diff] [blame] | 3472 | if (!*args[1]) { |
| 3473 | goto stats_error_parsing; |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3474 | } else if (!strcmp(args[1], "admin")) { |
| 3475 | struct stats_admin_rule *rule; |
| 3476 | |
| 3477 | if (curproxy == &defproxy) { |
| 3478 | Alert("parsing [%s:%d]: '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
| 3479 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3480 | goto out; |
| 3481 | } |
| 3482 | |
| 3483 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 3484 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3485 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3486 | goto out; |
| 3487 | } |
| 3488 | |
| 3489 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
| 3490 | Alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n", |
| 3491 | file, linenum, args[0], args[1]); |
| 3492 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3493 | goto out; |
| 3494 | } |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 3495 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 3496 | Alert("parsing [%s:%d] : error detected while parsing a '%s %s' rule : %s.\n", |
| 3497 | file, linenum, args[0], args[1], errmsg); |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3498 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3499 | goto out; |
| 3500 | } |
| 3501 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3502 | err_code |= warnif_cond_conflicts(cond, |
| 3503 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 3504 | file, linenum); |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3505 | |
| 3506 | rule = (struct stats_admin_rule *)calloc(1, sizeof(*rule)); |
| 3507 | rule->cond = cond; |
| 3508 | LIST_INIT(&rule->list); |
| 3509 | LIST_ADDQ(&curproxy->uri_auth->admin_rules, &rule->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3510 | } else if (!strcmp(args[1], "uri")) { |
| 3511 | if (*(args[2]) == 0) { |
| 3512 | Alert("parsing [%s:%d] : 'uri' needs an URI prefix.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3513 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3514 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3515 | } else if (!stats_set_uri(&curproxy->uri_auth, args[2])) { |
| 3516 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3517 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3518 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3519 | } |
| 3520 | } else if (!strcmp(args[1], "realm")) { |
| 3521 | if (*(args[2]) == 0) { |
| 3522 | Alert("parsing [%s:%d] : 'realm' needs an realm name.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3523 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3524 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3525 | } else if (!stats_set_realm(&curproxy->uri_auth, args[2])) { |
| 3526 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3527 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3528 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3529 | } |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 3530 | } else if (!strcmp(args[1], "refresh")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 3531 | unsigned interval; |
| 3532 | |
| 3533 | err = parse_time_err(args[2], &interval, TIME_UNIT_S); |
| 3534 | if (err) { |
| 3535 | Alert("parsing [%s:%d] : unexpected character '%c' in stats refresh interval.\n", |
| 3536 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3537 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3538 | goto out; |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 3539 | } else if (!stats_set_refresh(&curproxy->uri_auth, interval)) { |
| 3540 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3541 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3542 | goto out; |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 3543 | } |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3544 | } 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] | 3545 | struct http_req_rule *rule; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3546 | |
| 3547 | if (curproxy == &defproxy) { |
| 3548 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3549 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3550 | goto out; |
| 3551 | } |
| 3552 | |
| 3553 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 3554 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3555 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3556 | goto out; |
| 3557 | } |
| 3558 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3559 | if (!LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) && |
| 3560 | !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] | 3561 | Warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n", |
| 3562 | file, linenum, args[0]); |
| 3563 | err_code |= ERR_WARN; |
| 3564 | } |
| 3565 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3566 | 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] | 3567 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3568 | if (!rule) { |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3569 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3570 | goto out; |
| 3571 | } |
| 3572 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3573 | err_code |= warnif_cond_conflicts(rule->cond, |
| 3574 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 3575 | file, linenum); |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3576 | LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list); |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3577 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3578 | } else if (!strcmp(args[1], "auth")) { |
| 3579 | if (*(args[2]) == 0) { |
| 3580 | 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] | 3581 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3582 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3583 | } else if (!stats_add_auth(&curproxy->uri_auth, args[2])) { |
| 3584 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3585 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3586 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3587 | } |
| 3588 | } else if (!strcmp(args[1], "scope")) { |
| 3589 | if (*(args[2]) == 0) { |
| 3590 | Alert("parsing [%s:%d] : 'scope' needs a proxy name.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3591 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3592 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3593 | } else if (!stats_add_scope(&curproxy->uri_auth, args[2])) { |
| 3594 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3595 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3596 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3597 | } |
| 3598 | } else if (!strcmp(args[1], "enable")) { |
| 3599 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 3600 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3601 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3602 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3603 | } |
Krzysztof Oledzki | d9db927 | 2007-10-15 10:05:11 +0200 | [diff] [blame] | 3604 | } else if (!strcmp(args[1], "hide-version")) { |
| 3605 | if (!stats_set_flag(&curproxy->uri_auth, ST_HIDEVER)) { |
| 3606 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3607 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3608 | goto out; |
Krzysztof Oledzki | d9db927 | 2007-10-15 10:05:11 +0200 | [diff] [blame] | 3609 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3610 | } else if (!strcmp(args[1], "show-legends")) { |
| 3611 | if (!stats_set_flag(&curproxy->uri_auth, ST_SHLGNDS)) { |
| 3612 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3613 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3614 | goto out; |
| 3615 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3616 | } else if (!strcmp(args[1], "show-node")) { |
| 3617 | |
| 3618 | if (*args[2]) { |
| 3619 | int i; |
| 3620 | char c; |
| 3621 | |
| 3622 | for (i=0; args[2][i]; i++) { |
| 3623 | c = args[2][i]; |
Willy Tarreau | 88e0581 | 2010-03-03 00:16:00 +0100 | [diff] [blame] | 3624 | if (!isupper((unsigned char)c) && !islower((unsigned char)c) && |
| 3625 | !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.') |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3626 | break; |
| 3627 | } |
| 3628 | |
| 3629 | if (!i || args[2][i]) { |
| 3630 | Alert("parsing [%s:%d]: '%s %s' invalid node name - should be a string" |
| 3631 | "with digits(0-9), letters(A-Z, a-z), hyphen(-) or underscode(_).\n", |
| 3632 | file, linenum, args[0], args[1]); |
| 3633 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3634 | goto out; |
| 3635 | } |
| 3636 | } |
| 3637 | |
| 3638 | if (!stats_set_node(&curproxy->uri_auth, args[2])) { |
| 3639 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3640 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3641 | goto out; |
| 3642 | } |
| 3643 | } else if (!strcmp(args[1], "show-desc")) { |
| 3644 | char *desc = NULL; |
| 3645 | |
| 3646 | if (*args[2]) { |
| 3647 | int i, len=0; |
| 3648 | char *d; |
| 3649 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 3650 | for (i = 2; *args[i]; i++) |
| 3651 | len += strlen(args[i]) + 1; |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3652 | |
| 3653 | desc = d = (char *)calloc(1, len); |
| 3654 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 3655 | d += snprintf(d, desc + len - d, "%s", args[2]); |
| 3656 | for (i = 3; *args[i]; i++) |
| 3657 | d += snprintf(d, desc + len - d, " %s", args[i]); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3658 | } |
| 3659 | |
| 3660 | if (!*args[2] && !global.desc) |
| 3661 | Warning("parsing [%s:%d]: '%s' requires a parameter or 'desc' to be set in the global section.\n", |
| 3662 | file, linenum, args[1]); |
| 3663 | else { |
| 3664 | if (!stats_set_desc(&curproxy->uri_auth, desc)) { |
| 3665 | free(desc); |
| 3666 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3667 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3668 | goto out; |
| 3669 | } |
| 3670 | free(desc); |
| 3671 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3672 | } else { |
Krzysztof Piotr Oledzki | 260a3bb | 2010-01-06 16:25:05 +0100 | [diff] [blame] | 3673 | stats_error_parsing: |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3674 | 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] | 3675 | 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] | 3676 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3677 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3678 | } |
| 3679 | } |
| 3680 | else if (!strcmp(args[0], "option")) { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3681 | int optnum; |
| 3682 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3683 | if (*(args[1]) == '\0') { |
| 3684 | Alert("parsing [%s:%d]: '%s' expects an option name.\n", |
| 3685 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3686 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3687 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3688 | } |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3689 | |
| 3690 | for (optnum = 0; cfg_opts[optnum].name; optnum++) { |
| 3691 | if (!strcmp(args[1], cfg_opts[optnum].name)) { |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 3692 | if (cfg_opts[optnum].cap == PR_CAP_NONE) { |
| 3693 | Alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n", |
| 3694 | file, linenum, cfg_opts[optnum].name); |
| 3695 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3696 | goto out; |
| 3697 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3698 | if (warnifnotcap(curproxy, cfg_opts[optnum].cap, file, linenum, args[1], NULL)) { |
| 3699 | err_code |= ERR_WARN; |
| 3700 | goto out; |
| 3701 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3702 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 3703 | curproxy->no_options &= ~cfg_opts[optnum].val; |
| 3704 | curproxy->options &= ~cfg_opts[optnum].val; |
| 3705 | |
| 3706 | switch (kwm) { |
| 3707 | case KWM_STD: |
| 3708 | curproxy->options |= cfg_opts[optnum].val; |
| 3709 | break; |
| 3710 | case KWM_NO: |
| 3711 | curproxy->no_options |= cfg_opts[optnum].val; |
| 3712 | break; |
| 3713 | case KWM_DEF: /* already cleared */ |
| 3714 | break; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 3715 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3716 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3717 | goto out; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3718 | } |
| 3719 | } |
| 3720 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 3721 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) { |
| 3722 | if (!strcmp(args[1], cfg_opts2[optnum].name)) { |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 3723 | if (cfg_opts2[optnum].cap == PR_CAP_NONE) { |
| 3724 | Alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n", |
| 3725 | file, linenum, cfg_opts2[optnum].name); |
| 3726 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3727 | goto out; |
| 3728 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3729 | if (warnifnotcap(curproxy, cfg_opts2[optnum].cap, file, linenum, args[1], NULL)) { |
| 3730 | err_code |= ERR_WARN; |
| 3731 | goto out; |
| 3732 | } |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 3733 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 3734 | curproxy->no_options2 &= ~cfg_opts2[optnum].val; |
| 3735 | curproxy->options2 &= ~cfg_opts2[optnum].val; |
| 3736 | |
| 3737 | switch (kwm) { |
| 3738 | case KWM_STD: |
| 3739 | curproxy->options2 |= cfg_opts2[optnum].val; |
| 3740 | break; |
| 3741 | case KWM_NO: |
| 3742 | curproxy->no_options2 |= cfg_opts2[optnum].val; |
| 3743 | break; |
| 3744 | case KWM_DEF: /* already cleared */ |
| 3745 | break; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 3746 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3747 | goto out; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 3748 | } |
| 3749 | } |
| 3750 | |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 3751 | /* HTTP options override each other. They can be cancelled using |
| 3752 | * "no option xxx" which only switches to default mode if the mode |
| 3753 | * was this one (useful for cancelling options set in defaults |
| 3754 | * sections). |
| 3755 | */ |
| 3756 | if (strcmp(args[1], "httpclose") == 0) { |
| 3757 | if (kwm == KWM_STD) { |
| 3758 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3759 | curproxy->options |= PR_O_HTTP_PCL; |
| 3760 | goto out; |
| 3761 | } |
| 3762 | else if (kwm == KWM_NO) { |
| 3763 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_PCL) |
| 3764 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3765 | goto out; |
| 3766 | } |
| 3767 | } |
| 3768 | else if (strcmp(args[1], "forceclose") == 0) { |
| 3769 | if (kwm == KWM_STD) { |
| 3770 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3771 | curproxy->options |= PR_O_HTTP_FCL; |
| 3772 | goto out; |
| 3773 | } |
| 3774 | else if (kwm == KWM_NO) { |
| 3775 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_FCL) |
| 3776 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3777 | goto out; |
| 3778 | } |
| 3779 | } |
| 3780 | else if (strcmp(args[1], "http-server-close") == 0) { |
| 3781 | if (kwm == KWM_STD) { |
| 3782 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3783 | curproxy->options |= PR_O_HTTP_SCL; |
| 3784 | goto out; |
| 3785 | } |
| 3786 | else if (kwm == KWM_NO) { |
| 3787 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_SCL) |
| 3788 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3789 | goto out; |
| 3790 | } |
| 3791 | } |
| 3792 | else if (strcmp(args[1], "http-keep-alive") == 0) { |
| 3793 | if (kwm == KWM_STD) { |
| 3794 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3795 | curproxy->options |= PR_O_HTTP_KAL; |
| 3796 | goto out; |
| 3797 | } |
| 3798 | else if (kwm == KWM_NO) { |
| 3799 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_KAL) |
| 3800 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3801 | goto out; |
| 3802 | } |
| 3803 | } |
| 3804 | else if (strcmp(args[1], "http-tunnel") == 0) { |
| 3805 | if (kwm == KWM_STD) { |
| 3806 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3807 | curproxy->options |= PR_O_HTTP_TUN; |
| 3808 | goto out; |
| 3809 | } |
| 3810 | else if (kwm == KWM_NO) { |
| 3811 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_TUN) |
| 3812 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3813 | goto out; |
| 3814 | } |
| 3815 | } |
| 3816 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 3817 | if (kwm != KWM_STD) { |
| 3818 | 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] | 3819 | file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3820 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3821 | goto out; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3822 | } |
| 3823 | |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3824 | if (!strcmp(args[1], "httplog")) { |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 3825 | char *logformat; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3826 | /* generate a complete HTTP log */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 3827 | logformat = default_http_log_format; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3828 | if (*(args[2]) != '\0') { |
| 3829 | if (!strcmp(args[2], "clf")) { |
| 3830 | curproxy->options2 |= PR_O2_CLFLOG; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 3831 | logformat = clf_http_log_format; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3832 | } else { |
| 3833 | 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] | 3834 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3835 | goto out; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3836 | } |
| 3837 | } |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 3838 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 3839 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 3840 | curproxy->conf.logformat_string != clf_http_log_format) |
| 3841 | free(curproxy->conf.logformat_string); |
| 3842 | curproxy->conf.logformat_string = logformat; |
| 3843 | |
| 3844 | free(curproxy->conf.lfs_file); |
| 3845 | curproxy->conf.lfs_file = strdup(curproxy->conf.args.file); |
| 3846 | curproxy->conf.lfs_line = curproxy->conf.args.line; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3847 | } |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 3848 | else if (!strcmp(args[1], "tcplog")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3849 | /* generate a detailed TCP log */ |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 3850 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 3851 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 3852 | curproxy->conf.logformat_string != clf_http_log_format) |
| 3853 | free(curproxy->conf.logformat_string); |
| 3854 | curproxy->conf.logformat_string = default_tcp_log_format; |
| 3855 | |
| 3856 | free(curproxy->conf.lfs_file); |
| 3857 | curproxy->conf.lfs_file = strdup(curproxy->conf.args.file); |
| 3858 | curproxy->conf.lfs_line = curproxy->conf.args.line; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 3859 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3860 | else if (!strcmp(args[1], "tcpka")) { |
| 3861 | /* enable TCP keep-alives on client and server sessions */ |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3862 | 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] | 3863 | err_code |= ERR_WARN; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3864 | |
| 3865 | if (curproxy->cap & PR_CAP_FE) |
| 3866 | curproxy->options |= PR_O_TCP_CLI_KA; |
| 3867 | if (curproxy->cap & PR_CAP_BE) |
| 3868 | curproxy->options |= PR_O_TCP_SRV_KA; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3869 | } |
| 3870 | else if (!strcmp(args[1], "httpchk")) { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3871 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3872 | err_code |= ERR_WARN; |
| 3873 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3874 | /* use HTTP request to check servers' health */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3875 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 3876 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3877 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 3878 | curproxy->options2 |= PR_O2_HTTP_CHK; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3879 | if (!*args[2]) { /* no argument */ |
| 3880 | curproxy->check_req = strdup(DEF_CHECK_REQ); /* default request */ |
| 3881 | curproxy->check_len = strlen(DEF_CHECK_REQ); |
| 3882 | } else if (!*args[3]) { /* one argument : URI */ |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3883 | 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] | 3884 | curproxy->check_req = (char *)malloc(reqlen); |
| 3885 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3886 | "OPTIONS %s HTTP/1.0\r\n", args[2]); /* URI to use */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3887 | } else { /* more arguments : METHOD URI [HTTP_VER] */ |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3888 | int reqlen = strlen(args[2]) + strlen(args[3]) + 3 + strlen("\r\n"); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3889 | if (*args[4]) |
| 3890 | reqlen += strlen(args[4]); |
| 3891 | else |
| 3892 | reqlen += strlen("HTTP/1.0"); |
| 3893 | |
| 3894 | curproxy->check_req = (char *)malloc(reqlen); |
| 3895 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3896 | "%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] | 3897 | } |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 3898 | } |
| 3899 | else if (!strcmp(args[1], "ssl-hello-chk")) { |
| 3900 | /* use SSLv3 CLIENT HELLO to check servers' health */ |
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; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3903 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3904 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 3905 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3906 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Willy Tarreau | 07a5490 | 2010-03-29 18:33:29 +0200 | [diff] [blame] | 3907 | curproxy->options2 |= PR_O2_SSL3_CHK; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3908 | } |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 3909 | else if (!strcmp(args[1], "smtpchk")) { |
| 3910 | /* use SMTP request to check servers' health */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3911 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 3912 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3913 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 3914 | curproxy->options2 |= PR_O2_SMTP_CHK; |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 3915 | |
| 3916 | if (!*args[2] || !*args[3]) { /* no argument or incomplete EHLO host */ |
| 3917 | curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */ |
| 3918 | curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ); |
| 3919 | } else { /* ESMTP EHLO, or SMTP HELO, and a hostname */ |
| 3920 | if (!strcmp(args[2], "EHLO") || !strcmp(args[2], "HELO")) { |
| 3921 | int reqlen = strlen(args[2]) + strlen(args[3]) + strlen(" \r\n") + 1; |
| 3922 | curproxy->check_req = (char *)malloc(reqlen); |
| 3923 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
| 3924 | "%s %s\r\n", args[2], args[3]); /* HELO hostname */ |
| 3925 | } else { |
| 3926 | /* this just hits the default for now, but you could potentially expand it to allow for other stuff |
| 3927 | though, it's unlikely you'd want to send anything other than an EHLO or HELO */ |
| 3928 | curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */ |
| 3929 | curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ); |
| 3930 | } |
| 3931 | } |
| 3932 | } |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 3933 | else if (!strcmp(args[1], "pgsql-check")) { |
| 3934 | /* use PostgreSQL request to check servers' health */ |
| 3935 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 3936 | err_code |= ERR_WARN; |
| 3937 | |
| 3938 | free(curproxy->check_req); |
| 3939 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3940 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 3941 | curproxy->options2 |= PR_O2_PGSQL_CHK; |
| 3942 | |
| 3943 | if (*(args[2])) { |
| 3944 | int cur_arg = 2; |
| 3945 | |
| 3946 | while (*(args[cur_arg])) { |
| 3947 | if (strcmp(args[cur_arg], "user") == 0) { |
| 3948 | char * packet; |
| 3949 | uint32_t packet_len; |
| 3950 | uint32_t pv; |
| 3951 | |
| 3952 | /* suboption header - needs additional argument for it */ |
| 3953 | if (*(args[cur_arg+1]) == 0) { |
| 3954 | Alert("parsing [%s:%d] : '%s %s %s' expects <username> as argument.\n", |
| 3955 | file, linenum, args[0], args[1], args[cur_arg]); |
| 3956 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3957 | goto out; |
| 3958 | } |
| 3959 | |
| 3960 | /* uint32_t + uint32_t + strlen("user")+1 + strlen(username)+1 + 1 */ |
| 3961 | packet_len = 4 + 4 + 5 + strlen(args[cur_arg + 1])+1 +1; |
| 3962 | pv = htonl(0x30000); /* protocol version 3.0 */ |
| 3963 | |
| 3964 | packet = (char*) calloc(1, packet_len); |
| 3965 | |
| 3966 | memcpy(packet + 4, &pv, 4); |
| 3967 | |
| 3968 | /* copy "user" */ |
| 3969 | memcpy(packet + 8, "user", 4); |
| 3970 | |
| 3971 | /* copy username */ |
| 3972 | memcpy(packet + 13, args[cur_arg+1], strlen(args[cur_arg+1])); |
| 3973 | |
| 3974 | free(curproxy->check_req); |
| 3975 | curproxy->check_req = packet; |
| 3976 | curproxy->check_len = packet_len; |
| 3977 | |
| 3978 | packet_len = htonl(packet_len); |
| 3979 | memcpy(packet, &packet_len, 4); |
| 3980 | cur_arg += 2; |
| 3981 | } else { |
| 3982 | /* unknown suboption - catchall */ |
| 3983 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'user'.\n", |
| 3984 | file, linenum, args[0], args[1]); |
| 3985 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3986 | goto out; |
| 3987 | } |
| 3988 | } /* end while loop */ |
| 3989 | } |
| 3990 | } |
| 3991 | |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 3992 | else if (!strcmp(args[1], "redis-check")) { |
| 3993 | /* use REDIS PING request to check servers' health */ |
| 3994 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 3995 | err_code |= ERR_WARN; |
| 3996 | |
| 3997 | free(curproxy->check_req); |
| 3998 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3999 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 4000 | curproxy->options2 |= PR_O2_REDIS_CHK; |
| 4001 | |
| 4002 | curproxy->check_req = (char *) malloc(sizeof(DEF_REDIS_CHECK_REQ) - 1); |
| 4003 | memcpy(curproxy->check_req, DEF_REDIS_CHECK_REQ, sizeof(DEF_REDIS_CHECK_REQ) - 1); |
| 4004 | curproxy->check_len = sizeof(DEF_REDIS_CHECK_REQ) - 1; |
| 4005 | } |
| 4006 | |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 4007 | else if (!strcmp(args[1], "mysql-check")) { |
| 4008 | /* use MYSQL request to check servers' health */ |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 4009 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 4010 | err_code |= ERR_WARN; |
| 4011 | |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 4012 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 4013 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4014 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 4015 | curproxy->options2 |= PR_O2_MYSQL_CHK; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 4016 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 4017 | /* 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] | 4018 | * const char mysql40_client_auth_pkt[] = { |
| 4019 | * "\x0e\x00\x00" // packet length |
| 4020 | * "\x01" // packet number |
| 4021 | * "\x00\x00" // client capabilities |
| 4022 | * "\x00\x00\x01" // max packet |
| 4023 | * "haproxy\x00" // username (null terminated string) |
| 4024 | * "\x00" // filler (always 0x00) |
| 4025 | * "\x01\x00\x00" // packet length |
| 4026 | * "\x00" // packet number |
| 4027 | * "\x01" // COM_QUIT command |
| 4028 | * }; |
| 4029 | */ |
| 4030 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 4031 | /* This is an example of a MySQL >=4.1 client Authentication packet provided by Nenad Merdanovic. |
| 4032 | * const char mysql41_client_auth_pkt[] = { |
| 4033 | * "\x0e\x00\x00\" // packet length |
| 4034 | * "\x01" // packet number |
| 4035 | * "\x00\x00\x00\x00" // client capabilities |
| 4036 | * "\x00\x00\x00\x01" // max packet |
| 4037 | * "\x21" // character set (UTF-8) |
| 4038 | * char[23] // All zeroes |
| 4039 | * "haproxy\x00" // username (null terminated string) |
| 4040 | * "\x00" // filler (always 0x00) |
| 4041 | * "\x01\x00\x00" // packet length |
| 4042 | * "\x00" // packet number |
| 4043 | * "\x01" // COM_QUIT command |
| 4044 | * }; |
| 4045 | */ |
| 4046 | |
| 4047 | |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 4048 | if (*(args[2])) { |
| 4049 | int cur_arg = 2; |
| 4050 | |
| 4051 | while (*(args[cur_arg])) { |
| 4052 | if (strcmp(args[cur_arg], "user") == 0) { |
| 4053 | char *mysqluser; |
| 4054 | int packetlen, reqlen, userlen; |
| 4055 | |
| 4056 | /* suboption header - needs additional argument for it */ |
| 4057 | if (*(args[cur_arg+1]) == 0) { |
| 4058 | Alert("parsing [%s:%d] : '%s %s %s' expects <username> as argument.\n", |
| 4059 | file, linenum, args[0], args[1], args[cur_arg]); |
| 4060 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4061 | goto out; |
| 4062 | } |
| 4063 | mysqluser = args[cur_arg + 1]; |
| 4064 | userlen = strlen(mysqluser); |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 4065 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 4066 | if (*(args[cur_arg+2])) { |
| 4067 | if (!strcmp(args[cur_arg+2], "post-41")) { |
| 4068 | packetlen = userlen + 7 + 27; |
| 4069 | reqlen = packetlen + 9; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 4070 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 4071 | free(curproxy->check_req); |
| 4072 | curproxy->check_req = (char *)calloc(1, reqlen); |
| 4073 | curproxy->check_len = reqlen; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 4074 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 4075 | snprintf(curproxy->check_req, 4, "%c%c%c", |
| 4076 | ((unsigned char) packetlen & 0xff), |
| 4077 | ((unsigned char) (packetlen >> 8) & 0xff), |
| 4078 | ((unsigned char) (packetlen >> 16) & 0xff)); |
| 4079 | |
| 4080 | curproxy->check_req[3] = 1; |
| 4081 | curproxy->check_req[5] = 130; |
| 4082 | curproxy->check_req[11] = 1; |
| 4083 | curproxy->check_req[12] = 33; |
| 4084 | memcpy(&curproxy->check_req[36], mysqluser, userlen); |
| 4085 | curproxy->check_req[36 + userlen + 1 + 1] = 1; |
| 4086 | curproxy->check_req[36 + userlen + 1 + 1 + 4] = 1; |
| 4087 | cur_arg += 3; |
| 4088 | } else { |
| 4089 | Alert("parsing [%s:%d] : keyword '%s' only supports option 'post-41'.\n", file, linenum, args[cur_arg+2]); |
| 4090 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4091 | goto out; |
| 4092 | } |
| 4093 | } else { |
| 4094 | packetlen = userlen + 7; |
| 4095 | reqlen = packetlen + 9; |
| 4096 | |
| 4097 | free(curproxy->check_req); |
| 4098 | curproxy->check_req = (char *)calloc(1, reqlen); |
| 4099 | curproxy->check_len = reqlen; |
| 4100 | |
| 4101 | snprintf(curproxy->check_req, 4, "%c%c%c", |
| 4102 | ((unsigned char) packetlen & 0xff), |
| 4103 | ((unsigned char) (packetlen >> 8) & 0xff), |
| 4104 | ((unsigned char) (packetlen >> 16) & 0xff)); |
| 4105 | |
| 4106 | curproxy->check_req[3] = 1; |
| 4107 | curproxy->check_req[5] = 128; |
| 4108 | curproxy->check_req[8] = 1; |
| 4109 | memcpy(&curproxy->check_req[9], mysqluser, userlen); |
| 4110 | curproxy->check_req[9 + userlen + 1 + 1] = 1; |
| 4111 | curproxy->check_req[9 + userlen + 1 + 1 + 4] = 1; |
| 4112 | cur_arg += 2; |
| 4113 | } |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 4114 | } else { |
| 4115 | /* unknown suboption - catchall */ |
| 4116 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'user'.\n", |
| 4117 | file, linenum, args[0], args[1]); |
| 4118 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4119 | goto out; |
| 4120 | } |
| 4121 | } /* end while loop */ |
| 4122 | } |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 4123 | } |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 4124 | else if (!strcmp(args[1], "ldap-check")) { |
| 4125 | /* use LDAP request to check servers' health */ |
| 4126 | free(curproxy->check_req); |
| 4127 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4128 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 4129 | curproxy->options2 |= PR_O2_LDAP_CHK; |
| 4130 | |
| 4131 | curproxy->check_req = (char *) malloc(sizeof(DEF_LDAP_CHECK_REQ) - 1); |
| 4132 | memcpy(curproxy->check_req, DEF_LDAP_CHECK_REQ, sizeof(DEF_LDAP_CHECK_REQ) - 1); |
| 4133 | curproxy->check_len = sizeof(DEF_LDAP_CHECK_REQ) - 1; |
| 4134 | } |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 4135 | else if (!strcmp(args[1], "tcp-check")) { |
| 4136 | /* use raw TCPCHK send/expect to check servers' health */ |
| 4137 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 4138 | err_code |= ERR_WARN; |
| 4139 | |
| 4140 | free(curproxy->check_req); |
| 4141 | curproxy->check_req = NULL; |
| 4142 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 4143 | curproxy->options2 |= PR_O2_TCPCHK_CHK; |
| 4144 | } |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 4145 | else if (!strcmp(args[1], "external-check")) { |
| 4146 | /* excute an external command to check servers' health */ |
| 4147 | free(curproxy->check_req); |
| 4148 | curproxy->check_req = NULL; |
| 4149 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 4150 | curproxy->options2 |= PR_O2_EXT_CHK; |
| 4151 | } |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 4152 | else if (!strcmp(args[1], "forwardfor")) { |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 4153 | int cur_arg; |
| 4154 | |
| 4155 | /* insert x-forwarded-for field, but not for the IP address listed as an except. |
| 4156 | * set default options (ie: bitfield, header name, etc) |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 4157 | */ |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 4158 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 4159 | curproxy->options |= PR_O_FWDFOR | PR_O_FF_ALWAYS; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 4160 | |
| 4161 | free(curproxy->fwdfor_hdr_name); |
| 4162 | curproxy->fwdfor_hdr_name = strdup(DEF_XFORWARDFOR_HDR); |
| 4163 | curproxy->fwdfor_hdr_len = strlen(DEF_XFORWARDFOR_HDR); |
| 4164 | |
| 4165 | /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */ |
| 4166 | cur_arg = 2; |
| 4167 | while (*(args[cur_arg])) { |
| 4168 | if (!strcmp(args[cur_arg], "except")) { |
| 4169 | /* suboption except - needs additional argument for it */ |
Thierry FOURNIER | fc7ac7b | 2014-02-11 15:23:04 +0100 | [diff] [blame] | 4170 | 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] | 4171 | Alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n", |
| 4172 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4173 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4174 | goto out; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 4175 | } |
| 4176 | /* flush useless bits */ |
| 4177 | curproxy->except_net.s_addr &= curproxy->except_mask.s_addr; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 4178 | cur_arg += 2; |
| 4179 | } else if (!strcmp(args[cur_arg], "header")) { |
| 4180 | /* suboption header - needs additional argument for it */ |
| 4181 | if (*(args[cur_arg+1]) == 0) { |
| 4182 | Alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 4183 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4184 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4185 | goto out; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 4186 | } |
| 4187 | free(curproxy->fwdfor_hdr_name); |
| 4188 | curproxy->fwdfor_hdr_name = strdup(args[cur_arg+1]); |
| 4189 | curproxy->fwdfor_hdr_len = strlen(curproxy->fwdfor_hdr_name); |
| 4190 | cur_arg += 2; |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 4191 | } else if (!strcmp(args[cur_arg], "if-none")) { |
| 4192 | curproxy->options &= ~PR_O_FF_ALWAYS; |
| 4193 | cur_arg += 1; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 4194 | } else { |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 4195 | /* unknown suboption - catchall */ |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 4196 | 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] | 4197 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4198 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4199 | goto out; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 4200 | } |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 4201 | } /* end while loop */ |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 4202 | } |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 4203 | else if (!strcmp(args[1], "originalto")) { |
| 4204 | int cur_arg; |
| 4205 | |
| 4206 | /* insert x-original-to field, but not for the IP address listed as an except. |
| 4207 | * set default options (ie: bitfield, header name, etc) |
| 4208 | */ |
| 4209 | |
| 4210 | curproxy->options |= PR_O_ORGTO; |
| 4211 | |
| 4212 | free(curproxy->orgto_hdr_name); |
| 4213 | curproxy->orgto_hdr_name = strdup(DEF_XORIGINALTO_HDR); |
| 4214 | curproxy->orgto_hdr_len = strlen(DEF_XORIGINALTO_HDR); |
| 4215 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 4216 | /* 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] | 4217 | cur_arg = 2; |
| 4218 | while (*(args[cur_arg])) { |
| 4219 | if (!strcmp(args[cur_arg], "except")) { |
| 4220 | /* suboption except - needs additional argument for it */ |
Thierry FOURNIER | fc7ac7b | 2014-02-11 15:23:04 +0100 | [diff] [blame] | 4221 | 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] | 4222 | Alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n", |
| 4223 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4224 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4225 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 4226 | } |
| 4227 | /* flush useless bits */ |
| 4228 | curproxy->except_to.s_addr &= curproxy->except_mask_to.s_addr; |
| 4229 | cur_arg += 2; |
| 4230 | } else if (!strcmp(args[cur_arg], "header")) { |
| 4231 | /* suboption header - needs additional argument for it */ |
| 4232 | if (*(args[cur_arg+1]) == 0) { |
| 4233 | Alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 4234 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4235 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4236 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 4237 | } |
| 4238 | free(curproxy->orgto_hdr_name); |
| 4239 | curproxy->orgto_hdr_name = strdup(args[cur_arg+1]); |
| 4240 | curproxy->orgto_hdr_len = strlen(curproxy->orgto_hdr_name); |
| 4241 | cur_arg += 2; |
| 4242 | } else { |
| 4243 | /* unknown suboption - catchall */ |
| 4244 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n", |
| 4245 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4246 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4247 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 4248 | } |
| 4249 | } /* end while loop */ |
| 4250 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4251 | else { |
| 4252 | Alert("parsing [%s:%d] : unknown option '%s'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4253 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4254 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4255 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4256 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4257 | } |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 4258 | else if (!strcmp(args[0], "default_backend")) { |
| 4259 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4260 | err_code |= ERR_WARN; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 4261 | |
| 4262 | if (*(args[1]) == 0) { |
| 4263 | 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] | 4264 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4265 | goto out; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 4266 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 4267 | free(curproxy->defbe.name); |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 4268 | curproxy->defbe.name = strdup(args[1]); |
| 4269 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4270 | else if (!strcmp(args[0], "redispatch") || !strcmp(args[0], "redisp")) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4271 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4272 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4273 | |
Willy Tarreau | a3c504c | 2014-04-28 22:37:32 +0200 | [diff] [blame] | 4274 | if (!already_warned(WARN_REDISPATCH_DEPRECATED)) |
| 4275 | 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] | 4276 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4277 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4278 | /* enable reconnections to dispatch */ |
| 4279 | curproxy->options |= PR_O_REDISP; |
| 4280 | } |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 4281 | else if (!strcmp(args[0], "http-check")) { |
| 4282 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4283 | err_code |= ERR_WARN; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 4284 | |
| 4285 | if (strcmp(args[1], "disable-on-404") == 0) { |
| 4286 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 4287 | curproxy->options |= PR_O_DISABLE404; |
| 4288 | } |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 4289 | else if (strcmp(args[1], "send-state") == 0) { |
| 4290 | /* enable emission of the apparent state of a server in HTTP checks */ |
| 4291 | curproxy->options2 |= PR_O2_CHK_SNDST; |
| 4292 | } |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 4293 | else if (strcmp(args[1], "expect") == 0) { |
| 4294 | const char *ptr_arg; |
| 4295 | int cur_arg; |
| 4296 | |
| 4297 | if (curproxy->options2 & PR_O2_EXP_TYPE) { |
| 4298 | Alert("parsing [%s:%d] : '%s %s' already specified.\n", file, linenum, args[0], args[1]); |
| 4299 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4300 | goto out; |
| 4301 | } |
| 4302 | |
| 4303 | cur_arg = 2; |
| 4304 | /* consider exclamation marks, sole or at the beginning of a word */ |
| 4305 | while (*(ptr_arg = args[cur_arg])) { |
| 4306 | while (*ptr_arg == '!') { |
| 4307 | curproxy->options2 ^= PR_O2_EXP_INV; |
| 4308 | ptr_arg++; |
| 4309 | } |
| 4310 | if (*ptr_arg) |
| 4311 | break; |
| 4312 | cur_arg++; |
| 4313 | } |
| 4314 | /* now ptr_arg points to the beginning of a word past any possible |
| 4315 | * exclamation mark, and cur_arg is the argument which holds this word. |
| 4316 | */ |
| 4317 | if (strcmp(ptr_arg, "status") == 0) { |
| 4318 | if (!*(args[cur_arg + 1])) { |
| 4319 | Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 4320 | file, linenum, args[0], args[1], ptr_arg); |
| 4321 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4322 | goto out; |
| 4323 | } |
| 4324 | curproxy->options2 |= PR_O2_EXP_STS; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 4325 | free(curproxy->expect_str); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 4326 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
| 4327 | } |
| 4328 | else if (strcmp(ptr_arg, "string") == 0) { |
| 4329 | if (!*(args[cur_arg + 1])) { |
| 4330 | Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 4331 | file, linenum, args[0], args[1], ptr_arg); |
| 4332 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4333 | goto out; |
| 4334 | } |
| 4335 | curproxy->options2 |= PR_O2_EXP_STR; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 4336 | free(curproxy->expect_str); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 4337 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
| 4338 | } |
| 4339 | else if (strcmp(ptr_arg, "rstatus") == 0) { |
| 4340 | if (!*(args[cur_arg + 1])) { |
| 4341 | Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 4342 | file, linenum, args[0], args[1], ptr_arg); |
| 4343 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4344 | goto out; |
| 4345 | } |
| 4346 | curproxy->options2 |= PR_O2_EXP_RSTS; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 4347 | free(curproxy->expect_str); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 4348 | if (curproxy->expect_regex) { |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 4349 | regex_free(curproxy->expect_regex); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 4350 | free(curproxy->expect_regex); |
| 4351 | curproxy->expect_regex = NULL; |
| 4352 | } |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 4353 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 4354 | curproxy->expect_regex = calloc(1, sizeof(*curproxy->expect_regex)); |
| 4355 | error = NULL; |
| 4356 | if (!regex_comp(args[cur_arg + 1], curproxy->expect_regex, 1, 1, &error)) { |
| 4357 | Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s': %s.\n", |
| 4358 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1], error); |
| 4359 | free(error); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 4360 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4361 | goto out; |
| 4362 | } |
| 4363 | } |
| 4364 | else if (strcmp(ptr_arg, "rstring") == 0) { |
| 4365 | if (!*(args[cur_arg + 1])) { |
| 4366 | Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 4367 | file, linenum, args[0], args[1], ptr_arg); |
| 4368 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4369 | goto out; |
| 4370 | } |
| 4371 | curproxy->options2 |= PR_O2_EXP_RSTR; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 4372 | free(curproxy->expect_str); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 4373 | if (curproxy->expect_regex) { |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 4374 | regex_free(curproxy->expect_regex); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 4375 | free(curproxy->expect_regex); |
| 4376 | curproxy->expect_regex = NULL; |
| 4377 | } |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 4378 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 4379 | curproxy->expect_regex = calloc(1, sizeof(*curproxy->expect_regex)); |
| 4380 | error = NULL; |
| 4381 | if (!regex_comp(args[cur_arg + 1], curproxy->expect_regex, 1, 1, &error)) { |
| 4382 | Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s': %s.\n", |
| 4383 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1], error); |
| 4384 | free(error); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 4385 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4386 | goto out; |
| 4387 | } |
| 4388 | } |
| 4389 | else { |
| 4390 | Alert("parsing [%s:%d] : '%s %s' only supports [!] 'status', 'string', 'rstatus', 'rstring', found '%s'.\n", |
| 4391 | file, linenum, args[0], args[1], ptr_arg); |
| 4392 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4393 | goto out; |
| 4394 | } |
| 4395 | } |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 4396 | else { |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 4397 | 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] | 4398 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4399 | goto out; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 4400 | } |
| 4401 | } |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 4402 | else if (!strcmp(args[0], "tcp-check")) { |
| 4403 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 4404 | err_code |= ERR_WARN; |
| 4405 | |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 4406 | if (strcmp(args[1], "connect") == 0) { |
| 4407 | const char *ptr_arg; |
| 4408 | int cur_arg; |
| 4409 | struct tcpcheck_rule *tcpcheck; |
| 4410 | struct list *l; |
| 4411 | |
| 4412 | /* check if first rule is also a 'connect' action */ |
| 4413 | l = (struct list *)&curproxy->tcpcheck_rules; |
| 4414 | if (l->p != l->n) { |
| 4415 | tcpcheck = (struct tcpcheck_rule *)l->n; |
| 4416 | if (tcpcheck && tcpcheck->action != TCPCHK_ACT_CONNECT) { |
| 4417 | Alert("parsing [%s:%d] : first step MUST also be a 'connect' when there is a 'connect' step in the tcp-check ruleset.\n", |
| 4418 | file, linenum); |
| 4419 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4420 | goto out; |
| 4421 | } |
| 4422 | } |
| 4423 | |
| 4424 | cur_arg = 2; |
| 4425 | tcpcheck = (struct tcpcheck_rule *)calloc(1, sizeof(*tcpcheck)); |
| 4426 | tcpcheck->action = TCPCHK_ACT_CONNECT; |
| 4427 | |
| 4428 | /* parsing each parameters to fill up the rule */ |
| 4429 | while (*(ptr_arg = args[cur_arg])) { |
| 4430 | /* tcp port */ |
| 4431 | if (strcmp(args[cur_arg], "port") == 0) { |
| 4432 | if ( (atol(args[cur_arg + 1]) > 65535) || |
| 4433 | (atol(args[cur_arg + 1]) < 1) ){ |
| 4434 | Alert("parsing [%s:%d] : '%s %s %s' expects a valid TCP port (from range 1 to 65535), got %s.\n", |
| 4435 | file, linenum, args[0], args[1], "port", args[cur_arg + 1]); |
| 4436 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4437 | goto out; |
| 4438 | } |
| 4439 | tcpcheck->port = atol(args[cur_arg + 1]); |
| 4440 | cur_arg += 2; |
| 4441 | } |
| 4442 | /* send proxy protocol */ |
| 4443 | else if (strcmp(args[cur_arg], "send-proxy") == 0) { |
| 4444 | tcpcheck->conn_opts |= TCPCHK_OPT_SEND_PROXY; |
| 4445 | cur_arg++; |
| 4446 | } |
| 4447 | #ifdef USE_OPENSSL |
| 4448 | else if (strcmp(args[cur_arg], "ssl") == 0) { |
| 4449 | curproxy->options |= PR_O_TCPCHK_SSL; |
| 4450 | tcpcheck->conn_opts |= TCPCHK_OPT_SSL; |
| 4451 | cur_arg++; |
| 4452 | } |
| 4453 | #endif /* USE_OPENSSL */ |
| 4454 | else { |
| 4455 | #ifdef USE_OPENSSL |
| 4456 | Alert("parsing [%s:%d] : '%s %s' expects 'port', 'send-proxy' or 'ssl' but got '%s' as argument.\n", |
| 4457 | #else /* USE_OPENSSL */ |
| 4458 | Alert("parsing [%s:%d] : '%s %s' expects 'port', 'send-proxy' or but got '%s' as argument.\n", |
| 4459 | #endif /* USE_OPENSSL */ |
| 4460 | file, linenum, args[0], args[1], args[cur_arg]); |
| 4461 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4462 | goto out; |
| 4463 | } |
| 4464 | |
| 4465 | } |
| 4466 | |
| 4467 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 4468 | } |
| 4469 | else if (strcmp(args[1], "send") == 0) { |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 4470 | if (! *(args[2]) ) { |
| 4471 | /* SEND string expected */ |
| 4472 | Alert("parsing [%s:%d] : '%s %s %s' expects <STRING> as argument.\n", |
| 4473 | file, linenum, args[0], args[1], args[2]); |
| 4474 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4475 | goto out; |
| 4476 | } else { |
| 4477 | struct tcpcheck_rule *tcpcheck; |
| 4478 | |
| 4479 | tcpcheck = (struct tcpcheck_rule *)calloc(1, sizeof(*tcpcheck)); |
| 4480 | |
| 4481 | tcpcheck->action = TCPCHK_ACT_SEND; |
| 4482 | tcpcheck->string_len = strlen(args[2]); |
| 4483 | tcpcheck->string = strdup(args[2]); |
| 4484 | tcpcheck->expect_regex = NULL; |
| 4485 | |
| 4486 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 4487 | } |
| 4488 | } |
| 4489 | else if (strcmp(args[1], "send-binary") == 0) { |
| 4490 | if (! *(args[2]) ) { |
| 4491 | /* SEND binary string expected */ |
| 4492 | Alert("parsing [%s:%d] : '%s %s %s' expects <BINARY STRING> as argument.\n", |
| 4493 | file, linenum, args[0], args[1], args[2]); |
| 4494 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4495 | goto out; |
| 4496 | } else { |
| 4497 | struct tcpcheck_rule *tcpcheck; |
| 4498 | char *err = NULL; |
| 4499 | |
| 4500 | tcpcheck = (struct tcpcheck_rule *)calloc(1, sizeof(*tcpcheck)); |
| 4501 | |
| 4502 | tcpcheck->action = TCPCHK_ACT_SEND; |
| 4503 | if (parse_binary(args[2], &tcpcheck->string, &tcpcheck->string_len, &err) == 0) { |
| 4504 | Alert("parsing [%s:%d] : '%s %s %s' expects <BINARY STRING> as argument, but %s\n", |
| 4505 | file, linenum, args[0], args[1], args[2], err); |
| 4506 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4507 | goto out; |
| 4508 | } |
| 4509 | tcpcheck->expect_regex = NULL; |
| 4510 | |
| 4511 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 4512 | } |
| 4513 | } |
| 4514 | else if (strcmp(args[1], "expect") == 0) { |
| 4515 | const char *ptr_arg; |
| 4516 | int cur_arg; |
| 4517 | int inverse = 0; |
| 4518 | |
| 4519 | if (curproxy->options2 & PR_O2_EXP_TYPE) { |
| 4520 | Alert("parsing [%s:%d] : '%s %s' already specified.\n", file, linenum, args[0], args[1]); |
| 4521 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4522 | goto out; |
| 4523 | } |
| 4524 | |
| 4525 | cur_arg = 2; |
| 4526 | /* consider exclamation marks, sole or at the beginning of a word */ |
| 4527 | while (*(ptr_arg = args[cur_arg])) { |
| 4528 | while (*ptr_arg == '!') { |
| 4529 | inverse = !inverse; |
| 4530 | ptr_arg++; |
| 4531 | } |
| 4532 | if (*ptr_arg) |
| 4533 | break; |
| 4534 | cur_arg++; |
| 4535 | } |
| 4536 | /* now ptr_arg points to the beginning of a word past any possible |
| 4537 | * exclamation mark, and cur_arg is the argument which holds this word. |
| 4538 | */ |
| 4539 | if (strcmp(ptr_arg, "binary") == 0) { |
| 4540 | if (!*(args[cur_arg + 1])) { |
| 4541 | Alert("parsing [%s:%d] : '%s %s %s' expects <binary string> as an argument.\n", |
| 4542 | file, linenum, args[0], args[1], ptr_arg); |
| 4543 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4544 | goto out; |
| 4545 | } |
| 4546 | struct tcpcheck_rule *tcpcheck; |
| 4547 | char *err = NULL; |
| 4548 | |
| 4549 | tcpcheck = (struct tcpcheck_rule *)calloc(1, sizeof(*tcpcheck)); |
| 4550 | |
| 4551 | tcpcheck->action = TCPCHK_ACT_EXPECT; |
| 4552 | if (parse_binary(args[cur_arg + 1], &tcpcheck->string, &tcpcheck->string_len, &err) == 0) { |
| 4553 | Alert("parsing [%s:%d] : '%s %s %s' expects <BINARY STRING> as argument, but %s\n", |
| 4554 | file, linenum, args[0], args[1], args[2], err); |
| 4555 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4556 | goto out; |
| 4557 | } |
| 4558 | tcpcheck->expect_regex = NULL; |
| 4559 | tcpcheck->inverse = inverse; |
| 4560 | |
| 4561 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 4562 | } |
| 4563 | else if (strcmp(ptr_arg, "string") == 0) { |
| 4564 | if (!*(args[cur_arg + 1])) { |
| 4565 | Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 4566 | file, linenum, args[0], args[1], ptr_arg); |
| 4567 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4568 | goto out; |
| 4569 | } |
| 4570 | struct tcpcheck_rule *tcpcheck; |
| 4571 | |
| 4572 | tcpcheck = (struct tcpcheck_rule *)calloc(1, sizeof(*tcpcheck)); |
| 4573 | |
| 4574 | tcpcheck->action = TCPCHK_ACT_EXPECT; |
| 4575 | tcpcheck->string_len = strlen(args[cur_arg + 1]); |
| 4576 | tcpcheck->string = strdup(args[cur_arg + 1]); |
| 4577 | tcpcheck->expect_regex = NULL; |
| 4578 | tcpcheck->inverse = inverse; |
| 4579 | |
| 4580 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 4581 | } |
| 4582 | else if (strcmp(ptr_arg, "rstring") == 0) { |
| 4583 | if (!*(args[cur_arg + 1])) { |
| 4584 | Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 4585 | file, linenum, args[0], args[1], ptr_arg); |
| 4586 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4587 | goto out; |
| 4588 | } |
| 4589 | struct tcpcheck_rule *tcpcheck; |
| 4590 | |
| 4591 | tcpcheck = (struct tcpcheck_rule *)calloc(1, sizeof(*tcpcheck)); |
| 4592 | |
| 4593 | tcpcheck->action = TCPCHK_ACT_EXPECT; |
| 4594 | tcpcheck->string_len = 0; |
| 4595 | tcpcheck->string = NULL; |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 4596 | tcpcheck->expect_regex = calloc(1, sizeof(*tcpcheck->expect_regex)); |
| 4597 | error = NULL; |
| 4598 | if (!regex_comp(args[cur_arg + 1], tcpcheck->expect_regex, 1, 1, &error)) { |
| 4599 | Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s': %s.\n", |
| 4600 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1], error); |
| 4601 | free(error); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 4602 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4603 | goto out; |
| 4604 | } |
| 4605 | tcpcheck->inverse = inverse; |
| 4606 | |
| 4607 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 4608 | } |
| 4609 | else { |
| 4610 | Alert("parsing [%s:%d] : '%s %s' only supports [!] 'binary', 'string', 'rstring', found '%s'.\n", |
| 4611 | file, linenum, args[0], args[1], ptr_arg); |
| 4612 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4613 | goto out; |
| 4614 | } |
| 4615 | } |
| 4616 | else { |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 4617 | 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] | 4618 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4619 | goto out; |
| 4620 | } |
| 4621 | } |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 4622 | else if (!strcmp(args[0], "monitor")) { |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 4623 | if (curproxy == &defproxy) { |
| 4624 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4625 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4626 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 4627 | } |
| 4628 | |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 4629 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4630 | err_code |= ERR_WARN; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 4631 | |
| 4632 | if (strcmp(args[1], "fail") == 0) { |
| 4633 | /* add a condition to fail monitor requests */ |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 4634 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 4635 | Alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n", |
| 4636 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4637 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4638 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 4639 | } |
| 4640 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 4641 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 4642 | Alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition : %s.\n", |
| 4643 | file, linenum, args[0], args[1], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4644 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4645 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 4646 | } |
| 4647 | LIST_ADDQ(&curproxy->mon_fail_cond, &cond->list); |
| 4648 | } |
| 4649 | else { |
| 4650 | 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] | 4651 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4652 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 4653 | } |
| 4654 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4655 | #ifdef TPROXY |
| 4656 | else if (!strcmp(args[0], "transparent")) { |
| 4657 | /* enable transparent proxy connections */ |
| 4658 | curproxy->options |= PR_O_TRANSP; |
| 4659 | } |
| 4660 | #endif |
| 4661 | else if (!strcmp(args[0], "maxconn")) { /* maxconn */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4662 | 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] | 4663 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4664 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4665 | if (*(args[1]) == 0) { |
| 4666 | 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] | 4667 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4668 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4669 | } |
| 4670 | curproxy->maxconn = atol(args[1]); |
| 4671 | } |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 4672 | else if (!strcmp(args[0], "backlog")) { /* backlog */ |
| 4673 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4674 | err_code |= ERR_WARN; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 4675 | |
| 4676 | if (*(args[1]) == 0) { |
| 4677 | 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] | 4678 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4679 | goto out; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 4680 | } |
| 4681 | curproxy->backlog = atol(args[1]); |
| 4682 | } |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 4683 | else if (!strcmp(args[0], "fullconn")) { /* fullconn */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4684 | 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] | 4685 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4686 | |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 4687 | if (*(args[1]) == 0) { |
| 4688 | 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] | 4689 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4690 | goto out; |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 4691 | } |
| 4692 | curproxy->fullconn = atol(args[1]); |
| 4693 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4694 | else if (!strcmp(args[0], "grace")) { /* grace time (ms) */ |
| 4695 | if (*(args[1]) == 0) { |
| 4696 | 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] | 4697 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4698 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4699 | } |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4700 | err = parse_time_err(args[1], &val, TIME_UNIT_MS); |
| 4701 | if (err) { |
| 4702 | Alert("parsing [%s:%d] : unexpected character '%c' in grace time.\n", |
| 4703 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4704 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4705 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4706 | } |
| 4707 | curproxy->grace = val; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4708 | } |
| 4709 | else if (!strcmp(args[0], "dispatch")) { /* dispatch address */ |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4710 | struct sockaddr_storage *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4711 | int port1, port2; |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 4712 | struct protocol *proto; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4713 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4714 | if (curproxy == &defproxy) { |
| 4715 | 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] | 4716 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4717 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4718 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4719 | else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4720 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4721 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 4722 | sk = str2sa_range(args[1], &port1, &port2, &errmsg, NULL); |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4723 | if (!sk) { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 4724 | Alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 4725 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 4726 | goto out; |
| 4727 | } |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 4728 | |
| 4729 | proto = protocol_by_family(sk->ss_family); |
| 4730 | if (!proto || !proto->connect) { |
| 4731 | Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 4732 | file, linenum, args[0], args[1]); |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4733 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4734 | goto out; |
| 4735 | } |
| 4736 | |
| 4737 | if (port1 != port2) { |
| 4738 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'.\n", |
| 4739 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4740 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4741 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4742 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4743 | |
| 4744 | if (!port1) { |
| 4745 | Alert("parsing [%s:%d] : '%s' : missing port number in '%s', <addr:port> expected.\n", |
| 4746 | file, linenum, args[0], args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4747 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4748 | goto out; |
| 4749 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4750 | |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4751 | curproxy->dispatch_addr = *sk; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4752 | curproxy->options |= PR_O_DISPATCH; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4753 | } |
| 4754 | else if (!strcmp(args[0], "balance")) { /* set balancing with optional algorithm */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4755 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4756 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4757 | |
Willy Tarreau | a93c74b | 2012-05-08 18:14:39 +0200 | [diff] [blame] | 4758 | if (backend_parse_balance((const char **)args + 1, &errmsg, curproxy) < 0) { |
| 4759 | Alert("parsing [%s:%d] : %s %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4760 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4761 | goto out; |
Willy Tarreau | 2fcb500 | 2007-05-08 13:35:26 +0200 | [diff] [blame] | 4762 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4763 | } |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 4764 | else if (!strcmp(args[0], "hash-type")) { /* set hashing method */ |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 4765 | /** |
| 4766 | * The syntax for hash-type config element is |
| 4767 | * hash-type {map-based|consistent} [[<algo>] avalanche] |
| 4768 | * |
| 4769 | * The default hash function is sdbm for map-based and sdbm+avalanche for consistent. |
| 4770 | */ |
| 4771 | 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] | 4772 | |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 4773 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 4774 | err_code |= ERR_WARN; |
| 4775 | |
| 4776 | if (strcmp(args[1], "consistent") == 0) { /* use consistent hashing */ |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 4777 | curproxy->lbprm.algo |= BE_LB_HASH_CONS; |
| 4778 | } |
| 4779 | else if (strcmp(args[1], "map-based") == 0) { /* use map-based hashing */ |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 4780 | curproxy->lbprm.algo |= BE_LB_HASH_MAP; |
| 4781 | } |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 4782 | else if (strcmp(args[1], "avalanche") == 0) { |
| 4783 | 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]); |
| 4784 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4785 | goto out; |
Willy Tarreau | 798a39c | 2010-11-24 15:04:29 +0100 | [diff] [blame] | 4786 | } |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 4787 | else { |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 4788 | 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] | 4789 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4790 | goto out; |
| 4791 | } |
Bhaskar | 98634f0 | 2013-10-29 23:30:51 -0400 | [diff] [blame] | 4792 | |
| 4793 | /* set the hash function to use */ |
| 4794 | if (!*args[2]) { |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 4795 | /* the default algo is sdbm */ |
Bhaskar | 98634f0 | 2013-10-29 23:30:51 -0400 | [diff] [blame] | 4796 | curproxy->lbprm.algo |= BE_LB_HFCN_SDBM; |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 4797 | |
| 4798 | /* if consistent with no argument, then avalanche modifier is also applied */ |
| 4799 | if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS) |
| 4800 | curproxy->lbprm.algo |= BE_LB_HMOD_AVAL; |
Bhaskar | 98634f0 | 2013-10-29 23:30:51 -0400 | [diff] [blame] | 4801 | } else { |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 4802 | /* set the hash function */ |
| 4803 | if (!strcmp(args[2], "sdbm")) { |
| 4804 | curproxy->lbprm.algo |= BE_LB_HFCN_SDBM; |
| 4805 | } |
| 4806 | else if (!strcmp(args[2], "djb2")) { |
| 4807 | curproxy->lbprm.algo |= BE_LB_HFCN_DJB2; |
Willy Tarreau | a0f4271 | 2013-11-14 14:30:35 +0100 | [diff] [blame] | 4808 | } else if (!strcmp(args[2], "wt6")) { |
| 4809 | curproxy->lbprm.algo |= BE_LB_HFCN_WT6; |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 4810 | } |
| 4811 | else { |
Willy Tarreau | a0f4271 | 2013-11-14 14:30:35 +0100 | [diff] [blame] | 4812 | Alert("parsing [%s:%d] : '%s' only supports 'sdbm', 'djb2' or 'wt6' hash functions.\n", file, linenum, args[0]); |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 4813 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4814 | goto out; |
| 4815 | } |
| 4816 | |
| 4817 | /* set the hash modifier */ |
| 4818 | if (!strcmp(args[3], "avalanche")) { |
| 4819 | curproxy->lbprm.algo |= BE_LB_HMOD_AVAL; |
| 4820 | } |
| 4821 | else if (*args[3]) { |
| 4822 | Alert("parsing [%s:%d] : '%s' only supports 'avalanche' as a modifier for hash functions.\n", file, linenum, args[0]); |
| 4823 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4824 | goto out; |
| 4825 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4826 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 4827 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 4828 | else if (strcmp(args[0], "unique-id-format") == 0) { |
| 4829 | if (!*(args[1])) { |
| 4830 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 4831 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4832 | goto out; |
| 4833 | } |
William Lallemand | 3203ff4 | 2012-11-11 17:30:56 +0100 | [diff] [blame] | 4834 | if (*(args[2])) { |
| 4835 | Alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]); |
| 4836 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4837 | goto out; |
| 4838 | } |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 4839 | free(curproxy->conf.uniqueid_format_string); |
| 4840 | curproxy->conf.uniqueid_format_string = strdup(args[1]); |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 4841 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 4842 | free(curproxy->conf.uif_file); |
| 4843 | curproxy->conf.uif_file = strdup(curproxy->conf.args.file); |
| 4844 | curproxy->conf.uif_line = curproxy->conf.args.line; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4845 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 4846 | |
| 4847 | else if (strcmp(args[0], "unique-id-header") == 0) { |
| 4848 | if (!*(args[1])) { |
| 4849 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 4850 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4851 | goto out; |
| 4852 | } |
| 4853 | free(curproxy->header_unique_id); |
| 4854 | curproxy->header_unique_id = strdup(args[1]); |
| 4855 | } |
| 4856 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4857 | else if (strcmp(args[0], "log-format") == 0) { |
| 4858 | if (!*(args[1])) { |
| 4859 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 4860 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4861 | goto out; |
| 4862 | } |
William Lallemand | 3203ff4 | 2012-11-11 17:30:56 +0100 | [diff] [blame] | 4863 | if (*(args[2])) { |
| 4864 | Alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]); |
| 4865 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4866 | goto out; |
| 4867 | } |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 4868 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 4869 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 4870 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 4871 | curproxy->conf.logformat_string != clf_http_log_format) |
| 4872 | free(curproxy->conf.logformat_string); |
| 4873 | curproxy->conf.logformat_string = strdup(args[1]); |
| 4874 | |
| 4875 | free(curproxy->conf.lfs_file); |
| 4876 | curproxy->conf.lfs_file = strdup(curproxy->conf.args.file); |
| 4877 | curproxy->conf.lfs_line = curproxy->conf.args.line; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 4878 | |
| 4879 | /* get a chance to improve log-format error reporting by |
| 4880 | * reporting the correct line-number when possible. |
| 4881 | */ |
| 4882 | if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) { |
| 4883 | Warning("parsing [%s:%d] : backend '%s' : 'log-format' directive is ignored in backends.\n", |
| 4884 | file, linenum, curproxy->id); |
| 4885 | err_code |= ERR_WARN; |
| 4886 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4887 | } |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4888 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4889 | else if (!strcmp(args[0], "log") && kwm == KWM_NO) { |
| 4890 | /* delete previous herited or defined syslog servers */ |
| 4891 | struct logsrv *back; |
| 4892 | |
| 4893 | if (*(args[1]) != 0) { |
| 4894 | Alert("parsing [%s:%d]:%s : 'no log' does not expect arguments.\n", file, linenum, args[1]); |
| 4895 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4896 | goto out; |
| 4897 | } |
| 4898 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4899 | list_for_each_entry_safe(tmplogsrv, back, &curproxy->logsrvs, list) { |
| 4900 | LIST_DEL(&tmplogsrv->list); |
| 4901 | free(tmplogsrv); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4902 | } |
| 4903 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4904 | else if (!strcmp(args[0], "log")) { /* syslog server address */ |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4905 | struct logsrv *logsrv; |
| 4906 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4907 | if (*(args[1]) && *(args[2]) == 0 && !strcmp(args[1], "global")) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4908 | /* copy global.logrsvs linked list to the end of curproxy->logsrvs */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4909 | list_for_each_entry(tmplogsrv, &global.logsrvs, list) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4910 | struct logsrv *node = malloc(sizeof(struct logsrv)); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4911 | memcpy(node, tmplogsrv, sizeof(struct logsrv)); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4912 | LIST_INIT(&node->list); |
| 4913 | LIST_ADDQ(&curproxy->logsrvs, &node->list); |
| 4914 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4915 | } |
| 4916 | else if (*(args[1]) && *(args[2])) { |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 4917 | struct sockaddr_storage *sk; |
| 4918 | int port1, port2; |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 4919 | int arg = 0; |
| 4920 | int len = 0; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4921 | |
| 4922 | logsrv = calloc(1, sizeof(struct logsrv)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4923 | |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 4924 | /* just after the address, a length may be specified */ |
| 4925 | if (strcmp(args[arg+2], "len") == 0) { |
| 4926 | len = atoi(args[arg+3]); |
| 4927 | if (len < 80 || len > 65535) { |
| 4928 | Alert("parsing [%s:%d] : invalid log length '%s', must be between 80 and 65535.\n", |
| 4929 | file, linenum, args[arg+3]); |
| 4930 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4931 | goto out; |
| 4932 | } |
| 4933 | logsrv->maxlen = len; |
| 4934 | |
| 4935 | /* skip these two args */ |
| 4936 | arg += 2; |
| 4937 | } |
| 4938 | else |
| 4939 | logsrv->maxlen = MAX_SYSLOG_LEN; |
| 4940 | |
| 4941 | if (logsrv->maxlen > global.max_syslog_len) { |
| 4942 | global.max_syslog_len = logsrv->maxlen; |
| 4943 | logline = realloc(logline, global.max_syslog_len + 1); |
| 4944 | } |
| 4945 | |
| 4946 | logsrv->facility = get_log_facility(args[arg+2]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4947 | if (logsrv->facility < 0) { |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 4948 | 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] | 4949 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4950 | goto out; |
| 4951 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4952 | } |
| 4953 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4954 | logsrv->level = 7; /* max syslog level = debug */ |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 4955 | if (*(args[arg+3])) { |
| 4956 | logsrv->level = get_log_level(args[arg+3]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4957 | if (logsrv->level < 0) { |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 4958 | 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] | 4959 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4960 | goto out; |
| 4961 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4962 | } |
| 4963 | } |
| 4964 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4965 | logsrv->minlvl = 0; /* limit syslog level to this level (emerg) */ |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 4966 | if (*(args[arg+4])) { |
| 4967 | logsrv->minlvl = get_log_level(args[arg+4]); |
Willy Tarreau | f7f057b | 2013-01-24 00:31:24 +0100 | [diff] [blame] | 4968 | if (logsrv->minlvl < 0) { |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 4969 | 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] | 4970 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4971 | goto out; |
| 4972 | |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 4973 | } |
| 4974 | } |
| 4975 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 4976 | sk = str2sa_range(args[1], &port1, &port2, &errmsg, NULL); |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 4977 | if (!sk) { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 4978 | Alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 4979 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 4980 | goto out; |
| 4981 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4982 | |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 4983 | logsrv->addr = *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4984 | |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 4985 | if (sk->ss_family == AF_INET || sk->ss_family == AF_INET6) { |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4986 | if (port1 != port2) { |
| 4987 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 4988 | file, linenum, args[0], args[1]); |
| 4989 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4990 | goto out; |
| 4991 | } |
| 4992 | |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4993 | if (!port1) |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4994 | set_host_port(&logsrv->addr, SYSLOG_PORT); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4995 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4996 | |
| 4997 | LIST_ADDQ(&curproxy->logsrvs, &logsrv->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4998 | } |
| 4999 | else { |
| 5000 | Alert("parsing [%s:%d] : 'log' expects either <address[:port]> and <facility> or 'global' as arguments.\n", |
| 5001 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5002 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5003 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5004 | } |
| 5005 | } |
| 5006 | 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] | 5007 | int cur_arg; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5008 | int port1, port2; |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 5009 | struct sockaddr_storage *sk; |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 5010 | struct protocol *proto; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5011 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5012 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5013 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5014 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5015 | if (!*args[1]) { |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5016 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optionally '%s' <addr>, and '%s' <name>.\n", |
| 5017 | file, linenum, "source", "usesrc", "interface"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5018 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5019 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5020 | } |
Willy Tarreau | 368480c | 2009-03-01 08:27:21 +0100 | [diff] [blame] | 5021 | |
| 5022 | /* we must first clear any optional default setting */ |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 5023 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 5024 | free(curproxy->conn_src.iface_name); |
| 5025 | curproxy->conn_src.iface_name = NULL; |
| 5026 | curproxy->conn_src.iface_len = 0; |
Willy Tarreau | 368480c | 2009-03-01 08:27:21 +0100 | [diff] [blame] | 5027 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 5028 | sk = str2sa_range(args[1], &port1, &port2, &errmsg, NULL); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 5029 | if (!sk) { |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 5030 | Alert("parsing [%s:%d] : '%s %s' : %s\n", |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 5031 | file, linenum, args[0], args[1], errmsg); |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 5032 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 5033 | goto out; |
| 5034 | } |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 5035 | |
| 5036 | proto = protocol_by_family(sk->ss_family); |
| 5037 | if (!proto || !proto->connect) { |
| 5038 | 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] | 5039 | file, linenum, args[0], args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 5040 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5041 | goto out; |
| 5042 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5043 | |
| 5044 | if (port1 != port2) { |
| 5045 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 5046 | file, linenum, args[0], args[1]); |
| 5047 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5048 | goto out; |
| 5049 | } |
| 5050 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 5051 | curproxy->conn_src.source_addr = *sk; |
| 5052 | curproxy->conn_src.opts |= CO_SRC_BIND; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5053 | |
| 5054 | cur_arg = 2; |
| 5055 | while (*(args[cur_arg])) { |
| 5056 | if (!strcmp(args[cur_arg], "usesrc")) { /* address to use outside */ |
Pieter Baauw | d551fb5 | 2013-05-08 22:49:23 +0200 | [diff] [blame] | 5057 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_TRANSPARENT) |
| 5058 | #if !defined(CONFIG_HAP_TRANSPARENT) |
Willy Tarreau | 9cf8d3f | 2014-05-09 22:56:10 +0200 | [diff] [blame] | 5059 | if (!is_inet_addr(&curproxy->conn_src.source_addr)) { |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5060 | Alert("parsing [%s:%d] : '%s' requires an explicit 'source' address.\n", |
| 5061 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5062 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5063 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5064 | } |
| 5065 | #endif |
| 5066 | if (!*args[cur_arg + 1]) { |
| 5067 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n", |
| 5068 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5069 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5070 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5071 | } |
| 5072 | |
| 5073 | if (!strcmp(args[cur_arg + 1], "client")) { |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 5074 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 5075 | curproxy->conn_src.opts |= CO_SRC_TPROXY_CLI; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5076 | } else if (!strcmp(args[cur_arg + 1], "clientip")) { |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 5077 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 5078 | curproxy->conn_src.opts |= CO_SRC_TPROXY_CIP; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 5079 | } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) { |
| 5080 | char *name, *end; |
| 5081 | |
| 5082 | name = args[cur_arg+1] + 7; |
| 5083 | while (isspace(*name)) |
| 5084 | name++; |
| 5085 | |
| 5086 | end = name; |
| 5087 | while (*end && !isspace(*end) && *end != ',' && *end != ')') |
| 5088 | end++; |
| 5089 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 5090 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 5091 | curproxy->conn_src.opts |= CO_SRC_TPROXY_DYN; |
| 5092 | curproxy->conn_src.bind_hdr_name = calloc(1, end - name + 1); |
| 5093 | curproxy->conn_src.bind_hdr_len = end - name; |
| 5094 | memcpy(curproxy->conn_src.bind_hdr_name, name, end - name); |
| 5095 | curproxy->conn_src.bind_hdr_name[end-name] = '\0'; |
| 5096 | curproxy->conn_src.bind_hdr_occ = -1; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 5097 | |
| 5098 | /* now look for an occurrence number */ |
| 5099 | while (isspace(*end)) |
| 5100 | end++; |
| 5101 | if (*end == ',') { |
| 5102 | end++; |
| 5103 | name = end; |
| 5104 | if (*end == '-') |
| 5105 | end++; |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 5106 | while (isdigit((int)*end)) |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 5107 | end++; |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 5108 | curproxy->conn_src.bind_hdr_occ = strl2ic(name, end-name); |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 5109 | } |
| 5110 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 5111 | if (curproxy->conn_src.bind_hdr_occ < -MAX_HDR_HISTORY) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 5112 | Alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative" |
| 5113 | " occurrences values smaller than %d.\n", |
| 5114 | file, linenum, MAX_HDR_HISTORY); |
| 5115 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5116 | goto out; |
| 5117 | } |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5118 | } else { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 5119 | struct sockaddr_storage *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5120 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 5121 | sk = str2sa_range(args[cur_arg + 1], &port1, &port2, &errmsg, NULL); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 5122 | if (!sk) { |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 5123 | Alert("parsing [%s:%d] : '%s %s' : %s\n", |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 5124 | file, linenum, args[cur_arg], args[cur_arg+1], errmsg); |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 5125 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 5126 | goto out; |
| 5127 | } |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 5128 | |
| 5129 | proto = protocol_by_family(sk->ss_family); |
| 5130 | if (!proto || !proto->connect) { |
| 5131 | Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 5132 | file, linenum, args[cur_arg], args[cur_arg+1]); |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5133 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5134 | goto out; |
| 5135 | } |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 5136 | |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5137 | if (port1 != port2) { |
| 5138 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 5139 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 5140 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5141 | goto out; |
| 5142 | } |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 5143 | curproxy->conn_src.tproxy_addr = *sk; |
| 5144 | curproxy->conn_src.opts |= CO_SRC_TPROXY_ADDR; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5145 | } |
| 5146 | global.last_checks |= LSTCHK_NETADM; |
Pieter Baauw | d551fb5 | 2013-05-08 22:49:23 +0200 | [diff] [blame] | 5147 | #if !defined(CONFIG_HAP_TRANSPARENT) |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5148 | global.last_checks |= LSTCHK_CTTPROXY; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 5149 | #endif |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5150 | #else /* no TPROXY support */ |
| 5151 | 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] | 5152 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5153 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5154 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5155 | #endif |
| 5156 | cur_arg += 2; |
| 5157 | continue; |
Willy Tarreau | 77074d5 | 2006-11-12 23:57:19 +0100 | [diff] [blame] | 5158 | } |
| 5159 | |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5160 | if (!strcmp(args[cur_arg], "interface")) { /* specifically bind to this interface */ |
| 5161 | #ifdef SO_BINDTODEVICE |
| 5162 | if (!*args[cur_arg + 1]) { |
| 5163 | Alert("parsing [%s:%d] : '%s' : missing interface name.\n", |
| 5164 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5165 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5166 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5167 | } |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 5168 | free(curproxy->conn_src.iface_name); |
| 5169 | curproxy->conn_src.iface_name = strdup(args[cur_arg + 1]); |
| 5170 | curproxy->conn_src.iface_len = strlen(curproxy->conn_src.iface_name); |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5171 | global.last_checks |= LSTCHK_NETADM; |
| 5172 | #else |
| 5173 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 5174 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5175 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5176 | goto out; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 5177 | #endif |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5178 | cur_arg += 2; |
| 5179 | continue; |
| 5180 | } |
| 5181 | 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] | 5182 | file, linenum, args[0], "interface", "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5183 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5184 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 5185 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5186 | } |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 5187 | else if (!strcmp(args[0], "usesrc")) { /* address to use outside: needs "source" first */ |
| 5188 | Alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n", |
| 5189 | file, linenum, "usesrc", "source"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5190 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5191 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 5192 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5193 | 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] | 5194 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5195 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 5196 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5197 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5198 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5199 | } |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5200 | |
| 5201 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5202 | SMP_OPT_DIR_REQ, ACT_REPLACE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5203 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5204 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5205 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5206 | } |
| 5207 | else if (!strcmp(args[0], "reqdel")) { /* delete request header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5208 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5209 | SMP_OPT_DIR_REQ, ACT_REMOVE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5210 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5211 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5212 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5213 | } |
| 5214 | 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] | 5215 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5216 | SMP_OPT_DIR_REQ, ACT_DENY, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5217 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5218 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5219 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5220 | } |
| 5221 | 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] | 5222 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5223 | SMP_OPT_DIR_REQ, ACT_PASS, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5224 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5225 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5226 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5227 | } |
| 5228 | 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] | 5229 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5230 | SMP_OPT_DIR_REQ, ACT_ALLOW, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5231 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5232 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5233 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5234 | } |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 5235 | 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] | 5236 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5237 | SMP_OPT_DIR_REQ, ACT_TARPIT, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5238 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5239 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5240 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 5241 | } |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5242 | 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] | 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_SETBE, 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 | 40bac83 | 2014-04-28 22:37:06 +0200 | [diff] [blame] | 5248 | |
| 5249 | if (!already_warned(WARN_REQSETBE_DEPRECATED)) |
| 5250 | 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] | 5251 | } |
| 5252 | 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] | 5253 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5254 | SMP_OPT_DIR_REQ, ACT_SETBE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5255 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5256 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5257 | goto out; |
Willy Tarreau | 40bac83 | 2014-04-28 22:37:06 +0200 | [diff] [blame] | 5258 | |
| 5259 | if (!already_warned(WARN_REQSETBE_DEPRECATED)) |
| 5260 | 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] | 5261 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5262 | 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] | 5263 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5264 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 5265 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5266 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5267 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5268 | } |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5269 | |
| 5270 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5271 | SMP_OPT_DIR_REQ, ACT_REPLACE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5272 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5273 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5274 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5275 | } |
| 5276 | 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] | 5277 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5278 | SMP_OPT_DIR_REQ, ACT_REMOVE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5279 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5280 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5281 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5282 | } |
| 5283 | 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] | 5284 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5285 | SMP_OPT_DIR_REQ, ACT_DENY, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5286 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5287 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5288 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5289 | } |
| 5290 | 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] | 5291 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5292 | SMP_OPT_DIR_REQ, ACT_PASS, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5293 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5294 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5295 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5296 | } |
| 5297 | 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] | 5298 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5299 | SMP_OPT_DIR_REQ, ACT_ALLOW, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5300 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5301 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5302 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5303 | } |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 5304 | 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] | 5305 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5306 | SMP_OPT_DIR_REQ, ACT_TARPIT, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5307 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5308 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5309 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 5310 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5311 | else if (!strcmp(args[0], "reqadd")) { /* add request header */ |
Willy Tarreau | f4f0412 | 2010-01-28 18:10:50 +0100 | [diff] [blame] | 5312 | struct cond_wordlist *wl; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5313 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5314 | if (curproxy == &defproxy) { |
| 5315 | 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] | 5316 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5317 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5318 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5319 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5320 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5321 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5322 | if (*(args[1]) == 0) { |
| 5323 | 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] | 5324 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5325 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5326 | } |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5327 | |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 5328 | if ((strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0)) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 5329 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args+2, &errmsg)) == NULL) { |
| 5330 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 5331 | file, linenum, args[0], errmsg); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 5332 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5333 | goto out; |
| 5334 | } |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 5335 | err_code |= warnif_cond_conflicts(cond, |
| 5336 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 5337 | file, linenum); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 5338 | } |
| 5339 | else if (*args[2]) { |
| 5340 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 5341 | file, linenum, args[0], args[2]); |
| 5342 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5343 | goto out; |
| 5344 | } |
| 5345 | |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5346 | wl = calloc(1, sizeof(*wl)); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 5347 | wl->cond = cond; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5348 | wl->s = strdup(args[1]); |
| 5349 | LIST_ADDQ(&curproxy->req_add, &wl->list); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 5350 | warnif_misplaced_reqadd(curproxy, file, linenum, args[0]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5351 | } |
| 5352 | 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] | 5353 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5354 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 5355 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5356 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5357 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5358 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5359 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5360 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5361 | SMP_OPT_DIR_RES, ACT_REPLACE, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5362 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5363 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5364 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5365 | } |
| 5366 | else if (!strcmp(args[0], "rspdel")) { /* delete response header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5367 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5368 | SMP_OPT_DIR_RES, ACT_REMOVE, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5369 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5370 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5371 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5372 | } |
| 5373 | else if (!strcmp(args[0], "rspdeny")) { /* block response header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5374 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5375 | SMP_OPT_DIR_RES, ACT_DENY, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5376 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5377 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5378 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5379 | } |
| 5380 | 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] | 5381 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5382 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 5383 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5384 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5385 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5386 | } |
| 5387 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5388 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5389 | SMP_OPT_DIR_RES, ACT_REPLACE, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5390 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5391 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5392 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5393 | } |
| 5394 | 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] | 5395 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5396 | SMP_OPT_DIR_RES, ACT_REMOVE, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5397 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5398 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5399 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5400 | } |
| 5401 | 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] | 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_DENY, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5404 | args[0], args[1], NULL, (const char **)args+2); |
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], "rspadd")) { /* add response header */ |
Willy Tarreau | f4f0412 | 2010-01-28 18:10:50 +0100 | [diff] [blame] | 5409 | struct cond_wordlist *wl; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5410 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5411 | if (curproxy == &defproxy) { |
| 5412 | 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] | 5413 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5414 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5415 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5416 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5417 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5418 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5419 | if (*(args[1]) == 0) { |
| 5420 | 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] | 5421 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5422 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5423 | } |
| 5424 | |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5425 | if ((strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0)) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 5426 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args+2, &errmsg)) == NULL) { |
| 5427 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 5428 | file, linenum, args[0], errmsg); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5429 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5430 | goto out; |
| 5431 | } |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 5432 | err_code |= warnif_cond_conflicts(cond, |
| 5433 | (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR, |
| 5434 | file, linenum); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5435 | } |
| 5436 | else if (*args[2]) { |
| 5437 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 5438 | file, linenum, args[0], args[2]); |
| 5439 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5440 | goto out; |
| 5441 | } |
| 5442 | |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5443 | wl = calloc(1, sizeof(*wl)); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5444 | wl->cond = cond; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5445 | wl->s = strdup(args[1]); |
| 5446 | LIST_ADDQ(&curproxy->rsp_add, &wl->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5447 | } |
| 5448 | else if (!strcmp(args[0], "errorloc") || |
| 5449 | !strcmp(args[0], "errorloc302") || |
| 5450 | !strcmp(args[0], "errorloc303")) { /* error location */ |
| 5451 | int errnum, errlen; |
| 5452 | char *err; |
| 5453 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5454 | if (warnifnotcap(curproxy, PR_CAP_FE | PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5455 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5456 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5457 | if (*(args[2]) == 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 5458 | Alert("parsing [%s:%d] : <%s> expects <status_code> and <url> as arguments.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5459 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5460 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5461 | } |
| 5462 | |
| 5463 | errnum = atol(args[1]); |
| 5464 | if (!strcmp(args[0], "errorloc303")) { |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 5465 | errlen = strlen(HTTP_303) + strlen(args[2]) + 5; |
| 5466 | err = malloc(errlen); |
| 5467 | 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] | 5468 | } else { |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 5469 | errlen = strlen(HTTP_302) + strlen(args[2]) + 5; |
| 5470 | err = malloc(errlen); |
| 5471 | 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] | 5472 | } |
| 5473 | |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 5474 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) { |
| 5475 | if (http_err_codes[rc] == errnum) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 5476 | chunk_destroy(&curproxy->errmsg[rc]); |
| 5477 | chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 5478 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5479 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5480 | } |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 5481 | |
| 5482 | if (rc >= HTTP_ERR_SIZE) { |
| 5483 | Warning("parsing [%s:%d] : status code %d not handled, error relocation will be ignored.\n", |
| 5484 | file, linenum, errnum); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5485 | free(err); |
| 5486 | } |
| 5487 | } |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5488 | else if (!strcmp(args[0], "errorfile")) { /* error message from a file */ |
| 5489 | int errnum, errlen, fd; |
| 5490 | char *err; |
| 5491 | struct stat stat; |
| 5492 | |
| 5493 | 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] | 5494 | err_code |= ERR_WARN; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5495 | |
| 5496 | if (*(args[2]) == 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 5497 | 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] | 5498 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5499 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5500 | } |
| 5501 | |
| 5502 | fd = open(args[2], O_RDONLY); |
| 5503 | if ((fd < 0) || (fstat(fd, &stat) < 0)) { |
| 5504 | Alert("parsing [%s:%d] : error opening file <%s> for custom error message <%s>.\n", |
| 5505 | file, linenum, args[2], args[1]); |
| 5506 | if (fd >= 0) |
| 5507 | close(fd); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5508 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5509 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5510 | } |
| 5511 | |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 5512 | if (stat.st_size <= global.tune.bufsize) { |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5513 | errlen = stat.st_size; |
| 5514 | } else { |
| 5515 | 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] | 5516 | file, linenum, args[2], global.tune.bufsize); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5517 | err_code |= ERR_WARN; |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 5518 | errlen = global.tune.bufsize; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5519 | } |
| 5520 | |
| 5521 | err = malloc(errlen); /* malloc() must succeed during parsing */ |
| 5522 | errnum = read(fd, err, errlen); |
| 5523 | if (errnum != errlen) { |
| 5524 | Alert("parsing [%s:%d] : error reading file <%s> for custom error message <%s>.\n", |
| 5525 | file, linenum, args[2], args[1]); |
| 5526 | close(fd); |
| 5527 | free(err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5528 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5529 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5530 | } |
| 5531 | close(fd); |
| 5532 | |
| 5533 | errnum = atol(args[1]); |
| 5534 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) { |
| 5535 | if (http_err_codes[rc] == errnum) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 5536 | chunk_destroy(&curproxy->errmsg[rc]); |
| 5537 | chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen); |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5538 | break; |
| 5539 | } |
| 5540 | } |
| 5541 | |
| 5542 | if (rc >= HTTP_ERR_SIZE) { |
| 5543 | Warning("parsing [%s:%d] : status code %d not handled, error customization will be ignored.\n", |
| 5544 | file, linenum, errnum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5545 | err_code |= ERR_WARN; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5546 | free(err); |
| 5547 | } |
| 5548 | } |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5549 | else if (!strcmp(args[0], "compression")) { |
| 5550 | struct comp *comp; |
| 5551 | if (curproxy->comp == NULL) { |
| 5552 | comp = calloc(1, sizeof(struct comp)); |
| 5553 | curproxy->comp = comp; |
| 5554 | } else { |
| 5555 | comp = curproxy->comp; |
| 5556 | } |
| 5557 | |
| 5558 | if (!strcmp(args[1], "algo")) { |
| 5559 | int cur_arg; |
William Lallemand | 8b52bb3 | 2012-11-16 18:06:41 +0100 | [diff] [blame] | 5560 | struct comp_ctx *ctx; |
William Lallemand | 552df67 | 2012-11-07 13:21:47 +0100 | [diff] [blame] | 5561 | |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5562 | cur_arg = 2; |
| 5563 | if (!*args[cur_arg]) { |
| 5564 | Alert("parsing [%s:%d] : '%s' expects <algorithm>\n", |
| 5565 | file, linenum, args[0]); |
| 5566 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5567 | goto out; |
| 5568 | } |
| 5569 | while (*(args[cur_arg])) { |
| 5570 | if (comp_append_algo(comp, args[cur_arg]) < 0) { |
| 5571 | Alert("parsing [%s:%d] : '%s' : '%s' is not a supported algorithm.\n", |
| 5572 | file, linenum, args[0], args[cur_arg]); |
| 5573 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5574 | goto out; |
| 5575 | } |
William Lallemand | 552df67 | 2012-11-07 13:21:47 +0100 | [diff] [blame] | 5576 | if (curproxy->comp->algos->init(&ctx, 9) == 0) { |
| 5577 | curproxy->comp->algos->end(&ctx); |
| 5578 | } else { |
| 5579 | Alert("parsing [%s:%d] : '%s' : Can't init '%s' algorithm.\n", |
| 5580 | file, linenum, args[0], args[cur_arg]); |
| 5581 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5582 | goto out; |
| 5583 | } |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5584 | cur_arg ++; |
| 5585 | continue; |
| 5586 | } |
| 5587 | } |
Willy Tarreau | 70737d1 | 2012-10-27 00:34:28 +0200 | [diff] [blame] | 5588 | else if (!strcmp(args[1], "offload")) { |
| 5589 | comp->offload = 1; |
| 5590 | } |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5591 | else if (!strcmp(args[1], "type")) { |
| 5592 | int cur_arg; |
| 5593 | cur_arg = 2; |
| 5594 | if (!*args[cur_arg]) { |
| 5595 | Alert("parsing [%s:%d] : '%s' expects <type>\n", |
| 5596 | file, linenum, args[0]); |
| 5597 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5598 | goto out; |
| 5599 | } |
| 5600 | while (*(args[cur_arg])) { |
| 5601 | comp_append_type(comp, args[cur_arg]); |
| 5602 | cur_arg ++; |
| 5603 | continue; |
| 5604 | } |
| 5605 | } |
| 5606 | else { |
Willy Tarreau | 70737d1 | 2012-10-27 00:34:28 +0200 | [diff] [blame] | 5607 | Alert("parsing [%s:%d] : '%s' expects 'algo', 'type' or 'offload'\n", |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5608 | file, linenum, args[0]); |
| 5609 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5610 | goto out; |
| 5611 | } |
| 5612 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5613 | else { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 5614 | struct cfg_kw_list *kwl; |
| 5615 | int index; |
| 5616 | |
| 5617 | list_for_each_entry(kwl, &cfg_keywords.list, list) { |
| 5618 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 5619 | if (kwl->kw[index].section != CFG_LISTEN) |
| 5620 | continue; |
| 5621 | if (strcmp(kwl->kw[index].kw, args[0]) == 0) { |
| 5622 | /* prepare error message just in case */ |
Willy Tarreau | 28a47d6 | 2012-09-18 20:02:48 +0200 | [diff] [blame] | 5623 | 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] | 5624 | if (rc < 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 5625 | Alert("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5626 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5627 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 5628 | } |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 5629 | else if (rc > 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 5630 | Warning("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5631 | err_code |= ERR_WARN; |
| 5632 | goto out; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 5633 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5634 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 5635 | } |
| 5636 | } |
| 5637 | } |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5638 | |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5639 | 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] | 5640 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5641 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5642 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5643 | out: |
Willy Tarreau | f4068b6 | 2012-05-08 17:37:49 +0200 | [diff] [blame] | 5644 | free(errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5645 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5646 | } |
| 5647 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5648 | int |
KOVACS Krisztian | b3e54fe | 2014-11-17 15:11:45 +0100 | [diff] [blame] | 5649 | cfg_parse_netns(const char *file, int linenum, char **args, int kwm) |
| 5650 | { |
| 5651 | #ifdef CONFIG_HAP_NS |
| 5652 | const char *err; |
| 5653 | const char *item = args[0]; |
| 5654 | |
| 5655 | if (!strcmp(item, "namespace_list")) { |
| 5656 | return 0; |
| 5657 | } |
| 5658 | else if (!strcmp(item, "namespace")) { |
| 5659 | size_t idx = 1; |
| 5660 | const char *current; |
| 5661 | while (*(current = args[idx++])) { |
| 5662 | err = invalid_char(current); |
| 5663 | if (err) { |
| 5664 | Alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 5665 | file, linenum, *err, item, current); |
| 5666 | return ERR_ALERT | ERR_FATAL; |
| 5667 | } |
| 5668 | |
| 5669 | if (netns_store_lookup(current, strlen(current))) { |
| 5670 | Alert("parsing [%s:%d]: Namespace '%s' is already added.\n", |
| 5671 | file, linenum, current); |
| 5672 | return ERR_ALERT | ERR_FATAL; |
| 5673 | } |
| 5674 | if (!netns_store_insert(current)) { |
| 5675 | Alert("parsing [%s:%d]: Cannot open namespace '%s'.\n", |
| 5676 | file, linenum, current); |
| 5677 | return ERR_ALERT | ERR_FATAL; |
| 5678 | } |
| 5679 | } |
| 5680 | } |
| 5681 | |
| 5682 | return 0; |
| 5683 | #else |
| 5684 | Alert("parsing [%s:%d]: namespace support is not compiled in.", |
| 5685 | file, linenum); |
| 5686 | return ERR_ALERT | ERR_FATAL; |
| 5687 | #endif |
| 5688 | } |
| 5689 | |
| 5690 | int |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5691 | cfg_parse_users(const char *file, int linenum, char **args, int kwm) |
| 5692 | { |
| 5693 | |
| 5694 | int err_code = 0; |
| 5695 | const char *err; |
| 5696 | |
| 5697 | if (!strcmp(args[0], "userlist")) { /* new userlist */ |
| 5698 | struct userlist *newul; |
| 5699 | |
| 5700 | if (!*args[1]) { |
| 5701 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 5702 | file, linenum, args[0]); |
| 5703 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5704 | goto out; |
| 5705 | } |
| 5706 | |
| 5707 | err = invalid_char(args[1]); |
| 5708 | if (err) { |
| 5709 | Alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 5710 | file, linenum, *err, args[0], args[1]); |
| 5711 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5712 | goto out; |
| 5713 | } |
| 5714 | |
| 5715 | for (newul = userlist; newul; newul = newul->next) |
| 5716 | if (!strcmp(newul->name, args[1])) { |
| 5717 | Warning("parsing [%s:%d]: ignoring duplicated userlist '%s'.\n", |
| 5718 | file, linenum, args[1]); |
| 5719 | err_code |= ERR_WARN; |
| 5720 | goto out; |
| 5721 | } |
| 5722 | |
| 5723 | newul = (struct userlist *)calloc(1, sizeof(struct userlist)); |
| 5724 | if (!newul) { |
| 5725 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 5726 | err_code |= ERR_ALERT | ERR_ABORT; |
| 5727 | goto out; |
| 5728 | } |
| 5729 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5730 | newul->name = strdup(args[1]); |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 5731 | if (!newul->name) { |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5732 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 5733 | err_code |= ERR_ALERT | ERR_ABORT; |
| 5734 | goto out; |
| 5735 | } |
| 5736 | |
| 5737 | newul->next = userlist; |
| 5738 | userlist = newul; |
| 5739 | |
| 5740 | } else if (!strcmp(args[0], "group")) { /* new group */ |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 5741 | int cur_arg; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5742 | const char *err; |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 5743 | struct auth_groups *ag; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5744 | |
| 5745 | if (!*args[1]) { |
| 5746 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 5747 | file, linenum, args[0]); |
| 5748 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5749 | goto out; |
| 5750 | } |
| 5751 | |
| 5752 | err = invalid_char(args[1]); |
| 5753 | if (err) { |
| 5754 | Alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 5755 | file, linenum, *err, args[0], args[1]); |
| 5756 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5757 | goto out; |
| 5758 | } |
| 5759 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 5760 | for (ag = userlist->groups; ag; ag = ag->next) |
| 5761 | if (!strcmp(ag->name, args[1])) { |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5762 | Warning("parsing [%s:%d]: ignoring duplicated group '%s' in userlist '%s'.\n", |
| 5763 | file, linenum, args[1], userlist->name); |
| 5764 | err_code |= ERR_ALERT; |
| 5765 | goto out; |
| 5766 | } |
| 5767 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 5768 | ag = calloc(1, sizeof(*ag)); |
| 5769 | if (!ag) { |
| 5770 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 5771 | err_code |= ERR_ALERT | ERR_ABORT; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5772 | goto out; |
| 5773 | } |
| 5774 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 5775 | ag->name = strdup(args[1]); |
| 5776 | if (!ag) { |
| 5777 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 5778 | err_code |= ERR_ALERT | ERR_ABORT; |
| 5779 | goto out; |
| 5780 | } |
| 5781 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5782 | cur_arg = 2; |
| 5783 | |
| 5784 | while (*args[cur_arg]) { |
| 5785 | if (!strcmp(args[cur_arg], "users")) { |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 5786 | ag->groupusers = strdup(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5787 | cur_arg += 2; |
| 5788 | continue; |
| 5789 | } else { |
| 5790 | Alert("parsing [%s:%d]: '%s' only supports 'users' option.\n", |
| 5791 | file, linenum, args[0]); |
| 5792 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5793 | goto out; |
| 5794 | } |
| 5795 | } |
| 5796 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 5797 | ag->next = userlist->groups; |
| 5798 | userlist->groups = ag; |
| 5799 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5800 | } else if (!strcmp(args[0], "user")) { /* new user */ |
| 5801 | struct auth_users *newuser; |
| 5802 | int cur_arg; |
| 5803 | |
| 5804 | if (!*args[1]) { |
| 5805 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 5806 | file, linenum, args[0]); |
| 5807 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5808 | goto out; |
| 5809 | } |
| 5810 | |
| 5811 | for (newuser = userlist->users; newuser; newuser = newuser->next) |
| 5812 | if (!strcmp(newuser->user, args[1])) { |
| 5813 | Warning("parsing [%s:%d]: ignoring duplicated user '%s' in userlist '%s'.\n", |
| 5814 | file, linenum, args[1], userlist->name); |
| 5815 | err_code |= ERR_ALERT; |
| 5816 | goto out; |
| 5817 | } |
| 5818 | |
| 5819 | newuser = (struct auth_users *)calloc(1, sizeof(struct auth_users)); |
| 5820 | if (!newuser) { |
| 5821 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 5822 | err_code |= ERR_ALERT | ERR_ABORT; |
| 5823 | goto out; |
| 5824 | } |
| 5825 | |
| 5826 | newuser->user = strdup(args[1]); |
| 5827 | |
| 5828 | newuser->next = userlist->users; |
| 5829 | userlist->users = newuser; |
| 5830 | |
| 5831 | cur_arg = 2; |
| 5832 | |
| 5833 | while (*args[cur_arg]) { |
| 5834 | if (!strcmp(args[cur_arg], "password")) { |
Cyril Bonté | 1a0191d | 2014-08-29 20:20:02 +0200 | [diff] [blame] | 5835 | #ifdef CONFIG_HAP_CRYPT |
| 5836 | if (!crypt("", args[cur_arg + 1])) { |
| 5837 | Alert("parsing [%s:%d]: the encrypted password used for user '%s' is not supported by crypt(3).\n", |
| 5838 | file, linenum, newuser->user); |
| 5839 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5840 | goto out; |
| 5841 | } |
| 5842 | #else |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5843 | Warning("parsing [%s:%d]: no crypt(3) support compiled, encrypted passwords will not work.\n", |
| 5844 | file, linenum); |
| 5845 | err_code |= ERR_ALERT; |
| 5846 | #endif |
| 5847 | newuser->pass = strdup(args[cur_arg + 1]); |
| 5848 | cur_arg += 2; |
| 5849 | continue; |
| 5850 | } else if (!strcmp(args[cur_arg], "insecure-password")) { |
| 5851 | newuser->pass = strdup(args[cur_arg + 1]); |
| 5852 | newuser->flags |= AU_O_INSECURE; |
| 5853 | cur_arg += 2; |
| 5854 | continue; |
| 5855 | } else if (!strcmp(args[cur_arg], "groups")) { |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 5856 | newuser->u.groups_names = strdup(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5857 | cur_arg += 2; |
| 5858 | continue; |
| 5859 | } else { |
| 5860 | Alert("parsing [%s:%d]: '%s' only supports 'password', 'insecure-password' and 'groups' options.\n", |
| 5861 | file, linenum, args[0]); |
| 5862 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5863 | goto out; |
| 5864 | } |
| 5865 | } |
| 5866 | } else { |
| 5867 | Alert("parsing [%s:%d]: unknown keyword '%s' in '%s' section\n", file, linenum, args[0], "users"); |
| 5868 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5869 | } |
| 5870 | |
| 5871 | out: |
| 5872 | return err_code; |
| 5873 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5874 | |
| 5875 | /* |
| 5876 | * This function reads and parses the configuration file given in the argument. |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5877 | * Returns the error code, 0 if OK, or any combination of : |
| 5878 | * - ERR_ABORT: must abort ASAP |
| 5879 | * - ERR_FATAL: we can continue parsing but not start the service |
| 5880 | * - ERR_WARN: a warning has been emitted |
| 5881 | * - ERR_ALERT: an alert has been emitted |
| 5882 | * Only the two first ones can stop processing, the two others are just |
| 5883 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5884 | */ |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 5885 | int readcfgfile(const char *file) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5886 | { |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5887 | char thisline[LINESIZE]; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5888 | FILE *f; |
| 5889 | int linenum = 0; |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5890 | int err_code = 0; |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 5891 | struct cfg_section *cs = NULL; |
| 5892 | struct cfg_section *ics; |
| 5893 | |
| 5894 | /* Register internal sections */ |
| 5895 | if (!cfg_register_section("listen", cfg_parse_listen) || |
| 5896 | !cfg_register_section("frontend", cfg_parse_listen) || |
| 5897 | !cfg_register_section("backend", cfg_parse_listen) || |
| 5898 | !cfg_register_section("ruleset", cfg_parse_listen) || |
| 5899 | !cfg_register_section("defaults", cfg_parse_listen) || |
| 5900 | !cfg_register_section("global", cfg_parse_global) || |
| 5901 | !cfg_register_section("userlist", cfg_parse_users) || |
KOVACS Krisztian | b3e54fe | 2014-11-17 15:11:45 +0100 | [diff] [blame] | 5902 | !cfg_register_section("peers", cfg_parse_peers) || |
| 5903 | !cfg_register_section("namespace_list", cfg_parse_netns)) |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 5904 | return -1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5905 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5906 | if ((f=fopen(file,"r")) == NULL) |
| 5907 | return -1; |
| 5908 | |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5909 | while (fgets(thisline, sizeof(thisline), f) != NULL) { |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 5910 | int arg, kwm = KWM_STD; |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5911 | char *end; |
| 5912 | char *args[MAX_LINE_ARGS + 1]; |
| 5913 | char *line = thisline; |
| 5914 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5915 | linenum++; |
| 5916 | |
| 5917 | end = line + strlen(line); |
| 5918 | |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5919 | if (end-line == sizeof(thisline)-1 && *(end-1) != '\n') { |
| 5920 | /* Check if we reached the limit and the last char is not \n. |
| 5921 | * Watch out for the last line without the terminating '\n'! |
| 5922 | */ |
| 5923 | Alert("parsing [%s:%d]: line too long, limit: %d.\n", |
Willy Tarreau | 5e4a6f1 | 2009-04-11 19:42:49 +0200 | [diff] [blame] | 5924 | file, linenum, (int)sizeof(thisline)-1); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5925 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5926 | } |
| 5927 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5928 | /* skip leading spaces */ |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 5929 | while (isspace((unsigned char)*line)) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5930 | line++; |
| 5931 | |
| 5932 | arg = 0; |
| 5933 | args[arg] = line; |
| 5934 | |
| 5935 | while (*line && arg < MAX_LINE_ARGS) { |
| 5936 | /* first, we'll replace \\, \<space>, \#, \r, \n, \t, \xXX with their |
| 5937 | * C equivalent value. Other combinations left unchanged (eg: \1). |
| 5938 | */ |
| 5939 | if (*line == '\\') { |
| 5940 | int skip = 0; |
| 5941 | if (line[1] == ' ' || line[1] == '\\' || line[1] == '#') { |
| 5942 | *line = line[1]; |
| 5943 | skip = 1; |
| 5944 | } |
| 5945 | else if (line[1] == 'r') { |
| 5946 | *line = '\r'; |
| 5947 | skip = 1; |
| 5948 | } |
| 5949 | else if (line[1] == 'n') { |
| 5950 | *line = '\n'; |
| 5951 | skip = 1; |
| 5952 | } |
| 5953 | else if (line[1] == 't') { |
| 5954 | *line = '\t'; |
| 5955 | skip = 1; |
| 5956 | } |
| 5957 | else if (line[1] == 'x') { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5958 | if ((line + 3 < end) && ishex(line[2]) && ishex(line[3])) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5959 | unsigned char hex1, hex2; |
| 5960 | hex1 = toupper(line[2]) - '0'; |
| 5961 | hex2 = toupper(line[3]) - '0'; |
| 5962 | if (hex1 > 9) hex1 -= 'A' - '9' - 1; |
| 5963 | if (hex2 > 9) hex2 -= 'A' - '9' - 1; |
| 5964 | *line = (hex1<<4) + hex2; |
| 5965 | skip = 3; |
| 5966 | } |
| 5967 | else { |
| 5968 | 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] | 5969 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5970 | } |
| 5971 | } |
| 5972 | if (skip) { |
Cyril Bonté | dd1b01d | 2009-12-06 13:43:42 +0100 | [diff] [blame] | 5973 | memmove(line + 1, line + 1 + skip, end - (line + skip)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5974 | end -= skip; |
| 5975 | } |
| 5976 | line++; |
| 5977 | } |
| 5978 | else if (*line == '#' || *line == '\n' || *line == '\r') { |
| 5979 | /* end of string, end of loop */ |
| 5980 | *line = 0; |
| 5981 | break; |
| 5982 | } |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 5983 | else if (isspace((unsigned char)*line)) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5984 | /* a non-escaped space is an argument separator */ |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5985 | *line++ = '\0'; |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 5986 | while (isspace((unsigned char)*line)) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5987 | line++; |
| 5988 | args[++arg] = line; |
| 5989 | } |
| 5990 | else { |
| 5991 | line++; |
| 5992 | } |
| 5993 | } |
| 5994 | |
| 5995 | /* empty line */ |
| 5996 | if (!**args) |
| 5997 | continue; |
| 5998 | |
Willy Tarreau | 7bb651e | 2009-11-09 21:16:53 +0100 | [diff] [blame] | 5999 | if (*line) { |
| 6000 | /* we had to stop due to too many args. |
| 6001 | * Let's terminate the string, print the offending part then cut the |
| 6002 | * last arg. |
| 6003 | */ |
| 6004 | while (*line && *line != '#' && *line != '\n' && *line != '\r') |
| 6005 | line++; |
| 6006 | *line = '\0'; |
| 6007 | |
Krzysztof Piotr Oledzki | 500b8f0 | 2009-12-15 22:34:51 +0100 | [diff] [blame] | 6008 | 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] | 6009 | file, linenum, arg + 1, (long)(args[arg] - thisline + 1), args[arg]); |
Willy Tarreau | 7bb651e | 2009-11-09 21:16:53 +0100 | [diff] [blame] | 6010 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6011 | args[arg] = line; |
| 6012 | } |
| 6013 | |
Willy Tarreau | 540abe4 | 2007-05-02 20:50:16 +0200 | [diff] [blame] | 6014 | /* zero out remaining args and ensure that at least one entry |
| 6015 | * is zeroed out. |
| 6016 | */ |
| 6017 | while (++arg <= MAX_LINE_ARGS) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6018 | args[arg] = line; |
| 6019 | } |
| 6020 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 6021 | /* check for keyword modifiers "no" and "default" */ |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 6022 | if (!strcmp(args[0], "no")) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6023 | char *tmp; |
| 6024 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 6025 | kwm = KWM_NO; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6026 | tmp = args[0]; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 6027 | for (arg=0; *args[arg+1]; arg++) |
| 6028 | args[arg] = args[arg+1]; // shift args after inversion |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6029 | *tmp = '\0'; // fix the next arg to \0 |
| 6030 | args[arg] = tmp; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 6031 | } |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 6032 | else if (!strcmp(args[0], "default")) { |
| 6033 | kwm = KWM_DEF; |
| 6034 | for (arg=0; *args[arg+1]; arg++) |
| 6035 | args[arg] = args[arg+1]; // shift args after inversion |
| 6036 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 6037 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6038 | if (kwm != KWM_STD && strcmp(args[0], "option") != 0 && \ |
| 6039 | strcmp(args[0], "log") != 0) { |
| 6040 | 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] | 6041 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 6042 | } |
| 6043 | |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 6044 | /* detect section start */ |
| 6045 | list_for_each_entry(ics, §ions, list) { |
| 6046 | if (strcmp(args[0], ics->section_name) == 0) { |
| 6047 | cursection = ics->section_name; |
| 6048 | cs = ics; |
| 6049 | break; |
| 6050 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 6051 | } |
| 6052 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6053 | /* else it's a section keyword */ |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 6054 | if (cs) |
| 6055 | err_code |= cs->section_parser(file, linenum, args, kwm); |
| 6056 | else { |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6057 | 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] | 6058 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6059 | } |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 6060 | |
| 6061 | if (err_code & ERR_ABORT) |
| 6062 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6063 | } |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 6064 | cursection = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6065 | fclose(f); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 6066 | return err_code; |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6067 | } |
| 6068 | |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 6069 | /* This function propagates processes from frontend <from> to backend <to> so |
| 6070 | * that it is always guaranteed that a backend pointed to by a frontend is |
| 6071 | * bound to all of its processes. After that, if the target is a "listen" |
| 6072 | * instance, the function recursively descends the target's own targets along |
| 6073 | * default_backend, use_backend rules, and reqsetbe rules. Since the bits are |
| 6074 | * checked first to ensure that <to> is already bound to all processes of |
| 6075 | * <from>, there is no risk of looping and we ensure to follow the shortest |
| 6076 | * path to the destination. |
| 6077 | * |
| 6078 | * It is possible to set <to> to NULL for the first call so that the function |
| 6079 | * takes care of visiting the initial frontend in <from>. |
| 6080 | * |
| 6081 | * It is important to note that the function relies on the fact that all names |
| 6082 | * have already been resolved. |
| 6083 | */ |
| 6084 | void propagate_processes(struct proxy *from, struct proxy *to) |
| 6085 | { |
| 6086 | struct switching_rule *rule; |
| 6087 | struct hdr_exp *exp; |
| 6088 | |
| 6089 | if (to) { |
| 6090 | /* check whether we need to go down */ |
| 6091 | if (from->bind_proc && |
| 6092 | (from->bind_proc & to->bind_proc) == from->bind_proc) |
| 6093 | return; |
| 6094 | |
| 6095 | if (!from->bind_proc && !to->bind_proc) |
| 6096 | return; |
| 6097 | |
| 6098 | to->bind_proc = from->bind_proc ? |
| 6099 | (to->bind_proc | from->bind_proc) : 0; |
| 6100 | |
| 6101 | /* now propagate down */ |
| 6102 | from = to; |
| 6103 | } |
| 6104 | |
Willy Tarreau | 8a95d8c | 2014-12-18 13:56:26 +0100 | [diff] [blame] | 6105 | if (!(from->cap & PR_CAP_FE)) |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 6106 | return; |
| 6107 | |
Willy Tarreau | f6b7001 | 2014-12-18 14:00:43 +0100 | [diff] [blame] | 6108 | if (from->state == PR_STSTOPPED) |
| 6109 | return; |
| 6110 | |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 6111 | /* default_backend */ |
| 6112 | if (from->defbe.be) |
| 6113 | propagate_processes(from, from->defbe.be); |
| 6114 | |
| 6115 | /* use_backend */ |
| 6116 | list_for_each_entry(rule, &from->switching_rules, list) { |
Cyril Bonté | 5163969 | 2014-10-02 19:56:25 +0200 | [diff] [blame] | 6117 | if (rule->dynamic) |
| 6118 | continue; |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 6119 | to = rule->be.backend; |
| 6120 | propagate_processes(from, to); |
| 6121 | } |
| 6122 | |
| 6123 | /* reqsetbe */ |
| 6124 | for (exp = from->req_exp; exp != NULL; exp = exp->next) { |
| 6125 | if (exp->action != ACT_SETBE) |
| 6126 | continue; |
| 6127 | to = (struct proxy *)exp->replace; |
| 6128 | propagate_processes(from, to); |
| 6129 | } |
| 6130 | } |
| 6131 | |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6132 | /* |
| 6133 | * Returns the error code, 0 if OK, or any combination of : |
| 6134 | * - ERR_ABORT: must abort ASAP |
| 6135 | * - ERR_FATAL: we can continue parsing but not start the service |
| 6136 | * - ERR_WARN: a warning has been emitted |
| 6137 | * - ERR_ALERT: an alert has been emitted |
| 6138 | * Only the two first ones can stop processing, the two others are just |
| 6139 | * indicators. |
| 6140 | */ |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6141 | int check_config_validity() |
| 6142 | { |
| 6143 | int cfgerr = 0; |
| 6144 | struct proxy *curproxy = NULL; |
| 6145 | struct server *newsrv = NULL; |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6146 | int err_code = 0; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6147 | unsigned int next_pxid = 1; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6148 | struct bind_conf *bind_conf; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6149 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6150 | bind_conf = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6151 | /* |
| 6152 | * Now, check for the integrity of all that we have collected. |
| 6153 | */ |
| 6154 | |
| 6155 | /* will be needed further to delay some tasks */ |
Willy Tarreau | b0b37bc | 2008-06-23 14:00:57 +0200 | [diff] [blame] | 6156 | tv_update_date(0,1); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6157 | |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 6158 | if (!global.tune.max_http_hdr) |
| 6159 | global.tune.max_http_hdr = MAX_HTTP_HDR; |
| 6160 | |
| 6161 | if (!global.tune.cookie_len) |
| 6162 | global.tune.cookie_len = CAPTURE_LEN; |
| 6163 | |
| 6164 | pool2_capture = create_pool("capture", global.tune.cookie_len, MEM_F_SHARED); |
| 6165 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6166 | /* Post initialisation of the users and groups lists. */ |
| 6167 | err_code = userlist_postinit(); |
| 6168 | if (err_code != ERR_NONE) |
| 6169 | goto out; |
| 6170 | |
Willy Tarreau | 55bc0f8 | 2009-03-15 14:51:53 +0100 | [diff] [blame] | 6171 | /* first, we will invert the proxy list order */ |
| 6172 | curproxy = NULL; |
| 6173 | while (proxy) { |
| 6174 | struct proxy *next; |
| 6175 | |
| 6176 | next = proxy->next; |
| 6177 | proxy->next = curproxy; |
| 6178 | curproxy = proxy; |
| 6179 | if (!next) |
| 6180 | break; |
| 6181 | proxy = next; |
| 6182 | } |
| 6183 | |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 6184 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6185 | struct switching_rule *rule; |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 6186 | struct server_rule *srule; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6187 | struct sticking_rule *mrule; |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 6188 | struct tcp_rule *trule; |
Willy Tarreau | 09448f7 | 2014-06-25 18:12:15 +0200 | [diff] [blame] | 6189 | struct http_req_rule *hrqrule; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6190 | unsigned int next_id; |
Willy Tarreau | 16a2147 | 2012-11-19 12:39:59 +0100 | [diff] [blame] | 6191 | int nbproc; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6192 | |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 6193 | if (curproxy->uuid < 0) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6194 | /* proxy ID not set, use automatic numbering with first |
| 6195 | * spare entry starting with next_pxid. |
| 6196 | */ |
| 6197 | next_pxid = get_next_id(&used_proxy_id, next_pxid); |
| 6198 | curproxy->conf.id.key = curproxy->uuid = next_pxid; |
| 6199 | eb32_insert(&used_proxy_id, &curproxy->conf.id); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6200 | } |
Krzysztof Piotr Oledzki | df5cb9f | 2010-02-05 20:58:27 +0100 | [diff] [blame] | 6201 | next_pxid++; |
| 6202 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6203 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6204 | if (curproxy->state == PR_STSTOPPED) { |
Willy Tarreau | da250db | 2008-10-12 12:07:48 +0200 | [diff] [blame] | 6205 | /* ensure we don't keep listeners uselessly bound */ |
| 6206 | stop_proxy(curproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6207 | continue; |
| 6208 | } |
| 6209 | |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 6210 | /* Check multi-process mode compatibility for the current proxy */ |
| 6211 | |
| 6212 | if (curproxy->bind_proc) { |
| 6213 | /* an explicit bind-process was specified, let's check how many |
| 6214 | * processes remain. |
| 6215 | */ |
| 6216 | nbproc = popcount(curproxy->bind_proc); |
| 6217 | |
| 6218 | curproxy->bind_proc &= nbits(global.nbproc); |
| 6219 | if (!curproxy->bind_proc && nbproc == 1) { |
| 6220 | 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); |
| 6221 | curproxy->bind_proc = 1; |
| 6222 | } |
| 6223 | else if (!curproxy->bind_proc && nbproc > 1) { |
| 6224 | 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); |
| 6225 | curproxy->bind_proc = 0; |
| 6226 | } |
| 6227 | } |
| 6228 | |
Willy Tarreau | 3d20958 | 2014-05-09 17:06:11 +0200 | [diff] [blame] | 6229 | /* check and reduce the bind-proc of each listener */ |
| 6230 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
| 6231 | unsigned long mask; |
| 6232 | |
| 6233 | if (!bind_conf->bind_proc) |
| 6234 | continue; |
| 6235 | |
| 6236 | mask = nbits(global.nbproc); |
| 6237 | if (curproxy->bind_proc) |
| 6238 | mask &= curproxy->bind_proc; |
| 6239 | /* mask cannot be null here thanks to the previous checks */ |
| 6240 | |
| 6241 | nbproc = popcount(bind_conf->bind_proc); |
| 6242 | bind_conf->bind_proc &= mask; |
| 6243 | |
| 6244 | if (!bind_conf->bind_proc && nbproc == 1) { |
| 6245 | 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", |
| 6246 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
| 6247 | bind_conf->bind_proc = mask & ~(mask - 1); |
| 6248 | } |
| 6249 | else if (!bind_conf->bind_proc && nbproc > 1) { |
| 6250 | 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", |
| 6251 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
| 6252 | bind_conf->bind_proc = 0; |
| 6253 | } |
| 6254 | } |
| 6255 | |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 6256 | if (global.nbproc > 1 && curproxy->table.peers.name) { |
| 6257 | Alert("Proxy '%s': peers can't be used in multi-process mode (nbproc > 1).\n", |
| 6258 | curproxy->id); |
| 6259 | cfgerr++; |
| 6260 | } |
Willy Tarreau | 16a2147 | 2012-11-19 12:39:59 +0100 | [diff] [blame] | 6261 | |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 6262 | switch (curproxy->mode) { |
| 6263 | case PR_MODE_HEALTH: |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6264 | cfgerr += proxy_cfg_ensure_no_http(curproxy); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 6265 | if (!(curproxy->cap & PR_CAP_FE)) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6266 | Alert("config : %s '%s' cannot be in health mode as it has no frontend capability.\n", |
| 6267 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 6268 | cfgerr++; |
| 6269 | } |
| 6270 | |
| 6271 | if (curproxy->srv != NULL) |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6272 | Warning("config : servers will be ignored for %s '%s'.\n", |
| 6273 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 6274 | break; |
| 6275 | |
| 6276 | case PR_MODE_TCP: |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6277 | cfgerr += proxy_cfg_ensure_no_http(curproxy); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 6278 | break; |
| 6279 | |
| 6280 | case PR_MODE_HTTP: |
Willy Tarreau | 25320b2 | 2013-03-24 07:22:08 +0100 | [diff] [blame] | 6281 | curproxy->http_needed = 1; |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 6282 | break; |
| 6283 | } |
| 6284 | |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 6285 | if ((curproxy->cap & PR_CAP_BE) && (curproxy->mode != PR_MODE_HEALTH)) { |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6286 | if (curproxy->lbprm.algo & BE_LB_KIND) { |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 6287 | if (curproxy->options & PR_O_TRANSP) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6288 | Alert("config : %s '%s' cannot use both transparent and balance mode.\n", |
| 6289 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 6290 | cfgerr++; |
| 6291 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6292 | #ifdef WE_DONT_SUPPORT_SERVERLESS_LISTENERS |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 6293 | else if (curproxy->srv == NULL) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6294 | Alert("config : %s '%s' needs at least 1 server in balance mode.\n", |
| 6295 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 6296 | cfgerr++; |
| 6297 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6298 | #endif |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 6299 | else if (curproxy->options & PR_O_DISPATCH) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6300 | Warning("config : dispatch address of %s '%s' will be ignored in balance mode.\n", |
| 6301 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6302 | err_code |= ERR_WARN; |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 6303 | } |
| 6304 | } |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 6305 | 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] | 6306 | /* If no LB algo is set in a backend, and we're not in |
| 6307 | * transparent mode, dispatch mode nor proxy mode, we |
| 6308 | * want to use balance roundrobin by default. |
| 6309 | */ |
| 6310 | curproxy->lbprm.algo &= ~BE_LB_ALGO; |
| 6311 | curproxy->lbprm.algo |= BE_LB_ALGO_RR; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6312 | } |
| 6313 | } |
Willy Tarreau | 193cf93 | 2007-09-17 10:17:23 +0200 | [diff] [blame] | 6314 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 6315 | if (curproxy->options & PR_O_DISPATCH) |
| 6316 | curproxy->options &= ~(PR_O_TRANSP | PR_O_HTTP_PROXY); |
| 6317 | else if (curproxy->options & PR_O_HTTP_PROXY) |
| 6318 | curproxy->options &= ~(PR_O_DISPATCH | PR_O_TRANSP); |
| 6319 | else if (curproxy->options & PR_O_TRANSP) |
| 6320 | curproxy->options &= ~(PR_O_DISPATCH | PR_O_HTTP_PROXY); |
Willy Tarreau | 8293658 | 2007-11-30 15:20:09 +0100 | [diff] [blame] | 6321 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 6322 | if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_HTTP_CHK) { |
| 6323 | if (curproxy->options & PR_O_DISABLE404) { |
| 6324 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n", |
| 6325 | "disable-on-404", proxy_type_str(curproxy), curproxy->id); |
| 6326 | err_code |= ERR_WARN; |
| 6327 | curproxy->options &= ~PR_O_DISABLE404; |
| 6328 | } |
| 6329 | if (curproxy->options2 & PR_O2_CHK_SNDST) { |
| 6330 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n", |
| 6331 | "send-state", proxy_type_str(curproxy), curproxy->id); |
| 6332 | err_code |= ERR_WARN; |
| 6333 | curproxy->options &= ~PR_O2_CHK_SNDST; |
| 6334 | } |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 6335 | } |
| 6336 | |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 6337 | if ((curproxy->options2 & PR_O2_CHK_ANY) == PR_O2_EXT_CHK) { |
| 6338 | if (!global.external_check) { |
| 6339 | Alert("Proxy '%s' : '%s' unable to find required 'global.external-check'.\n", |
| 6340 | curproxy->id, "option external-check"); |
| 6341 | cfgerr++; |
| 6342 | } |
| 6343 | if (!curproxy->check_command) { |
| 6344 | Alert("Proxy '%s' : '%s' unable to find required 'external-check command'.\n", |
| 6345 | curproxy->id, "option external-check"); |
| 6346 | cfgerr++; |
| 6347 | } |
| 6348 | } |
| 6349 | |
| 6350 | if (curproxy->check_command) { |
| 6351 | int clear = 0; |
| 6352 | if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_EXT_CHK) { |
| 6353 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option external-check').\n", |
| 6354 | "external-check command", proxy_type_str(curproxy), curproxy->id); |
| 6355 | err_code |= ERR_WARN; |
| 6356 | clear = 1; |
| 6357 | } |
| 6358 | if (curproxy->check_command[0] != '/' && !curproxy->check_path) { |
| 6359 | Alert("Proxy '%s': '%s' does not have a leading '/' and 'external-command path' is not set.\n", |
| 6360 | curproxy->id, "external-check command"); |
| 6361 | cfgerr++; |
| 6362 | } |
| 6363 | if (clear) { |
| 6364 | free(curproxy->check_command); |
| 6365 | curproxy->check_command = NULL; |
| 6366 | } |
| 6367 | } |
| 6368 | |
| 6369 | if (curproxy->check_path) { |
| 6370 | if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_EXT_CHK) { |
| 6371 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option external-check').\n", |
| 6372 | "external-check path", proxy_type_str(curproxy), curproxy->id); |
| 6373 | err_code |= ERR_WARN; |
| 6374 | free(curproxy->check_path); |
| 6375 | curproxy->check_path = NULL; |
| 6376 | } |
| 6377 | } |
| 6378 | |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 6379 | /* if a default backend was specified, let's find it */ |
| 6380 | if (curproxy->defbe.name) { |
| 6381 | struct proxy *target; |
| 6382 | |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 6383 | target = findproxy_mode(curproxy->defbe.name, curproxy->mode, PR_CAP_BE); |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6384 | if (!target) { |
| 6385 | Alert("Proxy '%s': unable to find required default_backend: '%s'.\n", |
| 6386 | curproxy->id, curproxy->defbe.name); |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 6387 | cfgerr++; |
| 6388 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6389 | Alert("Proxy '%s': loop detected for default_backend: '%s'.\n", |
| 6390 | curproxy->id, curproxy->defbe.name); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6391 | cfgerr++; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 6392 | } else { |
| 6393 | free(curproxy->defbe.name); |
| 6394 | curproxy->defbe.be = target; |
Willy Tarreau | ff67813 | 2012-02-13 14:32:34 +0100 | [diff] [blame] | 6395 | |
| 6396 | /* Emit a warning if this proxy also has some servers */ |
| 6397 | if (curproxy->srv) { |
| 6398 | Warning("In proxy '%s', the 'default_backend' rule always has precedence over the servers, which will never be used.\n", |
| 6399 | curproxy->id); |
| 6400 | err_code |= ERR_WARN; |
| 6401 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6402 | } |
| 6403 | } |
| 6404 | |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 6405 | /* find the target proxy in setbe */ |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 6406 | if (curproxy->mode == PR_MODE_HTTP && curproxy->req_exp != NULL) { |
| 6407 | /* map jump target for ACT_SETBE in req_rep chain */ |
| 6408 | struct hdr_exp *exp; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 6409 | for (exp = curproxy->req_exp; exp != NULL; exp = exp->next) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6410 | struct proxy *target; |
| 6411 | |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 6412 | if (exp->action != ACT_SETBE) |
| 6413 | continue; |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6414 | |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 6415 | target = findproxy_mode(exp->replace, PR_MODE_HTTP, PR_CAP_BE); |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6416 | if (!target) { |
| 6417 | Alert("Proxy '%s': unable to find required setbe: '%s'.\n", |
| 6418 | curproxy->id, exp->replace); |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 6419 | cfgerr++; |
| 6420 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6421 | Alert("Proxy '%s': loop detected for setbe: '%s'.\n", |
| 6422 | curproxy->id, exp->replace); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 6423 | cfgerr++; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 6424 | } else { |
| 6425 | free((void *)exp->replace); |
| 6426 | exp->replace = (const char *)target; |
| 6427 | } |
| 6428 | } |
| 6429 | } |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6430 | |
| 6431 | /* find the target proxy for 'use_backend' rules */ |
| 6432 | list_for_each_entry(rule, &curproxy->switching_rules, list) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6433 | struct proxy *target; |
Bertrand Jacquin | 702d44f | 2013-11-19 11:43:06 +0100 | [diff] [blame] | 6434 | struct logformat_node *node; |
| 6435 | char *pxname; |
| 6436 | |
| 6437 | /* Try to parse the string as a log format expression. If the result |
| 6438 | * of the parsing is only one entry containing a simple string, then |
| 6439 | * it's a standard string corresponding to a static rule, thus the |
| 6440 | * parsing is cancelled and be.name is restored to be resolved. |
| 6441 | */ |
| 6442 | pxname = rule->be.name; |
| 6443 | LIST_INIT(&rule->be.expr); |
| 6444 | parse_logformat_string(pxname, curproxy, &rule->be.expr, 0, SMP_VAL_FE_HRQ_HDR, |
| 6445 | curproxy->conf.args.file, curproxy->conf.args.line); |
| 6446 | node = LIST_NEXT(&rule->be.expr, struct logformat_node *, list); |
| 6447 | |
| 6448 | if (!LIST_ISEMPTY(&rule->be.expr)) { |
| 6449 | if (node->type != LOG_FMT_TEXT || node->list.n != &rule->be.expr) { |
| 6450 | rule->dynamic = 1; |
| 6451 | free(pxname); |
| 6452 | continue; |
| 6453 | } |
| 6454 | /* simple string: free the expression and fall back to static rule */ |
| 6455 | free(node->arg); |
| 6456 | free(node); |
| 6457 | } |
| 6458 | |
| 6459 | rule->dynamic = 0; |
| 6460 | rule->be.name = pxname; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6461 | |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 6462 | target = findproxy_mode(rule->be.name, curproxy->mode, PR_CAP_BE); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6463 | |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6464 | if (!target) { |
| 6465 | Alert("Proxy '%s': unable to find required use_backend: '%s'.\n", |
| 6466 | curproxy->id, rule->be.name); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6467 | cfgerr++; |
| 6468 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6469 | Alert("Proxy '%s': loop detected for use_backend: '%s'.\n", |
| 6470 | curproxy->id, rule->be.name); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6471 | cfgerr++; |
| 6472 | } else { |
| 6473 | free((void *)rule->be.name); |
| 6474 | rule->be.backend = target; |
| 6475 | } |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 6476 | } |
| 6477 | |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 6478 | /* find the target server for 'use_server' rules */ |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 6479 | list_for_each_entry(srule, &curproxy->server_rules, list) { |
| 6480 | struct server *target = findserver(curproxy, srule->srv.name); |
| 6481 | |
| 6482 | if (!target) { |
| 6483 | Alert("config : %s '%s' : unable to find server '%s' referenced in a 'use-server' rule.\n", |
| 6484 | proxy_type_str(curproxy), curproxy->id, srule->srv.name); |
| 6485 | cfgerr++; |
| 6486 | continue; |
| 6487 | } |
| 6488 | free((void *)srule->srv.name); |
| 6489 | srule->srv.ptr = target; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6490 | } |
| 6491 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6492 | /* find the target table for 'stick' rules */ |
| 6493 | list_for_each_entry(mrule, &curproxy->sticking_rules, list) { |
| 6494 | struct proxy *target; |
| 6495 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 6496 | curproxy->be_req_ana |= AN_REQ_STICKING_RULES; |
| 6497 | if (mrule->flags & STK_IS_STORE) |
| 6498 | curproxy->be_rsp_ana |= AN_RES_STORE_RULES; |
| 6499 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6500 | if (mrule->table.name) |
Willy Tarreau | c00cdc2 | 2010-06-06 16:48:26 +0200 | [diff] [blame] | 6501 | target = findproxy(mrule->table.name, 0); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6502 | else |
| 6503 | target = curproxy; |
| 6504 | |
| 6505 | if (!target) { |
| 6506 | Alert("Proxy '%s': unable to find stick-table '%s'.\n", |
| 6507 | curproxy->id, mrule->table.name); |
| 6508 | cfgerr++; |
| 6509 | } |
| 6510 | else if (target->table.size == 0) { |
| 6511 | Alert("Proxy '%s': stick-table '%s' used but not configured.\n", |
| 6512 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 6513 | cfgerr++; |
| 6514 | } |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 6515 | else if (!stktable_compatible_sample(mrule->expr, target->table.type)) { |
| 6516 | 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] | 6517 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 6518 | cfgerr++; |
| 6519 | } |
| 6520 | else { |
| 6521 | free((void *)mrule->table.name); |
| 6522 | mrule->table.t = &(target->table); |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 6523 | stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID, NULL); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6524 | } |
| 6525 | } |
| 6526 | |
| 6527 | /* find the target table for 'store response' rules */ |
| 6528 | list_for_each_entry(mrule, &curproxy->storersp_rules, list) { |
| 6529 | struct proxy *target; |
| 6530 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 6531 | curproxy->be_rsp_ana |= AN_RES_STORE_RULES; |
| 6532 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6533 | if (mrule->table.name) |
Willy Tarreau | c00cdc2 | 2010-06-06 16:48:26 +0200 | [diff] [blame] | 6534 | target = findproxy(mrule->table.name, 0); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6535 | else |
| 6536 | target = curproxy; |
| 6537 | |
| 6538 | if (!target) { |
| 6539 | Alert("Proxy '%s': unable to find store table '%s'.\n", |
| 6540 | curproxy->id, mrule->table.name); |
| 6541 | cfgerr++; |
| 6542 | } |
| 6543 | else if (target->table.size == 0) { |
| 6544 | Alert("Proxy '%s': stick-table '%s' used but not configured.\n", |
| 6545 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 6546 | cfgerr++; |
| 6547 | } |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 6548 | else if (!stktable_compatible_sample(mrule->expr, target->table.type)) { |
| 6549 | 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] | 6550 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 6551 | cfgerr++; |
| 6552 | } |
| 6553 | else { |
| 6554 | free((void *)mrule->table.name); |
| 6555 | mrule->table.t = &(target->table); |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 6556 | stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID, NULL); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6557 | } |
| 6558 | } |
| 6559 | |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 6560 | /* find the target table for 'tcp-request' layer 4 rules */ |
| 6561 | list_for_each_entry(trule, &curproxy->tcp_req.l4_rules, list) { |
| 6562 | struct proxy *target; |
| 6563 | |
Willy Tarreau | b4c8493 | 2013-07-23 19:15:30 +0200 | [diff] [blame] | 6564 | 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] | 6565 | continue; |
| 6566 | |
| 6567 | if (trule->act_prm.trk_ctr.table.n) |
| 6568 | target = findproxy(trule->act_prm.trk_ctr.table.n, 0); |
| 6569 | else |
| 6570 | target = curproxy; |
| 6571 | |
| 6572 | if (!target) { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6573 | Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n", |
| 6574 | curproxy->id, trule->act_prm.trk_ctr.table.n, |
Willy Tarreau | 34c2fb6 | 2013-12-02 23:29:05 +0100 | [diff] [blame] | 6575 | tcp_trk_idx(trule->action)); |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 6576 | cfgerr++; |
| 6577 | } |
| 6578 | else if (target->table.size == 0) { |
| 6579 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
| 6580 | curproxy->id, trule->act_prm.trk_ctr.table.n ? trule->act_prm.trk_ctr.table.n : curproxy->id); |
| 6581 | cfgerr++; |
| 6582 | } |
Willy Tarreau | 5f53de7 | 2012-12-12 00:25:44 +0100 | [diff] [blame] | 6583 | else if (!stktable_compatible_sample(trule->act_prm.trk_ctr.expr, target->table.type)) { |
| 6584 | Alert("Proxy '%s': stick-table '%s' uses a type incompatible with the 'track-sc%d' rule.\n", |
| 6585 | 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] | 6586 | tcp_trk_idx(trule->action)); |
Willy Tarreau | 5f53de7 | 2012-12-12 00:25:44 +0100 | [diff] [blame] | 6587 | cfgerr++; |
| 6588 | } |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 6589 | else { |
| 6590 | free(trule->act_prm.trk_ctr.table.n); |
| 6591 | trule->act_prm.trk_ctr.table.t = &target->table; |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6592 | /* 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] | 6593 | * to pass a list of counters to track and allocate them right here using |
| 6594 | * stktable_alloc_data_type(). |
| 6595 | */ |
| 6596 | } |
| 6597 | } |
| 6598 | |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 6599 | /* find the target table for 'tcp-request' layer 6 rules */ |
| 6600 | list_for_each_entry(trule, &curproxy->tcp_req.inspect_rules, list) { |
| 6601 | struct proxy *target; |
| 6602 | |
Willy Tarreau | b4c8493 | 2013-07-23 19:15:30 +0200 | [diff] [blame] | 6603 | 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] | 6604 | continue; |
| 6605 | |
| 6606 | if (trule->act_prm.trk_ctr.table.n) |
| 6607 | target = findproxy(trule->act_prm.trk_ctr.table.n, 0); |
| 6608 | else |
| 6609 | target = curproxy; |
| 6610 | |
| 6611 | if (!target) { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6612 | Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n", |
| 6613 | curproxy->id, trule->act_prm.trk_ctr.table.n, |
Willy Tarreau | 34c2fb6 | 2013-12-02 23:29:05 +0100 | [diff] [blame] | 6614 | tcp_trk_idx(trule->action)); |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 6615 | cfgerr++; |
| 6616 | } |
| 6617 | else if (target->table.size == 0) { |
| 6618 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
| 6619 | curproxy->id, trule->act_prm.trk_ctr.table.n ? trule->act_prm.trk_ctr.table.n : curproxy->id); |
| 6620 | cfgerr++; |
| 6621 | } |
Willy Tarreau | 5f53de7 | 2012-12-12 00:25:44 +0100 | [diff] [blame] | 6622 | else if (!stktable_compatible_sample(trule->act_prm.trk_ctr.expr, target->table.type)) { |
| 6623 | Alert("Proxy '%s': stick-table '%s' uses a type incompatible with the 'track-sc%d' rule.\n", |
| 6624 | 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] | 6625 | tcp_trk_idx(trule->action)); |
Willy Tarreau | 5f53de7 | 2012-12-12 00:25:44 +0100 | [diff] [blame] | 6626 | cfgerr++; |
| 6627 | } |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 6628 | else { |
| 6629 | free(trule->act_prm.trk_ctr.table.n); |
| 6630 | trule->act_prm.trk_ctr.table.t = &target->table; |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6631 | /* 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] | 6632 | * to pass a list of counters to track and allocate them right here using |
| 6633 | * stktable_alloc_data_type(). |
| 6634 | */ |
| 6635 | } |
| 6636 | } |
| 6637 | |
Willy Tarreau | 09448f7 | 2014-06-25 18:12:15 +0200 | [diff] [blame] | 6638 | /* find the target table for 'http-request' layer 7 rules */ |
| 6639 | list_for_each_entry(hrqrule, &curproxy->http_req_rules, list) { |
| 6640 | struct proxy *target; |
| 6641 | |
| 6642 | if (hrqrule->action < HTTP_REQ_ACT_TRK_SC0 || hrqrule->action > HTTP_REQ_ACT_TRK_SCMAX) |
| 6643 | continue; |
| 6644 | |
| 6645 | if (hrqrule->act_prm.trk_ctr.table.n) |
| 6646 | target = findproxy(hrqrule->act_prm.trk_ctr.table.n, 0); |
| 6647 | else |
| 6648 | target = curproxy; |
| 6649 | |
| 6650 | if (!target) { |
| 6651 | Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n", |
| 6652 | curproxy->id, hrqrule->act_prm.trk_ctr.table.n, |
| 6653 | http_req_trk_idx(hrqrule->action)); |
| 6654 | cfgerr++; |
| 6655 | } |
| 6656 | else if (target->table.size == 0) { |
| 6657 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
| 6658 | curproxy->id, hrqrule->act_prm.trk_ctr.table.n ? hrqrule->act_prm.trk_ctr.table.n : curproxy->id); |
| 6659 | cfgerr++; |
| 6660 | } |
| 6661 | else if (!stktable_compatible_sample(hrqrule->act_prm.trk_ctr.expr, target->table.type)) { |
| 6662 | Alert("Proxy '%s': stick-table '%s' uses a type incompatible with the 'track-sc%d' rule.\n", |
| 6663 | curproxy->id, hrqrule->act_prm.trk_ctr.table.n ? hrqrule->act_prm.trk_ctr.table.n : curproxy->id, |
| 6664 | http_req_trk_idx(hrqrule->action)); |
| 6665 | cfgerr++; |
| 6666 | } |
| 6667 | else { |
| 6668 | free(hrqrule->act_prm.trk_ctr.table.n); |
| 6669 | hrqrule->act_prm.trk_ctr.table.t = &target->table; |
| 6670 | /* Note: if we decide to enhance the track-sc syntax, we may be able |
| 6671 | * to pass a list of counters to track and allocate them right here using |
| 6672 | * stktable_alloc_data_type(). |
| 6673 | */ |
| 6674 | } |
| 6675 | } |
| 6676 | |
Willy Tarreau | b3dc39d | 2014-04-28 22:06:57 +0200 | [diff] [blame] | 6677 | /* move any "block" rules at the beginning of the http-request rules */ |
| 6678 | if (!LIST_ISEMPTY(&curproxy->block_rules)) { |
| 6679 | /* insert block_rules into http_req_rules at the beginning */ |
| 6680 | curproxy->block_rules.p->n = curproxy->http_req_rules.n; |
| 6681 | curproxy->http_req_rules.n->p = curproxy->block_rules.p; |
| 6682 | curproxy->block_rules.n->p = &curproxy->http_req_rules; |
| 6683 | curproxy->http_req_rules.n = curproxy->block_rules.n; |
| 6684 | LIST_INIT(&curproxy->block_rules); |
| 6685 | } |
| 6686 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 6687 | if (curproxy->table.peers.name) { |
| 6688 | struct peers *curpeers = peers; |
| 6689 | |
| 6690 | for (curpeers = peers; curpeers; curpeers = curpeers->next) { |
| 6691 | if (strcmp(curpeers->id, curproxy->table.peers.name) == 0) { |
| 6692 | free((void *)curproxy->table.peers.name); |
Willy Tarreau | 973ca49 | 2013-01-17 21:34:52 +0100 | [diff] [blame] | 6693 | curproxy->table.peers.p = curpeers; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 6694 | break; |
| 6695 | } |
| 6696 | } |
| 6697 | |
| 6698 | if (!curpeers) { |
| 6699 | Alert("Proxy '%s': unable to find sync peers '%s'.\n", |
| 6700 | curproxy->id, curproxy->table.peers.name); |
Willy Tarreau | d66bf96 | 2011-10-28 14:16:49 +0200 | [diff] [blame] | 6701 | free((void *)curproxy->table.peers.name); |
| 6702 | curproxy->table.peers.p = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 6703 | cfgerr++; |
| 6704 | } |
| 6705 | else if (!curpeers->peers_fe) { |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 6706 | Alert("Proxy '%s': unable to find local peer '%s' in peers section '%s'.\n", |
| 6707 | curproxy->id, localpeer, curpeers->id); |
Willy Tarreau | d66bf96 | 2011-10-28 14:16:49 +0200 | [diff] [blame] | 6708 | curproxy->table.peers.p = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 6709 | cfgerr++; |
| 6710 | } |
| 6711 | } |
| 6712 | |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 6713 | if (curproxy->uri_auth && !(curproxy->uri_auth->flags & ST_CONVDONE) && |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 6714 | !LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) && |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6715 | (curproxy->uri_auth->userlist || curproxy->uri_auth->auth_realm )) { |
| 6716 | Alert("%s '%s': stats 'auth'/'realm' and 'http-request' can't be used at the same time.\n", |
| 6717 | "proxy", curproxy->id); |
| 6718 | cfgerr++; |
| 6719 | goto out_uri_auth_compat; |
| 6720 | } |
| 6721 | |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 6722 | 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] | 6723 | const char *uri_auth_compat_req[10]; |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 6724 | struct http_req_rule *rule; |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6725 | int i = 0; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6726 | |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6727 | /* build the ACL condition from scratch. We're relying on anonymous ACLs for that */ |
| 6728 | uri_auth_compat_req[i++] = "auth"; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6729 | |
| 6730 | if (curproxy->uri_auth->auth_realm) { |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6731 | uri_auth_compat_req[i++] = "realm"; |
| 6732 | uri_auth_compat_req[i++] = curproxy->uri_auth->auth_realm; |
| 6733 | } |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6734 | |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6735 | uri_auth_compat_req[i++] = "unless"; |
| 6736 | uri_auth_compat_req[i++] = "{"; |
| 6737 | uri_auth_compat_req[i++] = "http_auth(.internal-stats-userlist)"; |
| 6738 | uri_auth_compat_req[i++] = "}"; |
| 6739 | uri_auth_compat_req[i++] = ""; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6740 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 6741 | rule = parse_http_req_cond(uri_auth_compat_req, "internal-stats-auth-compat", 0, curproxy); |
| 6742 | if (!rule) { |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6743 | cfgerr++; |
| 6744 | break; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6745 | } |
| 6746 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 6747 | LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list); |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6748 | |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6749 | if (curproxy->uri_auth->auth_realm) { |
| 6750 | free(curproxy->uri_auth->auth_realm); |
| 6751 | curproxy->uri_auth->auth_realm = NULL; |
| 6752 | } |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 6753 | |
| 6754 | curproxy->uri_auth->flags |= ST_CONVDONE; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6755 | } |
| 6756 | out_uri_auth_compat: |
| 6757 | |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 6758 | /* compile the log format */ |
| 6759 | if (!(curproxy->cap & PR_CAP_FE)) { |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 6760 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 6761 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 6762 | curproxy->conf.logformat_string != clf_http_log_format) |
| 6763 | free(curproxy->conf.logformat_string); |
| 6764 | curproxy->conf.logformat_string = NULL; |
| 6765 | free(curproxy->conf.lfs_file); |
| 6766 | curproxy->conf.lfs_file = NULL; |
| 6767 | curproxy->conf.lfs_line = 0; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 6768 | } |
| 6769 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 6770 | if (curproxy->conf.logformat_string) { |
| 6771 | curproxy->conf.args.ctx = ARGC_LOG; |
| 6772 | curproxy->conf.args.file = curproxy->conf.lfs_file; |
| 6773 | curproxy->conf.args.line = curproxy->conf.lfs_line; |
| 6774 | 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] | 6775 | 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] | 6776 | curproxy->conf.args.file = NULL; |
| 6777 | curproxy->conf.args.line = 0; |
| 6778 | } |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 6779 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 6780 | if (curproxy->conf.uniqueid_format_string) { |
| 6781 | curproxy->conf.args.ctx = ARGC_UIF; |
| 6782 | curproxy->conf.args.file = curproxy->conf.uif_file; |
| 6783 | curproxy->conf.args.line = curproxy->conf.uif_line; |
Thierry FOURNIER | d048d8b | 2014-03-13 16:46:18 +0100 | [diff] [blame] | 6784 | 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] | 6785 | (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] | 6786 | curproxy->conf.uif_file, curproxy->conf.uif_line); |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 6787 | curproxy->conf.args.file = NULL; |
| 6788 | curproxy->conf.args.line = 0; |
| 6789 | } |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 6790 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6791 | /* only now we can check if some args remain unresolved. |
| 6792 | * This must be done after the users and groups resolution. |
| 6793 | */ |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 6794 | cfgerr += smp_resolve_args(curproxy); |
| 6795 | if (!cfgerr) |
| 6796 | cfgerr += acl_find_targets(curproxy); |
Krzysztof Piotr Oledzki | f9423ae | 2010-01-29 19:26:18 +0100 | [diff] [blame] | 6797 | |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 6798 | if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) && |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6799 | (((curproxy->cap & PR_CAP_FE) && !curproxy->timeout.client) || |
Willy Tarreau | d825eef | 2007-05-12 22:35:00 +0200 | [diff] [blame] | 6800 | ((curproxy->cap & PR_CAP_BE) && (curproxy->srv) && |
Willy Tarreau | ce887fd | 2012-05-12 12:50:00 +0200 | [diff] [blame] | 6801 | (!curproxy->timeout.connect || |
| 6802 | (!curproxy->timeout.server && (curproxy->mode == PR_MODE_HTTP || !curproxy->timeout.tunnel)))))) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6803 | Warning("config : missing timeouts for %s '%s'.\n" |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 6804 | " | While not properly invalid, you will certainly encounter various problems\n" |
| 6805 | " | 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] | 6806 | " | timeouts are set to a non-zero value: 'client', 'connect', 'server'.\n", |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6807 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6808 | err_code |= ERR_WARN; |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 6809 | } |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 6810 | |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6811 | /* Historically, the tarpit and queue timeouts were inherited from contimeout. |
| 6812 | * We must still support older configurations, so let's find out whether those |
| 6813 | * parameters have been set or must be copied from contimeouts. |
| 6814 | */ |
| 6815 | if (curproxy != &defproxy) { |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6816 | if (!curproxy->timeout.tarpit || |
| 6817 | curproxy->timeout.tarpit == defproxy.timeout.tarpit) { |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6818 | /* tarpit timeout not set. We search in the following order: |
| 6819 | * default.tarpit, curr.connect, default.connect. |
| 6820 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6821 | if (defproxy.timeout.tarpit) |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6822 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6823 | else if (curproxy->timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6824 | curproxy->timeout.tarpit = curproxy->timeout.connect; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6825 | else if (defproxy.timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6826 | curproxy->timeout.tarpit = defproxy.timeout.connect; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6827 | } |
| 6828 | if ((curproxy->cap & PR_CAP_BE) && |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6829 | (!curproxy->timeout.queue || |
| 6830 | curproxy->timeout.queue == defproxy.timeout.queue)) { |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6831 | /* queue timeout not set. We search in the following order: |
| 6832 | * default.queue, curr.connect, default.connect. |
| 6833 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6834 | if (defproxy.timeout.queue) |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6835 | curproxy->timeout.queue = defproxy.timeout.queue; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6836 | else if (curproxy->timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6837 | curproxy->timeout.queue = curproxy->timeout.connect; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6838 | else if (defproxy.timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6839 | curproxy->timeout.queue = defproxy.timeout.connect; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6840 | } |
| 6841 | } |
| 6842 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 6843 | if ((curproxy->options2 & PR_O2_CHK_ANY) == PR_O2_SSL3_CHK) { |
Willy Tarreau | 137325d | 2010-02-01 16:38:17 +0100 | [diff] [blame] | 6844 | curproxy->check_len = sizeof(sslv3_client_hello_pkt) - 1; |
| 6845 | curproxy->check_req = (char *)malloc(curproxy->check_len); |
| 6846 | memcpy(curproxy->check_req, sslv3_client_hello_pkt, curproxy->check_len); |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 6847 | } |
| 6848 | |
Willy Tarreau | 215663d | 2014-06-13 18:30:23 +0200 | [diff] [blame] | 6849 | if (!LIST_ISEMPTY(&curproxy->tcpcheck_rules) && |
| 6850 | (curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_TCPCHK_CHK) { |
| 6851 | Warning("config : %s '%s' uses tcp-check rules without 'option tcp-check', so the rules are ignored.\n", |
| 6852 | proxy_type_str(curproxy), curproxy->id); |
| 6853 | err_code |= ERR_WARN; |
| 6854 | } |
| 6855 | |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 6856 | /* ensure that cookie capture length is not too large */ |
| 6857 | if (curproxy->capture_len >= global.tune.cookie_len) { |
| 6858 | Warning("config : truncating capture length to %d bytes for %s '%s'.\n", |
| 6859 | global.tune.cookie_len - 1, proxy_type_str(curproxy), curproxy->id); |
| 6860 | err_code |= ERR_WARN; |
| 6861 | curproxy->capture_len = global.tune.cookie_len - 1; |
| 6862 | } |
| 6863 | |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 6864 | /* The small pools required for the capture lists */ |
Willy Tarreau | 9a54e13 | 2012-03-24 08:33:05 +0100 | [diff] [blame] | 6865 | if (curproxy->nb_req_cap) { |
Willy Tarreau | d9ed3d2 | 2014-06-13 12:23:06 +0200 | [diff] [blame] | 6866 | curproxy->req_cap_pool = create_pool("ptrcap", |
| 6867 | curproxy->nb_req_cap * sizeof(char *), |
| 6868 | MEM_F_SHARED); |
Willy Tarreau | 9a54e13 | 2012-03-24 08:33:05 +0100 | [diff] [blame] | 6869 | } |
| 6870 | |
| 6871 | if (curproxy->nb_rsp_cap) { |
Willy Tarreau | d9ed3d2 | 2014-06-13 12:23:06 +0200 | [diff] [blame] | 6872 | curproxy->rsp_cap_pool = create_pool("ptrcap", |
| 6873 | curproxy->nb_rsp_cap * sizeof(char *), |
| 6874 | MEM_F_SHARED); |
Willy Tarreau | 9a54e13 | 2012-03-24 08:33:05 +0100 | [diff] [blame] | 6875 | } |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 6876 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6877 | /* first, we will invert the servers list order */ |
| 6878 | newsrv = NULL; |
| 6879 | while (curproxy->srv) { |
| 6880 | struct server *next; |
| 6881 | |
| 6882 | next = curproxy->srv->next; |
| 6883 | curproxy->srv->next = newsrv; |
| 6884 | newsrv = curproxy->srv; |
| 6885 | if (!next) |
| 6886 | break; |
| 6887 | curproxy->srv = next; |
| 6888 | } |
| 6889 | |
Willy Tarreau | 17edc81 | 2014-01-03 12:14:34 +0100 | [diff] [blame] | 6890 | /* Check that no server name conflicts. This causes trouble in the stats. |
| 6891 | * We only emit a warning for the first conflict affecting each server, |
| 6892 | * in order to avoid combinatory explosion if all servers have the same |
| 6893 | * name. We do that only for servers which do not have an explicit ID, |
| 6894 | * because these IDs were made also for distinguishing them and we don't |
| 6895 | * want to annoy people who correctly manage them. |
| 6896 | */ |
| 6897 | for (newsrv = curproxy->srv; newsrv; newsrv = newsrv->next) { |
| 6898 | struct server *other_srv; |
| 6899 | |
| 6900 | if (newsrv->puid) |
| 6901 | continue; |
| 6902 | |
| 6903 | for (other_srv = curproxy->srv; other_srv && other_srv != newsrv; other_srv = other_srv->next) { |
| 6904 | if (!other_srv->puid && strcmp(other_srv->id, newsrv->id) == 0) { |
| 6905 | Warning("parsing [%s:%d] : %s '%s', another server named '%s' was defined without an explicit ID at line %d, this is not recommended.\n", |
| 6906 | newsrv->conf.file, newsrv->conf.line, |
| 6907 | proxy_type_str(curproxy), curproxy->id, |
| 6908 | newsrv->id, other_srv->conf.line); |
| 6909 | break; |
| 6910 | } |
| 6911 | } |
| 6912 | } |
| 6913 | |
Willy Tarreau | dd70165 | 2010-05-25 23:03:02 +0200 | [diff] [blame] | 6914 | /* assign automatic UIDs to servers which don't have one yet */ |
| 6915 | next_id = 1; |
| 6916 | newsrv = curproxy->srv; |
| 6917 | while (newsrv != NULL) { |
| 6918 | if (!newsrv->puid) { |
| 6919 | /* server ID not set, use automatic numbering with first |
| 6920 | * spare entry starting with next_svid. |
| 6921 | */ |
| 6922 | next_id = get_next_id(&curproxy->conf.used_server_id, next_id); |
| 6923 | newsrv->conf.id.key = newsrv->puid = next_id; |
| 6924 | eb32_insert(&curproxy->conf.used_server_id, &newsrv->conf.id); |
| 6925 | } |
| 6926 | next_id++; |
| 6927 | newsrv = newsrv->next; |
| 6928 | } |
| 6929 | |
Willy Tarreau | 2069704 | 2007-11-15 23:26:18 +0100 | [diff] [blame] | 6930 | curproxy->lbprm.wmult = 1; /* default weight multiplier */ |
Willy Tarreau | 5dc2fa6 | 2007-11-19 19:10:18 +0100 | [diff] [blame] | 6931 | curproxy->lbprm.wdiv = 1; /* default weight divider */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6932 | |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 6933 | /* |
| 6934 | * If this server supports a maxconn parameter, it needs a dedicated |
| 6935 | * tasks to fill the emptied slots when a connection leaves. |
| 6936 | * Also, resolve deferred tracking dependency if needed. |
| 6937 | */ |
| 6938 | newsrv = curproxy->srv; |
| 6939 | while (newsrv != NULL) { |
| 6940 | if (newsrv->minconn > newsrv->maxconn) { |
| 6941 | /* Only 'minconn' was specified, or it was higher than or equal |
| 6942 | * to 'maxconn'. Let's turn this into maxconn and clean it, as |
| 6943 | * this will avoid further useless expensive computations. |
| 6944 | */ |
| 6945 | newsrv->maxconn = newsrv->minconn; |
| 6946 | } else if (newsrv->maxconn && !newsrv->minconn) { |
| 6947 | /* minconn was not specified, so we set it to maxconn */ |
| 6948 | newsrv->minconn = newsrv->maxconn; |
| 6949 | } |
| 6950 | |
Emeric Brun | 01f8e2f | 2012-05-18 16:02:00 +0200 | [diff] [blame] | 6951 | #ifdef USE_OPENSSL |
Emeric Brun | 94324a4 | 2012-10-11 14:00:19 +0200 | [diff] [blame] | 6952 | if (newsrv->use_ssl || newsrv->check.use_ssl) |
| 6953 | cfgerr += ssl_sock_prepare_srv_ctx(newsrv, curproxy); |
Emeric Brun | 01f8e2f | 2012-05-18 16:02:00 +0200 | [diff] [blame] | 6954 | #endif /* USE_OPENSSL */ |
Emeric Brun | 94324a4 | 2012-10-11 14:00:19 +0200 | [diff] [blame] | 6955 | |
Willy Tarreau | 2f075e9 | 2013-12-03 11:11:34 +0100 | [diff] [blame] | 6956 | /* set the check type on the server */ |
| 6957 | newsrv->check.type = curproxy->options2 & PR_O2_CHK_ANY; |
| 6958 | |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 6959 | if (newsrv->trackit) { |
| 6960 | struct proxy *px; |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 6961 | struct server *srv, *loop; |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 6962 | char *pname, *sname; |
| 6963 | |
| 6964 | pname = newsrv->trackit; |
| 6965 | sname = strrchr(pname, '/'); |
| 6966 | |
| 6967 | if (sname) |
| 6968 | *sname++ = '\0'; |
| 6969 | else { |
| 6970 | sname = pname; |
| 6971 | pname = NULL; |
| 6972 | } |
| 6973 | |
| 6974 | if (pname) { |
| 6975 | px = findproxy(pname, PR_CAP_BE); |
| 6976 | if (!px) { |
| 6977 | Alert("config : %s '%s', server '%s': unable to find required proxy '%s' for tracking.\n", |
| 6978 | proxy_type_str(curproxy), curproxy->id, |
| 6979 | newsrv->id, pname); |
| 6980 | cfgerr++; |
| 6981 | goto next_srv; |
| 6982 | } |
| 6983 | } else |
| 6984 | px = curproxy; |
| 6985 | |
| 6986 | srv = findserver(px, sname); |
| 6987 | if (!srv) { |
| 6988 | Alert("config : %s '%s', server '%s': unable to find required server '%s' for tracking.\n", |
| 6989 | proxy_type_str(curproxy), curproxy->id, |
| 6990 | newsrv->id, sname); |
| 6991 | cfgerr++; |
| 6992 | goto next_srv; |
| 6993 | } |
| 6994 | |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 6995 | if (!(srv->check.state & CHK_ST_CONFIGURED) && |
| 6996 | !(srv->agent.state & CHK_ST_CONFIGURED) && |
| 6997 | !srv->track && !srv->trackit) { |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 6998 | Alert("config : %s '%s', server '%s': unable to use %s/%s for " |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 6999 | "tracking as it does not have any check nor agent enabled.\n", |
| 7000 | proxy_type_str(curproxy), curproxy->id, |
| 7001 | newsrv->id, px->id, srv->id); |
| 7002 | cfgerr++; |
| 7003 | goto next_srv; |
| 7004 | } |
| 7005 | |
| 7006 | for (loop = srv->track; loop && loop != newsrv; loop = loop->track); |
| 7007 | |
| 7008 | if (loop) { |
| 7009 | Alert("config : %s '%s', server '%s': unable to track %s/%s as it " |
| 7010 | "belongs to a tracking chain looping back to %s/%s.\n", |
| 7011 | proxy_type_str(curproxy), curproxy->id, |
| 7012 | newsrv->id, px->id, srv->id, px->id, loop->id); |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 7013 | cfgerr++; |
| 7014 | goto next_srv; |
| 7015 | } |
| 7016 | |
| 7017 | if (curproxy != px && |
| 7018 | (curproxy->options & PR_O_DISABLE404) != (px->options & PR_O_DISABLE404)) { |
| 7019 | Alert("config : %s '%s', server '%s': unable to use %s/%s for" |
| 7020 | "tracking: disable-on-404 option inconsistency.\n", |
| 7021 | proxy_type_str(curproxy), curproxy->id, |
| 7022 | newsrv->id, px->id, srv->id); |
| 7023 | cfgerr++; |
| 7024 | goto next_srv; |
| 7025 | } |
| 7026 | |
| 7027 | /* 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] | 7028 | if (srv->admin & SRV_ADMF_MAINT) { |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 7029 | newsrv->admin |= SRV_ADMF_IMAINT; |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 7030 | newsrv->state = SRV_ST_STOPPED; |
Simon Horman | 125d099 | 2013-02-24 17:23:38 +0900 | [diff] [blame] | 7031 | newsrv->check.health = 0; |
Simon Horman | d60d691 | 2013-11-25 10:46:36 +0900 | [diff] [blame] | 7032 | newsrv->agent.health = 0; |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 7033 | } |
| 7034 | |
| 7035 | newsrv->track = srv; |
Willy Tarreau | 1a53a3a | 2013-12-11 15:27:05 +0100 | [diff] [blame] | 7036 | newsrv->tracknext = srv->trackers; |
| 7037 | srv->trackers = newsrv; |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 7038 | |
| 7039 | free(newsrv->trackit); |
| 7040 | newsrv->trackit = NULL; |
| 7041 | } |
| 7042 | next_srv: |
| 7043 | newsrv = newsrv->next; |
| 7044 | } |
| 7045 | |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 7046 | /* We have to initialize the server lookup mechanism depending |
| 7047 | * on what LB algorithm was choosen. |
| 7048 | */ |
| 7049 | |
| 7050 | curproxy->lbprm.algo &= ~(BE_LB_LKUP | BE_LB_PROP_DYN); |
| 7051 | switch (curproxy->lbprm.algo & BE_LB_KIND) { |
| 7052 | case BE_LB_KIND_RR: |
Willy Tarreau | 9757a38 | 2009-10-03 12:56:50 +0200 | [diff] [blame] | 7053 | if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_RR_STATIC) { |
| 7054 | curproxy->lbprm.algo |= BE_LB_LKUP_MAP; |
| 7055 | init_server_map(curproxy); |
| 7056 | } else { |
| 7057 | curproxy->lbprm.algo |= BE_LB_LKUP_RRTREE | BE_LB_PROP_DYN; |
| 7058 | fwrr_init_server_groups(curproxy); |
| 7059 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 7060 | break; |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 7061 | |
Willy Tarreau | 3ebb116 | 2012-02-13 16:57:44 +0100 | [diff] [blame] | 7062 | case BE_LB_KIND_CB: |
Willy Tarreau | f09c660 | 2012-02-13 17:12:08 +0100 | [diff] [blame] | 7063 | if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_CB_LC) { |
| 7064 | curproxy->lbprm.algo |= BE_LB_LKUP_LCTREE | BE_LB_PROP_DYN; |
| 7065 | fwlc_init_server_tree(curproxy); |
| 7066 | } else { |
| 7067 | curproxy->lbprm.algo |= BE_LB_LKUP_FSTREE | BE_LB_PROP_DYN; |
| 7068 | fas_init_server_tree(curproxy); |
| 7069 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 7070 | break; |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 7071 | |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 7072 | case BE_LB_KIND_HI: |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 7073 | if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS) { |
| 7074 | curproxy->lbprm.algo |= BE_LB_LKUP_CHTREE | BE_LB_PROP_DYN; |
| 7075 | chash_init_server_tree(curproxy); |
| 7076 | } else { |
| 7077 | curproxy->lbprm.algo |= BE_LB_LKUP_MAP; |
| 7078 | init_server_map(curproxy); |
| 7079 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 7080 | break; |
| 7081 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7082 | |
| 7083 | if (curproxy->options & PR_O_LOGASAP) |
| 7084 | curproxy->to_log &= ~LW_BYTES; |
| 7085 | |
Willy Tarreau | e7ded1f | 2009-08-09 10:11:45 +0200 | [diff] [blame] | 7086 | if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) && |
Willy Tarreau | d79a3b2 | 2012-12-28 09:40:16 +0100 | [diff] [blame] | 7087 | (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] | 7088 | Warning("config : log format ignored for %s '%s' since it has no log address.\n", |
| 7089 | proxy_type_str(curproxy), curproxy->id); |
| 7090 | err_code |= ERR_WARN; |
| 7091 | } |
| 7092 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 7093 | if (curproxy->mode != PR_MODE_HTTP) { |
| 7094 | int optnum; |
| 7095 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 7096 | if (curproxy->uri_auth) { |
| 7097 | Warning("config : 'stats' statement ignored for %s '%s' as it requires HTTP mode.\n", |
| 7098 | proxy_type_str(curproxy), curproxy->id); |
| 7099 | err_code |= ERR_WARN; |
| 7100 | curproxy->uri_auth = NULL; |
| 7101 | } |
| 7102 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 7103 | if (curproxy->options & (PR_O_FWDFOR | PR_O_FF_ALWAYS)) { |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 7104 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 7105 | "forwardfor", proxy_type_str(curproxy), curproxy->id); |
| 7106 | err_code |= ERR_WARN; |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 7107 | curproxy->options &= ~(PR_O_FWDFOR | PR_O_FF_ALWAYS); |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 7108 | } |
| 7109 | |
| 7110 | if (curproxy->options & PR_O_ORGTO) { |
| 7111 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 7112 | "originalto", proxy_type_str(curproxy), curproxy->id); |
| 7113 | err_code |= ERR_WARN; |
| 7114 | curproxy->options &= ~PR_O_ORGTO; |
| 7115 | } |
| 7116 | |
| 7117 | for (optnum = 0; cfg_opts[optnum].name; optnum++) { |
| 7118 | if (cfg_opts[optnum].mode == PR_MODE_HTTP && |
| 7119 | (curproxy->cap & cfg_opts[optnum].cap) && |
| 7120 | (curproxy->options & cfg_opts[optnum].val)) { |
| 7121 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 7122 | cfg_opts[optnum].name, proxy_type_str(curproxy), curproxy->id); |
| 7123 | err_code |= ERR_WARN; |
| 7124 | curproxy->options &= ~cfg_opts[optnum].val; |
| 7125 | } |
| 7126 | } |
| 7127 | |
| 7128 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) { |
| 7129 | if (cfg_opts2[optnum].mode == PR_MODE_HTTP && |
| 7130 | (curproxy->cap & cfg_opts2[optnum].cap) && |
| 7131 | (curproxy->options2 & cfg_opts2[optnum].val)) { |
| 7132 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 7133 | cfg_opts2[optnum].name, proxy_type_str(curproxy), curproxy->id); |
| 7134 | err_code |= ERR_WARN; |
| 7135 | curproxy->options2 &= ~cfg_opts2[optnum].val; |
| 7136 | } |
| 7137 | } |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 7138 | |
Pieter Baauw | d551fb5 | 2013-05-08 22:49:23 +0200 | [diff] [blame] | 7139 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_TRANSPARENT) |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 7140 | if (curproxy->conn_src.bind_hdr_occ) { |
| 7141 | curproxy->conn_src.bind_hdr_occ = 0; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 7142 | 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] | 7143 | proxy_type_str(curproxy), curproxy->id, curproxy->conn_src.bind_hdr_name); |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 7144 | err_code |= ERR_WARN; |
| 7145 | } |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 7146 | #endif |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 7147 | } |
| 7148 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7149 | /* |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 7150 | * ensure that we're not cross-dressing a TCP server into HTTP. |
| 7151 | */ |
| 7152 | newsrv = curproxy->srv; |
| 7153 | while (newsrv != NULL) { |
Willy Tarreau | 0cec331 | 2011-10-31 13:49:26 +0100 | [diff] [blame] | 7154 | if ((curproxy->mode != PR_MODE_HTTP) && newsrv->rdr_len) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7155 | Alert("config : %s '%s' : server cannot have cookie or redirect prefix in non-HTTP mode.\n", |
| 7156 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 7157 | cfgerr++; |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 7158 | } |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 7159 | |
Willy Tarreau | 0cec331 | 2011-10-31 13:49:26 +0100 | [diff] [blame] | 7160 | if ((curproxy->mode != PR_MODE_HTTP) && newsrv->cklen) { |
| 7161 | Warning("config : %s '%s' : ignoring cookie for server '%s' as HTTP mode is disabled.\n", |
| 7162 | proxy_type_str(curproxy), curproxy->id, newsrv->id); |
| 7163 | err_code |= ERR_WARN; |
| 7164 | } |
| 7165 | |
Willy Tarreau | c93cd16 | 2014-05-13 15:54:22 +0200 | [diff] [blame] | 7166 | if ((newsrv->flags & SRV_F_MAPPORTS) && (curproxy->options2 & PR_O2_RDPC_PRST)) { |
Willy Tarreau | 82ffa39 | 2013-08-13 17:19:08 +0200 | [diff] [blame] | 7167 | Warning("config : %s '%s' : RDP cookie persistence will not work for server '%s' because it lacks an explicit port number.\n", |
| 7168 | proxy_type_str(curproxy), curproxy->id, newsrv->id); |
| 7169 | err_code |= ERR_WARN; |
| 7170 | } |
| 7171 | |
Pieter Baauw | d551fb5 | 2013-05-08 22:49:23 +0200 | [diff] [blame] | 7172 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_TRANSPARENT) |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 7173 | if (curproxy->mode != PR_MODE_HTTP && newsrv->conn_src.bind_hdr_occ) { |
| 7174 | newsrv->conn_src.bind_hdr_occ = 0; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 7175 | 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] | 7176 | 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] | 7177 | err_code |= ERR_WARN; |
| 7178 | } |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 7179 | #endif |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 7180 | newsrv = newsrv->next; |
| 7181 | } |
| 7182 | |
Willy Tarreau | e42bd96 | 2014-09-16 16:21:19 +0200 | [diff] [blame] | 7183 | /* check if we have a frontend with "tcp-request content" looking at L7 |
| 7184 | * with no inspect-delay |
| 7185 | */ |
| 7186 | if ((curproxy->cap & PR_CAP_FE) && !curproxy->tcp_req.inspect_delay) { |
| 7187 | list_for_each_entry(trule, &curproxy->tcp_req.inspect_rules, list) { |
| 7188 | if (trule->action == TCP_ACT_CAPTURE && |
| 7189 | !(trule->act_prm.cap.expr->fetch->val & SMP_VAL_FE_SES_ACC)) |
| 7190 | break; |
| 7191 | if ((trule->action >= TCP_ACT_TRK_SC0 && trule->action <= TCP_ACT_TRK_SCMAX) && |
| 7192 | !(trule->act_prm.trk_ctr.expr->fetch->val & SMP_VAL_FE_SES_ACC)) |
| 7193 | break; |
| 7194 | } |
| 7195 | |
| 7196 | if (&trule->list != &curproxy->tcp_req.inspect_rules) { |
| 7197 | Warning("config : %s '%s' : some 'tcp-request content' rules explicitly depending on request" |
| 7198 | " contents were found in a frontend without any 'tcp-request inspect-delay' setting." |
| 7199 | " This means that these rules will randomly find their contents. This can be fixed by" |
| 7200 | " setting the tcp-request inspect-delay.\n", |
| 7201 | proxy_type_str(curproxy), curproxy->id); |
| 7202 | err_code |= ERR_WARN; |
| 7203 | } |
| 7204 | } |
| 7205 | |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 7206 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 7207 | if (!curproxy->accept) |
| 7208 | curproxy->accept = frontend_accept; |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 7209 | |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 7210 | if (curproxy->tcp_req.inspect_delay || |
| 7211 | !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules)) |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 7212 | curproxy->fe_req_ana |= AN_REQ_INSPECT_FE; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 7213 | |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 7214 | if (curproxy->mode == PR_MODE_HTTP) { |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 7215 | 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] | 7216 | 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] | 7217 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 7218 | |
| 7219 | /* both TCP and HTTP must check switching rules */ |
| 7220 | curproxy->fe_req_ana |= AN_REQ_SWITCHING_RULES; |
| 7221 | } |
| 7222 | |
| 7223 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 7224 | if (curproxy->tcp_req.inspect_delay || |
| 7225 | !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules)) |
| 7226 | curproxy->be_req_ana |= AN_REQ_INSPECT_BE; |
| 7227 | |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 7228 | if (!LIST_ISEMPTY(&curproxy->tcp_rep.inspect_rules)) |
| 7229 | curproxy->be_rsp_ana |= AN_RES_INSPECT; |
| 7230 | |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 7231 | if (curproxy->mode == PR_MODE_HTTP) { |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 7232 | 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] | 7233 | 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] | 7234 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 7235 | |
| 7236 | /* If the backend does requires RDP cookie persistence, we have to |
| 7237 | * enable the corresponding analyser. |
| 7238 | */ |
| 7239 | if (curproxy->options2 & PR_O2_RDPC_PRST) |
| 7240 | curproxy->be_req_ana |= AN_REQ_PRST_RDP_COOKIE; |
| 7241 | } |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 7242 | } |
| 7243 | |
| 7244 | /***********************************************************/ |
| 7245 | /* At this point, target names have already been resolved. */ |
| 7246 | /***********************************************************/ |
| 7247 | |
| 7248 | /* Check multi-process mode compatibility */ |
| 7249 | |
| 7250 | if (global.nbproc > 1 && global.stats_fe) { |
| 7251 | list_for_each_entry(bind_conf, &global.stats_fe->conf.bind, by_fe) { |
| 7252 | unsigned long mask; |
| 7253 | |
| 7254 | mask = nbits(global.nbproc); |
| 7255 | if (global.stats_fe->bind_proc) |
| 7256 | mask &= global.stats_fe->bind_proc; |
| 7257 | |
| 7258 | if (bind_conf->bind_proc) |
| 7259 | mask &= bind_conf->bind_proc; |
| 7260 | |
| 7261 | /* stop here if more than one process is used */ |
| 7262 | if (popcount(mask) > 1) |
| 7263 | break; |
| 7264 | } |
| 7265 | if (&bind_conf->by_fe != &global.stats_fe->conf.bind) { |
| 7266 | 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"); |
| 7267 | } |
| 7268 | } |
| 7269 | |
| 7270 | /* Make each frontend inherit bind-process from its listeners when not specified. */ |
| 7271 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 7272 | if (curproxy->bind_proc) |
| 7273 | continue; |
| 7274 | |
| 7275 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
| 7276 | unsigned long mask; |
| 7277 | |
| 7278 | mask = bind_conf->bind_proc ? bind_conf->bind_proc : ~0UL; |
| 7279 | curproxy->bind_proc |= mask; |
| 7280 | } |
| 7281 | |
| 7282 | if (!curproxy->bind_proc) |
| 7283 | curproxy->bind_proc = ~0UL; |
| 7284 | } |
| 7285 | |
| 7286 | if (global.stats_fe) { |
| 7287 | list_for_each_entry(bind_conf, &global.stats_fe->conf.bind, by_fe) { |
| 7288 | unsigned long mask; |
| 7289 | |
| 7290 | mask = bind_conf->bind_proc ? bind_conf->bind_proc : ~0UL; |
| 7291 | global.stats_fe->bind_proc |= mask; |
| 7292 | } |
| 7293 | if (!global.stats_fe->bind_proc) |
| 7294 | global.stats_fe->bind_proc = ~0UL; |
| 7295 | } |
| 7296 | |
Willy Tarreau | acbe8ab | 2014-10-01 20:50:17 +0200 | [diff] [blame] | 7297 | /* propagate bindings from frontends to backends. Don't do it if there |
| 7298 | * are any fatal errors as we must not call it with unresolved proxies. |
| 7299 | */ |
| 7300 | if (!cfgerr) { |
| 7301 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 7302 | if (curproxy->cap & PR_CAP_FE) |
| 7303 | propagate_processes(curproxy, NULL); |
| 7304 | } |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 7305 | } |
| 7306 | |
| 7307 | /* Bind each unbound backend to all processes when not specified. */ |
| 7308 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 7309 | if (curproxy->bind_proc) |
| 7310 | continue; |
| 7311 | curproxy->bind_proc = ~0UL; |
| 7312 | } |
| 7313 | |
| 7314 | /*******************************************************/ |
| 7315 | /* At this step, all proxies have a non-null bind_proc */ |
| 7316 | /*******************************************************/ |
| 7317 | |
| 7318 | /* perform the final checks before creating tasks */ |
| 7319 | |
| 7320 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 7321 | struct listener *listener; |
| 7322 | unsigned int next_id; |
| 7323 | int nbproc; |
| 7324 | |
| 7325 | nbproc = popcount(curproxy->bind_proc & nbits(global.nbproc)); |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 7326 | |
Emeric Brun | c52962f | 2012-11-15 18:28:02 +0100 | [diff] [blame] | 7327 | #ifdef USE_OPENSSL |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 7328 | /* Configure SSL for each bind line. |
| 7329 | * Note: if configuration fails at some point, the ->ctx member |
| 7330 | * remains NULL so that listeners can later detach. |
| 7331 | */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7332 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
Emeric Brun | caa19cc | 2014-05-07 16:10:18 +0200 | [diff] [blame] | 7333 | int alloc_ctx; |
| 7334 | |
Emeric Brun | c52962f | 2012-11-15 18:28:02 +0100 | [diff] [blame] | 7335 | if (!bind_conf->is_ssl) { |
| 7336 | if (bind_conf->default_ctx) { |
| 7337 | Warning("Proxy '%s': A certificate was specified but SSL was not enabled on bind '%s' at [%s:%d] (use 'ssl').\n", |
| 7338 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
| 7339 | } |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7340 | continue; |
Emeric Brun | c52962f | 2012-11-15 18:28:02 +0100 | [diff] [blame] | 7341 | } |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7342 | if (!bind_conf->default_ctx) { |
Emeric Brun | fc0421f | 2012-09-07 17:30:07 +0200 | [diff] [blame] | 7343 | 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] | 7344 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 7345 | cfgerr++; |
| 7346 | continue; |
| 7347 | } |
| 7348 | |
Emeric Brun | 8dc6039 | 2014-05-09 13:52:00 +0200 | [diff] [blame] | 7349 | 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] | 7350 | if (alloc_ctx < 0) { |
Emeric Brun | 93ee249 | 2014-05-09 14:01:48 +0200 | [diff] [blame] | 7351 | if (alloc_ctx == SHCTX_E_INIT_LOCK) |
| 7352 | 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"); |
| 7353 | else |
Emeric Brun | caa19cc | 2014-05-07 16:10:18 +0200 | [diff] [blame] | 7354 | Alert("Unable to allocate SSL session cache.\n"); |
Emeric Brun | 93ee249 | 2014-05-09 14:01:48 +0200 | [diff] [blame] | 7355 | cfgerr++; |
| 7356 | continue; |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 7357 | } |
| 7358 | |
Emeric Brun | fc0421f | 2012-09-07 17:30:07 +0200 | [diff] [blame] | 7359 | /* initialize all certificate contexts */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7360 | cfgerr += ssl_sock_prepare_all_ctx(bind_conf, curproxy); |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7361 | } |
Emeric Brun | c52962f | 2012-11-15 18:28:02 +0100 | [diff] [blame] | 7362 | #endif /* USE_OPENSSL */ |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 7363 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 7364 | /* adjust this proxy's listeners */ |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7365 | next_id = 1; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 7366 | list_for_each_entry(listener, &curproxy->conf.listeners, by_fe) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7367 | if (!listener->luid) { |
| 7368 | /* listener ID not set, use automatic numbering with first |
| 7369 | * spare entry starting with next_luid. |
| 7370 | */ |
| 7371 | next_id = get_next_id(&curproxy->conf.used_listener_id, next_id); |
| 7372 | listener->conf.id.key = listener->luid = next_id; |
| 7373 | eb32_insert(&curproxy->conf.used_listener_id, &listener->conf.id); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7374 | } |
Krzysztof Piotr Oledzki | df5cb9f | 2010-02-05 20:58:27 +0100 | [diff] [blame] | 7375 | next_id++; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7376 | |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 7377 | /* enable separate counters */ |
| 7378 | if (curproxy->options2 & PR_O2_SOCKSTAT) { |
| 7379 | listener->counters = (struct licounters *)calloc(1, sizeof(struct licounters)); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 7380 | if (!listener->name) |
| 7381 | memprintf(&listener->name, "sock-%d", listener->luid); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 7382 | } |
Willy Tarreau | 81796be | 2012-09-22 19:11:47 +0200 | [diff] [blame] | 7383 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 7384 | if (curproxy->options & PR_O_TCP_NOLING) |
| 7385 | listener->options |= LI_O_NOLINGER; |
Willy Tarreau | 32368ce | 2012-09-06 11:10:55 +0200 | [diff] [blame] | 7386 | if (!listener->maxconn) |
| 7387 | listener->maxconn = curproxy->maxconn; |
| 7388 | if (!listener->backlog) |
| 7389 | listener->backlog = curproxy->backlog; |
Willy Tarreau | 16a2147 | 2012-11-19 12:39:59 +0100 | [diff] [blame] | 7390 | if (!listener->maxaccept) |
| 7391 | listener->maxaccept = global.tune.maxaccept ? global.tune.maxaccept : 64; |
| 7392 | |
| 7393 | /* we want to have an optimal behaviour on single process mode to |
| 7394 | * maximize the work at once, but in multi-process we want to keep |
| 7395 | * some fairness between processes, so we target half of the max |
| 7396 | * number of events to be balanced over all the processes the proxy |
| 7397 | * is bound to. Rememeber that maxaccept = -1 must be kept as it is |
| 7398 | * used to disable the limit. |
| 7399 | */ |
| 7400 | if (listener->maxaccept > 0) { |
| 7401 | if (nbproc > 1) |
| 7402 | listener->maxaccept = (listener->maxaccept + 1) / 2; |
| 7403 | listener->maxaccept = (listener->maxaccept + nbproc - 1) / nbproc; |
| 7404 | } |
| 7405 | |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 7406 | listener->timeout = &curproxy->timeout.client; |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 7407 | listener->accept = session_accept; |
Willy Tarreau | 3bc1377 | 2008-12-07 11:50:35 +0100 | [diff] [blame] | 7408 | listener->handler = process_session; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 7409 | listener->analysers |= curproxy->fe_req_ana; |
Willy Tarreau | 3bc1377 | 2008-12-07 11:50:35 +0100 | [diff] [blame] | 7410 | |
Willy Tarreau | a5c0ab2 | 2010-05-31 10:30:33 +0200 | [diff] [blame] | 7411 | if (!LIST_ISEMPTY(&curproxy->tcp_req.l4_rules)) |
| 7412 | listener->options |= LI_O_TCP_RULES; |
| 7413 | |
Willy Tarreau | de3041d | 2010-05-31 10:56:17 +0200 | [diff] [blame] | 7414 | if (curproxy->mon_mask.s_addr) |
| 7415 | listener->options |= LI_O_CHK_MONNET; |
| 7416 | |
Willy Tarreau | 9ea05a7 | 2009-06-14 12:07:01 +0200 | [diff] [blame] | 7417 | /* smart accept mode is automatic in HTTP mode */ |
| 7418 | if ((curproxy->options2 & PR_O2_SMARTACC) || |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7419 | ((curproxy->mode == PR_MODE_HTTP || listener->bind_conf->is_ssl) && |
Willy Tarreau | 9ea05a7 | 2009-06-14 12:07:01 +0200 | [diff] [blame] | 7420 | !(curproxy->no_options2 & PR_O2_SMARTACC))) |
| 7421 | listener->options |= LI_O_NOQUICKACK; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 7422 | } |
| 7423 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7424 | /* Release unused SSL configs */ |
| 7425 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
| 7426 | if (bind_conf->is_ssl) |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 7427 | continue; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7428 | #ifdef USE_OPENSSL |
| 7429 | ssl_sock_free_all_ctx(bind_conf); |
Emeric Brun | fb510ea | 2012-10-05 12:00:26 +0200 | [diff] [blame] | 7430 | free(bind_conf->ca_file); |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7431 | free(bind_conf->ciphers); |
Emeric Brun | 2b58d04 | 2012-09-20 17:10:03 +0200 | [diff] [blame] | 7432 | free(bind_conf->ecdhe); |
Emeric Brun | fb510ea | 2012-10-05 12:00:26 +0200 | [diff] [blame] | 7433 | free(bind_conf->crl_file); |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 7434 | #endif /* USE_OPENSSL */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7435 | } |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 7436 | |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 7437 | if (nbproc > 1) { |
| 7438 | if (curproxy->uri_auth) { |
Willy Tarreau | eb791e0 | 2014-09-16 15:11:04 +0200 | [diff] [blame] | 7439 | int count, maxproc = 0; |
| 7440 | |
| 7441 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
| 7442 | count = popcount(bind_conf->bind_proc); |
| 7443 | if (count > maxproc) |
| 7444 | maxproc = count; |
| 7445 | } |
| 7446 | /* backends have 0, frontends have 1 or more */ |
| 7447 | if (maxproc != 1) |
| 7448 | Warning("Proxy '%s': in multi-process mode, stats will be" |
| 7449 | " limited to process assigned to the current request.\n", |
| 7450 | curproxy->id); |
| 7451 | |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 7452 | if (!LIST_ISEMPTY(&curproxy->uri_auth->admin_rules)) { |
| 7453 | Warning("Proxy '%s': stats admin will not work correctly in multi-process mode.\n", |
| 7454 | curproxy->id); |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 7455 | } |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 7456 | } |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 7457 | if (curproxy->appsession_name) { |
| 7458 | Warning("Proxy '%s': appsession will not work correctly in multi-process mode.\n", |
| 7459 | curproxy->id); |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 7460 | } |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 7461 | if (!LIST_ISEMPTY(&curproxy->sticking_rules)) { |
| 7462 | Warning("Proxy '%s': sticking rules will not work correctly in multi-process mode.\n", |
| 7463 | curproxy->id); |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 7464 | } |
| 7465 | } |
Willy Tarreau | 918ff60 | 2011-07-25 16:33:49 +0200 | [diff] [blame] | 7466 | |
| 7467 | /* create the task associated with the proxy */ |
| 7468 | curproxy->task = task_new(); |
| 7469 | if (curproxy->task) { |
| 7470 | curproxy->task->context = curproxy; |
| 7471 | curproxy->task->process = manage_proxy; |
| 7472 | /* no need to queue, it will be done automatically if some |
| 7473 | * listener gets limited. |
| 7474 | */ |
| 7475 | curproxy->task->expire = TICK_ETERNITY; |
| 7476 | } else { |
| 7477 | Alert("Proxy '%s': no more memory when trying to allocate the management task\n", |
| 7478 | curproxy->id); |
| 7479 | cfgerr++; |
| 7480 | } |
Willy Tarreau | b369a04 | 2014-09-16 13:21:03 +0200 | [diff] [blame] | 7481 | } |
| 7482 | |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 7483 | /* automatically compute fullconn if not set. We must not do it in the |
| 7484 | * loop above because cross-references are not yet fully resolved. |
| 7485 | */ |
| 7486 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 7487 | /* If <fullconn> is not set, let's set it to 10% of the sum of |
| 7488 | * the possible incoming frontend's maxconns. |
| 7489 | */ |
| 7490 | if (!curproxy->fullconn && (curproxy->cap & PR_CAP_BE)) { |
| 7491 | struct proxy *fe; |
| 7492 | int total = 0; |
| 7493 | |
| 7494 | /* sum up the number of maxconns of frontends which |
| 7495 | * reference this backend at least once or which are |
| 7496 | * the same one ('listen'). |
| 7497 | */ |
| 7498 | for (fe = proxy; fe; fe = fe->next) { |
| 7499 | struct switching_rule *rule; |
| 7500 | struct hdr_exp *exp; |
| 7501 | int found = 0; |
| 7502 | |
| 7503 | if (!(fe->cap & PR_CAP_FE)) |
| 7504 | continue; |
| 7505 | |
| 7506 | if (fe == curproxy) /* we're on a "listen" instance */ |
| 7507 | found = 1; |
| 7508 | |
| 7509 | if (fe->defbe.be == curproxy) /* "default_backend" */ |
| 7510 | found = 1; |
| 7511 | |
| 7512 | /* check if a "use_backend" rule matches */ |
| 7513 | if (!found) { |
| 7514 | list_for_each_entry(rule, &fe->switching_rules, list) { |
Bertrand Jacquin | 702d44f | 2013-11-19 11:43:06 +0100 | [diff] [blame] | 7515 | if (!rule->dynamic && rule->be.backend == curproxy) { |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 7516 | found = 1; |
| 7517 | break; |
| 7518 | } |
| 7519 | } |
| 7520 | } |
| 7521 | |
| 7522 | /* check if a "reqsetbe" rule matches */ |
| 7523 | for (exp = fe->req_exp; !found && exp; exp = exp->next) { |
| 7524 | if (exp->action == ACT_SETBE && |
| 7525 | (struct proxy *)exp->replace == curproxy) { |
| 7526 | found = 1; |
| 7527 | break; |
| 7528 | } |
| 7529 | } |
| 7530 | |
| 7531 | /* now we've checked all possible ways to reference a backend |
| 7532 | * from a frontend. |
| 7533 | */ |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 7534 | if (!found) |
| 7535 | continue; |
| 7536 | total += fe->maxconn; |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 7537 | } |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 7538 | /* we have the sum of the maxconns in <total>. We only |
| 7539 | * keep 10% of that sum to set the default fullconn, with |
| 7540 | * a hard minimum of 1 (to avoid a divide by zero). |
| 7541 | */ |
| 7542 | curproxy->fullconn = (total + 9) / 10; |
| 7543 | if (!curproxy->fullconn) |
| 7544 | curproxy->fullconn = 1; |
| 7545 | } |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 7546 | } |
| 7547 | |
Willy Tarreau | 056f568 | 2010-06-06 15:51:11 +0200 | [diff] [blame] | 7548 | /* initialize stick-tables on backend capable proxies. This must not |
| 7549 | * be done earlier because the data size may be discovered while parsing |
| 7550 | * other proxies. |
| 7551 | */ |
Godbach | 9703e66 | 2013-12-11 21:11:41 +0800 | [diff] [blame] | 7552 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
Willy Tarreau | 5830213 | 2014-02-24 20:59:47 +0100 | [diff] [blame] | 7553 | if (curproxy->state == PR_STSTOPPED) |
| 7554 | continue; |
| 7555 | |
Godbach | 9703e66 | 2013-12-11 21:11:41 +0800 | [diff] [blame] | 7556 | if (!stktable_init(&curproxy->table)) { |
| 7557 | Alert("Proxy '%s': failed to initialize stick-table.\n", curproxy->id); |
| 7558 | cfgerr++; |
| 7559 | } |
| 7560 | } |
Willy Tarreau | 056f568 | 2010-06-06 15:51:11 +0200 | [diff] [blame] | 7561 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7562 | /* |
| 7563 | * Recount currently required checks. |
| 7564 | */ |
| 7565 | |
| 7566 | for (curproxy=proxy; curproxy; curproxy=curproxy->next) { |
| 7567 | int optnum; |
| 7568 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 7569 | for (optnum = 0; cfg_opts[optnum].name; optnum++) |
| 7570 | if (curproxy->options & cfg_opts[optnum].val) |
| 7571 | global.last_checks |= cfg_opts[optnum].checks; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7572 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 7573 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) |
| 7574 | if (curproxy->options2 & cfg_opts2[optnum].val) |
| 7575 | global.last_checks |= cfg_opts2[optnum].checks; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7576 | } |
| 7577 | |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 7578 | if (peers) { |
| 7579 | struct peers *curpeers = peers, **last; |
| 7580 | struct peer *p, *pb; |
| 7581 | |
| 7582 | /* Remove all peers sections which don't have a valid listener. |
| 7583 | * This can happen when a peers section is never referenced and |
| 7584 | * does not contain a local peer. |
| 7585 | */ |
| 7586 | last = &peers; |
| 7587 | while (*last) { |
| 7588 | curpeers = *last; |
| 7589 | if (curpeers->peers_fe) { |
| 7590 | last = &curpeers->next; |
| 7591 | continue; |
| 7592 | } |
| 7593 | |
| 7594 | Warning("Removing incomplete section 'peers %s' (no peer named '%s').\n", |
| 7595 | curpeers->id, localpeer); |
| 7596 | |
| 7597 | p = curpeers->remote; |
| 7598 | while (p) { |
| 7599 | pb = p->next; |
| 7600 | free(p->id); |
| 7601 | free(p); |
| 7602 | p = pb; |
| 7603 | } |
| 7604 | |
| 7605 | /* Destroy and unlink this curpeers section. |
| 7606 | * Note: curpeers is backed up into *last. |
| 7607 | */ |
| 7608 | free(curpeers->id); |
| 7609 | curpeers = curpeers->next; |
| 7610 | free(*last); |
| 7611 | *last = curpeers; |
| 7612 | } |
| 7613 | } |
| 7614 | |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 7615 | pool2_hdr_idx = create_pool("hdr_idx", |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame] | 7616 | global.tune.max_http_hdr * sizeof(struct hdr_idx_elem), |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 7617 | MEM_F_SHARED); |
| 7618 | |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 7619 | if (cfgerr > 0) |
| 7620 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7621 | out: |
| 7622 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7623 | } |
| 7624 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 7625 | /* |
| 7626 | * Registers the CFG keyword list <kwl> as a list of valid keywords for next |
| 7627 | * parsing sessions. |
| 7628 | */ |
| 7629 | void cfg_register_keywords(struct cfg_kw_list *kwl) |
| 7630 | { |
| 7631 | LIST_ADDQ(&cfg_keywords.list, &kwl->list); |
| 7632 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7633 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 7634 | /* |
| 7635 | * Unregisters the CFG keyword list <kwl> from the list of valid keywords. |
| 7636 | */ |
| 7637 | void cfg_unregister_keywords(struct cfg_kw_list *kwl) |
| 7638 | { |
| 7639 | LIST_DEL(&kwl->list); |
| 7640 | LIST_INIT(&kwl->list); |
| 7641 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7642 | |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 7643 | /* this function register new section in the haproxy configuration file. |
| 7644 | * <section_name> is the name of this new section and <section_parser> |
| 7645 | * is the called parser. If two section declaration have the same name, |
| 7646 | * only the first declared is used. |
| 7647 | */ |
| 7648 | int cfg_register_section(char *section_name, |
| 7649 | int (*section_parser)(const char *, int, char **, int)) |
| 7650 | { |
| 7651 | struct cfg_section *cs; |
| 7652 | |
| 7653 | cs = calloc(1, sizeof(*cs)); |
| 7654 | if (!cs) { |
| 7655 | Alert("register section '%s': out of memory.\n", section_name); |
| 7656 | return 0; |
| 7657 | } |
| 7658 | |
| 7659 | cs->section_name = section_name; |
| 7660 | cs->section_parser = section_parser; |
| 7661 | |
| 7662 | LIST_ADDQ(§ions, &cs->list); |
| 7663 | |
| 7664 | return 1; |
| 7665 | } |
| 7666 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7667 | /* |
| 7668 | * Local variables: |
| 7669 | * c-indent-level: 8 |
| 7670 | * c-basic-offset: 8 |
| 7671 | * End: |
| 7672 | */ |